Add in-emulator UART console window (C key)

This commit is contained in:
Baptiste MOINE committed 2026-05-03 09:42:43 +02:00
1 parent e527872acb
commit ce9d2734f1
4 files changed
+338 -17

No files matched your search

+28 -16
View File
@@ -1,5 +1,6 @@
#include "sdl_display.h"
#include "config_window.h"
#include "console_window.h"
#include "../emu_state.h"
#include "../t210/memory_map.h"
@@ -8,20 +9,20 @@
#include <cstring>
#include <vector>
// Some SDL events are not window-targeted (e.g. SDL_QUIT). Returns true only
// for events that carry a windowID matching the config window.
static bool event_targets_config_window(const SDL_Event &ev) {
Uint32 cfg_id = config_window_id();
if (cfg_id == 0) return false;
// Returns true only for events that carry a windowID matching the given
// auxiliary window's id. Generic so the event router can use it for both
// the config window (M key) and the UART console (C key).
static bool event_targets_window(const SDL_Event &ev, Uint32 wid) {
if (wid == 0) return false;
switch (ev.type) {
case SDL_WINDOWEVENT: return ev.window.windowID == cfg_id;
case SDL_WINDOWEVENT: return ev.window.windowID == wid;
case SDL_KEYDOWN:
case SDL_KEYUP: return ev.key.windowID == cfg_id;
case SDL_TEXTINPUT: return ev.text.windowID == cfg_id;
case SDL_KEYUP: return ev.key.windowID == wid;
case SDL_TEXTINPUT: return ev.text.windowID == wid;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: return ev.button.windowID == cfg_id;
case SDL_MOUSEMOTION: return ev.motion.windowID == cfg_id;
case SDL_MOUSEWHEEL: return ev.wheel.windowID == cfg_id;
case SDL_MOUSEBUTTONUP: return ev.button.windowID == wid;
case SDL_MOUSEMOTION: return ev.motion.windowID == wid;
case SDL_MOUSEWHEEL: return ev.wheel.windowID == wid;
default: return false;
}
}
@@ -404,17 +405,22 @@ bool sdl_display_poll_events(EmuState *state, uc_engine *uc) {
// close be handled by its own handler below (which just hides it).
if (event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_CLOSE &&
event.window.windowID != config_window_id()) {
event.window.windowID != config_window_id() &&
event.window.windowID != console_window_id()) {
state->running = false;
return false;
}
// Route events targeting the hardware config window to ImGui and skip
// the main-window handlers below (so e.g. typing into a hex input doesn't
// also press POWER).
if (event_targets_config_window(event)) {
// Route events targeting an auxiliary ImGui window to its own handler
// and skip the main-window handlers below (so typing into a hex input
// doesn't also press POWER, etc.).
if (event_targets_window(event, config_window_id())) {
config_window_handle_event(event);
continue;
}
if (event_targets_window(event, console_window_id())) {
console_window_handle_event(event);
continue;
}
// ---- Mouse → FTS4 touchscreen events ----
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
uint16_t px = 0, py = 0;
@@ -510,6 +516,12 @@ bool sdl_display_poll_events(EmuState *state, uc_engine *uc) {
printf("[diag] Swizzle Override: %d (-1=Auto, 0=Pitch, 2=Block)\n",
g_swizzle_override);
break;
case SDLK_c:
console_window_toggle();
printf("[ui] UART console %s\n",
console_window_is_visible() ? "OPEN" : "CLOSED");
fflush(stdout);
break;
case SDLK_m:
config_window_toggle();
printf("[diag] Config window %s\n",