The Raster Routine, The Bones of the Intro - Slarti64/C64-Code-Hacking GitHub Wiki

The Raster Routine, The Bones of the Intro

The first thing I would need is a basic raster routine, for playing music and creating colour splits (my PETSCII logo uses a black background colour surrounded by reversed blue characters, so there needs to be a split to change the background colour to blue to match).

I looked at my early demos, and they depended on Kernal registers and routines, and used the stack to store the registers between interrupts. This would not do for a modern intro, so instead I looked to PETSCII Ate My TinySID as it also had the PETSCII proportional font scroller I needed.

Here’s the source of the basic routine, with one raster interrupt, playing music. TASS64 format is used.

* = $080D
; Clear the screen
LDX #$00
– LDA #$20
STA $0400,x
STA $0500,x
STA $0600,x
STA $0700,x
LDA #$01
STA $D900,x
STA $DA00,x
STA $DB00,x
STA $DAE8,x
INX
BNE –
SEI
JSR $1000 ; init SID tune
LDA #$7F
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 #$06
STA $D020 ;Border Color
LDA #$00
STA $D021 ;Background Color 0
LDA #$00
STA $D012 ;Raster Position
LDA #<start ; set the raster interrupt to the start label location
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
loop JMP loop
start STA nexta+1
STX nextx+1
STY nexty+1
LDA #$06
STA $D020
STA $D021
JSR $1003
LDA #$1B
STA $D011 ;VIC Control Register 1
LDX #<start ; send the interrupt back to the start label location
LDY #>start
LDA #$00
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
*=$1000
.binary “music.prg”,2

You’ll notice it uses what is known as self-modifying code, instead of using the stack to push and pull the registers between interrupts, this saves raster cycles over using the stack for when you’re doing cycle intensive demo work. So, for instance, A is stored in nexta+1 which will load the value after the interrupt is finished. This is necessary so your interrupts don’t mess up the normal goings on of the c64.

Coming up next we’ll add a colour split, in the meantime as a quick coding challenge, try to add another raster routine with a colour split yourself 😉