Skip to content

Instantly share code, notes, and snippets.

@dgellow
Last active December 29, 2015 10:24
Show Gist options
  • Save dgellow/162b6c0613e868754a5a to your computer and use it in GitHub Desktop.
Save dgellow/162b6c0613e868754a5a to your computer and use it in GitHub Desktop.
c64 scrolling hello world. To be assembled using `dasm`. https://youtu.be/l_xk4MDTjOo
processor 6502 ; define processor family for dasm
org $C000 ; memory location for our code
CR = $0d
clear = $e544 ; clear screen
screenbeg = $0400 ; beginning of screen memory
screenend = $07e7 ; end of screen memory
screenpos = $8000 ; current position in screen
screenwidth = #$20
main:
jsr initscreen
jsr loop
rts
loop:
jsr clear
jsr drawmsg
inc screenpos ; increment current screen position
jmp loop ; loop
rts
initscreen:
lda #$00
sta $d020 ; border
sta $d021 ; background
sta screenpos ; screen position
rts
return:
rts
msg:
.byte "HELLO WORLD!"
.byte 0
rts
drawmsg:
ldx #$00 ; regX keeps msg index
ldy screenpos ; regY keeps screen position
cpy #$20
bcs screenposgreatherthan
jmp drawmsghelper
drawmsghelper:
jsr drawmsgloop
rts
drawmsgloop:
lda msg,x ; char at msg index
beq return ; exit when zero byte
and #$3f ; ascii to petscii
sta screenbeg,y ; modify screen memory
inx
iny
cpy #$20
bcs ycountergreatherthan
jmp drawmsgloop
screenposgreatherthan:
ldy #$00
sty screenpos
jmp drawmsghelper
ycountergreatherthan:
tya
sbc #$20
tay
jmp drawmsgloop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment