UEFI Graphics Development With AI: Building a Breakout Game From Scratch in Visual Studio 2019
A hands-on account of using AI coding assistants to build a graphical breakout game that runs in the UEFI Shell and renders Chinese text, on Windows with nothing but Visual Studio 2019 installed. It covers model selection under cost and quota constraints, a progressive build strategy, graphics output protocol and pixel format handling, timer and keyboard events, 16×16 bitmap font rendering, and the minimal PE/COFF linker setup — along with what worked, what did not, and the manual fallbacks that kept the project moving.
In a bare-metal environment like BIOS/UEFI, where there is no operating system underneath to fall back on, how much work can AI coding tools actually carry? This article is a retrospective on an experiment: on a Windows machine, using only Visual Studio 2019, generating from scratch a graphical breakout game that runs in the UEFI Shell and supports Chinese text display.
A note on cost before anything else: the figures here come from personal measurement only. One round of roughly two hours of high-intensity conversation cost a little over 200 RMB. Actual prices change over time and vary by region, subscription quota, and model version, so treat this as an observation rather than a fixed quote.
Unlike web, backend, or desktop development, a UEFI program runs before the operating system takes over. There is no filesystem ready to use, no runtime library, and no debugger. Many problems that the OS normally hides become immediately visible. That makes UEFI a useful pressure test for the real capabilities of an AI coding tool.
Experiment Rules
The rules were deliberately strict:
- The Windows environment had exactly one basic IDE installed: Visual Studio 2019.
- No additional firmware build toolchain was installed.
- The local codebase started at zero.
- The target project had to be a Chinese-language graphical breakout game that can be copied to a USB stick and run after booting into the UEFI Shell.
Model Selection and the Limits of a Subscription Plan
Model selection changed during the experiment. It started with a flagship model generating the bulk of the code: responses were fast and the logic was fairly complete. To keep the cost of high-frequency development under control, the work then moved to a subscription-plan model from a Chinese provider. That plan consumed quota quickly on this task, and later model calls became restricted or unavailable for reasons that were never determined.
As a result, the experiment never depended on a single model working fully autonomously. The final approach was a hybrid: AI produced drafts and explanations, a human corrected build parameters, and a lightweight model filled in fragments.
Breakout was chosen as the test project because the structure is simple while the coverage is broad. It contains the typical elements of graphics rendering, input handling, collision detection, scoring logic, and interface text, which makes it easy to observe where an AI’s ability ends in an unfamiliar environment.
Why UEFI Is Hard: the Missing Support System
Compared with a web environment or a HarmonyOS platform, the core difficulty in UEFI is not business logic. It is the absence of a supporting system:
- The program must be produced as a PE/COFF image, with the subsystem type set to EFI Application.
- The C runtime library cannot be relied upon.
- Every capability is obtained through the handle–protocol model.
- Debugging feedback is scarce.
- Chinese glyphs must be rendered by yourself.
Stacked together, these factors put strict pressure on both the correctness of AI output against the specification and its debuggability.
Choosing a Model by Task, Not by “Strongest”
The right question is not which model is strongest, but how the task, the toolchain, and the cost constraints line up:
- Everyday business logic, scripts, and API integration can use a mid-tier model or a subscription plan to keep unit cost down.
- Complex algorithms, unfamiliar frameworks, and stubborn defects are worth concentrating on a flagship model.
- Low-level work with high knowledge density — firmware, drivers, kernels — relies more heavily on a flagship model combined with local documentation retrieval.
- High-frequency, high-volume tasks are better served by a subscription plan or a local model.
For this experiment, AI showed clear value in explaining protocols, generating skeletons, and suggesting build parameters. On details such as calling conventions, linker options, and font glyph indexing, however, its output was still sometimes inaccurate or outright misleading, and the developer has to cover the gap using official specifications and actual run results.
A Progressive Strategy, and a Mid-Experiment Interruption
The build proceeded incrementally. First the program drew a single static frame. Then the paddle responded to the arrow keys. Then the ball moved and a frame loop was added. Then the brick array, collision response, scoring, and win/lose determination were filled in. Finally came Chinese text, background refresh, and screen flicker.
Each round added functionality on top of a build that already ran, avoiding a single oversized request that would let the model drift out of control.
Midway through, restricted model calls interrupted the autonomous loop, and the work shifted to a “live guidance” mode: the AI explained the direction of a problem, while I looked up reference material, changed linker parameters, and adjusted the entry function and subsystem settings. That stage exposed the boundary of AI-assisted development more honestly than anything else: when a model cannot keep producing runnable code, it can still lower the cost of understanding, but it cannot replace the engineer on the last mile.
Results: What Ran, What Did Not, What Fell Back
Working:
- Basic graphics output under the UEFI Shell
- Full-screen background drawing
- Paddle control with the arrow keys
- Ball-to-paddle and ball-to-brick collisions
- Scoring and a pause prompt
- Chinese title and prompt text rendered from a 16×16 bitmap font
Not working:
- A fully automatic build with zero human involvement
- Resolution auto-adaptation across different machines
- Complete compatibility with every firmware pixel format
- Linker configuration that needs no manual correction
Manual fallbacks that made it run:
- Adding minimal header files and protocol declarations
- Setting the PE subsystem and the entry symbol manually
- Disabling the default CRT and providing
memcpyandmemsetstubs - Using a built-in bitmap font with a missing-glyph fallback
Overall, AI had high auxiliary value in this experiment, but “fully autonomous completion” remained unrealistic.
The Graphics Output Protocol Comes First
UEFI graphics development starts with the graphics output protocol. Obtain EFI_GRAPHICS_OUTPUT_PROTOCOL through the Boot Services LocateProtocol interface. Do not assume a fixed resolution: read Mode->Info->HorizontalResolution and VerticalResolution first, then compute the layout from the actual dimensions.
The more critical issue is the color format. It is not safe to assume that a Blt operation only requires the 8-bit Blt-only format. Check Mode->Info->PixelFormat instead. Only when the format is PixelBltOnly can you treat the Blt buffer as 8 bits per pixel. The more common case is a 32-bit RGB or BGR format, which means constructing source pixels in the matching byte order while taking reserved or alpha bits into account.
To reduce the risk of a garbled screen, probe the real byte order with a 1×1 pixel. Allocate a four-byte buffer, write a known color such as red 0x00FF0000, call Gop->Blt for a 1×1 BltBufferToVideo, then read it back with BltVideoToBltBuffer. If the value read back differs, probe with green and blue as well to determine where the red, green, and blue channels actually sit in memory.
Game Loop: Timer Events Instead of Busy Waiting
A while(1) busy loop is the wrong shape for a game loop. It burns CPU and sends the fan spinning. A better approach is to create a periodic timer through Boot Services, for example at 60 Hz, which is a period of roughly 166667 units of 100 ns. Create a keyboard event alongside it and wait with WaitForEvent for either the timer or the keyboard.
When the timer expires, advance one frame of logic. When the keyboard event arrives, read and consume the pending key, handling the arrow keys and ESC to exit.
Chinese Text Is the Hard Part
The built-in UEFI font normally covers Latin characters only, so Chinese must be rendered by hand. One reliable approach is a 16×16 bitmap font with 32 bytes per glyph, two bytes per row. When drawing, do not read only the left half of each row: iterate all 16 rows, take both bytes per row, and emit the full 16 columns of pixels.
If the interface text starts out as UTF-8 or UTF-16, it first has to be converted into something indexable. A common approach is to convert wide characters to GB2312 region/cell codes and then look them up in the font using codes in the 0xA1A0 to 0xF7FE range. When the font is missing a glyph, fall back to a space, a question mark, or an English placeholder, and never read out of bounds.
Sample drawing logic:
for (int row = 0; row < 16; ++row) {unsigned char bits[2] = { Glyph[row * 2], Glyph[row * 2 + 1] };for (int col = 0; col < 16; ++col) {if (bits[col >> 3] & (0x80 >> (col & 7)))PutPixel(x + col, y + row, fgColor);}}
Entry Point and Linking With Only Visual Studio 2019
The entry point and linker settings look basic, but they decide whether you get from zero to one. A minimal build checklist:
- If UEFI headers are missing, create minimal headers that declare the required structures:
EFI_STATUS,EFI_HANDLE,EFI_SYSTEM_TABLE,EFI_BOOT_SERVICES,EFI_GRAPHICS_OUTPUT_PROTOCOL, and so on. - Link with
/SUBSYSTEM:EFI_APPLICATIONso the subsystem type is set to 10. - Use
/ENTRY:efi_mainfor the entry function, matching the x64 calling convention; marking it withEFIAPIis recommended. - Remove the default C runtime dependency with
/NODEFAULTLIBand supply your ownmemcpy,memset, and similar stubs. - Check stack commit and section alignment, set sensible
/STACKvalues, and make sure the image is acceptable to the UEFI loader. - When
LNK2019orLNK2001unresolved external errors appear, check the entry symbol, the protocol GUIDs, and the calling convention first.
Common troubleshooting reduces to five categories:
- PE subsystem errors usually show up as an image that is not recognized at all; check the linker options.
- Unresolved entry symbols usually show up as
LNKerrors; check/ENTRYand the function declaration. - A garbled
Bltscreen usually comes from a misjudged pixel format; readPixelFormatand run the 1×1 probe. - Missing Chinese glyphs usually come from wrong font indexing; check the UTF-16 to GB2312 conversion and the missing-glyph fallback.
- Unresponsive keys usually come from the event loop or from not consuming the buffer; use
WaitForEventand clear the keyboard state.
The Value and the Boundary
The value of AI assistance in UEFI development lies mainly in lowering the barrier of unfamiliar knowledge, speeding up solution design, pointing in the right direction when debugging, and producing code drafts. It explains concepts like the graphics output protocol, timer events, the PE subsystem, and calling conventions to developers who do not work in firmware, which noticeably cuts down on blind trial and error.
The boundaries are equally clear. Specification details can be distorted, so protocol field names and constants must be checked against the official headers. The debugging loop still depends on a human, because the AI cannot see the actual screen output or observe hardware behavior. Complex integration has to be verified step by step. And differences between models in long-context handling and complex reasoning affect the success rate.
For firmware developers, the more sensible way to use AI is to treat it as a senior engineer rather than a ghostwriter: let it explain solutions, generate drafts, and break problems down, while keeping final verification, specification checks, and quality control in your own hands. What actually gets restructured is not the engineer being replaced, but the center of gravity shifting from line-by-line implementation toward defining the problem, validating the result, and controlling the boundaries. When a model becomes unavailable or runs out of quota, a clear specification, a solid understanding of the relevant specifications, and a reproducible build checklist are still enough to keep the project moving.
