Port the shared emulator harness (all apps) to SDL 3.4 + SDL3_ttf 3.2:
- window creation without position args; renderer logical size via
SDL_SetRenderLogicalPresentation(LETTERBOX); SDL_RenderTexture;
SDL_SaveBMP_IO frame dumps
- SDL_EVENT_* event scheme, flattened SDL_KeyboardEvent, float mouse
coords; clicks mapped with SDL_ConvertEventToRenderCoordinates, keeping
the Xwayland global-state cross-check from 260a2b3
- audio shim on the stream API (SDL_OpenAudioDeviceStream +
SDL_PutAudioStreamData) since SDL_QueueAudio is gone
- TTF_RenderText_Blended (explicit length); SDL3_ttf header layout
handled via __has_include (Ubuntu installs under SDL3_ttf/)
- e2e freeze-tint pixel assertions updated to the committed
diagonal-stripe pattern (stale since the freeze rework; pre-existing
failures at HEAD under SDL2), sampled away from the freeze text
Full suite green: 14 unit + 7 integration + 3 E2E journeys, 0 failures.
MissileCommand, MiataDrive, NetDeck build; CrtTerminal (missing sndBlip
declaration) and Lotus3 (sketch not in repo) fail identically at HEAD -
pre-existing, out of scope.
79 lines
2.2 KiB
C++
79 lines
2.2 KiB
C++
/**
|
|
* 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 <SDL3/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;
|
|
bool tx_desc_auto_clear;
|
|
};
|
|
|
|
struct i2s_pin_config_t {
|
|
int bck_io_num;
|
|
int ws_io_num;
|
|
int data_out_num;
|
|
int data_in_num;
|
|
};
|
|
|
|
inline SDL_AudioStream *&emuAudioStream()
|
|
{
|
|
static SDL_AudioStream *s = nullptr;
|
|
return s;
|
|
}
|
|
|
|
inline int i2s_driver_install(i2s_port_t, const i2s_config_t *cfg, int, void *)
|
|
{
|
|
// SDL3 audio: open a stream on the default playback device with our
|
|
// spec (conversion to the device format is automatic) and feed it from
|
|
// i2s_write() via SDL_PutAudioStreamData().
|
|
SDL_AudioSpec want {};
|
|
want.freq = (int)cfg->sample_rate;
|
|
want.format = SDL_AUDIO_S16;
|
|
want.channels = 1;
|
|
|
|
emuAudioStream() = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK,
|
|
&want, nullptr, nullptr);
|
|
if (!emuAudioStream()) {
|
|
std::printf("[emu] no audio device: %s (running silent)\n", SDL_GetError());
|
|
return ESP_FAIL;
|
|
}
|
|
SDL_ResumeAudioStreamDevice(emuAudioStream());
|
|
std::printf("[emu] audio open: %d Hz\n", want.freq);
|
|
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 (emuAudioStream()) SDL_PutAudioStreamData(emuAudioStream(), src, (int)size);
|
|
if (written) *written = size;
|
|
return ESP_OK;
|
|
}
|
|
|
|
inline void i2s_zero_dma_buffer(i2s_port_t) {}
|