Implementing SMC headers and starting to implement LoRom mapping

This commit is contained in:
AnonymusRaccoon
2020-02-04 13:37:14 +01:00
parent 8261c273b2
commit 5d766f3200
5 changed files with 19 additions and 6 deletions
-1
View File
@@ -16,6 +16,5 @@ int main(int argc, char **argv)
}
Memory::MemoryBus bus;
SNES snes(std::make_shared<Memory::MemoryBus>(bus), argv[1]);
bus.mapComponents(snes);
return 0;
}
+8 -3
View File
@@ -49,7 +49,7 @@ namespace ComSquare::Cartridge
{
if (addr >= this->_size)
throw InvalidAddress("Cartridge read", addr);
return this->_data[addr];
return this->_data[addr + this->_romStart];
}
void Cartridge::write_internal(uint24_t addr, uint8_t data)
@@ -109,7 +109,7 @@ namespace ComSquare::Cartridge
uint32_t Cartridge::_getHeaderAddress()
{
std::vector<uint32_t> address = {0x7FC0, 0xFFC0, 0x81C0, 0x101C0};
const std::vector<uint32_t> address = {0x7FC0, 0xFFC0, 0x81C0, 0x101C0};
int bestScore = -1;
uint32_t bestAddress = 0;
@@ -176,6 +176,11 @@ namespace ComSquare::Cartridge
std::memcpy(name, &this->_data[headerAddress + 0xC0u], 21);
name[21] = '\0';
this->header.gameName = std::string(name);
return headerAddress & 0x200u;
if (headerAddress & 0x200u) {
this->_romStart = 0x200u;
this->_size -= 0x200u;
return true;
}
return false;
}
}
+3 -1
View File
@@ -60,12 +60,14 @@ namespace ComSquare::Cartridge
};
//! @brief Contains the rom's memory/instructions.
class Cartridge : Memory::IRectangleMemory {
class Cartridge : public Memory::IRectangleMemory {
private:
//! @brief The rom data (contains all the instructions).
uint8_t *_data;
//! @brief The size of the rom data.
size_t _size;
//! @brief Sometime the rom's data has an offset for a SMC header. This value indicate the start of the real rom discarding this header.
uint16_t _romStart;
//! @brief Get the size of a rom from it's path.
//! @param romPath The path of the rom to get info from.
+5
View File
@@ -79,5 +79,10 @@ namespace ComSquare::Memory
this->_mirrorComponents(console, i);
// TODO should map SRam, cartridge etc via the mapping mode of the cartridge.
if (console.cartridge->header.mappingMode & Cartridge::LoRom) {
console.cartridge->setMemoryRegion(0x80, 0xFF, 0x8000, 0xFFFF);
this->_memoryAccessors.push_back(console.cartridge);
}
}
}
+3 -1
View File
@@ -12,5 +12,7 @@ namespace ComSquare
apu(new APU::APU()),
cartridge(new Cartridge::Cartridge(romPath)),
wram(new Ram::Ram(16384))
{ }
{
bus->mapComponents(*this);
}
}