2019-02-15 21:33:13 -05:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "IMemoryHandler.h"
|
2019-03-12 09:15:57 -04:00
|
|
|
#include "CartTypes.h"
|
2020-06-18 00:58:22 -04:00
|
|
|
#include "BaseCoprocessor.h"
|
2019-03-12 09:15:57 -04:00
|
|
|
#include "../Utilities/ISerializable.h"
|
2019-02-15 21:33:13 -05:00
|
|
|
|
2019-07-25 22:22:09 -04:00
|
|
|
class MemoryMappings;
|
2019-02-17 14:42:35 -05:00
|
|
|
class VirtualFile;
|
2019-07-06 14:25:51 -04:00
|
|
|
class EmuSettings;
|
2019-07-14 21:45:12 -04:00
|
|
|
class NecDsp;
|
2019-07-25 22:22:09 -04:00
|
|
|
class Sa1;
|
2019-07-30 22:34:52 -04:00
|
|
|
class Gsu;
|
2019-08-03 23:43:51 -04:00
|
|
|
class Cx4;
|
2020-06-18 00:58:22 -04:00
|
|
|
class SuperGameboy;
|
2020-02-19 23:53:34 -05:00
|
|
|
class BsxCart;
|
|
|
|
class BsxMemoryPack;
|
2020-05-18 16:10:53 -04:00
|
|
|
class Gameboy;
|
2019-07-14 21:45:12 -04:00
|
|
|
class Console;
|
2019-10-19 15:23:17 -04:00
|
|
|
class SpcFileData;
|
2019-12-28 09:18:40 -05:00
|
|
|
enum class ConsoleRegion;
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2019-03-12 09:15:57 -04:00
|
|
|
class BaseCartridge : public ISerializable
|
2019-02-15 21:33:13 -05:00
|
|
|
{
|
|
|
|
private:
|
2021-03-10 11:13:28 -05:00
|
|
|
Console *_console;
|
2019-07-06 14:25:51 -04:00
|
|
|
|
2019-02-17 14:42:35 -05:00
|
|
|
vector<unique_ptr<IMemoryHandler>> _prgRomHandlers;
|
|
|
|
vector<unique_ptr<IMemoryHandler>> _saveRamHandlers;
|
2019-07-13 13:43:56 -04:00
|
|
|
SnesCartInformation _cartInfo = {};
|
2020-02-12 19:36:47 -05:00
|
|
|
uint32_t _headerOffset = 0;
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2020-06-18 00:58:22 -04:00
|
|
|
bool _needCoprocSync = false;
|
2019-07-14 21:45:12 -04:00
|
|
|
unique_ptr<BaseCoprocessor> _coprocessor;
|
2021-03-10 11:13:28 -05:00
|
|
|
|
|
|
|
NecDsp *_necDsp = nullptr;
|
|
|
|
Sa1 *_sa1 = nullptr;
|
|
|
|
Gsu *_gsu = nullptr;
|
|
|
|
Cx4 *_cx4 = nullptr;
|
|
|
|
SuperGameboy *_sgb = nullptr;
|
2020-02-19 23:53:34 -05:00
|
|
|
BsxCart* _bsx = nullptr;
|
|
|
|
unique_ptr<BsxMemoryPack> _bsxMemPack;
|
2020-05-18 16:10:53 -04:00
|
|
|
unique_ptr<Gameboy> _gameboy;
|
2019-07-14 21:45:12 -04:00
|
|
|
|
2019-07-13 13:43:56 -04:00
|
|
|
CartFlags::CartFlags _flags = CartFlags::CartFlags::None;
|
2019-07-14 21:45:12 -04:00
|
|
|
CoprocessorType _coprocessorType = CoprocessorType::None;
|
2019-07-31 23:32:16 -04:00
|
|
|
bool _hasBattery = false;
|
2020-02-16 21:11:01 -05:00
|
|
|
bool _hasRtc = false;
|
2019-02-24 20:04:59 -05:00
|
|
|
string _romPath;
|
2019-03-31 15:51:13 -04:00
|
|
|
string _patchPath;
|
2019-02-24 20:04:59 -05:00
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
uint8_t* _prgRom = nullptr;
|
|
|
|
uint8_t* _saveRam = nullptr;
|
2021-03-10 11:13:28 -05:00
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
uint32_t _prgRomSize = 0;
|
|
|
|
uint32_t _saveRamSize = 0;
|
2019-07-30 22:34:52 -04:00
|
|
|
uint32_t _coprocessorRamSize = 0;
|
2021-03-10 11:13:28 -05:00
|
|
|
|
2019-10-19 15:23:17 -04:00
|
|
|
shared_ptr<SpcFileData> _spcData;
|
2019-10-26 17:47:57 -04:00
|
|
|
vector<uint8_t> _embeddedFirmware;
|
2019-02-15 21:33:13 -05:00
|
|
|
|
2019-02-24 20:04:59 -05:00
|
|
|
void LoadBattery();
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2019-03-08 20:18:13 -05:00
|
|
|
int32_t GetHeaderScore(uint32_t addr);
|
2019-03-02 21:17:45 -05:00
|
|
|
void DisplayCartInfo();
|
|
|
|
|
2019-07-14 21:45:12 -04:00
|
|
|
CoprocessorType GetCoprocessorType();
|
2019-07-16 00:11:23 -04:00
|
|
|
CoprocessorType GetSt01xVersion();
|
2019-07-14 21:45:12 -04:00
|
|
|
CoprocessorType GetDspVersion();
|
|
|
|
|
2020-02-22 17:42:18 -05:00
|
|
|
bool MapSpecificCarts(MemoryMappings& mm);
|
|
|
|
void MapBsxMemoryPack(MemoryMappings& mm);
|
2019-12-12 22:14:55 -05:00
|
|
|
void ApplyConfigOverrides();
|
2021-03-10 11:13:28 -05:00
|
|
|
|
2019-10-19 15:23:17 -04:00
|
|
|
void LoadRom();
|
|
|
|
void LoadSpc();
|
2020-06-18 22:42:51 -04:00
|
|
|
bool LoadGameboy(VirtualFile& romFile, bool sgbEnabled);
|
2020-05-18 16:10:53 -04:00
|
|
|
void SetupCpuHalt();
|
2019-07-25 22:22:09 -04:00
|
|
|
void InitCoprocessor();
|
2019-10-26 17:47:57 -04:00
|
|
|
void LoadEmbeddedFirmware();
|
2019-07-14 21:45:12 -04:00
|
|
|
|
2019-04-10 18:45:49 -04:00
|
|
|
string GetCartName();
|
2019-07-05 21:27:45 -04:00
|
|
|
string GetGameCode();
|
2019-04-10 18:45:49 -04:00
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
public:
|
2019-03-31 14:50:12 -04:00
|
|
|
virtual ~BaseCartridge();
|
2019-02-16 01:16:57 -05:00
|
|
|
|
2021-03-10 11:13:28 -05:00
|
|
|
static shared_ptr<BaseCartridge> CreateCartridge(Console* console, VirtualFile &romFile, VirtualFile &patchFile);
|
2019-02-15 21:33:13 -05:00
|
|
|
|
2019-07-14 21:45:12 -04:00
|
|
|
void Reset();
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2019-03-16 12:20:18 -04:00
|
|
|
void SaveBattery();
|
|
|
|
|
2021-03-10 11:13:28 -05:00
|
|
|
void Init(MemoryMappings &mm);
|
2019-07-25 22:22:09 -04:00
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
RomInfo GetRomInfo();
|
2020-06-06 22:34:40 -04:00
|
|
|
vector<uint8_t> GetOriginalPrgRom();
|
2019-12-28 09:18:40 -05:00
|
|
|
ConsoleRegion GetRegion();
|
2020-02-26 21:45:49 -05:00
|
|
|
uint32_t GetCrc32();
|
2019-03-12 09:15:57 -04:00
|
|
|
string GetSha1Hash();
|
2019-07-14 21:45:12 -04:00
|
|
|
CartFlags::CartFlags GetCartFlags();
|
2019-02-26 22:27:09 -05:00
|
|
|
|
2021-03-10 11:13:28 -05:00
|
|
|
void RegisterHandlers(MemoryMappings &mm);
|
2019-02-15 21:33:13 -05:00
|
|
|
|
|
|
|
uint8_t* DebugGetPrgRom() { return _prgRom; }
|
|
|
|
uint8_t* DebugGetSaveRam() { return _saveRam; }
|
|
|
|
uint32_t DebugGetPrgRomSize() { return _prgRomSize; }
|
|
|
|
uint32_t DebugGetSaveRamSize() { return _saveRamSize; }
|
2019-03-12 09:15:57 -04:00
|
|
|
|
2019-07-14 21:45:12 -04:00
|
|
|
NecDsp* GetDsp();
|
2019-07-25 22:22:09 -04:00
|
|
|
Sa1* GetSa1();
|
2019-07-30 22:34:52 -04:00
|
|
|
Gsu* GetGsu();
|
2019-08-03 23:43:51 -04:00
|
|
|
Cx4* GetCx4();
|
2020-06-18 00:58:22 -04:00
|
|
|
SuperGameboy* GetSuperGameboy();
|
2020-02-19 23:53:34 -05:00
|
|
|
BsxCart* GetBsx();
|
|
|
|
BsxMemoryPack* GetBsxMemoryPack();
|
2020-05-18 16:10:53 -04:00
|
|
|
Gameboy* GetGameboy();
|
2019-07-30 22:34:52 -04:00
|
|
|
|
|
|
|
void RunCoprocessors();
|
2021-03-10 11:13:28 -05:00
|
|
|
|
2020-06-18 00:58:22 -04:00
|
|
|
__forceinline void SyncCoprocessors()
|
|
|
|
{
|
2021-03-10 11:13:28 -05:00
|
|
|
if(_needCoprocSync) {
|
2020-06-18 00:58:22 -04:00
|
|
|
_coprocessor->Run();
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 22:34:52 -04:00
|
|
|
|
2019-07-14 21:45:12 -04:00
|
|
|
BaseCoprocessor* GetCoprocessor();
|
|
|
|
|
2019-07-25 22:22:09 -04:00
|
|
|
vector<unique_ptr<IMemoryHandler>>& GetPrgRomHandlers();
|
|
|
|
vector<unique_ptr<IMemoryHandler>>& GetSaveRamHandlers();
|
|
|
|
|
2019-10-19 15:23:17 -04:00
|
|
|
SpcFileData* GetSpcData();
|
|
|
|
|
2021-03-10 11:13:28 -05:00
|
|
|
void Serialize(Serializer &s) override;
|
2019-02-15 21:33:13 -05:00
|
|
|
};
|