diff --git a/common/common.asm b/common/common.asm index 808e002..c8bbed9 100644 --- a/common/common.asm +++ b/common/common.asm @@ -116,27 +116,12 @@ _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 +_PSH .( ; PSH r 2r RS <- Rr - push onto stack LDY _RSI ; get register stack index - 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 - LDY _RSI ; get register stack index - LDA _R0,X ; transfer four bytes over + CPY #_RSS ; compare against limit + BCC _1 ; still room, all okay + BRK ; next push will cause a stack overflow, abort and call exception handler (TODO) +_1 LDA _R0,X ; transfer four bytes over STA _RS,Y INY LDA _R0+1,X @@ -152,6 +137,26 @@ _PSH .( ; PSH r 3r RS <- Rr - push onto stack 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 fa732bb..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 @@ -89,11 +89,12 @@ _IDX = _ACC + 1 ; saved index X to restore _IDY = _IDX + 1 ; saved index Y to restore _PS = _IDY + 1 ; saved processor status to restore -; 256 bytes of page two +; 224 bytes of page two _RS = $200 ; register stack +_RSS = (FN_FX - _RS) ; register stack size -; 64 bytes of page three -FN_FX = $300 ; list of system and user functions +; last 32 bytes of page two +FN_FX = $2E0 ; list of system and user functions ; function constants _ESC_C = $00 @@ -114,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