From 09a92740e9e667928e87d447952cd5c7e37c457a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Thu, 2 Feb 2017 14:46:10 +0100 Subject: [PATCH] Add test case for assembling functions. --- test/Makefile | 5 ++++- test/test_assemble.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/test_assemble.c diff --git a/test/Makefile b/test/Makefile index 762d9e3..59d1a32 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,7 @@ VASM=vasm6502_std VASMFLAGS=-Fbin -c02 UTILS=utils.o -TESTS=test_bus test_emulation test_stepping +TESTS=test_bus test_emulation test_stepping test_assemble TESTROMS:=$(addsuffix .rom,$(basename $(wildcard *.s))) all : $(TESTS) $(TESTROMS) @@ -19,6 +19,9 @@ test_bus : test_bus.o $(UTILS) $(RK6502LIB) test_emulation : test_emulation.o $(UTILS) $(RK6502LIB) $(CC) -o $@ $(LDFLAGS) $< $(UTILS) $(RK6502LIB) +test_assemble : test_assemble.o $(UTILS) $(RK6502LIB) + $(CC) -o $@ $(LDFLAGS) $< $(UTILS) $(RK6502LIB) + %.rom : %.s $(VASM) $(VASMFLAGS) -o $@ $< diff --git a/test/test_assemble.c b/test/test_assemble.c new file mode 100644 index 0000000..0c24915 --- /dev/null +++ b/test/test_assemble.c @@ -0,0 +1,49 @@ +#include + +#include +#include +#include +#include + +#include "bus.h" +#include "rk65c02.h" +#include "instruction.h" +#include "utils.h" + +ATF_TC_WITHOUT_HEAD(asm_single); +ATF_TC_BODY(asm_single, tc) +{ + rk65c02emu_t e; + bus_t b; + uint8_t *asmbuf; + uint8_t bsize; + uint16_t caddr; + + b = bus_init(); + e = rk65c02_init(&b); + + caddr = ROM_LOAD_ADDR; + e.regs.PC = ROM_LOAD_ADDR; + + ATF_REQUIRE(assemble_single_implied(&asmbuf, &bsize, "nop")); + ATF_CHECK(asmbuf[0] == 0xEA); /* check if nop really */ + ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); + free(asmbuf); + caddr += bsize; + + ATF_REQUIRE(assemble_single_implied(&asmbuf, &bsize, "stp")); + ATF_CHECK(asmbuf[0] == 0xDB); /* check if stp really */ + ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); + free(asmbuf); + caddr += bsize; + + rk65c02_start(&e); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, asm_single); + + return (atf_no_error()); +} +