Fixed multiplayer SGB mode

This commit is contained in:
Lior Halphon 2018-12-04 23:46:30 +02:00
parent 241577a7f1
commit ea09dfc888
3 changed files with 6 additions and 9 deletions

View File

@ -1,4 +1,3 @@
#include <stdio.h>
#include "gb.h" #include "gb.h"
#include <assert.h> #include <assert.h>

View File

@ -731,8 +731,7 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
case GB_IO_JOYP: case GB_IO_JOYP:
GB_sgb_write(gb, value); 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); GB_update_joyp(gb);
return; return;

View File

@ -84,13 +84,11 @@ static void command_ready(GB_gameboy_t *gb)
} }
if (gb->sgb->command[0] == 0xf9) { if (gb->sgb->command[0] == 0xf9) {
if (gb->sgb->command[0xc] != 3) { // SGB Flag 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; gb->sgb->disable_commands = true;
} }
} }
else if (gb->sgb->command[0] == 0xfb) { else if (gb->sgb->command[0] == 0xfb) {
if (gb->sgb->command[0x3] != 0x33) { // Old licensee code 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; gb->sgb->disable_commands = true;
} }
} }
@ -247,6 +245,11 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value)
switch ((value >> 4) & 3) { switch ((value >> 4) & 3) {
case 3: case 3:
gb->sgb->ready_for_pulse = true; 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; break;
case 2: // Zero 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)); memset(gb->sgb->command, 0, sizeof(gb->sgb->command));
gb->sgb->ready_for_stop = false; 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; break;
default: default: