4 #include "executor.h"
\r
7 static unsigned short SoundBufferPos;
\r
9 void StartPlayBack(void)
\r
15 static void SBCallback(void *uudata, unsigned char *Buffer, int Length)
\r
17 unsigned short Pos, Cur, Left;
\r
22 if(SoundBufferPos >= (SB_SIZE >> 1))
\r
27 Left = (SB_SIZE >> 1) - SoundBufferPos;
\r
28 Cur = (Length > Left)?Left:Length;
\r
29 memcpy(Buffer + Pos, SoundBuffer + SoundBufferPos, Cur);
\r
31 SoundBufferPos += Cur;
\r
36 unsigned char SBReset(void)
\r
38 SDL_AudioSpec my, got;
\r
40 SoundBufferPos = SB_SIZE;
\r
42 my.format = AUDIO_U8;
\r
44 my.samples = SB_SIZE >> 1;
\r
45 my.callback = SBCallback;
\r
46 if(SDL_OpenAudio(&my, &got) < 0)
\r
48 printf("Could not open SDL audio: %s\n", SDL_GetError());
\r
51 if((got.freq != 44100) ||
\r
52 (got.format != AUDIO_U8) ||
\r
53 (got.channels != 1))
\r
55 printf("Audio format mismatch(%i %i %i)!\n", got.freq, got.format, got.channels);
\r
61 void TerminatePlayBack(void)
\r
67 /*void DSPOutput(unsigned char Value)
\r
69 while((inp(DSPAddress + 12) & 0x80) == 0x80);
\r
70 outp(DSPAddress + 12, Value);
\r
73 unsigned char DSPInput(void)
\r
75 while((inp(DSPAddress + 14) & 0x80) == 0);
\r
76 return(inp(DSPAddress + 10));
\r
79 void StartPlayBack(void)
\r
81 unsigned long PhysAddress;
\r
83 PhysAddress = ((unsigned long)DOSSoundBuffer.rm_segment << 4);
\r
84 outp((DMAChannel < 4)?10:0xD4, 4 | (DMAChannel & 3));
\r
85 outp((DMAChannel < 4)?12:0xD8, 0);
\r
86 outp((DMAChannel < 4)?11:0xD6, 0x58 | (DMAChannel & 3));
\r
87 outp(DMAAddress, (unsigned char)(PhysAddress & 0xFF));
\r
88 outp(DMAAddress, (unsigned char)((PhysAddress & 0xFF00) >> 8));
\r
89 outp(DMAPage, (unsigned char)((PhysAddress & 0x0F0000) >> 16));
\r
90 outp(DMACount, (unsigned char)((SB_SIZE - 1) & 0xFF));
\r
91 outp(DMACount, (unsigned char)(((SB_SIZE - 1) & 0xFF00) >> 8));
\r
92 outp((DMAChannel < 4)?10:0xD4, (DMAChannel & 3));
\r
94 DSPOutput((unsigned char)(((65536 - (256000000 / ((unsigned long)SBSampleRate))) & 0xFF00) / 0x100));
\r
96 DSPOutput((unsigned char)((SB_SIZE - 2) >> 1));
\r
97 DSPOutput((unsigned char)((SB_SIZE - 2) >> 9));
\r
105 inp(DSPAddress + 14);
\r
107 outp(DSPAddress + 4, 0x82);
\r
108 if((inp(DSPAddress + 5) & 2) == 2)
\r
109 inp(DSPAddress + 15);
\r
111 if(ReadyBuffer == 0)
\r
117 outp(PICAddress, 0x20);
\r
120 unsigned char SBReset(void)
\r
122 unsigned short i, Success;
\r
126 for(i = 0; (i < 5) && (Success == 0); i++)
\r
128 outp(DSPAddress + 6, 1);
\r
129 for(o = 0; o < 100000; o++);
\r
130 outp(DSPAddress + 6, 0);
\r
131 if(DSPInput() == 0xAA)
\r
167 DMAAddress = DMAChannel << 1;
\r
168 DMACount = (DMAChannel << 1) + 1;
\r
170 DMAAddress = 0xC0 + ((DMAChannel - 4) << 2);
\r
171 DMACount = 0xC2 + ((DMAChannel - 4) << 2);
\r
173 PICAddress = (IRQLine >= 8)?0xA0:0x20;
\r
174 outp(DSPAddress + 4, 10);
\r
175 outp(DSPAddress + 5, 0);
\r
176 outp(DSPAddress + 4, 4);
\r
177 outp(DSPAddress + 5, 255);
\r
178 outp(DSPAddress + 4, 34);
\r
179 outp(DSPAddress + 5, 255);
\r
181 SetISR(IRQLine + ((IRQLine >= 8)?0x68:8), (unsigned long)SBInt, &NewSBInt, &OldSBInt);
\r
182 OldMask = inp(PICAddress + 1);
\r
183 outp(PICAddress + 1, OldMask & ~(1 << ((IRQLine >= 8)?(IRQLine - 8):IRQLine)));
\r
187 void TerminatePlayBack(void)
\r
189 DSPOutput((unsigned char)((DMAChannel < 4)?0xDA:0xD9));
\r
190 outp(PICAddress + 1, OldMask);
\r
191 ReturnISR(IRQLine + ((IRQLine >= 8)?0x68:8), &NewSBInt, &OldSBInt);
\r