Duckstation/src/pse/bus.h

135 lines
4.9 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;
2019-09-17 06:26:00 +00:00
class InterruptController;
2019-09-17 09:22:39 +00:00
class GPU;
class CDROM;
class Pad;
2019-09-20 13:40:19 +00:00
class Timers;
2019-09-09 07:01:26 +00:00
class System;
class Bus
{
public:
Bus();
~Bus();
2019-09-20 13:40:19 +00:00
bool Initialize(CPU::Core* cpu, DMA* dma, InterruptController* interrupt_controller, GPU* gpu, CDROM* cdrom, Pad* pad, Timers* timers);
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-22 15:28:00 +00:00
void SetExpansionROM(std::vector<u8> data);
2019-09-09 07:01:26 +00:00
private:
2019-09-22 15:28:00 +00:00
static constexpr u32 EXP1_BASE = 0x1F000000;
static constexpr u32 EXP1_SIZE = 0x800000;
static constexpr u32 EXP1_MASK = EXP1_SIZE - 1;
static constexpr u32 PAD_BASE = 0x1F801040;
static constexpr u32 PAD_SIZE = 0x10;
static constexpr u32 PAD_MASK = PAD_SIZE - 1;
2019-09-22 15:28:00 +00:00
static constexpr u32 SIO_BASE = 0x1F801050;
static constexpr u32 SIO_SIZE = 0x10;
static constexpr u32 SIO_MASK = SIO_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-20 13:40:19 +00:00
static constexpr u32 TIMERS_BASE = 0x1F801100;
static constexpr u32 TIMERS_SIZE = 0x40;
static constexpr u32 TIMERS_MASK = TIMERS_SIZE - 1;
2019-09-17 09:22:39 +00:00
static constexpr u32 CDROM_BASE = 0x1F801800;
static constexpr u32 CDROM_SIZE = 0x04;
static constexpr u32 CDROM_MASK = CDROM_SIZE - 1;
static constexpr u32 GPU_BASE = 0x1F801810;
static constexpr u32 GPU_SIZE = 0x10;
static constexpr u32 GPU_MASK = GPU_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);
2019-09-22 15:28:00 +00:00
bool DoReadEXP1(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteEXP1(MemoryAccessSize size, u32 offset, u32 value);
bool DoReadEXP2(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteEXP2(MemoryAccessSize size, u32 offset, u32 value);
2019-09-09 07:01:26 +00:00
bool DoReadPad(MemoryAccessSize size, u32 offset, u32& value);
bool DoWritePad(MemoryAccessSize size, u32 offset, u32 value);
2019-09-22 15:28:00 +00:00
bool DoReadSIO(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteSIO(MemoryAccessSize size, u32 offset, u32 value);
2019-09-17 09:22:39 +00:00
bool DoReadCDROM(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteCDROM(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);
2019-09-20 13:40:19 +00:00
bool DoReadTimers(MemoryAccessSize size, u32 offset, u32& value);
bool DoWriteTimers(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;
2019-09-17 09:22:39 +00:00
CDROM* m_cdrom = nullptr;
Pad* m_pad = nullptr;
2019-09-20 13:40:19 +00:00
Timers* m_timers = nullptr;
2019-09-09 07:01:26 +00:00
std::array<u8, 2097152> m_ram{}; // 2MB RAM
std::array<u8, 524288> m_bios{}; // 512K BIOS ROM
2019-09-22 15:28:00 +00:00
std::vector<u8> m_exp1_rom;
2019-09-09 07:01:26 +00:00
String m_tty_line_buffer;
};
#include "bus.inl"