almost timing
This commit is contained in:
parent
bb7e0fbc51
commit
0a6e0b6833
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -77,6 +77,7 @@ name = "gb-emu"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"spin_sleep",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -196,6 +197,16 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin_sleep"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cafa7900db085f4354dbc7025e25d7a839a14360ea13b5fc4fd717f2d3b23134"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
|
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
clap = {version = "4.1.1", features = ["derive"]}
|
||||
spin_sleep = "1.1.1"
|
|
@ -1,4 +1,4 @@
|
|||
use std::mem::transmute;
|
||||
use std::{mem::transmute, time::Duration};
|
||||
|
||||
use crate::{verbose_println, Memory};
|
||||
|
||||
|
@ -25,6 +25,10 @@ pub struct CPU {
|
|||
pub last_instruction_addr: u16,
|
||||
}
|
||||
|
||||
// MHz
|
||||
const CLOCK_SPEED: f64 = 4.194304 * 1000000.;
|
||||
const SPEEDUP: f64 = 1.;
|
||||
|
||||
impl CPU {
|
||||
pub fn exec_next(&mut self) {
|
||||
self.last_instruction_addr = self.reg.pc;
|
||||
|
@ -43,7 +47,10 @@ impl CPU {
|
|||
opcode,
|
||||
self.last_instruction_addr
|
||||
);
|
||||
self.run_opcode(opcode);
|
||||
let cycles = self.run_opcode(opcode);
|
||||
spin_sleep::sleep(Duration::from_secs_f64(
|
||||
(cycles * 4) as f64 / (CLOCK_SPEED * SPEEDUP),
|
||||
));
|
||||
}
|
||||
|
||||
fn next_opcode(&mut self) -> u8 {
|
||||
|
|
Loading…
Reference in a new issue