execute 7 instructions per frame
This commit is contained in:
parent
afe5ed835e
commit
b447f0ccee
1 changed files with 13 additions and 8 deletions
|
@ -8,7 +8,8 @@ use rand::Rng;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Instant;
|
use std::thread::sleep;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
/// Represents the display's width in pixels.
|
/// Represents the display's width in pixels.
|
||||||
const DISPLAY_WIDTH: usize = 64;
|
const DISPLAY_WIDTH: usize = 64;
|
||||||
|
@ -126,15 +127,20 @@ where
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let elapsed_time = now.duration_since(tick_timer);
|
let elapsed_time = now.duration_since(tick_timer);
|
||||||
let elapsed_seconds = elapsed_time.as_secs_f32();
|
let elapsed_seconds = elapsed_time.as_secs_f32();
|
||||||
if elapsed_seconds >= 1.0 / target_fps {
|
if elapsed_seconds >= (1.0 / target_fps) {
|
||||||
// fetch instruction & decode it
|
for _ in 0..=7 {
|
||||||
let instruction = self.fetch_instruction()?;
|
// fetch instruction & decode it
|
||||||
self.program_counter += 2;
|
let instruction = self.fetch_instruction()?;
|
||||||
|
self.program_counter += 2;
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
self.execute_instruction(instruction)?;
|
self.execute_instruction(instruction)?;
|
||||||
|
}
|
||||||
|
|
||||||
tick_timer = Instant::now();
|
tick_timer = Instant::now();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sleep(Duration::from_millis(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +229,6 @@ where
|
||||||
} else {
|
} else {
|
||||||
self.registers[0xF] = 0;
|
self.registers[0xF] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.display.render(&self.display_data);
|
self.display.render(&self.display_data);
|
||||||
}
|
}
|
||||||
ProcessorInstruction::Return => {
|
ProcessorInstruction::Return => {
|
||||||
|
|
Loading…
Reference in a new issue