Files
jak-project/game/overlord/jakx/isocommon.cpp
T
Tyler Wilding d3cc739e43 jakx: Commit existing work from other PRs (#4112)
This attempts to get into master whatever work was done in this PR /
it's earlier PR https://github.com/open-goal/jak-project/pull/3965

I don't want this work to be lost / floating around in massive PRs.

However the changes are:
- switch to ntsc_v1 instead of PAL as the development target, as we have
done for all other games
- remove most of the copied-from-jak2/3 changes as they need to be
confirmed during the decompilation process not just assumed
- avoids committing any changes to `game/kernel/common` as it was not
clear to me if these were changes made in jak x's kernel that were not
properly broken out into it's own functions. We don't want to
accidentally introduce bugs into jak1-3's kernel code.
- in other words, if the change in the kernel only happens in jak x...it
should likely be specific to jak x's kernel, not common.

---------

Co-authored-by: VodBox <dillon@vodbox.io>
Co-authored-by: yodah <greenboyyodah@gmail.com>
2025-12-31 21:08:44 -05:00

118 lines
2.6 KiB
C++

#include "isocommon.h"
#include "common/util/Assert.h"
namespace jakx {
void jakx_overlord_init_globals_isocommon() {}
/*!
* Convert file name to "ISO Name"
* ISO names are upper case and 12 bytes long.
* xxxxxxxxyyy0
*
* x - uppercase letter of file name, or space
* y - uppercase letter of file extension, or space
* 0 - null terminator (\0, not the character zero)
*/
void MakeISOName(ISOName* dst, const char* src) {
int i = 0;
const char* src_ptr = src;
char* dst_ptr = dst->data;
// copy name and upper case
while ((i < 8) && (*src_ptr) && (*src_ptr != '.')) {
char c = *src_ptr;
src_ptr++;
if (('`' < c) && (c < '{')) { // lower case
c -= 0x20;
}
*dst_ptr = c;
dst_ptr++;
i++;
}
// pad out name with spaces
while (i < 8) {
*dst_ptr = ' ';
dst_ptr++;
i++;
}
// increment past period
if (*src_ptr == '.')
src_ptr++;
// same for extension
while (i < 11 && (*src_ptr)) {
char c = *src_ptr;
src_ptr++;
if (('`' < c) && (c < '{')) { // lower case
c -= 0x20;
}
*dst_ptr = c;
dst_ptr++;
i++;
}
while (i < 11) {
*dst_ptr = ' ';
dst_ptr++;
i++;
}
*dst_ptr = 0;
}
// UnmakeISOName
/*!
* Pack an 8-character (64-bits) file name into a packed vag file name (32 + 10 = 42 bit).
*/
int PackVAGFileName(u32* out, const char* name) {
if (!out || !name) {
return 0;
}
int ret = 1;
// accumulator of up to 4 packed characters
u32 acc = 0;
u32 first_four = 0;
for (int i = 0; i < 8; i++) {
// start the second word:
if (i == 4) {
first_four = acc;
acc = 0;
}
// read character from input
u32 name_char = *((const u8*)name);
name++;
u32 remapped_char;
if (name_char - 'A' < 26) { // capital letter
remapped_char = name_char - 'A' + 1; // so A becomes 1.
} else if (name_char - 'a' < 26) { // lowercase letter
remapped_char = name_char - 'a' + 1; // so a becomes 1.
} else if (name_char - '0' < 10) { // digit
remapped_char = name_char - '0' + 27; // so 0 becomes 27
} else if (name_char == '-') {
remapped_char = 37;
} else if (name_char == ' ' || name_char == '\0') {
remapped_char = 0;
} else {
ASSERT_NOT_REACHED(); // invalid char in input.
}
ASSERT((remapped_char & 0xff) == remapped_char);
acc = acc * 38 + remapped_char; // (null + alphabet + 10 + dash)
}
out[0] = (first_four << 0x15) | acc;
out[1] = first_four >> 0xb;
return ret;
}
// UnpackVAGFileName - nobody uses it...
} // namespace jakx