This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vm fetch/decode/execute structure
- Loading branch information
Showing
9 changed files
with
507 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use log::trace; | ||
|
||
pub struct Memory { | ||
pub data: Vec<u8>, | ||
} | ||
|
||
impl Memory { | ||
pub fn new(size: usize) -> Self { | ||
Memory { | ||
data: vec![0; size], | ||
} | ||
} | ||
|
||
pub fn from(data: Vec<u8>) -> Self { | ||
Memory { data } | ||
} | ||
|
||
pub fn read(&self, address: u16) -> u8 { | ||
self.data[address as usize] | ||
} | ||
|
||
pub fn read_word(&self, address: u16) -> u16 { | ||
u16::from_le_bytes([ | ||
self.data[address as usize], | ||
self.data[(address + 1) as usize], | ||
]) | ||
} | ||
|
||
pub fn read_bytes(&self, address: u16, size: usize) -> &[u8] { | ||
&self.data[address as usize..(address as usize + size)] | ||
} | ||
|
||
pub fn write(&mut self, address: u16, value: u8) { | ||
self.data[address as usize] = value; | ||
} | ||
|
||
pub fn write_word(&mut self, address: u16, value: u16) { | ||
let bytes = value.to_le_bytes(); | ||
self.data[address as usize] = bytes[0]; | ||
self.data[(address + 1) as usize] = bytes[1]; | ||
} | ||
|
||
pub fn write_bytes(&mut self, address: u16, data: &[u8]) { | ||
trace!("WRITE[{:04X}]: {:?}", address, data); | ||
self.data[address as usize..(address as usize + data.len())].copy_from_slice(data); | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
self.data.len() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
mod memory; | ||
mod register_set; | ||
mod vm; | ||
|
||
pub use vm::Interpretable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.