Mercurial > repos > blastem
comparison blastem.c @ 997:560da2e455c2
YOUR EMULATOR SUX is dead. Needs logic analyzer testing to check exact delay though.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 30 Apr 2016 10:47:29 -0700 |
parents | 784bc1e45e80 |
children | 8d032a368dd5 |
comparison
equal
deleted
inserted
replaced
996:784bc1e45e80 | 997:560da2e455c2 |
---|---|
364 | 364 |
365 while (vdp_data_port_write(v_context, value) < 0) { | 365 while (vdp_data_port_write(v_context, value) < 0) { |
366 while(v_context->flags & FLAG_DMA_RUN) { | 366 while(v_context->flags & FLAG_DMA_RUN) { |
367 vdp_run_dma_done(v_context, gen->frame_end); | 367 vdp_run_dma_done(v_context, gen->frame_end); |
368 if (v_context->cycles >= gen->frame_end) { | 368 if (v_context->cycles >= gen->frame_end) { |
369 context->current_cycle = v_context->cycles; | 369 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
370 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; | |
371 if (m68k_cycle_diff < cycle_diff) { | |
372 m68k_cycle_diff += MCLKS_PER_68K; | |
373 } | |
374 context->current_cycle += m68k_cycle_diff; | |
370 gen->bus_busy = 1; | 375 gen->bus_busy = 1; |
371 sync_components(context, 0); | 376 sync_components(context, 0); |
372 gen->bus_busy = 0; | 377 gen->bus_busy = 0; |
373 } | 378 } |
374 } | 379 } |
379 if (blocked) { | 384 if (blocked) { |
380 while (blocked) { | 385 while (blocked) { |
381 while(v_context->flags & FLAG_DMA_RUN) { | 386 while(v_context->flags & FLAG_DMA_RUN) { |
382 vdp_run_dma_done(v_context, gen->frame_end); | 387 vdp_run_dma_done(v_context, gen->frame_end); |
383 if (v_context->cycles >= gen->frame_end) { | 388 if (v_context->cycles >= gen->frame_end) { |
384 context->current_cycle = v_context->cycles; | 389 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
390 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; | |
391 if (m68k_cycle_diff < cycle_diff) { | |
392 m68k_cycle_diff += MCLKS_PER_68K; | |
393 } | |
394 context->current_cycle += m68k_cycle_diff; | |
385 gen->bus_busy = 1; | 395 gen->bus_busy = 1; |
386 sync_components(context, 0); | 396 sync_components(context, 0); |
387 gen->bus_busy = 0; | 397 gen->bus_busy = 0; |
388 } | 398 } |
399 if (!(v_context->flags & FLAG_DMA_RUN)) { | |
400 //two more slots of delay are needed to kill sufficient sprite capacity in Overdrive | |
401 //TODO: Measure exact value with logic analyzer | |
402 vdp_run_context(v_context, v_context->cycles + 1); | |
403 vdp_run_context(v_context, v_context->cycles + 1); | |
404 } | |
389 } | 405 } |
406 | |
390 if (blocked < 0) { | 407 if (blocked < 0) { |
391 blocked = vdp_control_port_write(v_context, value); | 408 blocked = vdp_control_port_write(v_context, value); |
392 } else { | 409 } else { |
393 blocked = 0; | 410 blocked = 0; |
394 } | 411 } |
401 } else { | 418 } else { |
402 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); | 419 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); |
403 } | 420 } |
404 if (v_context->cycles != before_cycle) { | 421 if (v_context->cycles != before_cycle) { |
405 //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); | 422 //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); |
406 context->current_cycle = v_context->cycles; | 423 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
424 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; | |
425 if (m68k_cycle_diff < cycle_diff) { | |
426 m68k_cycle_diff += MCLKS_PER_68K; | |
427 } | |
428 context->current_cycle += m68k_cycle_diff; | |
407 #ifdef REFRESH_EMULATION | 429 #ifdef REFRESH_EMULATION |
408 last_sync_cycle = context->current_cycle; | 430 last_sync_cycle = context->current_cycle; |
409 #endif | 431 #endif |
410 //Lock the Z80 out of the bus until the VDP access is complete | 432 //Lock the Z80 out of the bus until the VDP access is complete |
411 gen->bus_busy = 1; | 433 gen->bus_busy = 1; |