Skip to content

Commit

Permalink
Format source
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobMillward committed Feb 28, 2023
1 parent fbdebe0 commit 2a0f683
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/chip8/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl CPU {
// CALL addr
(2, _, _, _) => {
self.registers.inc_pc();
self.return_stack.push(self.registers.pc).expect("Unable to push value to stack");
self.return_stack
.push(self.registers.pc)
.expect("Unable to push value to stack");
self.registers.pc = nnn;
}
// SE Vx, byte
Expand Down
29 changes: 16 additions & 13 deletions src/chip8/return_stack.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#[derive(Debug, PartialEq)]
pub(super) enum StackError {
Overflow,
Underflow
Underflow,
}



pub(super) struct ReturnStack {
stack: [u16; 16],
sp: u8,
Expand All @@ -32,7 +30,6 @@ impl ReturnStack {
pub fn pop(&mut self) -> Result<u16, StackError> {
if self.sp == 0 {
return Err(StackError::Underflow);

}

self.sp -= 1;
Expand Down Expand Up @@ -63,10 +60,13 @@ mod tests {
let result = stack.push(1);
assert!(result.is_err());

assert_eq!( match result {
Ok(_) => unreachable!(),
Err(err) => err
}, StackError::Overflow);
assert_eq!(
match result {
Ok(_) => unreachable!(),
Err(err) => err,
},
StackError::Overflow
);
}

#[test]
Expand All @@ -76,9 +76,12 @@ mod tests {
let result = stack.pop();
assert!(result.is_err());

assert_eq!( match result {
Ok(_) => unreachable!(),
Err(err) => err
}, StackError::Underflow);
assert_eq!(
match result {
Ok(_) => unreachable!(),
Err(err) => err,
},
StackError::Underflow
);
}
}
}
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
extern crate minifb;

use std::{
fs::File,
io::Read
};
use clap::Parser;
use std::{fs::File, io::Read};

mod chip8;
mod window;
Expand All @@ -24,7 +21,6 @@ fn main() {
let mut file = File::open(args.input_rom).unwrap();
let mut data = Vec::<u8>::new();
file.read_to_end(&mut data).expect("File not found!");

run_chip8_program(&data);
}

0 comments on commit 2a0f683

Please sign in to comment.