From fe7bfb12e6e4204c81362bd3ae4e0f4a3d18646b Mon Sep 17 00:00:00 2001 From: Russell-S-Harper Date: Tue, 7 Aug 2018 20:14:24 -0400 Subject: [PATCH] Adding protection for PSH and POP. --- common/common.asm | 9 +++++++-- common/common.h | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/common.asm b/common/common.asm index 808e002..f607661 100644 --- a/common/common.asm +++ b/common/common.asm @@ -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 diff --git a/common/common.h b/common/common.h index fa732bb..c91bb2b 100644 --- a/common/common.h +++ b/common/common.h @@ -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