Using AI to Build a Tank Battle Game in the UEFI Shell: A Practical Retrospective

    This article reviews a hands-on evaluation of AI code generation using a single benchmark task: building a classic top-down tank battle game under the UEFI Shell, with eight maps, four enemy tank types, five power-ups, particle effects, 640x480 BGRA output, and a stable 30 FPS. It explains why fragmented coding tasks are poor benchmarks, outlines the firmware environment's graphics constraints and common pitfalls around the Graphics Output Protocol (GOP), and walks through a failed attempt to build a firmware emulation project before switching to a virtualized environment. The article closes with a reusable evaluation methodology covering budget caps, layered prompting, failure classification, reproducibility, and cost observability.

    1. Why Use a “Game Inside Firmware” as the Benchmark

    When evaluating code generation, fragmented tasks like “write a sorting function” are the worst choice. They reveal neither the model’s understanding of engineering structure nor its ability to self-correct when facing errors. So I fixed a unified benchmark task: implement a classic top-down tank battle game under the UEFI Shell, with eight maps, four types of enemy tanks, five power-ups, particle effects, 640x480 BGRA output, and a stable 30 FPS.

    The value of this task is that it stress-tests four capabilities at once:

    • Modeling an unfamiliar runtime environment. UEFI has no operating system, no standard library, only firmware services and protocols.
    • Precise control over graphics output. Pixel format, width alignment, and double buffering—one mistake and the screen turns to noise.
    • Long-file organization. Game logic, rendering, collision, and map data must be layered, not piled into a single file.
    • Error-driven repair. A compile failure and a black screen at runtime are two completely different kinds of failure.

    Note that this article only offers a horizontal observation under the same benchmark and does not compare against models outside the region. The reason is practical: only with a unified benchmark, unified prompts, and a unified environment are the samples comparable; meanwhile, supporting the continuous iteration of domestic models is itself a prerequisite for making the benchmark more meaningful.

    2. Environment Boundaries: What UEFI Graphics Can Actually Do

    A UEFI application runs in the firmware stage, and it can rely on only three things: the boot services and runtime services from the system table, and protocols that must be opened manually when needed. Graphics output goes through GOP (Graphics Output Protocol), whose mode information tells you the resolution, bits per pixel, and, critically, the byte layout.

    Illustrative initialization logic:

    1. // Pseudocode: get the mode and locate the frame buffer
    2. GraphicsOutput = LocateProtocol(&GopGuid);
    3. ModeInfo = GraphicsOutput->QueryMode(GraphicsOutput, 0);
    4. FrameBuffer = GraphicsOutput->Mode->FrameBufferBase;
    5. // Direct BGRA writes; note that PixelsPerScanLine may be greater than Width
    6. for (UINTN y = 0; y < Height; y++) {
    7. UINT32 *Row = (UINT32 *)((UINT8 *)FrameBuffer + y * Stride);
    8. for (UINTN x = 0; x < Width; x++) {
    9. Row[x] = MakeColor(b, g, r, 0);
    10. }
    11. }

    There are three high-frequency pitfalls here, and whether the model can proactively avoid them directly determines success or failure:

    1. Using Width * 4 as the row stride. For alignment, firmware often has PixelsPerScanLine greater than the visible width, so computing the address purely from the width skews the image.
    2. No double buffering, computing and writing at the same time causes tearing. A workable approach is to maintain a back buffer in memory and copy it to the frame buffer in one shot each frame.
    3. Frame rate depending on a fixed delay. The correct approach is to use the timing capability provided by boot services to compute time deltas, rather than hardcoding a sleep duration.

    3. The First Crash: The Emulator Project Configuration Became a Cost Black Hole

    Following the established process, the first step is to generate a Chinese project description file that lays out the runtime environment, graphics approach, and gameplay points all at once. This step is extremely cheap and the output quality is good, showing that “writing the constraints clearly” has the best cost-performance ratio.

    The real divergence appeared in the second step: put the code into a firmware emulation project, build it with a compilation toolchain on Windows, then run it in the emulator. Of the six previous samples, only two got through this path; the rest all got stuck. This sample got stuck too, and it was the most costly failure.

    It repeatedly did three things: modify the description file to add module entries, adjust the volume and file system layout in the firmware file, and fill in dependencies and library instance mappings. The errors changed from “entry point not found” to “library instance mismatch,” then to missing symbols at the link stage. Each round of changes burned tokens, but the error did not budge. About one-third of the budget was consumed here, and the problem remained.

    The cause of failure is worth abstracting: it is not that the model “can’t write code,” but that there is too much tacit knowledge about engineering constraints:

    • The module type (application/driver/library) must match the entry point signature;
    • dependency exports and imports must be closed, and circular dependencies fail the build outright;
    • the firmware volume layout determines whether files can be packed into the image and enumerated in the Shell;
    • the toolchain’s naming conventions, alignment, and debug symbol settings can trigger baffling link errors.

    This kind of knowledge has low density in public corpora and varies greatly across versions; the model lacks a reliable prior and can only rely on trial and error, and trial and error in a billing environment equals continuous bleeding.

    4. The Right Way to Cut Losses: Switch the Verification Environment to a Virtualization Platform

    My instruction was just one sentence: stop building the emulation project, and use a virtualized environment to debug and run.

    The engineering logic of this decision is to decouple “build correctness” from “runtime correctness.” Under the virtualization approach, the firmware code can go through an independent executable build path, and the output is a directly bootable image; the VM can provide OVMF-style firmware with disk, serial, and display devices, and the run results can be screenshotted and screen-recorded.

    After the switch, progress was obvious: the black screen was traced to the row stride, the screen noise to the missing buffer, and the unresponsive input to repeated key-scan triggering without debouncing. All three types of problems converged within a few rounds.

    Recommended verification loop:

    1. Light up the screen with a minimal skeleton first: just clear the screen and draw one rectangle, confirming the protocol and address calculations are correct.
    2. Add the back buffer and frame timing, confirming stable refresh.
    3. Then layer on the map, collision, enemy spawning, and power-up logic.
    4. Keep a rollback-able build artifact at each step to avoid having to redo everything after breaking one spot.

    5. A Reusable Evaluation Method

    Abstracting this experience into a method for future evaluations:

    • Segment the budget. Set a hard cap for “environment adaptation”; switch approaches once the line is crossed, and don’t wrestle with the toolchain.
    • Layer the prompts. Give the runtime environment and output protocol first, then the gameplay, then the performance targets, avoiding a one-time pile-up that causes constraints to conflict.
    • Classify failures. Distinguish build-time, boot-time, and logic-time failures; use different handling strategies for different categories.
    • Make results reproducible. Archive the code, build scripts, run screenshots, and parameters together so a third party can pull it down and run it directly.
    • Make cost observable. Only by tracking consumption per stage can you tell whether the model is “expensive because it’s thinking” or “expensive because it’s spinning.”

    The conclusion is not complicated: in an obscure environment like firmware, the model’s coding ability is not the bottleneck; tacit environmental knowledge and the judgment of when to cut losses are. Whoever admits earlier that a path won’t work and switches verification means has the lower total cost. In engineering, the same goes for people.