CPU: Allow move instructions to be interrupted by an IRQ/NMI

+ Implemented WAI instruction
This commit is contained in:
Sour 2019-03-02 10:58:25 -05:00
parent 28a151e00d
commit e321b247ac

View file

@ -655,56 +655,47 @@ Move operations
****************/ ****************/
void Cpu::MVN() void Cpu::MVN()
{ {
#ifndef DUMMYCPU
_state.DBR = _operand & 0xFF; _state.DBR = _operand & 0xFF;
uint32_t destBank = _state.DBR << 16; uint32_t destBank = _state.DBR << 16;
uint32_t srcBank = (_operand << 8) & 0xFF0000; uint32_t srcBank = (_operand << 8) & 0xFF0000;
do {
uint8_t value = ReadData(srcBank | _state.X);
Write(destBank | _state.Y, value);
Idle(); uint8_t value = ReadData(srcBank | _state.X);
Idle(); Write(destBank | _state.Y, value);
_state.X++; Idle();
_state.Y++; Idle();
_state.A--;
if(_state.A != 0xFFFF) { _state.X++;
//"Idle" cycles, instruction re-reads OP code and operands before every new byte _state.Y++;
Read((_state.K << 16) | (_state.PC - 3), MemoryOperationType::Read); _state.A--;
Read((_state.K << 16) | (_state.PC - 2), MemoryOperationType::Read);
Read((_state.K << 16) | (_state.PC - 1), MemoryOperationType::Read);
} if(_state.A != 0xFFFF) {
} while(_state.A != 0xFFFF); //Operation isn't done, set the PC back to the start of the instruction
#endif _state.PC -= 3;
}
} }
void Cpu::MVP() void Cpu::MVP()
{ {
#ifndef DUMMYCPU
_state.DBR = _operand & 0xFF; _state.DBR = _operand & 0xFF;
uint32_t destBank = _state.DBR << 16; uint32_t destBank = _state.DBR << 16;
uint32_t srcBank = (_operand << 8) & 0xFF0000; uint32_t srcBank = (_operand << 8) & 0xFF0000;
do {
uint8_t value = ReadData(srcBank | _state.X);
Write(destBank | _state.Y, value);
Idle(); uint8_t value = ReadData(srcBank | _state.X);
Idle(); Write(destBank | _state.Y, value);
_state.X--; Idle();
_state.Y--; Idle();
_state.A--;
if(_state.A != 0xFFFF) { _state.X--;
//"Idle" cycles, instruction re-reads OP code and operands before every new byte _state.Y--;
Read((_state.K << 16) | (_state.PC - 3), MemoryOperationType::Read); _state.A--;
Read((_state.K << 16) | (_state.PC - 2), MemoryOperationType::Read);
Read((_state.K << 16) | (_state.PC - 1), MemoryOperationType::Read); if(_state.A != 0xFFFF) {
} //Operation isn't done, set the PC back to the start of the instruction
} while(_state.A != 0xFFFF); _state.PC -= 3;
#endif }
} }
/******************** /********************
@ -1090,7 +1081,14 @@ void Cpu::STP()
void Cpu::WAI() void Cpu::WAI()
{ {
#ifndef DUMMYCPU
//Wait for interrupt //Wait for interrupt
while(!_irqSource && !_nmiFlag) {
_memoryManager->IncrementMasterClockValue<4>();
}
Idle();
Idle();
#endif
} }
/**************** /****************