CRT Terminal app

This commit is contained in:
Dejvino
2026-11-11 22:03:40 +01:00
parent 1ef22cc832
commit 951c56168c
10 changed files with 1447 additions and 28 deletions
+60 -11
View File
@@ -1,15 +1,15 @@
/**
* SDL2 host for the MissileCommand sketch — run the game on your PC.
* SDL2 host for T-Deck example sketches — run the app on your PC.
* The sketch is selected with -DAPP_INO (see the Makefile, APP=...).
*
* Input mapping:
* Arrow keys trackball roll (hold to keep rolling)
* Mouse wheel trackball roll (each notch = a ball pulse burst)
* Enter / right-click trackball press (fire)
* Left-click screen tap (aim + fire)
* A S D fire from left / center / right battery
* Space fire from nearest battery
* U / V volume up / down
* M mute toggle
* Enter / right-click trackball press
* Left-click screen tap
* Letters/digits keyboard device @ I2C 0x55
* Backspace/Delete keyboard device (0x08 / 0x7F)
* --type "text" queue keys programmatically (for smoke tests)
*/
#include <SDL.h>
#include <SDL_ttf.h>
@@ -19,8 +19,15 @@
#include "emu_gfx.h"
#include "emu_input.h"
// pull in the whole game as a single translation unit
#include "MissileCommand.ino"
#ifndef APP_INO
#define APP_INO "MissileCommand.ino"
#endif
#ifndef APP_NAME
#define APP_NAME "T-Deck app"
#endif
// pull in the whole sketch as a single translation unit
#include APP_INO
// ---------------------------------------------------------------------------
// Global instances declared extern in the shims
@@ -63,14 +70,22 @@ int main(int argc, char **argv)
{
long maxFrames = -1;
const char *dumpPath = nullptr;
bool autoplay = false;
const char *typeStr = nullptr;
int typeFromFrame = 30;
int dumpEvery = 0;
#ifdef EMU_APP_MISSILECOMMAND
bool autoplay = false;
#endif
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--frames") && i + 1 < argc) maxFrames = atol(argv[++i]);
else if (!strcmp(argv[i], "--dump") && i + 1 < argc) dumpPath = argv[++i];
else if (!strcmp(argv[i], "--dump-interval") && i + 1 < argc) dumpEvery = atoi(argv[++i]);
else if (!strcmp(argv[i], "--type") && i + 1 < argc) typeStr = argv[++i];
else if (!strcmp(argv[i], "--type-at") && i + 1 < argc) typeFromFrame = atoi(argv[++i]);
#ifdef EMU_APP_MISSILECOMMAND
else if (!strcmp(argv[i], "--wave") && i + 1 < argc) emuStartWaveRequest = atoi(argv[++i]);
else if (!strcmp(argv[i], "--autoplay")) autoplay = true;
#endif
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
@@ -79,7 +94,7 @@ int main(int argc, char **argv)
}
TTF_Init();
SDL_Window *win = SDL_CreateWindow("Missile Command — T-Deck emulator",
SDL_Window *win = SDL_CreateWindow("T-Deck emulator — " APP_NAME,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, SDL_WINDOW_RESIZABLE);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
@@ -122,6 +137,12 @@ int main(int argc, char **argv)
case SDLK_SPACE:
emu::keyboard.push_back(' ');
break;
case SDLK_BACKSPACE:
emu::keyboard.push_back(0x08);
break;
case SDLK_DELETE:
emu::keyboard.push_back(0x7F);
break;
case SDLK_ESCAPE:
running = false;
break;
@@ -203,7 +224,34 @@ int main(int argc, char **argv)
}
}
// --type: queue the string on the keyboard device like a human typing
// (one char per --type-at start, ~40 ms apart in millis time, so the
// sketch processes each key before the next arrives).
// '\n' emulates Enter: press the trackball pin for one iteration.
static const char *typeNext = nullptr;
static int typePressPin = -1;
static unsigned long lastTypeMs = 0;
if (typeStr && frame >= (uint32_t)typeFromFrame) {
if (typePressPin >= 0) {
emu::pinLevels[typePressPin] = 1; // release the Enter press
typePressPin = -1;
}
if (!typeNext) typeNext = typeStr;
const char *typeEnd = typeStr + strlen(typeStr);
if (typeNext < typeEnd && millis() - lastTypeMs >= 40) {
lastTypeMs = millis();
if (*typeNext == '\n' || *typeNext == '\r') {
typeNext++; // consume the Enter char
emu::pinLevels[BOARD_BOOT_PIN] = 0;
typePressPin = BOARD_BOOT_PIN;
} else {
emu::keyboard.push_back((uint8_t)*typeNext++);
}
}
}
// Headless test mode: start the game, wander the crosshair, keep firing.
#ifdef EMU_APP_MISSILECOMMAND
if (autoplay) {
static bool started = false;
if (!started && frame >= 5) {
@@ -215,6 +263,7 @@ int main(int argc, char **argv)
if (frame % 4 == 0) emu::pinLevels[dirPin[dir]] ^= 1;
if (frame % 75 == 0) emu::keyboard.push_back('s');
}
#endif
// fire any emulated interrupts triggered by the pin changes above
emu::dispatchIsrs();
+2 -2
View File
@@ -13,8 +13,8 @@ class Preferences {
public:
bool begin(const char *ns, bool readOnly = false)
{
(void)ns;
(void)readOnly;
snprintf(path_, sizeof(path_), "%s-prefs.cfg", ns);
map_.clear();
if (FILE *f = fopen(path_, "r")) {
char key[64];
@@ -53,5 +53,5 @@ private:
}
std::unordered_map<std::string, uint32_t> map_;
const char *path_ = "mc-prefs.cfg";
char path_[64] = "mc-prefs.cfg";
};