Use 6502_65C02_functional_tests, and two bug fixes

- transfer operations should update n and z flags
 - TSX should transfer SP, not SR
This commit is contained in:
Takashi Toyoshima 2014-12-08 00:21:06 +09:00
parent 1f39658a0b
commit d0ad06c86a
4 changed files with 73 additions and 3 deletions

8
6502.S
View File

@ -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

View File

@ -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

58
ftest.c Normal file
View File

@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
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;
}

1
test.c
View File

@ -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);