mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-21 06:35:10 +00:00
Implemnting PEI
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../Exceptions/InvalidAddress.hpp"
|
#include "../Exceptions/InvalidAddress.hpp"
|
||||||
|
#include "../Exceptions/InvalidOpcode.hpp"
|
||||||
|
|
||||||
namespace ComSquare::CPU
|
namespace ComSquare::CPU
|
||||||
{
|
{
|
||||||
@@ -265,6 +266,7 @@ namespace ComSquare::CPU
|
|||||||
case AbsoluteIndirectIndexedByX:
|
case AbsoluteIndirectIndexedByX:
|
||||||
return this->_getAbsoluteIndirectIndexedByXAddr();
|
return this->_getAbsoluteIndirectIndexedByXAddr();
|
||||||
}
|
}
|
||||||
|
throw InvalidOpcode("Unknown addressing mode for.");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CPU::_executeInstruction(uint8_t opcode)
|
unsigned CPU::_executeInstruction(uint8_t opcode)
|
||||||
|
|||||||
@@ -435,6 +435,8 @@ namespace ComSquare::CPU
|
|||||||
int ROR(uint24_t, AddressingMode);
|
int ROR(uint24_t, AddressingMode);
|
||||||
//! @brief Push Effective PC Relative Indirect Address
|
//! @brief Push Effective PC Relative Indirect Address
|
||||||
int PER(uint24_t, AddressingMode);
|
int PER(uint24_t, AddressingMode);
|
||||||
|
//! @brief Push Effective Indirect Address
|
||||||
|
int PEI(uint24_t, AddressingMode);
|
||||||
|
|
||||||
//! @brief All the instructions of the CPU.
|
//! @brief All the instructions of the CPU.
|
||||||
//! @info Instructions are indexed by their opcode
|
//! @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::DirectPageIndirectIndexedByY, 2}, // D1
|
||||||
{&CPU::CMP, 5, "cmp", AddressingMode::DirectPageIndirect, 2}, // D2
|
{&CPU::CMP, 5, "cmp", AddressingMode::DirectPageIndirect, 2}, // D2
|
||||||
{&CPU::CMP, 7, "cmp", AddressingMode::StackRelativeIndirectIndexedByY, 2}, // D3
|
{&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::CMP, 4, "cmp", AddressingMode::DirectPageIndexedByX, 2}, // D5
|
||||||
{&CPU::DEC, 6, "dec", AddressingMode::DirectPageIndexedByX, 2}, // D6
|
{&CPU::DEC, 6, "dec", AddressingMode::DirectPageIndexedByX, 2}, // D6
|
||||||
{&CPU::CMP, 6, "cmp", AddressingMode::DirectPageIndirectIndexedByYLong, 2}, // D7
|
{&CPU::CMP, 6, "cmp", AddressingMode::DirectPageIndirectIndexedByYLong, 2}, // D7
|
||||||
|
|||||||
@@ -193,6 +193,12 @@ namespace ComSquare::CPU
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CPU::PEI(uint24_t value, AddressingMode)
|
||||||
|
{
|
||||||
|
this->_push(static_cast<uint16_t>(value));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int CPU::XCE(uint24_t, AddressingMode)
|
int CPU::XCE(uint24_t, AddressingMode)
|
||||||
{
|
{
|
||||||
bool oldCarry = this->_registers.p.c;
|
bool oldCarry = this->_registers.p.c;
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ namespace ComSquare
|
|||||||
private:
|
private:
|
||||||
std::string _msg;
|
std::string _msg;
|
||||||
public:
|
public:
|
||||||
|
explicit InvalidOpcode(const std::string &what)
|
||||||
|
{
|
||||||
|
this->_msg = what;
|
||||||
|
}
|
||||||
|
|
||||||
explicit InvalidOpcode(const std::string &pu, unsigned opcode)
|
explicit InvalidOpcode(const std::string &pu, unsigned opcode)
|
||||||
{
|
{
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|||||||
@@ -928,3 +928,15 @@ Test(PER, simple)
|
|||||||
uint16_t value = snes.cpu->_pop16();
|
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);
|
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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user