diff --git a/common/common.asm b/common/common.asm index f607661..c8bbed9 100644 --- a/common/common.asm +++ b/common/common.asm @@ -116,27 +116,7 @@ _SET .( ; SET r aabbcc.dd 1r dd cc bb aa Rr <- aabbcc.dd - set register _1 RTS ; done .) -_POP .( ; POP r 2r Rr <- RS - pop from stack - LDY _RSI ; get register stack index - BNE _1 ; all good, something can be popped off the stack - BRK ; next pop will cause a stack underflow, abort and call exception handler (TODO) -_1 DEY ; transfer four bytes over - LDA _RS,Y - STA _R0+3,X - DEY - LDA _RS,Y - STA _R0+2,X - DEY - LDA _RS,Y - STA _R0+1,X - DEY - LDA _RS,Y - STA _R0,X - STY _RSI ; update register stack index - RTS -.) - -_PSH .( ; PSH r 3r RS <- Rr - push onto stack +_PSH .( ; PSH r 2r RS <- Rr - push onto stack LDY _RSI ; get register stack index CPY #_RSS ; compare against limit BCC _1 ; still room, all okay @@ -157,6 +137,26 @@ _1 LDA _R0,X ; transfer four bytes over RTS .) +_POP .( ; POP r 3r Rr <- RS - pop from stack + LDY _RSI ; get register stack index + BNE _1 ; all good, something can be popped off the stack + BRK ; next pop will cause a stack underflow, abort and call exception handler (TODO) +_1 DEY ; transfer four bytes over + LDA _RS,Y + STA _R0+3,X + DEY + LDA _RS,Y + STA _R0+2,X + DEY + LDA _RS,Y + STA _R0+1,X + DEY + LDA _RS,Y + STA _R0,X + STY _RSI ; update register stack index + RTS +.) + _EXC .( ; EXC r 4r Rr <-> RS - exchange Rr with stack LDY _RSI ; RS to RD LDA _RS-1,Y diff --git a/common/common.h b/common/common.h index c91bb2b..432002c 100644 --- a/common/common.h +++ b/common/common.h @@ -14,8 +14,8 @@ ; Instructions ; SET r aabbcc.dd 1r dd cc bb aa Rr <- aabbccdd - set register -; POP r 2r Rr <- RS - pop from stack -; PSH r 3r RS <- Rr - push onto stack +; PSH r 2r RS <- Rr - push onto stack +; POP r 3r Rr <- RS - pop from stack ; EXC r 4r Rr <-> RS - exchange Rr with stack ; INR r 5r Rr <- Rr + 1.0 - increment register ; DCR r 6r Rr <- Rr - 1.0 - decrement register @@ -115,8 +115,8 @@ _SVI_C = $0e _CMR_C = $0f _SET_C = $10 -_POP_C = $20 -_PSH_C = $30 +_PSH_C = $20 +_POP_C = $30 _EXC_C = $40 _INR_C = $50 _DCR_C = $60 diff --git a/common/macros.h b/common/macros.h index fc2ad78..e3d8951 100644 --- a/common/macros.h +++ b/common/macros.h @@ -75,8 +75,8 @@ #define SVI(p, q) .BYTE _SVI_C, p * 16 + q #define CMR(p, q) .BYTE _CMR_C, p * 16 + q #define SET(r, v) .BYTE _SET_C + r, _SET_V(#v) -#define POP(r) .BYTE _POP_C + r #define PSH(r) .BYTE _PSH_C + r +#define POP(r) .BYTE _POP_C + r #define EXC(r) .BYTE _EXC_C + r #define INR(r) .BYTE _INR_C + r #define DCR(r) .BYTE _DCR_C + r