Mesen-SX/Core/MemoryManager.h

80 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include "stdafx.h"
2019-02-26 22:27:09 -05:00
#include "DebugTypes.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 Console;
class Ppu;
enum class MemoryOperationType;
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:
shared_ptr<Console> _console;
2019-02-26 22:27:09 -05:00
shared_ptr<RegisterHandlerA> _registerHandlerA;
shared_ptr<RegisterHandlerB> _registerHandlerB;
InternalRegisters *_regs;
shared_ptr<Ppu> _ppu;
2019-02-15 00:08:50 -05:00
IMemoryHandler* _handlers[0x100 * 0x10];
vector<unique_ptr<RamHandler>> _workRamHandlers;
uint8_t *_workRam;
2019-03-09 00:31:54 -05:00
uint8_t _openBus;
uint64_t _masterClock;
2019-02-21 18:12:44 -05:00
uint8_t _masterClockTable[2][0x10000];
2019-03-08 10:26:54 -05:00
__forceinline void Exec();
public:
2019-02-26 22:27:09 -05:00
void Initialize(shared_ptr<Console> console);
~MemoryManager();
2019-02-26 22:27:09 -05:00
void RegisterHandler(uint32_t startAddr, uint32_t endAddr, IMemoryHandler* handler);
2019-02-26 22:27:09 -05:00
void GenerateMasterClockTable();
void IncrementMasterClock(uint32_t addr);
2019-02-21 23:35:51 -05:00
template<uint16_t value>
2019-02-26 22:27:09 -05:00
void IncrementMasterClockValue();
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);
uint8_t Peek(uint32_t addr);
uint16_t PeekWord(uint32_t addr);
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);
2019-03-09 00:31:54 -05:00
uint8_t GetOpenBus();
2019-02-26 22:27:09 -05:00
uint64_t GetMasterClock();
uint8_t* DebugGetWorkRam();
2019-03-07 20:12:32 -05:00
bool IsRegister(uint32_t cpuAddress);
bool IsWorkRam(uint32_t cpuAddress);
2019-02-26 22:27:09 -05:00
AddressInfo GetAbsoluteAddress(uint32_t addr);
int GetRelativeAddress(AddressInfo &address, int32_t cpuAddress = -1);
2019-03-12 09:15:57 -04:00
void Serialize(Serializer &s) override;
2019-02-26 22:27:09 -05:00
};
2019-02-21 23:35:51 -05:00
2019-02-26 22:27:09 -05:00
template<uint16_t value>
void MemoryManager::IncrementMasterClockValue()
{
2019-03-08 10:26:54 -05:00
uint16_t cyclesToRun = value;
while(cyclesToRun >= 2) {
cyclesToRun -= 2;
Exec();
2019-02-21 23:35:51 -05:00
}
2019-02-26 22:27:09 -05:00
}