;COLOUR SPLITTING USING $D012
MAIN LDA #$30
LDX #$00 ;BLACK
RASTER1 CMP $D012
STX $D020 ;ASSIGN BLACK TO
STX $D021 ;BORDER AND FRAME
LDX #$01 ;WHITE
RASTER2 CMP $D012
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
----- 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
LDX #$XX ;Timing Value
------ Rest of program
You could reverse the timing loop, but if you do, you would need to change the values into the following.
CPX #$XX ;Timing Value
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.<> SEI
Right, 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
Let us say for example you are writing a demo, game or utility, you
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:
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:
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.
let's add another command to the IRQ. After JSR flash, try JSR CHAR,
RTS inset the label CHAR and enter INC $D018 and add another RTS,
and run. You'll get some funny effects happening. This is because the
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.
colour washing routine, inside
;an IRQ Raster Interrupt Player
* = $1000
SHOWMS LDA MESSAGE,X
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.
;COLOUR WASHING ROUTINE
COLWASH LDA COLOUR+$00
CYCLE LDA COLOUR+$01,X
;DATA TABLES FOR COLOURS
;DATA FOR TEXT 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
CYCLE LDA COLOUR-$01,X
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.