Building a Vertical Scrolling Shooter on UEFI: An AI Development Practice Across Two Delivery Rounds
This article documents a practical experiment in using AI-assisted programming to build a playable vertical scrolling shooter that runs directly on UEFI. It explains why the firmware environment makes an effective testbed, how to front-load toolchain and image uncertainties through a reusable constraint template, and how to handle Chinese text rendering correctly using variable-length decoding and separate byte-length and display-width metrics. It also covers a four-layer game architecture, frame pacing and performance limits without a scheduler, and how the model rebuilt lost source code from build scripts and prior constraints. The piece closes with a reusable collaboration workflow and a verification checklist, showing that consistency under strict constraints matters more than code elegance.
1. Why Build a Game on UEFI
Most developers think of graphics programs as running “on top of an operating system,” with a window system, font libraries, and ready-made abstractions for audio and input. UEFI (Unified Extensible Firmware Interface) removes all of these assumptions. It runs during the boot phase with only a limited layer of boot services and protocols, no process scheduling, and no general-purpose libraries beyond a basic file system. Once boot services are exited, even the runtime services that were previously available stop working. Writing a playable vertical scrolling shooter under these constraints is essentially an extreme-environment check of engineering capability.
There are three reasons this scenario was chosen as a testbed for AI-assisted programming. First, the feedback loop is extremely short: the build output is a bootable image that runs immediately in a virtual machine, so correctness is obvious and does not depend on a complex dependency chain. Second, fault tolerance is extremely low: any out-of-bounds write or any uninitialized framebuffer pointer shows up directly as screen corruption or a crash, so there is no way to “get it running first and debug later.” Third, the capability coverage is broad: graphics output, key input, timing control, embedded resources, text rendering, state machines, and level logic are all required, which genuinely tests how well the model handles system-level details.
The result was a working version completed within two rounds of conversation, with clear improvement over the previous generation of models in environment setup and Chinese text handling, and a significant reduction in rework. It is worth emphasizing that “two rounds, right the first time” does not mean the model generated everything correctly in a single pass. It means each round of feedback was absorbed accurately, without repeatedly clarifying the same class of problem.
2. Environment Setup: Resolving Uncertainty Up Front
The first pitfall in UEFI development is not the code but the toolchain and image organization. The practical approach is to ask about all uncertainties at once and settle them at once:
- Confirm the target architecture and firmware mode: x86_64 or AArch64, and whether the Compatibility Support Module must be disabled.
- Confirm the build artifact form: a bootable image or a loadable driver module, since the two have completely different entry signatures and dependencies.
- Confirm the source of memory allocation: use the allocation interface provided by boot services during the boot phase, and switch to a self-maintained heap after exiting.
- Confirm the boundaries of using the graphics output protocol, including setting the resolution mode, obtaining the framebuffer address, and the pixel format (commonly BGR or RGB).
- Confirm the input source: the scan code set of the keyboard controller and how to query its state.
Putting these constraints into the initial prompt at once keeps the model from oscillating on basic questions such as “which entry point to use” and “which pixel format to use for colors.” In practice, organizing the constraints into a fixed reusable template is the most effective step for reducing communication cost.
[Project Constraint Template]Target: UEFI application, x86_64, standalone bootable imageEntry: standard application entry signature, parameters are the image handle and system table pointerGraphics: use the graphics output protocol, set 640x480, handle the pixel format according to the actual query resultInput: poll using the keyboard controller protocol, support long press and continuous fireMemory: allocate via boot services during the boot phase, use a self-built memory pool after exitResources: all embedded as static arrays, no external file dependenciesOutput: zero-warning build, uninitialized variables prohibited
3. Chinese Text Display: From “Displays” to “Displays Correctly”
Chinese rendering is where the previous generation of models most often failed. Common problems included truncating multi-byte characters by single bytes, treating character width as one byte and causing all subsequent text to shift, and lacking line-wrapping and boundary-clipping logic. In this round, the model proactively addressed three things: correctly decoding code points according to variable-length encoding, maintaining two separate metrics of “byte length” and “display width,” and clipping text that exceeds the screen rather than discarding it outright.
A reliable practice is to decouple font data from rendering logic, so the rendering layer accepts only code points and coordinates and the glyph source is replaceable:
/* The rendering layer only cares about code points, coordinates, and colors; the glyph source is replaceable */typedef struct {int codepoint; /* decoded code point */int width; /* display width; Chinese characters count as 2 */int height;const unsigned char *bitmap;} glyph_t;void text_draw(int x, int y, const char *utf8, color_t fg);
Three engineering rules are also required: the decoding function must have a deterministic fallback strategy for invalid sequences; width calculation and line wrapping must share the same set of rules; and boundary clipping must be completed before rendering to avoid writing past the framebuffer. Once these three are in place, interface text no longer shows half a character or an entire line shifted out of position.
4. Gameplay Systems: Layered Design Keeps Complexity Controllable
A vertical scrolling shooter looks simple, but combining five levels of weapon upgrades, a wingman system, items, and boss battles causes the number of states to grow rapidly. An effective structure splits the system into four layers that communicate only through well-defined data structures:
- Input layer: converts scan codes into three semantic events—“pressed,” “released,” and “continuous fire”—abstracting away hardware differences.
- Entity layer: the player, enemies, bullets, and items share the same position and lifecycle fields, with behavior distinguished by a type tag.
- Rules layer: collision detection, damage resolution, drop probability, and weapon level transitions are all handled as pure functions, making them easy to reason about and test.
- Presentation layer: only responsible for drawing entity states as pixels, and does not participate in any rule decisions.
For weapon upgrades, a “level-to-bullet-pattern” mapping table is recommended instead of stacking conditional checks in every branch:
Level 1: single straight shotLevel 2: double parallel shotsLevel 3: three-way fanLevel 4: four-way fan + rearward side shotsLevel 5: five-way fan + continuous homing bullets
The key to the wingman system is coordinate-system consistency: the wingman’s offset relative to the main ship must be calculated in the same coordinate system, otherwise the wingman jitters when the main ship moves. Boss battles are expressed with a phased state machine, where each phase declares its bullet pattern, duration, and transition condition, avoiding hard-coding the timeline into the main loop. Items and drops follow “single responsibility”: one item changes only one value, making anomalies easy to trace.
5. Timing and Performance: Stability Without a Scheduler
The firmware environment has no ready-made timer abstraction, so pacing must be implemented manually. A common approach is to read the current value from the high-precision timer protocol, subtract the previous frame’s timestamp, accumulate until a fixed step is reached, and then advance the logic, keeping rendering and logic decoupled. The benefit is that the logic frame rate stays constant, and how fast or slow the screen refreshes does not affect bullet speed or collision results.
Three performance baselines apply: refresh only the necessary regions of the framebuffer to reduce full-screen redraws; set an upper limit on the number of entities and reuse an object pool to avoid frequent allocation; and use coarse filtering before precise checks in collision detection, reducing complexity from quadratic to nearly linear.
6. Rebuilding After Source Loss: Autonomy Is the Key Difference
The most valuable moment in this practice was when the source code was accidentally lost during a build-directory cleanup. Instead of stopping at the conclusion that “the file does not exist,” the model used the existing build commands, target architecture, and prior constraints to regenerate the entry point, rendering, and main-loop skeleton, restored the build, and continued iterating. This reflects three reusable habits:
- Treat build scripts and compiler flags as the source of truth, and infer the directory structure and module boundaries from them.
- Rebuild the external interfaces and data structures first, then fill in the internal implementation, so that compilability is restored as early as possible.
- Immediately run a full build and runtime verification after rebuilding to confirm there are no hidden gaps.
The takeaway for engineering teams is that documenting constraints, interfaces, and build methods as templates is equivalent to preparing a recoverable “minimal trusted context” for the AI.
7. A Reusable Collaboration Workflow and Verification Checklist
Turning the above experience into a process means stability comes from the process rather than luck:
- Requirements phase: produce a constraint template that locks down the architecture, entry point, pixel format, and resource approach in one pass.
- Design phase: define data structures before writing logic, and require modules to communicate through structs.
- Implementation phase: commit in small steps, solving only one class of problem per round and avoiding large-scale rewrites.
- Verification phase: run a fixed checklist—zero-warning build, cold boot in a virtual machine, display of the full Chinese character set, switching across all five weapon levels, wingman following without jitter, each item taking effect uniquely, correct boss phase transitions, and no memory growth during long-running sessions.
- Retrospective phase: record the reasons for rework and write high-frequency issues back into the template.
For teams running this kind of build in the cloud, a container platform can standardize toolchain versions, object storage can hold build artifacts and templates, and log and monitoring services with alerting can track build success rates and failure distribution, turning “two-round delivery” from an isolated case into a measurable, repeatable norm. The general capabilities that Baidu AI Cloud provides for this kind of development workflow can serve as a reference for implementation.
8. Conclusion
Completing a vertical scrolling shooter with full gameplay in an environment as “unsupported” as UEFI tests not whether the model can write elegant code, but whether it can stay consistent under strict constraints: constraints that do not drift, interfaces that are not invented, errors that can be located, and losses that can be recovered. Only by templating constraints, layering the system, and turning verification into a checklist does the efficiency gain from human-AI collaboration become sustainable.
