31 static Uint8 dave_int_write;
32 static int cnt_1hz, cnt_50hz, cnt_31khz, cnt_1khz, cnt_tg0, cnt_tg1, cnt_tg2;
33 static int cnt_load_tg0, cnt_load_tg1, cnt_load_tg2;
34 static int tg0_ff, tg1_ff, tg2_ff;
43 static SDL_AudioDeviceID audio = 0;
44 static int audio_stopped = 0;
45 static SDL_AudioSpec audio_spec;
46 #define AUDIO_BUFFER_SIZE 0x4000
48 static Uint8 *audio_buffer_r = audio_buffer;
49 static Uint8 *audio_buffer_w = audio_buffer;
50 static int dave_ticks_per_sample_counter = 0;
51 static int dave_ticks_per_sample = 6;
55 static inline Uint16 dave_render_audio_sample (
void )
60 left = ports[0xA8] << 2;
63 left = tg0_ff * ports[0xA8] +
64 tg1_ff * ports[0xA9] +
68 right = ports[0xAC] << 2;
71 right = tg0_ff * ports[0xAC] +
72 tg1_ff * ports[0xAD] +
76 DEBUGPRINT(
"DAVE: TG: %d %d %d Vol-l=%02X,%02X,%02X,%02X Vol-r=%02X,%02X,%02X,%02X FREQ=%d,%d,%d CNT=%d,%d,%d SYNC=%d" NL, tg0_ff, tg1_ff, tg2_ff,
77 ports[0xA8], ports[0xA9], ports[0xAA], ports[0xAB],
78 ports[0xAC], ports[0xAD], ports[0xAE], ports[0xAF],
79 ports[0xA0] | ((ports[0xA1] & 15) << 8),
80 ports[0xA2] | ((ports[0xA3] & 15) << 8),
81 ports[0xA4] | ((ports[0xA5] & 15) << 8),
82 cnt_tg0, cnt_tg1, cnt_tg2,
86 return (right << 8) | left;
91 static void audio_fill_stereo (
Uint16 stereo_sample )
93 *(
Uint16*)(audio_buffer_w) = stereo_sample;
96 audio_buffer_w = audio_buffer;
101 static void audio_callback(
void *userdata,
Uint8 *
stream,
int len)
104 if (audio_buffer_r == audio_buffer_w) {
109 *(
stream++) = *(audio_buffer_r++);
111 audio_buffer_r = audio_buffer;
119 return (audio != 0 && !audio_stopped);
126 SDL_PauseAudioDevice(audio, 0);
136 SDL_PauseAudioDevice(audio, 1);
147 SDL_CloseAudioDevice(audio);
160 SDL_memset(&want, 0,
sizeof(want));
162 want.format = AUDIO_U8;
165 want.callback = audio_callback;
166 want.userdata = NULL;
167 audio = SDL_OpenAudioDevice(NULL, 0, &want, &audio_spec, 0);
169 ERROR_WINDOW(
"Cannot initiailze audio: %s\n", SDL_GetError());
170 else if (want.freq != audio_spec.freq || want.format != audio_spec.format || want.channels != audio_spec.channels) {
172 ERROR_WINDOW(
"Bad audio parameters (w/h freq=%d/%d, fmt=%d/%d, chans=%d/%d, smpls=%d/%d, cannot use sound",
173 want.freq, audio_spec.freq, want.format, audio_spec.format, want.channels, audio_spec.channels, want.samples, audio_spec.samples
186 if (ports[0xBF] & 2) {
188 dave_ticks_per_sample = 4;
191 dave_ticks_per_sample = 6;
210 for (a = 0xA0; a <= 0xBF; a++)
215 cnt_1hz = 0; cnt_50hz = 0; cnt_31khz = 0; cnt_1khz = 0; cnt_tg0 = 0; cnt_tg1 = 0; cnt_tg2 = 0;
216 tg0_ff = 0; tg1_ff = 0; tg2_ff = 0;
234 DEBUG(
"DAVE/VINT: LACTH is set!" NL);
245 static inline void dave_int_tg (
void )
247 if (dave_int_write & 1)
258 if ((--cnt_50hz) < 0) {
260 if ((ports[0xA7] & 96) == 32)
264 if ((--cnt_1khz) < 0) {
266 if ((ports[0xA7] & 96) == 0)
270 if (ports[0xA7] & 1) {
271 cnt_tg0 = cnt_load_tg0;
273 }
else if ((--cnt_tg0) < 0) {
274 cnt_tg0 = cnt_load_tg0;
276 if ((ports[0xA7] & 96) == 64)
280 if (ports[0xA7] & 2) {
281 cnt_tg1 = cnt_load_tg1;
283 }
else if ((--cnt_tg1) < 0) {
284 cnt_tg1 = cnt_load_tg1;
286 if ((ports[0xA7] & 96) == 96)
290 if (ports[0xA7] & 4) {
291 cnt_tg2 = cnt_load_tg2;
293 }
else if ((--cnt_tg2) < 0) {
294 cnt_tg2 = cnt_load_tg2;
298 if ((--cnt_1hz) < 0) {
299 cnt_1hz = 250000 - 1;
300 if (dave_int_write & 4)
307 if ((--dave_ticks_per_sample_counter) < 0) {
310 audio_fill_stereo(dave_render_audio_sample());
317 ((ports[0xF0] + ports[0xF1]) >> 1) |
318 (((ports[0xF2] + ports[0xF3]) >> 1) << 8)
325 dave_ticks_per_sample_counter = dave_ticks_per_sample - 1;
347 cnt_load_tg0 = (cnt_load_tg0 & 0xF00 ) |
value;
350 cnt_load_tg0 = (cnt_load_tg0 & 0x0FF ) | ((
value & 0xF) << 8);
353 cnt_load_tg1 = (cnt_load_tg1 & 0xF00 ) |
value;
356 cnt_load_tg1 = (cnt_load_tg1 & 0x0FF ) | ((
value & 0xF) << 8);
359 cnt_load_tg2 = (cnt_load_tg2 & 0xF00 ) |
value;
362 cnt_load_tg2 = (cnt_load_tg2 & 0x0FF ) | ((
value & 0xF) << 8);