{"kind":"doc","doc":{"title":"GBCformer","section":{"slug":"experiments","name":"Experiments"},"rkey":"1793399415000-gbcformer","cid":"bafkreiavfpu4t4v7jzea3en63zin6jankvflcua73xy7r4wke4nlcwlc6e","renderKey":"bafkreiavfpu4t4v7jzea3en63zin6jankvflcua73xy7r4wke4nlcwlc6e@2026-11-27T22:15:36Z@2026-11-27T22:15:36Z@Experiments|Open source projects and experiments","href":"/experiments/1793399415000-gbcformer","publishedAt":"2026-11-27T22:15:36Z","updatedAt":"2026-11-27T22:15:36Z","tags":["gbcformer","game-boy","llama","emulator","ai"],"description":"A Game Boy Color compiled into Llama weights","readingMinutes":5,"markdown":"GBCformer is an experimental Game Boy Color emulator compiled to Llama weights. The whole GBC, its CPU, memory, graphics, audio and control logic, runs in one Llama checkpoint. The host loads the ROM, supplies the buttons and the elapsed time, runs the inference, shows the picture, plays the sound and saves.\n\n![Pokémon Yellow's intro, every frame computed by the model](blob://bafkreiglmftlgbjiey6y6s6lbhcdgby7litgmnhgkwyfm5at4kgfldg66e)\n\nThe idea was loosely inspired by [NESFormer](https://github.com/dbreunig/nesformer), which compiles an NES's CPU into a Qwen3.5 model. It stores the CPU, the NES's 2 KB of RAM and the cartridge ROM inside the model, leaves graphics to the host and has no sound. It plays games by predicting the CPU's execution log one token at a time.\n\nGBCformer is a bit different:\n\n- It uses Llama instead of Qwen\n- The GBC CPU, memory, graphics, sound and control logic are in the model, including the timer, interrupts and DMA\n- Memory lives in attention's cache\n- The model works out a GBC CPU step in one pass instead of writing tokens one at a time. Steps that read an I/O register take a second\n\nIt shares no code with NESFormer, and is on GitHub: [iammatthias/GBCformer](https://github.com/iammatthias/GBCformer).\n\nNothing in the model is trained. A compiler writes every weight, so it behaves exactly the way it was written. The whole thing is one Llama checkpoint, about 1.5 GB.\n\nMemory is the KV cache. The cartridge ROM, the RAM and video memory all sit in attention's cache, one cell per 8-byte line, and reading memory is attention picking out the right cell. A write adds a new cell that replaces the old one.\n\nEach part of the Game Boy Color is its own circuit inside that one model: the CPU, graphics, sound, and the control logic (timer, interrupts, joypad, DMA and the screen's line timing). They share the same weights and run side by side as separate streams, the way a model server runs a few conversations at once.\n\n![The GBC CPU, memory, graphics, sound and control all run inside one Llama model, and the host program shows the picture, plays the sound, reads the buttons and keeps time.](blob://bafkreic4rewxaynqzqsiphhxkjxpwkgo6qr7rclvharxbz5zgmnr6x2ypy)\n\nTo shrink the model and speed it up, I borrowed from how Nintendo built the real thing. The cartridge bank gets worked out once per pass, like the mapper chip on the cartridge. Attention pulls each byte straight out of its memory line, like a RAM's column decoder. Line timing runs on a fixed schedule. The sound chip's high-pass filter is a capacitor on the real hardware, so it moved out of the model and onto the host with the rest of the output.\n\nThe hard part is keeping it exact. Floating point rounds, and one rounding error is enough to throw an emulator off. So the compiler only uses numbers that f16 holds exactly. Every weight is a small integer times a power of two, and every value inside the model stays an exact integer.\n\nIt can run in lockstep with a reference emulator, which checks every step and stops at the first difference. Every test here ran that way. That only shows the model matches my emulator, so for real hardware there are test ROMs. It passes all 500,000 [SingleStepTests](https://github.com/SingleStepTests/sm83) cases for the CPU and all 321 hardware tests in the project's test set, which pulls from mooneye, SameSuite, Mealybug, blargg, acid2 and daid.\n\n![The color run from the boot hand-off to Oak, every frame from the model in lockstep, with the sound model's audio](blob://bafkreihhr4fwpktcljtdnjomlrchyiwy5jv4zn7m5ur7womcrgaliqyomu)\n\nIt isn't tied to Yellow. Link's Awakening DX, Crystal and Mario DX each run their first 300 frames with every frame matching too.\n\n![Link's Awakening DX, Crystal and Mario DX side by side, 300 frames each from the boot hand-off, every part in weights as one model, in lockstep](blob://bafkreibzy4lbb7n2rhkmes4qoq62kzyknhjaojxyz2lyane7ta4hfw6giu)\n\nSince it's a plain Llama model, llama.cpp can run it. Unpatched llama.cpp, on my M1 Max's GPU, ran Pokémon Yellow from the boot hand-off to frame 300. That's about 1.37 million passes, and every one matched my own engine. It took about 15 and a half hours.\n\nSo llama.cpp proves the point. It's not how you'd want to play it.\n\nThe project has its own runner for that. It has no Game Boy logic in it. It loads the ROM, feeds in the buttons and the time, runs the model, and shows the picture and plays the sound. It knows the model only does integer math, and that one instruction to the next barely changes the input, so it only recomputes the parts of the network that changed.\n\nOn the M1 Max, Yellow's text boxes, the slowest scene I've timed, run at a bit over 60 fps, and walking around the overworld is about 130. A real Game Boy Color draws 59.7 frames a second.\n\n## Playing further\n\nThe intro is one thing. A real game is another, so I ran a recorded input log of Yellow through it. It starts at power-on with a new game and ends on the S.S. Anne, with HM01 and two badges. That's 503,652 frames, about 2 hours 20 minutes of game time.\n\nEvery one of those frames came out of the model in the project's runner, faster than the real thing. Then my reference emulator played the same presses, and every frame and every sound sample matched. Two hours of game and not one frame off.\n\nThe sound is the model's own. It boots from an open-source boot ROM, so you'd see the SameBoy logo at power-on instead of Nintendo's.\n\n![Pokémon Yellow from power-on to the S.S. Anne, in 13 cuts](blob://bafkreicyrnri53p5gip6eqr6ovjbjrwaxr5s5p7c3hivcsfmcv35njzfby)\n\nThe early game is mostly walking and talking. Pikachu follows you out of Pallet Town and up Route 1, and Brock is the first badge in Pewter.\n\n![Route 1, with Pikachu following](blob://bafkreicl5vho7ejwq3a36qn2flho6blkixoicdavswsm4wuil7pz3lhgye)\n\n![Brock defeated, and the first badge](blob://bafkreials4kpprftf7bcbmjlol7fitzjildvvbybn6lxjfeq6fl5bjyrp4)\n\nThen Mt. Moon. The Helix Fossil is in there, and so are Jessie and James.\n\n![Jessie and James appear](blob://bafkreibmi4szgvb6impl73embad467gg6nrlancorirn6s2u6ci2yk3f3y)\n\nPast Mt. Moon is Cerulean City. The rival shows up again, then Nugget Bridge, then Bill and his cell separator. Misty is the second badge.\n\n![Nugget Bridge](blob://bafkreihh6jlfqeh3c6euncohm62ky6me6jnhyvnwbxsgamxqiheodpvjle)\n\n![Misty defeated, and the second badge](blob://bafkreibppwty4wvwbpwsl2q5jdrx7nhy3gqr6zh4zzb7aozo6ksdhieeum)\n\nFrom there it's the underground path down to Vermilion and onto the S.S. Anne. The rival turns up one more time on the ship, and the captain hands over HM01.\n\n![HM01 from the S.S. Anne's captain](blob://bafkreid2h2dgv3q4aun5ogdfa3uk6er7zlqfnptnao36mjeimbpgqtiylq)\n\n## What it isn't\n\n- It isn't a perfect Game Boy Color. There are known gaps against real hardware, and they're listed in the repo\n- The llama.cpp run covers 300 frames from the boot hand-off, not a full game\n- In llama.cpp, each pass runs every weight but only looks at the memory cells picked for it, not the whole cache\n- The full llama.cpp run has only been on a Mac's GPU\n\nThe test set, the limits, and what runs where are all in the repo: [iammatthias/GBCformer](https://github.com/iammatthias/GBCformer).\n","media":{"bafkreiglmftlgbjiey6y6s6lbhcdgby7litgmnhgkwyfm5at4kgfldg66e":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreic4rewxaynqzqsiphhxkjxpwkgo6qr7rclvharxbz5zgmnr6x2ypy":{"mime":"image/png","width":1600,"height":800,"dominantColor":"#f0f4f6","blurhash":"L5SZ2.M{%Mt70MofayfQxuNGV@j[","thumbCid":"bafkreiethiydggdpobghcrsmmxvm7qn7y3lqpjmrejhmvo4jajs7zlmuqu"},"bafkreihhr4fwpktcljtdnjomlrchyiwy5jv4zn7m5ur7womcrgaliqyomu":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreibzy4lbb7n2rhkmes4qoq62kzyknhjaojxyz2lyane7ta4hfw6giu":{"mime":"video/mp4","width":960,"height":288,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreicyrnri53p5gip6eqr6ovjbjrwaxr5s5p7c3hivcsfmcv35njzfby":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreicl5vho7ejwq3a36qn2flho6blkixoicdavswsm4wuil7pz3lhgye":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreials4kpprftf7bcbmjlol7fitzjildvvbybn6lxjfeq6fl5bjyrp4":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreibmi4szgvb6impl73embad467gg6nrlancorirn6s2u6ci2yk3f3y":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreihh6jlfqeh3c6euncohm62ky6me6jnhyvnwbxsgamxqiheodpvjle":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreibppwty4wvwbpwsl2q5jdrx7nhy3gqr6zh4zzb7aozo6ksdhieeum":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null},"bafkreid2h2dgv3q4aun5ogdfa3uk6er7zlqfnptnao36mjeimbpgqtiylq":{"mime":"video/mp4","width":640,"height":576,"dominantColor":null,"blurhash":null,"thumbCid":null}},"series":{},"related":[{"title":"Obsidian Plugins","href":"/experiments/1789490903000-obsidian-plugins","section":"experiments","description":"An overview of three Obsidian plugins the author built: an image uploader that sends embedded images to Pinata and rewrites references as ipfs:// URIs, plus AI-powered generators for note excerpts and tags.","publishedAt":"2026-09-20T05:10:12Z"},{"title":"Phosphene","href":"/art/1781816428977-phosphene","section":"art","description":"A camera that turns each photo into a poem, then paints a new image from those words.","publishedAt":"2026-06-18T21:00:28Z"},{"title":"I Got a Common Turtle","href":"/posts/1775137360175-i-got-a-common-turtle","section":"posts","description":"I got a Common turtle from Claude Code's deterministic buddy system, so I brute-forced the generation algorithm.","publishedAt":"2026-04-02T06:42:00Z"},{"title":"Replacing a Rabbit's Brain: Connecting the R1 to Hermes","href":"/posts/1775069974473-replacing-rabbit-s-brain-connecting-a-rabbit-r1-to-hermes","section":"posts","description":"I replaced the OpenClaw agent on my R1 with Hermes, running locally on a MacBook Pro.","publishedAt":"2026-04-01T11:59:00Z"},{"title":"OpenClaw and the Rabbit R1","href":"/posts/1774911232779-openclaw-and-the-rabbit-r1","section":"posts","description":"I got my Rabbit R1 talking to my Pinata-hosted agent. The agent did most of the work.","publishedAt":"2026-03-30T15:53:00Z"},{"title":"Koios: Memory, Feedback, and Containment","href":"/posts/1768671170751-koios-memory-feedback-and-containment","section":"posts","description":"Autonomous agent with persistent memory inspired by classical theory of mind","publishedAt":"2026-01-17T09:32:00Z"}],"prev":{"title":"Apron","href":"/experiments/1793375787000-apron"},"next":{"title":"UL stack","href":"/experiments/1795914662921-ulstack"}}}