2020-03-07 12:13:15 -05:00
|
|
|
; The Parameter stack (PS) is maintained by SP and the Return stack (RS) is
|
|
|
|
; maintained by IX. This allows us to generally use push and pop freely because
|
|
|
|
; PS is the most frequently used. However, this causes a problem with routine
|
|
|
|
; calls: because in Forth, the stack isn't balanced within each call, our return
|
|
|
|
; offset, when placed by a CALL, messes everything up. This is one of the
|
2020-03-09 08:49:51 -04:00
|
|
|
; reasons why we need stack management routines below. IX always points to RS'
|
|
|
|
; Top Of Stack (TOS)
|
2020-03-07 12:13:15 -05:00
|
|
|
;
|
|
|
|
; This return stack contain "Interpreter pointers", that is a pointer to the
|
|
|
|
; address of a word, as seen in a compiled list of words.
|
|
|
|
|
|
|
|
; Push value HL to RS
|
|
|
|
pushRS:
|
|
|
|
inc ix
|
|
|
|
inc ix
|
2020-03-09 08:49:51 -04:00
|
|
|
ld (ix), l
|
|
|
|
ld (ix+1), h
|
2020-03-07 12:13:15 -05:00
|
|
|
ret
|
|
|
|
|
|
|
|
; Pop RS' TOS to HL
|
|
|
|
popRS:
|
2020-03-09 08:49:51 -04:00
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
2020-03-07 12:13:15 -05:00
|
|
|
dec ix
|
|
|
|
dec ix
|
|
|
|
ret
|
2020-03-07 20:20:11 -05:00
|
|
|
|
2020-03-17 17:29:03 -04:00
|
|
|
popRSIP:
|
|
|
|
call popRS
|
|
|
|
ld (IP), hl
|
|
|
|
ret
|
|
|
|
|
2020-03-10 21:37:06 -04:00
|
|
|
; Skip the next two bytes in RS' TOS
|
|
|
|
skipRS:
|
|
|
|
push hl
|
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
|
|
|
inc hl \ inc hl
|
|
|
|
ld (ix), l
|
|
|
|
ld (ix+1), h
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2020-03-13 16:40:55 -04:00
|
|
|
; Verifies that SP and RS are within bounds. If it's not, call ABORT
|
2020-03-17 14:56:08 -04:00
|
|
|
chkRS:
|
2020-03-13 16:40:55 -04:00
|
|
|
push ix \ pop hl
|
|
|
|
push de ; --> lvl 1
|
|
|
|
ld de, RS_ADDR
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de
|
|
|
|
pop de ; <-- lvl 1
|
2020-03-17 14:56:08 -04:00
|
|
|
jp c, abortUnderflow
|
|
|
|
ret
|
|
|
|
|
|
|
|
chkPS:
|
|
|
|
push hl
|
2020-03-07 20:20:11 -05:00
|
|
|
ld hl, (INITIAL_SP)
|
2020-03-17 14:56:08 -04:00
|
|
|
; We have the return address for this very call on the stack and
|
|
|
|
; protected registers. Let's compensate
|
|
|
|
dec hl \ dec hl
|
2020-03-07 20:20:11 -05:00
|
|
|
dec hl \ dec hl
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, sp
|
2020-03-17 14:56:08 -04:00
|
|
|
pop hl
|
2020-03-07 20:20:11 -05:00
|
|
|
ret nc ; (INITIAL_SP) >= SP? good
|
2020-03-17 14:56:08 -04:00
|
|
|
jp abortUnderflow
|