aboutsummaryrefslogtreecommitdiff
path: root/stack.go
diff options
context:
space:
mode:
Diffstat (limited to 'stack.go')
-rw-r--r--stack.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/stack.go b/stack.go
index 324e16d..da87aa9 100644
--- a/stack.go
+++ b/stack.go
@@ -1,24 +1,22 @@
package j1
-const stackSize = 0x20
-
type stack struct {
- data [stackSize]uint16 // stack
- sp int8 // 5 bit stack pointer
+ data [0x20]uint16 // stack
+ sp int8 // 5 bit stack pointer
}
func (s *stack) move(dir int8) {
- s.sp = (s.sp + dir) & (stackSize - 1)
+ s.sp = (s.sp + dir) & int8(len(s.data)-1)
}
func (s *stack) push(v uint16) {
- s.sp = (s.sp + 1) & (stackSize - 1)
+ s.sp = (s.sp + 1) & int8(len(s.data)-1)
s.data[s.sp] = v
}
func (s *stack) pop() uint16 {
sp := s.sp
- s.sp = (s.sp - 1) & (stackSize - 1)
+ s.sp = (s.sp - 1) & int8(len(s.data)-1)
return s.data[sp]
}