📄 m6502ops.h
字号:
NZ |= tmp & A /* mask to lazy Z */
#else
#define BIT \
P &= ~(_fN|_fV|_fZ); \
P |= tmp & (_fN|_fV); \
if ((tmp & A) == 0) \
P |= _fZ
#endif
/* 6502 ********************************************************
* BMI Branch if minus
***************************************************************/
#if LAZY_FLAGS
#define BMI BRA(NZ & 0x8000)
#else
#define BMI BRA(P & _fN)
#endif
/* 6502 ********************************************************
* BNE Branch if not equal
***************************************************************/
#if LAZY_FLAGS
#define BNE BRA(NZ & 0xff)
#else
#define BNE BRA(!(P & _fZ))
#endif
/* 6502 ********************************************************
* BPL Branch if plus
***************************************************************/
#if LAZY_FLAGS
#define BPL BRA(!(NZ & 0x8000))
#else
#define BPL BRA(!(P & _fN))
#endif
/* 6502 ********************************************************
* BRK Break
* increment PC, push PC hi, PC lo, flags (with B bit set),
* set I flag, reset D flag and jump via IRQ vector
***************************************************************/
#define BRK \
PCW++; \
PUSH(PCH); \
PUSH(PCL); \
COMPOSE_P; \
PUSH(P | _fB); \
P = (P | _fI) & ~_fD; \
PCL = RDMEM(M6502_IRQ_VEC); \
PCH = RDMEM(M6502_IRQ_VEC+1); \
change_pc16(PCD)
/* 6502 ********************************************************
* BVC Branch if overflow clear
***************************************************************/
#define BVC BRA(!(P & _fV))
/* 6502 ********************************************************
* BVS Branch if overflow set
***************************************************************/
#define BVS BRA(P & _fV)
/* 6502 ********************************************************
* CLC Clear carry flag
***************************************************************/
#define CLC \
P &= ~_fC
/* 6502 ********************************************************
* CLD Clear decimal flag
***************************************************************/
#define CLD \
P &= ~_fD
/* 6502 ********************************************************
* CLI Clear interrupt flag
***************************************************************/
#define CLI \
if (m6502.pending_irq && (P & _fI)) \
m6502.after_cli = 1; \
P &= ~_fI
/* 6502 ********************************************************
* CLV Clear overflow flag
***************************************************************/
#define CLV \
P &= ~_fV
/* 6502 ********************************************************
* CMP Compare accumulator
***************************************************************/
#define CMP \
P &= ~_fC; \
if (A >= tmp) \
P |= _fC; \
SET_NZ((byte)(A - tmp))
/* 6502 ********************************************************
* CPX Compare index X
***************************************************************/
#define CPX \
P &= ~_fC; \
if (X >= tmp) \
P |= _fC; \
SET_NZ((byte)(X - tmp))
/* 6502 ********************************************************
* CPY Compare index Y
***************************************************************/
#define CPY \
P &= ~_fC; \
if (Y >= tmp) \
P |= _fC; \
SET_NZ((byte)(Y - tmp))
/* 6502 ********************************************************
* DEC Decrement memory
***************************************************************/
#define DEC \
tmp = (byte)--tmp; \
SET_NZ(tmp)
/* 6502 ********************************************************
* DEX Decrement index X
***************************************************************/
#define DEX \
X = (byte)--X; \
SET_NZ(X)
/* 6502 ********************************************************
* DEY Decrement index Y
***************************************************************/
#define DEY \
Y = (byte)--Y; \
SET_NZ(Y)
/* 6502 ********************************************************
* EOR Logical exclusive or
***************************************************************/
#define EOR \
A = (byte)(A ^ tmp); \
SET_NZ(A)
/* 6502 ********************************************************
* ILL Illegal opcode
***************************************************************/
#define ILL \
if (0) \
printf("M6502 illegal opcode %04x: %02x\n", \
(PCW-1)&0xffff, cpu_readop((PCW-1)&0xffff))
/* 6502 ********************************************************
* INC Increment memory
***************************************************************/
#define INC \
tmp = (byte)++tmp; \
SET_NZ(tmp)
/* 6502 ********************************************************
* INX Increment index X
***************************************************************/
#define INX \
X = (byte)++X; \
SET_NZ(X)
/* 6502 ********************************************************
* INY Increment index Y
***************************************************************/
#define INY \
Y = (byte)++Y; \
SET_NZ(Y)
/* 6502 ********************************************************
* JMP Jump to address
* set PC to the effective address
***************************************************************/
#define JMP \
PCD = EAD; \
change_pc16(PCD)
/* 6502 ********************************************************
* JSR Jump to subroutine
* decrement PC (sic!) push PC hi, push PC lo and set
* PC to the effective address
***************************************************************/
#define JSR \
EAL = RDOPARG(); \
PUSH(PCH); \
PUSH(PCL); \
EAH = RDOPARG(); \
PCD = EAD; \
change_pc16(PCD)
/* 6502 ********************************************************
* LDA Load accumulator
***************************************************************/
#define LDA \
A = (byte)tmp; \
SET_NZ(A)
/* 6502 ********************************************************
* LDX Load index X
***************************************************************/
#define LDX \
X = (byte)tmp; \
SET_NZ(X)
/* 6502 ********************************************************
* LDY Load index Y
***************************************************************/
#define LDY \
Y = (byte)tmp; \
SET_NZ(Y)
/* 6502 ********************************************************
* LSR Logic shift right
* 0 -> [7][6][5][4][3][2][1][0] -> C
***************************************************************/
#define LSR \
P = (P & ~_fC) | (tmp & _fC); \
tmp = (byte)tmp >> 1; \
SET_NZ(tmp)
/* 6502 ********************************************************
* NOP No operation
***************************************************************/
#define NOP
/* 6502 ********************************************************
* ORA Logical inclusive or
***************************************************************/
#define ORA \
A = (byte)(A | tmp); \
SET_NZ(A)
/* 6502 ********************************************************
* PHA Push accumulator
***************************************************************/
#define PHA \
PUSH(A)
/* 6502 ********************************************************
* PHP Push processor status (flags)
***************************************************************/
#define PHP \
COMPOSE_P; \
PUSH(P)
/* 6502 ********************************************************
* PLA Pull accumulator
***************************************************************/
#define PLA \
PULL(A); \
SET_NZ(A)
/* 6502 ********************************************************
* PLP Pull processor status (flags)
***************************************************************/
#if LAZY_FLAGS
#define PLP \
if (P & _fI) \
{ \
PULL(P); \
if (m6502.pending_irq && !(P & _fI)) \
m6502.after_cli = 1; \
} \
else \
{ \
PULL(P); \
} \
P |= _fT; \
NZ = ((P & _fN) << 8) | ((P & _fZ) ^ _fZ)
#else
#define PLP \
if (P & _fI) \
{ \
PULL(P); \
if (m6502.pending_irq && !(P & _fI)) \
m6502.after_cli = 1; \
} \
else \
{ \
PULL(P); \
} \
P |= _fT
#endif
/* 6502 ********************************************************
* ROL Rotate left
* new C <- [7][6][5][4][3][2][1][0] <- C
***************************************************************/
#define ROL \
tmp = (tmp << 1) | (P & _fC); \
P = (P & ~_fC) | ((tmp >> 8) & _fC); \
tmp = (byte)tmp; \
SET_NZ(tmp)
/* 6502 ********************************************************
* ROR Rotate right
* C -> [7][6][5][4][3][2][1][0] -> new C
***************************************************************/
#define ROR \
tmp |= (P & _fC) << 8; \
P = (P & ~_fC) | (tmp & _fC); \
tmp = (byte)(tmp >> 1); \
SET_NZ(tmp)
/* 6502 ********************************************************
* RTI Return from interrupt
* pull flags, pull PC lo, pull PC hi and increment PC
* PCW++;
***************************************************************/
#if LAZY_FLAGS
#define RTI \
PULL(P); \
PULL(PCL); \
PULL(PCH); \
P |= _fT; \
NZ = ((P & _fN) << 8) | ((P & _fZ) ^ _fZ); \
if (m6502.pending_irq && !(P & _fI)) \
m6502.after_cli = 1; \
change_pc16(PCD)
#else
#define RTI \
PULL(P); \
PULL(PCL); \
PULL(PCH); \
P |= _fT; \
if (m6502.pending_irq && !(P & _fI)) \
m6502.after_cli = 1; \
change_pc16(PCD)
#endif
/* 6502 ********************************************************
* RTS Return from subroutine
* pull PC lo, PC hi and increment PC
***************************************************************/
#define RTS \
PULL(PCL); \
PULL(PCH); \
PCW++; \
change_pc16(PCD)
/* 6502 ********************************************************
* SBC Subtract with carry
***************************************************************/
#define SBC \
if (P & _fD) \
{ \
int c = (P & _fC) ^ _fC; \
int sum = A - tmp - c; \
int lo = (A & 0x0f) - (tmp & 0x0f) - c; \
int hi = (A & 0xf0) - (tmp & 0xf0); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -