Split the machine from its front end, and add Voyager
The Segan Voyager is the same SplitBit with a screen and a speaker instead of a terminal, and this is the rung that makes there be two of them at all. Everything that is actually the machine - the CPU, the controller, the devices, the run loop, the reporting - moves to machine.c, and each front end brings one file of its own. emulator.c is now sixty lines of argument handling and a three line loop. The machine runs in SLICES rather than to completion, because that is the cut a window needs: run a slice, present a frame, run another. A terminal runs slices until the machine stops. Both loops are three lines, which is why the cut is there rather than anywhere else. At this stage Voyager's window is empty. There is no video device yet and inventing a temporary way to draw would mean building something to throw away. PLAIN MAKE STILL WORKS WITH NO GRAPHICS LIBRARY. Raylib is probed by compiling and linking against it rather than by looking for a file, because a header with no library behind it passes a file check and then fails at link time. Where it is missing, make says so once and builds everything else - the machine, the assembler, the disk tool, the linter and the whole suite. A project about a small understandable CPU should not need OpenGL to run its tests. That nearly broke here: make strict globs Source/Emulator/*.c, so it would have tried to compile voyager.c and failed on precisely the machines the split exists to support, and this machine has Raylib so nothing would have caught it. Tests/voyager.sh runs the WHOLE MANIFEST through Voyager and holds it to the recorded results SplitBit is held to. Not that the two look alike: that one satisfies every recording the other does, byte for byte, exit status included. It reuses run.sh, which now takes the machine from SPLITBIT_EMULATOR, rather than keeping a second copy of the runner that would drift. Voyager not being built is not a failure - it says so and passes. Verified both ways. Made Voyager print one extra line, and 114 of 165 failed: exactly the tests that run the emulator, with the 51 assemble-only and xfail cases correctly untouched. Removed the binary, and the script skipped. Built with HAVE_RAYLIB=no, and everything else still built and checked clean. --headless is taken out of the arguments in voyager.c rather than in the shared parser, which should not learn about a window only one binary has. It exists so the suite can run this binary at all: a front end that could only be exercised by a person looking at it would be a front end nothing checks. loadFile takes a const char * now, which it always should have. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
4c3eac8d9c
commit
e3ef25e3b3
@@ -33,24 +33,63 @@ SRC_DIR_LINT = Source/Linter
|
||||
OBJ_DIR = Object
|
||||
|
||||
# Source files
|
||||
EMU_SRCS = emulator.c io.c controller.c utility.c cpu.c bootstrap.c assembly.c rom.c
|
||||
#
|
||||
# MACHINE_SRCS is the machine itself, and both front ends link all of it. What separates
|
||||
# SplitBit from Voyager is one file each: a terminal or a window. Anything that drifts out
|
||||
# of the shared list and into one of those is behaviour the other does not have, which is
|
||||
# the thing this split exists to prevent.
|
||||
MACHINE_SRCS = machine.c io.c controller.c utility.c cpu.c bootstrap.c assembly.c rom.c
|
||||
EMU_SRCS = emulator.c $(MACHINE_SRCS)
|
||||
VOY_SRCS = voyager.c $(MACHINE_SRCS)
|
||||
ASM_SRCS = Assembler.c assembly.c firstPass.c Assm-util.c secondPass.c
|
||||
DSK_SRCS = SplitDisk.c
|
||||
LINT_SRCS = Linter.c
|
||||
|
||||
EMU_OBJS = $(EMU_SRCS:%.c=$(OBJ_DIR)/%.o)
|
||||
VOY_OBJS = $(VOY_SRCS:%.c=$(OBJ_DIR)/%.o)
|
||||
ASM_OBJS = $(ASM_SRCS:%.c=$(OBJ_DIR)/%.o)
|
||||
DSK_OBJS = $(DSK_SRCS:%.c=$(OBJ_DIR)/%.o)
|
||||
LINT_OBJS = $(LINT_SRCS:%.c=$(OBJ_DIR)/%.o) $(OBJ_DIR)/assembly.o
|
||||
|
||||
# Output binary names
|
||||
EMU_TARGET = SplitBit
|
||||
VOY_TARGET = Voyager
|
||||
ASM_TARGET = Assembler
|
||||
DSK_TARGET = SplitDisk
|
||||
LINT_TARGET = SplitLint
|
||||
|
||||
# Default target: build the emulator and its three host-side tools.
|
||||
all: $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET)
|
||||
# ---- Whether this machine can build Voyager ----
|
||||
#
|
||||
# PROBED BY BUILDING SOMETHING, not by looking for a file. A header that is present with no
|
||||
# library behind it, or a library that needs flags this does not pass, would both pass a
|
||||
# file check and then fail at link time, which is a much worse way to find out. If this
|
||||
# compiles and links, so will Voyager.
|
||||
#
|
||||
# pkg-config first because that is what a packaged Raylib provides, and a bare -lraylib
|
||||
# after it because a Raylib built from source usually does not install one.
|
||||
RAYLIB_CFLAGS := $(shell pkg-config --cflags raylib 2>/dev/null)
|
||||
RAYLIB_LIBS := $(shell pkg-config --libs raylib 2>/dev/null)
|
||||
ifeq ($(strip $(RAYLIB_LIBS)),)
|
||||
RAYLIB_LIBS := -lraylib -lm
|
||||
endif
|
||||
HAVE_RAYLIB := $(shell printf '#include <raylib.h>\nint main(void){return (int)GetTime();}\n' \
|
||||
| $(CC) -x c - -o /dev/null $(RAYLIB_CFLAGS) $(RAYLIB_LIBS) 2>/dev/null \
|
||||
&& echo yes)
|
||||
|
||||
# Default target: the machine, its three host-side tools, and Voyager where it can be built.
|
||||
#
|
||||
# VOYAGER IS NOT IN THE HARD LIST. Everything below it - the assembler, the disk tool, the
|
||||
# linter, the whole test suite - has to build on a machine with no graphics library at all,
|
||||
# because a project about a small understandable CPU should not need OpenGL to run its
|
||||
# tests. Where Raylib is missing, 'make' says so once and builds everything else.
|
||||
TOOLS = $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET)
|
||||
|
||||
ifeq ($(HAVE_RAYLIB),yes)
|
||||
all: $(TOOLS) $(VOY_TARGET)
|
||||
else
|
||||
all: $(TOOLS)
|
||||
@echo "Raylib was not found, so Voyager was not built. Everything else is here."
|
||||
endif
|
||||
|
||||
# ---- The ROM the machine wakes up in ----
|
||||
#
|
||||
@@ -86,6 +125,15 @@ $(OBJ_DIR)/rom.o: $(SRC_DIR_EMU)/rom.c $(SRC_DIR_EMU)/rom.h
|
||||
$(EMU_TARGET): $(EMU_OBJS)
|
||||
$(CC) $(CFLAGS) -o $(EMU_TARGET) $(EMU_OBJS)
|
||||
|
||||
# Voyager: the same machine with a screen and a speaker. Its own object for the front end,
|
||||
# and the shared ones for everything that is actually the machine.
|
||||
$(VOY_TARGET): $(VOY_OBJS)
|
||||
$(CC) $(CFLAGS) -o $(VOY_TARGET) $(VOY_OBJS) $(RAYLIB_LIBS)
|
||||
|
||||
$(OBJ_DIR)/voyager.o: $(SRC_DIR_EMU)/voyager.c
|
||||
mkdir -p $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) $(POSIXFLAGS) $(RAYLIB_CFLAGS) $(DEPFLAGS) -c $< -o $@
|
||||
|
||||
# Assembler binary
|
||||
$(ASM_TARGET): $(ASM_OBJS)
|
||||
$(CC) $(CFLAGS) -o $(ASM_TARGET) $(ASM_OBJS)
|
||||
@@ -129,19 +177,29 @@ $(OBJ_DIR)/%.o: $(SRC_DIR_ASM)/%.c
|
||||
# that did not reach far enough, which the ordinary -Os build never saw.
|
||||
STRICT = -std=c11 -pedantic -Wall -Wextra -Werror $(POSIXFLAGS)
|
||||
|
||||
#
|
||||
# VOYAGER IS CHECKED SEPARATELY, and only where Raylib is. It includes raylib.h, so putting
|
||||
# it in the loop below would make 'make test' fail on exactly the machines the two-binary
|
||||
# split exists to support - and it would not be noticed here, where Raylib is installed.
|
||||
strict:
|
||||
@for source in $(SRC_DIR_EMU)/*.c $(SRC_DIR_ASM)/*.c $(SRC_DIR_DSK)/*.c $(SRC_DIR_LINT)/*.c; do \
|
||||
case "$$source" in *voyager.c) continue ;; esac; \
|
||||
$(CC) $(STRICT) -c $$source -o /dev/null || exit 1; \
|
||||
done
|
||||
ifeq ($(HAVE_RAYLIB),yes)
|
||||
@$(CC) $(STRICT) $(RAYLIB_CFLAGS) -c $(SRC_DIR_EMU)/voyager.c -o /dev/null
|
||||
endif
|
||||
@echo "The sources build clean under -std=c11 -pedantic."
|
||||
|
||||
# Run the test suite against the programs in Programs/
|
||||
test: $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET) strict
|
||||
test: all strict
|
||||
@./Tests/lint.sh
|
||||
@echo
|
||||
@echo
|
||||
@./Tests/run.sh
|
||||
@echo
|
||||
@./Tests/voyager.sh
|
||||
@echo
|
||||
@./Tests/disk.sh
|
||||
@echo
|
||||
@./Tests/cycles.sh
|
||||
@@ -183,6 +241,8 @@ sanitize:
|
||||
@echo
|
||||
@./Tests/run.sh
|
||||
@echo
|
||||
@./Tests/voyager.sh
|
||||
@echo
|
||||
@./Tests/disk.sh
|
||||
@echo
|
||||
@./Tests/cycles.sh
|
||||
@@ -208,7 +268,7 @@ clean:
|
||||
rm -rf $(OBJ_DIR)
|
||||
rm -rf Tests/build
|
||||
rm -f $(SRC_DIR_EMU)/rom.c
|
||||
rm -f $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET)
|
||||
rm -f $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET) $(VOY_TARGET)
|
||||
|
||||
# Install compiled binaries
|
||||
install: $(EMU_TARGET) $(ASM_TARGET) $(DSK_TARGET) $(LINT_TARGET)
|
||||
|
||||
Reference in New Issue
Block a user