The ST7789 receives pixel bytes high-byte-first, and TFT_eSprite's pushSprite sends the sprite buffer raw — which is why the sprite's own primitives store colors byte-swapped (drawPixel: color = color>>8 | color<<8). RoomViewCore wrote native little-endian values instead, so every pixel reached the panel byte-swapped: BG 0x0002 showed as green (0x0200), the fogged floor 0x0882 as pink (0x8208) — exactly the symptoms reported from hardware. The core now stores pixels in panel wire order (toWire byteswap on store, one 16-bit rotate per pixel); the emulator blit unswaps before the 565-to-8888 expansion, so its output is pixel-identical. Also add -O2 to the firmware env: PlatformIO's default -Os optimizes for size and was likely a large part of the 13 fps report.
67 lines
2.5 KiB
C++
67 lines
2.5 KiB
C++
/**
|
|
* RoomView — top-down "3D" flythrough of NetDeck's demo map.
|
|
*
|
|
* Target: T-Deck emulator (320x240, RGB565 device framebuffer).
|
|
*
|
|
* This file is only the emulator shell: keyboard pump, delta time, and
|
|
* the 565 -> 8888 presentation blit (the stand-in for the SPI push).
|
|
* The whole renderer lives in the device-agnostic RoomViewCore.h,
|
|
* shared 1:1 with the ESP32-S3 firmware build (fw/RoomViewHW.ino), so
|
|
* benchmark numbers measured on hardware describe exactly this code.
|
|
*
|
|
* 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)
|
|
* - write pixels into emuGfx::fb[] (320x240, ABGR8888 uint32)
|
|
* - set emuGfx::dirty = true each frame you want presented
|
|
* - read keys from emu::keyboard (ASCII queue, filled from SDL events)
|
|
*
|
|
* Keys: a/d orbit speed, w/s zoom, r/f altitude, space pause, q/ESC quit.
|
|
*/
|
|
|
|
#include "shim.h"
|
|
#include "RoomViewCore.h"
|
|
|
|
extern uint32_t emuGfx::fb[320 * 240];
|
|
extern bool emuGfx::dirty;
|
|
extern std::deque<uint8_t> emu::keyboard;
|
|
|
|
// The "device" framebuffer the core renders into.
|
|
static uint16_t fb565[rvcore::W * rvcore::H];
|
|
|
|
void setup() {
|
|
rvcore::rvInit(fb565);
|
|
}
|
|
|
|
void loop() {
|
|
// --- keyboard pump ---
|
|
while (!emu::keyboard.empty()) {
|
|
uint8_t k = emu::keyboard.front();
|
|
emu::keyboard.pop_front();
|
|
rvcore::rvInput(k);
|
|
}
|
|
if (rvcore::rvQuitRequested()) emu::quitRequested = true;
|
|
|
|
// --- 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)
|
|
|
|
rvcore::rvFrame(dt, now);
|
|
|
|
// --- "SPI push": the buffer is in panel wire order (big-endian 565),
|
|
// exactly what the T-Deck's ST7789 receives. For the desktop window,
|
|
// unswap back to native RGB565 and expand to 8888.
|
|
for (int i = 0; i < rvcore::W * rvcore::H; i++) {
|
|
uint16_t c = (uint16_t)((fb565[i] << 8) | (fb565[i] >> 8)); // wire -> native
|
|
uint32_t r5 = (c >> 11) & 31, g6 = (c >> 5) & 63, b5 = c & 31;
|
|
uint32_t r = (r5 << 3) | (r5 >> 2); // 5 -> 8 bit expansion
|
|
uint32_t g = (g6 << 2) | (g6 >> 4); // 6 -> 8 bit expansion
|
|
uint32_t b = (b5 << 3) | (b5 >> 2);
|
|
emuGfx::fb[i] = 0xFF000000u | (b << 16) | (g << 8) | r;
|
|
}
|
|
emuGfx::dirty = true;
|
|
}
|