From d7c59e8bd4ff2573af4487847ead467b32a9ba37 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 22 Oct 2020 20:24:54 -0400 Subject: [PATCH] GBHawk: Fix behaviour of button pressed during STOP --- src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs | 2 +- src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs | 11 ++++++----- .../Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs | 7 ++++++- .../Consoles/Nintendo/GBHawk/GBHawk.cs | 1 + .../Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs index 3638714352..d92a81b290 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs @@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 // unsaved variables public bool checker; - byte interrupt_src_reg, interrupt_enable_reg; + byte interrupt_src_reg, interrupt_enable_reg, buttons_pressed; public void BuildInstructionTable() { diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index e5884b3c8d..d3f019539f 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -92,7 +92,8 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 public Func PeekMemory; public Func DummyReadMemory; - // Get external interrupt registers + // Get external interrupt registers and button presses + public Func GetButtons; public Func GetIntRegs; public Action SetIntRegs; @@ -477,11 +478,11 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 stop_check = true; } - interrupt_src_reg = GetIntRegs(0); + buttons_pressed = GetButtons(0); if (stop_time > 0) { - // Timer interrupts can prematurely terminate a speedchange, nt sure about other sources + // Timer interrupts can prematurely terminate a speedchange, not sure about other sources // NOTE: some testing around the edge case of where the speed actually changes is needed if (I_use && interrupts_enabled) { @@ -536,7 +537,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 } // If a button is pressed during speed change, the processor will jam - if (interrupt_src_reg.Bit(4)) + if ((buttons_pressed & 0xF) != 0xF) { stop_time++; break; @@ -544,7 +545,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 } // Button press will exit stop loop even if speed change in progress, even without interrupts enabled - if (interrupt_src_reg.Bit(4)) + if ((buttons_pressed & 0xF) != 0xF) { // TODO: On a gameboy, you can only un-STOP once, needs further testing TraceCallback?.Invoke(new TraceInfo diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index 6e792d20b4..b14ca47467 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (ppu.DMA_start && !cpu.halted && !cpu.stopped) { ppu.DMA_tick(); } serialport.serial_transfer_tick(); - timer.tick(); + timer.tick(); cpu.ExecuteOne(); timer.divider_reg++; @@ -344,6 +344,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Acc_Y_state = _controllerDeck.ReadAccY1(controller); } + public byte GetButtons(ushort r) + { + return input_register; + } + public byte GetIntRegs(ushort r) { if (r==0) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index ad7922e0ed..6b589baf03 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -109,6 +109,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk DummyReadMemory = ReadMemory, OnExecFetch = ExecFetch, SpeedFunc = SpeedFunc, + GetButtons = GetButtons, GetIntRegs = GetIntRegs, SetIntRegs = SetIntRegs }; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs index f7812baaf6..9b226e80c4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs @@ -1,5 +1,6 @@ using BizHawk.Common; using BizHawk.Emulation.Cores.Components.LR35902; +using System; namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { @@ -60,7 +61,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return 0xFF; } - } else {