blob: f165b5b602606206da4a37ebe63abdc4383555dc (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "Cartridge.h"
#include "lib/binarytools/BinaryReader.h"
#include <Companion.h>
void N64::Cartridge::Initialize() {
LUS::BinaryReader reader((char*)this->gRomData.data(), this->gRomData.size());
reader.SetEndianness(Torch::Endianness::Big);
reader.Seek(0x10, LUS::SeekOffsetType::Start);
#ifdef ROM_CRC_BSWAP
this->gRomCRC = BSWAP32(reader.ReadUInt32());
#else
this->gRomCRC = reader.ReadUInt32();
#endif
reader.Seek(0x20, LUS::SeekOffsetType::Start);
this->gGameTitle = std::string(reader.ReadCString());
this->gGameTitle.pop_back(); // Remove null terminator
reader.Seek(0x3E, LUS::SeekOffsetType::Start);
uint8_t country = reader.ReadUByte();
this->gVersion = reader.ReadUByte();
this->gHash = Companion::CalculateHash(this->gRomData);
switch (country) {
case 'J':
this->gCountryCode = CountryCode::Japan;
break;
case 'E':
this->gCountryCode = CountryCode::NorthAmerica;
break;
case 'P':
this->gCountryCode = CountryCode::Europe;
break;
default:
this->gCountryCode = CountryCode::Unknown;
break;
}
reader.Close();
}
const std::string& N64::Cartridge::GetGameTitle() {
return this->gGameTitle;
}
N64::CountryCode N64::Cartridge::GetCountry() {
return this->gCountryCode;
}
uint8_t N64::Cartridge::GetVersion() const {
return this->gVersion;
}
std::string N64::Cartridge::GetHash() {
return this->gHash;
}
std::string N64::Cartridge::GetCountryCode() {
switch (this->gCountryCode) {
case CountryCode::Japan:
return "jp";
case CountryCode::NorthAmerica:
return "us";
case CountryCode::Europe:
return "eu";
default:
return "unk";
}
}
uint32_t N64::Cartridge::GetCRC() {
return this->gRomCRC;
}
|