; frames.s - generated-program software frames (E04-S02). ; ; All routines run with CR=$0E and IRQs masked. FRAME_SP/FRAME_FP live at ; $FB-$FE; the frame stack occupies $B800-$BFFF and grows downward from ; $C000. See src/common/frames.inc for the layout and calling convention. ; ; frame_enter is transactional on failure: if the stack bound would be ; crossed, SP and FP are restored to their entry values and C=1 with ; frame_error=FRAME_ERR_STACK. No partial frame remains. .setcpu "6502" .include "../common/frames.inc" .export frame_init, frame_enter, frame_leave, frame_discard .export frame_push_byte, frame_push_word, frame_error .segment "CODE" ; Empty software stack: SP=$C000, FP=0, no error. frame_init: lda #FRAME_STACK_TOP sta FRAME_SP+1 lda #$00 sta FRAME_FP sta FRAME_FP+1 sta frame_error clc rts ; A/X = byte count (low/high). C=0 and SP updated on success; C=1 with ; FRAME_ERR_STACK and SP unchanged when the new SP would fall below the base. frame_reserve: sta frame_size stx frame_size+1 lda FRAME_SP sec sbc frame_size sta frame_new_sp lda FRAME_SP+1 sbc frame_size+1 sta frame_new_sp+1 lda frame_new_sp+1 cmp #>FRAME_STACK_BASE bcc @fail bne @ok lda frame_new_sp cmp #