Processor: Fix input
This commit is contained in:
@@ -7,8 +7,8 @@ Yet another chip8 emulator written in rust \o/
|
|||||||
|
|
||||||
+ Expand on this README
|
+ Expand on this README
|
||||||
+ Add some documentation
|
+ Add some documentation
|
||||||
+ Add delay for beeper
|
+ Add sound for beeper
|
||||||
+ Fix input
|
+ Fix tests for input
|
||||||
|
|
||||||
## System Dependencies
|
## System Dependencies
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl Display {
|
|||||||
Display {
|
Display {
|
||||||
canvas,
|
canvas,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&mut self, pixel: &[[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT]) {
|
pub fn draw(&mut self, pixel: &[[u8; crate::SCREEN_WIDTH]; crate::SCREEN_HEIGHT]) {
|
||||||
for (y, &row) in pixel.iter().enumerate() {
|
for (y, &row) in pixel.iter().enumerate() {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
extern crate sdl2;
|
extern crate sdl2;
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
use crate::fontset::FONT;
|
use crate::fontset::FONT;
|
||||||
use crate::display::Display;
|
use crate::display::Display;
|
||||||
@@ -71,8 +73,8 @@ impl Processor {
|
|||||||
// play sound using sdl2
|
// play sound using sdl2
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// add delay
|
// modern pc's are too fast :o
|
||||||
// TODO
|
thread::sleep(Duration::from_millis(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +209,7 @@ impl Processor {
|
|||||||
|
|
||||||
// Call subroutine at nnn
|
// Call subroutine at nnn
|
||||||
fn code_2nnn(&mut self, nnn: usize) {
|
fn code_2nnn(&mut self, nnn: usize) {
|
||||||
self.stack[self.sp] = self.pc;
|
self.stack[self.sp] = self.pc + 2;
|
||||||
self.sp += 1;
|
self.sp += 1;
|
||||||
self.pc = nnn;
|
self.pc = nnn;
|
||||||
}
|
}
|
||||||
@@ -519,11 +521,10 @@ mod tests{
|
|||||||
fn test_code_2nnn() {
|
fn test_code_2nnn() {
|
||||||
let mut processor = new_processor();
|
let mut processor = new_processor();
|
||||||
processor.sp = 0;
|
processor.sp = 0;
|
||||||
let current = processor.pc;
|
|
||||||
processor.decode_opcode(0x2333);
|
processor.decode_opcode(0x2333);
|
||||||
assert_eq!(processor.sp, 1);
|
assert_eq!(processor.sp, 1);
|
||||||
assert_eq!(processor.pc, 0x0333);
|
assert_eq!(processor.pc, 0x0333);
|
||||||
assert_eq!(processor.stack[0], current);
|
assert_eq!(processor.stack[0], NEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user