Got it. I've got a "trap" defined for anything that is "Unofficial". I created a jump table with all opcodes and when it gets looked up in the table as a "trap" execution stops and an error gets printed. Looks good for the most part. I'm really surprised at how much actually went correctly. I do have some issues with it though. JSR/RTS seem to be giving me problems (Incorrect addresses pushed/popped) and some documentation states one thing while other states another thing.
What do you guys think about doing it this way?
Code:
typedef void (* op_cback)(mos_6502_t *, opcode_t *);
Code:
#include "MOS_6502.h"
char * mnemonics[] = {
"brk","ora","trp","trp","trp","ora","asl","trp","php","ora","asl","trp","trp","ora","asl","trp",
"bpl","ora","trp","trp","trp","ora","asl","trp","clc","ora","trp","trp","trp","ora","asl","trp",
"jsr","and","trp","trp","bit","and","rol","trp","plp","and","rol","trp","bit","and","rol","trp",
"bmi","and","trp","trp","trp","and","rol","trp","sec","and","trp","trp","trp","and","rol","trp",
"rti","eor","trp","trp","trp","eor","lsr","trp","pha","eor","lsr","trp","jmp","eor","lsr","trp",
"bvc","eor","trp","trp","trp","eor","lsr","trp","cli","eor","trp","trp","trp","eor","lsr","trp",
"rts","adc","trp","trp","trp","adc","ror","trp","pla","adc","ror","trp","jmp","adc","ror","trp",
"bvs","adc","trp","trp","trp","adc","ror","trp","sei","adc","trp","trp","trp","adc","ror","trp",
"trp","sta","trp","trp","sty","sta","stx","trp","dey","trp","txa","trp","sty","sta","stx","trp",
"bcc","sta","trp","trp","sty","sta","stx","trp","tya","sta","txs","trp","trp","sta","trp","trp",
"ldy","lda","ldx","trp","ldy","lda","ldx","trp","tay","lda","tax","trp","ldy","lda","ldx","trp",
"bcs","lda","trp","trp","ldy","lda","ldx","trp","clv","lda","tsx","trp","ldy","lda","ldx","trp",
"cpy","cmp","trp","trp","cpy","cmp","dec","trp","iny","cmp","dex","trp","cpy","cmp","dec","trp",
"bne","cmp","trp","trp","trp","cmp","dec","trp","cld","cmp","trp","trp","trp","cmp","dec","trp",
"cpx","sbc","trp","trp","cpx","sbc","inc","trp","inx","sbc","nop","trp","cpx","sbc","inc","trp",
"beq","sbc","trp","trp","trp","sbc","inc","trp","sed","sbc","trp","trp","trp","sbc","inc","trp",
};
op_cback op_jmp_tbl[] = {
brk, ora, trp, trp, trp, ora, asl, trp, php, ora, asl, trp, trp, ora, asl, trp,
bpl, ora, trp, trp, trp, ora, asl, trp, clc, ora, trp, trp, trp, ora, asl, trp,
jsr, and, trp, trp, bit, and, rol, trp, plp, and, rol, trp, bit, and, rol, trp,
bmi, and, trp, trp, trp, and, rol, trp, sec, and, trp, trp, trp, and, rol, trp,
rti, eor, trp, trp, trp, eor, lsr, trp, pha, eor, lsr, trp, jmp, eor, lsr, trp,
bvc, eor, trp, trp, trp, eor, lsr, trp, cli, eor, trp, trp, trp, eor, lsr, trp,
rts, adc, trp, trp, trp, adc, ror, trp, pla, adc, ror, trp, jmp, adc, ror, trp,
bvs, adc, trp, trp, trp, adc, ror, trp, sei, adc, trp, trp, trp, adc, ror, trp,
trp, sta, trp, trp, sty, sta, stx, trp, dey, trp, txa, trp, sty, sta, stx, trp,
bcc, sta, trp, trp, sty, sta, stx, trp, tya, sta, txs, trp, trp, sta, trp, trp,
ldy, lda, ldx, trp, ldy, lda, ldx, trp, tay, lda, tax, trp, ldy, lda, ldx, trp,
bcs, lda, trp, trp, ldy, lda, ldx, trp, clv, lda, tsx, trp, ldy, lda, ldx, trp,
cpy, cmp, trp, trp, cpy, cmp, dec, trp, iny, cmp, dex, trp, cpy, cmp, dec, trp,
bne, cmp, trp, trp, trp, cmp, dec, trp, cld, cmp, trp, trp, trp, cmp, dec, trp,
cpx, sbc, trp, trp, cpx, sbc, inc, trp, inx, sbc, nop, trp, cpx, sbc, inc, trp,
beq, sbc, trp, trp, trp, sbc, inc, trp, sed, sbc, trp, trp, trp, sbc, inc, trp
};
Code:
extern op_cback op_jmp_tbl[];
void execute_inst(mos_6502_t * mos_ctx, opcode_t * op){
op_jmp_tbl[op->opcode](mos_ctx, op);
}