# HG changeset patch # User Michael Pavone # Date 1661147792 25200 # Node ID 40290a92388632997ac1e6e99c9749fb794cf774 # Parent 01ff005b08f600fbaf968186d84bcbed80f8550a Implement Game Gear start button and region register diff -r 01ff005b08f6 -r 40290a923886 sms.c --- a/sms.c Sun Aug 21 22:29:47 2022 -0700 +++ b/sms.c Sun Aug 21 22:56:32 2022 -0700 @@ -195,6 +195,35 @@ return 1; } +static uint8_t gg_io_read(uint32_t location, void *vcontext) +{ + z80_context *z80 = vcontext; + sms_context *sms = z80->system; + if (!location) { + return sms->start_button_region; + } else { + //TODO: implement link port + return 0xFF; + } +} + +static void *gg_io_write(uint32_t location, void *vcontext, uint8_t value) +{ + //TODO: implement link port + return vcontext; +} + +static uint8_t psg_pan_read(uint32_t location, void *vcontext) +{ + //TODO: implement PSG pan + return 0xFF; +} + +static void *psg_pan_write(uint32_t location, void *vcontext, uint8_t value) +{ + //TODO: implement PSG pan + return vcontext; +} static memmap_chunk io_map[] = { {0x00, 0x40, 0xFF, .write_8 = memory_io_write}, {0x40, 0x80, 0xFF, .read_8 = hv_read, .write_8 = sms_psg_write}, @@ -202,6 +231,15 @@ {0xC0, 0x100,0xFF, .read_8 = io_read} }; +static memmap_chunk io_gg[] = { + {0x00, 0x07, 0xFF, .read_8 = gg_io_read, .write_8 = gg_io_write}, + {0x07, 0x08, 0xFF, .read_8 = psg_pan_read, .write_8 = psg_pan_write}, + {0x08, 0x40, 0xFF, .write_8 = memory_io_write}, + {0x40, 0x80, 0xFF, .read_8 = hv_read, .write_8 = sms_psg_write}, + {0x80, 0xC0, 0xFF, .read_8 = vdp_read, .write_8 = vdp_write}, + {0xC0, 0x100,0xFF, .read_8 = io_read} +}; + static void set_speed_percent(system_header * system, uint32_t percent) { sms_context *context = (sms_context *)system; @@ -543,6 +581,8 @@ if (button == MAIN_UNIT_PAUSE) { vdp_pbc_pause(sms->vdp); } + } else if (sms->vdp->type == VDP_GAMEGEAR && gamepad_num == 1 && button == BUTTON_START) { + sms->start_button_region &= 0x7F; } else { io_gamepad_down(&sms->io, gamepad_num, button); } @@ -551,7 +591,11 @@ static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button) { sms_context *sms = (sms_context *)system; - io_gamepad_up(&sms->io, gamepad_num, button); + if (sms->vdp->type == VDP_GAMEGEAR && gamepad_num == 1 && button == BUTTON_START) { + sms->start_button_region |= 0x80; + } else { + io_gamepad_up(&sms->io, gamepad_num, button); + } } static void mouse_down(system_header *system, uint8_t mouse_num, uint8_t button) @@ -626,7 +670,13 @@ sms->header.info.map = malloc(sizeof(memmap_chunk) * sms->header.info.map_chunks); memcpy(sms->header.info.map, memory_map, sizeof(memmap_chunk) * sms->header.info.map_chunks); z80_options *zopts = malloc(sizeof(z80_options)); - init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_map, 4, 15, 0xFF); + uint8_t vdp_type = strcasecmp(media->extension, "gg") ? VDP_GENESIS : VDP_GAMEGEAR; + if (vdp_type == VDP_GAMEGEAR) { + init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_gg, 6, 15, 0xFF); + sms->start_button_region = 0xC0; + } else { + init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_map, 4, 15, 0xFF); + } sms->z80 = init_z80_context(zopts); sms->z80->system = sms; sms->z80->Z80_OPTS->gen.debug_cmd_handler = debug_commands; @@ -650,7 +700,7 @@ set_gain_config(sms); - sms->vdp = init_vdp_context(0, 0, strcasecmp(media->extension, "gg") ? VDP_GENESIS : VDP_GAMEGEAR); + sms->vdp = init_vdp_context(0, 0, vdp_type); sms->vdp->system = &sms->header; sms->header.info.save_type = SAVE_NONE; diff -r 01ff005b08f6 -r 40290a923886 sms.h --- a/sms.h Sun Aug 21 22:29:47 2022 -0700 +++ b/sms.h Sun Aug 21 22:56:32 2022 -0700 @@ -26,6 +26,7 @@ uint32_t normal_clock; uint32_t last_frame; uint8_t should_return; + uint8_t start_button_region; uint8_t ram[SMS_RAM_SIZE]; uint8_t bank_regs[4]; uint8_t cart_ram[SMS_CART_RAM_SIZE];