fix preserving X register in CHRIN

This commit is contained in:
Paul Gardner-Stephen committed 2019-04-22 03:33:52 +09:30
1 parent 836f19e834
commit 374815ed68
1 file changed
+15 -9
+15 -9
View File
@@ -4,9 +4,11 @@
;; If from keyboard, then it gets a whole line of input, and returns the first char. ;; If from keyboard, then it gets a whole line of input, and returns the first char.
;; Repeated calls after that read out the successive bytes of the line of input. ;; Repeated calls after that read out the successive bytes of the line of input.
chrin: chrin:
;; XXX - Don't corrupt X ;; Save X
stx last_printed_character_ascii txa
pha
chrin_repeat:
;; Do we have a line of input we are currently returning? ;; Do we have a line of input we are currently returning?
;; If so, return the next byte, and clear the flag when we reach the end. ;; If so, return the next byte, and clear the flag when we reach the end.
@@ -23,7 +25,8 @@ chrin:
;; Return carriage return and clear pending input flag ;; Return carriage return and clear pending input flag
lda #$00 lda #$00
sta keyboard_input_ready sta keyboard_input_ready
ldx last_printed_character_ascii pla
tax
lda #$0d lda #$0d
clc clc
rts rts
@@ -31,7 +34,8 @@ chrin:
not_end_of_input: not_end_of_input:
;; Return next byte of waiting input and advance index ;; Return next byte of waiting input and advance index
tay tay
ldx last_printed_character_ascii pla
tax
lda (start_of_keyboard_input),y lda (start_of_keyboard_input),y
inc keyboard_input_ready inc keyboard_input_ready
clc clc
@@ -42,7 +46,7 @@ read_from_keyboard:
;; Wait for a key ;; Wait for a key
lda keys_in_key_buffer lda keys_in_key_buffer
beq chrin beq chrin_repeat
lda keyboard_buffer lda keyboard_buffer
cmp #$0d cmp #$0d
@@ -78,7 +82,8 @@ read_from_keyboard:
sta keyboard_input_ready sta keyboard_input_ready
;; Return first char of line ;; Return first char of line
ldy #$00 ldy #$00
ldx last_printed_character_ascii pla
tax
lda (start_of_keyboard_input),y lda (start_of_keyboard_input),y
clc clc
rts rts
@@ -87,7 +92,8 @@ empty_line:
;; For an empty line, just return the carriage return ;; For an empty line, just return the carriage return
;; (and don't forget to actually print the carriage return, so that ;; (and don't forget to actually print the carriage return, so that
;; the cursor advances and screen scrolls as required) ;; the cursor advances and screen scrolls as required)
ldx last_printed_character_ascii pla
tax
lda #$0d lda #$0d
clc clc
rts rts
@@ -100,7 +106,7 @@ not_enter:
jsr pop_keyboard_buffer jsr pop_keyboard_buffer
;; Keep looking for input from keyboard until carriage return ;; Keep looking for input from keyboard until carriage return
jmp chrin jmp chrin_repeat
pop_keyboard_buffer: pop_keyboard_buffer:
;; Pop key out of keyboard buffer ;; Pop key out of keyboard buffer