In this blog post, I will be attempting to recreate the below code using ROM routines with instructions sets designed for 6502. These instruction sets will include modifying Accumulator, Y, and X registers to display text on screen. Also with instruction sets, there are ROM Routines.
Your order will be delivered to: J. Doe 1750 Finch Ave E Toronto ON M2J 2X5
The first thing I want to discuss is the built-in subroutines available for 6502 chips. There are 5 ROM subroutines SCINIT, CHRIN, CHROUT, SCREEN, and PLOT.
1) SCINIT – used to initialize or clear the screen.
2) CHRIN – accepts user input one character at a time and returns A
3) CHROUT – outputs one character to screen from A at the current cursor position
4) SCREEN – returns screen size in the x and y register
5) PLOT – used to get or set cursor position
Output Message – CHROUT
We all know how to output a message in 6502, but how about using ROM routines to accomplish this with just a few lines of instructions.
; 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 done jsr CHROUT iny bne char done: brk 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
Here we have the accumulator register being loaded with the message from our dcb. every iny will cycle through the message in 32 bit sizes until it reaches 0. Each time the accumulator register is loaded with a character from our dcb, it is then outputted to screen using CHROUT one character at a time. This will continue until the accumulator hits 0 and triggers the beq Z (zero flag).
Setting Cursor Position – PLOT
To set a cursor position on the text screen on the 6502 emulator, we will be using PLOT.
; 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 clc ldx #$03 ldy #$01 jsr PLOT lda #$41 jsr CHROUT clc ldx #$02 ldy #$02 jsr PLOT lda #$42 jsr CHROUT brk
With the above lines of code, I am able to determine where I want my cursor to begin after I output my message.
Character Input from Keyboard – CHRIN
In 6502, we can get character from input and display it onto the screen. It is simple with a few instructions to store the last ASCII keyword pressed into a register and output it onto text display with sta $ff00 (first page, first pixel). The following without ROM will allow for input of a string. With ROM we were able to replicate the exact instructions for taking input from keyboard and displaying on text display
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 input: jsr CHRIN bne display jmp idle display: jsr CHROUT iny jmp input idle: lda $f000,y eor #$80 sta $f000,y lda $ff jmp input
We were able to integrate CHRIN routine where if character input is not equal to zero or negative, then it would jump to idle. Idle is used to show where the current position on the text display is. Once a character is entered, CHRIN would take that character, return it to accumulator and branch to display. Display will then output that character from the accumulator onto the text display.
In conclusion, we were able to let the ROM routines handle instructions such as loading and storing to accumulator because the CHRIN will return a character to accumulator while CHROUT will output a character stored in the accumulator.