When the THEC64 from Retro Games was released at the end of December 2019, I was able to spend some time making up for lost time with the so-called “breadbox”.
With a lot of interest I read through the official Commodore 64 User’s Guide and learnd some BASIC, the onboard programming language. In the last two years I have been playing with the C64 on and off and have also been looking into the 6502 assembly programming language.
In this short article I’m going to show you one way to print a string in 6502 assembly programming language.
Here you can see the final result. We simply print the string COMMODORE 64 at the top left corner of the screen.
In BASIC this can be done with this simple line of code (although the position will be different):
PRINT "COMMODORE 64"
You can access the source code on my github repository here.
Loading the string with the upper code takes 470 cycles (see below how to
calculate number of cycles used). I tried different other options, which in
general use less space, but take significant more cycles. For example this
approach, using the subroutines $e50c
and $ab1e
will take 5192 cycles
and does exactly the same.
ldx #$00 ; Select row
ldy #$00 ; Select column
jsr $e50c ; Set cursor
print lda #<str ; Load lo-byte of string adress
ldy #>str ; Load hi-byte of string adress
jsr $ab1e ; Print string
rts ; End.
str .text "COMMODORE 64"
.byte $00
For more informations about the VICE monitor, have a look at the official manual.