Duckstation/src/pse/bus.h

97 lines
3.4 KiB
C
Raw Normal View History

2019-09-09 07:01:26 +00:00
#pragma once
#include "YBaseLib/String.h"
#include "types.h"
#include <array>
class StateWrapper;
2019-09-17 06:26:00 +00:00
namespace CPU
{
class Core;
}
2019-09-09 07:01:26 +00:00
class DMA;
class GPU;
2019-09-17 06:26:00 +00:00
class InterruptController;
2019-09-09 07:01:26 +00:00
class System;
class Bus
{
public:
Bus();
~Bus();
2019-09-17 06:26:00 +00:00
bool Initialize(CPU::Core* cpu, DMA* dma, InterruptController* interrupt_controller, GPU* gpu);
2019-09-09 07:01:26 +00:00
void Reset();
bool DoState(StateWrapper& sw);
bool ReadByte(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u8* value);
bool ReadHalfWord(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u16* value);
bool ReadWord(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u32* value);
2019-09-09 07:01:26 +00:00
bool WriteByte(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u8 value);
bool WriteHalfWord(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u16 value);
bool WriteWord(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u32 value);
2019-09-09 07:01:26 +00:00
template<MemoryAccessType type, MemoryAccessSize size>
bool DispatchAccess(PhysicalMemoryAddress cpu_address, PhysicalMemoryAddress bus_address, u32& value);
void PatchBIOS(u32 address, u32 value, u32 mask = UINT32_C(0xFFFFFFFF));
2019-09-09 07:01:26 +00:00
private:
static constexpr u32 GPU_BASE = 0x1F801810;
static constexpr u32 GPU_SIZE = 0x10;
static constexpr u32 GPU_MASK = GPU_SIZE - 1;
2019-09-17 06:26:00 +00:00
static constexpr u32 INTERRUPT_CONTROLLER_BASE = 0x1F801070;
static constexpr u32 INTERRUPT_CONTROLLER_SIZE = 0x08;
static constexpr u32 INTERRUPT_CONTROLLER_MASK = INTERRUPT_CONTROLLER_SIZE - 1;
static constexpr u32 DMA_BASE = 0x1F801080;
static constexpr u32 DMA_SIZE = 0x80;
static constexpr u32 DMA_MASK = DMA_SIZE - 1;
2019-09-09 07:01:26 +00:00
static constexpr u32 SPU_BASE = 0x1F801C00;
static constexpr u32 SPU_SIZE = 0x300;
static constexpr u32 SPU_MASK = 0x3FF;
static constexpr u32 EXP2_BASE = 0x1F802000;
static constexpr u32 EXP2_SIZE = 0x2000;
static constexpr u32 EXP2_MASK = EXP2_SIZE - 1;
static constexpr u32 BIOS_BASE = 0x1FC00000;
static constexpr u32 BIOS_SIZE = 0x80000;
2019-09-09 07:01:26 +00:00
bool LoadBIOS();
template<MemoryAccessType type, MemoryAccessSize size>
bool DoRAMAccess(u32 offset, u32& value);
template<MemoryAccessType type, MemoryAccessSize size>
bool DoBIOSAccess(u32 offset, u32& value);
bool DoInvalidAccess(MemoryAccessType type, MemoryAccessSize size, PhysicalMemoryAddress cpu_address,
PhysicalMemoryAddress bus_address, u32& value);
bool ReadExpansionRegion2(MemoryAccessSize size, u32 offset, u32& value);
bool WriteExpansionRegion2(MemoryAccessSize size, u32 offset, u32 value);
bool DoReadGPU(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteGPU(MemoryAccessSize size, u32 offset, u32 value);
2019-09-09 07:01:26 +00:00
2019-09-17 06:26:00 +00:00
bool DoReadInterruptController(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteInterruptController(MemoryAccessSize size, u32 offset, u32 value);
2019-09-09 07:01:26 +00:00
bool DoReadDMA(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteDMA(MemoryAccessSize size, u32 offset, u32 value);
bool ReadSPU(MemoryAccessSize size, u32 offset, u32& value);
bool WriteSPU(MemoryAccessSize size, u32 offset, u32 value);
2019-09-09 07:01:26 +00:00
2019-09-17 06:26:00 +00:00
CPU::Core* m_cpu = nullptr;
2019-09-09 07:01:26 +00:00
DMA* m_dma = nullptr;
2019-09-17 06:26:00 +00:00
InterruptController* m_interrupt_controller = nullptr;
2019-09-09 07:01:26 +00:00
GPU* m_gpu = nullptr;
std::array<u8, 2097152> m_ram{}; // 2MB RAM
std::array<u8, 524288> m_bios{}; // 512K BIOS ROM
String m_tty_line_buffer;
};
#include "bus.inl"