mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-20 14:15:11 +00:00
Starting to test addressings modes
This commit is contained in:
@@ -227,20 +227,20 @@ namespace ComSquare::CPU
|
||||
|
||||
uint24_t CPU::_GetImmediateAddr()
|
||||
{
|
||||
return this->_registers.pc++;
|
||||
return this->_registers.pac++;
|
||||
}
|
||||
|
||||
uint24_t CPU::_GetDirectAddr()
|
||||
{
|
||||
uint8_t addr = this->_bus->read(this->_registers.pc++);
|
||||
uint8_t addr = this->_bus->read(this->_registers.pac++);
|
||||
return this->_registers.d + addr;
|
||||
}
|
||||
|
||||
uint24_t CPU::_GetAbsoluteAddr()
|
||||
{
|
||||
uint24_t addr = this->_registers.dbr << 16u;
|
||||
addr += this->_bus->read(this->_registers.pc++) << 8u;
|
||||
addr += this->_bus->read(this->_registers.pc++);
|
||||
addr += this->_bus->read(this->_registers.pac++) << 8u;
|
||||
addr += this->_bus->read(this->_registers.pac++);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,10 @@ namespace ComSquare::CPU
|
||||
};
|
||||
uint16_t d;
|
||||
};
|
||||
//! @brief The program banK register;
|
||||
uint8_t k;
|
||||
union {
|
||||
struct {
|
||||
//! @brief The Program Bank Register;
|
||||
uint8_t pbr;
|
||||
//! @brief The Program Counter;
|
||||
union {
|
||||
struct {
|
||||
@@ -43,6 +45,10 @@ namespace ComSquare::CPU
|
||||
};
|
||||
uint16_t pc;
|
||||
};
|
||||
};
|
||||
//! @brief The current Program Address Counter (does not exist in a snes but is useful here).
|
||||
uint24_t pac;
|
||||
};
|
||||
//! @brief The Stack pointer
|
||||
union {
|
||||
struct {
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace ComSquare::Cartridge
|
||||
|
||||
uint8_t Cartridge::read_internal(uint24_t addr)
|
||||
{
|
||||
std::cout << "Reading a addr: " << std::hex << addr << " romStart: " << std::hex << _romStart << std::endl;
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Cartridge read", addr);
|
||||
return this->_data[addr + this->_romStart];
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Created by anonymus-raccoon on 1/29/20.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "IRectangleMemory.hpp"
|
||||
#include "../Exceptions/InvalidAddress.hpp"
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace ComSquare::Memory
|
||||
{
|
||||
auto it = std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr<IMemory> &accessor)
|
||||
{
|
||||
// std::cout << "Accessor: " << std::hex << accessor->getStart() << " Has access:: " << accessor->hasMemoryAt(addr) << std::endl;
|
||||
return accessor->hasMemoryAt(addr);
|
||||
});
|
||||
if (it == this->_memoryAccessors.end())
|
||||
|
||||
@@ -12,7 +12,25 @@ using namespace ComSquare;
|
||||
Test(AddrMode, Immediate)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pc = 0x15;
|
||||
cr_assert_eq(pair.second.cpu->_GetImmediateAddr(), 0x15);
|
||||
cr_assert_eq(pair.second.cpu->_registers.pc, 0x16);
|
||||
pair.second.cpu->_registers.pac = 0x000015;
|
||||
cr_assert_eq(pair.second.cpu->_GetImmediateAddr(), 0x000015, "Got %i, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x000016);
|
||||
}
|
||||
|
||||
Test(AddrMode, ImmediateBankChange)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pac = 0x00FFFF;
|
||||
cr_assert_eq(pair.second.cpu->_GetImmediateAddr(), 0x00FFFF);
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x010000);
|
||||
}
|
||||
|
||||
Test(AddrMode, Direct)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cartridge->_data[0] = 0x15;
|
||||
pair.second.cpu->_registers.pac = 0x808000;
|
||||
pair.second.cpu->_registers.d = 0x1000;
|
||||
cr_assert_eq(pair.second.cpu->_GetDirectAddr(), 0x1015, "Returned address was %i but was expecting 0x1015.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
|
||||
}
|
||||
@@ -287,6 +287,16 @@ Test(BusRead, ReadROM)
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
Test(BusRead, ReadROMStart)
|
||||
{
|
||||
auto pair = Init();
|
||||
uint8_t data;
|
||||
|
||||
pair.second.cartridge->_data[0] = 123;
|
||||
data = pair.first.read(0x808000);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
Test(BusRead, ReadCPU)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
@@ -14,7 +14,7 @@ std::pair<Memory::MemoryBus, SNES> Init()
|
||||
Memory::MemoryBus bus;
|
||||
Renderer::NoRenderer norenderer(0, 0, 0);
|
||||
SNES snes(std::make_shared<Memory::MemoryBus>(bus), "", norenderer);
|
||||
snes.cartridge->_size = 10;
|
||||
snes.cartridge->_size = 100;
|
||||
snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
|
||||
snes.cartridge->header.mappingMode = Cartridge::LoRom;
|
||||
snes.sram->_size = 10;
|
||||
|
||||
Reference in New Issue
Block a user