Finishing Bit operations

This commit is contained in:
Melefo
2020-02-20 17:40:09 +01:00
parent d958bd5131
commit 98c5036b58
5 changed files with 276 additions and 19 deletions
+58
View File
@@ -3,6 +3,7 @@
//
#include "../APU.hpp"
#include "../../Utility/Utility.hpp"
namespace ComSquare::APU
{
@@ -31,4 +32,61 @@ namespace ComSquare::APU
this->_internalRegisters.z = !data;
return 6;
}
int APU::TCLR1(uint24_t abs)
{
uint8_t data = this->_internalRead(abs);
this->_internalWrite(abs, data & ~this->_internalRegisters.a);
this->_internalRegisters.n = data & 0x80u;
this->_internalRegisters.z = !data;
return 6;
}
int APU::AND1(std::pair<uint24_t, uint24_t> operand, bool invert)
{
if (invert)
this->_internalRegisters.c &= ~this->_internalRead(operand.first) & (1u << operand.second);
else
this->_internalRegisters.c &= this->_internalRead(operand.first) & (1u << operand.second);
return 4;
}
int APU::OR1(std::pair<uint24_t, uint24_t> operand, bool invert)
{
if (invert)
this->_internalRegisters.c |= ~this->_internalRead(operand.first) & (1u << operand.second);
else
this->_internalRegisters.c |= this->_internalRead(operand.first) & (1u << operand.second);
return 5;
}
int APU::EOR1(std::pair<uint24_t, uint24_t> operand)
{
this->_internalRegisters.c ^= this->_internalRead(operand.first) & (1u << operand.second);
return 5;
}
int APU::NOT1(std::pair<uint24_t, uint24_t> operand)
{
this->_internalWrite(operand.first, this->_internalRead(operand.first) ^ (1u << operand.second));
return 5;
}
int APU::MOV1(std::pair<uint24_t, uint24_t> operand, bool to_carry)
{
if (to_carry) {
this->_internalRegisters.c = this->_internalRead(operand.first) & (1u << operand.second);
return 4;
}
else {
uint24_t mask = (1u << operand.second);
if (this->_internalRegisters.c)
this->_internalWrite(operand.first, this->_internalRead(operand.first) | mask);
else
this->_internalWrite(operand.first, this->_internalRead(operand.first) & ~mask);
return 6;
}
}
}