LLM Programming in Practice: From a Firmware Game to Complex Code Repair

    This article examines how large language models perform in a real firmware graphics project, where useful results depend on environment setup, code comprehension, log-based debugging, and iterative repair after failure. It proposes a staged, reproducible way to evaluate LLM programming behavior and extracts practical lessons for integrating models into software engineering workflows without judging them by a single final outcome.

    As large language models increasingly enter the software development process, developers are no longer asking only whether a model can generate code. The more important questions are whether it can understand an unfamiliar project, set up a runnable environment, locate low-level problems from logs, keep fixing issues after an initial failure, and ultimately deliver a program that is genuinely usable.

    Compared with typical web applications or scripting tasks, a graphics program running in a firmware environment is a stronger test of a model’s overall ability. It usually involves the boot flow, memory layout, protocol access, input devices, graphics output, build configuration, and serial debug output. A mistake in any one of these areas can prevent the program from compiling, cause it to exit immediately after startup, or produce no visible output at all.

    This article uses the development of a simple graphics game in a firmware environment as a case study. It discusses how large language models perform in complex programming tasks, where their limits appear, and how the process can be improved. The focus is not on comparing two specific products to see which is stronger, but on observing whether an intelligent programming system can complete the full path from code understanding to a closed problem-solving loop when facing a real engineering problem.

    I. Why the Final Result Alone Is Not Enough

    In practical testing, a common approach is to assign different tasks to different models and compare which one finishes faster. This method is intuitive, but not rigorous.

    For example, one model may be asked to build a Breakout game from scratch, while another is asked to build Tetris. Both tasks appear to belong to the same category: making a small game in a firmware environment. But their actual difficulty may be completely different:

    • The complexity of the game logic differs;
    • The graphics drawing approach may differ;
    • The input handling flow may differ;
    • The completeness of the initial code differs;
    • The build environment and project configuration may differ;
    • The amount of available debugging information also differs.

    Therefore, simply comparing development time can easily mistake differences in task difficulty for differences in model capability. A more reasonable evaluation should include the following dimensions:

    1. Environment setup capability: Can the model identify dependencies, configure the build entry point, and generate an executable file?
    2. Code understanding capability: Can it quickly map module responsibilities and call relationships?
    3. Error localization capability: Can it narrow the problem scope through logs, abnormal behavior, and code context?
    4. Repair capability: Is the fix genuinely effective, and does it introduce new side effects?
    5. Iteration capability: After the first failure, can it adjust the approach based on feedback instead of repeatedly generating similar code?
    6. Engineering quality: Do the code structure, maintainability, boundary handling, and comments meet the requirements for sustainable development?

    In other words, a model delivering a “runnable program” is only the minimum standard. A higher-level capability is the ability to gradually build a correct problem model in an uncertain environment with incomplete information.

    II. Test Scenario: Why a Small Game Can Expose Low-Level Problems

    In ordinary applications, users can usually see error messages directly. In a firmware environment, however, problem symptoms are often very limited. A program may display one startup line and then exit immediately. It may also remain on a black screen with no clear error message.

    A simple graphics game usually contains at least the following modules:

    • Program entry and startup initialization;
    • Graphics output protocol acquisition;
    • Screen resolution and frame buffer configuration;
    • Game main loop;
    • Game object state management;
    • Keyboard input handling;
    • Collision detection;
    • Graphics drawing;
    • Delay and frame rate control;
    • Serial or debug output.

    These modules have clear dependencies. For example, the rendering module depends on a valid frame buffer, the input module depends on the correct device protocol, and the main loop depends on successful completion of the initialization stage. If a pointer becomes invalid during initialization, the entire program may terminate before it ever reaches the game logic.

    The challenge of this kind of task for a large language model is that it cannot merely generate code that “looks reasonable.” It must also understand the lifecycle and interface constraints of the runtime environment.

    III. Stage One: From Unfamiliar Code to a Runnable Program

    When facing a multi-file project generated by another model, an effective approach is not to immediately ask the model to “fix all problems.” Instead, it should first perform a structured review.

    1. Build a Project Map First

    The model should first answer several basic questions:

    • Where is the program entry function?
    • What is the initialization order?
    • Where does the game main loop begin?
    • Which module is responsible for graphics output?
    • Which module is responsible for input?
    • How are ownership and lifecycle managed?
    • Does the build configuration match the source code?
    • Are there uninitialized variables, dangling pointers, or invalid handles?

    If the model can first produce a module relationship description, developers can judge whether it truly understands the code rather than merely guessing from file names.

    A reasonably ideal review result should look like this:

    1. Entry function
    2. ├── Initialize graphics output
    3. ├── Initialize input device
    4. ├── Create game state
    5. └── Enter main loop
    6. ├── Read input
    7. ├── Update object positions
    8. ├── Perform collision detection
    9. └── Draw current frame

    This structured analysis is very important for later debugging because it helps developers quickly determine whether the fault is in the initialization stage, the main loop stage, or the rendering stage.

    2. Typical Problem: Lifetime of Protocol Query Results

    In firmware graphics programs, a common mistake is to directly store a struct pointer returned by a protocol query interface and then continue using it after switching display modes.

    The problem can be abstracted as follows:

    1. info = QueryMode();
    2. SetMode(target_mode);
    3. use(info);

    If SetMode changes the underlying buffer or releases the original query result, info may become a dangling pointer. In this case, the program may exhibit the following symptoms:

    • It crashes immediately after startup;
    • Drawing behaves abnormally;
    • It works at some resolutions but fails at others;
    • Debug and release builds behave differently.

    A safer order is:

    1. QueryMode();
    2. SetMode(target_mode);
    3. QueryMode();
    4. use(current_info);

    Of course, the actual implementation still needs to handle memory allocation and release according to the interface contract. But from an engineering principle perspective, after any operation that changes device state, code should not assume that previously obtained state information remains valid.

    The value of this type of problem is that it is not a simple syntax error. It involves interface lifecycle, memory validity, and device state transitions. Whether a model can identify it reflects its understanding of low-level programming semantics.

    3. Typical Problem: Incorrect Protocol Identifier Configuration

    If the program can enter the main loop but the screen never shows an image, the problem is not necessarily in the drawing function itself. It may also occur during graphics protocol acquisition.

    A common troubleshooting order in a firmware environment should be:

    1. Was the graphics output protocol located successfully?
    2. Is the obtained protocol object null?
    3. Is the current display mode valid?
    4. Is the frame buffer address correct?
    5. Is the pixel stride for each line correct?
    6. Does the pixel format match the drawing logic?
    7. Does the drawing area exceed the actual resolution?

    In particular, protocol identifiers are usually defined by fixed structures. If the code uses an incorrect identifier, an incorrect version declaration, or a mismatched interface type, the program may not report an error at compile time, but at runtime it will fail to obtain the correct graphics protocol.

    Therefore, during debugging, do not only observe whether there is an image. Key state should also be output:

    1. Locate graphics protocol: success
    2. Current width: 1024
    3. Current height: 768
    4. Frame buffer: valid
    5. Pixels per line: 1024
    6. Pixel format: supported

    These logs help developers break a “black screen” into more specific problems, instead of making the model repeatedly modify drawing code based on guesswork.

    IV. Stage Two: From Runnable to Usable

    A program that can start does not mean the task is complete. The game still needs a round of functional and engineering quality optimization.

    1. Verify That the Main Loop Is Stable

    First, confirm that the main loop has clear pacing control. A loop without delay can cause:

    • High CPU usage;
    • Input state being read too frequently;
    • Game speed being tied to machine performance;
    • Screen flicker during refresh;
    • Debug output flooding the screen.

    A more reasonable design is to use a fixed timestep, or at least introduce a basic delay:

    1. Read input
    2. Calculate elapsed time
    3. Update game state
    4. Perform collision detection
    5. Draw current frame
    6. Wait for next frame

    If a fixed timestep is used, avoid treating “how many pixels to move per loop” directly as game speed. Displacement should be calculated based on the time interval.

    2. Check Boundaries and Collision Logic

    For a Breakout-style game, the model needs to handle the following boundaries:

    • Does the ball pass through the screen edge?
    • Is the bounce angle reasonable when the ball hits the paddle?
    • When the ball overlaps a brick, is the brick removed only once?
    • When multiple bricks are hit at the same time, is the state consistent?
    • When lives reach zero, does the game end correctly?
    • When restarting, is the old state cleared?

    These problems often do not appear during the first run. They may appear during fast player input, continuous collisions, or extreme positions. Therefore, testing should not only verify that “an image appears.” Boundary scenarios should also be designed and run repeatedly.

    3. The Input System Must Consider Device Differences

    Keyboard input in a firmware environment is not as stable and uniform as in desktop programs. Different devices may have:

    • Key repeat events;
    • Differences in the order of press and release events;
    • Some special keys that cannot be recognized;
    • Input read speed that does not match the main loop speed.

    When handling input, the model should clearly distinguish between “key events” and “current key state.” If only transient events are read, long-press movement may be discontinuous. If only state is recorded, start, pause, and exit operations may not be handled correctly.

    V. How to Design More Reliable Intelligent Programming Tests

    To avoid test results being distorted by task differences, a staged and reproducible test plan can be used.

    Stage One: Environment Preparation

    Fix the following in advance:

    • Compiler version;
    • Project directory structure;
    • Launch method;
    • Runtime device or virtual environment;
    • Available debug output channel;
    • Test input method.

    The more stable the environment, the more the results reflect the model itself rather than accidental differences in environment configuration.

    Stage Two: Unified Task Description

    The task description should include clear acceptance conditions, such as:

    • The program compiles successfully;
    • It can enter graphics mode;
    • It can respond to specified keys;
    • The game main loop continues running;
    • The exit flow works normally;
    • The core logic has no obvious out-of-bounds issues;
    • The code has a basic modular structure.

    At the same time, avoid giving key implementation details directly in the description. Otherwise, the test evaluates the model’s ability to follow prompts, not its ability to solve problems.

    Stage Three: Record the Full Process

    In addition to recording whether the final result succeeded, also record:

    • Whether the first compilation passed;
    • What happened during the first run;
    • What assumptions the model proposed;
    • Which changes actually solved the problem;
    • Whether regression failures occurred;
    • How many files were modified in total;
    • Whether manual input of key information was required.

    This kind of process data is more useful than a single “success or failure” result.

    Stage Four: Distinguish Model Capability from Tool Capability

    Intelligent programming usually depends on the terminal, editor, compiler, and runtime environment. The final outcome is the result of multiple factors working together:

    1. Model reasoning ability
    2. + Tool invocation ability
    3. + Context management ability
    4. + Runtime feedback quality
    5. + Engineering environment stability
    6. = Actual development outcome

    Without logs, the model may only be able to guess. If compiler information is incomplete, the model may be unable to determine the source of the error. If the context is too long and key information is truncated, the model may repeat the same mistake. Therefore, evaluation should try to distinguish “the model cannot do it” from “the system did not provide enough feedback.”

    VI. Practical Implications for Developers

    Several generally useful conclusions can be drawn from this type of case.

    First, the value of large language models in code review and debugging is often no less than in generating code from scratch. In real projects, a large amount of work is not about creating entirely new programs, but about understanding legacy code, locating anomalies, and fixing boundary issues. Whether a model can quickly build a full picture of the project determines whether it is truly productive.

    Second, clear feedback is more important than vague instructions. “The program does not run” provides very limited information, while “it exits immediately after calling the graphics protocol, and the last serial log is after the mode switch” can significantly narrow the troubleshooting scope.

    Third, models are suitable for high-frequency, repetitive work that requires broad context retrieval, but key changes still need human verification. This is especially true for code involving memory lifecycle, device protocols, boot flow, and hardware state. Such code cannot be delivered solely because a model claims it has been fixed.

    Fourth, truly valuable intelligent programming capability is not about generating perfect code in one pass. It is about establishing a sustainable feedback loop:

    1. Propose a solution
    2. → Compile
    3. → Run
    4. → Collect logs
    5. → Analyze symptoms
    6. → Modify code
    7. → Regression test

    As long as this loop is stable enough, even if the first generated code has defects, the model may still complete a high-quality delivery through multiple iterations.

    Conclusion

    Developing a graphics game in a firmware environment may look like a small project, but it actually covers multiple areas at once: the build system, device protocols, memory management, input handling, graphics rendering, and debugging engineering. It is well suited as a comprehensive case for observing the programming capability of large language models.

    When evaluating whether a model is “good to use,” do not look only at whether it can generate a large amount of code. Pay more attention to whether it can understand an unfamiliar project, handle runtime feedback, identify low-level errors, and keep the system stable after multiple rounds of modification.

    For developers, the most effective way to use models is not to treat them as one-time code generators, but to include them in the full software engineering process: review first, then run; record symptoms first, then propose hypotheses; verify after every change, and confirm through repeatable tests that the fix is actually effective. Only in this way can the generative capability of large language models be turned into reliable engineering productivity.