From 22e0217890fdc2a1ff992e44ebe7c655cbd90989 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 25 Jan 2023 19:40:31 +0100 Subject: [PATCH] print emulator state as hex --- src/emulator/main.rs | 9 +++++---- test | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 test diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 52a635b..42be8d8 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -95,11 +95,12 @@ fn set_register(register: Register, value: u8, state: &mut EmulatorState) { fn print_state(state: &EmulatorState) { // State println!("\nsp\tpc\tei"); - println!("{}\t{}\t{}", state.sp, state.pc, state.ei); + println!("{:#06x}\t{:#06x}\t{}", state.sp, state.pc, state.ei); // Registers println!("\nB\tC\tD\tE\tH\tL\tA"); - println!("{}\t{}\t{}\t{}\t{}\t{}\t{}", state.b, state.c, state.d, state.e, state.h, state.l, state.a); + println!("{:#04x}\t{:#04x}\t{:#04x}\t{:#04x}\t{:#04x}\t{:#04x}\t{:#04x}", + state.b, state.c, state.d, state.e, state.h, state.l, state.a); // Flags println!("\nz\ts\tp\tc"); @@ -129,11 +130,11 @@ fn main() { .expect("Provide a path to a ROM file to emulate as an argument"); let file = fs::read(filename).expect("where file"); - for i in 0..8192 { + for i in 0..(MEMORY_SIZE.min(file.len())) { state.memory[i] = file[i]; } - while state.pc < 8192 { + while state.pc < MEMORY_SIZE as u16 { tick(&mut state); } diff --git a/test b/test new file mode 100644 index 0000000..c595b2d --- /dev/null +++ b/test @@ -0,0 +1 @@ +ÆdÆóv \ No newline at end of file