mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
Added decimal mode (untested): http://www.6502.org/tutorials/decimal_mode.html
git-svn-id: svn://svn.cc65.org/cc65/trunk@4327 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ca5ada12ba
commit
8b7c9fdc4f
@ -221,11 +221,28 @@ static char BreakMsg[1024];
|
||||
|
||||
/* ADC */
|
||||
#define ADC(v) \
|
||||
if (GET_DF ()) { \
|
||||
Warning ("Decimal mode not available"); \
|
||||
} else { \
|
||||
do { \
|
||||
unsigned old = Regs.AC; \
|
||||
unsigned rhs = (v & 0xFF); \
|
||||
if (GET_DF ()) { \
|
||||
unsigned lo; \
|
||||
int res; \
|
||||
lo = (old & 0x0F) + (rhs & 0x0F) + GET_CF (); \
|
||||
if (lo >= 0x0A) { \
|
||||
lo = ((lo + 0x06) & 0x0F) + 0x10; \
|
||||
} \
|
||||
Regs.AC = (old & 0xF0) + (rhs & 0xF0) + lo; \
|
||||
res = (signed char)(old & 0xF0) + \
|
||||
(signed char)(rhs & 0xF0) + \
|
||||
(signed char)lo; \
|
||||
TEST_ZF (old + rhs + GET_CF ()); \
|
||||
TEST_SF (Regs.AC); \
|
||||
if (Regs.AC >= 0xA0) { \
|
||||
Regs.AC += 0x60; \
|
||||
} \
|
||||
TEST_CF (Regs.AC); \
|
||||
SET_OF ((res < -128) || (res > 127)); \
|
||||
} else { \
|
||||
Regs.AC += rhs + GET_CF (); \
|
||||
TEST_ZF (Regs.AC); \
|
||||
TEST_SF (Regs.AC); \
|
||||
@ -233,7 +250,8 @@ static char BreakMsg[1024];
|
||||
SET_OF (!((old ^ rhs) & 0x80) && \
|
||||
((old ^ Regs.AC) & 0x80)); \
|
||||
Regs.AC &= 0xFF; \
|
||||
}
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* branches */
|
||||
#define BRANCH(cond) \
|
||||
@ -254,12 +272,12 @@ static char BreakMsg[1024];
|
||||
|
||||
/* compares */
|
||||
#define CMP(v1,v2) \
|
||||
{ \
|
||||
do { \
|
||||
unsigned Result = v1 - v2; \
|
||||
TEST_ZF (Result & 0xFF); \
|
||||
TEST_SF (Result); \
|
||||
SET_CF (Result <= 0xFF); \
|
||||
}
|
||||
} while (0)
|
||||
|
||||
|
||||
/* ROL */
|
||||
@ -284,19 +302,34 @@ static char BreakMsg[1024];
|
||||
|
||||
/* SBC */
|
||||
#define SBC(v) \
|
||||
if (GET_DF ()) { \
|
||||
Warning ("Decimal mode not available"); \
|
||||
} else { \
|
||||
do { \
|
||||
unsigned old = Regs.AC; \
|
||||
unsigned rhs = (v & 0xFF); \
|
||||
if (GET_DF ()) { \
|
||||
unsigned lo; \
|
||||
int res; \
|
||||
lo = (old & 0x0F) - (rhs & 0x0F) + GET_CF () - 1; \
|
||||
if (lo & 0x80) { \
|
||||
lo = ((lo - 0x06) & 0x0F) - 0x10; \
|
||||
} \
|
||||
Regs.AC = (old & 0xF0) - (rhs & 0xF0) + lo; \
|
||||
if (Regs.AC & 0x80) { \
|
||||
Regs.AC -= 0x60; \
|
||||
} \
|
||||
res = Regs.AC - rhs + (!GET_CF ()); \
|
||||
TEST_ZF (res); \
|
||||
TEST_SF (res); \
|
||||
SET_CF (res <= 0xFF); \
|
||||
SET_OF (((old^rhs) & (old^res) & 0x80)); \
|
||||
} else { \
|
||||
Regs.AC -= rhs - (!GET_CF ()); \
|
||||
TEST_ZF (Regs.AC); \
|
||||
TEST_SF (Regs.AC); \
|
||||
SET_CF (Regs.AC <= 0xFF); \
|
||||
SET_OF (((old^rhs) & (old^Regs.AC) & 0x80)); \
|
||||
Regs.AC &= 0xFF; \
|
||||
}
|
||||
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user