From b078ca802f8f38e5602c8ce89d9b340ff0a6aacd Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Mon, 27 Mar 2023 16:36:26 -0400 Subject: 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 --- src/GBACart.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/GBACart.h') diff --git a/src/GBACart.h b/src/GBACart.h index 8610714..3357d22 100644 --- a/src/GBACart.h +++ b/src/GBACart.h @@ -49,6 +49,9 @@ public: virtual u8 SRAMRead(u32 addr); virtual void SRAMWrite(u32 addr, u8 val); + + virtual u8* GetSaveMemory() const; + virtual u32 GetSaveMemoryLength() const; }; // CartGame -- regular retail game cart (ROM, SRAM) @@ -74,6 +77,8 @@ public: virtual u8 SRAMRead(u32 addr) override; virtual void SRAMWrite(u32 addr, u8 val) override; + virtual u8* GetSaveMemory() const override; + virtual u32 GetSaveMemoryLength() const override; protected: virtual void ProcessGPIO(); @@ -207,6 +212,19 @@ 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 -- cgit v1.2.3