Add Missile Command game for T-Deck + desktop emulator
Game (examples/MissileCommand): - Classic Missile Command: 6 cities, 3 batteries x 10 missiles, escalating waves, smart bombs, score multiplier, session high score - Trackball aims, press/tap fires, keyboard A/S/D selects battery, screen tap aims+fires - Rendering: incremental TFT_eSPI drawing (persistent enemy trails that vanish on death, no AA-rocket trails, explosion circles that repair terrain, ghost-free crosshair) - Sound (sound_engine.cpp): non-blocking I2S task on core 0; wave-start alarm of four falling tones (like the original), sweeps/noise effects, U/V/M keyboard volume control with OSD, master volume scaling Emulator (emulator/): - SDL2 host that compiles the unmodified sketch against shim headers (Arduino, TFT_eSPI->framebuffer, GT911 touch, I2C keyboard, I2S->SDL audio); arrow keys emulate the trackball, --autoplay/--frames/--dump flags for headless smoke tests
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* I2S driver shim: routes i2s_write() output to an SDL audio device
|
||||
* (8 kHz mono S16, queue-based, exactly what the sound engine feeds).
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <SDL.h>
|
||||
|
||||
#define ESP_OK 0
|
||||
#define ESP_FAIL -1
|
||||
#define ESP_INTR_FLAG_LEVEL1 1
|
||||
|
||||
typedef int i2s_port_t;
|
||||
typedef int i2s_mode_t;
|
||||
enum { I2S_NUM_0 = 0, I2S_NUM_1 = 1 };
|
||||
enum { I2S_MODE_MASTER = 0x01, I2S_MODE_TX = 0x04 };
|
||||
enum { I2S_BITS_PER_SAMPLE_16BIT = 16 };
|
||||
enum { I2S_CHANNEL_FMT_ONLY_LEFT = 0 };
|
||||
enum { I2S_COMM_FORMAT_STAND_I2S = 0x01 };
|
||||
#define I2S_PIN_NO_CHANGE (-1)
|
||||
|
||||
struct i2s_config_t {
|
||||
int mode;
|
||||
unsigned sample_rate;
|
||||
int bits_per_sample;
|
||||
int channel_format;
|
||||
int communication_format;
|
||||
int intr_alloc_flags;
|
||||
int dma_buf_count;
|
||||
int dma_buf_len;
|
||||
};
|
||||
|
||||
struct i2s_pin_config_t {
|
||||
int bck_io_num;
|
||||
int ws_io_num;
|
||||
int data_out_num;
|
||||
int data_in_num;
|
||||
};
|
||||
|
||||
inline SDL_AudioDeviceID &emuAudioDev()
|
||||
{
|
||||
static SDL_AudioDeviceID d = 0;
|
||||
return d;
|
||||
}
|
||||
|
||||
inline int i2s_driver_install(i2s_port_t, const i2s_config_t *cfg, int, void *)
|
||||
{
|
||||
SDL_AudioSpec want {}, have {};
|
||||
want.freq = (int)cfg->sample_rate;
|
||||
want.format = AUDIO_S16SYS;
|
||||
want.channels = 1;
|
||||
want.samples = 512;
|
||||
want.callback = nullptr; // SDL_QueueAudio mode
|
||||
|
||||
emuAudioDev() = SDL_OpenAudioDevice(nullptr, 0, &want, &have, 0);
|
||||
if (emuAudioDev() == 0) {
|
||||
std::printf("[emu] no audio device: %s (running silent)\n", SDL_GetError());
|
||||
return ESP_FAIL;
|
||||
}
|
||||
SDL_PauseAudioDevice(emuAudioDev(), 0);
|
||||
std::printf("[emu] audio open: %d Hz (requested %u)\n", have.freq, cfg->sample_rate);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
inline int i2s_set_pin(i2s_port_t, const i2s_pin_config_t *) { return ESP_OK; }
|
||||
|
||||
inline int i2s_write(i2s_port_t, const void *src, size_t size, size_t *written, unsigned)
|
||||
{
|
||||
if (emuAudioDev()) SDL_QueueAudio(emuAudioDev(), src, (uint32_t)size);
|
||||
if (written) *written = size;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
inline void i2s_zero_dma_buffer(i2s_port_t) {}
|
||||
Reference in New Issue
Block a user