diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs index 5d22c0adec..3237e21af6 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs @@ -576,7 +576,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 // exit halt / stop loop instr_table[256 * 60 * 2 + 60] = IDLE; instr_table[256 * 60 * 2 + 60 + 1] = IDLE; - instr_table[256 * 60 * 2 + 60 + 2] = IDLE; + instr_table[256 * 60 * 2 + 60 + 2] = HALT_CHK; instr_table[256 * 60 * 2 + 60 + 3] = OP; // skipped loop diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index a2f9e90cc4..fb05754856 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -425,7 +425,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 if (!stop_check) { // Z contains the second stop byte, not sure if it's useful at all - stop_time = SpeedFunc(Regs[Z]); + stop_time = SpeedFunc(0); stop_check = true; } @@ -433,6 +433,11 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 if (stop_time > 0) { + if (stop_time == (32768 - 43)) + { + SpeedFunc(1); + } + stop_time--; if (stop_time == 0) 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 bc10211eff..588d23596a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -101,10 +101,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { // These things all tick twice as fast in GBC double speed mode // Note that DMA is halted when the CPU is halted - if (ppu.DMA_start && !cpu.halted && !cpu.stopped) { ppu.DMA_tick(); } - serialport.serial_transfer_tick(); - cpu.ExecuteOne(); - timer.tick(); if (double_speed) { @@ -113,17 +109,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk cpu.ExecuteOne(); timer.tick(); } + + if (ppu.DMA_start && !cpu.halted && !cpu.stopped) { ppu.DMA_tick(); } + serialport.serial_transfer_tick(); + cpu.ExecuteOne(); + timer.tick(); } else { - cpu.TotalExecutedCycles++; - timer.tick(); - if (double_speed) { cpu.TotalExecutedCycles++; timer.tick(); } + + cpu.TotalExecutedCycles++; + timer.tick(); } if (in_vblank && !in_vblank_old) @@ -254,23 +255,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // Switch Speed (GBC only) public int SpeedFunc(int temp) { - if (is_GBC) + if (temp == 0) { - if (speed_switch) + if (is_GBC) { - speed_switch = false; - Console.WriteLine("Speed Switch: " + cpu.TotalExecutedCycles); - int ret = double_speed ? (32768 - 20) : (32768 - 20); // actual time needs checking - double_speed = !double_speed; - return ret; + if (speed_switch) + { + speed_switch = false; + Console.WriteLine("Speed Switch: " + cpu.TotalExecutedCycles); + int ret = double_speed ? 32768 - 20 : 32768 - 20; // actual time needs checking + return ret; + } + + // if we are not switching speed, return 0 + return 0; } - // if we are not switching speed, return 0 + // if we are in GB mode, return 0, cannot switch speed + return 0; + } + else + { + double_speed = !double_speed; return 0; } - - // if we are in GB mode, return 0, cannot switch speed - return 0; } public void GetControllerState(IController controller) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/HW_Registers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/HW_Registers.cs index 373deef6b2..fd9bdddd90 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/HW_Registers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/HW_Registers.cs @@ -101,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 0xFF4D: if (GBC_compat) { - ret = (byte)(((double_speed ? 1 : 0) << 7) + ((speed_switch ? 1 : 0))); + ret = (byte)(((double_speed ? 1 : 0) << 7) | (speed_switch ? 1 : 0) | 0x7E); } else {