-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSID.h
executable file
·172 lines (134 loc) · 3.27 KB
/
SID.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Frodo, Commodore 64 emulator for the iPhone
Copyright (C) 1994-1997,2002 Christian Bauer
See gpl.txt for license information.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* SID.h - 6581 emulation
*
* Frodo (C) 1994-1997,2002 Christian Bauer
*/
#ifndef _SID_H
#define _SID_H
#include <stdlib.h>
#define USE_FASTSID
#ifdef USE_FASTSID
#import "FastDigitalRenderer.h"
#define RENDERER_TYPE FastDigitalRenderer
#else
#import "DigitalRenderer.h"
#define RENDERER_TYPE DigitalRenderer
#endif
// Define this if you want an emulation of an 8580
// (affects combined waveforms)
#undef EMUL_MOS8580
class Prefs;
class C64;
class DigitalRenderer;
struct MOS6581State;
// Class for administrative functions
class MOS6581 {
public:
MOS6581(C64 *c64);
~MOS6581();
void Reset(void);
uint8 ReadRegister(uint16 adr);
void WriteRegister(uint16 adr, uint8 byte);
void NewPrefs(Prefs *prefs);
void PauseSound(void);
void ResumeSound(void);
void GetState(MOS6581State *ss);
void SetState(MOS6581State *ss);
void EmulateLine(void);
void VBlank(void);
private:
void open_close_renderer(int old_type, int new_type);
C64 *the_c64; // Pointer to C64 object
RENDERER_TYPE *the_renderer; // Pointer to current renderer
uint8 regs[32]; // Copies of the 25 write-only SID registers
uint8 last_sid_byte; // Last value written to SID
};
// SID state
struct MOS6581State {
uint8 freq_lo_1;
uint8 freq_hi_1;
uint8 pw_lo_1;
uint8 pw_hi_1;
uint8 ctrl_1;
uint8 AD_1;
uint8 SR_1;
uint8 freq_lo_2;
uint8 freq_hi_2;
uint8 pw_lo_2;
uint8 pw_hi_2;
uint8 ctrl_2;
uint8 AD_2;
uint8 SR_2;
uint8 freq_lo_3;
uint8 freq_hi_3;
uint8 pw_lo_3;
uint8 pw_hi_3;
uint8 ctrl_3;
uint8 AD_3;
uint8 SR_3;
uint8 fc_lo;
uint8 fc_hi;
uint8 res_filt;
uint8 mode_vol;
uint8 pot_x;
uint8 pot_y;
uint8 osc_3;
uint8 env_3;
};
/*
* Fill buffer (for Unix sound routines), sample volume (for sampled voice)
*/
inline void MOS6581::EmulateLine(void)
{
assert(the_renderer != NULL);
the_renderer->EmulateLine();
}
inline void MOS6581::VBlank(void)
{
assert(the_renderer != NULL);
the_renderer->VBlank();
}
/*
* Read from register
*/
inline uint8 MOS6581::ReadRegister(uint16 adr)
{
// A/D converters
if (adr == 0x19 || adr == 0x1a) {
last_sid_byte = 0;
return 0xff;
}
// Voice 3 oscillator/EG readout
if (adr == 0x1b || adr == 0x1c) {
last_sid_byte = 0;
return rand();
}
// Write-only register: Return last value written to SID
return last_sid_byte;
}
/*
* Write to register
*/
inline void MOS6581::WriteRegister(uint16 adr, uint8 byte)
{
assert(the_renderer != NULL);
// Keep a local copy of the register values
last_sid_byte = regs[adr] = byte;
the_renderer->WriteRegister(adr, byte);
}
#endif