/** * Demo sketch — replace this file with your own experiment. * * This is the EMULATOR SHELL only. The actual demo lives in DemoCore.h * (device-agnostic: RGB565 in panel wire order) so the same core can be * driven by the firmware twin in fw/DemoHW.ino for hardware benchmarks. * * Contract with the emulator host (src/main.cpp): * - implement setup() — called once at launch * - implement loop() — called once per frame (host paces at ~60 fps) * - the host provides emuGfx::fb565[] (320x240, RGB565 in panel wire * order) — render into it, or hand your own buffer to the core * - set emuGfx::dirty = true each frame you want presented * - read keys from emu::keyboard (ASCII queue, filled from SDL events) * * Update state with DELTA TIME, not per-frame constants: measure the real * seconds since the previous loop() call (see loop() below) and scale all * speeds in "units per second" by it. Then the sketch runs at the same * speed no matter what fps the host (or the real hardware) manages. * * This sample just bounces a colored box around — enough to prove the * pipeline works. Delete everything and start from the structure below. */ #include "shim.h" #include "DemoCore.h" // Emulator state provided by the host (src/main.cpp) extern uint16_t emuGfx::fb565[320 * 240]; extern bool emuGfx::dirty; extern std::deque emu::keyboard; void setup() { demo::demoInit(emuGfx::fb565); } void loop() { // Keyboard pump while (!emu::keyboard.empty()) { uint8_t k = emu::keyboard.front(); emu::keyboard.pop_front(); demo::demoInput(k); } // Delta time: seconds since the previous frame. static unsigned long lastMs = 0; unsigned long now = millis(); float dt = lastMs ? (now - lastMs) / 1000.0f : 1.0f / 60.0f; lastMs = now; if (dt > 0.1f) dt = 0.1f; // clamp after stalls (drag, breakpoint) // Render one frame into the 565 buffer demo::demoFrame(dt, now); // Present: the host expands 565 -> 8888 for the desktop window emuGfx::dirty = true; }