Mercurial > audlegacy-plugins
comparison src/adplug/core/adl.cxx @ 955:4709ce4e209e trunk
[svn] Run indent -ts4 -nut -bli0 -cdw on this messy lot. Upstream is not consistent with whitespace anyway, no loss there.
author | chainsaw |
---|---|
date | Sat, 14 Apr 2007 15:23:50 -0700 |
parents | 48ebfc711a8c |
children | 368f8ee0a95f |
comparison
equal
deleted
inserted
replaced
954:d7a6fd179cd2 | 955:4709ce4e209e |
---|---|
59 # define debugC(i1, i2, ...) AdPlug_LogWrite(__VA_ARGS__); \ | 59 # define debugC(i1, i2, ...) AdPlug_LogWrite(__VA_ARGS__); \ |
60 AdPlug_LogWrite("\n") | 60 AdPlug_LogWrite("\n") |
61 #else | 61 #else |
62 # define kDebugLevelSound 1 | 62 # define kDebugLevelSound 1 |
63 | 63 |
64 static inline void warning(const char *str, ...) | 64 static inline void |
65 { | 65 warning (const char *str, ...) |
66 } | 66 { |
67 | 67 } |
68 static inline void debugC(int i1, int i2, const char *str, ...) | 68 |
69 static inline void | |
70 debugC (int i1, int i2, const char *str, ...) | |
69 { | 71 { |
70 } | 72 } |
71 #endif | 73 #endif |
72 | 74 |
73 // #define warning(...) | 75 // #define warning(...) |
78 // Basic Adlib Programming: | 80 // Basic Adlib Programming: |
79 // http://www.gamedev.net/reference/articles/article446.asp | 81 // http://www.gamedev.net/reference/articles/article446.asp |
80 | 82 |
81 #define CALLBACKS_PER_SECOND 72 | 83 #define CALLBACKS_PER_SECOND 72 |
82 | 84 |
83 typedef uint8_t uint8; | 85 typedef uint8_t uint8; |
84 typedef int8_t int8; | 86 typedef int8_t int8; |
85 typedef uint16_t uint16; | 87 typedef uint16_t uint16; |
86 typedef int16_t int16; | 88 typedef int16_t int16; |
87 typedef uint32_t uint32; | 89 typedef uint32_t uint32; |
88 typedef int32_t int32; | 90 typedef int32_t int32; |
89 typedef uint8_t byte; | 91 typedef uint8_t byte; |
90 | 92 |
91 static inline uint16 READ_LE_UINT16(const void *ptr) { | 93 static inline uint16 |
92 const byte *b = (const byte *)ptr; | 94 READ_LE_UINT16 (const void *ptr) |
95 { | |
96 const byte *b = (const byte *) ptr; | |
93 return (b[1] << 8) + b[0]; | 97 return (b[1] << 8) + b[0]; |
94 } | 98 } |
95 | 99 |
96 static inline uint16 READ_BE_UINT16(const void *ptr) { | 100 static inline uint16 |
97 const byte *b = (const byte *)ptr; | 101 READ_BE_UINT16 (const void *ptr) |
102 { | |
103 const byte *b = (const byte *) ptr; | |
98 return (b[0] << 8) + b[1]; | 104 return (b[0] << 8) + b[1]; |
99 } | 105 } |
100 | 106 |
101 class AdlibDriver { | 107 class AdlibDriver |
108 { | |
102 public: | 109 public: |
103 AdlibDriver(Copl *opl); | 110 AdlibDriver (Copl * opl); |
104 ~AdlibDriver(); | 111 ~AdlibDriver (); |
105 | 112 |
106 int callback(int opcode, ...); | 113 int callback (int opcode, ...); |
107 void callback(); | 114 void callback (); |
108 | 115 |
109 // AudioStream API | 116 // AudioStream API |
110 // int readBuffer(int16 *buffer, const int numSamples) { | 117 // int readBuffer(int16 *buffer, const int numSamples) { |
111 // int32 samplesLeft = numSamples; | 118 // int32 samplesLeft = numSamples; |
112 // memset(buffer, 0, sizeof(int16) * numSamples); | 119 // memset(buffer, 0, sizeof(int16) * numSamples); |
113 // while (samplesLeft) { | 120 // while (samplesLeft) { |
114 // if (!_samplesTillCallback) { | 121 // if (!_samplesTillCallback) { |
115 // callback(); | 122 // callback(); |
116 // _samplesTillCallback = _samplesPerCallback; | 123 // _samplesTillCallback = _samplesPerCallback; |
117 // _samplesTillCallbackRemainder += _samplesPerCallbackRemainder; | 124 // _samplesTillCallbackRemainder += _samplesPerCallbackRemainder; |
118 // if (_samplesTillCallbackRemainder >= CALLBACKS_PER_SECOND) { | 125 // if (_samplesTillCallbackRemainder >= CALLBACKS_PER_SECOND) { |
119 // _samplesTillCallback++; | 126 // _samplesTillCallback++; |
120 // _samplesTillCallbackRemainder -= CALLBACKS_PER_SECOND; | 127 // _samplesTillCallbackRemainder -= CALLBACKS_PER_SECOND; |
121 // } | 128 // } |
122 // } | 129 // } |
123 | 130 |
124 // int32 render = MIN(samplesLeft, _samplesTillCallback); | 131 // int32 render = MIN(samplesLeft, _samplesTillCallback); |
125 // samplesLeft -= render; | 132 // samplesLeft -= render; |
126 // _samplesTillCallback -= render; | 133 // _samplesTillCallback -= render; |
127 // YM3812UpdateOne(_adlib, buffer, render); | 134 // YM3812UpdateOne(_adlib, buffer, render); |
128 // buffer += render; | 135 // buffer += render; |
129 // } | 136 // } |
130 // return numSamples; | 137 // return numSamples; |
131 // } | 138 // } |
132 | 139 |
133 bool isStereo() const { return false; } | 140 bool isStereo () const |
134 bool endOfData() const { return false; } | 141 { |
135 // int getRate() const { return _mixer->getOutputRate(); } | 142 return false; |
136 | 143 } |
137 struct OpcodeEntry { | 144 bool endOfData () const |
138 typedef int (AdlibDriver::*DriverOpcode)(va_list &list); | 145 { |
146 return false; | |
147 } | |
148 // int getRate() const { return _mixer->getOutputRate(); } | |
149 | |
150 struct OpcodeEntry | |
151 { | |
152 typedef int (AdlibDriver::*DriverOpcode) (va_list & list); | |
139 DriverOpcode function; | 153 DriverOpcode function; |
140 const char *name; | 154 const char *name; |
141 }; | 155 }; |
142 | 156 |
143 void setupOpcodeList(); | 157 void setupOpcodeList (); |
144 const OpcodeEntry *_opcodeList; | 158 const OpcodeEntry *_opcodeList; |
145 int _opcodesEntries; | 159 int _opcodesEntries; |
146 | 160 |
147 int snd_ret0x100(va_list &list); | 161 int snd_ret0x100 (va_list & list); |
148 int snd_ret0x1983(va_list &list); | 162 int snd_ret0x1983 (va_list & list); |
149 int snd_initDriver(va_list &list); | 163 int snd_initDriver (va_list & list); |
150 int snd_deinitDriver(va_list &list); | 164 int snd_deinitDriver (va_list & list); |
151 int snd_setSoundData(va_list &list); | 165 int snd_setSoundData (va_list & list); |
152 int snd_unkOpcode1(va_list &list); | 166 int snd_unkOpcode1 (va_list & list); |
153 int snd_startSong(va_list &list); | 167 int snd_startSong (va_list & list); |
154 int snd_unkOpcode2(va_list &list); | 168 int snd_unkOpcode2 (va_list & list); |
155 int snd_unkOpcode3(va_list &list); | 169 int snd_unkOpcode3 (va_list & list); |
156 int snd_readByte(va_list &list); | 170 int snd_readByte (va_list & list); |
157 int snd_writeByte(va_list &list); | 171 int snd_writeByte (va_list & list); |
158 int snd_getSoundTrigger(va_list &list); | 172 int snd_getSoundTrigger (va_list & list); |
159 int snd_unkOpcode4(va_list &list); | 173 int snd_unkOpcode4 (va_list & list); |
160 int snd_dummy(va_list &list); | 174 int snd_dummy (va_list & list); |
161 int snd_getNullvar4(va_list &list); | 175 int snd_getNullvar4 (va_list & list); |
162 int snd_setNullvar3(va_list &list); | 176 int snd_setNullvar3 (va_list & list); |
163 int snd_setFlag(va_list &list); | 177 int snd_setFlag (va_list & list); |
164 int snd_clearFlag(va_list &list); | 178 int snd_clearFlag (va_list & list); |
165 | 179 |
166 // These variables have not yet been named, but some of them are partly | 180 // These variables have not yet been named, but some of them are partly |
167 // known nevertheless: | 181 // known nevertheless: |
168 // | 182 // |
169 // unk16 - Sound-related. Possibly some sort of pitch bend. | 183 // unk16 - Sound-related. Possibly some sort of pitch bend. |
184 // unk38 - Sound-effect. Used for primaryEffect2() | 198 // unk38 - Sound-effect. Used for primaryEffect2() |
185 // unk39 - Currently unused, except for updateCallback56() | 199 // unk39 - Currently unused, except for updateCallback56() |
186 // unk40 - Currently unused, except for updateCallback56() | 200 // unk40 - Currently unused, except for updateCallback56() |
187 // unk41 - Sound-effect. Used for primaryEffect2() | 201 // unk41 - Sound-effect. Used for primaryEffect2() |
188 | 202 |
189 struct Channel { | 203 struct Channel |
204 { | |
190 uint8 opExtraLevel2; | 205 uint8 opExtraLevel2; |
191 uint8 *dataptr; | 206 uint8 *dataptr; |
192 uint8 duration; | 207 uint8 duration; |
193 uint8 repeatCounter; | 208 uint8 repeatCounter; |
194 int8 baseOctave; | 209 int8 baseOctave; |
212 uint8 baseFreq; | 227 uint8 baseFreq; |
213 uint8 tempo; | 228 uint8 tempo; |
214 uint8 position; | 229 uint8 position; |
215 uint8 regAx; | 230 uint8 regAx; |
216 uint8 regBx; | 231 uint8 regBx; |
217 typedef void (AdlibDriver::*Callback)(Channel&); | 232 typedef void (AdlibDriver::*Callback) (Channel &); |
218 Callback primaryEffect; | 233 Callback primaryEffect; |
219 Callback secondaryEffect; | 234 Callback secondaryEffect; |
220 uint8 fractionalSpacing; | 235 uint8 fractionalSpacing; |
221 uint8 opLevel1; | 236 uint8 opLevel1; |
222 uint8 opLevel2; | 237 uint8 opLevel2; |
223 uint8 opExtraLevel3; | 238 uint8 opExtraLevel3; |
224 uint8 twoChan; | 239 uint8 twoChan; |
225 uint8 unk39; | 240 uint8 unk39; |
226 uint8 unk40; | 241 uint8 unk40; |
227 uint8 spacing1; | 242 uint8 spacing1; |
228 uint8 durationRandomness; | 243 uint8 durationRandomness; |
229 uint8 unk19; | 244 uint8 unk19; |
230 uint8 unk18; | 245 uint8 unk18; |
235 uint8 tempoReset; | 250 uint8 tempoReset; |
236 uint8 rawNote; | 251 uint8 rawNote; |
237 int8 unk16; | 252 int8 unk16; |
238 }; | 253 }; |
239 | 254 |
240 void primaryEffect1(Channel &channel); | 255 void primaryEffect1 (Channel & channel); |
241 void primaryEffect2(Channel &channel); | 256 void primaryEffect2 (Channel & channel); |
242 void secondaryEffect1(Channel &channel); | 257 void secondaryEffect1 (Channel & channel); |
243 | 258 |
244 void resetAdlibState(); | 259 void resetAdlibState (); |
245 void writeOPL(byte reg, byte val); | 260 void writeOPL (byte reg, byte val); |
246 void initChannel(Channel &channel); | 261 void initChannel (Channel & channel); |
247 void noteOff(Channel &channel); | 262 void noteOff (Channel & channel); |
248 void unkOutput2(uint8 num); | 263 void unkOutput2 (uint8 num); |
249 | 264 |
250 uint16 getRandomNr(); | 265 uint16 getRandomNr (); |
251 void setupDuration(uint8 duration, Channel &channel); | 266 void setupDuration (uint8 duration, Channel & channel); |
252 | 267 |
253 void setupNote(uint8 rawNote, Channel &channel, bool flag = false); | 268 void setupNote (uint8 rawNote, Channel & channel, bool flag = false); |
254 void setupInstrument(uint8 regOffset, uint8 *dataptr, Channel &channel); | 269 void setupInstrument (uint8 regOffset, uint8 * dataptr, Channel & channel); |
255 void noteOn(Channel &channel); | 270 void noteOn (Channel & channel); |
256 | 271 |
257 void adjustVolume(Channel &channel); | 272 void adjustVolume (Channel & channel); |
258 | 273 |
259 uint8 calculateOpLevel1(Channel &channel); | 274 uint8 calculateOpLevel1 (Channel & channel); |
260 uint8 calculateOpLevel2(Channel &channel); | 275 uint8 calculateOpLevel2 (Channel & channel); |
261 | 276 |
262 uint16 checkValue(int16 val) { | 277 uint16 checkValue (int16 val) |
278 { | |
263 if (val < 0) | 279 if (val < 0) |
264 val = 0; | 280 val = 0; |
265 else if (val > 0x3F) | 281 else if (val > 0x3F) |
266 val = 0x3F; | 282 val = 0x3F; |
267 return val; | 283 return val; |
270 // The sound data has at least two lookup tables: | 286 // The sound data has at least two lookup tables: |
271 // | 287 // |
272 // * One for programs, starting at offset 0. | 288 // * One for programs, starting at offset 0. |
273 // * One for instruments, starting at offset 500. | 289 // * One for instruments, starting at offset 500. |
274 | 290 |
275 uint8 *getProgram(int progId) { | 291 uint8 *getProgram (int progId) |
276 return _soundData + READ_LE_UINT16(_soundData + 2 * progId); | 292 { |
277 } | 293 return _soundData + READ_LE_UINT16 (_soundData + 2 * progId); |
278 | 294 } |
279 uint8 *getInstrument(int instrumentId) { | 295 |
280 return _soundData + READ_LE_UINT16(_soundData + 500 + 2 * instrumentId); | 296 uint8 *getInstrument (int instrumentId) |
281 } | 297 { |
282 | 298 return _soundData + READ_LE_UINT16 (_soundData + 500 + 2 * instrumentId); |
283 void setupPrograms(); | 299 } |
284 void executePrograms(); | 300 |
285 | 301 void setupPrograms (); |
286 struct ParserOpcode { | 302 void executePrograms (); |
287 typedef int (AdlibDriver::*POpcode)(uint8 *&dataptr, Channel &channel, uint8 value); | 303 |
304 struct ParserOpcode | |
305 { | |
306 typedef int (AdlibDriver::*POpcode) (uint8 * &dataptr, Channel & channel, | |
307 uint8 value); | |
288 POpcode function; | 308 POpcode function; |
289 const char *name; | 309 const char *name; |
290 }; | 310 }; |
291 | 311 |
292 void setupParserOpcodeTable(); | 312 void setupParserOpcodeTable (); |
293 const ParserOpcode *_parserOpcodeTable; | 313 const ParserOpcode *_parserOpcodeTable; |
294 int _parserOpcodeTableSize; | 314 int _parserOpcodeTableSize; |
295 | 315 |
296 int update_setRepeat(uint8 *&dataptr, Channel &channel, uint8 value); | 316 int update_setRepeat (uint8 * &dataptr, Channel & channel, uint8 value); |
297 int update_checkRepeat(uint8 *&dataptr, Channel &channel, uint8 value); | 317 int update_checkRepeat (uint8 * &dataptr, Channel & channel, uint8 value); |
298 int update_setupProgram(uint8 *&dataptr, Channel &channel, uint8 value); | 318 int update_setupProgram (uint8 * &dataptr, Channel & channel, uint8 value); |
299 int update_setNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value); | 319 int update_setNoteSpacing (uint8 * &dataptr, Channel & channel, |
300 int update_jump(uint8 *&dataptr, Channel &channel, uint8 value); | 320 uint8 value); |
301 int update_jumpToSubroutine(uint8 *&dataptr, Channel &channel, uint8 value); | 321 int update_jump (uint8 * &dataptr, Channel & channel, uint8 value); |
302 int update_returnFromSubroutine(uint8 *&dataptr, Channel &channel, uint8 value); | 322 int update_jumpToSubroutine (uint8 * &dataptr, Channel & channel, |
303 int update_setBaseOctave(uint8 *&dataptr, Channel &channel, uint8 value); | 323 uint8 value); |
304 int update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 value); | 324 int update_returnFromSubroutine (uint8 * &dataptr, Channel & channel, |
305 int update_playRest(uint8 *&dataptr, Channel &channel, uint8 value); | 325 uint8 value); |
306 int update_writeAdlib(uint8 *&dataptr, Channel &channel, uint8 value); | 326 int update_setBaseOctave (uint8 * &dataptr, Channel & channel, uint8 value); |
307 int update_setupNoteAndDuration(uint8 *&dataptr, Channel &channel, uint8 value); | 327 int update_stopChannel (uint8 * &dataptr, Channel & channel, uint8 value); |
308 int update_setBaseNote(uint8 *&dataptr, Channel &channel, uint8 value); | 328 int update_playRest (uint8 * &dataptr, Channel & channel, uint8 value); |
309 int update_setupSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); | 329 int update_writeAdlib (uint8 * &dataptr, Channel & channel, uint8 value); |
310 int update_stopOtherChannel(uint8 *&dataptr, Channel &channel, uint8 value); | 330 int update_setupNoteAndDuration (uint8 * &dataptr, Channel & channel, |
311 int update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, uint8 value); | 331 uint8 value); |
312 int update_setupInstrument(uint8 *&dataptr, Channel &channel, uint8 value); | 332 int update_setBaseNote (uint8 * &dataptr, Channel & channel, uint8 value); |
313 int update_setupPrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); | 333 int update_setupSecondaryEffect1 (uint8 * &dataptr, Channel & channel, |
314 int update_removePrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); | 334 uint8 value); |
315 int update_setBaseFreq(uint8 *&dataptr, Channel &channel, uint8 value); | 335 int update_stopOtherChannel (uint8 * &dataptr, Channel & channel, |
316 int update_setupPrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value); | 336 uint8 value); |
317 int update_setPriority(uint8 *&dataptr, Channel &channel, uint8 value); | 337 int update_waitForEndOfProgram (uint8 * &dataptr, Channel & channel, |
318 int updateCallback23(uint8 *&dataptr, Channel &channel, uint8 value); | 338 uint8 value); |
319 int updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value); | 339 int update_setupInstrument (uint8 * &dataptr, Channel & channel, |
320 int update_setExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value); | 340 uint8 value); |
321 int update_setupDuration(uint8 *&dataptr, Channel &channel, uint8 value); | 341 int update_setupPrimaryEffect1 (uint8 * &dataptr, Channel & channel, |
322 int update_playNote(uint8 *&dataptr, Channel &channel, uint8 value); | 342 uint8 value); |
323 int update_setFractionalNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value); | 343 int update_removePrimaryEffect1 (uint8 * &dataptr, Channel & channel, |
324 int update_setTempo(uint8 *&dataptr, Channel &channel, uint8 value); | 344 uint8 value); |
325 int update_removeSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value); | 345 int update_setBaseFreq (uint8 * &dataptr, Channel & channel, uint8 value); |
326 int update_setChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value); | 346 int update_setupPrimaryEffect2 (uint8 * &dataptr, Channel & channel, |
327 int update_setExtraLevel3(uint8 *&dataptr, Channel &channel, uint8 value); | 347 uint8 value); |
328 int update_setExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value); | 348 int update_setPriority (uint8 * &dataptr, Channel & channel, uint8 value); |
329 int update_changeExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value); | 349 int updateCallback23 (uint8 * &dataptr, Channel & channel, uint8 value); |
330 int update_setAMDepth(uint8 *&dataptr, Channel &channel, uint8 value); | 350 int updateCallback24 (uint8 * &dataptr, Channel & channel, uint8 value); |
331 int update_setVibratoDepth(uint8 *&dataptr, Channel &channel, uint8 value); | 351 int update_setExtraLevel1 (uint8 * &dataptr, Channel & channel, |
332 int update_changeExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value); | 352 uint8 value); |
333 int updateCallback38(uint8 *&dataptr, Channel &channel, uint8 value); | 353 int update_setupDuration (uint8 * &dataptr, Channel & channel, uint8 value); |
334 int updateCallback39(uint8 *&dataptr, Channel &channel, uint8 value); | 354 int update_playNote (uint8 * &dataptr, Channel & channel, uint8 value); |
335 int update_removePrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value); | 355 int update_setFractionalNoteSpacing (uint8 * &dataptr, Channel & channel, |
336 int updateCallback41(uint8 *&dataptr, Channel &channel, uint8 value); | 356 uint8 value); |
337 int update_resetToGlobalTempo(uint8 *&dataptr, Channel &channel, uint8 value); | 357 int update_setTempo (uint8 * &dataptr, Channel & channel, uint8 value); |
338 int update_nop1(uint8 *&dataptr, Channel &channel, uint8 value); | 358 int update_removeSecondaryEffect1 (uint8 * &dataptr, Channel & channel, |
339 int update_setDurationRandomness(uint8 *&dataptr, Channel &channel, uint8 value); | 359 uint8 value); |
340 int update_changeChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value); | 360 int update_setChannelTempo (uint8 * &dataptr, Channel & channel, |
341 int updateCallback46(uint8 *&dataptr, Channel &channel, uint8 value); | 361 uint8 value); |
342 int update_nop2(uint8 *&dataptr, Channel &channel, uint8 value); | 362 int update_setExtraLevel3 (uint8 * &dataptr, Channel & channel, |
343 int update_setupRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); | 363 uint8 value); |
344 int update_playRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); | 364 int update_setExtraLevel2 (uint8 * &dataptr, Channel & channel, |
345 int update_removeRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value); | 365 uint8 value); |
346 int updateCallback51(uint8 *&dataptr, Channel &channel, uint8 value); | 366 int update_changeExtraLevel2 (uint8 * &dataptr, Channel & channel, |
347 int updateCallback52(uint8 *&dataptr, Channel &channel, uint8 value); | 367 uint8 value); |
348 int updateCallback53(uint8 *&dataptr, Channel &channel, uint8 value); | 368 int update_setAMDepth (uint8 * &dataptr, Channel & channel, uint8 value); |
349 int update_setSoundTrigger(uint8 *&dataptr, Channel &channel, uint8 value); | 369 int update_setVibratoDepth (uint8 * &dataptr, Channel & channel, |
350 int update_setTempoReset(uint8 *&dataptr, Channel &channel, uint8 value); | 370 uint8 value); |
351 int updateCallback56(uint8 *&dataptr, Channel &channel, uint8 value); | 371 int update_changeExtraLevel1 (uint8 * &dataptr, Channel & channel, |
372 uint8 value); | |
373 int updateCallback38 (uint8 * &dataptr, Channel & channel, uint8 value); | |
374 int updateCallback39 (uint8 * &dataptr, Channel & channel, uint8 value); | |
375 int update_removePrimaryEffect2 (uint8 * &dataptr, Channel & channel, | |
376 uint8 value); | |
377 int updateCallback41 (uint8 * &dataptr, Channel & channel, uint8 value); | |
378 int update_resetToGlobalTempo (uint8 * &dataptr, Channel & channel, | |
379 uint8 value); | |
380 int update_nop1 (uint8 * &dataptr, Channel & channel, uint8 value); | |
381 int update_setDurationRandomness (uint8 * &dataptr, Channel & channel, | |
382 uint8 value); | |
383 int update_changeChannelTempo (uint8 * &dataptr, Channel & channel, | |
384 uint8 value); | |
385 int updateCallback46 (uint8 * &dataptr, Channel & channel, uint8 value); | |
386 int update_nop2 (uint8 * &dataptr, Channel & channel, uint8 value); | |
387 int update_setupRhythmSection (uint8 * &dataptr, Channel & channel, | |
388 uint8 value); | |
389 int update_playRhythmSection (uint8 * &dataptr, Channel & channel, | |
390 uint8 value); | |
391 int update_removeRhythmSection (uint8 * &dataptr, Channel & channel, | |
392 uint8 value); | |
393 int updateCallback51 (uint8 * &dataptr, Channel & channel, uint8 value); | |
394 int updateCallback52 (uint8 * &dataptr, Channel & channel, uint8 value); | |
395 int updateCallback53 (uint8 * &dataptr, Channel & channel, uint8 value); | |
396 int update_setSoundTrigger (uint8 * &dataptr, Channel & channel, | |
397 uint8 value); | |
398 int update_setTempoReset (uint8 * &dataptr, Channel & channel, uint8 value); | |
399 int updateCallback56 (uint8 * &dataptr, Channel & channel, uint8 value); | |
352 | 400 |
353 // These variables have not yet been named, but some of them are partly | 401 // These variables have not yet been named, but some of them are partly |
354 // known nevertheless: | 402 // known nevertheless: |
355 // | 403 // |
356 // _unkValue1 - Unknown. Used for updating _unkValue2 | 404 // _unkValue1 - Unknown. Used for updating _unkValue2 |
438 static const uint8 _unkTables[][32]; | 486 static const uint8 _unkTables[][32]; |
439 | 487 |
440 Copl *opl; | 488 Copl *opl; |
441 }; | 489 }; |
442 | 490 |
443 AdlibDriver::AdlibDriver(Copl *newopl) | 491 AdlibDriver::AdlibDriver (Copl * newopl):opl (newopl) |
444 : opl(newopl) | 492 { |
445 { | 493 setupOpcodeList (); |
446 setupOpcodeList(); | 494 setupParserOpcodeTable (); |
447 setupParserOpcodeTable(); | 495 |
448 | 496 // _mixer = mixer; |
449 // _mixer = mixer; | |
450 | 497 |
451 _flags = 0; | 498 _flags = 0; |
452 // _adlib = makeAdlibOPL(getRate()); | 499 // _adlib = makeAdlibOPL(getRate()); |
453 // assert(_adlib); | 500 // assert(_adlib); |
454 | 501 |
455 memset(_channels, 0, sizeof(_channels)); | 502 memset (_channels, 0, sizeof (_channels)); |
456 _soundData = 0; | 503 _soundData = 0; |
457 | 504 |
458 _vibratoAndAMDepthBits = _curRegOffset = 0; | 505 _vibratoAndAMDepthBits = _curRegOffset = 0; |
459 | 506 |
460 _lastProcessed = _flagTrigger = _curChannel = _rhythmSectionBits = 0; | 507 _lastProcessed = _flagTrigger = _curChannel = _rhythmSectionBits = 0; |
470 _unkValue11 = _unkValue12 = _unkValue13 = _unkValue14 = _unkValue15 = | 517 _unkValue11 = _unkValue12 = _unkValue13 = _unkValue14 = _unkValue15 = |
471 _unkValue16 = _unkValue17 = _unkValue18 = _unkValue19 = _unkValue20 = 0; | 518 _unkValue16 = _unkValue17 = _unkValue18 = _unkValue19 = _unkValue20 = 0; |
472 | 519 |
473 _tablePtr1 = _tablePtr2 = 0; | 520 _tablePtr1 = _tablePtr2 = 0; |
474 | 521 |
475 // _mixer->setupPremix(this); | 522 // _mixer->setupPremix(this); |
476 | 523 |
477 // _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; | 524 // _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; |
478 // _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; | 525 // _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; |
479 _samplesTillCallback = 0; | 526 _samplesTillCallback = 0; |
480 _samplesTillCallbackRemainder = 0; | 527 _samplesTillCallbackRemainder = 0; |
481 } | 528 } |
482 | 529 |
483 AdlibDriver::~AdlibDriver() { | 530 AdlibDriver::~AdlibDriver () |
484 // _mixer->setupPremix(0); | 531 { |
485 // OPLDestroy(_adlib); | 532 // _mixer->setupPremix(0); |
486 // _adlib = 0; | 533 // OPLDestroy(_adlib); |
487 } | 534 // _adlib = 0; |
488 | 535 } |
489 int AdlibDriver::callback(int opcode, ...) { | 536 |
490 // lock(); | 537 int |
491 if (opcode >= _opcodesEntries || opcode < 0) { | 538 AdlibDriver::callback (int opcode, ...) |
492 warning("AdlibDriver: calling unknown opcode '%d'", opcode); | 539 { |
540 // lock(); | |
541 if (opcode >= _opcodesEntries || opcode < 0) | |
542 { | |
543 warning ("AdlibDriver: calling unknown opcode '%d'", opcode); | |
493 return 0; | 544 return 0; |
494 } | 545 } |
495 | 546 |
496 debugC(9, kDebugLevelSound, "Calling opcode '%s' (%d)", _opcodeList[opcode].name, opcode); | 547 debugC (9, kDebugLevelSound, "Calling opcode '%s' (%d)", |
548 _opcodeList[opcode].name, opcode); | |
497 | 549 |
498 va_list args; | 550 va_list args; |
499 va_start(args, opcode); | 551 va_start (args, opcode); |
500 int returnValue = (this->*(_opcodeList[opcode].function))(args); | 552 int returnValue = (this->*(_opcodeList[opcode].function)) (args); |
501 va_end(args); | 553 va_end (args); |
502 // unlock(); | 554 // unlock(); |
503 return returnValue; | 555 return returnValue; |
504 } | 556 } |
505 | 557 |
506 // Opcodes | 558 // Opcodes |
507 | 559 |
508 int AdlibDriver::snd_ret0x100(va_list &list) { | 560 int |
561 AdlibDriver::snd_ret0x100 (va_list & list) | |
562 { | |
509 return 0x100; | 563 return 0x100; |
510 } | 564 } |
511 | 565 |
512 int AdlibDriver::snd_ret0x1983(va_list &list) { | 566 int |
567 AdlibDriver::snd_ret0x1983 (va_list & list) | |
568 { | |
513 return 0x1983; | 569 return 0x1983; |
514 } | 570 } |
515 | 571 |
516 int AdlibDriver::snd_initDriver(va_list &list) { | 572 int |
573 AdlibDriver::snd_initDriver (va_list & list) | |
574 { | |
517 _lastProcessed = _soundsPlaying = 0; | 575 _lastProcessed = _soundsPlaying = 0; |
518 resetAdlibState(); | 576 resetAdlibState (); |
519 return 0; | 577 return 0; |
520 } | 578 } |
521 | 579 |
522 int AdlibDriver::snd_deinitDriver(va_list &list) { | 580 int |
523 resetAdlibState(); | 581 AdlibDriver::snd_deinitDriver (va_list & list) |
524 return 0; | 582 { |
525 } | 583 resetAdlibState (); |
526 | 584 return 0; |
527 int AdlibDriver::snd_setSoundData(va_list &list) { | 585 } |
528 if (_soundData) { | 586 |
529 delete [] _soundData; | 587 int |
588 AdlibDriver::snd_setSoundData (va_list & list) | |
589 { | |
590 if (_soundData) | |
591 { | |
592 delete[]_soundData; | |
530 _soundData = 0; | 593 _soundData = 0; |
531 } | 594 } |
532 _soundData = va_arg(list, uint8*); | 595 _soundData = va_arg (list, uint8 *); |
533 return 0; | 596 return 0; |
534 } | 597 } |
535 | 598 |
536 int AdlibDriver::snd_unkOpcode1(va_list &list) { | 599 int |
537 warning("unimplemented snd_unkOpcode1"); | 600 AdlibDriver::snd_unkOpcode1 (va_list & list) |
538 return 0; | 601 { |
539 } | 602 warning ("unimplemented snd_unkOpcode1"); |
540 | 603 return 0; |
541 int AdlibDriver::snd_startSong(va_list &list) { | 604 } |
542 int songId = va_arg(list, int); | 605 |
606 int | |
607 AdlibDriver::snd_startSong (va_list & list) | |
608 { | |
609 int songId = va_arg (list, int); | |
543 _flags |= 8; | 610 _flags |= 8; |
544 _flagTrigger = 1; | 611 _flagTrigger = 1; |
545 | 612 |
546 uint8 *ptr = getProgram(songId); | 613 uint8 *ptr = getProgram (songId); |
547 uint8 chan = *ptr; | 614 uint8 chan = *ptr; |
548 | 615 |
549 if ((songId << 1) != 0) { | 616 if ((songId << 1) != 0) |
550 if (chan == 9) { | 617 { |
618 if (chan == 9) | |
619 { | |
551 if (_flags & 2) | 620 if (_flags & 2) |
552 return 0; | 621 return 0; |
553 } else { | 622 } |
623 else | |
624 { | |
554 if (_flags & 1) | 625 if (_flags & 1) |
555 return 0; | 626 return 0; |
556 } | 627 } |
557 } | 628 } |
558 | 629 |
559 _soundIdTable[_soundsPlaying++] = songId; | 630 _soundIdTable[_soundsPlaying++] = songId; |
560 _soundsPlaying &= 0x0F; | 631 _soundsPlaying &= 0x0F; |
561 | 632 |
562 return 0; | 633 return 0; |
563 } | 634 } |
564 | 635 |
565 int AdlibDriver::snd_unkOpcode2(va_list &list) { | 636 int |
566 warning("unimplemented snd_unkOpcode2"); | 637 AdlibDriver::snd_unkOpcode2 (va_list & list) |
567 return 0; | 638 { |
568 } | 639 warning ("unimplemented snd_unkOpcode2"); |
569 | 640 return 0; |
570 int AdlibDriver::snd_unkOpcode3(va_list &list) { | 641 } |
571 int value = va_arg(list, int); | 642 |
643 int | |
644 AdlibDriver::snd_unkOpcode3 (va_list & list) | |
645 { | |
646 int value = va_arg (list, int); | |
572 int loop = value; | 647 int loop = value; |
573 if (value < 0) { | 648 if (value < 0) |
649 { | |
574 value = 0; | 650 value = 0; |
575 loop = 9; | 651 loop = 9; |
576 } | 652 } |
577 loop -= value; | 653 loop -= value; |
578 ++loop; | 654 ++loop; |
579 | 655 |
580 while (loop--) { | 656 while (loop--) |
657 { | |
581 _curChannel = value; | 658 _curChannel = value; |
582 Channel &channel = _channels[_curChannel]; | 659 Channel & channel = _channels[_curChannel]; |
583 channel.priority = 0; | 660 channel.priority = 0; |
584 channel.dataptr = 0; | 661 channel.dataptr = 0; |
585 if (value != 9) { | 662 if (value != 9) |
586 noteOff(channel); | 663 { |
664 noteOff (channel); | |
587 } | 665 } |
588 ++value; | 666 ++value; |
589 } | 667 } |
590 | 668 |
591 return 0; | 669 return 0; |
592 } | 670 } |
593 | 671 |
594 int AdlibDriver::snd_readByte(va_list &list) { | 672 int |
595 int a = va_arg(list, int); | 673 AdlibDriver::snd_readByte (va_list & list) |
596 int b = va_arg(list, int); | 674 { |
597 uint8 *ptr = getProgram(a) + b; | 675 int a = va_arg (list, int); |
676 int b = va_arg (list, int); | |
677 uint8 *ptr = getProgram (a) + b; | |
598 return *ptr; | 678 return *ptr; |
599 } | 679 } |
600 | 680 |
601 int AdlibDriver::snd_writeByte(va_list &list) { | 681 int |
602 int a = va_arg(list, int); | 682 AdlibDriver::snd_writeByte (va_list & list) |
603 int b = va_arg(list, int); | 683 { |
604 int c = va_arg(list, int); | 684 int a = va_arg (list, int); |
605 uint8 *ptr = getProgram(a) + b; | 685 int b = va_arg (list, int); |
686 int c = va_arg (list, int); | |
687 uint8 *ptr = getProgram (a) + b; | |
606 uint8 oldValue = *ptr; | 688 uint8 oldValue = *ptr; |
607 *ptr = (uint8)c; | 689 *ptr = (uint8) c; |
608 return oldValue; | 690 return oldValue; |
609 } | 691 } |
610 | 692 |
611 int AdlibDriver::snd_getSoundTrigger(va_list &list) { | 693 int |
694 AdlibDriver::snd_getSoundTrigger (va_list & list) | |
695 { | |
612 return _soundTrigger; | 696 return _soundTrigger; |
613 } | 697 } |
614 | 698 |
615 int AdlibDriver::snd_unkOpcode4(va_list &list) { | 699 int |
616 warning("unimplemented snd_unkOpcode4"); | 700 AdlibDriver::snd_unkOpcode4 (va_list & list) |
617 return 0; | 701 { |
618 } | 702 warning ("unimplemented snd_unkOpcode4"); |
619 | 703 return 0; |
620 int AdlibDriver::snd_dummy(va_list &list) { | 704 } |
621 return 0; | 705 |
622 } | 706 int |
623 | 707 AdlibDriver::snd_dummy (va_list & list) |
624 int AdlibDriver::snd_getNullvar4(va_list &list) { | 708 { |
625 warning("unimplemented snd_getNullvar4"); | 709 return 0; |
626 return 0; | 710 } |
627 } | 711 |
628 | 712 int |
629 int AdlibDriver::snd_setNullvar3(va_list &list) { | 713 AdlibDriver::snd_getNullvar4 (va_list & list) |
630 warning("unimplemented snd_setNullvar3"); | 714 { |
631 return 0; | 715 warning ("unimplemented snd_getNullvar4"); |
632 } | 716 return 0; |
633 | 717 } |
634 int AdlibDriver::snd_setFlag(va_list &list) { | 718 |
719 int | |
720 AdlibDriver::snd_setNullvar3 (va_list & list) | |
721 { | |
722 warning ("unimplemented snd_setNullvar3"); | |
723 return 0; | |
724 } | |
725 | |
726 int | |
727 AdlibDriver::snd_setFlag (va_list & list) | |
728 { | |
635 int oldFlags = _flags; | 729 int oldFlags = _flags; |
636 _flags |= va_arg(list, int); | 730 _flags |= va_arg (list, int); |
637 return oldFlags; | 731 return oldFlags; |
638 } | 732 } |
639 | 733 |
640 int AdlibDriver::snd_clearFlag(va_list &list) { | 734 int |
735 AdlibDriver::snd_clearFlag (va_list & list) | |
736 { | |
641 int oldFlags = _flags; | 737 int oldFlags = _flags; |
642 _flags &= ~(va_arg(list, int)); | 738 _flags &= ~(va_arg (list, int)); |
643 return oldFlags; | 739 return oldFlags; |
644 } | 740 } |
645 | 741 |
646 // timer callback | 742 // timer callback |
647 | 743 |
648 void AdlibDriver::callback() { | 744 void |
649 // lock(); | 745 AdlibDriver::callback () |
746 { | |
747 // lock(); | |
650 --_flagTrigger; | 748 --_flagTrigger; |
651 if (_flagTrigger < 0) | 749 if (_flagTrigger < 0) |
652 _flags &= ~8; | 750 _flags &= ~8; |
653 setupPrograms(); | 751 setupPrograms (); |
654 executePrograms(); | 752 executePrograms (); |
655 | 753 |
656 uint8 temp = _unkValue3; | 754 uint8 temp = _unkValue3; |
657 _unkValue3 += _tempo; | 755 _unkValue3 += _tempo; |
658 if (_unkValue3 < temp) { | 756 if (_unkValue3 < temp) |
659 if (!(--_unkValue2)) { | 757 { |
758 if (!(--_unkValue2)) | |
759 { | |
660 _unkValue2 = _unkValue1; | 760 _unkValue2 = _unkValue1; |
661 ++_unkValue4; | 761 ++_unkValue4; |
662 } | 762 } |
663 } | 763 } |
664 // unlock(); | 764 // unlock(); |
665 } | 765 } |
666 | 766 |
667 void AdlibDriver::setupPrograms() { | 767 void |
668 while (_lastProcessed != _soundsPlaying) { | 768 AdlibDriver::setupPrograms () |
669 uint8 *ptr = getProgram(_soundIdTable[_lastProcessed]); | 769 { |
770 while (_lastProcessed != _soundsPlaying) | |
771 { | |
772 uint8 *ptr = getProgram (_soundIdTable[_lastProcessed]); | |
670 uint8 chan = *ptr++; | 773 uint8 chan = *ptr++; |
671 uint8 priority = *ptr++; | 774 uint8 priority = *ptr++; |
672 | 775 |
673 // Only start this sound if its priority is higher than the one | 776 // Only start this sound if its priority is higher than the one |
674 // already playing. | 777 // already playing. |
675 | 778 |
676 Channel &channel = _channels[chan]; | 779 Channel & channel = _channels[chan]; |
677 | 780 |
678 if (priority >= channel.priority) { | 781 if (priority >= channel.priority) |
679 initChannel(channel); | 782 { |
783 initChannel (channel); | |
680 channel.priority = priority; | 784 channel.priority = priority; |
681 channel.dataptr = ptr; | 785 channel.dataptr = ptr; |
682 channel.tempo = 0xFF; | 786 channel.tempo = 0xFF; |
683 channel.position = 0xFF; | 787 channel.position = 0xFF; |
684 channel.duration = 1; | 788 channel.duration = 1; |
685 unkOutput2(chan); | 789 unkOutput2 (chan); |
686 } | 790 } |
687 | 791 |
688 ++_lastProcessed; | 792 ++_lastProcessed; |
689 _lastProcessed &= 0x0F; | 793 _lastProcessed &= 0x0F; |
690 } | 794 } |
722 // | 826 // |
723 // Finally, most of the times that the callback is called, it will invoke the | 827 // Finally, most of the times that the callback is called, it will invoke the |
724 // effects callbacks. The final opcode in a set can prevent this, if it's a | 828 // effects callbacks. The final opcode in a set can prevent this, if it's a |
725 // function and it returns anything other than 1. | 829 // function and it returns anything other than 1. |
726 | 830 |
727 void AdlibDriver::executePrograms() { | 831 void |
832 AdlibDriver::executePrograms () | |
833 { | |
728 // Each channel runs its own program. There are ten channels: One for | 834 // Each channel runs its own program. There are ten channels: One for |
729 // each Adlib channel (0-8), plus one "control channel" (9) which is | 835 // each Adlib channel (0-8), plus one "control channel" (9) which is |
730 // the one that tells the other channels what to do. | 836 // the one that tells the other channels what to do. |
731 | 837 |
732 for (_curChannel = 9; _curChannel >= 0; --_curChannel) { | 838 for (_curChannel = 9; _curChannel >= 0; --_curChannel) |
839 { | |
733 int result = 1; | 840 int result = 1; |
734 | 841 |
735 if (!_channels[_curChannel].dataptr) { | 842 if (!_channels[_curChannel].dataptr) |
843 { | |
736 continue; | 844 continue; |
737 } | 845 } |
738 | 846 |
739 Channel &channel = _channels[_curChannel]; | 847 Channel & channel = _channels[_curChannel]; |
740 _curRegOffset = _regOffset[_curChannel]; | 848 _curRegOffset = _regOffset[_curChannel]; |
741 | 849 |
742 if (channel.tempoReset) { | 850 if (channel.tempoReset) |
851 { | |
743 channel.tempo = _tempo; | 852 channel.tempo = _tempo; |
744 } | 853 } |
745 | 854 |
746 uint8 backup = channel.position; | 855 uint8 backup = channel.position; |
747 channel.position += channel.tempo; | 856 channel.position += channel.tempo; |
748 if (channel.position < backup) { | 857 if (channel.position < backup) |
749 if (--channel.duration) { | 858 { |
750 if (channel.duration == channel.spacing2) | 859 if (--channel.duration) |
751 noteOff(channel); | 860 { |
752 if (channel.duration == channel.spacing1 && _curChannel != 9) | 861 if (channel.duration == channel.spacing2) |
753 noteOff(channel); | 862 noteOff (channel); |
754 } else { | 863 if (channel.duration == channel.spacing1 && _curChannel != 9) |
755 // An opcode is not allowed to modify its own | 864 noteOff (channel); |
756 // data pointer except through the 'dataptr' | 865 } |
757 // parameter. To enforce that, we have to work | 866 else |
758 // on a copy of the data pointer. | 867 { |
759 // | 868 // An opcode is not allowed to modify its own |
760 // This fixes a subtle music bug where the | 869 // data pointer except through the 'dataptr' |
761 // wrong music would play when getting the | 870 // parameter. To enforce that, we have to work |
762 // quill in Kyra 1. | 871 // on a copy of the data pointer. |
763 uint8 *dataptr = channel.dataptr; | 872 // |
764 while (dataptr) { | 873 // This fixes a subtle music bug where the |
765 uint8 opcode = *dataptr++; | 874 // wrong music would play when getting the |
766 uint8 param = *dataptr++; | 875 // quill in Kyra 1. |
767 | 876 uint8 *dataptr = channel.dataptr; |
768 if (opcode & 0x80) { | 877 while (dataptr) |
769 opcode &= 0x7F; | 878 { |
770 if (opcode >= _parserOpcodeTableSize) | 879 uint8 opcode = *dataptr++; |
771 opcode = _parserOpcodeTableSize - 1; | 880 uint8 param = *dataptr++; |
772 debugC(9, kDebugLevelSound, "Calling opcode '%s' (%d) (channel: %d)", _parserOpcodeTable[opcode].name, opcode, _curChannel); | 881 |
773 result = (this->*(_parserOpcodeTable[opcode].function))(dataptr, channel, param); | 882 if (opcode & 0x80) |
774 channel.dataptr = dataptr; | 883 { |
775 if (result) | 884 opcode &= 0x7F; |
776 break; | 885 if (opcode >= _parserOpcodeTableSize) |
777 } else { | 886 opcode = _parserOpcodeTableSize - 1; |
778 debugC(9, kDebugLevelSound, "Note on opcode 0x%02X (duration: %d) (channel: %d)", opcode, param, _curChannel); | 887 debugC (9, kDebugLevelSound, |
779 setupNote(opcode, channel); | 888 "Calling opcode '%s' (%d) (channel: %d)", |
780 noteOn(channel); | 889 _parserOpcodeTable[opcode].name, opcode, _curChannel); |
781 setupDuration(param, channel); | 890 result = |
782 if (param) { | 891 (this->*(_parserOpcodeTable[opcode].function)) (dataptr, |
783 channel.dataptr = dataptr; | 892 channel, param); |
784 break; | 893 channel.dataptr = dataptr; |
785 } | 894 if (result) |
786 } | 895 break; |
787 } | 896 } |
897 else | |
898 { | |
899 debugC (9, kDebugLevelSound, | |
900 "Note on opcode 0x%02X (duration: %d) (channel: %d)", | |
901 opcode, param, _curChannel); | |
902 setupNote (opcode, channel); | |
903 noteOn (channel); | |
904 setupDuration (param, channel); | |
905 if (param) | |
906 { | |
907 channel.dataptr = dataptr; | |
908 break; | |
909 } | |
910 } | |
911 } | |
788 } | 912 } |
789 } | 913 } |
790 | 914 |
791 if (result == 1) { | 915 if (result == 1) |
916 { | |
792 if (channel.primaryEffect) | 917 if (channel.primaryEffect) |
793 (this->*(channel.primaryEffect))(channel); | 918 (this->*(channel.primaryEffect)) (channel); |
794 if (channel.secondaryEffect) | 919 if (channel.secondaryEffect) |
795 (this->*(channel.secondaryEffect))(channel); | 920 (this->*(channel.secondaryEffect)) (channel); |
796 } | 921 } |
797 } | 922 } |
798 } | 923 } |
799 | 924 |
800 // | 925 // |
801 | 926 |
802 void AdlibDriver::resetAdlibState() { | 927 void |
803 debugC(9, kDebugLevelSound, "resetAdlibState()"); | 928 AdlibDriver::resetAdlibState () |
929 { | |
930 debugC (9, kDebugLevelSound, "resetAdlibState()"); | |
804 _rnd = 0x1234; | 931 _rnd = 0x1234; |
805 | 932 |
806 // Authorize the control of the waveforms | 933 // Authorize the control of the waveforms |
807 writeOPL(0x01, 0x20); | 934 writeOPL (0x01, 0x20); |
808 | 935 |
809 // Select FM music mode | 936 // Select FM music mode |
810 writeOPL(0x08, 0x00); | 937 writeOPL (0x08, 0x00); |
811 | 938 |
812 // I would guess the main purpose of this is to turn off the rhythm, | 939 // I would guess the main purpose of this is to turn off the rhythm, |
813 // thus allowing us to use 9 melodic voices instead of 6. | 940 // thus allowing us to use 9 melodic voices instead of 6. |
814 writeOPL(0xBD, 0x00); | 941 writeOPL (0xBD, 0x00); |
815 | 942 |
816 int loop = 10; | 943 int loop = 10; |
817 while (loop--) { | 944 while (loop--) |
818 if (loop != 9) { | 945 { |
946 if (loop != 9) | |
947 { | |
819 // Silence the channel | 948 // Silence the channel |
820 writeOPL(0x40 + _regOffset[loop], 0x3F); | 949 writeOPL (0x40 + _regOffset[loop], 0x3F); |
821 writeOPL(0x43 + _regOffset[loop], 0x3F); | 950 writeOPL (0x43 + _regOffset[loop], 0x3F); |
822 } | 951 } |
823 initChannel(_channels[loop]); | 952 initChannel (_channels[loop]); |
824 } | 953 } |
825 } | 954 } |
826 | 955 |
827 // Old calling style: output0x388(0xABCD) | 956 // Old calling style: output0x388(0xABCD) |
828 // New calling style: writeOPL(0xAB, 0xCD) | 957 // New calling style: writeOPL(0xAB, 0xCD) |
829 | 958 |
830 void AdlibDriver::writeOPL(byte reg, byte val) { | 959 void |
831 opl->write(reg, val); | 960 AdlibDriver::writeOPL (byte reg, byte val) |
832 } | 961 { |
833 | 962 opl->write (reg, val); |
834 void AdlibDriver::initChannel(Channel &channel) { | 963 } |
835 debugC(9, kDebugLevelSound, "initChannel(%lu)", (long)(&channel - _channels)); | 964 |
836 memset(&channel.dataptr, 0, sizeof(Channel) - ((char*)&channel.dataptr - (char*)&channel)); | 965 void |
966 AdlibDriver::initChannel (Channel & channel) | |
967 { | |
968 debugC (9, kDebugLevelSound, "initChannel(%lu)", | |
969 (long) (&channel - _channels)); | |
970 memset (&channel.dataptr, 0, | |
971 sizeof (Channel) - ((char *) &channel.dataptr - (char *) &channel)); | |
837 | 972 |
838 channel.tempo = 0xFF; | 973 channel.tempo = 0xFF; |
839 channel.priority = 0; | 974 channel.priority = 0; |
840 // normally here are nullfuncs but we set 0 for now | 975 // normally here are nullfuncs but we set 0 for now |
841 channel.primaryEffect = 0; | 976 channel.primaryEffect = 0; |
842 channel.secondaryEffect = 0; | 977 channel.secondaryEffect = 0; |
843 channel.spacing1 = 1; | 978 channel.spacing1 = 1; |
844 } | 979 } |
845 | 980 |
846 void AdlibDriver::noteOff(Channel &channel) { | 981 void |
847 debugC(9, kDebugLevelSound, "noteOff(%lu)", (long)(&channel - _channels)); | 982 AdlibDriver::noteOff (Channel & channel) |
983 { | |
984 debugC (9, kDebugLevelSound, "noteOff(%lu)", (long) (&channel - _channels)); | |
848 | 985 |
849 // The control channel has no corresponding Adlib channel | 986 // The control channel has no corresponding Adlib channel |
850 | 987 |
851 if (_curChannel >= 9) | 988 if (_curChannel >= 9) |
852 return; | 989 return; |
858 | 995 |
859 // This means the "Key On" bit will always be 0 | 996 // This means the "Key On" bit will always be 0 |
860 channel.regBx &= 0xDF; | 997 channel.regBx &= 0xDF; |
861 | 998 |
862 // Octave / F-Number / Key-On | 999 // Octave / F-Number / Key-On |
863 writeOPL(0xB0 + _curChannel, channel.regBx); | 1000 writeOPL (0xB0 + _curChannel, channel.regBx); |
864 } | 1001 } |
865 | 1002 |
866 void AdlibDriver::unkOutput2(uint8 chan) { | 1003 void |
867 debugC(9, kDebugLevelSound, "unkOutput2(%d)", chan); | 1004 AdlibDriver::unkOutput2 (uint8 chan) |
1005 { | |
1006 debugC (9, kDebugLevelSound, "unkOutput2(%d)", chan); | |
868 | 1007 |
869 // The control channel has no corresponding Adlib channel | 1008 // The control channel has no corresponding Adlib channel |
870 | 1009 |
871 if (chan >= 9) | 1010 if (chan >= 9) |
872 return; | 1011 return; |
880 uint8 offset = _regOffset[chan]; | 1019 uint8 offset = _regOffset[chan]; |
881 | 1020 |
882 // The channel is cleared: First the attack/delay rate, then the | 1021 // The channel is cleared: First the attack/delay rate, then the |
883 // sustain level/release rate, and finally the note is turned off. | 1022 // sustain level/release rate, and finally the note is turned off. |
884 | 1023 |
885 writeOPL(0x60 + offset, 0xFF); | 1024 writeOPL (0x60 + offset, 0xFF); |
886 writeOPL(0x63 + offset, 0xFF); | 1025 writeOPL (0x63 + offset, 0xFF); |
887 | 1026 |
888 writeOPL(0x80 + offset, 0xFF); | 1027 writeOPL (0x80 + offset, 0xFF); |
889 writeOPL(0x83 + offset, 0xFF); | 1028 writeOPL (0x83 + offset, 0xFF); |
890 | 1029 |
891 writeOPL(0xB0 + chan, 0x00); | 1030 writeOPL (0xB0 + chan, 0x00); |
892 | 1031 |
893 // ...and then the note is turned on again, with whatever value is | 1032 // ...and then the note is turned on again, with whatever value is |
894 // still lurking in the A0 + chan register, but everything else - | 1033 // still lurking in the A0 + chan register, but everything else - |
895 // including the two most significant frequency bit, and the octave - | 1034 // including the two most significant frequency bit, and the octave - |
896 // set to zero. | 1035 // set to zero. |
905 // | 1044 // |
906 // Ken Silverman's Adlib emulator (which can be found on his Web page - | 1045 // Ken Silverman's Adlib emulator (which can be found on his Web page - |
907 // http://www.advsys.net/ken - and as part of AdPlug) also seems to be | 1046 // http://www.advsys.net/ken - and as part of AdPlug) also seems to be |
908 // immune, but is apparently not as feature complete as MAME's. | 1047 // immune, but is apparently not as feature complete as MAME's. |
909 | 1048 |
910 writeOPL(0xB0 + chan, 0x20); | 1049 writeOPL (0xB0 + chan, 0x20); |
911 } | 1050 } |
912 | 1051 |
913 // I believe this is a random number generator. It actually does seem to | 1052 // I believe this is a random number generator. It actually does seem to |
914 // generate an even distribution of almost all numbers from 0 through 65535, | 1053 // generate an even distribution of almost all numbers from 0 through 65535, |
915 // though in my tests some numbers were never generated. | 1054 // though in my tests some numbers were never generated. |
916 | 1055 |
917 uint16 AdlibDriver::getRandomNr() { | 1056 uint16 |
1057 AdlibDriver::getRandomNr () | |
1058 { | |
918 _rnd += 0x9248; | 1059 _rnd += 0x9248; |
919 uint16 lowBits = _rnd & 7; | 1060 uint16 lowBits = _rnd & 7; |
920 _rnd >>= 3; | 1061 _rnd >>= 3; |
921 _rnd |= (lowBits << 13); | 1062 _rnd |= (lowBits << 13); |
922 return _rnd; | 1063 return _rnd; |
923 } | 1064 } |
924 | 1065 |
925 void AdlibDriver::setupDuration(uint8 duration, Channel &channel) { | 1066 void |
926 debugC(9, kDebugLevelSound, "setupDuration(%d, %lu)", duration, (long)(&channel - _channels)); | 1067 AdlibDriver::setupDuration (uint8 duration, Channel & channel) |
927 if (channel.durationRandomness) { | 1068 { |
928 channel.duration = duration + (getRandomNr() & channel.durationRandomness); | 1069 debugC (9, kDebugLevelSound, "setupDuration(%d, %lu)", duration, |
1070 (long) (&channel - _channels)); | |
1071 if (channel.durationRandomness) | |
1072 { | |
1073 channel.duration = | |
1074 duration + (getRandomNr () & channel.durationRandomness); | |
929 return; | 1075 return; |
930 } | 1076 } |
931 if (channel.fractionalSpacing) { | 1077 if (channel.fractionalSpacing) |
1078 { | |
932 channel.spacing2 = (duration >> 3) * channel.fractionalSpacing; | 1079 channel.spacing2 = (duration >> 3) * channel.fractionalSpacing; |
933 } | 1080 } |
934 channel.duration = duration; | 1081 channel.duration = duration; |
935 } | 1082 } |
936 | 1083 |
937 // This function may or may not play the note. It's usually followed by a call | 1084 // This function may or may not play the note. It's usually followed by a call |
938 // to noteOn(), which will always play the current note. | 1085 // to noteOn(), which will always play the current note. |
939 | 1086 |
940 void AdlibDriver::setupNote(uint8 rawNote, Channel &channel, bool flag) { | 1087 void |
941 debugC(9, kDebugLevelSound, "setupNote(%d, %lu)", rawNote, (long)(&channel - _channels)); | 1088 AdlibDriver::setupNote (uint8 rawNote, Channel & channel, bool flag) |
1089 { | |
1090 debugC (9, kDebugLevelSound, "setupNote(%d, %lu)", rawNote, | |
1091 (long) (&channel - _channels)); | |
942 | 1092 |
943 channel.rawNote = rawNote; | 1093 channel.rawNote = rawNote; |
944 | 1094 |
945 int8 note = (rawNote & 0x0F) + channel.baseNote; | 1095 int8 note = (rawNote & 0x0F) + channel.baseNote; |
946 int8 octave = ((rawNote + channel.baseOctave) >> 4) & 0x0F; | 1096 int8 octave = ((rawNote + channel.baseOctave) >> 4) & 0x0F; |
947 | 1097 |
948 // There are only twelve notes. If we go outside that, we have to | 1098 // There are only twelve notes. If we go outside that, we have to |
949 // adjust the note and octave. | 1099 // adjust the note and octave. |
950 | 1100 |
951 if (note >= 12) { | 1101 if (note >= 12) |
1102 { | |
952 note -= 12; | 1103 note -= 12; |
953 octave++; | 1104 octave++; |
954 } else if (note < 0) { | 1105 } |
1106 else if (note < 0) | |
1107 { | |
955 note += 12; | 1108 note += 12; |
956 octave--; | 1109 octave--; |
957 } | 1110 } |
958 | 1111 |
959 // The calculation of frequency looks quite different from the original | 1112 // The calculation of frequency looks quite different from the original |
969 uint16 freq = _unkTable[note] + channel.baseFreq; | 1122 uint16 freq = _unkTable[note] + channel.baseFreq; |
970 | 1123 |
971 // When called from callback 41, the behaviour is slightly different: | 1124 // When called from callback 41, the behaviour is slightly different: |
972 // We adjust the frequency, even when channel.unk16 is 0. | 1125 // We adjust the frequency, even when channel.unk16 is 0. |
973 | 1126 |
974 if (channel.unk16 || flag) { | 1127 if (channel.unk16 || flag) |
1128 { | |
975 const uint8 *table; | 1129 const uint8 *table; |
976 | 1130 |
977 if (channel.unk16 >= 0) { | 1131 if (channel.unk16 >= 0) |
1132 { | |
978 table = _unkTables[(channel.rawNote & 0x0F) + 2]; | 1133 table = _unkTables[(channel.rawNote & 0x0F) + 2]; |
979 freq += table[channel.unk16]; | 1134 freq += table[channel.unk16]; |
980 } else { | 1135 } |
1136 else | |
1137 { | |
981 table = _unkTables[channel.rawNote & 0x0F]; | 1138 table = _unkTables[channel.rawNote & 0x0F]; |
982 freq -= table[-channel.unk16]; | 1139 freq -= table[-channel.unk16]; |
983 } | 1140 } |
984 } | 1141 } |
985 | 1142 |
986 channel.regAx = freq & 0xFF; | 1143 channel.regAx = freq & 0xFF; |
987 channel.regBx = (channel.regBx & 0x20) | (octave << 2) | ((freq >> 8) & 0x03); | 1144 channel.regBx = |
1145 (channel.regBx & 0x20) | (octave << 2) | ((freq >> 8) & 0x03); | |
988 | 1146 |
989 // Keep the note on or off | 1147 // Keep the note on or off |
990 writeOPL(0xA0 + _curChannel, channel.regAx); | 1148 writeOPL (0xA0 + _curChannel, channel.regAx); |
991 writeOPL(0xB0 + _curChannel, channel.regBx); | 1149 writeOPL (0xB0 + _curChannel, channel.regBx); |
992 } | 1150 } |
993 | 1151 |
994 void AdlibDriver::setupInstrument(uint8 regOffset, uint8 *dataptr, Channel &channel) { | 1152 void |
995 debugC(9, kDebugLevelSound, "setupInstrument(%d, %p, %lu)", regOffset, (const void *)dataptr, (long)(&channel - _channels)); | 1153 AdlibDriver::setupInstrument (uint8 regOffset, uint8 * dataptr, |
1154 Channel & channel) | |
1155 { | |
1156 debugC (9, kDebugLevelSound, "setupInstrument(%d, %p, %lu)", regOffset, | |
1157 (const void *) dataptr, (long) (&channel - _channels)); | |
996 // Amplitude Modulation / Vibrato / Envelope Generator Type / | 1158 // Amplitude Modulation / Vibrato / Envelope Generator Type / |
997 // Keyboard Scaling Rate / Modulator Frequency Multiple | 1159 // Keyboard Scaling Rate / Modulator Frequency Multiple |
998 writeOPL(0x20 + regOffset, *dataptr++); | 1160 writeOPL (0x20 + regOffset, *dataptr++); |
999 writeOPL(0x23 + regOffset, *dataptr++); | 1161 writeOPL (0x23 + regOffset, *dataptr++); |
1000 | 1162 |
1001 uint8 temp = *dataptr++; | 1163 uint8 temp = *dataptr++; |
1002 | 1164 |
1003 // Feedback / Algorithm | 1165 // Feedback / Algorithm |
1004 | 1166 |
1005 // It is very likely that _curChannel really does refer to the same | 1167 // It is very likely that _curChannel really does refer to the same |
1006 // channel as regOffset, but there's only one Cx register per channel. | 1168 // channel as regOffset, but there's only one Cx register per channel. |
1007 | 1169 |
1008 writeOPL(0xC0 + _curChannel, temp); | 1170 writeOPL (0xC0 + _curChannel, temp); |
1009 | 1171 |
1010 // The algorithm bit. I don't pretend to understand this fully, but | 1172 // The algorithm bit. I don't pretend to understand this fully, but |
1011 // "If set to 0, operator 1 modulates operator 2. In this case, | 1173 // "If set to 0, operator 1 modulates operator 2. In this case, |
1012 // operator 2 is the only one producing sound. If set to 1, both | 1174 // operator 2 is the only one producing sound. If set to 1, both |
1013 // operators produce sound directly. Complex sounds are more easily | 1175 // operators produce sound directly. Complex sounds are more easily |
1014 // created if the algorithm is set to 0." | 1176 // created if the algorithm is set to 0." |
1015 | 1177 |
1016 channel.twoChan = temp & 1; | 1178 channel.twoChan = temp & 1; |
1017 | 1179 |
1018 // Waveform Select | 1180 // Waveform Select |
1019 writeOPL(0xE0 + regOffset, *dataptr++); | 1181 writeOPL (0xE0 + regOffset, *dataptr++); |
1020 writeOPL(0xE3 + regOffset, *dataptr++); | 1182 writeOPL (0xE3 + regOffset, *dataptr++); |
1021 | 1183 |
1022 channel.opLevel1 = *dataptr++; | 1184 channel.opLevel1 = *dataptr++; |
1023 channel.opLevel2 = *dataptr++; | 1185 channel.opLevel2 = *dataptr++; |
1024 | 1186 |
1025 // Level Key Scaling / Total Level | 1187 // Level Key Scaling / Total Level |
1026 writeOPL(0x40 + regOffset, calculateOpLevel1(channel)); | 1188 writeOPL (0x40 + regOffset, calculateOpLevel1 (channel)); |
1027 writeOPL(0x43 + regOffset, calculateOpLevel2(channel)); | 1189 writeOPL (0x43 + regOffset, calculateOpLevel2 (channel)); |
1028 | 1190 |
1029 // Attack Rate / Decay Rate | 1191 // Attack Rate / Decay Rate |
1030 writeOPL(0x60 + regOffset, *dataptr++); | 1192 writeOPL (0x60 + regOffset, *dataptr++); |
1031 writeOPL(0x63 + regOffset, *dataptr++); | 1193 writeOPL (0x63 + regOffset, *dataptr++); |
1032 | 1194 |
1033 // Sustain Level / Release Rate | 1195 // Sustain Level / Release Rate |
1034 writeOPL(0x80 + regOffset, *dataptr++); | 1196 writeOPL (0x80 + regOffset, *dataptr++); |
1035 writeOPL(0x83 + regOffset, *dataptr++); | 1197 writeOPL (0x83 + regOffset, *dataptr++); |
1036 } | 1198 } |
1037 | 1199 |
1038 // Apart from playing the note, this function also updates the variables for | 1200 // Apart from playing the note, this function also updates the variables for |
1039 // primary effect 2. | 1201 // primary effect 2. |
1040 | 1202 |
1041 void AdlibDriver::noteOn(Channel &channel) { | 1203 void |
1042 debugC(9, kDebugLevelSound, "noteOn(%lu)", (long)(&channel - _channels)); | 1204 AdlibDriver::noteOn (Channel & channel) |
1205 { | |
1206 debugC (9, kDebugLevelSound, "noteOn(%lu)", (long) (&channel - _channels)); | |
1043 | 1207 |
1044 // The "note on" bit is set, and the current note is played. | 1208 // The "note on" bit is set, and the current note is played. |
1045 | 1209 |
1046 channel.regBx |= 0x20; | 1210 channel.regBx |= 0x20; |
1047 writeOPL(0xB0 + _curChannel, channel.regBx); | 1211 writeOPL (0xB0 + _curChannel, channel.regBx); |
1048 | 1212 |
1049 int8 shift = 9 - channel.unk33; | 1213 int8 shift = 9 - channel.unk33; |
1050 uint16 temp = channel.regAx | (channel.regBx << 8); | 1214 uint16 temp = channel.regAx | (channel.regBx << 8); |
1051 channel.unk37 = ((temp & 0x3FF) >> shift) & 0xFF; | 1215 channel.unk37 = ((temp & 0x3FF) >> shift) & 0xFF; |
1052 channel.unk38 = channel.unk36; | 1216 channel.unk38 = channel.unk36; |
1053 } | 1217 } |
1054 | 1218 |
1055 void AdlibDriver::adjustVolume(Channel &channel) { | 1219 void |
1056 debugC(9, kDebugLevelSound, "adjustVolume(%lu)", (long)(&channel - _channels)); | 1220 AdlibDriver::adjustVolume (Channel & channel) |
1221 { | |
1222 debugC (9, kDebugLevelSound, "adjustVolume(%lu)", | |
1223 (long) (&channel - _channels)); | |
1057 // Level Key Scaling / Total Level | 1224 // Level Key Scaling / Total Level |
1058 | 1225 |
1059 writeOPL(0x43 + _regOffset[_curChannel], calculateOpLevel2(channel)); | 1226 writeOPL (0x43 + _regOffset[_curChannel], calculateOpLevel2 (channel)); |
1060 if (channel.twoChan) | 1227 if (channel.twoChan) |
1061 writeOPL(0x40 + _regOffset[_curChannel], calculateOpLevel1(channel)); | 1228 writeOPL (0x40 + _regOffset[_curChannel], calculateOpLevel1 (channel)); |
1062 } | 1229 } |
1063 | 1230 |
1064 // This is presumably only used for some sound effects, e.g. Malcolm blowing up | 1231 // This is presumably only used for some sound effects, e.g. Malcolm blowing up |
1065 // the trees in the intro (but not the effect where he "booby-traps" the big | 1232 // the trees in the intro (but not the effect where he "booby-traps" the big |
1066 // tree) and turning Kallak to stone. Related functions and variables: | 1233 // tree) and turning Kallak to stone. Related functions and variables: |
1075 // | 1242 // |
1076 // unk29 - determines how often the notes are played | 1243 // unk29 - determines how often the notes are played |
1077 // unk30 - modifies the frequency | 1244 // unk30 - modifies the frequency |
1078 // unk31 - determines how often the notes are played | 1245 // unk31 - determines how often the notes are played |
1079 | 1246 |
1080 void AdlibDriver::primaryEffect1(Channel &channel) { | 1247 void |
1081 debugC(9, kDebugLevelSound, "Calling primaryEffect1 (channel: %d)", _curChannel); | 1248 AdlibDriver::primaryEffect1 (Channel & channel) |
1249 { | |
1250 debugC (9, kDebugLevelSound, "Calling primaryEffect1 (channel: %d)", | |
1251 _curChannel); | |
1082 uint8 temp = channel.unk31; | 1252 uint8 temp = channel.unk31; |
1083 channel.unk31 += channel.unk29; | 1253 channel.unk31 += channel.unk29; |
1084 if (channel.unk31 >= temp) | 1254 if (channel.unk31 >= temp) |
1085 return; | 1255 return; |
1086 | 1256 |
1089 | 1259 |
1090 // This is presumably to shift the "note on" bit so far to the left | 1260 // This is presumably to shift the "note on" bit so far to the left |
1091 // that it won't be affected by any of the calculations below. | 1261 // that it won't be affected by any of the calculations below. |
1092 uint16 unk2 = ((channel.regBx & 0x20) << 8) | (channel.regBx & 0x1C); | 1262 uint16 unk2 = ((channel.regBx & 0x20) << 8) | (channel.regBx & 0x1C); |
1093 | 1263 |
1094 int16 unk3 = (int16)channel.unk30; | 1264 int16 unk3 = (int16) channel.unk30; |
1095 | 1265 |
1096 if (unk3 >= 0) { | 1266 if (unk3 >= 0) |
1267 { | |
1097 unk1 += unk3; | 1268 unk1 += unk3; |
1098 if (unk1 >= 734) { | 1269 if (unk1 >= 734) |
1270 { | |
1099 // The new frequency is too high. Shift it down and go | 1271 // The new frequency is too high. Shift it down and go |
1100 // up one octave. | 1272 // up one octave. |
1101 unk1 >>= 1; | 1273 unk1 >>= 1; |
1102 if (!(unk1 & 0x3FF)) | 1274 if (!(unk1 & 0x3FF)) |
1103 ++unk1; | 1275 ++unk1; |
1104 unk2 = (unk2 & 0xFF00) | ((unk2 + 4) & 0xFF); | 1276 unk2 = (unk2 & 0xFF00) | ((unk2 + 4) & 0xFF); |
1105 unk2 &= 0xFF1C; | 1277 unk2 &= 0xFF1C; |
1106 } | 1278 } |
1107 } else { | 1279 } |
1280 else | |
1281 { | |
1108 unk1 += unk3; | 1282 unk1 += unk3; |
1109 if (unk1 < 388) { | 1283 if (unk1 < 388) |
1284 { | |
1110 // The new frequency is too low. Shift it up and go | 1285 // The new frequency is too low. Shift it up and go |
1111 // down one octave. | 1286 // down one octave. |
1112 unk1 <<= 1; | 1287 unk1 <<= 1; |
1113 if (!(unk1 & 0x3FF)) | 1288 if (!(unk1 & 0x3FF)) |
1114 --unk1; | 1289 --unk1; |
1115 unk2 = (unk2 & 0xFF00) | ((unk2 - 4) & 0xFF); | 1290 unk2 = (unk2 & 0xFF00) | ((unk2 - 4) & 0xFF); |
1116 unk2 &= 0xFF1C; | 1291 unk2 &= 0xFF1C; |
1117 } | 1292 } |
1118 } | 1293 } |
1119 | 1294 |
1120 // Make sure that the new frequency is still a 10-bit value. | 1295 // Make sure that the new frequency is still a 10-bit value. |
1121 unk1 &= 0x3FF; | 1296 unk1 &= 0x3FF; |
1122 | 1297 |
1123 writeOPL(0xA0 + _curChannel, unk1 & 0xFF); | 1298 writeOPL (0xA0 + _curChannel, unk1 & 0xFF); |
1124 channel.regAx = unk1 & 0xFF; | 1299 channel.regAx = unk1 & 0xFF; |
1125 | 1300 |
1126 // Shift down the "note on" bit again. | 1301 // Shift down the "note on" bit again. |
1127 uint8 value = unk1 >> 8; | 1302 uint8 value = unk1 >> 8; |
1128 value |= (unk2 >> 8) & 0xFF; | 1303 value |= (unk2 >> 8) & 0xFF; |
1129 value |= unk2 & 0xFF; | 1304 value |= unk2 & 0xFF; |
1130 | 1305 |
1131 writeOPL(0xB0 + _curChannel, value); | 1306 writeOPL (0xB0 + _curChannel, value); |
1132 channel.regBx = value; | 1307 channel.regBx = value; |
1133 } | 1308 } |
1134 | 1309 |
1135 // This is presumably only used for some sound effects, e.g. Malcolm entering | 1310 // This is presumably only used for some sound effects, e.g. Malcolm entering |
1136 // and leaving Kallak's hut. Related functions and variables: | 1311 // and leaving Kallak's hut. Related functions and variables: |
1158 // unk41 - determines how often the notes are played | 1333 // unk41 - determines how often the notes are played |
1159 // | 1334 // |
1160 // Note that unk41 is never initialised. Not that it should matter much, but it | 1335 // Note that unk41 is never initialised. Not that it should matter much, but it |
1161 // is a bit sloppy. | 1336 // is a bit sloppy. |
1162 | 1337 |
1163 void AdlibDriver::primaryEffect2(Channel &channel) { | 1338 void |
1164 debugC(9, kDebugLevelSound, "Calling primaryEffect2 (channel: %d)", _curChannel); | 1339 AdlibDriver::primaryEffect2 (Channel & channel) |
1165 if (channel.unk38) { | 1340 { |
1341 debugC (9, kDebugLevelSound, "Calling primaryEffect2 (channel: %d)", | |
1342 _curChannel); | |
1343 if (channel.unk38) | |
1344 { | |
1166 --channel.unk38; | 1345 --channel.unk38; |
1167 return; | 1346 return; |
1168 } | 1347 } |
1169 | 1348 |
1170 uint8 temp = channel.unk41; | 1349 uint8 temp = channel.unk41; |
1171 channel.unk41 += channel.unk32; | 1350 channel.unk41 += channel.unk32; |
1172 if (channel.unk41 < temp) { | 1351 if (channel.unk41 < temp) |
1352 { | |
1173 uint16 unk1 = channel.unk37; | 1353 uint16 unk1 = channel.unk37; |
1174 if (!(--channel.unk34)) { | 1354 if (!(--channel.unk34)) |
1355 { | |
1175 unk1 ^= 0xFFFF; | 1356 unk1 ^= 0xFFFF; |
1176 ++unk1; | 1357 ++unk1; |
1177 channel.unk37 = unk1; | 1358 channel.unk37 = unk1; |
1178 channel.unk34 = channel.unk35; | 1359 channel.unk34 = channel.unk35; |
1179 } | 1360 } |
1180 | 1361 |
1181 uint16 unk2 = (channel.regAx | (channel.regBx << 8)) & 0x3FF; | 1362 uint16 unk2 = (channel.regAx | (channel.regBx << 8)) & 0x3FF; |
1182 unk2 += unk1; | 1363 unk2 += unk1; |
1183 | 1364 |
1184 channel.regAx = unk2 & 0xFF; | 1365 channel.regAx = unk2 & 0xFF; |
1185 channel.regBx = (channel.regBx & 0xFC) | (unk2 >> 8); | 1366 channel.regBx = (channel.regBx & 0xFC) | (unk2 >> 8); |
1186 | 1367 |
1187 // Octave / F-Number / Key-On | 1368 // Octave / F-Number / Key-On |
1188 writeOPL(0xA0 + _curChannel, channel.regAx); | 1369 writeOPL (0xA0 + _curChannel, channel.regAx); |
1189 writeOPL(0xB0 + _curChannel, channel.regBx); | 1370 writeOPL (0xB0 + _curChannel, channel.regBx); |
1190 } | 1371 } |
1191 } | 1372 } |
1192 | 1373 |
1193 // I don't know where this is used. The same operation is performed several | 1374 // I don't know where this is used. The same operation is performed several |
1194 // times on the current channel, using a chunk of the _soundData[] buffer for | 1375 // times on the current channel, using a chunk of the _soundData[] buffer for |
1213 // unk20 - the start index into the data chunk | 1394 // unk20 - the start index into the data chunk |
1214 // unk21 - the current index into the data chunk | 1395 // unk21 - the current index into the data chunk |
1215 // unk22 - the operation to perform | 1396 // unk22 - the operation to perform |
1216 // offset - the offset to the data chunk | 1397 // offset - the offset to the data chunk |
1217 | 1398 |
1218 void AdlibDriver::secondaryEffect1(Channel &channel) { | 1399 void |
1219 debugC(9, kDebugLevelSound, "Calling secondaryEffect1 (channel: %d)", _curChannel); | 1400 AdlibDriver::secondaryEffect1 (Channel & channel) |
1401 { | |
1402 debugC (9, kDebugLevelSound, "Calling secondaryEffect1 (channel: %d)", | |
1403 _curChannel); | |
1220 uint8 temp = channel.unk18; | 1404 uint8 temp = channel.unk18; |
1221 channel.unk18 += channel.unk19; | 1405 channel.unk18 += channel.unk19; |
1222 if (channel.unk18 < temp) { | 1406 if (channel.unk18 < temp) |
1223 if (--channel.unk21 < 0) { | 1407 { |
1408 if (--channel.unk21 < 0) | |
1409 { | |
1224 channel.unk21 = channel.unk20; | 1410 channel.unk21 = channel.unk20; |
1225 } | 1411 } |
1226 writeOPL(channel.unk22 + _curRegOffset, _soundData[channel.offset + channel.unk21]); | 1412 writeOPL (channel.unk22 + _curRegOffset, |
1227 } | 1413 _soundData[channel.offset + channel.unk21]); |
1228 } | 1414 } |
1229 | 1415 } |
1230 uint8 AdlibDriver::calculateOpLevel1(Channel &channel) { | 1416 |
1417 uint8 | |
1418 AdlibDriver::calculateOpLevel1 (Channel & channel) | |
1419 { | |
1231 int8 value = channel.opLevel1 & 0x3F; | 1420 int8 value = channel.opLevel1 & 0x3F; |
1232 | 1421 |
1233 if (channel.twoChan) { | 1422 if (channel.twoChan) |
1423 { | |
1234 value += channel.opExtraLevel1; | 1424 value += channel.opExtraLevel1; |
1235 value += channel.opExtraLevel2; | 1425 value += channel.opExtraLevel2; |
1236 value += channel.opExtraLevel3; | 1426 value += channel.opExtraLevel3; |
1237 } | 1427 } |
1238 | 1428 |
1239 // Preserve the scaling level bits from opLevel1 | 1429 // Preserve the scaling level bits from opLevel1 |
1240 | 1430 |
1241 return checkValue(value) | (channel.opLevel1 & 0xC0); | 1431 return checkValue (value) | (channel.opLevel1 & 0xC0); |
1242 } | 1432 } |
1243 | 1433 |
1244 uint8 AdlibDriver::calculateOpLevel2(Channel &channel) { | 1434 uint8 |
1435 AdlibDriver::calculateOpLevel2 (Channel & channel) | |
1436 { | |
1245 int8 value = channel.opLevel2 & 0x3F; | 1437 int8 value = channel.opLevel2 & 0x3F; |
1246 | 1438 |
1247 value += channel.opExtraLevel1; | 1439 value += channel.opExtraLevel1; |
1248 value += channel.opExtraLevel2; | 1440 value += channel.opExtraLevel2; |
1249 value += channel.opExtraLevel3; | 1441 value += channel.opExtraLevel3; |
1250 | 1442 |
1251 // Preserve the scaling level bits from opLevel2 | 1443 // Preserve the scaling level bits from opLevel2 |
1252 | 1444 |
1253 return checkValue(value) | (channel.opLevel2 & 0xC0); | 1445 return checkValue (value) | (channel.opLevel2 & 0xC0); |
1254 } | 1446 } |
1255 | 1447 |
1256 // parser opcodes | 1448 // parser opcodes |
1257 | 1449 |
1258 int AdlibDriver::update_setRepeat(uint8 *&dataptr, Channel &channel, uint8 value) { | 1450 int |
1451 AdlibDriver::update_setRepeat (uint8 * &dataptr, Channel & channel, | |
1452 uint8 value) | |
1453 { | |
1259 channel.repeatCounter = value; | 1454 channel.repeatCounter = value; |
1260 return 0; | 1455 return 0; |
1261 } | 1456 } |
1262 | 1457 |
1263 int AdlibDriver::update_checkRepeat(uint8 *&dataptr, Channel &channel, uint8 value) { | 1458 int |
1459 AdlibDriver::update_checkRepeat (uint8 * &dataptr, Channel & channel, | |
1460 uint8 value) | |
1461 { | |
1264 ++dataptr; | 1462 ++dataptr; |
1265 if (--channel.repeatCounter) { | 1463 if (--channel.repeatCounter) |
1266 int16 add = READ_LE_UINT16(dataptr - 2); | 1464 { |
1465 int16 add = READ_LE_UINT16 (dataptr - 2); | |
1267 dataptr += add; | 1466 dataptr += add; |
1268 } | 1467 } |
1269 return 0; | 1468 return 0; |
1270 } | 1469 } |
1271 | 1470 |
1272 int AdlibDriver::update_setupProgram(uint8 *&dataptr, Channel &channel, uint8 value) { | 1471 int |
1472 AdlibDriver::update_setupProgram (uint8 * &dataptr, Channel & channel, | |
1473 uint8 value) | |
1474 { | |
1273 if (value == 0xFF) | 1475 if (value == 0xFF) |
1274 return 0; | 1476 return 0; |
1275 | 1477 |
1276 uint8 *ptr = getProgram(value); | 1478 uint8 *ptr = getProgram (value); |
1277 uint8 chan = *ptr++; | 1479 uint8 chan = *ptr++; |
1278 uint8 priority = *ptr++; | 1480 uint8 priority = *ptr++; |
1279 | 1481 |
1280 Channel &channel2 = _channels[chan]; | 1482 Channel & channel2 = _channels[chan]; |
1281 | 1483 |
1282 if (priority >= channel2.priority) { | 1484 if (priority >= channel2.priority) |
1485 { | |
1283 _flagTrigger = 1; | 1486 _flagTrigger = 1; |
1284 _flags |= 8; | 1487 _flags |= 8; |
1285 initChannel(channel2); | 1488 initChannel (channel2); |
1286 channel2.priority = priority; | 1489 channel2.priority = priority; |
1287 channel2.dataptr = ptr; | 1490 channel2.dataptr = ptr; |
1288 channel2.tempo = 0xFF; | 1491 channel2.tempo = 0xFF; |
1289 channel2.position = 0xFF; | 1492 channel2.position = 0xFF; |
1290 channel2.duration = 1; | 1493 channel2.duration = 1; |
1291 unkOutput2(chan); | 1494 unkOutput2 (chan); |
1292 } | 1495 } |
1293 | 1496 |
1294 return 0; | 1497 return 0; |
1295 } | 1498 } |
1296 | 1499 |
1297 int AdlibDriver::update_setNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value) { | 1500 int |
1501 AdlibDriver::update_setNoteSpacing (uint8 * &dataptr, Channel & channel, | |
1502 uint8 value) | |
1503 { | |
1298 channel.spacing1 = value; | 1504 channel.spacing1 = value; |
1299 return 0; | 1505 return 0; |
1300 } | 1506 } |
1301 | 1507 |
1302 int AdlibDriver::update_jump(uint8 *&dataptr, Channel &channel, uint8 value) { | 1508 int |
1509 AdlibDriver::update_jump (uint8 * &dataptr, Channel & channel, uint8 value) | |
1510 { | |
1303 --dataptr; | 1511 --dataptr; |
1304 int16 add = READ_LE_UINT16(dataptr); dataptr += 2; | 1512 int16 add = READ_LE_UINT16 (dataptr); |
1513 dataptr += 2; | |
1305 dataptr += add; | 1514 dataptr += add; |
1306 return 0; | 1515 return 0; |
1307 } | 1516 } |
1308 | 1517 |
1309 int AdlibDriver::update_jumpToSubroutine(uint8 *&dataptr, Channel &channel, uint8 value) { | 1518 int |
1519 AdlibDriver::update_jumpToSubroutine (uint8 * &dataptr, Channel & channel, | |
1520 uint8 value) | |
1521 { | |
1310 --dataptr; | 1522 --dataptr; |
1311 int16 add = READ_LE_UINT16(dataptr); dataptr += 2; | 1523 int16 add = READ_LE_UINT16 (dataptr); |
1524 dataptr += 2; | |
1312 channel.dataptrStack[channel.dataptrStackPos++] = dataptr; | 1525 channel.dataptrStack[channel.dataptrStackPos++] = dataptr; |
1313 dataptr += add; | 1526 dataptr += add; |
1314 return 0; | 1527 return 0; |
1315 } | 1528 } |
1316 | 1529 |
1317 int AdlibDriver::update_returnFromSubroutine(uint8 *&dataptr, Channel &channel, uint8 value) { | 1530 int |
1531 AdlibDriver::update_returnFromSubroutine (uint8 * &dataptr, Channel & channel, | |
1532 uint8 value) | |
1533 { | |
1318 dataptr = channel.dataptrStack[--channel.dataptrStackPos]; | 1534 dataptr = channel.dataptrStack[--channel.dataptrStackPos]; |
1319 return 0; | 1535 return 0; |
1320 } | 1536 } |
1321 | 1537 |
1322 int AdlibDriver::update_setBaseOctave(uint8 *&dataptr, Channel &channel, uint8 value) { | 1538 int |
1539 AdlibDriver::update_setBaseOctave (uint8 * &dataptr, Channel & channel, | |
1540 uint8 value) | |
1541 { | |
1323 channel.baseOctave = value; | 1542 channel.baseOctave = value; |
1324 return 0; | 1543 return 0; |
1325 } | 1544 } |
1326 | 1545 |
1327 int AdlibDriver::update_stopChannel(uint8 *&dataptr, Channel &channel, uint8 value) { | 1546 int |
1547 AdlibDriver::update_stopChannel (uint8 * &dataptr, Channel & channel, | |
1548 uint8 value) | |
1549 { | |
1328 channel.priority = 0; | 1550 channel.priority = 0; |
1329 if (_curChannel != 9) { | 1551 if (_curChannel != 9) |
1330 noteOff(channel); | 1552 { |
1553 noteOff (channel); | |
1331 } | 1554 } |
1332 dataptr = 0; | 1555 dataptr = 0; |
1333 return 2; | 1556 return 2; |
1334 } | 1557 } |
1335 | 1558 |
1336 int AdlibDriver::update_playRest(uint8 *&dataptr, Channel &channel, uint8 value) { | 1559 int |
1337 setupDuration(value, channel); | 1560 AdlibDriver::update_playRest (uint8 * &dataptr, Channel & channel, |
1338 noteOff(channel); | 1561 uint8 value) |
1562 { | |
1563 setupDuration (value, channel); | |
1564 noteOff (channel); | |
1339 return (value != 0); | 1565 return (value != 0); |
1340 } | 1566 } |
1341 | 1567 |
1342 int AdlibDriver::update_writeAdlib(uint8 *&dataptr, Channel &channel, uint8 value) { | 1568 int |
1343 writeOPL(value, *dataptr++); | 1569 AdlibDriver::update_writeAdlib (uint8 * &dataptr, Channel & channel, |
1344 return 0; | 1570 uint8 value) |
1345 } | 1571 { |
1346 | 1572 writeOPL (value, *dataptr++); |
1347 int AdlibDriver::update_setupNoteAndDuration(uint8 *&dataptr, Channel &channel, uint8 value) { | 1573 return 0; |
1348 setupNote(value, channel); | 1574 } |
1575 | |
1576 int | |
1577 AdlibDriver::update_setupNoteAndDuration (uint8 * &dataptr, Channel & channel, | |
1578 uint8 value) | |
1579 { | |
1580 setupNote (value, channel); | |
1349 value = *dataptr++; | 1581 value = *dataptr++; |
1350 setupDuration(value, channel); | 1582 setupDuration (value, channel); |
1351 return (value != 0); | 1583 return (value != 0); |
1352 } | 1584 } |
1353 | 1585 |
1354 int AdlibDriver::update_setBaseNote(uint8 *&dataptr, Channel &channel, uint8 value) { | 1586 int |
1587 AdlibDriver::update_setBaseNote (uint8 * &dataptr, Channel & channel, | |
1588 uint8 value) | |
1589 { | |
1355 channel.baseNote = value; | 1590 channel.baseNote = value; |
1356 return 0; | 1591 return 0; |
1357 } | 1592 } |
1358 | 1593 |
1359 int AdlibDriver::update_setupSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1594 int |
1595 AdlibDriver::update_setupSecondaryEffect1 (uint8 * &dataptr, | |
1596 Channel & channel, uint8 value) | |
1597 { | |
1360 channel.unk18 = value; | 1598 channel.unk18 = value; |
1361 channel.unk19 = value; | 1599 channel.unk19 = value; |
1362 channel.unk20 = channel.unk21 = *dataptr++; | 1600 channel.unk20 = channel.unk21 = *dataptr++; |
1363 channel.unk22 = *dataptr++; | 1601 channel.unk22 = *dataptr++; |
1364 channel.offset = READ_LE_UINT16(dataptr); dataptr += 2; | 1602 channel.offset = READ_LE_UINT16 (dataptr); |
1603 dataptr += 2; | |
1365 channel.secondaryEffect = &AdlibDriver::secondaryEffect1; | 1604 channel.secondaryEffect = &AdlibDriver::secondaryEffect1; |
1366 return 0; | 1605 return 0; |
1367 } | 1606 } |
1368 | 1607 |
1369 int AdlibDriver::update_stopOtherChannel(uint8 *&dataptr, Channel &channel, uint8 value) { | 1608 int |
1370 Channel &channel2 = _channels[value]; | 1609 AdlibDriver::update_stopOtherChannel (uint8 * &dataptr, Channel & channel, |
1610 uint8 value) | |
1611 { | |
1612 Channel & channel2 = _channels[value]; | |
1371 channel2.duration = 0; | 1613 channel2.duration = 0; |
1372 channel2.priority = 0; | 1614 channel2.priority = 0; |
1373 channel2.dataptr = 0; | 1615 channel2.dataptr = 0; |
1374 return 0; | 1616 return 0; |
1375 } | 1617 } |
1376 | 1618 |
1377 int AdlibDriver::update_waitForEndOfProgram(uint8 *&dataptr, Channel &channel, uint8 value) { | 1619 int |
1378 uint8 *ptr = getProgram(value); | 1620 AdlibDriver::update_waitForEndOfProgram (uint8 * &dataptr, Channel & channel, |
1621 uint8 value) | |
1622 { | |
1623 uint8 *ptr = getProgram (value); | |
1379 uint8 chan = *ptr; | 1624 uint8 chan = *ptr; |
1380 | 1625 |
1381 if (!_channels[chan].dataptr) { | 1626 if (!_channels[chan].dataptr) |
1627 { | |
1382 return 0; | 1628 return 0; |
1383 } | 1629 } |
1384 | 1630 |
1385 dataptr -= 2; | 1631 dataptr -= 2; |
1386 return 2; | 1632 return 2; |
1387 } | 1633 } |
1388 | 1634 |
1389 int AdlibDriver::update_setupInstrument(uint8 *&dataptr, Channel &channel, uint8 value) { | 1635 int |
1390 setupInstrument(_curRegOffset, getInstrument(value), channel); | 1636 AdlibDriver::update_setupInstrument (uint8 * &dataptr, Channel & channel, |
1391 return 0; | 1637 uint8 value) |
1392 } | 1638 { |
1393 | 1639 setupInstrument (_curRegOffset, getInstrument (value), channel); |
1394 int AdlibDriver::update_setupPrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1640 return 0; |
1641 } | |
1642 | |
1643 int | |
1644 AdlibDriver::update_setupPrimaryEffect1 (uint8 * &dataptr, Channel & channel, | |
1645 uint8 value) | |
1646 { | |
1395 channel.unk29 = value; | 1647 channel.unk29 = value; |
1396 channel.unk30 = READ_BE_UINT16(dataptr); | 1648 channel.unk30 = READ_BE_UINT16 (dataptr); |
1397 dataptr += 2; | 1649 dataptr += 2; |
1398 channel.primaryEffect = &AdlibDriver::primaryEffect1; | 1650 channel.primaryEffect = &AdlibDriver::primaryEffect1; |
1399 channel.unk31 = 0xFF; | 1651 channel.unk31 = 0xFF; |
1400 return 0; | 1652 return 0; |
1401 } | 1653 } |
1402 | 1654 |
1403 int AdlibDriver::update_removePrimaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1655 int |
1656 AdlibDriver::update_removePrimaryEffect1 (uint8 * &dataptr, Channel & channel, | |
1657 uint8 value) | |
1658 { | |
1404 --dataptr; | 1659 --dataptr; |
1405 channel.primaryEffect = 0; | 1660 channel.primaryEffect = 0; |
1406 channel.unk30 = 0; | 1661 channel.unk30 = 0; |
1407 return 0; | 1662 return 0; |
1408 } | 1663 } |
1409 | 1664 |
1410 int AdlibDriver::update_setBaseFreq(uint8 *&dataptr, Channel &channel, uint8 value) { | 1665 int |
1666 AdlibDriver::update_setBaseFreq (uint8 * &dataptr, Channel & channel, | |
1667 uint8 value) | |
1668 { | |
1411 channel.baseFreq = value; | 1669 channel.baseFreq = value; |
1412 return 0; | 1670 return 0; |
1413 } | 1671 } |
1414 | 1672 |
1415 int AdlibDriver::update_setupPrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value) { | 1673 int |
1674 AdlibDriver::update_setupPrimaryEffect2 (uint8 * &dataptr, Channel & channel, | |
1675 uint8 value) | |
1676 { | |
1416 channel.unk32 = value; | 1677 channel.unk32 = value; |
1417 channel.unk33 = *dataptr++; | 1678 channel.unk33 = *dataptr++; |
1418 uint8 temp = *dataptr++; | 1679 uint8 temp = *dataptr++; |
1419 channel.unk34 = temp + 1; | 1680 channel.unk34 = temp + 1; |
1420 channel.unk35 = temp << 1; | 1681 channel.unk35 = temp << 1; |
1421 channel.unk36 = *dataptr++; | 1682 channel.unk36 = *dataptr++; |
1422 channel.primaryEffect = &AdlibDriver::primaryEffect2; | 1683 channel.primaryEffect = &AdlibDriver::primaryEffect2; |
1423 return 0; | 1684 return 0; |
1424 } | 1685 } |
1425 | 1686 |
1426 int AdlibDriver::update_setPriority(uint8 *&dataptr, Channel &channel, uint8 value) { | 1687 int |
1688 AdlibDriver::update_setPriority (uint8 * &dataptr, Channel & channel, | |
1689 uint8 value) | |
1690 { | |
1427 channel.priority = value; | 1691 channel.priority = value; |
1428 return 0; | 1692 return 0; |
1429 } | 1693 } |
1430 | 1694 |
1431 int AdlibDriver::updateCallback23(uint8 *&dataptr, Channel &channel, uint8 value) { | 1695 int |
1696 AdlibDriver::updateCallback23 (uint8 * &dataptr, Channel & channel, | |
1697 uint8 value) | |
1698 { | |
1432 value >>= 1; | 1699 value >>= 1; |
1433 _unkValue1 = _unkValue2 = value; | 1700 _unkValue1 = _unkValue2 = value; |
1434 _unkValue3 = 0xFF; | 1701 _unkValue3 = 0xFF; |
1435 _unkValue4 = _unkValue5 = 0; | 1702 _unkValue4 = _unkValue5 = 0; |
1436 return 0; | 1703 return 0; |
1437 } | 1704 } |
1438 | 1705 |
1439 int AdlibDriver::updateCallback24(uint8 *&dataptr, Channel &channel, uint8 value) { | 1706 int |
1440 if (_unkValue5) { | 1707 AdlibDriver::updateCallback24 (uint8 * &dataptr, Channel & channel, |
1441 if (_unkValue4 & value) { | 1708 uint8 value) |
1709 { | |
1710 if (_unkValue5) | |
1711 { | |
1712 if (_unkValue4 & value) | |
1713 { | |
1442 _unkValue5 = 0; | 1714 _unkValue5 = 0; |
1443 return 0; | 1715 return 0; |
1444 } | 1716 } |
1445 } | 1717 } |
1446 | 1718 |
1447 if (!(value & _unkValue4)) { | 1719 if (!(value & _unkValue4)) |
1720 { | |
1448 ++_unkValue5; | 1721 ++_unkValue5; |
1449 } | 1722 } |
1450 | 1723 |
1451 dataptr -= 2; | 1724 dataptr -= 2; |
1452 channel.duration = 1; | 1725 channel.duration = 1; |
1453 return 2; | 1726 return 2; |
1454 } | 1727 } |
1455 | 1728 |
1456 int AdlibDriver::update_setExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1729 int |
1730 AdlibDriver::update_setExtraLevel1 (uint8 * &dataptr, Channel & channel, | |
1731 uint8 value) | |
1732 { | |
1457 channel.opExtraLevel1 = value; | 1733 channel.opExtraLevel1 = value; |
1458 adjustVolume(channel); | 1734 adjustVolume (channel); |
1459 return 0; | 1735 return 0; |
1460 } | 1736 } |
1461 | 1737 |
1462 int AdlibDriver::update_setupDuration(uint8 *&dataptr, Channel &channel, uint8 value) { | 1738 int |
1463 setupDuration(value, channel); | 1739 AdlibDriver::update_setupDuration (uint8 * &dataptr, Channel & channel, |
1740 uint8 value) | |
1741 { | |
1742 setupDuration (value, channel); | |
1464 return (value != 0); | 1743 return (value != 0); |
1465 } | 1744 } |
1466 | 1745 |
1467 int AdlibDriver::update_playNote(uint8 *&dataptr, Channel &channel, uint8 value) { | 1746 int |
1468 setupDuration(value, channel); | 1747 AdlibDriver::update_playNote (uint8 * &dataptr, Channel & channel, |
1469 noteOn(channel); | 1748 uint8 value) |
1749 { | |
1750 setupDuration (value, channel); | |
1751 noteOn (channel); | |
1470 return (value != 0); | 1752 return (value != 0); |
1471 } | 1753 } |
1472 | 1754 |
1473 int AdlibDriver::update_setFractionalNoteSpacing(uint8 *&dataptr, Channel &channel, uint8 value) { | 1755 int |
1756 AdlibDriver::update_setFractionalNoteSpacing (uint8 * &dataptr, | |
1757 Channel & channel, uint8 value) | |
1758 { | |
1474 channel.fractionalSpacing = value & 7; | 1759 channel.fractionalSpacing = value & 7; |
1475 return 0; | 1760 return 0; |
1476 } | 1761 } |
1477 | 1762 |
1478 int AdlibDriver::update_setTempo(uint8 *&dataptr, Channel &channel, uint8 value) { | 1763 int |
1764 AdlibDriver::update_setTempo (uint8 * &dataptr, Channel & channel, | |
1765 uint8 value) | |
1766 { | |
1479 _tempo = value; | 1767 _tempo = value; |
1480 return 0; | 1768 return 0; |
1481 } | 1769 } |
1482 | 1770 |
1483 int AdlibDriver::update_removeSecondaryEffect1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1771 int |
1772 AdlibDriver::update_removeSecondaryEffect1 (uint8 * &dataptr, | |
1773 Channel & channel, uint8 value) | |
1774 { | |
1484 --dataptr; | 1775 --dataptr; |
1485 channel.secondaryEffect = 0; | 1776 channel.secondaryEffect = 0; |
1486 return 0; | 1777 return 0; |
1487 } | 1778 } |
1488 | 1779 |
1489 int AdlibDriver::update_setChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value) { | 1780 int |
1781 AdlibDriver::update_setChannelTempo (uint8 * &dataptr, Channel & channel, | |
1782 uint8 value) | |
1783 { | |
1490 channel.tempo = value; | 1784 channel.tempo = value; |
1491 return 0; | 1785 return 0; |
1492 } | 1786 } |
1493 | 1787 |
1494 int AdlibDriver::update_setExtraLevel3(uint8 *&dataptr, Channel &channel, uint8 value) { | 1788 int |
1789 AdlibDriver::update_setExtraLevel3 (uint8 * &dataptr, Channel & channel, | |
1790 uint8 value) | |
1791 { | |
1495 channel.opExtraLevel3 = value; | 1792 channel.opExtraLevel3 = value; |
1496 return 0; | 1793 return 0; |
1497 } | 1794 } |
1498 | 1795 |
1499 int AdlibDriver::update_setExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value) { | 1796 int |
1797 AdlibDriver::update_setExtraLevel2 (uint8 * &dataptr, Channel & channel, | |
1798 uint8 value) | |
1799 { | |
1500 int channelBackUp = _curChannel; | 1800 int channelBackUp = _curChannel; |
1501 | 1801 |
1502 _curChannel = value; | 1802 _curChannel = value; |
1503 Channel &channel2 = _channels[value]; | 1803 Channel & channel2 = _channels[value]; |
1504 channel2.opExtraLevel2 = *dataptr++; | 1804 channel2.opExtraLevel2 = *dataptr++; |
1505 adjustVolume(channel2); | 1805 adjustVolume (channel2); |
1506 | 1806 |
1507 _curChannel = channelBackUp; | 1807 _curChannel = channelBackUp; |
1508 return 0; | 1808 return 0; |
1509 } | 1809 } |
1510 | 1810 |
1511 int AdlibDriver::update_changeExtraLevel2(uint8 *&dataptr, Channel &channel, uint8 value) { | 1811 int |
1812 AdlibDriver::update_changeExtraLevel2 (uint8 * &dataptr, Channel & channel, | |
1813 uint8 value) | |
1814 { | |
1512 int channelBackUp = _curChannel; | 1815 int channelBackUp = _curChannel; |
1513 | 1816 |
1514 _curChannel = value; | 1817 _curChannel = value; |
1515 Channel &channel2 = _channels[value]; | 1818 Channel & channel2 = _channels[value]; |
1516 channel2.opExtraLevel2 += *dataptr++; | 1819 channel2.opExtraLevel2 += *dataptr++; |
1517 adjustVolume(channel2); | 1820 adjustVolume (channel2); |
1518 | 1821 |
1519 _curChannel = channelBackUp; | 1822 _curChannel = channelBackUp; |
1520 return 0; | 1823 return 0; |
1521 } | 1824 } |
1522 | 1825 |
1523 // Apart from initialising to zero, these two functions are the only ones that | 1826 // Apart from initialising to zero, these two functions are the only ones that |
1524 // modify _vibratoAndAMDepthBits. | 1827 // modify _vibratoAndAMDepthBits. |
1525 | 1828 |
1526 int AdlibDriver::update_setAMDepth(uint8 *&dataptr, Channel &channel, uint8 value) { | 1829 int |
1830 AdlibDriver::update_setAMDepth (uint8 * &dataptr, Channel & channel, | |
1831 uint8 value) | |
1832 { | |
1527 if (value & 1) | 1833 if (value & 1) |
1528 _vibratoAndAMDepthBits |= 0x80; | 1834 _vibratoAndAMDepthBits |= 0x80; |
1529 else | 1835 else |
1530 _vibratoAndAMDepthBits &= 0x7F; | 1836 _vibratoAndAMDepthBits &= 0x7F; |
1531 | 1837 |
1532 writeOPL(0xBD, _vibratoAndAMDepthBits); | 1838 writeOPL (0xBD, _vibratoAndAMDepthBits); |
1533 return 0; | 1839 return 0; |
1534 } | 1840 } |
1535 | 1841 |
1536 int AdlibDriver::update_setVibratoDepth(uint8 *&dataptr, Channel &channel, uint8 value) { | 1842 int |
1843 AdlibDriver::update_setVibratoDepth (uint8 * &dataptr, Channel & channel, | |
1844 uint8 value) | |
1845 { | |
1537 if (value & 1) | 1846 if (value & 1) |
1538 _vibratoAndAMDepthBits |= 0x40; | 1847 _vibratoAndAMDepthBits |= 0x40; |
1539 else | 1848 else |
1540 _vibratoAndAMDepthBits &= 0xBF; | 1849 _vibratoAndAMDepthBits &= 0xBF; |
1541 | 1850 |
1542 writeOPL(0xBD, _vibratoAndAMDepthBits); | 1851 writeOPL (0xBD, _vibratoAndAMDepthBits); |
1543 return 0; | 1852 return 0; |
1544 } | 1853 } |
1545 | 1854 |
1546 int AdlibDriver::update_changeExtraLevel1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1855 int |
1856 AdlibDriver::update_changeExtraLevel1 (uint8 * &dataptr, Channel & channel, | |
1857 uint8 value) | |
1858 { | |
1547 channel.opExtraLevel1 += value; | 1859 channel.opExtraLevel1 += value; |
1548 adjustVolume(channel); | 1860 adjustVolume (channel); |
1549 return 0; | 1861 return 0; |
1550 } | 1862 } |
1551 | 1863 |
1552 int AdlibDriver::updateCallback38(uint8 *&dataptr, Channel &channel, uint8 value) { | 1864 int |
1865 AdlibDriver::updateCallback38 (uint8 * &dataptr, Channel & channel, | |
1866 uint8 value) | |
1867 { | |
1553 int channelBackUp = _curChannel; | 1868 int channelBackUp = _curChannel; |
1554 | 1869 |
1555 _curChannel = value; | 1870 _curChannel = value; |
1556 Channel &channel2 = _channels[value]; | 1871 Channel & channel2 = _channels[value]; |
1557 channel2.duration = channel2.priority = 0; | 1872 channel2.duration = channel2.priority = 0; |
1558 channel2.dataptr = 0; | 1873 channel2.dataptr = 0; |
1559 channel2.opExtraLevel2 = 0; | 1874 channel2.opExtraLevel2 = 0; |
1560 | 1875 |
1561 if (value != 9) { | 1876 if (value != 9) |
1877 { | |
1562 uint8 outValue = _regOffset[value]; | 1878 uint8 outValue = _regOffset[value]; |
1563 | 1879 |
1564 // Feedback strength / Connection type | 1880 // Feedback strength / Connection type |
1565 writeOPL(0xC0 + _curChannel, 0x00); | 1881 writeOPL (0xC0 + _curChannel, 0x00); |
1566 | 1882 |
1567 // Key scaling level / Operator output level | 1883 // Key scaling level / Operator output level |
1568 writeOPL(0x43 + outValue, 0x3F); | 1884 writeOPL (0x43 + outValue, 0x3F); |
1569 | 1885 |
1570 // Sustain Level / Release Rate | 1886 // Sustain Level / Release Rate |
1571 writeOPL(0x83 + outValue, 0xFF); | 1887 writeOPL (0x83 + outValue, 0xFF); |
1572 | 1888 |
1573 // Key On / Octave / Frequency | 1889 // Key On / Octave / Frequency |
1574 writeOPL(0xB0 + _curChannel, 0x00); | 1890 writeOPL (0xB0 + _curChannel, 0x00); |
1575 } | 1891 } |
1576 | 1892 |
1577 _curChannel = channelBackUp; | 1893 _curChannel = channelBackUp; |
1578 return 0; | 1894 return 0; |
1579 } | 1895 } |
1580 | 1896 |
1581 int AdlibDriver::updateCallback39(uint8 *&dataptr, Channel &channel, uint8 value) { | 1897 int |
1898 AdlibDriver::updateCallback39 (uint8 * &dataptr, Channel & channel, | |
1899 uint8 value) | |
1900 { | |
1582 uint16 unk = *dataptr++; | 1901 uint16 unk = *dataptr++; |
1583 unk |= value << 8; | 1902 unk |= value << 8; |
1584 unk &= getRandomNr(); | 1903 unk &= getRandomNr (); |
1585 | 1904 |
1586 uint16 unk2 = ((channel.regBx & 0x1F) << 8) | channel.regAx; | 1905 uint16 unk2 = ((channel.regBx & 0x1F) << 8) | channel.regAx; |
1587 unk2 += unk; | 1906 unk2 += unk; |
1588 unk2 |= ((channel.regBx & 0x20) << 8); | 1907 unk2 |= ((channel.regBx & 0x20) << 8); |
1589 | 1908 |
1590 // Frequency | 1909 // Frequency |
1591 writeOPL(0xA0 + _curChannel, unk2 & 0xFF); | 1910 writeOPL (0xA0 + _curChannel, unk2 & 0xFF); |
1592 | 1911 |
1593 // Key On / Octave / Frequency | 1912 // Key On / Octave / Frequency |
1594 writeOPL(0xB0 + _curChannel, (unk2 & 0xFF00) >> 8); | 1913 writeOPL (0xB0 + _curChannel, (unk2 & 0xFF00) >> 8); |
1595 | 1914 |
1596 return 0; | 1915 return 0; |
1597 } | 1916 } |
1598 | 1917 |
1599 int AdlibDriver::update_removePrimaryEffect2(uint8 *&dataptr, Channel &channel, uint8 value) { | 1918 int |
1919 AdlibDriver::update_removePrimaryEffect2 (uint8 * &dataptr, Channel & channel, | |
1920 uint8 value) | |
1921 { | |
1600 --dataptr; | 1922 --dataptr; |
1601 channel.primaryEffect = 0; | 1923 channel.primaryEffect = 0; |
1602 return 0; | 1924 return 0; |
1603 } | 1925 } |
1604 | 1926 |
1605 int AdlibDriver::updateCallback41(uint8 *&dataptr, Channel &channel, uint8 value) { | 1927 int |
1928 AdlibDriver::updateCallback41 (uint8 * &dataptr, Channel & channel, | |
1929 uint8 value) | |
1930 { | |
1606 channel.unk16 = value; | 1931 channel.unk16 = value; |
1607 setupNote(channel.rawNote, channel, true); | 1932 setupNote (channel.rawNote, channel, true); |
1608 return 0; | 1933 return 0; |
1609 } | 1934 } |
1610 | 1935 |
1611 int AdlibDriver::update_resetToGlobalTempo(uint8 *&dataptr, Channel &channel, uint8 value) { | 1936 int |
1937 AdlibDriver::update_resetToGlobalTempo (uint8 * &dataptr, Channel & channel, | |
1938 uint8 value) | |
1939 { | |
1612 --dataptr; | 1940 --dataptr; |
1613 channel.tempo = _tempo; | 1941 channel.tempo = _tempo; |
1614 return 0; | 1942 return 0; |
1615 } | 1943 } |
1616 | 1944 |
1617 int AdlibDriver::update_nop1(uint8 *&dataptr, Channel &channel, uint8 value) { | 1945 int |
1946 AdlibDriver::update_nop1 (uint8 * &dataptr, Channel & channel, uint8 value) | |
1947 { | |
1618 --dataptr; | 1948 --dataptr; |
1619 return 0; | 1949 return 0; |
1620 } | 1950 } |
1621 | 1951 |
1622 int AdlibDriver::update_setDurationRandomness(uint8 *&dataptr, Channel &channel, uint8 value) { | 1952 int |
1953 AdlibDriver::update_setDurationRandomness (uint8 * &dataptr, | |
1954 Channel & channel, uint8 value) | |
1955 { | |
1623 channel.durationRandomness = value; | 1956 channel.durationRandomness = value; |
1624 return 0; | 1957 return 0; |
1625 } | 1958 } |
1626 | 1959 |
1627 int AdlibDriver::update_changeChannelTempo(uint8 *&dataptr, Channel &channel, uint8 value) { | 1960 int |
1628 int tempo = channel.tempo + (int8)value; | 1961 AdlibDriver::update_changeChannelTempo (uint8 * &dataptr, Channel & channel, |
1962 uint8 value) | |
1963 { | |
1964 int tempo = channel.tempo + (int8) value; | |
1629 | 1965 |
1630 if (tempo <= 0) | 1966 if (tempo <= 0) |
1631 tempo = 1; | 1967 tempo = 1; |
1632 else if (tempo > 255) | 1968 else if (tempo > 255) |
1633 tempo = 255; | 1969 tempo = 255; |
1634 | 1970 |
1635 channel.tempo = tempo; | 1971 channel.tempo = tempo; |
1636 return 0; | 1972 return 0; |
1637 } | 1973 } |
1638 | 1974 |
1639 int AdlibDriver::updateCallback46(uint8 *&dataptr, Channel &channel, uint8 value) { | 1975 int |
1976 AdlibDriver::updateCallback46 (uint8 * &dataptr, Channel & channel, | |
1977 uint8 value) | |
1978 { | |
1640 uint8 entry = *dataptr++; | 1979 uint8 entry = *dataptr++; |
1641 _tablePtr1 = _unkTable2[entry++]; | 1980 _tablePtr1 = _unkTable2[entry++]; |
1642 _tablePtr2 = _unkTable2[entry]; | 1981 _tablePtr2 = _unkTable2[entry]; |
1643 if (value == 2) { | 1982 if (value == 2) |
1983 { | |
1644 // Frequency | 1984 // Frequency |
1645 writeOPL(0xA0, _tablePtr2[0]); | 1985 writeOPL (0xA0, _tablePtr2[0]); |
1646 } | 1986 } |
1647 return 0; | 1987 return 0; |
1648 } | 1988 } |
1649 | 1989 |
1650 // TODO: This is really the same as update_nop1(), so they should be combined | 1990 // TODO: This is really the same as update_nop1(), so they should be combined |
1651 // into one single update_nop(). | 1991 // into one single update_nop(). |
1652 | 1992 |
1653 int AdlibDriver::update_nop2(uint8 *&dataptr, Channel &channel, uint8 value) { | 1993 int |
1994 AdlibDriver::update_nop2 (uint8 * &dataptr, Channel & channel, uint8 value) | |
1995 { | |
1654 --dataptr; | 1996 --dataptr; |
1655 return 0; | 1997 return 0; |
1656 } | 1998 } |
1657 | 1999 |
1658 int AdlibDriver::update_setupRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { | 2000 int |
2001 AdlibDriver::update_setupRhythmSection (uint8 * &dataptr, Channel & channel, | |
2002 uint8 value) | |
2003 { | |
1659 int channelBackUp = _curChannel; | 2004 int channelBackUp = _curChannel; |
1660 int regOffsetBackUp = _curRegOffset; | 2005 int regOffsetBackUp = _curRegOffset; |
1661 | 2006 |
1662 _curChannel = 6; | 2007 _curChannel = 6; |
1663 _curRegOffset = _regOffset[6]; | 2008 _curRegOffset = _regOffset[6]; |
1664 | 2009 |
1665 setupInstrument(_curRegOffset, getInstrument(value), channel); | 2010 setupInstrument (_curRegOffset, getInstrument (value), channel); |
1666 _unkValue6 = channel.opLevel2; | 2011 _unkValue6 = channel.opLevel2; |
1667 | 2012 |
1668 _curChannel = 7; | 2013 _curChannel = 7; |
1669 _curRegOffset = _regOffset[7]; | 2014 _curRegOffset = _regOffset[7]; |
1670 | 2015 |
1671 setupInstrument(_curRegOffset, getInstrument(*dataptr++), channel); | 2016 setupInstrument (_curRegOffset, getInstrument (*dataptr++), channel); |
1672 _unkValue7 = channel.opLevel1; | 2017 _unkValue7 = channel.opLevel1; |
1673 _unkValue8 = channel.opLevel2; | 2018 _unkValue8 = channel.opLevel2; |
1674 | 2019 |
1675 _curChannel = 8; | 2020 _curChannel = 8; |
1676 _curRegOffset = _regOffset[8]; | 2021 _curRegOffset = _regOffset[8]; |
1677 | 2022 |
1678 setupInstrument(_curRegOffset, getInstrument(*dataptr++), channel); | 2023 setupInstrument (_curRegOffset, getInstrument (*dataptr++), channel); |
1679 _unkValue9 = channel.opLevel1; | 2024 _unkValue9 = channel.opLevel1; |
1680 _unkValue10 = channel.opLevel2; | 2025 _unkValue10 = channel.opLevel2; |
1681 | 2026 |
1682 // Octave / F-Number / Key-On for channels 6, 7 and 8 | 2027 // Octave / F-Number / Key-On for channels 6, 7 and 8 |
1683 | 2028 |
1684 _channels[6].regBx = *dataptr++ & 0x2F; | 2029 _channels[6].regBx = *dataptr++ & 0x2F; |
1685 writeOPL(0xB6, _channels[6].regBx); | 2030 writeOPL (0xB6, _channels[6].regBx); |
1686 writeOPL(0xA6, *dataptr++); | 2031 writeOPL (0xA6, *dataptr++); |
1687 | 2032 |
1688 _channels[7].regBx = *dataptr++ & 0x2F; | 2033 _channels[7].regBx = *dataptr++ & 0x2F; |
1689 writeOPL(0xB7, _channels[7].regBx); | 2034 writeOPL (0xB7, _channels[7].regBx); |
1690 writeOPL(0xA7, *dataptr++); | 2035 writeOPL (0xA7, *dataptr++); |
1691 | 2036 |
1692 _channels[8].regBx = *dataptr++ & 0x2F; | 2037 _channels[8].regBx = *dataptr++ & 0x2F; |
1693 writeOPL(0xB8, _channels[8].regBx); | 2038 writeOPL (0xB8, _channels[8].regBx); |
1694 writeOPL(0xA8, *dataptr++); | 2039 writeOPL (0xA8, *dataptr++); |
1695 | 2040 |
1696 _rhythmSectionBits = 0x20; | 2041 _rhythmSectionBits = 0x20; |
1697 | 2042 |
1698 _curRegOffset = regOffsetBackUp; | 2043 _curRegOffset = regOffsetBackUp; |
1699 _curChannel = channelBackUp; | 2044 _curChannel = channelBackUp; |
1700 return 0; | 2045 return 0; |
1701 } | 2046 } |
1702 | 2047 |
1703 int AdlibDriver::update_playRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { | 2048 int |
2049 AdlibDriver::update_playRhythmSection (uint8 * &dataptr, Channel & channel, | |
2050 uint8 value) | |
2051 { | |
1704 // Any instrument that we want to play, and which was already playing, | 2052 // Any instrument that we want to play, and which was already playing, |
1705 // is temporarily keyed off. Instruments that were off already, or | 2053 // is temporarily keyed off. Instruments that were off already, or |
1706 // which we don't want to play, retain their old on/off status. This is | 2054 // which we don't want to play, retain their old on/off status. This is |
1707 // probably so that the instrument's envelope is played from its | 2055 // probably so that the instrument's envelope is played from its |
1708 // beginning again... | 2056 // beginning again... |
1709 | 2057 |
1710 writeOPL(0xBD, (_rhythmSectionBits & ~(value & 0x1F)) | 0x20); | 2058 writeOPL (0xBD, (_rhythmSectionBits & ~(value & 0x1F)) | 0x20); |
1711 | 2059 |
1712 // ...but since we only set the rhythm instrument bits, and never clear | 2060 // ...but since we only set the rhythm instrument bits, and never clear |
1713 // them (until the entire rhythm section is disabled), I'm not sure how | 2061 // them (until the entire rhythm section is disabled), I'm not sure how |
1714 // useful the cleverness above is. We could perhaps simply turn off all | 2062 // useful the cleverness above is. We could perhaps simply turn off all |
1715 // the rhythm instruments instead. | 2063 // the rhythm instruments instead. |
1716 | 2064 |
1717 _rhythmSectionBits |= value; | 2065 _rhythmSectionBits |= value; |
1718 | 2066 |
1719 writeOPL(0xBD, _vibratoAndAMDepthBits | 0x20 | _rhythmSectionBits); | 2067 writeOPL (0xBD, _vibratoAndAMDepthBits | 0x20 | _rhythmSectionBits); |
1720 return 0; | 2068 return 0; |
1721 } | 2069 } |
1722 | 2070 |
1723 int AdlibDriver::update_removeRhythmSection(uint8 *&dataptr, Channel &channel, uint8 value) { | 2071 int |
2072 AdlibDriver::update_removeRhythmSection (uint8 * &dataptr, Channel & channel, | |
2073 uint8 value) | |
2074 { | |
1724 --dataptr; | 2075 --dataptr; |
1725 _rhythmSectionBits = 0; | 2076 _rhythmSectionBits = 0; |
1726 | 2077 |
1727 // All the rhythm bits are cleared. The AM and Vibrato depth bits | 2078 // All the rhythm bits are cleared. The AM and Vibrato depth bits |
1728 // remain unchanged. | 2079 // remain unchanged. |
1729 | 2080 |
1730 writeOPL(0xBD, _vibratoAndAMDepthBits); | 2081 writeOPL (0xBD, _vibratoAndAMDepthBits); |
1731 return 0; | 2082 return 0; |
1732 } | 2083 } |
1733 | 2084 |
1734 int AdlibDriver::updateCallback51(uint8 *&dataptr, Channel &channel, uint8 value) { | 2085 int |
2086 AdlibDriver::updateCallback51 (uint8 * &dataptr, Channel & channel, | |
2087 uint8 value) | |
2088 { | |
1735 uint8 value2 = *dataptr++; | 2089 uint8 value2 = *dataptr++; |
1736 | 2090 |
1737 if (value & 1) { | 2091 if (value & 1) |
2092 { | |
1738 _unkValue12 = value2; | 2093 _unkValue12 = value2; |
1739 | 2094 |
1740 // Channel 7, op1: Level Key Scaling / Total Level | 2095 // Channel 7, op1: Level Key Scaling / Total Level |
1741 writeOPL(0x51, checkValue(value2 + _unkValue7 + _unkValue11 + _unkValue12)); | 2096 writeOPL (0x51, |
1742 } | 2097 checkValue (value2 + _unkValue7 + _unkValue11 + _unkValue12)); |
1743 | 2098 } |
1744 if (value & 2) { | 2099 |
2100 if (value & 2) | |
2101 { | |
1745 _unkValue14 = value2; | 2102 _unkValue14 = value2; |
1746 | 2103 |
1747 // Channel 8, op2: Level Key Scaling / Total Level | 2104 // Channel 8, op2: Level Key Scaling / Total Level |
1748 writeOPL(0x55, checkValue(value2 + _unkValue10 + _unkValue13 + _unkValue14)); | 2105 writeOPL (0x55, |
1749 } | 2106 checkValue (value2 + _unkValue10 + _unkValue13 + _unkValue14)); |
1750 | 2107 } |
1751 if (value & 4) { | 2108 |
2109 if (value & 4) | |
2110 { | |
1752 _unkValue15 = value2; | 2111 _unkValue15 = value2; |
1753 | 2112 |
1754 // Channel 8, op1: Level Key Scaling / Total Level | 2113 // Channel 8, op1: Level Key Scaling / Total Level |
1755 writeOPL(0x52, checkValue(value2 + _unkValue9 + _unkValue16 + _unkValue15)); | 2114 writeOPL (0x52, |
1756 } | 2115 checkValue (value2 + _unkValue9 + _unkValue16 + _unkValue15)); |
1757 | 2116 } |
1758 if (value & 8) { | 2117 |
2118 if (value & 8) | |
2119 { | |
1759 _unkValue18 = value2; | 2120 _unkValue18 = value2; |
1760 | 2121 |
1761 // Channel 7, op2: Level Key Scaling / Total Level | 2122 // Channel 7, op2: Level Key Scaling / Total Level |
1762 writeOPL(0x54, checkValue(value2 + _unkValue8 + _unkValue17 + _unkValue18)); | 2123 writeOPL (0x54, |
1763 } | 2124 checkValue (value2 + _unkValue8 + _unkValue17 + _unkValue18)); |
1764 | 2125 } |
1765 if (value & 16) { | 2126 |
2127 if (value & 16) | |
2128 { | |
1766 _unkValue20 = value2; | 2129 _unkValue20 = value2; |
1767 | 2130 |
1768 // Channel 6, op2: Level Key Scaling / Total Level | 2131 // Channel 6, op2: Level Key Scaling / Total Level |
1769 writeOPL(0x53, checkValue(value2 + _unkValue6 + _unkValue19 + _unkValue20)); | 2132 writeOPL (0x53, |
1770 } | 2133 checkValue (value2 + _unkValue6 + _unkValue19 + _unkValue20)); |
1771 | 2134 } |
1772 return 0; | 2135 |
1773 } | 2136 return 0; |
1774 | 2137 } |
1775 int AdlibDriver::updateCallback52(uint8 *&dataptr, Channel &channel, uint8 value) { | 2138 |
2139 int | |
2140 AdlibDriver::updateCallback52 (uint8 * &dataptr, Channel & channel, | |
2141 uint8 value) | |
2142 { | |
1776 uint8 value2 = *dataptr++; | 2143 uint8 value2 = *dataptr++; |
1777 | 2144 |
1778 if (value & 1) { | 2145 if (value & 1) |
1779 _unkValue11 = checkValue(value2 + _unkValue7 + _unkValue11 + _unkValue12); | 2146 { |
2147 _unkValue11 = | |
2148 checkValue (value2 + _unkValue7 + _unkValue11 + _unkValue12); | |
1780 | 2149 |
1781 // Channel 7, op1: Level Key Scaling / Total Level | 2150 // Channel 7, op1: Level Key Scaling / Total Level |
1782 writeOPL(0x51, _unkValue11); | 2151 writeOPL (0x51, _unkValue11); |
1783 } | 2152 } |
1784 | 2153 |
1785 if (value & 2) { | 2154 if (value & 2) |
1786 _unkValue13 = checkValue(value2 + _unkValue10 + _unkValue13 + _unkValue14); | 2155 { |
2156 _unkValue13 = | |
2157 checkValue (value2 + _unkValue10 + _unkValue13 + _unkValue14); | |
1787 | 2158 |
1788 // Channel 8, op2: Level Key Scaling / Total Level | 2159 // Channel 8, op2: Level Key Scaling / Total Level |
1789 writeOPL(0x55, _unkValue13); | 2160 writeOPL (0x55, _unkValue13); |
1790 } | 2161 } |
1791 | 2162 |
1792 if (value & 4) { | 2163 if (value & 4) |
1793 _unkValue16 = checkValue(value2 + _unkValue9 + _unkValue16 + _unkValue15); | 2164 { |
2165 _unkValue16 = | |
2166 checkValue (value2 + _unkValue9 + _unkValue16 + _unkValue15); | |
1794 | 2167 |
1795 // Channel 8, op1: Level Key Scaling / Total Level | 2168 // Channel 8, op1: Level Key Scaling / Total Level |
1796 writeOPL(0x52, _unkValue16); | 2169 writeOPL (0x52, _unkValue16); |
1797 } | 2170 } |
1798 | 2171 |
1799 if (value & 8) { | 2172 if (value & 8) |
1800 _unkValue17 = checkValue(value2 + _unkValue8 + _unkValue17 + _unkValue18); | 2173 { |
2174 _unkValue17 = | |
2175 checkValue (value2 + _unkValue8 + _unkValue17 + _unkValue18); | |
1801 | 2176 |
1802 // Channel 7, op2: Level Key Scaling / Total Level | 2177 // Channel 7, op2: Level Key Scaling / Total Level |
1803 writeOPL(0x54, _unkValue17); | 2178 writeOPL (0x54, _unkValue17); |
1804 } | 2179 } |
1805 | 2180 |
1806 if (value & 16) { | 2181 if (value & 16) |
1807 _unkValue19 = checkValue(value2 + _unkValue6 + _unkValue19 + _unkValue20); | 2182 { |
2183 _unkValue19 = | |
2184 checkValue (value2 + _unkValue6 + _unkValue19 + _unkValue20); | |
1808 | 2185 |
1809 // Channel 6, op2: Level Key Scaling / Total Level | 2186 // Channel 6, op2: Level Key Scaling / Total Level |
1810 writeOPL(0x53, _unkValue19); | 2187 writeOPL (0x53, _unkValue19); |
1811 } | 2188 } |
1812 | 2189 |
1813 return 0; | 2190 return 0; |
1814 } | 2191 } |
1815 | 2192 |
1816 int AdlibDriver::updateCallback53(uint8 *&dataptr, Channel &channel, uint8 value) { | 2193 int |
2194 AdlibDriver::updateCallback53 (uint8 * &dataptr, Channel & channel, | |
2195 uint8 value) | |
2196 { | |
1817 uint8 value2 = *dataptr++; | 2197 uint8 value2 = *dataptr++; |
1818 | 2198 |
1819 if (value & 1) { | 2199 if (value & 1) |
2200 { | |
1820 _unkValue11 = value2; | 2201 _unkValue11 = value2; |
1821 | 2202 |
1822 // Channel 7, op1: Level Key Scaling / Total Level | 2203 // Channel 7, op1: Level Key Scaling / Total Level |
1823 writeOPL(0x51, checkValue(value2 + _unkValue7 + _unkValue12)); | 2204 writeOPL (0x51, checkValue (value2 + _unkValue7 + _unkValue12)); |
1824 } | 2205 } |
1825 | 2206 |
1826 if (value & 2) { | 2207 if (value & 2) |
2208 { | |
1827 _unkValue13 = value2; | 2209 _unkValue13 = value2; |
1828 | 2210 |
1829 // Channel 8, op2: Level Key Scaling / Total Level | 2211 // Channel 8, op2: Level Key Scaling / Total Level |
1830 writeOPL(0x55, checkValue(value2 + _unkValue10 + _unkValue14)); | 2212 writeOPL (0x55, checkValue (value2 + _unkValue10 + _unkValue14)); |
1831 } | 2213 } |
1832 | 2214 |
1833 if (value & 4) { | 2215 if (value & 4) |
2216 { | |
1834 _unkValue16 = value2; | 2217 _unkValue16 = value2; |
1835 | 2218 |
1836 // Channel 8, op1: Level Key Scaling / Total Level | 2219 // Channel 8, op1: Level Key Scaling / Total Level |
1837 writeOPL(0x52, checkValue(value2 + _unkValue9 + _unkValue15)); | 2220 writeOPL (0x52, checkValue (value2 + _unkValue9 + _unkValue15)); |
1838 } | 2221 } |
1839 | 2222 |
1840 if (value & 8) { | 2223 if (value & 8) |
2224 { | |
1841 _unkValue17 = value2; | 2225 _unkValue17 = value2; |
1842 | 2226 |
1843 // Channel 7, op2: Level Key Scaling / Total Level | 2227 // Channel 7, op2: Level Key Scaling / Total Level |
1844 writeOPL(0x54, checkValue(value2 + _unkValue8 + _unkValue18)); | 2228 writeOPL (0x54, checkValue (value2 + _unkValue8 + _unkValue18)); |
1845 } | 2229 } |
1846 | 2230 |
1847 if (value & 16) { | 2231 if (value & 16) |
2232 { | |
1848 _unkValue19 = value2; | 2233 _unkValue19 = value2; |
1849 | 2234 |
1850 // Channel 6, op2: Level Key Scaling / Total Level | 2235 // Channel 6, op2: Level Key Scaling / Total Level |
1851 writeOPL(0x53, checkValue(value2 + _unkValue6 + _unkValue20)); | 2236 writeOPL (0x53, checkValue (value2 + _unkValue6 + _unkValue20)); |
1852 } | 2237 } |
1853 | 2238 |
1854 return 0; | 2239 return 0; |
1855 } | 2240 } |
1856 | 2241 |
1857 int AdlibDriver::update_setSoundTrigger(uint8 *&dataptr, Channel &channel, uint8 value) { | 2242 int |
2243 AdlibDriver::update_setSoundTrigger (uint8 * &dataptr, Channel & channel, | |
2244 uint8 value) | |
2245 { | |
1858 _soundTrigger = value; | 2246 _soundTrigger = value; |
1859 return 0; | 2247 return 0; |
1860 } | 2248 } |
1861 | 2249 |
1862 int AdlibDriver::update_setTempoReset(uint8 *&dataptr, Channel &channel, uint8 value) { | 2250 int |
2251 AdlibDriver::update_setTempoReset (uint8 * &dataptr, Channel & channel, | |
2252 uint8 value) | |
2253 { | |
1863 channel.tempoReset = value; | 2254 channel.tempoReset = value; |
1864 return 0; | 2255 return 0; |
1865 } | 2256 } |
1866 | 2257 |
1867 int AdlibDriver::updateCallback56(uint8 *&dataptr, Channel &channel, uint8 value) { | 2258 int |
2259 AdlibDriver::updateCallback56 (uint8 * &dataptr, Channel & channel, | |
2260 uint8 value) | |
2261 { | |
1868 channel.unk39 = value; | 2262 channel.unk39 = value; |
1869 channel.unk40 = *dataptr++; | 2263 channel.unk40 = *dataptr++; |
1870 return 0; | 2264 return 0; |
1871 } | 2265 } |
1872 | 2266 |
1873 // static res | 2267 // static res |
1874 | 2268 |
1875 #define COMMAND(x) { &AdlibDriver::x, #x } | 2269 #define COMMAND(x) { &AdlibDriver::x, #x } |
1876 | 2270 |
1877 void AdlibDriver::setupOpcodeList() { | 2271 void |
2272 AdlibDriver::setupOpcodeList () | |
2273 { | |
1878 static const OpcodeEntry opcodeList[] = { | 2274 static const OpcodeEntry opcodeList[] = { |
1879 COMMAND(snd_ret0x100), | 2275 COMMAND (snd_ret0x100), |
1880 COMMAND(snd_ret0x1983), | 2276 COMMAND (snd_ret0x1983), |
1881 COMMAND(snd_initDriver), | 2277 COMMAND (snd_initDriver), |
1882 COMMAND(snd_deinitDriver), | 2278 COMMAND (snd_deinitDriver), |
1883 COMMAND(snd_setSoundData), | 2279 COMMAND (snd_setSoundData), |
1884 COMMAND(snd_unkOpcode1), | 2280 COMMAND (snd_unkOpcode1), |
1885 COMMAND(snd_startSong), | 2281 COMMAND (snd_startSong), |
1886 COMMAND(snd_unkOpcode2), | 2282 COMMAND (snd_unkOpcode2), |
1887 COMMAND(snd_unkOpcode3), | 2283 COMMAND (snd_unkOpcode3), |
1888 COMMAND(snd_readByte), | 2284 COMMAND (snd_readByte), |
1889 COMMAND(snd_writeByte), | 2285 COMMAND (snd_writeByte), |
1890 COMMAND(snd_getSoundTrigger), | 2286 COMMAND (snd_getSoundTrigger), |
1891 COMMAND(snd_unkOpcode4), | 2287 COMMAND (snd_unkOpcode4), |
1892 COMMAND(snd_dummy), | 2288 COMMAND (snd_dummy), |
1893 COMMAND(snd_getNullvar4), | 2289 COMMAND (snd_getNullvar4), |
1894 COMMAND(snd_setNullvar3), | 2290 COMMAND (snd_setNullvar3), |
1895 COMMAND(snd_setFlag), | 2291 COMMAND (snd_setFlag), |
1896 COMMAND(snd_clearFlag) | 2292 COMMAND (snd_clearFlag) |
1897 }; | 2293 }; |
1898 | 2294 |
1899 _opcodeList = opcodeList; | 2295 _opcodeList = opcodeList; |
1900 _opcodesEntries = ARRAYSIZE(opcodeList); | 2296 _opcodesEntries = ARRAYSIZE (opcodeList); |
1901 } | 2297 } |
1902 | 2298 |
1903 void AdlibDriver::setupParserOpcodeTable() { | 2299 void |
2300 AdlibDriver::setupParserOpcodeTable () | |
2301 { | |
1904 static const ParserOpcode parserOpcodeTable[] = { | 2302 static const ParserOpcode parserOpcodeTable[] = { |
1905 // 0 | 2303 // 0 |
1906 COMMAND(update_setRepeat), | 2304 COMMAND (update_setRepeat), |
1907 COMMAND(update_checkRepeat), | 2305 COMMAND (update_checkRepeat), |
1908 COMMAND(update_setupProgram), | 2306 COMMAND (update_setupProgram), |
1909 COMMAND(update_setNoteSpacing), | 2307 COMMAND (update_setNoteSpacing), |
1910 | 2308 |
1911 // 4 | 2309 // 4 |
1912 COMMAND(update_jump), | 2310 COMMAND (update_jump), |
1913 COMMAND(update_jumpToSubroutine), | 2311 COMMAND (update_jumpToSubroutine), |
1914 COMMAND(update_returnFromSubroutine), | 2312 COMMAND (update_returnFromSubroutine), |
1915 COMMAND(update_setBaseOctave), | 2313 COMMAND (update_setBaseOctave), |
1916 | 2314 |
1917 // 8 | 2315 // 8 |
1918 COMMAND(update_stopChannel), | 2316 COMMAND (update_stopChannel), |
1919 COMMAND(update_playRest), | 2317 COMMAND (update_playRest), |
1920 COMMAND(update_writeAdlib), | 2318 COMMAND (update_writeAdlib), |
1921 COMMAND(update_setupNoteAndDuration), | 2319 COMMAND (update_setupNoteAndDuration), |
1922 | 2320 |
1923 // 12 | 2321 // 12 |
1924 COMMAND(update_setBaseNote), | 2322 COMMAND (update_setBaseNote), |
1925 COMMAND(update_setupSecondaryEffect1), | 2323 COMMAND (update_setupSecondaryEffect1), |
1926 COMMAND(update_stopOtherChannel), | 2324 COMMAND (update_stopOtherChannel), |
1927 COMMAND(update_waitForEndOfProgram), | 2325 COMMAND (update_waitForEndOfProgram), |
1928 | 2326 |
1929 // 16 | 2327 // 16 |
1930 COMMAND(update_setupInstrument), | 2328 COMMAND (update_setupInstrument), |
1931 COMMAND(update_setupPrimaryEffect1), | 2329 COMMAND (update_setupPrimaryEffect1), |
1932 COMMAND(update_removePrimaryEffect1), | 2330 COMMAND (update_removePrimaryEffect1), |
1933 COMMAND(update_setBaseFreq), | 2331 COMMAND (update_setBaseFreq), |
1934 | 2332 |
1935 // 20 | 2333 // 20 |
1936 COMMAND(update_stopChannel), | 2334 COMMAND (update_stopChannel), |
1937 COMMAND(update_setupPrimaryEffect2), | 2335 COMMAND (update_setupPrimaryEffect2), |
1938 COMMAND(update_stopChannel), | 2336 COMMAND (update_stopChannel), |
1939 COMMAND(update_stopChannel), | 2337 COMMAND (update_stopChannel), |
1940 | 2338 |
1941 // 24 | 2339 // 24 |
1942 COMMAND(update_stopChannel), | 2340 COMMAND (update_stopChannel), |
1943 COMMAND(update_stopChannel), | 2341 COMMAND (update_stopChannel), |
1944 COMMAND(update_setPriority), | 2342 COMMAND (update_setPriority), |
1945 COMMAND(update_stopChannel), | 2343 COMMAND (update_stopChannel), |
1946 | 2344 |
1947 // 28 | 2345 // 28 |
1948 COMMAND(updateCallback23), | 2346 COMMAND (updateCallback23), |
1949 COMMAND(updateCallback24), | 2347 COMMAND (updateCallback24), |
1950 COMMAND(update_setExtraLevel1), | 2348 COMMAND (update_setExtraLevel1), |
1951 COMMAND(update_stopChannel), | 2349 COMMAND (update_stopChannel), |
1952 | 2350 |
1953 // 32 | 2351 // 32 |
1954 COMMAND(update_setupDuration), | 2352 COMMAND (update_setupDuration), |
1955 COMMAND(update_playNote), | 2353 COMMAND (update_playNote), |
1956 COMMAND(update_stopChannel), | 2354 COMMAND (update_stopChannel), |
1957 COMMAND(update_stopChannel), | 2355 COMMAND (update_stopChannel), |
1958 | 2356 |
1959 // 36 | 2357 // 36 |
1960 COMMAND(update_setFractionalNoteSpacing), | 2358 COMMAND (update_setFractionalNoteSpacing), |
1961 COMMAND(update_stopChannel), | 2359 COMMAND (update_stopChannel), |
1962 COMMAND(update_setTempo), | 2360 COMMAND (update_setTempo), |
1963 COMMAND(update_removeSecondaryEffect1), | 2361 COMMAND (update_removeSecondaryEffect1), |
1964 | 2362 |
1965 // 40 | 2363 // 40 |
1966 COMMAND(update_stopChannel), | 2364 COMMAND (update_stopChannel), |
1967 COMMAND(update_setChannelTempo), | 2365 COMMAND (update_setChannelTempo), |
1968 COMMAND(update_stopChannel), | 2366 COMMAND (update_stopChannel), |
1969 COMMAND(update_setExtraLevel3), | 2367 COMMAND (update_setExtraLevel3), |
1970 | 2368 |
1971 // 44 | 2369 // 44 |
1972 COMMAND(update_setExtraLevel2), | 2370 COMMAND (update_setExtraLevel2), |
1973 COMMAND(update_changeExtraLevel2), | 2371 COMMAND (update_changeExtraLevel2), |
1974 COMMAND(update_setAMDepth), | 2372 COMMAND (update_setAMDepth), |
1975 COMMAND(update_setVibratoDepth), | 2373 COMMAND (update_setVibratoDepth), |
1976 | 2374 |
1977 // 48 | 2375 // 48 |
1978 COMMAND(update_changeExtraLevel1), | 2376 COMMAND (update_changeExtraLevel1), |
1979 COMMAND(update_stopChannel), | 2377 COMMAND (update_stopChannel), |
1980 COMMAND(update_stopChannel), | 2378 COMMAND (update_stopChannel), |
1981 COMMAND(updateCallback38), | 2379 COMMAND (updateCallback38), |
1982 | 2380 |
1983 // 52 | 2381 // 52 |
1984 COMMAND(update_stopChannel), | 2382 COMMAND (update_stopChannel), |
1985 COMMAND(updateCallback39), | 2383 COMMAND (updateCallback39), |
1986 COMMAND(update_removePrimaryEffect2), | 2384 COMMAND (update_removePrimaryEffect2), |
1987 COMMAND(update_stopChannel), | 2385 COMMAND (update_stopChannel), |
1988 | 2386 |
1989 // 56 | 2387 // 56 |
1990 COMMAND(update_stopChannel), | 2388 COMMAND (update_stopChannel), |
1991 COMMAND(updateCallback41), | 2389 COMMAND (updateCallback41), |
1992 COMMAND(update_resetToGlobalTempo), | 2390 COMMAND (update_resetToGlobalTempo), |
1993 COMMAND(update_nop1), | 2391 COMMAND (update_nop1), |
1994 | 2392 |
1995 // 60 | 2393 // 60 |
1996 COMMAND(update_setDurationRandomness), | 2394 COMMAND (update_setDurationRandomness), |
1997 COMMAND(update_changeChannelTempo), | 2395 COMMAND (update_changeChannelTempo), |
1998 COMMAND(update_stopChannel), | 2396 COMMAND (update_stopChannel), |
1999 COMMAND(updateCallback46), | 2397 COMMAND (updateCallback46), |
2000 | 2398 |
2001 // 64 | 2399 // 64 |
2002 COMMAND(update_nop2), | 2400 COMMAND (update_nop2), |
2003 COMMAND(update_setupRhythmSection), | 2401 COMMAND (update_setupRhythmSection), |
2004 COMMAND(update_playRhythmSection), | 2402 COMMAND (update_playRhythmSection), |
2005 COMMAND(update_removeRhythmSection), | 2403 COMMAND (update_removeRhythmSection), |
2006 | 2404 |
2007 // 68 | 2405 // 68 |
2008 COMMAND(updateCallback51), | 2406 COMMAND (updateCallback51), |
2009 COMMAND(updateCallback52), | 2407 COMMAND (updateCallback52), |
2010 COMMAND(updateCallback53), | 2408 COMMAND (updateCallback53), |
2011 COMMAND(update_setSoundTrigger), | 2409 COMMAND (update_setSoundTrigger), |
2012 | 2410 |
2013 // 72 | 2411 // 72 |
2014 COMMAND(update_setTempoReset), | 2412 COMMAND (update_setTempoReset), |
2015 COMMAND(updateCallback56), | 2413 COMMAND (updateCallback56), |
2016 COMMAND(update_stopChannel) | 2414 COMMAND (update_stopChannel) |
2017 }; | 2415 }; |
2018 | 2416 |
2019 _parserOpcodeTable = parserOpcodeTable; | 2417 _parserOpcodeTable = parserOpcodeTable; |
2020 _parserOpcodeTableSize = ARRAYSIZE(parserOpcodeTable); | 2418 _parserOpcodeTableSize = ARRAYSIZE (parserOpcodeTable); |
2021 } | 2419 } |
2420 | |
2022 #undef COMMAND | 2421 #undef COMMAND |
2023 | 2422 |
2024 // This table holds the register offset for operator 1 for each of the nine | 2423 // This table holds the register offset for operator 1 for each of the nine |
2025 // channels. To get the register offset for operator 2, simply add 3. | 2424 // channels. To get the register offset for operator 2, simply add 3. |
2026 | 2425 |
2027 const uint8 AdlibDriver::_regOffset[] = { | 2426 const uint8 |
2427 AdlibDriver::_regOffset[] = { | |
2028 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, | 2428 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, |
2029 0x12 | 2429 0x12 |
2030 }; | 2430 }; |
2031 | 2431 |
2032 // Given the size of this table, and the range of its values, it's probably the | 2432 // Given the size of this table, and the range of its values, it's probably the |
2033 // F-Numbers (10 bits) for the notes of the 12-tone scale. However, it does not | 2433 // F-Numbers (10 bits) for the notes of the 12-tone scale. However, it does not |
2034 // match the table in the Adlib documentation I've seen. | 2434 // match the table in the Adlib documentation I've seen. |
2035 | 2435 |
2036 const uint16 AdlibDriver::_unkTable[] = { | 2436 const uint16 |
2437 AdlibDriver::_unkTable[] = { | |
2037 0x0134, 0x0147, 0x015A, 0x016F, 0x0184, 0x019C, 0x01B4, 0x01CE, 0x01E9, | 2438 0x0134, 0x0147, 0x015A, 0x016F, 0x0184, 0x019C, 0x01B4, 0x01CE, 0x01E9, |
2038 0x0207, 0x0225, 0x0246 | 2439 0x0207, 0x0225, 0x0246 |
2039 }; | 2440 }; |
2040 | 2441 |
2041 // These tables are currently only used by updateCallback46(), which only ever | 2442 // These tables are currently only used by updateCallback46(), which only ever |
2042 // uses the first element of one of the sub-tables. | 2443 // uses the first element of one of the sub-tables. |
2043 | 2444 |
2044 const uint8 *AdlibDriver::_unkTable2[] = { | 2445 const uint8 * |
2446 AdlibDriver::_unkTable2[] = { | |
2045 AdlibDriver::_unkTable2_1, | 2447 AdlibDriver::_unkTable2_1, |
2046 AdlibDriver::_unkTable2_2, | 2448 AdlibDriver::_unkTable2_2, |
2047 AdlibDriver::_unkTable2_1, | 2449 AdlibDriver::_unkTable2_1, |
2048 AdlibDriver::_unkTable2_2, | 2450 AdlibDriver::_unkTable2_2, |
2049 AdlibDriver::_unkTable2_3, | 2451 AdlibDriver::_unkTable2_3, |
2050 AdlibDriver::_unkTable2_2 | 2452 AdlibDriver::_unkTable2_2 |
2051 }; | 2453 }; |
2052 | 2454 |
2053 const uint8 AdlibDriver::_unkTable2_1[] = { | 2455 const uint8 |
2456 AdlibDriver::_unkTable2_1[] = { | |
2054 0x50, 0x50, 0x4F, 0x4F, 0x4E, 0x4E, 0x4D, 0x4D, | 2457 0x50, 0x50, 0x4F, 0x4F, 0x4E, 0x4E, 0x4D, 0x4D, |
2055 0x4C, 0x4C, 0x4B, 0x4B, 0x4A, 0x4A, 0x49, 0x49, | 2458 0x4C, 0x4C, 0x4B, 0x4B, 0x4A, 0x4A, 0x49, 0x49, |
2056 0x48, 0x48, 0x47, 0x47, 0x46, 0x46, 0x45, 0x45, | 2459 0x48, 0x48, 0x47, 0x47, 0x46, 0x46, 0x45, 0x45, |
2057 0x44, 0x44, 0x43, 0x43, 0x42, 0x42, 0x41, 0x41, | 2460 0x44, 0x44, 0x43, 0x43, 0x42, 0x42, 0x41, 0x41, |
2058 0x40, 0x40, 0x3F, 0x3F, 0x3E, 0x3E, 0x3D, 0x3D, | 2461 0x40, 0x40, 0x3F, 0x3F, 0x3E, 0x3E, 0x3D, 0x3D, |
2069 0x14, 0x14, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, | 2472 0x14, 0x14, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, |
2070 0x10, 0x10 | 2473 0x10, 0x10 |
2071 }; | 2474 }; |
2072 | 2475 |
2073 // no don't ask me WHY this table exsits! | 2476 // no don't ask me WHY this table exsits! |
2074 const uint8 AdlibDriver::_unkTable2_2[] = { | 2477 const uint8 |
2478 AdlibDriver::_unkTable2_2[] = { | |
2075 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 2479 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
2076 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | 2480 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
2077 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 2481 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
2078 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, | 2482 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, |
2079 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 2483 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
2088 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, | 2492 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, |
2089 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | 2493 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
2090 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F | 2494 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F |
2091 }; | 2495 }; |
2092 | 2496 |
2093 const uint8 AdlibDriver::_unkTable2_3[] = { | 2497 const uint8 |
2498 AdlibDriver::_unkTable2_3[] = { | |
2094 0x40, 0x40, 0x40, 0x3F, 0x3F, 0x3F, 0x3E, 0x3E, | 2499 0x40, 0x40, 0x40, 0x3F, 0x3F, 0x3F, 0x3E, 0x3E, |
2095 0x3E, 0x3D, 0x3D, 0x3D, 0x3C, 0x3C, 0x3C, 0x3B, | 2500 0x3E, 0x3D, 0x3D, 0x3D, 0x3C, 0x3C, 0x3C, 0x3B, |
2096 0x3B, 0x3B, 0x3A, 0x3A, 0x3A, 0x39, 0x39, 0x39, | 2501 0x3B, 0x3B, 0x3A, 0x3A, 0x3A, 0x39, 0x39, 0x39, |
2097 0x38, 0x38, 0x38, 0x37, 0x37, 0x37, 0x36, 0x36, | 2502 0x38, 0x38, 0x38, 0x37, 0x37, 0x37, 0x36, 0x36, |
2098 0x36, 0x35, 0x35, 0x35, 0x34, 0x34, 0x34, 0x33, | 2503 0x36, 0x35, 0x35, 0x35, 0x34, 0x34, 0x34, 0x33, |
2115 // outside this table, but in reality that probably won't happen. | 2520 // outside this table, but in reality that probably won't happen. |
2116 // | 2521 // |
2117 // This could be some sort of pitch bend, but I have yet to see it used for | 2522 // This could be some sort of pitch bend, but I have yet to see it used for |
2118 // anything so it's hard to say. | 2523 // anything so it's hard to say. |
2119 | 2524 |
2120 const uint8 AdlibDriver::_unkTables[][32] = { | 2525 const uint8 |
2526 AdlibDriver::_unkTables[][32] = { | |
2121 // 0 | 2527 // 0 |
2122 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, | 2528 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, |
2123 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, | 2529 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, |
2124 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x19, | 2530 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x19, |
2125 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21 }, | 2531 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21}, |
2126 // 1 | 2532 // 1 |
2127 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x07, 0x09, | 2533 {0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x07, 0x09, |
2128 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, | 2534 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, |
2129 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x1A, | 2535 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x1A, |
2130 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x22, 0x24 }, | 2536 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x22, 0x24}, |
2131 // 2 | 2537 // 2 |
2132 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x09, | 2538 {0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x09, |
2133 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12, 0x13, | 2539 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12, 0x13, |
2134 0x14, 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1C, 0x1D, | 2540 0x14, 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1C, 0x1D, |
2135 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x24, 0x25, 0x26 }, | 2541 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x24, 0x25, 0x26}, |
2136 // 3 | 2542 // 3 |
2137 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, | 2543 {0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, |
2138 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12, 0x13, | 2544 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12, 0x13, |
2139 0x14, 0x15, 0x16, 0x17, 0x18, 0x1A, 0x1C, 0x1D, | 2545 0x14, 0x15, 0x16, 0x17, 0x18, 0x1A, 0x1C, 0x1D, |
2140 0x1E, 0x1F, 0x20, 0x21, 0x23, 0x25, 0x27, 0x28 }, | 2546 0x1E, 0x1F, 0x20, 0x21, 0x23, 0x25, 0x27, 0x28}, |
2141 // 4 | 2547 // 4 |
2142 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, | 2548 {0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x08, 0x0A, |
2143 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x13, 0x15, | 2549 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x13, 0x15, |
2144 0x16, 0x17, 0x18, 0x19, 0x1B, 0x1D, 0x1F, 0x20, | 2550 0x16, 0x17, 0x18, 0x19, 0x1B, 0x1D, 0x1F, 0x20, |
2145 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x2A }, | 2551 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x28, 0x2A}, |
2146 // 5 | 2552 // 5 |
2147 { 0x00, 0x01, 0x02, 0x03, 0x05, 0x07, 0x09, 0x0B, | 2553 {0x00, 0x01, 0x02, 0x03, 0x05, 0x07, 0x09, 0x0B, |
2148 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, | 2554 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, |
2149 0x16, 0x17, 0x18, 0x19, 0x1B, 0x1D, 0x1F, 0x20, | 2555 0x16, 0x17, 0x18, 0x19, 0x1B, 0x1D, 0x1F, 0x20, |
2150 0x21, 0x22, 0x23, 0x25, 0x27, 0x29, 0x2B, 0x2D }, | 2556 0x21, 0x22, 0x23, 0x25, 0x27, 0x29, 0x2B, 0x2D}, |
2151 // 6 | 2557 // 6 |
2152 { 0x00, 0x01, 0x02, 0x03, 0x05, 0x07, 0x09, 0x0B, | 2558 {0x00, 0x01, 0x02, 0x03, 0x05, 0x07, 0x09, 0x0B, |
2153 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, | 2559 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, |
2154 0x16, 0x17, 0x18, 0x1A, 0x1C, 0x1E, 0x21, 0x24, | 2560 0x16, 0x17, 0x18, 0x1A, 0x1C, 0x1E, 0x21, 0x24, |
2155 0x25, 0x26, 0x27, 0x29, 0x2B, 0x2D, 0x2F, 0x30 }, | 2561 0x25, 0x26, 0x27, 0x29, 0x2B, 0x2D, 0x2F, 0x30}, |
2156 // 7 | 2562 // 7 |
2157 { 0x00, 0x01, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, | 2563 {0x00, 0x01, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, |
2158 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, 0x18, | 2564 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x15, 0x18, |
2159 0x19, 0x1A, 0x1C, 0x1D, 0x1F, 0x21, 0x23, 0x25, | 2565 0x19, 0x1A, 0x1C, 0x1D, 0x1F, 0x21, 0x23, 0x25, |
2160 0x26, 0x27, 0x29, 0x2B, 0x2D, 0x2F, 0x30, 0x32 }, | 2566 0x26, 0x27, 0x29, 0x2B, 0x2D, 0x2F, 0x30, 0x32}, |
2161 // 8 | 2567 // 8 |
2162 { 0x00, 0x01, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0D, | 2568 {0x00, 0x01, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0D, |
2163 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x14, 0x17, 0x1A, | 2569 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x14, 0x17, 0x1A, |
2164 0x19, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x25, 0x28, | 2570 0x19, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x25, 0x28, |
2165 0x29, 0x2A, 0x2B, 0x2D, 0x2F, 0x31, 0x33, 0x35 }, | 2571 0x29, 0x2A, 0x2B, 0x2D, 0x2F, 0x31, 0x33, 0x35}, |
2166 // 9 | 2572 // 9 |
2167 { 0x00, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0E, | 2573 {0x00, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0E, |
2168 0x0F, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1B, | 2574 0x0F, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1B, |
2169 0x1C, 0x1D, 0x1E, 0x20, 0x22, 0x24, 0x26, 0x29, | 2575 0x1C, 0x1D, 0x1E, 0x20, 0x22, 0x24, 0x26, 0x29, |
2170 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x39 }, | 2576 0x2A, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x39}, |
2171 // 10 | 2577 // 10 |
2172 { 0x00, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0E, | 2578 {0x00, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0E, |
2173 0x0F, 0x10, 0x12, 0x14, 0x16, 0x19, 0x1B, 0x1E, | 2579 0x0F, 0x10, 0x12, 0x14, 0x16, 0x19, 0x1B, 0x1E, |
2174 0x1F, 0x21, 0x23, 0x25, 0x27, 0x29, 0x2B, 0x2D, | 2580 0x1F, 0x21, 0x23, 0x25, 0x27, 0x29, 0x2B, 0x2D, |
2175 0x2E, 0x2F, 0x31, 0x32, 0x34, 0x36, 0x39, 0x3C }, | 2581 0x2E, 0x2F, 0x31, 0x32, 0x34, 0x36, 0x39, 0x3C}, |
2176 // 11 | 2582 // 11 |
2177 { 0x00, 0x01, 0x03, 0x05, 0x07, 0x0A, 0x0C, 0x0F, | 2583 {0x00, 0x01, 0x03, 0x05, 0x07, 0x0A, 0x0C, 0x0F, |
2178 0x10, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1E, | 2584 0x10, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1E, |
2179 0x1F, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2B, 0x2E, | 2585 0x1F, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2B, 0x2E, |
2180 0x2F, 0x30, 0x32, 0x34, 0x36, 0x39, 0x3C, 0x3F }, | 2586 0x2F, 0x30, 0x32, 0x34, 0x36, 0x39, 0x3C, 0x3F}, |
2181 // 12 | 2587 // 12 |
2182 { 0x00, 0x02, 0x04, 0x06, 0x08, 0x0B, 0x0D, 0x10, | 2588 {0x00, 0x02, 0x04, 0x06, 0x08, 0x0B, 0x0D, 0x10, |
2183 0x11, 0x12, 0x14, 0x16, 0x18, 0x1B, 0x1E, 0x21, | 2589 0x11, 0x12, 0x14, 0x16, 0x18, 0x1B, 0x1E, 0x21, |
2184 0x22, 0x23, 0x25, 0x27, 0x29, 0x2C, 0x2F, 0x32, | 2590 0x22, 0x23, 0x25, 0x27, 0x29, 0x2C, 0x2F, 0x32, |
2185 0x33, 0x34, 0x36, 0x38, 0x3B, 0x34, 0x41, 0x44 }, | 2591 0x33, 0x34, 0x36, 0x38, 0x3B, 0x34, 0x41, 0x44}, |
2186 // 13 | 2592 // 13 |
2187 { 0x00, 0x02, 0x04, 0x06, 0x08, 0x0B, 0x0D, 0x11, | 2593 {0x00, 0x02, 0x04, 0x06, 0x08, 0x0B, 0x0D, 0x11, |
2188 0x12, 0x13, 0x15, 0x17, 0x1A, 0x1D, 0x20, 0x23, | 2594 0x12, 0x13, 0x15, 0x17, 0x1A, 0x1D, 0x20, 0x23, |
2189 0x24, 0x25, 0x27, 0x29, 0x2C, 0x2F, 0x32, 0x35, | 2595 0x24, 0x25, 0x27, 0x29, 0x2C, 0x2F, 0x32, 0x35, |
2190 0x36, 0x37, 0x39, 0x3B, 0x3E, 0x41, 0x44, 0x47 } | 2596 0x36, 0x37, 0x39, 0x3B, 0x3E, 0x41, 0x44, 0x47} |
2191 }; | 2597 }; |
2192 | 2598 |
2193 // #pragma mark - | 2599 // #pragma mark - |
2194 | 2600 |
2195 // At the time of writing, the only known case where Kyra 1 uses sound triggers | 2601 // At the time of writing, the only known case where Kyra 1 uses sound triggers |
2196 // is in the castle, to cycle between three different songs. | 2602 // is in the castle, to cycle between three different songs. |
2197 | 2603 |
2198 const int CadlPlayer::_kyra1SoundTriggers[] = { | 2604 const int |
2605 CadlPlayer::_kyra1SoundTriggers[] = { | |
2199 0, 4, 5, 3 | 2606 0, 4, 5, 3 |
2200 }; | 2607 }; |
2201 | 2608 |
2202 const int CadlPlayer::_kyra1NumSoundTriggers = ARRAYSIZE(CadlPlayer::_kyra1SoundTriggers); | 2609 const int |
2203 | 2610 CadlPlayer::_kyra1NumSoundTriggers = |
2204 CadlPlayer::CadlPlayer(Copl *newopl) | 2611 ARRAYSIZE (CadlPlayer::_kyra1SoundTriggers); |
2205 : CPlayer(newopl), numsubsongs(0), _trackEntries(), _soundDataPtr(0) | 2612 |
2206 { | 2613 CadlPlayer::CadlPlayer (Copl * newopl):CPlayer (newopl), numsubsongs (0), _trackEntries (), |
2207 memset(_trackEntries, 0, sizeof(_trackEntries)); | 2614 _soundDataPtr (0) |
2208 _driver = new AdlibDriver(newopl); | 2615 { |
2209 assert(_driver); | 2616 memset (_trackEntries, 0, sizeof (_trackEntries)); |
2617 _driver = new AdlibDriver (newopl); | |
2618 assert (_driver); | |
2210 | 2619 |
2211 _sfxPlayingSound = -1; | 2620 _sfxPlayingSound = -1; |
2212 // _soundFileLoaded = ""; | 2621 // _soundFileLoaded = ""; |
2213 | 2622 |
2214 _soundTriggers = _kyra1SoundTriggers; | 2623 _soundTriggers = _kyra1SoundTriggers; |
2215 _numSoundTriggers = _kyra1NumSoundTriggers; | 2624 _numSoundTriggers = _kyra1NumSoundTriggers; |
2216 | 2625 |
2217 init(); | 2626 init (); |
2218 } | 2627 } |
2219 | 2628 |
2220 CadlPlayer::~CadlPlayer() { | 2629 CadlPlayer::~CadlPlayer () |
2221 delete [] _soundDataPtr; _soundDataPtr = 0; | 2630 { |
2222 delete _driver; _driver = 0; | 2631 delete[]_soundDataPtr; |
2223 } | 2632 _soundDataPtr = 0; |
2224 | 2633 delete _driver; |
2225 bool CadlPlayer::init() { | 2634 _driver = 0; |
2226 _driver->callback(2); | 2635 } |
2227 _driver->callback(16, int(4)); | 2636 |
2637 bool | |
2638 CadlPlayer::init () | |
2639 { | |
2640 _driver->callback (2); | |
2641 _driver->callback (16, int (4)); | |
2228 return true; | 2642 return true; |
2229 } | 2643 } |
2230 | 2644 |
2231 void CadlPlayer::process() { | 2645 void |
2232 uint8 trigger = _driver->callback(11); | 2646 CadlPlayer::process () |
2233 | 2647 { |
2234 if (trigger < _numSoundTriggers) { | 2648 uint8 trigger = _driver->callback (11); |
2649 | |
2650 if (trigger < _numSoundTriggers) | |
2651 { | |
2235 int soundId = _soundTriggers[trigger]; | 2652 int soundId = _soundTriggers[trigger]; |
2236 | 2653 |
2237 if (soundId) { | 2654 if (soundId) |
2238 playTrack(soundId); | 2655 { |
2656 playTrack (soundId); | |
2239 } | 2657 } |
2240 } else { | 2658 } |
2241 warning("Unknown sound trigger %d", trigger); | 2659 else |
2660 { | |
2661 warning ("Unknown sound trigger %d", trigger); | |
2242 // TODO: At this point, we really want to clear the trigger... | 2662 // TODO: At this point, we really want to clear the trigger... |
2243 } | 2663 } |
2244 } | 2664 } |
2245 | 2665 |
2246 // void CadlPlayer::setVolume(int volume) { | 2666 // void CadlPlayer::setVolume(int volume) { |
2247 // } | 2667 // } |
2248 | 2668 |
2249 // int CadlPlayer::getVolume() { | 2669 // int CadlPlayer::getVolume() { |
2250 // return 0; | 2670 // return 0; |
2251 // } | 2671 // } |
2252 | 2672 |
2253 // void CadlPlayer::loadMusicFile(const char *file) { | 2673 // void CadlPlayer::loadMusicFile(const char *file) { |
2254 // loadSoundFile(file); | 2674 // loadSoundFile(file); |
2255 // } | 2675 // } |
2256 | 2676 |
2257 void CadlPlayer::playTrack(uint8 track) { | 2677 void |
2258 play(track); | 2678 CadlPlayer::playTrack (uint8 track) |
2679 { | |
2680 play (track); | |
2259 } | 2681 } |
2260 | 2682 |
2261 // void CadlPlayer::haltTrack() { | 2683 // void CadlPlayer::haltTrack() { |
2262 // unk1(); | 2684 // unk1(); |
2263 // unk2(); | 2685 // unk2(); |
2264 // //_engine->_system->delayMillis(3 * 60); | 2686 // //_engine->_system->delayMillis(3 * 60); |
2265 // } | 2687 // } |
2266 | 2688 |
2267 void CadlPlayer::playSoundEffect(uint8_t track) { | 2689 void |
2268 play(track); | 2690 CadlPlayer::playSoundEffect (uint8_t track) |
2269 } | 2691 { |
2270 | 2692 play (track); |
2271 void CadlPlayer::play(uint8_t track) { | 2693 } |
2694 | |
2695 void | |
2696 CadlPlayer::play (uint8_t track) | |
2697 { | |
2272 uint8 soundId = _trackEntries[track]; | 2698 uint8 soundId = _trackEntries[track]; |
2273 if ((int8)soundId == -1 || !_soundDataPtr) | 2699 if ((int8) soundId == -1 || !_soundDataPtr) |
2274 return; | 2700 return; |
2275 soundId &= 0xFF; | 2701 soundId &= 0xFF; |
2276 _driver->callback(16, 0); | 2702 _driver->callback (16, 0); |
2277 // while ((_driver->callback(16, 0) & 8)) { | 2703 // while ((_driver->callback(16, 0) & 8)) { |
2278 // We call the system delay and not the game delay to avoid concurrency issues. | 2704 // We call the system delay and not the game delay to avoid concurrency issues. |
2279 // _engine->_system->delayMillis(10); | 2705 // _engine->_system->delayMillis(10); |
2280 // } | 2706 // } |
2281 if (_sfxPlayingSound != -1) { | 2707 if (_sfxPlayingSound != -1) |
2708 { | |
2282 // Restore the sounds's normal values. | 2709 // Restore the sounds's normal values. |
2283 _driver->callback(10, _sfxPlayingSound, int(1), int(_sfxPriority)); | 2710 _driver->callback (10, _sfxPlayingSound, int (1), int (_sfxPriority)); |
2284 _driver->callback(10, _sfxPlayingSound, int(3), int(_sfxFourthByteOfSong)); | 2711 _driver->callback (10, _sfxPlayingSound, int (3), |
2712 int (_sfxFourthByteOfSong)); | |
2285 _sfxPlayingSound = -1; | 2713 _sfxPlayingSound = -1; |
2286 } | 2714 } |
2287 | 2715 |
2288 int chan = _driver->callback(9, soundId, int(0)); | 2716 int chan = _driver->callback (9, soundId, int (0)); |
2289 | 2717 |
2290 if (chan != 9) { | 2718 if (chan != 9) |
2719 { | |
2291 _sfxPlayingSound = soundId; | 2720 _sfxPlayingSound = soundId; |
2292 _sfxPriority = _driver->callback(9, soundId, int(1)); | 2721 _sfxPriority = _driver->callback (9, soundId, int (1)); |
2293 _sfxFourthByteOfSong = _driver->callback(9, soundId, int(3)); | 2722 _sfxFourthByteOfSong = _driver->callback (9, soundId, int (3)); |
2294 | 2723 |
2295 // In the cases I've seen, the mysterious fourth byte has been | 2724 // In the cases I've seen, the mysterious fourth byte has been |
2296 // the parameter for the update_setExtraLevel3() callback. | 2725 // the parameter for the update_setExtraLevel3() callback. |
2297 // | 2726 // |
2298 // The extra level is part of the channels "total level", which | 2727 // The extra level is part of the channels "total level", which |
2303 // and a slightly higher (i.e. softer) extra level 3 than they | 2732 // and a slightly higher (i.e. softer) extra level 3 than they |
2304 // would have if they were started from anywhere else. Strange. | 2733 // would have if they were started from anywhere else. Strange. |
2305 | 2734 |
2306 int newVal = ((((-_sfxFourthByteOfSong) + 63) * 0xFF) >> 8) & 0xFF; | 2735 int newVal = ((((-_sfxFourthByteOfSong) + 63) * 0xFF) >> 8) & 0xFF; |
2307 newVal = -newVal + 63; | 2736 newVal = -newVal + 63; |
2308 _driver->callback(10, soundId, int(3), newVal); | 2737 _driver->callback (10, soundId, int (3), newVal); |
2309 newVal = ((_sfxPriority * 0xFF) >> 8) & 0xFF; | 2738 newVal = ((_sfxPriority * 0xFF) >> 8) & 0xFF; |
2310 _driver->callback(10, soundId, int(1), newVal); | 2739 _driver->callback (10, soundId, int (1), newVal); |
2311 } | 2740 } |
2312 | 2741 |
2313 _driver->callback(6, soundId); | 2742 _driver->callback (6, soundId); |
2314 } | 2743 } |
2315 | 2744 |
2316 // void CadlPlayer::beginFadeOut() { | 2745 // void CadlPlayer::beginFadeOut() { |
2317 // playSoundEffect(1); | 2746 // playSoundEffect(1); |
2318 // } | 2747 // } |
2319 | 2748 |
2320 bool CadlPlayer::load(VFSFile *fd, const CFileProvider &fp) | 2749 bool |
2321 { | 2750 CadlPlayer::load (VFSFile * fd, const CFileProvider & fp) |
2322 binistream *f = fp.open(fd); | 2751 { |
2323 std::string filename(fd->uri); | 2752 binistream *f = fp.open (fd); |
2753 std::string filename (fd->uri); | |
2324 | 2754 |
2325 // file validation section | 2755 // file validation section |
2326 if(!f || !fp.extension(filename, ".adl")) { | 2756 if (!f || !fp.extension (filename, ".adl")) |
2327 fp.close(f); | 2757 { |
2758 fp.close (f); | |
2328 return false; | 2759 return false; |
2329 } | 2760 } |
2330 | 2761 |
2331 // if (_soundFileLoaded == file) | 2762 // if (_soundFileLoaded == file) |
2332 // return; | 2763 // return; |
2333 | 2764 |
2334 // if (_soundDataPtr) { | 2765 // if (_soundDataPtr) { |
2335 // haltTrack(); | 2766 // haltTrack(); |
2336 // } | 2767 // } |
2337 | 2768 |
2338 uint8 *file_data = 0; uint32 file_size = 0; | 2769 uint8 *file_data = 0; |
2339 | 2770 uint32 file_size = 0; |
2340 // char filename[25]; | 2771 |
2341 // sprintf(filename, "%s.ADL", file); | 2772 // char filename[25]; |
2342 | 2773 // sprintf(filename, "%s.ADL", file); |
2343 // file_data = _engine->resource()->fileData(filename, &file_size); | 2774 |
2344 // if (!file_data) { | 2775 // file_data = _engine->resource()->fileData(filename, &file_size); |
2345 // warning("Couldn't find music file: '%s'", filename); | 2776 // if (!file_data) { |
2346 // return; | 2777 // warning("Couldn't find music file: '%s'", filename); |
2347 // } | 2778 // return; |
2348 | 2779 // } |
2349 unk2(); | 2780 |
2350 unk1(); | 2781 unk2 (); |
2351 | 2782 unk1 (); |
2352 file_size = fp.filesize(f); | 2783 |
2353 file_data = new uint8 [file_size]; | 2784 file_size = fp.filesize (f); |
2354 f->readString((char *)file_data, file_size); | 2785 file_data = new uint8[file_size]; |
2355 | 2786 f->readString ((char *) file_data, file_size); |
2356 _driver->callback(8, int(-1)); | 2787 |
2788 _driver->callback (8, int (-1)); | |
2357 _soundDataPtr = 0; | 2789 _soundDataPtr = 0; |
2358 | 2790 |
2359 uint8 *p = file_data; | 2791 uint8 *p = file_data; |
2360 memcpy(_trackEntries, p, 120*sizeof(uint8)); | 2792 memcpy (_trackEntries, p, 120 * sizeof (uint8)); |
2361 p += 120; | 2793 p += 120; |
2362 | 2794 |
2363 int soundDataSize = file_size - 120; | 2795 int soundDataSize = file_size - 120; |
2364 | 2796 |
2365 _soundDataPtr = new uint8[soundDataSize]; | 2797 _soundDataPtr = new uint8[soundDataSize]; |
2366 assert(_soundDataPtr); | 2798 assert (_soundDataPtr); |
2367 | 2799 |
2368 memcpy(_soundDataPtr, p, soundDataSize*sizeof(uint8)); | 2800 memcpy (_soundDataPtr, p, soundDataSize * sizeof (uint8)); |
2369 | 2801 |
2370 delete [] file_data; | 2802 delete[]file_data; |
2371 file_data = p = 0; | 2803 file_data = p = 0; |
2372 file_size = 0; | 2804 file_size = 0; |
2373 | 2805 |
2374 _driver->callback(4, _soundDataPtr); | 2806 _driver->callback (4, _soundDataPtr); |
2375 | 2807 |
2376 // _soundFileLoaded = file; | 2808 // _soundFileLoaded = file; |
2377 | 2809 |
2378 for(int i = 0; i < 200; i++) | 2810 for (int i = 0; i < 200; i++) |
2379 if(_trackEntries[i] != 0xff) | 2811 if (_trackEntries[i] != 0xff) |
2380 numsubsongs = i + 1; | 2812 numsubsongs = i + 1; |
2381 | 2813 |
2382 fp.close(f); | 2814 fp.close (f); |
2383 return true; | 2815 return true; |
2384 } | 2816 } |
2385 | 2817 |
2386 void CadlPlayer::rewind(int subsong) | 2818 void |
2387 { | 2819 CadlPlayer::rewind (int subsong) |
2388 opl->init(); | 2820 { |
2389 opl->write(1,32); | 2821 opl->init (); |
2390 playSoundEffect(subsong); | 2822 opl->write (1, 32); |
2823 playSoundEffect (subsong); | |
2391 cursubsong = subsong; | 2824 cursubsong = subsong; |
2392 update(); | 2825 update (); |
2393 } | 2826 } |
2394 | 2827 |
2395 unsigned int CadlPlayer::getsubsongs() | 2828 unsigned int |
2829 CadlPlayer::getsubsongs () | |
2396 { | 2830 { |
2397 return numsubsongs; | 2831 return numsubsongs; |
2398 } | 2832 } |
2399 | 2833 |
2400 bool CadlPlayer::update() | 2834 bool |
2835 CadlPlayer::update () | |
2401 { | 2836 { |
2402 bool songend = true; | 2837 bool songend = true; |
2403 | 2838 |
2404 // if(_trackEntries[cursubsong] == 0xff) | 2839 // if(_trackEntries[cursubsong] == 0xff) |
2405 // return false; | 2840 // return false; |
2406 | 2841 |
2407 _driver->callback(); | 2842 _driver->callback (); |
2408 | 2843 |
2409 for(int i = 0; i < 10; i++) | 2844 for (int i = 0; i < 10; i++) |
2410 if(_driver->_channels[i].dataptr != NULL) | 2845 if (_driver->_channels[i].dataptr != NULL) |
2411 songend = false; | 2846 songend = false; |
2412 | 2847 |
2413 return !songend; | 2848 return !songend; |
2414 } | 2849 } |
2415 | 2850 |
2416 void CadlPlayer::unk1() { | 2851 void |
2417 playSoundEffect(0); | 2852 CadlPlayer::unk1 () |
2853 { | |
2854 playSoundEffect (0); | |
2418 //_engine->_system->delayMillis(5 * 60); | 2855 //_engine->_system->delayMillis(5 * 60); |
2419 } | 2856 } |
2420 | 2857 |
2421 void CadlPlayer::unk2() { | 2858 void |
2422 playSoundEffect(0); | 2859 CadlPlayer::unk2 () |
2423 } | 2860 { |
2424 | 2861 playSoundEffect (0); |
2425 CPlayer *CadlPlayer::factory(Copl *newopl) | 2862 } |
2426 { | 2863 |
2427 return new CadlPlayer(newopl); | 2864 CPlayer * |
2428 } | 2865 CadlPlayer::factory (Copl * newopl) |
2866 { | |
2867 return new CadlPlayer (newopl); | |
2868 } |