From 6f7b894e922809721694f7eb11183979f3d18d49 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Fri, 11 Oct 2024 09:50:01 -0400 Subject: [PATCH] Gemma now has a test that runs the IBM Logo and verifies the video is as expected when done. --- gemma/src/chip8/instructions.rs | 6 +- gemma/tests/computer_tests.rs | 12 +++- gemmaegui/src/bin/gemmaegui.rs | 1 - .../test/gemma_integration_ibm_rom_output.asc | 64 +++++++++---------- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/gemma/src/chip8/instructions.rs b/gemma/src/chip8/instructions.rs index 7280fd7..b7840d7 100644 --- a/gemma/src/chip8/instructions.rs +++ b/gemma/src/chip8/instructions.rs @@ -1190,7 +1190,7 @@ mod test { x.registers.poke(0x1, 0x10); x.registers.poke(0x2, 0x08); Chip8CpuInstructions::SubVxVy(0x1, 0x02).execute(&mut x); - assert_eq!(x.registers.peek(0xf), 0); + assert_eq!(x.registers.peek(0xf), 1); assert_eq!(x.registers.peek(0x1), 0x8); assert_eq!(x.registers.peek_pc(), 0x202); } @@ -1249,7 +1249,7 @@ mod test { // expect the result to be 0x0b assert_eq!(x.registers.peek(0x1), 0x0b); // expect the vf register to be set to 1 as there was overflow - assert_eq!(x.registers.peek(0xf), 0x0); + assert_eq!(x.registers.peek(0xf), 0x1); let mut x = Chip8Computer::new(); x.registers.poke(0x01, 0xab); @@ -1258,7 +1258,7 @@ mod test { // expect the result to be 11110101, -0xB, -11, 245, 0xF5 assert_eq!(x.registers.peek(0x1), 0xf5); - assert_eq!(x.registers.peek(0xf), 0x1); + assert_eq!(x.registers.peek(0xf), 0x0); } #[test] diff --git a/gemma/tests/computer_tests.rs b/gemma/tests/computer_tests.rs index f0035f9..90f3210 100644 --- a/gemma/tests/computer_tests.rs +++ b/gemma/tests/computer_tests.rs @@ -6,11 +6,17 @@ fn smoke() { assert!(true) } #[test] fn test_rom_1_works() { let mut x = Chip8Computer::new(); - // Load the IBM rom and run it... + // Load the IBM rom and run it. + // it takes 39 cycles to get to the end so lets run it 40. + + let test_rom_to_run = std::fs::read("../resources/roms/2-ibm-logo.ch8").unwrap(); + x.load_bytes_to_memory(0x200, test_rom_to_run.into()); + for i in 0..40 { + x.step_system(); + } // ...then verify that the current video memory of the chip-8 // simulator matches what we expect it to be - assert_eq!(x.dump_video_to_string(), ); - + assert_eq!(x.dump_video_to_string(), std::fs::read_to_string("../resources/test/gemma_integration_ibm_rom_output.asc").unwrap()); } diff --git a/gemmaegui/src/bin/gemmaegui.rs b/gemmaegui/src/bin/gemmaegui.rs index 52de01e..107515c 100644 --- a/gemmaegui/src/bin/gemmaegui.rs +++ b/gemmaegui/src/bin/gemmaegui.rs @@ -35,7 +35,6 @@ fn controls_view(mut system: &mut Chip8Computer, state: &mut EmmaEGuiState, ui: ui.checkbox(&mut state.display_memory, "Display Memory"); ui.checkbox(&mut state.display_video, "Display Video"); ui.checkbox(&mut state.display_registers, "Display Registers"); - } fn registers_view(system: &Chip8Computer, ui:& mut Ui) { diff --git a/resources/test/gemma_integration_ibm_rom_output.asc b/resources/test/gemma_integration_ibm_rom_output.asc index f66cb76..2dfb029 100644 --- a/resources/test/gemma_integration_ibm_rom_output.asc +++ b/resources/test/gemma_integration_ibm_rom_output.asc @@ -1,32 +1,32 @@ - - - - - - - - - ******** ********* ***** ***** * * - * * - ******** *********** ****** ****** * - - **** *** *** ***** ***** * * - *** - **** ******* ******* ******* * - * - **** ******* *** ******* *** - * - **** *** *** *** ***** *** - *** - ******** *********** ***** *** ***** * - ** - ******** ********* ***** * ***** *** - - - - - - - - - + + + + + + + + + ******** ********* ***** ***** * * + * * + ******** *********** ****** ****** * + + **** *** *** ***** ***** * * + *** + **** ******* ******* ******* * + * + **** ******* *** ******* *** + * + **** *** *** *** ***** *** + *** + ******** *********** ***** *** ***** * + ** + ******** ********* ***** * ***** *** + + + + + + + + +