Processor: Fix input

This commit is contained in:
Marco Thomas
2021-06-11 17:52:28 +02:00
parent fcc40065a7
commit 6a6dddff91
3 changed files with 9 additions and 8 deletions

View File

@@ -7,8 +7,8 @@ Yet another chip8 emulator written in rust \o/
+ Expand on this README
+ Add some documentation
+ Add delay for beeper
+ Fix input
+ Add sound for beeper
+ Fix tests for input
## System Dependencies

View File

@@ -30,7 +30,7 @@ impl Display {
Display {
canvas,
}
}
}
pub fn draw(&mut self, pixel: &[[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT]) {
for (y, &row) in pixel.iter().enumerate() {

View File

@@ -1,6 +1,8 @@
extern crate sdl2;
use rand::Rng;
use std::time::Duration;
use std::thread;
use crate::fontset::FONT;
use crate::display::Display;
@@ -71,8 +73,8 @@ impl Processor {
// play sound using sdl2
// TODO
// add delay
// TODO
// modern pc's are too fast :o
thread::sleep(Duration::from_millis(3));
}
}
@@ -207,7 +209,7 @@ impl Processor {
// Call subroutine at nnn
fn code_2nnn(&mut self, nnn: usize) {
self.stack[self.sp] = self.pc;
self.stack[self.sp] = self.pc + 2;
self.sp += 1;
self.pc = nnn;
}
@@ -519,11 +521,10 @@ mod tests{
fn test_code_2nnn() {
let mut processor = new_processor();
processor.sp = 0;
let current = processor.pc;
processor.decode_opcode(0x2333);
assert_eq!(processor.sp, 1);
assert_eq!(processor.pc, 0x0333);
assert_eq!(processor.stack[0], current);
assert_eq!(processor.stack[0], NEXT);
}
#[test]