1x2 Font Scroller with Music - Slarti64/C64-Code-Hacking GitHub Wiki
Ok, as promised, it’s time for new sourcecode! This time it’s a 1×2 character scroller, a two line high scroll font. Apologies for the slight delay in releasing this one, but I had some difficulty finding an appropriate charset. This one is by Nuckhead of Backbone Society, Device, and was released by itself as a 1×2 font on csdb. You’ll find several fonts on CSDB if you do a search for “1X2 fonts”.
Firstly, I’ll tell you how to rip your own fonts. Firstly, find an intro or demo with a 1×2 font charset. Then with freeze with VICE monitor and check the contents of $D018, this will tell you exactly where the charset is stored. There’s a simple method to make sense of setting $D018, just seperate the hex digits first, then multiply them both by $400 (it helps if you have a hex calculator). The first result will tell you where the screen is stored, and the second result, rounded off to the nearest $800, will tell you where the charset is stored. Screens use $400 memory, and charsets use $800 memory.
So, onto the code. Creating a 1×2 scroller from a 1×2 scroller is quite simple, actually. Simply scroll the second line of the screen as well, and when you stamp on the character from the scrolltext, add #$80 and then stamp it on the next line. This gives you one line of text, and one line of reversed text, as this is how most 1×2 font charsets are stored. If you find your charset seems to be corrupted on assembling your code, consider that your source font may have been built differently. This happened to me on one font I wanted to rip, and it took two days before I realised it was the font at fault, and not me…
Well, there you have it, your first 1×2 font scroller, your challenge for next time is to rip and display a 2×2 font! Until next time, stay tuned!
*=$0801
; BASIC runnable stub, handy snippet!
.word ss,2005
.null $9e,^init;will be sys 4096
ss .word 0
init SEI
LDX #$00
; Clear the screen
- LDA #$20
STA $0400,x
STA $0500,x
STA $0600,x
STA $06E0,x
; Clear colour memory
LDA #$01
STA $D900,x
STA $DA00,x
STA $DB00,x
STA $DBE0,x
INX
BNE -
JSR $1000 ; init music
LDA #$1F
STA $DC0D ;CIA1: CIA Interrupt Control Register
STA $DD0D ;CIA2: CIA Interrupt Control Register
LDA #$1B
STA $D011 ;VIC Control Register 1
LDA #$01
STA $D01A ;VIC Interrupt Mask Register (IMR)
LDA #$00
STA $D020 ;Border Color
STA $D021 ;Background Color 0
LDA #$00
STA $D012 ;Raster Position
LDA #<start
STA $FFFE ;IRQ
LDA #>start
STA $FFFF ;IRQ
LDX #<nmi
LDY #>nmi
STX $FFFA ;NMI
STY $FFFB ;NMI
LDA #$35
LDX #$FF
STA $01
TXS
INC $D019 ;VIC Interrupt Request Register (IRR)
LDA $DC0D ;CIA1: CIA Interrupt Control Register
LDA $DD0D ;CIA2: CIA Interrupt Control Register
CLI
- JMP -
start STA nexta+1
STX nextx+1
STY nexty+1
LDA #$19
STA $D018
LDA #$00
STA $D020
STA $D021
JSR $1003
JSR scroller
LDA #$1B
STA $D011 ;VIC Control Register 1
LDX #<next
LDY #>next
LDA #$32
STX $FFFE ;IRQ
STY $FFFF ;IRQ
STA $D012 ;Raster Position
INC $D019 ;VIC Interrupt Request Register (IRR)
nexta LDA #$00
nextx LDX #$00
nexty LDY #$00
nmi RTI
next STA nexta1+1
STX nextx1+1
STY nexty1+1
LDA xpos ; store the current xpos in $D016
STA $D016
LDA #$18
STA $D018
; Set the interrupt to the start label and set the raster to #$00
LDX #<start
LDY #>start
LDA #$00
STX $FFFE
STY $FFFF
STA $D012
INC $D019
nexta1 LDA #$00
nextx1 LDX #$00
nexty1 LDY #$00
RTI
scroller LDA xpos
CLC
SBC speed ; Subtract speed from xpos
BCC + ; if carry clear, skip to the next bit
STA xpos ; if carry set (value is minus) then reset to zero
RTS
+ AND #$07 ; Make sure the value is between 0 and 7
STA xpos
LDX #$00
; Scroll the first two lines of the screen
- LDA $0401,x
STA $0400,x
LDA $0429,x
STA $0428,x
INX
CPX #$27
BNE -
LDA gettext+1
CLC
ADC #$01 ; add one to the gettext location
STA gettext+1
BCC gettext
INC gettext+2
gettext LDA scrolltext
BNE + ; If a zero is detected in the scrolltext, loop
LDX #<scrolltext
LDY #>scrolltext
STX gettext+1
STY gettext+2
JMP gettext
+ STA $0427
CLC
ADC #$80
STA $044F
RTS
xpos .byte 7
speed .byte 2
scrolltext
.enc screen
.text " welcome to this simple 1x2 scroller, your next challenge is to create a 2x2 scroller!!! stay tuned.... "
.byte 0
*=$1000
.binary "music.prg",2
*=$2000
.binary "1x2charset.prg",2