From 7acfb643177aaf6c03fcf178e053d98c78984683 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Tue, 17 Jun 2025 02:31:32 +0200 Subject: [PATCH] Add ESPboy frontend --- frontend_espboy/frontend_espboy.ino | 139 ++++++++++++++++++++++++++++ game.h | 3 - renderer.h | 7 ++ 3 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 frontend_espboy/frontend_espboy.ino diff --git a/frontend_espboy/frontend_espboy.ino b/frontend_espboy/frontend_espboy.ino new file mode 100644 index 0000000..07d5377 --- /dev/null +++ b/frontend_espboy/frontend_espboy.ino @@ -0,0 +1,139 @@ +/** + @file frontend_espboy.ino + + Experimental Licar frontend for ESPboy, unstable and unplayable, but able to + load a few of the smallest maps and allow driving a bit. +*/ + +#include +#include +#include +#include + +#define MCP23017address 0 +#define MCP4725address 0x60 + +Adafruit_MCP23017 mcp; +Adafruit_MCP4725 dac; +TFT_eSPI tft; + +#define LCR_SETTING_RESOLUTION_X 64 +#define LCR_SETTING_RESOLUTION_Y 64 +#define LCR_SETTING_MUSIC 0 +#define LCR_SETTING_GHOST_MAX_SAMPLES 0 +#define LCR_SETTING_332_COLOR 1 +#define LCR_LOADING_COMMAND wdt_reset(); +#define S3L_SORT 0 +#define LCR_SETTING_MAP_MAX_BLOCKS 512 +#define LCR_SETTING_MAX_MAP_VERTICES 500 +#define LCR_SETTING_MAX_MAP_TRIANGLES 600 +#define LCR_SETTING_REPLAY_MAX_SIZE 0 +#define LCR_SETTING_CAR_SHADOW 0 +#define LCR_SETTING_PARTICLES 0 +#define LCR_SETTING_LOG_LEVEL 0 +#define LCR_SETTING_LOD_DISTANCE 100 +#define LCR_SETTING_CAR_ANIMATION_SUBDIVIDE 0 + +#define LCR_SETTING_FPS 25 + +#define LCR_SETTING_POTATO_GRAPHICS 1 + +#define LCR_SETTING_ENABLE_DATA_FILE 0 +#define LCR_SETTING_ONLY_SMALL_MAPS 1 + +#include "game.h" + +uint8_t gamescreen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y]; +uint8_t keys; + +void LCR_drawPixel(unsigned long index, uint16_t color) +{ + gamescreen[index] = color & 0xff; +} + +void LCR_sleep(uint16_t timeMs) +{ +} + +uint8_t LCR_keyPressed(uint8_t key) +{ + switch (key) + { + case LCR_KEY_UP: return keys & 0x02; break; + case LCR_KEY_DOWN: return keys & 0x04; break; + case LCR_KEY_RIGHT: return keys & 0x08; break; + case LCR_KEY_LEFT: return keys & 0x01; break; + case LCR_KEY_A: return keys & 0x10; break; + case LCR_KEY_B: return keys & 0x20; break; + default: return 0; break; + } +} + +char LCR_getNextDataFileChar(void) +{ + return 0; +} + +void LCR_appendDataStr(const char *str) +{ + return; +} + +void setup() +{ + *((volatile uint32_t *) 0x60000900) &= ~(1); // disable watchdog + + dac.begin(MCP4725address); + delay (100); + dac.setVoltage(0,false); + mcp.begin(MCP23017address); + delay(100); + + // buttons + for (uint8_t i = 0; i < 8; i++) + { + mcp.pinMode(i,INPUT); + mcp.pullUp(i,HIGH); + } + + mcp.pinMode(8,OUTPUT); + mcp.digitalWrite(8,LOW); + + tft.begin(); + delay(100); + tft.setRotation(0); + + tft.setAddrWindow(0,128,0,128); + tft.fillScreen(TFT_BLACK); + + dac.setVoltage(4095,true); // backlight + + LCR_gameInit(0,0); +} + +void loop() +{ + keys = ~mcp.readGPIOAB() & 255; + wdt_reset(); + LCR_gameStep(millis()); + + for (int y = 0; y < LCR_SETTING_RESOLUTION_Y; ++y) + { + for (int i = 0; i < 2; ++i) + { + uint8_t *pixel = gamescreen + y * LCR_SETTING_RESOLUTION_X; + + for (int x = 0; x < LCR_SETTING_RESOLUTION_X; ++x) + { + uint16_t color = *pixel; + color = + ((color & 0xe0) << 8) | ((color & 0x1c) << 6) | ((color & 0x03) << 3); + + tft.pushColor(color); + tft.pushColor(color); + + pixel++; + } + } + } +} diff --git a/game.h b/game.h index 79ec27f..d096877 100644 --- a/game.h +++ b/game.h @@ -366,8 +366,6 @@ struct } dataFile; #define LCR_GHOST_SAMPLE_SIZE 5 - -#if LCR_SETTING_GHOST_MAX_SAMPLES != 0 struct { uint8_t active; @@ -379,7 +377,6 @@ struct allow ghosts for even long replays. */ int16_t offset[3]; ///< Small correcting position offset. } ghost; -#endif #ifdef LCR_FPS_GET_MS uint16_t renderFrameMS; diff --git a/renderer.h b/renderer.h index ff3dd5b..02d2153 100644 --- a/renderer.h +++ b/renderer.h @@ -41,6 +41,13 @@ #define S3L_PERSPECTIVE_CORRECTION 0 #define S3L_NEAR_CROSS_STRATEGY 1 #define S3L_FLAT 1 + #define S3L_Z_BUFFER 0 + + #ifndef S3L_SORT + #define S3L_SORT 1 + #endif + + #define S3L_MAX_TRIANGES_DRAWN 48 #endif #define S3L_NEAR (10 * (S3L_F / 16)) // too low value will cause overflows