From acf2807dc63436bf1720778257632ae70b6464f6 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Fri, 20 Mar 2020 03:14:31 +0100
Subject: [PATCH 01/14] Adding the bus debugger's view
---
ui/busView.ui | 373 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 373 insertions(+)
create mode 100644 ui/busView.ui
diff --git a/ui/busView.ui b/ui/busView.ui
new file mode 100644
index 0000000..cddaee3
--- /dev/null
+++ b/ui/busView.ui
@@ -0,0 +1,373 @@
+
+
+ MainWindow
+
+
+
+ 0
+ 0
+ 898
+ 620
+
+
+
+ MainWindow
+
+
+
+
+
+ 0
+ 0
+ 901
+ 621
+
+
+
+ Qt::Horizontal
+
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Sunken
+
+
+ 3
+
+
+ 2
+
+
+ -
+
+
+ Filters
+
+
+
-
+
+
+ Read from
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+ false
+
+
+
-
+
+
+ CPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ APU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ PPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ ROM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ WRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ SRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ VRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ OAM RAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ CG RAM
+
+
+
+ -
+
+
+ true
+
+
+
+
+
+
+ -
+
+
+ Write to
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+ false
+
+
+
-
+
+
+ CPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ APU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ PPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ ROM
+
+
+
+ -
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+ -
+
+
+ WRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ SRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ VRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ OAM RAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ CG RAM
+
+
+
+ -
+
+
+ true
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
-
+
+
+ Clear
+
+
+ false
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
From ea19186269806cd20fa2e6ce715b1d109be1a914 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Fri, 20 Mar 2020 16:41:45 +0100
Subject: [PATCH 02/14] Splitting the debug window of the component to allow
quick change of a component
---
CMakeLists.txt | 15 +-
sources/CPU/AddressingModes.cpp | 184 ++++++++++++++++++++++
sources/CPU/CPU.cpp | 208 ++-----------------------
sources/CPU/CPU.hpp | 5 +-
sources/Debugger/CPUDebug.cpp | 28 ++--
sources/Debugger/CPUDebug.hpp | 8 +-
sources/Debugger/ClosableWindow.hpp | 34 ++++
sources/Debugger/MemoryBusDebug.cpp | 19 +++
sources/Debugger/MemoryBusDebug.hpp | 27 ++++
sources/PPU/PPU.cpp | 19 ++-
sources/PPU/PPU.hpp | 3 +-
sources/Renderer/QtRenderer/QtSFML.cpp | 9 ++
sources/Renderer/QtRenderer/QtSFML.hpp | 2 +
sources/SNES.cpp | 40 +++--
sources/SNES.hpp | 14 +-
main.cpp => sources/main.cpp | 30 ++--
tests/tests.cpp | 6 +-
ui/busView.ui | 4 +-
18 files changed, 407 insertions(+), 248 deletions(-)
create mode 100644 sources/CPU/AddressingModes.cpp
create mode 100644 sources/Debugger/ClosableWindow.hpp
create mode 100644 sources/Debugger/MemoryBusDebug.cpp
create mode 100644 sources/Debugger/MemoryBusDebug.hpp
rename main.cpp => sources/main.cpp (52%)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e12549a..bdf401a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,7 +77,11 @@ add_executable(unit_tests
sources/APU/Instructions/Stack.cpp
sources/APU/Instructions/Subroutine.cpp
sources/APU/Instructions/ProgramFlow.cpp
- tests/CPU/Math/testSBC.cpp sources/CPU/Instructions/TransferRegisters.cpp tests/CPU/TransferRegisters.cpp)
+ tests/CPU/Math/testSBC.cpp
+ sources/CPU/Instructions/TransferRegisters.cpp
+ tests/CPU/TransferRegisters.cpp
+ sources/CPU/AddressingModes.cpp
+)
# include criterion & coverage
target_link_libraries(unit_tests criterion -lgcov)
@@ -95,7 +99,7 @@ set(CMAKE_AUTOUIC ON)
# make app
add_executable(ComSquare
- main.cpp
+ sources/main.cpp
sources/SNES.cpp
sources/SNES.hpp
sources/Memory/MemoryBus.cpp
@@ -166,7 +170,12 @@ add_executable(ComSquare
sources/APU/Instructions/Stack.cpp
sources/APU/Instructions/Subroutine.cpp
sources/APU/Instructions/ProgramFlow.cpp
- sources/CPU/Instructions/TransferRegisters.cpp)
+ sources/CPU/Instructions/TransferRegisters.cpp
+ sources/CPU/AddressingModes.cpp
+ sources/Debugger/MemoryBusDebug.cpp
+ sources/Debugger/MemoryBusDebug.hpp
+ sources/Debugger/ClosableWindow.hpp
+)
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
diff --git a/sources/CPU/AddressingModes.cpp b/sources/CPU/AddressingModes.cpp
new file mode 100644
index 0000000..cbe52ff
--- /dev/null
+++ b/sources/CPU/AddressingModes.cpp
@@ -0,0 +1,184 @@
+//
+// Created by anonymus-raccoon on 3/20/20.
+//
+
+#include "../Models/Int24.hpp"$
+#include "CPU.hpp"
+
+namespace ComSquare::CPU
+{
+ uint24_t CPU::_getImmediateAddrForA()
+ {
+ uint24_t effective = this->_registers.pac++;
+ if (!this->_registers.p.m)
+ this->_registers.pac++;
+ return effective;
+ }
+
+ uint24_t CPU::_getImmediateAddrForX()
+ {
+ uint24_t effective = this->_registers.pac++;
+ if (!this->_registers.p.x_b)
+ this->_registers.pac++;
+ return effective;
+ }
+
+ uint24_t CPU::_getDirectAddr()
+ {
+ 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.pac++);
+ addr += this->_bus->read(this->_registers.pac++) << 8u;
+ return addr;
+ }
+
+ uint24_t CPU::_getAbsoluteLongAddr()
+ {
+ uint24_t addr = this->_bus->read(this->_registers.pac++);
+ addr += this->_bus->read(this->_registers.pac++) << 8u;
+ addr += this->_bus->read(this->_registers.pac++) << 16u;
+ return addr;
+ }
+
+ uint24_t CPU::_getDirectIndirectIndexedYAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ uint24_t base = this->_bus->read(dp);
+ base += this->_bus->read(dp + 1) << 8u;
+ base += this->_registers.dbr << 16u;
+ if ((base & 0x80000000u) == (((base + this->_registers.y) & 0x80000000u)))
+ this->_hasIndexCrossedPageBoundary = true;
+ return base + this->_registers.y;
+ }
+
+ uint24_t CPU::_getDirectIndirectIndexedYLongAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ uint24_t base = this->_bus->read(dp);
+ base += this->_bus->read(dp + 1) << 8u;
+ base += this->_bus->read(dp + 2) << 16u;
+ return base;
+ }
+
+ uint24_t CPU::_getDirectIndirectIndexedXAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ dp += this->_registers.x;
+ uint24_t base = this->_bus->read(dp);
+ base += this->_bus->read(dp + 1) << 8u;
+ base += this->_registers.dbr << 16u;
+ return base;
+ }
+
+ uint24_t CPU::_getDirectIndexedByXAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ dp += this->_registers.x;
+ return dp;
+ }
+
+ uint24_t CPU::_getDirectIndexedByYAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ dp += this->_registers.y;
+ return dp;
+ }
+
+ uint24_t CPU::_getAbsoluteIndexedByXAddr()
+ {
+ uint16_t abs = this->_bus->read(this->_registers.pac++);
+ abs += this->_bus->read(this->_registers.pac++) << 8u;
+ uint24_t effective = abs + (this->_registers.dbr << 16u);
+ if ((effective & 0x80000000u) == (((effective + this->_registers.x) & 0x80000000u)))
+ this->_hasIndexCrossedPageBoundary = true;
+ return effective + this->_registers.x;
+ }
+
+ uint24_t CPU::_getAbsoluteIndexedByYAddr()
+ {
+ uint16_t abs = this->_bus->read(this->_registers.pac++);
+ abs += this->_bus->read(this->_registers.pac++) << 8u;
+ uint24_t effective = abs + (this->_registers.dbr << 16u);
+ if ((effective & 0x80000000u) == (((effective + this->_registers.y) & 0x80000000u)))
+ this->_hasIndexCrossedPageBoundary = true;
+ return effective + this->_registers.y;
+ }
+
+ uint24_t CPU::_getAbsoluteIndexedByXLongAddr()
+ {
+ uint24_t lng = this->_bus->read(this->_registers.pac++);
+ lng += this->_bus->read(this->_registers.pac++) << 8u;
+ lng += this->_bus->read(this->_registers.pac++) << 16u;
+ return lng + this->_registers.x;
+ }
+
+ uint24_t CPU::_getProgramCounterRelativeAddr()
+ {
+ uint24_t pc = this->_registers.pac;
+ int8_t mod = this->_bus->read(this->_registers.pac++);
+ return pc + mod;
+ }
+
+ uint24_t CPU::_getProgramCounterRelativeLongAddr()
+ {
+ uint24_t pc = this->_registers.pac;
+ uint8_t val1 = this->_bus->read(this->_registers.pac++);
+ uint8_t val2 = this->_bus->read(this->_registers.pac++);
+ int16_t mod = val2 > 0x7F ? (static_cast(val2) * 256 - val1) : (val1 | val2 << 8u);
+ return pc + mod;
+ }
+
+ uint24_t CPU::_getAbsoluteIndirectAddr()
+ {
+ uint16_t abs = this->_bus->read(this->_registers.pac++);
+ abs += this->_bus->read(this->_registers.pac++) << 8u;
+ uint24_t effective = this->_bus->read(abs);
+ effective += this->_bus->read(abs + 1) << 8u;
+ return effective;
+ }
+
+ uint24_t CPU::_getAbsoluteIndirectIndexedByXAddr()
+ {
+ uint24_t abs = this->_bus->read(this->_registers.pac++);
+ abs += this->_bus->read(this->_registers.pac++) << 8u;
+ abs += this->_registers.x;
+ uint24_t effective = this->_bus->read(abs);
+ effective += this->_bus->read(abs + 1) << 8u;
+ return effective;
+ }
+
+ uint24_t CPU::_getDirectIndirectAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ uint24_t effective = this->_bus->read(dp);
+ effective += this->_bus->read(dp + 1) << 8u;
+ effective += this->_registers.dbr << 16u;
+ return effective;
+ }
+
+ uint24_t CPU::_getDirectIndirectLongAddr()
+ {
+ uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
+ uint24_t effective = this->_bus->read(dp);
+ effective += this->_bus->read(++dp) << 8u;
+ effective += this->_bus->read(++dp) << 16u;
+ return effective;
+ }
+
+ uint24_t CPU::_getStackRelativeAddr()
+ {
+ return this->_bus->read(this->_registers.pac++) + this->_registers.s;
+ }
+
+ uint24_t CPU::_getStackRelativeIndirectIndexedYAddr()
+ {
+ uint24_t base = this->_bus->read(this->_registers.pac++) + this->_registers.s;
+ base += this->_registers.dbr << 16u;
+ return base + this->_registers.y;
+ }
+}
\ No newline at end of file
diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp
index ffc2647..5a81b0f 100644
--- a/sources/CPU/CPU.cpp
+++ b/sources/CPU/CPU.cpp
@@ -18,6 +18,11 @@ namespace ComSquare::CPU
this->RESB();
}
+ void CPU::setMemoryBus(std::shared_ptr bus)
+ {
+ this->_bus = std::move(bus);
+ }
+
//! @bref The CPU's internal registers starts at $4200 and finish at $421F.
uint8_t CPU::read(uint24_t addr)
{
@@ -204,9 +209,9 @@ namespace ComSquare::CPU
case Instructions::COP: this->COP(); return 7 + !this->_isEmulationMode;
- case Instructions::RTI: this->RTI(); return 6 + !this->_isEmulationMode;
+ case Instructions::RTI: this->RTI(); return 6 + !this->_isEmulationMode;
- case Instructions::ADC_IM: this->ADC(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
+ case Instructions::ADC_IM: this->ADC(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
case Instructions::ADC_ABS: this->ADC(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
case Instructions::ADC_ABSl: this->ADC(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
case Instructions::ADC_DP: this->ADC(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
@@ -250,7 +255,7 @@ namespace ComSquare::CPU
case Instructions::STZ_ABSX: this->STX(this->_getAbsoluteIndexedByXAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
case Instructions::STZ_DPX: this->STX(this->_getDirectIndexedByXAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
- case Instructions::LDA_IM: this->LDA(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
+ case Instructions::LDA_IM: this->LDA(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
case Instructions::LDA_ABS: this->LDA(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
case Instructions::LDA_ABSl: this->LDA(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
case Instructions::LDA_DP: this->LDA(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
@@ -266,13 +271,13 @@ namespace ComSquare::CPU
case Instructions::LDA_SR: this->LDA(this->_getStackRelativeAddr()); return 4 + !this->_registers.p.m;
case Instructions::LDA_SRYi: this->LDA(this->_getStackRelativeIndirectIndexedYAddr()); return 7 + !this->_registers.p.m;
- case Instructions::LDX_IM: this->LDX(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
+ case Instructions::LDX_IM: this->LDX(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
case Instructions::LDX_ABS: this->LDX(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
case Instructions::LDX_DP: this->LDX(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
case Instructions::LDX_ABSY: this->LDX(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
case Instructions::LDX_DPY: this->LDX(this->_getDirectIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
- case Instructions::LDY_IM: this->LDY(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
+ case Instructions::LDY_IM: this->LDY(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
case Instructions::LDY_ABS: this->LDY(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
case Instructions::LDY_DP: this->LDY(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
case Instructions::LDY_ABSY: this->LDY(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
@@ -311,7 +316,7 @@ namespace ComSquare::CPU
case Instructions::SED: this->SED(); return 2;
case Instructions::SEI: this->SEI(); return 2;
- case Instructions::AND_IM: this->AND(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
+ case Instructions::AND_IM: this->AND(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
case Instructions::AND_ABS: this->AND(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
case Instructions::AND_ABSl: this->AND(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
case Instructions::AND_DP: this->AND(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
@@ -352,13 +357,13 @@ namespace ComSquare::CPU
case Instructions::INX: this->INX(); return 2;
case Instructions::INY: this->INY(); return 2;
- case Instructions::CPX_IM: this->CPX(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
- case Instructions::CPX_ABS: this->CPX(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
- case Instructions::CPX_DP: this->CPX(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
+ case Instructions::CPX_IM: this->CPX(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
+ case Instructions::CPX_ABS: this->CPX(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
+ case Instructions::CPX_DP: this->CPX(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
- case Instructions::CPY_IM: this->CPY(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
- case Instructions::CPY_ABS: this->CPY(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
- case Instructions::CPY_DP: this->CPY(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
+ case Instructions::CPY_IM: this->CPY(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
+ case Instructions::CPY_ABS: this->CPY(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
+ case Instructions::CPY_DP: this->CPY(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
case Instructions::BCC: return this->BCC(this->_registers.pc++) + 2 + this->_isEmulationMode;
case Instructions::BCS: return this->BCS(this->_registers.pc++) + 2 + this->_isEmulationMode;
@@ -403,183 +408,4 @@ namespace ComSquare::CPU
{
return this->_bus->read(++this->_registers.s) + (this->_bus->read(++this->_registers.s) << 8u);
}
-
- ////////////////////////////////////////////////////////////////////
- /// Addressing modes
- ////////////////////////////////////////////////////////////////////
-
- uint24_t CPU::_getImmediateAddrForA()
- {
- uint24_t effective = this->_registers.pac++;
- if (!this->_registers.p.m)
- this->_registers.pac++;
- return effective;
- }
-
- uint24_t CPU::_getImmediateAddrForX()
- {
- uint24_t effective = this->_registers.pac++;
- if (!this->_registers.p.x_b)
- this->_registers.pac++;
- return effective;
- }
-
- uint24_t CPU::_getDirectAddr()
- {
- 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.pac++);
- addr += this->_bus->read(this->_registers.pac++) << 8u;
- return addr;
- }
-
- uint24_t CPU::_getAbsoluteLongAddr()
- {
- uint24_t addr = this->_bus->read(this->_registers.pac++);
- addr += this->_bus->read(this->_registers.pac++) << 8u;
- addr += this->_bus->read(this->_registers.pac++) << 16u;
- return addr;
- }
-
- uint24_t CPU::_getDirectIndirectIndexedYAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- uint24_t base = this->_bus->read(dp);
- base += this->_bus->read(dp + 1) << 8u;
- base += this->_registers.dbr << 16u;
- if ((base & 0x80000000u) == (((base + this->_registers.y) & 0x80000000u)))
- this->_hasIndexCrossedPageBoundary = true;
- return base + this->_registers.y;
- }
-
- uint24_t CPU::_getDirectIndirectIndexedYLongAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- uint24_t base = this->_bus->read(dp);
- base += this->_bus->read(dp + 1) << 8u;
- base += this->_bus->read(dp + 2) << 16u;
- return base;
- }
-
- uint24_t CPU::_getDirectIndirectIndexedXAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- dp += this->_registers.x;
- uint24_t base = this->_bus->read(dp);
- base += this->_bus->read(dp + 1) << 8u;
- base += this->_registers.dbr << 16u;
- return base;
- }
-
- uint24_t CPU::_getDirectIndexedByXAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- dp += this->_registers.x;
- return dp;
- }
-
- uint24_t CPU::_getDirectIndexedByYAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- dp += this->_registers.y;
- return dp;
- }
-
- uint24_t CPU::_getAbsoluteIndexedByXAddr()
- {
- uint16_t abs = this->_bus->read(this->_registers.pac++);
- abs += this->_bus->read(this->_registers.pac++) << 8u;
- uint24_t effective = abs + (this->_registers.dbr << 16u);
- if ((effective & 0x80000000u) == (((effective + this->_registers.x) & 0x80000000u)))
- this->_hasIndexCrossedPageBoundary = true;
- return effective + this->_registers.x;
- }
-
- uint24_t CPU::_getAbsoluteIndexedByYAddr()
- {
- uint16_t abs = this->_bus->read(this->_registers.pac++);
- abs += this->_bus->read(this->_registers.pac++) << 8u;
- uint24_t effective = abs + (this->_registers.dbr << 16u);
- if ((effective & 0x80000000u) == (((effective + this->_registers.y) & 0x80000000u)))
- this->_hasIndexCrossedPageBoundary = true;
- return effective + this->_registers.y;
- }
-
- uint24_t CPU::_getAbsoluteIndexedByXLongAddr()
- {
- uint24_t lng = this->_bus->read(this->_registers.pac++);
- lng += this->_bus->read(this->_registers.pac++) << 8u;
- lng += this->_bus->read(this->_registers.pac++) << 16u;
- return lng + this->_registers.x;
- }
-
- uint24_t CPU::_getProgramCounterRelativeAddr()
- {
- uint24_t pc = this->_registers.pac;
- int8_t mod = this->_bus->read(this->_registers.pac++);
- return pc + mod;
- }
-
- uint24_t CPU::_getProgramCounterRelativeLongAddr()
- {
- uint24_t pc = this->_registers.pac;
- uint8_t val1 = this->_bus->read(this->_registers.pac++);
- uint8_t val2 = this->_bus->read(this->_registers.pac++);
- int16_t mod = val2 > 0x7F ? (static_cast(val2) * 256 - val1) : (val1 | val2 << 8u);
- return pc + mod;
- }
-
- uint24_t CPU::_getAbsoluteIndirectAddr()
- {
- uint16_t abs = this->_bus->read(this->_registers.pac++);
- abs += this->_bus->read(this->_registers.pac++) << 8u;
- uint24_t effective = this->_bus->read(abs);
- effective += this->_bus->read(abs + 1) << 8u;
- return effective;
- }
-
- uint24_t CPU::_getAbsoluteIndirectIndexedByXAddr()
- {
- uint24_t abs = this->_bus->read(this->_registers.pac++);
- abs += this->_bus->read(this->_registers.pac++) << 8u;
- abs += this->_registers.x;
- uint24_t effective = this->_bus->read(abs);
- effective += this->_bus->read(abs + 1) << 8u;
- return effective;
- }
-
- uint24_t CPU::_getDirectIndirectAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- uint24_t effective = this->_bus->read(dp);
- effective += this->_bus->read(dp + 1) << 8u;
- effective += this->_registers.dbr << 16u;
- return effective;
- }
-
- uint24_t CPU::_getDirectIndirectLongAddr()
- {
- uint16_t dp = this->_bus->read(this->_registers.pac++) + this->_registers.d;
- uint24_t effective = this->_bus->read(dp);
- effective += this->_bus->read(++dp) << 8u;
- effective += this->_bus->read(++dp) << 16u;
- return effective;
- }
-
- uint24_t CPU::_getStackRelativeAddr()
- {
- return this->_bus->read(this->_registers.pac++) + this->_registers.s;
- }
-
- uint24_t CPU::_getStackRelativeIndirectIndexedYAddr()
- {
- uint24_t base = this->_bus->read(this->_registers.pac++) + this->_registers.s;
- base += this->_registers.dbr << 16u;
- return base + this->_registers.y;
- }
}
\ No newline at end of file
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index b3cc6cf..a856962 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -555,7 +555,7 @@ namespace ComSquare::CPU
explicit CPU(std::shared_ptr bus, Cartridge::Header &cartridgeHeader);
CPU(const CPU &) = default;
CPU &operator=(const CPU &) = delete;
- ~CPU() = default;
+ ~CPU() override = default;
//! @brief This function continue to execute the Cartridge code.
//! @return The number of CPU cycles that elapsed
virtual unsigned update();
@@ -572,6 +572,9 @@ namespace ComSquare::CPU
//! @brief Reset interrupt - Called on boot and when the reset button is pressed.
virtual void RESB();
+
+ //! @brief Change the memory bus used by the CPU.
+ void setMemoryBus(std::shared_ptr bus);
};
}
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index bb80fe6..77ab9f1 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -5,33 +5,41 @@
#include "CPUDebug.hpp"
#include "../Utility/Utility.hpp"
#include "../Exceptions/InvalidOpcode.hpp"
+#include
+#include
using namespace ComSquare::CPU;
namespace ComSquare::Debugger
{
CPUDebug::CPUDebug(CPU &basicCPU, SNES &snes)
- : CPU(basicCPU), QMainWindow(), _ui(), _snes(snes)
+ : CPU(basicCPU), _window(new ClosableWindow(this, &CPUDebug::disableDebugger)), _ui(), _snes(snes)
{
- this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setContextMenuPolicy(Qt::NoContextMenu);
+ this->_window->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setAttribute(Qt::WA_DeleteOnClose);
- this->_ui.setupUi(this);
+ this->_ui.setupUi(this->_window);
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
QMainWindow::connect(this->_ui.clear, &QPushButton::released, this, &CPUDebug::clearHistory);
- this->show();
+ this->_window->show();
this->_updateRegistersPanel();
}
+ void CPUDebug::disableDebugger()
+ {
+ this->_snes.disableCPUDebugging();
+ }
+
+ CPUDebug::~CPUDebug()
+ {
+ std::cout << "Destructor" << std::endl;
+ }
+
unsigned CPUDebug::update()
{
try {
- if (!this->isVisible()) {
- this->_snes.disableCPUDebugging();
- return 0;
- }
-
if (this->_isPaused)
return 0xFF;
return CPU::update();
diff --git a/sources/Debugger/CPUDebug.hpp b/sources/Debugger/CPUDebug.hpp
index e40f361..a7219a8 100644
--- a/sources/Debugger/CPUDebug.hpp
+++ b/sources/Debugger/CPUDebug.hpp
@@ -9,12 +9,14 @@
#include "../Renderer/SFRenderer.hpp"
#include "../SNES.hpp"
#include "../../ui/ui_cpu.h"
+#include "ClosableWindow.hpp"
namespace ComSquare::Debugger
{
//! @brief A custom CPU with a window that show it's registers and the disassembly.
- class CPUDebug : public CPU::CPU, public QMainWindow {
+ class CPUDebug : public CPU::CPU, public QObject {
private:
+ ClosableWindow *_window;
//! @brief A widget that contain the whole UI.
Ui::CPUView _ui;
//! @brief If this is set to true, the execution of the CPU will be paused.
@@ -56,6 +58,8 @@ namespace ComSquare::Debugger
void step();
//! @brief Clear the history panel.
void clearHistory();
+ //! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
+ void disableDebugger();
public:
//! @brief Update the UI when reseting the CPU.
void RESB() override;
@@ -63,7 +67,7 @@ namespace ComSquare::Debugger
explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes);
CPUDebug(const CPUDebug &) = delete;
CPUDebug &operator=(const CPUDebug &) = delete;
- ~CPUDebug() override = default;
+ ~CPUDebug() override;
//! @brief Override the basic cpu's update to allow pausing of the CPU only.
unsigned update() override;
diff --git a/sources/Debugger/ClosableWindow.hpp b/sources/Debugger/ClosableWindow.hpp
new file mode 100644
index 0000000..f87df08
--- /dev/null
+++ b/sources/Debugger/ClosableWindow.hpp
@@ -0,0 +1,34 @@
+//
+// Created by anonymus-raccoon on 3/20/20.
+//
+
+#ifndef COMSQUARE_CLOSABLEWINDOW_HPP
+#define COMSQUARE_CLOSABLEWINDOW_HPP
+
+#include
+
+namespace ComSquare::Debugger
+{
+ template
+ class ClosableWindow : public QMainWindow {
+ protected:
+ void closeEvent(QCloseEvent *) override
+ {
+ (this->_obj->*this->_onClose)();
+ }
+
+ private:
+ T *_obj;
+ void (T::*_onClose)();
+
+ public:
+ explicit ClosableWindow(T *obj, void (T::*onClose)())
+ : _obj(obj), _onClose(onClose)
+ { }
+ ClosableWindow(const ClosableWindow &) = delete;
+ ClosableWindow &operator=(const ClosableWindow &) = delete;
+ ~ClosableWindow() override = default;
+ };
+}
+
+#endif //COMSQUARE_CLOSABLEWINDOW_HPP
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
new file mode 100644
index 0000000..37168ad
--- /dev/null
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -0,0 +1,19 @@
+//
+// Created by anonymus-raccoon on 3/20/20.
+//
+
+#include "MemoryBusDebug.hpp"
+
+namespace ComSquare::Debugger
+{
+ MemoryBusDebug::MemoryBusDebug(const ComSquare::Memory::MemoryBus &bus)
+ : MemoryBus(bus), QMainWindow(), _ui()
+ {
+ this->setContextMenuPolicy(Qt::NoContextMenu);
+ this->setAttribute(Qt::WA_QuitOnClose, false);
+
+ this->_ui.setupUi(this);
+// QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
+ this->show();
+ }
+}
\ No newline at end of file
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
new file mode 100644
index 0000000..e93c6e0
--- /dev/null
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -0,0 +1,27 @@
+//
+// Created by anonymus-raccoon on 3/20/20.
+//
+
+#ifndef COMSQUARE_MEMORYBUSDEBUG_HPP
+#define COMSQUARE_MEMORYBUSDEBUG_HPP
+
+#include
+#include "../Memory/MemoryBus.hpp"
+#include "../../ui/ui_busView.h"
+
+namespace ComSquare::Debugger
+{
+ //! @brief window that allow the user to view all data going through the memory bus.
+ class MemoryBusDebug : public Memory::MemoryBus, public QMainWindow {
+ private:
+ //! @brief A widget that contain the whole UI.
+ Ui::BusView _ui;
+ public:
+ explicit MemoryBusDebug(const Memory::MemoryBus &bus);
+ MemoryBusDebug(const MemoryBusDebug &) = delete;
+ MemoryBusDebug &operator=(const MemoryBusDebug &) = delete;
+ ~MemoryBusDebug() override = default;
+ };
+}
+
+#endif //COMSQUARE_MEMORYBUSDEBUG_HPP
diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp
index d029ca0..92d40a6 100644
--- a/sources/PPU/PPU.cpp
+++ b/sources/PPU/PPU.cpp
@@ -10,6 +10,15 @@
namespace ComSquare::PPU
{
+ PPU::PPU(Renderer::IRenderer &renderer):
+ _renderer(renderer),
+ _vram(65536),
+ _oamram(544),
+ _cgram(512)
+ {
+ this->_isLowByte = true;
+ }
+
uint8_t PPU::read(uint24_t addr)
{
switch (addr) {
@@ -235,14 +244,4 @@ namespace ComSquare::PPU
}
this->_renderer.drawScreen();
}
-
- PPU::PPU(const std::shared_ptr &bus, Renderer::IRenderer &renderer):
- _renderer(renderer),
- _bus(std::move(bus)),
- _vram(65536),
- _oamram(544),
- _cgram(512)
- {
- this->_isLowByte = true;
- }
}
\ No newline at end of file
diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp
index 0836011..85ed2aa 100644
--- a/sources/PPU/PPU.hpp
+++ b/sources/PPU/PPU.hpp
@@ -545,12 +545,11 @@ namespace ComSquare::PPU
uint32_t mpy;
} mpy;
Renderer::IRenderer &_renderer;
- std::shared_ptr _bus;
Ram::ExtendedRam _vram;
Ram::ExtendedRam _oamram;
Ram::ExtendedRam _cgram;
public:
- PPU(const std::shared_ptr &bus, Renderer::IRenderer &renderer);
+ PPU(Renderer::IRenderer &renderer);
PPU(const PPU &) = default;
PPU &operator=(const PPU &) = delete;
~PPU() = default;
diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp
index a2abe00..9020d62 100644
--- a/sources/Renderer/QtRenderer/QtSFML.cpp
+++ b/sources/Renderer/QtRenderer/QtSFML.cpp
@@ -55,6 +55,10 @@ namespace ComSquare::Renderer
apuDebugger->setShortcut(Qt::Key_F4);
QMainWindow::connect(apuDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugAPU);
debugger->addAction(apuDebugger);
+ QAction *busDebugger = new QAction("Memory bus Viewer", &this->_window);
+ busDebugger->setShortcut(Qt::Key_F5);
+ QMainWindow::connect(busDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugBus);
+ debugger->addAction(busDebugger);
this->_window.show();
}
@@ -110,4 +114,9 @@ namespace ComSquare::Renderer
{
this->_snes.enableAPUDebugging();
}
+
+ void QtFullSFML::enableDebugBus()
+ {
+ this->_snes.enableMemoryBusDebugging();
+ }
}
\ No newline at end of file
diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp
index 66096b6..b971b82 100644
--- a/sources/Renderer/QtRenderer/QtSFML.hpp
+++ b/sources/Renderer/QtRenderer/QtSFML.hpp
@@ -31,6 +31,8 @@ namespace ComSquare::Renderer
void enableHeaderViewer();
//! @brief Action called when clicking on the enable APU debugger button.
void enableDebugAPU();
+ //! @brief Action called when clicking on the enable Memory Bus debugger button.
+ void enableDebugBus();
//! @brief Action called when clicking on the reset button.
void reset();
QtFullSFML(SNES &snes, QWidget* parent, const QPoint& position, const QSize& size, int frameRate = 0);
diff --git a/sources/SNES.cpp b/sources/SNES.cpp
index 73d4450..aa5824c 100644
--- a/sources/SNES.cpp
+++ b/sources/SNES.cpp
@@ -8,21 +8,23 @@
#ifdef DEBUGGER_ENABLED
#include "Debugger/CPUDebug.hpp"
#include "Debugger/APUDebug.hpp"
+#include "Debugger/MemoryBusDebug.hpp"
+
#endif
namespace ComSquare
{
- SNES::SNES(const std::shared_ptr &bus, const std::string &romPath, Renderer::IRenderer &renderer) :
- _bus(bus),
+ SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) :
+ _bus(std::make_shared()),
cartridge(new Cartridge::Cartridge(romPath)),
wram(new Ram::Ram(16384)),
sram(new Ram::Ram(this->cartridge->header.sramSize)),
apuRam(new APU::MemoryMap()),
- cpu(new CPU::CPU(bus, cartridge->header)),
- ppu(new PPU::PPU(bus, renderer)),
+ cpu(new CPU::CPU(this->_bus, cartridge->header)),
+ ppu(new PPU::PPU(renderer)),
apu(new APU::APU(this->apuRam))
{
- bus->mapComponents(*this);
+ this->_bus->mapComponents(*this);
}
void SNES::enableCPUDebugging()
@@ -43,7 +45,7 @@ namespace ComSquare
void SNES::enableRamViewer()
{
#ifdef DEBUGGER_ENABLED
- this->_ramViewer = std::make_shared(*this, *this->_bus);
+ this->_ramViewer = std::make_unique(*this, *this->_bus);
#endif
}
@@ -64,7 +66,7 @@ namespace ComSquare
void SNES::enableHeaderViewer()
{
#ifdef DEBUGGER_ENABLED
- this->_headerViewer = std::make_shared(*this->cartridge);
+ this->_headerViewer = std::make_unique(*this->cartridge);
#endif
}
@@ -78,9 +80,9 @@ namespace ComSquare
void SNES::enableAPUDebugging()
{
#ifdef DEBUGGER_ENABLED
- this->apu = std::make_shared(*this->apu, *this);
+ this->apu = std::make_shared(*this->apu, *this);
#else
- std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
+ std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
}
@@ -88,4 +90,24 @@ namespace ComSquare
{
this->apu = std::make_shared(*this->apu);
}
+
+ void SNES::disableMemoryBusDebugging()
+ {
+ #ifdef DEBUGGER_ENABLED
+ this->_bus = std::make_shared(*this->_bus);
+ this->cpu->setMemoryBus(this->_bus);
+ #else
+ std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
+ #endif
+ }
+
+ void SNES::enableMemoryBusDebugging()
+ {
+ #ifdef DEBUGGER_ENABLED
+ this->_bus = std::make_shared(*this->_bus);
+ this->cpu->setMemoryBus(this->_bus);
+ #else
+ std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
+ #endif
+ }
}
diff --git a/sources/SNES.hpp b/sources/SNES.hpp
index 5fc5846..b9a2025 100644
--- a/sources/SNES.hpp
+++ b/sources/SNES.hpp
@@ -25,10 +25,12 @@ namespace ComSquare
private:
#ifdef DEBUGGER_ENABLED
//! @brief The window that allow the user to view a memory.
- std::shared_ptr _ramViewer;
+ std::unique_ptr _ramViewer;
//! @brief The window that allow the user to view the cartridge's header.
- std::shared_ptr _headerViewer;
+ std::unique_ptr _headerViewer;
+// std::unique_ptr _bus;
public:
//! @brief Cartridge containing instructions (ROM).
@@ -65,11 +67,15 @@ namespace ComSquare
void disableAPUDebugging();
//! @brief Enable the APU's debugging window.
void enableAPUDebugging();
+ //! @brief Disable the Memory Bus's debugging window.
+ void disableMemoryBusDebugging();
+ //! @brief Enable the Memory Bus's debugging window.
+ void enableMemoryBusDebugging();
//! @brief Create all the components using a common memory bus for all of them.
- SNES(const std::shared_ptr &bus, const std::string &ramPath, Renderer::IRenderer &renderer);
+ SNES(const std::string &ramPath, Renderer::IRenderer &renderer);
SNES(const SNES &) = default;
- SNES &operator=(const SNES &) = default;
+ SNES &operator=(const SNES &) = delete;
~SNES() = default;
};
}
diff --git a/main.cpp b/sources/main.cpp
similarity index 52%
rename from main.cpp
rename to sources/main.cpp
index a2bb748..ed678cd 100644
--- a/main.cpp
+++ b/sources/main.cpp
@@ -5,15 +5,21 @@
#include
#include
#include
-#include "sources/SNES.hpp"
-#include "sources/Renderer/SFRenderer.hpp"
-#include "sources/Renderer/QtRenderer/QtSFML.hpp"
+#include "SNES.hpp"
+#include "Renderer/SFRenderer.hpp"
+#include "Renderer/QtRenderer/QtSFML.hpp"
using namespace ComSquare;
void usage(char *bin)
{
- std::cout << "ComSquare:" << std::endl << "\tUsage: " << bin << " rom_path" << std::endl;
+ std::cout << "ComSquare:" << std::endl
+ << "\tUsage: " << bin << " rom_path [options]" << std::endl
+ << "Options:" << std::endl
+ << "\t-c, --cpu: \tEnable the debugger of the CPU." << std::endl
+ << "\t-m, --memory: \tEnable the memory viewer panel." << std::endl
+ << "\t-h, --header: \tShow the header of the cartridge." << std::endl
+ << "\t-b, --bus: \tShow the memory bus's log." << std::endl;
}
void parseArguments(int argc, char **argv, SNES &snes)
@@ -21,13 +27,14 @@ void parseArguments(int argc, char **argv, SNES &snes)
while (true) {
int option_index = 0;
static struct option long_options[] = {
- {"cpu", no_argument, 0, 'c' },
- {"memory", no_argument, 0, 'm' },
- {"header", no_argument, 0, 'h' },
- {0, 0, 0, 0 }
+ {"cpu", no_argument, 0, 'c'},
+ {"memory", no_argument, 0, 'm'},
+ {"header", no_argument, 0, 'h'},
+ {"bus", no_argument, 0, 'b'},
+ {0, 0, 0, 0}
};
- char c = getopt_long(argc, argv, "cmh", long_options, &option_index);
+ int c = getopt_long(argc, argv, "cmh", long_options, &option_index);
if (c == -1)
break;
switch (c) {
@@ -43,6 +50,9 @@ void parseArguments(int argc, char **argv, SNES &snes)
case 'h':
snes.enableHeaderViewer();
break;
+ case 'b':
+ snes.enableMemoryBusDebugging();
+ break;
default:
break;
}
@@ -58,7 +68,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
Renderer::QtSFML renderer(600, 800);
- SNES snes(std::make_shared(), argv[1], renderer);
+ SNES snes(argv[1], renderer);
renderer.createWindow(snes, 60);
parseArguments(argc, argv, snes);
return QApplication::exec();
diff --git a/tests/tests.cpp b/tests/tests.cpp
index c9a3bd7..5864663 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -13,14 +13,12 @@ using namespace ComSquare;
std::pair, SNES> Init()
{
- std::shared_ptr bus = std::make_shared();
Renderer::NoRenderer norenderer(0, 0, 0);
- SNES snes(bus, "../tests/my_cartridge", norenderer);
+ SNES snes("../tests/my_cartridge", norenderer);
snes.cartridge->_size = 100;
snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
snes.cartridge->header.mappingMode = Cartridge::LoRom;
snes.sram->_size = 100;
snes.sram->_data = new uint8_t[snes.cartridge->_size];
-// bus->mapComponents(snes);
- return std::make_pair(bus, snes);
+ return std::make_pair(snes._bus, snes);
}
\ No newline at end of file
diff --git a/ui/busView.ui b/ui/busView.ui
index cddaee3..2b700d8 100644
--- a/ui/busView.ui
+++ b/ui/busView.ui
@@ -1,7 +1,7 @@
- MainWindow
-
+ BusView
+
0
From 75f9ffad8ebed7cade1b753e9d29b83c2ce2c2b3 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Fri, 20 Mar 2020 16:45:37 +0100
Subject: [PATCH 03/14] Preventing a memory leak
---
sources/Cartridge/Cartridge.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sources/Cartridge/Cartridge.hpp b/sources/Cartridge/Cartridge.hpp
index 3f17279..ff9461f 100644
--- a/sources/Cartridge/Cartridge.hpp
+++ b/sources/Cartridge/Cartridge.hpp
@@ -91,7 +91,7 @@ namespace ComSquare::Cartridge
//! @brief The cartridge can't be assigned.
Cartridge &operator=(const Cartridge &) = delete;
//! @brief Destructor that free the cartridge data.
- ~Cartridge() = default;
+ ~Cartridge() override = default;
//! @brief The header of the cartridge.
Header header;
From 09cd825bed0197c092cfdd1f021fee5337141622 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Mon, 23 Mar 2020 23:07:15 +0100
Subject: [PATCH 04/14] Cleaning up all debuggers
---
sources/APU/APU.cpp | 5 ++
sources/APU/APU.hpp | 3 ++
sources/CPU/CPU.cpp | 5 ++
sources/CPU/CPU.hpp | 3 ++
sources/Debugger/APUDebug.cpp | 30 ++++++++----
sources/Debugger/APUDebug.hpp | 15 +++++-
sources/Debugger/CPUDebug.cpp | 20 +++++---
sources/Debugger/CPUDebug.hpp | 9 +++-
sources/Debugger/ClosableWindow.hpp | 6 +--
sources/Debugger/HeaderViewer.cpp | 74 +++++++++++++++++------------
sources/Debugger/HeaderViewer.hpp | 43 +++++++++++------
sources/Debugger/MemoryBusDebug.cpp | 32 ++++++++++---
sources/Debugger/MemoryBusDebug.hpp | 20 ++++++--
sources/Debugger/MemoryViewer.cpp | 23 ++++++---
sources/Debugger/MemoryViewer.hpp | 12 ++++-
sources/Memory/MemoryBus.cpp | 5 ++
sources/Memory/MemoryBus.hpp | 3 ++
sources/SNES.cpp | 60 ++++++++++++++---------
sources/SNES.hpp | 3 +-
19 files changed, 266 insertions(+), 105 deletions(-)
diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp
index 19a96d9..a4d9a7e 100644
--- a/sources/APU/APU.cpp
+++ b/sources/APU/APU.cpp
@@ -18,6 +18,11 @@ namespace ComSquare::APU
this->reset();
}
+ bool APU::isDebugger()
+ {
+ return false;
+ }
+
uint8_t APU::_internalRead(uint24_t addr) {
switch (addr) {
case 0x0000 ... 0x00EF:
diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp
index 5006316..f71afc0 100644
--- a/sources/APU/APU.hpp
+++ b/sources/APU/APU.hpp
@@ -273,6 +273,9 @@ namespace ComSquare::APU
//! @brief This function is executed when the SNES is powered on or the reset button is pushed.
void reset();
+
+ //! @brief Return true if the CPU is overloaded with debugging features.
+ virtual bool isDebugger();
};
}
diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp
index 5a81b0f..e4efc02 100644
--- a/sources/CPU/CPU.cpp
+++ b/sources/CPU/CPU.cpp
@@ -18,6 +18,11 @@ namespace ComSquare::CPU
this->RESB();
}
+ bool CPU::isDebugger()
+ {
+ return false;
+ }
+
void CPU::setMemoryBus(std::shared_ptr bus)
{
this->_bus = std::move(bus);
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index a856962..8efd3d8 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -573,6 +573,9 @@ namespace ComSquare::CPU
//! @brief Reset interrupt - Called on boot and when the reset button is pressed.
virtual void RESB();
+ //! @brief Return true if the CPU is overloaded with debugging features.
+ virtual bool isDebugger();
+
//! @brief Change the memory bus used by the CPU.
void setMemoryBus(std::shared_ptr bus);
};
diff --git a/sources/Debugger/APUDebug.cpp b/sources/Debugger/APUDebug.cpp
index 443334e..6b34b5d 100644
--- a/sources/Debugger/APUDebug.cpp
+++ b/sources/Debugger/APUDebug.cpp
@@ -12,15 +12,16 @@ namespace ComSquare::Debugger
{
APUDebug::APUDebug(APU &apu, SNES &snes) :
APU(apu),
- QMainWindow(),
+ _window(new ClosableWindow(*this, &APUDebug::disableDebugger)),
_ui(),
_snes(snes)
{
- this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setContextMenuPolicy(Qt::NoContextMenu);
+ this->_window->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setAttribute(Qt::WA_DeleteOnClose);
- this->_ui.setupUi(this);
- this->show();
+ this->_ui.setupUi(this->_window);
+ this->_window->show();
this->_updatePanel();
}
@@ -479,10 +480,21 @@ namespace ComSquare::Debugger
void APUDebug::update(unsigned cycles)
{
- if (!this->isVisible()) {
- this->_snes.disableAPUDebugging();
- return;
- }
return APU::update(cycles);
}
+
+ void APUDebug::disableDebugger()
+ {
+ this->_snes.disableAPUDebugging();
+ }
+
+ bool APUDebug::isDebugger()
+ {
+ return true;
+ }
+
+ void APUDebug::focus()
+ {
+ this->_window->activateWindow();
+ }
}
\ No newline at end of file
diff --git a/sources/Debugger/APUDebug.hpp b/sources/Debugger/APUDebug.hpp
index 41d66e1..68a2f30 100644
--- a/sources/Debugger/APUDebug.hpp
+++ b/sources/Debugger/APUDebug.hpp
@@ -11,8 +11,11 @@
namespace ComSquare::Debugger
{
- class APUDebug : public APU::APU, public QMainWindow {
+ class APUDebug : public APU::APU {
private:
+ //! @brief The QT window for this debugger.
+ ClosableWindow *_window;
+
//! @brief A widget that contain the whole UI.
Ui::APUView _ui;
@@ -30,6 +33,10 @@ namespace ComSquare::Debugger
//! @brief return the mnemonic of the current instruction done.
std::string _getInstructionString();
+
+ public slots:
+ //! @brief Called when the window is closed. Turn off the debugger and revert to a basic APU.
+ void disableDebugger();
public:
//! @brief Convert a basic APU to a debugging APU.
explicit APUDebug(ComSquare::APU::APU &apu, SNES &snes);
@@ -39,6 +46,12 @@ namespace ComSquare::Debugger
//! @brief Override the apu's update to disable debugging.
void update(unsigned cycles) override;
+
+ //! @brief Return true if the CPU is overloaded with debugging features.
+ bool isDebugger() override;
+
+ //! @brief Focus the debugger's window.
+ void focus();
};
}
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index 77ab9f1..30a86ad 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -13,7 +13,10 @@ using namespace ComSquare::CPU;
namespace ComSquare::Debugger
{
CPUDebug::CPUDebug(CPU &basicCPU, SNES &snes)
- : CPU(basicCPU), _window(new ClosableWindow(this, &CPUDebug::disableDebugger)), _ui(), _snes(snes)
+ : CPU(basicCPU),
+ _window(new ClosableWindow(*this, &CPUDebug::disableDebugger)),
+ _ui(),
+ _snes(snes)
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
@@ -27,16 +30,16 @@ namespace ComSquare::Debugger
this->_updateRegistersPanel();
}
+ bool CPUDebug::isDebugger()
+ {
+ return true;
+ }
+
void CPUDebug::disableDebugger()
{
this->_snes.disableCPUDebugging();
}
- CPUDebug::~CPUDebug()
- {
- std::cout << "Destructor" << std::endl;
- }
-
unsigned CPUDebug::update()
{
try {
@@ -390,4 +393,9 @@ namespace ComSquare::Debugger
CPU::RESB();
this->_updateRegistersPanel();
}
+
+ void CPUDebug::focus()
+ {
+ this->_window->activateWindow();
+ }
}
\ No newline at end of file
diff --git a/sources/Debugger/CPUDebug.hpp b/sources/Debugger/CPUDebug.hpp
index a7219a8..15fbb7c 100644
--- a/sources/Debugger/CPUDebug.hpp
+++ b/sources/Debugger/CPUDebug.hpp
@@ -16,6 +16,7 @@ namespace ComSquare::Debugger
//! @brief A custom CPU with a window that show it's registers and the disassembly.
class CPUDebug : public CPU::CPU, public QObject {
private:
+ //! @brief The QT window for this debugger.
ClosableWindow *_window;
//! @brief A widget that contain the whole UI.
Ui::CPUView _ui;
@@ -67,7 +68,13 @@ namespace ComSquare::Debugger
explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes);
CPUDebug(const CPUDebug &) = delete;
CPUDebug &operator=(const CPUDebug &) = delete;
- ~CPUDebug() override;
+ ~CPUDebug() override = default;
+
+ //! @brief Return true if the CPU is overloaded with debugging features.
+ bool isDebugger() override;
+
+ //! @brief Focus the debugger's window.
+ void focus();
//! @brief Override the basic cpu's update to allow pausing of the CPU only.
unsigned update() override;
diff --git a/sources/Debugger/ClosableWindow.hpp b/sources/Debugger/ClosableWindow.hpp
index f87df08..02f8bae 100644
--- a/sources/Debugger/ClosableWindow.hpp
+++ b/sources/Debugger/ClosableWindow.hpp
@@ -14,15 +14,15 @@ namespace ComSquare::Debugger
protected:
void closeEvent(QCloseEvent *) override
{
- (this->_obj->*this->_onClose)();
+ (this->_obj.*this->_onClose)();
}
private:
- T *_obj;
+ T &_obj;
void (T::*_onClose)();
public:
- explicit ClosableWindow(T *obj, void (T::*onClose)())
+ explicit ClosableWindow(T &obj, void (T::*onClose)())
: _obj(obj), _onClose(onClose)
{ }
ClosableWindow(const ClosableWindow &) = delete;
diff --git a/sources/Debugger/HeaderViewer.cpp b/sources/Debugger/HeaderViewer.cpp
index 92b421b..2e77c88 100644
--- a/sources/Debugger/HeaderViewer.cpp
+++ b/sources/Debugger/HeaderViewer.cpp
@@ -4,50 +4,64 @@
#include "HeaderViewer.hpp"
#include "../Utility/Utility.hpp"
+#include "../SNES.hpp"
namespace ComSquare::Debugger
{
- HeaderViewer::HeaderViewer(ComSquare::Cartridge::Cartridge &cartridge) :
- _cartridge(cartridge),
+ HeaderViewer::HeaderViewer(ComSquare::SNES &snes)
+ : _window(new ClosableWindow(*this, &HeaderViewer::disableDebugger)),
+ _snes(snes),
+ _cartridge(*snes.cartridge),
_ui()
{
- this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setContextMenuPolicy(Qt::NoContextMenu);
+ this->_window->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setAttribute(Qt::WA_DeleteOnClose);
- this->_ui.setupUi(this);
- this->_ui.nameLineEdit->setText(cartridge.header.gameName.c_str());
+ this->_ui.setupUi(this->_window);
+ this->_ui.nameLineEdit->setText(this->_cartridge.header.gameName.c_str());
std::string memType;
- if (cartridge.header.mappingMode & Cartridge::LoRom)
+ if (this->_cartridge.header.mappingMode & Cartridge::LoRom)
memType += "LoRom ";
- if (cartridge.header.mappingMode & Cartridge::HiRom)
+ if (this->_cartridge.header.mappingMode & Cartridge::HiRom)
memType += "HiRom ";
- if (cartridge.header.mappingMode & Cartridge::SlowRom)
+ if (this->_cartridge.header.mappingMode & Cartridge::SlowRom)
memType += "SlowRom ";
- if (cartridge.header.mappingMode & Cartridge::FastRom)
+ if (this->_cartridge.header.mappingMode & Cartridge::FastRom)
memType += "FastRom ";
- if (cartridge.header.mappingMode & Cartridge::ExRom)
+ if (this->_cartridge.header.mappingMode & Cartridge::ExRom)
memType += "ExRom ";
this->_ui.mappingLineEdit->setText(memType.c_str());
- this->_ui.romSizeLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.romSize).c_str());
- this->_ui.sRamSizeLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.sramSize).c_str());
- this->_ui.versionLineEdit->setText(std::to_string(cartridge.header.version).c_str());
- this->_ui.creatorIDLineEdit->setText(std::to_string(cartridge.header.creatorID).c_str());
- this->_ui.checksumLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.checksum).c_str());
- this->_ui.checksumComplementLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.checksumComplement).c_str());
+ this->_ui.romSizeLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.romSize).c_str());
+ this->_ui.sRamSizeLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.sramSize).c_str());
+ this->_ui.versionLineEdit->setText(std::to_string(this->_cartridge.header.version).c_str());
+ this->_ui.creatorIDLineEdit->setText(std::to_string(this->_cartridge.header.creatorID).c_str());
+ this->_ui.checksumLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.checksum).c_str());
+ this->_ui.checksumComplementLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.checksumComplement).c_str());
- this->_ui.coProcessorLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.cop).c_str());
- this->_ui.breakLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.brk).c_str());
- this->_ui.abortLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.abort).c_str());
- this->_ui.nMInteruptLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.nmi).c_str());
- this->_ui.resetLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.reset).c_str());
- this->_ui.interruptRequestLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.irq).c_str());
+ this->_ui.coProcessorLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.cop).c_str());
+ this->_ui.breakLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.brk).c_str());
+ this->_ui.abortLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.abort).c_str());
+ this->_ui.nMInteruptLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.nmi).c_str());
+ this->_ui.resetLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.reset).c_str());
+ this->_ui.interruptRequestLineEdit->setText(ComSquare::Utility::to_hex(this->_cartridge.header.emulationInterrupts.irq).c_str());
- this->_ui.coProcessorLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.cop).c_str());
- this->_ui.breakLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.brk).c_str());
- this->_ui.abortLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.abort).c_str());
- this->_ui.nMInteruptLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.nmi).c_str());
- this->_ui.resetLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.reset).c_str());
- this->_ui.interruptRequestLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.irq).c_str());
- this->show();
+ this->_ui.coProcessorLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.cop).c_str());
+ this->_ui.breakLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.brk).c_str());
+ this->_ui.abortLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.abort).c_str());
+ this->_ui.nMInteruptLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.nmi).c_str());
+ this->_ui.resetLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.reset).c_str());
+ this->_ui.interruptRequestLineEditNat->setText(ComSquare::Utility::to_hex(this->_cartridge.header.nativeInterrupts.irq).c_str());
+ this->_window->show();
+ }
+
+ void HeaderViewer::disableDebugger()
+ {
+ this->_snes.disableHeaderViewer();
+ }
+
+ void HeaderViewer::focus()
+ {
+ this->_window->activateWindow();
}
}
\ No newline at end of file
diff --git a/sources/Debugger/HeaderViewer.hpp b/sources/Debugger/HeaderViewer.hpp
index b8e1226..e0cf04e 100644
--- a/sources/Debugger/HeaderViewer.hpp
+++ b/sources/Debugger/HeaderViewer.hpp
@@ -8,22 +8,37 @@
#include
#include "../Cartridge/Cartridge.hpp"
#include "../../ui/ui_cartridgeView.h"
+#include "ClosableWindow.hpp"
-namespace ComSquare::Debugger
+namespace ComSquare
{
- //! @brief Window that show the header of the currently running game.
- class HeaderViewer : public QMainWindow {
- private:
- //! @brief The cartrdige containing the header.
- Cartridge::Cartridge &_cartridge;
- //! @brief The layout of the viewer.
- Ui::CatridgeView _ui;
- public:
- explicit HeaderViewer(Cartridge::Cartridge &cartridge);
- HeaderViewer(const HeaderViewer &) = delete;
- HeaderViewer &operator=(const HeaderViewer &) = delete;
- ~HeaderViewer() override = default;
- };
+ class SNES;
+ namespace Debugger
+ {
+ //! @brief Window that show the header of the currently running game.
+ class HeaderViewer {
+ private:
+ //! @brief The QT window for this debugger.
+ ClosableWindow *_window{};
+ //! @brief A reference to the snes (to disable the debugger).
+ SNES &_snes;
+ //! @brief The cartridge containing the header.
+ Cartridge::Cartridge &_cartridge;
+ //! @brief The layout of the viewer.
+ Ui::CatridgeView _ui;
+ public slots:
+ //! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
+ void disableDebugger();
+ public:
+ //! @brief Focus the debugger's window.
+ void focus();
+
+ explicit HeaderViewer(SNES &snes);
+ HeaderViewer(const HeaderViewer &) = delete;
+ HeaderViewer &operator=(const HeaderViewer &) = delete;
+ ~HeaderViewer() = default;
+ };
+ }
}
#endif //COMSQUARE_HEADERVIEWER_HPP
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 37168ad..725cdf8 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -3,17 +3,35 @@
//
#include "MemoryBusDebug.hpp"
+#include "../SNES.hpp"
namespace ComSquare::Debugger
{
- MemoryBusDebug::MemoryBusDebug(const ComSquare::Memory::MemoryBus &bus)
- : MemoryBus(bus), QMainWindow(), _ui()
+ MemoryBusDebug::MemoryBusDebug(SNES &snes, const Memory::MemoryBus &bus)
+ : MemoryBus(bus),
+ _window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
+ _snes(snes),
+ _ui()
{
- this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setContextMenuPolicy(Qt::NoContextMenu);
+ this->_window->setAttribute(Qt::WA_QuitOnClose, false);
- this->_ui.setupUi(this);
-// QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
- this->show();
+ this->_ui.setupUi(this->_window);
+ this->_window->show();
+ }
+
+ void MemoryBusDebug::disableViewer()
+ {
+ this->_snes.disableMemoryBusDebugging();
+ }
+
+ void MemoryBusDebug::focus()
+ {
+ this->_window->activateWindow();
+ }
+
+ bool MemoryBusDebug::isDebugger()
+ {
+ return true;
}
}
\ No newline at end of file
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index e93c6e0..6edd4f6 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -8,19 +8,33 @@
#include
#include "../Memory/MemoryBus.hpp"
#include "../../ui/ui_busView.h"
+#include "ClosableWindow.hpp"
namespace ComSquare::Debugger
{
//! @brief window that allow the user to view all data going through the memory bus.
- class MemoryBusDebug : public Memory::MemoryBus, public QMainWindow {
+ class MemoryBusDebug : public Memory::MemoryBus {
private:
+ //! @brief The QT window for this debugger.
+ ClosableWindow *_window;
+ //! @brief A reference to the snes (to disable the debugger).
+ SNES &_snes;
//! @brief A widget that contain the whole UI.
Ui::BusView _ui;
+ public slots:
+ //! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
+ void disableViewer();
public:
- explicit MemoryBusDebug(const Memory::MemoryBus &bus);
+ explicit MemoryBusDebug(SNES &snes, const Memory::MemoryBus &bus);
MemoryBusDebug(const MemoryBusDebug &) = delete;
MemoryBusDebug &operator=(const MemoryBusDebug &) = delete;
- ~MemoryBusDebug() override = default;
+ ~MemoryBusDebug() = default;
+
+ //! @brief Focus the debugger's window.
+ void focus();
+
+ //! @brief Return true if the Bus is overloaded with debugging features.
+ bool isDebugger() override;
};
}
diff --git a/sources/Debugger/MemoryViewer.cpp b/sources/Debugger/MemoryViewer.cpp
index 632f356..748b9b7 100644
--- a/sources/Debugger/MemoryViewer.cpp
+++ b/sources/Debugger/MemoryViewer.cpp
@@ -65,16 +65,17 @@ void MemoryViewerModel::setMemory(std::shared_ptr memory)
namespace ComSquare::Debugger
{
MemoryViewer::MemoryViewer(ComSquare::SNES &snes, Memory::MemoryBus &bus) :
- QMainWindow(),
+ _window(new ClosableWindow(*this, &MemoryViewer::disableViewer)),
_snes(snes),
_bus(bus),
_ui(),
_model(snes.wram)
{
- this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setContextMenuPolicy(Qt::NoContextMenu);
+ this->_window->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setAttribute(Qt::WA_DeleteOnClose);
- this->_ui.setupUi(this);
+ this->_ui.setupUi(this->_window);
this->_ui.tableView->setModel(&this->_model);
this->_ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
this->_ui.tabs->addTab("&WRam");
@@ -84,7 +85,12 @@ namespace ComSquare::Debugger
QMainWindow::connect(this->_ui.actionGoto, &QAction::triggered, this, &MemoryViewer::gotoAddr);
QMainWindow::connect(this->_ui.actionGoto_Absolute, &QAction::triggered, this, &MemoryViewer::gotoAbsoluteAddr);
QObject::connect(this->_ui.tabs, &QTabBar::currentChanged, this, &MemoryViewer::changeRam);
- this->show();
+ this->_window->show();
+ }
+
+ void MemoryViewer::disableViewer()
+ {
+ this->_snes.disableRamViewer();
}
void MemoryViewer::changeRam(int id)
@@ -118,7 +124,7 @@ namespace ComSquare::Debugger
void MemoryViewer::_internalGoto(bool isAbsolute)
{
- QDialog dialog(this);
+ QDialog dialog(this->_window);
dialog.setWindowModality(Qt::WindowModal);
Ui::GotoDialog dialogUI;
dialogUI.setupUi(&dialog);
@@ -162,4 +168,9 @@ namespace ComSquare::Debugger
throw InvalidAddress("Memory viewer switch to address", addr);
return addr - accessor->getStart();
}
+
+ void MemoryViewer::focus()
+ {
+ this->_window->activateWindow();
+ }
}
\ No newline at end of file
diff --git a/sources/Debugger/MemoryViewer.hpp b/sources/Debugger/MemoryViewer.hpp
index cd4c13f..3619866 100644
--- a/sources/Debugger/MemoryViewer.hpp
+++ b/sources/Debugger/MemoryViewer.hpp
@@ -10,6 +10,7 @@
#include "../../ui/ui_gotoDialog.h"
#include "../Ram/Ram.hpp"
#include "../Memory/MemoryBus.hpp"
+#include "ClosableWindow.hpp"
#include
using ComSquare::Ram::Ram;
@@ -49,8 +50,11 @@ namespace ComSquare
namespace Debugger
{
//! @brief Class responsible of the Memory Viewer.
- class MemoryViewer : public QMainWindow {
+ class MemoryViewer : public QObject {
+ Q_OBJECT
private:
+ //! @brief The QT window for this debugger.
+ ClosableWindow *_window;
//! @brief SNES containing all rams to view.
SNES &_snes;
//! @brief The memory bus used to get the view for a given address.
@@ -61,6 +65,9 @@ namespace ComSquare
MemoryViewerModel _model;
//! @brief Helper function to create the goto dialog.
void _internalGoto(bool isAbsolute);
+ public slots:
+ //! @brief Called when the window is closed. Turn off the debugger.
+ void disableViewer();
public:
//! @brief Select the memory tab corresponding to a 24 bit address (map the address via the bus).
//! @return The address converted to the new tab's locale space.
@@ -73,6 +80,9 @@ namespace ComSquare
//! @brief Create a popup asking you where you want to jump to with the absolute mode selected.
void gotoAbsoluteAddr();
+ //! @brief Focus the memory viewer's window.
+ void focus();
+
explicit MemoryViewer(SNES &snes, Memory::MemoryBus &bus);
MemoryViewer(const MemoryViewer &) = delete;
MemoryViewer &operator=(const MemoryViewer &) = delete;
diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp
index bb9229f..2e3177a 100644
--- a/sources/Memory/MemoryBus.cpp
+++ b/sources/Memory/MemoryBus.cpp
@@ -97,4 +97,9 @@ namespace ComSquare::Memory
}
// TODO should implement HiRom.
}
+
+ bool MemoryBus::isDebugger()
+ {
+ return false;
+ }
}
\ No newline at end of file
diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp
index 3274807..bf67793 100644
--- a/sources/Memory/MemoryBus.hpp
+++ b/sources/Memory/MemoryBus.hpp
@@ -54,6 +54,9 @@ namespace ComSquare
//! @param addr The address you want to look for.
//! @return The components responsible for the address param or nullptr if none was found.
std::shared_ptr getAccessor(uint24_t addr);
+
+ //! @brief Return true if the Bus is overloaded with debugging features.
+ virtual bool isDebugger();
};
}
}
diff --git a/sources/SNES.cpp b/sources/SNES.cpp
index aa5824c..e286c9e 100644
--- a/sources/SNES.cpp
+++ b/sources/SNES.cpp
@@ -27,10 +27,20 @@ namespace ComSquare
this->_bus->mapComponents(*this);
}
+ void SNES::update()
+ {
+ unsigned cycleCount = this->cpu->update();
+ this->ppu->update(cycleCount);
+ this->apu->update(cycleCount);
+ }
+
void SNES::enableCPUDebugging()
{
#ifdef DEBUGGER_ENABLED
- this->cpu = std::make_shared(*this->cpu, *this);
+ if (this->cpu->isDebugger())
+ std::static_pointer_cast(this->cpu)->focus();
+ else
+ this->cpu = std::make_shared(*this->cpu, *this);
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
@@ -38,14 +48,16 @@ namespace ComSquare
void SNES::disableCPUDebugging()
{
- std::cout << "Disable the debugger of the CPU" << std::endl;
this->cpu = std::make_shared(*this->cpu);
}
void SNES::enableRamViewer()
{
#ifdef DEBUGGER_ENABLED
- this->_ramViewer = std::make_unique(*this, *this->_bus);
+ if (this->_ramViewer)
+ this->_ramViewer->focus();
+ else
+ this->_ramViewer = std::make_unique(*this, *this->_bus);
#endif
}
@@ -56,17 +68,13 @@ namespace ComSquare
#endif
}
- void SNES::update()
- {
- unsigned cycleCount = this->cpu->update();
- this->ppu->update(cycleCount);
- this->apu->update(cycleCount);
- }
-
void SNES::enableHeaderViewer()
{
#ifdef DEBUGGER_ENABLED
- this->_headerViewer = std::make_unique(*this->cartridge);
+ if (this->_headerViewer)
+ this->_headerViewer->focus();
+ else
+ this->_headerViewer = std::make_unique(*this);
#endif
}
@@ -80,7 +88,10 @@ namespace ComSquare
void SNES::enableAPUDebugging()
{
#ifdef DEBUGGER_ENABLED
- this->apu = std::make_shared(*this->apu, *this);
+ if (this->apu->isDebugger())
+ std::static_pointer_cast(this->apu)->focus();
+ else
+ this->apu = std::make_shared(*this->apu, *this);
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
@@ -91,6 +102,21 @@ namespace ComSquare
this->apu = std::make_shared(*this->apu);
}
+ void SNES::enableMemoryBusDebugging()
+ {
+ #ifdef DEBUGGER_ENABLED
+ if (this->_bus->isDebugger())
+ std::static_pointer_cast(this->_bus)->focus();
+ else
+ {
+ this->_bus = std::make_shared(*this, *this->_bus);
+ this->cpu->setMemoryBus(this->_bus);
+ }
+ #else
+ std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
+ #endif
+ }
+
void SNES::disableMemoryBusDebugging()
{
#ifdef DEBUGGER_ENABLED
@@ -100,14 +126,4 @@ namespace ComSquare
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
}
-
- void SNES::enableMemoryBusDebugging()
- {
- #ifdef DEBUGGER_ENABLED
- this->_bus = std::make_shared(*this->_bus);
- this->cpu->setMemoryBus(this->_bus);
- #else
- std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
- #endif
- }
}
diff --git a/sources/SNES.hpp b/sources/SNES.hpp
index b9a2025..25fb99e 100644
--- a/sources/SNES.hpp
+++ b/sources/SNES.hpp
@@ -28,7 +28,6 @@ namespace ComSquare
std::unique_ptr _ramViewer;
//! @brief The window that allow the user to view the cartridge's header.
std::unique_ptr _headerViewer;
-// std::unique_ptr _bus;
@@ -74,7 +73,7 @@ namespace ComSquare
//! @brief Create all the components using a common memory bus for all of them.
SNES(const std::string &ramPath, Renderer::IRenderer &renderer);
- SNES(const SNES &) = default;
+ SNES(const SNES &) = delete;
SNES &operator=(const SNES &) = delete;
~SNES() = default;
};
From 95f17c06a8db3ad95de6ccec2006e8bb16297097 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 01:53:45 +0100
Subject: [PATCH 05/14] Finishing to clean tests and adding the start of the
bus logger
---
CMakeLists.txt | 19 +-
sources/APU/APU.cpp | 10 +-
sources/APU/APU.hpp | 7 +-
sources/APU/DSP/DSP.cpp | 8 +-
sources/APU/DSP/DSP.hpp | 11 +-
sources/APU/Instructions/Subroutine.cpp | 5 +
sources/CPU/AddressingModes.cpp | 2 +-
sources/CPU/CPU.hpp | 7 +-
.../CPU/Instructions/InternalInstruction.cpp | 5 +
sources/Cartridge/Cartridge.cpp | 2 +-
sources/Cartridge/Cartridge.hpp | 4 +-
sources/Debugger/MemoryBusDebug.cpp | 80 +-
sources/Debugger/MemoryBusDebug.hpp | 54 +-
sources/Debugger/MemoryViewer.cpp | 4 +-
sources/Memory/AMemory.cpp | 40 +
sources/Memory/{IMemory.hpp => AMemory.hpp} | 21 +-
...ctangleMemory.cpp => ARectangleMemory.cpp} | 12 +-
...ctangleMemory.hpp => ARectangleMemory.hpp} | 20 +-
sources/Memory/IMemory.cpp | 35 -
sources/Memory/MemoryBus.cpp | 8 +-
sources/Memory/MemoryBus.hpp | 10 +-
sources/Memory/MemoryShadow.cpp | 9 +-
sources/Memory/MemoryShadow.hpp | 22 +-
sources/Memory/RectangleShadow.cpp | 9 +-
sources/Memory/RectangleShadow.hpp | 16 +-
sources/PPU/PPU.cpp | 5 +
sources/PPU/PPU.hpp | 13 +-
sources/Ram/Ram.cpp | 11 +-
sources/Ram/Ram.hpp | 13 +-
sources/Renderer/QtRenderer/QtSFML.cpp | 4 +-
sources/SNES.cpp | 4 +-
tests/APU/testAPU.cpp | 67 +-
tests/APU/testAPUInstructions.cpp | 122 +-
tests/CPU/Math/testADC.cpp | 164 +--
tests/CPU/Math/testSBC.cpp | 124 +-
tests/CPU/TransferRegisters.cpp | 192 +--
tests/CPU/testAddressingMode.cpp | 364 +++---
tests/CPU/testBits.cpp | 52 +-
tests/CPU/testInternal.cpp | 1082 ++++++++---------
tests/CPU/testInterupts.cpp | 112 +-
tests/CPU/testStore.cpp | 174 +--
tests/PPU/testPpuWrite.cpp | 282 ++---
tests/PPU/testPpuWriteFromVmain.cpp | 320 ++---
tests/testMemoryBus.cpp | 309 +++--
tests/tests.cpp | 24 -
tests/tests.hpp | 16 +-
ui/busView.ui | 723 +++++------
47 files changed, 2421 insertions(+), 2176 deletions(-)
create mode 100644 sources/Memory/AMemory.cpp
rename sources/Memory/{IMemory.hpp => AMemory.hpp} (82%)
rename sources/Memory/{IRectangleMemory.cpp => ARectangleMemory.cpp} (85%)
rename sources/Memory/{IRectangleMemory.hpp => ARectangleMemory.hpp} (89%)
delete mode 100644 sources/Memory/IMemory.cpp
delete mode 100644 tests/tests.cpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bdf401a..c9aa11d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,7 +10,6 @@ add_compile_options(-W -Wall -Wextra -Wshadow)
# make unit tests
add_executable(unit_tests
tests/CPU/testAddressingMode.cpp
- tests/tests.cpp
tests/CPU/testInterupts.cpp
tests/testMemoryBus.cpp
tests/tests.hpp
@@ -18,8 +17,8 @@ add_executable(unit_tests
sources/SNES.hpp
sources/Memory/MemoryBus.cpp
sources/Memory/MemoryBus.hpp
- sources/Memory/IMemory.hpp
- sources/Memory/IMemory.cpp
+ sources/Memory/AMemory.hpp
+ sources/Memory/AMemory.cpp
sources/PPU/PPU.cpp
sources/PPU/PPU.hpp
sources/CPU/CPU.cpp
@@ -37,8 +36,8 @@ add_executable(unit_tests
sources/Ram/Ram.hpp
sources/Memory/MemoryShadow.cpp
sources/Memory/MemoryShadow.hpp
- sources/Memory/IRectangleMemory.cpp
- sources/Memory/IRectangleMemory.hpp
+ sources/Memory/ARectangleMemory.cpp
+ sources/Memory/ARectangleMemory.hpp
sources/APU/DSP/DSP.cpp
sources/APU/DSP/DSP.hpp
sources/Renderer/IRenderer.hpp
@@ -58,7 +57,6 @@ add_executable(unit_tests
tests/APU/testAPU.cpp
sources/CPU/Instructions/MathematicalOperations.cpp
tests/CPU/testAddressingMode.cpp
- tests/tests.cpp
tests/PPU/testPpuWrite.cpp
tests/PPU/testPpuWriteFromVmain.cpp
sources/CPU/Instructions/MathematicalOperations.cpp
@@ -104,8 +102,8 @@ add_executable(ComSquare
sources/SNES.hpp
sources/Memory/MemoryBus.cpp
sources/Memory/MemoryBus.hpp
- sources/Memory/IMemory.hpp
- sources/Memory/IMemory.cpp
+ sources/Memory/AMemory.hpp
+ sources/Memory/AMemory.cpp
sources/PPU/PPU.cpp
sources/PPU/PPU.hpp
sources/CPU/CPU.cpp
@@ -123,8 +121,8 @@ add_executable(ComSquare
sources/Ram/Ram.hpp
sources/Memory/MemoryShadow.cpp
sources/Memory/MemoryShadow.hpp
- sources/Memory/IRectangleMemory.cpp
- sources/Memory/IRectangleMemory.hpp
+ sources/Memory/ARectangleMemory.cpp
+ sources/Memory/ARectangleMemory.hpp
sources/APU/DSP/DSP.cpp
sources/APU/DSP/DSP.hpp
sources/Renderer/IRenderer.hpp
@@ -155,6 +153,7 @@ add_executable(ComSquare
ui/ramView.ui
ui/cartridgeView.ui
ui/apuView.ui
+ ui/busView.ui
resources/appResources.qrc
sources/Utility/Utility.hpp
sources/Debugger/MemoryViewer.cpp
diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp
index a4d9a7e..9b97357 100644
--- a/sources/APU/APU.cpp
+++ b/sources/APU/APU.cpp
@@ -13,7 +13,7 @@ namespace ComSquare::APU
{
APU::APU(std::shared_ptr &map) :
_map(map),
- _dsp(new DSP::DSP)
+ _dsp(new DSP::DSP())
{
this->reset();
}
@@ -359,10 +359,10 @@ namespace ComSquare::APU
}
MemoryMap::MemoryMap() :
- Page0(0x00F0),
- Page1(0x0100),
- Memory(0xFDC0),
- IPL(0x0040)
+ Page0(0x00F0, "APU's Page 0"),
+ Page1(0x0100, "APU's Page 1"),
+ Memory(0xFDC0, "APU's Ram"),
+ IPL(0x0040, "IPL Rom")
{
}
diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp
index f71afc0..0e58ad3 100644
--- a/sources/APU/APU.hpp
+++ b/sources/APU/APU.hpp
@@ -7,7 +7,7 @@
#include
#include "DSP/DSP.hpp"
-#include "../Memory/IMemory.hpp"
+#include "../Memory/AMemory.hpp"
#include "../Ram/Ram.hpp"
namespace ComSquare::APU
@@ -131,7 +131,7 @@ namespace ComSquare::APU
~MemoryMap() = default;
};
- class APU : public Memory::IMemory {
+ class APU : public Memory::AMemory {
protected:
//! @brief All the registers of the APU CPU
Registers _registers{};
@@ -155,6 +155,9 @@ namespace ComSquare::APU
//! @throw InvalidAddress will be thrown if the address is more than $FFFF (the number of register).
void _internalWrite(uint24_t addr, uint8_t data);
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
+
//! @brief Current state of APU CPU
StateMode _state = Running;
diff --git a/sources/APU/DSP/DSP.cpp b/sources/APU/DSP/DSP.cpp
index 0f926ce..1b895c7 100644
--- a/sources/APU/DSP/DSP.cpp
+++ b/sources/APU/DSP/DSP.cpp
@@ -7,9 +7,6 @@
namespace ComSquare::APU::DSP
{
- DSP::DSP()
- { }
-
uint8_t DSP::read(uint24_t addr)
{
switch (addr) {
@@ -591,4 +588,9 @@ namespace ComSquare::APU::DSP
{
return this->_channels;
}
+
+ std::string DSP::getName()
+ {
+ return "DSP";
+ }
}
\ No newline at end of file
diff --git a/sources/APU/DSP/DSP.hpp b/sources/APU/DSP/DSP.hpp
index 603a0db..9e25c6a 100644
--- a/sources/APU/DSP/DSP.hpp
+++ b/sources/APU/DSP/DSP.hpp
@@ -7,7 +7,7 @@
#include
#include
-#include "../../Memory/IMemory.hpp"
+#include "../../Memory/AMemory.hpp"
namespace ComSquare::APU::DSP
{
@@ -113,7 +113,7 @@ namespace ComSquare::APU::DSP
uint8_t coeff;
};
- class DSP : public Memory::IMemory {
+ class DSP : public Memory::AMemory {
private:
//! @brief All registers of the DSP
Registers _registers{};
@@ -121,10 +121,10 @@ namespace ComSquare::APU::DSP
//! @brief 8x channels of sample used to make sound
std::array _channels{};
public:
- explicit DSP();
+ DSP() = default;
DSP(const DSP &) = default;
DSP &operator=(const DSP &) = default;
- ~DSP() = default;
+ ~DSP() override = default;
Registers getRegisters();
@@ -140,6 +140,9 @@ namespace ComSquare::APU::DSP
//! @param data The new value of the register.
//! @throw InvalidAddress will be thrown if the address is more than $7F (the number of register).
void write(uint24_t addr, uint8_t data) override;
+
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
};
}
diff --git a/sources/APU/Instructions/Subroutine.cpp b/sources/APU/Instructions/Subroutine.cpp
index 34eb031..3dcf2c3 100644
--- a/sources/APU/Instructions/Subroutine.cpp
+++ b/sources/APU/Instructions/Subroutine.cpp
@@ -52,4 +52,9 @@ namespace ComSquare::APU
this->RET();
return 6;
}
+
+ std::string APU::getName()
+ {
+ return "APU";
+ }
}
\ No newline at end of file
diff --git a/sources/CPU/AddressingModes.cpp b/sources/CPU/AddressingModes.cpp
index cbe52ff..edcb35f 100644
--- a/sources/CPU/AddressingModes.cpp
+++ b/sources/CPU/AddressingModes.cpp
@@ -2,7 +2,7 @@
// Created by anonymus-raccoon on 3/20/20.
//
-#include "../Models/Int24.hpp"$
+#include "../Models/Int24.hpp"
#include "CPU.hpp"
namespace ComSquare::CPU
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index 8efd3d8..cdecf8b 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -5,7 +5,7 @@
#ifndef COMSQUARE_CPU_HPP
#define COMSQUARE_CPU_HPP
-#include "../Memory/IMemory.hpp"
+#include "../Memory/AMemory.hpp"
#include "../Memory/MemoryBus.hpp"
#include "../Models/Int24.hpp"
#include "../Cartridge/Cartridge.hpp"
@@ -363,7 +363,7 @@ namespace ComSquare::CPU
};
//! @brief The main CPU
- class CPU : public Memory::IMemory {
+ class CPU : public Memory::AMemory {
protected:
//! @brief All the registers of the CPU
Registers _registers{};
@@ -570,6 +570,9 @@ namespace ComSquare::CPU
//! @throw InvalidAddress will be thrown if the address is more than $1F (the number of register).
void write(uint24_t addr, uint8_t data) override;
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
+
//! @brief Reset interrupt - Called on boot and when the reset button is pressed.
virtual void RESB();
diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp
index 6c16c0c..3b3d5f6 100644
--- a/sources/CPU/Instructions/InternalInstruction.cpp
+++ b/sources/CPU/Instructions/InternalInstruction.cpp
@@ -307,4 +307,9 @@ namespace ComSquare::CPU
{
this->_registers.pac = value;
}
+
+ std::string CPU::getName()
+ {
+ return "CPU";
+ }
}
\ No newline at end of file
diff --git a/sources/Cartridge/Cartridge.cpp b/sources/Cartridge/Cartridge.cpp
index dd326fd..61ce1e0 100644
--- a/sources/Cartridge/Cartridge.cpp
+++ b/sources/Cartridge/Cartridge.cpp
@@ -13,7 +13,7 @@
namespace ComSquare::Cartridge
{
Cartridge::Cartridge(const std::string &romPath)
- : Ram::Ram(0)
+ : Ram::Ram(0, "Cartridge")
{
try {
if (romPath.empty())
diff --git a/sources/Cartridge/Cartridge.hpp b/sources/Cartridge/Cartridge.hpp
index ff9461f..9dc7c73 100644
--- a/sources/Cartridge/Cartridge.hpp
+++ b/sources/Cartridge/Cartridge.hpp
@@ -6,9 +6,9 @@
#define COMSQUARE_CARTRIDGE_HPP
#include
-#include "../Memory/IMemory.hpp"
+#include "../Memory/AMemory.hpp"
#include "../Models/Int24.hpp"
-#include "../Memory/IRectangleMemory.hpp"
+#include "../Memory/ARectangleMemory.hpp"
#include "InterruptVectors.hpp"
#include "../Ram/Ram.hpp"
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 725cdf8..3c16a07 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -4,6 +4,7 @@
#include "MemoryBusDebug.hpp"
#include "../SNES.hpp"
+#include "../Utility/Utility.hpp"
namespace ComSquare::Debugger
{
@@ -11,12 +12,20 @@ namespace ComSquare::Debugger
: MemoryBus(bus),
_window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
_snes(snes),
- _ui()
+ _ui(),
+ _model()
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
+ this->_window->setAttribute(Qt::WA_DeleteOnClose);
this->_ui.setupUi(this->_window);
+ this->_ui.log->setModel(&this->_model);
+ this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
+ this->_ui.log->horizontalHeader()->setStretchLastSection(true);
+ this->_ui.log->horizontalHeader()->setSectionsMovable(true);
+ for (int i = 0; i < 5; i++)
+ this->_ui.log->setColumnWidth(i, this->_ui.log->width());
this->_window->show();
}
@@ -34,4 +43,71 @@ namespace ComSquare::Debugger
{
return true;
}
-}
\ No newline at end of file
+
+ uint8_t MemoryBusDebug::read(uint24_t addr)
+ {
+ return MemoryBus::read(addr);
+ }
+
+ void MemoryBusDebug::write(uint24_t addr, uint8_t data)
+ {
+ MemoryBus::write(addr, data);
+ }
+}
+
+int BusLogModel::rowCount(const QModelIndex &) const
+{
+ return this->_logs.size();
+}
+
+int BusLogModel::columnCount(const QModelIndex &) const
+{
+ return 5;
+}
+
+QVariant BusLogModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::TextAlignmentRole)
+ return Qt::AlignCenter;
+ if (role != Qt::DisplayRole)
+ return QVariant();
+ ComSquare::Debugger::BusLog log = this->_logs[index.row()];
+ switch (index.column()) {
+ case 0:
+ return QString(log.write ? "Write" : "Read");
+ case 1:
+ return QString(ComSquare::Utility::to_hex(log.addr).c_str());
+ case 2:
+ return QString(log.accessor.getName().c_str());
+ case 3:
+ return QString(log.accessor.getValueName(log.addr - log.accessor.getStart()).c_str());
+ case 4:
+ return QString(ComSquare::Utility::to_hex(log.oldData).c_str());
+ case 5:
+ return QString(ComSquare::Utility::to_hex(log.newData).c_str());
+ default:
+ return QVariant();
+ }
+}
+
+QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole || orientation == Qt::Vertical)
+ return QVariant();
+ switch (section) {
+ case 0:
+ return QString("Type");
+ case 1:
+ return QString("Address");
+ case 2:
+ return QString("Component");
+ case 3:
+ return QString("Data Name");
+ case 4:
+ return QString("Old Data");
+ case 5:
+ return QString("New Data");
+ default:
+ return QString("");
+ }
+}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 6edd4f6..6d9bcb5 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -10,6 +10,43 @@
#include "../../ui/ui_busView.h"
#include "ClosableWindow.hpp"
+namespace ComSquare::Debugger
+{
+ //! @brief The struct used to represent memory bus logs.
+ struct BusLog {
+ bool write;
+ uint24_t addr;
+ Memory::AMemory &accessor;
+ uint8_t oldData;
+ uint8_t newData;
+ };
+}
+
+
+//! @brief The qt model that bind the logs to the view.
+class BusLogModel : public QAbstractTableModel
+{
+Q_OBJECT
+private:
+ //! @brief The logs to display.
+ std::vector _logs;
+public:
+ BusLogModel() = default;
+ BusLogModel(const BusLogModel &) = delete;
+ const BusLogModel &operator=(const BusLogModel &) = delete;
+ ~BusLogModel() override = default;
+
+ //! @brief The number of row the table has.
+ int rowCount(const QModelIndex &parent) const override;
+ //! @brief The number of column the table has.
+ int columnCount(const QModelIndex &parent) const override;
+ //! @brief Return a data representing the table cell.
+ QVariant data(const QModelIndex &index, int role) const override;
+ //! @brief Override the headers to use hex values.
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
+};
+
+
namespace ComSquare::Debugger
{
//! @brief window that allow the user to view all data going through the memory bus.
@@ -21,7 +58,12 @@ namespace ComSquare::Debugger
SNES &_snes;
//! @brief A widget that contain the whole UI.
Ui::BusView _ui;
- public slots:
+ //! @brief The Log visualizer model for QT.
+ BusLogModel _model;
+
+ //! @brief Log a read/write to the debugger.
+// void log()
+ public:
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
void disableViewer();
public:
@@ -30,6 +72,16 @@ namespace ComSquare::Debugger
MemoryBusDebug &operator=(const MemoryBusDebug &) = delete;
~MemoryBusDebug() = default;
+ //! @brief Read data at a global address and log it to the debugger.
+ //! @param addr The address to read from.
+ //! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
+ uint8_t read(uint24_t addr) override;
+
+ //! @brief Write a data to a global address and log it to the debugger.
+ //! @param addr The address to write to.
+ //! @param data The data to write.
+ void write(uint24_t addr, uint8_t data) override;
+
//! @brief Focus the debugger's window.
void focus();
diff --git a/sources/Debugger/MemoryViewer.cpp b/sources/Debugger/MemoryViewer.cpp
index 748b9b7..1e59b53 100644
--- a/sources/Debugger/MemoryViewer.cpp
+++ b/sources/Debugger/MemoryViewer.cpp
@@ -149,10 +149,10 @@ namespace ComSquare::Debugger
unsigned MemoryViewer::switchToAddrTab(uint24_t addr)
{
- std::shared_ptr accessor = this->_bus.getAccessor(addr);
+ std::shared_ptr accessor = this->_bus.getAccessor(addr);
if (!accessor)
throw InvalidAddress("Memory viewer switch to address", addr);
- Memory::IMemory *ptr;
+ Memory::AMemory *ptr;
if (accessor->isMirror())
ptr = accessor->getMirrored().get();
else
diff --git a/sources/Memory/AMemory.cpp b/sources/Memory/AMemory.cpp
new file mode 100644
index 0000000..ce51b16
--- /dev/null
+++ b/sources/Memory/AMemory.cpp
@@ -0,0 +1,40 @@
+//
+// Created by anonymus-raccoon on 1/23/20.
+//
+
+#include "AMemory.hpp"
+#include
+
+namespace ComSquare::Memory
+{
+ void AMemory::setMemoryRegion(uint24_t start, uint24_t end)
+ {
+ this->_start = start;
+ this->_end = end;
+ }
+
+ bool AMemory::hasMemoryAt(uint24_t addr)
+ {
+ return this->_start <= addr && addr <= this->_end;
+ }
+
+ uint32_t AMemory::getStart()
+ {
+ return this->_start;
+ }
+
+ bool AMemory::isMirror()
+ {
+ return false;
+ }
+
+ std::shared_ptr AMemory::getMirrored()
+ {
+ return nullptr;
+ }
+
+ std::string AMemory::getValueName(uint24_t)
+ {
+ return "???";
+ }
+}
\ No newline at end of file
diff --git a/sources/Memory/IMemory.hpp b/sources/Memory/AMemory.hpp
similarity index 82%
rename from sources/Memory/IMemory.hpp
rename to sources/Memory/AMemory.hpp
index 78aa385..ab2fd7b 100644
--- a/sources/Memory/IMemory.hpp
+++ b/sources/Memory/AMemory.hpp
@@ -2,8 +2,8 @@
// Created by anonymus-raccoon on 1/23/20.
//
-#ifndef COMSQUARE_IMEMORY_HPP
-#define COMSQUARE_IMEMORY_HPP
+#ifndef COMSQUARE_AMEMORY_HPP
+#define COMSQUARE_AMEMORY_HPP
#include
@@ -14,7 +14,7 @@
namespace ComSquare::Memory
{
//! @brief Common interface implemented by all components mapping memory.
- class IMemory {
+ class AMemory {
private:
//! @brief The starting address mapped to this component.
uint24_t _start = 0;
@@ -34,7 +34,7 @@ namespace ComSquare::Memory
//! @brief Change starting and ending points of this mapped memory.
//! @param start The first address mapped to this component.
//! @param end The last address mapped to this component.
- //! @warning The start/end address should be a continuous range. You can't map address 0x0 and 0x2 but not 0x1. To do that, use two IMemory.
+ //! @warning The start/end address should be a continuous range. You can't map address 0x0 and 0x2 but not 0x1. To do that, use two AMemory.
void setMemoryRegion(uint24_t start, uint24_t end);
//! @brief Return true if this component has mapped the address.
//! @param addr The address to check.
@@ -46,14 +46,17 @@ namespace ComSquare::Memory
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
virtual bool isMirror();
+ //! @brief Get the name of this accessor (used for debug purpose)
+ virtual std::string getName() = 0;
+ //! @brief Get the name of the data at the address
+ //! @param addr The address (in local space)
+ virtual std::string getValueName(uint24_t addr);
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
- virtual std::shared_ptr getMirrored();
- // TODO add destructors everywhere
- // TODO rename this as an abstract.
- virtual ~IMemory() = default;
+ virtual std::shared_ptr getMirrored();
+ virtual ~AMemory() = default;
};
};
-#endif //COMSQUARE_IMEMORY_HPP
+#endif //COMSQUARE_AMEMORY_HPP
diff --git a/sources/Memory/IRectangleMemory.cpp b/sources/Memory/ARectangleMemory.cpp
similarity index 85%
rename from sources/Memory/IRectangleMemory.cpp
rename to sources/Memory/ARectangleMemory.cpp
index 98ccea5..b60aa66 100644
--- a/sources/Memory/IRectangleMemory.cpp
+++ b/sources/Memory/ARectangleMemory.cpp
@@ -3,12 +3,12 @@
//
#include
-#include "IRectangleMemory.hpp"
+#include "ARectangleMemory.hpp"
#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::Memory
{
- uint8_t IRectangleMemory::read(uint24_t addr)
+ uint8_t ARectangleMemory::read(uint24_t addr)
{
addr += this->getStart();
uint8_t bank = addr >> 16u;
@@ -25,7 +25,7 @@ namespace ComSquare::Memory
return this->read_internal(page);
}
- void IRectangleMemory::write(uint24_t addr, uint8_t data)
+ void ARectangleMemory::write(uint24_t addr, uint8_t data)
{
addr += this->getStart();
uint8_t bank = addr >> 16u;
@@ -42,7 +42,7 @@ namespace ComSquare::Memory
this->write_internal(page, data);
}
- bool IRectangleMemory::hasMemoryAt(uint24_t addr)
+ bool ARectangleMemory::hasMemoryAt(uint24_t addr)
{
uint8_t bank = addr >> 16u;
uint16_t page = addr;
@@ -53,12 +53,12 @@ namespace ComSquare::Memory
return false;
}
- uint24_t IRectangleMemory::getStart()
+ uint24_t ARectangleMemory::getStart()
{
return (this->_startBank << 16u) + this->_startPage;
}
- void IRectangleMemory::setMemoryRegion(uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage)
+ void ARectangleMemory::setMemoryRegion(uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage)
{
this->_startBank = startBank;
this->_endBank = endBank;
diff --git a/sources/Memory/IRectangleMemory.hpp b/sources/Memory/ARectangleMemory.hpp
similarity index 89%
rename from sources/Memory/IRectangleMemory.hpp
rename to sources/Memory/ARectangleMemory.hpp
index 4c99985..f3adb8f 100644
--- a/sources/Memory/IRectangleMemory.hpp
+++ b/sources/Memory/ARectangleMemory.hpp
@@ -2,16 +2,16 @@
// Created by anonymus-raccoon on 1/29/20.
//
-#ifndef COMSQUARE_IRECTANGLEMEMORY_HPP
-#define COMSQUARE_IRECTANGLEMEMORY_HPP
+#ifndef COMSQUARE_ARECTANGLEMEMORY_HPP
+#define COMSQUARE_ARECTANGLEMEMORY_HPP
-#include "IMemory.hpp"
+#include "AMemory.hpp"
namespace ComSquare::Memory
{
- //! @brief Superset of the IMemory to map non continuous rectangle to the memory. (A rectangle that spam across more than one bank but that does not start at 0000 or end at FFFF).
- class IRectangleMemory : public IMemory {
+ //! @brief Superset of the AMemory to map non continuous rectangle to the memory. (A rectangle that spam across more than one bank but that does not start at 0000 or end at FFFF).
+ class ARectangleMemory : public AMemory {
private:
//! @brief The first bank to map to.
uint8_t _startBank = 0;
@@ -22,22 +22,22 @@ namespace ComSquare::Memory
//! @brief The last address of each bank to map.
uint16_t _endPage = 0;
public:
- //! @brief Read data from the component using the same method as the basic IMemory.
+ //! @brief Read data from the component using the same method as the basic AMemory.
//! @param addr The global 24 bits address. This method is responsible of mapping to the component's read.
//! @throw InvalidAddress if the address is not mapped to the component.
//! @return Return the data at the address given as parameter.
uint8_t read(uint24_t addr) override;
- //! @brief Write data to this component using the same method as the basic IMemory.
+ //! @brief Write data to this component using the same method as the basic AMemory.
//! @param addr The global 24 bits address. This method is responsible of mapping to the component's write.
//! @param data The new data to write.
//! @throw InvalidAddress if the address is not mapped to the component.
void write(uint24_t addr, uint8_t data) override;
- //! @brief Internal component read. Implement this as you would implement a basic IMemory's read.
+ //! @brief Internal component read. Implement this as you would implement a basic AMemory's read.
//! @param addr The local address to read from. 0x0 refer to the first byte of your data and the address is in the component's space. That means that you can consider this address as continuous
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
//! @return Return the data at the address given as parameter.
virtual uint8_t read_internal(uint24_t addr) = 0;
- //! @brief Internal component write. Implement this as you would implement a basic IMemory's write.
+ //! @brief Internal component write. Implement this as you would implement a basic AMemory's write.
//! @param addr The local address to write to. 0x0 refer to the first byte of your data and the address is in the component's space. That means that you can consider this address as continuous
//! @param data The new data to write.
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
@@ -59,4 +59,4 @@ namespace ComSquare::Memory
};
}
-#endif //COMSQUARE_IRECTANGLEMEMORY_HPP
+#endif //COMSQUARE_ARECTANGLEMEMORY_HPP
diff --git a/sources/Memory/IMemory.cpp b/sources/Memory/IMemory.cpp
deleted file mode 100644
index eff2491..0000000
--- a/sources/Memory/IMemory.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Created by anonymus-raccoon on 1/23/20.
-//
-
-#include "IMemory.hpp"
-#include
-
-namespace ComSquare::Memory
-{
- void IMemory::setMemoryRegion(uint24_t start, uint24_t end)
- {
- this->_start = start;
- this->_end = end;
- }
-
- bool IMemory::hasMemoryAt(uint24_t addr)
- {
- return this->_start <= addr && addr <= this->_end;
- }
-
- uint32_t IMemory::getStart()
- {
- return this->_start;
- }
-
- bool IMemory::isMirror()
- {
- return false;
- }
-
- std::shared_ptr IMemory::getMirrored()
- {
- return nullptr;
- }
-}
\ No newline at end of file
diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp
index 2e3177a..5f8a252 100644
--- a/sources/Memory/MemoryBus.cpp
+++ b/sources/Memory/MemoryBus.cpp
@@ -11,9 +11,9 @@
namespace ComSquare::Memory
{
- std::shared_ptr MemoryBus::getAccessor(uint24_t addr)
+ std::shared_ptr MemoryBus::getAccessor(uint24_t addr)
{
- auto it = std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr &accessor)
+ auto it = std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr &accessor)
{
return accessor->hasMemoryAt(addr);
});
@@ -24,7 +24,7 @@ namespace ComSquare::Memory
uint8_t MemoryBus::read(uint24_t addr)
{
- std::shared_ptr handler = this->getAccessor(addr);
+ std::shared_ptr handler = this->getAccessor(addr);
if (!handler) {
std::cout << "Unknown memory accessor for address " << std::hex << addr << ". Using open bus." << std::endl;
@@ -37,7 +37,7 @@ namespace ComSquare::Memory
void MemoryBus::write(uint24_t addr, uint8_t data)
{
- std::shared_ptr handler = this->getAccessor(addr);
+ std::shared_ptr handler = this->getAccessor(addr);
if (!handler) {
std::cout << "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write." << std::endl;
diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp
index bf67793..5647ac4 100644
--- a/sources/Memory/MemoryBus.hpp
+++ b/sources/Memory/MemoryBus.hpp
@@ -8,7 +8,7 @@
#include
#include
#include
-#include "IMemory.hpp"
+#include "AMemory.hpp"
namespace ComSquare
{
@@ -20,7 +20,7 @@ namespace ComSquare
class MemoryBus {
private:
//! @brief The list of components registered inside the bus. Every components that can read/write to a public address should be in this vector.
- std::vector> _memoryAccessors;
+ std::vector> _memoryAccessors;
//! @brief The last value read via the memory bus.
uint8_t _openBus = 0;
@@ -39,12 +39,12 @@ namespace ComSquare
//! @brief Read data at a global address.
//! @param addr The address to read from.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
- uint8_t read(uint24_t addr);
+ virtual uint8_t read(uint24_t addr);
//! @brief Write a data to a global address.
//! @param addr The address to write to.
//! @param data The data to write.
- void write(uint24_t addr, uint8_t data);
+ virtual void write(uint24_t addr, uint8_t data);
//! @brief Map components to the address space using the currently loaded cartridge to set the right mapping mode.
//! @param console All the components.
@@ -53,7 +53,7 @@ namespace ComSquare
//! @brief Helper function to get the components that is responsible of read/write at an address.
//! @param addr The address you want to look for.
//! @return The components responsible for the address param or nullptr if none was found.
- std::shared_ptr getAccessor(uint24_t addr);
+ std::shared_ptr getAccessor(uint24_t addr);
//! @brief Return true if the Bus is overloaded with debugging features.
virtual bool isDebugger();
diff --git a/sources/Memory/MemoryShadow.cpp b/sources/Memory/MemoryShadow.cpp
index 4256c52..246e7c6 100644
--- a/sources/Memory/MemoryShadow.cpp
+++ b/sources/Memory/MemoryShadow.cpp
@@ -8,7 +8,7 @@
namespace ComSquare::Memory
{
- MemoryShadow::MemoryShadow(std::shared_ptr initial, uint24_t start, uint24_t end)
+ MemoryShadow::MemoryShadow(std::shared_ptr initial, uint24_t start, uint24_t end)
: _initial(std::move(initial))
{
this->setMemoryRegion(start, end);
@@ -29,8 +29,13 @@ namespace ComSquare::Memory
return true;
}
- std::shared_ptr MemoryShadow::getMirrored()
+ std::shared_ptr MemoryShadow::getMirrored()
{
return this->_initial;
}
+
+ std::string MemoryShadow::getName()
+ {
+ return this->_initial->getName();
+ }
}
\ No newline at end of file
diff --git a/sources/Memory/MemoryShadow.hpp b/sources/Memory/MemoryShadow.hpp
index 0653522..673eaf3 100644
--- a/sources/Memory/MemoryShadow.hpp
+++ b/sources/Memory/MemoryShadow.hpp
@@ -6,37 +6,39 @@
#define COMSQUARE_MEMORYSHADOW_HPP
#include
-#include "IMemory.hpp"
+#include "AMemory.hpp"
namespace ComSquare::Memory
{
- class MemoryShadow : public IMemory {
+ class MemoryShadow : public AMemory {
private:
//! @brief Memory to shadow from.
- std::shared_ptr _initial;
+ std::shared_ptr _initial;
public:
//! @brief Create a shadow for the memory given as parameter.
- explicit MemoryShadow(std::shared_ptr initial, uint24_t start, uint24_t end);
+ explicit MemoryShadow(std::shared_ptr initial, uint24_t start, uint24_t end);
MemoryShadow(const MemoryShadow &) = default;
MemoryShadow &operator=(const MemoryShadow &) = default;
~MemoryShadow() = default;
- //! @brief Read from the initial IMemory given.
- //! @param addr The address to read from. The address 0x0 should refer to the first byte of the initial IMemory.
- //! @throw InvalidAddress will be thrown if the address is more than the size of the initial IMemory.
+ //! @brief Read from the initial AMemory given.
+ //! @param addr The address to read from. The address 0x0 should refer to the first byte of the initial AMemory.
+ //! @throw InvalidAddress will be thrown if the address is more than the size of the initial AMemory.
//! @return Return the data at the address.
uint8_t read(uint24_t addr) override;
//! @brief Write data to the ram.
- //! @param addr The address to write to. The address 0x0 should refer to the first byte of the initial IMemory.
+ //! @param addr The address to write to. The address 0x0 should refer to the first byte of the initial AMemory.
//! @param data The data to write.
- //! @throw InvalidAddress will be thrown if the address is more than the size of the initial IMemory.
+ //! @throw InvalidAddress will be thrown if the address is more than the size of the initial AMemory.
void write(uint24_t addr, uint8_t data) override;
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
bool isMirror() override;
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
- std::shared_ptr getMirrored() override;
+ std::shared_ptr getMirrored() override;
};
}
diff --git a/sources/Memory/RectangleShadow.cpp b/sources/Memory/RectangleShadow.cpp
index 09e9a48..f798389 100644
--- a/sources/Memory/RectangleShadow.cpp
+++ b/sources/Memory/RectangleShadow.cpp
@@ -9,7 +9,7 @@
namespace ComSquare::Memory
{
- RectangleShadow::RectangleShadow(std::shared_ptr initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage)
+ RectangleShadow::RectangleShadow(std::shared_ptr initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage)
: _initial(std::move(initial))
{
this->setMemoryRegion(startBank, endBank, startPage, endPage);
@@ -38,8 +38,13 @@ namespace ComSquare::Memory
return true;
}
- std::shared_ptr RectangleShadow::getMirrored()
+ std::shared_ptr RectangleShadow::getMirrored()
{
return this->_initial;
}
+
+ std::string RectangleShadow::getName()
+ {
+ return this->_initial->getName();
+ }
}
\ No newline at end of file
diff --git a/sources/Memory/RectangleShadow.hpp b/sources/Memory/RectangleShadow.hpp
index e1486e1..756ab0d 100644
--- a/sources/Memory/RectangleShadow.hpp
+++ b/sources/Memory/RectangleShadow.hpp
@@ -6,30 +6,30 @@
#define COMSQUARE_RECTANGLESHADOW_HPP
#include
-#include "IRectangleMemory.hpp"
+#include "ARectangleMemory.hpp"
#include "MemoryShadow.hpp"
namespace ComSquare::Memory
{
- class RectangleShadow : public IRectangleMemory {
+ class RectangleShadow : public ARectangleMemory {
private:
//! @brief Memory to shadow from.
- std::shared_ptr _initial;
+ std::shared_ptr _initial;
//! @brief The number of banks to add to the memory before accessing it from the initial data.
uint8_t _bankOffset = 0;
public:
//! @brief Create a shadow for the memory given as parameter.
- explicit RectangleShadow(std::shared_ptr initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage);
+ explicit RectangleShadow(std::shared_ptr initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage);
RectangleShadow(const RectangleShadow &) = default;
RectangleShadow &operator=(const RectangleShadow &) = default;
~RectangleShadow() = default;
- //! @brief Internal component read. Implement this as you would implement a basic IMemory's read.
+ //! @brief Internal component read. Implement this as you would implement a basic AMemory's read.
//! @param addr The local address to read from. 0x0 refer to the first byte of your data and the address is in the component's space. That means that you can consider this address as continuous
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
//! @return Return the data at the address given as parameter.
uint8_t read_internal(uint24_t addr) override;
- //! @brief Internal component write. Implement this as you would implement a basic IMemory's write.
+ //! @brief Internal component write. Implement this as you would implement a basic AMemory's write.
//! @param addr The local address to write to. 0x0 refer to the first byte of your data and the address is in the component's space. That means that you can consider this address as continuous
//! @param data The new data to write.
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
@@ -37,9 +37,11 @@ namespace ComSquare::Memory
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
bool isMirror() override;
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
- std::shared_ptr getMirrored() override;
+ std::shared_ptr getMirrored() override;
RectangleShadow *setBankOffset(uint8_t bankOffset);
};
diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp
index 92d40a6..9fd377e 100644
--- a/sources/PPU/PPU.cpp
+++ b/sources/PPU/PPU.cpp
@@ -244,4 +244,9 @@ namespace ComSquare::PPU
}
this->_renderer.drawScreen();
}
+
+ std::string PPU::getName()
+ {
+ return "PPU";
+ }
}
\ No newline at end of file
diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp
index 85ed2aa..ec0d8d4 100644
--- a/sources/PPU/PPU.hpp
+++ b/sources/PPU/PPU.hpp
@@ -6,7 +6,7 @@
#define COMSQUARE_PPU_HPP
#include
-#include "../Memory/IMemory.hpp"
+#include "../Memory/AMemory.hpp"
#include "../Memory/MemoryBus.hpp"
#include "../Renderer/IRenderer.hpp"
#include "../Ram/ExtendedRam.hpp"
@@ -156,7 +156,7 @@ namespace ComSquare::PPU
};
//! @brief The class containing all the registers the PPU
- class PPU : public Memory::IMemory {
+ class PPU : public Memory::AMemory {
private:
/* struct _layerInfo {
bool _characterSize;
@@ -549,10 +549,10 @@ namespace ComSquare::PPU
Ram::ExtendedRam _oamram;
Ram::ExtendedRam _cgram;
public:
- PPU(Renderer::IRenderer &renderer);
- PPU(const PPU &) = default;
+ explicit PPU(Renderer::IRenderer &renderer);
+ PPU(const PPU &) = delete;
PPU &operator=(const PPU &) = delete;
- ~PPU() = default;
+ ~PPU() override = default;
//! @brief Read data from the component.
//! @param addr The local address to read from (0x0 should refer to the first byte of this component).
@@ -564,6 +564,9 @@ namespace ComSquare::PPU
//! @param data The new data to write.
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
void write(uint24_t addr, uint8_t data) override;
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
+
//! @brief Update the PPU of n cycles.
//! @param The number of cycles to update.
void update(unsigned cycles);
diff --git a/sources/Ram/Ram.cpp b/sources/Ram/Ram.cpp
index 4209e8d..320834e 100644
--- a/sources/Ram/Ram.cpp
+++ b/sources/Ram/Ram.cpp
@@ -3,13 +3,15 @@
//
#include
+#include
#include "Ram.hpp"
#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::Ram
{
- Ram::Ram(size_t size)
- : _size(size)
+ Ram::Ram(size_t size, std::string ramName)
+ : _size(size),
+ _ramName(std::move(ramName))
{
if (size == 0)
this->_data = nullptr;
@@ -51,4 +53,9 @@ namespace ComSquare::Ram
{
return this->_size;
}
+
+ std::string Ram::getName()
+ {
+ return this->_ramName;
+ }
}
diff --git a/sources/Ram/Ram.hpp b/sources/Ram/Ram.hpp
index 26a3871..24b7f88 100644
--- a/sources/Ram/Ram.hpp
+++ b/sources/Ram/Ram.hpp
@@ -5,25 +5,27 @@
#ifndef COMSQUARE_RAM_HPP
#define COMSQUARE_RAM_HPP
-#include "../Memory/IRectangleMemory.hpp"
+#include "../Memory/ARectangleMemory.hpp"
namespace ComSquare::Ram
{
- class Ram : public Memory::IRectangleMemory {
+ class Ram : public Memory::ARectangleMemory {
protected:
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
uint8_t *_data;
//! @brief The size of the ram (iny bytes).
size_t _size;
+ //! @brief The name of this ram.
+ std::string _ramName;
public:
//! @brief Create a ram of a given size in bytes.
- explicit Ram(size_t size);
+ explicit Ram(size_t size, std::string ramName);
//! @brief The ram can't be copied.
Ram(const Ram &) = delete;
//! @brief The ram can't be assigned.
Ram &operator=(Ram &) = delete;
//! @brief Destructor that free the ram.
- ~Ram();
+ ~Ram() override;
//! @brief Read from the ram.
//! @param addr The address to read from. The address 0x0 should refer to the first byte of this ram.
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
@@ -41,6 +43,9 @@ namespace ComSquare::Ram
//! @param value replace value
void memset(uint24_t start, uint24_t end, uint8_t value);
+ //! @brief Get the name of this accessor (used for debug purpose)
+ std::string getName() override;
+
//! @brief Get the size of the ram in bytes.
size_t getSize();
};
diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp
index 9020d62..0471f67 100644
--- a/sources/Renderer/QtRenderer/QtSFML.cpp
+++ b/sources/Renderer/QtRenderer/QtSFML.cpp
@@ -33,12 +33,12 @@ namespace ComSquare::Renderer
//TODO implement rom openning from this menu.
(void)file;
- QMenu *game = this->_window.menuBar()->addMenu("Game");
+ QMenu *game = this->_window.menuBar()->addMenu("&Game");
QAction *reset = new QAction("Reset", &this->_window);
QMainWindow::connect(reset, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::reset);
game->addAction(reset);
- QMenu *debugger = this->_window.menuBar()->addMenu("Debugger");
+ QMenu *debugger = this->_window.menuBar()->addMenu("&Debugger");
QAction *cpuDebugger = new QAction("CPU's Debugger", &this->_window);
cpuDebugger->setShortcut(Qt::Key_F1);
QMainWindow::connect(cpuDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugCPU);
diff --git a/sources/SNES.cpp b/sources/SNES.cpp
index e286c9e..5cc42a8 100644
--- a/sources/SNES.cpp
+++ b/sources/SNES.cpp
@@ -17,8 +17,8 @@ namespace ComSquare
SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) :
_bus(std::make_shared()),
cartridge(new Cartridge::Cartridge(romPath)),
- wram(new Ram::Ram(16384)),
- sram(new Ram::Ram(this->cartridge->header.sramSize)),
+ wram(new Ram::Ram(16384, "WRam")),
+ sram(new Ram::Ram(this->cartridge->header.sramSize, "SRam")),
apuRam(new APU::MemoryMap()),
cpu(new CPU::CPU(this->_bus, cartridge->header)),
ppu(new PPU::PPU(renderer)),
diff --git a/tests/APU/testAPU.cpp b/tests/APU/testAPU.cpp
index 7357cc9..2c54013 100644
--- a/tests/APU/testAPU.cpp
+++ b/tests/APU/testAPU.cpp
@@ -19,8 +19,8 @@ using namespace ComSquare;
Test(_internalRead, register)
{
- auto apu = Init().second.apu;
- uint8_t result = 0;
+ Init()
+ auto apu = snes.apu;int8_t result = 0;
apu->_registers.counter0 = 123;
result = apu->_internalRead(0x00FD);
@@ -29,7 +29,8 @@ Test(_internalRead, register)
Test(_internalRead, Page0)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_map->Page0._data[0x0010] = 123;
@@ -39,7 +40,8 @@ Test(_internalRead, Page0)
Test(_internalRead, Page1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_map->Page1._data[0x0042] = 123;
@@ -49,7 +51,8 @@ Test(_internalRead, Page1)
Test(_internalRead, Memory)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_map->Memory._data[0xFCDC] = 123;
@@ -59,7 +62,8 @@ Test(_internalRead, Memory)
Test(_internalRead, IPL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_map->IPL._data[0x001F] = 123;
@@ -69,7 +73,8 @@ Test(_internalRead, IPL)
Test(_internalRead, Invalid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
cr_assert_throw(apu->_internalRead(0x10000), InvalidAddress);
}
@@ -82,7 +87,8 @@ Test(_internalRead, Invalid)
Test(_internalWrite, Page0)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalWrite(0x0001, 123);
cr_assert_eq(apu->_map->Page0._data[0x0001], 123);
@@ -90,7 +96,8 @@ Test(_internalWrite, Page0)
Test(_internalWrite, register)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalWrite(0x00F4, 123);
cr_assert_eq(apu->_registers.port0, 123);
@@ -98,7 +105,8 @@ Test(_internalWrite, register)
Test(_internalWrite, Page1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalWrite(0x01FF, 123);
cr_assert_eq(apu->_map->Page1._data[0x00FF], 123);
@@ -106,7 +114,8 @@ Test(_internalWrite, Page1)
Test(_internalWrite, Memory)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalWrite(0x0789, 123);
cr_assert_eq(apu->_map->Memory._data[0x0589], 123);
@@ -114,7 +123,8 @@ Test(_internalWrite, Memory)
Test(_internalWrite, IPL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalWrite(0xFFF0, 123);
cr_assert_eq(apu->_map->IPL._data[0x0030], 123);
@@ -122,7 +132,8 @@ Test(_internalWrite, IPL)
Test(_internalWrite, Invalid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
cr_assert_throw(apu->_internalWrite(0x10000, 123), InvalidAddress);
}
@@ -135,7 +146,8 @@ Test(_internalWrite, Invalid)
Test(read, Valid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_registers.port2 = 123;
@@ -145,7 +157,8 @@ Test(read, Valid)
Test(read, Invalid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
cr_assert_throw(apu->read(0x10000), InvalidAddress);
}
@@ -158,7 +171,8 @@ Test(read, Invalid)
Test(write, Valid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->write(0x03, 123);
cr_assert_eq(apu->_registers.port3, 123);
@@ -166,7 +180,8 @@ Test(write, Valid)
Test(write, Invalid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
cr_assert_throw(apu->write(0x04, 123), InvalidAddress);
}
@@ -179,7 +194,8 @@ Test(write, Invalid)
Test(executeInstruction, Valid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
uint8_t result = 0;
apu->_internalRegisters.pc = 0x00;
@@ -189,7 +205,8 @@ Test(executeInstruction, Valid)
Test(executeInstruction, Invalid)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalRegisters.pc = 0xFFFF;
cr_assert_throw(apu->_executeInstruction(), InvalidOpcode);
@@ -203,7 +220,8 @@ Test(executeInstruction, Invalid)
Test(update, running)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalRegisters.pc = 0x00;
apu->update(1);
@@ -212,7 +230,8 @@ Test(update, running)
Test(update, stopped)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_state = APU::Stopped;
apu->update(1);
@@ -227,7 +246,8 @@ Test(update, stopped)
Test(_get, direct)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalRegisters.pc = 0x32;
apu->_internalWrite(0x32, 123);
@@ -236,7 +256,8 @@ Test(_get, direct)
Test(_get, absolute)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
apu->_internalRegisters.pc = 0x32;
apu->_internalWrite(0x32, 0b00001111);
diff --git a/tests/APU/testAPUInstructions.cpp b/tests/APU/testAPUInstructions.cpp
index cf3b5c4..e632a3b 100644
--- a/tests/APU/testAPUInstructions.cpp
+++ b/tests/APU/testAPUInstructions.cpp
@@ -12,7 +12,7 @@
using namespace ComSquare;
-////////////////////
+////////////////////Init()\n\tauto apu = snes.apu
// //
// Standbys tests //
// //
@@ -20,7 +20,8 @@ using namespace ComSquare;
Test(Standbys, NOP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->NOP();
@@ -29,7 +30,8 @@ Test(Standbys, NOP)
Test(Standbys, SLEEP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->SLEEP();
@@ -39,7 +41,8 @@ Test(Standbys, SLEEP)
Test(Standbys, STOP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->STOP();
@@ -55,7 +58,8 @@ Test(Standbys, STOP)
Test(PSW, CLRC)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->CLRC();
@@ -65,7 +69,8 @@ Test(PSW, CLRC)
Test(PSW, SETC)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->SETC();
@@ -75,7 +80,8 @@ Test(PSW, SETC)
Test(PSW, NOTC)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.c = false;
@@ -86,7 +92,8 @@ Test(PSW, NOTC)
Test(PSW, CLRV)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->CLRV();
@@ -97,7 +104,8 @@ Test(PSW, CLRV)
Test(PSW, CLRP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->CLRP();
@@ -107,7 +115,8 @@ Test(PSW, CLRP)
Test(PSW, SETP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->SETP();
@@ -117,7 +126,8 @@ Test(PSW, SETP)
Test(PSW, EI)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->EI();
@@ -127,7 +137,8 @@ Test(PSW, EI)
Test(PSW, DI)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
result = apu->DI();
@@ -143,7 +154,8 @@ Test(PSW, DI)
Test(Bit, SET1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.pc = 0x32;
@@ -157,7 +169,8 @@ Test(Bit, SET1)
Test(Bit, CLR1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.pc = 0x32;
@@ -171,7 +184,8 @@ Test(Bit, CLR1)
Test(Bit, TSET1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -190,7 +204,8 @@ Test(Bit, TSET1)
Test(Bit, TCLR1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 0x80;
@@ -209,7 +224,8 @@ Test(Bit, TCLR1)
Test(Bit, AND1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -226,7 +242,8 @@ Test(Bit, AND1)
Test(Bit, AND1_invert)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -243,7 +260,8 @@ Test(Bit, AND1_invert)
Test(Bit, OR1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -260,7 +278,8 @@ Test(Bit, OR1)
Test(Bit, OR1_invert)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -277,7 +296,8 @@ Test(Bit, OR1_invert)
Test(Bit, EOR1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -294,7 +314,8 @@ Test(Bit, EOR1)
Test(Bit, NOT1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -311,7 +332,8 @@ Test(Bit, NOT1)
Test(Bit, MOV1)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -328,7 +350,8 @@ Test(Bit, MOV1)
Test(Bit, MOV1_carry)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 42;
@@ -351,7 +374,8 @@ Test(Bit, MOV1_carry)
Test(Stack, PUSH)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.a = 56;
@@ -363,7 +387,8 @@ Test(Stack, PUSH)
Test(Stack, POP)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(++apu->_internalRegisters.sp | 0x100u, 82);
@@ -381,7 +406,8 @@ Test(Stack, POP)
Test(Subroutine, CALL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_getAbsoluteAddr(), 23);
@@ -395,7 +421,8 @@ Test(Subroutine, CALL)
Test(Subroutine, PCALL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 123);
@@ -406,7 +433,8 @@ Test(Subroutine, PCALL)
Test(Subroutine, TCALL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(0xFFD0, 45);
@@ -417,7 +445,8 @@ Test(Subroutine, TCALL)
Test(Subroutine, BRK)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalRegisters.pch = 0xFF;
@@ -438,7 +467,8 @@ Test(Subroutine, BRK)
Test(Subroutine, RET)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(++apu->_internalRegisters.sp | 0x100u, 0x12);
@@ -452,7 +482,8 @@ Test(Subroutine, RET)
Test(Subroutine, RETI)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(++apu->_internalRegisters.sp | 0x100u, 0x12);
@@ -474,7 +505,8 @@ Test(Subroutine, RETI)
Test(ProgramFlow, BRA)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -486,7 +518,8 @@ Test(ProgramFlow, BRA)
Test(ProgramFlow, BEQ)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -501,7 +534,8 @@ Test(ProgramFlow, BEQ)
Test(ProgramFlow, BNE)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -517,7 +551,8 @@ Test(ProgramFlow, BNE)
Test(ProgramFlow, BCS)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -532,7 +567,8 @@ Test(ProgramFlow, BCS)
Test(ProgramFlow, BCC)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -548,7 +584,8 @@ Test(ProgramFlow, BCC)
Test(ProgramFlow, BVS)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -563,7 +600,8 @@ Test(ProgramFlow, BVS)
Test(ProgramFlow, BVC)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -579,7 +617,8 @@ Test(ProgramFlow, BVC)
Test(ProgramFlow, BMI)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
@@ -594,7 +633,8 @@ Test(ProgramFlow, BMI)
Test(ProgramFlow, BPL)
{
- auto apu = Init().second.apu;
+ Init()
+ auto apu = snes.apu;
int result = 0;
apu->_internalWrite(apu->_internalRegisters.pc, 23);
diff --git a/tests/CPU/Math/testADC.cpp b/tests/CPU/Math/testADC.cpp
index 137493b..67222fd 100644
--- a/tests/CPU/Math/testADC.cpp
+++ b/tests/CPU/Math/testADC.cpp
@@ -10,114 +10,114 @@ using namespace ComSquare;
Test(ADC, addingOne)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 1, "The accumulator's value should be 0x1 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.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 1, "The accumulator's value should be 0x1 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(ADC, addingOneEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.a = 0;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 1, "The accumulator's value should be 0x1 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.");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.a = 0;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 1, "The accumulator's value should be 0x1 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(ADC, overflow)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0xFFFF;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flags should 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, true, "The zero flags should be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0xFFFF;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flags should be set.");
}
Test(ADC, overflowEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.a = 0xFF;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flags should 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, true, "The zero flags should be set.");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.a = 0xFF;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flags should be set.");
}
Test(ADC, signedOverflow)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0x7FFF;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0x8000, "The accumulator's value should be 0x8000 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, 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.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0x7FFF;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0x8000, "The accumulator's value should be 0x8000 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, true, "The overflow flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(ADC, signedOverflowEmulated)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.a = 0x007F;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0x0080, "The accumulator's value should be 0x0080 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, 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.");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.a = 0x007F;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0x0080, "The accumulator's value should be 0x0080 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, true, "The overflow flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(ADC, negative)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0x8FFF;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->ADC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0x9000, "The accumulator's value should be 0x9000 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 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.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0x8FFF;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0x9000, "The accumulator's value should be 0x9000 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.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 = false;
- 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.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.a = 0x000F;
+ snes.wram->_data[0] = 0x01;
+ snes.wram->_data[1] = 0x04;
+ snes.cpu->ADC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0x0410, "The accumulator's value should be 0x0410 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
\ No newline at end of file
diff --git a/tests/CPU/Math/testSBC.cpp b/tests/CPU/Math/testSBC.cpp
index 4543749..22c2a9e 100644
--- a/tests/CPU/Math/testSBC.cpp
+++ b/tests/CPU/Math/testSBC.cpp
@@ -10,83 +10,83 @@ using namespace ComSquare;
Test(SBC, removingOne)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.c = true;
- pair.second.cpu->_registers.a = 0x1;
- pair.second.wram->_data[0] = 0x1;
- pair.second.cpu->SBC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flags should 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, true, "The zero flags should be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.c = true;
+ snes.cpu->_registers.a = 0x1;
+ snes.wram->_data[0] = 0x1;
+ snes.cpu->SBC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0, "The accumulator's value should be 0x0 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flags should be set.");
}
Test(SBC, legitOverflowWithCarry)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0x1;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.p.c = true;
- pair.second.wram->_data[0] = 0x03;
- pair.second.wram->_data[1] = 0x20;
- pair.second.cpu->SBC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0xDFFE, "The accumulator's value should be 0xDFFE 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, true, "The negative flags should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flags should not be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0x1;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.p.c = true;
+ snes.wram->_data[0] = 0x03;
+ snes.wram->_data[1] = 0x20;
+ snes.cpu->SBC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0xDFFE, "The accumulator's value should be 0xDFFE but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(SBC, overflowWithCarry)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.a = 0x1;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.p.c = true;
- pair.second.wram->_data[0] = 0x03;
- pair.second.wram->_data[1] = 0x20;
- pair.second.cpu->SBC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0xDFFE, "The accumulator's value should be 0xDFFE 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 be not 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.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.a = 0x1;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.p.c = true;
+ snes.wram->_data[0] = 0x03;
+ snes.wram->_data[1] = 0x20;
+ snes.cpu->SBC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0xDFFE, "The accumulator's value should be 0xDFFE but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should be not set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should not be set.");
}
Test(SBC, overflowEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.a = 0x1;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.p.c = false;
- pair.second.wram->_data[0] = 0x02;
- pair.second.cpu->SBC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0xFE, "The accumulator's value should be 0xFE 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, true, "The negative flags should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flags should be not set.");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.a = 0x1;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.p.c = false;
+ snes.wram->_data[0] = 0x02;
+ snes.cpu->SBC(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0xFE, "The accumulator's value should be 0xFE but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should be not set.");
}
//Test(SBC, decimal)
//{
-// auto pair = Init();
-// pair.second.cpu->_isEmulationMode = true;
-// pair.second.cpu->_registers.a = 0x1;
-// pair.second.cpu->_registers.p.d = true;
-// pair.second.cpu->_registers.p.m = false;
-// pair.second.wram->_data[0] = 0x03;
-// pair.second.wram->_data[1] = 0x20;
-// pair.second.cpu->SBC(0x0);
-// cr_assert_eq(pair.second.cpu->_registers.a, 0x7998, "The accumulator's value should be 0x7998 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 be not set.");
+// Init()
+// snes.cpu->_isEmulationMode = true;
+// snes.cpu->_registers.a = 0x1;
+// snes.cpu->_registers.p.d = true;
+// snes.cpu->_registers.p.m = false;
+// snes.wram->_data[0] = 0x03;
+// snes.wram->_data[1] = 0x20;
+// snes.cpu->SBC(0x0);
+// cr_assert_eq(snes.cpu->_registers.a, 0x7998, "The accumulator's value should be 0x7998 but it was 0x%x.", snes.cpu->_registers.a);
+// cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flags should not be set.");
+// cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flags should not be set.");
+// cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+// cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should be not set.");
//}
diff --git a/tests/CPU/TransferRegisters.cpp b/tests/CPU/TransferRegisters.cpp
index 9dd6069..7ee8e76 100644
--- a/tests/CPU/TransferRegisters.cpp
+++ b/tests/CPU/TransferRegisters.cpp
@@ -11,137 +11,137 @@ using namespace ComSquare;
Test(TAX, 16bitsTo16Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.x = 0xABCD;
- pair.second.cpu->_registers.a = 0xFEDC;
- pair.second.cpu->TAX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0xFEDC, "The flags should be 0xFEDC but it was %x", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.x = 0xABCD;
+ snes.cpu->_registers.a = 0xFEDC;
+ snes.cpu->TAX();
+ cr_assert_eq(snes.cpu->_registers.x, 0xFEDC, "The flags should be 0xFEDC but it was %x", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
}
Test(TAX, 16bitsTo8Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.x = 0xFEDC;
- pair.second.cpu->_registers.a = 0xAB00;
- pair.second.cpu->TAX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0xFE00, "The flags should be 0xFE00 but it was %x", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.x = 0xFEDC;
+ snes.cpu->_registers.a = 0xAB00;
+ snes.cpu->TAX();
+ cr_assert_eq(snes.cpu->_registers.x, 0xFE00, "The flags should be 0xFE00 but it was %x", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.");
}
Test(TAX, 8bitsTo16Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.p.m = true;
- pair.second.cpu->_registers.x = 0xFEDC;
- pair.second.cpu->_registers.a = 0xAB;
- pair.second.cpu->TAX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0x00AB, "The flags should be 0x00AB but it was %x", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->_registers.x = 0xFEDC;
+ snes.cpu->_registers.a = 0xAB;
+ snes.cpu->TAX();
+ cr_assert_eq(snes.cpu->_registers.x, 0x00AB, "The flags should be 0x00AB but it was %x", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
}
Test(TAX, 8bitsTo8Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.m = true;
- pair.second.cpu->_registers.x = 0xFE;
- pair.second.cpu->_registers.a = 0xAB;
- pair.second.cpu->TAX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0xAB, "The flags should be 0xAB but it was %x", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should be not set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->_registers.x = 0xFE;
+ snes.cpu->_registers.a = 0xAB;
+ snes.cpu->TAX();
+ cr_assert_eq(snes.cpu->_registers.x, 0xAB, "The flags should be 0xAB but it was %x", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should be not set.");
}
Test(TAY, 16bitsTo16Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.y = 0xABCD;
- pair.second.cpu->_registers.a = 0xFEDC;
- pair.second.cpu->TAY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0xFEDC, "The y register should be 0xFEDC but it was %x", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.y = 0xABCD;
+ snes.cpu->_registers.a = 0xFEDC;
+ snes.cpu->TAY();
+ cr_assert_eq(snes.cpu->_registers.y, 0xFEDC, "The y register should be 0xFEDC but it was %x", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
}
Test(TAY, 16bitsTo8Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.y = 0xFEDC;
- pair.second.cpu->_registers.a = 0xAB00;
- pair.second.cpu->TAY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0xFE00, "The y register should be 0xFE00 but it was %x", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.y = 0xFEDC;
+ snes.cpu->_registers.a = 0xAB00;
+ snes.cpu->TAY();
+ cr_assert_eq(snes.cpu->_registers.y, 0xFE00, "The y register should be 0xFE00 but it was %x", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.");
}
Test(TAY, 8bitsTo16Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.p.m = true;
- pair.second.cpu->_registers.y = 0xFEDC;
- pair.second.cpu->_registers.a = 0xAB;
- pair.second.cpu->TAY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0x00AB, "The y register should be 0x00AB but it was %x", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->_registers.y = 0xFEDC;
+ snes.cpu->_registers.a = 0xAB;
+ snes.cpu->TAY();
+ cr_assert_eq(snes.cpu->_registers.y, 0x00AB, "The y register should be 0x00AB but it was %x", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
}
Test(TAY, 8bitsTo8Bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.m = true;
- pair.second.cpu->_registers.y = 0xFE;
- pair.second.cpu->_registers.a = 0xAB;
- pair.second.cpu->TAY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0xAB, "The y register should be 0xAB but it was %x", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should be not set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->_registers.y = 0xFE;
+ snes.cpu->_registers.a = 0xAB;
+ snes.cpu->TAY();
+ cr_assert_eq(snes.cpu->_registers.y, 0xAB, "The y register should be 0xAB but it was %x", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should be not set.");
}
Test(TXS, 16bitsIndex)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.x = 0xABCD;
- pair.second.cpu->TXS();
- cr_assert_eq(pair.second.cpu->_registers.s, 0xABCD, "The stack pointer should be 0xABCD but it was %x", pair.second.cpu->_registers.s);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should be not set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.x = 0xABCD;
+ snes.cpu->TXS();
+ cr_assert_eq(snes.cpu->_registers.s, 0xABCD, "The stack pointer should be 0xABCD but it was %x", snes.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should be not set.");
}
Test(TXS, 8bitsIndex)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.x = 0xABCD;
- pair.second.cpu->TXS();
- cr_assert_eq(pair.second.cpu->_registers.s, 0x00CD, "The stack pointer should be 0x00CD but it was %x", pair.second.cpu->_registers.s);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should be not set.");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.x = 0xABCD;
+ snes.cpu->TXS();
+ cr_assert_eq(snes.cpu->_registers.s, 0x00CD, "The stack pointer should be 0x00CD but it was %x", snes.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should be not set.");
}
\ No newline at end of file
diff --git a/tests/CPU/testAddressingMode.cpp b/tests/CPU/testAddressingMode.cpp
index 0c7cf4f..0ae047f 100644
--- a/tests/CPU/testAddressingMode.cpp
+++ b/tests/CPU/testAddressingMode.cpp
@@ -12,290 +12,290 @@ using namespace ComSquare;
Test(AddrModeInit, LegitBus)
{
- auto pair = Init();
- cr_assert_eq(pair.first.get(), pair.second.cpu->_bus.get(), "Warning, the CPU's bus is not the same the SNES's bus. Next tests of the CPU may fail.");
+ Init()
+ cr_assert_eq(snes._bus.get(), snes.cpu->_bus.get(), "Warning, the CPU's bus is not the same the SNES's bus. Next tests of the CPU may fail.");
}
Test(AddrMode, Immediate)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x000015;
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.m = false;
- cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x000017);
+ Init()
+ snes.cpu->_registers.pac = 0x000015;
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.m = false;
+ cr_assert_eq(snes.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
+ cr_assert_eq(snes.cpu->_registers.pac, 0x000017);
}
Test(AddrMode, ImmediateMemoryFlag)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.pac = 0x000015;
- pair.second.cpu->_registers.p.m = false;
- cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x000017);
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.pac = 0x000015;
+ snes.cpu->_registers.p.m = false;
+ cr_assert_eq(snes.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
+ cr_assert_eq(snes.cpu->_registers.pac, 0x000017);
}
Test(AddrMode, ImmediateBankChange)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x00FFFF;
- pair.second.cpu->_registers.p.m = true;
- cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x00FFFF);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x010000);
+ Init()
+ snes.cpu->_registers.pac = 0x00FFFF;
+ snes.cpu->_registers.p.m = true;
+ cr_assert_eq(snes.cpu->_getImmediateAddrForA(), 0x00FFFF);
+ cr_assert_eq(snes.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 %x but was expecting 0x1015.", pair.second.cpu->_getDirectAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cartridge->_data[0] = 0x15;
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cpu->_registers.d = 0x1000;
+ cr_assert_eq(snes.cpu->_getDirectAddr(), 0x1015, "Returned address was %x but was expecting 0x1015.", snes.cpu->_getDirectAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, Absolute)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x1C;
- pair.second.cartridge->_data[1] = 0x90;
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cpu->_registers.dbr = 0x88;
- cr_assert_eq(pair.second.cpu->_getAbsoluteAddr(), 0x88901C, "Returned address was %x but was expecting 0x88901C.", pair.second.cpu->_getAbsoluteAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808002);
+ Init()
+ snes.cartridge->_data[0] = 0x1C;
+ snes.cartridge->_data[1] = 0x90;
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cpu->_registers.dbr = 0x88;
+ cr_assert_eq(snes.cpu->_getAbsoluteAddr(), 0x88901C, "Returned address was %x but was expecting 0x88901C.", snes.cpu->_getAbsoluteAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808002);
}
Test(AddrMode, AbsoluteLong)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x1C;
- pair.second.cartridge->_data[1] = 0x90;
- pair.second.cartridge->_data[2] = 0xFF;
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cpu->_registers.dbr = 0x88;
- cr_assert_eq(pair.second.cpu->_getAbsoluteLongAddr(), 0xFF901C, "Returned address was %x but was expecting 0xFF901C.", pair.second.cpu->_getAbsoluteLongAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808003);
+ Init()
+ snes.cartridge->_data[0] = 0x1C;
+ snes.cartridge->_data[1] = 0x90;
+ snes.cartridge->_data[2] = 0xFF;
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cpu->_registers.dbr = 0x88;
+ cr_assert_eq(snes.cpu->_getAbsoluteLongAddr(), 0xFF901C, "Returned address was %x but was expecting 0xFF901C.", snes.cpu->_getAbsoluteLongAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808003);
}
Test(AddrMode, DirectIndirectIndexed)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.wram->_data[0x1010] = 0x30;
- pair.second.wram->_data[0x1011] = 0x40;
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cpu->_registers.dbr = 0x80;
- pair.second.cpu->_registers.y = 0x0001;
- pair.second.cpu->_registers.d = 0x1000;
- cr_assert_eq(pair.second.cpu->_getDirectIndirectIndexedYAddr(), 0x804031, "Returned address was %x but was expecting 0x804031.",
- pair.second.cpu->_getDirectIndirectIndexedYAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cartridge->_data[0] = 0x10;
+ snes.wram->_data[0x1010] = 0x30;
+ snes.wram->_data[0x1011] = 0x40;
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cpu->_registers.dbr = 0x80;
+ snes.cpu->_registers.y = 0x0001;
+ snes.cpu->_registers.d = 0x1000;
+ cr_assert_eq(snes.cpu->_getDirectIndirectIndexedYAddr(), 0x804031, "Returned address was %x but was expecting 0x804031.",
+ snes.cpu->_getDirectIndirectIndexedYAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, DirectIndirectIndexedLong)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cpu->_registers.d = 0x1000;
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.wram->_data[0x1010] = 0x30;
- pair.second.wram->_data[0x1011] = 0x40;
- pair.second.wram->_data[0x1012] = 0x23;
- cr_assert_eq(pair.second.cpu->_getDirectIndirectIndexedYLongAddr(), 0x234030, "Returned address was %x but was expecting 0x234030.",
- pair.second.cpu->_getDirectIndirectIndexedYLongAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cpu->_registers.d = 0x1000;
+ snes.cartridge->_data[0] = 0x10;
+ snes.wram->_data[0x1010] = 0x30;
+ snes.wram->_data[0x1011] = 0x40;
+ snes.wram->_data[0x1012] = 0x23;
+ cr_assert_eq(snes.cpu->_getDirectIndirectIndexedYLongAddr(), 0x234030, "Returned address was %x but was expecting 0x234030.",
+ snes.cpu->_getDirectIndirectIndexedYLongAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, DirectIndexedIndirect)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cpu->_registers.d = 0x1000;
- pair.second.cpu->_registers.x = 0x0002;
- pair.second.wram->_data[0x1012] = 0x30;
- pair.second.wram->_data[0x1013] = 0x40;
- pair.second.cpu->_registers.dbr = 0x80;
- pair.second.cpu->_registers.pac = 0x808000;
- cr_assert_eq(pair.second.cpu->_getDirectIndirectIndexedXAddr(), 0x804030, "Returned address was %x but was expecting 0x804030.",
- pair.second.cpu->_getDirectIndirectIndexedXAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cartridge->_data[0] = 0x10;
+ snes.cpu->_registers.d = 0x1000;
+ snes.cpu->_registers.x = 0x0002;
+ snes.wram->_data[0x1012] = 0x30;
+ snes.wram->_data[0x1013] = 0x40;
+ snes.cpu->_registers.dbr = 0x80;
+ snes.cpu->_registers.pac = 0x808000;
+ cr_assert_eq(snes.cpu->_getDirectIndirectIndexedXAddr(), 0x804030, "Returned address was %x but was expecting 0x804030.",
+ snes.cpu->_getDirectIndirectIndexedXAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, DirectIndexedByX)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cpu->_registers.d = 0x1000;
- pair.second.cpu->_registers.x = 0x0002;
- pair.second.cpu->_registers.pac = 0x808000;
- cr_assert_eq(pair.second.cpu->_getDirectIndexedByXAddr(), 0x1012, "Returned address was %x but was expecting 0x1012.", pair.second.cpu->_getDirectIndexedByXAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cartridge->_data[0] = 0x10;
+ snes.cpu->_registers.d = 0x1000;
+ snes.cpu->_registers.x = 0x0002;
+ snes.cpu->_registers.pac = 0x808000;
+ cr_assert_eq(snes.cpu->_getDirectIndexedByXAddr(), 0x1012, "Returned address was %x but was expecting 0x1012.", snes.cpu->_getDirectIndexedByXAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, DirectIndexedByY)
{
- auto pair = Init();
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cpu->_registers.d = 0x1000;
- pair.second.cpu->_registers.y = 0x0002;
- pair.second.cpu->_registers.pac = 0x808000;
- cr_assert_eq(pair.second.cpu->_getDirectIndexedByYAddr(), 0x1012, "Returned address was %x but was expecting 0x1012.", pair.second.cpu->_getDirectIndexedByYAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ Init()
+ snes.cartridge->_data[0] = 0x10;
+ snes.cpu->_registers.d = 0x1000;
+ snes.cpu->_registers.y = 0x0002;
+ snes.cpu->_registers.pac = 0x808000;
+ cr_assert_eq(snes.cpu->_getDirectIndexedByYAddr(), 0x1012, "Returned address was %x but was expecting 0x1012.", snes.cpu->_getDirectIndexedByYAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, AbsoluteIndexByX)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cartridge->_data[1] = 0xAC;
- pair.second.cpu->_registers.dbr = 0xEF;
- pair.second.cpu->_registers.x = 0x0005;
- cr_assert_eq(pair.second.cpu->_getAbsoluteIndexedByXAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.", pair.second.cpu->_getAbsoluteIndexedByXAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808002);
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x10;
+ snes.cartridge->_data[1] = 0xAC;
+ snes.cpu->_registers.dbr = 0xEF;
+ snes.cpu->_registers.x = 0x0005;
+ cr_assert_eq(snes.cpu->_getAbsoluteIndexedByXAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.", snes.cpu->_getAbsoluteIndexedByXAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808002);
}
Test(AddrMode, AbsoluteIndexByY)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cartridge->_data[1] = 0xAC;
- pair.second.cpu->_registers.dbr = 0xEF;
- pair.second.cpu->_registers.y = 0x0005;
- cr_assert_eq(pair.second.cpu->_getAbsoluteIndexedByYAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.", pair.second.cpu->_getAbsoluteIndexedByYAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808002);
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x10;
+ snes.cartridge->_data[1] = 0xAC;
+ snes.cpu->_registers.dbr = 0xEF;
+ snes.cpu->_registers.y = 0x0005;
+ cr_assert_eq(snes.cpu->_getAbsoluteIndexedByYAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.", snes.cpu->_getAbsoluteIndexedByYAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808002);
}
Test(AddrMode, AbsoluteLongIndexByX)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x10;
- pair.second.cartridge->_data[1] = 0xAC;
- pair.second.cartridge->_data[2] = 0xEF;
- pair.second.cpu->_registers.x = 0x0005;
- cr_assert_eq(pair.second.cpu->_getAbsoluteIndexedByXLongAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.",
- pair.second.cpu->_getAbsoluteIndexedByXLongAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808003);
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x10;
+ snes.cartridge->_data[1] = 0xAC;
+ snes.cartridge->_data[2] = 0xEF;
+ snes.cpu->_registers.x = 0x0005;
+ cr_assert_eq(snes.cpu->_getAbsoluteIndexedByXLongAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.",
+ snes.cpu->_getAbsoluteIndexedByXLongAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808003);
}
Test(AddrMode, ProgramCounterRelativePositive)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808010;
- pair.second.cartridge->_data[0x10] = 0x15;
- cr_assert_eq(pair.second.cpu->_getProgramCounterRelativeAddr(), 0x808025, "Returned address was %x but was expecting 0x808025.", pair.second.cpu->_getProgramCounterRelativeAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808011);
+ Init()
+ snes.cpu->_registers.pac = 0x808010;
+ snes.cartridge->_data[0x10] = 0x15;
+ cr_assert_eq(snes.cpu->_getProgramCounterRelativeAddr(), 0x808025, "Returned address was %x but was expecting 0x808025.", snes.cpu->_getProgramCounterRelativeAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808011);
}
Test(AddrMode, ProgramCounterRelativeNegative)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808010;
- pair.second.cartridge->_data[0x10] = -0x15;
- cr_assert_eq(pair.second.cpu->_getProgramCounterRelativeAddr(), 0x807FFB, "Returned address was %x but was expecting 0x807FFB.", pair.second.cpu->_getProgramCounterRelativeAddr());
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808011);
+ Init()
+ snes.cpu->_registers.pac = 0x808010;
+ snes.cartridge->_data[0x10] = -0x15;
+ cr_assert_eq(snes.cpu->_getProgramCounterRelativeAddr(), 0x807FFB, "Returned address was %x but was expecting 0x807FFB.", snes.cpu->_getProgramCounterRelativeAddr());
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808011);
}
Test(AddrMode, ProgramCounterRelativeLongPositive)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808010;
- pair.second.cartridge->_data[0x10] = 0x15;
- pair.second.cartridge->_data[0x11] = 0x10;
- auto addr = pair.second.cpu->_getProgramCounterRelativeLongAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808010;
+ snes.cartridge->_data[0x10] = 0x15;
+ snes.cartridge->_data[0x11] = 0x10;
+ auto addr = snes.cpu->_getProgramCounterRelativeLongAddr();
cr_assert_eq(addr, 0x809025, "Returned address was %x but was expecting 0x809025.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808012);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808012);
}
Test(AddrMode, ProgramCounterRelativeLongNegative)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808010;
- pair.second.cartridge->_data[0x10] = 0x10;
- pair.second.cartridge->_data[0x11] = -0x15;
- auto addr = pair.second.cpu->_getProgramCounterRelativeLongAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808010;
+ snes.cartridge->_data[0x10] = 0x10;
+ snes.cartridge->_data[0x11] = -0x15;
+ auto addr = snes.cpu->_getProgramCounterRelativeLongAddr();
cr_assert_eq(addr, 0x806B00, "Returned address was %x but was expecting 0x806B00.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808012);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808012);
}
Test(AddrMode, AbsoluteIndirect)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0xAB;
- pair.second.cartridge->_data[1] = 0x01;
- pair.second.wram->_data[0x01AB] = 0xEF;
- pair.second.wram->_data[0x01AC] = 0x01;
- auto addr = pair.second.cpu->_getAbsoluteIndirectAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0xAB;
+ snes.cartridge->_data[1] = 0x01;
+ snes.wram->_data[0x01AB] = 0xEF;
+ snes.wram->_data[0x01AC] = 0x01;
+ auto addr = snes.cpu->_getAbsoluteIndirectAddr();
cr_assert_eq(addr, 0x01EF, "Returned address was %x but was expecting 0x01EF.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808002);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808002);
}
Test(AddrMode, AbsoluteIndexedIndirect)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0xAB;
- pair.second.cartridge->_data[1] = 0x01;
- pair.second.cpu->_registers.x = 2;
- pair.second.wram->_data[0x01AD] = 0xEF;
- pair.second.wram->_data[0x01AE] = 0x01;
- auto addr = pair.second.cpu->_getAbsoluteIndirectIndexedByXAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0xAB;
+ snes.cartridge->_data[1] = 0x01;
+ snes.cpu->_registers.x = 2;
+ snes.wram->_data[0x01AD] = 0xEF;
+ snes.wram->_data[0x01AE] = 0x01;
+ auto addr = snes.cpu->_getAbsoluteIndirectIndexedByXAddr();
cr_assert_eq(addr, 0x01EF, "Returned address was %x but was expecting 0x01EF.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808002);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808002);
}
Test(AddrMode, DirectIndirect)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x01;
- pair.second.cpu->_registers.d = 0x1010;
- pair.second.wram->_data[0x1011] = 0xEF;
- pair.second.wram->_data[0x1012] = 0x01;
- pair.second.cpu->_registers.dbr = 0x88;
- auto addr = pair.second.cpu->_getDirectIndirectAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x01;
+ snes.cpu->_registers.d = 0x1010;
+ snes.wram->_data[0x1011] = 0xEF;
+ snes.wram->_data[0x1012] = 0x01;
+ snes.cpu->_registers.dbr = 0x88;
+ auto addr = snes.cpu->_getDirectIndirectAddr();
cr_assert_eq(addr, 0x8801EF, "Returned address was %x but was expecting 0x8801EF.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, DirectIndirectLong)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x06;
- pair.second.cpu->_registers.d = 0x1010;
- pair.second.wram->_data[0x1016] = 0xEF;
- pair.second.wram->_data[0x1017] = 0x01;
- pair.second.wram->_data[0x1018] = 0x88;
- auto addr = pair.second.cpu->_getDirectIndirectLongAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x06;
+ snes.cpu->_registers.d = 0x1010;
+ snes.wram->_data[0x1016] = 0xEF;
+ snes.wram->_data[0x1017] = 0x01;
+ snes.wram->_data[0x1018] = 0x88;
+ auto addr = snes.cpu->_getDirectIndirectLongAddr();
cr_assert_eq(addr, 0x8801EF, "Returned address was %x but was expecting 0x8801EF.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, StackRelative)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x06;
- pair.second.cpu->_registers.s = 0x1010;
- auto addr = pair.second.cpu->_getStackRelativeAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x06;
+ snes.cpu->_registers.s = 0x1010;
+ auto addr = snes.cpu->_getStackRelativeAddr();
cr_assert_eq(addr, 0x1016, "Returned address was %x but was expecting 0x1016.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, StackRelativeIndirectIndexed)
{
- auto pair = Init();
- pair.second.cpu->_registers.pac = 0x808000;
- pair.second.cartridge->_data[0] = 0x06;
- pair.second.cpu->_registers.s = 0x1010;
- pair.second.cpu->_registers.y = 0x5;
- pair.second.cpu->_registers.dbr = 0x88;
- auto addr = pair.second.cpu->_getStackRelativeIndirectIndexedYAddr();
+ Init()
+ snes.cpu->_registers.pac = 0x808000;
+ snes.cartridge->_data[0] = 0x06;
+ snes.cpu->_registers.s = 0x1010;
+ snes.cpu->_registers.y = 0x5;
+ snes.cpu->_registers.dbr = 0x88;
+ auto addr = snes.cpu->_getStackRelativeIndirectIndexedYAddr();
cr_assert_eq(addr, 0x88101B, "Returned address was %x but was expecting 0x88101B.", addr);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x808001);
}
\ No newline at end of file
diff --git a/tests/CPU/testBits.cpp b/tests/CPU/testBits.cpp
index 2902dfd..04b3fe6 100644
--- a/tests/CPU/testBits.cpp
+++ b/tests/CPU/testBits.cpp
@@ -11,40 +11,40 @@ using namespace ComSquare;
Test(AND, emulation)
{
- auto pair = Init();
- pair.second.wram->_data[0] = 0x00;
- pair.second.cpu->_registers.a = 0xFF;
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->AND(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0x00, "The flags should be 0x00 but it was %x", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ Init()
+ snes.wram->_data[0] = 0x00;
+ snes.cpu->_registers.a = 0xFF;
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->AND(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0x00, "The flags should be 0x00 but it was %x", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
}
Test(AND, nativeNegative)
{
- auto pair = Init();
- pair.second.wram->_data[0] = 0xF0;
- pair.second.wram->_data[1] = 0xF0;
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.a = 0xFF00;
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->AND(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0xF000, "The flags should be 0xF000 but it was %x", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.");
+ Init()
+ snes.wram->_data[0] = 0xF0;
+ snes.wram->_data[1] = 0xF0;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.a = 0xFF00;
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->AND(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0xF000, "The flags should be 0xF000 but it was %x", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
}
Test(AND, emulationTest)
{
- auto pair = Init();
- pair.second.wram->_data[0] = 0b00110011;
- pair.second.cpu->_registers.a = 0b00110111;
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->AND(0x0);
- cr_assert_eq(pair.second.cpu->_registers.a, 0b00110011, "The flags should be 0b00110011 but it was %x", pair.second.cpu->_registers.a);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.");
+ Init()
+ snes.wram->_data[0] = 0b00110011;
+ snes.cpu->_registers.a = 0b00110111;
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->AND(0x0);
+ cr_assert_eq(snes.cpu->_registers.a, 0b00110011, "The flags should be 0b00110011 but it was %x", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
}
diff --git a/tests/CPU/testInternal.cpp b/tests/CPU/testInternal.cpp
index 888caf4..7caa8ea 100644
--- a/tests/CPU/testInternal.cpp
+++ b/tests/CPU/testInternal.cpp
@@ -14,889 +14,889 @@ using namespace ComSquare;
Test(SEP, setall)
{
- auto pair = Init();
- pair.second.cpu->SEP(0xFF);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->SEP(0xFF);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0xFF, "The flag should be 0xFF but it was %x", data);
}
Test(SEP, setsome)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0b01000000;
- pair.second.cpu->SEP(0b10110101);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->_registers.p.flags = 0b01000000;
+ snes.cpu->SEP(0b10110101);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0b11110101, "The flag should be 245 but it was %i", data);
}
Test(REP, resetall)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->REP(0xFF);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->REP(0xFF);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0x00, "The flag should be 0x00 but it was %x", data);
}
Test(REP, resetsome)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.flags = 0b01000000;
- pair.second.cpu->REP(0b01000000);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.flags = 0b01000000;
+ snes.cpu->REP(0b01000000);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0x0, "The flag should be 0 but it was %x", data);
}
Test(REP, resetallEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->REP(0xFF);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->REP(0xFF);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0b00110000, "The flag should be 0b00110000 but it was %x", data);
}
Test(REP, resetsomeEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0b01000101;
- pair.second.cpu->REP(0b01000001);
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0b01000101;
+ snes.cpu->REP(0b01000001);
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0b00110100, "The flag should be 0b00110100 but it was %x", data);
}
Test(JSR, jump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0xABCD;
- pair.second.cpu->_registers.s = 0x0123;
- pair.second.cpu->JSR(0xABFF);
- auto pc = pair.second.cpu->_registers.pc;
+ Init()
+ snes.cpu->_registers.pc = 0xABCD;
+ snes.cpu->_registers.s = 0x0123;
+ snes.cpu->JSR(0xABFF);
+ auto pc = snes.cpu->_registers.pc;
cr_assert_eq(pc, 0xABFF, "The PC should be 0xABFF but it was %x", pc);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0121, "The stack pointer should be 0x0121 but it was %x", pair.second.cpu->_registers.s);
- auto pushed = pair.second.cpu->_pop16();
+ cr_assert_eq(snes.cpu->_registers.s, 0x0121, "The stack pointer should be 0x0121 but it was %x", snes.cpu->_registers.s);
+ auto pushed = snes.cpu->_pop16();
cr_assert_eq(pushed, 0xABCC, "The value pushed to the stack should be 0xABCC but it was %x", pushed);
}
Test(JSL, jump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pbr = 0xFF;
- pair.second.cpu->_registers.pc = 0xABCD;
- pair.second.cpu->_registers.s = 0x0123;
- pair.second.cpu->JSL(0xCDABFF);
- auto pac = pair.second.cpu->_registers.pac;
+ Init()
+ snes.cpu->_registers.pbr = 0xFF;
+ snes.cpu->_registers.pc = 0xABCD;
+ snes.cpu->_registers.s = 0x0123;
+ snes.cpu->JSL(0xCDABFF);
+ auto pac = snes.cpu->_registers.pac;
cr_assert_eq(pac, 0xCDABFF, "The PC should be 0xCDABFF but it was %x", pac);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0120, "The stack pointer should be 0x0120 but it was %x", pair.second.cpu->_registers.s);
- auto pushed = pair.second.cpu->_pop16() + (pair.second.cpu->_pop() << 16u);
+ cr_assert_eq(snes.cpu->_registers.s, 0x0120, "The stack pointer should be 0x0120 but it was %x", snes.cpu->_registers.s);
+ auto pushed = snes.cpu->_pop16() + (snes.cpu->_pop() << 16u);
cr_assert_eq(pushed, 0xFFABCC, "The value pushed to the stack should be 0xFFABCD but it was %x", pushed);
}
Test(PHA, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.a = 0xABCD;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHA();
- cr_assert_eq(pair.second.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", pair.second.wram->_data[1]);
- cr_assert_eq(pair.second.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.a = 0xABCD;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHA();
+ cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]);
+ cr_assert_eq(snes.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s);
}
Test(PHB, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.dbr = 0xFF;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHB();
- cr_assert_eq(pair.second.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.dbr = 0xFF;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHB();
+ cr_assert_eq(snes.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PHD, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.d = 0xABCD;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHD();
- cr_assert_eq(pair.second.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", pair.second.wram->_data[1]);
- cr_assert_eq(pair.second.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.d = 0xABCD;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHD();
+ cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]);
+ cr_assert_eq(snes.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s);
}
Test(PHK, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.pbr = 0xFF;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHK();
- cr_assert_eq(pair.second.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.pbr = 0xFF;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHK();
+ cr_assert_eq(snes.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PHP, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0xFF;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHP();
- cr_assert_eq(pair.second.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.p.flags = 0xFF;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHP();
+ cr_assert_eq(snes.wram->_data[2], 0xFF, "The first value pushed to the stack should be 0xFF but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PHX, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.x = 0xABCD;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHX();
- cr_assert_eq(pair.second.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", pair.second.wram->_data[1]);
- cr_assert_eq(pair.second.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.x = 0xABCD;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHX();
+ cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]);
+ cr_assert_eq(snes.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s);
}
Test(PHY, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.y = 0xABCD;
- pair.second.cpu->_registers.s = 0x02;
- pair.second.cpu->PHY();
- cr_assert_eq(pair.second.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", pair.second.wram->_data[1]);
- cr_assert_eq(pair.second.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", pair.second.wram->_data[2]);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", pair.second.cpu->_registers.s);
+ Init()
+ snes.cpu->_registers.y = 0xABCD;
+ snes.cpu->_registers.s = 0x02;
+ snes.cpu->PHY();
+ cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]);
+ cr_assert_eq(snes.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", snes.wram->_data[2]);
+ cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s);
}
Test(PLA, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0xCD;
- pair.second.wram->_data[2] = 0x7B;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLA();
- auto data = pair.second.cpu->_registers.a;
+ Init()
+ snes.wram->_data[1] = 0xCD;
+ snes.wram->_data[2] = 0x7B;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLA();
+ auto data = snes.cpu->_registers.a;
cr_assert_eq(data, 0x7BCD, "The accumulator should be 0x7BCD but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLA, zero)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLA();
- auto data = pair.second.cpu->_registers.a;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLA();
+ auto data = snes.cpu->_registers.a;
cr_assert_eq(data, 0x0000, "The accumulator should be 0x0000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLA, negative)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0xA0;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLA();
- auto data = pair.second.cpu->_registers.a;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0xA0;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLA();
+ auto data = snes.cpu->_registers.a;
cr_assert_eq(data, 0xA000, "The accumulator should be 0xA000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag not should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag not should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLX, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0xCD;
- pair.second.wram->_data[2] = 0x7B;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLX();
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.wram->_data[1] = 0xCD;
+ snes.wram->_data[2] = 0x7B;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLX();
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x7BCD, "The X register should be 0x7BCD but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLX, zero)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLX();
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLX();
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x0000, "The x register should be 0x0000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLX, negative)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0xA0;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLX();
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0xA0;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLX();
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0xA000, "The x register should be 0xA000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag not should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag not should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLY, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0xCD;
- pair.second.wram->_data[2] = 0x7B;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLY();
- auto data = pair.second.cpu->_registers.y;
+ Init()
+ snes.wram->_data[1] = 0xCD;
+ snes.wram->_data[2] = 0x7B;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLY();
+ auto data = snes.cpu->_registers.y;
cr_assert_eq(data, 0x7BCD, "The Y register should be 0x7BCD but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLY, zero)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLY();
- auto data = pair.second.cpu->_registers.y;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLY();
+ auto data = snes.cpu->_registers.y;
cr_assert_eq(data, 0x0000, "The y register should be 0x0000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLY, negative)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0xA0;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLY();
- auto data = pair.second.cpu->_registers.y;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0xA0;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLY();
+ auto data = snes.cpu->_registers.y;
cr_assert_eq(data, 0xA000, "The y register should be 0xA000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag not should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag not should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLD, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0xCD;
- pair.second.wram->_data[2] = 0x7B;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLD();
- auto data = pair.second.cpu->_registers.d;
+ Init()
+ snes.wram->_data[1] = 0xCD;
+ snes.wram->_data[2] = 0x7B;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLD();
+ auto data = snes.cpu->_registers.d;
cr_assert_eq(data, 0x7BCD, "The D register should be 0x7BCD but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLD, zero)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLD();
- auto data = pair.second.cpu->_registers.d;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLD();
+ auto data = snes.cpu->_registers.d;
cr_assert_eq(data, 0x0000, "The d register should be 0x0000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLD, negative)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.wram->_data[2] = 0xA0;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLD();
- auto data = pair.second.cpu->_registers.d;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.wram->_data[2] = 0xA0;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLD();
+ auto data = snes.cpu->_registers.d;
cr_assert_eq(data, 0xA000, "The D register should be 0xA000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag not should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag not should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x2, "The Stack pointer should be equal to 0x2 but it was %x", snes.cpu->_registers.s);
}
Test(PLB, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x7D;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLB();
- auto data = pair.second.cpu->_registers.dbr;
+ Init()
+ snes.wram->_data[1] = 0x7D;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLB();
+ auto data = snes.cpu->_registers.dbr;
cr_assert_eq(data, 0x7D, "The DBR should be 0x7D but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PLB, zero)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLB();
- auto data = pair.second.cpu->_registers.dbr;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLB();
+ auto data = snes.cpu->_registers.dbr;
cr_assert_eq(data, 0x00, "The dbr should be 0x00 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PLB, negative)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0xA0;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->PLB();
- auto data = pair.second.cpu->_registers.dbr;
+ Init()
+ snes.wram->_data[1] = 0xA0;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->PLB();
+ auto data = snes.cpu->_registers.dbr;
cr_assert_eq(data, 0xA0, "The D register should be 0xA0 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag not should be set.", pair.second.cpu->_registers.p.z);
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set.", pair.second.cpu->_registers.p.n);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag not should be set.", snes.cpu->_registers.p.z);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.", snes.cpu->_registers.p.n);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PLP, basic)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x7D;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->PLP();
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.wram->_data[1] = 0x7D;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->PLP();
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0x7D, "The flags should be 0x7D but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(PLP, emulation)
{
- auto pair = Init();
- pair.second.wram->_data[1] = 0x00;
- pair.second.cpu->_registers.s = 0x00;
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->PLP();
- auto data = pair.second.cpu->_registers.p.flags;
+ Init()
+ snes.wram->_data[1] = 0x00;
+ snes.cpu->_registers.s = 0x00;
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->PLP();
+ auto data = snes.cpu->_registers.p.flags;
cr_assert_eq(data, 0b00110000, "The flags should be 0b00110000 but it was %x", data);
- cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
+ cr_assert_eq(snes.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", snes.cpu->_registers.s);
}
Test(CLC, clear)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0xFF;
- pair.second.cpu->CLC();
- cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0xFF;
+ snes.cpu->CLC();
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flag should not be set");
}
Test(CLI, clear)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0xFF;
- pair.second.cpu->CLI();
- cr_assert_eq(pair.second.cpu->_registers.p.i, false, "The interrupt flag should not be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0xFF;
+ snes.cpu->CLI();
+ cr_assert_eq(snes.cpu->_registers.p.i, false, "The interrupt flag should not be set");
}
Test(CLD, clear)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0xFF;
- pair.second.cpu->CLD();
- cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0xFF;
+ snes.cpu->CLD();
+ cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set");
}
Test(CLV, clear)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0xFF;
- pair.second.cpu->CLV();
- cr_assert_eq(pair.second.cpu->_registers.p.v, false, "The overflow flag should not be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0xFF;
+ snes.cpu->CLV();
+ cr_assert_eq(snes.cpu->_registers.p.v, false, "The overflow flag should not be set");
}
Test(SEC, set)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0x00;
- pair.second.cpu->SEC();
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flag should be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0x00;
+ snes.cpu->SEC();
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flag should be set");
}
Test(SEI, set)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0x00;
- pair.second.cpu->SEI();
- cr_assert_eq(pair.second.cpu->_registers.p.i, true, "The interrupt disabled flag should be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0x00;
+ snes.cpu->SEI();
+ cr_assert_eq(snes.cpu->_registers.p.i, true, "The interrupt disabled flag should be set");
}
Test(SED, set)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0x00;
- pair.second.cpu->SED();
- cr_assert_eq(pair.second.cpu->_registers.p.d, true, "The decimal flag should be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0x00;
+ snes.cpu->SED();
+ cr_assert_eq(snes.cpu->_registers.p.d, true, "The decimal flag should be set");
}
Test(XCE, enableEmulation)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.c = true;
- pair.second.cpu->_registers.xh = 0xFF;
- pair.second.cpu->_registers.yh = 0xFF;
- pair.second.cpu->XCE();
- cr_assert_eq(pair.second.cpu->_isEmulationMode, true, "The e flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.m, false, "The memory width flag should be untouched (unset)");
- cr_assert_eq(pair.second.cpu->_registers.p.x_b, false, "The index width flag should be untouched (unset)");
- cr_assert_eq(pair.second.cpu->_registers.xh, 0xFF, "The high byte of the x index flag should be untouched (0xFF)");
- cr_assert_eq(pair.second.cpu->_registers.yh, 0xFF, "The high byte of the y index flag should be untouched (0xFF)");
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.c = true;
+ snes.cpu->_registers.xh = 0xFF;
+ snes.cpu->_registers.yh = 0xFF;
+ snes.cpu->XCE();
+ cr_assert_eq(snes.cpu->_isEmulationMode, true, "The e flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.m, false, "The memory width flag should be untouched (unset)");
+ cr_assert_eq(snes.cpu->_registers.p.x_b, false, "The index width flag should be untouched (unset)");
+ cr_assert_eq(snes.cpu->_registers.xh, 0xFF, "The high byte of the x index flag should be untouched (0xFF)");
+ cr_assert_eq(snes.cpu->_registers.yh, 0xFF, "The high byte of the y index flag should be untouched (0xFF)");
}
Test(XCE, enableNative)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.xh = 0xFF;
- pair.second.cpu->_registers.yh = 0xFF;
- pair.second.cpu->XCE();
- cr_assert_eq(pair.second.cpu->_isEmulationMode, false, "The e flag should be not set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.m, true, "The memory width flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.x_b, true, "The index width flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.xh, 0, "The high byte of the x index flag should be set to 0");
- cr_assert_eq(pair.second.cpu->_registers.yh, 0, "The high byte of the y index flag should be set to 0");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.xh = 0xFF;
+ snes.cpu->_registers.yh = 0xFF;
+ snes.cpu->XCE();
+ cr_assert_eq(snes.cpu->_isEmulationMode, false, "The e flag should be not set");
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.m, true, "The memory width flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.x_b, true, "The index width flag should be set");
+ cr_assert_eq(snes.cpu->_registers.xh, 0, "The high byte of the x index flag should be set to 0");
+ cr_assert_eq(snes.cpu->_registers.yh, 0, "The high byte of the y index flag should be set to 0");
}
Test(INX, basic)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.x = 0xFF;
- pair.second.cpu->INX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0x0100, "The x register should be equal to 0x0100 but it was 0x%x.", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.x = 0xFF;
+ snes.cpu->INX();
+ cr_assert_eq(snes.cpu->_registers.x, 0x0100, "The x register should be equal to 0x0100 but it was 0x%x.", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
}
Test(INX, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.x = 0xFF;
- pair.second.cpu->INX();
- cr_assert_eq(pair.second.cpu->_registers.x, 0x00, "The x register should be equal to 0x00 but it was 0x%x.", pair.second.cpu->_registers.x);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.x = 0xFF;
+ snes.cpu->INX();
+ cr_assert_eq(snes.cpu->_registers.x, 0x00, "The x register should be equal to 0x00 but it was 0x%x.", snes.cpu->_registers.x);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
}
Test(INY, basic)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.y = 0xFF;
- pair.second.cpu->INY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0x0100, "The y register should be equal to 0x0100 but it was 0x%x.", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.y = 0xFF;
+ snes.cpu->INY();
+ cr_assert_eq(snes.cpu->_registers.y, 0x0100, "The y register should be equal to 0x0100 but it was 0x%x.", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
}
Test(INY, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.y = 0xFF;
- pair.second.cpu->INY();
- cr_assert_eq(pair.second.cpu->_registers.y, 0x00, "The y register should be equal to 0x00 but it was 0x%x.", pair.second.cpu->_registers.y);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.y = 0xFF;
+ snes.cpu->INY();
+ cr_assert_eq(snes.cpu->_registers.y, 0x00, "The y register should be equal to 0x00 but it was 0x%x.", snes.cpu->_registers.y);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
}
Test(CPX, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.x = 0xFF;
- pair.second.wram->_data[0] = 0xFF;
- pair.second.cpu->CPX(0x0);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flag should be set");
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.x = 0xFF;
+ snes.wram->_data[0] = 0xFF;
+ snes.cpu->CPX(0x0);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flag should be set");
}
Test(CPX, negative)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.x = 0x80;
- pair.second.wram->_data[0] = 0xFF;
- pair.second.cpu->CPX(0x0);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.x = 0x80;
+ snes.wram->_data[0] = 0xFF;
+ snes.cpu->CPX(0x0);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flag should not be set");
}
Test(CPX, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.x = 0x8888;
- pair.second.wram->_data[0] = 0x88;
- pair.second.wram->_data[1] = 0x98;
- pair.second.cpu->CPX(0x0);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
+ Init()
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.x = 0x8888;
+ snes.wram->_data[0] = 0x88;
+ snes.wram->_data[1] = 0x98;
+ snes.cpu->CPX(0x0);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flag should not be set");
}
Test(CPY, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.y = 0xFF;
- pair.second.wram->_data[0] = 0xFF;
- pair.second.cpu->CPY(0x0);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, true, "The carry flag should be set");
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.y = 0xFF;
+ snes.wram->_data[0] = 0xFF;
+ snes.cpu->CPY(0x0);
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, true, "The carry flag should be set");
}
Test(CPY, negative)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.p.flags = 0;
- pair.second.cpu->_registers.y = 0x80;
- pair.second.wram->_data[0] = 0xFF;
- pair.second.cpu->CPY(0x0);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag should not be set");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag should be set");
- cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.p.flags = 0;
+ snes.cpu->_registers.y = 0x80;
+ snes.wram->_data[0] = 0xFF;
+ snes.cpu->CPY(0x0);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set");
+ cr_assert_eq(snes.cpu->_registers.p.c, false, "The carry flag should not be set");
}
Test(BCC, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BCC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BCC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BCC, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BCC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BCC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BCC, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BCC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BCC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BCS, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BCS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BCS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BCS, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BCS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BCS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BCS, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.c = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BCS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.c = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BCS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BEQ, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BEQ(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BEQ(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BEQ, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BEQ(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BEQ(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BEQ, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BEQ(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BEQ(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BNE, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BNE(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BNE(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BNE, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BNE(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BNE(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BNE, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.z = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BNE(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.z = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BNE(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BMI, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BMI(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BMI(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BMI, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BMI(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BMI(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BMI, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BMI(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BMI(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BPL, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BPL(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BPL(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BPL, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BPL(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BPL(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BPL, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.n = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BPL(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.n = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BPL(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BRA, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BRA(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BRA(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BRA, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BRA(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BRA(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BRL, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x8080;
- pair.second.wram->_data[0] = 0x00;
- pair.second.wram->_data[1] = 0x10;
- pair.second.cpu->BRL(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x9080, "The program counter should be equal to 0x9080 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.pc = 0x8080;
+ snes.wram->_data[0] = 0x00;
+ snes.wram->_data[1] = 0x10;
+ snes.cpu->BRL(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x9080, "The program counter should be equal to 0x9080 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BRL, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x8080;
- pair.second.wram->_data[0] = 0x00;
- pair.second.wram->_data[1] = 0xF0;
- pair.second.cpu->BRL(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x7080, "The program counter should be equal to 0x7080 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.pc = 0x8080;
+ snes.wram->_data[0] = 0x00;
+ snes.wram->_data[1] = 0xF0;
+ snes.cpu->BRL(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x7080, "The program counter should be equal to 0x7080 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVC, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BVC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BVC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVC, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BVC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BVC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVC, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BVC(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BVC(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVS, basic)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x50;
- pair.second.cpu->BVS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x50;
+ snes.cpu->BVS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0xD0, "The program counter should be equal to 0xD0 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVS, negativeJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = true;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0xF0;
- pair.second.cpu->BVS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = true;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0xF0;
+ snes.cpu->BVS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x70, "The program counter should be equal to 0x70 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(BVS, noJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.v = false;
- pair.second.cpu->_registers.pc = 0x80;
- pair.second.wram->_data[0] = 0x90;
- pair.second.cpu->BVS(0x0);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.p.v = false;
+ snes.cpu->_registers.pc = 0x80;
+ snes.wram->_data[0] = 0x90;
+ snes.cpu->BVS(0x0);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(JMP, simpleJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x8000;
- pair.second.cpu->JMP(0x1000);
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x1000, "The program counter should be equal to 0x9000 but it was 0x%x.", pair.second.cpu->_registers.pc);
+ Init()
+ snes.cpu->_registers.pc = 0x8000;
+ snes.cpu->JMP(0x1000);
+ cr_assert_eq(snes.cpu->_registers.pc, 0x1000, "The program counter should be equal to 0x9000 but it was 0x%x.", snes.cpu->_registers.pc);
}
Test(JML, simpleJump)
{
- auto pair = Init();
- pair.second.cpu->_registers.pc = 0x8000;
- pair.second.cpu->JML(0x10AB00);
- cr_assert_eq(pair.second.cpu->_registers.pac, 0x10AB00, "The program counter should be equal to 0x10AB00 but it was 0x%x.", pair.second.cpu->_registers.pac);
+ Init()
+ snes.cpu->_registers.pc = 0x8000;
+ snes.cpu->JML(0x10AB00);
+ cr_assert_eq(snes.cpu->_registers.pac, 0x10AB00, "The program counter should be equal to 0x10AB00 but it was 0x%x.", snes.cpu->_registers.pac);
}
\ No newline at end of file
diff --git a/tests/CPU/testInterupts.cpp b/tests/CPU/testInterupts.cpp
index 3773285..9d26dd2 100644
--- a/tests/CPU/testInterupts.cpp
+++ b/tests/CPU/testInterupts.cpp
@@ -12,82 +12,82 @@ using namespace ComSquare;
Test(CPU_emulated, BRK)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cartridge->header.emulationInterrupts.brk = 0x123u;
- pair.second.cpu->_registers.p.flags = 0xF1;
- pair.second.cpu->_registers.pc = 0x156u;
- pair.second.cpu->_registers.pbr = 0x15;
- pair.second.cpu->BRK();
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", pair.second.cpu->_registers.pc);
- cr_assert_eq(pair.second.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", pair.second.cpu->_registers.pbr);
- cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.x_b, true, "The break flag should be set.");
- int data = pair.second.cpu->_pop();
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cartridge->header.emulationInterrupts.brk = 0x123u;
+ snes.cpu->_registers.p.flags = 0xF1;
+ snes.cpu->_registers.pc = 0x156u;
+ snes.cpu->_registers.pbr = 0x15;
+ snes.cpu->BRK();
+ cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
+ cr_assert_eq(snes.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", snes.cpu->_registers.pbr);
+ cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.x_b, true, "The break flag should be set.");
+ int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
- data = pair.second.cpu->_pop16();
+ data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
}
Test(CPU_native, BRK)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cartridge->header.nativeInterrupts.brk = 0x123u;
- pair.second.cpu->_registers.p.flags = 0xF1;
- pair.second.cpu->_registers.pc = 0x156u;
- pair.second.cpu->_registers.pbr = 0x15;
- pair.second.cpu->BRK();
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", pair.second.cpu->_registers.pc);
- cr_assert_eq(pair.second.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", pair.second.cpu->_registers.pbr);
- cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
- int data = pair.second.cpu->_pop();
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cartridge->header.nativeInterrupts.brk = 0x123u;
+ snes.cpu->_registers.p.flags = 0xF1;
+ snes.cpu->_registers.pc = 0x156u;
+ snes.cpu->_registers.pbr = 0x15;
+ snes.cpu->BRK();
+ cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
+ cr_assert_eq(snes.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", snes.cpu->_registers.pbr);
+ cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
+ int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
- data = pair.second.cpu->_pop16();
+ data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
- data = pair.second.cpu->_pop();
+ data = snes.cpu->_pop();
cr_assert_eq(data, 0x15, "The program bank register should be pushed on the stack but it was 0x%X (expected 0x15).", data);
}
Test(CPU_emulated, COP)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = true;
- pair.second.cartridge->header.emulationInterrupts.cop = 0x123u;
- pair.second.cpu->_registers.p.flags = 0x0F;
- pair.second.cpu->_registers.pc = 0x156u;
- pair.second.cpu->_registers.pbr = 0x15;
- pair.second.cpu->COP();
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", pair.second.cpu->_registers.pc);
- cr_assert_eq(pair.second.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", pair.second.cpu->_registers.pbr);
- cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.x_b, false, "The break flag should not be set.");
- int data = pair.second.cpu->_pop();
+ Init()
+ snes.cpu->_isEmulationMode = true;
+ snes.cartridge->header.emulationInterrupts.cop = 0x123u;
+ snes.cpu->_registers.p.flags = 0x0F;
+ snes.cpu->_registers.pc = 0x156u;
+ snes.cpu->_registers.pbr = 0x15;
+ snes.cpu->COP();
+ cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
+ cr_assert_eq(snes.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", snes.cpu->_registers.pbr);
+ cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.x_b, false, "The break flag should not be set.");
+ int data = snes.cpu->_pop();
cr_assert_eq(data, 0x0F, "The Status Registers should be pushed into the stack with the value 0x0F but it was 0x%X (expected 0xF1).", data);
- data = pair.second.cpu->_pop16();
+ data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
}
Test(CPU_native, COP)
{
- auto pair = Init();
- pair.second.cpu->_isEmulationMode = false;
- pair.second.cartridge->header.nativeInterrupts.cop = 0x123u;
- pair.second.cpu->_registers.p.flags = 0xF1;
- pair.second.cpu->_registers.pc = 0x156u;
- pair.second.cpu->_registers.pbr = 0x15;
- pair.second.cpu->COP();
- cr_assert_eq(pair.second.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", pair.second.cpu->_registers.pc);
- cr_assert_eq(pair.second.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", pair.second.cpu->_registers.pbr);
- cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
- int data = pair.second.cpu->_pop();
+ Init()
+ snes.cpu->_isEmulationMode = false;
+ snes.cartridge->header.nativeInterrupts.cop = 0x123u;
+ snes.cpu->_registers.p.flags = 0xF1;
+ snes.cpu->_registers.pc = 0x156u;
+ snes.cpu->_registers.pbr = 0x15;
+ snes.cpu->COP();
+ cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
+ cr_assert_eq(snes.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", snes.cpu->_registers.pbr);
+ cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
+ int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
- data = pair.second.cpu->_pop16();
+ data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
- data = pair.second.cpu->_pop();
+ data = snes.cpu->_pop();
cr_assert_eq(data, 0x15, "The program bank register should be pushed on the stack but it was 0x%X (expected 0x15).", data);
}
\ No newline at end of file
diff --git a/tests/CPU/testStore.cpp b/tests/CPU/testStore.cpp
index 2c61114..3bd0a97 100644
--- a/tests/CPU/testStore.cpp
+++ b/tests/CPU/testStore.cpp
@@ -11,157 +11,157 @@ using namespace ComSquare;
Test(STA, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.m = true;
- pair.second.cpu->_registers.a = 0x11;
- pair.second.cpu->STA(0x0);
- auto data = pair.second.wram->_data[0];
+ Init()
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->_registers.a = 0x11;
+ snes.cpu->STA(0x0);
+ auto data = snes.wram->_data[0];
cr_assert_eq(data, 0x11, "The stored value should be 0x11 but it was 0x%x.", data);
}
Test(STA, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.m = false;
- pair.second.cpu->_registers.a = 0x11AB;
- pair.second.cpu->STA(0x0);
- auto data = pair.second.wram->_data[0] + (pair.second.wram->_data[1] << 8u);
+ Init()
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->_registers.a = 0x11AB;
+ snes.cpu->STA(0x0);
+ auto data = snes.wram->_data[0] + (snes.wram->_data[1] << 8u);
cr_assert_eq(data, 0x11AB, "The stored value should be 0x11AB but it was 0x%x.", data);
}
Test(STX, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.x = 0x11;
- pair.second.cpu->STX(0x0);
- auto data = pair.second.wram->_data[0];
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.x = 0x11;
+ snes.cpu->STX(0x0);
+ auto data = snes.wram->_data[0];
cr_assert_eq(data, 0x11, "The stored value should be 0x11 but it was 0x%x.", data);
}
Test(STX, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.x = 0x11AB;
- pair.second.cpu->STX(0x0);
- auto data = pair.second.wram->_data[0] + (pair.second.wram->_data[1] << 8u);
+ Init()
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.x = 0x11AB;
+ snes.cpu->STX(0x0);
+ auto data = snes.wram->_data[0] + (snes.wram->_data[1] << 8u);
cr_assert_eq(data, 0x11AB, "The stored value should be 0x11AB but it was 0x%x.", data);
}
Test(STY, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.cpu->_registers.y = 0x11;
- pair.second.cpu->STY(0x0);
- auto data = pair.second.wram->_data[0];
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.cpu->_registers.y = 0x11;
+ snes.cpu->STY(0x0);
+ auto data = snes.wram->_data[0];
cr_assert_eq(data, 0x11, "The stored value should be 0x11 but it was 0x%x.", data);
}
Test(STY, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.cpu->_registers.y = 0x11AB;
- pair.second.cpu->STY(0x0);
- auto data = pair.second.wram->_data[0] + (pair.second.wram->_data[1] << 8u);
+ Init()
+ snes.cpu->_registers.p.x_b = false;
+ snes.cpu->_registers.y = 0x11AB;
+ snes.cpu->STY(0x0);
+ auto data = snes.wram->_data[0] + (snes.wram->_data[1] << 8u);
cr_assert_eq(data, 0x11AB, "The stored value should be 0x11AB but it was 0x%x.", data);
}
Test(STZ, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.m = true;
- pair.second.wram->_data[0] = 0x11;
- pair.second.cpu->STZ(0x0);
- auto data = pair.second.wram->_data[0];
+ Init()
+ snes.cpu->_registers.p.m = true;
+ snes.wram->_data[0] = 0x11;
+ snes.cpu->STZ(0x0);
+ auto data = snes.wram->_data[0];
cr_assert_eq(data, 0x00, "The stored value should be 0x00 but it was 0x%x.", data);
}
Test(STZ, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.m = false;
- pair.second.wram->_data[0] = 0x11;
- pair.second.wram->_data[1] = 0x11;
- pair.second.cpu->STZ(0x0);
- auto data = pair.second.wram->_data[0] + (pair.second.wram->_data[1] << 8u);
+ Init()
+ snes.cpu->_registers.p.m = false;
+ snes.wram->_data[0] = 0x11;
+ snes.wram->_data[1] = 0x11;
+ snes.cpu->STZ(0x0);
+ auto data = snes.wram->_data[0] + (snes.wram->_data[1] << 8u);
cr_assert_eq(data, 0x00, "The stored value should be 0x00 but it was 0x%x.", data);
}
Test(LDX, 8bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.wram->_data[0] = 0x01;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.wram->_data[0] = 0x01;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x01, "The stored value should be 0x01 but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag register should not be set.");
}
Test(LDX, 8bitsNegative)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.wram->_data[0] = 0x11;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.wram->_data[0] = 0x11;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x11, "The stored value should be 0x11 but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag register should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag register should be set.");
}
Test(LDX, 8bitsZero)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = true;
- pair.second.wram->_data[0] = 0x00;
- pair.second.wram->_data[1] = 0x11;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = true;
+ snes.wram->_data[0] = 0x00;
+ snes.wram->_data[1] = 0x11;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x00, "The stored value should be 0x00 but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag register should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag register should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag register should not be set.");
}
Test(LDX, 16bits)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.wram->_data[0] = 0xAB;
- pair.second.wram->_data[1] = 001;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = false;
+ snes.wram->_data[0] = 0xAB;
+ snes.wram->_data[1] = 001;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x01AB, "The stored value should be 0x01AB but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag register should not be set.");
}
Test(LDX, 16bitsNegative)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.wram->_data[0] = 0xAB;
- pair.second.wram->_data[1] = 0x11;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = false;
+ snes.wram->_data[0] = 0xAB;
+ snes.wram->_data[1] = 0x11;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x11AB, "The stored value should be 0x11AB but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag register should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag register should be set.");
}
Test(LDX, 16bitsZero)
{
- auto pair = Init();
- pair.second.cpu->_registers.p.x_b = false;
- pair.second.wram->_data[0] = 0x00;
- pair.second.wram->_data[1] = 0x00;
- pair.second.cpu->LDX(0x0);
- auto data = pair.second.cpu->_registers.x;
+ Init()
+ snes.cpu->_registers.p.x_b = false;
+ snes.wram->_data[0] = 0x00;
+ snes.wram->_data[1] = 0x00;
+ snes.cpu->LDX(0x0);
+ auto data = snes.cpu->_registers.x;
cr_assert_eq(data, 0x0000, "The stored value should be 0x0000 but it was 0x%x.", data);
- cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag register should be set.");
- cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flag register should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag register should not be set.");
}
\ No newline at end of file
diff --git a/tests/PPU/testPpuWrite.cpp b/tests/PPU/testPpuWrite.cpp
index 926771d..814edb9 100644
--- a/tests/PPU/testPpuWrite.cpp
+++ b/tests/PPU/testPpuWrite.cpp
@@ -13,253 +13,253 @@ using namespace ComSquare;
Test(PPU_write, inidisp_data_full_ones)
{
- auto pair = Init();
- pair.first->write(0x2100, 0b11111111);
- cr_assert_eq(pair.second.ppu->_inidisp.fblank, true);
- cr_assert_eq(pair.second.ppu->_inidisp.brightness, 0xF);
+ Init()
+ snes._bus->write(0x2100, 0b11111111);
+ cr_assert_eq(snes.ppu->_inidisp.fblank, true);
+ cr_assert_eq(snes.ppu->_inidisp.brightness, 0xF);
}
Test(PPU_write, inidisp_data_full_zeros)
{
- auto pair = Init();
- pair.first->write(0x2100, 0b00000000);
- cr_assert_eq(pair.second.ppu->_inidisp.fblank, false);
- cr_assert_eq(pair.second.ppu->_inidisp.brightness, 0x0);
+ Init()
+ snes._bus->write(0x2100, 0b00000000);
+ cr_assert_eq(snes.ppu->_inidisp.fblank, false);
+ cr_assert_eq(snes.ppu->_inidisp.brightness, 0x0);
}
Test(PPU_write, inidisp_data_fBlank_on_brghtness_off)
{
- auto pair = Init();
- pair.first->write(0x2100, 0b10000000);
- cr_assert_eq(pair.second.ppu->_inidisp.fblank, true);
- cr_assert_eq(pair.second.ppu->_inidisp.brightness, 0x0);
+ Init()
+ snes._bus->write(0x2100, 0b10000000);
+ cr_assert_eq(snes.ppu->_inidisp.fblank, true);
+ cr_assert_eq(snes.ppu->_inidisp.brightness, 0x0);
}
Test(PPU_write, inidisp_data_fBlank_off_brghtness_max)
{
- auto pair = Init();
- pair.first->write(0x2100, 0b00001111);
- cr_assert_eq(pair.second.ppu->_inidisp.fblank, false);
- cr_assert_eq(pair.second.ppu->_inidisp.brightness, 0xF);
+ Init()
+ snes._bus->write(0x2100, 0b00001111);
+ cr_assert_eq(snes.ppu->_inidisp.fblank, false);
+ cr_assert_eq(snes.ppu->_inidisp.brightness, 0xF);
}
Test(PPU_write, inidisp_data_fBlank_off_brghtness_half)
{
- auto pair = Init();
- pair.first->write(0x2100, 0b00000101);
- cr_assert_eq(pair.second.ppu->_inidisp.fblank, false);
- cr_assert_eq(pair.second.ppu->_inidisp.brightness, 0x5);
+ Init()
+ snes._bus->write(0x2100, 0b00000101);
+ cr_assert_eq(snes.ppu->_inidisp.fblank, false);
+ cr_assert_eq(snes.ppu->_inidisp.brightness, 0x5);
}
Test(PPU_write, obsel_111_object_size_and_all_null)
{
- auto pair = Init();
- pair.first->write(0x2101, 0b11100000);
- cr_assert_eq(pair.second.ppu->_obsel.objectSize, 0b111);
- cr_assert_eq(pair.second.ppu->_obsel.nameSelect, 0b00);
- cr_assert_eq(pair.second.ppu->_obsel.nameBaseSelect, 0b000);
+ Init()
+ snes._bus->write(0x2101, 0b11100000);
+ cr_assert_eq(snes.ppu->_obsel.objectSize, 0b111);
+ cr_assert_eq(snes.ppu->_obsel.nameSelect, 0b00);
+ cr_assert_eq(snes.ppu->_obsel.nameBaseSelect, 0b000);
}
Test(PPU_write, obsel_data_full)
{
- auto pair = Init();
- pair.first->write(0x2101, 0b11111111);
- cr_assert_eq(pair.second.ppu->_obsel.objectSize, 0b111);
- cr_assert_eq(pair.second.ppu->_obsel.nameSelect, 0b11);
- cr_assert_eq(pair.second.ppu->_obsel.nameBaseSelect, 0b111);
+ Init()
+ snes._bus->write(0x2101, 0b11111111);
+ cr_assert_eq(snes.ppu->_obsel.objectSize, 0b111);
+ cr_assert_eq(snes.ppu->_obsel.nameSelect, 0b11);
+ cr_assert_eq(snes.ppu->_obsel.nameBaseSelect, 0b111);
}
Test(PPU_write, obsel_data_full_nameselect)
{
- auto pair = Init();
- pair.first->write(0x2101, 0b00011000);
- cr_assert_eq(pair.second.ppu->_obsel.objectSize, 0b000);
- cr_assert_eq(pair.second.ppu->_obsel.nameSelect, 0b11);
- cr_assert_eq(pair.second.ppu->_obsel.nameBaseSelect, 0b000);
+ Init()
+ snes._bus->write(0x2101, 0b00011000);
+ cr_assert_eq(snes.ppu->_obsel.objectSize, 0b000);
+ cr_assert_eq(snes.ppu->_obsel.nameSelect, 0b11);
+ cr_assert_eq(snes.ppu->_obsel.nameBaseSelect, 0b000);
}
Test(PPU_write, obsel_data_full_baseselect)
{
- auto pair = Init();
- pair.first->write(0x2101, 0b00000111);
- cr_assert_eq(pair.second.ppu->_obsel.objectSize, 0b000);
- cr_assert_eq(pair.second.ppu->_obsel.nameSelect, 0b00);
- cr_assert_eq(pair.second.ppu->_obsel.nameBaseSelect, 0b111);
+ Init()
+ snes._bus->write(0x2101, 0b00000111);
+ cr_assert_eq(snes.ppu->_obsel.objectSize, 0b000);
+ cr_assert_eq(snes.ppu->_obsel.nameSelect, 0b00);
+ cr_assert_eq(snes.ppu->_obsel.nameBaseSelect, 0b111);
}
Test(PPU_write, oamaddl_data_full)
{
- auto pair = Init();
- pair.first->write(0x2102, 0b11111111);
- cr_assert_eq(pair.second.ppu->_oamadd.oamAddress, 0b011111111);
+ Init()
+ snes._bus->write(0x2102, 0b11111111);
+ cr_assert_eq(snes.ppu->_oamadd.oamAddress, 0b011111111);
}
Test(PPU_write, oamaddh_data_full)
{
- auto pair = Init();
- pair.first->write(0x2103, 0b11111111);
- cr_assert_eq(pair.second.ppu->_oamadd.objPriorityActivationBit, true);
- cr_assert_eq(pair.second.ppu->_oamadd.oamAddress, 0b100000000);
+ Init()
+ snes._bus->write(0x2103, 0b11111111);
+ cr_assert_eq(snes.ppu->_oamadd.objPriorityActivationBit, true);
+ cr_assert_eq(snes.ppu->_oamadd.oamAddress, 0b100000000);
}
Test(PPU_write, oamaddlh_data_full)
{
- auto pair = Init();
- pair.first->write(0x2102, 0b11111111);
- pair.first->write(0x2103, 0b11111111);
- cr_assert_eq(pair.second.ppu->_oamadd.objPriorityActivationBit, true);
- cr_assert_eq(pair.second.ppu->_oamadd.oamAddress, 0b111111111);
+ Init()
+ snes._bus->write(0x2102, 0b11111111);
+ snes._bus->write(0x2103, 0b11111111);
+ cr_assert_eq(snes.ppu->_oamadd.objPriorityActivationBit, true);
+ cr_assert_eq(snes.ppu->_oamadd.oamAddress, 0b111111111);
}
Test(PPU_write, oamaddlh_data_full_priorityBit_off)
{
- auto pair = Init();
- pair.first->write(0x2102, 0b11111111);
- pair.first->write(0x2103, 0b01111111);
- cr_assert_eq(pair.second.ppu->_oamadd.objPriorityActivationBit, false);
- cr_assert_eq(pair.second.ppu->_oamadd.oamAddress, 0b111111111);
+ Init()
+ snes._bus->write(0x2102, 0b11111111);
+ snes._bus->write(0x2103, 0b01111111);
+ cr_assert_eq(snes.ppu->_oamadd.objPriorityActivationBit, false);
+ cr_assert_eq(snes.ppu->_oamadd.oamAddress, 0b111111111);
}
Test(PPU_write, oamaddlh_oamAdress_11_priorityBit_on)
{
- auto pair = Init();
- pair.first->write(0x2102, 0b00001011);
- pair.first->write(0x2103, 0b10011100);
- cr_assert_eq(pair.second.ppu->_oamadd.objPriorityActivationBit, true);
- cr_assert_eq(pair.second.ppu->_oamadd.oamAddress, 11);
+ Init()
+ snes._bus->write(0x2102, 0b00001011);
+ snes._bus->write(0x2103, 0b10011100);
+ cr_assert_eq(snes.ppu->_oamadd.objPriorityActivationBit, true);
+ cr_assert_eq(snes.ppu->_oamadd.oamAddress, 11);
}
Test(PPU_write, bgmode_data_full)
{
- auto pair = Init();
- pair.first->write(0x2105, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgmode.bgMode, 7);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg1, true);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg2, true);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg3, true);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg4, true);
- cr_assert_eq(pair.second.ppu->_bgmode.mode1Bg3PriorityBit, true);
+ Init()
+ snes._bus->write(0x2105, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgmode.bgMode, 7);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg1, true);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg2, true);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg3, true);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg4, true);
+ cr_assert_eq(snes.ppu->_bgmode.mode1Bg3PriorityBit, true);
}
Test(PPU_write, bgmode_bgmode_5_and_bg24_on)
{
- auto pair = Init();
- pair.first->write(0x2105, 0b10100101);
- cr_assert_eq(pair.second.ppu->_bgmode.bgMode, 5);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg1, false);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg2, true);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg3, false);
- cr_assert_eq(pair.second.ppu->_bgmode.characterSizeBg4, true);
- cr_assert_eq(pair.second.ppu->_bgmode.mode1Bg3PriorityBit, false);
+ Init()
+ snes._bus->write(0x2105, 0b10100101);
+ cr_assert_eq(snes.ppu->_bgmode.bgMode, 5);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg1, false);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg2, true);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg3, false);
+ cr_assert_eq(snes.ppu->_bgmode.characterSizeBg4, true);
+ cr_assert_eq(snes.ppu->_bgmode.mode1Bg3PriorityBit, false);
}
Test(PPU_write, mosaic_data_full)
{
- auto pair = Init();
- pair.first->write(0x2106, 0b11111111);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true);
- cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0xF);
+ Init()
+ snes._bus->write(0x2106, 0b11111111);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg1, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg2, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg3, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg4, true);
+ cr_assert_eq(snes.ppu->_mosaic.pixelSize, 0xF);
}
Test(PPU_write, mosaic_affectbg23_w_1x1_size)
{
- auto pair = Init();
- pair.first->write(0x2106, 0b00000110);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, false);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, false);
- cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x0);
+ Init()
+ snes._bus->write(0x2106, 0b00000110);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg1, false);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg2, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg3, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg4, false);
+ cr_assert_eq(snes.ppu->_mosaic.pixelSize, 0x0);
}
Test(PPU_write, mosaic_affectbg14_w_2x2_size)
{
- auto pair = Init();
- pair.first->write(0x2106, 0b00101001);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg1, true);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg2, false);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg3, false);
- cr_assert_eq(pair.second.ppu->_mosaic.affectBg4, true);
- cr_assert_eq(pair.second.ppu->_mosaic.pixelSize, 0x2);
+ Init()
+ snes._bus->write(0x2106, 0b00101001);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg1, true);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg2, false);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg3, false);
+ cr_assert_eq(snes.ppu->_mosaic.affectBg4, true);
+ cr_assert_eq(snes.ppu->_mosaic.pixelSize, 0x2);
}
Test(PPU_write, bg1sc_data_full)
{
- auto pair = Init();
- pair.first->write(0x2107, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapAddress, 0b111111);
- cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapHorizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_bgsc[0].tilemapVerticalMirroring, true);
+ Init()
+ snes._bus->write(0x2107, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgsc[0].tilemapAddress, 0b111111);
+ cr_assert_eq(snes.ppu->_bgsc[0].tilemapHorizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_bgsc[0].tilemapVerticalMirroring, true);
}
Test(PPU_write, bg2sc_data_full)
{
- auto pair = Init();
- pair.first->write(0x2108, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapAddress, 0b111111);
- cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapHorizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_bgsc[1].tilemapVerticalMirroring, true);
+ Init()
+ snes._bus->write(0x2108, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgsc[1].tilemapAddress, 0b111111);
+ cr_assert_eq(snes.ppu->_bgsc[1].tilemapHorizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_bgsc[1].tilemapVerticalMirroring, true);
}
Test(PPU_write, bg3sc_data_full)
{
- auto pair = Init();
- pair.first->write(0x2109, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapAddress, 0b111111);
- cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapHorizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_bgsc[2].tilemapVerticalMirroring, true);
+ Init()
+ snes._bus->write(0x2109, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgsc[2].tilemapAddress, 0b111111);
+ cr_assert_eq(snes.ppu->_bgsc[2].tilemapHorizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_bgsc[2].tilemapVerticalMirroring, true);
}
Test(PPU_write, bg4sc_data_full)
{
- auto pair = Init();
- pair.first->write(0x210A, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0b111111);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, true);
+ Init()
+ snes._bus->write(0x210A, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapAddress, 0b111111);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapHorizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapVerticalMirroring, true);
}
Test(PPU_write, bg4sc_data_null)
{
- auto pair = Init();
- pair.first->write(0x210A, 0b00000000);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, false);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, false);
+ Init()
+ snes._bus->write(0x210A, 0b00000000);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapAddress, 0);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapHorizontalMirroring, false);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapVerticalMirroring, false);
}
Test(PPU_write, bg4sc_horizontal_off_vertical_on_random_tilemapAdress)
{
- auto pair = Init();
- pair.first->write(0x210A, 0b11000110);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapAddress, 0b110001);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapHorizontalMirroring, false);
- cr_assert_eq(pair.second.ppu->_bgsc[3].tilemapVerticalMirroring, true);
+ Init()
+ snes._bus->write(0x210A, 0b11000110);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapAddress, 0b110001);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapHorizontalMirroring, false);
+ cr_assert_eq(snes.ppu->_bgsc[3].tilemapVerticalMirroring, true);
}
Test(PPU_write, bg12nba_data_full)
{
- auto pair = Init();
- pair.first->write(0x210B, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg1a3, 0b1111);
- cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg2a4, 0b1111);
+ Init()
+ snes._bus->write(0x210B, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgnba[0].baseAddressBg1a3, 0b1111);
+ cr_assert_eq(snes.ppu->_bgnba[0].baseAddressBg2a4, 0b1111);
}
Test(PPU_write, bg34nba_data_full)
{
- auto pair = Init();
- pair.first->write(0x210C, 0b11111111);
- cr_assert_eq(pair.second.ppu->_bgnba[1].baseAddressBg1a3, 0b1111);
- cr_assert_eq(pair.second.ppu->_bgnba[1].baseAddressBg2a4, 0b1111);
+ Init()
+ snes._bus->write(0x210C, 0b11111111);
+ cr_assert_eq(snes.ppu->_bgnba[1].baseAddressBg1a3, 0b1111);
+ cr_assert_eq(snes.ppu->_bgnba[1].baseAddressBg2a4, 0b1111);
}
Test(PPU_write, bg12nba_data_random_data)
{
- auto pair = Init();
- pair.first->write(0x210B, 0b10101010);
- cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg1a3, 0b1010);
- cr_assert_eq(pair.second.ppu->_bgnba[0].baseAddressBg2a4, 0b1010);
+ Init()
+ snes._bus->write(0x210B, 0b10101010);
+ cr_assert_eq(snes.ppu->_bgnba[0].baseAddressBg1a3, 0b1010);
+ cr_assert_eq(snes.ppu->_bgnba[0].baseAddressBg2a4, 0b1010);
}
\ No newline at end of file
diff --git a/tests/PPU/testPpuWriteFromVmain.cpp b/tests/PPU/testPpuWriteFromVmain.cpp
index fe21962..d8fdae7 100644
--- a/tests/PPU/testPpuWriteFromVmain.cpp
+++ b/tests/PPU/testPpuWriteFromVmain.cpp
@@ -13,260 +13,260 @@ using namespace ComSquare;
Test(PPU_write_2, vmain_data_full)
{
- auto pair = Init();
- pair.first->write(0x2115, 0b11111111);
- cr_assert_eq(pair.second.ppu->_vmain.incrementMode, true);
- cr_assert_eq(pair.second.ppu->_vmain.addressRemapping, 0b11);
- cr_assert_eq(pair.second.ppu->_vmain.incrementAmount, 0b11);
+ Init()
+ snes._bus->write(0x2115, 0b11111111);
+ cr_assert_eq(snes.ppu->_vmain.incrementMode, true);
+ cr_assert_eq(snes.ppu->_vmain.addressRemapping, 0b11);
+ cr_assert_eq(snes.ppu->_vmain.incrementAmount, 0b11);
}
Test(PPU_write_2, vmain_incrementmode_off_false_else_full)
{
- auto pair = Init();
- pair.first->write(0x2115, 0b01111111);
- cr_assert_eq(pair.second.ppu->_vmain.incrementMode, false);
- cr_assert_eq(pair.second.ppu->_vmain.addressRemapping, 0b11);
- cr_assert_eq(pair.second.ppu->_vmain.incrementAmount, 0b11);
+ Init()
+ snes._bus->write(0x2115, 0b01111111);
+ cr_assert_eq(snes.ppu->_vmain.incrementMode, false);
+ cr_assert_eq(snes.ppu->_vmain.addressRemapping, 0b11);
+ cr_assert_eq(snes.ppu->_vmain.incrementAmount, 0b11);
}
Test(PPU_write_2, vmain_addressremaping_null_else_full)
{
- auto pair = Init();
- pair.first->write(0x2115, 0b11110011);
- cr_assert_eq(pair.second.ppu->_vmain.incrementMode, true);
- cr_assert_eq(pair.second.ppu->_vmain.addressRemapping, 0b00);
- cr_assert_eq(pair.second.ppu->_vmain.incrementAmount, 0b11);
+ Init()
+ snes._bus->write(0x2115, 0b11110011);
+ cr_assert_eq(snes.ppu->_vmain.incrementMode, true);
+ cr_assert_eq(snes.ppu->_vmain.addressRemapping, 0b00);
+ cr_assert_eq(snes.ppu->_vmain.incrementAmount, 0b11);
}
Test(PPU_write_2, vmain_incrementamount_null_else_full)
{
- auto pair = Init();
- pair.first->write(0x2115, 0b11111100);
- cr_assert_eq(pair.second.ppu->_vmain.incrementMode, true);
- cr_assert_eq(pair.second.ppu->_vmain.addressRemapping, 0b11);
- cr_assert_eq(pair.second.ppu->_vmain.incrementAmount, 0b00);
+ Init()
+ snes._bus->write(0x2115, 0b11111100);
+ cr_assert_eq(snes.ppu->_vmain.incrementMode, true);
+ cr_assert_eq(snes.ppu->_vmain.addressRemapping, 0b11);
+ cr_assert_eq(snes.ppu->_vmain.incrementAmount, 0b00);
}
Test(PPU_write_2, vmadd_full_data)
{
- auto pair = Init();
- pair.first->write(0x2116, 0b11111111);
- pair.first->write(0x2117, 0b11111111);
- cr_assert_eq(pair.second.ppu->_vmadd.vmadd, 0b1111111111111111);
+ Init()
+ snes._bus->write(0x2116, 0b11111111);
+ snes._bus->write(0x2117, 0b11111111);
+ cr_assert_eq(snes.ppu->_vmadd.vmadd, 0b1111111111111111);
}
Test(PPU_write_2, vmadd_full_high_byte_null)
{
- auto pair = Init();
- pair.first->write(0x2116, 0b11111111);
- pair.first->write(0x2117, 0b00000000);
- cr_assert_eq(pair.second.ppu->_vmadd.vmadd, 0b0000000011111111);
+ Init()
+ snes._bus->write(0x2116, 0b11111111);
+ snes._bus->write(0x2117, 0b00000000);
+ cr_assert_eq(snes.ppu->_vmadd.vmadd, 0b0000000011111111);
}
Test(PPU_write_2, vmdata_full_data)
{
- auto pair = Init();
- pair.first->write(0x2118, 0b11111111);
- pair.first->write(0x2119, 0b11111111);
- cr_assert_eq(pair.second.ppu->_vmdata.vmdata, 0b1111111111111111);
+ Init()
+ snes._bus->write(0x2118, 0b11111111);
+ snes._bus->write(0x2119, 0b11111111);
+ cr_assert_eq(snes.ppu->_vmdata.vmdata, 0b1111111111111111);
}
Test(PPU_write_2, vmdata_full_high_byte_null)
{
- auto pair = Init();
- pair.first->write(0x2118, 0b11111111);
- pair.first->write(0x2119, 0b00000000);
- cr_assert_eq(pair.second.ppu->_vmdata.vmdata, 0b0000000011111111);
+ Init()
+ snes._bus->write(0x2118, 0b11111111);
+ snes._bus->write(0x2119, 0b00000000);
+ cr_assert_eq(snes.ppu->_vmdata.vmdata, 0b0000000011111111);
}
Test(PPU_write_2, cgadd_full_high_byte_null)
{
- auto pair = Init();
- pair.first->write(0x2121, 0b11111111);
- cr_assert_eq(pair.second.ppu->_cgadd, 0b11111111);
- cr_assert_eq(pair.second.ppu->_isLowByte, true);
+ Init()
+ snes._bus->write(0x2121, 0b11111111);
+ cr_assert_eq(snes.ppu->_cgadd, 0b11111111);
+ cr_assert_eq(snes.ppu->_isLowByte, true);
}
Test(PPU_write_2, cgdata_data_full)
{
- auto pair = Init();
- pair.first->write(0x2121, 0x0);
- pair.first->write(0x2122, 0b11111111);
- cr_assert_eq(pair.second.ppu->_cgdata.cgdatal, 0b11111111);
- cr_assert_eq(pair.second.ppu->_isLowByte, false);
- int address = pair.second.ppu->_cgadd;
- pair.first->write(0x2122, 0b11111000);
- cr_assert_eq(pair.second.ppu->_cgdata.cgdatah, 0b11111000);
- cr_assert_eq(pair.second.ppu->_isLowByte, true);
- cr_assert_eq(pair.second.ppu->_cgadd, address + 1);
+ Init()
+ snes._bus->write(0x2121, 0x0);
+ snes._bus->write(0x2122, 0b11111111);
+ cr_assert_eq(snes.ppu->_cgdata.cgdatal, 0b11111111);
+ cr_assert_eq(snes.ppu->_isLowByte, false);
+ int address = snes.ppu->_cgadd;
+ snes._bus->write(0x2122, 0b11111000);
+ cr_assert_eq(snes.ppu->_cgdata.cgdatah, 0b11111000);
+ cr_assert_eq(snes.ppu->_isLowByte, true);
+ cr_assert_eq(snes.ppu->_cgadd, address + 1);
}
Test(PPU_write_2, m7sel_data_full)
{
- auto pair = Init();
- pair.first->write(0x211A, 0b11111111);
- cr_assert_eq(pair.second.ppu->_m7sel.playingFieldSize, true);
- cr_assert_eq(pair.second.ppu->_m7sel.emptySpaceFill, true);
- cr_assert_eq(pair.second.ppu->_m7sel.horizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_m7sel.verticalMirroring, true);
+ Init()
+ snes._bus->write(0x211A, 0b11111111);
+ cr_assert_eq(snes.ppu->_m7sel.playingFieldSize, true);
+ cr_assert_eq(snes.ppu->_m7sel.emptySpaceFill, true);
+ cr_assert_eq(snes.ppu->_m7sel.horizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_m7sel.verticalMirroring, true);
}
Test(PPU_write_2, m7sel_data_actual)
{
- auto pair = Init();
- pair.first->write(0x211A, 0b01111101);
- cr_assert_eq(pair.second.ppu->_m7sel.playingFieldSize, false);
- cr_assert_eq(pair.second.ppu->_m7sel.emptySpaceFill, true);
- cr_assert_eq(pair.second.ppu->_m7sel.horizontalMirroring, true);
- cr_assert_eq(pair.second.ppu->_m7sel.verticalMirroring, false);
+ Init()
+ snes._bus->write(0x211A, 0b01111101);
+ cr_assert_eq(snes.ppu->_m7sel.playingFieldSize, false);
+ cr_assert_eq(snes.ppu->_m7sel.emptySpaceFill, true);
+ cr_assert_eq(snes.ppu->_m7sel.horizontalMirroring, true);
+ cr_assert_eq(snes.ppu->_m7sel.verticalMirroring, false);
}
Test(PPU_write_2, w12sel_data_full)
{
- auto pair = Init();
- pair.first->write(0x2123, 0b11111111);
- cr_assert_eq(pair.second.ppu->_wsel[0].window1InversionForBg1Bg2Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow1ForBg1Bg2Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].window2InversionForBg1Bg3Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow2ForBg1Bg3Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].window1InversionForBg2Bg4Color, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow1ForBg2Bg4Color, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].window2InversionForBg2Bg4Color, true);
- cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow2ForBg2Bg4Color, true);
+ Init()
+ snes._bus->write(0x2123, 0b11111111);
+ cr_assert_eq(snes.ppu->_wsel[0].window1InversionForBg1Bg2Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[0].enableWindow1ForBg1Bg2Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[0].window2InversionForBg1Bg3Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[0].enableWindow2ForBg1Bg3Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[0].window1InversionForBg2Bg4Color, true);
+ cr_assert_eq(snes.ppu->_wsel[0].enableWindow1ForBg2Bg4Color, true);
+ cr_assert_eq(snes.ppu->_wsel[0].window2InversionForBg2Bg4Color, true);
+ cr_assert_eq(snes.ppu->_wsel[0].enableWindow2ForBg2Bg4Color, true);
}
Test(PPU_write_2, w34sel_data_full)
{
- auto pair = Init();
- pair.first->write(0x2124, 0b10101010);
- cr_assert_eq(pair.second.ppu->_wsel[1].window1InversionForBg1Bg2Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow1ForBg1Bg2Obj, false);
- cr_assert_eq(pair.second.ppu->_wsel[1].window2InversionForBg1Bg3Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow2ForBg1Bg3Obj, false);
- cr_assert_eq(pair.second.ppu->_wsel[1].window1InversionForBg2Bg4Color, true);
- cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow1ForBg2Bg4Color, false);
- cr_assert_eq(pair.second.ppu->_wsel[1].window2InversionForBg2Bg4Color, true);
- cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow2ForBg2Bg4Color, false);
+ Init()
+ snes._bus->write(0x2124, 0b10101010);
+ cr_assert_eq(snes.ppu->_wsel[1].window1InversionForBg1Bg2Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[1].enableWindow1ForBg1Bg2Obj, false);
+ cr_assert_eq(snes.ppu->_wsel[1].window2InversionForBg1Bg3Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[1].enableWindow2ForBg1Bg3Obj, false);
+ cr_assert_eq(snes.ppu->_wsel[1].window1InversionForBg2Bg4Color, true);
+ cr_assert_eq(snes.ppu->_wsel[1].enableWindow1ForBg2Bg4Color, false);
+ cr_assert_eq(snes.ppu->_wsel[1].window2InversionForBg2Bg4Color, true);
+ cr_assert_eq(snes.ppu->_wsel[1].enableWindow2ForBg2Bg4Color, false);
}
Test(PPU_write_2, wobjsel_data_full)
{
- auto pair = Init();
- pair.first->write(0x2125, 0b10110001);
- cr_assert_eq(pair.second.ppu->_wsel[2].window1InversionForBg1Bg2Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow1ForBg1Bg2Obj, false);
- cr_assert_eq(pair.second.ppu->_wsel[2].window2InversionForBg1Bg3Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow2ForBg1Bg3Obj, true);
- cr_assert_eq(pair.second.ppu->_wsel[2].window1InversionForBg2Bg4Color, false);
- cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow1ForBg2Bg4Color, false);
- cr_assert_eq(pair.second.ppu->_wsel[2].window2InversionForBg2Bg4Color, false);
- cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow2ForBg2Bg4Color, true);
+ Init()
+ snes._bus->write(0x2125, 0b10110001);
+ cr_assert_eq(snes.ppu->_wsel[2].window1InversionForBg1Bg2Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[2].enableWindow1ForBg1Bg2Obj, false);
+ cr_assert_eq(snes.ppu->_wsel[2].window2InversionForBg1Bg3Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[2].enableWindow2ForBg1Bg3Obj, true);
+ cr_assert_eq(snes.ppu->_wsel[2].window1InversionForBg2Bg4Color, false);
+ cr_assert_eq(snes.ppu->_wsel[2].enableWindow1ForBg2Bg4Color, false);
+ cr_assert_eq(snes.ppu->_wsel[2].window2InversionForBg2Bg4Color, false);
+ cr_assert_eq(snes.ppu->_wsel[2].enableWindow2ForBg2Bg4Color, true);
}
Test(PPU_write_2, wbglog_data_full)
{
- auto pair = Init();
- pair.first->write(0x212A, 0b10110001);
- cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg1, 0b10);
- cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg2, 0b11);
- cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg3, 0b00);
- cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg4, 0b01);
+ Init()
+ snes._bus->write(0x212A, 0b10110001);
+ cr_assert_eq(snes.ppu->_wbglog.maskLogicBg1, 0b10);
+ cr_assert_eq(snes.ppu->_wbglog.maskLogicBg2, 0b11);
+ cr_assert_eq(snes.ppu->_wbglog.maskLogicBg3, 0b00);
+ cr_assert_eq(snes.ppu->_wbglog.maskLogicBg4, 0b01);
}
Test(PPU_write_2, wobjlog_data_full)
{
- auto pair = Init();
- pair.first->write(0x212B, 0b10110001);
- cr_assert_eq(pair.second.ppu->_wobjlog.maskLogicObj, 0b01);
- cr_assert_eq(pair.second.ppu->_wobjlog.maskLogicColor, 0b00);
+ Init()
+ snes._bus->write(0x212B, 0b10110001);
+ cr_assert_eq(snes.ppu->_wobjlog.maskLogicObj, 0b01);
+ cr_assert_eq(snes.ppu->_wobjlog.maskLogicColor, 0b00);
}
Test(PPU_write_2, tm_data_full)
{
- auto pair = Init();
- pair.first->write(0x212C, 0b10110001);
- cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg1, true);
- cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg2, false);
- cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg3, false);
- cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg4, false);
- cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayObj, true);
+ Init()
+ snes._bus->write(0x212C, 0b10110001);
+ cr_assert_eq(snes.ppu->_t[0].enableWindowDisplayBg1, true);
+ cr_assert_eq(snes.ppu->_t[0].enableWindowDisplayBg2, false);
+ cr_assert_eq(snes.ppu->_t[0].enableWindowDisplayBg3, false);
+ cr_assert_eq(snes.ppu->_t[0].enableWindowDisplayBg4, false);
+ cr_assert_eq(snes.ppu->_t[0].enableWindowDisplayObj, true);
}
Test(PPU_write_2, ts_data_full)
{
- auto pair = Init();
- pair.first->write(0x212D, 0b10101110);
- cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg1, false);
- cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg2, true);
- cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg3, true);
- cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg4, true);
- cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayObj, false);
+ Init()
+ snes._bus->write(0x212D, 0b10101110);
+ cr_assert_eq(snes.ppu->_t[1].enableWindowDisplayBg1, false);
+ cr_assert_eq(snes.ppu->_t[1].enableWindowDisplayBg2, true);
+ cr_assert_eq(snes.ppu->_t[1].enableWindowDisplayBg3, true);
+ cr_assert_eq(snes.ppu->_t[1].enableWindowDisplayBg4, true);
+ cr_assert_eq(snes.ppu->_t[1].enableWindowDisplayObj, false);
}
Test(PPU_write_2, tmw_data_full)
{
- auto pair = Init();
- pair.first->write(0x212E, 0b10101110);
- cr_assert_eq(pair.second.ppu->_tw[0].enableWindowMaskingBg1, false);
- cr_assert_eq(pair.second.ppu->_tw[0].enableWindowMaskingBg2, true);
- cr_assert_eq(pair.second.ppu->_tw[0].enableWindowMaskingBg3, true);
- cr_assert_eq(pair.second.ppu->_tw[0].enableWindowMaskingBg4, true);
- cr_assert_eq(pair.second.ppu->_tw[0].enableWindowMaskingObj, false);
+ Init()
+ snes._bus->write(0x212E, 0b10101110);
+ cr_assert_eq(snes.ppu->_tw[0].enableWindowMaskingBg1, false);
+ cr_assert_eq(snes.ppu->_tw[0].enableWindowMaskingBg2, true);
+ cr_assert_eq(snes.ppu->_tw[0].enableWindowMaskingBg3, true);
+ cr_assert_eq(snes.ppu->_tw[0].enableWindowMaskingBg4, true);
+ cr_assert_eq(snes.ppu->_tw[0].enableWindowMaskingObj, false);
}
Test(PPU_write_2, tsw_data_full)
{
- auto pair = Init();
- pair.first->write(0x212F, 0b10100011);
- cr_assert_eq(pair.second.ppu->_tw[1].enableWindowMaskingBg1, true);
- cr_assert_eq(pair.second.ppu->_tw[1].enableWindowMaskingBg2, true);
- cr_assert_eq(pair.second.ppu->_tw[1].enableWindowMaskingBg3, false);
- cr_assert_eq(pair.second.ppu->_tw[1].enableWindowMaskingBg4, false);
- cr_assert_eq(pair.second.ppu->_tw[1].enableWindowMaskingObj, false);
+ Init()
+ snes._bus->write(0x212F, 0b10100011);
+ cr_assert_eq(snes.ppu->_tw[1].enableWindowMaskingBg1, true);
+ cr_assert_eq(snes.ppu->_tw[1].enableWindowMaskingBg2, true);
+ cr_assert_eq(snes.ppu->_tw[1].enableWindowMaskingBg3, false);
+ cr_assert_eq(snes.ppu->_tw[1].enableWindowMaskingBg4, false);
+ cr_assert_eq(snes.ppu->_tw[1].enableWindowMaskingObj, false);
}
Test(PPU_write_2, cgwsel_data_full)
{
- auto pair = Init();
- pair.first->write(0x2130, 0b10111001);
- cr_assert_eq(pair.second.ppu->_cgwsel.clipColorToBlackBeforeMath, 0b10);
- cr_assert_eq(pair.second.ppu->_cgwsel.preventColorMath, 0b11);
- cr_assert_eq(pair.second.ppu->_cgwsel.addSubscreen, false);
- cr_assert_eq(pair.second.ppu->_cgwsel.directColorMode, true);
+ Init()
+ snes._bus->write(0x2130, 0b10111001);
+ cr_assert_eq(snes.ppu->_cgwsel.clipColorToBlackBeforeMath, 0b10);
+ cr_assert_eq(snes.ppu->_cgwsel.preventColorMath, 0b11);
+ cr_assert_eq(snes.ppu->_cgwsel.addSubscreen, false);
+ cr_assert_eq(snes.ppu->_cgwsel.directColorMode, true);
}
Test(PPU_write_2, cgadsub_data_full)
{
- auto pair = Init();
- pair.first->write(0x2131, 0b10111001);
- cr_assert_eq(pair.second.ppu->_cgadsub.addSubtractSelect, true);
- cr_assert_eq(pair.second.ppu->_cgadsub.halfColorMath, false);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathBackdrop, true);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathObj, true);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathBg4, true);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathBg3, false);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathBg2, false);
- cr_assert_eq(pair.second.ppu->_cgadsub.enableColorMathBg1, true);
+ Init()
+ snes._bus->write(0x2131, 0b10111001);
+ cr_assert_eq(snes.ppu->_cgadsub.addSubtractSelect, true);
+ cr_assert_eq(snes.ppu->_cgadsub.halfColorMath, false);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathBackdrop, true);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathObj, true);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathBg4, true);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathBg3, false);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathBg2, false);
+ cr_assert_eq(snes.ppu->_cgadsub.enableColorMathBg1, true);
}
Test(PPU_write_2, coldata_data_full)
{
- auto pair = Init();
- pair.first->write(0x2132, 0b10111001);
- cr_assert_eq(pair.second.ppu->_coldata.blue, true);
- cr_assert_eq(pair.second.ppu->_coldata.green, false);
- cr_assert_eq(pair.second.ppu->_coldata.red, true);
- cr_assert_eq(pair.second.ppu->_coldata.colorIntensity, 0b11001);
+ Init()
+ snes._bus->write(0x2132, 0b10111001);
+ cr_assert_eq(snes.ppu->_coldata.blue, true);
+ cr_assert_eq(snes.ppu->_coldata.green, false);
+ cr_assert_eq(snes.ppu->_coldata.red, true);
+ cr_assert_eq(snes.ppu->_coldata.colorIntensity, 0b11001);
}
Test(PPU_write_2, setini_data_full)
{
- auto pair = Init();
- pair.first->write(0x2133, 0b10111001);
- cr_assert_eq(pair.second.ppu->_setini.externalSync, true);
- cr_assert_eq(pair.second.ppu->_setini.mode7ExtBg, false);
- cr_assert_eq(pair.second.ppu->_setini.enablePseudoHiresMode, true);
- cr_assert_eq(pair.second.ppu->_setini.overscanMode, false);
- cr_assert_eq(pair.second.ppu->_setini.objInterlace, false);
- cr_assert_eq(pair.second.ppu->_setini.screenInterlace, true);
+ Init()
+ snes._bus->write(0x2133, 0b10111001);
+ cr_assert_eq(snes.ppu->_setini.externalSync, true);
+ cr_assert_eq(snes.ppu->_setini.mode7ExtBg, false);
+ cr_assert_eq(snes.ppu->_setini.enablePseudoHiresMode, true);
+ cr_assert_eq(snes.ppu->_setini.overscanMode, false);
+ cr_assert_eq(snes.ppu->_setini.objInterlace, false);
+ cr_assert_eq(snes.ppu->_setini.screenInterlace, true);
}
\ No newline at end of file
diff --git a/tests/testMemoryBus.cpp b/tests/testMemoryBus.cpp
index 9b581cd..f1d27f8 100644
--- a/tests/testMemoryBus.cpp
+++ b/tests/testMemoryBus.cpp
@@ -7,7 +7,7 @@
#include
#include "tests.hpp"
#include "../sources/Memory/MemoryBus.hpp"
-#include "../sources/Memory/IMemory.hpp"
+#include "../sources/Memory/AMemory.hpp"
#include "../sources/SNES.hpp"
#include "../sources/Renderer/NoRenderer.hpp"
#include "../sources/Memory/MemoryShadow.hpp"
@@ -26,248 +26,237 @@ using namespace ComSquare;
Test(BusAccessor, GetWramStart)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x7E0000);
- cr_assert_eq(accessor.get(), pair.second.wram.get());
+ accessor = snes._bus->getAccessor(0x7E0000);
+ cr_assert_eq(accessor.get(), snes.wram.get());
}
Test(BusAccessor, GetWramEnd)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x7FFFFF);
- cr_assert_eq(accessor.get(), pair.second.wram.get());
+ accessor = snes._bus->getAccessor(0x7FFFFF);
+ cr_assert_eq(accessor.get(), snes.wram.get());
}
Test(BusAccessor, GetWramMirror)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x2F11FF));
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x2F11FF));
cr_assert_neq(accessor, nullptr);
- cr_assert_eq(accessor->_initial.get(), pair.second.wram.get());
+ cr_assert_eq(accessor->_initial.get(), snes.wram.get());
}
Test(BusAccessor, GetWramMirror2)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x100000));
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x100000));
cr_assert_neq(accessor, nullptr);
- cr_assert_eq(accessor->_initial.get(), pair.second.wram.get());
+ cr_assert_eq(accessor->_initial.get(), snes.wram.get());
}
Test(BusAccessor, GetWramMirror3)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x1010));
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x1010));
cr_assert_neq(accessor, nullptr);
- cr_assert_eq(accessor->_initial.get(), pair.second.wram.get());
+ cr_assert_eq(accessor->_initial.get(), snes.wram.get());
}
Test(BusAccessor, GetOpenBus)
{
- auto pair = Init();
- std::shared_ptr accessor = pair.first->getAccessor(0x897654);
+ Init()
+ std::shared_ptr accessor = snes._bus->getAccessor(0x897654);
cr_assert_eq(accessor.get(), nullptr);
}
Test(BusAccessor, GetSramStart)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x700000));
- cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x700000));
+ cr_assert_eq(accessor->_initial.get(), snes.sram.get());
}
Test(BusAccessor, GetSramEnd)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x7D7FFF));
- cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x7D7FFF));
+ cr_assert_eq(accessor->_initial.get(), snes.sram.get());
}
Test(BusAccessor, GetSramMirror)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0xF00123));
- cr_assert_eq(accessor.get(), pair.second.sram.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0xF00123));
+ cr_assert_eq(accessor.get(), snes.sram.get());
}
-//Test(BusAccessor, GetSramMirror2)
-//{
-// auto pair = Init();
-// std::shared_ptr accessor = nullptr;
-//
-// // TODO implement the SRam accessor for the FE/FF.
-// //std::cout << pair.first->getAccessor(0xFE0123) << std::endl;
-// accessor = std::static_pointer_cast(pair.first->getAccessor(0xFE0123));
-// cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
-//}
-
Test(BusAccessor, GetAPUStart)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x002140);
- cr_assert_eq(accessor.get(), pair.second.apu.get());
+ accessor = snes._bus->getAccessor(0x002140);
+ cr_assert_eq(accessor.get(), snes.apu.get());
}
Test(BusAccessor, GetAPUEnd)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x002143);
- cr_assert_eq(accessor.get(), pair.second.apu.get());
+ accessor = snes._bus->getAccessor(0x002143);
+ cr_assert_eq(accessor.get(), snes.apu.get());
}
Test(BusAccessor, GetAPUMirror)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0xAB2143));
- cr_assert_eq(accessor->_initial.get(), pair.second.apu.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0xAB2143));
+ cr_assert_eq(accessor->_initial.get(), snes.apu.get());
}
Test(BusAccessor, GetAPUMirrorFirstHalf)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x052143));
- cr_assert_eq(accessor->_initial.get(), pair.second.apu.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x052143));
+ cr_assert_eq(accessor->_initial.get(), snes.apu.get());
}
Test(BusAccessor, GetCPUStart)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x004200);
- cr_assert_eq(accessor.get(), pair.second.cpu.get());
+ accessor = snes._bus->getAccessor(0x004200);
+ cr_assert_eq(accessor.get(), snes.cpu.get());
}
Test(BusAccessor, GetCPUEnd)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x00421F);
- cr_assert_eq(accessor.get(), pair.second.cpu.get());
+ accessor = snes._bus->getAccessor(0x00421F);
+ cr_assert_eq(accessor.get(), snes.cpu.get());
}
Test(BusAccessor, GetPPU1Start)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x00213E);
- cr_assert_eq(accessor.get(), pair.second.ppu.get());
+ accessor = snes._bus->getAccessor(0x00213E);
+ cr_assert_eq(accessor.get(), snes.ppu.get());
}
Test(BusAccessor, GetPPU1End)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x00213F);
- cr_assert_eq(accessor.get(), pair.second.ppu.get());
+ accessor = snes._bus->getAccessor(0x00213F);
+ cr_assert_eq(accessor.get(), snes.ppu.get());
}
Test(BusAccessor, GetCPU)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x004212);
- cr_assert_eq(accessor.get(), pair.second.cpu.get());
+ accessor = snes._bus->getAccessor(0x004212);
+ cr_assert_eq(accessor.get(), snes.cpu.get());
}
Test(BusAccessor, GetPPU1Mirror)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x80213F));
- cr_assert_eq(accessor->_initial.get(), pair.second.ppu.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x80213F));
+ cr_assert_eq(accessor->_initial.get(), snes.ppu.get());
}
Test(BusAccessor, GetCPU2Mirror)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x804212));
- cr_assert_eq(accessor->_initial.get(), pair.second.cpu.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x804212));
+ cr_assert_eq(accessor->_initial.get(), snes.cpu.get());
}
Test(BusAccessor, GetRomStart)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0x808000);
- cr_assert_eq(accessor.get(), pair.second.cartridge.get());
+ accessor = snes._bus->getAccessor(0x808000);
+ cr_assert_eq(accessor.get(), snes.cartridge.get());
}
Test(BusAccessor, GetRomEnd)
{
- auto pair = Init();
- std::shared_ptr accessor = nullptr;
+ Init()
+ std::shared_ptr accessor = nullptr;
- accessor = pair.first->getAccessor(0xFFFFFF);
- cr_assert_eq(accessor.get(), pair.second.cartridge.get());
+ accessor = snes._bus->getAccessor(0xFFFFFF);
+ cr_assert_eq(accessor.get(), snes.cartridge.get());
}
Test(BusAccessor, GetRomMirror)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x694200));
- cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x694200));
+ cr_assert_eq(accessor->_initial.get(), snes.cartridge.get());
}
Test(BusAccessor, GetRomMirror2)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x01FEDC));
- cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x01FEDC));
+ cr_assert_eq(accessor->_initial.get(), snes.cartridge.get());
}
Test(BusAccessor, GetRomMirror3)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0xDE1248));
- cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0xDE1248));
+ cr_assert_eq(accessor->_initial.get(), snes.cartridge.get());
}
Test(BusAccessor, Get0x0)
{
- auto pair = Init();
+ Init()
std::shared_ptr accessor = nullptr;
- accessor = std::static_pointer_cast(pair.first->getAccessor(0x0));
- cr_assert_eq(accessor->_initial.get(), pair.second.wram.get());
+ accessor = std::static_pointer_cast(snes._bus->getAccessor(0x0));
+ cr_assert_eq(accessor->_initial.get(), snes.wram.get());
}
///////////////////////////
@@ -278,132 +267,132 @@ Test(BusAccessor, Get0x0)
Test(BusRead, Read0x0)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.wram->_data[0] = 123;
- data = pair.first->read(0x0);
+ snes.wram->_data[0] = 123;
+ data = snes._bus->read(0x0);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadOutside, .init = cr_redirect_stdout)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.first->_openBus = 123;
- data = pair.first->read(0x002000);
+ snes._bus->_openBus = 123;
+ data = snes._bus->read(0x002000);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadOutside2, .init = cr_redirect_stdout)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.first->_openBus = 123;
- data = pair.first->read(0xBF2FFF);
+ snes._bus->_openBus = 123;
+ data = snes._bus->read(0xBF2FFF);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadOutside3, .init = cr_redirect_stdout)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.first->_openBus = 123;
- data = pair.first->read(0x127654);
+ snes._bus->_openBus = 123;
+ data = snes._bus->read(0x127654);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadAPU)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.apu->_registers.port0 = 123;
- data = pair.first->read(0x002140);
+ snes.apu->_registers.port0 = 123;
+ data = snes._bus->read(0x002140);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadROM)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.cartridge->_data[5] = 123;
- data = pair.first->read(0x808005);
+ snes.cartridge->_data[5] = 123;
+ data = snes._bus->read(0x808005);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadROMStart)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.cartridge->_data[0] = 123;
- data = pair.first->read(0x808000);
+ snes.cartridge->_data[0] = 123;
+ data = snes._bus->read(0x808000);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadCPU)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.cpu->_internalRegisters.wrio = 123;
- data = pair.first->read(0x004201);
+ snes.cpu->_internalRegisters.wrio = 123;
+ data = snes._bus->read(0x004201);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadPPU)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.ppu->mpy.mpyl = 123;
- data = pair.first->read(0x002134);
+ snes.ppu->mpy.mpyl = 123;
+ data = snes._bus->read(0x002134);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadSRAM)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.sram->_data[7] = 123;
- data = pair.first->read(0x700007);
+ snes.sram->_data[7] = 123;
+ data = snes._bus->read(0x700007);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadWRAM)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.wram->_data[3] = 123;
- data = pair.first->read(0x7E0003);
+ snes.wram->_data[3] = 123;
+ data = snes._bus->read(0x7E0003);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadWRAM2)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.wram->_data[0x1010] = 123;
- data = pair.first->read(0x7E1010);
+ snes.wram->_data[0x1010] = 123;
+ data = snes._bus->read(0x7E1010);
cr_assert_eq(data, 123);
}
Test(BusRead, ReadWRAMMirror)
{
- auto pair = Init();
+ Init()
uint8_t data;
- pair.second.wram->_data[0x1010] = 123;
- data = pair.first->read(0x1010);
+ snes.wram->_data[0x1010] = 123;
+ data = snes._bus->read(0x1010);
cr_assert_eq(data, 123);
}
@@ -415,60 +404,60 @@ Test(BusRead, ReadWRAMMirror)
Test(BusWrite, Write0x0)
{
- auto pair = Init();
+ Init()
try {
- pair.first->write(0x0, 123);
+ snes._bus->write(0x0, 123);
} catch (std::exception &ex) {
std::cout << ex.what() << std::endl;
}
- cr_assert_eq(pair.second.wram->_data[0], 123);
+ cr_assert_eq(snes.wram->_data[0], 123);
}
Test(BusWrite, WriteAPU)
{
- auto pair = Init();
+ Init()
- pair.first->write(0x002143, 123);
- cr_assert_eq(pair.second.apu->_registers.port3, 123);
+ snes._bus->write(0x002143, 123);
+ cr_assert_eq(snes.apu->_registers.port3, 123);
}
Test(BusWrite, WritePPU)
{
- auto pair = Init();
+ Init()
- pair.first->write(0x002106, 123);
- cr_assert_eq(pair.second.ppu->_mosaic.raw, 123);
+ snes._bus->write(0x002106, 123);
+ cr_assert_eq(snes.ppu->_mosaic.raw, 123);
}
Test(BusWrite, WriteCPU)
{
- auto pair = Init();
+ Init()
- pair.first->write(0x00420D, 123);
- cr_assert_eq(pair.second.cpu->_internalRegisters.memsel, 123);
+ snes._bus->write(0x00420D, 123);
+ cr_assert_eq(snes.cpu->_internalRegisters.memsel, 123);
}
Test(BusWrite, WriteROM)
{
- auto pair = Init();
+ Init()
- cr_assert_throw(pair.first->write(0x808005, 123), InvalidAction);
+ cr_assert_throw(snes._bus->write(0x808005, 123), InvalidAction);
}
Test(BusWrite, WriteWRAM)
{
- auto pair = Init();
+ Init()
- pair.first->write(0x7E0002, 123);
- cr_assert_eq(pair.second.wram->_data[2], 123);
+ snes._bus->write(0x7E0002, 123);
+ cr_assert_eq(snes.wram->_data[2], 123);
}
Test(BusWrite, WriteSRAM)
{
- auto pair = Init();
+ Init()
- pair.first->write(0x700009, 123);
- cr_assert_eq(pair.second.sram->_data[9], 123);
+ snes._bus->write(0x700009, 123);
+ cr_assert_eq(snes.sram->_data[9], 123);
}
\ No newline at end of file
diff --git a/tests/tests.cpp b/tests/tests.cpp
deleted file mode 100644
index 5864663..0000000
--- a/tests/tests.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Created by anonymus-raccoon on 2/10/20.
-//
-
-#include
-#include
-#include
-#include "tests.hpp"
-#include "../sources/Renderer/NoRenderer.hpp"
-#include "../sources/SNES.hpp"
-
-using namespace ComSquare;
-
-std::pair, SNES> Init()
-{
- Renderer::NoRenderer norenderer(0, 0, 0);
- SNES snes("../tests/my_cartridge", norenderer);
- snes.cartridge->_size = 100;
- snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
- snes.cartridge->header.mappingMode = Cartridge::LoRom;
- snes.sram->_size = 100;
- snes.sram->_data = new uint8_t[snes.cartridge->_size];
- return std::make_pair(snes._bus, snes);
-}
\ No newline at end of file
diff --git a/tests/tests.hpp b/tests/tests.hpp
index 3c33198..b37f81a 100644
--- a/tests/tests.hpp
+++ b/tests/tests.hpp
@@ -10,6 +10,20 @@
#define class struct
#include "../sources/Memory/MemoryBus.hpp"
-std::pair, ComSquare::SNES> Init();
+#include
+#include
+#include
+#include "tests.hpp"
+#include "../sources/Renderer/NoRenderer.hpp"
+#include "../sources/SNES.hpp"
+
+#define Init() \
+ Renderer::NoRenderer norenderer(0, 0, 0); \
+ SNES snes("../tests/my_cartridge", norenderer); \
+ snes.cartridge->_size = 100; \
+ snes.cartridge->_data = new uint8_t[snes.cartridge->_size]; \
+ snes.cartridge->header.mappingMode = Cartridge::LoRom; \
+ snes.sram->_size = 100; \
+ snes.sram->_data = new uint8_t[snes.cartridge->_size];
#endif //COMSQUARE_TESTS_HPP
diff --git a/ui/busView.ui b/ui/busView.ui
index 2b700d8..5185e76 100644
--- a/ui/busView.ui
+++ b/ui/busView.ui
@@ -11,363 +11,378 @@
- MainWindow
+ Memory Bus Logger
+
+
+
+ :/resources/Logo.png:/resources/Logo.png
-
-
-
- 0
- 0
- 901
- 621
-
-
-
- Qt::Horizontal
-
-
-
-
- QFrame::StyledPanel
-
-
- QFrame::Sunken
-
-
- 3
-
-
- 2
-
-
- -
-
-
- Filters
-
-
-
-
-
-
- Read from
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
- false
-
-
-
-
-
-
- CPU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- APU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- PPU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- ROM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- WRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- SRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- VRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- OAM RAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- CG RAM
-
-
-
- -
-
-
- true
-
-
-
-
-
-
- -
-
-
- Write to
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
- false
-
-
-
-
-
-
- CPU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- APU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- PPU
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- ROM
-
-
-
- -
-
-
- false
-
-
- true
-
-
- false
-
-
- false
-
-
-
- -
-
-
- WRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- SRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- VRAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- OAM RAM
-
-
-
- -
-
-
- true
-
-
-
- -
-
-
- CG RAM
-
-
-
- -
-
-
- true
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
- Clear
-
-
- false
-
-
-
- -
-
-
-
-
-
-
-
-
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Qt::Horizontal
+
+
+
+
+ 1
+ 0
+
+
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Sunken
+
+
+ 3
+
+
+ 2
+
+
+
-
+
+
+ Filters
+
+
+
-
+
+
+ Read from
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+ false
+
+
+
-
+
+
+ CPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ APU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ PPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ ROM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ WRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ SRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ VRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ OAM RAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ CG RAM
+
+
+
+ -
+
+
+ true
+
+
+
+
+
+
+ -
+
+
+ Write to
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+ false
+
+
+
-
+
+
+ CPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ APU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ PPU
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ ROM
+
+
+
+ -
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+ -
+
+
+ WRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ SRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ VRAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ OAM RAM
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ CG RAM
+
+
+
+ -
+
+
+ true
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
-
+
+
+ Clear
+
+
+ false
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
-
+
+
+
From 51ddb1f1cb0a7abbe44fcb56e1ff89c1f634ceb5 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 02:56:46 +0100
Subject: [PATCH 06/14] Making the internal logger work
---
sources/Debugger/MemoryBusDebug.cpp | 29 +++++++++++++++++++++++++++--
sources/Debugger/MemoryBusDebug.hpp | 10 ++++++----
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 3c16a07..886c694 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -5,6 +5,8 @@
#include "MemoryBusDebug.hpp"
#include "../SNES.hpp"
#include "../Utility/Utility.hpp"
+#include "../Exceptions/InvalidAction.hpp"
+#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::Debugger
{
@@ -46,13 +48,29 @@ namespace ComSquare::Debugger
uint8_t MemoryBusDebug::read(uint24_t addr)
{
+ auto accessor = this->getAccessor(addr);
+ uint8_t value = accessor->read(addr - accessor->getStart());
+ this->_model.log(BusLog(false, addr, accessor, value, value));
+
return MemoryBus::read(addr);
}
void MemoryBusDebug::write(uint24_t addr, uint8_t data)
{
+ auto accessor = this->getAccessor(addr);
+ uint8_t value;
+ try {
+ value = accessor->read(addr - accessor->getStart());
+ } catch (InvalidAddress &) {
+ value = 0;
+ }
+ this->_model.log(BusLog(true, addr, accessor, value, data));
MemoryBus::write(addr, data);
}
+
+ BusLog::BusLog(bool write, uint24_t addr, std::shared_ptr &accessor, uint8_t oldData, uint8_t newData) :
+ write(write), addr(addr), accessor(accessor), oldData(oldData), newData(newData)
+ {}
}
int BusLogModel::rowCount(const QModelIndex &) const
@@ -78,9 +96,9 @@ QVariant BusLogModel::data(const QModelIndex &index, int role) const
case 1:
return QString(ComSquare::Utility::to_hex(log.addr).c_str());
case 2:
- return QString(log.accessor.getName().c_str());
+ return QString(log.accessor->getName().c_str());
case 3:
- return QString(log.accessor.getValueName(log.addr - log.accessor.getStart()).c_str());
+ return QString(log.accessor->getValueName(log.addr - log.accessor->getStart()).c_str());
case 4:
return QString(ComSquare::Utility::to_hex(log.oldData).c_str());
case 5:
@@ -111,3 +129,10 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r
return QString("");
}
}
+
+void BusLogModel::log(ComSquare::Debugger::BusLog log)
+{
+ this->_logs.push_back(log);
+ this->insertRow(this->_logs.size());
+ // The row may be inserted but items are not displayed.
+}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 6d9bcb5..8146c0e 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -14,9 +14,11 @@ namespace ComSquare::Debugger
{
//! @brief The struct used to represent memory bus logs.
struct BusLog {
+ BusLog(bool write, uint24_t addr, std::shared_ptr &accessor, uint8_t oldData, uint8_t newData);
+
bool write;
uint24_t addr;
- Memory::AMemory &accessor;
+ std::shared_ptr &accessor;
uint8_t oldData;
uint8_t newData;
};
@@ -36,6 +38,9 @@ public:
const BusLogModel &operator=(const BusLogModel &) = delete;
~BusLogModel() override = default;
+ //! @brief Add a log to the model
+ void log(ComSquare::Debugger::BusLog log);
+
//! @brief The number of row the table has.
int rowCount(const QModelIndex &parent) const override;
//! @brief The number of column the table has.
@@ -60,9 +65,6 @@ namespace ComSquare::Debugger
Ui::BusView _ui;
//! @brief The Log visualizer model for QT.
BusLogModel _model;
-
- //! @brief Log a read/write to the debugger.
-// void log()
public:
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
void disableViewer();
From 189be63638918146bad0ced7d44b10449e180e5a Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 13:17:23 +0100
Subject: [PATCH 07/14] Finishing a basic logger
---
sources/Debugger/MemoryBusDebug.cpp | 14 ++++++++------
sources/Debugger/MemoryBusDebug.hpp | 4 +++-
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 886c694..33a3b89 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -68,8 +68,8 @@ namespace ComSquare::Debugger
MemoryBus::write(addr, data);
}
- BusLog::BusLog(bool write, uint24_t addr, std::shared_ptr &accessor, uint8_t oldData, uint8_t newData) :
- write(write), addr(addr), accessor(accessor), oldData(oldData), newData(newData)
+ BusLog::BusLog(bool _write, uint24_t _addr, std::shared_ptr &_accessor, uint8_t _oldData, uint8_t _newData) :
+ write(_write), addr(_addr), accessor(std::move(_accessor)), oldData(_oldData), newData(_newData)
{}
}
@@ -80,7 +80,7 @@ int BusLogModel::rowCount(const QModelIndex &) const
int BusLogModel::columnCount(const QModelIndex &) const
{
- return 5;
+ return this->_columnCount;
}
QVariant BusLogModel::data(const QModelIndex &index, int role) const
@@ -96,9 +96,9 @@ QVariant BusLogModel::data(const QModelIndex &index, int role) const
case 1:
return QString(ComSquare::Utility::to_hex(log.addr).c_str());
case 2:
- return QString(log.accessor->getName().c_str());
+ return QString(log.accessor ? log.accessor->getName().c_str() : "Bus");
case 3:
- return QString(log.accessor->getValueName(log.addr - log.accessor->getStart()).c_str());
+ return QString(log.accessor ? log.accessor->getValueName(log.addr - log.accessor->getStart()).c_str() : "Open bus");
case 4:
return QString(ComSquare::Utility::to_hex(log.oldData).c_str());
case 5:
@@ -133,6 +133,8 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r
void BusLogModel::log(ComSquare::Debugger::BusLog log)
{
this->_logs.push_back(log);
- this->insertRow(this->_logs.size());
+ int row = this->_logs.size();
+ this->insertRow(row);
+ emit this->layoutChanged();
// The row may be inserted but items are not displayed.
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 8146c0e..9c2dc9e 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -18,7 +18,7 @@ namespace ComSquare::Debugger
bool write;
uint24_t addr;
- std::shared_ptr &accessor;
+ std::shared_ptr accessor;
uint8_t oldData;
uint8_t newData;
};
@@ -32,6 +32,8 @@ Q_OBJECT
private:
//! @brief The logs to display.
std::vector _logs;
+ //! @brief The number of column;
+ const int _columnCount = 6;
public:
BusLogModel() = default;
BusLogModel(const BusLogModel &) = delete;
From a3c406db9d0165d88d4d6510661faf9424a304cb Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 14:19:03 +0100
Subject: [PATCH 08/14] Adding a proxy to filter logs, it's still a bit
unstable and not linked to checkboxes but it works
---
sources/Debugger/MemoryBusDebug.cpp | 27 ++++++++++++++---
sources/Debugger/MemoryBusDebug.hpp | 47 +++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 33a3b89..fa02651 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -15,18 +15,20 @@ namespace ComSquare::Debugger
_window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
_snes(snes),
_ui(),
- _model()
+ _model(),
+ _proxy(this->_model)
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
this->_window->setAttribute(Qt::WA_DeleteOnClose);
this->_ui.setupUi(this->_window);
- this->_ui.log->setModel(&this->_model);
+ this->_proxy.setSourceModel(&this->_model);
+ this->_ui.log->setModel(&this->_proxy);
this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
this->_ui.log->horizontalHeader()->setStretchLastSection(true);
this->_ui.log->horizontalHeader()->setSectionsMovable(true);
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < this->_model.column; i++)
this->_ui.log->setColumnWidth(i, this->_ui.log->width());
this->_window->show();
}
@@ -80,7 +82,7 @@ int BusLogModel::rowCount(const QModelIndex &) const
int BusLogModel::columnCount(const QModelIndex &) const
{
- return this->_columnCount;
+ return this->column;
}
QVariant BusLogModel::data(const QModelIndex &index, int role) const
@@ -136,5 +138,20 @@ void BusLogModel::log(ComSquare::Debugger::BusLog log)
int row = this->_logs.size();
this->insertRow(row);
emit this->layoutChanged();
- // The row may be inserted but items are not displayed.
+}
+
+ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
+{
+ return this->_logs[index];
+}
+
+BusLoggerProxy::BusLoggerProxy(BusLogModel &parent) : QSortFilterProxyModel(), _parent(parent) {}
+
+bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
+
+ if (log.accessor && log.accessor->getName() == "Cartridge")
+ return false;
+ return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 9c2dc9e..c90baf6 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -6,6 +6,7 @@
#define COMSQUARE_MEMORYBUSDEBUG_HPP
#include
+#include
#include "../Memory/MemoryBus.hpp"
#include "../../ui/ui_busView.h"
#include "ClosableWindow.hpp"
@@ -22,27 +23,44 @@ namespace ComSquare::Debugger
uint8_t oldData;
uint8_t newData;
};
+
+ //! @brief The struct representing filters of the memory bus's logger.
+ struct BusLoggerFilters {
+ bool cpu = true;
+ bool apu = true;
+ bool ppu = true;
+ bool rom = true;
+ bool wram = true;
+ bool sram = true;
+ bool vram = true;
+ bool oamram = true;
+ bool cgram = true;
+ };
}
//! @brief The qt model that bind the logs to the view.
class BusLogModel : public QAbstractTableModel
{
-Q_OBJECT
+ Q_OBJECT
private:
//! @brief The logs to display.
std::vector _logs;
- //! @brief The number of column;
- const int _columnCount = 6;
public:
BusLogModel() = default;
BusLogModel(const BusLogModel &) = delete;
const BusLogModel &operator=(const BusLogModel &) = delete;
~BusLogModel() override = default;
+ //! @brief The number of column;
+ const int column = 6;
+
//! @brief Add a log to the model
void log(ComSquare::Debugger::BusLog log);
+ //! @brief Get a log at an index.
+ ComSquare::Debugger::BusLog getLogAt(int index);
+
//! @brief The number of row the table has.
int rowCount(const QModelIndex &parent) const override;
//! @brief The number of column the table has.
@@ -53,6 +71,27 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
};
+//! @brief A class to filter logs from the memory bus's debugger.
+class BusLoggerProxy : public QSortFilterProxyModel {
+ Q_OBJECT
+private:
+ //! @brief The parent to get the original data for filters
+ BusLogModel &_parent;
+protected:
+ //! @brief Function that filter logs.
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+public:
+ //! @brief Currently enabled read filters
+ ComSquare::Debugger::BusLoggerFilters readFilters = ComSquare::Debugger::BusLoggerFilters();
+ //! @brief Currently enabled write filters
+ ComSquare::Debugger::BusLoggerFilters writeFilters = ComSquare::Debugger::BusLoggerFilters();
+
+ BusLoggerProxy(BusLogModel &parent);
+ BusLoggerProxy(const BusLoggerProxy &) = delete;
+ const BusLoggerProxy &operator=(const BusLoggerProxy &) = delete;
+ ~BusLoggerProxy() override = default;
+};
+
namespace ComSquare::Debugger
{
@@ -67,6 +106,8 @@ namespace ComSquare::Debugger
Ui::BusView _ui;
//! @brief The Log visualizer model for QT.
BusLogModel _model;
+ //! @brief A QT proxy to filter the logs.
+ BusLoggerProxy _proxy;
public:
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
void disableViewer();
From 256fea8955687bf83eeb127dceb48e5d3ca6b3e2 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 19:25:33 +0100
Subject: [PATCH 09/14] Making the CPU debugger's bus read silent
---
sources/Debugger/CPUDebug.cpp | 34 ++++++++++++++---------------
sources/Debugger/MemoryBusDebug.cpp | 20 +++++++++--------
sources/Debugger/MemoryBusDebug.hpp | 2 +-
sources/Memory/MemoryBus.cpp | 2 +-
sources/Memory/MemoryBus.hpp | 3 ++-
5 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index 30a86ad..df2108a 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -45,6 +45,8 @@ namespace ComSquare::Debugger
try {
if (this->_isPaused)
return 0xFF;
+ if (this->_isStepping)
+ return this->_executeInstruction(this->_bus->read(this->_registers.pac++));
return CPU::update();
} catch (InvalidOpcode &e) {
if (!this->_isPaused)
@@ -55,10 +57,6 @@ namespace ComSquare::Debugger
unsigned CPUDebug::_executeInstruction(uint8_t opcode)
{
- if (this->_isPaused) {
- this->_registers.pac--;
- return 0;
- }
if (this->_isStepping) {
this->_isStepping = false;
this->_isPaused = true;
@@ -130,10 +128,10 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValueForA(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
if (!this->_registers.p.m)
- value += this->_bus->read(pc + 1) << 8u;
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
return ss.str();
@@ -141,10 +139,10 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValueForX(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
if (!this->_registers.p.x_b)
- value += this->_bus->read(pc + 1) << 8u;
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
return ss.str();
@@ -153,14 +151,14 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValue8Bits(uint24_t pc)
{
std::stringstream ss;
- ss << "#$" << std::hex << static_cast(this->_bus->read(pc));
+ ss << "#$" << std::hex << static_cast(this->_bus->read(pc), true);
return ss.str();
}
std::string CPUDebug::_getImmediateValue16Bits(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
- value += this->_bus->read(pc + 1) << 8u;
+ unsigned value = this->_bus->read(pc, true);
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
@@ -170,22 +168,22 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getDirectValue(uint24_t pc)
{
std::stringstream ss;
- ss << "$" << std::hex << static_cast(this->_bus->read(pc));
+ ss << "$" << std::hex << static_cast(this->_bus->read(pc), true);
return ss.str();
}
std::string CPUDebug::_getAbsoluteValue(uint24_t pc)
{
std::stringstream ss;
- ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u));
+ ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u), true);
return ss.str();
}
std::string CPUDebug::_getAbsoluteLongValue(uint24_t pc)
{
- unsigned value = this->_bus->read(pc++);
- value += this->_bus->read(pc++) << 8u;
- value += this->_bus->read(pc) << 16u;
+ unsigned value = this->_bus->read(pc++, true);
+ value += this->_bus->read(pc++, true) << 8u;
+ value += this->_bus->read(pc, true) << 16u;
std::stringstream ss;
ss << "$" << std::hex << value;
@@ -194,7 +192,7 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getDirectIndexedByXValue(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
std::stringstream ss;
ss << "$" << std::hex << value << ", x";
@@ -203,7 +201,7 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getInstructionString(uint24_t pc)
{
- uint8_t opcode = this->_bus->read(pc++);
+ uint8_t opcode = this->_bus->read(pc++, true);
switch (opcode) {
case Instructions::BRK: return "BRK";
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index fa02651..18bad54 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -48,12 +48,13 @@ namespace ComSquare::Debugger
return true;
}
- uint8_t MemoryBusDebug::read(uint24_t addr)
+ uint8_t MemoryBusDebug::read(uint24_t addr, bool silence)
{
- auto accessor = this->getAccessor(addr);
- uint8_t value = accessor->read(addr - accessor->getStart());
- this->_model.log(BusLog(false, addr, accessor, value, value));
-
+ if (!silence) {
+ auto accessor = this->getAccessor(addr);
+ uint8_t value = accessor->read(addr - accessor->getStart());
+ this->_model.log(BusLog(false, addr, accessor, value, value));
+ }
return MemoryBus::read(addr);
}
@@ -134,10 +135,11 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r
void BusLogModel::log(ComSquare::Debugger::BusLog log)
{
- this->_logs.push_back(log);
int row = this->_logs.size();
+ this->beginInsertRows(QModelIndex(), row, row);
+ this->_logs.push_back(log);
this->insertRow(row);
- emit this->layoutChanged();
+ this->endInsertRows();
}
ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
@@ -151,7 +153,7 @@ bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePa
{
ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
- if (log.accessor && log.accessor->getName() == "Cartridge")
- return false;
+// if (log.accessor && log.accessor->getName() == "Cartridge")
+// return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index c90baf6..61a74d9 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -120,7 +120,7 @@ namespace ComSquare::Debugger
//! @brief Read data at a global address and log it to the debugger.
//! @param addr The address to read from.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
- uint8_t read(uint24_t addr) override;
+ uint8_t read(uint24_t addr, bool silence = false) override;
//! @brief Write a data to a global address and log it to the debugger.
//! @param addr The address to write to.
diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp
index 5f8a252..12a0391 100644
--- a/sources/Memory/MemoryBus.cpp
+++ b/sources/Memory/MemoryBus.cpp
@@ -22,7 +22,7 @@ namespace ComSquare::Memory
return *it;
}
- uint8_t MemoryBus::read(uint24_t addr)
+ uint8_t MemoryBus::read(uint24_t addr, bool)
{
std::shared_ptr handler = this->getAccessor(addr);
diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp
index 5647ac4..983ebfd 100644
--- a/sources/Memory/MemoryBus.hpp
+++ b/sources/Memory/MemoryBus.hpp
@@ -38,8 +38,9 @@ namespace ComSquare
//! @brief Read data at a global address.
//! @param addr The address to read from.
+ //! @param silence Disable login to the memory bus's debugger (if enabled). Should only be used by other debuggers.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
- virtual uint8_t read(uint24_t addr);
+ virtual uint8_t read(uint24_t addr, bool silence = false);
//! @brief Write a data to a global address.
//! @param addr The address to write to.
From 40f843da7563fa45afc9fbd3bfc9ffd1eae36894 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 21:06:54 +0100
Subject: [PATCH 10/14] Adding filters
---
CMakeLists.txt | 4 +-
sources/APU/APU.cpp | 18 ++++-
sources/APU/APU.hpp | 3 +
sources/APU/DSP/DSP.cpp | 5 ++
sources/APU/DSP/DSP.hpp | 3 +
sources/APU/Instructions/Subroutine.cpp | 5 --
sources/CPU/CPU.cpp | 10 +++
sources/CPU/CPU.hpp | 4 +
.../CPU/Instructions/InternalInstruction.cpp | 5 --
sources/Cartridge/Cartridge.cpp | 2 +-
sources/Debugger/MemoryBusDebug.cpp | 80 ++++++++++++++++++-
sources/Debugger/MemoryBusDebug.hpp | 6 +-
sources/Memory/AMemory.hpp | 3 +
sources/Memory/MemoryShadow.cpp | 5 ++
sources/Memory/MemoryShadow.hpp | 2 +
sources/Memory/RectangleShadow.cpp | 5 ++
sources/Memory/RectangleShadow.hpp | 2 +
sources/PPU/PPU.cpp | 5 ++
sources/PPU/PPU.hpp | 2 +
sources/Ram/Ram.cpp | 8 +-
sources/Ram/Ram.hpp | 7 +-
sources/SNES.cpp | 4 +-
22 files changed, 160 insertions(+), 28 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c9aa11d..9589780 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,7 +79,7 @@ add_executable(unit_tests
sources/CPU/Instructions/TransferRegisters.cpp
tests/CPU/TransferRegisters.cpp
sources/CPU/AddressingModes.cpp
-)
+ sources/Models/Components.hpp)
# include criterion & coverage
target_link_libraries(unit_tests criterion -lgcov)
@@ -174,7 +174,7 @@ add_executable(ComSquare
sources/Debugger/MemoryBusDebug.cpp
sources/Debugger/MemoryBusDebug.hpp
sources/Debugger/ClosableWindow.hpp
-)
+ sources/Models/Components.hpp)
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp
index 9b97357..c12542c 100644
--- a/sources/APU/APU.cpp
+++ b/sources/APU/APU.cpp
@@ -23,6 +23,16 @@ namespace ComSquare::APU
return false;
}
+ std::string APU::getName()
+ {
+ return "APU";
+ }
+
+ Component APU::getComponent()
+ {
+ return Apu;
+ }
+
uint8_t APU::_internalRead(uint24_t addr) {
switch (addr) {
case 0x0000 ... 0x00EF:
@@ -359,10 +369,10 @@ namespace ComSquare::APU
}
MemoryMap::MemoryMap() :
- Page0(0x00F0, "APU's Page 0"),
- Page1(0x0100, "APU's Page 1"),
- Memory(0xFDC0, "APU's Ram"),
- IPL(0x0040, "IPL Rom")
+ Page0(0x00F0, Apu, "APU's Page 0"),
+ Page1(0x0100, Apu, "APU's Page 1"),
+ Memory(0xFDC0, Apu, "APU's Ram"),
+ IPL(0x0040, Apu, "IPL Rom")
{
}
diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp
index 0e58ad3..1d22ec3 100644
--- a/sources/APU/APU.hpp
+++ b/sources/APU/APU.hpp
@@ -158,6 +158,9 @@ namespace ComSquare::APU
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
+
//! @brief Current state of APU CPU
StateMode _state = Running;
diff --git a/sources/APU/DSP/DSP.cpp b/sources/APU/DSP/DSP.cpp
index 1b895c7..421826e 100644
--- a/sources/APU/DSP/DSP.cpp
+++ b/sources/APU/DSP/DSP.cpp
@@ -593,4 +593,9 @@ namespace ComSquare::APU::DSP
{
return "DSP";
}
+
+ Component DSP::getComponent()
+ {
+ return Apu;
+ }
}
\ No newline at end of file
diff --git a/sources/APU/DSP/DSP.hpp b/sources/APU/DSP/DSP.hpp
index 9e25c6a..1676cd5 100644
--- a/sources/APU/DSP/DSP.hpp
+++ b/sources/APU/DSP/DSP.hpp
@@ -143,6 +143,9 @@ namespace ComSquare::APU::DSP
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
};
}
diff --git a/sources/APU/Instructions/Subroutine.cpp b/sources/APU/Instructions/Subroutine.cpp
index 3dcf2c3..34eb031 100644
--- a/sources/APU/Instructions/Subroutine.cpp
+++ b/sources/APU/Instructions/Subroutine.cpp
@@ -52,9 +52,4 @@ namespace ComSquare::APU
this->RET();
return 6;
}
-
- std::string APU::getName()
- {
- return "APU";
- }
}
\ No newline at end of file
diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp
index e4efc02..cfce0c8 100644
--- a/sources/CPU/CPU.cpp
+++ b/sources/CPU/CPU.cpp
@@ -413,4 +413,14 @@ namespace ComSquare::CPU
{
return this->_bus->read(++this->_registers.s) + (this->_bus->read(++this->_registers.s) << 8u);
}
+
+ std::string CPU::getName()
+ {
+ return "CPU";
+ }
+
+ Component CPU::getComponent()
+ {
+ return Cpu;
+ }
}
\ No newline at end of file
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index cdecf8b..84d613f 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -9,6 +9,7 @@
#include "../Memory/MemoryBus.hpp"
#include "../Models/Int24.hpp"
#include "../Cartridge/Cartridge.hpp"
+#include "../Memory/AMemory.hpp"
namespace ComSquare::CPU
{
@@ -573,6 +574,9 @@ namespace ComSquare::CPU
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
+
//! @brief Reset interrupt - Called on boot and when the reset button is pressed.
virtual void RESB();
diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp
index 3b3d5f6..6c16c0c 100644
--- a/sources/CPU/Instructions/InternalInstruction.cpp
+++ b/sources/CPU/Instructions/InternalInstruction.cpp
@@ -307,9 +307,4 @@ namespace ComSquare::CPU
{
this->_registers.pac = value;
}
-
- std::string CPU::getName()
- {
- return "CPU";
- }
}
\ No newline at end of file
diff --git a/sources/Cartridge/Cartridge.cpp b/sources/Cartridge/Cartridge.cpp
index 61ce1e0..227903a 100644
--- a/sources/Cartridge/Cartridge.cpp
+++ b/sources/Cartridge/Cartridge.cpp
@@ -13,7 +13,7 @@
namespace ComSquare::Cartridge
{
Cartridge::Cartridge(const std::string &romPath)
- : Ram::Ram(0, "Cartridge")
+ : Ram::Ram(0, Rom, "Cartridge")
{
try {
if (romPath.empty())
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 18bad54..d4065c8 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -30,6 +30,60 @@ namespace ComSquare::Debugger
this->_ui.log->horizontalHeader()->setSectionsMovable(true);
for (int i = 0; i < this->_model.column; i++)
this->_ui.log->setColumnWidth(i, this->_ui.log->width());
+
+ QMainWindow::connect(this->_ui.fromAPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].apu = checked;
+ });
+ QMainWindow::connect(this->_ui.fromCPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].cpu = checked;
+ });
+ QMainWindow::connect(this->_ui.fromOAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].oamram = checked;
+ });
+ QMainWindow::connect(this->_ui.fromPPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].ppu = checked;
+ });
+ QMainWindow::connect(this->_ui.fromROM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].rom = checked;
+ });
+ QMainWindow::connect(this->_ui.fromSRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].sram = checked;
+ });
+ QMainWindow::connect(this->_ui.fromVRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].vram = checked;
+ });
+ QMainWindow::connect(this->_ui.fromWRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].wram = checked;
+ });
+ QMainWindow::connect(this->_ui.fromCG, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[0].cgram = checked;
+ });
+
+ QMainWindow::connect(this->_ui.toAPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].apu = checked;
+ });
+ QMainWindow::connect(this->_ui.toCPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].cpu = checked;
+ });
+ QMainWindow::connect(this->_ui.toOAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].oamram = checked;
+ });
+ QMainWindow::connect(this->_ui.toPPU, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].ppu = checked;
+ });
+ QMainWindow::connect(this->_ui.toSRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].sram = checked;
+ });
+ QMainWindow::connect(this->_ui.toVRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].vram = checked;
+ });
+ QMainWindow::connect(this->_ui.toWRAM, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].wram = checked;
+ });
+ QMainWindow::connect(this->_ui.toCG, &QCheckBox::toggled, [this](bool checked) {
+ this->_proxy.filters[1].cgram = checked;
+ });
+
this->_window->show();
}
@@ -153,7 +207,27 @@ bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePa
{
ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
-// if (log.accessor && log.accessor->getName() == "Cartridge")
-// return false;
- return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
+ if (!log.accessor)
+ return true;
+ ComSquare::Component component = log.accessor->getComponent();
+ switch (component) {
+ case ComSquare::Component::Cpu:
+ return this->filters[log.write].cpu;
+ case ComSquare::Component::Ppu:
+ return this->filters[log.write].ppu;
+ case ComSquare::Component::Apu:
+ return this->filters[log.write].apu;
+ case ComSquare::Component::Rom:
+ return this->filters[log.write].rom;
+ case ComSquare::Component::WRam:
+ return this->filters[log.write].wram;
+ case ComSquare::Component::VRam:
+ return this->filters[log.write].vram;
+ case ComSquare::Component::CGRam:
+ return this->filters[log.write].cgram;
+ case ComSquare::Component::OAMRam:
+ return this->filters[log.write].oamram;
+ case ComSquare::Component::SRam:
+ return this->filters[log.write].sram;
+ }
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 61a74d9..55c993d 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -81,10 +81,8 @@ protected:
//! @brief Function that filter logs.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
public:
- //! @brief Currently enabled read filters
- ComSquare::Debugger::BusLoggerFilters readFilters = ComSquare::Debugger::BusLoggerFilters();
- //! @brief Currently enabled write filters
- ComSquare::Debugger::BusLoggerFilters writeFilters = ComSquare::Debugger::BusLoggerFilters();
+ //! @brief Currently enabled filters, index 0 is for reads, index 1 for writes.
+ ComSquare::Debugger::BusLoggerFilters filters[2] = {ComSquare::Debugger::BusLoggerFilters(), ComSquare::Debugger::BusLoggerFilters()};
BusLoggerProxy(BusLogModel &parent);
BusLoggerProxy(const BusLoggerProxy &) = delete;
diff --git a/sources/Memory/AMemory.hpp b/sources/Memory/AMemory.hpp
index ab2fd7b..5215436 100644
--- a/sources/Memory/AMemory.hpp
+++ b/sources/Memory/AMemory.hpp
@@ -10,6 +10,7 @@
#include
#include
#include "../Models/Int24.hpp"
+#include "../Models/Components.hpp"
namespace ComSquare::Memory
{
@@ -48,6 +49,8 @@ namespace ComSquare::Memory
virtual bool isMirror();
//! @brief Get the name of this accessor (used for debug purpose)
virtual std::string getName() = 0;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ virtual Component getComponent() = 0;
//! @brief Get the name of the data at the address
//! @param addr The address (in local space)
virtual std::string getValueName(uint24_t addr);
diff --git a/sources/Memory/MemoryShadow.cpp b/sources/Memory/MemoryShadow.cpp
index 246e7c6..ecc4b4f 100644
--- a/sources/Memory/MemoryShadow.cpp
+++ b/sources/Memory/MemoryShadow.cpp
@@ -38,4 +38,9 @@ namespace ComSquare::Memory
{
return this->_initial->getName();
}
+
+ Component MemoryShadow::getComponent()
+ {
+ return this->_initial->getComponent();
+ }
}
\ No newline at end of file
diff --git a/sources/Memory/MemoryShadow.hpp b/sources/Memory/MemoryShadow.hpp
index 673eaf3..7c33c43 100644
--- a/sources/Memory/MemoryShadow.hpp
+++ b/sources/Memory/MemoryShadow.hpp
@@ -36,6 +36,8 @@ namespace ComSquare::Memory
bool isMirror() override;
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
std::shared_ptr getMirrored() override;
diff --git a/sources/Memory/RectangleShadow.cpp b/sources/Memory/RectangleShadow.cpp
index f798389..9d924d4 100644
--- a/sources/Memory/RectangleShadow.cpp
+++ b/sources/Memory/RectangleShadow.cpp
@@ -47,4 +47,9 @@ namespace ComSquare::Memory
{
return this->_initial->getName();
}
+
+ Component RectangleShadow::getComponent()
+ {
+ return this->_initial->getComponent();
+ }
}
\ No newline at end of file
diff --git a/sources/Memory/RectangleShadow.hpp b/sources/Memory/RectangleShadow.hpp
index 756ab0d..d3130d9 100644
--- a/sources/Memory/RectangleShadow.hpp
+++ b/sources/Memory/RectangleShadow.hpp
@@ -39,6 +39,8 @@ namespace ComSquare::Memory
bool isMirror() override;
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
std::shared_ptr getMirrored() override;
diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp
index 9fd377e..5cc3aa8 100644
--- a/sources/PPU/PPU.cpp
+++ b/sources/PPU/PPU.cpp
@@ -249,4 +249,9 @@ namespace ComSquare::PPU
{
return "PPU";
}
+
+ Component PPU::getComponent()
+ {
+ return Ppu;
+ }
}
\ No newline at end of file
diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp
index ec0d8d4..0c64f3c 100644
--- a/sources/PPU/PPU.hpp
+++ b/sources/PPU/PPU.hpp
@@ -566,6 +566,8 @@ namespace ComSquare::PPU
void write(uint24_t addr, uint8_t data) override;
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
//! @brief Update the PPU of n cycles.
//! @param The number of cycles to update.
diff --git a/sources/Ram/Ram.cpp b/sources/Ram/Ram.cpp
index 320834e..100901d 100644
--- a/sources/Ram/Ram.cpp
+++ b/sources/Ram/Ram.cpp
@@ -9,8 +9,9 @@
namespace ComSquare::Ram
{
- Ram::Ram(size_t size, std::string ramName)
+ Ram::Ram(size_t size, Component type, std::string ramName)
: _size(size),
+ _ramType(type),
_ramName(std::move(ramName))
{
if (size == 0)
@@ -58,4 +59,9 @@ namespace ComSquare::Ram
{
return this->_ramName;
}
+
+ Component Ram::getComponent()
+ {
+ return this->_ramType;
+ }
}
diff --git a/sources/Ram/Ram.hpp b/sources/Ram/Ram.hpp
index 24b7f88..d9297e7 100644
--- a/sources/Ram/Ram.hpp
+++ b/sources/Ram/Ram.hpp
@@ -15,11 +15,13 @@ namespace ComSquare::Ram
uint8_t *_data;
//! @brief The size of the ram (iny bytes).
size_t _size;
+ //! @brief An id identifying the type of memory this is (for the debugger)
+ Component _ramType;
//! @brief The name of this ram.
std::string _ramName;
public:
//! @brief Create a ram of a given size in bytes.
- explicit Ram(size_t size, std::string ramName);
+ explicit Ram(size_t size, Component, std::string ramName);
//! @brief The ram can't be copied.
Ram(const Ram &) = delete;
//! @brief The ram can't be assigned.
@@ -46,6 +48,9 @@ namespace ComSquare::Ram
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
+ //! @brief Get the component of this accessor (used for debug purpose)
+ Component getComponent() override;
+
//! @brief Get the size of the ram in bytes.
size_t getSize();
};
diff --git a/sources/SNES.cpp b/sources/SNES.cpp
index 5cc42a8..3dc9674 100644
--- a/sources/SNES.cpp
+++ b/sources/SNES.cpp
@@ -17,8 +17,8 @@ namespace ComSquare
SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) :
_bus(std::make_shared()),
cartridge(new Cartridge::Cartridge(romPath)),
- wram(new Ram::Ram(16384, "WRam")),
- sram(new Ram::Ram(this->cartridge->header.sramSize, "SRam")),
+ wram(new Ram::Ram(16384, WRam, "WRam")),
+ sram(new Ram::Ram(this->cartridge->header.sramSize, SRam, "SRam")),
apuRam(new APU::MemoryMap()),
cpu(new CPU::CPU(this->_bus, cartridge->header)),
ppu(new PPU::PPU(renderer)),
From 031cea84dfe588ea9b0fa2b4cf7ed6fd1e4e4153 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 21:41:52 +0100
Subject: [PATCH 11/14] Implementing filter buttons
---
sources/Debugger/MemoryBusDebug.cpp | 22 ++++++++++++++++++++++
sources/Debugger/MemoryBusDebug.hpp | 5 ++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index d4065c8..2fe1ecd 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -33,55 +33,72 @@ namespace ComSquare::Debugger
QMainWindow::connect(this->_ui.fromAPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].apu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromCPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].cpu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromOAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].oamram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromPPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].ppu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromROM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].rom = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromSRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].sram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromVRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].vram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromWRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].wram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.fromCG, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[0].cgram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toAPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].apu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toCPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].cpu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toOAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].oamram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toPPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].ppu = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toSRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].sram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toVRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].vram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toWRAM, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].wram = checked;
+ this->_proxy.refresh();
});
QMainWindow::connect(this->_ui.toCG, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].cgram = checked;
+ this->_proxy.refresh();
});
this->_window->show();
@@ -231,3 +248,8 @@ bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePa
return this->filters[log.write].sram;
}
}
+
+void BusLoggerProxy::refresh()
+{
+ this->invalidateFilter();
+}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 55c993d..7432b7b 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -84,7 +84,10 @@ public:
//! @brief Currently enabled filters, index 0 is for reads, index 1 for writes.
ComSquare::Debugger::BusLoggerFilters filters[2] = {ComSquare::Debugger::BusLoggerFilters(), ComSquare::Debugger::BusLoggerFilters()};
- BusLoggerProxy(BusLogModel &parent);
+ //! @brief Refresh the view after a change of filters.
+ void refresh();
+
+ explicit BusLoggerProxy(BusLogModel &parent);
BusLoggerProxy(const BusLoggerProxy &) = delete;
const BusLoggerProxy &operator=(const BusLoggerProxy &) = delete;
~BusLoggerProxy() override = default;
From c007ce6feede9e78315076f613aed958ce984826 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 21:42:26 +0100
Subject: [PATCH 12/14] Oups
---
sources/Models/Components.hpp | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 sources/Models/Components.hpp
diff --git a/sources/Models/Components.hpp b/sources/Models/Components.hpp
new file mode 100644
index 0000000..4621fa6
--- /dev/null
+++ b/sources/Models/Components.hpp
@@ -0,0 +1,22 @@
+//
+// Created by anonymus-raccoon on 3/24/20.
+//
+
+#ifndef COMSQUARE_COMPONENTS_HPP
+#define COMSQUARE_COMPONENTS_HPP
+
+namespace ComSquare
+{
+ enum Component {
+ Cpu = 1u << 0u,
+ Ppu = 1u << 1u,
+ Apu = 1u << 2u,
+ Rom = 1u << 3u,
+ WRam = 1u << 4u,
+ VRam = 1u << 5u,
+ OAMRam = 1u << 6u,
+ CGRam = 1u << 7u,
+ SRam = 1u << 8u,
+ };
+}
+#endif //COMSQUARE_COMPONENTS_HPP
From 15aa1a7dde1a1797e1b67cecd3cfec52aeb5be8d Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 23:15:33 +0100
Subject: [PATCH 13/14] Implementing the clear button
---
sources/Debugger/MemoryBusDebug.cpp | 16 ++++++++++++++--
sources/Debugger/MemoryBusDebug.hpp | 4 +++-
ui/busView.ui | 2 +-
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 2fe1ecd..ef0fab9 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -101,6 +101,11 @@ namespace ComSquare::Debugger
this->_proxy.refresh();
});
+ QMainWindow::connect(this->_ui.clearBtn, &QPushButton::pressed, [this]() {
+ this->_model.clearLogs();
+ this->_proxy.refresh();
+ });
+
this->_window->show();
}
@@ -204,7 +209,7 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r
}
}
-void BusLogModel::log(ComSquare::Debugger::BusLog log)
+void BusLogModel::log(const ComSquare::Debugger::BusLog& log)
{
int row = this->_logs.size();
this->beginInsertRows(QModelIndex(), row, row);
@@ -218,9 +223,16 @@ ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
return this->_logs[index];
}
+void BusLogModel::clearLogs()
+{
+ this->beginResetModel();
+ this->_logs.clear();
+ this->endResetModel();
+}
+
BusLoggerProxy::BusLoggerProxy(BusLogModel &parent) : QSortFilterProxyModel(), _parent(parent) {}
-bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &) const
{
ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index 7432b7b..6f7ff3b 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -56,10 +56,12 @@ public:
const int column = 6;
//! @brief Add a log to the model
- void log(ComSquare::Debugger::BusLog log);
+ void log(const ComSquare::Debugger::BusLog& log);
//! @brief Get a log at an index.
ComSquare::Debugger::BusLog getLogAt(int index);
+ //! @brief Clear all the logs
+ void clearLogs();
//! @brief The number of row the table has.
int rowCount(const QModelIndex &parent) const override;
diff --git a/ui/busView.ui b/ui/busView.ui
index 5185e76..9b91312 100644
--- a/ui/busView.ui
+++ b/ui/busView.ui
@@ -359,7 +359,7 @@
-
-
+
Clear
From af58aca1a2b1878212de0ee305f910592980ea08 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Wed, 25 Mar 2020 00:17:51 +0100
Subject: [PATCH 14/14] Implementing the toogle all
---
sources/Debugger/MemoryBusDebug.cpp | 24 ++++++++++++++++++++++++
ui/busView.ui | 18 ++++++++++++++++--
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index ef0fab9..17314cd 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -67,6 +67,17 @@ namespace ComSquare::Debugger
this->_proxy.filters[0].cgram = checked;
this->_proxy.refresh();
});
+ QMainWindow::connect(this->_ui.fromToggle, &QPushButton::pressed, [this]() {
+ this->_ui.fromWRAM->setChecked(!this->_proxy.filters[0].wram);
+ this->_ui.fromCPU->setChecked(!this->_proxy.filters[0].cpu);
+ this->_ui.fromAPU->setChecked(!this->_proxy.filters[0].apu);
+ this->_ui.fromPPU->setChecked(!this->_proxy.filters[0].ppu);
+ this->_ui.fromVRAM->setChecked(!this->_proxy.filters[0].vram);
+ this->_ui.fromOAM->setChecked(!this->_proxy.filters[0].oamram);
+ this->_ui.fromCG->setChecked(!this->_proxy.filters[0].cgram);
+ this->_ui.fromROM->setChecked(!this->_proxy.filters[0].rom);
+ this->_ui.fromSRAM->setChecked(!this->_proxy.filters[0].sram);
+ });
QMainWindow::connect(this->_ui.toAPU, &QCheckBox::toggled, [this](bool checked) {
this->_proxy.filters[1].apu = checked;
@@ -105,6 +116,17 @@ namespace ComSquare::Debugger
this->_model.clearLogs();
this->_proxy.refresh();
});
+ QMainWindow::connect(this->_ui.toToggle, &QPushButton::pressed, [this]() {
+ this->_ui.toWRAM->setChecked(!this->_proxy.filters[1].wram);
+ this->_ui.toCPU->setChecked(!this->_proxy.filters[1].cpu);
+ this->_ui.toAPU->setChecked(!this->_proxy.filters[1].apu);
+ this->_ui.toPPU->setChecked(!this->_proxy.filters[1].ppu);
+ this->_ui.toVRAM->setChecked(!this->_proxy.filters[1].vram);
+ this->_ui.toOAM->setChecked(!this->_proxy.filters[1].oamram);
+ this->_ui.toCG->setChecked(!this->_proxy.filters[1].cgram);
+ this->_ui.toROM->setChecked(!this->_proxy.filters[1].rom);
+ this->_ui.toSRAM->setChecked(!this->_proxy.filters[1].sram);
+ });
this->_window->show();
}
@@ -258,6 +280,8 @@ bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &) const
return this->filters[log.write].oamram;
case ComSquare::Component::SRam:
return this->filters[log.write].sram;
+ default:
+ return true;
}
}
diff --git a/ui/busView.ui b/ui/busView.ui
index 9b91312..d2b5cb5 100644
--- a/ui/busView.ui
+++ b/ui/busView.ui
@@ -69,7 +69,7 @@
false
-
+
-
@@ -196,6 +196,13 @@
+ -
+
+
+ Toggle all
+
+
+
@@ -210,7 +217,7 @@
false
-
+
-
@@ -346,6 +353,13 @@
+ -
+
+
+ Toggle all
+
+
+