10 #include <ctype.h> // for toupper()
\r
14 int __cdecl _getch(void); // from conio.h
\r
16 #define _getch getchar
\r
20 #include <audio/AudioStream.h>
\r
21 #include <audio/AudioStream_SpcDrvFuns.h>
\r
22 #include "vgmSndDrv.h"
\r
23 #include "3812intf.h"
\r
26 int main(int argc, char* argv[]);
\r
27 static UINT32 FillBuffer(void* Params, UINT32 bufSize, void* Data);
\r
28 void OPL2_Write(UINT8 reg, UINT8 data);
\r
29 UINT8 OPL2_ReadStatus(void);
\r
30 void EngineControlCUI(void);
\r
35 static void* audDrv;
\r
36 static void* audDrvLog;
\r
37 INT32 CHIP_SAMPLE_RATE;
\r
38 VGM_FILE vgmFiles[VGM_SLOTS];
\r
40 int main(int argc, char* argv[])
\r
46 AUDDRV_INFO* drvInfo;
\r
50 drvCount = Audio_GetDriverCount();
\r
56 Audio_GetDriverInfo(idWavOut, &drvInfo);
\r
57 printf("Using driver %s.\n", drvInfo->drvName);
\r
58 retVal = AudioDrv_Init(idWavOut, &audDrv);
\r
61 printf("WaveOut: Drv Init Error: %02X\n", retVal);
\r
65 opts = AudioDrv_GetOptions(audDrv);
\r
66 opts->numChannels = 1;
\r
67 opts->numBitsPerSmpl = 16;
\r
68 CHIP_SAMPLE_RATE = opts->sampleRate;
\r
70 device_start_ym3812(0, 3579545);
\r
71 device_reset_ym3812(0);
\r
74 AudioDrv_SetCallback(audDrv, FillBuffer);
\r
75 printf("Opening Device %u ...\n", idWavOutDev);
\r
76 retVal = AudioDrv_Start(audDrv, idWavOutDev);
\r
79 printf("Dev Init Error: %02X\n", retVal);
\r
80 goto Exit_DrvDeinit;
\r
84 printf("Current Latency: %u ms\n", AudioDrv_GetLatency(audDrv));*/
\r
87 retVal = AudioDrv_Stop(audDrv);
\r
91 device_stop_ym3812(0);
\r
92 AudioDrv_Deinit(&audDrv);
\r
98 if (_CrtDumpMemoryLeaks())
\r
105 INT32 chipSmplL[1] = {0};
\r
106 INT32 chipSmplR[1] = {0};
\r
107 INT32* chipSmpls[2] = {chipSmplL, chipSmplR};
\r
108 static UINT32 smplLastIrq = 0;
\r
109 static UINT32 FillBuffer(void* Params, UINT32 bufSize, void* data)
\r
114 INT32 chipSmplsFin;
\r
116 smplCount = bufSize / 2;
\r
117 SmplPtr16 = (INT16*)data;
\r
118 for (curSmpl = 0; curSmpl < smplCount; curSmpl ++)
\r
120 ym3812_stream_update(0, chipSmpls, 1);
\r
121 UpdateSoundEngine();
\r
124 chipSmplsFin = chipSmplL[0];
\r
127 if ((curSmpl / (smplCount / 16)) < 15)
\r
128 chipSmplsFin += +0x0100;
\r
130 chipSmplsFin += -0x0100;
\r
133 if (chipSmplsFin < -0x7FFF)
\r
134 chipSmplsFin = -0x7FFF;
\r
135 else if (chipSmplsFin > 0x7FFF)
\r
136 chipSmplsFin = 0x7FFF;
\r
137 SmplPtr16[curSmpl] = (INT16)chipSmplsFin;
\r
139 return curSmpl * 2;
\r
143 void OPL2_Write(UINT8 reg, UINT8 data)
\r
145 ym3812_w(0, 0, reg);
\r
146 ym3812_w(0, 1, data);
\r
150 UINT8 OPL2_ReadStatus(void)
\r
152 return ym3812_r(0, 0);
\r
157 INLINE UINT8 getVgmID(char vgmIdChar)
\r
159 vgmIdChar = toupper(vgmIdChar);
\r
160 if (vgmIdChar == 'M')
\r
162 else if (vgmIdChar >= '0' && vgmIdChar < '0'+VGM_SLOTS)
\r
163 return (UINT8)(vgmIdChar - '0');
\r
168 INLINE UINT8 getVgmChn(char vgmChnChar)
\r
170 vgmChnChar = toupper(vgmChnChar);
\r
171 if (vgmChnChar == 'M')
\r
173 else if (vgmChnChar >= '0' && vgmChnChar <= '9')
\r
174 return vgmChnChar - '0';
\r
179 void EngineControlCUI(void)
\r
181 VGM_FILE* tempVgmFile;
\r
183 char inLine[0x100];
\r
190 printf("Commands:\n");
\r
191 printf("Ls File.vgm - Load File.vgm into Slot s\n");
\r
192 printf("Pcs - Play Slot s on Channel c\n");
\r
193 printf("Sc - Stop Channel c\n");
\r
194 printf("S - Stop all SFX\n");
\r
195 printf("E - Pause Music\n");
\r
196 printf("R - Resume Music\n");
\r
197 printf("Channels: M = music, 0-5 = SFX\n");
\r
198 printf("Slots: M, 0-3 (M equals slot 0)\n");
\r
200 for (curSFX = 0; curSFX < VGM_SLOTS; curSFX ++)
\r
201 memset(&vgmFiles[curSFX], 0x00, sizeof(VGM_FILE));
\r
205 tempStr = fgets(inLine, 0x100, stdin);
\r
206 if (tempStr == NULL)
\r
208 tempPos = strlen(inLine);
\r
211 inLine[tempPos-1] = '\0';
\r
213 switch(toupper(inLine[0]))
\r
216 vgmId = getVgmID(inLine[1]);
\r
219 printf("Wrong File Slot!\n");
\r
222 tempVgmFile = &vgmFiles[vgmId];
\r
223 FreeVGMFile(tempVgmFile);
\r
224 retVal = OpenVGMFile(inLine + 3, tempVgmFile);
\r
226 printf("Load Error 0x%02X\n", retVal);
\r
228 printf("VGM loaded into slot %d.\n", vgmId);
\r
231 vgmChn = getVgmChn(inLine[1]);
\r
232 vgmId = getVgmID(inLine[2]);
\r
233 if (vgmChn == 0xFF)
\r
235 printf("Wrong Channel!\n");
\r
240 printf("Wrong File Slot!\n");
\r
243 tempVgmFile = &vgmFiles[vgmId];
\r
244 if (vgmChn == 0x7F)
\r
245 PlayMusic(tempVgmFile);
\r
247 PlaySFX(tempVgmFile, vgmChn);
\r
250 vgmChn = getVgmChn(inLine[1]);
\r
251 if (vgmChn == 0x7F)
\r
259 case 'R': // resume
\r
263 printf("Unknown Command!\n");
\r
270 for (curSFX = 0; curSFX < VGM_SLOTS; curSFX ++)
\r
271 FreeVGMFile(&vgmFiles[curSFX]);
\r