Part 31: FredMSloniker - Hex Wars Redux - Part 1Grimwit, I'm afraid your match is going to have to wait. Why? Because the overhauling I'm doing on Hex War has grown to the point that I'm unlikely to be finished soon. So, for content, have the first of my update journals! This is going to reiterate some stuff from the thread, as I originally wrote it for a separate Hex War thread, but it may be helpful to readers anyway.
Tuning up Hex War: Part 1
Before I get into the changes I made to Hex War, let's talk about how I got it into my computer in the first place.
Hex War was published in the July 1986 issue of Compute!, a magazine that, over its lifetime, covered everything from the Commodore PET to the latest Windows 98 boxes. Originally written for the Commodore 128, Hex War was ported to the Commodore 64, Apple ][, Atari 8-bit computers, Amiga, and IBM PC. I'll be covering the Commodore 64 version, which is identical to the original 128 version except for one minor niggle, which I'll describe later.
While I could have found the game on some skeevy internet site, where's the fun in that? I headed over to the Internet Archive, where I could download a PDF version of the magazine, and took a look at the game's code, which looked something like this:
Then I opened my favorite text editor and started typing that sucker in, which looked something like this:
The eagle-eyed among you will notice some differences between what I typed and what's in the magazine, specifically between curly brackets. The reason is that the Commodore 64 doesn't have curly brackets, but it does have a number of characters that can't be typed in ASCII, some of which are difficult to tell apart at a glance. The magazine represented these characters in a variety of ways so you knew what to type. While I could have typed the program directly into my emulator of choice, I decided to take a different approach, namely using this:
C64List is a program designed to take a text file and turn it into a .prg file, which is a format that emulators can read. It can also reverse the process and do a number of other useful things, some of which I'll be showing off.
So now I had a .prg file and could load it into VICE, right? Noooot quite. See, when VICE loads a .prg file, it immediately runs the program, which is bad, because the Commodore 64 version needs a preloader:
Why it needs a preloader is rather technical (and is the niggle I mentioned earlier). See, the program uses a custom character set for its map. (Technically it could use the built-in character set, but then the hexagons would be squares arranged in a hexagon pattern instead.) However, a custom character set must exist in the same 16K block (out of 64K) as the screen memory - and while you can move the screen memory to another 16K block (indeed, to any 1K block), Commodore BASIC doesn't support printing to any location but the default. The default location is in the first 16K of memory, most of which is taken up by... BASIC program storage.
In order to make room for a custom character set, therefore, the preloader (through a somewhat arcane process involving writing into the keyboard buffer) changes the pointer to the start of BASIC memory to point a bit higher, initializes that memory, then loads and runs Hex War itself. With the lower memory unused, Hex War can now copy the character ROM into it, make some changes, then tell the computer to look there instead for its character set.
So how did I get this all to work? Well, I typed in the main game and the preloader and converted them to .prg files. Then I used a command-line utility, C1451, that's included with VICE to make a .d64 file (a virtual floppy disk) and put both .prgs onto that disk. By making sure the preloader was the first program on the disk, I could autoload that .d64 file in VICE (which loads and runs the first program), loading the preloader, which then loaded the game.
But I'm getting ahead of myself. What if I made some typoes? (Spoiler alert: I did make some typoes.) Well, that's what the Automatic Proofreader is for.
You type this program in (very carefully), save it, then run it, and it tampers with Commodore BASIC's line-entering routine so that every time you type in a line of code and press Enter, a two-letter code appears in the upper-left corner of the screen. (It then erases itself - the BASIC part, at least - so you can type your program in, which is why you save it before running it.) If the displayed code doesn't match the code to the left of the line number, you made a mistake and need to fix the line.
Since I typed the program in with C64List, I had to jump through a hoop or two to use the proofreader. Specifically, I had to make a .prg, put it on a disk image with C1451, then attach that disk image to drive 8 in the emulator. I typed in, saved, and ran the proofreader, loaded (but did not run) Hex War, then used the LIST command to list a small portion of the program (enough to fit on a screen). Then I moved the cursor over each line and pressed Enter, which re-entered the line, triggering the checksum:
If (when) I found errors, I fixed them in the emulator. Once I was done fixing them, I saved the corrected program to disk. Then I could reset the emulator (needed to dislodge the Automatic Proofreader's shenanigans), load the loader, run it, wait while it loaded the game, and be presented with this lovely screen:
So that's how I got to the point where I could play Hex War. Next update: I started making some changes.