Merge branch 'cc65:master' into feature-add-timer

This commit is contained in:
Sidney Cadot
2024-12-22 18:16:15 +01:00
committed by GitHub
3 changed files with 381 additions and 112 deletions

View File

@@ -8,6 +8,8 @@
.import _fgetc, popptr1, pushptr1, popax, pushax, return0, ___errno .import _fgetc, popptr1, pushptr1, popax, pushax, return0, ___errno
.importzp ptr1, ptr4 .importzp ptr1, ptr4
.feature string_escapes
.include "errno.inc" .include "errno.inc"
.include "stdio.inc" .include "stdio.inc"
.include "_file.inc" .include "_file.inc"
@@ -88,7 +90,22 @@ read_loop:
bne :+ bne :+
inc ptr4+1 inc ptr4+1
: cmp #$0A ; Stop at \n ; The next code line:
;
; .byte $c9, "\n"
;
; corresponds to a CMP #imm with the target-specific newline value as its operand.
; This works because (with the 'string_escapes' feature enabled), the "\n" string
; assembles to the target-specific value for the newline character.
;
; It would be better if we could just write:
;
; cmp #'\n'
;
; Unfortunately, ca65 doesn't currently handle escape characters in character
; constants. In the longer term, fixing that would be the preferred solution.
: .byte $c9, "\n" ; cmp #'\n'
beq done beq done
bne read_loop bne read_loop

View File

@@ -37,10 +37,11 @@
/* Known bugs and limitations of the 65C02 simulation: /* Known bugs and limitations of the 65C02 simulation:
* support currently only on the level of 65SC02: * support currently only on the level of 65SC02:
BBRx, BBSx, RMBx, SMBx, WAI, and STP are unsupported BBRx, BBSx, RMBx, SMBx, WAI, and STP are unsupported
* BCD flag handling equals 6502 (unchecked if bug is simulated or wrong for
6502)
*/ */
#include <stdbool.h>
#include <stdint.h>
#include "memory.h" #include "memory.h"
#include "peripherals.h" #include "peripherals.h"
#include "error.h" #include "error.h"
@@ -663,40 +664,85 @@ static unsigned HaveIRQRequest;
TEST_SF (Regs.AC) TEST_SF (Regs.AC)
/* ADC */ /* ADC, binary mode (6502 and 65C02) */
#define ADC(v) \ #define ADC_BINARY_MODE(v) \
do { \ do { \
unsigned old = Regs.AC; \ const uint8_t op = v; \
unsigned rhs = (v & 0xFF); \ const uint8_t OldAC = Regs.AC; \
if (GET_DF ()) { \ bool carry = GET_CF(); \
unsigned lo; \ Regs.AC = (OldAC + op + carry); \
int res; \ const bool NV = Regs.AC >= 0x80; \
lo = (old & 0x0F) + (rhs & 0x0F) + GET_CF (); \ carry = OldAC + op + carry >= 0x100; \
if (lo >= 0x0A) { \ SET_SF(NV); \
lo = ((lo + 0x06) & 0x0F) + 0x10; \ SET_OF(((OldAC >= 0x80) ^ NV) & ((op >= 0x80) ^ NV)); \
} \ SET_ZF(Regs.AC == 0); \
Regs.AC = (old & 0xF0) + (rhs & 0xF0) + lo; \ SET_CF(carry); \
res = (signed char)(old & 0xF0) + \ } while (0)
(signed char)(rhs & 0xF0) + \
(signed char)lo; \ /* ADC, decimal mode (6502 behavior) */
TEST_ZF (old + rhs + GET_CF ()); \ #define ADC_DECIMAL_MODE_6502(v) \
TEST_SF (Regs.AC); \ do { \
if (Regs.AC >= 0xA0) { \ const uint8_t op = v; \
Regs.AC += 0x60; \ const uint8_t OldAC = Regs.AC; \
} \ bool carry = GET_CF(); \
TEST_CF (Regs.AC); \ const uint8_t binary_result = OldAC + op + carry; \
SET_OF ((res < -128) || (res > 127)); \ uint8_t low_nibble = (OldAC & 15) + (op & 15) + carry; \
if (CPU == CPU_65C02) { \ if ((carry = low_nibble > 9)) \
++Cycles; \ low_nibble = (low_nibble - 10) & 15; \
} \ uint8_t high_nibble = (OldAC >> 4) + (op >> 4) + carry; \
const bool NV = (high_nibble & 8) != 0; \
if ((carry = high_nibble > 9)) \
high_nibble = (high_nibble - 10) & 15; \
Regs.AC = (high_nibble << 4) | low_nibble; \
SET_SF(NV); \
SET_OF(((OldAC >= 0x80) ^ NV) & ((op >= 0x80) ^ NV)); \
SET_ZF(binary_result == 0); \
SET_CF(carry); \
} while (0)
/* ADC, decimal mode (65C02 behavior) */
#define ADC_DECIMAL_MODE_65C02(v) \
do { \
const uint8_t op = v; \
const uint8_t OldAC = Regs.AC; \
const bool OldCF = GET_CF(); \
bool carry = OldCF; \
uint8_t low_nibble = (OldAC & 15) + (op & 15) + carry; \
if ((carry = low_nibble > 9)) \
low_nibble = (low_nibble - 10) & 15; \
uint8_t high_nibble = (OldAC >> 4) + (op >> 4) + carry; \
const bool PrematureSF = (high_nibble & 8) != 0; \
if ((carry = high_nibble > 9)) \
high_nibble = (high_nibble - 10) & 15; \
Regs.AC = (high_nibble << 4) | low_nibble; \
const bool NewZF = Regs.AC == 0; \
const bool NewSF = Regs.AC >= 0x80; \
const bool NewOF = ((OldAC >= 0x80) ^ PrematureSF) & \
((op >= 0x80) ^ PrematureSF); \
SET_SF(NewSF); \
SET_OF(NewOF); \
SET_ZF(NewZF); \
SET_CF(carry); \
++Cycles; \
} while (0)
/* ADC, 6502 version */
#define ADC_6502(v) \
do { \
if (GET_DF()) { \
ADC_DECIMAL_MODE_6502(v); \
} else { \ } else { \
Regs.AC += rhs + GET_CF (); \ ADC_BINARY_MODE(v); \
TEST_ZF (Regs.AC); \ } \
TEST_SF (Regs.AC); \ } while (0)
TEST_CF (Regs.AC); \
SET_OF (!((old ^ rhs) & 0x80) && \ /* ADC, 65C02 version */
((old ^ Regs.AC) & 0x80)); \ #define ADC_65C02(v) \
Regs.AC &= 0xFF; \ do { \
if (GET_DF()) { \
ADC_DECIMAL_MODE_65C02(v); \
} else { \
ADC_BINARY_MODE(v); \
} \ } \
} while (0) } while (0)
@@ -823,7 +869,7 @@ static unsigned HaveIRQRequest;
} \ } \
SET_CF (Val & 0x01); \ SET_CF (Val & 0x01); \
Val >>= 1; \ Val >>= 1; \
ADC (Val) ADC_6502 (Val)
/* BIT */ /* BIT */
#define BIT(Val) \ #define BIT(Val) \
@@ -880,7 +926,7 @@ static unsigned HaveIRQRequest;
/* ISC */ /* ISC */
#define ISC(Val) \ #define ISC(Val) \
Val = (Val + 1) & 0xFF; \ Val = (Val + 1) & 0xFF; \
SBC(Val) SBC_6502(Val)
/* ASR */ /* ASR */
#define ASR(Val) \ #define ASR(Val) \
@@ -921,8 +967,14 @@ static unsigned HaveIRQRequest;
} while (0); } while (0);
/* ANE */ /* ANE */
/* An "unstable" illegal opcode that depends on a "constant" value that isn't
* really constant. It varies between machines, with temperature, and so on.
* Original sim65 behavior was to use the constant 0xEF here. To get behavior
* in line with the 65x02 testsuite, we now use the value 0xEE instead,
* which is also a reasonable choice that can be observed in practice.
*/
#define ANE(Val) \ #define ANE(Val) \
Val = (Regs.AC | 0xEF) & Regs.XR & Val; \ Val = (Regs.AC | 0xEE) & Regs.XR & Val; \
Regs.AC = Val; \ Regs.AC = Val; \
TEST_SF (Val); \ TEST_SF (Val); \
TEST_ZF (Val) TEST_ZF (Val)
@@ -978,33 +1030,85 @@ static unsigned HaveIRQRequest;
TEST_SF (Val); \ TEST_SF (Val); \
TEST_ZF (Val) TEST_ZF (Val)
/* SBC, binary mode (6502 and 65C02) */
/* SBC */ #define SBC_BINARY_MODE(v) \
#define SBC(v) \
do { \ do { \
unsigned r_a = Regs.AC; \ const uint8_t op = v; \
unsigned src = (v) & 0xFF; \ const uint8_t OldAC = Regs.AC; \
unsigned ccc = (Regs.SR & CF) ^ CF; \ const bool borrow = !GET_CF(); \
unsigned tmp = r_a - src - ccc; \ Regs.AC = (OldAC - op - borrow); \
\ const bool NV = Regs.AC >= 0x80; \
SET_CF(tmp < 0x100); \ SET_SF(NV); \
TEST_SF(tmp); \ SET_OF(((OldAC >= 0x80) ^ NV) & ((op < 0x80) ^ NV)); \
TEST_ZF(tmp); \ SET_ZF(Regs.AC == 0); \
SET_OF((r_a ^ tmp) & (r_a ^ src) & 0x80); \ SET_CF(OldAC >= op + borrow); \
\ } while (0)
if (GET_DF ()) { \
unsigned low = (r_a & 0x0f) - (src & 0x0f) - ccc; \ /* SBC, decimal mode (6502 behavior) */
tmp = (r_a & 0xf0) - (src & 0xf0); \ #define SBC_DECIMAL_MODE_6502(v) \
if (low & 0x10) { \ do { \
low -= 6; \ const uint8_t op = v; \
tmp -= 0x10; \ const uint8_t OldAC = Regs.AC; \
} \ bool borrow = !GET_CF(); \
tmp = (low & 0xf) | tmp; \ const uint8_t binary_result = OldAC - op - borrow; \
if (tmp & 0x100) { \ const bool NV = binary_result >= 0x80; \
tmp -= 0x60; \ uint8_t low_nibble = (OldAC & 15) - (op & 15) - borrow; \
} \ if ((borrow = low_nibble >= 0x80)) \
low_nibble = (low_nibble + 10) & 15; \
uint8_t high_nibble = (OldAC >> 4) - (op >> 4) - borrow;\
if ((borrow = high_nibble >= 0x80)) \
high_nibble = (high_nibble + 10) & 15; \
Regs.AC = (high_nibble << 4) | low_nibble; \
SET_SF(NV); \
SET_OF(((OldAC >= 0x80) ^ NV) & ((op < 0x80) ^ NV)); \
SET_ZF(binary_result == 0); \
SET_CF(!borrow); \
} while (0)
/* SBC, decimal mode (65C02 behavior) */
#define SBC_DECIMAL_MODE_65C02(v) \
do { \
const uint8_t op = v; \
const uint8_t OldAC = Regs.AC; \
bool borrow = !GET_CF(); \
uint8_t low_nibble = (OldAC & 15) - (op & 15) - borrow; \
if ((borrow = low_nibble >= 0x80)) \
low_nibble += 10; \
const bool low_nibble_still_negative = \
(low_nibble >= 0x80); \
low_nibble &= 15; \
uint8_t high_nibble = (OldAC >> 4) - (op >> 4) - borrow;\
const bool PN = (high_nibble & 8) != 0; \
if ((borrow = high_nibble >= 0x80)) \
high_nibble += 10; \
high_nibble -= low_nibble_still_negative; \
high_nibble &= 15; \
Regs.AC = (high_nibble << 4) | low_nibble; \
SET_SF(Regs.AC >= 0x80); \
SET_OF(((OldAC >= 0x80) ^ PN) & ((op < 0x80) ^ PN)); \
SET_ZF(Regs.AC == 0x00); \
SET_CF(!borrow); \
++Cycles; \
} while (0)
/* SBC, 6502 version */
#define SBC_6502(v) \
do { \
if (GET_DF()) { \
SBC_DECIMAL_MODE_6502(v); \
} else { \
SBC_BINARY_MODE(v); \
} \
} while (0)
/* SBC, 65C02 version */
#define SBC_65C02(v) \
do { \
if (GET_DF()) { \
SBC_DECIMAL_MODE_65C02(v); \
} else { \
SBC_BINARY_MODE(v); \
} \ } \
Regs.AC = tmp & 0xFF; \
} while (0) } while (0)
@@ -1353,13 +1457,37 @@ static void OPC_6502_1F (void)
static void OPC_6502_20 (void) static void OPC_6502_20 (void)
/* Opcode $20: JSR */ /* Opcode $20: JSR */
{ {
unsigned Addr; /* The obvious way to implement JSR for the 6502 is to (a) read the target address,
* and then (b) push the return address minus one. Or do (b) first, then (a).
*
* However, there is a non-obvious case where this conflicts with the actual order
* of operations that the 6502 does, which is:
*
* (a) Load the LSB of the target address.
* (b) Push the MSB of the return address, minus one.
* (c) Push the LSB of the return address, minus one.
* (d) Load the MSB of the target address.
*
* This can make a difference in a pretty esoteric case, if the JSR target is located,
* wholly or in part, inside the stack page (!). This won't happen in normal code
* but it can happen in specifically constructed examples.
*
* To deal with this, we load the LSB and MSB of the target address separately,
* with the pushing of the return address sandwiched in between, to mimic
* the order of the bus operations on a real 6502.
*/
unsigned AddrLo, AddrHi;
Cycles = 6; Cycles = 6;
Addr = MemReadWord (Regs.PC+1); Regs.PC += 1;
Regs.PC += 2; AddrLo = MemReadByte(Regs.PC);
Regs.PC += 1;
PUSH (PCH); PUSH (PCH);
PUSH (PCL); PUSH (PCL);
Regs.PC = Addr; AddrHi = MemReadByte(Regs.PC);
Regs.PC = AddrLo + (AddrHi << 8);
ParaVirtHooks (&Regs); ParaVirtHooks (&Regs);
} }
@@ -1888,11 +2016,17 @@ static void OPC_6502_60 (void)
static void OPC_6502_61 (void) static void OPC_6502_61 (void)
/* Opcode $61: ADC (zp,x) */ /* Opcode $61: ADC (zp,x) */
{ {
ALU_OP (ZPXIND, ADC); ALU_OP (ZPXIND, ADC_6502);
} }
static void OPC_65C02_61 (void)
/* Opcode $61: ADC (zp,x) */
{
ALU_OP (ZPXIND, ADC_65C02);
}
static void OPC_6502_63 (void) static void OPC_6502_63 (void)
/* Opcode $63: RRA (zp,x) */ /* Opcode $63: RRA (zp,x) */
{ {
@@ -1912,7 +2046,15 @@ static void OPC_65SC02_64 (void)
static void OPC_6502_65 (void) static void OPC_6502_65 (void)
/* Opcode $65: ADC zp */ /* Opcode $65: ADC zp */
{ {
ALU_OP (ZP, ADC); ALU_OP (ZP, ADC_6502);
}
static void OPC_65C02_65 (void)
/* Opcode $65: ADC zp */
{
ALU_OP (ZP, ADC_65C02);
} }
@@ -1948,11 +2090,17 @@ static void OPC_6502_68 (void)
static void OPC_6502_69 (void) static void OPC_6502_69 (void)
/* Opcode $69: ADC #imm */ /* Opcode $69: ADC #imm */
{ {
ALU_OP_IMM (ADC); ALU_OP_IMM (ADC_6502);
} }
static void OPC_65C02_69 (void)
/* Opcode $69: ADC #imm */
{
ALU_OP_IMM (ADC_65C02);
}
static void OPC_6502_6A (void) static void OPC_6502_6A (void)
/* Opcode $6A: ROR a */ /* Opcode $6A: ROR a */
{ {
@@ -2011,7 +2159,15 @@ static void OPC_65C02_6C (void)
static void OPC_6502_6D (void) static void OPC_6502_6D (void)
/* Opcode $6D: ADC abs */ /* Opcode $6D: ADC abs */
{ {
ALU_OP (ABS, ADC); ALU_OP (ABS, ADC_6502);
}
static void OPC_65C02_6D (void)
/* Opcode $6D: ADC abs */
{
ALU_OP (ABS, ADC_65C02);
} }
@@ -2043,15 +2199,23 @@ static void OPC_6502_70 (void)
static void OPC_6502_71 (void) static void OPC_6502_71 (void)
/* Opcode $71: ADC (zp),y */ /* Opcode $71: ADC (zp),y */
{ {
ALU_OP (ZPINDY, ADC); ALU_OP (ZPINDY, ADC_6502);
} }
static void OPC_65SC02_72 (void) static void OPC_65C02_71 (void)
/* Opcode $71: ADC (zp),y */
{
ALU_OP (ZPINDY, ADC_65C02);
}
static void OPC_65C02_72 (void)
/* Opcode $72: ADC (zp) */ /* Opcode $72: ADC (zp) */
{ {
ALU_OP (ZPIND, ADC); ALU_OP (ZPIND, ADC_65C02);
} }
@@ -2075,11 +2239,17 @@ static void OPC_65SC02_74 (void)
static void OPC_6502_75 (void) static void OPC_6502_75 (void)
/* Opcode $75: ADC zp,x */ /* Opcode $75: ADC zp,x */
{ {
ALU_OP (ZPX, ADC); ALU_OP (ZPX, ADC_6502);
} }
static void OPC_65C02_75 (void)
/* Opcode $75: ADC zp,x */
{
ALU_OP (ZPX, ADC_65C02);
}
static void OPC_6502_76 (void) static void OPC_6502_76 (void)
/* Opcode $76: ROR zp,x */ /* Opcode $76: ROR zp,x */
{ {
@@ -2109,7 +2279,15 @@ static void OPC_6502_78 (void)
static void OPC_6502_79 (void) static void OPC_6502_79 (void)
/* Opcode $79: ADC abs,y */ /* Opcode $79: ADC abs,y */
{ {
ALU_OP (ABSY, ADC); ALU_OP (ABSY, ADC_6502);
}
static void OPC_65C02_79 (void)
/* Opcode $79: ADC abs,y */
{
ALU_OP (ABSY, ADC_65C02);
} }
@@ -2151,7 +2329,15 @@ static void OPC_65SC02_7C (void)
static void OPC_6502_7D (void) static void OPC_6502_7D (void)
/* Opcode $7D: ADC abs,x */ /* Opcode $7D: ADC abs,x */
{ {
ALU_OP (ABSX, ADC); ALU_OP (ABSX, ADC_6502);
}
static void OPC_65C02_7D (void)
/* Opcode $7D: ADC abs,x */
{
ALU_OP (ABSX, ADC_65C02);
} }
@@ -2993,11 +3179,17 @@ static void OPC_6502_E0 (void)
static void OPC_6502_E1 (void) static void OPC_6502_E1 (void)
/* Opcode $E1: SBC (zp,x) */ /* Opcode $E1: SBC (zp,x) */
{ {
ALU_OP (ZPXIND, SBC); ALU_OP (ZPXIND, SBC_6502);
} }
static void OPC_65C02_E1 (void)
/* Opcode $E1: SBC (zp,x) */
{
ALU_OP (ZPXIND, SBC_65C02);
}
static void OPC_6502_E3 (void) static void OPC_6502_E3 (void)
/* Opcode $E3: ISC (zp,x) */ /* Opcode $E3: ISC (zp,x) */
{ {
@@ -3017,7 +3209,15 @@ static void OPC_6502_E4 (void)
static void OPC_6502_E5 (void) static void OPC_6502_E5 (void)
/* Opcode $E5: SBC zp */ /* Opcode $E5: SBC zp */
{ {
ALU_OP (ZP, SBC); ALU_OP (ZP, SBC_6502);
}
static void OPC_65C02_E5 (void)
/* Opcode $E5: SBC zp */
{
ALU_OP (ZP, SBC_65C02);
} }
@@ -3048,17 +3248,23 @@ static void OPC_6502_E8 (void)
/* Aliases of opcode $EA */ /* Aliases of opcode $E9 */
#define OPC_6502_EB OPC_6502_E9 #define OPC_6502_EB OPC_6502_E9
static void OPC_6502_E9 (void) static void OPC_6502_E9 (void)
/* Opcode $E9: SBC #imm */ /* Opcode $E9: SBC #imm */
{ {
ALU_OP_IMM (SBC); ALU_OP_IMM (SBC_6502);
} }
static void OPC_65C02_E9 (void)
/* Opcode $E9: SBC #imm */
{
ALU_OP_IMM (SBC_65C02);
}
/* Aliases of opcode $EA */ /* Aliases of opcode $EA */
#define OPC_6502_1A OPC_6502_EA #define OPC_6502_1A OPC_6502_EA
#define OPC_6502_3A OPC_6502_EA #define OPC_6502_3A OPC_6502_EA
@@ -3124,7 +3330,15 @@ static void OPC_6502_EC (void)
static void OPC_6502_ED (void) static void OPC_6502_ED (void)
/* Opcode $ED: SBC abs */ /* Opcode $ED: SBC abs */
{ {
ALU_OP (ABS, SBC); ALU_OP (ABS, SBC_6502);
}
static void OPC_65C02_ED (void)
/* Opcode $ED: SBC abs */
{
ALU_OP (ABS, SBC_65C02);
} }
@@ -3155,15 +3369,24 @@ static void OPC_6502_F0 (void)
static void OPC_6502_F1 (void) static void OPC_6502_F1 (void)
/* Opcode $F1: SBC (zp),y */ /* Opcode $F1: SBC (zp),y */
{ {
ALU_OP (ZPINDY, SBC); ALU_OP (ZPINDY, SBC_6502);
} }
static void OPC_65SC02_F2 (void)
static void OPC_65C02_F1 (void)
/* Opcode $F1: SBC (zp),y */
{
ALU_OP (ZPINDY, SBC_65C02);
}
static void OPC_65C02_F2 (void)
/* Opcode $F2: SBC (zp) */ /* Opcode $F2: SBC (zp) */
{ {
ALU_OP (ZPIND, SBC); ALU_OP (ZPIND, SBC_65C02);
} }
@@ -3179,7 +3402,15 @@ static void OPC_6502_F3 (void)
static void OPC_6502_F5 (void) static void OPC_6502_F5 (void)
/* Opcode $F5: SBC zp,x */ /* Opcode $F5: SBC zp,x */
{ {
ALU_OP (ZPX, SBC); ALU_OP (ZPX, SBC_6502);
}
static void OPC_65C02_F5 (void)
/* Opcode $F5: SBC zp,x */
{
ALU_OP (ZPX, SBC_65C02);
} }
@@ -3213,7 +3444,15 @@ static void OPC_6502_F8 (void)
static void OPC_6502_F9 (void) static void OPC_6502_F9 (void)
/* Opcode $F9: SBC abs,y */ /* Opcode $F9: SBC abs,y */
{ {
ALU_OP (ABSY, SBC); ALU_OP (ABSY, SBC_6502);
}
static void OPC_65C02_F9 (void)
/* Opcode $F9: SBC abs,y */
{
ALU_OP (ABSY, SBC_65C02);
} }
@@ -3241,7 +3480,15 @@ static void OPC_6502_FB (void)
static void OPC_6502_FD (void) static void OPC_6502_FD (void)
/* Opcode $FD: SBC abs,x */ /* Opcode $FD: SBC abs,x */
{ {
ALU_OP (ABSX, SBC); ALU_OP (ABSX, SBC_6502);
}
static void OPC_65C02_FD (void)
/* Opcode $FD: SBC abs,x */
{
ALU_OP (ABSX, SBC_65C02);
} }
@@ -3891,35 +4138,35 @@ static const OPFunc OP65C02Table[256] = {
OPC_65C02_5E, OPC_65C02_5E,
OPC_Illegal, // $5F: BBR5 currently unsupported OPC_Illegal, // $5F: BBR5 currently unsupported
OPC_6502_60, OPC_6502_60,
OPC_6502_61, OPC_65C02_61,
OPC_65C02_NOP22, // $62 OPC_65C02_NOP22, // $62
OPC_65C02_NOP11, // $63 OPC_65C02_NOP11, // $63
OPC_65SC02_64, OPC_65SC02_64,
OPC_6502_65, OPC_65C02_65,
OPC_6502_66, OPC_6502_66,
OPC_Illegal, // $67: RMB6 currently unsupported OPC_Illegal, // $67: RMB6 currently unsupported
OPC_6502_68, OPC_6502_68,
OPC_6502_69, OPC_65C02_69,
OPC_6502_6A, OPC_6502_6A,
OPC_65C02_NOP11, // $6B OPC_65C02_NOP11, // $6B
OPC_65C02_6C, OPC_65C02_6C,
OPC_6502_6D, OPC_65C02_6D,
OPC_6502_6E, OPC_6502_6E,
OPC_Illegal, // $6F: BBR6 currently unsupported OPC_Illegal, // $6F: BBR6 currently unsupported
OPC_6502_70, OPC_6502_70,
OPC_6502_71, OPC_65C02_71,
OPC_65SC02_72, OPC_65C02_72,
OPC_65C02_NOP11, // $73 OPC_65C02_NOP11, // $73
OPC_65SC02_74, OPC_65SC02_74,
OPC_6502_75, OPC_65C02_75,
OPC_6502_76, OPC_6502_76,
OPC_Illegal, // $77: RMB7 currently unsupported OPC_Illegal, // $77: RMB7 currently unsupported
OPC_6502_78, OPC_6502_78,
OPC_6502_79, OPC_65C02_79,
OPC_65SC02_7A, OPC_65SC02_7A,
OPC_65C02_NOP11, // $7B OPC_65C02_NOP11, // $7B
OPC_65SC02_7C, OPC_65SC02_7C,
OPC_6502_7D, OPC_65C02_7D,
OPC_65C02_7E, OPC_65C02_7E,
OPC_Illegal, // $7F: BBR7 currently unsupported OPC_Illegal, // $7F: BBR7 currently unsupported
OPC_65SC02_80, OPC_65SC02_80,
@@ -4019,35 +4266,35 @@ static const OPFunc OP65C02Table[256] = {
OPC_6502_DE, OPC_6502_DE,
OPC_Illegal, // $DF: BBS5 currently unsupported OPC_Illegal, // $DF: BBS5 currently unsupported
OPC_6502_E0, OPC_6502_E0,
OPC_6502_E1, OPC_65C02_E1,
OPC_65C02_NOP22, // $E2 OPC_65C02_NOP22, // $E2
OPC_65C02_NOP11, // $E3 OPC_65C02_NOP11, // $E3
OPC_6502_E4, OPC_6502_E4,
OPC_6502_E5, OPC_65C02_E5,
OPC_6502_E6, OPC_6502_E6,
OPC_Illegal, // $E7: SMB6 currently unsupported OPC_Illegal, // $E7: SMB6 currently unsupported
OPC_6502_E8, OPC_6502_E8,
OPC_6502_E9, OPC_65C02_E9,
OPC_6502_EA, OPC_6502_EA,
OPC_65C02_NOP11, // $EB OPC_65C02_NOP11, // $EB
OPC_6502_EC, OPC_6502_EC,
OPC_6502_ED, OPC_65C02_ED,
OPC_6502_EE, OPC_6502_EE,
OPC_Illegal, // $EF: BBS6 currently unsupported OPC_Illegal, // $EF: BBS6 currently unsupported
OPC_6502_F0, OPC_6502_F0,
OPC_6502_F1, OPC_65C02_F1,
OPC_65SC02_F2, OPC_65C02_F2,
OPC_65C02_NOP11, // $F3 OPC_65C02_NOP11, // $F3
OPC_65C02_NOP24, // $F4 OPC_65C02_NOP24, // $F4
OPC_6502_F5, OPC_65C02_F5,
OPC_6502_F6, OPC_6502_F6,
OPC_Illegal, // $F7: SMB7 currently unsupported OPC_Illegal, // $F7: SMB7 currently unsupported
OPC_6502_F8, OPC_6502_F8,
OPC_6502_F9, OPC_65C02_F9,
OPC_65SC02_FA, OPC_65SC02_FA,
OPC_65C02_NOP11, // $FB OPC_65C02_NOP11, // $FB
OPC_65C02_NOP34, // $FC OPC_65C02_NOP34, // $FC
OPC_6502_FD, OPC_65C02_FD,
OPC_6502_FE, OPC_6502_FE,
OPC_Illegal, // $FF: BBS7 currently unsupported OPC_Illegal, // $FF: BBS7 currently unsupported
}; };

View File

@@ -37,6 +37,8 @@
#define _6502_H #define _6502_H
#include <stdint.h>
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
@@ -57,14 +59,17 @@ extern CPUType CPU;
/* 6502 CPU registers */ /* 6502 CPU registers */
typedef struct CPURegs CPURegs; typedef struct CPURegs CPURegs;
struct CPURegs { struct CPURegs {
unsigned AC; /* Accumulator */ uint8_t AC; /* Accumulator */
unsigned XR; /* X register */ uint8_t XR; /* X register */
unsigned YR; /* Y register */ uint8_t YR; /* Y register */
unsigned SR; /* Status register */ uint8_t SR; /* Status register */
unsigned SP; /* Stackpointer */ uint8_t SP; /* Stackpointer */
unsigned PC; /* Program counter */ uint16_t PC; /* Program counter */
}; };
/* Current CPU registers */
extern CPURegs Regs;
/* Status register bits */ /* Status register bits */
#define CF 0x01 /* Carry flag */ #define CF 0x01 /* Carry flag */
#define ZF 0x02 /* Zero flag */ #define ZF 0x02 /* Zero flag */