AI Takes Over Abandoned Code: Repairing a UEFI Game
A practical experiment in using an AI coding assistant to revive an unfinished UEFI game project. The process covers structured code review, serial-log debugging, a stale pointer caused by incorrect GOP call ordering, and a misconfigured GUID. It also shows why AI-assisted maintenance and debugging can produce better results than asking a model to build the same project from scratch.
1. Background: Asking AI to Clean Up After AI
I recently ran an interesting experiment: I asked different large language models to complete a demanding task—build a runnable game in a UEFI environment, commonly associated with the BIOS stage before the operating system loads.
This kind of task is challenging because it operates outside the mature runtime environment provided by an operating system. There is no standard C library, window system, or ready-made input/output framework. Everything must rely directly on UEFI firmware protocols for graphics rendering and keyboard input.
In the first round of experiments, Model A performed reasonably well. With the help of an AI coding tool, I spent about two and a half hours getting it to build a Chinese-language Breakout game that could run under UEFI. The project compiled successfully on the first attempt and ran correctly the first time.
Model B, however, was asked to build a Tetris game. After nearly six hours, it had not even established a working build environment. In the end, it produced no runnable program.
After I published the results, some readers pointed out that the two models had been assigned different tasks, making the comparison unfair. That criticism was valid, but it also led to a more interesting idea.
Although Model B had failed, the code it left behind looked surprisingly organized: seven source files, a modular design, and a clear hierarchy. Throwing it away seemed wasteful.
That became the central question of this experiment:
What happens if the unfinished code from Model B is handed over, unchanged, to another AI coding assistant? Can the assistant bring this “dead” project back to life?
In other words, let AI clean up after AI.
This scenario has clear practical value. In everyday development, engineers often inherit half-finished projects: code left behind by a former colleague, a poor-quality outsourced delivery, or even a personal project abandoned months earlier. Whether AI coding assistants can serve as effective “codebase successors” directly affects their value in real engineering environments.
2. Experiment Design: A Two-Stage Repair Strategy
To make the experiment reproducible and the evaluation more objective, I defined a two-round testing plan:
- Round 1: Bring it back to life — Make the code compile, run successfully, and display something on screen.
- Round 2: Refine it — Once the game runs, improve code quality, performance, and the overall gameplay experience.
The “make it run first, refine it later” strategy is useful beyond this experiment. When dealing with an abandoned project, the right approach is usually not to redesign the architecture immediately. First establish a minimal working state, then refactor incrementally.
This is a practical application of a familiar software engineering principle: get the program running before attempting major improvements.
3. Round 1 in Practice: From Broken Code to a Running Game
3.1 Environment Setup and Code Review
I copied all of Model B’s source files, without modification, into a clean build environment and started the AI coding assistant.
My first instruction was deliberately limited:
“Review this code and identify potential problems.”
This reflects an important prompt-engineering lesson: do not ask the AI to modify the code immediately.
Having it read the code, analyze the architecture, and produce a list of issues first has several benefits:
- It provides a way to evaluate whether the AI actually understands the overall design.
- The issue list acts as a technical health report that human developers can review.
- It reduces the risk of destructive changes made before the AI has sufficient context.
The AI’s response was encouraging. It inspected the major components—the entry point, main loop, game logic, rendering module, and input-handling module—and produced a structured list of issues within a few minutes. It also claimed that the project should run after the fixes were applied.
I allowed it to proceed.
3.2 Problem One: A Crash Caused by a Dangling Pointer
The project compiled successfully. When I ran it, however, it printed:
Starting Game Loop
and then exited immediately.
That was already a significant improvement over the original result, but the project was clearly not finished. I asked the AI to add more detailed diagnostics along the critical execution path and report progress through the serial port.
In an environment such as UEFI, where mature debugging tools may not be available, serial logging is one of the most effective ways to locate failures. It is also a common “logging first” practice in embedded and low-level development.
The serial output narrowed the problem down to the code executed after a Graphics Output Protocol (GOP) call. Further analysis identified the root cause:
- The code called
QueryModeto retrieve framebuffer information before callingSetMode, then stored the returnedinfopointer. - According to the UEFI specification,
SetModerebuilds the memory associated with the display mode. The buffer returned by the earlierQueryModecall is therefore no longer valid. - The code continued to use the invalid pointer, effectively dereferencing a dangling pointer, which caused an exception and terminated the program.
This is a classic low-level API sequencing error and a common pitfall in UEFI development.
The AI proposed the correct fix: call QueryMode again after SetMode succeeds, or retrieve the current information through the Mode member, so that rendering uses valid memory.
Illustrative pseudocode:
// Incorrect: retrieve info before SetMode and continue using it afterwardgop->QueryMode(gop, mode, &size, &info);gop->SetMode(gop, mode);// info is no longer valid here!// Correct: retrieve the current information after SetModegop->SetMode(gop, mode);info = gop->Mode->Info; // Access the currently valid information
After this change, the program stopped crashing. The first major issue was resolved.
3.3 Problem Two: A Misconfigured GUID Prevented Graphics Output
The program now ran reliably, but the game screen still did not appear. I reported this behavior to the AI and asked it to continue investigating.
This time, the analysis identified a more subtle issue: the GUID used for the GOP protocol was incorrect.
UEFI development frameworks define multiple GUID constants related to graphics output. Their names can be similar, but their purposes differ. Some identify the protocol interface itself, while others identify service handles or devices that support the protocol.
If the wrong GUID is used in the code or dependency configuration, locating the protocol through the system tables may fail or return the wrong object. The program then cannot correctly obtain graphics output capabilities, and no game screen can be rendered.
This issue is a good example of where AI assistance can be particularly useful in low-level development:
- GUIDs are long hexadecimal values that are difficult for humans to read and easy to overlook.
- The error may not be in the business logic. It may be hidden in an inconspicuous constant reference or module dependency declaration.
- An AI assistant can quickly compare similar GUID definitions in the framework and infer which one matches the semantics of the call site.
After correcting the GUID, I rebuilt and ran the project again. The game finally appeared on screen.
At that point, Round 1 had achieved its goal: code that had never successfully run was brought from zero to one under the supervision of an AI coding assistant.
4. Key Lessons from the Experiment
4.1 Writing Code and Fixing Code Are Different AI Capabilities
This experiment suggests that an AI coding assistant may perform better when taking over and repairing an existing project than when creating an equivalent project from scratch.
The reason is straightforward. A repair task provides concrete code context and observable failure symptoms, which significantly narrows the problem space. Starting from scratch requires the AI to make architectural decisions, configure the environment, and resolve many open-ended design questions. The number of ways to fail is much larger.
The lesson is important: do not dismiss an AI simply because it failed to build a project from scratch. It may perform very differently in engineering tasks such as maintenance, debugging, and refactoring.
4.2 Humans Act as Information Relays and Decision-Makers
Throughout the repair process, my own actions were relatively limited:
- Run the program.
- Observe what happens.
- Send serial logs and failure symptoms to the AI.
- Decide when to move to the next stage.
Yet this human role remained essential. The AI could not independently see the screen or directly experience the actual firmware environment. The efficiency of the feedback loop directly affects the efficiency of AI-assisted debugging.
A precise description of the observed behavior and the original logs is far more useful than a vague statement such as “it does not work.”
4.3 Structured Debugging Is a Reusable Method
Looking back at the process, it can be summarized as a general workflow for AI-assisted troubleshooting:
- Review before modifying: Ask the AI to produce an issue list and establish a global understanding of the codebase.
- Improve observability: Add logs or serial output so that the failure location becomes visible.
- Solve one issue at a time: Address crashes before display problems to avoid mixing multiple failures.
- Keep humans in the verification loop: Run the program after each change and use real results to drive the next iteration.
This workflow is not limited to UEFI development. It can be applied to almost any situation in which an AI assistant takes over an abandoned or incomplete project.
5. Final Thoughts
The most valuable result of this experiment was not proving that one model is stronger than another. It was validating a different model of software collaboration:
Abandoned code does not always need to be discarded and rebuilt. AI can act as an efficient successor for unfinished projects.
Every day, many half-complete software projects are abandoned. If AI can bring them back to life at a relatively low cost, those neglected engineering assets may still have practical value.
Round 2—the refinement phase—is still in progress. It includes frame-rate optimization, tuning the feel of block rotation, and further restructuring of the codebase. I will share the results separately.
If you have a codebase that seems too weak to use but too valuable to discard, this workflow is worth trying. Let the AI perform a technical health check first. It may understand how to revive the project better than its original author.
