2019-02-11 22:41:34 -05:00
|
|
|
#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-11 22:41:34 -05:00
|
|
|
|
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-02-13 13:32:21 -05:00
|
|
|
|
2019-03-12 09:15:57 -04:00
|
|
|
class MemoryManager : public ISerializable
|
2019-02-11 22:41:34 -05:00
|
|
|
{
|
2019-02-15 21:33:13 -05:00
|
|
|
public:
|
|
|
|
constexpr static uint32_t WorkRamSize = 0x20000;
|
|
|
|
|
2019-02-11 22:41:34 -05:00
|
|
|
private:
|
2019-02-12 22:13:09 -05:00
|
|
|
shared_ptr<Console> _console;
|
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
shared_ptr<RegisterHandlerA> _registerHandlerA;
|
|
|
|
shared_ptr<RegisterHandlerB> _registerHandlerB;
|
|
|
|
|
2019-03-04 17:49:14 -05:00
|
|
|
InternalRegisters *_regs;
|
2019-02-13 13:32:21 -05:00
|
|
|
shared_ptr<Ppu> _ppu;
|
2019-02-15 00:08:50 -05:00
|
|
|
|
2019-02-17 14:42:35 -05:00
|
|
|
IMemoryHandler* _handlers[0x100 * 0x10];
|
|
|
|
vector<unique_ptr<RamHandler>> _workRamHandlers;
|
|
|
|
|
2019-03-04 17:49:14 -05:00
|
|
|
uint8_t *_workRam;
|
2019-02-13 13:32:21 -05:00
|
|
|
uint64_t _masterClock;
|
2019-04-20 09:30:51 -04:00
|
|
|
uint16_t _hClock = 0;
|
|
|
|
uint16_t _dramRefreshPosition = 0;
|
|
|
|
uint16_t _hdmaInitPosition = 0;
|
2019-04-20 11:46:51 -04:00
|
|
|
uint8_t _openBus;
|
|
|
|
uint8_t _cpuSpeed;
|
|
|
|
|
2019-04-20 21:54:51 -04:00
|
|
|
bool _hasEvent[1369];
|
2019-04-20 11:46:51 -04:00
|
|
|
uint8_t _masterClockTable[2][0x10000];
|
2019-02-11 22:41:34 -05:00
|
|
|
|
2019-04-20 09:30:51 -04:00
|
|
|
void UpdateEvents();
|
2019-04-20 11:46:51 -04:00
|
|
|
void Exec();
|
2019-03-08 10:26:54 -05:00
|
|
|
|
2019-02-11 22:41:34 -05:00
|
|
|
public:
|
2019-02-26 22:27:09 -05:00
|
|
|
void Initialize(shared_ptr<Console> console);
|
2019-03-31 14:50:12 -04:00
|
|
|
virtual ~MemoryManager();
|
2019-02-13 13:32:21 -05:00
|
|
|
|
2019-03-16 12:20:18 -04:00
|
|
|
void Reset();
|
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
void RegisterHandler(uint32_t startAddr, uint32_t endAddr, IMemoryHandler* handler);
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
void GenerateMasterClockTable();
|
2019-04-20 09:30:51 -04:00
|
|
|
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-13 13:32:21 -05:00
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
uint8_t Read(uint32_t addr, MemoryOperationType type);
|
2019-03-16 16:36:58 -04:00
|
|
|
uint8_t ReadDma(uint32_t addr, bool forBusA);
|
2019-03-26 22:34:48 -04:00
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
uint8_t Peek(uint32_t addr);
|
2019-02-28 16:53:04 -05:00
|
|
|
uint16_t PeekWord(uint32_t addr);
|
2019-03-26 22:34:48 -04:00
|
|
|
void PeekBlock(uint32_t addr, uint8_t * dest);
|
2019-02-13 13:32:21 -05:00
|
|
|
|
2019-02-26 22:27:09 -05:00
|
|
|
void Write(uint32_t addr, uint8_t value, MemoryOperationType type);
|
2019-03-16 16:36:58 -04:00
|
|
|
void WriteDma(uint32_t addr, uint8_t value, bool forBusA);
|
2019-02-17 14:42:35 -05:00
|
|
|
|
2019-03-09 00:31:54 -05:00
|
|
|
uint8_t GetOpenBus();
|
2019-02-26 22:27:09 -05:00
|
|
|
uint64_t GetMasterClock();
|
2019-04-20 11:46:51 -04:00
|
|
|
uint16_t GetHClock();
|
2019-02-26 22:27:09 -05:00
|
|
|
uint8_t* DebugGetWorkRam();
|
2019-02-13 13:32:21 -05:00
|
|
|
|
2019-04-20 09:30:51 -04:00
|
|
|
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);
|
2019-03-09 14:27:32 -05:00
|
|
|
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
|
|
|
}
|