diff --git a/Core/gb.c b/Core/gb.c index cb99d4c..bad1910 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -372,7 +372,6 @@ uint8_t GB_run(GB_gameboy_t *gb) gb->cycles_since_run = 0; GB_cpu_run(gb); if (gb->vblank_just_occured) { - GB_update_joyp(gb); GB_rtc_run(gb); GB_debugger_handle_async_commands(gb); GB_rewind_push(gb); @@ -812,3 +811,8 @@ unsigned GB_get_player_count(GB_gameboy_t *gb) { return GB_is_sgb(gb)? gb->sgb->player_count : 1; } + +void GB_set_update_input_hint_callback(GB_gameboy_t *gb, GB_update_input_hint_callback_t callback) +{ + gb->update_input_hint_callback = callback; +} diff --git a/Core/gb.h b/Core/gb.h index f429b45..b798a04 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -238,6 +238,7 @@ typedef void (*GB_infrared_callback_t)(GB_gameboy_t *gb, bool on, long cycles_si typedef void (*GB_rumble_callback_t)(GB_gameboy_t *gb, bool rumble_on); typedef void (*GB_serial_transfer_bit_start_callback_t)(GB_gameboy_t *gb, bool bit_to_send); typedef bool (*GB_serial_transfer_bit_end_callback_t)(GB_gameboy_t *gb); +typedef void (*GB_update_input_hint_callback_t)(GB_gameboy_t *gb); typedef struct { bool state; @@ -527,6 +528,7 @@ struct GB_gameboy_internal_s { GB_rumble_callback_t rumble_callback; GB_serial_transfer_bit_start_callback_t serial_transfer_bit_start_callback; GB_serial_transfer_bit_end_callback_t serial_transfer_bit_end_callback; + GB_update_input_hint_callback_t update_input_hint_callback; /* IR */ long cycles_since_ir_change; // In 8MHz units @@ -674,6 +676,7 @@ void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback) void GB_set_rgb_encode_callback(GB_gameboy_t *gb, GB_rgb_encode_callback_t callback); void GB_set_infrared_callback(GB_gameboy_t *gb, GB_infrared_callback_t callback); void GB_set_rumble_callback(GB_gameboy_t *gb, GB_rumble_callback_t callback); +void GB_set_update_input_hint_callback(GB_gameboy_t *gb, GB_update_input_hint_callback_t callback); /* These APIs are used when using internal clock */ void GB_set_serial_transfer_bit_start_callback(GB_gameboy_t *gb, GB_serial_transfer_bit_start_callback_t callback); diff --git a/Core/joypad.c b/Core/joypad.c index ebdf2f5..4ae6e67 100644 --- a/Core/joypad.c +++ b/Core/joypad.c @@ -65,6 +65,7 @@ void GB_set_key_state(GB_gameboy_t *gb, GB_key_t index, bool pressed) { assert(index >= 0 && index < GB_KEY_MAX); gb->keys[0][index] = pressed; + GB_update_joyp(gb); } void GB_set_key_state_for_player(GB_gameboy_t *gb, GB_key_t index, unsigned player, bool pressed) @@ -72,4 +73,5 @@ void GB_set_key_state_for_player(GB_gameboy_t *gb, GB_key_t index, unsigned play assert(index >= 0 && index < GB_KEY_MAX); assert(player < 4); gb->keys[player][index] = pressed; + GB_update_joyp(gb); } diff --git a/Core/memory.c b/Core/memory.c index c15ae42..9104cbd 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -307,6 +307,7 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) return (gb->apu.is_active[GB_NOISE] ? (gb->apu.samples[GB_NOISE] << 4) : 0) | (gb->apu.is_active[GB_WAVE] ? (gb->apu.samples[GB_WAVE]) : 0); case GB_IO_JOYP: + GB_timing_sync(gb); case GB_IO_TMA: case GB_IO_LCDC: case GB_IO_SCY: diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index cf8bf09..12ca670 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -234,6 +234,7 @@ static void stop(GB_gameboy_t *gb, uint8_t opcode) } else { + GB_timing_sync(gb); if ((gb->io_registers[GB_IO_JOYP] & 0xF) != 0xF) { /* HW Bug? When STOP is executed while a button is down, the CPU halts forever yet the other hardware keeps running. */ @@ -1397,6 +1398,7 @@ void GB_cpu_run(GB_gameboy_t *gb) return; } if (gb->stopped) { + GB_timing_sync(gb); GB_advance_cycles(gb, 4); if ((gb->io_registers[GB_IO_JOYP] & 0xF) != 0xF) { gb->stopped = false; @@ -1409,6 +1411,10 @@ void GB_cpu_run(GB_gameboy_t *gb) return; } + if ((gb->interrupt_enable & 0x10) && (gb->ime || gb->halted)) { + GB_timing_sync(gb); + } + if (gb->halted && !GB_is_cgb(gb) && !gb->just_halted) { GB_advance_cycles(gb, 2); } diff --git a/Core/timing.c b/Core/timing.c index 039f750..b14a00b 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -73,6 +73,9 @@ void GB_timing_sync(GB_gameboy_t *gb) } gb->cycles_since_last_sync = 0; + if (gb->update_input_hint_callback) { + gb->update_input_hint_callback(gb); + } } #else diff --git a/SDL/main.c b/SDL/main.c index 451ac9c..be52afd 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -435,6 +435,7 @@ restart: GB_set_color_correction_mode(&gb, configuration.color_correction_mode); GB_set_highpass_filter_mode(&gb, configuration.highpass_mode); GB_set_rewind_length(&gb, configuration.rewind_length); + GB_set_update_input_hint_callback(&gb, handle_events); } SDL_DestroyTexture(texture);