Created
December 26, 2020 10:11
-
-
Save JimmyDansbo/49ea401a0e5cc0b77c9acc45399ea416 to your computer and use it in GitHub Desktop.
Hello World as a Commander X16 ROM image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!cpu 65c02 | |
VERA_ADDR_L = $9F20 | |
VERA_ADDR_M = $9F21 | |
VERA_ADDR_H = $9F22 | |
VERA_DATA0 = $9F23 | |
VERA_CTRL = $9F25 | |
VERA_DC_VIDEO = $9F29 | |
VERA_DC_HSCALE = $9F2A | |
VERA_DC_VSCALE = $9F2B | |
VERA_DC_HSTOP = $9F2A | |
VERA_DC_VSTOP = $9F2C | |
VERA_L1_CONFIG = $9F34 | |
VERA_L1_TILEBASE = $9F36 | |
Print_var = $30 | |
Print_col = $32 | |
*=$C000 ; since this is a Commander X16, the ROM starts loading at $C000 | |
Reset: | |
jsr VERA_init_text_80x60 | |
; Set the X/Y coordinates to 0 0 | |
lda #%00010000 ; Increment 1, High-addr=0 | |
sta VERA_ADDR_H | |
stz VERA_ADDR_M ; Y coordinate | |
stz VERA_ADDR_L ; X coordinate | |
; print COMMANDER X16 | |
lda #<my_str | |
sta Print_var | |
lda #>my_str | |
sta Print_var+1 | |
; White on black = $01 | |
lda #$01 | |
sta Print_col | |
jsr VERA_print_line | |
lda #30 ; Y coordinate (middle of screen) | |
sta VERA_ADDR_M | |
lda #64 ; X coordinate: (screenwidth/2)-(stringlength/2) | |
sta VERA_ADDR_L ; multiplied by 2 because in normal screemode, | |
; 1 byte is used for character and 1 for color | |
; print HELLO WORLD | |
lda #<my_str2 | |
sta Print_var | |
lda #>my_str2 | |
sta Print_var+1 | |
; White on blue = $61 | |
lda #$61 | |
sta Print_col | |
jsr VERA_print_line | |
.end: bra .end | |
; Initialize the VERA in 80x60 text mode | |
VERA_init_text_80x60: | |
; load the font | |
jsr VERA_load_font | |
; reset the rest of the device | |
; +--------- Current field | |
; |+-------- Sprite Enable | |
; ||+------- Layer 1 enable | |
; |||+------ Layer 0 enable | |
; ||||+----- not used | |
; |||||+---- Chroma disable | |
; ||||||++-- Output mode | |
lda #%00100001 ; C=Chrome Disable, O=Outputmode, (1=vga) | |
sta VERA_DC_VIDEO | |
lda #128 ; Hscale - 128=normal, 64=2x | |
sta VERA_DC_HSCALE | |
lda #128 ; vscale - 128=Normal, 64=2x | |
sta VERA_DC_VSCALE | |
; ++-------- Map Height 01 | |
; || | |
; ||++------ Map Width 10 | |
; |||| | |
; ||||+----- T256C 0 | |
; |||||+---- Bitmap mode 0 | |
; ||||||++-- Colour depth 00 | |
lda #%01100000 | |
sta VERA_L1_CONFIG | |
; ++++++---- Tile base address | |
; ||||||+--- Height | |
; |||||||+-- Width | |
lda #%01111100 | |
sta VERA_L1_TILEBASE | |
; R------A R=Reset, A= Adress (port 1 / 2) | |
lda #%00000000 | |
sta VERA_CTRL | |
; Set the X/Y coordinates to 0 0 | |
lda #%00010000 ; Increment 1, High-addr=0 | |
sta VERA_ADDR_H | |
lda #0 ; Y coordinate | |
sta VERA_ADDR_M | |
sta VERA_ADDR_L ; X coordinate | |
; Clear the screen with black background | |
ldx #80 | |
ldy #60 | |
@loop: | |
lda #$20 ; Space character | |
sta VERA_DATA0 | |
lda #$01 ; White on black | |
sta VERA_DATA0 | |
dex | |
bne @loop | |
ldx #80 | |
inc VERA_ADDR_M | |
stz VERA_ADDR_L | |
dey | |
bne @loop | |
rts | |
VERA_print_line: | |
ldx Print_col ; Load colors to use | |
ldy #0 ; Use .Y as index into string | |
@loop: | |
lda (Print_var),y | |
beq @end ; If it is 0, jump to end | |
sta VERA_DATA0 ; Write character to VERA memory, VERA | |
; will automaticly add 2 to address. | |
stx VERA_DATA0 ; Write color information | |
iny ; Increment .Y | |
bra @loop ; Jump back to get next character | |
@end: | |
rts | |
; Loading the font from the font data still has gaps. For one it only loads the first 32 characters. | |
; |- Hacked to make 2 loops to get all characters from font data | |
VERA_load_font: | |
stz VERA_CTRL | |
stz VERA_ADDR_L | |
lda #$F8 | |
sta VERA_ADDR_M | |
lda #$10 | |
sta VERA_ADDR_H | |
lda #<VERA_FONT_DATA | |
sta Print_var | |
lda #>VERA_FONT_DATA | |
sta Print_var+1 | |
ldy #0 | |
@loop1: | |
lda (Print_var),y | |
sta VERA_DATA0 | |
iny | |
bne @loop1 | |
inc Print_var+1 | |
ldy #0 | |
@loop2: | |
lda (Print_var),y | |
sta VERA_DATA0 | |
iny | |
bne @loop2 | |
rts | |
VERA_FONT_DATA: | |
!byte %01111100, %11000110, %11011110, %11011110, %11011110, %11000000, %01111000, %00000000 ; @ 0 | |
!byte %00110000, %01111000, %11001100, %11001100, %11111100, %11001100, %11001100, %00000000 ; A 1 | |
!byte %11111100, %01100110, %01100110, %01111100, %01100110, %01100110, %11111100, %00000000 ; B 2 | |
!byte %00111100, %01100110, %11000000, %11000000, %11000000, %01100110, %00111100, %00000000 ; C 3 | |
!byte %11111000, %01101100, %01100110, %01100110, %01100110, %01101100, %11111000, %00000000 ; D 4 | |
!byte %11111110, %01100010, %01101000, %01111000, %01101000, %01100010, %11111110, %00000000 ; E 5 | |
!byte %11111110, %01100010, %01101000, %01111000, %01101000, %01100000, %11110000, %00000000 ; F 6 | |
!byte %00111100, %01100110, %11000000, %11000000, %11001110, %01100110, %00111110, %00000000 ; G 7 | |
!byte %11001100, %11001100, %11001100, %11111100, %11001100, %11001100, %11001100, %00000000 ; H 8 | |
!byte %01111000, %00110000, %00110000, %00110000, %00110000, %00110000, %01111000, %00000000 ; I 9 | |
!byte %00011110, %00001100, %00001100, %00001100, %11001100, %11001100, %01111000, %00000000 ; J 10 | |
!byte %11100110, %01100110, %01101100, %01111000, %01101100, %01100110, %11100110, %00000000 ; K 11 | |
!byte %11110000, %01100000, %01100000, %01100000, %01100010, %01100110, %11111110, %00000000 ; L 12 | |
!byte %11000110, %11101110, %11111110, %11111110, %11010110, %11000110, %11000110, %00000000 ; M 13 | |
!byte %11000110, %11100110, %11110110, %11011110, %11001110, %11000110, %11000110, %00000000 ; N 14 | |
!byte %00111000, %01101100, %11000110, %11000110, %11000110, %01101100, %00111000, %00000000 ; O 15 | |
!byte %11111100, %01100110, %01100110, %01111100, %01100000, %01100000, %11110000, %00000000 ; P 16 | |
!byte %01111000, %11001100, %11001100, %11001100, %11011100, %01111000, %00011100, %00000000 ; Q 17 | |
!byte %11111100, %01100110, %01100110, %01111100, %01101100, %01100110, %11100110, %00000000 ; R 18 | |
!byte %01111000, %11001100, %11100000, %01110000, %00011100, %11001100, %01111000, %00000000 ; S 19 | |
!byte %11111100, %10110100, %00110000, %00110000, %00110000, %00110000, %01111000, %00000000 ; T 20 | |
!byte %11001100, %11001100, %11001100, %11001100, %11001100, %11001100, %11111100, %00000000 ; U 21 | |
!byte %11001100, %11001100, %11001100, %11001100, %11001100, %01111000, %00110000, %00000000 ; V 22 | |
!byte %11000110, %11000110, %11000110, %11010110, %11111110, %11101110, %11000110, %00000000 ; W 23 | |
!byte %11000110, %11000110, %01101100, %00111000, %00111000, %01101100, %11000110, %00000000 ; X 24 | |
!byte %11001100, %11001100, %11001100, %01111000, %00110000, %00110000, %01111000, %00000000 ; Y 25 | |
!byte %11111110, %11000110, %10001100, %00011000, %00110010, %01100110, %11111110, %00000000 ; Z 26 | |
!byte %01111000, %01100000, %01100000, %01100000, %01100000, %01100000, %01111000, %00000000 ; [ 27 | |
!byte %00001100, %00010010, %00110000, %01111100, %00110000, %01100010, %11111100, %00000000 ; £ 28 | |
!byte %01111000, %00011000, %00011000, %00011000, %00011000, %00011000, %01111000, %00000000 ; ] 29 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; TODO 30 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; TODO 31 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; space 32 | |
!byte %00011000, %00111100, %00111100, %00011000, %00011000, %00000000, %00011000, %00000000 ; ! 33 | |
!byte %01101100, %01101100, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; "" 34 | |
!byte %01101100, %01101100, %11111110, %01101100, %11111110, %01101100, %01101100, %00000000 ; # 35 | |
!byte %00110000, %01111100, %11000000, %01111000, %00001100, %11111000, %00110000, %00000000 ; $ 36 | |
!byte %00000000, %11000110, %11001100, %00011000, %00110000, %01100110, %11000110, %00000000 ; % 37 | |
!byte %00111000, %01101100, %00111000, %01110110, %11011100, %11001100, %01110110, %00000000 ; & 38 | |
!byte %01100000, %01100000, %11000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; ' 39 | |
!byte %00011000, %00110000, %01100000, %01100000, %01100000, %00110000, %00011000, %00000000 ; ( 40 | |
!byte %01100000, %00110000, %00011000, %00011000, %00011000, %00110000, %01100000, %00000000 ; ) 41 | |
!byte %00000000, %01100110, %00111100, %11111111, %00111100, %01100110, %00000000, %00000000 ; * 42 | |
!byte %00000000, %00110000, %00110000, %11111100, %00110000, %00110000, %00000000, %00000000 ; + 43 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00110000, %00110000, %01100000 ; , 44 | |
!byte %00000000, %00000000, %00000000, %11111100, %00000000, %00000000, %00000000, %00000000 ; - 45 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00110000, %00110000, %00000000 ; . 46 | |
!byte %00000110, %00001100, %00011000, %00110000, %01100000, %11000000, %10000000, %00000000 ; / 47 | |
!byte %01111100, %11000110, %11001110, %11011110, %11110110, %11100110, %01111100, %00000000 ; 0 48 | |
!byte %00110000, %01110000, %00110000, %00110000, %00110000, %00110000, %11111100, %00000000 ; 1 49 | |
!byte %01111000, %11001100, %00001100, %00111000, %01100000, %11001100, %11111100, %00000000 ; 2 50 | |
!byte %01111000, %11001100, %00001100, %00111000, %00001100, %11001100, %01111000, %00000000 ; 3 51 | |
!byte %00011100, %00111100, %01101100, %11001100, %11111110, %00001100, %00011110, %00000000 ; 4 52 | |
!byte %11111100, %11000000, %11111000, %00001100, %00001100, %11001100, %01111000, %00000000 ; 5 53 | |
!byte %00111000, %01100000, %11000000, %11111000, %11001100, %11001100, %01111000, %00000000 ; 6 54 | |
!byte %11111100, %11001100, %00001100, %00011000, %00110000, %00110000, %00110000, %00000000 ; 7 55 | |
!byte %01111000, %11001100, %11001100, %01111000, %11001100, %11001100, %01111000, %00000000 ; 8 56 | |
!byte %01111000, %11001100, %11001100, %01111100, %00001100, %00011000, %01110000, %00000000 ; 9 57 | |
!byte %00000000, %00110000, %00110000, %00000000, %00000000, %00110000, %00110000, %00000000 ; : 58 | |
!byte %00000000, %00110000, %00110000, %00000000, %00000000, %00110000, %00110000, %01100000 ; ; 59 | |
!byte %00011000, %00110000, %01100000, %11000000, %01100000, %00110000, %00011000, %00000000 ; < 60 | |
!byte %00000000, %00000000, %11111100, %00000000, %00000000, %11111100, %00000000, %00000000 ; = 61 | |
!byte %01100000, %00110000, %00011000, %00001100, %00011000, %00110000, %01100000, %00000000 ; > 62 | |
!byte %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 ; ? 63 | |
; ==================== end of VERA driver ================= | |
; Zero terminated "string" encoded to use the default VERA font layout | |
; See: https://cx16.dk/veratext/ | |
my_str: | |
!byte $03,$0F,$0D,$0D,$01,$0E,$04,$05,$12,$20,$18,$31,$36,$00 | |
; H E L L O , W O R L D ! | |
my_str2: | |
!byte $20,$08,$05,$0C,$0C,$0F,$2C,$20,$17,$0F,$12,$0C,$04,$21,$20,$00 | |
; since this is a 65c02, we need to define the reset vector | |
*=$fffc | |
!word Reset | |
!word $0000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment