trevors_chip8_toy/gemma/src/chip8/delay_timer.rs
Trevor Merritt 67ca71ccb7 my first schip rom works in my schip emulator.
BUGFIX: Corrects runaway after drawing in my first schip rom
scroll down, left, right all test with test rom
assembler now assembles to the expected output it seems
fixes incorrect loading of schip font to memory
replaces schip font from new chatgpt feedback
2024-11-06 10:40:52 -05:00

37 lines
636 B
Rust

use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct DelayTimer {
counter: u8,
}
impl Default for DelayTimer {
fn default() -> Self {
Self::new()
}
}
impl DelayTimer {
pub fn current(&self) -> u8 {
self.counter
}
pub fn new() -> Self {
DelayTimer { counter: 0xff }
}
pub fn reset(&mut self) {
self.counter = 0xff;
}
pub fn set_timer(&mut self, new_value: u8) {
self.counter = new_value
}
pub fn tick(&mut self) {
if self.counter > 0 {
self.counter -= 1;
}
}
}