cpu_65c02_ora(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0x02:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0x03:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x04:
cpu_65c02_tsb(self, cpu_65c02_ea_zero_page(self));
cpu_65c02_asl(self, CPU_65C02_EA_A);
break;
case 0x0b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x0c:
cpu_65c02_tsb(self, cpu_65c02_ea_absolute(self));
cpu_65c02_ora(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0x13:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x14:
cpu_65c02_trb(self, cpu_65c02_ea_zero_page(self));
cpu_65c02_inc(self, CPU_65C02_EA_A);
break;
case 0x1b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x1c:
cpu_65c02_trb(self, cpu_65c02_ea_absolute(self));
cpu_65c02_and(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0x22:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0x23:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x24:
cpu_65c02_bit(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self)));
cpu_65c02_rol(self, CPU_65C02_EA_A);
break;
case 0x2b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x2c:
cpu_65c02_bit(self, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute(self)));
cpu_65c02_and(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0x33:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x34:
cpu_65c02_bit(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)));
cpu_65c02_dec(self, CPU_65C02_EA_A);
break;
case 0x3b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x3c:
cpu_65c02_bit(self, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x)));
cpu_65c02_eor(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0x42:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0x43:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x44:
- cpu_65c02_ill23(self);
+ cpu_65c02_illegal_opcode23(self);
break;
case 0x45:
cpu_65c02_eor(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self)));
cpu_65c02_lsr(self, CPU_65C02_EA_A);
break;
case 0x4b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x4c:
cpu_65c02_jmp(self, cpu_65c02_ea_absolute(self));
cpu_65c02_eor(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0x53:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x54:
- cpu_65c02_ill24(self);
+ cpu_65c02_illegal_opcode24(self);
break;
case 0x55:
cpu_65c02_eor(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)));
cpu_65c02_ph(self, self->regs.byte.y);
break;
case 0x5b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x5c:
- cpu_65c02_ill38(self);
+ cpu_65c02_illegal_opcode38(self);
break;
case 0x5d:
cpu_65c02_eor(self, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x)));
cpu_65c02_adc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0x62:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0x63:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x64:
cpu_65c02_st(self, 0, cpu_65c02_ea_zero_page(self));
cpu_65c02_ror(self, CPU_65C02_EA_A);
break;
case 0x6b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x6c:
cpu_65c02_jmp(self, cpu_65c02_ea_absolute_indirect(self));
cpu_65c02_adc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0x73:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x74:
cpu_65c02_st(self, 0, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x));
cpu_65c02_pl(self, CPU_65C02_EA_Y);
break;
case 0x7b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x7c:
cpu_65c02_jmp(self, cpu_65c02_ea_absolute_indexed_indirect(self, self->regs.byte.x));
cpu_65c02_st(self, self->regs.byte.a, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x));
break;
case 0x82:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0x83:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x84:
cpu_65c02_st(self, self->regs.byte.y, cpu_65c02_ea_zero_page(self));
cpu_65c02_ld(self, CPU_65C02_EA_A, self->regs.byte.x);
break;
case 0x8b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x8c:
cpu_65c02_st(self, self->regs.byte.y, cpu_65c02_ea_absolute(self));
cpu_65c02_st(self, self->regs.byte.a, cpu_65c02_ea_zero_page_indirect(self));
break;
case 0x93:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x94:
cpu_65c02_st(self, self->regs.byte.y, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x));
cpu_65c02_st(self, self->regs.byte.x, CPU_65C02_EA_S);
break;
case 0x9b:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0x9c:
cpu_65c02_st(self, 0, cpu_65c02_ea_absolute(self));
cpu_65c02_ld(self, CPU_65C02_EA_X, cpu_65c02_fetch_byte(self));
break;
case 0xa3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xa4:
cpu_65c02_ld(self, CPU_65C02_EA_Y, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self)));
cpu_65c02_ld(self, CPU_65C02_EA_X, self->regs.byte.a);
break;
case 0xab:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xac:
cpu_65c02_ld(self, CPU_65C02_EA_Y, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute(self)));
cpu_65c02_ld(self, CPU_65C02_EA_A, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0xb3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xb4:
cpu_65c02_ld(self, CPU_65C02_EA_Y, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)));
cpu_65c02_ld(self, CPU_65C02_EA_X, self->regs.byte.s);
break;
case 0xbb:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xbc:
cpu_65c02_ld(self, CPU_65C02_EA_Y, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x)));
cpu_65c02_cmp(self, self->regs.byte.a, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0xc2:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0xc3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xc4:
cpu_65c02_cmp(self, self->regs.byte.y, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self)));
cpu_65c02_cmp(self, self->regs.byte.a, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0xd3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xd4:
- cpu_65c02_ill24(self);
+ cpu_65c02_illegal_opcode24(self);
break;
case 0xd5:
cpu_65c02_cmp(self, self->regs.byte.a, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)));
cpu_65c02_ph(self, self->regs.byte.x);
break;
case 0xdb:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xdc:
- cpu_65c02_ill34(self);
+ cpu_65c02_illegal_opcode34(self);
break;
case 0xdd:
cpu_65c02_cmp(self, self->regs.byte.a, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x)));
cpu_65c02_sbc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x)));
break;
case 0xe2:
- cpu_65c02_ill22(self);
+ cpu_65c02_illegal_opcode22(self);
break;
case 0xe3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xe4:
cpu_65c02_cmp(self, self->regs.byte.x, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self)));
cpu_65c02_nop(self);
break;
case 0xeb:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xec:
cpu_65c02_cmp(self, self->regs.byte.x, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute(self)));
cpu_65c02_sbc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self)));
break;
case 0xf3:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xf4:
- cpu_65c02_ill24(self);
+ cpu_65c02_illegal_opcode24(self);
break;
case 0xf5:
cpu_65c02_sbc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)));
cpu_65c02_pl(self, CPU_65C02_EA_X);
break;
case 0xfb:
- cpu_65c02_ill11(self);
+ cpu_65c02_illegal_opcode11(self);
break;
case 0xfc:
- cpu_65c02_ill34(self);
+ cpu_65c02_illegal_opcode34(self);
break;
case 0xfd:
cpu_65c02_sbc(self, cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x)));
import sys
+# for these opcodes, operand 1 is an rvalue
+rvalue1_opcodes = {
+ 'cmp',
+ 'st'
+}
+
+# for these opcodes, last operand is an rvalue
rvalue_opcodes = {
'adc',
'and',
'cpx',
'cpy',
'eor',
- 'lda',
- 'ldx',
- 'ldy',
+ 'ld',
'ora',
+ 'ph',
'sbc',
}
+
rvalue_modes = {
'#$12': 'cpu_65c02_fetch_byte(self)',
- '$12': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page(self))',
- '$12,x': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x))',
- '$12,y': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.y))',
- '$3412': 'cpu_65c02_read_byte(self, cpu_65c02_ea_absolute(self))',
- '$3412,x': 'cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.x))',
- '$3412,y': 'cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed(self, self->regs.byte.y))',
- '($12)': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect(self))',
- '($12),y': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indirect_indexed(self, self->regs.byte.y))',
- '($12,x)': 'cpu_65c02_read_byte(self, cpu_65c02_ea_zero_page_indexed_indirect(self, self->regs.byte.x))',
- '($3412)': 'cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indirect(self))',
- '($3412,x)': 'cpu_65c02_read_byte(self, cpu_65c02_ea_absolute_indexed_indirect(self, self->regs.byte.x))',
+ 'a': 'self->regs.byte.a',
+ 'x': 'self->regs.byte.x',
+ 'y': 'self->regs.byte.y',
+ 's': 'self->regs.byte.s',
+ 'p': 'self->regs.byte.p',
}
lvalue_modes = {
+ 'ne': '!self->regs.bit.zf',
+ 'eq': 'self->regs.bit.zf',
+ 'cc': '!self->regs.bit.cf',
+ 'cs': 'self->regs.bit.cf',
+ 'vc': '!self->regs.bit.vf',
+ 'vs': 'self->regs.bit.vf',
+ 'pl': '!self->regs.bit.nf',
+ 'mi': 'self->regs.bit.nf',
'$0014': 'cpu_65c02_ea_relative(self)',
'$12': 'cpu_65c02_ea_zero_page(self)',
'$12,x': 'cpu_65c02_ea_zero_page_indexed(self, self->regs.byte.x)',
'($3412)': 'cpu_65c02_ea_absolute_indirect(self)',
'($3412,x)': 'cpu_65c02_ea_absolute_indexed_indirect(self, self->regs.byte.x)',
'a': 'CPU_65C02_EA_A',
+ 'x': 'CPU_65C02_EA_X',
+ 'y': 'CPU_65C02_EA_Y',
+ 'p': 'CPU_65C02_EA_P',
+ 's': 'CPU_65C02_EA_S',
+ 'c': 'CPU_65C02_REG_P_BIT_C',
+ 'd': 'CPU_65C02_REG_P_BIT_D',
+ 'i': 'CPU_65C02_REG_P_BIT_I',
+ 'v': 'CPU_65C02_REG_P_BIT_V',
}
line = sys.stdin.readline().strip()
line = sys.stdin.readline().strip()
print(f' case 0x{i:02x}:')
- instr = line.lower().split()
- if instr[0] == '???':
- instr[0] = 'ill' # illegal opcode
- if len(instr) >= 2:
- if instr[0] in rvalue_opcodes:
- instr[1] = rvalue_modes[instr[1]]
- else:
- instr[1] = lvalue_modes[instr[1]]
+ instr = line.split()
+
+ j0 = 1 + int(instr[0] in rvalue1_opcodes)
+ j1 = len(instr) - int(instr[0] in rvalue_opcodes)
+
+ # operands [1, j0) are rvalue
+ for k in range(1, j0):
+ if instr[k] in rvalue_modes:
+ instr[k] = rvalue_modes[instr[k]]
+ elif instr[k] in lvalue_modes:
+ instr[k] = 'cpu_65c02_read_byte(self, {0:s})'.format(
+ lvalue_modes[instr[k]]
+ )
+
+ # operands [j0, j1) are lvalue
+ for k in range(j0, j1):
+ if instr[k] in lvalue_modes:
+ instr[k] = lvalue_modes[instr[k]]
+
+ # operands [j1, n) are rvalue
+ for k in range(j1, len(instr)):
+ if instr[k] in rvalue_modes:
+ instr[k] = rvalue_modes[instr[k]]
+ elif instr[k] in lvalue_modes:
+ instr[k] = 'cpu_65c02_read_byte(self, {0:s})'.format(
+ lvalue_modes[instr[k]]
+ )
+
print(
' cpu_65c02_{0:s}(self{1:s});'.format(
instr[0],
+++ /dev/null
-s/cpu_65c02_ill(self/cpu_65c02_ill11(self/
-s/cpu_65c02_rmb\([0-7]\)(self/cpu_65c02_rmb(self, \1/
-s/cpu_65c02_smb\([0-7]\)(self/cpu_65c02_smb(self, \1/
-s/cpu_65c02_ph\([axyp]\)(self/cpu_65c02_ph(self, self->regs.byte.\1/
-s/cpu_65c02_pl\([axy]\)(self/cpu_65c02_pl(self, CPU_65C02_EA_\1/
-s/cpu_65c02_bpl(self/cpu_65c02_bnc(self/
-s/cpu_65c02_bmi(self/cpu_65c02_bns(self/
-s/cpu_65c02_bne(self/cpu_65c02_bzc(self/
-s/cpu_65c02_beq(self/cpu_65c02_bzs(self/
-s/cpu_65c02_bra(self/cpu_65c02_bra(self, true/
-s/cpu_65c02_b\([czvn]\)c(self/cpu_65c02_bra(self, !self->regs.bit.\1f/
-s/cpu_65c02_b\([czvn]\)s(self/cpu_65c02_bra(self, self->regs.bit.\1f/
-s/cpu_65c02_stz(self/cpu_65c02_st(self, 0/
-s/cpu_65c02_st\([axy]\)(self/cpu_65c02_st(self, self->regs.byte.\1/
-s/cpu_65c02_ld\([axy]\)(self/cpu_65c02_ld(self, CPU_65C02_EA_\1/
-s/cpu_65c02_txs(self/cpu_65c02_st(self, self->regs.byte.x, CPU_65C02_EA_S)/
-s/cpu_65c02_t\([axys]\)\([axys]\)(self/cpu_65c02_ld(self, CPU_65C02_EA_\2, self->regs.byte.\1/
-s/cpu_65c02_cl\([cidv]\)(self/cpu_65c02_cl(self, CPU_65C02_REG_P_BIT_\1/
-s/cpu_65c02_se\([cidv]\)(self/cpu_65c02_se(self, CPU_65C02_REG_P_BIT_\1/
-s/cpu_65c02_in\([xy]\)(self/cpu_65c02_inc(self, CPU_65C02_EA_\1/
-s/cpu_65c02_de\([xy]\)(self/cpu_65c02_dec(self, CPU_65C02_EA_\1/
-s/cpu_65c02_cmp(self/cpu_65c02_cmp(self, self->regs.byte.a/
-s/cpu_65c02_cp\([xy]\)(self/cpu_65c02_cmp(self, self->regs.byte.\1/
-s/^ cpu_65c02_brk(self);$/ ++self->regs.word.pc;\n cpu_65c02_irq(self, true, CPU_65C02_IRQ_VECTOR);/
-s/CPU_65C02_EA_a/CPU_65C02_EA_A/g
-s/CPU_65C02_EA_x/CPU_65C02_EA_X/g
-s/CPU_65C02_EA_y/CPU_65C02_EA_Y/g
-s/CPU_65C02_EA_p/CPU_65C02_EA_P/g
-s/CPU_65C02_EA_s/CPU_65C02_EA_S/g
-s/CPU_65C02_REG_P_BIT_c/CPU_65C02_REG_P_BIT_C/g
-s/CPU_65C02_REG_P_BIT_i/CPU_65C02_REG_P_BIT_I/g
-s/CPU_65C02_REG_P_BIT_d/CPU_65C02_REG_P_BIT_D/g
-s/CPU_65C02_REG_P_BIT_v/CPU_65C02_REG_P_BIT_V/g