Add documentation
This commit is contained in:
16
README.md
16
README.md
@@ -3,21 +3,23 @@ chip8-rs
|
|||||||
|
|
||||||
Yet another chip8 emulator written in rust \o/
|
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
|
## Games
|
||||||
+ Fix tests for input
|
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
|
## System Dependencies
|
||||||
|
|
||||||
`sdl2` together with its dependencies are required to be installed on your hostmachine.
|
`sdl2` together with its dependencies are required to be installed on your hostmachine.
|
||||||
On Arch-based distros you can use these packages:
|
On Arch-based distros you can use these packages:
|
||||||
`sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_ttf`
|
`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:
|
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)
|
+ [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/)
|
+ [How to write an emulator (CHIP-8 interpreter)](http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/)
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ impl Display {
|
|||||||
});
|
});
|
||||||
let _ = self.canvas
|
let _ = self.canvas
|
||||||
.fill_rect(
|
.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();
|
self.canvas.present();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const OPCODE_SIZE: usize = 2;
|
|||||||
|
|
||||||
pub struct Processor {
|
pub struct Processor {
|
||||||
memory: [u8; crate::MEMORY_SIZE],
|
memory: [u8; crate::MEMORY_SIZE],
|
||||||
register: [u8; 16],
|
register: [u8; 16], // general purpose registers
|
||||||
index: usize, // used to store memory addresses
|
index: usize, // used to store memory addresses
|
||||||
pc: usize, // programm counter
|
pc: usize, // programm counter
|
||||||
screen: [[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT],
|
screen: [[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT],
|
||||||
@@ -21,7 +21,7 @@ pub struct Processor {
|
|||||||
sound_timer: usize,
|
sound_timer: usize,
|
||||||
stack: [usize; 16],
|
stack: [usize; 16],
|
||||||
sp: usize, // stack pointer
|
sp: usize, // stack pointer
|
||||||
key: [bool; 16],
|
key: [bool; 16], // bool table for keyinputs
|
||||||
waiting_for_key: bool,
|
waiting_for_key: bool,
|
||||||
waiting_key_location: usize,
|
waiting_key_location: usize,
|
||||||
}
|
}
|
||||||
@@ -56,11 +56,12 @@ impl Processor {
|
|||||||
let mut display = Display::new(&sdl_ctx);
|
let mut display = Display::new(&sdl_ctx);
|
||||||
let mut input = Input::new(&sdl_ctx);
|
let mut input = Input::new(&sdl_ctx);
|
||||||
|
|
||||||
|
// load binary file
|
||||||
self.load_game(&game);
|
self.load_game(&game);
|
||||||
|
|
||||||
loop {
|
while let Ok(key) = input.fetch() {
|
||||||
// get keyinput using sdl2
|
// get keypress from loop
|
||||||
self.key = input.fetch().unwrap();
|
self.key = key;
|
||||||
|
|
||||||
// emulate one cycle
|
// emulate one cycle
|
||||||
self.cycle();
|
self.cycle();
|
||||||
@@ -294,7 +295,7 @@ impl Processor {
|
|||||||
fn code_8xy5(&mut self, x: usize, y: usize) {
|
fn code_8xy5(&mut self, x: usize, y: usize) {
|
||||||
let x_val = self.register[x];
|
let x_val = self.register[x];
|
||||||
let y_val = self.register[y];
|
let y_val = self.register[y];
|
||||||
|
|
||||||
self.register[0x0f] = (x_val > y_val) as u8;
|
self.register[0x0f] = (x_val > y_val) as u8;
|
||||||
self.register[x] = x_val.wrapping_sub(y_val) as u8;
|
self.register[x] = x_val.wrapping_sub(y_val) as u8;
|
||||||
self.pc += OPCODE_SIZE;
|
self.pc += OPCODE_SIZE;
|
||||||
@@ -764,13 +765,13 @@ mod tests{
|
|||||||
// skip if equal
|
// skip if equal
|
||||||
let mut processor = new_processor();
|
let mut processor = new_processor();
|
||||||
processor.key[9] = true;
|
processor.key[9] = true;
|
||||||
processor.memory[3] = 9;
|
processor.register[3] = 9;
|
||||||
processor.decode_opcode(0xe39e);
|
processor.decode_opcode(0xe39e);
|
||||||
assert_eq!(processor.pc, SKIP);
|
assert_eq!(processor.pc, SKIP);
|
||||||
|
|
||||||
// dont skip
|
// dont skip
|
||||||
let mut processor = new_processor();
|
let mut processor = new_processor();
|
||||||
processor.memory[3] = 9;
|
processor.register[3] = 9;
|
||||||
processor.decode_opcode(0xe39e);
|
processor.decode_opcode(0xe39e);
|
||||||
assert_eq!(processor.pc, NEXT);
|
assert_eq!(processor.pc, NEXT);
|
||||||
}
|
}
|
||||||
@@ -780,13 +781,13 @@ mod tests{
|
|||||||
// skip if equal
|
// skip if equal
|
||||||
let mut processor = new_processor();
|
let mut processor = new_processor();
|
||||||
processor.key[9] = true;
|
processor.key[9] = true;
|
||||||
processor.memory[3] = 9;
|
processor.register[3] = 9;
|
||||||
processor.decode_opcode(0xe3a1);
|
processor.decode_opcode(0xe3a1);
|
||||||
assert_eq!(processor.pc, NEXT);
|
assert_eq!(processor.pc, NEXT);
|
||||||
|
|
||||||
// dont skip
|
// dont skip
|
||||||
let mut processor = new_processor();
|
let mut processor = new_processor();
|
||||||
processor.memory[3] = 9;
|
processor.register[3] = 9;
|
||||||
processor.decode_opcode(0xe3a1);
|
processor.decode_opcode(0xe3a1);
|
||||||
assert_eq!(processor.pc, SKIP);
|
assert_eq!(processor.pc, SKIP);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user