diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 363ddb1d6ee7c564637b9545140fe6a7521a687e..e86ce7a185a35f6d7f8f581214f011678cca5ac4 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -94,11 +94,12 @@ pub struct State { next_tick_time: u32, beep_ticks: u32, pixel_color: [u8; 3], + diag_color: [u8; 3], pixel_color_index: u32, title: String, rom_name: String, rom_loaded: bool, - diagnostics: bool, + diag: bool, } impl State { @@ -121,11 +122,12 @@ fn main() { next_tick_time: 0, beep_ticks: 0, pixel_color: COLORS[0], + diag_color: COLORS[1], pixel_color_index: 0, title: String::from(TITLE_INITIAL), rom_name: String::from("unloaded"), rom_loaded: false, - diagnostics: false, + diag: false, }; // initializes the SDL sub-system @@ -250,6 +252,8 @@ fn main() { } => { state.pixel_color_index = (state.pixel_color_index + 1) % COLORS.len() as u32; state.pixel_color = COLORS[state.pixel_color_index as usize]; + let diag_color_index = (state.pixel_color_index + 2) % COLORS.len() as u32; + state.diag_color = COLORS[diag_color_index as usize]; None } @@ -257,7 +261,7 @@ fn main() { keycode: Some(Keycode::T), .. } => { - state.diagnostics = !state.diagnostics; + state.diag = !state.diag; None } @@ -376,12 +380,13 @@ fn main() { // draws the diagnostics information to the canvas in case the // current state is requesting the display of it - if state.diagnostics { + if state.diag { let x = 12; let mut y = 12; let padding = 2; let text = format!( - "ROM: {}\nFrequency: {} Hz\nDisplay: {} fps\nPC: 0x{:04x}\nSP: 0x{:04x}", + "Engine: {}\nROM: {}\nFrequency: {} Hz\nDisplay: {} fps\nPC: 0x{:04x}\nSP: 0x{:04x}", + state.system.name(), state.rom_name, state.logic_frequency, state.visual_frequency, @@ -394,9 +399,9 @@ fn main() { let surface = font .render(part) .blended(Color::RGBA( - state.pixel_color[0], - state.pixel_color[1], - state.pixel_color[2], + state.diag_color[0], + state.diag_color[1], + state.diag_color[2], 255, )) .unwrap(); diff --git a/src/chip8.rs b/src/chip8.rs index 7091ebd100137dd2b7f8ad61d735fc99c7b444f4..ce6b37e0f77a8e2a87e06d6c937380c706c1da54 100644 --- a/src/chip8.rs +++ b/src/chip8.rs @@ -108,6 +108,10 @@ impl Chip8 { self.reset(); } + pub fn name(&self) -> &str { + "classic" + } + pub fn pixels(&self) -> Vec<u8> { self.vram.to_vec() } diff --git a/src/chip8_neo.rs b/src/chip8_neo.rs index 3a983cdf58b3435fe7feede421bf11856ea5c7ec..43e0ce2e2bc3158bb2d728807856d8a67bb4b1b7 100644 --- a/src/chip8_neo.rs +++ b/src/chip8_neo.rs @@ -84,6 +84,10 @@ impl Chip8Neo { self.reset(); } + pub fn name(&self) -> &str { + "neo" + } + pub fn pixels(&self) -> Vec<u8> { self.vram.to_vec() } @@ -93,7 +97,7 @@ impl Chip8Neo { // the PC (program counter) accordingly let instruction = (self.ram[self.pc as usize] as u16) << 8 | self.ram[self.pc as usize + 1] as u16; - self.pc += 0x2; + self.pc += 2; let opcode = instruction & 0xf000; let address = instruction & 0x0fff; @@ -254,6 +258,7 @@ impl Chip8Neo { self.vram = [0u8; DISPLAY_WIDTH * DISPLAY_HEIGHT]; } + #[inline(always)] fn draw_sprite(&mut self, x0: usize, y0: usize, height: usize) { self.regs[0xf] = 0; for y in 0..height {