UEFI Pac-Man: What Building a Firmware Game with AI Coding Tools Reveals

    This article examines how AI coding tools perform on an unusually unforgiving task: building a Pac-Man-style game that runs in the UEFI Shell environment. It covers the specific obstacles of firmware development (PE/COFF toolchain constraints, protocol-based graphics and text output, scan-code input handling, frame pacing), the results an AI tool delivered, and the quality problems that only surfaced during source review. The conclusion is practical: AI tools can quickly produce a working skeleton, but architectural decisions, code review, and final quality control still belong to the developer. Post/PUT

    Why a UEFI Game Is a Good Test of Coding Tools

    When you build a small game on a general-purpose operating system, most of the complexity is already hidden from you. Window management, graphics drivers, input events, and memory allocation are all handled by mature runtimes. UEFI is the firmware stage between power-on self-test and operating system loading — much closer to bare metal. There is no complete OS service layer, so everything has to be assembled by hand on top of a limited set of firmware protocols.

    That is exactly what makes a Pac-Man-style game in a UEFI Shell environment a demanding test of an AI coding tool. It probes several capabilities at once:

    • Environment awareness — whether the tool understands that compiling, linking, and running a firmware program is fundamentally different from a normal application.
    • Protocol proficiency — whether it can correctly use firmware protocols for graphics output, text output, and input devices.
    • Logical completeness — whether modules such as the maze, pellets, power pellets, ghost AI, and collision detection work together correctly.
    • Self-correction — whether it can locate and fix both compile errors and runtime defects.

    The working conditions were deliberately close to a realistic development scenario: a single mainstream IDE, no existing code repository locally, and essentially no expert guidance — leaving the tool to complete the full loop from zero to a runnable build on its own.

    The Hard Constraints of UEFI Game Development

    To make sense of what came next, it helps to be clear about where the real difficulty lies.

    1. An unusual toolchain. A UEFI application is essentially a PE/COFF image that the firmware loader can recognize. Building it depends on specific libraries and linker options, and the calling convention, entry point signature, and stack protection strategy all differ from a typical desktop program. A small mistake in the build configuration leads to link failures or an unrecognized entry point — which is why many attempts stall at the very first hurdle.

    2. Protocol-based graphics and text. At the firmware stage there is no graphics API library to call. All drawing has to go through the Graphics Output Protocol, which typically means switching the device into graphics mode yourself and managing the framebuffer directly. Text output uses a separate simple text output protocol. Moving characters and drawing sprites means writing pixels, not calling ready-made drawing functions.

    3. Low-level input handling. Keyboard events have to be polled through the simple text input protocol. There is no event queue and no key-mapping library, so converting scan codes into directional control is your job.

    4. The main loop and frame control. The game needs a stable loop that handles the read input → update state → render cadence. Firmware environments have no mature timer framework, so frame rate control also has to be implemented manually.

    Where the AI Coding Tool Shone

    Under clear rules, a strong AI coding tool tends to deliver a few results better than expected.

    It built its own environment. The most notable move was that the tool did not passively wait for environment support. Instead, it proactively built a Win32 simulation harness that could run directly on the desktop. This shows it identified the core pain point — firmware programs are slow and awkward to launch repeatedly for debugging — and worked around the boot overhead of the real firmware environment by first constructing a local test shell that could host the game logic and provide visual verification. For an AI, filling in the missing pieces of a develop-and-debug loop is a meaningful step from “code generator” toward “engineering collaborator.”

    Visual and logical completeness in the first pass. The first version already showed a complete maze, a movable yellow character, four ghosts with eyes, and pellets and power pellets correctly distributed. Rendering worked, characters were legible, and input responded smoothly — visually very close to the classic game. That suggests a reasonably solid internal grasp of the structure and state machine behind this genre.

    Efficient defect localization. One typical defect: after eating a power pellet, the ghosts neither fled nor could be eaten in reverse — in other words, the core state transition for power mode was never actually implemented. Once this was pointed out, the tool corrected it quickly, indicating some capacity for causal reasoning and local refactoring.

    The Real Concerns Behind “It Runs on the First Try”

    If that was an impressive start, the problems that surfaced on a closer read of the source are the most instructive part of this exercise. “The output looks right” and “the code is right” are two different things. The usual concerns cluster in a few places:

    • Missing maintainability: to get it running fast, the code may be tightly coupled with no module boundaries, mixing maze data, game state, and rendering logic together — leaving almost nowhere to start when extending it later.
    • Ignored edge cases: collision detection, wall-wrapping logic, and ghost AI path selection often cover only the ideal path, with no robust handling of boundary cells, overlapping characters, or extreme frame rates.
    • Careless resource management: allocation and release of framebuffer and string buffers lack discipline, which can become a real problem under the constrained memory of an actual firmware environment.
    • Localized fixes: fixing the power pellet mechanic does not guarantee that related states in the state machine were also checked — the classic pattern of fixing one bug while another pops up.

    The central conclusion: AI coding tools are good at quickly producing a “runnable skeleton,” but the final gate on engineering quality has to be guarded by a human. Treating generated output as a finished product is the biggest risk in this kind of practice.

    Practical Ways to Use Coding Tools in Firmware-Level Development

    Drawing on the review above, a few actionable practices stand out.

    1. Establish the skeleton first, then fill in the flesh. Have the tool produce a placeholder framework with clear layering — input module, game state, rendering module, main loop — and then implement each module in depth. This substantially reduces coupling.

    2. Pin down core logic with explicit contracts. Giving precise implementation contracts for key mechanics reduces defects that “look right but are logically wrong.” For power pellets, for example, you can specify semantics like this:

    1. // Enter power mode after eating a pellet: set the duration
    2. // and switch every ghost to the frightened state
    3. void OnPowerPelletEaten(void) {
    4. gPowerModeTimer = POWER_MODE_DURATION;
    5. for (int i = 0; i < GHOST_COUNT; i++) {
    6. ghosts[i].state = GHOST_FRIGHTENED;
    7. }
    8. }

    The main loop should keep a stable structure around the three phases of input, update, and render:

    1. while (gRunning) {
    2. ProcessInput(); // Poll the keyboard, update the character's target direction
    3. UpdateGameState(); // Advance characters, ghost AI, collisions, and the state machine
    4. Render(); // Draw the screen through the graphics output protocol
    5. FrameDelay(); // Frame rate control
    6. }

    3. Enforce review rather than accepting a successful run. The bar should not stop at “does it run.” Check edge cases, state machine completeness, resource management, and code structure item by item. When the tool fixes one defect, ask it to actively look for related defects of the same kind.

    4. Keep architectural decisions with the human. Layering, data structure design, and the simulation-shell approach are decisions the developer should own. Position the tool as an efficient executor, not the decision maker.

    5. Make good use of simulation and minimal reproduction environments. Launching and debugging real firmware is expensive, so borrowing the idea of a locally built simulation shell can significantly shorten the modify-and-verify iteration cycle.

    Summary

    Using a Pac-Man game under UEFI to evaluate AI coding tools yields a two-sided lesson. On one hand, the tool showed far more autonomy than expected in setting up the environment, generating domain logic, and fixing defects, quickly completing the path from zero to runnable. On the other, “running” is not the same as “acceptable” — maintainability, robustness at the edges, and resource discipline in the source still need the developer’s personal oversight.

    The most effective collaboration model is to treat the AI coding tool as a capable execution engine, with clear structural constraints and strict code review defining its boundaries. In low-tolerance environments like firmware this matters even more: it can get you to the finish line faster, but you keep your hands on the wheel.