Skip to content

Commit

Permalink
fix: interrupt timing issue
Browse files Browse the repository at this point in the history
Allows blargg's test ROM to pass.
  • Loading branch information
joamag committed Feb 25, 2024
1 parent cc9bf51 commit 5fc2d30
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions frontends/sdl/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");

Expand All @@ -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)");

Expand All @@ -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)");

Expand All @@ -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)");

Expand All @@ -244,7 +244,7 @@ impl Cpu {
self.halted = false;
}

return 24;
return 20;
}
}

Expand Down

0 comments on commit 5fc2d30

Please sign in to comment.