Skip to content

Commit

Permalink
apple2e: implemented some timeout handling screen_getchar (untuned)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasbaumann committed Dec 1, 2024
1 parent 6609bca commit 7460f0d
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/arch/apple2e/apple2e.S
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,20 @@ zproc screen_putstring
rts
zendproc

; XA = timeout in cs
; XA = timeout in cs (X=MSB, A=LSB)
; carry set on timeout
; carry clean when A=key

zproc screen_getchar
sta ptr
stx ptr+1
; this feels wrong, but how is otherwise X=0 working with DEC and underflows?
inc ptr+1
; TODO: adjust here
;~ clc
;~ rol ptr+1
;~ rol ptr

; Turn the disk motor off.

Expand All @@ -429,15 +438,27 @@ zproc screen_getchar

jsr draw_cursor

; Wait for the key.
; Wait for the key, or time out

zrepeat
lda KBD_READ
zuntil_mi
_wait_loop:
ldy #$ff ; 255 * 5 cycles
_inner_loop:
lda KBD_READ ; 4 cycles
bpl _no_key ; 3 cycles, branch usually taken
; got a key
sta KBD_STROBERESET
and #0x7f
clc
rts
_no_key:
dey ; 2 cycles
bne _inner_loop ; 3 cycles usually (unless 0)
dec ptr ; 5 cycles
bne _wait_loop ; 3 cycles (2 if 0)
dec ptr+1 ; 5 cycles
bne _wait_loop ; 3 cycles (2 if 0)
sec
rts
zendproc

zproc screen_showcursor
Expand Down

0 comments on commit 7460f0d

Please sign in to comment.