From 2f85d10ce25d0cacf167228d802830a12f1d4f2a Mon Sep 17 00:00:00 2001 From: Daniel Adams Date: Sat, 20 Apr 2024 08:40:01 -1000 Subject: [PATCH] Expose more internal members --- src/chip8.rs | 58 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/chip8.rs b/src/chip8.rs index f6e8976..5669cdd 100644 --- a/src/chip8.rs +++ b/src/chip8.rs @@ -126,11 +126,55 @@ impl Chip8 { memory_slice.copy_from_slice(bytes.as_slice()); } + pub fn get_memory(&self) -> Vec { + Vec::from(&self.memory) + } + /// Get screen pixel data as a sequence of Uint8s pub fn get_display(&self) -> Vec { Vec::from(&self.display) } + pub fn get_pc(&self) -> u16 { + self.pc + } + + pub fn get_delay_timer(&self) -> u8 { + self.delay_timer + } + + pub fn get_sound_timer(&self) -> u8 { + self.sound_timer + } + + pub fn get_stack(&self) -> Vec { + Vec::from(self.stack.clone()) + } + + pub fn get_keypad(&self) -> Vec { + self.keypad.iter().map(|x| if *x { 1 } else { 0 }).collect() + } + + pub fn get_index(&self) -> u16 { + self.i + } + + pub fn get_registers(&self) -> Vec { + Vec::from(&self.registers) + } + + pub fn displayed_this_frame(&self) -> bool { + self.displayed + } + + pub fn hires_mode(&self) -> bool { + self.hires_mode + } + + pub fn get_current_opcode(&self) -> u16 { + ((self.memory[self.pc as usize] as u16) << 8) | (self.memory[(self.pc + 1) as usize] as u16) + } + /// Execute the next instruction at the program counter pub fn run(&mut self) { self.displayed = false; @@ -363,7 +407,7 @@ impl Chip8 { let width = if n == 0 && self.variant != Variant::CHIP8 { 16_u16 } else { 8_u16 }; // The height of the sprite (16 if SCHIP and N = 0, otherwise N) let height = if n == 0 && self.variant != Variant::CHIP8 { 16_u16 } else { n as u16 }; - // The maximum width od the display + // The maximum width of the display let max_width = if self.hires_mode { 128_u16 } else { 64_u16 }; // The maximum height of the display let max_height = if self.hires_mode { 64_u16 } else { 32_u16 }; @@ -521,18 +565,6 @@ impl Chip8 { } } - pub fn get_sound_timer(&self) -> u8 { - self.sound_timer - } - - pub fn displayed_this_frame(&self) -> bool { - self.displayed - } - - pub fn hires_mode(&self) -> bool { - self.hires_mode - } - fn get_keypad_value_from_index(&self, key_index: u8) -> u8 { // TODO: Account for keypad layout variations // Assuming standard for now