Files
Matthias Endler 9ff04c75f1 Add interrupt handling (NMI, IRQ) and WAI/STP wait states (#122)
Implements hardware interrupt support following the W65C02S datasheet:

Interrupt handling:
- Add nmi_pending() and irq_pending() to Bus trait
- NMI: edge-triggered (falling edge detection)
- IRQ: level-triggered, maskable by I flag
- service_interrupt() pushes PC/status, sets I flag, jumps to vector

Wait states:
- Replace `halted: bool` with WaitState enum (Running,
  WaitingForInterrupt, WaitingForReset)
- WAI instruction waits for interrupt, resumes on IRQ or NMI
- STP instruction waits for reset

Helper methods:
- Add push_address() for pushing 16-bit addresses to stack
- Add set_word() to Bus trait for writing 16-bit values

Testing:
- Integrate Klaus2m5 interrupt test suite
- Add unit tests for IRQ, NMI, and WAI behavior
- Concurrent BRK+IRQ+NMI test disabled (hardware timing edge case)

References:
- W65C02S Datasheet, Section 3.4 (IRQB) and 3.6 (NMIB)
- Klaus2m5/6502_65C02_functional_tests

Closes #64
2026-02-06 17:16:13 +01:00

39 lines
1.2 KiB
Makefile

.PHONY: help
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+( +[a-zA-Z_-]+)*:.*?## / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# Test assembly binaries
TEST_ASSETS = tests/assets
INTERRUPT_TEST_SRC = $(TEST_ASSETS)/6502_interrupt_test.s
INTERRUPT_TEST_BIN = $(TEST_ASSETS)/6502_interrupt_test.bin
LINKER_CFG = $(TEST_ASSETS)/linker.cfg
.PHONY: build-test-bins
build-test-bins: $(INTERRUPT_TEST_BIN) ## Build test assembly binaries
$(INTERRUPT_TEST_BIN): $(INTERRUPT_TEST_SRC) $(LINKER_CFG)
@echo "Building interrupt test binary..."
ca65 -o $(INTERRUPT_TEST_SRC:.s=.o) $(INTERRUPT_TEST_SRC)
ld65 -C $(LINKER_CFG) -o $(INTERRUPT_TEST_BIN) $(INTERRUPT_TEST_SRC:.s=.o)
@rm -f $(INTERRUPT_TEST_SRC:.s=.o)
.PHONY: test
test: build-test-bins ## Run tests
cargo test
.PHONY: clean
clean: ## Clean up
cargo clean
.PHONY: format fmt
format fmt: ## Format code
cargo fmt
.PHONY: lint
lint: ## Run linter
cargo clippy --all-targets --all-features -- -D warnings
.PHONY: lint-fix
lint-fix: ## Run linter; apply fixes
cargo clippy --all-targets --all-features --allow-dirty --fix -- -D warnings