Mesen-SX/Core/MemoryManager.h

105 lines
2.2 KiB
C
Raw Normal View History

#pragma once
#include "stdafx.h"
2019-02-26 22:27:09 -05:00
#include "DebugTypes.h"
#include "MemoryMappings.h"
2019-03-12 09:15:57 -04:00
#include "../Utilities/ISerializable.h"
2019-02-26 22:27:09 -05:00
class IMemoryHandler;
class RegisterHandlerA;
class RegisterHandlerB;
class InternalRegisters;
class RamHandler;
class BaseCartridge;
2019-02-26 22:27:09 -05:00
class Console;
class Ppu;
class Cpu;
2019-10-12 22:40:25 -04:00
class CheatManager;
2019-02-26 22:27:09 -05:00
enum class MemoryOperationType;
2020-06-24 18:43:49 -04:00
enum class SnesEventType : uint8_t
{
HdmaInit,
DramRefresh,
HdmaStart,
EndOfScanline
};
2019-03-12 09:15:57 -04:00
class MemoryManager : public ISerializable
{
2019-02-15 21:33:13 -05:00
public:
constexpr static uint32_t WorkRamSize = 0x20000;
private:
Console* _console;
2019-02-26 22:27:09 -05:00
shared_ptr<RegisterHandlerA> _registerHandlerA;
shared_ptr<RegisterHandlerB> _registerHandlerB;
2020-12-19 23:30:09 +03:00
InternalRegisters* _regs;
Ppu* _ppu;
Cpu* _cpu;
BaseCartridge* _cart;
2019-10-12 22:40:25 -04:00
CheatManager* _cheatManager;
2020-12-19 23:30:09 +03:00
uint8_t* _workRam;
2020-06-24 18:43:49 -04:00
uint64_t _masterClock = 0;
uint16_t _hClock = 0;
2020-06-24 18:43:49 -04:00
uint16_t _nextEventClock = 0;
uint16_t _dramRefreshPosition = 0;
2020-06-24 18:43:49 -04:00
SnesEventType _nextEvent = SnesEventType::DramRefresh;
SnesMemoryType _memTypeBusA = SnesMemoryType::PrgRom;
2020-06-24 18:43:49 -04:00
uint8_t _cpuSpeed = 8;
uint8_t _openBus = 0;
MemoryMappings _mappings;
vector<unique_ptr<IMemoryHandler>> _workRamHandlers;
uint8_t _masterClockTable[0x800];
void Exec();
2019-03-08 10:26:54 -05:00
2020-06-24 18:43:49 -04:00
void ProcessEvent();
public:
void Initialize(Console* console);
virtual ~MemoryManager();
void Reset();
2019-02-26 22:27:09 -05:00
void GenerateMasterClockTable();
void IncMasterClock4();
void IncMasterClock6();
void IncMasterClock8();
void IncMasterClock40();
void IncMasterClockStartup();
2019-02-26 22:27:09 -05:00
void IncrementMasterClockValue(uint16_t value);
2019-02-26 22:27:09 -05:00
uint8_t Read(uint32_t addr, MemoryOperationType type);
uint8_t ReadDma(uint32_t addr, bool forBusA);
2019-02-26 22:27:09 -05:00
uint8_t Peek(uint32_t addr);
uint16_t PeekWord(uint32_t addr);
2020-12-19 23:30:09 +03:00
void PeekBlock(uint32_t addr, uint8_t* dest);
2019-02-26 22:27:09 -05:00
void Write(uint32_t addr, uint8_t value, MemoryOperationType type);
void WriteDma(uint32_t addr, uint8_t value, bool forBusA);
2019-03-09 00:31:54 -05:00
uint8_t GetOpenBus();
2019-02-26 22:27:09 -05:00
uint64_t GetMasterClock();
uint16_t GetHClock();
2019-02-26 22:27:09 -05:00
uint8_t* DebugGetWorkRam();
MemoryMappings* GetMemoryMappings();
uint8_t GetCpuSpeed(uint32_t addr);
uint8_t GetCpuSpeed();
void SetCpuSpeed(uint8_t speed);
SnesMemoryType GetMemoryTypeBusA();
2019-03-07 20:12:32 -05:00
bool IsRegister(uint32_t cpuAddress);
bool IsWorkRam(uint32_t cpuAddress);
2019-03-12 09:15:57 -04:00
2020-12-19 23:30:09 +03:00
void Serialize(Serializer& s) override;
2019-02-26 22:27:09 -05:00
};