From bd56f5fa899f2c453d51a32af1a693e80a3369af Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 15 Jan 2017 22:54:01 -0800 Subject: Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier. --- genesis.c | 28 +++++++++++++++++----------- vdp.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/genesis.c b/genesis.c index 9644fbe..6377e40 100644 --- a/genesis.c +++ b/genesis.c @@ -148,6 +148,10 @@ uint32_t last_sync_cycle; uint32_t refresh_counter; #endif +#include +#define ADJUST_BUFFER (8*MCLKS_LINE*313) +#define MAX_NO_ADJUST (UINT_MAX-ADJUST_BUFFER) + m68k_context * sync_components(m68k_context * context, uint32_t address) { genesis_context * gen = context->system; @@ -176,17 +180,19 @@ m68k_context * sync_components(m68k_context * context, uint32_t address) exit(0); } } - - vdp_adjust_cycles(v_context, mclks); - io_adjust_cycles(gen->io.ports, context->current_cycle, mclks); - io_adjust_cycles(gen->io.ports+1, context->current_cycle, mclks); - io_adjust_cycles(gen->io.ports+2, context->current_cycle, mclks); - context->current_cycle -= mclks; - z80_adjust_cycles(z_context, mclks); - gen->ym->current_cycle -= mclks; - gen->psg->cycles -= mclks; - if (gen->ym->write_cycle != CYCLE_NEVER) { - gen->ym->write_cycle = gen->ym->write_cycle >= mclks ? gen->ym->write_cycle - mclks : 0; + if (context->current_cycle > MAX_NO_ADJUST) { + uint32_t deduction = mclks - ADJUST_BUFFER; + vdp_adjust_cycles(v_context, deduction); + io_adjust_cycles(gen->io.ports, context->current_cycle, deduction); + io_adjust_cycles(gen->io.ports+1, context->current_cycle, deduction); + io_adjust_cycles(gen->io.ports+2, context->current_cycle, deduction); + context->current_cycle -= deduction; + z80_adjust_cycles(z_context, deduction); + gen->ym->current_cycle -= deduction; + gen->psg->cycles -= deduction; + if (gen->ym->write_cycle != CYCLE_NEVER) { + gen->ym->write_cycle = gen->ym->write_cycle >= deduction ? gen->ym->write_cycle - deduction : 0; + } } } gen->frame_end = vdp_cycles_to_frame_end(v_context); diff --git a/vdp.c b/vdp.c index 701c894..38bb36d 100644 --- a/vdp.c +++ b/vdp.c @@ -1174,7 +1174,7 @@ static void render_map_output(uint32_t line, int32_t col, vdp_context * context) } col -= 2; dst = context->output + col * 8; - uint32_t color = context->colors[context->regs[REG_BG_COLOR]]; + uint32_t color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; for (int i = 0; i < 16; i++) { *(dst++) = color; -- cgit v1.2.3