<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/rss.xml.xsl" type="text/xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>iammatthias — #emulator</title><description>Entries tagged emulator.</description><link>https://iammatthias.com/</link><language>en-us</language><item><title>GBCformer</title><link>https://iammatthias.com/experiments/1793399415000-gbcformer/</link><guid isPermaLink="true">https://iammatthias.com/experiments/1793399415000-gbcformer/</guid><description>A Game Boy Color compiled into Llama weights</description><pubDate>Fri, 27 Nov 2026 22:15:36 GMT</pubDate><content:encoded>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;&lt;video controls preload=&quot;none&quot; playsinline aria-label=&quot;Pokémon Yellow&apos;s intro, every frame computed by the model&quot; src=&quot;https://blobs.farfield.systems/blobs/bafkreiglmftlgbjiey6y6s6lbhcdgby7litgmnhgkwyfm5at4kgfldg66e&quot;&gt;&lt;a href=&quot;https://blobs.farfield.systems/blobs/bafkreiglmftlgbjiey6y6s6lbhcdgby7litgmnhgkwyfm5at4kgfldg66e&quot;&gt;Watch the video&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;&lt;p&gt;The idea was loosely inspired by &lt;a href=&quot;https://github.com/dbreunig/nesformer&quot;&gt;NESFormer&lt;/a&gt;, which compiles an NES&amp;#39;s CPU into a Qwen3.5 model. It stores the CPU, the NES&amp;#39;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&amp;#39;s execution log one token at a time.&lt;/p&gt;
&lt;p&gt;GBCformer is a bit different:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It uses Llama instead of Qwen&lt;/li&gt;
&lt;li&gt;The GBC CPU, memory, graphics, sound and control logic are in the model, including the timer, interrupts and DMA&lt;/li&gt;
&lt;li&gt;Memory lives in attention&amp;#39;s cache&lt;/li&gt;
&lt;li&gt;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&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It shares no code with NESFormer, and is on GitHub: &lt;a href=&quot;https://github.com/iammatthias/GBCformer&quot;&gt;iammatthias/GBCformer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Nothing 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.&lt;/p&gt;
&lt;p&gt;Memory is the KV cache. The cartridge ROM, the RAM and video memory all sit in attention&amp;#39;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.&lt;/p&gt;
&lt;p&gt;Each 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&amp;#39;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.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://wsrv.nl/?url=https%3A%2F%2Fblobs.farfield.systems%2Fblobs%2Fbafkreic4rewxaynqzqsiphhxkjxpwkgo6qr7rclvharxbz5zgmnr6x2ypy&amp;amp;w=960&amp;amp;q=80&amp;amp;output=webp&quot; alt=&quot;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.&quot; /&gt;&lt;/p&gt;&lt;p&gt;To 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&amp;#39;s column decoder. Line timing runs on a fixed schedule. The sound chip&amp;#39;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.&lt;/p&gt;
&lt;p&gt;The 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.&lt;/p&gt;
&lt;p&gt;It 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 &lt;a href=&quot;https://github.com/SingleStepTests/sm83&quot;&gt;SingleStepTests&lt;/a&gt; cases for the CPU and all 321 hardware tests in the project&amp;#39;s test set, which pulls from mooneye, SameSuite, Mealybug, blargg, acid2 and daid.&lt;/p&gt;
&lt;p&gt;&lt;video controls preload=&quot;none&quot; playsinline aria-label=&quot;The color run from the boot hand-off to Oak, every frame from the model in lockstep, with the sound model&apos;s audio&quot; src=&quot;https://blobs.farfield.systems/blobs/bafkreihhr4fwpktcljtdnjomlrchyiwy5jv4zn7m5ur7womcrgaliqyomu&quot;&gt;&lt;a href=&quot;https://blobs.farfield.systems/blobs/bafkreihhr4fwpktcljtdnjomlrchyiwy5jv4zn7m5ur7womcrgaliqyomu&quot;&gt;Watch the video&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;&lt;p&gt;It isn&amp;#39;t tied to Yellow. Link&amp;#39;s Awakening DX, Crystal and Mario DX each run their first 300 frames with every frame matching too.&lt;/p&gt;
&lt;p&gt;&lt;video controls preload=&quot;none&quot; playsinline aria-label=&quot;Link&apos;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&quot; src=&quot;https://blobs.farfield.systems/blobs/bafkreibzy4lbb7n2rhkmes4qoq62kzyknhjaojxyz2lyane7ta4hfw6giu&quot;&gt;&lt;a href=&quot;https://blobs.farfield.systems/blobs/bafkreibzy4lbb7n2rhkmes4qoq62kzyknhjaojxyz2lyane7ta4hfw6giu&quot;&gt;Watch the video&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;&lt;p&gt;Since it&amp;#39;s a plain Llama model, llama.cpp can run it. Unpatched llama.cpp, on my M1 Max&amp;#39;s GPU, ran Pokémon Yellow from the boot hand-off to frame 300. That&amp;#39;s about 1.37 million passes, and every one matched my own engine. It took about 15 and a half hours.&lt;/p&gt;
&lt;p&gt;So llama.cpp proves the point. It&amp;#39;s not how you&amp;#39;d want to play it.&lt;/p&gt;
&lt;p&gt;The 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.&lt;/p&gt;
&lt;p&gt;On the M1 Max, Yellow&amp;#39;s text boxes, the slowest scene I&amp;#39;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.&lt;/p&gt;
&lt;h2&gt;Playing further&lt;/h2&gt;
&lt;p&gt;The 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&amp;#39;s 503,652 frames, about 2 hours 20 minutes of game time.&lt;/p&gt;
&lt;p&gt;Every one of those frames came out of the model in the project&amp;#39;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.&lt;/p&gt;
&lt;p&gt;The sound is the model&amp;#39;s own. It boots from an open-source boot ROM, so you&amp;#39;d see the SameBoy logo at power-on instead of Nintendo&amp;#39;s.&lt;/p&gt;
&lt;p&gt;&lt;video controls preload=&quot;none&quot; playsinline aria-label=&quot;Pokémon Yellow from power-on to the S.S. Anne, in 13 cuts&quot; src=&quot;https://blobs.farfield.systems/blobs/bafkreicyrnri53p5gip6eqr6ovjbjrwaxr5s5p7c3hivcsfmcv35njzfby&quot;&gt;&lt;a href=&quot;https://blobs.farfield.systems/blobs/bafkreicyrnri53p5gip6eqr6ovjbjrwaxr5s5p7c3hivcsfmcv35njzfby&quot;&gt;Watch the video&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;&lt;p&gt;The 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.&lt;/p&gt;
&lt;p&gt;&lt;video controls preload=&quot;none&quot; playsinline aria-label=&quot;Route 1, with Pikachu following&quot; src=&quot;https://blobs.farfield.systems/blobs/bafkreicl5vho7ejwq3a36qn2flho6blkixoicdavswsm4wuil7pz3lhgye&quot;&gt;&lt;a href=&quot;https://blobs.farfield.systems/blobs/bafkreicl5vho7ejwq3a36qn2flho6blkixoicdavswsm4wuil7pz3lhgye&quot;&gt;Watch the video&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;&lt;p&gt;Then Mt. Moon. The Helix Fossil is in there, and so are Jessie and James.&lt;/p&gt;
&lt;p&gt;Past Mt. Moon is Cerulean City. The rival shows up again, then Nugget Bridge, then Bill and his cell separator. Misty is the second badge.&lt;/p&gt;
&lt;p&gt;From there it&amp;#39;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.&lt;/p&gt;
&lt;h2&gt;What it isn&amp;#39;t&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;It isn&amp;#39;t a perfect Game Boy Color. There are known gaps against real hardware, and they&amp;#39;re listed in the repo&lt;/li&gt;
&lt;li&gt;The llama.cpp run covers 300 frames from the boot hand-off, not a full game&lt;/li&gt;
&lt;li&gt;In llama.cpp, each pass runs every weight but only looks at the memory cells picked for it, not the whole cache&lt;/li&gt;
&lt;li&gt;The full llama.cpp run has only been on a Mac&amp;#39;s GPU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The test set, the limits, and what runs where are all in the repo: &lt;a href=&quot;https://github.com/iammatthias/GBCformer&quot;&gt;iammatthias/GBCformer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://iammatthias.com/experiments/1793399415000-gbcformer&quot;&gt;View the full gallery (5 more) →&lt;/a&gt;&lt;/p&gt;</content:encoded><media:content url="https://wsrv.nl/?url=https%3A%2F%2Fblobs.farfield.systems%2Fblobs%2Fbafkreic4rewxaynqzqsiphhxkjxpwkgo6qr7rclvharxbz5zgmnr6x2ypy&amp;w=960&amp;q=80&amp;output=webp" medium="image"/><category>Experiments</category><category>gbcformer</category><category>game-boy</category><category>llama</category><category>emulator</category><category>ai</category></item></channel></rss>