Debian Codegraph @

src/engine/platform/sms.cpp

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "sms.h"
21 #include "../engine.h"
22 #include "../../ta-log.h"
23 #include <math.h>
24
25 #define rWrite(a,v) {if (!skipRegisterWrites) {writes.push(QueuedWrite(a,v)); if (dumpWrites) {addWrite(a,v);}}}
26
27 const char* regCheatSheetSN[]={
28 "DATA", "0",
29 NULL
30 };
31
32 const char* regCheatSheetGG[]={
33 "DATA", "0",
34 "Stereo", "1",
35 NULL
36 };
37
38 const char** DivPlatformSMS::getRegisterSheet() {
39 return stereo?regCheatSheetGG:regCheatSheetSN;
40 }
41
42 float DivPlatformSMS::getPostAmp() {
43 return 1.5f;
44 }
45
46 void DivPlatformSMS::poolWrite(unsigned short a, unsigned char v) {
47 if (a) {
48 regPool[9]=v;
49 } else {
50 if (v>=0x80) {
51 regPool[(v>>4)&7]&=~15;
52 regPool[(v>>4)&7]|=v&15;
53 chanLatch=(v>>5)&3;
54 } else {
55 regPool[chanLatch<<1]&=15;
56 regPool[chanLatch<<1]|=((v&15)<<4);
57 regPool[1+(chanLatch<<1)]&=15;
58 regPool[1+(chanLatch<<1)]|=v&0xf0;
59 }
60 }
61 }
62
63 void DivPlatformSMS::acquire_nuked(short** buf, size_t len) {
64 int oL=0;
65 int oR=0;
66
67 for (int i=0; i<4; i++) {
68 oscBuf[i]->begin(len);
69 }
70
71 for (size_t h=0; h<len; h++) {
72 if (!writes.empty()) {
73 QueuedWrite w=writes.front();
74 if (w.addr==0) {
75 YMPSG_Write(&sn_nuked,w.val);
76 } else if (w.addr==1) {
77 YMPSG_WriteStereo(&sn_nuked,w.val);
78 }
79
80 poolWrite(w.addr,w.val);
81
82 writes.pop();
83 }
84 YMPSG_Clock(&sn_nuked);
85 YMPSG_Clock(&sn_nuked);
86 YMPSG_Clock(&sn_nuked);
87 YMPSG_Clock(&sn_nuked);
88 YMPSG_Clock(&sn_nuked);
89 YMPSG_Clock(&sn_nuked);
90 YMPSG_Clock(&sn_nuked);
91 YMPSG_Clock(&sn_nuked);
92 YMPSG_Clock(&sn_nuked);
93 YMPSG_Clock(&sn_nuked);
94 YMPSG_Clock(&sn_nuked);
95 YMPSG_Clock(&sn_nuked);
96 YMPSG_Clock(&sn_nuked);
97 YMPSG_Clock(&sn_nuked);
98 YMPSG_Clock(&sn_nuked);
99 YMPSG_Clock(&sn_nuked);
100 YMPSG_GetOutput(&sn_nuked,&oL,&oR);
101 if (oL<-32768) oL=-32768;
102 if (oL>32767) oL=32767;
103 if (oR<-32768) oR=-32768;
104 if (oR>32767) oR=32767;
105 buf[0][h]=oL;
106 if (stereo) buf[1][h]=oR;
107 for (int i=0; i<4; i++) {
108 if (isMuted[i]) {
109 oscBuf[i]->putSample(h,0);
110 } else {
111 oscBuf[i]->putSample(h,sn_nuked.vol_table[sn_nuked.volume_out[i]]*3);
112 }
113 }
114 }
115
116 for (int i=0; i<4; i++) {
117 oscBuf[i]->end(len);
118 }
119 }
120
121 void DivPlatformSMS::acquire_mame(blip_buffer_t** bb, size_t len) {
122 thread_local short outs[2];
123
124 while (!writes.empty()) {
125 QueuedWrite w=writes.front();
126 if (stereo && (w.addr==1))
127 sn->stereo_w(w.val);
128 else if (w.addr==0) {
129 sn->write(w.val);
130 }
131
132 poolWrite(w.addr,w.val);
133
134 writes.pop();
135 }
136
137 for (int i=0; i<4; i++) {
138 oscBuf[i]->begin(len);
139 }
140
141 for (size_t h=0; h<len; h++) {
142 // wahahaha heuristic...
143 int advance=len-h;
144 for (int i=0; i<4; i++) {
145 if (sn->m_count[i]<advance) advance=sn->m_count[i];
146 }
147 if (advance<1) advance=1;
148
149 sn->sound_stream_update(outs,advance);
150
151 h+=advance-1;
152
153 if (outs[0]!=lastOut[0]) {
154 blip_add_delta(bb[0],h,outs[0]-lastOut[0]);
155 lastOut[0]=outs[0];
156 }
157 if (stereo) {
158 if (outs[1]!=lastOut[1]) {
159 blip_add_delta(bb[1],h,outs[1]-lastOut[1]);
160 lastOut[1]=outs[1];
161 }
162 }
163
164 for (int i=0; i<4; i++) {
165 if (isMuted[i]) {
166 oscBuf[i]->putSample(h,0);
167 } else {
168 oscBuf[i]->putSample(h,sn->get_channel_output(i)*3);
169 }
170 }
171 }
172
173 for (int i=0; i<4; i++) {
174 oscBuf[i]->end(len);
175 }
176 }
177
178 void DivPlatformSMS::acquire(short** buf, size_t len) {
179 if (nuked) {
180 acquire_nuked(buf,len);
181 }
182 }
183
184 void DivPlatformSMS::acquireDirect(blip_buffer_t** bb, size_t len) {
185 if (nuked) return;
186 acquire_mame(bb,len);
187 }
188
189 double DivPlatformSMS::NOTE_SN(int ch, int note) {
190 double CHIP_DIVIDER=toneDivider;
191 if (ch==3) CHIP_DIVIDER=noiseDivider;
192 if (parent->song.linearPitch==2 || !easyNoise) {
193 return NOTE_PERIODIC(note);
194 }
195 int easyStartingPeriod=16;
196 int easyThreshold=round(12.0*log((chipClock/(easyStartingPeriod*CHIP_DIVIDER))/(0.0625*parent->song.tuning))/log(2.0))-3;
197 if (note>easyThreshold) {
198 return MAX(0,easyStartingPeriod-(note-easyThreshold));
199 }
200 return NOTE_PERIODIC(note);
201 }
202
203 int DivPlatformSMS::snCalcFreq(int ch) {
204 double CHIP_DIVIDER=toneDivider;
205 if (ch==3) CHIP_DIVIDER=noiseDivider;
206 int easyStartingPeriod=16;
207 int easyThreshold=round(128.0*12.0*log((chipClock/(easyStartingPeriod*CHIP_DIVIDER))/(0.0625*parent->song.tuning))/log(2.0))-384+64;
208 int curFreq=chan[ch].baseFreq+chan[ch].pitch+chan[ch].pitch2+(chan[ch].arpOff<<7);
209 if (chan[ch].fixedArp) {
210 curFreq=chan[ch].baseNoteOverride<<7;
211 }
212 if (parent->song.linearPitch==2 && easyNoise && curFreq>easyThreshold) {
213 int ret=(((easyStartingPeriod<<7))-(curFreq-(easyThreshold)))>>7;
214 if (ret<0) ret=0;
215 return ret;
216 }
217 return parent->calcFreq(chan[ch].baseFreq,chan[ch].pitch,chan[ch].fixedArp?chan[ch].baseNoteOverride:chan[ch].arpOff,chan[ch].fixedArp,true,0,chan[ch].pitch2,chipClock,CHIP_DIVIDER);
218 }
219
220 void DivPlatformSMS::tick(bool sysTick) {
221 for (int i=0; i<4; i++) {
222 chan[i].std.next();
223 if (chan[i].std.vol.had) {
224 chan[i].outVol=VOL_SCALE_LOG(chan[i].std.vol.val,chan[i].vol,15);
225 if (chan[i].outVol<0) chan[i].outVol=0;
226 // old formula
227 // ((chan[i].vol&15)*MIN(15,chan[i].std.vol.val))>>4;
228 chan[i].writeVol=true;
229 }
230 if (NEW_ARP_STRAT) {
231 chan[i].handleArp();
232 } else if (chan[i].std.arp.had) {
233 if (!chan[i].inPorta) {
234 // TODO: add compatibility flag. this is horrible.
235 int areYouSerious=parent->calcArp(chan[i].note,chan[i].std.arp.val);
236 if (!easyNoise) while (areYouSerious>0x60) areYouSerious-=12;
237 chan[i].baseFreq=NOTE_SN(i,areYouSerious);
238 chan[i].actualNote=areYouSerious;
239 chan[i].freqChanged=true;
240 }
241 }
242 if (i==3) {
243 if (chan[i].std.duty.had) {
244 if (chan[i].std.duty.val!=snNoiseMode || parent->song.snDutyReset) {
245 snNoiseMode=chan[i].std.duty.val;
246 if (chan[i].std.duty.val<2) {
247 chan[3].freqChanged=false;
248 }
249 updateSNMode=true;
250 }
251 }
252 if (chan[i].std.phaseReset.had) {
253 if (chan[i].std.phaseReset.val==1) {
254 updateSNMode=true;
255 }
256 }
257 }
258 if (stereo) {
259 if (chan[i].std.panL.had) {
260 lastPan&=~(0x11<<i);
261 lastPan|=((chan[i].std.panL.val&1)<<i)|(((chan[i].std.panL.val>>1)&1)<<(i+4));
262 rWrite(1,lastPan);
263 }
264 }
265 if (chan[i].std.pitch.had) {
266 if (chan[i].std.pitch.mode) {
267 chan[i].pitch2+=chan[i].std.pitch.val;
268 CLAMP_VAR(chan[i].pitch2,-32768,32767);
269 } else {
270 chan[i].pitch2=chan[i].std.pitch.val;
271 }
272 chan[i].freqChanged=true;
273 }
274 }
275 for (int i=0; i<3; i++) {
276 if (chan[i].freqChanged) {
277 chan[i].freq=snCalcFreq(i);
278 if (chan[i].freq>1023) chan[i].freq=1023;
279 if (parent->song.snNoLowPeriods) {
280 if (chan[i].freq<8) chan[i].freq=1;
281 } else {
282 if (chan[i].freq<0) chan[i].freq=0;
283 }
284 //if (chan[i].actualNote>0x5d) chan[i].freq=0x01;
285 rWrite(0,0x80|i<<5|(chan[i].freq&15));
286 rWrite(0,chan[i].freq>>4);
287 // what?
288 /*if (i==2 && snNoiseMode&2) {
289 chan[3].baseFreq=chan[2].baseFreq;
290 chan[3].actualNote=chan[2].actualNote;
291 }*/
292 chan[i].freqChanged=false;
293 }
294 }
295 if (chan[3].freqChanged || updateSNMode) {
296 chan[3].freq=snCalcFreq(3);
297 //parent->calcFreq(chan[3].baseFreq,chan[3].pitch,chan[3].fixedArp?chan[3].baseNoteOverride:chan[3].arpOff,chan[3].fixedArp,true,0,chan[3].pitch2,chipClock,noiseDivider);
298 if (chan[3].freq>1023) chan[3].freq=1023;
299 if (parent->song.snNoLowPeriods) {
300 if (chan[3].actualNote>0x5d) chan[3].freq=0x01;
301 }
302 if (chan[3].freq<0) chan[3].freq=0;
303 if (snNoiseMode&2) { // take period from channel 3
304 if (updateSNMode || resetPhase) {
305 if (snNoiseMode&1) {
306 rWrite(0,0xe7);
307 } else {
308 rWrite(0,0xe3);
309 }
310 if (updateSNMode) {
311 rWrite(0,0xdf);
312 }
313 }
314
315 if (chan[3].freqChanged) {
316 rWrite(0,0xc0|(chan[3].freq&15));
317 rWrite(0,chan[3].freq>>4);
318 }
319 } else { // 3 fixed values
320 unsigned char value;
321 // TODO: new arp?
322 if (chan[3].std.arp.had) {
323 value=parent->calcArp(chan[3].note,chan[3].std.arp.val)%12;
324 } else { // pardon?
325 value=chan[3].note%12;
326 }
327 if (value<3) {
328 value=2-value;
329 if (value!=oldValue || updateSNMode || resetPhase) {
330 oldValue=value;
331 rWrite(0,0xe0|value|((snNoiseMode&1)<<2));
332 }
333 }
334 }
335 chan[3].freqChanged=false;
336 updateSNMode=false;
337 }
338 for (int i=0; i<4; i++) {
339 if (chan[i].writeVol) {
340 rWrite(0,0x90|(i<<5)|(isMuted[i]?15:(15-(chan[i].outVol&15))));
341 chan[i].writeVol=false;
342 }
343 if (chan[i].keyOff) {
344 rWrite(0,0x9f|i<<5);
345 chan[i].keyOff=false;
346 }
347 }
348 }
349
350 int DivPlatformSMS::dispatch(DivCommand c) {
351 switch (c.cmd) {
352 case DIV_CMD_NOTE_ON:
353 if (c.value!=DIV_NOTE_NULL) {
354 chan[c.chan].baseFreq=NOTE_SN(c.chan,c.value);
355 chan[c.chan].freqChanged=true;
356 chan[c.chan].note=c.value;
357 chan[c.chan].actualNote=c.value;
358 }
359 chan[c.chan].active=true;
360 chan[c.chan].keyOff=false;
361 //if (!parent->song.brokenOutVol2) {
362 chan[c.chan].writeVol=true;
363 chan[c.chan].outVol=chan[c.chan].vol;
364 //rWrite(0,0x90|c.chan<<5|(isMuted[c.chan]?15:(15-(chan[c.chan].vol&15))));
365 //}
366 chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_STD));
367 if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) {
368 chan[c.chan].outVol=chan[c.chan].vol;
369 }
370 break;
371 case DIV_CMD_NOTE_OFF:
372 chan[c.chan].active=false;
373 chan[c.chan].keyOff=true;
374 chan[c.chan].macroInit(NULL);
375 break;
376 case DIV_CMD_NOTE_OFF_ENV:
377 case DIV_CMD_ENV_RELEASE:
378 chan[c.chan].std.release();
379 break;
380 case DIV_CMD_INSTRUMENT:
381 chan[c.chan].ins=c.value;
382 //chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_STD));
383 break;
384 case DIV_CMD_VOLUME:
385 if (chan[c.chan].vol!=c.value) {
386 chan[c.chan].vol=c.value;
387 if (!chan[c.chan].std.vol.has) {
388 chan[c.chan].outVol=c.value;
389 }
390 if (chan[c.chan].active) {
391 chan[c.chan].writeVol=true;
392 }
393 }
394 break;
395 case DIV_CMD_GET_VOLUME:
396 if (chan[c.chan].std.vol.has) {
397 return chan[c.chan].vol;
398 }
399 return chan[c.chan].outVol;
400 break;
401 case DIV_CMD_PITCH:
402 chan[c.chan].pitch=c.value;
403 chan[c.chan].freqChanged=true;
404 break;
405 case DIV_CMD_NOTE_PORTA: {
406 int destFreq=NOTE_SN(c.chan,c.value2);
407 bool return2=false;
408 if (destFreq>chan[c.chan].baseFreq) {
409 chan[c.chan].baseFreq+=c.value;
410 if (chan[c.chan].baseFreq>=destFreq) {
411 chan[c.chan].baseFreq=destFreq;
412 return2=true;
413 }
414 } else {
415 chan[c.chan].baseFreq-=c.value;
416 if (chan[c.chan].baseFreq<=destFreq) {
417 chan[c.chan].baseFreq=destFreq;
418 return2=true;
419 }
420 }
421 chan[c.chan].freqChanged=true;
422 if (return2) {
423 chan[c.chan].inPorta=false;
424 return 2;
425 }
426 break;
427 }
428 case DIV_CMD_STD_NOISE_MODE:
429 snNoiseMode=(c.value&1)|((c.value&16)>>3);
430 updateSNMode=true;
431 break;
432 case DIV_CMD_PANNING: {
433 if (stereo) {
434 if (c.chan>3) c.chan=3;
435 lastPan&=~(0x11<<c.chan);
436 int pan=0;
437 if (c.value>0) pan|=0x10;
438 if (c.value2>0) pan|=0x01;
439 if (pan==0) pan=0x11;
440 lastPan|=pan<<c.chan;
441 rWrite(1,lastPan);
442 }
443 break;
444 }
445 case DIV_CMD_LEGATO:
446 chan[c.chan].baseFreq=NOTE_SN(c.chan,c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0)));
447 chan[c.chan].freqChanged=true;
448 chan[c.chan].note=c.value;
449 chan[c.chan].actualNote=c.value;
450 break;
451 case DIV_CMD_PRE_PORTA:
452 if (chan[c.chan].active && c.value2) {
453 if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_STD));
454 }
455 if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) chan[c.chan].baseFreq=NOTE_SN(c.chan,chan[c.chan].note);
456 chan[c.chan].inPorta=c.value;
457 break;
458 case DIV_CMD_GET_VOLMAX:
459 return 15;
460 break;
461 case DIV_CMD_MACRO_OFF:
462 chan[c.chan].std.mask(c.value,true);
463 break;
464 case DIV_CMD_MACRO_ON:
465 chan[c.chan].std.mask(c.value,false);
466 break;
467 case DIV_CMD_MACRO_RESTART:
468 chan[c.chan].std.restart(c.value);
469 break;
470 default:
471 break;
472 }
473 return 1;
474 }
475
476 void DivPlatformSMS::muteChannel(int ch, bool mute) {
477 isMuted[ch]=mute;
478 if (chan[ch].active) chan[ch].writeVol=true;
479 }
480
481 void DivPlatformSMS::forceIns() {
482 for (int i=0; i<4; i++) {
483 if (chan[i].active) {
484 chan[i].insChanged=true;
485 chan[i].freqChanged=true;
486 }
487 }
488 updateSNMode=true;
489 }
490
491 void* DivPlatformSMS::getChanState(int ch) {
492 return &chan[ch];
493 }
494
495 DivMacroInt* DivPlatformSMS::getChanMacroInt(int ch) {
496 return &chan[ch].std;
497 }
498
499 unsigned short DivPlatformSMS::getPan(int ch) {
500 if (!stereo) return 0;
501 unsigned char p=lastPan&(0x11<<ch);
502 return ((p&0xf0)?0x100:0)|((p&0x0f)?1:0);
503 }
504
505 DivDispatchOscBuffer* DivPlatformSMS::getOscBuffer(int ch) {
506 return oscBuf[ch];
507 }
508
509 int DivPlatformSMS::mapVelocity(int ch, float vel) {
510 return round(15.0*pow(vel,0.33));
511 }
512
513 float DivPlatformSMS::getGain(int ch, int vol) {
514 if (vol==0) return 0;
515 return 1.0/pow(10.0,(float)(15-vol)*2.0/20.0);
516 }
517
518 unsigned char* DivPlatformSMS::getRegisterPool() {
519 return regPool;
520 }
521
522 int DivPlatformSMS::getRegisterPoolSize() {
523 return stereo?9:8;
524 }
525
526 void DivPlatformSMS::reset() {
527 memset(regPool,0,16);
528 chanLatch=0;
529 while (!writes.empty()) writes.pop();
530 for (int i=0; i<4; i++) {
531 chan[i]=DivPlatformSMS::Channel();
532 chan[i].std.setEngine(parent);
533 }
534 if (dumpWrites) {
535 addWrite(0xffffffff,0);
536 }
537 sn->device_start();
538 YMPSG_Init(&sn_nuked,isRealSN,12,isRealSN?13:15,isRealSN?16383:32767);
539 snNoiseMode=3;
540 rWrite(0,0xe7);
541 updateSNMode=true;
542 oldValue=0xff;
543 lastPan=0xff;
544 if (stereo) {
545 rWrite(1,0xff);
546 }
547 lastOut[0]=0;
548 lastOut[1]=0;
549 }
550
551 int DivPlatformSMS::getOutputCount() {
552 return stereo?2:1;
553 }
554
555 bool DivPlatformSMS::keyOffAffectsArp(int ch) {
556 return true;
557 }
558
559 bool DivPlatformSMS::keyOffAffectsPorta(int ch) {
560 return true;
561 }
562
563 bool DivPlatformSMS::hasAcquireDirect() {
564 return !nuked;
565 }
566
567 bool DivPlatformSMS::getLegacyAlwaysSetVolume() {
568 return false;
569 }
570
571 int DivPlatformSMS::getPortaFloor(int ch) {
572 return 12;
573 }
574
575 void DivPlatformSMS::notifyInsDeletion(void* ins) {
576 for (int i=0; i<4; i++) {
577 chan[i].std.notifyInsDeletion((DivInstrument*)ins);
578 }
579 }
580
581 void DivPlatformSMS::poke(unsigned int addr, unsigned short val) {
582 rWrite(addr,val);
583 }
584
585 void DivPlatformSMS::poke(std::vector<DivRegWrite>& wlist) {
586 for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
587 }
588
589 void DivPlatformSMS::setFlags(const DivConfig& flags) {
590 switch (flags.getInt("clockSel",0)) {
591 case 1:
592 chipClock=COLOR_PAL*4.0/5.0;
593 break;
594 case 2:
595 chipClock=4000000;
596 break;
597 case 3:
598 chipClock=COLOR_NTSC/2.0;
599 break;
600 case 4:
601 chipClock=3000000;
602 break;
603 case 5:
604 chipClock=2000000;
605 break;
606 case 6:
607 chipClock=COLOR_NTSC/8.0;
608 break;
609 default:
610 chipClock=COLOR_NTSC;
611 break;
612 }
613 CHECK_CUSTOM_CLOCK;
614 resetPhase=!flags.getBool("noPhaseReset",false);
615 easyNoise=!flags.getBool("noEasyNoise",false);
616 divider=16;
617 toneDivider=64.0;
618 noiseDivider=64.0;
619 if (sn!=NULL) delete sn;
620 switch (flags.getInt("chipType",0)) {
621 case 1: // TI SN76489
622 sn=new sn76489_device();
623 isRealSN=true;
624 stereo=false;
625 noiseDivider=60.0; // 64 for match to tone frequency on non-Sega PSG but compatibility
626 break;
627 case 2: // TI+Atari
628 sn=new sn76496_base_device(0x4000, 0x0f35, 0x01, 0x02, true, false, false, true);
629 isRealSN=true;
630 stereo=false;
631 noiseDivider=60.0;
632 break;
633 case 3: // Game Gear (not fully emulated yet!)
634 sn=new gamegear_device();
635 isRealSN=false;
636 stereo=true;
637 break;
638 case 4: // TI SN76489A
639 sn=new sn76489a_device();
640 isRealSN=false; // TODO
641 stereo=false;
642 noiseDivider=60.0;
643 break;
644 case 5: // TI SN76496
645 sn=new sn76496_device();
646 isRealSN=false; // TODO
647 stereo=false;
648 noiseDivider=60.0;
649 break;
650 case 6: // NCR 8496
651 sn=new ncr8496_device();
652 isRealSN=false;
653 stereo=false;
654 noiseDivider=60.0;
655 break;
656 case 7: // Tandy PSSJ 3-voice sound
657 sn=new pssj3_device();
658 isRealSN=false;
659 stereo=false;
660 noiseDivider=60.0;
661 break;
662 case 8: // TI SN94624
663 sn=new sn94624_device();
664 isRealSN=true;
665 stereo=false;
666 divider=2;
667 toneDivider=8.0;
668 noiseDivider=7.5;
669 break;
670 case 9: // TI SN76494
671 sn=new sn76494_device();
672 isRealSN=false; // TODO
673 stereo=false;
674 divider=2;
675 toneDivider=8.0;
676 noiseDivider=7.5;
677 break;
678 default: // Sega
679 sn=new segapsg_device();
680 isRealSN=false;
681 stereo=false;
682 break;
683 }
684
685 rate=chipClock/divider;
686 for (int i=0; i<4; i++) {
687 oscBuf[i]->setRate(rate);
688 }
689 }
690
691 void DivPlatformSMS::setNuked(bool value) {
692 nuked=value;
693 }
694
695 int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
696 parent=p;
697 dumpWrites=false;
698 skipRegisterWrites=false;
699 resetPhase=false;
700 oldValue=0xff;
701 lastPan=0xff;
702 for (int i=0; i<4; i++) {
703 isMuted[i]=false;
704 oscBuf[i]=new DivDispatchOscBuffer;
705 }
706 sn=NULL;
707 setFlags(flags);
708 reset();
709 return 4;
710 }
711
712 void DivPlatformSMS::quit() {
713 for (int i=0; i<4; i++) {
714 delete oscBuf[i];
715 }
716 if (sn!=NULL) delete sn;
717 }
718
719 DivPlatformSMS::~DivPlatformSMS() {
720 }