Skip to content

Commit

Permalink
Merge pull request #13 from matushorvath/rename-tests
Browse files Browse the repository at this point in the history
Rename func_tests to func_test
  • Loading branch information
matushorvath authored Mar 3, 2024
2 parents 7b39d65 + 633cb9c commit 3bce59e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ endef

# Build
.PHONY: build
build: build-prep $(BINDIR)/vm6502.input $(BINDIR)/msbasic.input $(BINDIR)/func_tests.input
build: build-prep $(BINDIR)/vm6502.input $(BINDIR)/msbasic.input $(BINDIR)/func_test.input

.PHONY: build-prep
build-prep:
mkdir -p "$(BINDIR)" "$(OBJDIR)"

# Test
.PHONY: test
test: build msbasic_test func_tests
test: build msbasic_test func_test

.PHONY: func_tests
func_tests: $(BINDIR)/func_tests.input
$(ICVM) $(BINDIR)/func_tests.input < /dev/null
.PHONY: func_test
func_test: $(BINDIR)/func_test.input
$(ICVM) $(BINDIR)/func_test.input < /dev/null

.PHONY: msbasic_test
msbasic_test: $(BINDIR)/msbasic.input
Expand Down Expand Up @@ -85,12 +85,12 @@ $(BINDIR)/msbasic.input: $(addprefix $(OBJDIR)/, $(MSBASIC_OBJS)) $(LIBXIB)
$(OBJDIR)/msbasic_binary.o: $(MSBASICDIR)/tmp/vm6502.bin $(BINDIR)/bin2obj.input
$(run-bin2obj)

FUNC_TESTS_OBJS = $(BASE_OBJS) func_tests_callback.o binary.o func_tests_header.o func_tests_binary.o
FUNC_TEST_OBJS = $(BASE_OBJS) func_test_callback.o binary.o func_test_header.o func_test_binary.o

$(BINDIR)/func_tests.input: $(addprefix $(OBJDIR)/, $(FUNC_TESTS_OBJS)) $(LIBXIB)
$(BINDIR)/func_test.input: $(addprefix $(OBJDIR)/, $(FUNC_TEST_OBJS)) $(LIBXIB)
$(run-ld)

$(OBJDIR)/func_tests_binary.o: $(FUNCTESTDIR)/bin_files/6502_functional_test.bin $(BINDIR)/bin2obj.input
$(OBJDIR)/func_test_binary.o: $(FUNCTESTDIR)/bin_files/6502_functional_test.bin $(BINDIR)/bin2obj.input
$(run-bin2obj)

GEN_BITS_OBJS = gen_bits.o
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Now you can the `msbasic.input` Intcode image. Please substitute the correct pat
$ ICDIR=~/xzintbit MSBASICDIR=~/msbasic FUNCTESTDIR=~/6502_65C02_functional_tests make test
```

The functional tests take a minute or two to finish. If the build process looks frozen and the last output line mentions `func_tests.input`, you're probably still waiting for the tests. You can skip the tests by running a plain `make` instead of `make test`.
The functional test takes a minute or two to finish. If the build process looks frozen and the last output line mentions `func_test.input`, you're probably still waiting for the test. You can skip the test by running a plain `make` instead of `make test`.

Now you can execute the newly built image:
```sh
Expand All @@ -45,7 +45,7 @@ You should now see the `MEMORY SIZE?` prompt from Microsoft Basic. Enter a reaso
## Q & A

Q: How complete is the 6502 emulation?
A: All officially documented instructions are emulated. The virtual machine passes [6502 functional tests](https://github.com/amb5l/6502_65C02_functional_tests).
A: All officially documented instructions are emulated. The virtual machine passes the basic [6502 functional test](https://github.com/amb5l/6502_65C02_functional_tests/blob/master/6502_functional_test.a65).

Q: Why?
A: Just for fun.
46 changes: 23 additions & 23 deletions src/func_tests_callback.s → src/func_test_callback.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Callback function called by the VM for every 6502 instruction executed.

.EXPORT func_tests_callback
.EXPORT func_test_callback

# From state.s
.IMPORT reg_pc
Expand All @@ -10,49 +10,49 @@
.IMPORT print_str
.IMPORT halt_and_catch_fire

# We use this to detect a failed/successful test run and halt the VM, since the functional tests
# themselves never finish, they just enter a tight endless loop.
# We use this to detect a failed/successful test run and halt the VM, since the functional test
# itself never finishes, it just enters a tight endless loop.

# Previous value of the pc register
func_tests_prev_pc:
func_test_prev_pc:
db -1

# Test success address
# Can be found using bin_files/6502_functional_test.lst, search for "test passed, no errors"
.SYMBOL SUCCESS_ADDRESS 13417 # 0x3469

func_tests_callback:
func_test_callback:
.FRAME tmp # returns tmp
arb -1

# Have we reached the successful end of tests?
# Have we reached the successful end of the test?
eq [reg_pc], SUCCESS_ADDRESS, [rb + tmp]
jnz [rb + tmp], func_tests_callback_passed
jnz [rb + tmp], func_test_callback_passed

# Are we in a tight loop?
eq [reg_pc], [func_tests_prev_pc], [rb + tmp]
jnz [rb + tmp], func_tests_callback_failed
eq [reg_pc], [func_test_prev_pc], [rb + tmp]
jnz [rb + tmp], func_test_callback_failed

# Save previous pc value
add [reg_pc], 0, [func_tests_prev_pc]
add [reg_pc], 0, [func_test_prev_pc]

# Return 1 to keep running
add 1, 0, [rb + tmp]
jz 0, func_tests_callback_done
jz 0, func_test_callback_done

func_tests_callback_passed:
func_test_callback_passed:
# Successful test run
add func_tests_passed, 0, [rb - 1]
add func_test_passed, 0, [rb - 1]
arb -1
call print_str

# Return 0 to halt
add 0, 0, [rb + tmp]
jz 0, func_tests_callback_done
jz 0, func_test_callback_done

func_tests_callback_failed:
func_test_callback_failed:
# Failed test run
add func_tests_failed_start, 0, [rb - 1]
add func_test_failed_start, 0, [rb - 1]
arb -1
call print_str

Expand All @@ -61,7 +61,7 @@ func_tests_callback_failed:
arb -2
call print_num_radix

add func_tests_failed_end, 0, [rb - 1]
add func_test_failed_end, 0, [rb - 1]
arb -1
call print_str

Expand All @@ -70,17 +70,17 @@ func_tests_callback_failed:
# If you don't redirect stdin, this just waits for console input forever
call halt_and_catch_fire

func_tests_callback_done:
func_test_callback_done:
arb 1
ret 0
.ENDFRAME

# Strings
func_tests_passed:
db "Functional tests PASSED", 10, 0
func_tests_failed_start:
db "Functional tests FAILED (address: ", 0
func_tests_failed_end:
func_test_passed:
db "Functional test PASSED", 10, 0
func_test_failed_start:
db "Functional test FAILED (address: ", 0
func_test_failed_end:
db ")", 10, 0

.EOF
12 changes: 6 additions & 6 deletions src/func_tests_header.s → src/func_test_header.s
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This the header for the 6502 functional tests binary.
# It needs to be linked immediately after binary.o and immediately before the functional tests binary itself.
# This the header for the 6502 functional test binary.
# It needs to be linked immediately after binary.o and immediately before the functional test binary itself.

# The binary is available in git repository https://github.com/Klaus2m5/6502_65C02_functional_tests

# Start address for the functional tests binary
# Start address for the functional test binary
# Can be found using bin_files/6502_functional_test.lst, search for "Program start address is at"
db 1024 # 0x0400

# Load address for the functional tests binary
# Load address for the functional test binary
db 0

# Set up tracing
Expand All @@ -17,7 +17,7 @@
db 0

# Callback address
.IMPORT func_tests_callback
db func_tests_callback
.IMPORT func_test_callback
db func_test_callback

.EOF

0 comments on commit 3bce59e

Please sign in to comment.