What is a raster split and what does it do?

A raster split is a hardware command that can create amazing things. For example a C64 demo uses raster splits and interrupts. A raster split is triggered by using the $D012. If you ever bought or seen a C64 game in the 1980's and 1990's, you will have noticed that some front ends, or most use rasters to cut the screen. $D012 is known for it's clever features, such as screen cuts, raster bars, control inside an interrupt etc.

An example:
This is the fun bit. $D012 is used to create some raster splits. For example, if you wanted to make your own title screen for a C64 game, you would need to code in the raster splits. Let us say for example, you paint a logo using drawing programs, save them as a VIDCOM format and you want to display the normal font you created which is located at $2000. A raster split would need to be used, therefore you would need to split everything up. For example, a way a screen would be presented.:

If you look at the black line, you can see that this design represents the co-ordinates of the raster split. A prime example for something like this is a title logo, which was done for the game Balloonacy. Look below and you'll see what I mean by a raster split :o)

Now we are going to try something similar, but more simpler. We are going to program our own raster splits, but we are going to do this the more easier way. That's right, we are going to split the screen into two different colours. Now how do you do this? Easy, type in the listing below and you should begin to understand how the code will work :o)


MAIN        LDA #$30
                LDX #$00 ;BLACK
                BNE RASTER1
                STX $D020 ;ASSIGN BLACK TO
                STX $D021 ;BORDER AND FRAME
                LDA #$A8
                LDX #$01 ;WHITE
                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
                ----- 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
                CPX #$XX ;Timing Value
                BNE TIMER1

<>There is also another method in timing, which is the hardest of them all. Imagine you are doing a raster bar, which uses loads of colours, like some demo groups use. Well a timing table would need to be produced. To find out more about timing, read the disk mag 'Coders World' issue 2.

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
                LDA #<IRQ
                LDX #>IRQ
                STA $0314
                STX $0315
                LDA #$31
                STA $D012
                LDA #$7F
                STA $DC0D
                LDA #$1B
                STA $D011
                LDA #$01
                STA $D01A
HOLD            JMP HOLD
IRQ             LDA $D019
                AND #$01
                STA $D019
                LDA #$31
                STA $D012
                INC $0400

                JMP $EA7E

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 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:

  • Scrolltext
  • Raster Bars
  • Charset Animations
  • Playing Music
  • Colour washing
  • Advanced data handling (for special effects)
  • Sprite control
  • Keyboard commands
  • Joystick commands
However, INC $0400 does not mean much, apart from you'll see a character changing on the top left corner of the screen.

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

Now, delete INC $0400 and change to JSR $1003. This will play your music. Now, assemble and run.

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

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
           STA $0400,x
           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.

           JMP $EA31

                     STA COLOUR+$28
                     LDX #$00
CYCLE                LDA COLOUR+$01,X
                     STA COLOUR+$00,X
                     LDA COLOUR,X
                     STA $D800,X
                     CPX #$28
                     BNE CYCLE


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


             .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 :)

            STA  COLOUR+$00
            LDX #$28
            STA COLOUR+$00,X
            LDA COLOUR,X
            STA $D7FF,X
            BNE CYCLE

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.

Next Page / Previous Page / Back to Contents Page