forked from czajowaty/virtual_monsbaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BufferedPsxRam.hpp
52 lines (45 loc) · 1.77 KB
/
BufferedPsxRam.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef BUFFEREDPSXRAM_HPP
#define BUFFEREDPSXRAM_HPP
#include "PsxRamAddress.hpp"
#include "PsxRamConst.hpp"
#include <QByteArray>
#include <QString>
#include <array>
class BufferedPsxRam
{
using PsxRamBuffer = std::array<uint8_t, PsxRamConst::SIZE>;
public:
BufferedPsxRam();
void fill(char const* ram);
uint8_t readByte(PsxRamAddress address) const;
int8_t readSBbyte(PsxRamAddress address) const;
uint16_t readWord(PsxRamAddress address) const;
int16_t readSWord(PsxRamAddress address) const;
uint32_t readDWord(PsxRamAddress address) const;
int32_t readSDWord(PsxRamAddress address) const;
template <typename T>
T const* readAsPointer(PsxRamAddress address) const
{
constexpr uint32_t const size = sizeof(T);
PsxRamAddress inPsxRamAddress = PsxRamConst::toNoSegRamAddress(address);
if (!isInPsxRamRegion(inPsxRamAddress, size))
{ throwReadOutOfBoundsError(address, size); }
return reinterpret_cast<T const*>(inBufferPointer(inPsxRamAddress));
}
PsxRamAddress readAddress(PsxRamAddress address) const;
void readRegion(PsxRamAddress::Region const& region, uint8_t* buffer) const;
private:
constexpr std::size_t size() const
{ return ram_.size(); }
bool isInPsxRamRegion(PsxRamAddress address, uint32_t size) const;
uint8_t* inBufferPointer(PsxRamAddress address);
uint8_t const* inBufferPointer(PsxRamAddress address) const;
void throwReadOutOfBoundsError(PsxRamAddress address, uint32_t size) const;
void throwWriteOutOfBoundsError(PsxRamAddress address, uint32_t size) const;
void throwOutOfBoundsError(
char const* typeString,
PsxRamAddress address,
uint32_t size) const;
PsxRamBuffer ram_;
};
#endif // BUFFEREDPSXRAM_HPP