8bitlenser/lenser/viewer/wait.i
2026-07-03 19:35:35 -07:00

77 lines
2.2 KiB
OpenEdge ABL

; Shared "how long to show the picture" epilogue for the simple C64 viewers.
; Selected at assembly time by WAITMODE (set by viewer/assemble.py):
; 0 forever -- never returns; the picture stays until reset
; 1 until a key -- jsr GETIN until a key is pressed, then fall through
; 2 WAITSECS secs -- count KERNAL jiffies (JIFFYPS per second), then fall through
; 3 key OR secs -- whichever comes first (keys still work, but it auto-
; advances after WAITSECS); used by the slideshow viewer
; On fall-through the caller restores the text screen and RTSes to BASIC.
; The KERNAL IRQ is left running by these viewers, so GETIN and the jiffy clock
; ($a0-$a2, big-endian, $a2 = least significant) both work.
cv_t0 = $fb ; 16-bit jiffy snapshot (free after the copy)
cv_el = $fd ; 16-bit elapsed jiffies
#if WAITMODE == 0
cv_wait:
jmp cv_wait
#endif
#if WAITMODE == 1
lda #$00
sta $c6 ; empty the keyboard buffer first, so a key left
; over from RUN doesn't dismiss the picture at once
cv_wait:
jsr $ffe4 ; GETIN
beq cv_wait
#endif
#if WAITMODE == 2
lda $a2
sta cv_t0
lda $a1
sta cv_t0+1
cv_wait:
sec
lda $a2
sbc cv_t0
sta cv_el
lda $a1
sbc cv_t0+1
sta cv_el+1
lda cv_el+1
cmp #>(WAITSECS*JIFFYPS)
bcc cv_wait
bne cv_done
lda cv_el
cmp #<(WAITSECS*JIFFYPS)
bcc cv_wait
cv_done:
#endif
#if WAITMODE == 3
lda #$00
sta $c6 ; empty the keyboard buffer first
lda $a2
sta cv_t0
lda $a1
sta cv_t0+1
cv_wait:
jsr $ffe4 ; GETIN -- any key ends the slide immediately
bne cv_done
sec ; else check the elapsed-jiffies timeout
lda $a2
sbc cv_t0
sta cv_el
lda $a1
sbc cv_t0+1
sta cv_el+1
lda cv_el+1
cmp #>(WAITSECS*JIFFYPS)
bcc cv_wait
bne cv_done
lda cv_el
cmp #<(WAITSECS*JIFFYPS)
bcc cv_wait
cv_done:
#endif