preserve X register in chrin

This commit is contained in:
Paul Gardner-Stephen committed 2019-04-22 02:59:44 +09:30
1 parent 3067744304
commit 89f7f9ae55
1 file changed
+6 -6
+6 -6
View File
@@ -4,10 +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
stx last_printed_character_ascii
;; 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.
;; XXX - Implement
;; Do we have a line of input waiting? ;; Do we have a line of input waiting?
lda keyboard_input_ready lda keyboard_input_ready
@@ -22,6 +23,7 @@ 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
lda #$0d lda #$0d
clc clc
rts rts
@@ -29,6 +31,7 @@ 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
lda (start_of_keyboard_input),y lda (start_of_keyboard_input),y
inc keyboard_input_ready inc keyboard_input_ready
clc clc
@@ -70,11 +73,9 @@ read_from_keyboard:
sty end_of_input_line sty end_of_input_line
lda #$01 lda #$01
sta keyboard_input_ready sta keyboard_input_ready
;; Print the carriage return
lda #$0d
jsr chrout
;; Return first char of line ;; Return first char of line
ldy #$00 ldy #$00
ldx last_printed_character_ascii
lda (start_of_keyboard_input),y lda (start_of_keyboard_input),y
clc clc
rts rts
@@ -83,8 +84,7 @@ 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)
lda #$0d ldx last_printed_character_ascii
jsr chrout
lda #$0d lda #$0d
clc clc
rts rts