ScummVM API documentation
player_sid.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCUMM_PLAYERS_PLAYER_SID_H
23 #define SCUMM_PLAYERS_PLAYER_SID_H
24 
25 #include "common/mutex.h"
26 #include "common/scummsys.h"
27 #include "scumm/music.h"
28 #include "audio/sid.h"
29 
30 namespace Scumm {
31 
32 // the "channel" parameters seem to be in fact SID register
33 // offsets. Should be replaced.
34 enum sid_reg_t {
35  FREQ_VOICE1,
36  FREQ_VOICE2,
37  FREQ_VOICE3,
38  FREQ_FILTER,
39  PULSE_VOICE1,
40  PULSE_VOICE2,
41  PULSE_VOICE3
42 };
43 
44 class ScummEngine;
45 
46 class Player_SID : public MusicEngine {
47 public:
48  Player_SID(ScummEngine *scumm);
49  ~Player_SID() override;
50 
51  void setMusicVolume(int vol) override { _maxvol = vol; }
52  void startSound(int sound) override;
53  void stopSound(int sound) override;
54  void stopAllSounds() override;
55  int getSoundStatus(int sound) const override;
56  int getMusicTimer() override;
57 
58 private:
59  SID::SID *_sid;
60  void SID_Write(int reg, uint8 data);
61  void initSID();
62  uint8 *getResource(int resID);
63 
64  ScummEngine *_vm;
65  int _maxvol;
66  Common::Mutex _mutex;
67 
68  int _music_timer;
69  uint8* _music;
70 
71 private:
72  void initMusic(int songResIndex); // $7de6
73  int initSound(int soundResID); // $4D0A
74  void stopSound_intern(int soundResID); // $5093
75  void stopMusic_intern(); // $4CAA
76 
77  void resetSID(); // $48D8
78  void onTimer(); // $481B
79  void handleMusicBuffer();
80  int setupSongFileData(); // $36cb
81  void func_3674(int channel); // $3674
82  void resetPlayerState(); // $48f7
83  void processSongData(int channel); // $4939
84  void readSetSIDFilterAndProps(int *offset, uint8* dataPtr); // $49e7
85  void saveSongPos(int y, int channel);
86  void updateFreq(int channel);
87  void resetFreqDelta(int channel);
88  void readSongChunk(int channel); // $4a6b
89  void setSIDFreqAS(int channel); // $4be6
90  void setSIDWaveCtrlReg(int channel); // $4C0D
91  int setupSongPtr(int channel); // $4C1C
92  void unlockResource(int chanResIndex); // $4CDA
93  void countFreeChannels(); // $4f26
94  void func_4F45(int channel); // $4F45
95  void safeUnlockResource(int resIndex); // $4FEA
96  void releaseResource(int resIndex); // $5031
97  void releaseResChannels(int resIndex); // $5070
98  void releaseResourceUnk(int resIndex); // $50A4
99  void releaseChannel(int channel);
100  void clearSIDWaveform(int channel);
101  void stopChannel(int channel);
102  void swapVars(int channel, int swapIndex); // $51a5
103  void resetSwapVars(); // $52d0
104  void prepareSwapVars(int channel); // $52E5
105  void useSwapVars(int channel); // $5342
106  void lockResource(int resIndex); // $4ff4
107  void reserveChannel(int channel, uint8 prioValue, int chanResIndex); // $4ffe
108  void unlockCodeLocation(); // $513e
109  void lockCodeLocation(); // $514f
110  void func_7eae(int channel, uint8* songFileDataPtr); // $7eae
111  void func_819b(int channel); // $819b
112  void buildStepTbl(int step); // $82B4
113  int reserveSoundFilter(uint8 value, uint8 chanResIndex); // $4ED0
114  int reserveSoundVoice(uint8 value, uint8 chanResIndex); // $4EB8
115  void findLessPrioChannels(uint8 soundPrio); // $4ED8
116  void releaseResourceBySound(int resID); // $5088
117  void readVec6Data(int x, int *offset, uint8 *songFilePtr, int chanResID); // $4E99
118 
119  void unused1(); // $50AF
120 
121  uint8 chanBuffer[3][45];
122 
123  int resID_song;
124 
125  // statusBits1A/1B are always equal
126  uint8 statusBits1A;
127  uint8 statusBits1B;
128 
129  uint8 busyChannelBits;
130 
131  uint8 SIDReg23;
132  uint8 SIDReg23Stuff;
133  uint8 SIDReg24;
134 
135  uint8* chanFileData[3];
136  uint16 chanDataOffset[3];
137  uint8* songPosPtr[7];
138 
139  // 0..2: freq value voice1/2/3
140  // 3: filter freq
141  // 4..6: pulse width
142  uint16 freqReg[7];
143 
144  // start offset[i] for songFileOrChanBufData to obtain songPosPtr[i]
145  // vec6[0..2] = 0x0008;
146  // vec6[4..6] = 0x0019;
147  uint16 vec6[7];
148 
149  // current offset[i] for songFileOrChanBufData to obtain songPosPtr[i] (starts with vec6[i], increased later)
150  uint16 songFileOrChanBufOffset[7];
151 
152  uint16 freqDelta[7];
153  int freqDeltaCounter[7];
154  uint8* swapSongPosPtr[3];
155  uint8* swapVec5[3];
156  uint16 swapVec8[3];
157  uint16 swapVec10[3];
158  uint16 swapFreqReg[3];
159  int swapVec11[3];
160 
161  // never read
162  //uint8* vec5[7];
163  // never read
164  //uint8 vec19[7];
165  // never read (needed by scumm engine?)
166  //bool curChannelActive;
167 
168  uint8* vec20[7];
169 
170  uint8* swapVec20[3];
171 
172  // resource status (never read)
173  // bit7: some flag
174  // bit6..0: counter (use-count?), maybe just bit0 as flag (used/unused?)
175  uint8 resStatus[70];
176 
177  uint8* songFileOrChanBufData;
178  uint8* actSongFileData;
179 
180  uint16 stepTbl[33];
181 
182  bool initializing;
183  bool _soundInQueue;
184  bool isVoiceChannel;
185 
186  bool isMusicPlaying;
187  bool swapVarLoaded;
188  bool bgSoundActive;
189  bool filterUsed;
190 
191  uint8 bgSoundResID;
192  uint8 freeChannelCount;
193 
194  // seems to be used for managing the three voices
195  // bit[0..2]: 0 -> unused, 1 -> already in use
196  uint8 usedChannelBits;
197  uint8 attackReg[3];
198  uint8 sustainReg[3];
199 
200  // -1/0/1
201  int var481A;
202 
203  // bit-array: 00000cba
204  // a/b/c: channel1/2/3
205  uint8 songChannelBits;
206 
207  bool pulseWidthSwapped;
208  bool swapPrepared;
209 
210  // never read
211  //uint8 var5163;
212 
213  bool filterSwapped;
214  uint8 SIDReg24_HiNibble;
215  bool keepSwapVars;
216 
217  uint8 phaseBit[3];
218  bool releasePhase[3];
219 
220  // values: a resID or -1
221  // resIDs: 3, 4, 5 or song-number
222  int _soundQueue[7];
223 
224  // values: a resID or 0
225  // resIDs: 3, 4, 5 or song-number
226  int channelMap[7];
227 
228  uint8 songPosUpdateCounter[7];
229 
230  // priortity of channel contents
231  // MM: 1: lowest .. 120: highest (1,2,A,64,6E,73,78)
232  // Zak: -???: lowest .. 120: highest (5,32,64,65,66,6E,78, A5,A6,AF,D7)
233  uint8 chanPrio[7];
234 
235  // only [0..2] used?
236  uint8 waveCtrlReg[7];
237 
238  uint8 swapAttack[2];
239  uint8 swapSustain[2];
240  uint8 swapSongPrio[3];
241  int swapVec479C[3];
242  uint8 swapVec19[3];
243  uint8 swapSongPosUpdateCounter[3];
244  uint8 swapWaveCtrlReg[3];
245 
246  bool actFilterHasLowerPrio;
247  uint8 chansWithLowerPrioCount;
248  uint8 minChanPrio;
249  uint8 minChanPrioIndex;
250 };
251 
252 } // End of namespace Scumm
253 
254 #endif
void setMusicVolume(int vol) override
Definition: player_sid.h:51
Definition: music.h:40
Definition: scumm.h:511
Definition: sid.h:44
Definition: player_sid.h:46
int getMusicTimer() override
Definition: mutex.h:67
void stopSound(int sound) override
void startSound(int sound) override
int getSoundStatus(int sound) const override
Definition: actor.h:30
void stopAllSounds() override