summaryrefslogtreecommitdiff
path: root/src/stack.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/stack.rs')
-rw-r--r--src/stack.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/stack.rs b/src/stack.rs
index 2a0a514..14e1799 100644
--- a/src/stack.rs
+++ b/src/stack.rs
@@ -28,8 +28,20 @@ impl Stack {
}
pub fn pop_u16(&mut self) -> u16 {
- let byte_low = self.pop_u8();
- let byte_high = self.pop_u8();
+ self.sp = self.sp.wrapping_sub(1);
+ let byte_low = self.mem[self.sp as usize];
+ self.sp = self.sp.wrapping_sub(1);
+ let byte_high = self.mem[self.sp as usize];
+ u16::from_be_bytes([byte_high, byte_low])
+ }
+
+ pub fn get_u8(&mut self) -> u8 {
+ self.mem[self.sp.wrapping_sub(1) as usize]
+ }
+
+ pub fn get_u16(&mut self) -> u16 {
+ let byte_low = self.mem[self.sp.wrapping_sub(1) as usize];
+ let byte_high = self.mem[self.sp.wrapping_sub(2) as usize];
u16::from_be_bytes([byte_high, byte_low])
}