diff options
Diffstat (limited to 'src/n64')
| -rw-r--r-- | src/n64/Cartridge.cpp | 59 | ||||
| -rw-r--r-- | src/n64/Cartridge.h | 30 |
2 files changed, 89 insertions, 0 deletions
diff --git a/src/n64/Cartridge.cpp b/src/n64/Cartridge.cpp new file mode 100644 index 0000000..96e150c --- /dev/null +++ b/src/n64/Cartridge.cpp @@ -0,0 +1,59 @@ +#include "Cartridge.h" + +#include "hj/sha1.h" +#include "binarytools/BinaryReader.h" + +void N64::Cartridge::Initialize() { + LUS::BinaryReader reader((char*) this->gRomData.data(), this->gRomData.size()); + reader.SetEndianness(LUS::Endianness::Big); + reader.Seek(0x20, LUS::SeekOffsetType::Start); + this->gGameTitle = std::string(reader.ReadCString()); + reader.Seek(0x3E, LUS::SeekOffsetType::Start); + uint8_t country = reader.ReadUByte(); + this->gVersion = reader.ReadUByte(); + this->gHash = Chocobo1::SHA1().addData(this->gRomData).finalize().toString(); + 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"; + } +} diff --git a/src/n64/Cartridge.h b/src/n64/Cartridge.h new file mode 100644 index 0000000..e53b8ef --- /dev/null +++ b/src/n64/Cartridge.h @@ -0,0 +1,30 @@ +#pragma once + +#include <vector> +#include <string> + +namespace N64 { +enum class CountryCode { + Japan, + NorthAmerica, + Europe, + Unknown +}; + +class Cartridge { +public: + explicit Cartridge(const std::vector<uint8_t>& romData) : gRomData(romData), gCountryCode(CountryCode::Unknown), gVersion(0), gGameTitle("Unknown") {} + void Initialize(); + const std::string& GetGameTitle(); + std::string GetCountryCode(); + CountryCode GetCountry(); + uint8_t GetVersion() const; + std::string GetHash(); +private: + std::vector<uint8_t> gRomData; + CountryCode gCountryCode; + uint8_t gVersion; + std::string gGameTitle; + std::string gHash; +}; +}
\ No newline at end of file |
