WolPSX
Loading...
Searching...
No Matches
bus.hpp
1#ifndef BUS_HPP
2#define BUS_HPP
3
4#include <stdint.h>
5#include <string>
6
7#define BIOS_RANGE 0x1fc00000, 0x1fc7ffff
8#define MEM_CTRL_RANGE 0x1f801000, 0x1f801023
9#define RAM_SIZE_RANGE 0x1f801060, 0x1f801063
10#define CACHE_CTRL_RANGE 0xfffe0130, 0xfffe0133
11#define RAM_RANGE 0x00000000, 0x001fffff
12#define SPU_RANGE 0x1f801c00, 0x1f801ffc
13#define EXPANSION2_RANGE 0x1f802000, 0x1f803fff
14#define EXPANSION1_RANGE 0x1f000000, 0x1f7fffff
15#define INTERRUPT_RANGE 0x1f801070, 0x1f801077
16#define TIMER_RANGE 0x1f801100, 0x1f801131
17
18class CPU;
19class BIOS;
20class RAM;
21
26struct Range
27{
32 uint32_t start;
33
38 uint32_t end;
39
46 Range(uint32_t start, uint32_t end) : start(start), end(end) {}
47
55 bool contains(uint32_t addr)
56 {
57 return addr >= start && addr <= end;
58 }
59
66 uint32_t offset(uint32_t addr)
67 {
68 return addr - start;
69 }
70};
71
77class Bus
78{
79public:
80 Bus(std::string bios_path);
81
82 uint32_t read32_cpu(uint32_t addr);
83 void write32_cpu(uint32_t addr, uint32_t data);
84
85 uint16_t read16_cpu(uint32_t addr);
86 void write16_cpu(uint32_t addr, uint16_t data);
87
88 uint8_t read8_cpu(uint32_t addr);
89 void write8_cpu(uint32_t addr, uint8_t data);
90
91 void clock();
92
93private:
94 uint32_t region_mask(uint32_t addr);
95
96private:
102
108
114
119 Range bios_range = Range(BIOS_RANGE);
120
125 Range mem_ctrl_range = Range(MEM_CTRL_RANGE);
126
131 Range ram_size_range = Range(RAM_SIZE_RANGE);
132
137 Range cache_ctrl_range = Range(CACHE_CTRL_RANGE);
138
143 Range ram_range = Range(RAM_RANGE);
144
149 Range spu_range = Range(SPU_RANGE);
150
155 Range expansion2_range = Range(EXPANSION2_RANGE);
156
161 Range expansion1_range = Range(EXPANSION1_RANGE);
162
167 Range interrupt_range = Range(INTERRUPT_RANGE);
168
173 Range timer_range = Range(TIMER_RANGE);
174};
175
176#endif
Class to emulate the BIOS.
Definition bios.hpp:16
Class to implement the Bus.
Definition bus.hpp:78
void clock()
Clocks the PSX.
Definition bus_utils.cpp:47
Range mem_ctrl_range
Range of the Memory Control Registers.
Definition bus.hpp:125
RAM * ram
Pointer to the RAM object.
Definition bus.hpp:113
Range expansion1_range
Range of the Expansion 1.
Definition bus.hpp:161
Range ram_size_range
Range of the RAM Size Register.
Definition bus.hpp:131
CPU * cpu
Pointer to the CPU object.
Definition bus.hpp:101
uint16_t read16_cpu(uint32_t addr)
Reads a 16-bit word from the given address.
Definition bus.cpp:186
uint32_t read32_cpu(uint32_t addr)
Reads a 32-bit word from the given address.
Definition bus.cpp:47
Bus(std::string bios_path)
Construct a new Bus:: Bus object.
Definition bus.cpp:20
Range ram_range
Range of the RAM.
Definition bus.hpp:143
Range bios_range
Range of the BIOS.
Definition bus.hpp:119
Range timer_range
Range of the Timer Registers.
Definition bus.hpp:173
Range cache_ctrl_range
Range of the Cache Control Register.
Definition bus.hpp:137
BIOS * bios
Pointer to the BIOS object.
Definition bus.hpp:107
void write8_cpu(uint32_t addr, uint8_t data)
Writes a 8-bit word to the given address.
Definition bus.cpp:323
uint32_t region_mask(uint32_t addr)
Returns the region mask for a given address.
Definition bus_utils.cpp:15
Range expansion2_range
Range of the Expansion 2.
Definition bus.hpp:155
void write32_cpu(uint32_t addr, uint32_t data)
Writes a 32-bit word to the given address.
Definition bus.cpp:100
void write16_cpu(uint32_t addr, uint16_t data)
Writes a 16-bit word to the given address.
Definition bus.cpp:222
Range interrupt_range
Range of the Interrupt Registers.
Definition bus.hpp:167
Range spu_range
Range of the SPU (Sound Processing Unit) Registers.
Definition bus.hpp:149
uint8_t read8_cpu(uint32_t addr)
Reads a 8-bit word from the given address.
Definition bus.cpp:281
Class to emulate the CPU.
Definition cpu.hpp:145
Class to emulate the RAM.
Definition ram.hpp:13
Structure to store a range of addresses to allow easy checking.
Definition bus.hpp:27
Range(uint32_t start, uint32_t end)
Construct a new Range object.
Definition bus.hpp:46
uint32_t end
End of the range (inclusive)
Definition bus.hpp:38
bool contains(uint32_t addr)
Checks if the given address is in the range.
Definition bus.hpp:55
uint32_t offset(uint32_t addr)
Gets the offset of the given address from the start of the range.
Definition bus.hpp:66
uint32_t start
Start of the range (inclusive)
Definition bus.hpp:32