;===========================
;COLOUR
SPLITTING USING
$D012
;===========================
*=$0810
SEI
MAIN
LDA #$30
LDX #$00 ;BLACK
RASTER1
CMP $D012
BNE RASTER1
STX $D020 ;ASSIGN BLACK TO
STX $D021 ;BORDER AND FRAME
LDA #$A8
LDX #$01 ;WHITE
RASTER2
CMP $D012
BNE RASTER2
STX $D020
STX $D021
JMP MAIN
Now that we have typed in this listing if you run it, just assemble it and run the little program. You will see that the top border and frame is black, and that the bottom border and frame is white. You will also notice that using this routine, there are a few screen flickers. This is because we are not using an IRQ loop, and we're also not using TIMING either :o)
How do we add timing to rasters? There are different ways, but one of the easy ways is by adding the 'NOP' command a few times, before we actually start a process. For example
RASTER1
CMP
$D012
BNE RASTER1
NOP
----- Rest of program
Adding NOPs will move the little flickers further across the screen. Therefore you will need to add a few of these until the split is STRAIGHT and not FLICKERING :o)
There are other methods of timing, which you can use, which can be easier. You could use timing inside an x or y loop. For example
RASTER1
CMP
$D012
BNE RASTER1
LDX #$XX ;Timing Value
TIMER1
DEX
BNE TIMER1
------ Rest of program
You could reverse the timing loop, but if you do, you would need to change the values into the following.
LDX #$00
TIMER1
INX
CPX #$XX ;Timing Value
BNE TIMER1
Interrupts (The IRQ Raster Interrupt)
An IRQ Raster Interrupt is a routine, known as the Interrupt Request flag. This is a continuous loop, which can hold more than one control loop. Therefore uses more complicated techniques. Most people use IRQ interrupts to do various effects in their programs. I mainly use IRQ interrupts for my C64 games. A little explanation will be added in a short while. But first copy this routine into your Turbo Assembler before you actually do anything. Below is a listing that shows a nicr and small IRQ raster interrupt routine.
<> SEIRight, looking from the top of the IRQ flag, the values $0314 and $0315 are very special, these call INIT to produce the main IRQ interrupt flag, using the BASIC Kernal flag. But if you want non-kernal routines (Which are slightly more complex) then you'll see those in later chapters. However you MUST use (as highlighted) the prompts else your IRQ wont work properly. This is because they are vital to use in your program.
What can IRQ be
used for?
Let us say for example you are writing a demo, game or utility, you
might
need to use IRQ raster interrupt request flags to link various sources,
such as the following:
Okay, press RUN/STOP and restore, load a Demo Tune or a tune of your own into $1000, (JCH, DMC or equivalent), enter sys 36864 (G9000). Cross assembly users won't need to do this, as they are not using Turbo Assembler. Now do as follows:
Underneath STA $D01A enter:
LDA
#$00
JSR
$1000
This
is to initialise your music
You'll be able to hear some music playing in the background. Later on, we'll be taking a look at preparing a demo.
If you link other routines, be sure to JSR (routine) before JMP $EA7E Let's try something simple, such as flashing the screen. Before JSR $1003, put JSR FLASH and then underneath JMP $EA31, enter the following code:
FLASH
INC $D020
DEC $D021
RTS
Why do we add an RTS command at the end of this prompt? This is because if we don't use RTS, the program will not respond properly, in fact it will virtually crash and you may lose everything.
Now,
let's add another command to the IRQ. After JSR flash, try JSR CHAR,
Underneath
RTS inset the label CHAR and enter INC $D018 and add another RTS,
assemble
and run. You'll get some funny effects happening. This is because the
C64
is playing with your charset memory.
A practical an
fun example to try with interrupts - The Colour Washing routine.
In some demos and other programs on the Commodore 64, you see colours moving from the left hand side - to the right and also vice-versa. How do these simple routines work? Well, this is the easy part - in fact it is the easiest method of them all. Copy this listing below, and all will be revealed straight after the listing.
;Simple
colour washing routine, inside
;an
IRQ Raster Interrupt Player
* = $1000
LDX #$00
SHOWMS LDA MESSAGE,X
STA
$0400,x
INX
CPX #$28
BNE SHOWMS
Now create your own IRQ raster interrupt, make the screen black and set the C64 charset mode to $16 (LDA #$16 STA $D018)
Inside your IRQ raster interrupt routine, call the colour washing routine.
IRQ
JSR COLWASH
JMP $EA31
;======================
;COLOUR
WASHING ROUTINE
;======================
COLWASH
LDA COLOUR+$00
STA COLOUR+$28
LDX #$00
CYCLE
LDA COLOUR+$01,X
STA COLOUR+$00,X
LDA COLOUR,X
STA $D800,X
INX
CPX #$28
BNE CYCLE
RTS
;DATA TABLES FOR COLOURS
COLOUR
.BYTE $09,$09,$02,$02,$08
.BYTE $08,$0A,$0A,$0F,$0F
.BYTE $07,$07,$01,$01,$01
.BYTE $01,$01,$01,$01,$01
.BYTE $01,$01,$01,$01,$01
.BYTE $01,$01,$01,$07,$07
.BYTE $0F,$0F,$0A,$0A,$08
.BYTE $08,$02,$02,$09,$09
.BYTE $00,$00,$00,$00,$00
;DATA FOR TEXT MESSAGE
MESSAGE
.TEXT "RICHARD BAYLISS'"
.TEXT
" COLOUR SCROLLER"
.TEXT
" ACTIVE......"
.TEXT
"
"
If you take a look at this routine, during the control of the colour washing routine, we take the byte, which is at COLOUR+00 and then we place it at COLOUR+$28, then we call a continuous loop which makes the data table cycle, by subtracting each piece of data in the data table by one, and read the calculations 40 times ($28 times), therefore the data table pulls each byte of data. Also inside our loop, the colours are read from the data table and the positioned on to the C64's colour screen RAM, which is from $D800 until $D828. As for reading the message, you'll see for yourself how that works. It is easy to remember ;o)
There is also a simple way to -reverse- the direction of your colour-washing routine. The listing below shows how you can do this :)
;======================
;COLOUR
WASHING ROUTINE (REVERSED)
;======================
COLWASH
LDA COLOUR+$28
STA COLOUR+$00
LDX #$28
CYCLE
LDA COLOUR-$01,X
STA COLOUR+$00,X
LDA COLOUR,X
STA $D7FF,X
DEX
BNE CYCLE
RTS
We reverse the process. You'll also notice that $D800,x has been changed into $D7FF,x. Why is this? Well, simply because if you used $D800 instead of $D7FF you would find that the C64 will miss the first character, therefore you will need to subtract 1 from the screen ram location. Pretty easy to understand huh?
Something to try:
Now that you have learned how to do simple colour cycling, try and put BOTH routines on to the screen. Create your own message at the top of the screen, and bottom of the screen and use one cycling routine at the top and a reverse routine at the bottom.