diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index ea70f4c080ee7ae3445a812a12bd562b9d32c657..4c4955ff8261288e33d219d1d13d245eaffae2d8 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -27,6 +27,7 @@ const COLORS: [[u8; 3]; 6] = [ const LOGIC_HZ: u32 = 480; const VISUAL_HZ: u32 = 60; const IDLE_HZ: u32 = 60; +const TIMER_HZ: u32 = 60; const BEEP_DURATION: f32 = 0.1; @@ -87,6 +88,7 @@ pub struct State { logic_frequency: u32, visual_frequency: u32, idle_frequency: u32, + timer_frequency: u32, screen_scale: f32, beep_duration: f32, next_tick_time: u32, @@ -112,6 +114,7 @@ fn main() { logic_frequency: LOGIC_HZ, visual_frequency: VISUAL_HZ, idle_frequency: IDLE_HZ, + timer_frequency: TIMER_HZ, screen_scale: SCREEN_SCALE, beep_duration: BEEP_DURATION, next_tick_time: 0, @@ -313,9 +316,19 @@ fn main() { // to make sure that the proper number of updates are performed let logic_visual_ratio = state.logic_frequency / state.visual_frequency; for _ in 0..logic_visual_ratio { - // runs the tick operation in the CHIP-8 system, + // runs the clock operation in the CHIP-8 system, // effectively changing the logic state of the machine - state.system.tick(); + state.system.clock(); + } + + // calculates the ration between the timer and the visual frequency + // so that the proper timer updates are rune + let timer_visual_ratio = state.timer_frequency / state.visual_frequency; + for _ in 0..timer_visual_ratio { + // runs the clock for the timers (both sound and delay), + // after that tries to determine if a beep should be sounded + state.system.clock_dt(); + state.system.clock_st(); beep |= state.system.beep(); } diff --git a/src/chip8.rs b/src/chip8.rs index d282dbf9c4b74644aacb5ba78cf044264b519b00..c4898f2b09070e37ecdec703b23069f2becb9602 100644 --- a/src/chip8.rs +++ b/src/chip8.rs @@ -128,12 +128,6 @@ impl Chip8 { self.ram[ROM_START..ROM_START + rom.len()].clone_from_slice(rom); } - pub fn tick(&mut self) { - self.clock(); - self.clock_dt(); - self.clock_st(); - } - pub fn clock(&mut self) { let opcode = self.fetch_opcode(); self.process_opcode(opcode); diff --git a/src/chip8_neo.rs b/src/chip8_neo.rs index eb9724b1383d9bdaa8004b63df26be30e53c39a8..ab881937c8f54916e0c81d4f4cdfbb4c79a7d0df 100644 --- a/src/chip8_neo.rs +++ b/src/chip8_neo.rs @@ -5,7 +5,7 @@ pub const STACK_SIZE: usize = 16; pub const REGISTERS_SIZE: usize = 16; /// The starting address for the ROM loading, should be -/// the initial PC position. +/// the initial PC position for execution. const ROM_START: usize = 0x200; static FONT_SET: [u8; 80] = [