# Paper-S3 device emulator (from scratch). Only external dep: Cocoa (added later # for the window). Pure C core for now. CC := xcrun clang # The Command Line Tools SDK on this Mac is malformed (arm64e tbd); Xcode's is fine. SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk CFLAGS := -O2 -g -isysroot $(SDK) -Wall -Wno-unused SRCS := src/main.c src/mem.c src/image.c src/mmio.c src/xtensa.c src/elf.c src/panel.c src/co5300.c src/sdcard.c # GUI build reuses the same core (minus main.c's CLI main()) + a Cocoa front-end. GUISRCS := src/main.c src/mem.c src/image.c src/mmio.c src/xtensa.c src/elf.c src/panel.c src/co5300.c src/sdcard.c src/gui.m emu: $(SRCS) $(CC) $(CFLAGS) $(SRCS) -o emu emu-gui: $(GUISRCS) $(CC) $(CFLAGS) -DEMU_GUI -fobjc-arc $(GUISRCS) -framework Cocoa -o emu-gui # --- The self-test: the same core on a tiny bare-metal payload, used for the # browser (WASM) hero. The core files below are the emulator minus the CLI # main.c/gui.m; wasm.c provides the front-end (and a native test main). XGCC := ../.tooling/espressif/tools/xtensa-esp-elf/esp-14.2.0_20251107/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc CORE := src/wasm.c src/mem.c src/mmio.c src/xtensa.c src/elf.c src/panel.c src/co5300.c src/image.c # Build the bare-metal self-test binary with the ESP xtensa toolchain. selftest/wtest.elf: selftest/start.S selftest/wtest.c selftest/wtest.ld $(XGCC) -mtext-section-literals -ffreestanding -nostdlib -Os -Wall \ -T selftest/wtest.ld selftest/start.S selftest/wtest.c -o $@ # Native harness: run the self-test under the core and dump the panel to a PPM. selftest-native: selftest/wtest.elf $(CORE) $(CC) $(CFLAGS) -DEMU_SELFTEST_MAIN $(CORE) -o selftest/selftest # WebAssembly build of the emulator running the self-test (needs emscripten). wasm: selftest/wtest.elf $(CORE) emcc -O2 $(CORE) --embed-file selftest/wtest.elf@wtest.elf \ -s MODULARIZE=1 -s EXPORT_NAME=EmuSelfTest \ -s EXPORTED_FUNCTIONS='["_emu_boot","_emu_step","_emu_screen","_emu_width","_emu_height","_emu_pc","_malloc","_free"]' \ -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","HEAPU8"]' \ -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=web,node -o esp32emu.js clean: rm -f emu emu-gui selftest/selftest selftest/wtest.elf esp32emu.js esp32emu.wasm .PHONY: clean selftest-native wasm