diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-28 20:25:01 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-10-28 20:29:12 +1300 |
commit | 1a830a3d1b9d99653322d5ae49ea8165de7ed9d0 (patch) | |
tree | 798e77b6fcf2438b1c2538a67efe856a2f7cb979 /src/devices/memory.rs | |
parent | 03c4b069e1806af256730639cefdae115b24401a (diff) | |
download | bedrock-pc-01ba3901441af778d473f44acaee953d185245e7.zip |
Rewrite emulatorv1.0.0-alpha1
This is a complete rewrite and restructure of the entire emulator
project, as part of the effort in locking down the Bedrock specification
and in creating much better tooling for creating and using Bedrock
programs.
This commit adds a command-line argument scheme, an embedded assembler,
a headless emulator for use in non-graphical environments, deferred
window creation for programs that do not access the screen device,
and new versions of phosphor and bedrock-core. The new version of
phosphor supports multi-window programs, which will make it possible to
implement program forking in the system device later on, and the new
version of bedrock-core implements the final core specification.
Diffstat (limited to 'src/devices/memory.rs')
-rw-r--r-- | src/devices/memory.rs | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/src/devices/memory.rs b/src/devices/memory.rs deleted file mode 100644 index 56125d2..0000000 --- a/src/devices/memory.rs +++ /dev/null @@ -1,91 +0,0 @@ -macro_rules! then_inc { ($v:expr) => {{ $v = $v.wrapping_add(1); $v as usize }}; } - -type Page = [u8; 65536]; -fn new_blank_page() -> [u8; 65536] { [0; 65536] } - - -pub struct MemoryDevice { - // Hard limit on the number of pages which can be allocated - pub page_limit: u16, - // Pages which have actually been allocated - pub pages: Vec<Page>, - - pub page_1: u16, - pub address_1: u16, - pub page_2: u16, - pub address_2: u16, - pub copy_length: u16, -} - -impl MemoryDevice { - pub fn new() -> Self { - Self { - page_limit: 0, - pages: Vec::new(), - - page_1: 0, - address_1: 0, - page_2: 0, - address_2: 0, - copy_length: 0, - } - } - - pub fn copy(&mut self) { - let count = std::cmp::max(self.page_1, self.page_2) as usize + 1; - if count <= self.page_limit as usize { - if self.pages.len() < count { - self.pages.resize_with(count, new_blank_page); - } - let p1 = self.page_1 as usize; - let p2 = self.page_2 as usize; - let a1 = self.address_1; - let a2 = self.address_2; - - for i in 0..=self.copy_length { - let byte = self.pages[p2][a2.wrapping_add(i) as usize]; - self.pages[p1][a1.wrapping_add(i) as usize] = byte; - } - } - } - - pub fn read_from_head_1(&mut self) -> u8 { - let address = then_inc!(self.address_1); - if let Some(page) = self.pages.get(self.page_1 as usize) { - page[address] - } else { - 0x00 - } - } - - pub fn read_from_head_2(&mut self) -> u8 { - let address = then_inc!(self.address_2); - if let Some(page) = self.pages.get(self.page_2 as usize) { - page[address] - } else { - 0x00 - } - } - - pub fn write_to_head_1(&mut self, byte: u8) { - let address = then_inc!(self.address_1); - let page = self.page_1 as usize; - if self.page_limit as usize > page { - if self.pages.len() <= page { - self.pages.resize_with(page + 1, new_blank_page); - } - self.pages[page][address] = byte; - } - } - - pub fn write_to_head_2(&mut self, byte: u8) { - let address = then_inc!(self.address_1); - let page = self.page_2 as usize; - if self.page_limit as usize > page { - if self.pages.len() <= page { - self.pages.resize_with(page + 1, new_blank_page); - } - self.pages[page][address] = byte; - } - } -} |