mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-02 10:15:45 +00:00
Handling the m flag
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ add_executable(unit_tests
|
||||
sources/CPU/Instructions/CommonInstructions.hpp
|
||||
sources/Exceptions/InvalidOpcode.hpp
|
||||
sources/CPU/Instructions/Interrupts.cpp
|
||||
sources/CPU/Instructions/MathematicalOperations.cpp tests/CPU/testMath.cpp)
|
||||
sources/CPU/Instructions/MathematicalOperations.cpp tests/CPU/Math/testADC.cpp)
|
||||
|
||||
# include criterion & coverage
|
||||
target_link_libraries(unit_tests criterion -lgcov)
|
||||
|
||||
+4
-1
@@ -229,7 +229,10 @@ namespace ComSquare::CPU
|
||||
|
||||
uint24_t CPU::_getImmediateAddr()
|
||||
{
|
||||
return this->_registers.pac++;
|
||||
uint24_t effective = this->_registers.pac++;
|
||||
if (this->_registers.p.m)
|
||||
this->_registers.pac++;
|
||||
return effective;
|
||||
}
|
||||
|
||||
uint24_t CPU::_getDirectAddr()
|
||||
|
||||
+2
-1
@@ -187,6 +187,7 @@ namespace ComSquare::CPU
|
||||
enum Instructions
|
||||
{
|
||||
BRK = 0x00,
|
||||
|
||||
ADC_DPXi = 0x61,
|
||||
ADC_SR = 0x63,
|
||||
ADC_DP = 0x65,
|
||||
@@ -201,7 +202,7 @@ namespace ComSquare::CPU
|
||||
ADC_DPYil = 0x77,
|
||||
ADC_ABSY = 0x79,
|
||||
ADC_ABSX = 0x7D,
|
||||
ADC_ABSXl = 0x7F
|
||||
ADC_ABSXl = 0x7F,
|
||||
};
|
||||
|
||||
//! @brief The main CPU
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace ComSquare::CPU
|
||||
int CPU::ADC(uint24_t valueAddr)
|
||||
{
|
||||
unsigned value = this->_bus->read(valueAddr) + this->_registers.p.c;
|
||||
if (this->_registers.p.m)
|
||||
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||
unsigned negativeMask = this->_isEmulationMode ? 0xF0u : 0xF000u;
|
||||
unsigned maxValue = this->_isEmulationMode ? UINT8_MAX : UINT16_MAX;
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include <criterion/criterion.h>
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
#include "../tests.hpp"
|
||||
#include "../../sources/SNES.hpp"
|
||||
#include "../../sources/Memory/MemoryBus.hpp"
|
||||
#include "../../tests.hpp"
|
||||
#include "../../../sources/SNES.hpp"
|
||||
#include "../../../sources/Memory/MemoryBus.hpp"
|
||||
using namespace ComSquare;
|
||||
|
||||
Test(ADC, addingOne)
|
||||
@@ -93,4 +93,20 @@ Test(ADC, signedOverflowEmulated)
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.v, true, "The overflow flags should be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flags should be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flags should not be set.");
|
||||
}
|
||||
|
||||
Test(ADC, memoryTwoBytes)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_isEmulationMode = false;
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
pair.second.cpu->_registers.a = 0x000F;
|
||||
pair.second.wram->_data[0] = 0x01;
|
||||
pair.second.wram->_data[1] = 0x04;
|
||||
pair.second.cpu->ADC(0x0);
|
||||
cr_assert_eq(pair.second.cpu->_registers.a, 0x0410, "The accumulator's value should be 0x0410 but it was 0x%x.", pair.second.cpu->_registers.a);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flags should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.v, false, "The overflow flags should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flags should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flags should not be set.");
|
||||
}
|
||||
@@ -24,6 +24,15 @@ Test(AddrMode, Immediate)
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x000016);
|
||||
}
|
||||
|
||||
Test(AddrMode, ImmediateMemoryFlag)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pac = 0x000015;
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddr(), 0x000015, "Got %x, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x000017);
|
||||
}
|
||||
|
||||
Test(AddrMode, ImmediateBankChange)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
Reference in New Issue
Block a user