It feels like a long time since my last code post (and I’d say it has been). After being incredibly motivated last year after attending my first Syntax demo party, I got stuck into creating a few simple effects. Other interesting projects came up and my C64 demo coding took a back seat. Five weeks ago I got the email reminder about Syntax and decided there would be enough time to get something together. That did happen and I achieved my goal of entering a production into the Syntax#14 old skool demo category.
The last 5 weeks have been incredibly motivating, so while the energy is strong, I’m going to get back into posting up some details on things I learn once again. I’ve put a few things into the Syntro demo I’d like to cover in separate posts over the coming week or so.
To start with though, an effect (if you could call it that) which I’ve been interested in learning about for awhile is removing the top and bottom borders on the C64 display.
I don’t consider this an effect as on it’s own, there is nothing visually entertaining about it. It is however a base for other effects to be built upon.
First up, I create a new .asm file and insert a bunch of memory constants. I’ve taken to doing this and have a standard set in a template since I use them so often. I find it easier than remembering all the hex values. I will perhaps return to all my previous examples and update the source with the new formatting at some point too.
Next up I specify where to start the program. I’ve taken to using $0801 and inserting a small 12 byte sequence to auto run the program once loaded in VICE. It’s faster than typing SYSXXXX all the time. It’s important to note though that a packer / cruncher will inserts this automatically for you, so I only use it here for convenience.
To stop the C64 from rendering the top and bottom borders, it’s actually pretty straight forward. By default, the C64 will run in 25 row mode. The register $d011 can be used to switch between 25 and 24 row modes. Bit 4 controls this. When you want 25 row mode, this is set to on. To switch to 24 row mode, this bit needs to be set to 0.
Now that we know that, we can use this to our advantage. If we set an interrupt to occur at the last screen line, just before it begins drawing the lower border we can trick the C64 into thinking it is already drawing the border. When in 24 row mode, the C64 obviously begins drawing the borders 8 pixels higher. When it reaches scan line 250, it checks to see if it needs to start drawing the border. Since the border began drawing at line 242, it thinks it is already drawing it.
So we set up an interrupt to occur on scan line 249 and point it to a block of code which will do this.
This routine is very straight forward. It first acknowledges the interrupt and then resets bit 4 the $d011 register. This sets the C64 into 24 row mode. It then simply sets the next interrupt in the chain, which will restore back to 25 row mode.
The second interrupt routine simply grabs the current value of $d011 and sets bit 4 again to switch back to 25 row mode. It then sets the next interrupt to be the switch border off routine and will continue to loop. As more effects are added to this the interrupt chain will increase in size, but this is all there is to removing the upper and lower borders.
When we compile and run the code, this is what we get:
Great, so the borders have been removed, but there is some junk in both the top and bottom borders. It’s the same pattern repeated. Turns out that this is controlled by a single byte within the current bank the VIC chip is currently pointed at. The last byte of the bank in fact. In this case, $3fff is controlling this. If you play around with this byte, you will find that each bit renders another strip in each “character” position. So setting it to $ff, it will be a solid block. Setting it to $00 it will clear it – which is what we want here.
With that added to the code and recompiling, we now have open borders with no garbage.
With the borders removed, we are now free to build on this with other effects. I’d like to sort out some type of sprite scroller here in the future.
Full source available here: Link
This turned out to be much easier than I had originally thought. I expect the side borders are possibly similar. The C64 can work in 38 or 40 column mode and I expect that if I play around with this, I can get the borders to not render. No doubt this will need to be done per scan line though.. but I look forward to playing around with this soon enough.