Testing LLM Coding Skills: Repairing Broken Firmware Game Code

    This hands-on case study explores how an AI coding assistant repaired an unfinished firmware-level Tetris game left by another model. It covers structured code review, serial-log-driven debugging, pointer lifetime issues, graphics protocol identifiers, and targeted optimization, then distills the process into a repeatable workflow for AI-assisted low-level development.

    As AI-assisted programming becomes increasingly common, discussions about model capabilities tend to focus on two questions: Can a model build a complete feature from scratch? And can it take over unfinished legacy code and make it work?

    The first tests code generation. The second tests understanding, review, and repair. This experiment connected the two by asking one model to repair firmware-level game code written by another model—code that had never successfully run.

    The exercise was not a formal benchmark. Its value lay in observing how far an AI assistant could take a broken project and identifying practical ways for developers to guide that work.

    1. Background and Experiment Design

    The starting point was two independent development attempts.

    One model produced a working Breakout game in a firmware environment in approximately 2.5 hours. It compiled on the first attempt and ran successfully on its first launch.

    Another model attempted to implement Tetris. After nearly six hours, it had not even established a working build environment. The result was code that looked well organized but could not run.

    Comparing models on different tasks is not a fair performance benchmark. That objection is valid. However, the unfinished code offered a useful repair scenario in its own right: it had clear module boundaries and reasonable interface designs, yet contained critical implementation defects. This combination is familiar in real software projects.

    The experiment was therefore reorganized into two rounds:

    1. Make the broken code run. Transfer the existing code unchanged, ask the model to review the entire project, and then resolve execution failures one at a time.
    2. Refine and optimize. Once the program worked, improve rendering, code quality, and robustness.

    The goal was not to rank models. It was to examine what an AI assistant could accomplish and how a developer should direct it.

    2. Round One: Review Before Editing

    When taking over unfamiliar code, the most effective first step was not to start changing it. It was to ask the model to read the project and produce a list of suspected problems.

    The initial instruction was straightforward:

    Review this code and identify issues that could prevent it from running.

    The model examined the entry point, main loop, game logic, rendering module, and input handling. Within a few minutes, it returned a categorized issue list covering resource initialization order, pointer lifetimes, and protocol calling conventions.

    That review provided three benefits:

    • A system-wide understanding. Later changes had context, reducing the risk of isolated patches that ignored the rest of the program.
    • Testable hypotheses. Each suspected defect could be connected to an observable symptom and checked against logs.
    • Lower communication overhead. The developer could evaluate the model’s analysis rather than independently inspect every line.

    The practical lesson was clear: review first, modify second. A broad request such as “fix this program” can encourage local patching. A structured review encourages the model to build an understanding of the whole system before making changes.

    3. Failure One: The Program Exited Immediately After Startup

    After the review, testing began. The program compiled, printed startup messages to the serial console, and then exited immediately after:

    1. Starting Game Loop

    The symptom pointed to a failure around initialization or entry into the game loop.

    The next instruction was to add finer-grained debug logging, with serial progress markers around individual operations. Those markers quickly narrowed the failure to the code following a Graphics Output Protocol query.

    The investigation identified a pointer lifetime problem in the implementation: the pointer to mode information obtained from the query was no longer valid after the display mode was changed. Subsequent code continued reading through the old pointer, causing the program to exit abnormally.

    The repair changed when the mode information was retrieved:

    1. // Illustrative pseudocode
    2. status = gop->QueryMode(gop, mode, &size, &info);
    3. if (status != 0) { /* fallback */ }
    4. status = gop->SetMode(gop, target_mode);
    5. // QueryMode again after SetMode to avoid
    6. // using the old, invalid info pointer.
    7. status = gop->QueryMode(gop, target_mode, &size, &info);

    The snippet illustrates the change in call order rather than a complete implementation.

    This failure highlighted a recurring difficulty in firmware development: lifetime and sequencing constraints are not always apparent from an interface signature alone. Understanding them requires documentation, implementation knowledge, and verification.

    A useful way to guide the model was to ask it to create a table recording the source, valid lifetime, and party responsible for freeing each pointer, then compare that analysis with the runtime logs. After the repair, the program no longer exited immediately.

    The important observation was not simply that the model recognized an API name. It connected the execution sequence, pointer usage, and failure symptoms into a hypothesis that could be tested.

    4. Failure Two: The Wrong Graphics Protocol Identifier

    The program now stayed running, but the graphical interface still did not appear.

    After receiving that symptom, the model traced the problem to the graphics protocol identifier selected in the code. The firmware development framework contained several similarly named graphics-related identifiers with different purposes and interface associations. Selecting the wrong one caused handle lookup to fail, leaving the program without usable graphics output.

    This exposed another challenge in low-level development: similar interface and constant names can conceal important differences, while the relevant documentation may be scattered or sensitive to version details.

    For a human developer, resolving the issue means checking specifications and header files. For an AI assistant, the review should explicitly connect each identifier to its intended use.

    A more effective prompt was:

    List every graphics-output-related identifier and protocol definition used in this code. Explain the exact purpose and applicable context of each one. Identify which one the current code selects and why that selection may be incorrect.

    This “enumerate, then compare” approach was more precise than asking only, “Why is nothing displayed?”

    After the identifier was corrected, the graphical interface rendered successfully and the complete game screen appeared.

    5. Round Two: Targeted Refinement and Optimization

    Getting the program to run was only the first milestone. The second round focused on improving both code quality and the playing experience.

    The work covered four areas:

    1. Rendering and gameplay details. Adjust block-drop timing, line-clear animations, and colors to make the game feel closer to a conventional standalone mini-game.
    2. Boundary conditions. Address score overflow, repeated input, and pause/resume behavior to reduce the risk of inconsistent state during extended use.
    3. Error paths. Add failure handling and logging around protocol calls so that failures could be traced through serial output.
    4. Structural cleanup. Preserve the existing modular design while placing shared cross-module state behind explicit interfaces to reduce coupling.

    The main lesson from this round was to define what should change, why it should change, and how the change should be verified.

    Without those boundaries, a model may propose an unnecessarily broad refactor. A narrower instruction keeps the iteration manageable:

    Adjust only the timing logic in the main loop. Do not change the rendering interface. Provide self-test steps after making the changes.

    This kind of constraint made optimization easier to review and verify.

    6. A Practical Workflow for AI-Assisted Low-Level Development

    The two rounds suggested several practices that apply beyond this particular game.

    Have the AI read before it writes

    A review report provides the map for subsequent repairs. Establish the system model before asking for code changes.

    Use runtime evidence to guide diagnosis

    Exact crash locations and unedited log excerpts are more useful than an abstract description such as “the program is broken.” Observable behavior helps turn speculation into testable hypotheses.

    Make pointer lifetimes and interface contracts explicit

    Ask the model to document pointer ownership, validity, and release responsibilities, along with the required ordering of interface calls. These were central concerns in this repair.

    Make small changes and verify each one

    Fix one category of problem, run the program, confirm the result, and then move to the next issue. This makes it easier to identify which change affected the behavior.

    Treat model output as a hypothesis, not an answer

    In a firmware environment especially, plausible explanations are not enough. Conclusions need support from logs and actual execution.

    Keep failed projects as learning material

    The unfinished code made this experiment useful because it provided a realistic repair task. Engineering teams can similarly use sanitized code from past failures to practice AI-assisted review and debugging.

    7. Conclusion

    In less than an afternoon, code from a project that had failed to establish a working build environment became a runnable, playable firmware-level game.

    The most useful result was not a verdict on whether a particular model was “good at coding.” It was a repeatable collaboration process:

    Structured review → symptom-driven diagnosis → incremental repair and verification → constrained optimization.

    When developers guide an AI assistant with engineering discipline rather than open-ended requests, it can contribute meaningfully even in demanding firmware environments. For teams considering AI-assisted low-level development, this workflow provides a practical starting point.