From ce9ce078172f65deb65fdd0c448696b67f65b690 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 16 Jul 2019 20:44:27 +0300 Subject: [PATCH] Make the ICD APIs pixel based --- Core/display.c | 12 ++++++++---- Core/gb.c | 10 ++++++++-- Core/gb.h | 13 ++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Core/display.c b/Core/display.c index 54c53a5..04790f5 100644 --- a/Core/display.c +++ b/Core/display.c @@ -390,7 +390,9 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } } else if (gb->model & GB_MODEL_NO_SFC_BIT) { - gb->icd_row[gb->position_in_line] = pixel; + if (gb->icd_pixel_callback) { + gb->icd_pixel_callback(gb, pixel); + } } else { gb->screen[gb->position_in_line + gb->current_line * WIDTH] = gb->background_palettes_rgb[fifo_item->palette * 4 + pixel]; @@ -409,7 +411,9 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } } else if (gb->model & GB_MODEL_NO_SFC_BIT) { - gb->icd_row[gb->position_in_line] = pixel; + if (gb->icd_pixel_callback) { + gb->icd_pixel_callback(gb, pixel); + } } else { gb->screen[gb->position_in_line + gb->current_line * WIDTH] = gb->sprite_palettes_rgb[oam_fifo_item->palette * 4 + pixel]; @@ -897,8 +901,8 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->mode_for_interrupt = 2; /* TODO: Can this timing even be verified? */ - if (gb->icd_row_callback) { - gb->icd_row_callback(gb, gb->icd_row); + if (gb->icd_hreset_callback) { + gb->icd_hreset_callback(gb); } } diff --git a/Core/gb.c b/Core/gb.c index ff2fd3c..70f6c54 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -925,11 +925,17 @@ void GB_set_joyp_write_callback(GB_gameboy_t *gb, GB_joyp_write_callback_t callb gb->joyp_write_callback = callback; } -void GB_set_icd_row_callback(GB_gameboy_t *gb, GB_icd_row_callback_t callback) +void GB_set_icd_pixel_callback(GB_gameboy_t *gb, GB_icd_pixel_callback_t callback) { - gb->icd_row_callback = callback; + gb->icd_pixel_callback = callback; } +void GB_set_icd_hreset_callback(GB_gameboy_t *gb, GB_icd_hreset_callback_t callback) +{ + gb->icd_hreset_callback = callback; +} + + void GB_set_icd_vreset_callback(GB_gameboy_t *gb, GB_icd_vreset_callback_t callback) { gb->icd_vreset_callback = callback; diff --git a/Core/gb.h b/Core/gb.h index eed23e4..976a0aa 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -243,7 +243,8 @@ typedef void (*GB_serial_transfer_bit_start_callback_t)(GB_gameboy_t *gb, bool b 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 void (*GB_icd_row_callback_t)(GB_gameboy_t *gb, uint8_t *row); +typedef void (*GB_icd_pixel_callback_t)(GB_gameboy_t *gb, uint8_t row); +typedef void (*GB_icd_hreset_callback_t)(GB_gameboy_t *gb); typedef void (*GB_icd_vreset_callback_t)(GB_gameboy_t *gb); typedef struct { @@ -422,7 +423,6 @@ struct GB_gameboy_internal_s { uint16_t serial_length; uint8_t double_speed_alignment; uint8_t serial_count; - uint8_t icd_row[160]; ); /* APU */ @@ -451,7 +451,8 @@ struct GB_gameboy_internal_s { /* The LCDC will skip the first frame it renders after turning it on. On the CGB, a frame is not skipped if the previous frame was skipped as well. See https://www.reddit.com/r/EmuDev/comments/6exyxu/ */ - /* TODO: Drop this and properly emulate the dropped vreset signal*/ + + /* TODO: Drop this and properly emulate the dropped vreset signal*/ enum { GB_FRAMESKIP_LCD_TURNED_ON, // On a DMG, the LCD renders a blank screen during this state, // on a CGB, the previous frame is repeated (which might be @@ -538,7 +539,8 @@ struct GB_gameboy_internal_s { 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; - GB_icd_row_callback_t icd_row_callback; + GB_icd_pixel_callback_t icd_pixel_callback; + GB_icd_vreset_callback_t icd_hreset_callback; GB_icd_vreset_callback_t icd_vreset_callback; /* IR */ @@ -701,7 +703,8 @@ 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); -void GB_set_icd_row_callback(GB_gameboy_t *gb, GB_icd_row_callback_t callback); +void GB_set_icd_pixel_callback(GB_gameboy_t *gb, GB_icd_pixel_callback_t callback); +void GB_set_icd_hreset_callback(GB_gameboy_t *gb, GB_icd_hreset_callback_t callback); void GB_set_icd_vreset_callback(GB_gameboy_t *gb, GB_icd_vreset_callback_t callback); #ifdef GB_INTERNAL