From a72a2c087222b57ce254ca9ad143a2b58b4db851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Thu, 2 Feb 2017 21:16:31 +0100 Subject: [PATCH] Add test cases for 16-bit ADC and SBC. --- test/test_emulation.c | 46 +++++++++++++++++++++++++++++++++ test/test_emulation_adc_16bit.s | 21 +++++++++++++++ test/test_emulation_sbc_16bit.s | 21 +++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 test/test_emulation_adc_16bit.s create mode 100644 test/test_emulation_sbc_16bit.s diff --git a/test/test_emulation.c b/test/test_emulation.c index b5a7a3e..4058a3c 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -1036,9 +1036,54 @@ ATF_TC_BODY(emul_sbc, tc) } +ATF_TC_WITHOUT_HEAD(emul_adc_16bit); +ATF_TC_BODY(emul_adc_16bit, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + bus_write_1(&b, 0x62, 0x55); + bus_write_1(&b, 0x63, 0xAA); + bus_write_1(&b, 0x64, 0xAA); + bus_write_1(&b, 0x65, 0x55); + + ATF_REQUIRE(rom_start(&e, "test_emulation_adc_16bit.rom", tc)); + + ATF_CHECK(bus_read_1(&b, 0x66) == 0xFF); + ATF_CHECK(bus_read_1(&b, 0x67) == 0xFF); + rk65c02_dump_regs(&e); + +} + +ATF_TC_WITHOUT_HEAD(emul_sbc_16bit); +ATF_TC_BODY(emul_sbc_16bit, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + bus_write_1(&b, 0x62, 0xFF); + bus_write_1(&b, 0x63, 0xFF); + bus_write_1(&b, 0x64, 0xAA); + bus_write_1(&b, 0x65, 0x55); + ATF_REQUIRE(rom_start(&e, "test_emulation_sbc_16bit.rom", tc)); + + printf("%x %x\n", bus_read_1(&b, 0x66), bus_read_1(&b, 0x67)) ; + ATF_CHECK(bus_read_1(&b, 0x66) == 0x55); + ATF_CHECK(bus_read_1(&b, 0x67) == 0xAA); + rk65c02_dump_regs(&e); + +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, emul_and); + ATF_TP_ADD_TC(tp, emul_adc_16bit); ATF_TP_ADD_TC(tp, emul_bit); ATF_TP_ADD_TC(tp, emul_branch); ATF_TP_ADD_TC(tp, emul_cmp); @@ -1063,6 +1108,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, emul_txa_tya_tax_tay); ATF_TP_ADD_TC(tp, emul_sta); ATF_TP_ADD_TC(tp, emul_sbc); + ATF_TP_ADD_TC(tp, emul_sbc_16bit); ATF_TP_ADD_TC(tp, emul_sign_overflow); diff --git a/test/test_emulation_adc_16bit.s b/test/test_emulation_adc_16bit.s new file mode 100644 index 0000000..313fec5 --- /dev/null +++ b/test/test_emulation_adc_16bit.s @@ -0,0 +1,21 @@ +; 16-bit addition simple example by FMan/Tropyx +; modified by rkujawa + +.org 0xC000 +.set num1lo, 0x62 +.set num1hi, 0x63 +.set num2lo, 0x64 +.set num2hi, 0x65 +.set reslo, 0x66 +.set reshi, 0x67 + +; adds numbers 1 and 2, writes result to separate location + +add: clc ; clear carry + lda num1lo + adc num2lo + sta reslo ; store sum of LSBs + lda num1hi + adc num2hi ; add the MSBs using carry from + sta reshi ; the previous calculation + stp diff --git a/test/test_emulation_sbc_16bit.s b/test/test_emulation_sbc_16bit.s new file mode 100644 index 0000000..7709540 --- /dev/null +++ b/test/test_emulation_sbc_16bit.s @@ -0,0 +1,21 @@ +; 16-bit subtraction simple example by FMan/Tropyx +; modified by rkujawa + +.org 0xC000 +.set num1lo, 0x62 +.set num1hi, 0x63 +.set num2lo, 0x64 +.set num2hi, 0x65 +.set reslo, 0x66 +.set reshi, 0x67 + +; subtracts number 2 from number 1 and writes result out + +sub: sec ; set carry for borrow purpose + lda num1lo + sbc num2lo ; perform subtraction on the LSBs + sta reslo + lda num1hi ; do the same for the MSBs, with carry + sbc num2hi ; set according to the previous result + sta reshi + stp