There’s a particular thrill in opening up a program you didn’t write and asking it, politely but firmly, how it works. In one long working session I did exactly that to a Commodore 64 game called Fire Ant — 17 KB of machine code on a floppy-disk image — with Claude, Anthropic’s AI, as my pair-programmer.
By the end we had infinite lives, a native level editor that patches the disk image directly, my name on the title screen and in the victory message, and a cheat mode you toggle with a single keypress: the border turns red, the word CHEAT appears, and you can walk through walls. We also made a satisfying number of mistakes. This post is the whole story, mistakes included, because that’s where most of the learning was.
A note before we start: this was a purely educational exercise on a disk image I already had. I’m not sharing the game or my patched disks, and everything below is about how it works. The game itself is the work of its author, Mike Wacker — his name is on the original title screen — and all credit for it is his.
1. The patient: a .d64 disk image
A .d64 file is a byte-for-byte copy of a Commodore 1541 floppy disk: 35 tracks, 683 sectors of 256 bytes each, 174,848 bytes in total. The outer tracks are physically longer, so they hold more sectors:
| Tracks | Sectors per track | Total sectors |
|---|---|---|
| 1–17 | 21 | 357 |
| 18–24 | 19 | 133 |
| 25–30 | 18 | 108 |
| 31–35 | 17 | 85 |
Track 18 is special. Sector 18/0 holds the BAM (block availability map: one bit per sector saying whether it’s free) and sector 18/1 begins the directory. A file is a linked list: the first two bytes of every sector point at the next sector’s track and sector number, and in the final sector the “next track” is 0 while the second byte says how many bytes of that sector are in use. That leaves 254 bytes of payload per sector.
Our disk contains a single file, FIRE ANT: a program of 68 blocks, or 17,130 bytes, the first two of which are the load address $0801. That leaves 17,128 bytes of code and data to understand. Remember this consequence, because I tripped over it more than once: file offset = 2 + (address − $0801).
2. A disassembler, and why they lie
The 6502’s instructions are one, two or three bytes long, so you can’t simply decode a file from the top and trust the output. I wrote a small disassembler in Python (an opcode table and a loop), and the first lesson arrived almost immediately: code and data are interleaved. Point a disassembler at a level map or a font and it will cheerfully produce a plausible-looking stream of LDA, STA and JMP out of what is really just a picture.
The only reliable method is to start from known entry points, follow every JSR, JMP and branch, and treat everything else as data until proven otherwise. With that discipline we got a full listing; the rest of the project was detective work — find an interesting memory location, then find everything that reads or writes it.
3. Infinite lives in three bytes
The classic signature of a lives counter is a memory location being decremented, followed by a branch if the result went negative. Searching the listing turned up exactly that:
; before
$4138 CE 1C C0 DEC $C01C ; lives = lives - 1
$413B 30 03 BMI $4140 ; went negative? -> game over
; after
$4138 EA EA EA NOP NOP NOP ; lives never change
Replace the three-byte DEC with three NOPs (opcode $EA, “do nothing”) and the counter simply never goes down, so the game-over branch can never fire. Three bytes, one disk sector rewritten, and the next boot of the image in an emulator had a very forgiving ant. That is the heart of this hobby: the smallest possible edit, found by understanding rather than guessing.
4. Where do the levels live? Eight mazes in 920 bytes
Next question: how does the game store its eight “chambers”? The answer is delightfully compact. Each chamber is a 40 × 23 grid and each cell is a single bit: 1 for wall, 0 for empty. Five bytes make a row, 23 rows make 115 bytes, and eight chambers make 920 bytes. Two small tables, at $1D9C and $1DA4, hold the low and high bytes of each chamber’s address.

Don’t take my word for it — flip some bits yourself. This is a live copy of row 7 from chamber 1:
TRY IT: CLICK THE BITS
These five bytes are row 7 of chamber 1, copied from the disk. Flip a bit and watch the wall appear or vanish.
Once you know the format you can decode every chamber. The picture below was rendered straight from the original disk with a few lines of Python — no screenshots involved. Watching mazes appear out of a hex dump was the moment this stopped feeling abstract.

One honest caveat: that’s only “layer 1”, the walls. The keys, hazards, enemies and the order in which things must be collected live in other tables. Decoding those is the next project.
5. From hex dump to level editor
Naturally, once you can read the maps you want to draw them. The first version of my editor was a web page: click cells, export the bytes. It worked, but a web page can’t run a local program or hand you a ready-made .d64, so the export was just a block of text that I then had to feed to a separate patch script by hand. A very practical lesson in sandbox limits.
So version two is a native Python/tkinter app. You paint a chamber, pick a base disk and a new output filename, tick the boxes for custom title text and cheat mode, and press one button: out comes a brand-new .d64 that you can load straight into an emulator. Under the hood a patch is nothing more exotic than “follow the file’s sector chain, change some bytes in memory, write them back”:
def patch_chamber(prg: bytearray, n: int, new_bytes: bytes):
# +2 because the first two bytes of the PRG are the load address
off = CHAMBER_ADDRS[n] - 0x0801 + 2
prg[off:off + 115] = new_bytes

Two design rules paid off. First, patches are idempotent: apply the same patch twice and nothing changes, so the tool can safely start from any disk — including one it has already patched. Second, every write is read back and compared against what was intended, which is how several of my own mistakes got caught before they reached the emulator.
6. Cracking the font: my name on the title screen
The title screen credits MIKE WACKER, and I wanted to see my own name on my private copy. The text isn’t ASCII or standard PETSCII: the game ships its own character set, so the letter A is byte $3C, B is $3D, and so on, with space as $00. Encoding “MIKE WACKER” by that rule reproduces the bytes in the file exactly, which is how I knew I had the cipher right.

There was a catch. The original credit is exactly 11 bytes and a loop prints it; “PETER MAYHEW” is 12. The fix is a trick I used twice: relocate and widen. Find a run of unused $FF bytes (there were 16 at $2040 and 48 at $46D0), write the new text there, then patch the length and the pointer in the routine that prints it. For the title credit that meant changing an LDX count at $48FA and the operand of the LDA at $48FD so the loop reads from the new slot.
The same trick replaced the end-of-game message with “CONGRATULATIONS PETER MAYHEW!” — a 32-byte buffer at $46D0, with the game’s own typewriter effect left intact. Here’s a re-creation of how it types out:

To be clear, the swap lives only on my personal copy as a bit of fun; the game remains Mike Wacker’s.
7. Walking through walls (and my first wrong answer)
Next request: make the ant invincible, and let it walk through walls to the exit. Invincibility looked easy. At nine places the game detects a collision and jumps into the death handler at $4097; replace each with NOPs and nothing can hurt the ant. (The C64’s VIC-II chip flags sprite collisions in a hardware register at $D01E, which is part of why this kind of check is so easy to find.)
Walls were different, and this is where I have to confess a wrong turn. My first analysis — Claude’s, to be precise — confidently concluded that the player’s movement was unconditional, i.e. that the game never checks the maze before moving. I loaded the “noclip” disk and… walls still blocked me. Back to the listing. Movement is in fact gated by four small scan routines, at $0EF1, $0F21, $0F3B and $0F69, which look at the maze cells in each direction and answer “blocked” or “clear”. Patching them to always answer “clear” — the simplest becomes A9 00 60, i.e. LDA #$00 / RTS — finally let the ant stroll through the maze.
Lesson: a confident explanation is not a verified one. The test that mattered was a human pressing keys in an emulator.
8. The cheat key: 274 bytes of brand-new code
The most ambitious request was a cheat mode you can toggle during play: press C and the border turns red, the word CHEAT appears, and walls and enemies stop mattering; press C again and everything returns to normal. That needs new code, and the game has nowhere to put it. The design came down to four questions:
- Where does the code live? Appended to the end of the program, at
$4AE9— the very next byte after the original 17,130. - How does it get called? One
JSRin the game’s main loop (at$46B3) calls the routine at$3E15. I changed that instruction’s two-byte operand to point at a tiny trampoline at$4BF4, which does the original job, then runs our key check, then returns. Two bytes changed in the original game; everything else is new. - How does it read the keyboard? Zero-page location
$C5holds the matrix code of the key currently held down. The letter C is$14. - How does it switch walls and death on and off? It writes the patch bytes into the running game’s code (self-modifying code, driven by a table) and puts the original bytes back when you toggle off.
toggle_check: ; $4BDA
LDA $C5 ; which key is down right now?
CMP $4AEA ; same as last frame?
STA $4AEA ; remember it (STA doesn't touch the flags)
BEQ done ; unchanged or still held: ignore
CMP #$14 ; is it 'C'?
BNE done
LDA $4AE9 ; flip the cheat flag
EOR #$01
STA $4AE9
JSR $4B26 ; apply_cheat_state: patch the game live
done:
RTS
I couldn’t find an assembler that suited, so I built one by inverting the disassembler’s opcode table: the disassembler maps byte to mnemonic and addressing mode, the assembler maps them back. The safety net was a round-trip test — assemble the source, disassemble the bytes, and compare. 274 bytes later we had a cheat block.
Then came a problem I hadn’t expected. The original file ended partway through a sector, and 274 extra bytes spill into a new one. So the patcher also has to behave like a tiny disk operating system: find a free sector in the BAM, mark it used, link the old last sector to it, fix the used-byte count, and bump the directory’s block count from 68 to 69. Here’s the result on the disk map — the red sector is the new one:

And here’s every place we touched in the program, from the walls to the lives counter to the new block on the end:

And this is the payoff, as an animation: with cheat mode off the ant bumps into a wall and loses a life; press C and the border flips to red, CHEAT lights up, and the ant glides through to the exit. (It’s an illustration drawn from the real chamber data, not emulator footage.)

9. The bugs only an emulator could find
By now I’d verified everything I could statically: the assembler round-trips, the patched file matches the expected bytes, the hook points at the right address. It still had two bugs, and neither could have been found by staring at bytes.
To find them I ran the game in the VICE emulator with its remote monitor (x64sc -remotemonitor), a text interface that lets you stop the machine, step instructions, and read or write memory and registers. The tool had opinions — every new connection re-pauses the CPU, and the g command wouldn’t free-run — so I ended up driving it with deterministic step N commands and reading memory directly.
Bug 1: the clobbered register
My poke routine used the X register as its loop counter. But the game was still relying on X when our hook returned. After the toggle, X held our leftover counter value, and the game quietly carried on with corrupted state. The fix was one letter—use Y instead—but nothing in a listing screams “you broke somebody else’s register”. (The values in this animation are illustrative.)

Bug 2: the off-by-two
The table of “you died” trigger addresses was two bytes out, so the cheat was patching the middle of instructions instead of their starts. Subtracting 2 from every entry fixed it. It was, once again, the load-address header: the same family of bug that bit me in the free-space scan, in the hook offsets and in the sector search. Four times in one project is a pattern.
After both fixes I drove the cheat-apply routine directly in the emulator and confirmed the memory changed exactly as designed. In the interest of honesty: the toggle logic and both fixes were verified by stepping the code and reading memory back; a long, hands-on session with the C key on a real keyboard is still next on my list.
What I learned
- Disassemblers lie about data. Follow the control flow from known entry points; everything else is a picture until proven otherwise.
- The smallest edit wins. Infinite lives was three
NOPs, found by understanding what a lives counter looks like. - Mind the header. Off-by-two errors from the two-byte load address bit me at least four times. Write the offset formula on the wall.
- Static checking isn’t enough. Register clobbering and runtime state only show up in a real emulator. Test where it runs.
- Make patches idempotent and verify by reading back. It makes tools safe to re-run and bugs obvious.
- Build small tools. A disassembler, an assembler (with round-trip tests), a disk-image patcher and an editor each took an hour and paid for themselves many times over.
- An AI pair-programmer is fast, tireless and fallible. Claude was superb at the bookkeeping — sector chains, BAM updates, opcode tables, tooling — and confidently wrong about the wall logic. What closed the loop was a human testing the result.
- Know your sandbox. A web page can’t run local programs or hand you arbitrary file types, so the right tool was a native app.
- Constraints are creative. Hiding a longer name in 16 spare bytes is oddly satisfying.
What’s next
- Decode the other layers: keys, hazards, enemies and the pickup order that each chamber demands.
- Support more than eight chambers, so the editor can add levels rather than just replace them.
- More options for the patcher: starting lives, colours, muting the music.
- A proper long play-test of cheat mode with a real keyboard.
The tools only patch a disk image you supply, and I’m not distributing the game or any modified disks. If you want to try something similar, start with a legal copy of a game you love, a hex editor, an emulator such as VICE, and plenty of patience.
Credits and tools
Fire Ant is by Mike Wacker. Tools: Python 3 (tkinter for the editor, Pillow for the images on this page), the VICE emulator and its remote monitor, CCS64 for early screenshots, and Claude Code for the pair-programming. Every picture here was generated from the game’s own data; the animations are illustrative re-creations, not emulator captures.
Got your own retro rabbit hole? I’d love to hear about it in the comments.


