Implemnting PEI

This commit is contained in:
Anonymus Raccoon
2020-05-13 18:10:56 +02:00
parent 876b78a5c9
commit fea20fee70
5 changed files with 28 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
#include <utility>
#include <iostream>
#include "../Exceptions/InvalidAddress.hpp"
#include "../Exceptions/InvalidOpcode.hpp"
namespace ComSquare::CPU
{
@@ -265,6 +266,7 @@ namespace ComSquare::CPU
case AbsoluteIndirectIndexedByX:
return this->_getAbsoluteIndirectIndexedByXAddr();
}
throw InvalidOpcode("Unknown addressing mode for.");
}
unsigned CPU::_executeInstruction(uint8_t opcode)

View File

@@ -435,6 +435,8 @@ namespace ComSquare::CPU
int ROR(uint24_t, AddressingMode);
//! @brief Push Effective PC Relative Indirect Address
int PER(uint24_t, AddressingMode);
//! @brief Push Effective Indirect Address
int PEI(uint24_t, AddressingMode);
//! @brief All the instructions of the CPU.
//! @info Instructions are indexed by their opcode
@@ -651,7 +653,7 @@ namespace ComSquare::CPU
{&CPU::CMP, 5, "cmp", AddressingMode::DirectPageIndirectIndexedByY, 2}, // D1
{&CPU::CMP, 5, "cmp", AddressingMode::DirectPageIndirect, 2}, // D2
{&CPU::CMP, 7, "cmp", AddressingMode::StackRelativeIndirectIndexedByY, 2}, // D3
{&CPU::BRK, 7, "pei #-#", AddressingMode::Implied, 2}, // D4
{&CPU::PEI, 6, "pei", AddressingMode::DirectPage, 2}, // D4
{&CPU::CMP, 4, "cmp", AddressingMode::DirectPageIndexedByX, 2}, // D5
{&CPU::DEC, 6, "dec", AddressingMode::DirectPageIndexedByX, 2}, // D6
{&CPU::CMP, 6, "cmp", AddressingMode::DirectPageIndirectIndexedByYLong, 2}, // D7

View File

@@ -193,6 +193,12 @@ namespace ComSquare::CPU
return 0;
}
int CPU::PEI(uint24_t value, AddressingMode)
{
this->_push(static_cast<uint16_t>(value));
return 0;
}
int CPU::XCE(uint24_t, AddressingMode)
{
bool oldCarry = this->_registers.p.c;

View File

@@ -17,6 +17,11 @@ namespace ComSquare
private:
std::string _msg;
public:
explicit InvalidOpcode(const std::string &what)
{
this->_msg = what;
}
explicit InvalidOpcode(const std::string &pu, unsigned opcode)
{
std::stringstream stream;

View File

@@ -928,3 +928,15 @@ Test(PER, simple)
uint16_t value = snes.cpu->_pop16();
cr_assert_eq(value, 0x8004, "The pushed value should be equal to 0x8004 but it was 0x%x.", value);
}
Test(PEI, simple)
{
Init()
snes.cpu->_registers.s = 0x1FFF;
snes.wram->_data[0x0] = 0xFF;
snes.wram->_data[0x1] = 0xFF;
snes.cpu->PER(0x0, ComSquare::CPU::AddressingMode::Implied);
cr_assert_eq(snes.cpu->_registers.s, 0x1FFD, "The stack pointer should be equal to 0x1FFD but it was 0x%x.", snes.cpu->_registers.s);
uint16_t value = snes.cpu->_pop16();
cr_assert_eq(value, 0xFFFF, "The pushed value should be equal to 0xFFFF but it was 0x%x.", value);
}