1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-13 01:29:57 +00:00

Add SBC emulation.

Of dubious quality.
This commit is contained in:
Radosław Kujawa 2017-02-01 14:35:50 +01:00
parent 371856f6c7
commit 92418b0f1f
2 changed files with 39 additions and 9 deletions

View File

@ -224,34 +224,34 @@ OP_CMP_ABSX,"cmp",ABSOLUTEX,3,emul_cmp,false
OP_DEC_ABSX,"dec",ABSOLUTEX,3,emul_dec,false
OP_BBS5_REL,"bbs5",ZPR,2,emul_bbs5,true
OP_CPX_IMM,"cpx",IMMEDIATE,2,emul_cpx,false
OP_SBC_IZPX,"sbc",IZPX,2,NULL,false
OP_SBC_IZPX,"sbc",IZPX,2,emul_sbc,false
OP_NOPI_E3,"nop",IMMEDIATE,2,NULL,false
OP_NOPI_E4,"nop",IMPLIED,1,NULL,false
OP_CPX_ZP,"cpx",ZP,2,emul_cpx,false
OP_SBC_ZP,"sbc",ZP,2,NULL,false
OP_SBC_ZP,"sbc",ZP,2,emul_sbc,false
OP_INC_ZP,"inc",ZP,2,emul_inc,false
OP_SMB6_ZP,"smb6",ZP,2,emul_smb6,false
OP_INX,"inx",IMPLIED,1,emul_inx,false
OP_SBC_IMM,"sbc",IMMEDIATE,2,NULL,false
OP_SBC_IMM,"sbc",IMMEDIATE,2,emul_sbc,false
OP_NOP,"nop",IMPLIED,1,emul_nop,false
OP_NOPI_EC,"nop",IMPLIED,1,NULL,false
OP_CPX_ABS,"cpx",ABSOLUTE,3,emul_cpx,false
OP_SBC_ABS,"sbc",ABSOLUTE,3,NULL,false
OP_SBC_ABS,"sbc",ABSOLUTE,3,emul_sbc,false
OP_INC_ABS,"inc",ABSOLUTE,3,emul_inc,false
OP_BBS6_REL,"bbs6",ZPR,2,emul_bbs6,true
OP_BEQ_REL,"beq",RELATIVE,2,emul_beq,true
OP_SBC_IZPY,"sbc",IZPY,2,NULL,false
OP_SBC_IZP,"sbc",IZP,2,NULL,false
OP_SBC_IZPY,"sbc",IZPY,2,emul_sbc,false
OP_SBC_IZP,"sbc",IZP,2,emul_sbc,false
OP_NOPI_F4,"nop",IMPLIED,1,NULL,false
OP_NOPI_F5,"nop",ZPX,2,NULL,false
OP_SBC_ZPX,"sbc",ZPX,2,NULL,false
OP_SBC_ZPX,"sbc",ZPX,2,emul_sbc,false
OP_INC_ZPX,"inc",ZPX,2,emul_inc,false
OP_SMB7_ZP,"smb7",ZP,2,emul_smb7,false
OP_SED,"sed",IMPLIED,1,NULL,false
OP_SBC_ABSY,"sbc",ABSOLUTEY,3,NULL,false
OP_SBC_ABSY,"sbc",ABSOLUTEY,3,emul_sbc,false
OP_PLX,"plx",IMPLIED,1,emul_plx,false
OP_NOPI_FC,"nop",IMPLIED,1,NULL,false
OP_NOPI_FD,"nop",ABSOLUTE,3,NULL,false
OP_SBC_ABSX,"sbc",ABSOLUTEX,3,NULL,false
OP_SBC_ABSX,"sbc",ABSOLUTEX,3,emul_sbc,false
OP_INC_ABSX,"inc",ABSOLUTEX,3,emul_inc,false
OP_BBS7_REL,"bbs7",ZPR,2,emul_bbs7,true

1 opcode_id mnemonic addressing size emulation modify_pc
224 OP_DEC_ABSX dec ABSOLUTEX 3 emul_dec false
225 OP_BBS5_REL bbs5 ZPR 2 emul_bbs5 true
226 OP_CPX_IMM cpx IMMEDIATE 2 emul_cpx false
227 OP_SBC_IZPX sbc IZPX 2 NULL emul_sbc false
228 OP_NOPI_E3 nop IMMEDIATE 2 NULL false
229 OP_NOPI_E4 nop IMPLIED 1 NULL false
230 OP_CPX_ZP cpx ZP 2 emul_cpx false
231 OP_SBC_ZP sbc ZP 2 NULL emul_sbc false
232 OP_INC_ZP inc ZP 2 emul_inc false
233 OP_SMB6_ZP smb6 ZP 2 emul_smb6 false
234 OP_INX inx IMPLIED 1 emul_inx false
235 OP_SBC_IMM sbc IMMEDIATE 2 NULL emul_sbc false
236 OP_NOP nop IMPLIED 1 emul_nop false
237 OP_NOPI_EC nop IMPLIED 1 NULL false
238 OP_CPX_ABS cpx ABSOLUTE 3 emul_cpx false
239 OP_SBC_ABS sbc ABSOLUTE 3 NULL emul_sbc false
240 OP_INC_ABS inc ABSOLUTE 3 emul_inc false
241 OP_BBS6_REL bbs6 ZPR 2 emul_bbs6 true
242 OP_BEQ_REL beq RELATIVE 2 emul_beq true
243 OP_SBC_IZPY sbc IZPY 2 NULL emul_sbc false
244 OP_SBC_IZP sbc IZP 2 NULL emul_sbc false
245 OP_NOPI_F4 nop IMPLIED 1 NULL false
246 OP_NOPI_F5 nop ZPX 2 NULL false
247 OP_SBC_ZPX sbc ZPX 2 NULL emul_sbc false
248 OP_INC_ZPX inc ZPX 2 emul_inc false
249 OP_SMB7_ZP smb7 ZP 2 emul_smb7 false
250 OP_SED sed IMPLIED 1 NULL false
251 OP_SBC_ABSY sbc ABSOLUTEY 3 NULL emul_sbc false
252 OP_PLX plx IMPLIED 1 emul_plx false
253 OP_NOPI_FC nop IMPLIED 1 NULL false
254 OP_NOPI_FD nop ABSOLUTE 3 NULL false
255 OP_SBC_ABSX sbc ABSOLUTEX 3 NULL emul_sbc false
256 OP_INC_ABSX inc ABSOLUTEX 3 emul_inc false
257 OP_BBS7_REL bbs7 ZPR 2 emul_bbs7 true

View File

@ -790,6 +790,36 @@ emul_ror(rk65c02emu_t *e, void *id, instruction_t *i)
instruction_data_write_1(e, (instrdef_t *) id, i, val);
}
/* SBC - substract with carry */
void
emul_sbc(rk65c02emu_t *e, void *id, instruction_t *i)
{
uint8_t arg;
uint16_t res; /* meh */
arg = instruction_data_read_1(e, (instrdef_t *) id, i);
res = e->regs.A - arg;
if (e->regs.P & P_CARRY)
res--;
if ((e->regs.A ^ res) & (arg ^ res) & 0x80)
e->regs.P |= P_SIGN_OVERFLOW;
else
e->regs.P &= ~P_SIGN_OVERFLOW;
/* if the result does not fit into 8 bits then set carry */
if (res > 0xFF)
e->regs.P |= P_CARRY;
else
e->regs.P &= ~P_CARRY;
/* squash the result into accumulator's 8 bits, lol */
e->regs.A = (uint8_t) res;
instruction_status_adjust_zero(e, e->regs.A);
instruction_status_adjust_negative(e, e->regs.A);
}
/* SEC - set the carry flag */
void
emul_sec(rk65c02emu_t *e, void *id, instruction_t *i)