Emulator: migrate SDL2 -> SDL3
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.
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
/**
|
||||
* TFT_eSPI shim: renders the same drawing calls into a 320x240 ABGR8888
|
||||
* framebuffer that the SDL2 host pushes to a window. Text uses SDL_ttf with
|
||||
* framebuffer that the SDL3 host pushes to a window. Text uses SDL3_ttf with
|
||||
* DejaVu fonts as stand-ins for the TFT_eSPI font set.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#if __has_include(<SDL3/SDL_ttf.h>) // upstream install layout
|
||||
#include <SDL3/SDL_ttf.h>
|
||||
#else // Debian/Ubuntu package layout
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
#endif
|
||||
#include "emu_gfx.h"
|
||||
#include <map>
|
||||
|
||||
@@ -179,10 +183,10 @@ public:
|
||||
if (!f) return;
|
||||
|
||||
SDL_Color col = sdlColor(fg);
|
||||
SDL_Surface *surf = TTF_RenderUTF8_Blended(f, s.s.c_str(), col);
|
||||
SDL_Surface *surf = TTF_RenderText_Blended(f, s.s.c_str(), s.s.size(), col);
|
||||
if (!surf) return;
|
||||
SDL_Surface *conv = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_ABGR8888, 0);
|
||||
SDL_FreeSurface(surf);
|
||||
SDL_Surface *conv = SDL_ConvertSurface(surf, SDL_PIXELFORMAT_ABGR8888);
|
||||
SDL_DestroySurface(surf);
|
||||
if (!conv) return;
|
||||
|
||||
int w = conv->w, h = conv->h;
|
||||
@@ -214,7 +218,7 @@ public:
|
||||
if ((p >> 24) > 0) emuGfx::fb[ty * emuGfx::W + tx] = p;
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(conv);
|
||||
SDL_DestroySurface(conv);
|
||||
emuGfx::dirty = true;
|
||||
}
|
||||
|
||||
@@ -252,7 +256,7 @@ private:
|
||||
"/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf",
|
||||
};
|
||||
const char *path = bold ? paths[1] : paths[0];
|
||||
TTF_Font *f = TTF_OpenFont(path, size);
|
||||
TTF_Font *f = TTF_OpenFont(path, (float)size);
|
||||
if (!f) {
|
||||
f = TTF_OpenFont(paths[2], size);
|
||||
if (!f) f = TTF_OpenFont(paths[3], size);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <SDL.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define ESP_OK 0
|
||||
#define ESP_FAIL -1
|
||||
@@ -39,28 +39,30 @@ struct i2s_pin_config_t {
|
||||
int data_in_num;
|
||||
};
|
||||
|
||||
inline SDL_AudioDeviceID &emuAudioDev()
|
||||
inline SDL_AudioStream *&emuAudioStream()
|
||||
{
|
||||
static SDL_AudioDeviceID d = 0;
|
||||
return d;
|
||||
static SDL_AudioStream *s = nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline int i2s_driver_install(i2s_port_t, const i2s_config_t *cfg, int, void *)
|
||||
{
|
||||
SDL_AudioSpec want {}, have {};
|
||||
// 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 = AUDIO_S16SYS;
|
||||
want.format = SDL_AUDIO_S16;
|
||||
want.channels = 1;
|
||||
want.samples = 512;
|
||||
want.callback = nullptr; // SDL_QueueAudio mode
|
||||
|
||||
emuAudioDev() = SDL_OpenAudioDevice(nullptr, 0, &want, &have, 0);
|
||||
if (emuAudioDev() == 0) {
|
||||
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_PauseAudioDevice(emuAudioDev(), 0);
|
||||
std::printf("[emu] audio open: %d Hz (requested %u)\n", have.freq, cfg->sample_rate);
|
||||
SDL_ResumeAudioStreamDevice(emuAudioStream());
|
||||
std::printf("[emu] audio open: %d Hz\n", want.freq);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ 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 (emuAudioStream()) SDL_PutAudioStreamData(emuAudioStream(), src, (int)size);
|
||||
if (written) *written = size;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Framebuffer shared between the TFT_eSPI shim and the SDL2 host.
|
||||
* Framebuffer shared between the TFT_eSPI shim and the SDL3 host.
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Emulator <-> shim shared state. Included by both the Arduino shim headers
|
||||
* and the SDL2 host (main.cpp).
|
||||
* and the SDL3 host (main.cpp).
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
Reference in New Issue
Block a user