Building a Firmware-Level Graphics Game with an AI Coding Assistant: A Practice Retrospective

    This article reports a two-round experiment in which an AI coding assistant worked in a firmware-level graphics environment: first generating a Chinese Breakout game from scratch, then auditing and repairing an existing Tetris codebase that would not start. It documents the debugging process, including a dangling-pointer issue after display mode setup and an incorrect Graphics Output Protocol (GOP) GUID configuration, and distills practical lessons for collaborating with AI on low-resource, hard-to-debug engineering tasks.

    1. Why Use “Writing a Game in a Firmware Environment” as a Test Scenario

    When evaluating the real capabilities of AI coding assistants, tasks such as web applications and scripting tools no longer create much differentiation—mainstream models are already quite mature at code generation in common business scenarios. What truly tests a model’s value is scenarios with scarce reference material, low fault tolerance, and long feedback loops.

    Firmware-level graphics development satisfies all these conditions:

    • Extremely limited debugging options: there is no operating system and no conventional IDE breakpoint debugging; often the only way to approach a problem is through serial logs.
    • High knowledge density and niche subject matter: it involves graphics output protocols in firmware specifications, GUID matching, frame buffer management, and similar topics. The training corpus is relatively sparse, so a model cannot pass by “memorizing answers.”
    • Ambiguous error feedback: when a program crashes, there is often no error message at all, and the developer must reason together with the AI.

    I therefore designed an experiment: have an AI coding assistant, in a firmware development environment, write a runnable Chinese Breakout game from scratch, and then take over another “half-finished” codebase to complete fixes and optimization.

    2. Experiment Design: Two-Round Test Method

    To make the process controllable and the conclusions reproducible, I split the task into two rounds:

    Round 1: Get the program running. The only goal was for the screen to appear, input to respond, and game logic to advance. This round did not pursue code quality; it pursued only “power-on usability.”

    Round 2: Refinement and optimization. On top of a runnable program, organize the code structure, optimize rendering performance, and handle edge cases.

    The basic elements of the experiment environment included a common firmware development toolchain, a cross-compilation environment, QEMU virtual machine boot simulation, and serial output for log observation. For graphics, the experiment used the Graphics Output Protocol (GOP) from the firmware specification—referred to below as the graphics protocol—to directly operate the frame buffer.

    3. Round 1: Generating a Breakout Game from Scratch

    The result of this round was unexpectedly smooth. The entire development process took about two and a half hours. The program compiled on the first attempt, entered the game loop successfully on its first run, rendered the Chinese interface normally, responded to keyboard input, and completed collision detection.

    Reviewing this collaboration, several key points are worth recording:

    1. Requirements need to be described in a sufficiently “engineering-like” way. I did not simply say “write a Breakout game.” Instead, I explicitly gave constraints: target runtime environment, display resolution, direct frame buffer rendering, key mapping, and serial log switch. The more specific the constraints, the closer the AI-generated code was to a directly compilable state.

    2. Advance module by module rather than generating everything at once. I had the AI output code in the order “entry—graphics initialization—main loop—entity logic—rendering.” After each module was completed, I compiled and verified it before moving to the next. This avoided context drift during long-file generation.

    3. For compilation errors, paste the full error directly. Cross-compilation error messages are often long, but after pasting the complete output to the AI, it almost always located the root cause in one pass.

    4. Round 2: Letting AI Take Over a “Messy” Codebase

    The second round was more interesting. A previous task had left behind a Tetris codebase that could not run—the file structure was regular, with seven source files and clear module division, but it simply could not start in the target environment. I decided to have the AI first perform a code review and then fix the problems.

    Step 1: Code Review

    The instruction was only one sentence: “Review this code and identify problems that may prevent it from running.” The AI checked the entry function, main loop, game logic, rendering module, and input handling one by one. A few minutes later, it produced a list of issues and claimed the program would run after the fixes.

    The actual result was: the program started, printed the game loop startup log, and then exited directly—slightly better than “completely unable to run,” but still a failure.

    Issue 1: Program Crash and Dangling Pointer

    I asked the AI to add finer-grained debug logs and monitor execution progress through serial output. The logs showed that the exception occurred after a graphics protocol call.

    The AI’s analysis was representative: it speculated that the information pointer returned when querying the display mode was a temporary/dangling pointer. After calling the interface to set the display mode, the memory that the pointer originally pointed to had become invalid. Subsequent reads of fields such as resolution and pixel format returned garbage data, causing the initialization logic to exit abnormally.

    The fix was also classic: after completing display mode setup, fetch the frame buffer information again to ensure the pointer still pointed to valid memory. The logic is illustrated below:

    1. // Bad: fetch info first, then set mode; the pointer may become invalid
    2. Gop->QueryMode(Gop, ModeIndex, &InfoSize, &Info);
    3. Gop->SetMode(Gop, ModeIndex);
    4. // At this point, the memory pointed to by Info may have been reclaimed
    5. // Good: fetch again after setting the mode
    6. Gop->SetMode(Gop, ModeIndex);
    7. Gop->QueryMode(Gop, Gop->Mode->Mode, &InfoSize, &Info);
    8. FrameBuffer = (UINT32 *)Gop->Mode->FrameBufferBase;

    After the change, the crash disappeared.

    Issue 2: Incorrect Graphics Protocol GUID Configuration

    The program no longer crashed, but the graphical interface still did not appear. I reported the phenomenon to the AI, and after analyzing the runtime logs, it identified the second issue: the GUID configuration used when obtaining the graphics protocol was incorrect.

    In the firmware specification, there is more than one GUID definition related to graphics output, and the interfaces have different purposes—some are used to locate protocol instances, while others serve auxiliary purposes. With the wrong GUID, the system cannot correctly mount the graphics output protocol, and all subsequent rendering calls naturally fail. The hidden nature of this kind of problem is that the code syntax is completely correct, compilation produces no warnings, and only runtime behavior exposes the anomaly.

    After correcting the GUID, the frame buffer was finally lit up correctly, and the Tetris program ran completely.

    5. Methodology Learned from This Practice

    1. AI’s Real Level in Niche Domains

    This experiment shows that for domains with sparse corpus, such as firmware-level development, large models are not limited to “repeating common code found online.” They possess genuine reasoning ability—starting from vague runtime phenomena and combining log clues, they can infer deep issues such as dangling pointer lifetime and GUID misconfiguration. Of course, their output is not perfect. “One-pass” success depends more on proper task splitting and a timely feedback loop.

    2. The Right Way to Debug with AI

    • Keep the feedback loop short: verify only one hypothesis at a time, and immediately return the result (logs, phenomena) to the AI rather than accumulating a pile of questions.
    • Logs are the strongest communication medium: in an environment where breakpoint debugging is unavailable, serial logs are the “shared debugger” between you and the AI.
    • Let AI review before acting: for unfamiliar legacy code, a systematic review first is much more efficient than directly asking it to “fix it.”
    • Stay skeptical: when the AI claims “it will run after the change,” that is not necessarily accurate. There is a gap between its expression of confidence and its actual success rate, so actual runtime results must prevail.

    3. General Implications for Evaluating AI Coding Capability

    • Only same-task comparisons are persuasive: different models doing different tasks produce results that are not comparable. For horizontal comparison, task variables should be controlled consistently.
    • Scenario difficulty should be layered: from “can write business code” to “can debug low-level defects in a constrained environment,” the capability levels differ greatly. When selecting a model, test it against your own scenarios.
    • Engineering scaffolding affects results more than the model itself: task splitting, context organization, and verification rhythm—these aspects of “collaboration engineering” often determine final output quality more than model parameter count.

    6. Conclusion

    This practice gave me a clearer understanding of the role of an AI coding assistant: it is not the magic of “one-click software generation,” but a pair engineer with broad knowledge and extremely fast response that still requires a human to set direction and verify results. In firmware development, a field traditionally highly dependent on accumulated experience, AI can already substantially take on code review, issue localization, and fix implementation—provided the user has enough low-level knowledge to build an effective feedback loop.

    For developers who want to try similar scenarios, my advice is: start with small, verifiable goals, treat debug logs as the common language for communicating with AI, and always have a human gate every submission that is “supposedly fixed.”