mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-27 16:21:53 +00:00
Adding 8-bit Logical Operations
Testing every current operands
This commit is contained in:
+2
-2
@@ -81,7 +81,7 @@ add_executable(unit_tests
|
||||
sources/APU/Instructions/16bitArithmetic.cpp
|
||||
sources/APU/Instructions/16bitDataTransmission.cpp
|
||||
sources/APU/Instructions/8bitShiftRotation.cpp
|
||||
sources/APU/Instructions/8bitIncrementDecrement.cpp)
|
||||
sources/APU/Instructions/8bitIncrementDecrement.cpp sources/APU/Instructions/8bitLogical.cpp tests/APU/testOperand.cpp)
|
||||
|
||||
# include criterion & coverage
|
||||
target_link_libraries(unit_tests criterion -lgcov)
|
||||
@@ -173,7 +173,7 @@ add_executable(ComSquare
|
||||
sources/APU/Instructions/16bitArithmetic.cpp
|
||||
sources/APU/Instructions/16bitDataTransmission.cpp
|
||||
sources/APU/Instructions/8bitShiftRotation.cpp
|
||||
sources/APU/Instructions/8bitIncrementDecrement.cpp)
|
||||
sources/APU/Instructions/8bitIncrementDecrement.cpp sources/APU/Instructions/8bitLogical.cpp)
|
||||
|
||||
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
|
||||
|
||||
|
||||
+74
-2
@@ -168,6 +168,18 @@ namespace ComSquare::APU
|
||||
return this->SET1(this->_getDirectAddr(), 0);
|
||||
case 0x03:
|
||||
return this->BBS(this->_getDirectAddr(), 0);
|
||||
case 0x04:
|
||||
return this->ORacc(this->_getDirectAddr(), 3);
|
||||
case 0x05:
|
||||
return this->ORacc(this->_getAbsoluteAddr(), 4);
|
||||
case 0x06:
|
||||
return this->ORacc(this->_getIndexXAddr(), 3);
|
||||
case 0x07:
|
||||
return this->ORacc(this->_getAbsoluteDirectByXAddr(), 6);
|
||||
case 0x08:
|
||||
return this->ORacc(this->_getImmediateData(), 2);
|
||||
case 0x09:
|
||||
return this->OR(this->_getDirectAddr(), this->_getDirectAddr(), 6);
|
||||
case 0x0A:
|
||||
return this->OR1(this->_getAbsoluteBit());
|
||||
case 0x0B:
|
||||
@@ -188,6 +200,18 @@ namespace ComSquare::APU
|
||||
return this->CLR1(this->_getDirectAddr(), 0);
|
||||
case 0x13:
|
||||
return this->BBC(this->_getDirectAddr(), 0);
|
||||
case 0x14:
|
||||
return this->ORacc(this->_getDirectAddrByX(), 4);
|
||||
case 0x15:
|
||||
return this->ORacc(this->_getAbsoluteAddrByX(), 5);
|
||||
case 0x16:
|
||||
return this->ORacc(this->_getAbsoluteAddrByY(), 5);
|
||||
case 0x17:
|
||||
return this->ORacc(this->_getAbsoluteDirectAddrByY(), 6);
|
||||
case 0x18:
|
||||
return this->OR(this->_getDirectAddr(), this->_getImmediateData(), 5);
|
||||
case 0x19:
|
||||
return this->OR(this->_getIndexXAddr(), this->_getIndexYAddr(), 5);
|
||||
case 0x1A:
|
||||
return this->DECW(this->_getDirectAddr());
|
||||
case 0x1B:
|
||||
@@ -197,7 +221,7 @@ namespace ComSquare::APU
|
||||
case 0x1D:
|
||||
return this->DECreg(this->_internalRegisters.x);
|
||||
case 0x1F:
|
||||
return this->JMP(this->_getAbsoluteAddrByX(), true);
|
||||
return this->JMP(this->_getAbsoluteByXAddr(), true);
|
||||
case 0x20:
|
||||
return this->CLRP();
|
||||
case 0x21:
|
||||
@@ -206,6 +230,18 @@ namespace ComSquare::APU
|
||||
return this->SET1(this->_getDirectAddr(), 1);
|
||||
case 0x23:
|
||||
return this->BBS(this->_getDirectAddr(), 1);
|
||||
case 0x24:
|
||||
return this->ANDacc(this->_getDirectAddr(), 3);
|
||||
case 0x25:
|
||||
return this->ANDacc(this->_getAbsoluteAddr(), 4);
|
||||
case 0x26:
|
||||
return this->ANDacc(this->_getIndexXAddr(), 3);
|
||||
case 0x27:
|
||||
return this->ANDacc(this->_getAbsoluteDirectByXAddr(), 6);
|
||||
case 0x28:
|
||||
return this->ANDacc(this->_getImmediateData(), 2);
|
||||
case 0x29:
|
||||
return this->AND(this->_getDirectAddr(), this->_getDirectAddr(), 6);
|
||||
case 0x2A:
|
||||
return this->OR1(this->_getAbsoluteBit(), true);
|
||||
case 0x2B:
|
||||
@@ -215,7 +251,7 @@ namespace ComSquare::APU
|
||||
case 0x2D:
|
||||
return this->PUSH(this->_internalRegisters.a);
|
||||
case 0x2E:
|
||||
return this->CBNE(this->_getDirectValue());
|
||||
return this->CBNE(this->_getImmediateData());
|
||||
case 0x2F:
|
||||
return this->BRA();
|
||||
case 0x30:
|
||||
@@ -226,6 +262,18 @@ namespace ComSquare::APU
|
||||
return this->CLR1(this->_getDirectAddr(), 1);
|
||||
case 0x33:
|
||||
return this->BBC(this->_getDirectAddr(), 1);
|
||||
case 0x34:
|
||||
return this->ANDacc(this->_getDirectAddrByX(), 4);
|
||||
case 0x35:
|
||||
return this->ANDacc(this->_getAbsoluteAddrByX(), 5);
|
||||
case 0x36:
|
||||
return this->ANDacc(this->_getAbsoluteAddrByY(), 5);
|
||||
case 0x37:
|
||||
return this->ANDacc(this->_getAbsoluteDirectAddrByY(), 6);
|
||||
case 0x38:
|
||||
return this->AND(this->_getDirectAddr(), this->_getImmediateData(), 5);
|
||||
case 0x39:
|
||||
return this->AND(this->_getIndexXAddr(), this->_getIndexYAddr(), 5);
|
||||
case 0x3A:
|
||||
return this->INCW(this->_getDirectAddr());
|
||||
case 0x3B:
|
||||
@@ -244,6 +292,18 @@ namespace ComSquare::APU
|
||||
return this->SET1(this->_getDirectAddr(), 2);
|
||||
case 0x43:
|
||||
return this->BBS(this->_getDirectAddr(), 2);
|
||||
case 0x44:
|
||||
return this->EORacc(this->_getDirectAddr(), 3);
|
||||
case 0x45:
|
||||
return this->EORacc(this->_getAbsoluteAddr(), 4);
|
||||
case 0x46:
|
||||
return this->EORacc(this->_getIndexXAddr(), 3);
|
||||
case 0x47:
|
||||
return this->EORacc(this->_getAbsoluteDirectByXAddr(), 6);
|
||||
case 0x48:
|
||||
return this->EORacc(this->_getImmediateData(), 2);
|
||||
case 0x49:
|
||||
return this->EOR(this->_getDirectAddr(), this->_getDirectAddr(), 6);
|
||||
case 0x4A:
|
||||
return this->AND1(this->_getAbsoluteBit());
|
||||
case 0x4B:
|
||||
@@ -264,6 +324,18 @@ namespace ComSquare::APU
|
||||
return this->CLR1(this->_getDirectAddr(), 2);
|
||||
case 0x53:
|
||||
return this->BBC(this->_getDirectAddr(), 2);
|
||||
case 0x54:
|
||||
return this->EORacc(this->_getDirectAddrByX(), 4);
|
||||
case 0x55:
|
||||
return this->EORacc(this->_getAbsoluteAddrByX(), 5);
|
||||
case 0x56:
|
||||
return this->EORacc(this->_getAbsoluteAddrByY(), 5);
|
||||
case 0x57:
|
||||
return this->EORacc(this->_getAbsoluteDirectAddrByY(), 6);
|
||||
case 0x58:
|
||||
return this->EOR(this->_getDirectAddr(), this->_getImmediateData(), 5);
|
||||
case 0x59:
|
||||
return this->EOR(this->_getIndexXAddr(), this->_getIndexYAddr(), 5);
|
||||
case 0x5A:
|
||||
return this->CMPW(this->_getDirectAddr());
|
||||
case 0x5B:
|
||||
|
||||
+27
-2
@@ -162,15 +162,27 @@ namespace ComSquare::APU
|
||||
unsigned int _paddingCycles = 0;
|
||||
|
||||
//! @brief Get value of the Pointer Counter
|
||||
uint8_t _getDirectValue();
|
||||
uint8_t _getImmediateData();
|
||||
//! @brief Get direct page offset
|
||||
uint24_t _getDirectAddr();
|
||||
//! @brief Get Index X offset
|
||||
uint24_t _getIndexXAddr();
|
||||
//! @brief Get Index Y offset
|
||||
uint24_t _getIndexYAddr();
|
||||
//! @brief Get direct page offset and add to it the X Index Flag
|
||||
uint24_t _getDirectAddrByX();
|
||||
//! @brief Get absolute direct page offset
|
||||
uint24_t _getAbsoluteAddr();
|
||||
//! @brief Get absolute direct page offset nd add to it the X Index Flag
|
||||
//! @brief _get absolute direct page + X Index offset
|
||||
uint24_t _getAbsoluteByXAddr();
|
||||
//! @brief Get absolute direct page offset and add to it the X Index Flag
|
||||
uint24_t _getAbsoluteAddrByX();
|
||||
//! @brief Get absolute direct page offset and add to it the Y Index Flag
|
||||
uint24_t _getAbsoluteAddrByY();
|
||||
//! @brief Get absolute offset of the direct page added to the X Index Flag
|
||||
uint24_t _getAbsoluteDirectByXAddr();
|
||||
//! @brief Get absolute offset of the direct page and add the Y Index Flag to it
|
||||
uint24_t _getAbsoluteDirectAddrByY();
|
||||
//! @brief Get absolute offset and separate its bits
|
||||
std::pair<uint24_t, uint24_t> _getAbsoluteBit();
|
||||
|
||||
@@ -314,6 +326,19 @@ namespace ComSquare::APU
|
||||
int DEC(uint24_t addr, int cycles);
|
||||
//! @brief Decrement a register.
|
||||
int DECreg(uint8_t &value);
|
||||
|
||||
//! @brief Perform a bitwise AND.
|
||||
int AND(uint24_t operand1, uint24_t operand2, int cycles);
|
||||
//! @brief Perform a bitwise AND on the Accumulator flag.
|
||||
int ANDacc(uint24_t addr, int cycles);
|
||||
//! @brief Perform a bitwise OR.
|
||||
int OR(uint24_t operand1, uint24_t operand2, int cycles);
|
||||
//! @brief Perform a bitwise OR on the Accumulator flag.
|
||||
int ORacc(uint24_t addr, int cycles);
|
||||
//! @brief Perform an Exclusive OR.
|
||||
int EOR(uint24_t operand1, uint24_t operand2, int cycles);
|
||||
//! @brief Perform an Exclusive OR on the Accumulator flag.
|
||||
int EORacc(uint24_t addr, int cycles);
|
||||
public:
|
||||
explicit APU(std::shared_ptr<MemoryMap> &map);
|
||||
APU(const APU &) = default;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by Melefo on 26/02/2020.
|
||||
//
|
||||
|
||||
#include "../APU.hpp"
|
||||
|
||||
namespace ComSquare::APU
|
||||
{
|
||||
int APU::AND(uint24_t operand1, uint24_t operand2, int cycles)
|
||||
{
|
||||
uint8_t data = this->_internalRead(operand1) & this->_internalRead(operand2);
|
||||
|
||||
this->_internalWrite(operand1, data);
|
||||
this->_setNZflags(data);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int APU::ANDacc(uint24_t addr, int cycles)
|
||||
{
|
||||
this->_internalRegisters.a &= this->_internalRead(addr);
|
||||
this->_setNZflags(this->_internalRegisters.a);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int APU::OR(uint24_t operand1, uint24_t operand2, int cycles)
|
||||
{
|
||||
uint8_t data = this->_internalRead(operand1) | this->_internalRead(operand2);
|
||||
|
||||
this->_internalWrite(operand1, data);
|
||||
this->_setNZflags(data);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int APU::ORacc(uint24_t addr, int cycles)
|
||||
{
|
||||
this->_internalRegisters.a |= this->_internalRead(addr);
|
||||
this->_setNZflags(this->_internalRegisters.a);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int APU::EOR(uint24_t operand1, uint24_t operand2, int cycles)
|
||||
{
|
||||
uint8_t data = this->_internalRead(operand1) ^ this->_internalRead(operand2);
|
||||
|
||||
this->_internalWrite(operand1, data);
|
||||
this->_setNZflags(data);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int APU::EORacc(uint24_t addr, int cycles)
|
||||
{
|
||||
this->_internalRegisters.a ^= this->_internalRead(addr);
|
||||
this->_setNZflags(this->_internalRegisters.a);
|
||||
return cycles;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace ComSquare::APU
|
||||
{
|
||||
int APU::BRA()
|
||||
{
|
||||
int8_t offset = this->_getDirectValue();
|
||||
int8_t offset = this->_getImmediateData();
|
||||
|
||||
this->_internalRegisters.pc += offset;
|
||||
return 4;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ComSquare::APU
|
||||
|
||||
int APU::PCALL()
|
||||
{
|
||||
this->CALL(0xFF00u + this->_getDirectValue());
|
||||
this->CALL(0xFF00u + this->_getImmediateData());
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
+67
-9
@@ -7,14 +7,32 @@
|
||||
|
||||
namespace ComSquare::APU
|
||||
{
|
||||
uint8_t APU::_getDirectValue()
|
||||
uint8_t APU::_getImmediateData()
|
||||
{
|
||||
return this->_internalRead(this->_internalRegisters.pc++);
|
||||
}
|
||||
|
||||
uint24_t APU::_getDirectAddr()
|
||||
{
|
||||
uint24_t addr = this->_getDirectValue();
|
||||
uint24_t addr = this->_getImmediateData();
|
||||
|
||||
if (this->_internalRegisters.p)
|
||||
addr += 0x100;
|
||||
return addr;
|
||||
}
|
||||
|
||||
uint24_t APU::_getIndexXAddr()
|
||||
{
|
||||
uint24_t addr = this->_internalRegisters.x;
|
||||
|
||||
if (this->_internalRegisters.p)
|
||||
addr += 0x100;
|
||||
return addr;
|
||||
}
|
||||
|
||||
uint24_t APU::_getIndexYAddr()
|
||||
{
|
||||
uint24_t addr = this->_internalRegisters.y;
|
||||
|
||||
if (this->_internalRegisters.p)
|
||||
addr += 0x100;
|
||||
@@ -31,24 +49,38 @@ namespace ComSquare::APU
|
||||
|
||||
uint24_t APU::_getAbsoluteAddr()
|
||||
{
|
||||
uint24_t addr1 = this->_getDirectValue();
|
||||
uint24_t addr2 = this->_getDirectValue();
|
||||
uint24_t addr1 = this->_getImmediateData();
|
||||
uint24_t addr2 = this->_getImmediateData();
|
||||
|
||||
return (addr2 << 8u) | addr1;
|
||||
}
|
||||
|
||||
uint24_t APU::_getAbsoluteByXAddr()
|
||||
{
|
||||
uint24_t addr1 = this->_getImmediateData() + this->_internalRegisters.x;
|
||||
uint24_t addr2 = this->_getImmediateData() + this->_internalRegisters.x++;
|
||||
|
||||
return (addr2 << 8u) | addr1;
|
||||
}
|
||||
|
||||
uint24_t APU::_getAbsoluteAddrByX()
|
||||
{
|
||||
uint24_t addr1 = this->_getDirectValue() + this->_internalRegisters.x;
|
||||
uint24_t addr2 = this->_getDirectValue() + this->_internalRegisters.x++;
|
||||
uint24_t addr = _getAbsoluteAddr();
|
||||
|
||||
return (addr2 << 8u) | addr1;
|
||||
return addr + this->_internalRegisters.x;
|
||||
}
|
||||
|
||||
uint24_t APU::_getAbsoluteAddrByY()
|
||||
{
|
||||
uint24_t addr = _getAbsoluteAddr();
|
||||
|
||||
return addr + this->_internalRegisters.y;
|
||||
}
|
||||
|
||||
std::pair<uint24_t, uint24_t> APU::_getAbsoluteBit()
|
||||
{
|
||||
uint24_t addr1 = _getDirectValue();
|
||||
uint24_t addr2 = this->_getDirectValue();
|
||||
uint24_t addr1 = this->_getImmediateData();
|
||||
uint24_t addr2 = this->_getImmediateData();
|
||||
|
||||
uint24_t operandA = (addr2 << 8u) | addr1;
|
||||
uint24_t operandB = operandA >> 13u;
|
||||
@@ -56,4 +88,30 @@ namespace ComSquare::APU
|
||||
operandA = operandA & 0x1FFFu;
|
||||
return std::make_pair(operandA, operandB);
|
||||
}
|
||||
|
||||
uint24_t APU::_getAbsoluteDirectByXAddr()
|
||||
{
|
||||
uint24_t DirectIndexX = this->_getDirectAddr() + this->_internalRegisters.x;
|
||||
|
||||
uint24_t low = this->_internalRead(DirectIndexX++);
|
||||
if (this->_internalRegisters.p)
|
||||
DirectIndexX += 0x100;
|
||||
uint24_t high = this->_internalRead(DirectIndexX);
|
||||
|
||||
return (high << 8u) | low;
|
||||
}
|
||||
|
||||
uint24_t APU::_getAbsoluteDirectAddrByY()
|
||||
{
|
||||
uint24_t DirectIndexX = this->_getDirectAddr();
|
||||
|
||||
uint24_t low = this->_internalRead(DirectIndexX);
|
||||
DirectIndexX += 1;
|
||||
if (this->_internalRegisters.p)
|
||||
DirectIndexX += 0x100;
|
||||
uint24_t high = this->_internalRead(DirectIndexX);
|
||||
|
||||
printf("\n\nHey : %i\n\n", ((high << 8u) | low) + this->_internalRegisters.y);
|
||||
return ((high << 8u) | low) + this->_internalRegisters.y;
|
||||
}
|
||||
}
|
||||
@@ -217,29 +217,4 @@ Test(update, stopped)
|
||||
apu->_state = APU::Stopped;
|
||||
apu->update(1);
|
||||
cr_assert_eq(apu->_paddingCycles, 0);
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// //
|
||||
// APU::_get*Addr tests //
|
||||
// //
|
||||
//////////////////////////
|
||||
|
||||
Test(_get, direct)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalWrite(0x32, 123);
|
||||
cr_assert_eq(apu->_getDirectAddr(), 123);
|
||||
}
|
||||
|
||||
Test(_get, absolute)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
cr_assert_eq(apu->_getAbsoluteAddr(), 61455);
|
||||
}
|
||||
@@ -183,8 +183,6 @@ Test(Bit, TSET1)
|
||||
result = apu->TSET1(apu->_getAbsoluteAddr());
|
||||
apu->_internalRegisters.pc -= 2;
|
||||
cr_assert_eq(apu->_internalRead(apu->_getAbsoluteAddr()), 0x7B);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(result, 6);
|
||||
}
|
||||
|
||||
@@ -202,8 +200,6 @@ Test(Bit, TCLR1)
|
||||
result = apu->TCLR1(apu->_getAbsoluteAddr());
|
||||
apu->_internalRegisters.pc -= 2;
|
||||
cr_assert_eq(apu->_internalRead(apu->_getAbsoluteAddr()), 0x00);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(result, 6);
|
||||
}
|
||||
|
||||
@@ -693,7 +689,7 @@ Test(ProgramFlow, JMP)
|
||||
cr_assert_eq(apu->_internalRegisters.pc, 61455);
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.x = 0b000000001;
|
||||
result = apu->JMP(apu->_getAbsoluteAddrByX(), true);
|
||||
result = apu->JMP(apu->_getAbsoluteByXAddr(), true);
|
||||
cr_assert_eq(result, 6);
|
||||
cr_assert_eq(apu->_internalRegisters.pc, 61712);
|
||||
}
|
||||
@@ -715,8 +711,6 @@ Test(DecimalCompensation, DAA)
|
||||
result = apu->DAA();
|
||||
cr_assert_eq(result, 3);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x80);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
Test(DecimalCompensation, DAS)
|
||||
@@ -730,8 +724,6 @@ Test(DecimalCompensation, DAS)
|
||||
result = apu->DAS();
|
||||
cr_assert_eq(result, 3);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x99);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
@@ -816,10 +808,8 @@ Test(XVIbitArithmetic, ADDW)
|
||||
result = apu->ADDW(apu->_getDirectAddr());
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRegisters.ya, 0x6532);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.v, false);
|
||||
cr_assert_eq(apu->_internalRegisters.h, false);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.c, false);
|
||||
}
|
||||
|
||||
@@ -835,10 +825,8 @@ Test(XVIbitArithmetic, SUBW)
|
||||
result = apu->SUBW(apu->_getDirectAddr());
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRegisters.ya, 0x2110);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.v, false);
|
||||
cr_assert_eq(apu->_internalRegisters.h, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
}
|
||||
|
||||
@@ -853,9 +841,7 @@ Test(XVIbitArithmetic, CMPW)
|
||||
apu->_internalWrite(0x55 + 1, 0x22);
|
||||
result = apu->CMPW(apu->_getDirectAddr());
|
||||
cr_assert_eq(result, 4);
|
||||
cr_assert_eq(apu->_internalRegisters.z, true);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
@@ -881,8 +867,6 @@ Test(XVIbitDataTransmission, MOVW)
|
||||
apu->_internalWrite(0x55 + 1, 0x44);
|
||||
apu->MOVW(apu->_getDirectAddr(), true);
|
||||
cr_assert_eq(apu->_internalRegisters.ya, 0x4433);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@@ -901,16 +885,12 @@ Test(VIIIbitShiftRotation, ASL)
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0xCC);
|
||||
cr_assert_eq(apu->_internalRegisters.c, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
apu->_internalWrite(apu->_internalRegisters.pc, 0x55);
|
||||
apu->_internalWrite(0x55, 0xDD);
|
||||
result = apu->ASL(apu->_getDirectAddr(), 5);
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0xBA);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
Test(VIIIbitShiftRotation, LSR)
|
||||
@@ -923,16 +903,12 @@ Test(VIIIbitShiftRotation, LSR)
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x33);
|
||||
cr_assert_eq(apu->_internalRegisters.c, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
apu->_internalWrite(apu->_internalRegisters.pc, 0x55);
|
||||
apu->_internalWrite(0x55, 0xDD);
|
||||
result = apu->LSR(apu->_getDirectAddr(), 5);
|
||||
cr_assert_eq(result , 5);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0x6E);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
Test(VIIIbitShiftRotation, ROL)
|
||||
@@ -945,16 +921,12 @@ Test(VIIIbitShiftRotation, ROL)
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0xCC);
|
||||
cr_assert_eq(apu->_internalRegisters.c, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
apu->_internalWrite(apu->_internalRegisters.pc, 0x55);
|
||||
apu->_internalWrite(0x55, 0xDD);
|
||||
result = apu->ROL(apu->_getDirectAddr(), 5);
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0xBA);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
Test(VIIIbitShiftRotation, ROR)
|
||||
@@ -967,16 +939,12 @@ Test(VIIIbitShiftRotation, ROR)
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x33);
|
||||
cr_assert_eq(apu->_internalRegisters.c, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
apu->_internalWrite(apu->_internalRegisters.pc, 0x55);
|
||||
apu->_internalWrite(0x55, 0xDD);
|
||||
result = apu->ROR(apu->_getDirectAddr(), 5);
|
||||
cr_assert_eq(result , 5);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0x6E);
|
||||
cr_assert_eq(apu->_internalRegisters.c, true);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
Test(VIIIShiftRotation, XCN)
|
||||
@@ -988,8 +956,6 @@ Test(VIIIShiftRotation, XCN)
|
||||
result = apu->XCN();
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0xAA);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
@@ -1008,8 +974,6 @@ Test(VIIIbitIncrementDecrement, INC)
|
||||
result = apu->INC(apu->_getDirectAddr(), 4);
|
||||
cr_assert_eq(result, 4);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0xDE);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
}
|
||||
|
||||
Test(VIIIbitIncrementDecrement, INCreg)
|
||||
@@ -1021,8 +985,6 @@ Test(VIIIbitIncrementDecrement, INCreg)
|
||||
result = apu->INCreg(apu->_internalRegisters.a);
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x77);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
}
|
||||
|
||||
Test(VIIIbitIncrementDecrement, DEC)
|
||||
@@ -1035,8 +997,6 @@ Test(VIIIbitIncrementDecrement, DEC)
|
||||
result = apu->DEC(apu->_getDirectAddr(), 4);
|
||||
cr_assert_eq(result, 4);
|
||||
cr_assert_eq(apu->_internalRead(0x55), 0xDC);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, true);
|
||||
}
|
||||
|
||||
Test(VIIIbitIncrementDecrement, DECreg)
|
||||
@@ -1048,6 +1008,91 @@ Test(VIIIbitIncrementDecrement, DECreg)
|
||||
result = apu->DECreg(apu->_internalRegisters.a);
|
||||
cr_assert_eq(result, 2);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 0x75);
|
||||
cr_assert_eq(apu->_internalRegisters.z, false);
|
||||
cr_assert_eq(apu->_internalRegisters.n, false);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// //
|
||||
// (VIII)8-bit Logical tests //
|
||||
// //
|
||||
///////////////////////////////
|
||||
|
||||
Test(VIIILogical, ANDacc)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.a = 24;
|
||||
apu->_internalWrite(4, 23);
|
||||
result = apu->ANDacc(apu->_getIndexXAddr(), 3);
|
||||
cr_assert_eq(result, 3);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 16);
|
||||
}
|
||||
|
||||
Test(VIIILogical, AND)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.y = 7;
|
||||
apu->_internalWrite(4, 12);
|
||||
apu->_internalWrite(7, 44);
|
||||
result = apu->AND(apu->_getIndexXAddr(), apu->_getIndexYAddr(), 5);
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRead(4), 12);
|
||||
}
|
||||
|
||||
Test(VIIILogical, ORacc)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.a = 24;
|
||||
apu->_internalWrite(4, 23);
|
||||
result = apu->ORacc(apu->_getIndexXAddr(), 3);
|
||||
cr_assert_eq(result, 3);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 31);
|
||||
}
|
||||
|
||||
Test(VIIILogical, OR)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.y = 7;
|
||||
apu->_internalWrite(4, 12);
|
||||
apu->_internalWrite(7, 44);
|
||||
result = apu->OR(apu->_getIndexXAddr(), apu->_getIndexYAddr(), 5);
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRead(4), 44);
|
||||
}
|
||||
|
||||
Test(VIIILogical, EORacc)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.a = 24;
|
||||
apu->_internalWrite(4, 23);
|
||||
result = apu->EORacc(apu->_getIndexXAddr(), 3);
|
||||
cr_assert_eq(result, 3);
|
||||
cr_assert_eq(apu->_internalRegisters.a, 15);
|
||||
}
|
||||
|
||||
Test(VIIILogical, EOR)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
int result = 0;
|
||||
|
||||
apu->_internalRegisters.x = 4;
|
||||
apu->_internalRegisters.y = 7;
|
||||
apu->_internalWrite(4, 12);
|
||||
apu->_internalWrite(7, 44);
|
||||
result = apu->EOR(apu->_getIndexXAddr(), apu->_getIndexYAddr(), 5);
|
||||
cr_assert_eq(result, 5);
|
||||
cr_assert_eq(apu->_internalRead(4), 32);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// Created by Melefo on 26/02/2020.
|
||||
//
|
||||
|
||||
#include <criterion/criterion.h>
|
||||
#include "../tests.hpp"
|
||||
#include "../../sources/SNES.hpp"
|
||||
#include "../../sources/APU/APU.hpp"
|
||||
#include "../../sources/Exceptions/InvalidAddress.hpp"
|
||||
#include "../../sources/Exceptions/InvalidOpcode.hpp"
|
||||
|
||||
using namespace ComSquare;
|
||||
|
||||
Test(_get, immediate)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalWrite(0x32, 0x40);
|
||||
cr_assert_eq(apu->_getImmediateData(), 0x40);
|
||||
}
|
||||
|
||||
Test(_get, direct)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.p = true;
|
||||
apu->_internalWrite(0x32, 0x40);
|
||||
cr_assert_eq(apu->_getDirectAddr(), 0x140);
|
||||
}
|
||||
|
||||
Test(_get, X)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.x = 0x32;
|
||||
apu->_internalRegisters.p = true;
|
||||
cr_assert_eq(apu->_getIndexXAddr(), 0x132);
|
||||
}
|
||||
|
||||
Test(_get, Y)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.y = 0x32;
|
||||
apu->_internalRegisters.p = true;
|
||||
cr_assert_eq(apu->_getIndexYAddr(), 0x132);
|
||||
}
|
||||
|
||||
Test(_get, directbyX)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.x = 0x03;
|
||||
apu->_internalWrite(0x32, 0x40);
|
||||
cr_assert_eq(apu->_getDirectAddrByX(), 0x43);
|
||||
}
|
||||
|
||||
Test(_get, absolute)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
cr_assert_eq(apu->_getAbsoluteAddr(), 61455);
|
||||
}
|
||||
|
||||
Test(_get, absolutebyx)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.x = 10;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
cr_assert_eq(apu->_getAbsoluteByXAddr(), 64025);
|
||||
}
|
||||
|
||||
Test(_get, absoluteaddrbyx)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.x = 10;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
cr_assert_eq(apu->_getAbsoluteAddrByX(), 61465);
|
||||
}
|
||||
|
||||
Test(_get, absoluteaddrbyy)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.y = 10;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
cr_assert_eq(apu->_getAbsoluteAddrByY(), 61465);
|
||||
}
|
||||
|
||||
Test(_get, absolutebit)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
std::pair<uint24_t, uint24_t> result;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalWrite(0x32, 0b00001111);
|
||||
apu->_internalWrite(0x33, 0b11110000);
|
||||
result = apu->_getAbsoluteBit();
|
||||
cr_assert_eq(result.first, 4111);
|
||||
cr_assert_eq(result.second, 7);
|
||||
}
|
||||
|
||||
Test(_get, absolutebyxdirect)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.p = true;
|
||||
apu->_internalRegisters.x = 0x10;
|
||||
apu->_internalWrite(0x32, 0x42);
|
||||
apu->_internalWrite(0x152, 0b00001101);
|
||||
apu->_internalWrite(0x253, 0b01101011);
|
||||
cr_assert_eq(apu->_getAbsoluteDirectByXAddr(), 0b0110101100001101);
|
||||
}
|
||||
|
||||
Test(_get, absolutedirectbyy)
|
||||
{
|
||||
auto apu = Init().second.apu;
|
||||
|
||||
apu->_internalRegisters.pc = 0x32;
|
||||
apu->_internalRegisters.p = true;
|
||||
apu->_internalRegisters.y = 0x10;
|
||||
apu->_internalWrite(0x32, 0x42);
|
||||
apu->_internalWrite(0x142, 0b00001101);
|
||||
apu->_internalWrite(0x243, 0b01101011);
|
||||
cr_assert_eq(apu->_getAbsoluteDirectAddrByY(), 0b0110101100011101);
|
||||
}
|
||||
Reference in New Issue
Block a user