mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-02 07:28:56 +00:00
Correct SP arithmetic methods: All Blargg CPU tests now pass. Hurrah!
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
91c8855183
commit
ec15a2c90c
@ -13,7 +13,7 @@ EightBit::LR35902::LR35902(Bus& memory)
|
|||||||
|
|
||||||
void EightBit::LR35902::reset() {
|
void EightBit::LR35902::reset() {
|
||||||
IntelProcessor::reset();
|
IntelProcessor::reset();
|
||||||
SP().word = 0xfffe;
|
SP().word = Mask16 - 1;
|
||||||
di();
|
di();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,11 +21,10 @@ void EightBit::LR35902::initialise() {
|
|||||||
|
|
||||||
IntelProcessor::initialise();
|
IntelProcessor::initialise();
|
||||||
|
|
||||||
AF().word = 0xffff;
|
AF().word = Mask16;
|
||||||
|
BC().word = Mask16;
|
||||||
BC().word = 0xffff;
|
DE().word = Mask16;
|
||||||
DE().word = 0xffff;
|
HL().word = Mask16;
|
||||||
HL().word = 0xffff;
|
|
||||||
|
|
||||||
m_prefixCB = false;
|
m_prefixCB = false;
|
||||||
}
|
}
|
||||||
@ -687,13 +686,13 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
break;
|
break;
|
||||||
case 5: { // GB: ADD SP,dd
|
case 5: { // GB: ADD SP,dd
|
||||||
auto before = SP().word;
|
auto before = SP().word;
|
||||||
auto value = fetchByte();
|
int8_t value = fetchByte();
|
||||||
auto result = before + (int8_t)value;
|
auto result = before + value;
|
||||||
SP().word = result;
|
SP().word = result;
|
||||||
auto carried = before ^ value ^ result;
|
auto carried = before ^ value ^ (result & Mask16);
|
||||||
clearFlag(f, ZF | NF);
|
clearFlag(f, ZF | NF);
|
||||||
setFlag(f, CF, carried & 0x100);
|
setFlag(f, CF, carried & Bit8);
|
||||||
setFlag(f, HC, carried & 0x10);
|
setFlag(f, HC, carried & Bit4);
|
||||||
}
|
}
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
break;
|
break;
|
||||||
@ -703,13 +702,13 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
break;
|
break;
|
||||||
case 7: { // GB: LD HL,SP + dd
|
case 7: { // GB: LD HL,SP + dd
|
||||||
auto before = SP().word;
|
auto before = SP().word;
|
||||||
auto value = fetchByte();
|
int8_t value = fetchByte();
|
||||||
auto result = before + (int8_t)value;
|
auto result = before + value;
|
||||||
HL().word = result;
|
HL().word = result;
|
||||||
auto carried = before ^ value ^ result;
|
auto carried = before ^ value ^ (result & Mask16);
|
||||||
clearFlag(f, ZF | NF);
|
clearFlag(f, ZF | NF);
|
||||||
setFlag(f, CF, carried & 0x100);
|
setFlag(f, CF, carried & Bit8);
|
||||||
setFlag(f, HC, carried & 0x10);
|
setFlag(f, HC, carried & Bit4);
|
||||||
}
|
}
|
||||||
cycles += 3;
|
cycles += 3;
|
||||||
break;
|
break;
|
||||||
|
@ -36,6 +36,14 @@ namespace EightBit {
|
|||||||
Mask6 = Bit6 - 1,
|
Mask6 = Bit6 - 1,
|
||||||
Mask7 = Bit7 - 1,
|
Mask7 = Bit7 - 1,
|
||||||
Mask8 = Bit8 - 1,
|
Mask8 = Bit8 - 1,
|
||||||
|
Mask9 = Bit9 - 1,
|
||||||
|
Mask10 = Bit10 - 1,
|
||||||
|
Mask11 = Bit11 - 1,
|
||||||
|
Mask12 = Bit12 - 1,
|
||||||
|
Mask13 = Bit13 - 1,
|
||||||
|
Mask14 = Bit14 - 1,
|
||||||
|
Mask15 = Bit15 - 1,
|
||||||
|
Mask16 = Bit16 - 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int highNibble(int value) { return value >> 4; }
|
static int highNibble(int value) { return value >> 4; }
|
||||||
|
Loading…
Reference in New Issue
Block a user