Mesen-SX/Core/MemoryManager.h

95 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"
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;
uint64_t _masterClock;
uint16_t _hClock = 0;
uint16_t _dramRefreshPosition = 0;
uint16_t _hdmaInitPosition = 0;
uint8_t _openBus;
uint8_t _cpuSpeed;
2019-04-20 21:54:51 -04:00
bool _hasEvent[1369];
uint8_t _masterClockTable[2][0x10000];
void UpdateEvents();
void Exec();
2019-03-08 10:26:54 -05:00
public:
2019-02-26 22:27:09 -05:00
void Initialize(shared_ptr<Console> console);
virtual ~MemoryManager();
void Reset();
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();
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, bool forBusA);
2019-02-26 22:27:09 -05:00
uint8_t Peek(uint32_t addr);
uint16_t PeekWord(uint32_t addr);
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();
uint8_t GetCpuSpeed(uint32_t addr);
uint8_t GetCpuSpeed();
void SetCpuSpeed(uint8_t speed);
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
}