AI-Driven UEFI Development: Building a Chinese Breakout Game with a Stage-Gated Workflow

    This article documents a practical workflow for using AI to develop a UEFI Shell Breakout game with Chinese text rendering. It covers environment records, risk constraints, staged task decomposition, a minimal runnable skeleton, visual redraw strategies, display debugging, HZK16 font integration, acceptance testing, and the boundaries of AI-assisted BIOS/UEFI programming. The focus is on verifiable stages, build and runtime logs, rollback points, and human review.

    1. Test Environment and Risk Notices

    The program in this article runs in UEFI Shell and does not involve firmware flashing. Before reproducing the work, record the following environment items; otherwise, the scope of the conclusions cannot be determined:

    Environment item What to record
    Firmware and Shell version Motherboard model, firmware version, Shell version
    Target architecture e.g., x86_64; must match the build target
    Display parameters Available resolution list, pixel format (e.g., BGR or RGB), whether multiple modes are supported
    Build environment IDE name and version, compiler and linker versions, build script path
    Removable storage Partition format (usually a FAT-family file system), executable file path

    Several points require special attention. First, the firmware Shell lacks system-level protection. When a program fails, the usual recovery is a reboot. Development should therefore run on a test machine, and important data should be backed up in advance. Second, the program should only read and write graphics output and input devices; it should not access or modify firmware storage. Third, graphics protocol implementations differ across machines. A program that runs correctly on one machine may not display correctly on another.

    2. Task Breakdown and Stage Artifacts

    The rules for this practice were: install only one general integrated development environment on the desktop system, start with an empty local codebase, do not write code manually, and provide only requirements, acceptance criteria, and observed runtime behavior. The development process followed a closed loop of requirement decomposition, interface contracts, small generation steps, automated builds, runtime acceptance, and log-driven repair:

    1. task = decompose(requirement)
    2. for stage in stages:
    3. contract = define_acceptance(stage)
    4. patch = ai_generate(context, contract)
    5. build_ok = build(patch)
    6. if not build_ok:
    7. ai_repair(build_log)
    8. runtime_ok = run_case(contract.cases)
    9. if not runtime_ok:
    10. ai_repair(runtime_log)
    11. commit(patch)

    Each stage should leave clear artifacts so progress and rollback are easy to judge.

    Stage Input Acceptance criteria Typical failure log Rollback
    1. Minimal skeleton Requirements, entry convention Enters graphics mode, responds to keys, exits cleanly Protocol locate failure, mode set failure Return to the last runnable version
    2. Visual optimization Stage 1 version, element list Elements aligned, stable image, no ghosting Coordinate out of bounds, redraw exception Roll back the rendering path
    3. Display debugging Solid color, rectangle, and other test cases Mode, coordinates, and pixel format are correct Black screen, corrupted screen, offset Roll back step by step based on the symptom
    4. Chinese display Font file, test text Common Chinese characters and punctuation render correctly Missing glyph, encoding warning Switch to the fallback character

    The core of this paradigm is verifiability. Each iteration should ask the tool to solve one clear problem so the context does not become vague and rework is reduced. When billing is per call, cost is mainly spent on build-failure and runtime-failure logs. Logs should therefore be as complete as possible, and only key sections should be submitted to the tool.

    3. Stage 1: Building a Minimal Runnable Skeleton

    The first stage goal was to complete the closed loop: initialization, entering graphics mode, drawing the screen, polling input, updating state, and exiting. Visual quality was not an acceptance item.

    Graphics output is generally accessed through EFI_GRAPHICS_OUTPUT_PROTOCOL. The program first uses gBS->LocateProtocol to locate the protocol, then calls QueryMode to query available modes, and finally calls SetMode to switch to the target resolution. Input is generally read through SimpleTextInputProtocol; when waiting for a key, the gST->ConIn->WaitForKey event can be used to avoid busy waiting.

    The key checks for Stage 1 were:

    1. Whether protocol location succeeded, and whether the return value was recorded on failure.
    2. Whether SetMode returned success. If it returns EFI_UNSUPPORTED, the target mode is not supported by the current device, and another item in the mode list should be used.
    3. Whether key presses could be read, and whether the program could leave the main loop after the exit key was pressed.
    4. Whether allocated memory was released and text mode was restored before exit.

    An example log format follows; actual fields depend on tool output:

    1. [INFO] stage=1 step=locate_gop status=OK
    2. [INFO] stage=1 step=set_mode mode=2 status=OK
    3. [WARN] stage=1 step=read_key status=NOT_READY
    4. [INFO] stage=1 step=exit cleanup=done

    The core loop structure was:

    1. while not game_over:
    2. input = poll_input()
    3. update_world(input, dt)
    4. render_frame(world)
    5. present_frame()

    The human judgment criteria were simple: whether the program entered the graphics interface, whether it responded to keys, and whether it exited cleanly.

    4. Stage 2: Visual Optimization and Redraw Strategy

    After the skeleton ran, the screen needed to be clear and readable. Breakout requires a brick matrix, ball, paddle, borders, score, and status hints. Most visual problems come from redraw strategy and coordinate conversion.

    Two common strategies are:

    Strategy Applicable conditions Main risk
    Full-screen redraw Few elements, simple logic, low frame-rate requirements Large refresh volume per frame, possible flicker
    Dirty-rectangle redraw Many elements, higher frame rate required Incorrect changed-region tracking leaves ghosting

    When diagnosing flicker and ghosting, proceed in the following order:

    1. First disable all dynamic elements and keep only the static screen to confirm that the static part does not flicker.
    2. Enable dynamic elements one by one and observe which element causes ghosting.
    3. Check whether the old position of that element is cleared. Under a dirty-rectangle strategy, confirm that the cleared region includes the union of the old and new positions.
    4. Check coordinate conversion to confirm that the scale and offset from logical coordinates to pixel coordinates are consistent.

    5. Stage 3: Display Debugging with the Minimal Phenomenon Method

    In a firmware environment, black screens, corrupted screens, and image offsets usually come from errors in mode setting, pixel format, or buffer layout. This practice used the minimal phenomenon method, adding one variable at each step:

    1. Fill the entire screen with a single color to confirm that mode setting succeeded.
    2. Draw a rectangle at a fixed coordinate to confirm the coordinate origin and pixel format.
    3. Draw the brick matrix to confirm layout and row/column spacing.
    4. Add text and dynamic elements.

    After each step, copy the current version to a separate directory, such as versions/stage3_step2/, and record the diff patch from the previous version. When a problem appears at a step, return directly to the previous directory instead of continuing to modify the failing version.

    6. Stage 4: Chinese Display Implementation Details

    Firmware environments usually do not have a complete font system, so Chinese text requires embedded glyph data. A common approach in practice is a bitmap font. Each character in a GB2312-encoded HZK16 font is a 16×16 dot matrix, covering 3,755 first-level Chinese characters, 3,008 second-level Chinese characters, and some symbols. The font is stored as an external file and converted into an array during the build to avoid writing large amounts of glyph data into the source code.

    UEFI string type is CHAR16, which is UCS-2 encoded. Common Chinese characters are therefore within the Basic Multilingual Plane, and one character corresponds to one code unit. The display flow was:

    1. for cp in text_to_ucs2(text):
    2. glyph = font_lookup(cp)
    3. if glyph is missing:
    4. glyph = font_lookup(FALLBACK)
    5. blit_glyph(fb, pen_x, pen_y, glyph, color)
    6. pen_x += glyph.advance

    Several parameters need to be fixed during design:

    • Chinese character width is 16 pixels, English and digit width is 8 pixels, and line height is 16 pixels plus line spacing.
    • The fallback character uses a fixed box glyph; characters not found in the font are displayed as this glyph.
    • The font code point range is written into the configuration file, and test cases cover boundary characters.

    When building Chinese-related code, source files use UTF-8 encoding consistently. The build script runs a precheck program before compilation, scans all non-ASCII characters, and outputs file names and line numbers. For Chinese text in comments, there are two options: transcode or strip comments before the build, or require the toolchain to use the same character set as the source code. In the original practice, Chinese text in comments caused build warnings, so the precheck should be the first step of the build.

    7. Quality Assurance and Acceptance Table

    Low-level programs cannot rely only on the impression that they “seem to run.” Acceptance needs fixed test cases and comparable standards:

    Acceptance item Test case Pass criteria
    Initialization Execute the program after a cold boot Protocol location and mode setting both return success
    Mode setting Switch to each available mode No image offset, no black screen
    Input boundary Rapid repeated key presses; hold a direction key Paddle responds promptly; no lost keys or freeze
    Collision regression Ball hits boundary, brick, and paddle separately Bounce direction is correct; bricks are removed according to the rules
    Chinese display Common Chinese characters, full-width punctuation, one fallback character Glyphs are correct; fallback character position is correct
    Exit cleanup Normal exit and exit after pressing the exit key Text mode is restored; no residual image

    For each run, record the following log fields: timestamp, stage number, patch number, build result, error code, runtime symptom, and single-run duration. Cost statistics can be recorded by stage: number of calls, number of context characters submitted to the tool, and number of rework cycles. This shows where cost is concentrated.

    Logs and build artifacts can be stored in object storage or a logging service, but several points require attention: logs should not contain personal paths or credentials; retention should be set according to project requirements; and access permissions should be granted only to required members.

    8. Conclusion and Boundaries

    Under the constraints of this article, AI was able to advance the main parts of creative programming, including skeleton setup, state updates, collision logic, and Chinese glyph lookup and drawing. It could also locate problem files and line numbers from build logs and propose smaller-scope changes.

    The conclusions have clear premises. First, this article verifies only one game in one class of environment and cannot be generalized to all machines. Second, the font covers only the selected character set; characters outside the range rely on the fallback character. Third, performance, input latency, and long-run stability have no quantitative conclusions and require separate measurement on the target machine. Fourth, AI-generated code still needs human review, especially for memory release, firmware protocol calls, and the exit flow.

    The feasibility of AI-assisted BIOS programming depends on whether the process can be decomposed, verified, and rolled back. The stage artifact table, minimal phenomenon method, and acceptance checklist are tools for putting this process into practice.