Once the opcodes are all implemented, we need to test that the resulting “virtual processor” emulates everything correctly.
We already saw previously that we can assemble some source code, feed the emulator with the resulting binary and check the disassembled output.
I also modified the 65C02 assembler so it can generate an additional symbol file.
This then helps the emulator to build a table and display the corresponding labels in the disassembled code.
Ways of testing
We can check the state of the processor while we are running the program step by step (registers, program counter, status register, stack, and memory are displayed).
Or we can check the resulting output and memory values once it has been executed. Since the processor’s memory is an array of bytes in our emulator, it can easily be saved to a file, and thus be verified with the expected values.
But one of the most profitable things is to design a test program.
We just have to write the source code, assemble it and then we run it in the emulator.
We can use all the possible instructions to write functional tests.
For instance, one test could be a branching test:
; functional test ; small branch offset ORG $100 LDX #5 JMP bra_test back_ok: LDY #5 BNE forward JMP bra_err ; forward landing zone DEY DEY DEY DEY DEY forward: DEY DEY DEY DEY DEY BEQ bra_ok JMP bra_err ; backward landing zone DEX DEX DEX DEX DEX back: DEX DEX DEX DEX DEX BEQ back_ok JMP bra_err bra_test: BNE back bra_err: BRK bra_ok: