diff options
author | Arisotura <thetotalworm@gmail.com> | 2021-04-25 00:48:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-25 00:48:02 +0200 |
commit | 1846a712659ed31357e8ae795055dace0bdd951d (patch) | |
tree | a11c1bf2c0b61ee787dac81eec6d7f35fbcace63 /src/GBACart.h | |
parent | ede6e832d84b9d4b1117ee480122480a7c540509 (diff) |
Cart refactor (#1073)
complete cart-interface refactor, will make this code a lot easier to deal with
Diffstat (limited to 'src/GBACart.h')
-rw-r--r-- | src/GBACart.h | 142 |
1 files changed, 113 insertions, 29 deletions
diff --git a/src/GBACart.h b/src/GBACart.h index 7f5f916..1f4d258 100644 --- a/src/GBACart.h +++ b/src/GBACart.h @@ -22,39 +22,128 @@ #include "types.h"
#include "Savestate.h"
+namespace GBACart
+{
-namespace GBACart_SRAM
+// CartCommon -- base code shared by all cart types
+class CartCommon
{
+public:
+ CartCommon();
+ virtual ~CartCommon();
-extern u8* SRAM;
-extern u32 SRAMLength;
+ virtual void DoSavestate(Savestate* file);
-void Reset();
-void DoSavestate(Savestate* file);
+ virtual void LoadSave(const char* path, u32 type);
+ virtual void RelocateSave(const char* path, bool write);
-u8 Read8(u32 addr);
-u16 Read16(u32 addr);
-u32 Read32(u32 addr);
+ virtual int SetInput(int num, bool pressed);
-void Write8(u32 addr, u8 val);
-void Write16(u32 addr, u16 val);
-void Write32(u32 addr, u32 val);
+ virtual u16 ROMRead(u32 addr);
+ virtual void ROMWrite(u32 addr, u16 val);
-}
+ virtual u8 SRAMRead(u32 addr);
+ virtual void SRAMWrite(u32 addr, u8 val);
+};
+// CartGame -- regular retail game cart (ROM, SRAM)
+class CartGame : public CartCommon
+{
+public:
+ CartGame(u8* rom, u32 len);
+ virtual ~CartGame() override;
+
+ virtual void DoSavestate(Savestate* file) override;
+
+ virtual void LoadSave(const char* path, u32 type) override;
+ virtual void RelocateSave(const char* path, bool write) override;
+
+ virtual u16 ROMRead(u32 addr) override;
+ virtual void ROMWrite(u32 addr, u16 val) override;
+
+ virtual u8 SRAMRead(u32 addr) override;
+ virtual void SRAMWrite(u32 addr, u8 val) override;
+
+protected:
+ virtual void ProcessGPIO();
+
+ u8 SRAMRead_EEPROM(u32 addr);
+ void SRAMWrite_EEPROM(u32 addr, u8 val);
+ u8 SRAMRead_FLASH(u32 addr);
+ void SRAMWrite_FLASH(u32 addr, u8 val);
+ u8 SRAMRead_SRAM(u32 addr);
+ void SRAMWrite_SRAM(u32 addr, u8 val);
+
+ u8* ROM;
+ u32 ROMLength;
+
+ struct
+ {
+ u16 data;
+ u16 direction;
+ u16 control;
+
+ } GPIO;
+
+ enum SaveType
+ {
+ S_NULL,
+ S_EEPROM4K,
+ S_EEPROM64K,
+ S_SRAM256K,
+ S_FLASH512K,
+ S_FLASH1M
+ };
+
+ // from DeSmuME
+ struct
+ {
+ u8 state;
+ u8 cmd;
+ u8 device;
+ u8 manufacturer;
+ u8 bank;
+
+ } SRAMFlashState;
+
+ u8* SRAM;
+ FILE* SRAMFile;
+ u32 SRAMLength;
+ SaveType SRAMType;
+
+ char SRAMPath[1024];
+};
-namespace GBACart
+// CartGameSolarSensor -- Boktai game cart
+class CartGameSolarSensor : public CartGame
{
+public:
+ CartGameSolarSensor(u8* rom, u32 len);
+ virtual ~CartGameSolarSensor() override;
+
+ virtual void DoSavestate(Savestate* file) override;
+
+ virtual int SetInput(int num, bool pressed) override;
-struct GPIO
+private:
+ virtual void ProcessGPIO() override;
+
+ static const int kLuxLevels[11];
+
+ bool LightEdge;
+ u8 LightCounter;
+ u8 LightSample;
+ u8 LightLevel;
+};
+
+// possible inputs for GBA carts that might accept user input
+enum
{
- u16 data;
- u16 direction;
- u16 control;
+ Input_SolarSensorDown = 0,
+ Input_SolarSensorUp,
};
extern bool CartInserted;
-extern bool HasSolarSensor;
extern u8* CartROM;
extern u32 CartROMSize;
extern u32 CartCRC;
@@ -69,19 +158,14 @@ 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);
-void WriteGPIO(u32 addr, u16 val);
-
-}
+// TODO: make more flexible, support nonbinary inputs
+int SetInput(int num, bool pressed);
+u16 ROMRead(u32 addr);
+void ROMWrite(u32 addr, u16 val);
-namespace GBACart_SolarSensor
-{
-
-extern u8 LightLevel;
-
-void Reset();
-void DoSavestate(Savestate* file);
-void Process(GBACart::GPIO* gpio);
+u8 SRAMRead(u32 addr);
+void SRAMWrite(u32 addr, u8 val);
}
|