dos33fsprogs/games/peasant/hgr_input.s

76 lines
1.1 KiB
ArmAsm
Raw Permalink Normal View History

2021-08-12 03:53:49 +00:00
;====================
; hgr input
;====================
; TODO: save to string
; TODO: arbitrary Y location
; TODO: when backspacing, erase old char not XOR
hgr_input:
2021-08-15 05:12:43 +00:00
bit KEYRESET
2021-08-12 03:53:49 +00:00
ldx #0
ldy #184
lda #'>'
jsr hgr_put_char
ldx #1
stx INPUT_X
hgr_input_loop:
lda KEYPRESS
bpl hgr_input_loop
bit KEYRESET
and #$7f ; trim off top?
2021-08-15 05:12:43 +00:00
cmp #13 ; if return, then done
2021-08-12 03:53:49 +00:00
beq done_hgr_input
2021-08-15 05:12:43 +00:00
cmp #$7f ; check if backspace
2021-08-12 03:53:49 +00:00
beq hgr_input_backspace
cmp #8
beq hgr_input_backspace
2021-08-15 05:12:43 +00:00
ldx INPUT_X
sta input_buffer-1,X ; store to buffer
ldy #184 ; print char
2021-08-12 03:53:49 +00:00
ldx INPUT_X
jsr hgr_put_char
2021-08-15 05:12:43 +00:00
ldx INPUT_X
cpx #38
bcs input_too_big ; FIXME this is a hack
2021-08-12 03:53:49 +00:00
inc INPUT_X
2021-08-15 05:12:43 +00:00
input_too_big:
2021-08-12 03:53:49 +00:00
jmp hgr_input_loop
hgr_input_backspace:
ldx INPUT_X
cpx #1 ; don't backspace too far
beq hgr_input_loop
2021-08-15 05:12:43 +00:00
dec INPUT_X
ldx INPUT_X
lda input_buffer-1,X ; load old char
2021-08-12 03:53:49 +00:00
ldy #184
2021-08-15 05:12:43 +00:00
jsr hgr_put_char ; xor it on top
2021-08-12 03:53:49 +00:00
jmp hgr_input_loop
done_hgr_input:
2021-08-15 05:12:43 +00:00
ldx INPUT_X ; NUL terminate
lda #0
sta input_buffer-1,X
2021-08-12 03:53:49 +00:00
rts
2021-08-15 05:12:43 +00:00
input_buffer:
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0