Play the emulated audio, and build for Windows

Two things, both about being able to check the emulator's work rather than
infer it.

Sound. The samples a payload pushes through the ADMAIF PIO port were being
discarded; now they are written to last_audio.wav and played on the host.
Each FIFO word is already a stereo frame, so the capture needs only a header.
The take is played after it is complete rather than streamed while it is
produced: the emulator generates samples in bursts and stalls entirely
between phrases while the payload talks to the codec over I2C, so a live
stream underruns wherever the producer falls behind the sound card, heard as
flicker. Queueing the finished buffer removes the producer from the timing
path. The rate comes from the I2S_TIMING the payload programmed, not a
nominal 48 kHz, or the melody replays at the wrong pitch.

Windows. Cross-compiled in a container, since neither dependency has a MinGW
package. Three things had to be fixed to get there, none of them findable
without actually trying it:

  - mingw GCC 13 hits an internal compiler error on unicorn's
    qemu/softmmu/memory.c at -O2, so unicorn is built at -O1.
  - pread/pwrite are POSIX and absent on MinGW. The SD/eMMC image access now
    has a seek-then-read shim, which is equivalent here because the emulated
    storage is only touched from the CPU thread.
  - SDL renames main on Windows, so SDL2main must be linked before SDL2 with
    SDL_MAIN_HANDLED, and unicorn's threads need winpthread.

The .exe is static: one file, no DLLs beside it. Verified running natively -
it emulates a full hwtest sweep and plays the melody through WASAPI.

CI covers both platforms, and a third job runs the .exe on a Windows runner,
because a cross-build only proves it links. Builds on push and PR, not just
tags: the Windows build broke in three separate ways the first time it was
attempted, and a Linux-only workflow would have shown none of them.
This commit is contained in:
Baptiste MOINE committed 2026-08-20 10:05:33 +02:00
1 parent 6782304549
commit 390d64abe6
6 files changed
+404 -4

No files matched your search

+35 -2
View File
@@ -37,10 +37,43 @@ ifneq ($(SDL2_CFLAGS),)
LIBS = -lunicorn $(SDL2_LIBS) -lpthread
endif
.PHONY: all clean
# ---- Windows cross-build ---------------------------------------------------
#
# `make windows` builds rcm_emu.exe with the MinGW toolchain. Both deps come
# from the cross sysroot the container prepares (see Dockerfile.windows):
# SDL2 from its official MinGW devel tree, unicorn built from source.
#
# Statically linked on purpose. A .exe that needs libstdc++, libgcc, winpthread
# and SDL2.dll beside it is not something anyone wants to download from a
# release page, and SDL2 is linked static here too so there is exactly one
# file to ship.
#
# SDL on Windows renames main to SDL_main and supplies its own entry point, so
# the link order -lmingw32 -lSDL2main -lSDL2 matters and SDL2main must come
# before SDL2. The trailing Windows libraries are what static SDL2 and unicorn
# pull in: without them the link fails on missing WinMM / OLE / socket symbols.
WIN_CXX = x86_64-w64-mingw32-g++
WIN_OUT = rcm_emu.exe
WIN_OBJS = $(SRCS:.cpp=.win.o)
WIN_CXXFLAGS = -Wall -g -O2 -std=c++17 -MMD -MP -I. -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I/usr/x86_64-w64-mingw32/include/SDL2 -DSDL_MAIN_HANDLED
WIN_LIBS = -lmingw32 -lSDL2main -lSDL2 -lunicorn -lpthread -lwinmm -limm32 -lole32 -loleaut32 -lversion -lsetupapi -lcfgmgr32 -lgdi32 -lrpcrt4 -lws2_32 -luuid -lshell32 -ladvapi32 -luser32
WIN_LDFLAGS = -static -static-libgcc -static-libstdc++
.PHONY: all clean windows
all: $(OUTPUT)
windows: $(WIN_OUT)
$(WIN_OUT): $(WIN_OBJS)
$(WIN_CXX) $(WIN_LDFLAGS) -o $@ $^ $(WIN_LIBS)
@echo " built $@ ($$(stat -c%s $@) bytes)"
%.win.o: %.cpp
$(WIN_CXX) $(WIN_CXXFLAGS) -c -o $@ $<
-include $(WIN_OBJS:.o=.d)
$(OUTPUT): $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -52,4 +85,4 @@ $(OUTPUT): $(OBJS)
-include $(OBJS:.o=.d)
clean:
rm -f $(OUTPUT) $(OBJS) $(OBJS:.o=.d)
rm -f $(OUTPUT) $(OBJS) $(OBJS:.o=.d) \n $(WIN_OUT) $(WIN_OBJS) $(WIN_OBJS:.o=.d)