Fix 7-part SGB commands

This commit is contained in:
Lior Halphon 2021-10-10 02:55:12 +03:00
parent d263a8f6f8
commit b580e63c37
1 changed files with 13 additions and 12 deletions

View File

@ -434,9 +434,6 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value)
return;
}
if (gb->sgb->disable_commands) return;
if (gb->sgb->command_write_index >= sizeof(gb->sgb->command) * 8) {
return;
}
uint16_t command_size = (gb->sgb->command[0] & 7 ?: 1) * SGB_PACKET_SIZE * 8;
if ((gb->sgb->command[0] & 0xF1) == 0xF1) {
@ -468,12 +465,14 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value)
gb->sgb->ready_for_stop = false;
}
else {
if (gb->sgb->command_write_index < sizeof(gb->sgb->command) * 8) {
gb->sgb->command_write_index++;
gb->sgb->ready_for_pulse = false;
if (((gb->sgb->command_write_index) & (SGB_PACKET_SIZE * 8 - 1)) == 0) {
gb->sgb->ready_for_stop = true;
}
}
}
break;
case 1: // One
if (!gb->sgb->ready_for_pulse || !gb->sgb->ready_for_write) return;
@ -485,6 +484,7 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value)
memset(gb->sgb->command, 0, sizeof(gb->sgb->command));
}
else {
if (gb->sgb->command_write_index < sizeof(gb->sgb->command) * 8) {
gb->sgb->command[gb->sgb->command_write_index / 8] |= 1 << (gb->sgb->command_write_index & 7);
gb->sgb->command_write_index++;
gb->sgb->ready_for_pulse = false;
@ -492,6 +492,7 @@ void GB_sgb_write(GB_gameboy_t *gb, uint8_t value)
gb->sgb->ready_for_stop = true;
}
}
}
break;
case 0: