8#include "imgui/imgui.h"
20 auto location = 0x7FC0;
21 rom_size_ = 0x400 << rom_data[location + 0x17];
22 sram_size_ = 0x400 << rom_data[location + 0x18];
27 rom_[i] = rom_data[i];
39 size_t rom_data_size = rom_data.size();
40 size_t rom_address = 0;
41 const size_t ROM_CHUNK_SIZE = 0x8000;
42 for (
size_t bank = 0x00; bank <= 0x3F; ++bank) {
43 for (
size_t offset = 0x8000; offset <= 0xFFFF; offset += ROM_CHUNK_SIZE) {
44 if (rom_address < rom_data_size) {
45 std::copy(rom_data.begin() + rom_address,
46 rom_data.begin() + rom_address + ROM_CHUNK_SIZE,
47 memory_.begin() + (bank << 16) + offset);
48 rom_address += ROM_CHUNK_SIZE;
85 if (((bank >= 0x70 && bank < 0x7e) || bank >= 0xf0) && adr < 0x8000 &&
91 if (adr >= 0x8000 || bank >= 0x40) {
93 return rom_[((bank << 15) | (adr & 0x7fff)) & (
rom_size_ - 1)];
99 if (((bank >= 0x70 && bank < 0x7e) || bank > 0xf0) && adr < 0x8000 &&
108 if (bank < 0x40 && adr >= 0x6000 && adr < 0x8000 && sram_size_ > 0) {
110 return ram_[(((bank & 0x3f) << 13) | (adr & 0x1fff)) & (
sram_size_ - 1)];
112 if (adr >= 0x8000 || bank >= 0x40) {
114 return rom_[(((bank & 0x3f) << 16) | adr) & (
rom_size_ - 1)];
120 if ((bank & 0x7f) < 0x40 && adr >= 0x6000 && adr < 0x8000 && sram_size_ > 0) {
122 return ram_[(((bank & 0x3f) << 13) | (adr & 0x1fff)) & (
sram_size_ - 1)];
124 bool secondHalf = bank < 0x80;
126 if (adr >= 0x8000 || bank >= 0x40) {
128 return rom_[(((bank & 0x3f) << 16) | (secondHalf ? 0x400000 : 0) | adr) &
136 if (bank < 0x40 && adr >= 0x6000 && adr < 0x8000 && sram_size_ > 0) {
138 ram_[(((bank & 0x3f) << 13) | (adr & 0x1fff)) & (
sram_size_ - 1)] = val;
143 uint8_t bank = address >> 16;
144 uint32_t offset = address & 0xFFFF;
147 if (address <= 0x1FFF) {
148 return (0x7E << 16) + offset;
149 }
else if (address <= 0x5FFF) {
150 return (bank << 16) + (offset - 0x2000) + 0x2000;
151 }
else if (address <= 0x7FFF) {
152 return offset - 0x6000 + 0x6000;
155 return (bank << 16) + (offset - 0x8000) + 0x8000;
157 }
else if (bank == 0x7D) {
158 return offset + 0x7D0000;
159 }
else if (bank == 0x7E || bank == 0x7F) {
160 return offset + 0x7E0000;
161 }
else if (bank >= 0x80) {
std::vector< uint8_t > memory_
uint8_t cart_readExHirom(uint8_t bank, uint16_t adr)
void cart_writeLorom(uint8_t bank, uint16_t adr, uint8_t val)
uint8_t cart_readLorom(uint8_t bank, uint16_t adr)
uint32_t GetMappedAddress(uint32_t address) const
std::vector< uint8_t > rom_
uint8_t cart_read(uint8_t bank, uint16_t adr)
std::vector< uint8_t > ram_
void cart_writeHirom(uint8_t bank, uint16_t adr, uint8_t val)
void Initialize(const std::vector< uint8_t > &romData, bool verbose=false)
void cart_write(uint8_t bank, uint16_t adr, uint8_t val)
uint8_t cart_readHirom(uint8_t bank, uint16_t adr)