Emulator: Load cartridge header

This commit is contained in:
Riyyi
2022-08-25 00:10:57 +02:00
parent 2aa50d3532
commit dd2920b2a4
3 changed files with 47 additions and 10 deletions
+35 -2
View File
@@ -4,11 +4,25 @@
* SPDX-License-Identifier: MIT
*/
#include "loader.h"
#include <cstddef> // size_t
#include "cpu.h"
#include "emu.h"
#include "loader.h"
#include "ppu.h"
#include "ruc/file.h"
#include "ruc/format/print.h"
void Loader::loadRom(std::string_view rom_path)
{
if (!rom_path.empty()) {
m_rom_data = ruc::File(rom_path).data();
}
init();
}
// -----------------------------------------
void Loader::init()
{
@@ -24,7 +38,8 @@ void Loader::init()
// https://gbdev.io/pandocs/Memory_Map.html
// https://gbdev.io/pandocs/Power_Up_Sequence.html
Emu::the().addMemorySpace("BOOTROM1", 0x0000, 0x00ff); // 256B
Emu::the().addMemorySpace("BOOTROM1", 0x0000, 0x00ff); // 256B
loadCartridgeHeader();
Emu::the().addMemorySpace("BOOTROM2", 0x0200, 0x08ff); // 1792B
Emu::the().addMemorySpace("VRAM", 0x8000, 0x9fff, 2); // 8KiB * 2 banks
Emu::the().addMemorySpace("CARDRAM", 0xa000, 0xbfff, 1); // 8KiB * ? banks, if any
@@ -48,6 +63,11 @@ void Loader::init()
Emu::the().writeMemory(i, bootrom[i]);
}
update();
}
void Loader::update()
{
while (true) {
Emu::the().update();
}
@@ -57,3 +77,16 @@ void Loader::destroy()
{
Emu::destroy();
}
void Loader::loadCartridgeHeader()
{
if (m_rom_data.empty()) {
return;
}
Emu::the().addMemorySpace("CARTHEADER", 0x100, 0x14f);
for (size_t i = 0x100; i <= 0x14f; ++i) {
Emu::the().writeMemory(i, m_rom_data[i]);
}
}