Evaluating LLM Coding for Firmware Mini-Games: Engineering Capability Beyond Plausible Code

    Firmware mini-games are a small task with unusually strict runtime constraints. This article explains how to evaluate LLM-assisted programming not by whether generated code looks plausible, but by whether the model can work against real execution evidence and deliver a verifiable program. It covers acceptance boundaries, legacy-code review, startup and graphics troubleshooting, observability, decoupling game rules from low-level access, staged delivery, and fairer ways to compare coding agents.

    1. Evaluating LLM coding cannot stop at whether code looks right

    Asking an LLM to write a mini-game looks like a lightweight task. But when the runtime moves from the application layer down to firmware, the complexity rises sharply. Developers cannot assume a full window system, file service, mature runtime, or convenient debugging interface. Graphics output, keyboard input, timing control, and memory allocation often depend directly on services provided by the firmware.

    Such tasks expose a core question in LLM-assisted programming: is the model generating structurally reasonable code, or can it keep working against real runtime results and ultimately deliver a verifiable program?

    In the reference practice, a legacy game codebase had already been split into multiple files, with entry, drawing, input, and game logic organized in separate areas, but it still did not produce a runnable result. Follow-up troubleshooting encountered premature program exit and a graphical interface that would not display. This shows that a complete directory structure and consistent function naming are still far from a genuinely usable engineering result.

    More valuable evaluation dimensions include:

    • Can the model identify the constraints of the target runtime environment?
    • Can it distinguish build failures from runtime failures?
    • Can it turn logs into verifiable failure hypotheses?
    • Can it add regression verification after a fix?
    • Can it state which conclusions are confirmed and which still require experimental confirmation?

    These capabilities are closer to real development work than the number of lines generated in one pass.

    2. Define task boundaries first

    Before starting LLM-assisted programming, define what “done” means. Otherwise, the model may treat “code generated” as complete, “build succeeded” as usable, or even a single successful launch as functional stability.

    For a firmware graphical mini-game, acceptance can be divided into four levels.

    1. Build closure

    Source files can be compiled and linked in the agreed environment to produce an application file loadable by the target environment. This stage mainly verifies consistency in dependencies, entry conventions, type definitions, and build descriptions.

    Note that a successful build only proves that some static constraints are satisfied. It does not prove that graphics mode works, input is normal, or pointers are always valid.

    2. Startup closure

    The program can be loaded, enter the application entry point, complete necessary initialization, and remain running or exit as expected. If it returns immediately after startup, first determine whether initialization failed, the main-loop condition is wrong, or an invalid memory access caused the interruption.

    3. Functional closure

    The screen is visible, keys work, and game state can continue progressing. For a falling-block game, verify block spawning, movement, rotation, collision, locking, and line clearing. For a paddle-and-ball game, verify motion updates, boundary collisions, and failure detection.

    4. Stability closure

    The program maintains controlled behavior under repeated startup, long-running execution, and abnormal conditions, without obvious memory leaks, out-of-bounds access, or an inability to exit.

    Accepting these four layers separately prevents the model from repeatedly modifying parts that have not been confirmed, and it lets developers know exactly where the task is stuck.

    3. With legacy code, review before modifying

    When working with existing code, the most common mistake is to begin with a large-scale rewrite. This may temporarily bypass a problem, but it loses the original failure scene and introduces new variables.

    A more reliable approach is to first build two maps: the call path and the resource lifecycle.

    The call path should cover:

    application entry → protocol location → graphics initialization → input initialization → main loop → exit and cleanup

    The resource lifecycle should answer:

    • Which objects are held by the firmware?
    • Which buffers are allocated by query operations?
    • Which objects are allocated by the application itself?
    • Which data changes after a mode switch?
    • Which resources should be released on failure paths?

    Code review should prioritize issues that may prevent startup or cause invalid access, rather than first adjusting naming, comments, and file layout.

    A reasonable priority order is:

    1. Whether the entry point and calling conventions are correct
    2. Whether status return values are checked at each layer
    3. Whether pointers are initialized and validated
    4. Whether memory ownership and release paths are clear
    5. Whether graphics address, stride, and pixel format match
    6. Whether the main loop and game rules are correct
    7. Only then optimize structure and maintainability

    This is also an important standard for evaluating review quality: can the model rank risks, rather than outputting a long list of suggestions with no sense of priority?

    4. When the program exits after startup, add observability first

    When a program prints only one startup message and then ends, it is difficult to determine the cause from the symptom alone. It may be a normal return, an early exit triggered by an initialization error, or an invalid memory access.

    At this point, do not continue letting the model make consecutive changes based on guesses. First add logs that can locate the stage.

    At minimum, record:

    • The current execution stage
    • The return status of each key protocol call
    • The current display mode
    • Horizontal and vertical resolution
    • Pixel stride per row
    • Framebuffer base address and capacity
    • Input service initialization result
    • Main loop entry, exit, and exit reason

    Logs should be emitted before dangerous operations. For example, record the target mode before switching display modes, and record the validated address and range before writing to graphics memory. Otherwise, the program may fail before the key log is produced.

    In environments without a full debugging interface, serial logging is a common technique. But the logging itself must also be verified. Do not assume that “no output” means the program did not execute; the output channel may not be initialized, or the log may not have been flushed.

    The core principle is: every change should correspond to an explicit hypothesis, and new evidence should be used to determine whether that hypothesis holds.

    5. Graphics initialization troubleshooting: distinguish mode information from current state

    In firmware graphics development, there are clear boundaries between mode queries, mode switches, and actual drawing. Confusing these boundaries can easily cause a black screen or invalid access.

    1. Query results are not the current display state

    A mode query obtains information about a candidate mode, such as resolution, pixel format, and stride. After a mode switch is complete, actual drawing should be based on the currently valid state, rereading the required parameters rather than continuing to rely on all previously cached information.

    The original failure record attributed the problem to pointer invalidation after a mode switch. In professional troubleshooting, however, that explanation cannot be directly generalized into a universal rule. The ownership and lifetime of objects returned by different interfaces must be confirmed according to the specification and the specific call path.

    Key cases to investigate include:

    • Whether a pointer was never assigned correctly
    • Whether a query failed but its result was still used later
    • Whether a buffer was released early
    • Whether the application stored the address of a temporary object
    • Whether old dimensions or graphics addresses are still used after a mode switch
    • Whether type declarations or calling conventions are inconsistent with the actual interface

    Rereading the current state is a reasonable defensive practice, but it should not replace confirmation of the root cause.

    2. Protocol identifiers must match the target interface

    A graphics-related environment may contain multiple interfaces and identifiers for different purposes. Similar names do not mean they are interchangeable.

    If protocol location fails, check the identifier used, the interface declaration, and the status return value, rather than entering the drawing flow directly. If location appears successful but calls behave abnormally, also verify the interface type and calling convention to prevent interpreting the wrong object as another structure.

    Such errors are often invisible from code appearance: function names and variable names may all look correct, but the program has actually obtained a mismatched object.

    6. No display does not necessarily mean protocol location failed

    A black screen is a result, not a root cause. Even if the graphics interface has been obtained correctly, the following issues can still make the interface invisible.

    1. Mistaking screen width for stride

    Logical resolution describes the visible area, while stride describes the distance between the start positions of adjacent pixel rows. The two are not necessarily the same.

    For cases that support direct access, have a confirmed pixel layout, and use a fixed number of bytes per pixel, address calculation can be summarized as:

    pixel offset = (y × pixels per row + x) × bytes per pixel

    The actual stride must be used here. Using the visible width instead may cause image misalignment or writes to the wrong region.

    2. Ignoring pixel format

    Color channel order, bit masks, and access restrictions may differ. A color value that works in one environment cannot be assumed to be directly writable in all environments.

    If the current mode does not support the expected direct-access method, use the graphics transfer capability provided by the environment, or select a display mode that is explicitly supported, rather than blindly calculating addresses.

    3. Missing bounds checks

    Drawing functions should handle negative coordinates, shapes outside the screen, and overflow in width and height calculations. Edge clipping cannot rely only on game logic, because call conditions may change when text, animation, or debugging information is added later.

    A minimal graphics self-test is recommended: draw a background, a border, and several rectangles in different colors. After basic output is verified, connect the full game.

    7. Decouple game rules from low-level access

    Mixing low-level faults with game rules significantly increases troubleshooting difficulty. A clearer structure is:

    • Environment adaptation layer: handles display, input, timing, logging, and memory
    • Game state layer: maintains the board, object positions, velocity, score, and running state
    • Rule update layer: performs movement, collision, rotation, and state transitions
    • Drawing layer: converts game state into the screen

    This allows some pure logic to be verified even when the firmware program cannot yet start. For example, whether a block rotation goes out of bounds, whether a row is filled, and whether collision state is correct should not require a real display device to determine.

    The main loop should also keep responsibilities clear:

    1. Initialize the environment
    2. Run graphics and input self-checks
    3. While the program is still running:
    4. Read input
    5. Compute elapsed time
    6. Update state at a fixed logical step
    7. Draw the current frame
    8. Handle exit conditions
    9. Release resources owned by the application
    10. Return an explicit result

    A fixed logical step helps reduce the impact of runtime speed differences on game behavior. In an actual implementation, however, catch-up updates after abnormally long intervals should be limited to avoid falling into a large number of updates after one long pause.

    8. Two rounds are more reliable than pursuing completeness at once

    The goal of the first round should be minimal runnable behavior, not feature richness.

    Complete the steps in order: program startup, visible logs, solid-color background, key-to-exit, single-object movement, and finally the full rules. Each step should establish an independent checkpoint so that new faults can be limited to a small change scope.

    The second round then addresses experience and engineering quality, including:

    • Reduce repeated full-screen drawing
    • Introduce reasonable pacing for keys that require continuous response
    • Improve text layout and boundary indicators
    • Cover win/loss, restart, and exit flows
    • Complete cleanup on exception paths
    • Verify repeated startup and continuous running
    • Organize build instructions and troubleshooting records

    This approach also improves human-model collaboration: developers do not have to review a large amount of unknown code at once, and the model can converge on problems from clearer runtime feedback.

    9. How to measure LLM coding capability more fairly

    Completion time across different games, codebases, and environments cannot be used directly as a capability ranking. Tasks may look similar while the hidden workload differs: one project may be mainly difficult in graphics initialization, while another may be difficult in input handling or build configuration.

    For a relatively reliable comparison, standardize:

    • Initial requirements and acceptance criteria
    • Source-code starting point
    • Build and runtime environment
    • Scope of accessible materials
    • Human intervention permissions
    • Time budget
    • Logging and error-feedback methods

    Evaluation results should also not be limited to “success” or “failure.” More explanatory metrics include first build result, number of rounds to locate key faults, number of unrelated modifications, degree of human intervention, final feature coverage, and regression test pass status.

    Fixing a legacy project and developing from scratch should be recorded separately. The former emphasizes reading comprehension, root-cause localization, and constrained local modification; the latter emphasizes requirement decomposition, architecture design, and initial implementation. The two capabilities are related but not equivalent.

    10. Conclusion: what matters is a verifiable delivery loop

    Although a firmware mini-game is small in scale, it concentrates the engineering difficulties of LLM-assisted programming: strong environment constraints, limited feedback channels, sensitive interface details, and a long path from “compiles” to “runs stably.”

    Therefore, evaluating LLM coding capability should move from the surface quality of generated code to a complete loop composed of requirement understanding, risk identification, evidence collection, fault repair, and regression verification.

    For developers, the most effective approach is not to let the model retry indefinitely, but to provide clear boundaries, staged acceptance, and credible runtime evidence. For teams, the truly reusable output is not only runnable code, but also environment notes, problem-localization process, key technical constraints, and test records. Only when these are retained together can LLM-assisted programming move from occasional success to sustainable engineering practice.