vblank should be working
This commit is contained in:
parent
8b9bcb5026
commit
f87fe618fd
|
@ -265,6 +265,8 @@ fn main() {
|
|||
reg,
|
||||
last_instruction: 0x0,
|
||||
last_instruction_addr: 0x0,
|
||||
vblank_timer: 0.,
|
||||
vblank_remaining: 0,
|
||||
};
|
||||
cpu_ram_init(&mut cpu);
|
||||
let mut cycle_num = 0;
|
||||
|
|
|
@ -23,6 +23,8 @@ pub struct CPU {
|
|||
pub reg: Registers,
|
||||
pub last_instruction: u8,
|
||||
pub last_instruction_addr: u16,
|
||||
pub vblank_timer: f64,
|
||||
pub vblank_remaining: u8,
|
||||
}
|
||||
|
||||
// Hz
|
||||
|
@ -43,6 +45,12 @@ impl CPU {
|
|||
}
|
||||
}
|
||||
|
||||
if self.vblank_timer >= (1. / 59.7) {
|
||||
self.vblank_timer = 0.;
|
||||
self.vblank_remaining = 20;
|
||||
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0));
|
||||
}
|
||||
|
||||
verbose_println!(
|
||||
"exec {:#4X} from pc: {:#X}",
|
||||
opcode,
|
||||
|
@ -58,6 +66,15 @@ impl CPU {
|
|||
fn increment_timers(&mut self, cycles: u8) {
|
||||
let secs = (cycles * 4) as f64 / (CLOCK_SPEED * SPEEDUP);
|
||||
|
||||
self.vblank_timer += secs;
|
||||
if self.vblank_remaining > 0 {
|
||||
self.vblank_remaining = self.vblank_remaining.saturating_sub(cycles);
|
||||
if self.vblank_remaining == 0 {
|
||||
self.memory
|
||||
.set(0xFF0F, clear_bit(self.memory.get(0xFF0F), 0));
|
||||
}
|
||||
}
|
||||
|
||||
self.memory.set(
|
||||
0xFF04,
|
||||
self.memory
|
||||
|
@ -245,8 +262,12 @@ fn get_bit(byte: u8, flag: u8) -> bool {
|
|||
return got > 0x0;
|
||||
}
|
||||
|
||||
fn set_bit(byte: u8, flag: u8) -> u8 {
|
||||
byte | (1 << flag)
|
||||
}
|
||||
|
||||
fn clear_bit(byte: u8, flag: u8) -> u8 {
|
||||
byte & (!(1 << flag as u8))
|
||||
byte & (!(1 << flag))
|
||||
}
|
||||
|
||||
fn rotate(byte: u8, direction: &Direction) -> (u8, bool) {
|
||||
|
|
Loading…
Reference in a new issue