AI Coding in UEFI Shell: Building a Graphical Breakout Game from Scratch
This article documents an experiment in using AI coding tools inside a UEFI Shell environment, where no window system, font library, or input framework exists. It covers the test constraints, model selection criteria, the CLAUDE.md project charter, a six-stage delivery path, the three real technical difficulties (graphics refresh, Chinese glyph rendering, collision and numerical stability), and a reusable methodology for turning AI coding into a repeatable engineering process.
1. Why the Low-Level Environment Is a Real Test of AI Coding
When people evaluate AI coding tools, a common intuition is that low-level systems work — hardware initialization, register configuration, firmware protocol stacks — has scarce training data and a high expertise barrier, so AI is “probably not up to it.” That view has some merit, but it is too absolute.
A more accurate statement is that AI performance in low-level domains depends heavily on how you organize context and task boundaries. If you simply ask it to “write me a firmware program,” the results will be poor. But if you distill specification documents, interface definitions, and project conventions into a searchable local knowledge base, and break the task into small verifiable steps, the value of AI assistance grows considerably.
From an engineering perspective, firmware development falls into two categories. One is creative development: designing architecture and algorithms from zero. The other is porting and adaptation: moving existing capabilities onto new hardware and new platforms. AI is good at generating skeletons and candidate implementations for the former, and good at diff comparison and boilerplate filling for the latter. Combined, the real payoff is not “writing a few fewer lines of code” but restructuring the development paradigm: shifting from “humans write code, machines execute” to “humans define constraints and acceptance criteria, machines produce implementations, humans review.”
2. The Challenge Rules: Strict Constraints to Force Out Real Capability
To keep the test reproducible, the rules were deliberately harsh:
- Minimal environment: only one mature integrated development environment, with no extra auxiliary toolchains installed;
- Empty codebase: no existing local code, and the tester writes not a single line of implementation by hand;
- Minimal expert guidance: no register details or protocol details provided, leaving retrieval, design, and implementation entirely to the AI;
- Clear goal: run a graphical Breakout game under the firmware Shell, with Chinese display support and no audio.
Breakout was not chosen at random. It has a clear structure and a closed logic loop, while covering five core elements: graphics rendering, keyboard input, collision detection, state machines, and resource management. It is a classic sample for testing end-to-end delivery capability. Similar tests had been done in web and mobile OS environments; the difficulty of the firmware environment is that the supporting system is almost absent — no window system, no font rendering library, no input framework. Everything must be built on top of limited protocol capabilities.
3. Model and Tool Choice: From “Performance First” to “Affordable Cost”
In early trials, flagship models with fast responses and clear logic were genuinely useful, but per-use billing makes them expensive in high-frequency daily development. A widely cited analogy: top-tier sports cars perform superbly, yet what most people actually need is an economical, durable family car.
So this test used a cost-effective model from a cloud vendor’s coding package as the primary engine, accessed through an intelligent coding command-line tool, with the per-step confirmation mode disabled to improve continuity. The plan is to repeat the same task with different models to form an evaluation matrix that supports horizontal comparison. The point to stress is that model selection should not rely on a single leaderboard, but on three metrics: instruction retention in long contexts, cross-file consistency, and cost per unit of task.
4. Context Engineering: CLAUDE.md as the Project “Constitution”
The first instruction was to initialize a project description file, written in Chinese, stating the goal clearly:
# Project GoalA graphical Breakout game running under UEFI Shell, with Chinese display support and no audio.# Technical Constraints- Use only the current IDE and the existing compilation toolchain- Do not introduce third-party graphics libraries- All drawing is based on the basic graphics output protocol- Keyboard input is based on the simple text input protocol# Delivery Requirements- Provide an executable that can be copied to a USB drive and launched directly- Split key modules into: initialization, rendering, input, logic, resources
This file acts as the project “constitution”: it front-loads non-negotiable constraints and reduces AI drift during long tasks. Practical experience is that the more specific the constraints, the less rework; stating “what not to do” is often more effective than stating “what to do.”
5. Breaking Down the Implementation Path: Cutting a Big Task into Verifiable Small Steps
The most common failure mode in AI coding is “generating a complete system in one shot.” A steadier approach is to advance in stages, each producing something runnable:
- Skeleton stage: generate the entry point and main loop, able to print one line of text in the Shell and exit;
- Graphics stage: clear screen, draw rectangles, refresh, verifying that basic graphics output protocol calls are correct;
- Input stage: read key presses, implement left/right movement and an exit key;
- Logic stage: ball and brick data structures, collision detection, scoring, and failure conditions;
- Chinese stage: integrate a bitmap font, solving non-ASCII character display;
- Polish stage: frame rate control, boundary handling, cleanup on abnormal exit.
A sketch of the main loop:
while (running) {ProcessInput(&gState); // Non-blocking key readingUpdateGame(&gState, dt); // Physics and collisionRender(&gState); // Double-buffered drawing to avoid flickerWaitTick(16); // Roughly lock to about 60 frames}
6. Three Real Technical Difficulties
Graphics and refresh. Firmware environments usually provide only primitives at the “fill rectangle / output pixel” level, so double buffering and dirty-rectangle refresh must be implemented yourself; otherwise a fast-moving ball leaves trailing artifacts.
Chinese display. There is no system font, so a compact bitmap font must be embedded (such as a subset of common Chinese characters) and trimmed on demand to reduce size; a mapping from UTF-8 to glyph indices must also be implemented.
Collision and numerical stability. Ball speed and brick dimensions need normalization to avoid tunneling at high speed; a fixed time step is recommended for updates to reduce behavioral differences across frame rates.
7. Retrospective: The Real Capability Boundary of AI
The overall experience: AI can independently complete roughly eighty percent or more of the boilerplate and logic code, but for environment-specific details it still needs humans to supply precise interfaces and verification methods. In other words, what AI compresses is coding time, not engineering judgment time. Human value moves forward to defining constraints, making design trade-offs, and designing acceptance criteria.
8. A Reusable Methodology
- Write the project “constitution” first, then discuss implementation;
- Replace grand one-shot generation with small runnable steps;
- Distill domain knowledge into a local knowledge base for retrieval;
- Choose models with cost as a dimension, not just peak capability;
- Set automated or semi-automated acceptance checks at every stage.
This method also applies to combining general cloud product capabilities on Baidu AI Cloud — for example, using object storage to host the knowledge base, a container platform to run the compilation pipeline, and log and monitoring services to track build quality — turning AI coding from an “individual skill” into a “reproducible engineering process for teams.”
