diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/input.s | 92 |
1 files changed, 71 insertions, 21 deletions
diff --git a/test/input.s b/test/input.s index b699dda..a2725f6 100644 --- a/test/input.s +++ b/test/input.s @@ -12,7 +12,10 @@ string2: .byte "You typed, " end: .byte $0 - +x: + .word $0 +tmp: + .word $0 ; Input buffer. .org $2000 buffer: @@ -26,7 +29,7 @@ reset: ldy #$0 clr_buf: lda #$0 - cpy.w #$400 + cpy.w #$1000 beq start sta buffer, y iny @@ -47,7 +50,6 @@ sleep: lda end bne spin ; Are we done with getting input? read: - nop ; Sleep until we get a character. lda $C000 ; Get control register. beq rset_a ; Loop until we get a character. lda #$0 @@ -63,17 +65,66 @@ print: getchar: lda $C002 ; Get typed character. + cmp #$1B + beq esc cmp #$A beq nl ; Did the user type a newline? cmp #$8 beq bs ; Did the user type a backspace? + cmp #$7F + beq bs ; Did the user type a backspace? echo: sta $C001 ; Echo typed character. sta buffer, y ; Store typed character into the input buffer. iny ; Increment buffer offset. - nop jmp rset_a ; We are not, so add the backspace to the buffer. +esc: + lda $C000 ; Skip the '['. + lda $C000 ; Get the next character. + beq read ; We have an error, so discard it, and read the next character. + lda $C002 ; Get the escape code. + cmp #$41 ; Did the user press the up arrow? + beq up ; Yes, so move the cursor up. + cmp #$42 ; Did the user press the down arrow? + beq down ; Yes, so move the cursor down. + cmp #$43 ; Did the user press the right arrow? + beq right ; Yes, so move the cursor right. + cmp #$44 ; Did the user press the left arrow? + beq left ; Yes, so move the cursor left. +up: + lda #$1B + sta $C001 + lda #$5B + sta $C001 + lda #$41 + sta $C001 + jmp rset_a +down: + lda #$1B + sta $C001 + lda #$5B + sta $C001 + lda #$42 + sta $C001 + jmp rset_a +right: + lda #$1B + sta $C001 + lda #$5B + sta $C001 + lda #$43 + sta $C001 + jmp rset_a +left: + lda #$1B + sta $C001 + lda #$5B + sta $C001 + lda #$44 + sta $C001 + jmp rset_a + nl: sta $C001 lda #$0 ; Replace newline with a null terminator. @@ -81,10 +132,17 @@ nl: ldy.w #$0 ; Reset y, to print the result. jmp result +back: + sta $C001 ; Print backspace. + lda #$0 ; Put a null terminator, in place of the backspace. + sta buffer, y ; Place it into the input buffer. + dey ; Decrement buffer offset. + jmp read ; Get next character. + bs: - cpy #$0 - beq return ; Are we at the start of the buffer? - jmp echo ; We are not, so add the backspace to the buffer. + cpy #$0 ; Are we at the start of the buffer? + beq rset_a ; We are, so do not store the backspace into the buffer. + jmp back ; We are not, so add the backspace to the buffer. result: lda string2, y @@ -93,25 +151,18 @@ result: iny ; Increment offset. jmp result ; Keep printing. + rset_y: ldy.w #$0 jmp print_buf ; Print the input buffer. print_buf: lda buffer, y ; Get a character from the input buffer. - beq fin ; Are we done with printing the buffer? + beq spin ; Are we done with printing the buffer? sta $C001 ; Print said character. iny jmp print_buf ; Keep printing the buffer. -fin: - lda #$A ; Load a newline. - sta $C001 ; Print the newline. - lda #$1 ; Tell the program that we are done. - sta end ; We are done. - jmp sleep - - spin: nop nop @@ -132,10 +183,9 @@ spin: .org $FFA0 .qword irq_routine -;.org $0 -;viewmem -;.org $100 -;viewmem +.org $8000 +viewmem +.org $8100 +viewmem ;q done - |