This commit is contained in:
@@ -7,6 +7,8 @@ use std::sync::{Arc, Mutex};
|
|||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use super::registers::RegisterFile;
|
||||||
|
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
pub registers: RegisterFile,
|
pub registers: RegisterFile,
|
||||||
pub memory: Box<[u8; Self::DEVICE_MEMORY_SIZE]>,
|
pub memory: Box<[u8; Self::DEVICE_MEMORY_SIZE]>,
|
||||||
@@ -34,7 +36,7 @@ impl Device {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
log::trace!("Successfully initiated device memory");
|
log::trace!("Successfully initiated device memory");
|
||||||
Device {
|
Device {
|
||||||
registers: RegisterFile::new(),
|
registers: RegisterFile::default(),
|
||||||
memory,
|
memory,
|
||||||
frame_buffer: fb,
|
frame_buffer: fb,
|
||||||
stack: Vec::with_capacity(16),
|
stack: Vec::with_capacity(16),
|
||||||
@@ -46,10 +48,10 @@ impl Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Device {
|
impl Device {
|
||||||
|
pub const ROM_START: usize = 0x200;
|
||||||
const FONT_HEIGHT: u16 = 5;
|
const FONT_HEIGHT: u16 = 5;
|
||||||
const FONT_DEFAULT_MEM_LOCATION_START: usize = 0x50;
|
const FONT_DEFAULT_MEM_LOCATION_START: usize = 0x50;
|
||||||
const FONT_DEFAULT_MEM_LOCATION_END: usize = 0x9F;
|
const FONT_DEFAULT_MEM_LOCATION_END: usize = 0x9F;
|
||||||
const ROM_START: usize = 0x200;
|
|
||||||
|
|
||||||
pub fn cycle(&mut self) -> EmulatorResult<()> {
|
pub fn cycle(&mut self) -> EmulatorResult<()> {
|
||||||
let time_start = std::time::Instant::now();
|
let time_start = std::time::Instant::now();
|
||||||
@@ -240,9 +242,6 @@ impl Device {
|
|||||||
self.registers.i = addn_res;
|
self.registers.i = addn_res;
|
||||||
}
|
}
|
||||||
Instruction::GetKey(x) => {
|
Instruction::GetKey(x) => {
|
||||||
// if !self.device_keyboard.query_key_down(key_expected) {
|
|
||||||
// self.registers.pc -= 2;
|
|
||||||
// }
|
|
||||||
let mut possible_presses = (0..=0xfu8).filter(|x|{self.device_keyboard.query_key_down(*x)});
|
let mut possible_presses = (0..=0xfu8).filter(|x|{self.device_keyboard.query_key_down(*x)});
|
||||||
let pressed = possible_presses.next();
|
let pressed = possible_presses.next();
|
||||||
if let Some(pressed_key) = pressed {
|
if let Some(pressed_key) = pressed {
|
||||||
@@ -252,7 +251,6 @@ impl Device {
|
|||||||
} else{
|
} else{
|
||||||
self.registers.pc -= 2;
|
self.registers.pc -= 2;
|
||||||
}
|
}
|
||||||
// let key_expected = self.registers.v[x];
|
|
||||||
}
|
}
|
||||||
Instruction::SetIndexToFontCharacter(x) => {
|
Instruction::SetIndexToFontCharacter(x) => {
|
||||||
let requested_char = self.registers.v[x];
|
let requested_char = self.registers.v[x];
|
||||||
@@ -382,23 +380,3 @@ impl Drop for Device {
|
|||||||
self.timer.send_stop_signal()
|
self.timer.send_stop_signal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct RegisterFile {
|
|
||||||
pub v: [u8; 0x10],
|
|
||||||
/// program counter - only u12 technically.
|
|
||||||
pub pc: u16,
|
|
||||||
/// stack pointer
|
|
||||||
pub i: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RegisterFile {
|
|
||||||
pub const DEFAULT_PC_VALUE: u16 = Device::ROM_START as u16;
|
|
||||||
pub fn new() -> RegisterFile {
|
|
||||||
RegisterFile {
|
|
||||||
v: [0; 0x10],
|
|
||||||
pc: Self::DEFAULT_PC_VALUE,
|
|
||||||
i: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -2,5 +2,6 @@ pub mod timer;
|
|||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod instruction;
|
pub mod instruction;
|
||||||
mod device;
|
mod device;
|
||||||
|
mod registers;
|
||||||
|
|
||||||
pub use device::*;
|
pub use device::*;
|
||||||
|
22
src/device/registers.rs
Normal file
22
src/device/registers.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use super::Device;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RegisterFile {
|
||||||
|
pub v: [u8; 0x10],
|
||||||
|
/// program counter - only u12 technically.
|
||||||
|
pub pc: u16,
|
||||||
|
/// stack pointer
|
||||||
|
pub i: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RegisterFile {
|
||||||
|
pub const DEFAULT_PC_VALUE: u16 = Device::ROM_START as u16;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RegisterFile{
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { v: [0;0x10], pc: Self::DEFAULT_PC_VALUE, i: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user