Skip to content

Commit a4ad504

Browse files
committed
more roms run for test
1 parent 9fe8316 commit a4ad504

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/lib.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Default for Chip8Emulator {
8989
impl Chip8Emulator {
9090
#[must_use]
9191
pub fn new() -> Self {
92-
let mut emu: Chip8Emulator = Default::default();
92+
let mut emu: Self = Default::default();
9393
emu.memory[..(16 * 5)].copy_from_slice(&FONT_SPRITES);
9494
emu
9595
}
@@ -105,7 +105,8 @@ impl Chip8Emulator {
105105
}
106106

107107
/// Return the state of the display
108-
pub fn get_display(&self) -> &[bool] {
108+
#[must_use]
109+
pub const fn get_display(&self) -> &[bool] {
109110
&self.display
110111
}
111112

@@ -123,7 +124,7 @@ impl Chip8Emulator {
123124
op_code
124125
}
125126

126-
pub fn tick_timers(&mut self) {
127+
pub const fn tick_timers(&mut self) {
127128
if self.delay_timer > 0 {
128129
self.delay_timer -= 1;
129130
}
@@ -406,7 +407,7 @@ impl Chip8Emulator {
406407
let x_coord = self.v_registers[x as usize] as u16;
407408
let y_coord = self.v_registers[y as usize] as u16;
408409

409-
let num_rows = d as u16;
410+
let num_rows = u16::from(d);
410411
let mut flipped = false;
411412
// Iterate over each row of our sprite
412413
for y_line in 0..num_rows {
@@ -552,6 +553,9 @@ impl Chip8Emulator {
552553
mod tests {
553554
use super::*;
554555

556+
#[test]
557+
fn
558+
555559
#[test]
556560
fn it_works() {
557561
let mut cpu = Chip8Emulator::new();
@@ -580,7 +584,7 @@ mod tests {
580584
}
581585

582586
#[test]
583-
fn load_rom() {
587+
fn load_rom_pong() {
584588
let mut cpu = Chip8Emulator::new();
585589
let bytes = include_bytes!("./roms/PONG");
586590
cpu.load_data(bytes);
@@ -589,6 +593,37 @@ mod tests {
589593
if cpu.tick().is_none() {
590594
break;
591595
}
596+
cpu.tick_timers();
597+
counter += 1;
598+
}
599+
}
600+
601+
#[test]
602+
fn load_rom_guess() {
603+
let mut cpu = Chip8Emulator::new();
604+
let bytes = include_bytes!("./roms/GUESS");
605+
cpu.load_data(bytes);
606+
let mut counter = 0;
607+
while counter < 10000 {
608+
if cpu.tick().is_none() {
609+
break;
610+
}
611+
cpu.tick_timers();
612+
counter += 1;
613+
}
614+
}
615+
616+
#[test]
617+
fn load_rom_maze() {
618+
let mut cpu = Chip8Emulator::new();
619+
let bytes = include_bytes!("./roms/MAZE");
620+
cpu.load_data(bytes);
621+
let mut counter = 0;
622+
while counter < 10000 {
623+
if cpu.tick().is_none() {
624+
break;
625+
}
626+
cpu.tick_timers();
592627
counter += 1;
593628
}
594629
}

0 commit comments

Comments
 (0)