diff --git a/Core/joypad.c b/Core/joypad.c index 053ef2f..7713cbd 100644 --- a/Core/joypad.c +++ b/Core/joypad.c @@ -1,4 +1,3 @@ -#include #include "gb.h" #include diff --git a/Core/memory.c b/Core/memory.c index 3a646ae..dc394fa 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -731,8 +731,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value) case GB_IO_JOYP: GB_sgb_write(gb, value); - gb->io_registers[GB_IO_JOYP] &= 0x0F; - gb->io_registers[GB_IO_JOYP] |= value & 0xF0; + gb->io_registers[GB_IO_JOYP] = value & 0xF0; GB_update_joyp(gb); return; diff --git a/Core/sgb.c b/Core/sgb.c index bd3edc2..2fd134b 100644 --- a/Core/sgb.c +++ b/Core/sgb.c @@ -84,13 +84,11 @@ static void command_ready(GB_gameboy_t *gb) } if (gb->sgb->command[0] == 0xf9) { if (gb->sgb->command[0xc] != 3) { // SGB Flag - GB_log(gb, "SGB flag is not 0x03, disabling SGB features\n"); gb->sgb->disable_commands = true; } } else if (gb->sgb->command[0] == 0xfb) { if (gb->sgb->command[0x3] != 0x33) { // Old licensee code - GB_log(gb, "Old licensee code is not 0x33, disabling SGB features\n"); gb->sgb->disable_commands = true; } } @@ -247,6 +245,11 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value) switch ((value >> 4) & 3) { case 3: gb->sgb->ready_for_pulse = true; + /* TODO: This is the logic used by BGB which *should* work for most/all games, but a proper test ROM is needed */ + if (gb->sgb->player_count > 1 && (gb->io_registers[GB_IO_JOYP] & 0x30) == 0x10) { + gb->sgb->current_player++; + gb->sgb->current_player &= gb->sgb->player_count - 1; + } break; case 2: // Zero @@ -299,10 +302,6 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value) memset(gb->sgb->command, 0, sizeof(gb->sgb->command)); gb->sgb->ready_for_stop = false; } - if (gb->sgb->player_count > 1 && (value & 0x30) != (gb->io_registers[GB_IO_JOYP] & 0x30)) { - gb->sgb->current_player++; - gb->sgb->current_player &= gb->sgb->player_count - 1; - } break; default: