/* common */
#include "abend.h"
+#include "attrib.h"
#include "print.h"
/* sim65 */
-/* Return the flags as a boolean value */
+/* Return the flags as a boolean value (0/1) */
#define GET_CF() ((SR & CF) != 0)
#define GET_ZF() ((SR & ZF) != 0)
#define GET_IF() ((SR & IF) != 0)
/* Special test and set macros. The meaning of the parameter depends on the
* actual flag that should be set or reset.
*/
-#define TEST_ZF(v) SET_ZF (((v) & 0xFF) == 0)
-#define TEST_SF(v) SET_SF (((v) & 0x80) != 0)
-#define TEST_CF(v) SET_CF (((v) & 0xFF00) != 0)
+#define TEST_ZF(v) SET_ZF (((v) & 0xFF) == 0)
+#define TEST_SF(v) SET_SF (((v) & 0x80) != 0)
+#define TEST_CF(v) SET_CF (((v) & 0xFF00) != 0)
/* Program counter halves */
#define PCL (PC & 0xFF)
#define PCH ((PC >> 8) & 0xFF)
/* Stack operations */
-#define PUSH(Val) WriteMem (StackPage + SP--, Val)
-#define POP() ReadMem (StackPage + ++SP)
+#define PUSH(Val) MemWriteByte (StackPage + SP--, Val)
+#define POP() MemReadByte (StackPage + ++SP)
/* Test for page cross */
#define PAGE_CROSS(addr,offs) ((((addr) & 0xFF) + offs) >= 0x100)
/* #imm */
#define AC_OP_IMM(op) \
Cycles = 2; \
- AC = AC op ReadMem (PC+1); \
+ AC = AC op MemReadByte (PC+1); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
/* zp */
#define AC_OP_ZP(op) \
Cycles = 3; \
- AC = AC op ReadMem (ReadMem (PC+1)); \
+ AC = AC op MemReadByte (MemReadByte (PC+1));\
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
#define AC_OP_ZPX(op) \
unsigned char ZPAddr; \
Cycles = 4; \
- ZPAddr = ReadMem (PC+1) + XR; \
- AC = AC op ReadMem (ZPAddr); \
+ ZPAddr = MemReadByte (PC+1) + XR; \
+ AC = AC op MemReadByte (ZPAddr); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
#define AC_OP_ZPY(op) \
unsigned char ZPAddr; \
Cycles = 4; \
- ZPAddr = ReadMem (PC+1) + YR; \
- AC = AC op ReadMem (ZPAddr); \
+ ZPAddr = MemReadByte (PC+1) + YR; \
+ AC = AC op MemReadByte (ZPAddr); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
#define AC_OP_ABS(op) \
unsigned Addr; \
Cycles = 4; \
- Addr = ReadMemW (PC+1); \
- AC = AC op ReadMem (Addr); \
+ Addr = MemReadWord (PC+1); \
+ AC = AC op MemReadByte (Addr); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 3
#define AC_OP_ABSX(op) \
unsigned Addr; \
Cycles = 4; \
- Addr = ReadMemW (PC+1); \
+ Addr = MemReadWord (PC+1); \
if (PAGE_CROSS (Addr, XR)) { \
++Cycles; \
} \
- AC = AC | ReadMem (Addr + XR); \
+ AC = AC | MemReadByte (Addr + XR); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 3
#define AC_OP_ABSY(op) \
unsigned Addr; \
Cycles = 4; \
- Addr = ReadMemW (PC+1); \
+ Addr = MemReadWord (PC+1); \
if (PAGE_CROSS (Addr, YR)) { \
++Cycles; \
} \
- AC = AC | ReadMem (Addr + YR); \
+ AC = AC | MemReadByte (Addr + YR); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 3
unsigned char ZPAddr; \
unsigned Addr; \
Cycles = 6; \
- ZPAddr = ReadMem (PC+1) + XR; \
- Addr = ReadZeroPageW (ZPAddr); \
- AC = AC op ReadMem (Addr); \
+ ZPAddr = MemReadByte (PC+1) + XR; \
+ Addr = MemReadZPWord (ZPAddr); \
+ AC = AC op MemReadByte (Addr); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
unsigned char ZPAddr; \
unsigned Addr; \
Cycles = 5; \
- ZPAddr = ReadMem (PC+1); \
- Addr = ReadZeroPageW (ZPAddr) + YR; \
- AC = AC op ReadMem (Addr); \
+ ZPAddr = MemReadByte (PC+1); \
+ Addr = MemReadZPWord (ZPAddr) + YR; \
+ AC = AC op MemReadByte (Addr); \
TEST_ZF (AC); \
TEST_SF (AC); \
PC += 2
+/* ADC */
+#define ADC(v) \
+ if (GET_DF ()) { \
+ NotImplemented (); \
+ } else { \
+ unsigned Val; \
+ unsigned char rhs = v; \
+ Val = AC + rhs + GET_CF (); \
+ AC = (unsigned char) Val; \
+ TEST_ZF (AC); \
+ TEST_SF (AC); \
+ TEST_CF (Val); \
+ SET_OF (!((AC ^ rhs) & 0x80) && \
+ ((AC ^ Val) & 0x80)); \
+ }
+
/* branches */
#define BRANCH(cond) \
Cycles = 2; \
signed char Offs; \
unsigned char OldPCH; \
++Cycles; \
- Offs = (signed char) ReadMem (PC+1); \
+ Offs = (signed char) MemReadByte (PC+1);\
OldPCH = PCH; \
- PC += (int) Offs; \
+ PC += 2 + (int) Offs; \
if (PCH != OldPCH) { \
++Cycles; \
} \
}
+/* ROL */
+#define ROL(Val) \
+ Val <<= 1; \
+ if (GET_CF ()) { \
+ Val |= 0x01; \
+ } \
+ TEST_ZF (Val); \
+ TEST_SF (Val); \
+ TEST_CF (Val)
+
+/* ROR */
+#define ROR(Val) \
+ if (GET_CF ()) { \
+ Val |= 0x100; \
+ } \
+ SET_CF (Val & 0x01); \
+ Val >>= 1; \
+ TEST_ZF (Val); \
+ TEST_SF (Val)
+
+/* SBC */
+#define SBC(v) \
+ if (GET_DF ()) { \
+ NotImplemented (); \
+ } else { \
+ unsigned Val; \
+ unsigned char rhs = v; \
+ Val = AC - rhs - (!GET_CF ()); \
+ AC = (unsigned char) Val; \
+ TEST_ZF (AC); \
+ TEST_SF (AC); \
+ SET_CF (Val <= 0xFF); \
+ SET_OF (((AC^rhs) & (AC^Val) & 0x80)); \
+ }
+
+
/*****************************************************************************/
/* Helper functions */
-static void Illegal (void)
+static void OPC_Illegal (void) attribute ((noreturn));
+static void OPC_Illegal (void)
{
- fprintf (stderr, "Illegal: $%02X\n", ReadMem (PC));
+ fprintf (stderr, "Illegal: $%02X\n", MemReadByte (PC));
exit (EXIT_FAILURE);
}
+static void NotImplemented (void) attribute ((noreturn));
static void NotImplemented (void)
{
- fprintf (stderr, "Not implemented: $%02X\n", ReadMem (PC));
+ fprintf (stderr, "Not implemented: $%02X\n", MemReadByte (PC));
exit (EXIT_FAILURE);
}
PUSH (PCL);
PUSH (SR);
SET_IF (1);
- PC = ReadMemW (0xFFFE);
+ PC = MemReadWord (0xFFFE);
}
-static void OPC_6502_02 (void)
-/* Opcode $02 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_03 (void)
-/* Opcode $03 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_04 (void)
-/* Opcode $04 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_05 (void)
/* Opcode $05: ORA zp */
{
unsigned char ZPAddr;
unsigned Val;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr) << 1;
- WriteMem (ZPAddr, (unsigned char) Val);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr) << 1;
+ MemWriteByte (ZPAddr, (unsigned char) Val);
TEST_ZF (Val & 0xFF);
TEST_SF (Val);
SET_CF (Val & 0x100);
-static void OPC_6502_07 (void)
-/* Opcode $07 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_08 (void)
/* Opcode $08: PHP */
{
-static void OPC_6502_0B (void)
-/* Opcode $0B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_0C (void)
-/* Opcode $0C */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_0D (void)
/* Opcode $0D: ORA abs */
{
unsigned Addr;
unsigned Val;
Cycles = 6;
- Addr = ReadMemW (PC+1);
- Val = ReadMem (Addr) << 1;
- WriteMem (Addr, (unsigned char) Val);
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr) << 1;
+ MemWriteByte (Addr, (unsigned char) Val);
TEST_ZF (Val & 0xFF);
TEST_SF (Val);
SET_CF (Val & 0x100);
-static void OPC_6502_0F (void)
-/* Opcode $0F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_10 (void)
/* Opcode $10: BPL */
{
-static void OPC_6502_12 (void)
-/* Opcode $12 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_13 (void)
-/* Opcode $13 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_14 (void)
-/* Opcode $14 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_15 (void)
/* Opcode $15: ORA zp,x */
{
unsigned char ZPAddr;
unsigned Val;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Val = ReadMem (ZPAddr) << 1;
- WriteMem (ZPAddr, (unsigned char) Val);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr) << 1;
+ MemWriteByte (ZPAddr, (unsigned char) Val);
TEST_ZF (Val & 0xFF);
TEST_SF (Val);
SET_CF (Val & 0x100);
-static void OPC_6502_17 (void)
-/* Opcode $17 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_18 (void)
/* Opcode $18: CLC */
{
-static void OPC_6502_1A (void)
-/* Opcode $1A */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_1B (void)
-/* Opcode $1B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_1C (void)
-/* Opcode $1C */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_1D (void)
/* Opcode $1D: ORA abs,x */
{
unsigned Addr;
unsigned Val;
Cycles = 7;
- Addr = ReadMemW (PC+1) + XR;
- Val = ReadMem (Addr) << 1;
- WriteMem (Addr, (unsigned char) Val);
+ Addr = MemReadWord (PC+1) + XR;
+ Val = MemReadByte (Addr) << 1;
+ MemWriteByte (Addr, (unsigned char) Val);
TEST_ZF (Val & 0xFF);
TEST_SF (Val);
SET_CF (Val & 0x100);
-static void OPC_6502_1F (void)
-/* Opcode $1F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_20 (void)
/* Opcode $20: JSR */
{
unsigned Addr;
Cycles = 6;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
PC += 2;
PUSH (PCH);
PUSH (PCL);
-static void OPC_6502_22 (void)
-/* Opcode $22 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_23 (void)
-/* Opcode $23 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_24 (void)
/* Opcode $24: BIT zp */
{
unsigned char ZPAddr;
unsigned char Val;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr);
SET_SF (Val & 0x80);
SET_OF (Val & 0x40);
SET_ZF ((Val & AC) == 0);
unsigned char ZPAddr;
unsigned Val;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr) << 1;
- if (GET_CF ()) {
- Val |= 0x01;
- }
- AC = (unsigned char) Val;
- TEST_ZF (AC);
- TEST_SF (AC);
- TEST_CF (Val);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr);
+ ROL (Val);
+ MemWriteByte (ZPAddr, Val);
PC += 2;
}
-static void OPC_6502_27 (void)
-/* Opcode $27 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_28 (void)
/* Opcode $28: PLP */
{
{
unsigned Val;
Cycles = 2;
- Val = AC << 1;
- if (GET_CF ()) {
- Val |= 0x01;
- }
+ Val = AC;
+ ROL (Val);
AC = (unsigned char) Val;
- TEST_ZF (AC);
- TEST_SF (AC);
- TEST_CF (Val);
PC += 1;
}
-static void OPC_6502_2B (void)
-/* Opcode $2B */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_2C (void)
/* Opcode $2C: BIT abs */
{
unsigned Addr;
unsigned char Val;
Cycles = 4;
- Addr = ReadMem (PC+1);
- Val = ReadMem (Addr);
+ Addr = MemReadByte (PC+1);
+ Val = MemReadByte (Addr);
SET_SF (Val & 0x80);
SET_OF (Val & 0x40);
SET_ZF ((Val & AC) == 0);
unsigned Addr;
unsigned Val;
Cycles = 6;
- Addr = ReadMemW (PC+1);
- Val = ReadMem (Addr) << 1;
- if (GET_CF ()) {
- Val |= 0x01;
- }
- AC = (unsigned char) Val;
- TEST_ZF (AC);
- TEST_SF (AC);
- TEST_CF (Val);
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr);
+ ROL (Val);
+ MemWriteByte (Addr, Val);
PC += 3;
}
-static void OPC_6502_2F (void)
-/* Opcode $2F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_30 (void)
/* Opcode $30: BMI */
{
-static void OPC_6502_32 (void)
-/* Opcode $32 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_33 (void)
-/* Opcode $33 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_34 (void)
-/* Opcode $34 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_35 (void)
/* Opcode $35: AND zp,x */
{
unsigned char ZPAddr;
unsigned Val;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Val = ReadMem (ZPAddr) << 1;
- if (GET_CF ()) {
- Val |= 0x01;
- }
- AC = (unsigned char) Val;
- TEST_ZF (AC);
- TEST_SF (AC);
- TEST_CF (Val);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr);
+ ROL (Val);
+ MemWriteByte (ZPAddr, Val);
PC += 2;
}
-static void OPC_6502_37 (void)
-/* Opcode $37 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_38 (void)
/* Opcode $38: SEC */
{
-static void OPC_6502_3A (void)
-/* Opcode $3A */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_3B (void)
-/* Opcode $3B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_3C (void)
-/* Opcode $3C */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_3D (void)
/* Opcode $3D: AND abs,x */
{
unsigned Addr;
unsigned Val;
Cycles = 7;
- Addr = ReadMemW (PC+1) + XR;
- Val = ReadMem (Addr) << 1;
- if (GET_CF ()) {
- Val |= 0x01;
- }
- AC = (unsigned char) Val;
- TEST_ZF (AC);
- TEST_SF (AC);
- TEST_CF (Val);
+ Addr = MemReadWord (PC+1) + XR;
+ Val = MemReadByte (Addr);
+ ROL (Val);
+ MemWriteByte (Addr, Val);
PC += 2;
}
-static void OPC_6502_3F (void)
-/* Opcode $3F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_40 (void)
/* Opcode $40: RTI */
{
-static void OPC_6502_42 (void)
-/* Opcode $42 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_43 (void)
-/* Opcode $43 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_44 (void)
-/* Opcode $44 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_45 (void)
/* Opcode $45: EOR zp */
{
unsigned char ZPAddr;
unsigned char Val;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr);
SET_CF (Val & 0x01);
Val >>= 1;
- WriteMem (ZPAddr, Val);
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_47 (void)
-/* Opcode $47 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_48 (void)
/* Opcode $48: PHA */
{
-static void OPC_6502_4B (void)
-/* Opcode $4B */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_4C (void)
/* Opcode $4C: JMP abs */
{
Cycles = 3;
- PC = ReadMemW (PC+1);
+ PC = MemReadWord (PC+1);
}
unsigned Addr;
unsigned char Val;
Cycles = 6;
- Addr = ReadMemW (PC+1);
- Val = ReadMem (Addr);
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr);
SET_CF (Val & 0x01);
Val >>= 1;
- WriteMem (Addr, Val);
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_4F (void)
-/* Opcode $4F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_50 (void)
/* Opcode $50: BVC */
{
-static void OPC_6502_52 (void)
-/* Opcode $52 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_53 (void)
-/* Opcode $53 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_54 (void)
-/* Opcode $54 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_55 (void)
/* Opcode $55: EOR zp,x */
{
unsigned char ZPAddr;
unsigned char Val;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Val = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr);
SET_CF (Val & 0x01);
Val >>= 1;
- WriteMem (ZPAddr, Val);
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_57 (void)
-/* Opcode $57 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_58 (void)
/* Opcode $58: CLI */
{
-static void OPC_6502_5A (void)
-/* Opcode $5A */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_5B (void)
-/* Opcode $5B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_5C (void)
-/* Opcode $5C */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_5D (void)
/* Opcode $5D: EOR abs,x */
{
unsigned Addr;
unsigned char Val;
Cycles = 7;
- Addr = ReadMemW (PC+1) + XR;
- Val = ReadMem (Addr);
+ Addr = MemReadWord (PC+1) + XR;
+ Val = MemReadByte (Addr);
SET_CF (Val & 0x01);
Val >>= 1;
- WriteMem (Addr, Val);
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_5F (void)
-/* Opcode $5F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_60 (void)
/* Opcode $60: RTS */
{
static void OPC_6502_61 (void)
/* Opcode $61: ADC (zp,x) */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_62 (void)
-/* Opcode $62 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_63 (void)
-/* Opcode $63 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_64 (void)
-/* Opcode $64 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Addr;
+ Cycles = 6;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Addr = MemReadZPWord (ZPAddr);
+ ADC (MemReadByte (Addr));
+ PC += 2;
}
static void OPC_6502_65 (void)
/* Opcode $65: ADC zp */
{
- NotImplemented ();
+ unsigned char ZPAddr;
+ Cycles = 3;
+ ZPAddr = MemReadByte (PC+1);
+ ADC (MemReadByte (ZPAddr));
+ PC += 2;
}
static void OPC_6502_66 (void)
/* Opcode $66: ROR zp */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_67 (void)
-/* Opcode $67 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Val;
+ Cycles = 5;
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr);
+ ROR (Val);
+ MemWriteByte (ZPAddr, Val);
+ PC += 2;
}
static void OPC_6502_69 (void)
/* Opcode $69: ADC #imm */
{
- NotImplemented ();
+ Cycles = 2;
+ ADC (MemReadByte (PC+1));
+ PC += 2;
}
static void OPC_6502_6A (void)
/* Opcode $6A: ROR a */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_6B (void)
-/* Opcode $6B */
-{
- Illegal ();
+ unsigned Val;
+ Cycles = 2;
+ Val = AC;
+ ROR (Val);
+ AC = (unsigned char) Val;
+ PC += 1;
}
{
unsigned Addr;
Cycles = 5;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (CPU == CPU_6502) {
/* Emulate the 6502 bug */
- PC = ReadMem (Addr);
+ PC = MemReadByte (Addr);
Addr = (Addr & 0xFF00) | ((Addr + 1) & 0xFF);
- PC |= (ReadMem (Addr) << 8);
+ PC |= (MemReadByte (Addr) << 8);
} else {
/* 65C02 and above have this bug fixed */
- PC = ReadMemW (Addr);
+ PC = MemReadWord (Addr);
}
PC += 3;
}
static void OPC_6502_6D (void)
/* Opcode $6D: ADC abs */
{
- NotImplemented ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ ADC (MemReadByte (Addr));
+ PC += 3;
}
static void OPC_6502_6E (void)
/* Opcode $6E: ROR abs */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_6F (void)
-/* Opcode $6F */
-{
- Illegal ();
+ unsigned Addr;
+ unsigned Val;
+ Cycles = 6;
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr);
+ ROR (Val);
+ MemWriteByte (Addr, Val);
+ PC += 3;
}
static void OPC_6502_71 (void)
/* Opcode $71: ADC (zp),y */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_72 (void)
-/* Opcode $72 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_73 (void)
-/* Opcode $73 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_74 (void)
-/* Opcode $74 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Addr;
+ Cycles = 5;
+ ZPAddr = MemReadByte (PC+1);
+ Addr = MemReadZPWord (ZPAddr);
+ if (PAGE_CROSS (Addr, YR)) {
+ ++Cycles;
+ }
+ ADC (MemReadByte (Addr + YR));
+ PC += 2;
}
static void OPC_6502_75 (void)
/* Opcode $75: ADC zp,x */
{
- NotImplemented ();
+ unsigned char ZPAddr;
+ Cycles = 4;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ ADC (MemReadByte (ZPAddr));
+ PC += 2;
}
static void OPC_6502_76 (void)
/* Opcode $76: ROR zp,x */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_77 (void)
-/* Opcode $77 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Val;
+ Cycles = 6;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr);
+ ROR (Val);
+ MemWriteByte (ZPAddr, Val);
+ PC += 2;
}
static void OPC_6502_79 (void)
/* Opcode $79: ADC abs,y */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_7A (void)
-/* Opcode $7A */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_7B (void)
-/* Opcode $7B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_7C (void)
-/* Opcode $7C */
-{
- Illegal ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ if (PAGE_CROSS (Addr, YR)) {
+ ++Cycles;
+ }
+ ADC (MemReadByte (Addr + YR));
+ PC += 3;
}
static void OPC_6502_7D (void)
/* Opcode $7D: ADC abs,x */
{
- NotImplemented ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ if (PAGE_CROSS (Addr, XR)) {
+ ++Cycles;
+ }
+ ADC (MemReadByte (Addr + XR));
+ PC += 3;
}
static void OPC_6502_7E (void)
/* Opcode $7E: ROR abs,x */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_7F (void)
-/* Opcode $7F */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_80 (void)
-/* Opcode $80 */
-{
- Illegal ();
+ unsigned Addr;
+ unsigned Val;
+ Cycles = 7;
+ Addr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (Addr);
+ ROR (Val);
+ MemWriteByte (Addr, Val);
+ PC += 3;
}
static void OPC_6502_81 (void)
/* Opcode $81: STA (zp,x) */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_82 (void)
-/* Opcode $82 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_83 (void)
-/* Opcode $83 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Addr;
+ Cycles = 6;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Addr = MemReadZPWord (ZPAddr);
+ MemWriteByte (Addr, AC);
+ PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- WriteMem (ZPAddr, YR);
+ ZPAddr = MemReadByte (PC+1);
+ MemWriteByte (ZPAddr, YR);
PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- WriteMem (ZPAddr, AC);
+ ZPAddr = MemReadByte (PC+1);
+ MemWriteByte (ZPAddr, AC);
PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- WriteMem (ZPAddr, XR);
+ ZPAddr = MemReadByte (PC+1);
+ MemWriteByte (ZPAddr, XR);
PC += 2;
}
-static void OPC_6502_87 (void)
-/* Opcode $87 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_88 (void)
/* Opcode $88: DEY */
{
Cycles = 2;
--YR;
TEST_ZF (YR);
- TEST_SF (YR);
- PC += 1;
-}
-
-
-
-static void OPC_6502_89 (void)
-/* Opcode $89 */
-{
- Illegal ();
+ TEST_SF (YR);
+ PC += 1;
}
-static void OPC_6502_8B (void)
-/* Opcode $8B */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_8C (void)
/* Opcode $8C: STY abs */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- WriteMem (Addr, YR);
+ Addr = MemReadWord (PC+1);
+ MemWriteByte (Addr, YR);
PC += 3;
}
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- WriteMem (Addr, AC);
+ Addr = MemReadWord (PC+1);
+ MemWriteByte (Addr, AC);
PC += 3;
}
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- WriteMem (Addr, XR);
+ Addr = MemReadWord (PC+1);
+ MemWriteByte (Addr, XR);
PC += 3;
}
-static void OPC_6502_8F (void)
-/* Opcode $8F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_90 (void)
/* Opcode $90: BCC */
{
unsigned char ZPAddr;
unsigned Addr;
Cycles = 6;
- ZPAddr = ReadMem (PC+1);
- Addr = ReadZeroPageW (ZPAddr) + YR;
- WriteMem (Addr, AC);
+ ZPAddr = MemReadByte (PC+1);
+ Addr = MemReadZPWord (ZPAddr) + YR;
+ MemWriteByte (Addr, AC);
PC += 2;
}
-static void OPC_6502_92 (void)
-/* Opcode $92 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_93 (void)
-/* Opcode $93 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_94 (void)
/* Opcode $94: STY zp,x */
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + XR;
- WriteMem (ZPAddr, YR);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ MemWriteByte (ZPAddr, YR);
PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + XR;
- WriteMem (ZPAddr, AC);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ MemWriteByte (ZPAddr, AC);
PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + YR;
- WriteMem (ZPAddr, XR);
+ ZPAddr = MemReadByte (PC+1) + YR;
+ MemWriteByte (ZPAddr, XR);
PC += 2;
}
-static void OPC_6502_97 (void)
-/* Opcode $97 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_98 (void)
/* Opcode $98: TYA */
{
{
unsigned Addr;
Cycles = 5;
- Addr = ReadMemW (PC+1) + YR;
- WriteMem (Addr, AC);
+ Addr = MemReadWord (PC+1) + YR;
+ MemWriteByte (Addr, AC);
PC += 3;
}
-static void OPC_6502_9B (void)
-/* Opcode $9B */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_9C (void)
-/* Opcode $9C */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_9D (void)
/* Opcode $9D: STA abs,x */
{
unsigned Addr;
Cycles = 5;
- Addr = ReadMemW (PC+1) + XR;
- WriteMem (Addr, AC);
+ Addr = MemReadWord (PC+1) + XR;
+ MemWriteByte (Addr, AC);
PC += 3;
}
-static void OPC_6502_9E (void)
-/* Opcode $9E */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_9F (void)
-/* Opcode $9F */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_A0 (void)
/* Opcode $A0: LDY #imm */
{
Cycles = 2;
- YR = ReadMem (PC+1);
+ YR = MemReadByte (PC+1);
TEST_ZF (YR);
TEST_SF (YR);
PC += 2;
unsigned char ZPAddr;
unsigned Addr;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Addr = ReadZeroPageW (ZPAddr);
- AC = ReadMem (Addr);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Addr = MemReadZPWord (ZPAddr);
+ AC = MemReadByte (Addr);
TEST_ZF (AC);
TEST_SF (AC);
PC += 2;
/* Opcode $A2: LDX #imm */
{
Cycles = 2;
- XR = ReadMem (PC+1);
+ XR = MemReadByte (PC+1);
TEST_ZF (XR);
TEST_SF (XR);
PC += 2;
-static void OPC_6502_A3 (void)
-/* Opcode $A3 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_A4 (void)
/* Opcode $A4: LDY zp */
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- YR = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ YR = MemReadByte (ZPAddr);
TEST_ZF (YR);
TEST_SF (YR);
PC += 2;
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- AC = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ AC = MemReadByte (ZPAddr);
TEST_ZF (AC);
TEST_SF (AC);
PC += 2;
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- XR = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ XR = MemReadByte (ZPAddr);
TEST_ZF (XR);
TEST_SF (XR);
PC += 2;
-static void OPC_6502_A7 (void)
-/* Opcode $A7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_A8 (void)
/* Opcode $A8: TAY */
{
/* Opcode $A9: LDA #imm */
{
Cycles = 2;
- AC = ReadMem (PC+1);
+ AC = MemReadByte (PC+1);
TEST_ZF (AC);
TEST_SF (AC);
PC += 2;
-static void OPC_6502_AB (void)
-/* Opcode $AB */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_AC (void)
/* Opcode $AC: LDY abs */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- YR = ReadMem (Addr);
+ Addr = MemReadWord (PC+1);
+ YR = MemReadByte (Addr);
TEST_ZF (YR);
TEST_SF (YR);
PC += 3;
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- AC = ReadMem (Addr);
+ Addr = MemReadWord (PC+1);
+ AC = MemReadByte (Addr);
TEST_ZF (AC);
TEST_SF (AC);
PC += 3;
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- XR = ReadMem (Addr);
+ Addr = MemReadWord (PC+1);
+ XR = MemReadByte (Addr);
TEST_ZF (XR);
TEST_SF (XR);
PC += 3;
-static void OPC_6502_AF (void)
-/* Opcode $AF */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_B0 (void)
/* Opcode $B0: BCS */
{
unsigned char ZPAddr;
unsigned Addr;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Addr = ReadZeroPageW (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ Addr = MemReadZPWord (ZPAddr);
if (PAGE_CROSS (Addr, YR)) {
++Cycles;
}
- AC = ReadMem (Addr + YR);
+ AC = MemReadByte (Addr + YR);
TEST_ZF (AC);
TEST_SF (AC);
PC += 2;
-static void OPC_6502_B2 (void)
-/* Opcode $B2 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_B3 (void)
-/* Opcode $B3 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_B4 (void)
/* Opcode $B4: LDY zp,x */
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + XR;
- YR = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ YR = MemReadByte (ZPAddr);
TEST_ZF (YR);
TEST_SF (YR);
PC += 2;
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + XR;
- AC = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ AC = MemReadByte (ZPAddr);
TEST_ZF (AC);
TEST_SF (AC);
PC += 2;
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + YR;
- XR = ReadMem (ZPAddr);
+ ZPAddr = MemReadByte (PC+1) + YR;
+ XR = MemReadByte (ZPAddr);
TEST_ZF (XR);
TEST_SF (XR);
PC += 2;
-static void OPC_6502_B7 (void)
-/* Opcode $B7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_B8 (void)
/* Opcode $B8: CLV */
{
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, YR)) {
++Cycles;
}
- AC = ReadMem (Addr + YR);
+ AC = MemReadByte (Addr + YR);
TEST_ZF (AC);
TEST_SF (AC);
PC += 3;
-static void OPC_6502_BB (void)
-/* Opcode $BB */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_BC (void)
/* Opcode $BC: LDY abs,x */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, XR)) {
++Cycles;
}
- YR = ReadMem (Addr + XR);
+ YR = MemReadByte (Addr + XR);
TEST_ZF (YR);
TEST_SF (YR);
PC += 3;
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, XR)) {
++Cycles;
}
- AC = ReadMem (Addr + XR);
+ AC = MemReadByte (Addr + XR);
TEST_ZF (AC);
TEST_SF (AC);
PC += 3;
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, YR)) {
++Cycles;
}
- XR = ReadMem (Addr + YR);
+ XR = MemReadByte (Addr + YR);
TEST_ZF (XR);
TEST_SF (XR);
PC += 3;
-static void OPC_6502_BF (void)
-/* Opcode $BF */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_C0 (void)
/* Opcode $C0: CPY #imm */
{
Cycles = 2;
- CMP (YR, ReadMem (PC+1));
+ CMP (YR, MemReadByte (PC+1));
PC += 2;
}
unsigned char ZPAddr;
unsigned Addr;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Addr = ReadZeroPageW (ZPAddr);
- CMP (AC, ReadMem (Addr));
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Addr = MemReadZPWord (ZPAddr);
+ CMP (AC, MemReadByte (Addr));
PC += 2;
}
-static void OPC_6502_C2 (void)
-/* Opcode $C2 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_C3 (void)
-/* Opcode $C3 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_C4 (void)
/* Opcode $C4: CPY zp */
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- CMP (YR, ReadMem (ZPAddr));
+ ZPAddr = MemReadByte (PC+1);
+ CMP (YR, MemReadByte (ZPAddr));
PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- CMP (AC, ReadMem (ZPAddr));
+ ZPAddr = MemReadByte (PC+1);
+ CMP (AC, MemReadByte (ZPAddr));
PC += 2;
}
unsigned char ZPAddr;
unsigned char Val;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr) - 1;
- WriteMem (ZPAddr, Val);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr) - 1;
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_C7 (void)
-/* Opcode $C7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_C8 (void)
/* Opcode $C8: INY */
{
/* Opcode $C9: CMP #imm */
{
Cycles = 2;
- CMP (AC, ReadMem (PC+1));
+ CMP (AC, MemReadByte (PC+1));
PC += 2;
}
-static void OPC_6502_CB (void)
-/* Opcode $CB */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_CC (void)
/* Opcode $CC: CPY abs */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- CMP (YR, ReadMem (Addr));
+ Addr = MemReadWord (PC+1);
+ CMP (YR, MemReadByte (Addr));
PC += 3;
}
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- CMP (AC, ReadMem (Addr));
+ Addr = MemReadWord (PC+1);
+ CMP (AC, MemReadByte (Addr));
PC += 3;
}
unsigned Addr;
unsigned char Val;
Cycles = 6;
- Addr = ReadMemW (PC+1);
- Val = ReadMem (Addr) - 1;
- WriteMem (Addr, Val);
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr) - 1;
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_CF (void)
-/* Opcode $CF */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_D0 (void)
/* Opcode $D0: BNE */
{
unsigned ZPAddr;
unsigned Addr;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Addr = ReadMemW (ZPAddr);
+ ZPAddr = MemReadByte (PC+1);
+ Addr = MemReadWord (ZPAddr);
if (PAGE_CROSS (Addr, YR)) {
++Cycles;
}
- CMP (AC, ReadMem (Addr + YR));
+ CMP (AC, MemReadByte (Addr + YR));
PC += 2;
}
-static void OPC_6502_D2 (void)
-/* Opcode $D2 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_D3 (void)
-/* Opcode $D3 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_D4 (void)
-/* Opcode $D4 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_D5 (void)
/* Opcode $D5: CMP zp,x */
{
unsigned char ZPAddr;
Cycles = 4;
- ZPAddr = ReadMem (PC+1) + XR;
- CMP (AC, ReadMem (ZPAddr));
+ ZPAddr = MemReadByte (PC+1) + XR;
+ CMP (AC, MemReadByte (ZPAddr));
PC += 2;
}
unsigned char ZPAddr;
unsigned char Val;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Val = ReadMem (ZPAddr) - 1;
- WriteMem (ZPAddr, Val);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr) - 1;
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_D7 (void)
-/* Opcode $D7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_D8 (void)
/* Opcode $D8: CLD */
{
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, YR)) {
++Cycles;
}
- CMP (AC, ReadMem (Addr + YR));
+ CMP (AC, MemReadByte (Addr + YR));
PC += 3;
}
-static void OPC_6502_DA (void)
-/* Opcode $DA */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_DB (void)
-/* Opcode $DB */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_DC (void)
-/* Opcode $DC */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_DD (void)
/* Opcode $DD: CMP abs,x */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
+ Addr = MemReadWord (PC+1);
if (PAGE_CROSS (Addr, XR)) {
++Cycles;
}
- CMP (AC, ReadMem (Addr + XR));
+ CMP (AC, MemReadByte (Addr + XR));
PC += 3;
}
unsigned Addr;
unsigned char Val;
Cycles = 7;
- Addr = ReadMemW (PC+1) + XR;
- Val = ReadMem (Addr) - 1;
- WriteMem (Addr, Val);
+ Addr = MemReadWord (PC+1) + XR;
+ Val = MemReadByte (Addr) - 1;
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_DF (void)
-/* Opcode $DF */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_E0 (void)
/* Opcode $E0: CPX #imm */
{
Cycles = 2;
- CMP (XR, ReadMem (PC+1));
+ CMP (XR, MemReadByte (PC+1));
PC += 2;
}
static void OPC_6502_E1 (void)
/* Opcode $E1: SBC (zp,x) */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_E2 (void)
-/* Opcode $E2 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_E3 (void)
-/* Opcode $E3 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Addr;
+ Cycles = 6;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Addr = MemReadZPWord (ZPAddr);
+ SBC (MemReadByte (Addr));
+ PC += 2;
}
{
unsigned char ZPAddr;
Cycles = 3;
- ZPAddr = ReadMem (PC+1);
- CMP (XR, ReadMem (ZPAddr));
+ ZPAddr = MemReadByte (PC+1);
+ CMP (XR, MemReadByte (ZPAddr));
PC += 2;
}
static void OPC_6502_E5 (void)
/* Opcode $E5: SBC zp */
{
- NotImplemented ();
+ unsigned char ZPAddr;
+ Cycles = 3;
+ ZPAddr = MemReadByte (PC+1);
+ SBC (MemReadByte (ZPAddr));
+ PC += 2;
}
unsigned char ZPAddr;
unsigned char Val;
Cycles = 5;
- ZPAddr = ReadMem (PC+1);
- Val = ReadMem (ZPAddr) + 1;
- WriteMem (ZPAddr, Val);
+ ZPAddr = MemReadByte (PC+1);
+ Val = MemReadByte (ZPAddr) + 1;
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_E7 (void)
-/* Opcode $E7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_E8 (void)
/* Opcode $E8: INX */
{
static void OPC_6502_E9 (void)
/* Opcode $E9: SBC #imm */
{
- NotImplemented ();
+ Cycles = 2;
+ SBC (MemReadByte (PC+1));
+ PC += 2;
}
-static void OPC_6502_EB (void)
-/* Opcode $EB */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_EC (void)
/* Opcode $EC: CPX abs */
{
unsigned Addr;
Cycles = 4;
- Addr = ReadMemW (PC+1);
- CMP (XR, ReadMem (Addr));
+ Addr = MemReadWord (PC+1);
+ CMP (XR, MemReadByte (Addr));
PC += 3;
}
static void OPC_6502_ED (void)
/* Opcode $ED: SBC abs */
{
- NotImplemented ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ SBC (MemReadByte (Addr));
+ PC += 3;
}
unsigned Addr;
unsigned char Val;
Cycles = 6;
- Addr = ReadMemW (PC+1);
- Val = ReadMem (Addr) + 1;
- WriteMem (Addr, Val);
+ Addr = MemReadWord (PC+1);
+ Val = MemReadByte (Addr) + 1;
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_EF (void)
-/* Opcode $EF */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_F0 (void)
/* Opcode $F0: BEQ */
{
static void OPC_6502_F1 (void)
/* Opcode $F1: SBC (zp),y */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_F2 (void)
-/* Opcode $F2 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_F3 (void)
-/* Opcode $F3 */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_F4 (void)
-/* Opcode $F4 */
-{
- Illegal ();
+ unsigned char ZPAddr;
+ unsigned Addr;
+ Cycles = 5;
+ ZPAddr = MemReadByte (PC+1);
+ Addr = MemReadZPWord (ZPAddr);
+ if (PAGE_CROSS (Addr, YR)) {
+ ++Cycles;
+ }
+ SBC (MemReadByte (Addr + YR));
+ PC += 2;
}
static void OPC_6502_F5 (void)
/* Opcode $F5: SBC zp,x */
{
- NotImplemented ();
+ unsigned char ZPAddr;
+ Cycles = 4;
+ ZPAddr = MemReadByte (PC+1) + XR;
+ SBC (MemReadByte (ZPAddr));
+ PC += 2;
}
unsigned char ZPAddr;
unsigned char Val;
Cycles = 6;
- ZPAddr = ReadMem (PC+1) + XR;
- Val = ReadMem (ZPAddr) + 1;
- WriteMem (ZPAddr, Val);
+ ZPAddr = MemReadByte (PC+1) + XR;
+ Val = MemReadByte (ZPAddr) + 1;
+ MemWriteByte (ZPAddr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 2;
-static void OPC_6502_F7 (void)
-/* Opcode $F7 */
-{
- Illegal ();
-}
-
-
-
static void OPC_6502_F8 (void)
/* Opcode $F8: SED */
{
static void OPC_6502_F9 (void)
/* Opcode $F9: SBC abs,y */
{
- NotImplemented ();
-}
-
-
-
-static void OPC_6502_FA (void)
-/* Opcode $FA */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_FB (void)
-/* Opcode $FB */
-{
- Illegal ();
-}
-
-
-
-static void OPC_6502_FC (void)
-/* Opcode $FC */
-{
- Illegal ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ if (PAGE_CROSS (Addr, YR)) {
+ ++Cycles;
+ }
+ SBC (MemReadByte (Addr + YR));
+ PC += 3;
}
static void OPC_6502_FD (void)
/* Opcode $FD: SBC abs,x */
{
- NotImplemented ();
+ unsigned Addr;
+ Cycles = 4;
+ Addr = MemReadWord (PC+1);
+ if (PAGE_CROSS (Addr, XR)) {
+ ++Cycles;
+ }
+ SBC (MemReadByte (Addr + XR));
+ PC += 3;
}
unsigned Addr;
unsigned char Val;
Cycles = 7;
- Addr = ReadMemW (PC+1) + XR;
- Val = ReadMem (Addr) + 1;
- WriteMem (Addr, Val);
+ Addr = MemReadWord (PC+1) + XR;
+ Val = MemReadByte (Addr) + 1;
+ MemWriteByte (Addr, Val);
TEST_ZF (Val);
TEST_SF (Val);
PC += 3;
-static void OPC_6502_FF (void)
-/* Opcode $FF */
-{
- Illegal ();
-}
-
-
-
/*****************************************************************************/
/* Data */
/*****************************************************************************/
static OPCFunc OPCTable[256] = {
OPC_6502_00,
OPC_6502_01,
- OPC_6502_02,
- OPC_6502_03,
- OPC_6502_04,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_05,
OPC_6502_06,
- OPC_6502_07,
+ OPC_Illegal,
OPC_6502_08,
OPC_6502_09,
OPC_6502_0A,
- OPC_6502_0B,
- OPC_6502_0C,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_0D,
OPC_6502_0E,
- OPC_6502_0F,
+ OPC_Illegal,
OPC_6502_10,
OPC_6502_11,
- OPC_6502_12,
- OPC_6502_13,
- OPC_6502_14,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_15,
OPC_6502_16,
- OPC_6502_17,
+ OPC_Illegal,
OPC_6502_18,
OPC_6502_19,
- OPC_6502_1A,
- OPC_6502_1B,
- OPC_6502_1C,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_1D,
OPC_6502_1E,
- OPC_6502_1F,
+ OPC_Illegal,
OPC_6502_20,
OPC_6502_21,
- OPC_6502_22,
- OPC_6502_23,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_24,
OPC_6502_25,
OPC_6502_26,
- OPC_6502_27,
+ OPC_Illegal,
OPC_6502_28,
OPC_6502_29,
OPC_6502_2A,
- OPC_6502_2B,
+ OPC_Illegal,
OPC_6502_2C,
OPC_6502_2D,
OPC_6502_2E,
- OPC_6502_2F,
+ OPC_Illegal,
OPC_6502_30,
OPC_6502_31,
- OPC_6502_32,
- OPC_6502_33,
- OPC_6502_34,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_35,
OPC_6502_36,
- OPC_6502_37,
+ OPC_Illegal,
OPC_6502_38,
OPC_6502_39,
- OPC_6502_3A,
- OPC_6502_3B,
- OPC_6502_3C,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_3D,
OPC_6502_3E,
- OPC_6502_3F,
+ OPC_Illegal,
OPC_6502_40,
OPC_6502_41,
- OPC_6502_42,
- OPC_6502_43,
- OPC_6502_44,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_45,
OPC_6502_46,
- OPC_6502_47,
+ OPC_Illegal,
OPC_6502_48,
OPC_6502_49,
OPC_6502_4A,
- OPC_6502_4B,
+ OPC_Illegal,
OPC_6502_4C,
OPC_6502_4D,
OPC_6502_4E,
- OPC_6502_4F,
+ OPC_Illegal,
OPC_6502_50,
OPC_6502_51,
- OPC_6502_52,
- OPC_6502_53,
- OPC_6502_54,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_55,
OPC_6502_56,
- OPC_6502_57,
+ OPC_Illegal,
OPC_6502_58,
OPC_6502_59,
- OPC_6502_5A,
- OPC_6502_5B,
- OPC_6502_5C,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_5D,
OPC_6502_5E,
- OPC_6502_5F,
+ OPC_Illegal,
OPC_6502_60,
OPC_6502_61,
- OPC_6502_62,
- OPC_6502_63,
- OPC_6502_64,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_65,
OPC_6502_66,
- OPC_6502_67,
+ OPC_Illegal,
OPC_6502_68,
OPC_6502_69,
OPC_6502_6A,
- OPC_6502_6B,
+ OPC_Illegal,
OPC_6502_6C,
OPC_6502_6D,
OPC_6502_6E,
- OPC_6502_6F,
+ OPC_Illegal,
OPC_6502_70,
OPC_6502_71,
- OPC_6502_72,
- OPC_6502_73,
- OPC_6502_74,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_75,
OPC_6502_76,
- OPC_6502_77,
+ OPC_Illegal,
OPC_6502_78,
OPC_6502_79,
- OPC_6502_7A,
- OPC_6502_7B,
- OPC_6502_7C,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_7D,
OPC_6502_7E,
- OPC_6502_7F,
- OPC_6502_80,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_81,
- OPC_6502_82,
- OPC_6502_83,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_84,
OPC_6502_85,
OPC_6502_86,
- OPC_6502_87,
+ OPC_Illegal,
OPC_6502_88,
- OPC_6502_89,
+ OPC_Illegal,
OPC_6502_8A,
- OPC_6502_8B,
+ OPC_Illegal,
OPC_6502_8C,
OPC_6502_8D,
OPC_6502_8E,
- OPC_6502_8F,
+ OPC_Illegal,
OPC_6502_90,
OPC_6502_91,
- OPC_6502_92,
- OPC_6502_93,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_94,
OPC_6502_95,
OPC_6502_96,
- OPC_6502_97,
+ OPC_Illegal,
OPC_6502_98,
OPC_6502_99,
OPC_6502_9A,
- OPC_6502_9B,
- OPC_6502_9C,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_9D,
- OPC_6502_9E,
- OPC_6502_9F,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_A0,
OPC_6502_A1,
OPC_6502_A2,
- OPC_6502_A3,
+ OPC_Illegal,
OPC_6502_A4,
OPC_6502_A5,
OPC_6502_A6,
- OPC_6502_A7,
+ OPC_Illegal,
OPC_6502_A8,
OPC_6502_A9,
OPC_6502_AA,
- OPC_6502_AB,
+ OPC_Illegal,
OPC_6502_AC,
OPC_6502_AD,
OPC_6502_AE,
- OPC_6502_AF,
+ OPC_Illegal,
OPC_6502_B0,
OPC_6502_B1,
- OPC_6502_B2,
- OPC_6502_B3,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_B4,
OPC_6502_B5,
OPC_6502_B6,
- OPC_6502_B7,
+ OPC_Illegal,
OPC_6502_B8,
OPC_6502_B9,
OPC_6502_BA,
- OPC_6502_BB,
+ OPC_Illegal,
OPC_6502_BC,
OPC_6502_BD,
OPC_6502_BE,
- OPC_6502_BF,
+ OPC_Illegal,
OPC_6502_C0,
OPC_6502_C1,
- OPC_6502_C2,
- OPC_6502_C3,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_C4,
OPC_6502_C5,
OPC_6502_C6,
- OPC_6502_C7,
+ OPC_Illegal,
OPC_6502_C8,
OPC_6502_C9,
OPC_6502_CA,
- OPC_6502_CB,
+ OPC_Illegal,
OPC_6502_CC,
OPC_6502_CD,
OPC_6502_CE,
- OPC_6502_CF,
+ OPC_Illegal,
OPC_6502_D0,
OPC_6502_D1,
- OPC_6502_D2,
- OPC_6502_D3,
- OPC_6502_D4,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_D5,
OPC_6502_D6,
- OPC_6502_D7,
+ OPC_Illegal,
OPC_6502_D8,
OPC_6502_D9,
- OPC_6502_DA,
- OPC_6502_DB,
- OPC_6502_DC,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_DD,
OPC_6502_DE,
- OPC_6502_DF,
+ OPC_Illegal,
OPC_6502_E0,
OPC_6502_E1,
- OPC_6502_E2,
- OPC_6502_E3,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_E4,
OPC_6502_E5,
OPC_6502_E6,
- OPC_6502_E7,
+ OPC_Illegal,
OPC_6502_E8,
OPC_6502_E9,
OPC_6502_EA,
- OPC_6502_EB,
+ OPC_Illegal,
OPC_6502_EC,
OPC_6502_ED,
OPC_6502_EE,
- OPC_6502_EF,
+ OPC_Illegal,
OPC_6502_F0,
OPC_6502_F1,
- OPC_6502_F2,
- OPC_6502_F3,
- OPC_6502_F4,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_F5,
OPC_6502_F6,
- OPC_6502_F7,
+ OPC_Illegal,
OPC_6502_F8,
OPC_6502_F9,
- OPC_6502_FA,
- OPC_6502_FB,
- OPC_6502_FC,
+ OPC_Illegal,
+ OPC_Illegal,
+ OPC_Illegal,
OPC_6502_FD,
OPC_6502_FE,
- OPC_6502_FF,
+ OPC_Illegal,
};