ft(interpreter): impl simple stack init
This commit is contained in:
@@ -7,13 +7,13 @@ const MEMORY_SIZE: usize = 1048576;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Memory {
|
||||
memory: [Byte; MEMORY_SIZE as usize],
|
||||
pub raw: [Byte; MEMORY_SIZE as usize],
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
memory: [0; MEMORY_SIZE as usize],
|
||||
raw: [0; MEMORY_SIZE as usize],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ impl Memory {
|
||||
} else {
|
||||
match val {
|
||||
ImmediateOperand::Byte(b) => {
|
||||
self.memory[addr as usize] = b;
|
||||
self.raw[addr as usize] = b;
|
||||
}
|
||||
ImmediateOperand::Word(w) => {
|
||||
let [low, high] = w.to_le_bytes();
|
||||
self.memory[addr as usize] = low;
|
||||
self.memory[(addr + 1) as usize] = high;
|
||||
self.raw[addr as usize] = low;
|
||||
self.raw[(addr + 1) as usize] = high;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,12 @@ impl Memory {
|
||||
/// Warning: Does access at `addr`, not `DS:addr`!
|
||||
pub fn read_raw(&self, addr: Word) -> Result<Word, InterpreterError> {
|
||||
let b1 = self
|
||||
.memory
|
||||
.raw
|
||||
.get(addr as usize)
|
||||
.ok_or(InterpreterError::MemoryOutOfBound(addr))?
|
||||
.to_owned();
|
||||
let b2 = self
|
||||
.memory
|
||||
.raw
|
||||
.get((addr + 1) as usize)
|
||||
.ok_or(InterpreterError::MemoryOutOfBound(addr))?
|
||||
.to_owned();
|
||||
|
||||
Reference in New Issue
Block a user