Adding protection for PSH and POP.

This commit is contained in:
Russell-S-Harper 2018-08-07 20:14:24 -04:00
parent a3069872b1
commit fe7bfb12e6
2 changed files with 11 additions and 5 deletions

View File

@ -118,7 +118,9 @@ _1 RTS ; done
_POP .( ; POP r 2r Rr <- RS - pop from stack
LDY _RSI ; get register stack index
DEY ; transfer four bytes over
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
@ -136,7 +138,10 @@ _POP .( ; POP r 2r Rr <- RS - pop from stack
_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

View File

@ -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