Crosspost from LJ (8-18-06):
Galaga never looked so good!Â
Well, to me, at least. Anyone else would surely disagree. But the reason I'm fond of this particular screwed up photo is because it was the result of this.
After much wiring, I hooked up a flash eeprom (aka rewritable rom) with a specially patched (by me) version of Galaga to the beat up NES I acquired, and despite the appearance, it's entirely playable. In fact, considering I've played it so many times in the past, I was able to play the first few rounds and past the first bonus round without losing a life, all the while not even being able to see most of the enemies until they moved. xD
So you might be wondering how this is at all a success, considering how messed up it is. Well, that's because I totally knew it'd be this way beforehand. I just wanted to make sure I could get an eeprom to boot up the NES at all via wires. I didn't want to have to wire it, considering it involves so many, but the only alternative involved soldering, and I don't have an easy place to do that at, especially where I can vent the fumes. Plus, it means gutting an NES cartridge for the board, and I don't have any extras at the moment aside from a dead Dragon Warrior, and it's not suited to running Galaga. The only cartridge I have at the moment actually is SMB/Duck Hunt/Track Meet, which also isn't suited.
As for why the graphics are screwy, it's because there's no CHR rom installed, and what you do see is coming from graphics copied into the limited onboard NES graphics memory. Normally an NES cartridge has both a PRG (program) and CHR (characters aka tiles) rom, the former hooked to the cpu, and the latter hooked to the PPU (picture processing unit). Well, since I only have one eeprom at the moment, needing two different rom chips was obviously a problem. So my idea was to combine the roms into one, and just copy the other out into video memory on startup. I even added a little Fybertech intro screen, to indicate when the transfer is done, even though it happens almost instantaneously, and I could jump straight into the game and the player wouldn't know the difference between the original and my own, but what fun is it if I can't make it a little more personalized~!
Of course, this means the PPU needs an available 8kb of video ram to copy the CHR rom into. Emulators don't care, because there's no real hardware involved, and as far as it's concerned, there actually is 8kb of ram there in place of 8kb of CHR rom, so my patched ROM worked fine in that. Well, the actual NES only has 2kb of video memory, which it normally uses for screen layout data. You need at least 1kb for a single screen layout on a simple game, which leaves you with just 1kb of onboard memory to store tiles in (which is normally never done). So perhaps you're starting to see that 8kb of CHR rom doesn't fit into 1kb of ram, and hence the simplest explanation for why the screen was all screwy. The tiles it needed to display simply didn't exist, and in the places it expected to find'em, it was finding mirrors of other tiles (because the 2kb repeats if it tries to access anything higher than that). It was also finding screen layout data thinking it was tiles (again, because of the mirroring effect), which doesn't translate into any sort of imagery, and further explains the screen's screwiness.
Keep in mind that it's merely Galaga that's displaying incorrectly. There's no actual hardware problem involved (unless you count the lack of video memory). I can (and plan to) create a simple rom requiring far fewer tiles (64 max) which will only take up 1kb of video memory, leaving the other 1kb for screen layout data. Such a rom should work perfectly, because it's not trying to use more than is available. I'll take a picture when I do.
Anyhoo, as for the rom patch itself, I'll explain a little first. PRG roms can be 32kb max, unless you use a memory mapper (which a majority of NES games did), and the CHR can only be 8kb, unless, again, you use a mapper. The purpose of a mapper is to switch out pieces of code/graphics you don't need at the moment with pieces you do. But anyway, in order to stick both the CHR rom and my own code into just 32kb of space, this means I needed an NES rom which had 16kb or less PRG rom. There aren't many that are so small. The Japanese version of Galaga, one of my favorite games, just so happened to have 16kb of PRG rom, so I naturally used it for my experiment. The arrangement of PRG looks like this now:
[8kb Galaga CHR tiles][8kb Fyber code][16kb Galaga PRG code]
This takes up the full 32k allowable PRG rom space. At the tail end of the Galaga code are a standard set of pointers to where to jump in the code when the NES is turned on. I simply replaced that pointer to jump into my section of code, which copies the CHR into video memory, then jumps back to where Galaga would have initially jumped had I not interceded. The game doesn't know the difference. Also, even though I have 8kb of possible code space to work in, I probably only used a few hundred bytes for my copy procedure and logo (especially since I used Galaga graphics to display it).
So now the next thing to do is to add 8kb more video memory to the NES in place of an 8kb CHR rom. Some NES cartridges actually did this very thing, including ram in the cartridge instead of a second rom, and copied tiles out of a large PRG rom into video memory as they were needed. I guess this saved'em some money instead of burning two roms. But once the NES has an extra 8kb to store all these tiles in, Galaga will run fine. It's just hooking up another 20+ wires that's daunting. X_x
Oh, I should mention, the NES wouldn't even be working to do this if I hadn't killed the lockout chip. You know how an NES blinks every second if you don't put in a cartridge, or if the cart/connector is dirty? That's what's doing it. It's a stupid security feature they put in to keep out unlicensed games (which the Japanese version and top-loading American version didn't have). Disabling the chip is a simple modification, and I'd take a picture if it didn't mean pulling loose my wires to turn the NES board over to show you, so you'll have to take my word for it for now.
Anyhoo, this is probably rather long and drawn out, and surely confusing to many, but for anyone that found it interesting and is curious about anything regarding my mod here or the NES in general, feel free to ask. I've studied up enough on its workings to know pretty much everything about it . . !
If you want to check out my patched Galaga, you can
grab it here. The logo aint much to see, so you can just hit any button to continue past it into the game. See if you can get to level 30 . . ! I may use a combination of that logo screen and my
running Mario test rom for the small rom I plan to make to get the real NES displaying graphics using just that 1kb of available space. And then maybe soon I'll get that extra 8kb of ram wired in, so that Galaga will work correctly.