diff --git a/README.md b/README.md index d4691a5..f4074a4 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,23 @@ chip8-rs Yet another chip8 emulator written in rust \o/ -## TODO +If you encounter any problems, I encourage you to open a PR! -+ Expand on this README -+ Add some documentation -+ Add sound for beeper -+ Fix tests for input +![PONG](media/pong.png) + +## Games +Due to legal reasons, I can't provide any games nor links to them. +But they can be easily found by using a search engine! ## System Dependencies - `sdl2` together with its dependencies are required to be installed on your hostmachine. On Arch-based distros you can use these packages: `sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_ttf` -## Credits +## TODO +[ ] Add Beeper Sound +## Credits For this project I used the help from the following sites: + [Chip-8 Technical Reference](http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#3.0) + [How to write an emulator (CHIP-8 interpreter)](http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/) diff --git a/pong.png b/pong.png new file mode 100644 index 0000000..c93499a Binary files /dev/null and b/pong.png differ diff --git a/src/display.rs b/src/display.rs index 6e49487..086d27c 100644 --- a/src/display.rs +++ b/src/display.rs @@ -44,7 +44,10 @@ impl Display { }); let _ = self.canvas .fill_rect( - Rect::new((x * crate::SCREEN_SCALE) as i32, (y * crate::SCREEN_SCALE) as i32, crate::SCREEN_SCALE as u32, crate::SCREEN_SCALE as u32)); + Rect::new((x * crate::SCREEN_SCALE) as i32, + (y * crate::SCREEN_SCALE) as i32, + crate::SCREEN_SCALE as u32, + crate::SCREEN_SCALE as u32)); } } self.canvas.present(); diff --git a/src/processor.rs b/src/processor.rs index febbc3c..0c2b9b8 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -12,7 +12,7 @@ const OPCODE_SIZE: usize = 2; pub struct Processor { memory: [u8; crate::MEMORY_SIZE], - register: [u8; 16], + register: [u8; 16], // general purpose registers index: usize, // used to store memory addresses pc: usize, // programm counter screen: [[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT], @@ -21,7 +21,7 @@ pub struct Processor { sound_timer: usize, stack: [usize; 16], sp: usize, // stack pointer - key: [bool; 16], + key: [bool; 16], // bool table for keyinputs waiting_for_key: bool, waiting_key_location: usize, } @@ -56,11 +56,12 @@ impl Processor { let mut display = Display::new(&sdl_ctx); let mut input = Input::new(&sdl_ctx); + // load binary file self.load_game(&game); - loop { - // get keyinput using sdl2 - self.key = input.fetch().unwrap(); + while let Ok(key) = input.fetch() { + // get keypress from loop + self.key = key; // emulate one cycle self.cycle(); @@ -294,7 +295,7 @@ impl Processor { fn code_8xy5(&mut self, x: usize, y: usize) { let x_val = self.register[x]; let y_val = self.register[y]; - + self.register[0x0f] = (x_val > y_val) as u8; self.register[x] = x_val.wrapping_sub(y_val) as u8; self.pc += OPCODE_SIZE; @@ -764,13 +765,13 @@ mod tests{ // skip if equal let mut processor = new_processor(); processor.key[9] = true; - processor.memory[3] = 9; + processor.register[3] = 9; processor.decode_opcode(0xe39e); assert_eq!(processor.pc, SKIP); // dont skip let mut processor = new_processor(); - processor.memory[3] = 9; + processor.register[3] = 9; processor.decode_opcode(0xe39e); assert_eq!(processor.pc, NEXT); } @@ -780,13 +781,13 @@ mod tests{ // skip if equal let mut processor = new_processor(); processor.key[9] = true; - processor.memory[3] = 9; + processor.register[3] = 9; processor.decode_opcode(0xe3a1); assert_eq!(processor.pc, NEXT); // dont skip let mut processor = new_processor(); - processor.memory[3] = 9; + processor.register[3] = 9; processor.decode_opcode(0xe3a1); assert_eq!(processor.pc, SKIP); }