From 74eb60530b650da56f0f7ca33511f1aa80a74d69 Mon Sep 17 00:00:00 2001 From: Sylvain Colinet Date: Tue, 2 Nov 2021 21:54:04 +0100 Subject: [PATCH] Fuck RetroArch --- devices/retroarchhost.cpp | 22 +++++++++++++++++----- devices/retroarchhost.h | 10 ++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/devices/retroarchhost.cpp b/devices/retroarchhost.cpp index aa94c5f..192db24 100644 --- a/devices/retroarchhost.cpp +++ b/devices/retroarchhost.cpp @@ -34,6 +34,7 @@ RetroArchHost::RetroArchHost(QString name, QObject *parent) : QObject(parent) m_port = 55355; readRamHasRomAccess = false; readMemoryAPI = false; + useReadMemoryAPI = false; readMemoryHasRomAccess = false; lastId = -1; reqId = -1; @@ -68,7 +69,7 @@ qint64 RetroArchHost::getMemory(unsigned int address, unsigned int size) int raAddress = translateAddress(address); if (raAddress == -1) return -1; // error - QByteArray data = (readMemoryAPI ? "READ_CORE_MEMORY " : "READ_CORE_RAM ") + QByteArray::number(raAddress, 16) + " " + QByteArray::number(size) + "\n"; + QByteArray data = (useReadMemoryAPI ? "READ_CORE_MEMORY " : "READ_CORE_RAM ") + QByteArray::number(raAddress, 16) + " " + QByteArray::number(size) + "\n"; getMemorySize = (int)size; return queueCommand(data, GetMemory); } @@ -93,10 +94,10 @@ void RetroArchHost::writeMemoryData(qint64 id, QByteArray data) assert(writeMemoryBuffer.size() <= writeSize); if (writeSize == writeMemoryBuffer.size()) { - QByteArray data = (readMemoryAPI ? "WRITE_CORE_MEMORY " : "WRITE_CORE_RAM ") + QByteArray::number(writeAddress, 16) + " "; + QByteArray data = (useReadMemoryAPI ? "WRITE_CORE_MEMORY " : "WRITE_CORE_RAM ") + QByteArray::number(writeAddress, 16) + " "; data.append(writeMemoryBuffer.toHex(' ')); data.append('\n'); - if (!readMemoryAPI) { // old API does not send a reply + if (!useReadMemoryAPI) { // old API does not send a reply queueCommand(data, None, [this](qint64 sentId) { sDebug() << "Write memory done"; emit writeMemoryDone(sentId); @@ -392,6 +393,7 @@ int RetroArchHost::translateAddress(unsigned int address) int addr = static_cast(address); if (readMemoryAPI) { + useReadMemoryAPI = true; // ROM ACCESS if (addr < 0xE00000) { if (romType == HiROM && addr < 0x400000) { @@ -408,11 +410,21 @@ int RetroArchHost::translateAddress(unsigned int address) // WRAM if (addr >= 0xF50000 && addr <= 0xF70000) return 0x7E0000 + addr - 0xF50000; - // SRAM + // SRAM, this does not work properly with the new api + // This is a mess anyways xD if (addr >= 0xE00000 && addr < 0xF70000) - return rommapping_sram_pc_to_snes(address - 0xE00000, romType, false); + { + useReadMemoryAPI = false; + //if (!hasRomAccess()) + return addr - 0xE00000 + 0x20000; + if (romType == LoROM) + //return addr - 0xE00000 + 0x700000; + return lorom_sram_pc_to_snes(address - 0xE00000); + return lorom_sram_pc_to_snes(address - 0xE00000); + } return -1; } else { + useReadMemoryAPI = false; // Rom access if (addr < 0xE00000) { diff --git a/devices/retroarchhost.h b/devices/retroarchhost.h index 386c9a9..82160ba 100644 --- a/devices/retroarchhost.h +++ b/devices/retroarchhost.h @@ -92,7 +92,17 @@ class RetroArchHost : public QObject QHostAddress m_address; QString m_lastInfoError; bool readRamHasRomAccess; + // tell that we have a 1.9.0+ RA bool readMemoryAPI; + /* Enforce the use of write/read_core_memory or write/read_core_ram + * For some memory access the newest API does not work (like sram) + * This is a way to enforce the use of old api + * FIXME, this should maybe be in the queue? + */ + bool useReadMemoryAPI; + /* Can only access half LoROM with new API + * Why RA... + */ bool readMemoryHasRomAccess; qint64 reqId; State state;