CPU: Enabling 8-bit indexes must truncate the value of X/Y (refix)

This commit is contained in:
Sour 2019-02-20 22:46:14 -05:00
parent 1a90a36d3c
commit e6809305f1
3 changed files with 16 additions and 7 deletions

View file

@ -402,10 +402,10 @@ void Cpu::JSR()
void Cpu::RTI()
{
if(_state.EmulationMode) {
_state.PS = PopByte(); //TODO: incorrect
SetPS(PopByte());
_state.PC = PopWord();
} else {
_state.PS = PopByte(); //TODO: incorrect
SetPS(PopByte());
_state.PC = PopWord();
_state.K = PopByte();
}
@ -699,9 +699,9 @@ void Cpu::PLP()
{
//"For PLP, (all of) the flags are pulled from the stack. Note that when the e flag is 1, the m and x flag are forced to 1, so after the PLP, both flags will still be 1 no matter what value is pulled from the stack."
if(_state.EmulationMode) {
_state.PS = PopByte() | ProcFlags::MemoryMode8 | ProcFlags::IndexMode8;
SetPS(PopByte() | ProcFlags::MemoryMode8 | ProcFlags::IndexMode8);
} else {
_state.PS = PopByte();
SetPS(PopByte());
}
}
@ -971,9 +971,7 @@ void Cpu::XCE()
_state.EmulationMode = carry;
if(_state.EmulationMode) {
SetFlags(ProcFlags::IndexMode8 | ProcFlags::MemoryMode8);
_state.Y &= 0xFF;
_state.X &= 0xFF;
SetPS(_state.PS | ProcFlags::IndexMode8 | ProcFlags::MemoryMode8);
_state.SP = 0x100 | (_state.SP & 0xFF);
}
}

View file

@ -326,6 +326,16 @@ void Cpu::SetSP(uint16_t sp)
}
}
void Cpu::SetPS(uint8_t ps)
{
_state.PS = ps;
if(CheckFlag(ProcFlags::IndexMode8)) {
//Truncate X/Y when 8-bit indexes are enabled
_state.Y &= 0xFF;
_state.X &= 0xFF;
}
}
void Cpu::SetRegister(uint8_t &reg, uint8_t value)
{
SetZeroNegativeFlags(value);

View file

@ -54,6 +54,7 @@ private:
uint32_t FetchEffectiveAddress();
void SetSP(uint16_t sp);
void SetPS(uint8_t ps);
void SetRegister(uint8_t &reg, uint8_t value);
void SetRegister(uint16_t &reg, uint16_t value, bool eightBitMode);