diff --git a/CHANGELOG.md b/CHANGELOG.md index ac870e9073bb060993750dc39b4dbc582b3e8dde..e951e8fc2db71e8930c5cffc2283966eaddd7708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -* +* Issue related to interrupt timing, reduce interrupt to 20 cycles instead of 24 ## [0.9.18] - 2024-01-02 diff --git a/frontends/sdl/res/test/blargg/interrupt_time/interrupt_time.png b/frontends/sdl/res/test/blargg/interrupt_time/interrupt_time.png new file mode 100644 index 0000000000000000000000000000000000000000..67638ca4b6baee0f7ecc321b2ce1a5fbf3d007ac Binary files /dev/null and b/frontends/sdl/res/test/blargg/interrupt_time/interrupt_time.png differ diff --git a/frontends/sdl/src/test.rs b/frontends/sdl/src/test.rs index 44dd24f7672ccf30cc87c78bc919b37f8bfb7864..e1beab0aabd769bab28f24dc0432e0d5ac34716f 100644 --- a/frontends/sdl/src/test.rs +++ b/frontends/sdl/src/test.rs @@ -70,6 +70,22 @@ mod tests { assert!(image_result); } + #[test] + fn test_blargg_interrupt_time() { + let result: [u8; FRAME_BUFFER_SIZE] = run_image_test( + "../../res/roms/test/blargg/interrupt_time/interrupt_time.gb", + Some(20000000), + TestOptions { + mode: Some(GameBoyMode::Cgb), + ..TestOptions::default() + }, + ) + .unwrap(); + let image_result = + compare_images(&result, "res/test/blargg/interrupt_time/interrupt_time.png"); + assert!(image_result); + } + #[test] fn test_blargg_dmg_sound() { let result: [u8; FRAME_BUFFER_SIZE] = run_image_test( diff --git a/src/cpu.rs b/src/cpu.rs index 91037dbb6034dc26c4f7905ce0004c6f033f577a..ad5c3f9698a71ee8dd301c7627ad5eb17e8e2a09 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -172,7 +172,7 @@ impl Cpu { self.halted = false; } - return 24; + return 20; } else if (self.mmu.ie & 0x02 == 0x02) && self.mmu.ppu().int_stat() { debugln!("Going to run LCD STAT interrupt handler (0x48)"); @@ -190,7 +190,7 @@ impl Cpu { self.halted = false; } - return 24; + return 20; } else if (self.mmu.ie & 0x04 == 0x04) && self.mmu.timer().int_tima() { debugln!("Going to run Timer interrupt handler (0x50)"); @@ -208,7 +208,7 @@ impl Cpu { self.halted = false; } - return 24; + return 20; } else if (self.mmu.ie & 0x08 == 0x08) && self.mmu.serial().int_serial() { debugln!("Going to run Serial interrupt handler (0x58)"); @@ -226,7 +226,7 @@ impl Cpu { self.halted = false; } - return 24; + return 20; } else if (self.mmu.ie & 0x10 == 0x10) && self.mmu.pad().int_pad() { debugln!("Going to run JoyPad interrupt handler (0x60)"); @@ -244,7 +244,7 @@ impl Cpu { self.halted = false; } - return 24; + return 20; } }