# Copyright 2026 Leonardo Roman da Rosa # SPDX-License-Identifier: CERN-OHL-S-2.0 # # A convenience wrapper. run.py does the same thing and needs no make, which # matters on Windows where the FPGA toolchain lives but make usually does not. IVERILOG ?= iverilog VVP ?= vvp RTL := $(wildcard ../rtl/*.v) BUILD := build # The four directories run.py replays, in the same order: Sim2600's own wiring # of CLK2 first, then the console's. traces/local/ holds recordings of # commercial cartridges and is not committed. TRACES := $(wildcard traces/*.trace) $(wildcard traces/local/*.trace) \ $(wildcard traces/phi2/*.trace) $(wildcard traces/local/phi2/*.trace) # tb_board rebuilds PHI2 from the PHI0 the board makes itself, so it only means # anything against a trace recorded with the console's wiring. BOARD_TRACES := $(wildcard traces/phi2/*.trace) $(wildcard traces/local/phi2/*.trace) .PHONY: all test core board debug lint clean all: test test: core board $(BUILD)/tb_trace.vvp: tb_trace.v $(RTL) @mkdir -p $(BUILD) $(IVERILOG) -g2005 -I ../rtl -o $@ -s tb_trace $^ $(BUILD)/tb_board.vvp: tb_board.v $(RTL) @mkdir -p $(BUILD) $(IVERILOG) -g2005 -I ../rtl -o $@ -s tb_board $^ $(BUILD)/tb_debug.vvp: tb_debug.v $(RTL) @mkdir -p $(BUILD) $(IVERILOG) -g2005 -I ../rtl -o $@ -s tb_debug $^ # A testbench ends with $finish, so vvp exits 0 whether it printed PASS or # FAIL: the verdict has to be read out of the output, exactly as run.py does # it. Trusting vvp's exit code is how `make test` came to report success on a # core that failed every record of every trace. An empty trace list is a # failure too, for the same reason -- nothing checked is not the same as # nothing wrong. core: $(BUILD)/tb_trace.vvp @test -n "$(TRACES)" || { echo "no traces -- see README.md"; exit 1; }; \ fail=0; for t in $(TRACES); do \ echo "=== core: $$t ==="; \ $(VVP) $(BUILD)/tb_trace.vvp +trace=$$t +first=10 > $(BUILD)/run.log 2>&1 || fail=1; \ cat $(BUILD)/run.log; \ grep -q '^PASS' $(BUILD)/run.log || { echo "*** FAILED: $$t"; fail=1; }; \ done; rm -f $(BUILD)/run.log; exit $$fail board: $(BUILD)/tb_board.vvp @test -n "$(BOARD_TRACES)" || { echo "no console-wired traces in traces/phi2 -- see README.md"; exit 1; }; \ fail=0; for t in $(BOARD_TRACES); do \ echo "=== board: $$t ==="; \ $(VVP) $(BUILD)/tb_board.vvp +trace=$$t > $(BUILD)/run.log 2>&1 || fail=1; \ cat $(BUILD)/run.log; \ grep -q '^PASS' $(BUILD)/run.log || { echo "*** FAILED: $$t"; fail=1; }; \ done; rm -f $(BUILD)/run.log; exit $$fail debug: $(BUILD)/tb_debug.vvp $(VVP) $< +trace=$(TRACE) +align=$(ALIGN) +from=$(FROM) +to=$(TO) lint: $(IVERILOG) -g2005 -Wall -I ../rtl -o /dev/null -s tia $(RTL) clean: rm -rf $(BUILD)