Licar/frontend_espboy/frontend_espboy.ino

141 lines
3 KiB
Arduino
Raw Normal View History

2025-06-17 02:31:32 +02:00
/**
@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 <Arduino.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_MCP4725.h>
#include <TFT_eSPI.h>
#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();
2025-06-18 16:57:52 +02:00
#define LCR_SETTING_MAP_MAX_BLOCKS 280
#define LCR_SETTING_MAX_MAP_VERTICES 300
#define LCR_SETTING_MAX_MAP_TRIANGLES 300
2025-06-17 02:31:32 +02:00
#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
2025-06-18 16:57:52 +02:00
#define S3L_SORT 0
#define S3L_Z_BUFFER 0
#define S3L_MAX_TRIANGES_DRAWN 16
2025-06-17 02:31:32 +02:00
#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;
2025-06-18 02:02:30 +02:00
default: return 0; break;
2025-06-17 02:31:32 +02:00
}
}
char LCR_getNextDataFileChar(void)
{
return 0;
}
void LCR_appendDataStr(const char *str)
{
return;
}
void setup()
{
2025-06-18 23:09:01 +02:00
// *((volatile uint32_t *) 0x60000900) &= ~(1); // disable watchdog
wdt_disable();
2025-06-17 02:31:32 +02:00
dac.begin(MCP4725address);
2025-06-18 23:09:01 +02:00
delay(100);
2025-06-17 02:31:32 +02:00
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++;
}
}
}
}