Attacking the Demon in Multiple Regions
During June I was bombarded by an overwhelming amount of videos and discussion of the Penultimate cartridge for the VIC-20. Unable to withstand it anymore I splurged on an untested VIC-20 on eBay that also included the original box and eight cartridges and simultaneously placed an order for the Penultimate cartridge. While I had planned on getting a VIC-20 eventually, I regarded it as sort of a clunker because of the primitive text screen and limited built-in RAM, and it had remained low on my list of computers I wanted to try out.
A couple of days after getting my VIC-20 and matching Penultimate I was asked by Eric Gustafson if the Demon Attack that had been included on the Penultimate had been fixed so that it worked on both PAL *and* NTSC systems. Curious, I fired up the game and replied with a picture that showed the screen wasn't right and next thing I know I'm caught up in a discussion about what it might take to change the game so it autodetects the TV standard and works on both PAL and NTSC systems and if anyone might have the source code.
Intrigued by the challenge and since I happened to have a 6502 disassembler around from a previous project I disassembled the two different Demon Attack versions and was surprised that the changes were actually rather substantial. I had been expecting only minor changes which would be easy to combine, but the code for handling the TV standards seemed to have been completely rewritten when it was converted from one to the other.
To get a better idea of what was really going on and to make comparing the versions easier I decided I needed to come up with a way so that the auto-generated labels weren't based on address, but instead based on the code they pointed to. It took a bit of thinking but I was able to come up with something that worked quite well and made it much easier to see the common code as well as the changes.
With mostly matching labels on the disassembly combining the changes between the PAL and NTSC versions wasn't too difficult. I simply copied the subroutines that were different in one version into the other, added a couple of lines to check the machine version and then jump into either the original NTSC or PAL init routine, and then tried to assemble it. In the cases where the subroutines had identical labels the assembler complained I had duplicates and I just went in and manually fixed them. The other problem was after adding so much more code I had branches that were trying to go to code that was too far away, but all I had to do to fix that was to shuffle the subroutines around so that the branches were closer.
The auto-detect version of Demon Attack came in at a little over 4k. I thought it would be neat to keep it within the original 4k, but there's really not much reason to put that kind of effort into it when these days an 8k EPROM isn't a huge cost difference, and most people that want to play the game on real hardware will probably be using something like a Penultimate anyway that has far more than 8k of ROM space.
As several other people were interested in following along I went ahead and released my disassembler under the GPL and posted it up on github. I also finally got around to removing all the hardcoded stuff to special case just the Demon Attack code and added lots of options to the disassembler.
If you're interested in the combined auto-detecting Demon Attack, you can download both the assembler source I created and the assembled binary version below. Tynemouth Software has also already incorporated it into the Penultimate Cartridge and I highly recommend getting that if you want to play on a real VIC-20 and don't want to bother with the hassle of burning your own EPROMs and trying to install them on a cartridge.