From 084d768cca48fcec46a4939411d8700a658f7a75 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 30 Apr 2020 10:18:46 -0400 Subject: [PATCH] GBHawk: work on STOP --- BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs | 8 ++++++-- .../Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs | 12 +++++++++--- .../Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index 80d6091a26..e4634a67b4 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -424,7 +424,8 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 stopped = true; if (!stop_check) { - stop_time = SpeedFunc(0); + // Z contains the second stop byte, not sure if it's useful at all + stop_time = SpeedFunc(Regs[Z]); stop_check = true; } @@ -433,6 +434,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 if (stop_time > 0) { stop_time--; + if (stop_time == 0) { TraceCallback?.Invoke(new TraceInfo @@ -454,8 +456,10 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 instr_pntr = 256 * 60 * 2 + 60 * 5; // point to stop loop } } - else if (interrupt_src_reg.Bit(4)) // button pressed, not actually an interrupt though + else if (interrupt_src_reg.Bit(4)) // button pressed, even if interrupts are not enabled, still exists stop { + // TODO: OnExecFetch a gameboy, you can only un-STOP once, needs further testing + TraceCallback?.Invoke(new TraceInfo { Disassembly = "====un-stop====", diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index bf3137c315..19fb7de978 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -17,6 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public bool in_vblank_old; public bool in_vblank; public bool vblank_rise; + public bool controller_was_checked; public bool FrameAdvance(IController controller, bool render, bool rendersound) { @@ -56,10 +57,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk _islag = true; + controller_was_checked = false; + do_frame(controller); - // if the game is stopped but controller interrupts are on, check for interrupts - if ((cpu.stopped || cpu.halted) && _islag && ((REG_FFFF & 0x10) == 0x10)) + // if the game is halted but controller interrupts are on, check for interrupts + // if the game is stopped, any button press will un-stop even if interrupts are off + if ((cpu.stopped && !controller_was_checked) || (cpu.halted && ((REG_FFFF & 0x10) == 0x10))) { // update the controller state on VBlank GetControllerState(controller); @@ -125,6 +129,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { _islag = false; + controller_was_checked = true; + // update the controller state on VBlank GetControllerState(controller); @@ -262,7 +268,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk return 0; } - // if we are in GB mode, return 0 indicating not switching speed + // if we are in GB mode, return 0, cannot switch speed return 0; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs index ecced72d3c..3b0bfe1158 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs @@ -35,6 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync(nameof(in_vblank), ref in_vblank); ser.Sync(nameof(in_vblank_old), ref in_vblank_old); ser.Sync(nameof(vblank_rise), ref vblank_rise); + ser.Sync(nameof(controller_was_checked), ref controller_was_checked); ser.Sync(nameof(GB_bios_register), ref GB_bios_register); ser.Sync(nameof(input_register), ref input_register);