From d0ad06c86a5a235476a3355ea04606ba43fcef02 Mon Sep 17 00:00:00 2001 From: Takashi Toyoshima Date: Mon, 8 Dec 2014 00:21:06 +0900 Subject: [PATCH] Use 6502_65C02_functional_tests, and two bug fixes - transfer operations should update n and z flags - TSX should transfer SP, not SR --- 6502.S | 8 ++++++-- Makefile | 9 ++++++++- ftest.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.c | 1 + 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 ftest.c diff --git a/6502.S b/6502.S index a8ee572..82978d1 100644 --- a/6502.S +++ b/6502.S @@ -645,7 +645,9 @@ .endm .macro _t from to - mov \to, \from + mov r0, \from + mov \to, r0 + _flag_nz adds PC, PC, #1 .endm @@ -1369,7 +1371,7 @@ opb9: // LDA - Absolute, Y _decode opba: // TSX - _t SR, RX + _t SP, RX _decode opbc: // LDY - Absolute, X @@ -1913,6 +1915,8 @@ op_table: .long opff .bss + .global cpu6502_pc +cpu6502_pc: r_pc: .long 0 r_a: .long 0 r_x: .long 0 diff --git a/Makefile b/Makefile index b8b2d42..f277d99 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ SPEED = 115200 #SPEED = 9600 CLOCK = 12000 ROM = applebasic +//ROM = apple2o ROMOBJ = $(ROM).o ROMFLAG = -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata FRAMEPTR= -fomit-frame-pointer @@ -40,7 +41,13 @@ $(ROM).rom: # Test binary that runs on qemu user mode emulation for testing test: 6502.S test.c - $(CC) -mthumb -static $(FRAMEPTR) test.c 6502.S -o test && qemu-arm test + $(CC) -mthumb -static $(FRAMEPTR) test.c 6502.S -o test && \ + qemu-arm test + +# Test binary that runs on qemu user mode emulation for functional tests +ftest: 6502.S ftest.c + $(CC) -mthumb -static $(FRAMEPTR) ftest.c 6502.S -o ftest && \ + qemu-arm ftest # Assume a CQ Mary comaptible board. run: $(APP).bin diff --git a/ftest.c b/ftest.c new file mode 100644 index 0000000..9283aa0 --- /dev/null +++ b/ftest.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +static uint8_t mem[0x10000]; +extern uint32_t cpu6502_pc; + +void prn(int c) { + uint8_t fp; + __asm__("movs %0, r12": "=r"(fp)); + fprintf(stderr, "### $%02x ###\n", c); + fflush(stderr); + __asm__("movs r12, %0":: "r"(fp)); +} + +void cpu6502_dump( + uint16_t pc, uint8_t a, uint8_t x, uint8_t y, uint8_t sp, uint8_t sr) { + uint8_t fp; + __asm__("movs %0, r12": "=r"(fp)); + fprintf(stderr, "*** dump *** PC=$%04x A=$%02x X=$%02x Y=$%02x SP=$%02x " + "NV-B_DIZC=%d%d-%d_%d%d%d%d\n", + pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1, + (sr >> 3) & 1, (sr >> 2) & 1, (sr >> 1) & 1, sr & 1); + fflush(stderr); + __asm__("movs r12, %0":: "r"(fp)); +} + +uint8_t cpu6502_load(uint16_t addr) { + uint8_t fp; + uint8_t result = 0; + __asm__("movs %0, r12": "=r"(fp)); + result = mem[addr]; + fprintf(stderr, "load $%04x => $%02x\n", addr, result); + fflush(stderr); + __asm__("movs r12, %0":: "r"(fp)); + return result; +} + +void cpu6502_store(uint16_t addr, uint8_t data) { + uint8_t fp; + __asm__("movs %0, r12": "=r"(fp)); + mem[addr] = data; + fprintf(stderr, "store $%04x <= $%02x\n", addr, data); + fflush(stderr); + __asm__("movs r12, %0":: "r"(fp)); +} + +int main(int argc, char** argv) { + FILE* fp = fopen("6502_functional_test.bin", "rb"); + fread(mem, 1, 0x10000, fp); + fclose(fp); + cpu6502_reset(); + cpu6502_pc = 0x400; + fprintf(stderr, "quit: $%04x\n", cpu6502_run()); + return 0; +} + diff --git a/test.c b/test.c index 068373b..46be5be 100644 --- a/test.c +++ b/test.c @@ -100,6 +100,7 @@ void cpu6502_store(uint16_t addr, uint8_t data) { int main(int argc, char** argv) { FILE* fp = fopen("applebasic.rom", "rb"); + //FILE* fp = fopen("apple2o.rom", "rb"); memset(mem, 0, 0x10000); fread(&mem[0xd000], 1, 0x3000, fp); fclose(fp);