Browse Source

Emulator: Load cartridge header

master
Riyyi 2 years ago
parent
commit
dd2920b2a4
  1. 37
      src/loader.cpp
  2. 13
      src/loader.h
  3. 3
      src/main.cpp

37
src/loader.cpp

@ -4,11 +4,25 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "loader.h" #include <cstddef> // size_t
#include "cpu.h" #include "cpu.h"
#include "emu.h" #include "emu.h"
#include "loader.h"
#include "ppu.h" #include "ppu.h"
#include "ruc/file.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() void Loader::init()
{ {
@ -24,7 +38,8 @@ void Loader::init()
// 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
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("BOOTROM2", 0x0200, 0x08ff); // 1792B
Emu::the().addMemorySpace("VRAM", 0x8000, 0x9fff, 2); // 8KiB * 2 banks Emu::the().addMemorySpace("VRAM", 0x8000, 0x9fff, 2); // 8KiB * 2 banks
Emu::the().addMemorySpace("CARDRAM", 0xa000, 0xbfff, 1); // 8KiB * ? banks, if any Emu::the().addMemorySpace("CARDRAM", 0xa000, 0xbfff, 1); // 8KiB * ? banks, if any
@ -48,6 +63,11 @@ void Loader::init()
Emu::the().writeMemory(i, bootrom[i]); Emu::the().writeMemory(i, bootrom[i]);
} }
update();
}
void Loader::update()
{
while (true) { while (true) {
Emu::the().update(); Emu::the().update();
} }
@ -57,3 +77,16 @@ void Loader::destroy()
{ {
Emu::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]);
}
}

13
src/loader.h

@ -6,18 +6,23 @@
#pragma once #pragma once
#include "ruc/singleton.h" #include <string>
#include <string_view> #include <string_view>
#include "ruc/singleton.h"
class Loader final : public ruc::Singleton<Loader> { class Loader final : public ruc::Singleton<Loader> {
public: public:
Loader(s) {} Loader(s) {}
void loadRom(std::string_view rom_path);
private:
void init(); void init();
void update();
void destroy(); void destroy();
void setRomPath(std::string_view rom_path) { m_rom_path = rom_path; } void loadCartridgeHeader();
private: std::string m_rom_data;
std::string_view m_rom_path;
}; };

3
src/main.cpp

@ -19,8 +19,7 @@ int main(int argc, const char* argv[])
argParser.addOption(rom_path, 'r', "rom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes); argParser.addOption(rom_path, 'r', "rom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes);
argParser.parse(argc, argv); argParser.parse(argc, argv);
Loader::the().setRomPath(rom_path); Loader::the().loadRom(rom_path);
Loader::the().init();
return 0; return 0;
} }

Loading…
Cancel
Save