1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-22 15:31:12 +00:00

Implement (partial) JMP emulation and basic test for it.

This commit is contained in:
Radosław Kujawa 2017-01-27 22:28:33 +01:00
parent 05cedfb1f5
commit 8d2d694158
4 changed files with 56 additions and 3 deletions

View File

@ -75,7 +75,7 @@ OP_PHA,"pha",IMPLIED,1,emul_pha,false
OP_EOR_IMM,"eor",IMMEDIATE,2,emul_eor,false
OP_LSR,"lsr",ACCUMULATOR,1,emul_lsr,false
OP_NOPI_4C,"nop",IMPLIED,1,NULL,false
OP_JMP_ABS,"jmp",ABSOLUTE,3,NULL,true
OP_JMP_ABS,"jmp",ABSOLUTE,3,emul_jmp,true
OP_EOR_ABS,"eor",ABSOLUTE,3,emul_eor,false
OP_LSR_ABS,"lsr",ABSOLUTE,3,emul_lsr,false
OP_BBR4_REL,"bbr4",ZPR,2,NULL,true
@ -107,7 +107,7 @@ OP_PLA,"pla",IMPLIED,1,emul_pla,false
OP_ADC_IMM,"adc",IMMEDIATE,2,NULL,false
OP_ROR,"ror",ACCUMULATOR,1,emul_ror,false
OP_NOPI_6C,"nop",IMPLIED,1,NULL,false
OP_JMP_IABS,"jmp",IABSOLUTE,3,NULL,true
OP_JMP_IABS,"jmp",IABSOLUTE,3,emul_jmp,true
OP_ADC_ABS,"adc",ABSOLUTE,3,NULL,false
OP_ROR_ABS,"ror",ABSOLUTE,3,emul_ror,false
OP_BBR6_REL,"bbr6",ZPR,2,NULL,true
@ -123,7 +123,7 @@ OP_SEI,"sei",IMPLIED,1,NULL,false
OP_ADC_ABSY,"adc",ABSOLUTEY,3,NULL,false
OP_PLY,"ply",IMPLIED,1,emul_ply,false
OP_NOPI_7C,"nop",IMPLIED,1,NULL,false
OP_JMP_IABSX,"jmp",IABSOLUTEX,3,NULL,true
OP_JMP_IABSX,"jmp",IABSOLUTEX,3,emul_jmp,true
OP_ADC_ABSX,"adc",ABSOLUTEX,3,NULL,false
OP_ROR_ABSX,"ror",ABSOLUTEX,3,emul_ror,false
OP_BBR7_REL,"bbr7",ZPR,2,NULL,true

1 opcode_id mnemonic addressing size emulation modify_pc
75 OP_EOR_IMM eor IMMEDIATE 2 emul_eor false
76 OP_LSR lsr ACCUMULATOR 1 emul_lsr false
77 OP_NOPI_4C nop IMPLIED 1 NULL false
78 OP_JMP_ABS jmp ABSOLUTE 3 NULL emul_jmp true
79 OP_EOR_ABS eor ABSOLUTE 3 emul_eor false
80 OP_LSR_ABS lsr ABSOLUTE 3 emul_lsr false
81 OP_BBR4_REL bbr4 ZPR 2 NULL true
107 OP_ADC_IMM adc IMMEDIATE 2 NULL false
108 OP_ROR ror ACCUMULATOR 1 emul_ror false
109 OP_NOPI_6C nop IMPLIED 1 NULL false
110 OP_JMP_IABS jmp IABSOLUTE 3 NULL emul_jmp true
111 OP_ADC_ABS adc ABSOLUTE 3 NULL false
112 OP_ROR_ABS ror ABSOLUTE 3 emul_ror false
113 OP_BBR6_REL bbr6 ZPR 2 NULL true
123 OP_ADC_ABSY adc ABSOLUTEY 3 NULL false
124 OP_PLY ply IMPLIED 1 emul_ply false
125 OP_NOPI_7C nop IMPLIED 1 NULL false
126 OP_JMP_IABSX jmp IABSOLUTEX 3 NULL emul_jmp true
127 OP_ADC_ABSX adc ABSOLUTEX 3 NULL false
128 OP_ROR_ABSX ror ABSOLUTEX 3 emul_ror false
129 OP_BBR7_REL bbr7 ZPR 2 NULL true

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <assert.h>
#include "emulation.h"
@ -151,6 +152,29 @@ emul_iny(rk65c02emu_t *e, void *id, instruction_t *i)
instruction_status_adjust_negative(e, e->regs.Y);
}
/* JMP - JUMP~ */
void
emul_jmp(rk65c02emu_t *e, void *id, instruction_t *i)
{
uint16_t target;//, iaddr;
switch (((instrdef_t *)id)->mode) {
case ABSOLUTE:
target = i->op1 + (i->op2 << 8);
break;
case IABSOLUTE:
target = bus_read_1(e->bus, i->op1);
target |= (bus_read_1(e->bus, i->op2) << 8);
// target = bus_read_1(e->bus, indirect);
// target |= bus_read_1(e->bus, indirect + 1);
default:
assert(false); /* should never happen, lol */
break;
}
e->regs.PC = target;
}
/* LDA - load to accumulator */
void
emul_lda(rk65c02emu_t *e, void *id, instruction_t *i)

View File

@ -617,6 +617,30 @@ ATF_TC_BODY(emul_phx_phy_plx_ply, tc)
bus_finish(&b);
}
ATF_TC_WITHOUT_HEAD(emul_jmp);
ATF_TC_BODY(emul_jmp, tc)
{
rk65c02emu_t e;
bus_t b;
b = bus_init();
e = rk65c02_init(&b);
e.regs.PC = ROM_LOAD_ADDR;
ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR,
rom_path("test_emulation_jmp_abs.rom", tc)));
rk65c02_step(&e, 3);
rk65c02_dump_regs(&e);
/*
ATF_CHECK(e.regs.SP == 0xFE);
ATF_CHECK(bus_read_1(e.bus, STACK_END) == 0xAA);
e.regs.X = 0;
*/
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, emul_and);
@ -626,6 +650,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, emul_clc_sec);
ATF_TP_ADD_TC(tp, emul_inc);
ATF_TP_ADD_TC(tp, emul_inx_iny);
ATF_TP_ADD_TC(tp, emul_jmp);
ATF_TP_ADD_TC(tp, emul_lda);
ATF_TP_ADD_TC(tp, emul_nop);
ATF_TP_ADD_TC(tp, emul_ora);

View File

@ -0,0 +1,4 @@
start: nop
nop
jmp 0xC000