Chapter 7: Emulation, Testing, and Verification

This is an LLM ass-isted document, as are all in the ass/ subdirectory.
Of these, here in the dump/ subdirectory I keep the sloppy & doubtful ones.
I keep these as learning materials for myself, yet to be went thru.

Return to index

1. The Verification Loop

Writing retro software without an automated test loop is frustrating. You compile on modern Linux, but how do you verify that your PRC executes properly without transferring it to physical serial-cradle hardware every two minutes?

Today, modern web-based and native emulators make cycle-accurate testing fast, scriptable, and headless.

2. Survey of Modern Palm OS Emulators

Emulator Type Best For Screenshot / Automation Strategy
CloudpilotEmu Web (WASM) Zero-install, pixel-perfect web embedding Embedded JavaScript API (cloudpilot-emu-embedded)
Mu Native (C++/Qt) Fast desktop development, hardware peripheral emulation Headless via Xvfb + scrot
POSE (Palm OS Emulator) Legacy Native Historical reference (v3.5) Requires older Linux 32-bit compatibility

3. CloudpilotEmu: The Premier Modern Web Emulator

CloudpilotEmu is an open-source, cycle-accurate Motorola 68000 and DragonBall emulator compiled to WebAssembly (WASM). It supports Palm OS 1.0 through 4.1 devices (PalmPilot, Palm III, Palm V, Palm m500, and Palm m515).

3.1. The Embedded JavaScript API

Rather than clicking manually through a web UI, CloudpilotEmu exports an embedded JavaScript library that allows full programmatic control:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Palm OS Modern Test Harness</title>
    <script src="cloudpilot-emu.js"></script>
    <style>
        canvas {
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            width: 320px;
            height: 320px;
            border: 2px solid #333;
        }
    </style>
</head>
<body>
    <h1>Palm OS Test Runner</h1>
    <canvas id="screen" width="160" height="160"></canvas>
    <br>
    <button id="bootBtn">1. Boot ROM</button>
    <button id="installBtn">2. Install & Run App</button>
    <div id="status" style="font-family: monospace; margin-top: 10px;"></div>

    <script>
        const canvas = document.getElementById('screen');
        const status = document.getElementById('status');
        let emu = null;

        function log(msg) {
            status.textContent += msg + "\n";
            console.log(msg);
        }

        document.getElementById('bootBtn').onclick = async () => {
            log("Loading ROM...");
            const romResp = await fetch('palmM515.rom');
            const romData = await romResp.arrayBuffer();

            emu = await cloudpilot.createEmulator();
            await emu.loadRom(new Uint8Array(romData), undefined, cloudpilot.DeviceId.palmM515);
            emu.setCanvas(canvas);
            emu.bindInput(canvas);
            await emu.resume();
            log("Palm OS m515 booted successfully!");
        };

        document.getElementById('installBtn').onclick = async () => {
            log("Fetching Gpp14Modern.prc...");
            const prcResp = await fetch('Gpp14Modern.prc');
            const prcData = await prcResp.arrayBuffer();

            log("Installing database...");
            await emu.installDatabase(new Uint8Array(prcData));

            log("Launching Gpp14Modern...");
            // launchByName uses the internal DB name, NOT the filename!
            await emu.launchByName('Gpp14Modern');
            log("Application launched!");
        };
    </script>
</body>
</html>

4. Key Emulation Gotchas

  1. Internal Database Name vs. File Name (Pitfall #28): emu.launchByName() accepts the internal application database name embedded in the PRC header, not the file name on disk! To inspect the true DB name of any PRC:

    strings MyApp.prc | head -n 5
    # Output:
    # Gpp14Modern
    # applGP14
    

    If your file is named Hello.prc but was built with -n "Gpp14Modern", calling launchByName('Hello') will fail!

  2. Install Method Name (Pitfall #13): In modern CloudpilotEmu (v2.x+), the method is installDatabase(new Uint8Array(buf)), NOT installDb(). It is asynchronous (await).
  3. Canvas Pixelation CSS: Because Palm OS renders at 160x160, modern high-DPI browser rendering applies bilinear smoothing by default, making fonts blurry. Always set:

    canvas {
        image-rendering: pixelated;
        image-rendering: crisp-edges;
    }
    

5. Headless Testing with Native Emulators (Xvfb + scrot)

If you use a native emulator like Mu on a headless CI server, drive it using an X Virtual Framebuffer:

# 1. Start Xvfb virtual display
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99

# 2. Launch emulator with target ROM
mu --rom palmM515.rom &
EMU_PID=$!
sleep 3

# 3. Capture screenshot of launcher
scrot -z 01-boot.png

# 4. Inject PRC via CLI or socket
# ...
sleep 2
scrot -z 02-app-running.png

# Clean up
kill $EMU_PID

Treat screenshots as primary regression-test artifacts in your repository!

6. Further Reading & Reference Resources