Move GBACart-related global state into objects (#1870)
- RAII will now do the heavy lifting - Mark some methods as const or noexcept - Once the `NDS` object is finalized, most of these `assert`s can go away
This commit is contained in:
parent
b4ff911fa3
commit
8b47178add
|
@ -42,11 +42,6 @@ const char SOLAR_SENSOR_GAMECODES[10][5] =
|
|||
"A3IJ" // Boktai - The Sun Is in Your Hand (USA) (Sample)
|
||||
};
|
||||
|
||||
std::unique_ptr<CartCommon> Cart;
|
||||
|
||||
u16 OpenBusDecay;
|
||||
|
||||
|
||||
CartCommon::CartCommon()
|
||||
{
|
||||
}
|
||||
|
@ -77,7 +72,7 @@ int CartCommon::SetInput(int num, bool pressed)
|
|||
return -1;
|
||||
}
|
||||
|
||||
u16 CartCommon::ROMRead(u32 addr)
|
||||
u16 CartCommon::ROMRead(u32 addr) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -243,7 +238,7 @@ void CartGame::LoadSave(const u8* savedata, u32 savelen)
|
|||
Platform::WriteGBASave(savedata, len, 0, len);
|
||||
}
|
||||
|
||||
u16 CartGame::ROMRead(u32 addr)
|
||||
u16 CartGame::ROMRead(u32 addr) const
|
||||
{
|
||||
addr &= 0x01FFFFFF;
|
||||
|
||||
|
@ -639,7 +634,7 @@ void CartRAMExpansion::DoSavestate(Savestate* file)
|
|||
file->Var16(&RAMEnable);
|
||||
}
|
||||
|
||||
u16 CartRAMExpansion::ROMRead(u32 addr)
|
||||
u16 CartRAMExpansion::ROMRead(u32 addr) const
|
||||
{
|
||||
addr &= 0x01FFFFFF;
|
||||
|
||||
|
@ -696,25 +691,12 @@ void CartRAMExpansion::ROMWrite(u32 addr, u16 val)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool Init()
|
||||
{
|
||||
Cart = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeInit()
|
||||
{
|
||||
Cart = nullptr;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
void GBACartSlot::Reset() noexcept
|
||||
{
|
||||
if (Cart) Cart->Reset();
|
||||
}
|
||||
|
||||
void DoSavestate(Savestate* file)
|
||||
void GBACartSlot::DoSavestate(Savestate* file) noexcept
|
||||
{
|
||||
file->Section("GBAC"); // Game Boy Advance Cartridge
|
||||
|
||||
|
@ -816,7 +798,7 @@ std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen)
|
|||
return cart;
|
||||
}
|
||||
|
||||
bool InsertROM(std::unique_ptr<CartCommon>&& cart)
|
||||
bool GBACartSlot::InsertROM(std::unique_ptr<CartCommon>&& cart) noexcept
|
||||
{
|
||||
if (!cart) {
|
||||
Log(LogLevel::Error, "Failed to insert invalid GBA cart; existing cart (if any) was not ejected.\n");
|
||||
|
@ -844,14 +826,14 @@ bool InsertROM(std::unique_ptr<CartCommon>&& cart)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LoadROM(const u8* romdata, u32 romlen)
|
||||
bool GBACartSlot::LoadROM(const u8* romdata, u32 romlen) noexcept
|
||||
{
|
||||
std::unique_ptr<CartCommon> data = ParseROM(romdata, romlen);
|
||||
|
||||
return InsertROM(std::move(data));
|
||||
}
|
||||
|
||||
void LoadSave(const u8* savedata, u32 savelen)
|
||||
void GBACartSlot::LoadSave(const u8* savedata, u32 savelen) noexcept
|
||||
{
|
||||
if (Cart)
|
||||
{
|
||||
|
@ -862,7 +844,7 @@ void LoadSave(const u8* savedata, u32 savelen)
|
|||
}
|
||||
}
|
||||
|
||||
void LoadAddon(int type)
|
||||
void GBACartSlot::LoadAddon(int type) noexcept
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -876,13 +858,13 @@ void LoadAddon(int type)
|
|||
}
|
||||
}
|
||||
|
||||
void EjectCart()
|
||||
void GBACartSlot::EjectCart() noexcept
|
||||
{
|
||||
Cart = nullptr;
|
||||
}
|
||||
|
||||
|
||||
int SetInput(int num, bool pressed)
|
||||
int GBACartSlot::SetInput(int num, bool pressed) noexcept
|
||||
{
|
||||
if (Cart) return Cart->SetInput(num, pressed);
|
||||
|
||||
|
@ -890,44 +872,28 @@ int SetInput(int num, bool pressed)
|
|||
}
|
||||
|
||||
|
||||
void SetOpenBusDecay(u16 val)
|
||||
{
|
||||
OpenBusDecay = val;
|
||||
}
|
||||
|
||||
|
||||
u16 ROMRead(u32 addr)
|
||||
u16 GBACartSlot::ROMRead(u32 addr) const noexcept
|
||||
{
|
||||
if (Cart) return Cart->ROMRead(addr);
|
||||
|
||||
return ((addr >> 1) & 0xFFFF) | OpenBusDecay;
|
||||
}
|
||||
|
||||
void ROMWrite(u32 addr, u16 val)
|
||||
void GBACartSlot::ROMWrite(u32 addr, u16 val) noexcept
|
||||
{
|
||||
if (Cart) Cart->ROMWrite(addr, val);
|
||||
}
|
||||
|
||||
u8 SRAMRead(u32 addr)
|
||||
u8 GBACartSlot::SRAMRead(u32 addr) noexcept
|
||||
{
|
||||
if (Cart) return Cart->SRAMRead(addr);
|
||||
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
void SRAMWrite(u32 addr, u8 val)
|
||||
void GBACartSlot::SRAMWrite(u32 addr, u8 val) noexcept
|
||||
{
|
||||
if (Cart) Cart->SRAMWrite(addr, val);
|
||||
}
|
||||
|
||||
u8* GetSaveMemory()
|
||||
{
|
||||
return Cart ? Cart->GetSaveMemory() : nullptr;
|
||||
}
|
||||
|
||||
u32 GetSaveMemoryLength()
|
||||
{
|
||||
return Cart ? Cart->GetSaveMemoryLength() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
|
||||
virtual int SetInput(int num, bool pressed);
|
||||
|
||||
virtual u16 ROMRead(u32 addr);
|
||||
virtual u16 ROMRead(u32 addr) const;
|
||||
virtual void ROMWrite(u32 addr, u16 val);
|
||||
|
||||
virtual u8 SRAMRead(u32 addr);
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
virtual void SetupSave(u32 type) override;
|
||||
virtual void LoadSave(const u8* savedata, u32 savelen) override;
|
||||
|
||||
virtual u16 ROMRead(u32 addr) override;
|
||||
virtual u16 ROMRead(u32 addr) const override;
|
||||
virtual void ROMWrite(u32 addr, u16 val) override;
|
||||
|
||||
virtual u8 SRAMRead(u32 addr) override;
|
||||
|
@ -180,7 +180,7 @@ public:
|
|||
|
||||
void DoSavestate(Savestate* file) override;
|
||||
|
||||
u16 ROMRead(u32 addr) override;
|
||||
u16 ROMRead(u32 addr) const override;
|
||||
void ROMWrite(u32 addr, u16 val) override;
|
||||
|
||||
private:
|
||||
|
@ -195,13 +195,52 @@ enum
|
|||
Input_SolarSensorUp,
|
||||
};
|
||||
|
||||
extern std::unique_ptr<CartCommon> Cart;
|
||||
class GBACartSlot
|
||||
{
|
||||
public:
|
||||
GBACartSlot() noexcept = default;
|
||||
~GBACartSlot() noexcept = default;
|
||||
void Reset() noexcept;
|
||||
void DoSavestate(Savestate* file) noexcept;
|
||||
/// Applies the GBACartData to the emulator state and unloads an existing ROM if any.
|
||||
/// Upon successful insertion, \c cart will be nullptr and the global GBACart state
|
||||
/// (\c CartROM, CartInserted, etc.) will be updated.
|
||||
bool InsertROM(std::unique_ptr<CartCommon>&& cart) noexcept;
|
||||
bool LoadROM(const u8* romdata, u32 romlen) noexcept;
|
||||
void LoadSave(const u8* savedata, u32 savelen) noexcept;
|
||||
|
||||
bool Init();
|
||||
void DeInit();
|
||||
void Reset();
|
||||
void LoadAddon(int type) noexcept;
|
||||
|
||||
void DoSavestate(Savestate* file);
|
||||
void EjectCart() noexcept;
|
||||
|
||||
// TODO: make more flexible, support nonbinary inputs
|
||||
int SetInput(int num, bool pressed) noexcept;
|
||||
|
||||
void SetOpenBusDecay(u16 val) noexcept { OpenBusDecay = val; }
|
||||
|
||||
u16 ROMRead(u32 addr) const noexcept;
|
||||
void ROMWrite(u32 addr, u16 val) noexcept;
|
||||
|
||||
u8 SRAMRead(u32 addr) noexcept;
|
||||
void SRAMWrite(u32 addr, u8 val) noexcept;
|
||||
|
||||
/// This function is intended to allow frontends to save and load SRAM
|
||||
/// without using melonDS APIs.
|
||||
/// Modifying the emulated SRAM for any other reason is strongly discouraged.
|
||||
/// The returned pointer may be invalidated if the emulator is reset,
|
||||
/// or when a new game is loaded.
|
||||
/// Consequently, don't store the returned pointer for any longer than necessary.
|
||||
/// @returns Pointer to this cart's SRAM if a cart is loaded and supports SRAM, otherwise \c nullptr.
|
||||
[[nodiscard]] u8* GetSaveMemory() noexcept { return Cart ? Cart->GetSaveMemory() : nullptr; }
|
||||
[[nodiscard]] const u8* GetSaveMemory() const noexcept { return Cart ? Cart->GetSaveMemory() : nullptr; }
|
||||
|
||||
/// @returns The length of the buffer returned by ::GetSaveMemory()
|
||||
/// if a cart is loaded and supports SRAM, otherwise zero.
|
||||
[[nodiscard]] u32 GetSaveMemoryLength() const noexcept { return Cart ? Cart->GetSaveMemoryLength() : 0; }
|
||||
private:
|
||||
std::unique_ptr<CartCommon> Cart = nullptr;
|
||||
u16 OpenBusDecay = 0;
|
||||
};
|
||||
|
||||
/// Parses the given ROM data and constructs a \c GBACart::CartCommon subclass
|
||||
/// that can be inserted into the emulator or used to extract information about the cart beforehand.
|
||||
|
@ -213,45 +252,6 @@ void DoSavestate(Savestate* file);
|
|||
/// or \c nullptr if the ROM data couldn't be parsed.
|
||||
std::unique_ptr<CartCommon> ParseROM(const u8* romdata, u32 romlen);
|
||||
|
||||
/// Applies the GBACartData to the emulator state and unloads an existing ROM if any.
|
||||
/// Upon successful insertion, \c cart will be nullptr and the global GBACart state
|
||||
/// (\c CartROM, CartInserted, etc.) will be updated.
|
||||
bool InsertROM(std::unique_ptr<CartCommon>&& cart);
|
||||
bool LoadROM(const u8* romdata, u32 romlen);
|
||||
void LoadSave(const u8* savedata, u32 savelen);
|
||||
|
||||
void LoadAddon(int type);
|
||||
|
||||
void EjectCart();
|
||||
|
||||
//bool LoadROM(const char* path, const char* sram);
|
||||
//bool LoadROM(const u8* romdata, u32 filelength, const char *sram);
|
||||
//void RelocateSave(const char* path, bool write);
|
||||
|
||||
// TODO: make more flexible, support nonbinary inputs
|
||||
int SetInput(int num, bool pressed);
|
||||
|
||||
void SetOpenBusDecay(u16 val);
|
||||
|
||||
u16 ROMRead(u32 addr);
|
||||
void ROMWrite(u32 addr, u16 val);
|
||||
|
||||
u8 SRAMRead(u32 addr);
|
||||
void SRAMWrite(u32 addr, u8 val);
|
||||
|
||||
/// This function is intended to allow frontends to save and load SRAM
|
||||
/// without using melonDS APIs.
|
||||
/// Modifying the emulated SRAM for any other reason is strongly discouraged.
|
||||
/// The returned pointer may be invalidated if the emulator is reset,
|
||||
/// or when a new game is loaded.
|
||||
/// Consequently, don't store the returned pointer for any longer than necessary.
|
||||
/// @returns Pointer to this cart's SRAM if a cart is loaded and supports SRAM, otherwise \c nullptr.
|
||||
u8* GetSaveMemory();
|
||||
|
||||
/// @returns The length of the buffer returned by ::GetSaveMemory()
|
||||
/// if a cart is loaded and supports SRAM, otherwise zero.
|
||||
u32 GetSaveMemoryLength();
|
||||
|
||||
}
|
||||
|
||||
#endif // GBACART_H
|
||||
|
|
136
src/NDS.cpp
136
src/NDS.cpp
|
@ -16,6 +16,7 @@
|
|||
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -182,7 +183,7 @@ class SPU* SPU;
|
|||
class SPIHost* SPI;
|
||||
class RTC* RTC;
|
||||
class Wifi* Wifi;
|
||||
|
||||
std::unique_ptr<GBACart::GBACartSlot> GBACartSlot;
|
||||
class AREngine* AREngine;
|
||||
|
||||
bool Running;
|
||||
|
@ -226,9 +227,9 @@ bool Init()
|
|||
SPI = new class SPIHost();
|
||||
RTC = new class RTC();
|
||||
Wifi = new class Wifi();
|
||||
GBACartSlot = std::make_unique<GBACart::GBACartSlot>();
|
||||
|
||||
if (!NDSCart::Init()) return false;
|
||||
if (!GBACart::Init()) return false;
|
||||
if (!GPU::Init()) return false;
|
||||
|
||||
if (!DSi::Init()) return false;
|
||||
|
@ -259,7 +260,7 @@ void DeInit()
|
|||
delete Wifi; Wifi = nullptr;
|
||||
|
||||
NDSCart::DeInit();
|
||||
GBACart::DeInit();
|
||||
GBACartSlot = nullptr;
|
||||
GPU::DeInit();
|
||||
|
||||
DSi::DeInit();
|
||||
|
@ -644,7 +645,7 @@ void Reset()
|
|||
RCnt = 0;
|
||||
|
||||
NDSCart::Reset();
|
||||
GBACart::Reset();
|
||||
GBACartSlot->Reset();
|
||||
GPU::Reset();
|
||||
SPU->Reset();
|
||||
SPI->Reset();
|
||||
|
@ -846,7 +847,7 @@ bool DoSavestate(Savestate* file)
|
|||
|
||||
NDSCart::DoSavestate(file);
|
||||
if (ConsoleType == 0)
|
||||
GBACart::DoSavestate(file);
|
||||
GBACartSlot->DoSavestate(file);
|
||||
GPU::DoSavestate(file);
|
||||
SPU->DoSavestate(file);
|
||||
SPI->DoSavestate(file);
|
||||
|
@ -911,23 +912,28 @@ bool CartInserted()
|
|||
|
||||
bool LoadGBACart(const u8* romdata, u32 romlen, const u8* savedata, u32 savelen)
|
||||
{
|
||||
if (!GBACart::LoadROM(romdata, romlen))
|
||||
if (!GBACartSlot)
|
||||
return false;
|
||||
|
||||
if (!GBACartSlot->LoadROM(romdata, romlen))
|
||||
return false;
|
||||
|
||||
if (savedata && savelen)
|
||||
GBACart::LoadSave(savedata, savelen);
|
||||
GBACartSlot->LoadSave(savedata, savelen);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadGBAAddon(int type)
|
||||
{
|
||||
GBACart::LoadAddon(type);
|
||||
if (GBACartSlot)
|
||||
GBACartSlot->LoadAddon(type);
|
||||
}
|
||||
|
||||
void EjectGBACart()
|
||||
{
|
||||
GBACart::EjectCart();
|
||||
if (GBACartSlot)
|
||||
GBACartSlot->EjectCart();
|
||||
}
|
||||
|
||||
void LoadBIOS()
|
||||
|
@ -1493,7 +1499,8 @@ void SetGBASlotTimings()
|
|||
// for example, the Cartridge Construction Kit relies on this to determine that
|
||||
// the GBA slot is empty
|
||||
|
||||
GBACart::SetOpenBusDecay(openbus[(curcnt>>2) & 0x3]);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SetOpenBusDecay(openbus[(curcnt>>2) & 0x3]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2161,12 +2168,14 @@ u8 ARM9Read8(u32 addr)
|
|||
case 0x08000000:
|
||||
case 0x09000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x00; // deselected CPU is 00h-filled
|
||||
if (addr & 0x1) return GBACart::ROMRead(addr-1) >> 8;
|
||||
return GBACart::ROMRead(addr) & 0xFF;
|
||||
assert(GBACartSlot != nullptr);
|
||||
if (addr & 0x1) return GBACartSlot->ROMRead(addr-1) >> 8;
|
||||
return GBACartSlot->ROMRead(addr) & 0xFF;
|
||||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x00; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr);
|
||||
}
|
||||
|
||||
Log(LogLevel::Debug, "unknown arm9 read8 %08X\n", addr);
|
||||
|
@ -2221,12 +2230,14 @@ u16 ARM9Read16(u32 addr)
|
|||
case 0x08000000:
|
||||
case 0x09000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x0000; // deselected CPU is 00h-filled
|
||||
return GBACart::ROMRead(addr);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->ROMRead(addr);
|
||||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x0000; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr) |
|
||||
(GBACart::SRAMRead(addr+1) << 8);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr) |
|
||||
(GBACartSlot->SRAMRead(addr+1) << 8);
|
||||
}
|
||||
|
||||
//if (addr) Log(LogLevel::Warn, "unknown arm9 read16 %08X %08X\n", addr, ARM9->R[15]);
|
||||
|
@ -2281,15 +2292,17 @@ u32 ARM9Read32(u32 addr)
|
|||
case 0x08000000:
|
||||
case 0x09000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x00000000; // deselected CPU is 00h-filled
|
||||
return GBACart::ROMRead(addr) |
|
||||
(GBACart::ROMRead(addr+2) << 16);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->ROMRead(addr) |
|
||||
(GBACartSlot->ROMRead(addr+2) << 16);
|
||||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return 0x00000000; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr) |
|
||||
(GBACart::SRAMRead(addr+1) << 8) |
|
||||
(GBACart::SRAMRead(addr+2) << 16) |
|
||||
(GBACart::SRAMRead(addr+3) << 24);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr) |
|
||||
(GBACartSlot->SRAMRead(addr+1) << 8) |
|
||||
(GBACartSlot->SRAMRead(addr+2) << 16) |
|
||||
(GBACartSlot->SRAMRead(addr+3) << 24);
|
||||
}
|
||||
|
||||
//Log(LogLevel::Warn, "unknown arm9 read32 %08X | %08X %08X\n", addr, ARM9->R[15], ARM9->R[12]);
|
||||
|
@ -2332,7 +2345,8 @@ void ARM9Write8(u32 addr, u8 val)
|
|||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SRAMWrite(addr, val);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2392,13 +2406,15 @@ void ARM9Write16(u32 addr, u16 val)
|
|||
case 0x08000000:
|
||||
case 0x09000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
|
||||
GBACart::ROMWrite(addr, val);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->ROMWrite(addr, val);
|
||||
return;
|
||||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val & 0xFF);
|
||||
GBACart::SRAMWrite(addr+1, val >> 8);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SRAMWrite(addr, val & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+1, val >> 8);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2458,16 +2474,18 @@ void ARM9Write32(u32 addr, u32 val)
|
|||
case 0x08000000:
|
||||
case 0x09000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
|
||||
GBACart::ROMWrite(addr, val & 0xFFFF);
|
||||
GBACart::ROMWrite(addr+2, val >> 16);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->ROMWrite(addr, val & 0xFFFF);
|
||||
GBACartSlot->ROMWrite(addr+2, val >> 16);
|
||||
return;
|
||||
|
||||
case 0x0A000000:
|
||||
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val & 0xFF);
|
||||
GBACart::SRAMWrite(addr+1, (val >> 8) & 0xFF);
|
||||
GBACart::SRAMWrite(addr+2, (val >> 16) & 0xFF);
|
||||
GBACart::SRAMWrite(addr+3, val >> 24);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SRAMWrite(addr, val & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+1, (val >> 8) & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+2, (val >> 16) & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+3, val >> 24);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2559,13 +2577,15 @@ u8 ARM7Read8(u32 addr)
|
|||
case 0x09000000:
|
||||
case 0x09800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x00; // deselected CPU is 00h-filled
|
||||
if (addr & 0x1) return GBACart::ROMRead(addr-1) >> 8;
|
||||
return GBACart::ROMRead(addr) & 0xFF;
|
||||
assert(GBACartSlot != nullptr);
|
||||
if (addr & 0x1) return GBACartSlot->ROMRead(addr-1) >> 8;
|
||||
return GBACartSlot->ROMRead(addr) & 0xFF;
|
||||
|
||||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x00; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr);
|
||||
}
|
||||
|
||||
Log(LogLevel::Debug, "unknown arm7 read8 %08X %08X %08X/%08X\n", addr, ARM7->R[15], ARM7->R[0], ARM7->R[1]);
|
||||
|
@ -2625,13 +2645,15 @@ u16 ARM7Read16(u32 addr)
|
|||
case 0x09000000:
|
||||
case 0x09800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x0000; // deselected CPU is 00h-filled
|
||||
return GBACart::ROMRead(addr);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->ROMRead(addr);
|
||||
|
||||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x0000; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr) |
|
||||
(GBACart::SRAMRead(addr+1) << 8);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr) |
|
||||
(GBACartSlot->SRAMRead(addr+1) << 8);
|
||||
}
|
||||
|
||||
Log(LogLevel::Debug, "unknown arm7 read16 %08X %08X\n", addr, ARM7->R[15]);
|
||||
|
@ -2691,16 +2713,18 @@ u32 ARM7Read32(u32 addr)
|
|||
case 0x09000000:
|
||||
case 0x09800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x00000000; // deselected CPU is 00h-filled
|
||||
return GBACart::ROMRead(addr) |
|
||||
(GBACart::ROMRead(addr+2) << 16);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->ROMRead(addr) |
|
||||
(GBACartSlot->ROMRead(addr+2) << 16);
|
||||
|
||||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return 0x00000000; // deselected CPU is 00h-filled
|
||||
return GBACart::SRAMRead(addr) |
|
||||
(GBACart::SRAMRead(addr+1) << 8) |
|
||||
(GBACart::SRAMRead(addr+2) << 16) |
|
||||
(GBACart::SRAMRead(addr+3) << 24);
|
||||
assert(GBACartSlot != nullptr);
|
||||
return GBACartSlot->SRAMRead(addr) |
|
||||
(GBACartSlot->SRAMRead(addr+1) << 8) |
|
||||
(GBACartSlot->SRAMRead(addr+2) << 16) |
|
||||
(GBACartSlot->SRAMRead(addr+3) << 24);
|
||||
}
|
||||
|
||||
//Log(LogLevel::Warn, "unknown arm7 read32 %08X | %08X\n", addr, ARM7->R[15]);
|
||||
|
@ -2765,7 +2789,8 @@ void ARM7Write8(u32 addr, u8 val)
|
|||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SRAMWrite(addr, val);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2839,14 +2864,15 @@ void ARM7Write16(u32 addr, u16 val)
|
|||
case 0x09000000:
|
||||
case 0x09800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
|
||||
GBACart::ROMWrite(addr, val);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->ROMWrite(addr, val);
|
||||
return;
|
||||
|
||||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val & 0xFF);
|
||||
GBACart::SRAMWrite(addr+1, val >> 8);
|
||||
GBACartSlot->SRAMWrite(addr, val & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+1, val >> 8);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2920,17 +2946,19 @@ void ARM7Write32(u32 addr, u32 val)
|
|||
case 0x09000000:
|
||||
case 0x09800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
|
||||
GBACart::ROMWrite(addr, val & 0xFFFF);
|
||||
GBACart::ROMWrite(addr+2, val >> 16);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->ROMWrite(addr, val & 0xFFFF);
|
||||
GBACartSlot->ROMWrite(addr+2, val >> 16);
|
||||
return;
|
||||
|
||||
case 0x0A000000:
|
||||
case 0x0A800000:
|
||||
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
|
||||
GBACart::SRAMWrite(addr, val & 0xFF);
|
||||
GBACart::SRAMWrite(addr+1, (val >> 8) & 0xFF);
|
||||
GBACart::SRAMWrite(addr+2, (val >> 16) & 0xFF);
|
||||
GBACart::SRAMWrite(addr+3, val >> 24);
|
||||
assert(GBACartSlot != nullptr);
|
||||
GBACartSlot->SRAMWrite(addr, val & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+1, (val >> 8) & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+2, (val >> 16) & 0xFF);
|
||||
GBACartSlot->SRAMWrite(addr+3, val >> 24);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#define NDS_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include "Platform.h"
|
||||
#include "Savestate.h"
|
||||
#include "types.h"
|
||||
#include "GBACart.h"
|
||||
|
||||
// when touching the main loop/timing code, pls test a lot of shit
|
||||
// with this enabled, to make sure it doesn't desync
|
||||
|
@ -257,7 +259,7 @@ extern class SPU* SPU;
|
|||
extern class SPIHost* SPI;
|
||||
extern class RTC* RTC;
|
||||
extern class Wifi* Wifi;
|
||||
|
||||
extern std::unique_ptr<GBACart::GBACartSlot> GBACartSlot;
|
||||
extern class AREngine* AREngine;
|
||||
|
||||
const u32 ARM7WRAMSize = 0x10000;
|
||||
|
|
|
@ -384,7 +384,8 @@ void EmuThread::run()
|
|||
|
||||
if (Input::HotkeyPressed(HK_SolarSensorDecrease))
|
||||
{
|
||||
int level = GBACart::SetInput(GBACart::Input_SolarSensorDown, true);
|
||||
assert(NDS::GBACartSlot != nullptr);
|
||||
int level = NDS::GBACartSlot->SetInput(GBACart::Input_SolarSensorDown, true);
|
||||
if (level != -1)
|
||||
{
|
||||
char msg[64];
|
||||
|
@ -394,7 +395,8 @@ void EmuThread::run()
|
|||
}
|
||||
if (Input::HotkeyPressed(HK_SolarSensorIncrease))
|
||||
{
|
||||
int level = GBACart::SetInput(GBACart::Input_SolarSensorUp, true);
|
||||
assert(NDS::GBACartSlot != nullptr);
|
||||
int level = NDS::GBACartSlot->SetInput(GBACart::Input_SolarSensorUp, true);
|
||||
if (level != -1)
|
||||
{
|
||||
char msg[64];
|
||||
|
|
Loading…
Reference in New Issue