diff options
author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-03-27 16:36:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 22:36:26 +0200 |
commit | b078ca802f8f38e5602c8ce89d9b340ff0a6aacd (patch) | |
tree | 6b55e20ee7b733e5305648626279c64153696b27 /src/NDSCart.h | |
parent | 808292e424a2554b7e2b3f0fd0e86120c1dbabd5 (diff) |
Expose SRAM pointers for frontends that manage save data their own way (#1643)
* Add a clarifying comment
- In case it saves some poor bastard hours of fruitless work
* Expose GBA and NDS save memory
- Add GetSaveMemory and GetSaveMemoryLength functions
- Where unsupported, they return null and zero
Diffstat (limited to 'src/NDSCart.h')
-rw-r--r-- | src/NDSCart.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/NDSCart.h b/src/NDSCart.h index 10286ac..b9561f0 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -52,6 +52,9 @@ public: virtual u8 SPIWrite(u8 val, u32 pos, bool last); + virtual u8* GetSaveMemory() const; + virtual u32 GetSaveMemoryLength() const; + protected: void ReadROM(u32 addr, u32 len, u8* data, u32 offset); @@ -88,6 +91,9 @@ public: virtual u8 SPIWrite(u8 val, u32 pos, bool last) override; + virtual u8* GetSaveMemory() const override; + virtual u32 GetSaveMemoryLength() const override; + protected: void ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset); @@ -223,6 +229,19 @@ bool LoadROM(const u8* romdata, u32 romlen); void LoadSave(const u8* savedata, u32 savelen); void SetupDirectBoot(std::string romname); +/// 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(); + void EjectCart(); void ResetCart(); |