4 #include "executor.h"
\r
7 static unsigned short SoundBufferPos;
\r
9 void StartPlayBack(void)
\r
15 static void SBCallback(void *uudata, signed short *Buffer, int Length)
\r
18 unsigned short Pos, Cur, Left;
\r
24 if(SoundBufferPos >= (SB_SIZE >> 1))
\r
29 Left = (SB_SIZE >> 1) - SoundBufferPos;
\r
30 Cur = (Length > Left)?Left:Length;
\r
31 for(i = 0; i < Cur; i++)
\r
32 Buffer[Pos + i] = (((signed char)SoundBuffer[SoundBufferPos + i]) - 128) * 255;
\r
34 SoundBufferPos += Cur;
\r
39 unsigned char SBReset(void)
\r
41 SDL_AudioSpec my, got;
\r
43 SoundBufferPos = SB_SIZE;
\r
45 my.format = AUDIO_S16;
\r
47 my.samples = SB_SIZE >> 1;
\r
48 my.callback = (void (*)(void *, unsigned char *, int))SBCallback;
\r
49 if(SDL_OpenAudio(&my, &got) < 0)
\r
51 printf("Could not open SDL audio: %s\n", SDL_GetError());
\r
54 if((got.freq != 44100) ||
\r
55 (got.format != AUDIO_S16) ||
\r
56 (got.channels != 1))
\r
58 printf("Audio format mismatch(%i %i %i)!\n", got.freq, got.format, got.channels);
\r
64 void TerminatePlayBack(void)
\r
70 /*void DSPOutput(unsigned char Value)
\r
72 while((inp(DSPAddress + 12) & 0x80) == 0x80);
\r
73 outp(DSPAddress + 12, Value);
\r
76 unsigned char DSPInput(void)
\r
78 while((inp(DSPAddress + 14) & 0x80) == 0);
\r
79 return(inp(DSPAddress + 10));
\r
82 void StartPlayBack(void)
\r
84 unsigned long PhysAddress;
\r
86 PhysAddress = ((unsigned long)DOSSoundBuffer.rm_segment << 4);
\r
87 outp((DMAChannel < 4)?10:0xD4, 4 | (DMAChannel & 3));
\r
88 outp((DMAChannel < 4)?12:0xD8, 0);
\r
89 outp((DMAChannel < 4)?11:0xD6, 0x58 | (DMAChannel & 3));
\r
90 outp(DMAAddress, (unsigned char)(PhysAddress & 0xFF));
\r
91 outp(DMAAddress, (unsigned char)((PhysAddress & 0xFF00) >> 8));
\r
92 outp(DMAPage, (unsigned char)((PhysAddress & 0x0F0000) >> 16));
\r
93 outp(DMACount, (unsigned char)((SB_SIZE - 1) & 0xFF));
\r
94 outp(DMACount, (unsigned char)(((SB_SIZE - 1) & 0xFF00) >> 8));
\r
95 outp((DMAChannel < 4)?10:0xD4, (DMAChannel & 3));
\r
97 DSPOutput((unsigned char)(((65536 - (256000000 / ((unsigned long)SBSampleRate))) & 0xFF00) / 0x100));
\r
99 DSPOutput((unsigned char)((SB_SIZE - 2) >> 1));
\r
100 DSPOutput((unsigned char)((SB_SIZE - 2) >> 9));
\r
108 inp(DSPAddress + 14);
\r
110 outp(DSPAddress + 4, 0x82);
\r
111 if((inp(DSPAddress + 5) & 2) == 2)
\r
112 inp(DSPAddress + 15);
\r
114 if(ReadyBuffer == 0)
\r
120 outp(PICAddress, 0x20);
\r
123 unsigned char SBReset(void)
\r
125 unsigned short i, Success;
\r
129 for(i = 0; (i < 5) && (Success == 0); i++)
\r
131 outp(DSPAddress + 6, 1);
\r
132 for(o = 0; o < 100000; o++);
\r
133 outp(DSPAddress + 6, 0);
\r
134 if(DSPInput() == 0xAA)
\r
170 DMAAddress = DMAChannel << 1;
\r
171 DMACount = (DMAChannel << 1) + 1;
\r
173 DMAAddress = 0xC0 + ((DMAChannel - 4) << 2);
\r
174 DMACount = 0xC2 + ((DMAChannel - 4) << 2);
\r
176 PICAddress = (IRQLine >= 8)?0xA0:0x20;
\r
177 outp(DSPAddress + 4, 10);
\r
178 outp(DSPAddress + 5, 0);
\r
179 outp(DSPAddress + 4, 4);
\r
180 outp(DSPAddress + 5, 255);
\r
181 outp(DSPAddress + 4, 34);
\r
182 outp(DSPAddress + 5, 255);
\r
184 SetISR(IRQLine + ((IRQLine >= 8)?0x68:8), (unsigned long)SBInt, &NewSBInt, &OldSBInt);
\r
185 OldMask = inp(PICAddress + 1);
\r
186 outp(PICAddress + 1, OldMask & ~(1 << ((IRQLine >= 8)?(IRQLine - 8):IRQLine)));
\r
190 void TerminatePlayBack(void)
\r
192 DSPOutput((unsigned char)((DMAChannel < 4)?0xDA:0xD9));
\r
193 outp(PICAddress + 1, OldMask);
\r
194 ReturnISR(IRQLine + ((IRQLine >= 8)?0x68:8), &NewSBInt, &OldSBInt);
\r