From e1873ad2ec5833aaf963fe57e4972c24c5c2a30a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 15 Jul 2019 22:01:41 +0300 Subject: [PATCH] Add JOYP write callback API --- Core/gb.c | 5 +++++ Core/gb.h | 5 +++++ Core/sgb.c | 3 +++ 3 files changed, 13 insertions(+) diff --git a/Core/gb.c b/Core/gb.c index 6f846ca..a1d0f19 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -906,3 +906,8 @@ double GB_get_usual_frame_rate(GB_gameboy_t *gb) { return GB_get_clock_rate(gb) / (double)LCDC_PERIOD; } + +void GB_set_joyp_write_callback(GB_gameboy_t *gb, GB_joyp_write_callback_t callback) +{ + gb->joyp_write_callback = callback; +} diff --git a/Core/gb.h b/Core/gb.h index 6d10283..b82d743 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -242,6 +242,7 @@ 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 void (*GB_joyp_write_callback_t)(GB_gameboy_t *gb, uint8_t value); typedef struct { bool state; @@ -533,6 +534,7 @@ struct GB_gameboy_internal_s { 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; + GB_joyp_write_callback_t joyp_write_callback; /* IR */ long cycles_since_ir_change; // In 8MHz units @@ -691,6 +693,9 @@ bool GB_serial_get_data_bit(GB_gameboy_t *gb); void GB_serial_set_data_bit(GB_gameboy_t *gb, bool data); void GB_disconnect_serial(GB_gameboy_t *gb); + +/* For integration with SFC/SNES emulators */ +void GB_set_joyp_write_callback(GB_gameboy_t *gb, GB_joyp_write_callback_t callback); #ifdef GB_INTERNAL uint32_t GB_get_clock_rate(GB_gameboy_t *gb); diff --git a/Core/sgb.c b/Core/sgb.c index a422af0..ccc439a 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -295,6 +295,9 @@ static void command_ready(GB_gameboy_t *gb) void GB_sgb_write(GB_gameboy_t *gb, uint8_t value) { + if (gb->joyp_write_callback) { + gb->joyp_write_callback(gb, value); + } if (!GB_is_sgb(gb)) return; if (!GB_is_hle_sgb(gb)) { /* Notify via callback */