Autoload Tunnels of Doom game from ROM ###################################### Description =========== The hack described below modifies Tunnels of Doom to auto-load an initial game from cartridge ROM. After displaying the title screen, Tunnels of Doom will immediately proceed to the "start game" menu, as if you had just loaded a game. When used with an appropriate cartridge (e.g. FinalGROM 99), this allows Tunnels of Doom to be played without a disk or cassette. (A disk or cassette is still needed if you want to save your game, however.) The auto-loader does not verify that the ROM is present. The game will probably crash after displaying its title screen if no ROM is present. ROM preparation =============== First, get your Tunnels of Doom quest file into TIFILES or V9T9 FIAD format, or any other format that consists of a 128-byte header followed by the raw data. The resulting file should be 13,184 bytes. The auto-loader will ignore any additional data after the first 13,184 bytes. NB: PC99 FIAD format has a 256-byte header, so is not compatible. For FinalGROM 99, all you need to do is save this file on the SD card with a file name ending 'C.BIN'. Save the modified Tunnels of Doom GROM with the same name, but with 'G.BIN' in place of 'C.BIN'. If you have multiple quests, it is necessary to have a separate copy of the GROM for each quest. For use in other situations, e.g. with some emulators, you might need to split the ROM into two 8 KB files with names ending C.BIN (first 8 KB) and D.BIN (last 8 KB). Since the original file is smaller than 16 KB, you will need to add 3,200 zero bytes to the end of D.BIN. (The 'pad.py' script by Ralph Benzinger can be used to expand a file to 8 KB in size.) Known issues ============ The modified Tunnels of Doom works perfectly on V9T9, but your mileage might vary using FinalGROM 99. Using exactly the same files (i.e., separate C, D and G files), I have experienced display glitches and intermittent crashes using FinalGROM 99. However, other people have reported that it works. This might be a problem with my FG99, or it might be dependent on the firmware version. For me, the auto-loader code works - it is possible to start a game, but it will crash soon after. The longest game I have played with FG99 consisted of digging a new dungeon (using existing characters), buying some items in the shop, descending into the dungeon, then wandering a few corridors before the game froze while drawing a corridor. The crashes I have seen do not happen the same way every time, though some crashes are more common than others. Various display glitches and crashes I have seen: * Random junk drawn on screen as soon as game is launched. Immediate crash. * Returns to master title screen after showing game title screen. * Random junk at the bottom of the screen. * Start game and select difficulty menus overlaid on top of each other. * Colons, parenthesis and other symbols sometimes missing from various prompts. * Crash while digging the dungeon. Music sometimes keeps playing forever, sometimes stops altogether. * Shop menus displayed in the wrong colours. * Shop menus overlaid on top of each other. * Game freezes when purchasing from the shop. * Game freezes while drawing a corridor. GROM modification ================= I have created a pre-modified GROM named TODAUTOG.TEM. The instructions below describe how the changes work. Offset values ------------- Offsets in this document are relative to the start of cartridge GROM (i.e. absolute GROM address >6000). When editing a *G.BIN dump of cartridge GROM, these offsets can be used as direct offsets into the dump file. Startup code ------------ We modify the startup code to call our auto-load routine: The code at offset >003D (i.e. GROM address >603D) should look like this: 003D BE 3F 02 ST >02,@>833F 0040 39 00 01 01 77 B8 MOVE 1 FROM G@>77B8 TO VR1 Change this to: 003D 39 00 01 01 77 B8 MOVE 1 FROM G@>77B8 TO VR1 0043 05 97 11 B >9711 We get rid of the initial 'ST' because memory address @>833F is overwritten with another value (>03) after the auto-load routine completes, so this instruction is redundant. Removal of this instruction makes room for our branch instruction. Auto-load routine ----------------- Our auto-load routine uses unused space starting at offset >3711 (GROM address >9711). There are 239 bytes available here (up to >37FF). The last two bytes (at >37FE) contain a checksum. We don't bother about recalculating this, as nothing in Tunnels of Doom or the console checks it. 3711 07 20 ALL >20 3713 BF 28 61 14 DST >6114,@>8328 3717 83 8F DD 00 DNEG @>6000 3721 35 1F 80 AF 04 00 8F DD 80 MOVE >1F80 FROM @>6080 TO V@>0400 3724 83 8F DD 02 DNEG @>6002 3728 35 13 80 AF 23 80 8F DD 00 MOVE >1380 FROM @>6000 TO V@>2380 3732 05 61 0D B >610D We start by clearing the screen, as the Tunnels of Doom title screen is still visible. Since loading game data overwrites the character definitions in VDP memory, the title screen would briefly show junk if we kept it visible. The 'DST' instruction to initialise @>8328 is normally done by the load/save screen, but we're skipping that, so must do it here instead. I believe this memory address controls which screen FCTN+9 returns to. In this case, it causes FCTN+9 to return to the load/save screen. The 'DNEG' instructions switch the active ROM bank by performing a fake write to the cartridge ROM. Writes to >6000 activate the first 8 KB of the ROM; writes to >6002 activate the second 8 KB. FinalGROM 99 understands this bank-switching scheme. TI Extended BASIC uses the same technique. Tunnels of Doom save files are simply a dump of VDP memory, so we copy it back to VDP memory. >610D is the GROM address where execution resumes after a normal load, which performs some post-load initialisation then displays the "begin game" menu. Changing the menu title ----------------------- You may wish to change the text shown on the program menu. For titles of up to 17 characters, you can overwrite the "TUNNELS OF DOOM" title at offset >0015 (GROM address >6015). Though this is only 15 characters, the next two bytes do not appear to be used in the game. These two bytes are the first entry in a branch table, but the entry is a duplicate of the one that follows. Only the second entry is actually used. If you change the length of the title, also change the length byte at offset >0014 (GROM address >6014). If you need more than 17 characters, you will need to move the whole menu entry somewhere else. I suggest offset >3780 (GROM address >9780). This is 32 bytes prior to the end of the second GROM, and is all unused space. (You won't need more than 26 bytes.) First, change the pointer at offset >0006 (GROM address >6006) from >6010 to >9780 (this is absolute GROM address for the menu entry). Next, place the following bytes at offset >3780: >00 >00 >60 >36, followed by the length of the menu title (as a single byte) then the title itself. NB: Only use uppercase, as lowercase characters are not defined when the program menu is displayed. I suggest limiting the length to 20 characters, as FinalGROM 99 will truncate longer titles. The original TI program menu allows titles up to 21 characters. Author ====== Both the hack and this documentation were written by George Shaw.