ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/SID.h
Revision: 1.4
Committed: 2005-06-27T19:55:48Z (17 years, 5 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: VERSION_4_2, HEAD
Changes since 1.3: +1 -1 lines
Log Message:
updated copyright dates

File Contents

# Content
1 /*
2 * SID.h - 6581 emulation
3 *
4 * Frodo (C) 1994-1997,2002-2005 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 #ifndef _SID_H
22 #define _SID_H
23
24 #include <stdlib.h>
25
26
27 // Define this if you want an emulation of an 8580
28 // (affects combined waveforms)
29 #undef EMUL_MOS8580
30
31
32 class Prefs;
33 class C64;
34 class SIDRenderer;
35 struct MOS6581State;
36
37 // Class for administrative functions
38 class MOS6581 {
39 public:
40 MOS6581(C64 *c64);
41 ~MOS6581();
42
43 void Reset(void);
44 uint8 ReadRegister(uint16 adr);
45 void WriteRegister(uint16 adr, uint8 byte);
46 void NewPrefs(Prefs *prefs);
47 void PauseSound(void);
48 void ResumeSound(void);
49 void GetState(MOS6581State *ss);
50 void SetState(MOS6581State *ss);
51 void EmulateLine(void);
52
53 private:
54 void open_close_renderer(int old_type, int new_type);
55
56 C64 *the_c64; // Pointer to C64 object
57 SIDRenderer *the_renderer; // Pointer to current renderer
58 uint8 regs[32]; // Copies of the 25 write-only SID registers
59 uint8 last_sid_byte; // Last value written to SID
60 };
61
62
63 // Renderers do the actual audio data processing
64 class SIDRenderer {
65 public:
66 virtual ~SIDRenderer() {}
67 virtual void Reset(void)=0;
68 virtual void EmulateLine(void)=0;
69 virtual void WriteRegister(uint16 adr, uint8 byte)=0;
70 virtual void NewPrefs(Prefs *prefs)=0;
71 virtual void Pause(void)=0;
72 virtual void Resume(void)=0;
73 };
74
75
76 // SID state
77 struct MOS6581State {
78 uint8 freq_lo_1;
79 uint8 freq_hi_1;
80 uint8 pw_lo_1;
81 uint8 pw_hi_1;
82 uint8 ctrl_1;
83 uint8 AD_1;
84 uint8 SR_1;
85
86 uint8 freq_lo_2;
87 uint8 freq_hi_2;
88 uint8 pw_lo_2;
89 uint8 pw_hi_2;
90 uint8 ctrl_2;
91 uint8 AD_2;
92 uint8 SR_2;
93
94 uint8 freq_lo_3;
95 uint8 freq_hi_3;
96 uint8 pw_lo_3;
97 uint8 pw_hi_3;
98 uint8 ctrl_3;
99 uint8 AD_3;
100 uint8 SR_3;
101
102 uint8 fc_lo;
103 uint8 fc_hi;
104 uint8 res_filt;
105 uint8 mode_vol;
106
107 uint8 pot_x;
108 uint8 pot_y;
109 uint8 osc_3;
110 uint8 env_3;
111 };
112
113
114 /*
115 * Fill buffer (for Unix sound routines), sample volume (for sampled voice)
116 */
117
118 inline void MOS6581::EmulateLine(void)
119 {
120 if (the_renderer != NULL)
121 the_renderer->EmulateLine();
122 }
123
124
125 /*
126 * Read from register
127 */
128
129 inline uint8 MOS6581::ReadRegister(uint16 adr)
130 {
131 // A/D converters
132 if (adr == 0x19 || adr == 0x1a) {
133 last_sid_byte = 0;
134 return 0xff;
135 }
136
137 // Voice 3 oscillator/EG readout
138 if (adr == 0x1b || adr == 0x1c) {
139 last_sid_byte = 0;
140 return rand();
141 }
142
143 // Write-only register: Return last value written to SID
144 return last_sid_byte;
145 }
146
147
148 /*
149 * Write to register
150 */
151
152 inline void MOS6581::WriteRegister(uint16 adr, uint8 byte)
153 {
154 // Keep a local copy of the register values
155 last_sid_byte = regs[adr] = byte;
156
157 if (the_renderer != NULL)
158 the_renderer->WriteRegister(adr, byte);
159 }
160
161 #endif