Ford:

Sometimes, a bug that is totally a CPU bug just isn't a CPU bug. For the past week, we were puzzled as to why Gunhed (known in the US under the far more '80s title Blazing Lazers[sic]) refused to boot without getting stuck in an infinite loop overwriting all of VRAM (including the 8000-8FFF region that isn't even backed by physical memory) with 0s. Today, I finally tracked down the reason why. It turns out that Gunhed is a 384KiB ROM. On the PCE/TG16, ROMs of this size are mapped into memory in a rather interesting way. The first MiB of the address space is mapped to the game ROM. For a ROM of a size N that evenly divides 1MiB, the game is simply mirrored every N bytes. For a 384KiB ROM, however, this is not the case. Instead, the first 512KiB of the address space consist of the first 256KiB of the ROM image mirrored twice. Then, the upper 512KiB of the address space is filled with mirrored copies of the upper 128KiB of the ROM image. I believe this may be because the 384KiB cards were implemented using a 256KiB mask ROM and a 128KiB mask ROM with certain address lines used as chip enables, but I don't know for certain. As it turns out, we were reading an incorrect value from ROM, setting it as a base address in a pointer table, and then corrupting a whole load of memory, later triggering the VRAM clearing loop.

After discovering a mention of "strange" behavior with 384KiB ROM mappings in a random forum post from 15+ years ago, I played around with Mednafen to figure out the actual mapping, and then fixed my memory mapping logic. I was then greeted by the title screen to Gunhed (minus sprites)!

On Wednesday, Amolak and I will merge his sprite code branch into the master branch and attempt to boot a game with sprites enabled. If all goes well, we will then proceed onto the next phase in our project: synthesizing our Verilog and testing it on the FPGA board.

On an unrelated note, I ended up implementing the SET instruction and the modifications it performs to immediate-mode arithmetic operations. The peace of mind of having the full ISA implemented was worth the extra annoyance. :-)

