Skip to content

Commit

Permalink
Expose more internal members
Browse files Browse the repository at this point in the history
  • Loading branch information
msub2 committed Apr 20, 2024
1 parent c7cdd42 commit 2f85d10
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions src/chip8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,55 @@ impl Chip8 {
memory_slice.copy_from_slice(bytes.as_slice());
}

pub fn get_memory(&self) -> Vec<u8> {
Vec::from(&self.memory)
}

/// Get screen pixel data as a sequence of Uint8s
pub fn get_display(&self) -> Vec<u8> {
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<u16> {
Vec::from(self.stack.clone())
}

pub fn get_keypad(&self) -> Vec<u8> {
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<u8> {
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;
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f85d10

Please sign in to comment.