Skip to content

Commit

Permalink
Load addr, jump to addr plus v0 and random byte
Browse files Browse the repository at this point in the history
  • Loading branch information
mateodif committed Jun 17, 2023
1 parent 3ba151d commit 0352c38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ channel = "nightly"

[dependencies]
itertools = "0.10.5"
rand = "0.8.5"
16 changes: 13 additions & 3 deletions src/chip8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::default::Default;
use std::fs::read;
use std::path::Path;
use rand::Rng;

pub const MEMORY_SIZE: usize = 4 * 1024; // 0x1000 directions, from 0x0 to 0xFFF.
pub const DISPLAY_SIZE: usize = 64 * 32;
Expand Down Expand Up @@ -143,6 +144,7 @@ impl CHIP8 {
self.memory[i + start_address as usize] = slice[i];
}
}

pub fn load_from_file(&mut self, path: &Path) {
let path = path.canonicalize().unwrap();
let file = read(path).unwrap();
Expand Down Expand Up @@ -278,9 +280,17 @@ impl CHIP8 {
self.pc += 2;
}
},
Instruction::LoadAddressIntoIndex { address } => todo!(),
Instruction::JumpToAddressPlusV0 { address } => todo!(),
Instruction::RandomByteAndIntoRegister { register, byte } => todo!(),
Instruction::LoadAddressIntoIndex { address } => {
self.index = address;
},
Instruction::JumpToAddressPlusV0 { address } => {
self.pc = address + self.registers[0x0 as usize] as u16;
},
Instruction::RandomByteAndIntoRegister { register, byte } => {
let mut rng = rand::thread_rng();
let randint = rng.gen_range(0..255);
self.registers[register as usize] = byte & randint;
},
Instruction::DrawSprite { register1, register2, nibble } => todo!(),
Instruction::SkipIfKeyPressed { register } => todo!(),
Instruction::SkipIfKeyNotPressed { register } => todo!(),
Expand Down

0 comments on commit 0352c38

Please sign in to comment.