1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-22 18:29:20 +00:00

replace BCD maps with functions

This commit is contained in:
Stephen Crane 2019-02-24 12:41:33 +00:00
parent 066a82e93c
commit 448c702237
2 changed files with 12 additions and 10 deletions

View File

@ -148,12 +148,20 @@ void r6502::jsr() {
PC = vector(PC); PC = vector(PC);
} }
static inline uint8_t fromBCD(uint8_t i) {
return ((i >> 4) & 0x0f)*10 + (i & 0x0f);
}
static inline uint8_t toBCD(uint8_t i) {
return (((i % 100) / 10) << 4) | (i % 10);
}
void r6502::_adc(uint8_t d) { void r6502::_adc(uint8_t d) {
if (P.bits.D) { if (P.bits.D) {
int r = _fromBCD[A] + _fromBCD[d] + C; int r = fromBCD(A) + fromBCD(d) + C;
C = (r > 99); C = (r > 99);
if (C) r -= 100; if (C) r -= 100;
A = _toBCD[r]; A = toBCD(r);
} else { } else {
unsigned short u = (unsigned short)A + (unsigned short)d + (unsigned short)C; unsigned short u = (unsigned short)A + (unsigned short)d + (unsigned short)C;
short s = (char)A + (char)d + (char)C; short s = (char)A + (char)d + (char)C;
@ -166,10 +174,10 @@ void r6502::_adc(uint8_t d) {
} }
void r6502::sbcd(uint8_t d) { void r6502::sbcd(uint8_t d) {
int r = _fromBCD[A] - _fromBCD[d] - !C; int r = fromBCD(A) - fromBCD(d) - !C;
C = (r >= 0); C = (r >= 0);
if (r < 0) r += 100; if (r < 0) r += 100;
A = _toBCD[r & 0xff]; A = toBCD(r & 0xff);
N = (A & 0x80); N = (A & 0x80);
Z = A; Z = A;
// V not tested for: http://www.6502.org/tutorials/decimal_mode.html // V not tested for: http://www.6502.org/tutorials/decimal_mode.html
@ -193,11 +201,6 @@ void r6502::reset()
r6502::r6502(Memory &m): CPU(m) { r6502::r6502(Memory &m): CPU(m) {
for (int i=0; i < 256; i++) {
_fromBCD[i] = ((i >> 4) & 0x0f)*10 + (i & 0x0f);
_toBCD[i] = (((i % 100) / 10) << 4) | (i % 10);
}
OP *p = _ops; OP *p = _ops;
*p++=&r6502::brk; *p++=&r6502::ora_ix; *p++=&r6502::ill; *p++=&r6502::ill; *p++=&r6502::brk; *p++=&r6502::ora_ix; *p++=&r6502::ill; *p++=&r6502::ill;
*p++=&r6502::nop2; *p++=&r6502::ora_z; *p++=&r6502::asl_z; *p++=&r6502::ill; *p++=&r6502::nop2; *p++=&r6502::ora_z; *p++=&r6502::asl_z; *p++=&r6502::ill;

View File

@ -33,7 +33,6 @@ private:
} bits; } bits;
uint8_t flags; uint8_t flags;
} P; } P;
uint8_t _toBCD[256], _fromBCD[256]; // BCD maps
bool _irq; // interrupt pending? bool _irq; // interrupt pending?
void irq(); void irq();