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 SDL_AudioSpec audio_spec;
45 #define AUDIO_BUFFER_SIZE 0x4000
47 static Uint8 *audio_buffer_r = audio_buffer;
48 static Uint8 *audio_buffer_w = audio_buffer;
49 static int dave_ticks_per_sample_counter = 0;
50 static int dave_ticks_per_sample = 6;
54 static inline Uint16 dave_render_audio_sample (
void )
59 left = ports[0xA8] << 2;
62 left = tg0_ff * ports[0xA8] +
63 tg1_ff * ports[0xA9] +
67 right = ports[0xAC] << 2;
70 right = tg0_ff * ports[0xAC] +
71 tg1_ff * ports[0xAD] +
75 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,
76 ports[0xA8], ports[0xA9], ports[0xAA], ports[0xAB],
77 ports[0xAC], ports[0xAD], ports[0xAE], ports[0xAF],
78 ports[0xA0] | ((ports[0xA1] & 15) << 8),
79 ports[0xA2] | ((ports[0xA3] & 15) << 8),
80 ports[0xA4] | ((ports[0xA5] & 15) << 8),
81 cnt_tg0, cnt_tg1, cnt_tg2,
85 return (right << 8) | left;
90 static void audio_fill_stereo (
Uint16 stereo_sample )
92 *(
Uint16*)(audio_buffer_w) = stereo_sample;
95 audio_buffer_w = audio_buffer;
100 static void audio_callback(
void *userdata,
Uint8 *
stream,
int len)
103 if (audio_buffer_r == audio_buffer_w) {
108 *(
stream++) = *(audio_buffer_r++);
110 audio_buffer_r = audio_buffer;
120 SDL_PauseAudioDevice(audio, 0);
128 SDL_PauseAudioDevice(audio, 1);
137 SDL_CloseAudioDevice(audio);
147 SDL_memset(&want, 0,
sizeof(want));
149 want.format = AUDIO_U8;
152 want.callback = audio_callback;
153 want.userdata = NULL;
154 audio = SDL_OpenAudioDevice(NULL, 0, &want, &audio_spec, 0);
156 ERROR_WINDOW(
"Cannot initiailze audio: %s\n", SDL_GetError());
157 else if (want.freq != audio_spec.freq || want.format != audio_spec.format || want.channels != audio_spec.channels) {
159 ERROR_WINDOW(
"Bad audio parameters (w/h freq=%d/%d, fmt=%d/%d, chans=%d/%d, smpls=%d/%d, cannot use sound",
160 want.freq, audio_spec.freq, want.format, audio_spec.format, want.channels, audio_spec.channels, want.samples, audio_spec.samples
172 if (ports[0xBF] & 2) {
174 dave_ticks_per_sample = 4;
177 dave_ticks_per_sample = 6;
196 for (a = 0xA0; a <= 0xBF; a++)
201 cnt_1hz = 0; cnt_50hz = 0; cnt_31khz = 0; cnt_1khz = 0; cnt_tg0 = 0; cnt_tg1 = 0; cnt_tg2 = 0;
202 tg0_ff = 0; tg1_ff = 0; tg2_ff = 0;
220 DEBUG(
"DAVE/VINT: LACTH is set!" NL);
231 static inline void dave_int_tg (
void )
233 if (dave_int_write & 1)
244 if ((--cnt_50hz) < 0) {
246 if ((ports[0xA7] & 96) == 32)
250 if ((--cnt_1khz) < 0) {
252 if ((ports[0xA7] & 96) == 0)
256 if (ports[0xA7] & 1) {
257 cnt_tg0 = cnt_load_tg0;
259 }
else if ((--cnt_tg0) < 0) {
260 cnt_tg0 = cnt_load_tg0;
262 if ((ports[0xA7] & 96) == 64)
266 if (ports[0xA7] & 2) {
267 cnt_tg1 = cnt_load_tg1;
269 }
else if ((--cnt_tg1) < 0) {
270 cnt_tg1 = cnt_load_tg1;
272 if ((ports[0xA7] & 96) == 96)
276 if (ports[0xA7] & 4) {
277 cnt_tg2 = cnt_load_tg2;
279 }
else if ((--cnt_tg2) < 0) {
280 cnt_tg2 = cnt_load_tg2;
284 if ((--cnt_1hz) < 0) {
285 cnt_1hz = 250000 - 1;
286 if (dave_int_write & 4)
293 if ((--dave_ticks_per_sample_counter) < 0) {
296 audio_fill_stereo(dave_render_audio_sample());
303 ((ports[0xF0] + ports[0xF1]) >> 1) |
304 (((ports[0xF2] + ports[0xF3]) >> 1) << 8)
311 dave_ticks_per_sample_counter = dave_ticks_per_sample - 1;
333 cnt_load_tg0 = (cnt_load_tg0 & 0xF00 ) |
value;
336 cnt_load_tg0 = (cnt_load_tg0 & 0x0FF ) | ((
value & 0xF) << 8);
339 cnt_load_tg1 = (cnt_load_tg1 & 0xF00 ) |
value;
342 cnt_load_tg1 = (cnt_load_tg1 & 0x0FF ) | ((
value & 0xF) << 8);
345 cnt_load_tg2 = (cnt_load_tg2 & 0xF00 ) |
value;
348 cnt_load_tg2 = (cnt_load_tg2 & 0x0FF ) | ((
value & 0xF) << 8);