From ddb964f4dc8d08b7cc8c773db9b015d43a5d5dc5 Mon Sep 17 00:00:00 2001 From: Rachel <508861+Ryex@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:47:35 -0700 Subject: [PATCH] fix peek instruction --- .gitignore | 1 + ic10emu/src/interpreter.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index be4ac7c..63c0e00 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ pkg/ dist/ mode_modules/ target/ +Session.vim diff --git a/ic10emu/src/interpreter.rs b/ic10emu/src/interpreter.rs index 4f70f1d..89ee37b 100644 --- a/ic10emu/src/interpreter.rs +++ b/ic10emu/src/interpreter.rs @@ -373,7 +373,7 @@ impl IC { } pub fn poke(&mut self, address: f64, val: f64) -> Result { - let sp = address as i32; + let sp = address.round() as i32; if !(0..512).contains(&sp) { Err(ICError::StackIndexOutOfRange(address)) } else { @@ -384,7 +384,7 @@ impl IC { } pub fn peek(&self) -> Result { - let sp = (self.registers[16]) as i32; + let sp = (self.registers[16] - 1.0).round() as i32; if sp < 0 { Err(ICError::StackUnderflow) } else if sp >= 512 {