Compare commits
24
Commits
cd2673909c
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
301c9343da | ||
|
|
91884d65fb | ||
|
|
e566adad50 | ||
|
|
1c14228bf7 | ||
|
|
00ceacaf52 | ||
|
|
adb290a7c7 | ||
|
|
67539b6d43 | ||
|
|
7ed5c74faf | ||
|
|
f2a68e6294 | ||
|
|
5e6972e4da | ||
|
|
c0c592c438 | ||
|
|
900dbde54b | ||
|
|
16db21fcab | ||
|
|
d33de14694 | ||
|
|
80c68035c5 | ||
|
|
8f016b1095 | ||
|
|
869438e0e0 | ||
|
|
6943cfd684 | ||
|
|
fcfd27468d | ||
|
|
ce46f5033a | ||
|
|
5919f70537 | ||
|
|
136250355e | ||
|
|
66c10e3c3e | ||
|
|
7153b0e9b6 |
+3
-3
@@ -1,3 +1,3 @@
|
|||||||
[submodule "vendor/ruc"]
|
[submodule "vendor/inferno"]
|
||||||
path = vendor/ruc
|
path = vendor/inferno
|
||||||
url = https://github.com/riyyi/ruc
|
url = https://github.com/riyyi/inferno
|
||||||
|
|||||||
+15
-11
@@ -52,21 +52,28 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# Library
|
# Library
|
||||||
|
|
||||||
set(RUC_BUILD_TESTS OFF)
|
set(INFERNO_BUILD_EXAMPLES OFF)
|
||||||
add_subdirectory("vendor/ruc")
|
add_subdirectory("vendor/inferno")
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# Application target
|
# Application target
|
||||||
|
|
||||||
# Define source files
|
# Define source files
|
||||||
file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp")
|
file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp")
|
||||||
set(PROJECT_SOURCES ${PROJECT_SOURCES})
|
|
||||||
|
|
||||||
add_executable(${PROJECT} ${PROJECT_SOURCES})
|
add_executable(${PROJECT} ${PROJECT_SOURCES})
|
||||||
target_include_directories(${PROJECT} PRIVATE
|
target_include_directories(${PROJECT} PRIVATE
|
||||||
"src"
|
"src")
|
||||||
"vendor/ruc/src")
|
target_link_libraries(${PROJECT} inferno)
|
||||||
target_link_libraries(${PROJECT} ruc)
|
|
||||||
|
# ------------------------------------------
|
||||||
|
# Assets target
|
||||||
|
|
||||||
|
add_custom_target(${PROJECT}-assets
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/copy-assets.cmake
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
add_dependencies(${PROJECT} ${PROJECT}-assets)
|
||||||
|
add_dependencies(${PROJECT}-assets inferno-assets) # Copy project assets *AFTER* engine assets!
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# Execute target
|
# Execute target
|
||||||
@@ -87,9 +94,6 @@ if (GARBAGE_BUILD_TESTS)
|
|||||||
add_executable(${PROJECT}-unit-test ${TEST_SOURCES})
|
add_executable(${PROJECT}-unit-test ${TEST_SOURCES})
|
||||||
target_include_directories(${PROJECT}-unit-test PRIVATE
|
target_include_directories(${PROJECT}-unit-test PRIVATE
|
||||||
"src"
|
"src"
|
||||||
"test"
|
"test")
|
||||||
"vendor/ruc/src"
|
target_link_libraries(${PROJECT}-unit-test inferno)
|
||||||
"vendor/ruc/test")
|
|
||||||
target_link_libraries(${PROJECT}-unit-test ruc)
|
|
||||||
target_link_libraries(${PROJECT}-unit-test ruc-test)
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
+3
-4
@@ -10,14 +10,13 @@ Accurate GameBoy emulator.
|
|||||||
*** Clone
|
*** Clone
|
||||||
|
|
||||||
#+BEGIN_SRC shell-script
|
#+BEGIN_SRC shell-script
|
||||||
$ git clone https://gitlab.com/riyyi/garbage
|
$ git clone https://github.com/riyyi/garbage
|
||||||
$ cd garbage
|
$ cd garbage
|
||||||
$ git submodule init
|
$ git submodule update --init --recursive
|
||||||
$ git submodule update
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
Or
|
Or
|
||||||
#+BEGIN_SRC shell-script
|
#+BEGIN_SRC shell-script
|
||||||
$ git clone --recursive https://gitlab.com/riyyi/garbage
|
$ git clone --recursive https://github.com/riyyi/garbage
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
*** Update
|
*** Update
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"camera": {
|
||||||
|
"name": "Camera",
|
||||||
|
"translate": [ 0.0, 0.0, -1.0 ],
|
||||||
|
"rotate": [ 0.0, 0.0, 0.0 ],
|
||||||
|
"scale": [ 1.0, 1.0, 1.0 ],
|
||||||
|
"type": "orthographic",
|
||||||
|
"zoom-level": 0.45
|
||||||
|
},
|
||||||
|
"quad" : [
|
||||||
|
{
|
||||||
|
"name": "Screen",
|
||||||
|
"scale": [ 1.0, -0.9, 1.0 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"window": {
|
||||||
|
"fullscreen": "windowed",
|
||||||
|
"height": 432,
|
||||||
|
"title": "GarbAGE",
|
||||||
|
"vsync": true,
|
||||||
|
"width": 480
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
file(COPY ${CMAKE_CURRENT_LIST_DIR}/../assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
+1
-2
@@ -365,8 +365,7 @@ void CPU::swap()
|
|||||||
m_wait_cycles += 8;
|
m_wait_cycles += 8;
|
||||||
|
|
||||||
// Swap upper 4 bits in register r8 with lower 4 bits
|
// Swap upper 4 bits in register r8 with lower 4 bits
|
||||||
register_ = register_ & 0xff;
|
register_ = ((register_ >> 4) | (register_ << 4)) & 0xff;
|
||||||
register_ = (register_ >> 4) | (register_ << 4);
|
|
||||||
|
|
||||||
// Set flags
|
// Set flags
|
||||||
m_zf = (register_ == 0);
|
m_zf = (register_ == 0);
|
||||||
|
|||||||
+10
-17
@@ -12,6 +12,7 @@
|
|||||||
#include "ruc/format/color.h"
|
#include "ruc/format/color.h"
|
||||||
#include "ruc/format/print.h"
|
#include "ruc/format/print.h"
|
||||||
#include "ruc/meta/assert.h"
|
#include "ruc/meta/assert.h"
|
||||||
|
#include "ruc/meta/core.h"
|
||||||
|
|
||||||
CPU::CPU(uint32_t frequency)
|
CPU::CPU(uint32_t frequency)
|
||||||
: ProcessingUnit(frequency)
|
: ProcessingUnit(frequency)
|
||||||
@@ -95,20 +96,11 @@ void CPU::update()
|
|||||||
uint32_t interrupt_flag = Emu::the().readMemory(0xff0f) & 0x1f;
|
uint32_t interrupt_flag = Emu::the().readMemory(0xff0f) & 0x1f;
|
||||||
|
|
||||||
uint32_t interrupt = interrupt_enabled & interrupt_flag;
|
uint32_t interrupt = interrupt_enabled & interrupt_flag;
|
||||||
if (interrupt & InterruptRequest::VBlank) {
|
for (uint8_t i = 0; i < 5; ++i) {
|
||||||
handleInterrupt(interrupt_flag, InterruptRequest::VBlank, 0x40);
|
if (interrupt & BIT(i)) {
|
||||||
|
handleInterrupt(interrupt_flag, BIT(i), i * 8 + 0x40);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (interrupt & InterruptRequest::STAT) {
|
|
||||||
handleInterrupt(interrupt_flag, InterruptRequest::STAT, 0x48);
|
|
||||||
}
|
|
||||||
else if (interrupt & InterruptRequest::Timer) {
|
|
||||||
handleInterrupt(interrupt_flag, InterruptRequest::Timer, 0x50);
|
|
||||||
}
|
|
||||||
else if (interrupt & InterruptRequest::Serial) {
|
|
||||||
handleInterrupt(interrupt_flag, InterruptRequest::Serial, 0x58);
|
|
||||||
}
|
|
||||||
else if (interrupt & InterruptRequest::Joypad) {
|
|
||||||
handleInterrupt(interrupt_flag, InterruptRequest::Joypad, 0x60);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1249,7 +1241,7 @@ void CPU::ra()
|
|||||||
m_cf = (m_a & 0x80) == 0x80;
|
m_cf = (m_a & 0x80) == 0x80;
|
||||||
|
|
||||||
// Rotate register A left
|
// Rotate register A left
|
||||||
m_a = (m_a >> 7) | (m_a << 1);
|
m_a = ((m_a >> 7) | (m_a << 1)) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 0x0f: // RRCA
|
case 0x0f: // RRCA
|
||||||
|
|
||||||
@@ -1264,7 +1256,7 @@ void CPU::ra()
|
|||||||
m_cf = (m_a & 0x1) == 0x1;
|
m_cf = (m_a & 0x1) == 0x1;
|
||||||
|
|
||||||
// Rotate register A right
|
// Rotate register A right
|
||||||
m_a = (m_a >> 1) | (m_a << 7);
|
m_a = ((m_a >> 1) | (m_a << 7)) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 0x17: { // RLA
|
case 0x17: { // RLA
|
||||||
|
|
||||||
@@ -1280,7 +1272,7 @@ void CPU::ra()
|
|||||||
m_cf = (m_a & 0x80) == 0x80;
|
m_cf = (m_a & 0x80) == 0x80;
|
||||||
|
|
||||||
// Rotate register A left through carry
|
// Rotate register A left through carry
|
||||||
m_a = old_carry | (m_a << 1);
|
m_a = (old_carry | (m_a << 1)) & 0xff;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x1f: { // RRA
|
case 0x1f: { // RRA
|
||||||
@@ -1297,7 +1289,7 @@ void CPU::ra()
|
|||||||
m_cf = (m_a & 0x1) == 0x1;
|
m_cf = (m_a & 0x1) == 0x1;
|
||||||
|
|
||||||
// Rotate register A right through carry
|
// Rotate register A right through carry
|
||||||
m_a = (m_a >> 1) | (old_carry << 7);
|
m_a = ((m_a >> 1) | (old_carry << 7)) & 0xff;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -1481,6 +1473,7 @@ void CPU::call()
|
|||||||
|
|
||||||
if (!should_call) {
|
if (!should_call) {
|
||||||
m_wait_cycles += 12;
|
m_wait_cycles += 12;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
m_wait_cycles += 24;
|
m_wait_cycles += 24;
|
||||||
|
|
||||||
|
|||||||
@@ -13,19 +13,6 @@
|
|||||||
|
|
||||||
#include "processing-unit.h"
|
#include "processing-unit.h"
|
||||||
#include "ruc/format/formatter.h"
|
#include "ruc/format/formatter.h"
|
||||||
#include "ruc/meta/core.h"
|
|
||||||
|
|
||||||
namespace InterruptRequest {
|
|
||||||
|
|
||||||
enum Enum : uint8_t {
|
|
||||||
VBlank = BIT(0),
|
|
||||||
STAT = BIT(1),
|
|
||||||
Timer = BIT(2),
|
|
||||||
Serial = BIT(3),
|
|
||||||
Joypad = BIT(4),
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace InterruptRequest
|
|
||||||
|
|
||||||
class CPU final : public ProcessingUnit {
|
class CPU final : public ProcessingUnit {
|
||||||
private:
|
private:
|
||||||
|
|||||||
+18
-1
@@ -39,7 +39,7 @@ void Emu::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emu::addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit)
|
void Emu::addProcessingUnit(std::string_view name, std::shared_ptr<ProcessingUnit> processing_unit)
|
||||||
{
|
{
|
||||||
m_processing_units.emplace(name, processing_unit);
|
m_processing_units.emplace(name, processing_unit);
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,16 @@ void Emu::removeMemorySpace(std::string_view name)
|
|||||||
|
|
||||||
void Emu::writeMemory(uint32_t address, uint32_t value)
|
void Emu::writeMemory(uint32_t address, uint32_t value)
|
||||||
{
|
{
|
||||||
|
// Bail if the CPU tries to write to a read-only address
|
||||||
|
switch (address) {
|
||||||
|
case 0xff44:
|
||||||
|
ruc::error("writing to read-only address: {:#06x}", address);
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& memory_space : m_memory_spaces) {
|
for (auto& memory_space : m_memory_spaces) {
|
||||||
auto& memory = memory_space.second;
|
auto& memory = memory_space.second;
|
||||||
if (address >= memory.start_address && address <= memory.end_address) {
|
if (address >= memory.start_address && address <= memory.end_address) {
|
||||||
@@ -96,6 +106,13 @@ void Emu::writeMemory(uint32_t address, uint32_t value)
|
|||||||
|
|
||||||
uint32_t Emu::readMemory(uint32_t address) const
|
uint32_t Emu::readMemory(uint32_t address) const
|
||||||
{
|
{
|
||||||
|
switch (address) {
|
||||||
|
case 0xff44:
|
||||||
|
return *m_processing_units.at("PPU")->sharedRegister("LY");
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
for (const auto& memory_space : m_memory_spaces) {
|
for (const auto& memory_space : m_memory_spaces) {
|
||||||
const auto& memory = memory_space.second;
|
const auto& memory = memory_space.second;
|
||||||
if (address >= memory.start_address && address <= memory.end_address) {
|
if (address >= memory.start_address && address <= memory.end_address) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint32_t
|
||||||
#include <string>
|
#include <memory> // std::shared_ptr
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -30,11 +30,16 @@ class Emu final : public ruc::Singleton<Emu> {
|
|||||||
public:
|
public:
|
||||||
Emu(s) {}
|
Emu(s) {}
|
||||||
|
|
||||||
|
enum Mode : uint8_t {
|
||||||
|
DMG, // Game Boy
|
||||||
|
CGB, // Game Boy Color
|
||||||
|
};
|
||||||
|
|
||||||
void init(uint32_t frequency);
|
void init(uint32_t frequency);
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit);
|
void addProcessingUnit(std::string_view name, std::shared_ptr<ProcessingUnit> processing_unit);
|
||||||
void addMemorySpace(std::string_view name, uint32_t start_address, uint32_t end_address, uint32_t amount_of_banks = 1);
|
void addMemorySpace(std::string_view name, uint32_t start_address, uint32_t end_address, uint32_t amount_of_banks = 1);
|
||||||
void removeMemorySpace(std::string_view name);
|
void removeMemorySpace(std::string_view name);
|
||||||
|
|
||||||
@@ -43,10 +48,12 @@ public:
|
|||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
ProcessingUnit* processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
Mode mode() const { return m_mode; }
|
||||||
|
std::shared_ptr<ProcessingUnit> processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||||
MemorySpace memorySpace(std::string_view name) { return m_memory_spaces[name]; }
|
MemorySpace memorySpace(std::string_view name) { return m_memory_spaces[name]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mode m_mode { Mode::DMG };
|
||||||
uint32_t m_frequency { 0 };
|
uint32_t m_frequency { 0 };
|
||||||
double m_timestep { 0 };
|
double m_timestep { 0 };
|
||||||
uint32_t m_cycle { 0 };
|
uint32_t m_cycle { 0 };
|
||||||
@@ -55,6 +62,6 @@ private:
|
|||||||
|
|
||||||
ruc::Timer m_timer;
|
ruc::Timer m_timer;
|
||||||
|
|
||||||
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
std::unordered_map<std::string_view, std::shared_ptr<ProcessingUnit>> m_processing_units;
|
||||||
std::unordered_map<std::string_view, MemorySpace> m_memory_spaces;
|
std::unordered_map<std::string_view, MemorySpace> m_memory_spaces;
|
||||||
};
|
};
|
||||||
|
|||||||
+6
-14
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint32_t
|
||||||
|
#include <memory> // std::make_shared
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
@@ -42,13 +43,13 @@ void Loader::init()
|
|||||||
{
|
{
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
Emu::the().init(8000000);
|
Emu::the().init(4000000);
|
||||||
|
|
||||||
CPU cpu(8000000);
|
auto cpu = std::make_shared<CPU>(4000000);
|
||||||
PPU ppu(4000000);
|
auto ppu = std::make_shared<PPU>(4000000);
|
||||||
|
|
||||||
Emu::the().addProcessingUnit("cpu", &cpu);
|
Emu::the().addProcessingUnit("CPU", cpu);
|
||||||
Emu::the().addProcessingUnit("ppu", &ppu);
|
Emu::the().addProcessingUnit("PPU", ppu);
|
||||||
|
|
||||||
// https://gbdev.io/pandocs/Memory_Map.html
|
// https://gbdev.io/pandocs/Memory_Map.html
|
||||||
// https://gbdev.io/pandocs/Power_Up_Sequence.html
|
// https://gbdev.io/pandocs/Power_Up_Sequence.html
|
||||||
@@ -77,15 +78,6 @@ void Loader::init()
|
|||||||
|
|
||||||
Emu::the().writeMemory(i, bootrom[i]);
|
Emu::the().writeMemory(i, bootrom[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Loader::update()
|
|
||||||
{
|
|
||||||
while (true) {
|
|
||||||
Emu::the().update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loader::destroy()
|
void Loader::destroy()
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void update();
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
void loadCartridgeHeader();
|
void loadCartridgeHeader();
|
||||||
|
|||||||
+37
-5
@@ -5,13 +5,22 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "loader.h"
|
#include <string_view>
|
||||||
|
|
||||||
|
#include "inferno.h"
|
||||||
|
#include "inferno/entrypoint.h"
|
||||||
|
#include "ppu.h"
|
||||||
#include "ruc/argparser.h"
|
#include "ruc/argparser.h"
|
||||||
#include "ruc/format/print.h"
|
#include "ruc/format/print.h"
|
||||||
#include "ruc/timer.h"
|
#include "ruc/timer.h"
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
#include "emu.h"
|
||||||
|
#include "loader.h"
|
||||||
|
|
||||||
|
class GarbAGE final : public Inferno::Application {
|
||||||
|
public:
|
||||||
|
GarbAGE(int argc, char* argv[])
|
||||||
|
: Application()
|
||||||
{
|
{
|
||||||
std::string_view bootrom_path = "gbc_bios.bin";
|
std::string_view bootrom_path = "gbc_bios.bin";
|
||||||
std::string_view rom_path;
|
std::string_view rom_path;
|
||||||
@@ -23,6 +32,29 @@ int main(int argc, const char* argv[])
|
|||||||
|
|
||||||
Loader::the().setBootromPath(bootrom_path);
|
Loader::the().setBootromPath(bootrom_path);
|
||||||
Loader::the().loadRom(rom_path);
|
Loader::the().loadRom(rom_path);
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
~GarbAGE()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void update() override
|
||||||
|
{
|
||||||
|
// 154 scanlines * 456 cycles = 70224 cycles per frame
|
||||||
|
for (int i = 0; i < (144 * 456 + 10 * 456); ++i) {
|
||||||
|
Emu::the().update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void render() override
|
||||||
|
{
|
||||||
|
auto* ppu = static_cast<PPU*>(Emu::the().processingUnit("PPU").get());
|
||||||
|
ppu->render();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Inferno::Application* Inferno::createApplication(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
GarbAGE* gameboy = new GarbAGE(argc, argv);
|
||||||
|
return gameboy;
|
||||||
}
|
}
|
||||||
|
|||||||
+271
-7
@@ -5,15 +5,28 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint8_t, uint16_t, uint32_t
|
||||||
|
#include <memory> // std::make_shared
|
||||||
|
|
||||||
|
#include "glm/ext/vector_float3.hpp" // glm::vec3
|
||||||
|
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||||
|
#include "inferno/application.h"
|
||||||
|
#include "inferno/component/spritecomponent.h"
|
||||||
|
#include "inferno/component/transformcomponent.h"
|
||||||
|
#include "inferno/scene/scene.h"
|
||||||
|
#include "ruc/format/print.h"
|
||||||
|
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "ppu.h"
|
#include "ppu.h"
|
||||||
#include "ruc/format/print.h"
|
#include "ruc/meta/assert.h"
|
||||||
|
|
||||||
PPU::PPU(uint32_t frequency)
|
PPU::PPU(uint32_t frequency)
|
||||||
: ProcessingUnit(frequency)
|
: ProcessingUnit(frequency)
|
||||||
{
|
{
|
||||||
|
m_shared_registers.emplace("LY", &m_lcd_y_coordinate);
|
||||||
|
|
||||||
|
auto& scene = Inferno::Application::the().scene();
|
||||||
|
m_entity = scene.findEntity("Screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
PPU::~PPU()
|
PPU::~PPU()
|
||||||
@@ -29,10 +42,261 @@ void PPU::update()
|
|||||||
|
|
||||||
// print("PPU update\n");
|
// print("PPU update\n");
|
||||||
|
|
||||||
// Increment LY (LCD Y Coordinate)
|
m_clocks_into_frame++;
|
||||||
uint32_t ly_register = Emu::the().readMemory(0xff44) + 1;
|
|
||||||
if (ly_register >= 154) {
|
switch (m_state) {
|
||||||
ly_register = 0;
|
case State::OAMSearch:
|
||||||
|
// OAM logic goes here..
|
||||||
|
|
||||||
|
if (m_clocks_into_frame % 80 == 0) {
|
||||||
|
// Reset FIFO
|
||||||
|
m_pixel_fifo = {};
|
||||||
|
|
||||||
|
m_state = State::PixelTransfer;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State::PixelTransfer:
|
||||||
|
updatePixelFifo();
|
||||||
|
|
||||||
|
if (m_lcd_x_coordinate == 160) {
|
||||||
|
m_lcd_x_coordinate = 0;
|
||||||
|
m_state = State::HBlank;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State::HBlank:
|
||||||
|
// H-Blank logic goes here..
|
||||||
|
|
||||||
|
if (m_clocks_into_frame % (80 + 172 + 204) == 0) {
|
||||||
|
m_lcd_y_coordinate++;
|
||||||
|
if (m_lcd_y_coordinate == 144) {
|
||||||
|
m_state = State::VBlank;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_state = State::OAMSearch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State::VBlank:
|
||||||
|
// V-Blank logic goes here..
|
||||||
|
|
||||||
|
if (m_clocks_into_frame % (80 + 172 + 204) == 0) {
|
||||||
|
m_lcd_y_coordinate++;
|
||||||
|
if (m_lcd_y_coordinate == 154) {
|
||||||
|
resetFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::render()
|
||||||
|
{
|
||||||
|
LCDC lcd_control = static_cast<LCDC>(Emu::the().readMemory(0xff40));
|
||||||
|
|
||||||
|
if (!(lcd_control & LCDC::BGandWindowEnable)) {
|
||||||
|
// When Bit 0 is cleared, both background and window become blank (white)
|
||||||
|
auto pixel = getPixelColor(0, Palette::BGP);
|
||||||
|
for (size_t i = 0; i < m_screen.size(); i += 3) {
|
||||||
|
m_screen[i + 0] = pixel[0];
|
||||||
|
m_screen[i + 1] = pixel[1];
|
||||||
|
m_screen[i + 2] = pixel[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& scene = Inferno::Application::the().scene();
|
||||||
|
auto texture = std::make_shared<Inferno::Texture>(m_screen.data(), SCREEN_WIDTH, SCREEN_HEIGHT, FORMAT_SIZE);
|
||||||
|
scene.removeComponent<Inferno::SpriteComponent>(m_entity);
|
||||||
|
scene.addComponent<Inferno::SpriteComponent>(m_entity, glm::vec4 { 1.0f }, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::resetFrame()
|
||||||
|
{
|
||||||
|
m_state = State::OAMSearch;
|
||||||
|
m_clocks_into_frame = 0;
|
||||||
|
m_lcd_x_coordinate = 0;
|
||||||
|
m_lcd_y_coordinate = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
uint32_t PPU::getBgTileDataAddress(uint8_t tile_index)
|
||||||
|
{
|
||||||
|
// https://gbdev.io/pandocs/Tile_Data.html
|
||||||
|
switch (m_pixel_fifo.tile_data_address) {
|
||||||
|
case 0x8000:
|
||||||
|
// 0x8000-0x8fff: index 0 => 255
|
||||||
|
return m_pixel_fifo.tile_data_address + (tile_index * TILE_SIZE); // Each tile is 16 bytes
|
||||||
|
case 0x8800:
|
||||||
|
// 0x8800-0x8fff: index 128 => 255 (or -128 => -1)
|
||||||
|
// 0x9000-0x97ff: index 0 => 127
|
||||||
|
if (tile_index <= 127) {
|
||||||
|
return m_pixel_fifo.tile_data_address + 0x800 + (tile_index * TILE_SIZE); // Each tile is 16 bytes
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return m_pixel_fifo.tile_data_address + ((tile_index - 128) * TILE_SIZE); // Each tile is 16 bytes
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<uint8_t, 3> PPU::getPixelColor(uint8_t color_index, Palette palette)
|
||||||
|
{
|
||||||
|
VERIFY(color_index < 4, "trying to fetch invalid color index '{}'", color_index);
|
||||||
|
|
||||||
|
switch (Emu::the().mode()) {
|
||||||
|
case Emu::Mode::DMG: {
|
||||||
|
uint8_t palette_data = Emu::the().readMemory(palette) & 0xff;
|
||||||
|
uint8_t palette_value = palette_data >> (color_index * 2) & 0x3;
|
||||||
|
switch (palette_value) {
|
||||||
|
case 0:
|
||||||
|
return { 200, 199, 168 };
|
||||||
|
case 1:
|
||||||
|
return { 160, 160, 136 };
|
||||||
|
case 2:
|
||||||
|
return { 104, 104, 80 };
|
||||||
|
case 3:
|
||||||
|
return { 39, 40, 24 };
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Emu::Mode::CGB:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::updatePixelFifo()
|
||||||
|
{
|
||||||
|
switch (m_pixel_fifo.state) {
|
||||||
|
case PixelFifo::State::TileIndex:
|
||||||
|
tileIndex();
|
||||||
|
break;
|
||||||
|
case PixelFifo::State::TileDataLow:
|
||||||
|
tileDataLow();
|
||||||
|
break;
|
||||||
|
case PixelFifo::State::TileDataHigh:
|
||||||
|
tileDataHigh();
|
||||||
|
break;
|
||||||
|
case PixelFifo::State::Sleep:
|
||||||
|
sleep();
|
||||||
|
break;
|
||||||
|
case PixelFifo::State::Push:
|
||||||
|
pushFifo();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
};
|
||||||
|
|
||||||
|
pushPixel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::tileIndex()
|
||||||
|
{
|
||||||
|
if (!m_pixel_fifo.step) {
|
||||||
|
m_pixel_fifo.step = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_pixel_fifo.step = false;
|
||||||
|
m_pixel_fifo.state = PixelFifo::State::TileDataLow;
|
||||||
|
|
||||||
|
LCDC lcd_control = static_cast<LCDC>(Emu::the().readMemory(0xff40));
|
||||||
|
|
||||||
|
// Tile map
|
||||||
|
uint32_t bg_tile_map_address = (lcd_control & LCDC::BGTileMapArea) ? 0x9c00 : 0x9800;
|
||||||
|
// uint32_t window_tile_map_address = (lcd_control & LCDC::WindowTileMapArea) ? 0x9c00 : 0x9800;
|
||||||
|
|
||||||
|
// Tile data
|
||||||
|
m_pixel_fifo.tile_data_address = (lcd_control & LCDC::BGandWindowTileDataArea) ? 0x8000 : 0x8800;
|
||||||
|
|
||||||
|
// Viewport
|
||||||
|
// https://gbdev.io/pandocs/Scrolling.html#mid-frame-behavior
|
||||||
|
m_pixel_fifo.viewport_x = Emu::the().readMemory(0xff43); // TODO: only read lower 3-bits at beginning of scanline
|
||||||
|
m_pixel_fifo.viewport_y = Emu::the().readMemory(0xff42);
|
||||||
|
|
||||||
|
// Read the tile map index
|
||||||
|
uint16_t offset = (((m_pixel_fifo.viewport_y + m_lcd_y_coordinate) / TILE_HEIGHT) * 32)
|
||||||
|
+ ((m_pixel_fifo.viewport_x + m_pixel_fifo.x_coordinate) / TILE_WIDTH);
|
||||||
|
m_pixel_fifo.x_coordinate += 8;
|
||||||
|
m_pixel_fifo.tile_index = Emu::the().readMemory(bg_tile_map_address + offset);
|
||||||
|
|
||||||
|
// Set the tile line we're currently on
|
||||||
|
m_pixel_fifo.tile_line = (m_pixel_fifo.viewport_y + m_lcd_y_coordinate) % TILE_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::tileDataLow()
|
||||||
|
{
|
||||||
|
if (!m_pixel_fifo.step) {
|
||||||
|
m_pixel_fifo.step = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_pixel_fifo.step = false;
|
||||||
|
m_pixel_fifo.state = PixelFifo::State::TileDataHigh;
|
||||||
|
|
||||||
|
// Read tile data
|
||||||
|
m_pixel_fifo.pixels_lsb = Emu::the().readMemory(
|
||||||
|
getBgTileDataAddress(m_pixel_fifo.tile_index)
|
||||||
|
+ m_pixel_fifo.tile_line * 2); // Each tile line is 2 bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::tileDataHigh()
|
||||||
|
{
|
||||||
|
if (!m_pixel_fifo.step) {
|
||||||
|
m_pixel_fifo.step = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_pixel_fifo.step = false;
|
||||||
|
m_pixel_fifo.state = PixelFifo::State::Sleep;
|
||||||
|
|
||||||
|
// Read tile data
|
||||||
|
m_pixel_fifo.pixels_msb = Emu::the().readMemory(
|
||||||
|
getBgTileDataAddress(m_pixel_fifo.tile_index)
|
||||||
|
+ m_pixel_fifo.tile_line * 2 // Each tile line is 2 bytes
|
||||||
|
+ 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::sleep()
|
||||||
|
{
|
||||||
|
if (m_pixel_fifo.background.size() <= TILE_WIDTH + 1) {
|
||||||
|
m_pixel_fifo.state = PixelFifo::State::Push;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::pushFifo()
|
||||||
|
{
|
||||||
|
m_pixel_fifo.state = PixelFifo::State::TileIndex;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < TILE_WIDTH; ++i) {
|
||||||
|
uint8_t color_index = (m_pixel_fifo.pixels_lsb >> (7 - i)
|
||||||
|
| ((m_pixel_fifo.pixels_msb >> (7 - i)) << 1))
|
||||||
|
& 0x3;
|
||||||
|
m_pixel_fifo.background.push({ color_index, Palette::BGP });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPU::pushPixel()
|
||||||
|
{
|
||||||
|
// The pixel FIFO needs to contain more than 8 pixels to shift one out
|
||||||
|
if (m_pixel_fifo.background.size() > 8) {
|
||||||
|
auto pixel = m_pixel_fifo.background.front();
|
||||||
|
m_pixel_fifo.background.pop();
|
||||||
|
|
||||||
|
uint32_t index = (m_lcd_y_coordinate * SCREEN_WIDTH + m_lcd_x_coordinate) * FORMAT_SIZE;
|
||||||
|
auto color = getPixelColor(pixel.first, pixel.second);
|
||||||
|
m_screen[index + 0] = color[0];
|
||||||
|
m_screen[index + 1] = color[1];
|
||||||
|
m_screen[index + 2] = color[2];
|
||||||
|
m_lcd_x_coordinate++;
|
||||||
}
|
}
|
||||||
Emu::the().writeMemory(0xff44, ly_register);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,27 +7,103 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint8_t, uint32_t
|
#include <array>
|
||||||
|
#include <cstdint> // uint8_t, uint16_t, uint32_t
|
||||||
|
#include <queue>
|
||||||
|
#include <utility> // std::pair
|
||||||
|
|
||||||
|
#include "ruc/meta/core.h"
|
||||||
|
|
||||||
#include "processing-unit.h"
|
#include "processing-unit.h"
|
||||||
#include "ruc/meta/core.h"
|
|
||||||
|
#define SCREEN_WIDTH 160
|
||||||
|
#define SCREEN_HEIGHT 144
|
||||||
|
#define FORMAT_SIZE 3
|
||||||
|
#define TILE_WIDTH 8
|
||||||
|
#define TILE_HEIGHT 8
|
||||||
|
#define TILE_SIZE 16
|
||||||
|
|
||||||
|
class PPU final : public ProcessingUnit {
|
||||||
|
public:
|
||||||
|
PPU(uint32_t frequency);
|
||||||
|
~PPU();
|
||||||
|
|
||||||
enum LCDC : uint8_t {
|
enum LCDC : uint8_t {
|
||||||
None = 0,
|
None = 0,
|
||||||
BGandWindowEnable = BIT(0),
|
BGandWindowEnable = BIT(0),
|
||||||
OBJEnable = BIT(1),
|
OBJEnable = BIT(1),
|
||||||
OBJSize = BIT(2), // 0 = 8x8, 1 = 8x16
|
OBJSize = BIT(2), // 0 = 8x8, 1 = 8x16
|
||||||
BGTileMapArea = BIT(3), // 0 = 9800-9bff, 1 = 9c00-9fff
|
BGTileMapArea = BIT(3), // 0 = 0x9800-9bff, 1 = 0x9c00-9fff
|
||||||
BGandWindowTileDataArea = BIT(4), // 0 = 8800-97ff, 1 = 8000-8fff
|
BGandWindowTileDataArea = BIT(4), // 0 = 0x8800-97ff, 1 = 0x8000-8fff
|
||||||
WindowEnable = BIT(5), //
|
WindowEnable = BIT(5), //
|
||||||
WindowTileMapArea = BIT(6), // 0 = 9800-9bff, 1 = 9c00-9fff
|
WindowTileMapArea = BIT(6), // 0 = 0x9800-9bff, 1 = 0x9c00-9fff
|
||||||
LCDandPPUEnable = BIT(7),
|
LCDandPPUEnable = BIT(7),
|
||||||
};
|
};
|
||||||
|
|
||||||
class PPU final : public ProcessingUnit {
|
enum State : uint8_t {
|
||||||
public:
|
HBlank = 0,
|
||||||
PPU(uint32_t frequency);
|
VBlank = 1,
|
||||||
virtual ~PPU();
|
OAMSearch = 2,
|
||||||
|
PixelTransfer = 3,
|
||||||
virtual void update() override;
|
};
|
||||||
|
|
||||||
|
enum Palette : uint16_t {
|
||||||
|
BGP = 0xff47, // BG and Window palette
|
||||||
|
OBP0 = 0xff48, // OBJ palette 0
|
||||||
|
OBP1 = 0xff49, // OBJ palette 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PixelFifo {
|
||||||
|
enum State : uint8_t {
|
||||||
|
TileIndex,
|
||||||
|
TileDataLow,
|
||||||
|
TileDataHigh,
|
||||||
|
Sleep,
|
||||||
|
Push,
|
||||||
|
};
|
||||||
|
|
||||||
|
State state { State::TileIndex };
|
||||||
|
bool step { false };
|
||||||
|
uint32_t tile_data_address { 0 };
|
||||||
|
uint8_t viewport_x { 0 };
|
||||||
|
uint8_t viewport_y { 0 };
|
||||||
|
uint8_t x_coordinate { 0 };
|
||||||
|
uint8_t tile_index { 0 };
|
||||||
|
uint8_t tile_line { 0 };
|
||||||
|
uint8_t pixels_lsb { 0 };
|
||||||
|
uint8_t pixels_msb { 0 };
|
||||||
|
|
||||||
|
using Fifo = std::queue<std::pair<uint8_t, Palette>>; // colorID, source
|
||||||
|
|
||||||
|
Fifo background;
|
||||||
|
Fifo oam;
|
||||||
|
};
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
void render();
|
||||||
|
void resetFrame();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t getBgTileDataAddress(uint8_t tile_index);
|
||||||
|
std::array<uint8_t, 3> getPixelColor(uint8_t color_index, Palette palette);
|
||||||
|
|
||||||
|
void updatePixelFifo();
|
||||||
|
void tileIndex();
|
||||||
|
void tileDataLow();
|
||||||
|
void tileDataHigh();
|
||||||
|
void sleep();
|
||||||
|
void pushFifo();
|
||||||
|
void pushPixel();
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
State m_state { State::OAMSearch };
|
||||||
|
uint32_t m_clocks_into_frame { 0 };
|
||||||
|
uint32_t m_lcd_x_coordinate { 0 };
|
||||||
|
uint32_t m_lcd_y_coordinate { 0 }; // Note: includes V-Blank
|
||||||
|
|
||||||
|
PixelFifo m_pixel_fifo;
|
||||||
|
|
||||||
|
uint32_t m_entity { 0 };
|
||||||
|
std::array<uint8_t, SCREEN_WIDTH * SCREEN_HEIGHT * FORMAT_SIZE> m_screen;
|
||||||
};
|
};
|
||||||
|
|||||||
+29
-28
@@ -4,6 +4,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory> // std::make_shared, std::shared_ptr
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
@@ -26,13 +27,13 @@ struct CPUTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CPU runCPUTest(std::vector<uint8_t> test)
|
std::shared_ptr<CPU> runCPUTest(std::vector<uint8_t> test)
|
||||||
{
|
{
|
||||||
CPU cpu(4000000);
|
auto cpu = std::make_shared<CPU>(4000000);
|
||||||
|
|
||||||
Emu::the().destroy();
|
Emu::the().destroy();
|
||||||
Emu::the().init(8000000);
|
Emu::the().init(8000000);
|
||||||
Emu::the().addProcessingUnit("cpu", &cpu);
|
Emu::the().addProcessingUnit("cpu", cpu);
|
||||||
Emu::the().addMemorySpace("FULL", 0x0000, 0xffff);
|
Emu::the().addMemorySpace("FULL", 0x0000, 0xffff);
|
||||||
|
|
||||||
// Load the test
|
// Load the test
|
||||||
@@ -41,7 +42,7 @@ CPU runCPUTest(std::vector<uint8_t> test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the test
|
// Run the test
|
||||||
while (cpu.pc() < test.size()) {
|
while (cpu->pc() < test.size()) {
|
||||||
Emu::the().update();
|
Emu::the().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ TEST_CASE(CPUIsCarry)
|
|||||||
|
|
||||||
TEST_CASE(CPUAddPlusCarry)
|
TEST_CASE(CPUAddPlusCarry)
|
||||||
{
|
{
|
||||||
CPU cpu(0);
|
std::shared_ptr<CPU> cpu(0);
|
||||||
|
|
||||||
// ADC A,E
|
// ADC A,E
|
||||||
|
|
||||||
@@ -96,11 +97,11 @@ TEST_CASE(CPUAddPlusCarry)
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
cpu = runCPUTest(adc_r8);
|
cpu = runCPUTest(adc_r8);
|
||||||
EXPECT_EQ(cpu.a(), 0xf1);
|
EXPECT_EQ(cpu->a(), 0xf1);
|
||||||
EXPECT_EQ(cpu.zf(), 0x0);
|
EXPECT_EQ(cpu->zf(), 0x0);
|
||||||
EXPECT_EQ(cpu.nf(), 0x0);
|
EXPECT_EQ(cpu->nf(), 0x0);
|
||||||
EXPECT_EQ(cpu.hf(), 0x1);
|
EXPECT_EQ(cpu->hf(), 0x1);
|
||||||
EXPECT_EQ(cpu.cf(), 0x0);
|
EXPECT_EQ(cpu->cf(), 0x0);
|
||||||
|
|
||||||
// ADC A,i8
|
// ADC A,i8
|
||||||
|
|
||||||
@@ -112,11 +113,11 @@ TEST_CASE(CPUAddPlusCarry)
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
cpu = runCPUTest(adc_i8);
|
cpu = runCPUTest(adc_i8);
|
||||||
EXPECT_EQ(cpu.a(), 0x1d);
|
EXPECT_EQ(cpu->a(), 0x1d);
|
||||||
EXPECT_EQ(cpu.zf(), 0x0);
|
EXPECT_EQ(cpu->zf(), 0x0);
|
||||||
EXPECT_EQ(cpu.nf(), 0x0);
|
EXPECT_EQ(cpu->nf(), 0x0);
|
||||||
EXPECT_EQ(cpu.hf(), 0x0);
|
EXPECT_EQ(cpu->hf(), 0x0);
|
||||||
EXPECT_EQ(cpu.cf(), 0x1);
|
EXPECT_EQ(cpu->cf(), 0x1);
|
||||||
|
|
||||||
// ADC A,(HL)
|
// ADC A,(HL)
|
||||||
|
|
||||||
@@ -129,18 +130,18 @@ TEST_CASE(CPUAddPlusCarry)
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
cpu = runCPUTest(adc_hl);
|
cpu = runCPUTest(adc_hl);
|
||||||
EXPECT_EQ(cpu.a(), 0x0);
|
EXPECT_EQ(cpu->a(), 0x0);
|
||||||
EXPECT_EQ(cpu.zf(), 0x1);
|
EXPECT_EQ(cpu->zf(), 0x1);
|
||||||
EXPECT_EQ(cpu.nf(), 0x0);
|
EXPECT_EQ(cpu->nf(), 0x0);
|
||||||
EXPECT_EQ(cpu.hf(), 0x1);
|
EXPECT_EQ(cpu->hf(), 0x1);
|
||||||
EXPECT_EQ(cpu.cf(), 0x1);
|
EXPECT_EQ(cpu->cf(), 0x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(CPUSetStackPointer)
|
TEST_CASE(CPUSetStackPointer)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> test = { 0x31, 0xfe, 0xff }; // LD SP,i16
|
std::vector<uint8_t> test = { 0x31, 0xfe, 0xff }; // LD SP,i16
|
||||||
CPU cpu = runCPUTest(test);
|
auto cpu = runCPUTest(test);
|
||||||
EXPECT_EQ(cpu.sp(), 0xfffe);
|
EXPECT_EQ(cpu->sp(), 0xfffe);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(CPUPushToStack)
|
TEST_CASE(CPUPushToStack)
|
||||||
@@ -154,9 +155,9 @@ TEST_CASE(CPUPushToStack)
|
|||||||
0xc5, // PUSH BC
|
0xc5, // PUSH BC
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
CPU cpu = runCPUTest(push_bc);
|
auto cpu = runCPUTest(push_bc);
|
||||||
EXPECT_EQ(cpu.bc(), 0xfffc);
|
EXPECT_EQ(cpu->bc(), 0xfffc);
|
||||||
EXPECT_EQ(cpu.sp(), 0xfffc);
|
EXPECT_EQ(cpu->sp(), 0xfffc);
|
||||||
EXPECT_EQ(Emu::the().readMemory(0xfffd), 0xff);
|
EXPECT_EQ(Emu::the().readMemory(0xfffd), 0xff);
|
||||||
EXPECT_EQ(Emu::the().readMemory(0xfffc), 0xfc);
|
EXPECT_EQ(Emu::the().readMemory(0xfffc), 0xfc);
|
||||||
}
|
}
|
||||||
@@ -173,9 +174,9 @@ TEST_CASE(CPUPopFromStack)
|
|||||||
0xc1, // POP BC
|
0xc1, // POP BC
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
CPU cpu = runCPUTest(pop_bc);
|
auto cpu = runCPUTest(pop_bc);
|
||||||
EXPECT_EQ(cpu.bc(), 0x3c5f);
|
EXPECT_EQ(cpu->bc(), 0x3c5f);
|
||||||
EXPECT_EQ(cpu.sp(), 0xfffe);
|
EXPECT_EQ(cpu->sp(), 0xfffe);
|
||||||
EXPECT_EQ(Emu::the().readMemory(0xfffd), 0x3c);
|
EXPECT_EQ(Emu::the().readMemory(0xfffd), 0x3c);
|
||||||
EXPECT_EQ(Emu::the().readMemory(0xfffc), 0x5f);
|
EXPECT_EQ(Emu::the().readMemory(0xfffc), 0x5f);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
Submodule vendor/inferno added at f47babe5cf
Vendored
-1
Submodule vendor/ruc deleted from d3de1fb635
Reference in New Issue
Block a user