UEFI Shell Graphics Mini-Game with Chinese Display: Development Approach with a Minimal Toolchain

    This article outlines how to develop a graphics mini-game with Chinese display in the UEFI Shell using a minimal local toolchain. It explains why firmware-level work is a useful test for AI-assisted programming, defines experiment constraints and evaluation criteria, and reviews the core UEFI application structure, graphics output with double buffering, and keyboard input for the game loop.

    1. Why Use a Low-Level Firmware Scenario to Test AI Programming Ability

    Firmware development is often considered one of the areas that AI-assisted programming struggles to cover. There is some basis for this view. At runtime, firmware has no standard library, file system, or driver framework provided by an operating system; programs call platform-provided protocol interfaces directly. An incorrect protocol GUID, a missed return-value check, or unreleased memory can make a program fail to run or even affect device boot.

    Low-level firmware work falls roughly into two categories. The first is creative programming, such as implementing a diagnostic tool, a settings interface, or a debugging helper from scratch. The second is platform porting, which adapts existing functionality to new hardware and platforms, with the focus on understanding hardware differences and adjusting initialization flows. Both types require an accurate grasp of specifications, and both can benefit from AI assistance, though the stages that benefit differ.

    Breakout is a common case for testing programming ability because its structure is complete. A small game requires graphics rendering, user input, state management, and collision detection, and each module can be verified separately. Placing it in a UEFI Shell environment tests AI understanding of the firmware execution model, the graphics protocol, and the input protocol at the same time.

    2. Experiment Constraints and Evaluation Method

    An effective evaluation needs constraints defined first. The experiment design in this article includes three rules. First, the local environment keeps only the minimum tools needed to compile and run, with no additional auxiliary software preinstalled. Second, the working directory starts blank, with no existing code to reference. Third, humans provide only requirement descriptions, without protocol-call or register-level guidance, and AI completes the entire process from requirement understanding to an executable artifact.

    Evaluation dimensions should be defined before the experiment begins and recorded in every round. At least the following six items are recommended.

    • Compilation result: whether it passes on the first attempt, the error types, and the number of fixes.
    • Protocol call correctness: whether GUIDs, parameter order, and return-value checks conform to the specification.
    • Runtime usability: whether it can boot from a USB drive, run normally after entering the Shell, and exit normally.
    • Chinese display quality: whether characters are complete, alignment is correct, and garbled text is absent.
    • Number of human interventions: how many times a human must point out an issue, and the nature of each issue.
    • Iteration rounds: the number of rounds from requirement to a runnable version.

    A single experiment result is not enough to prove a conclusion. The same task may produce very different results at different times and in different contexts, so the input, output, and error logs of every round should be retained for retrospective comparison.

    3. Basic Structure of a UEFI Shell Application

    A UEFI application exists as a PE/COFF image file. On common x64 platforms, the executable is placed at \EFI\BOOT\BOOTX64.EFI on a USB drive, and the motherboard firmware scans removable media at boot and attempts to load that file. In the Shell, entering the file name runs it manually.

    The program entry function receives an image handle and a system table pointer. The system table contains Boot Services, Runtime Services, and console input/output interfaces. A schematic example is shown below:

    1. EFI_STATUS
    2. EFIAPI
    3. UefiMain (
    4. IN EFI_HANDLE ImageHandle,
    5. IN EFI_SYSTEM_TABLE *SystemTable
    6. )
    7. {
    8. EFI_STATUS Status;
    9. // 1. Locate the graphics output protocol
    10. // 2. Initialize game state
    11. // 3. Enter the main loop
    12. // 4. Release allocated resources before exit
    13. return EFI_SUCCESS;
    14. }

    Boot Services may be closed before the application exits, so the program must release memory it allocated and close events before finishing. Forgetting this step exhausts available memory after multiple runs. Such issues are less common in upper-layer applications, but they are a key check in firmware development.

    4. Graphics Output: Protocol Query and Double Buffering

    The graphics output protocol (EFI_GRAPHICS_OUTPUT_PROTOCOL) provides screen resolution, pixel format, and framebuffer access. The program should first query the protocol by GUID through Boot Services, then read the current mode information instead of assuming a fixed resolution.

    1. EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
    2. EFI_STATUS Status;
    3. Status = SystemTable->BootServices->LocateProtocol (
    4. &gEfiGraphicsOutputProtocolGuid,
    5. NULL,
    6. (VOID **)&Gop
    7. );
    8. if (EFI_ERROR (Status)) {
    9. return Status;
    10. }
    11. EFI_GRAPHICS_OUTPUT_BLT_PIXEL Gray = { 0x20, 0x20, 0x20, 0x00 }; // order: blue, green, red, reserved
    12. Gop->Blt (Gop, &Gray, EfiBltVideoFill, 0, 0, 0, 0, Width, Height, 0);

    Writing directly to video memory pixel by pixel easily causes flicker and is relatively inefficient. A more reliable approach is double buffering: draw the full frame in memory, then refresh it to the screen at once through EfiBltBufferToVideo. With only one screen write per frame, image stability improves noticeably.

    Note that different platforms may use different pixel formats, commonly RGB and BGR arrangements. The program should read the pixel format from the mode information and assemble colors accordingly. This point is easy to overlook, resulting in color channel mismatch that appears as swapped red and blue.

    5. Keyboard Input and the Game Main Loop

    The simple text input protocol (EFI_SIMPLE_TEXT_INPUT_PROTOCOL) provides key reading. Arrow keys and function keys are identified by ScanCode, while ordinary characters are identified by UnicodeChar. The read function returns EFI_NOT_READY when no key is available; the program should treat this as a normal case rather than an error.

    1. EFI_INPUT_KEY Key;
    2. Status = SystemTable->ConIn->ReadKeyStroke (SystemTable->ConIn, &Key);