diff options
Diffstat (limited to 'src/GBACart.h')
-rw-r--r-- | src/GBACart.h | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/GBACart.h b/src/GBACart.h index 3357d22..1c7bfb4 100644 --- a/src/GBACart.h +++ b/src/GBACart.h @@ -19,12 +19,21 @@ #ifndef GBACART_H
#define GBACART_H
+#include <memory>
#include "types.h"
#include "Savestate.h"
namespace GBACart
{
+enum CartType
+{
+ Default = 0x001,
+ Game = 0x101,
+ GameSolarSensor = 0x102,
+ RAMExpansion = 0x201,
+};
+
// CartCommon -- base code shared by all cart types
class CartCommon
{
@@ -32,8 +41,8 @@ public: CartCommon();
virtual ~CartCommon();
- virtual u32 Type() { return 0x001; }
- virtual u32 Checksum() { return 0; }
+ virtual u32 Type() const = 0;
+ virtual u32 Checksum() const { return 0; }
virtual void Reset();
@@ -50,6 +59,9 @@ public: virtual u8 SRAMRead(u32 addr);
virtual void SRAMWrite(u32 addr, u8 val);
+ [[nodiscard]] virtual const u8* GetROM() const { return nullptr; }
+ [[nodiscard]] virtual u32 GetROMLength() const { return 0; }
+
virtual u8* GetSaveMemory() const;
virtual u32 GetSaveMemoryLength() const;
};
@@ -61,8 +73,8 @@ public: CartGame(u8* rom, u32 len);
virtual ~CartGame() override;
- virtual u32 Type() override { return 0x101; }
- virtual u32 Checksum() override;
+ virtual u32 Type() const override { return CartType::Game; }
+ virtual u32 Checksum() const override;
virtual void Reset() override;
@@ -77,6 +89,9 @@ public: virtual u8 SRAMRead(u32 addr) override;
virtual void SRAMWrite(u32 addr, u8 val) override;
+ [[nodiscard]] const u8* GetROM() const override { return ROM; }
+ [[nodiscard]] u32 GetROMLength() const override { return ROMLength; }
+
virtual u8* GetSaveMemory() const override;
virtual u32 GetSaveMemoryLength() const override;
protected:
@@ -133,7 +148,7 @@ public: CartGameSolarSensor(u8* rom, u32 len);
virtual ~CartGameSolarSensor() override;
- virtual u32 Type() override { return 0x102; }
+ virtual u32 Type() const override { return CartType::GameSolarSensor; }
virtual void Reset() override;
@@ -159,7 +174,7 @@ public: CartRAMExpansion();
~CartRAMExpansion() override;
- virtual u32 Type() override { return 0x201; }
+ virtual u32 Type() const override { return CartType::RAMExpansion; }
void Reset() override;
@@ -180,9 +195,7 @@ enum Input_SolarSensorUp,
};
-extern bool CartInserted;
-extern u8* CartROM;
-extern u32 CartROMSize;
+extern std::unique_ptr<CartCommon> Cart;
bool Init();
void DeInit();
@@ -190,6 +203,20 @@ void Reset(); void DoSavestate(Savestate* file);
+/// 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.
+/// @param romdata The ROM data to parse.
+/// The returned cartridge will contain a copy of this data,
+/// so the caller may deallocate \c romdata after this function returns.
+/// @param romlen The length of the ROM data in bytes.
+/// @returns A \c GBACart::CartCommon object representing the parsed ROM,
+/// 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);
|