Mercurial > repos > blastem
comparison blastem.c @ 889:2d1122123fe9
Approximation of refresh wait states
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 16 Nov 2015 21:57:17 -0800 |
parents | e3f5ec336432 |
children | 90d54ccf9557 |
comparison
equal
deleted
inserted
replaced
888:bc127fa1f800 | 889:2d1122123fe9 |
---|---|
228 ym_run(gen->ym, target); | 228 ym_run(gen->ym, target); |
229 | 229 |
230 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); | 230 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); |
231 } | 231 } |
232 | 232 |
233 #define REFRESH_INTERVAL 130 | |
234 #define REFRESH_DELAY 2 | |
233 uint32_t last_frame_num; | 235 uint32_t last_frame_num; |
236 uint32_t last_sync_cycle; | |
237 uint32_t refresh_counter; | |
234 m68k_context * sync_components(m68k_context * context, uint32_t address) | 238 m68k_context * sync_components(m68k_context * context, uint32_t address) |
235 { | 239 { |
236 genesis_context * gen = context->system; | 240 genesis_context * gen = context->system; |
237 vdp_context * v_context = gen->vdp; | 241 vdp_context * v_context = gen->vdp; |
238 z80_context * z_context = gen->z80; | 242 z80_context * z_context = gen->z80; |
243 //lame estimation of refresh cycle delay | |
244 refresh_counter += context->current_cycle - last_sync_cycle; | |
245 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); | |
246 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); | |
247 | |
239 uint32_t mclks = context->current_cycle; | 248 uint32_t mclks = context->current_cycle; |
240 sync_z80(z_context, mclks); | 249 sync_z80(z_context, mclks); |
241 sync_sound(gen, mclks); | 250 sync_sound(gen, mclks); |
242 vdp_run_context(v_context, mclks); | 251 vdp_run_context(v_context, mclks); |
243 if (v_context->frame != last_frame_num) { | 252 if (v_context->frame != last_frame_num) { |
293 puts("Saved state to savestate.gst"); | 302 puts("Saved state to savestate.gst"); |
294 } else if(save_state) { | 303 } else if(save_state) { |
295 context->sync_cycle = context->current_cycle + 1; | 304 context->sync_cycle = context->current_cycle + 1; |
296 } | 305 } |
297 } | 306 } |
307 last_sync_cycle = context->current_cycle; | |
298 return context; | 308 return context; |
299 } | 309 } |
300 | 310 |
301 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) | 311 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) |
302 { | 312 { |
352 } else { | 362 } else { |
353 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); | 363 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); |
354 } | 364 } |
355 if (v_context->cycles != before_cycle) { | 365 if (v_context->cycles != before_cycle) { |
356 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); | 366 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); |
357 context->current_cycle = v_context->cycles; | 367 last_sync_cycle = context->current_cycle = v_context->cycles; |
358 //Lock the Z80 out of the bus until the VDP access is complete | 368 //Lock the Z80 out of the bus until the VDP access is complete |
359 gen->bus_busy = 1; | 369 gen->bus_busy = 1; |
360 sync_z80(gen->z80, v_context->cycles); | 370 sync_z80(gen->z80, v_context->cycles); |
361 gen->bus_busy = 0; | 371 gen->bus_busy = 0; |
362 } | 372 } |
425 } else { | 435 } else { |
426 value = vdp_test_port_read(v_context); | 436 value = vdp_test_port_read(v_context); |
427 } | 437 } |
428 if (v_context->cycles != before_cycle) { | 438 if (v_context->cycles != before_cycle) { |
429 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); | 439 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); |
430 context->current_cycle = v_context->cycles; | 440 last_sync_cycle = context->current_cycle = v_context->cycles; |
431 //Lock the Z80 out of the bus until the VDP access is complete | 441 //Lock the Z80 out of the bus until the VDP access is complete |
432 genesis_context *gen = context->system; | 442 genesis_context *gen = context->system; |
433 gen->bus_busy = 1; | 443 gen->bus_busy = 1; |
434 sync_z80(gen->z80, v_context->cycles); | 444 sync_z80(gen->z80, v_context->cycles); |
435 gen->bus_busy = 0; | 445 gen->bus_busy = 0; |