Created
September 29, 2019 17:33
-
-
Save dgnsrekt/1a6c5850fae483cd311d87976bf9fce4 to your computer and use it in GitHub Desktop.
chip8 memory debugger concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MAX_MEMORY: usize = 4096; | |
fn main() { | |
let mut memory: Vec<u32> = vec![0; MAX_MEMORY]; | |
memory[25] = 0x200; | |
memory[31] = 0xFFF; | |
memory[0x60] = 0x00E0; | |
memory[0xFFF] = 0xFFF; | |
let debug_address: usize = 0x60; | |
let debug_range: usize = 5; | |
let mut min_address: usize = 0; | |
let mut max_address: usize = 0; | |
if debug_address >= debug_range { | |
min_address = debug_address - debug_range; | |
max_address = debug_address + debug_range; | |
} else { | |
let debug_address: usize = debug_range; | |
min_address = debug_address - debug_range; | |
max_address = debug_address + debug_range; | |
} | |
let instruction = "CLEAR SCREEN"; | |
println!("ADDRS HEX DEC"); | |
memory | |
.iter() | |
.enumerate() | |
.filter(|(i, _x)| i >= &min_address) | |
.filter(|(i, _x)| i <= &max_address) | |
.for_each(|(i, x)| { | |
if i == debug_address { | |
println!("0x{0:04X} 0x{1:04X?} {1:04} <<< {2}", i, x, instruction) | |
} else { | |
println!("0x{0:04X} 0x{1:04X?} {1:04}", i, x) | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment