forked from czajowaty/ad_resources_dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PsxRamConst.hpp
45 lines (39 loc) · 1.64 KB
/
PsxRamConst.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
#ifndef PSXRAMCONST_HPP
#define PSXRAMCONST_HPP
#include "PsxRamAddress.hpp"
#include <QByteArray>
#include <cstdint>
struct PsxRamConst
{
static constexpr uint32_t const SIZE = 0x200000;
static constexpr PsxRamAddress::Raw const KUSEG_ADDRESS = 0x0;
static constexpr PsxRamAddress::Raw const KSEG0_ADDRESS = 0x80000000;
static constexpr PsxRamAddress::Raw const KSEG1_ADDRESS = 0xa0000000;
static constexpr PsxRamAddress::Mask const ADDRESS_MASK = 0x00ffffff;
static constexpr PsxRamAddress::Mask const SEGMENT_MASK = 0xff000000;
PsxRamConst() = delete;
static constexpr PsxRamAddress::Raw toKSeg0RamAddress(
PsxRamAddress::Raw rawAddress)
{ return toNoSegRamAddress(rawAddress) | PsxRamConst::KSEG0_ADDRESS; }
static constexpr PsxRamAddress::Raw toKSeg1RamAddress(
PsxRamAddress::Raw rawAddress)
{ return toNoSegRamAddress(rawAddress) | PsxRamConst::KSEG1_ADDRESS; }
static constexpr PsxRamAddress::Raw toNoSegRamAddress(
PsxRamAddress::Raw rawAddress)
{ return rawAddress & ADDRESS_MASK; }
static constexpr PsxRamAddress::Raw toSegPsxRamAddress(
PsxRamAddress::Raw rawAddress)
{ return rawAddress & SEGMENT_MASK; }
static constexpr bool isInPsxRamAddress(PsxRamAddress::Raw rawAddress)
{
auto segment = toSegPsxRamAddress(rawAddress);
if (
segment != KUSEG_ADDRESS &&
segment != KSEG0_ADDRESS &&
segment != KSEG1_ADDRESS)
{ return false; }
auto address = toNoSegRamAddress(rawAddress);
return address < SIZE;
}
};
#endif // PSXRAMCONST_HPP