2017-01-18 16:18:19 +00:00
|
|
|
#include <atf-c.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-01-19 10:49:05 +00:00
|
|
|
#include <stdbool.h>
|
2017-01-18 16:18:19 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bus.h"
|
|
|
|
#include "rk65c02.h"
|
|
|
|
|
2017-01-18 23:57:09 +00:00
|
|
|
#define ROM_LOAD_ADDR 0xC000
|
|
|
|
|
2017-01-19 10:49:05 +00:00
|
|
|
bool rom_start(rk65c02emu_t *, const char *);
|
|
|
|
|
|
|
|
bool
|
|
|
|
rom_start(rk65c02emu_t *e, const char *name)
|
|
|
|
{
|
|
|
|
e->regs.PC = ROM_LOAD_ADDR;
|
2017-01-20 09:41:56 +00:00
|
|
|
if(!bus_load_file(e->bus, ROM_LOAD_ADDR, name))
|
|
|
|
return false;
|
2017-01-19 10:49:05 +00:00
|
|
|
rk65c02_start(e);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:37:00 +00:00
|
|
|
ATF_TC_WITHOUT_HEAD(emul_lda);
|
|
|
|
ATF_TC_BODY(emul_lda, tc)
|
2017-01-18 16:18:19 +00:00
|
|
|
{
|
|
|
|
rk65c02emu_t e;
|
|
|
|
bus_t b;
|
|
|
|
|
|
|
|
b = bus_init();
|
|
|
|
e = rk65c02_init(&b);
|
|
|
|
|
2017-01-19 10:49:05 +00:00
|
|
|
/* LDA immediate */
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_imm.rom"));
|
|
|
|
/* ATF_CHECK(e.state == STOPPED); // separate test case for states? */
|
|
|
|
ATF_CHECK(e.regs.PC == ROM_LOAD_ADDR+3); // separate test case for PC? */
|
2017-01-18 21:37:00 +00:00
|
|
|
ATF_CHECK(e.regs.A == 0xAF);
|
|
|
|
|
2017-01-19 10:49:05 +00:00
|
|
|
/* LDA zero page */
|
|
|
|
bus_write_1(&b, 0x10, 0xAE);
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_zp.rom"));
|
|
|
|
ATF_CHECK(e.regs.A == 0xAE);
|
|
|
|
|
2017-01-18 21:37:00 +00:00
|
|
|
bus_finish(&b);
|
|
|
|
}
|
|
|
|
|
2017-01-20 09:41:56 +00:00
|
|
|
ATF_TC_WITHOUT_HEAD(emul_and);
|
|
|
|
ATF_TC_BODY(emul_and, tc)
|
|
|
|
{
|
|
|
|
rk65c02emu_t e;
|
|
|
|
bus_t b;
|
|
|
|
|
|
|
|
b = bus_init();
|
|
|
|
e = rk65c02_init(&b);
|
|
|
|
|
|
|
|
/* AND immediate */
|
|
|
|
e.regs.A = 0xFF;
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_and_imm.rom"));
|
|
|
|
ATF_CHECK(e.regs.A == 0xAA);
|
|
|
|
|
|
|
|
/* AND zero page */
|
|
|
|
/* bus_write_1(&b, 0x10, 0xAE);
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_and_zp.rom"));
|
|
|
|
ATF_CHECK(e.regs.A == 0xAE);*/
|
|
|
|
|
|
|
|
bus_finish(&b);
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:37:00 +00:00
|
|
|
ATF_TC_WITHOUT_HEAD(emul_nop);
|
|
|
|
ATF_TC_BODY(emul_nop, tc)
|
|
|
|
{
|
|
|
|
rk65c02emu_t e;
|
|
|
|
bus_t b;
|
|
|
|
|
|
|
|
b = bus_init();
|
|
|
|
e = rk65c02_init(&b);
|
|
|
|
|
2017-01-18 23:57:09 +00:00
|
|
|
e.regs.PC = ROM_LOAD_ADDR;
|
2017-01-18 21:37:00 +00:00
|
|
|
|
2017-01-20 21:24:08 +00:00
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_nop.rom"));
|
2017-01-18 21:37:00 +00:00
|
|
|
|
2017-01-20 22:18:25 +00:00
|
|
|
ATF_CHECK(e.regs.PC == ROM_LOAD_ADDR+2);
|
|
|
|
|
|
|
|
bus_finish(&b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test stack operation and stack related opcodes - PLA, PHA... */
|
|
|
|
ATF_TC_WITHOUT_HEAD(emul_stack);
|
|
|
|
ATF_TC_BODY(emul_stack, tc)
|
|
|
|
{
|
|
|
|
rk65c02emu_t e;
|
|
|
|
bus_t b;
|
|
|
|
|
|
|
|
b = bus_init();
|
|
|
|
e = rk65c02_init(&b);
|
|
|
|
|
|
|
|
/* place 0xAA on stack */
|
|
|
|
e.regs.SP = 0xFF;
|
|
|
|
e.regs.A = 0xAA;
|
|
|
|
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_pha.rom"));
|
|
|
|
|
|
|
|
ATF_CHECK(e.regs.SP == 0xFE);
|
|
|
|
ATF_CHECK(bus_read_1(e.bus, STACK_END) == 0xAA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run again to see if stack pointer further decrements and we'll
|
|
|
|
* end up with one more value on stack.
|
|
|
|
*/
|
|
|
|
e.regs.PC = ROM_LOAD_ADDR;
|
|
|
|
e.regs.A = 0xAB;
|
|
|
|
|
2017-01-18 21:37:00 +00:00
|
|
|
rk65c02_start(&e);
|
|
|
|
|
2017-01-20 22:18:25 +00:00
|
|
|
ATF_CHECK(e.regs.SP == 0xFD);
|
|
|
|
ATF_CHECK(bus_read_1(e.bus, STACK_END) == 0xAA);
|
|
|
|
ATF_CHECK(bus_read_1(e.bus, STACK_END-1) == 0xAB);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now let's see if loading back into accumulator works.
|
|
|
|
*/
|
|
|
|
e.regs.A = 0x0;
|
|
|
|
ATF_REQUIRE(rom_start(&e, "test_emulation_pla.rom"));
|
|
|
|
|
|
|
|
ATF_CHECK(e.regs.SP == 0xFE);
|
|
|
|
ATF_CHECK(e.regs.A == 0xAB);
|
2017-01-18 16:18:19 +00:00
|
|
|
|
|
|
|
bus_finish(&b);
|
|
|
|
}
|
|
|
|
|
|
|
|
ATF_TP_ADD_TCS(tp)
|
|
|
|
{
|
2017-01-20 09:41:56 +00:00
|
|
|
ATF_TP_ADD_TC(tp, emul_and);
|
2017-01-18 21:37:00 +00:00
|
|
|
ATF_TP_ADD_TC(tp, emul_lda);
|
|
|
|
ATF_TP_ADD_TC(tp, emul_nop);
|
2017-01-20 22:18:25 +00:00
|
|
|
ATF_TP_ADD_TC(tp, emul_stack);
|
2017-01-18 16:18:19 +00:00
|
|
|
|
|
|
|
return (atf_no_error());
|
|
|
|
}
|
|
|
|
|