Missingno
From simulation to emulation
A gate-level simulation gave me the data I’d been missing, and the confidence to let Missingno’s accuracy fall before it climbed.
After years of working on Missingno on and off, it had finally become something people were using. In the two months since its first release it had picked up several hundred downloads on Flathub, and each release had improved both what it could do and how accurately it did it. I wasn’t satisfied with its accuracy, though. Game Boy Color support was still waiting on a model I could be confident in, and I felt like I’d reached the limits of what my process could achieve.
I measured accuracy with test ROMs, small programs written by the emulation community that check an emulator’s behaviour against what real hardware does. Missingno was passing 713 of the 779 I’d collected, but the failures that were left were the hard ones: progress had stalled, and investigations had begun to go in circles. I could wait for a better AI model to come along, but that was out of my control. I had the right process, but not the right data, and better data was a lever I could pull myself, one that would compound with higher intelligence whenever it arrived.
Agents can only be as good as their inputs, and mine were scattered. I wanted to work close to the domain, at the level of signals, the ones and zeros passing between the chip’s logic gates, so I could see what was needed to model the hardware accurately and what could be simplified. GateBoy was my primary source for those, a C++ implementation of the chip’s signals that helped me bridge from software to hardware, but it was hard to trace signals through its code. My research receipts were spread across many investigations, and often contradictory in ways that weren’t noticeable until you looked at them together.
To take Missingno’s accuracy to the next level, I needed to go deeper. Until then I hadn’t really understood what a netlist was, let alone that one could be simulated. Furrtek had traced schematics of the Game Boy’s chip from photographs of its silicon, and Michael Singer and Regis Galland turned those into dmg-schematics, a corrected netlist listing every gate on the chip and how they’re wired together. Singer then generated dmg-sim from it, a program that simulates the chip on an ordinary computer, gate by gate, and records every signal as it changes while a test ROM runs.
I started with it in mid-April. Instead of reading static code and tracing signals through it in its head, the agent could run a test ROM through dmg-sim and watch the chip in motion, looking up exactly what each signal did, and when. One of the first things it measured was when the chip starts drawing each line. The answer came down to a chain of four gates that delays the start of the sprite search before each line, and Missingno modelled that delay in a single change, fixing 48 tests and breaking 30 others.
| Time | Signal | Becomes |
|---|---|---|
| 5.23 µs | Starts drawing | high |
| 5.23 µs | Drawing the line | high |
| 5.35 µs | Starts drawing | low |
| 46.4 µs | Finished drawing | high |
| 46.4 µs | Interrupt request | high |
| 46.4 µs | Interrupt flag | high |
| 46.5 µs | Drawing the line | low |
| 50.6 µs | Interrupt flag | low |
| 94.0 µs | Scanline | 1 |
| 94.2 µs | Finished drawing | low |
| 94.3 µs | Interrupt request | low |
| 113.3 µs | Starts drawing | high |
| 113.3 µs | Drawing the line | high |
| 113.4 µs | Starts drawing | low |
| 154.5 µs | Finished drawing | high |
| 154.5 µs | Interrupt request | high |
| 154.5 µs | Interrupt flag | high |
| 154.6 µs | Drawing the line | low |
| 202.5 µs | Scanline | 2 |
| 202.8 µs | Finished drawing | low |
| 202.8 µs | Interrupt request | low |
After those first results, two things were clear to me. The first was that this was the source I needed to push Missingno past its accuracy plateau, and I was thrilled to finally see a path forward. The second was that I needed to be prepared for things to get worse before they got better, possibly a lot worse. Many of Missingno’s passes relied on compensating errors, mistakes that held each other in balance, so fixing one shifted the weight and could tip over tests that had been passing. The more detailed the model got, the more places there were for timing to matter, too. The prospect gave me some trepidation, but I was confident enough in the data to take the plunge.
Rather than building on the notes I already had, I started a new set in their own repository, so the agent wouldn’t come to dmg-sim loaded with preconceptions it would then need to prove wrong. Its first brief told it not to read Missingno’s graphics code or my earlier research at all. Everything we learnt from the simulation went into one place, as a single description of how the chip’s timing worked, and each new run broadened it.
I had to change what success looked like, too. I accepted regressions when I was confident that’s where the data was pointing, and I tried to fix signals earlier in the pipeline first, pushing the errors later and later, though it’s never quite that simple. Missingno fell from 713 passing tests to 506 in less than a week. Pokémon Red broke at the end of the month, and I missed my usual first-weekend-of-the-month release for Missingno 26.5 because real games were glitching.
| Date | Passing | Failing | Share | Event |
|---|---|---|---|---|
| 1 April | 595 | 184 | 76.4% | |
| 2 April | 667 | 112 | 85.6% | |
| 3 April | 667 | 112 | 85.6% | |
| 4 April | 668 | 111 | 85.8% | |
| 5 April | 675 | 104 | 86.6% | |
| 6 April | 689 | 90 | 88.4% | |
| 7 April | 691 | 88 | 88.7% | |
| 8 April | 707 | 72 | 90.8% | |
| 9 April | 707 | 72 | 90.8% | |
| 11 April | 707 | 72 | 90.8% | |
| 14 April | 713 | 66 | 91.5% | |
| 15 April | 713 | 66 | 91.5% | First dmg-sim run |
| 16 April | 713 | 66 | 91.5% | |
| 17 April | 627 | 152 | 80.5% | |
| 18 April | 627 | 152 | 80.5% | |
| 19 April | 628 | 151 | 80.6% | |
| 20 April | 627 | 152 | 80.5% | |
| 21 April | 506 | 273 | 65.0% | |
| 22 April | 506 | 273 | 65.0% | |
| 23 April | 517 | 262 | 66.4% | |
| 24 April | 573 | 206 | 73.6% | |
| 25 April | 560 | 219 | 71.9% | |
| 26 April | 570 | 209 | 73.2% | |
| 27 April | 615 | 164 | 78.9% | |
| 28 April | 576 | 203 | 73.9% | |
| 29 April | 571 | 208 | 73.3% | |
| 30 April | 581 | 197 | 74.7% | |
| 1 May | 591 | 187 | 76.0% | |
| 2 May | 560 | 218 | 72.0% | |
| 3 May | 637 | 141 | 81.9% | |
| 4 May | 637 | 141 | 81.9% | |
| 5 May | 682 | 96 | 87.7% | |
| 6 May | 695 | 83 | 89.3% | |
| 7 May | 701 | 77 | 90.1% | |
| 9 May | 720 | 59 | 92.4% | |
| 10 May | 721 | 58 | 92.6% | |
| 11 May | 738 | 41 | 94.7% | |
| 12 May | 749 | 30 | 96.1% | |
| 13 May | 752 | 27 | 96.5% | |
| 14 May | 756 | 23 | 97.0% | |
| 15 May | 760 | 19 | 97.6% | |
| 16 May | 768 | 11 | 98.6% | |
| 17 May | 773 | 1 | 99.87% | |
| 19 May | 774 | 0 | 100% |
Once we got past the bottom and started working our way back out, things began to fall into place. Each simulation brought new data that fitted with what had come before, and each fix agreed with and built on the ones before it. When the agent investigating a failure reached something we hadn’t measured yet, it wrote up a request naming the signals and test ROM it needed, and I passed that to a second agent, which ran dmg-sim, analysed the results and added them to the notes so the first could carry on. The test ROMs decided whether a fix was right, or whether we needed more data.
By the middle of May, Missingno was passing all but a handful of tests, and those were ones where dmg-sim and the tests disagreed, so I’d set them aside until I could get data from real hardware. The Game Boy I’d ordered was still somewhere in the post, so an emudev community member ran them on theirs. In one, the hardware passed the test, so it really was a fraction of a microsecond faster than the simulation. In another, a real Game Boy agreed with dmg-sim rather than with the value the test expected.
With those results in, Missingno passed every test it ran for the first time, though only with a rule fitted to the test the hardware had passed. By the next morning, that rule had been replaced with a fix to how the signals actually cascade. I also had to decide where to stop. A few behaviours seem to come from the screen rather than the chip, so dmg-sim can’t produce them. With the model underneath already very accurate, I was prepared to handle those with small rules fitted to the tests, since nothing else would build upon them. A handful of other tests I set aside altogether, where the right answer seemed to depend on the individual console or wasn’t clear.
There was one more wave to come. I’d only imported part of Gambatte’s test suite, because I’d assumed its .gbc ROMs were for the Game Boy Color only, when many of them check the original Game Boy too. Missingno passed 91% of them straight away, and by early June I’d fixed the remaining issues and it was passing every test it ran. Today it passes 2,514, with six set aside.
The notes from all those simulations had grown into a detailed description of the chip’s timing, with every claim tied to a named gate in the netlist. I’d built on a lot of other people’s work to get there, from Furrtek’s tracing to dmg-sim itself, and I wanted to give something back, so in June I published it as the DMG Timing Specification. Turning my working notes into something more broadly useful was a challenge, and I’m still not completely satisfied with the result, but I think it’s a useful resource, especially for pointing an agent at.
It had been a long road, but I was finally satisfied with Missingno’s accuracy. I’d never really planned for it to be quite that accurate, but I’m not one to stop while I can still see a way forward. Now I was ready to take on the Game Boy Color, which would be a different kind of challenge.