MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / LoadBiosVersion

Function LoadBiosVersion

pcsx2/ps2/BiosTools.cpp:80–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static bool LoadBiosVersion(std::FILE* fp, u32& version, std::string& description, u32& region, std::string& zone, std::string& serial)
81{
82 romdir rd;
83 for (u32 i = 0; i < 512 * 1024; i++)
84 {
85 if (std::fread(&rd, sizeof(rd), 1, fp) != 1)
86 return false;
87
88 if (std::strncmp(rd.fileName, "RESET", sizeof(rd.fileName)) == 0)
89 break; /* found romdir */
90 }
91
92 s64 fileOffset = 0;
93 s64 fileSize = FileSystem::FSize64(fp);
94 bool foundRomVer = false;
95 char romver[14 + 1] = {}; // ascii version loaded from disk.
96 char extinfo[15 + 1] = {}; // ascii version loaded from disk.
97
98 // ensure it's a null-terminated and not zero-length string
99 while (rd.fileName[0] != '\0' && strnlen(rd.fileName, sizeof(rd.fileName)) != sizeof(rd.fileName))
100 {
101 if (std::strncmp(rd.fileName, "EXTINFO", sizeof(rd.fileName)) == 0)
102 {
103 s64 pos = FileSystem::FTell64(fp);
104 if (FileSystem::FSeek64(fp, fileOffset + 0x10, SEEK_SET) != 0 ||
105 std::fread(extinfo, 15, 1, fp) != 1 || FileSystem::FSeek64(fp, pos, SEEK_SET) != 0)
106 {
107 break;
108 }
109 serial = extinfo;
110 }
111
112 if (std::strncmp(rd.fileName, "ROMVER", sizeof(rd.fileName)) == 0)
113 {
114
115 s64 pos = FileSystem::FTell64(fp);
116 if (FileSystem::FSeek64(fp, fileOffset, SEEK_SET) != 0 ||
117 std::fread(romver, 14, 1, fp) != 1 || FileSystem::FSeek64(fp, pos, SEEK_SET) != 0)
118 {
119 break;
120 }
121
122 foundRomVer = true;
123 }
124
125 if ((rd.fileSize % 0x10) == 0)
126 fileOffset += rd.fileSize;
127 else
128 fileOffset += (rd.fileSize + 0x10) & 0xfffffff0;
129
130 if (std::fread(&rd, sizeof(rd), 1, fp) != 1)
131 break;
132 }
133
134 fileOffset -= ((rd.fileSize + 0x10) & 0xfffffff0) - rd.fileSize;
135
136 if (foundRomVer)
137 {

Callers 2

IsBIOSFunction · 0.85
LoadBIOSFunction · 0.85

Calls 4

StdStringFromFormatFunction · 0.85
clearMethod · 0.45
c_strMethod · 0.45
WriteLnMethod · 0.45

Tested by

no test coverage detected