1 #include "cps.h"
2 // QSound
3
4 static INT32 nQsndCyclesExtra;
5
qsndTimerOver(INT32,INT32)6 static INT32 qsndTimerOver(INT32, INT32)
7 {
8 // bprintf(PRINT_NORMAL, _T(" - IRQ -> 1.\n"));
9 ZetSetIRQLine(0xFF, CPU_IRQSTATUS_HOLD);
10
11 return 0;
12 }
13
QsndInit()14 INT32 QsndInit()
15 {
16 INT32 nRate;
17
18 // Init QSound z80
19 if (QsndZInit()) {
20 return 1;
21 }
22 BurnTimerInit(qsndTimerOver, NULL);
23
24 if (Cps1Qs == 1) {
25 nCpsZ80Cycles = 8000000 * 100 / nBurnFPS;
26 BurnTimerAttachZet(8000000);
27 } else {
28 nCpsZ80Cycles = 8000000 * 100 / nBurnFPS;
29 BurnTimerAttachZet(8000000);
30 }
31
32 if (nBurnSoundRate >= 0) {
33 nRate = nBurnSoundRate;
34 } else {
35 nRate = 11025;
36 }
37
38 QscInit(nRate); // Init QSound chip
39
40 return 0;
41 }
42
QsndSetRoute(INT32 nIndex,double nVolume,INT32 nRouteDir)43 void QsndSetRoute(INT32 nIndex, double nVolume, INT32 nRouteDir)
44 {
45 QscSetRoute(nIndex, nVolume, nRouteDir);
46 }
47
QsndReset()48 void QsndReset()
49 {
50 ZetOpen(0);
51 BurnTimerReset();
52 BurnTimerSetRetrig(0, 1.0 / 252.0);
53 ZetClose();
54
55 nQsndCyclesExtra = 0;
56 }
57
QsndExit()58 void QsndExit()
59 {
60 QscExit(); // Exit QSound chip
61 QsndZExit();
62 }
63
QsndScan(INT32 nAction)64 INT32 QsndScan(INT32 nAction)
65 {
66 if (nAction & ACB_DRIVER_DATA) {
67 QsndZScan(nAction); // Scan Z80
68 QscScan(nAction); // Scan QSound Chip
69
70 BurnTimerScan(nAction, NULL);
71 SCAN_VAR(nQsndCyclesExtra);
72 }
73
74 return 0;
75 }
76
QsndNewFrame()77 void QsndNewFrame()
78 {
79 ZetNewFrame();
80
81 ZetOpen(0);
82 ZetIdle(nQsndCyclesExtra);
83
84 QscNewFrame();
85 }
86
QsndEndFrame()87 void QsndEndFrame()
88 {
89 BurnTimerEndFrame(nCpsZ80Cycles);
90 if (pBurnSoundOut) QscUpdate(nBurnSoundLen);
91
92 nQsndCyclesExtra = ZetTotalCycles() - nCpsZ80Cycles;
93 ZetClose();
94 }
95
QsndSyncZ80()96 void QsndSyncZ80()
97 {
98 int nCycles = (INT64)SekTotalCycles() * nCpsZ80Cycles / nCpsCycles;
99
100 if (nCycles <= ZetTotalCycles()) {
101 return;
102 }
103
104 BurnTimerUpdate(nCycles);
105 }
106