Skip to content

Commit

Permalink
Slightly cleaner run_cpu function
Browse files Browse the repository at this point in the history
  • Loading branch information
krueger71 committed Dec 29, 2024
1 parent 05f1ac2 commit 4901945
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,14 @@ impl Emu {
}

fn run_cpu(&mut self, cycles_per_frame: u32) {
let mut cycles: u32 = 0;

let mut halfway = false;
while cycles < cycles_per_frame {
cycles += self.cpu.step();
// Interrupts should happen in the middle of frame and at the end
if !halfway && (cycles > cycles_per_frame / 2) {
cycles += self.cpu.interrupt(1);
halfway = true;
for i in [1, 2] {
let mut cycles: u32 = 0;

while cycles < cycles_per_frame / 2 {
cycles += self.cpu.step();
}
self.cpu.interrupt(i);
}
self.cpu.interrupt(2);
}

fn handle_input(&mut self, events: &mut sdl2::EventPump) {
Expand Down

0 comments on commit 4901945

Please sign in to comment.