; ; Program to test string input ; ; Compile with: ; cl65 -t none -o input_test.prg input_test.asm ; I/O Page Addresses CONS_IO =$FF00 ; Variable Addresses STR_BUF =$0280 ; 127 Bytes to 02FF (incl.) STR_LEN =$24 ; Zero page index var .FEATURE STRING_ESCAPES .WORD $0200 .ORG $0200 start: LDA #s_prompt ; on the zero-page STA $F1 ; and put the string JSR puts ; to the screen line: LDX #$00 ; Init str_buf index read: LDA CONS_IO ; Read char BMI read ; Repeat until B7 is clear STA STR_BUF,X ; Store to input buffer CMP #$0A ; If input was newline BEQ output ; Jump to output CMP #$08 ; If input was not backspace BNE echo ; skip backspace handling DEX ; Decrement text index (remove backspace) BMI line ; Buffer invali re-init line DEX ; Decrement text index (remove previous char) echo: STA CONS_IO ; Echo input character INX ; Increment index BPL read ; If index is under 128, continue DEX ; Decrement index to null-term pos output: LDA #$00 ; Add null-terminator STA STR_BUF,X ; to end of input buffer LDA #$0A ; Print a newline STA CONS_IO LDA # () ; puts: LDY #$00 ; Init index @ch: LDA ($F0),Y ; Get char from pointer at $00F0 BEQ @end ; Skip to end if zero STA CONS_IO ; Put char to screen INY ; Increment index JMP @ch ; Repeat until a zero is read @end: RTS ; Return s_prompt: .ASCIIZ "Type something:\n> " s_prefix: .ASCIIZ "You said: '" s_suffix: .ASCIIZ "'\nCool!\n"