In this blog post, I will describing how we will be using ROM routines to create a Data Input Form where we will display a message, have a user input their name and address, and take user input and display it onto the character display.
; ROM routines
define SCINIT $ff81 ; initialize/clear screen
define CHRIN $ffcf ; input character from keyboard
define CHROUT $ffd2 ; output character to screen
define SCREEN $ffed ; get screen size
define PLOT $fff0 ; get/set cursor coordinates
jsr SCINIT
ldy #$00
char: lda message,y
beq cursorPos
jsr CHROUT
iny
bne char
cursorPos: ;set cursor position
clc ;clear carry for PLOT
ldy #$02 ;set coordinate Y
ldx #$03 ;set coordinate X
jsr PLOT ;call PLOT
ldy #$00
input:
jsr CHRIN
bne display
jmp idle
display:
jsr CHROUT
iny
jmp input
backspace:
dey
jmp input
idle:
lda $f0a3,y
eor #$80
sta $f0a3,y
lda $ff
jmp input
brk ;in case program runs passed, it does not nuke the code by going into the dcb
message:
dcb "Y","o","u","r",32,"o","r","d","e","r",32,"w","i","l","l",32
dcb "b","e",32,"d","e","l","i","v","e","r","e","d",32,"t","o",":",$0d,$0d
The above code, we were able to produce a message and set a cursor position to where we can begin to type our characters.
Things to Implement to Complete Source Code
There are a couple of things still needed to implement before this source code is complete.
1) Backspace – Decrement the value loaded in the Y register to move the cursor position back each time backspace is pressed on the keyboard. We do this by using comparing $ff with the value #$08
2) Space bar – In the code above, when we press the space bar, the code ends. We need spaces in our character input and output
3) Enter – Load cursor to next line by using adc and adding #$32 to current position of cursor.
4) Arrow keys – We want the user to be able to move to a desired location and fix a misspelling or add a word to current cursor position.