CPU: Fixed issues with OR/EOR/AND and stack addressing mode

This commit is contained in:
Sour 2019-02-14 00:48:16 -05:00
parent 930f504861
commit 0f64559882
3 changed files with 32 additions and 19 deletions

View file

@ -459,17 +459,29 @@ Bitwise operations
*******************/
void Cpu::AND()
{
SetRegister(_state.A, _state.A & GetByteValue(), CheckFlag(ProcFlags::MemoryMode8));
if(CheckFlag(ProcFlags::MemoryMode8)) {
SetRegister(_state.A, _state.A & GetByteValue(), true);
} else {
SetRegister(_state.A, _state.A & GetWordValue(), false);
}
}
void Cpu::EOR()
{
SetRegister(_state.A, _state.A ^ GetByteValue(), CheckFlag(ProcFlags::MemoryMode8));
if(CheckFlag(ProcFlags::MemoryMode8)) {
SetRegister(_state.A, _state.A ^ GetByteValue(), true);
} else {
SetRegister(_state.A, _state.A ^ GetWordValue(), false);
}
}
void Cpu::ORA()
{
SetRegister(_state.A, _state.A | GetByteValue(), CheckFlag(ProcFlags::MemoryMode8));
if(CheckFlag(ProcFlags::MemoryMode8)) {
SetRegister(_state.A, _state.A | GetByteValue(), true);
} else {
SetRegister(_state.A, _state.A | GetWordValue(), false);
}
}
/****************
@ -840,7 +852,7 @@ void Cpu::TCD()
void Cpu::TCS()
{
_state.SP = _state.A;
SetSP(_state.A);
}
void Cpu::TDC()
@ -865,7 +877,7 @@ void Cpu::TXA()
void Cpu::TXS()
{
_state.SP = _state.X;
SetSP(_state.X);
}
void Cpu::TXY()

View file

@ -198,23 +198,13 @@ uint16_t Cpu::GetWordValue()
void Cpu::PushByte(uint8_t value)
{
if(_state.EmulationMode) {
_state.SP = 0x100 | (_state.SP & 0xFF);
Write(_state.SP, value);
_state.SP = 0x100 | ((_state.SP - 1) & 0xFF);
} else {
Write(_state.SP, value);
_state.SP--;
}
Write(_state.SP, value);
SetSP(_state.SP - 1);
}
uint8_t Cpu::PopByte()
{
if(_state.EmulationMode) {
_state.SP = 0x100 | ((_state.SP + 1) & 0xFF);
} else {
_state.SP++;
}
SetSP(_state.SP + 1);
return ReadData(_state.SP);
}
@ -299,13 +289,22 @@ uint32_t Cpu::FetchEffectiveAddress()
case AddrMode::StkRelIndIdxY: {
uint16_t addr = (uint16_t)(ReadOperandByte() + _state.SP);
return (GetDataAddress(addr) + _state.Y) & 0xFFFFFF;
return (GetDataAddress(ReadDataWord(addr)) + _state.Y) & 0xFFFFFF;
}
}
throw new std::runtime_error("Unreacheable code");
}
void Cpu::SetSP(uint16_t sp)
{
if(_state.EmulationMode) {
_state.SP = 0x100 | (sp & 0xFF);
} else {
_state.SP = sp;
}
}
void Cpu::SetRegister(uint8_t &reg, uint8_t value)
{
SetZeroNegativeFlags(value);

View file

@ -52,6 +52,8 @@ private:
uint32_t ReadOperandLong();
uint32_t FetchEffectiveAddress();
void SetSP(uint16_t sp);
void SetRegister(uint8_t &reg, uint8_t value);
void SetRegister(uint16_t &reg, uint16_t value, bool eightBitMode);