ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/SID_catweasel.h
Revision: 1.1
Committed: 2010-04-22T09:09:28Z (12 years, 7 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
use SDL for sound

File Contents

# Content
1 /*
2 * SID_linux.h - 6581 emulation, Catweasel specific stuff
3 *
4 * Frodo Copyright (C) Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22 #include <unistd.h>
23
24 // Catweasel ioctls (included here for convenience)
25 #include <linux/ioctl.h>
26 #define CWSID_IOCTL_TYPE ('S')
27 #define CWSID_IOCTL_RESET _IO(CWSID_IOCTL_TYPE, 0)
28 #define CWSID_IOCTL_CARDTYPE _IOR(CWSID_IOCTL_TYPE, 4, int)
29 #define CWSID_IOCTL_PAL _IO(CWSID_IOCTL_TYPE, 0x11)
30 #define CWSID_IOCTL_NTSC _IO(CWSID_IOCTL_TYPE, 0x12)
31 #define CWSID_IOCTL_DOUBLEBUFFER _IOW(CWSID_IOCTL_TYPE, 0x21, int)
32 #define CWSID_IOCTL_DELAY _IOW(CWSID_IOCTL_TYPE, 0x22, int)
33 #define CWSID_MAGIC 0x100
34
35
36 /*
37 * Renderer for Catweasel card
38 */
39
40 // Renderer class
41 class CatweaselRenderer : public SIDRenderer {
42 public:
43 CatweaselRenderer();
44 virtual ~CatweaselRenderer();
45
46 virtual void Reset(void);
47 virtual void EmulateLine(void) {}
48 virtual void WriteRegister(uint16 adr, uint8 byte);
49 virtual void NewPrefs(Prefs *prefs) {}
50 virtual void Pause(void) {}
51 virtual void Resume(void) {}
52
53 private:
54 int cwsid_fh; // Catweasel device file handle
55 };
56
57 // Constructor: Open Catweasel device and reset SID
58 CatweaselRenderer::CatweaselRenderer()
59 {
60 cwsid_fh = open("/dev/sid", O_WRONLY);
61 if (cwsid_fh >= 0) {
62 int i;
63 if (ioctl(cwsid_fh, CWSID_IOCTL_CARDTYPE, &i) < 0 || i != CWSID_MAGIC) {
64 close(cwsid_fh);
65 cwsid_fh = -1;
66 } else {
67 ioctl(cwsid_fh, CWSID_IOCTL_RESET);
68 ioctl(cwsid_fh, CWSID_IOCTL_DOUBLEBUFFER, 0);
69 }
70 }
71
72 Reset();
73 }
74
75 // Destructor: Reset SID and close Catweasel device
76 CatweaselRenderer::~CatweaselRenderer()
77 {
78 Reset();
79
80 if (cwsid_fh >= 0) {
81 close(cwsid_fh);
82 cwsid_fh = -1;
83 }
84 }
85
86 // Reset SID
87 void CatweaselRenderer::Reset(void)
88 {
89 if (cwsid_fh >= 0) {
90 uint8 zero = 0;
91 ioctl(cwsid_fh, CWSID_IOCTL_RESET);
92 lseek(cwsid_fh, 24, SEEK_SET);
93 write(cwsid_fh, &zero, 1);
94 }
95 }
96
97 // Write to register
98 void CatweaselRenderer::WriteRegister(uint16 adr, uint8 byte)
99 {
100 if (cwsid_fh >= 0 && adr < 0x1a) {
101 lseek(cwsid_fh, adr, SEEK_SET);
102 write(cwsid_fh, &byte, 1);
103 lseek(cwsid_fh, adr, SEEK_SET);
104 write(cwsid_fh, &byte, 1);
105 }
106 }