diff --git a/include/c64/asm6502.h b/include/c64/asm6502.h new file mode 100644 index 0000000..7373362 --- /dev/null +++ b/include/c64/asm6502.h @@ -0,0 +1,173 @@ +#ifndef C64_ASM_6502_H +#define C64_ASM_6502_H + +#include "types.h" + +enum AsmIns +{ + // Implied + + ASM_BRK = 0x00, + + ASM_RTI = 0x40, + ASM_RTS = 0x60, + + ASM_PHP = 0x08, + ASM_CLC = 0x18, + ASM_PLP = 0x28, + ASM_SEC = 0x38, + ASM_PHA = 0x48, + + ASM_CLI = 0x58, + ASM_PLA = 0x68, + ASM_SEI = 0x78, + + ASM_DEY = 0x88, + ASM_TYA = 0x98, + ASM_TAY = 0xa8, + ASM_CLV = 0xb8, + + ASM_INY = 0xc8, + ASM_CLD = 0xd8, + ASM_INX = 0xe8, + ASM_SED = 0xf8, + + ASM_TXA = 0x8a, + ASM_TXS = 0x9a, + ASM_TAX = 0xaa, + ASM_TSX = 0xba, + ASM_DEX = 0xca, + ASM_NOP = 0xea, + + // Relative + ASM_BPL = 0x10, + ASM_BMI = 0x30, + ASM_BVC = 0x50, + ASM_BVS = 0x70, + ASM_BCC = 0x90, + ASM_BCS = 0xb0, + ASM_BNE = 0xd0, + ASM_BEQ = 0xf0, + + // Generic address + ASM_ORA = 0x01, + ASM_AND = 0x21, + ASM_EOR = 0x41, + ASM_ADC = 0x61, + ASM_STA = 0x81, + ASM_LDA = 0xa1, + ASM_CMP = 0xc1, + ASM_SBC = 0xe1, + + ASM_STY = 0x80, + ASM_LDY = 0xa0, + ASM_CPY = 0xc0, + ASM_CPX = 0xe0, + + ASM_ASL = 0x02, + ASM_ROL = 0x22, + ASM_LSR = 0x42, + ASM_ROR = 0x62, + + ASM_STX = 0x82, + ASM_LDX = 0xa2, + ASM_DEC = 0xc2, + ASM_INC = 0xe2, + + // Limited Generic + ASM_BIT = 0x20, + + // Jump + ASM_JMP = 0x4c, + ASM_JSR = 0x2c +}; + +inline void asm_np(byte ** ip, AsmIns ins) +{ + (*ip)[0] = ins & 0xff; + (*ip)++; +} + +inline void asm_zp(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = (ins & 0xff) | 0x04; + (*ip)[1] = addr; + (*ip) += 2; +} + +inline void asm_rl(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = ins & 0xff; + (*ip)[1] = addr; + (*ip) += 2; +} + +inline void asm_im(byte ** ip, AsmIns ins, byte value) +{ + (*ip)[0] = (ins & 0xff) | ((ins & 0x01) << 3); + (*ip)[1] = value; + (*ip) += 2; +} + +inline void asm_zx(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = (ins & 0xff) | 0x05; + (*ip)[1] = addr; + (*ip) += 2; +} + +inline void asm_zy(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = (ins & 0xff) | 0x05; + (*ip)[1] = addr; + (*ip) += 2; +} + +inline void asm_ab(byte ** ip, AsmIns ins, unsigned addr) +{ + (*ip)[0] = (ins & 0xff) ^ 0x0c; + (*ip)[1] = addr & 0xff; + (*ip)[2] = addr >> 8; + (*ip) += 3; +} + +inline void asm_in(byte ** ip, AsmIns ins, unsigned addr) +{ + (*ip)[0] = (ins & 0xff) ^ 0x2c; + (*ip)[1] = addr & 0xff; + (*ip)[2] = addr >> 8; + (*ip) += 3; +} + +inline void asm_ax(byte ** ip, AsmIns ins, unsigned addr) +{ + (*ip)[0] = (ins & 0xff) | 0x1c; + (*ip)[1] = addr & 0xff; + (*ip)[2] = addr >> 8; + (*ip) += 3; +} + +inline void asm_ay(byte ** ip, AsmIns ins, unsigned addr) +{ + (*ip)[0] = (ins & 0xff) | 0x18; + (*ip)[1] = addr & 0xff; + (*ip)[2] = addr >> 8; + (*ip) += 3; +} + +inline void asm_ix(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = (ins & 0xff) | 0x00; + (*ip)[1] = addr; + (*ip) += 2; +} + +inline void asm_iy(byte ** ip, AsmIns ins, byte addr) +{ + (*ip)[0] = (ins & 0xff) | 0x01; + (*ip)[1] = addr; + (*ip) += 2; +} + +#endif + diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index e359dda..c462fb8 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -1560,6 +1560,27 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data, AsmInsT int c = t >= 256; + if (t && !data.mRegs[CPU_REG_C].mValue) + carryop = ASMIT_SEC; + else if (!t && data.mRegs[CPU_REG_C].mValue) + carryop = ASMIT_CLC; + + changed = true; + } + else if (mMode == ASMIM_IMMEDIATE_ADDRESS && data.mRegs[CPU_REG_A].mMode == NRDM_IMMEDIATE_ADDRESS && mLinkerObject == data.mRegs[CPU_REG_A].mLinkerObject) + { + int t; + if (mFlags & NCIF_LOWER) + t = (mAddress ^ 0xffff) + data.mRegs[CPU_REG_A].mValue + data.mRegs[CPU_REG_C].mValue; + else + t = ((mAddress ^ 0xffff) >> 8) + data.mRegs[CPU_REG_A].mValue + data.mRegs[CPU_REG_C].mValue; + + mType = ASMIT_LDA; + mMode = ASMIM_IMMEDIATE; + mAddress = t & 0xff; + + int c = t >= 256; + if (t && !data.mRegs[CPU_REG_C].mValue) carryop = ASMIT_SEC; else if (!t && data.mRegs[CPU_REG_C].mValue)