Skip to content

Instantly share code, notes, and snippets.

@JimmyDansbo
Created December 19, 2020 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimmyDansbo/3b1c1b0db1cda305361b35e2c68095ab to your computer and use it in GitHub Desktop.
Save JimmyDansbo/3b1c1b0db1cda305361b35e2c68095ab to your computer and use it in GitHub Desktop.
Example of writing text to screen using VERA on Commander X16
!cpu 65c02
; BASIC program ("10 SYS $0810")
*=$0801
!word $080C ; Pointer to next BASIC line
!word $000A ; Line number $000A = 10
!byte $9E ; SYS BASIC token
!pet " $810",0 ; Address where ASM starts
!word $0000 ; EOF BASIC program
*=$0810
; VERA registers needed to write characters on the screen.
; https://github.com/commanderx16/x16-docs/blob/master/VERA%20Programmer's%20Reference.md#registers
; It is assumed that the screen is in "normal" 80x60 text mode.
VERA_ADDR_L = $9F20
VERA_ADDR_M = $9F21
VERA_ADDR_H = $9F22
VERA_DATA0 = $9F23
main:
lda #%00100000 ; Increment 2, High-addr=0
sta VERA_ADDR_H
lda #30 ; Y coordinate (middle of screen)
sta VERA_ADDR_M
lda #33*2 ; X coordinate: (screenwidth/2)-(stringlength/2)
sta VERA_ADDR_L ; Multiplied by 2 because in normal screenmode,
; 1 byte is used for character and 1 for color
ldy #0 ; Use .Y as index into string
.loop: lda my_str,y ; Load character
beq .end: ; If it is 0, jump to end
sta VERA_DATA0 ; Write character to VERA memory, VERA
; will automaticly add 2 to address.
iny ; Increment .Y
bra .loop: ; Jump back to get next character
.end:
rts
; Zero terminated "string" encoded to use the default VERA font layout
; See: https://cx16.dk/veratext/
; H E L L O , W O R L D !
my_str: !byte $08,$05,$0C,$0C,$0F,$2C,$20,$17,$0F,$12,$0C,$04,$21,$00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment