ground bg map documentation

This commit is contained in:
DizzyEggg 2025-07-17 17:51:53 +02:00
parent 8efe6ea90b
commit 47cad2e720
5 changed files with 1197 additions and 1184 deletions

View File

@ -3,10 +3,10 @@
struct MapFilesStruct
{
/* 0x0 */ const u8 *fileName1;
/* 0x4 */ const u8 *fileName2;
/* 0x8 */ const u8 *fileName3;
/* 0xC */ const u8 *fileName4[4];
/* 0x0 */ const u8 *bplFileName;
/* 0x4 */ const u8 *bpcFileName;
/* 0x8 */ const u8 *bmaFileName;
/* 0xC */ const u8 *bpaFileNames[4];
};
enum {

View File

@ -9,7 +9,7 @@
#define UNK_E0_ARR_COUNT 32
#define UNK_3E0_ARR_COUNT 2
#define UNK_54C_ARR_COUNT 2
#define UNK_545_UNK6_ARR_COUNT 4
#define MAX_BPA_SLOTS 4
typedef struct SubStruct_0
{
@ -20,11 +20,12 @@ typedef struct SubStruct_0
u8 fillC;
} SubStruct_0;
struct UnkFileStruct
struct BpaHeader
{
u8 unk0;
s16 unk2;
void *unk4[0]; // This is most likely wrong, will need to be fixed.
u8 numTiles; // The number of individual tiles.
s16 numFrames; // The number of frames for each tile.
s32 durationPerFrame[0]; // Settings for each frame. One entry per frame.
// Tiles data below
};
typedef struct SubStruct_3E0
@ -33,8 +34,8 @@ typedef struct SubStruct_3E0
u8 unk1;
s16 unk2;
s16 unk4;
OpenedFile *unk8;
const struct UnkFileStruct *unkC;
OpenedFile *bpaFile;
const struct BpaHeader *unkC;
const void *unk10;
const void *unk14;
const void *unk18;
@ -62,6 +63,25 @@ typedef struct SubStruct_488
PixelPos bgRegOffsets; // Either bg2 or bg3
} SubStruct_488;
typedef struct BmaHeader
{
// Map width/height that the camera in game will travel in tiles. Also the width/height of the collision and unknown data layers! For most maps (Map Width Chunks) * (Tiling Width) = (Map Width Camera).
u8 mapWidthTiles;
u8 mapHeightTiles;
// Width/Height of chunks in tiles. Always 3, the value is ignored for these.
u8 tilingWidth;
u8 tilingHeight;
// Map width/height in chunks. Also the width/height of the chunk mappings.
u8 mapWidthChunks;
u8 mapHeightChunks;
u16 numLayers; // Number of layers in this map. Must match BPC layer size. Allowed values are only 1 or 2.
u16 hasDataLayer; // Seems to be a boolean flag (0 or 1). If >0, the Unknown Data Layer exists.
u16 hasCollision; // Number of Collision layers. 0, 1 or 2.
} BmaHeader;
// size: 0x18?
typedef struct SubStruct_52C
{
@ -75,30 +95,25 @@ typedef struct SubStruct_52C
s16 unkE; // 0x53A
s16 unk10; // 0x53C
s16 unk12; // 0x53E
void (*unk14)(void *, const void *, void *, s32); // TODO: fix void * to proper ptr types 0x540
void (*unk14)(void *, const void *, BmaHeader *, s32); // TODO: fix void * to proper ptr types 0x540
} SubStruct_52C;
typedef struct SubStruct_448
{
u8 unk0;
u8 unk1;
u8 unk2;
u8 unk3;
u8 unk4;
u8 unk5;
u16 unk6;
u16 unk8;
u16 unkA;
} SubStruct_448;
typedef struct SubStruct_545
typedef struct LayerSpecs
{
// Apparently these two fields are not present in pmd-sky?
s16 unk0;
s16 unk2;
s16 unk4;
s16 unk6[UNK_545_UNK6_ARR_COUNT];
s16 unkE;
} SubStruct_545;
s16 numTiles; // The number of tiles stored in the data + 1. The +1 is the null tile at the beginning of tiles.
s16 bpaSlotNumTiles[MAX_BPA_SLOTS]; // The number of tiles in the BPA on this slot. 0 if no BPA is assigned.
s16 numChunks; // Number of chunks in the tilemap + 1. The +1 is the null chunk at the beginning of tile mappings, that is not stored.
} LayerSpecs;
typedef struct BplHeader
{
s16 numPalettes;
s16 hasPalAnimations;
} BplHeader;
// size: 0x55C
typedef struct GroundBg
@ -106,15 +121,15 @@ typedef struct GroundBg
SubStruct_0 unk0[UNK_0_ARR_COUNT];
unkStruct_202EE8C unkE0[UNK_E0_ARR_COUNT];
SubStruct_3E0 unk3E0[UNK_3E0_ARR_COUNT];
OpenedFile *unk430;
OpenedFile *unk434;
OpenedFile *unk438;
OpenedFile *bplFile;
OpenedFile *bpcFile;
OpenedFile *bmaFile;
OpenedFile *unk43C;
OpenedFile *unk440;
s16 mapFileId;
SubStruct_448 unk448;
SubStruct_545 unk454;
s16 unk464[2];
BmaHeader bmaHeader;
LayerSpecs layerSpecs;
BplHeader bplHeader;
const void *unk468;
const void *unk46C;
u8 unk470;

View File

@ -135,7 +135,7 @@ static void PrintCurrentPageText(void)
const struct MapFilesStruct *mapFilesPtr = &gMapFilesTable[mapConversionPtr->mapFileTableId];
y = GetMenuEntryYCoord(&sDebugWindow->m.input, i);
PrintStringOnWindow(8, y, mapFilesPtr->fileName1, sDebugWindow->m.menuWinId, 0);
PrintStringOnWindow(8, y, mapFilesPtr->bplFileName, sDebugWindow->m.menuWinId, 0);
y = GetMenuEntryYCoord(&sDebugWindow->m.input, i);
PrintStringOnWindow(62, y, mapConversionPtr->text, sDebugWindow->m.menuWinId, 0);

View File

@ -21,9 +21,9 @@ extern const FileArchive gGroundFileArchive;
void sub_80A456C(GroundBg *groundBg, s32 id, const PixelPos *srcPos);
static void CloseOpenedFiles(GroundBg *groundBg);
static void sub_80A3EB0(SubStruct_488 *map488);
static const u8 *sub_80A3908(u16 **dstArray, const void *src_, SubStruct_52C *a2, SubStruct_448 *a3);
static void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, SubStruct_545 *a3);
static void _UncompressCell(void * a0, u16 *a1, const void * a2, SubStruct_52C *a3, SubStruct_545 *a4);
static const u8 *BmaLayerNrlDecompressor(u16 **dstArray, const void *bmaData, SubStruct_52C *a2, BmaHeader *bmaHeader);
static void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, LayerSpecs *a3);
static void _UncompressCell(void * a0, u16 *a1, const void * a2, SubStruct_52C *a3, LayerSpecs *a4);
static void sub_80A3D40(SubStruct_488 *map488, GroundBg *groundBg, s32 a2, s32 a3, bool8 a4);
static void sub_80A3E14(SubStruct_488 *map488, PixelPos *a1);
static void sub_80A3EBC(SubStruct_488 *map488);
@ -35,7 +35,7 @@ static void sub_80A3F94(SubStruct_488 *map488);
static void sub_80A4358(SubStruct_488 *map488);
extern void sub_8003810(u16 param_1, RGB_Union param_2);
extern void sub_809971C(u16 a0, const void *a1, int a2);
extern void sub_809971C(u16 idx, const RGB_Array *strPtrs, s32 n);
static const PixelPos sPositionZero = {0, 0};
@ -63,20 +63,20 @@ void GroundBg_Init(GroundBg *groundBg, const SubStruct_52C *a1)
groundBg->unk544 = NULL;
}
groundBg->unk430 = NULL;
groundBg->unk434 = NULL;
groundBg->unk438 = NULL;
groundBg->bplFile = NULL;
groundBg->bpcFile = NULL;
groundBg->bmaFile = NULL;
groundBg->unk43C = NULL;
groundBg->unk440 = NULL;
groundBg->unk52A = 0;
groundBg->mapFileId = -1;
groundBg->unk468 = 0;
groundBg->unk448.unk0 = 0;
groundBg->unk448.unk1 = 0;
groundBg->unk448.unk2 = 0;
groundBg->unk448.unk3 = 0;
groundBg->unk448.unk4 = 0;
groundBg->unk448.unk5 = 0;
groundBg->bmaHeader.mapWidthTiles = 0;
groundBg->bmaHeader.mapHeightTiles = 0;
groundBg->bmaHeader.tilingWidth = 0;
groundBg->bmaHeader.tilingHeight = 0;
groundBg->bmaHeader.mapWidthChunks = 0;
groundBg->bmaHeader.mapHeightChunks = 0;
unk0Ptr = &groundBg->unk0[0];
groundBg->unk46C = 0;
groundBg->unk470 = 0;
@ -95,7 +95,7 @@ void GroundBg_Init(GroundBg *groundBg, const SubStruct_52C *a1)
unkPtr->unk1 = 0;
unkPtr->unk2 = 0;
unkPtr->unk4 = 0;
unkPtr->unk8 = NULL;
unkPtr->bpaFile = NULL;
unkPtr->unkC = 0;
unkPtr->unk14 = 0;
unkPtr->unk10 = 0;
@ -134,9 +134,9 @@ void sub_80A2D68(GroundBg *groundBg)
void sub_80A2D88(GroundBg *groundBg)
{
if (groundBg->unk52C.unk14 != NULL) {
void *unk448 = &groundBg->unk448;
BmaHeader *bmaHeader = &groundBg->bmaHeader;
groundBg->unk544 = MemoryAlloc(groundBg->unk52C.unkE * 256, 6);
groundBg->unk52C.unk14(groundBg->unk544, groundBg->unk468, unk448, groundBg->unk52C.unkE);
groundBg->unk52C.unk14(groundBg->unk544, groundBg->unk468, bmaHeader, groundBg->unk52C.unkE);
}
}
@ -146,13 +146,13 @@ static void CloseOpenedFiles(GroundBg *groundBg)
for (i = 0; i < UNK_3E0_ARR_COUNT; i++) {
SubStruct_3E0 *unkPtr = &groundBg->unk3E0[i];
TRY_CLOSE_FILE_AND_SET_NULL(unkPtr->unk8);
TRY_CLOSE_FILE_AND_SET_NULL(unkPtr->bpaFile);
}
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->unk43C);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->unk440);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->unk430);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->unk434);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->unk438);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->bplFile);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->bpcFile);
TRY_CLOSE_FILE_AND_SET_NULL(groundBg->bmaFile);
}
void sub_80A2E64(GroundBg *groundBg)
@ -165,12 +165,12 @@ void sub_80A2E64(GroundBg *groundBg)
CloseOpenedFiles(groundBg);
groundBg->mapFileId = -1;
groundBg->unk528 = 0;
groundBg->unk448.unk0 = 0;
groundBg->unk448.unk1 = 0;
groundBg->unk448.unk2 = 0;
groundBg->unk448.unk3 = 0;
groundBg->unk448.unk4 = 0;
groundBg->unk448.unk5 = 0;
groundBg->bmaHeader.mapWidthTiles = 0;
groundBg->bmaHeader.mapHeightTiles = 0;
groundBg->bmaHeader.tilingWidth = 0;
groundBg->bmaHeader.tilingHeight = 0;
groundBg->bmaHeader.mapWidthChunks = 0;
groundBg->bmaHeader.mapHeightChunks = 0;
unk0Ptr = &groundBg->unk0[0];
groundBg->unk46C = 0;
groundBg->unk470 = 0;
@ -189,7 +189,7 @@ void sub_80A2E64(GroundBg *groundBg)
unkPtr->unk1 = 0;
unkPtr->unk2 = 0;
unkPtr->unk4 = 0;
unkPtr->unk8 = NULL;
unkPtr->bpaFile = NULL;
unkPtr->unkC = 0;
unkPtr->unk14 = 0;
unkPtr->unk10 = 0;
@ -221,15 +221,15 @@ void sub_80A2FBC(GroundBg *groundBg, s32 mapFileId_)
u16 r5;
s32 i, j, k;
const struct MapFilesStruct *mapFilesPtr;
s16 *mapPtr_464;
SubStruct_545 *mapPtr_454;
const u16 *file_434;
const void *file_438;
const void *file_430;
SubStruct_448 *mapPtr_448;
BplHeader *bplHeader;
LayerSpecs *layerSpecs;
const u16 *bpcData;
const void *bmaData;
const void *bplData;
BmaHeader *bmaHeader;
RGB_Union str2;
RGB_Union str1;
const void *r7;
const RGB_Array *rgbPal;
s32 unk0Id;
s32 id;
void *vramPtr;
@ -244,52 +244,52 @@ void sub_80A2FBC(GroundBg *groundBg, s32 mapFileId_)
CloseOpenedFiles(groundBg);
groundBg->mapFileId = mapFileId;
mapFilesPtr = &gMapFilesTable[mapFileId];
groundBg->unk430 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName1, &gGroundFileArchive);
groundBg->unk434 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName2, &gGroundFileArchive);
groundBg->unk438 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName3, &gGroundFileArchive);
file_430 = groundBg->unk430->data;
file_434 = groundBg->unk434->data;
file_438 = groundBg->unk438->data;
mapPtr_464 = groundBg->unk464;
mapPtr_454 = &groundBg->unk454;
mapPtr_448 = &groundBg->unk448;
groundBg->bplFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bplFileName, &gGroundFileArchive);
groundBg->bpcFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bpcFileName, &gGroundFileArchive);
groundBg->bmaFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bmaFileName, &gGroundFileArchive);
bplData = groundBg->bplFile->data;
bpcData = groundBg->bpcFile->data;
bmaData = groundBg->bmaFile->data;
bplHeader = &groundBg->bplHeader;
layerSpecs = &groundBg->layerSpecs;
bmaHeader = &groundBg->bmaHeader;
mapPtr_464[0] = *(u8 *)(file_430); file_430 += 2;
mapPtr_464[1] = *(u8 *)(file_430); file_430 += 2;
bplHeader->numPalettes = *(u8 *)(bplData); bplData += 2;
bplHeader->hasPalAnimations = *(u8 *)(bplData); bplData += 2;
mapPtr_454->unk0 = *file_434++;
mapPtr_454->unk2 = *file_434++;
mapPtr_454->unk4 = *file_434++;
layerSpecs->unk0 = *bpcData++;
layerSpecs->unk2 = *bpcData++;
layerSpecs->numTiles = *bpcData++;
sum = mapPtr_454->unk4;
for (k = 0; k < UNK_545_UNK6_ARR_COUNT; k++) {
mapPtr_454->unk6[k] = *file_434++;
sum += mapPtr_454->unk6[k];
sum = layerSpecs->numTiles;
for (k = 0; k < MAX_BPA_SLOTS; k++) {
layerSpecs->bpaSlotNumTiles[k] = *bpcData++;
sum += layerSpecs->bpaSlotNumTiles[k];
}
mapPtr_454->unkE = *file_434++;
layerSpecs->numChunks = *bpcData++;
mapPtr_448->unk0 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk1 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk2 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk3 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk4 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk5 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk6 = *(u8 *)(file_438); file_438 += 2;
mapPtr_448->unk8 = *(u8 *)(file_438); file_438 += 2;
mapPtr_448->unkA = *(u8 *)(file_438); file_438 += 2;
bmaHeader->mapWidthTiles = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapHeightTiles = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->tilingWidth = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->tilingHeight = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapWidthChunks = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapHeightChunks = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->numLayers = *(u8 *)(bmaData); bmaData += 2;
bmaHeader->hasDataLayer = *(u8 *)(bmaData); bmaData += 2;
bmaHeader->hasCollision = *(u8 *)(bmaData); bmaData += 2;
r7 = file_430;
rgbPal = bplData;
r5 = groundBg->unk52C.unk0 * 16;
str2 = (RGB_Union) {0};
str1.asArr.c[0] = 0xff;
str1.asArr.c[1] = 0xff;
str1.asArr.c[2] = 0xff;
str1.asArr.c[3] = 0;
for (i = 0; i < mapPtr_464[0] && i < groundBg->unk52C.unk2; i++) {
for (i = 0; i < bplHeader->numPalettes && i < groundBg->unk52C.unk2; i++) {
sub_8003810(r5++, str2);
sub_809971C(r5, r7, 15);
sub_809971C(r5, rgbPal, 15);
r5 += 15;
r7 += 60;
rgbPal += 15;
}
for (; i < groundBg->unk52C.unk2; i++) {
sub_8003810(r5++, str2);
@ -298,24 +298,24 @@ void sub_80A2FBC(GroundBg *groundBg, s32 mapFileId_)
}
}
sub_80A37C4((void *)(VRAM + 0x8000 + groundBg->unk52C.unk4 * 32), file_434, &groundBg->unk52C, &groundBg->unk454);
_UncompressCell(groundBg->unk548, &groundBg->unk528, file_434 + ((mapPtr_454->unk4 - 1) * 16), &groundBg->unk52C, &groundBg->unk454);
file_438 = sub_80A3908(groundBg->unk54C, file_438, &groundBg->unk52C, &groundBg->unk448);
groundBg->unk468 = file_438;
sub_80A37C4((void *)(VRAM + 0x8000 + groundBg->unk52C.unk4 * 32), bpcData, &groundBg->unk52C, &groundBg->layerSpecs);
_UncompressCell(groundBg->unk548, &groundBg->unk528, bpcData + ((layerSpecs->numTiles - 1) * 16), &groundBg->unk52C, &groundBg->layerSpecs);
bmaData = BmaLayerNrlDecompressor(groundBg->unk54C, bmaData, &groundBg->unk52C, &groundBg->bmaHeader);
groundBg->unk468 = bmaData;
if (groundBg->unk544 != NULL) {
groundBg->unk52C.unk14(groundBg->unk544, file_438, mapPtr_448, groundBg->unk52C.unkE);
groundBg->unk52C.unk14(groundBg->unk544, bmaData, bmaHeader, groundBg->unk52C.unkE);
}
sub0Ptr = groundBg->unk0;
unk0Id = 0;
if (mapPtr_464[1] != 0) {
const s16 *r3 = file_430 + (mapPtr_464[0] * 60);
const void *r6 = &r3[mapPtr_464[0] * 2];
if (bplHeader->hasPalAnimations != 0) {
const s16 *r3 = bplData + (bplHeader->numPalettes * 60);
const void *r6 = &r3[bplHeader->numPalettes * 2];
groundBg->unk46C = r3;
groundBg->unk470 = 1;
groundBg->unk471 = 1;
for (; unk0Id < mapPtr_464[0] && unk0Id < groundBg->unk52C.unk2; unk0Id++, sub0Ptr++, r3 += 2) {
for (; unk0Id < bplHeader->numPalettes && unk0Id < groundBg->unk52C.unk2; unk0Id++, sub0Ptr++, r3 += 2) {
if (r3[1] > 0) {
sub0Ptr->unk4 = r6;
r6 += r3[1] * 60;
@ -340,35 +340,35 @@ void sub_80A2FBC(GroundBg *groundBg, s32 mapFileId_)
sub0Ptr->unk4 = sub0Ptr->unk8 = 0;
}
vramPtr = (void *)(VRAM + 0x8000 + (groundBg->unk52C.unk4 + mapPtr_454->unk4) * 32);
vramPtr = (void *)(VRAM + 0x8000 + (groundBg->unk52C.unk4 + layerSpecs->numTiles) * 32);
for (id = 0; id < 2; id++) {
SubStruct_3E0 *sub3E0 = &groundBg->unk3E0[id];
if (mapFilesPtr->fileName4[id] != NULL) {
const struct UnkFileStruct *fileStr;
if (mapFilesPtr->bpaFileNames[id] != NULL) {
const struct BpaHeader *bpaHeader;
const void *r1, *r0;
sub3E0->unk8 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName4[id], &gGroundFileArchive);
sub3E0->bpaFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bpaFileNames[id], &gGroundFileArchive);
sub3E0->unk0 = 1;
sub3E0->unk1 = 1;
fileStr = sub3E0->unk8->data;
sub3E0->unkC = fileStr;
r1 = &fileStr->unk4;
r0 = r1 + fileStr->unk2 * 4;
bpaHeader = sub3E0->bpaFile->data;
sub3E0->unkC = bpaHeader;
r1 = &bpaHeader->durationPerFrame;
r0 = r1 + bpaHeader->numFrames * 4;
sub3E0->unk10 = sub3E0->unk14 = r1;
sub3E0->unk18 = sub3E0->unk1C = r0;
sub3E0->unk2 = 0;
sub3E0->unk4 = (u32) fileStr->unk4[0]; // ?
sub3E0->unk4 = bpaHeader->durationPerFrame[0];
sub3E0->unk20 = vramPtr;
sub3E0->unk24 = mapPtr_454->unk6[id] * 32;
sub3E0->unk24 = layerSpecs->bpaSlotNumTiles[id] * 32;
vramPtr += mapPtr_454->unk6[id] * 32;
vramPtr += layerSpecs->bpaSlotNumTiles[id] * 32;
}
else {
sub3E0->unk0 = 0;
sub3E0->unk1 = 0;
sub3E0->unk4 = 0;
sub3E0->unk2 = 0;
sub3E0->unk8 = NULL;
sub3E0->bpaFile = NULL;
sub3E0->unkC = 0;
sub3E0->unk14 = 0;
sub3E0->unk10 = 0;
@ -378,18 +378,17 @@ void sub_80A2FBC(GroundBg *groundBg, s32 mapFileId_)
sub3E0->unk24 = 0;
}
}
for (; id < 4; id++) {
if (mapFilesPtr->fileName4[id] != NULL) {
for (; id < MAX_BPA_SLOTS; id++) {
if (mapFilesPtr->bpaFileNames[id] != NULL) {
s32 n;
OpenedFile *file = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName4[id], &gGroundFileArchive);
const struct UnkFileStruct *fileStr = file->data;
u16 *r1 = (void *) fileStr->unk4;
r1 += fileStr->unk2 * 2;
OpenedFile *file = OpenFileAndGetFileDataPtr(mapFilesPtr->bpaFileNames[id], &gGroundFileArchive);
const struct BpaHeader *bpaHeader = file->data;
const u16 *tiles = (void *) &bpaHeader->durationPerFrame;
tiles += bpaHeader->numFrames * 2;
n = mapPtr_454->unk6[id] * 16;
n = layerSpecs->bpaSlotNumTiles[id] * 16;
for (k = 0; k < n; k++) {
*(u16 *)(vramPtr) = *r1;
r1++;
*(u16 *)(vramPtr) = *tiles++;
vramPtr += 2;
}
CloseFile(file);
@ -405,14 +404,14 @@ void sub_80A3440(GroundBg *groundBg, s32 mapFileId_, const DungeonLocation *dung
{
SubStruct_0 *sub0Ptr;
s32 i;
SubStruct_545 *mapPtr_454;
const u16 *file_434;
const void *file_438;
const void *file_430;
SubStruct_448 *mapPtr_448;
LayerSpecs *layerSpecs;
const u16 *bpcData;
const void *bmaData;
const void *bplData;
BmaHeader *bmaHeader;
s32 unk0Id, sub3E0Id;
const struct MapFilesStruct *mapFilesPtr;
s16 *mapPtr_464;
BplHeader *bplHeader;
u16 *unkPtrArray[2];
s32 mapFileId = (s16) mapFileId_;
@ -425,56 +424,56 @@ void sub_80A3440(GroundBg *groundBg, s32 mapFileId_, const DungeonLocation *dung
CloseOpenedFiles(groundBg);
groundBg->mapFileId = mapFileId;
mapFilesPtr = &gMapFilesTable[mapFileId];
groundBg->unk430 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName1, &gGroundFileArchive);
groundBg->unk434 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName2, &gGroundFileArchive);
groundBg->unk438 = OpenFileAndGetFileDataPtr(mapFilesPtr->fileName3, &gGroundFileArchive);
file_430 = groundBg->unk430->data;
file_434 = groundBg->unk434->data;
file_438 = groundBg->unk438->data;
mapPtr_464 = groundBg->unk464;
mapPtr_454 = &groundBg->unk454;
mapPtr_448 = &groundBg->unk448;
groundBg->bplFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bplFileName, &gGroundFileArchive);
groundBg->bpcFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bpcFileName, &gGroundFileArchive);
groundBg->bmaFile = OpenFileAndGetFileDataPtr(mapFilesPtr->bmaFileName, &gGroundFileArchive);
bplData = groundBg->bplFile->data;
bpcData = groundBg->bpcFile->data;
bmaData = groundBg->bmaFile->data;
bplHeader = &groundBg->bplHeader;
layerSpecs = &groundBg->layerSpecs;
bmaHeader = &groundBg->bmaHeader;
mapPtr_464[0] = *(u8 *)(file_430); file_430 += 2;
mapPtr_464[1] = *(u8 *)(file_430); file_430 += 2;
bplHeader->numPalettes = *(u8 *)(bplData); bplData += 2;
bplHeader->hasPalAnimations = *(u8 *)(bplData); bplData += 2;
mapPtr_454->unk0 = *file_434++;
mapPtr_454->unk2 = *file_434++;
mapPtr_454->unk4 = *file_434++;
layerSpecs->unk0 = *bpcData++;
layerSpecs->unk2 = *bpcData++;
layerSpecs->numTiles = *bpcData++;
for (i = 0; i < UNK_545_UNK6_ARR_COUNT; i++) {
mapPtr_454->unk6[i] = *file_434++;
for (i = 0; i < MAX_BPA_SLOTS; i++) {
layerSpecs->bpaSlotNumTiles[i] = *bpcData++;
}
mapPtr_454->unkE = *file_434++;
layerSpecs->numChunks = *bpcData++;
mapPtr_448->unk0 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk1 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk2 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk3 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk4 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk5 = *(u8 *)(file_438); file_438 += 1;
mapPtr_448->unk6 = *(u8 *)(file_438); file_438 += 2;
mapPtr_448->unk8 = *(u8 *)(file_438); file_438 += 2;
mapPtr_448->unkA = *(u8 *)(file_438); file_438 += 2;
bmaHeader->mapWidthTiles = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapHeightTiles = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->tilingWidth = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->tilingHeight = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapWidthChunks = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->mapHeightChunks = *(u8 *)(bmaData); bmaData += 1;
bmaHeader->numLayers = *(u8 *)(bmaData); bmaData += 2;
bmaHeader->hasDataLayer = *(u8 *)(bmaData); bmaData += 2;
bmaHeader->hasCollision = *(u8 *)(bmaData); bmaData += 2;
unkPtrArray[0] = groundBg->unk544;
unkPtrArray[1] = NULL;
file_438 = sub_80A3908(unkPtrArray, file_438, &groundBg->unk52C, &groundBg->unk448);
groundBg->unk468 = file_438;
sub_80ADD9C(&groundBg->unk43C, &groundBg->unk440, (void *)(VRAM + 0x8000), groundBg->unk548, groundBg->unk54C[0], dungLoc, a3, 0x40, mapPtr_448->unk5, groundBg->unk544, 0);
bmaData = BmaLayerNrlDecompressor(unkPtrArray, bmaData, &groundBg->unk52C, &groundBg->bmaHeader);
groundBg->unk468 = bmaData;
sub_80ADD9C(&groundBg->unk43C, &groundBg->unk440, (void *)(VRAM + 0x8000), groundBg->unk548, groundBg->unk54C[0], dungLoc, a3, 0x40, bmaHeader->mapHeightChunks, groundBg->unk544, 0);
// Unused return values
GetFileDataPtr(groundBg->unk43C, 0);
GetFileDataPtr(groundBg->unk440, 0);
groundBg->unk52C.unk14(groundBg->unk544, file_438, mapPtr_448, groundBg->unk52C.unkE);
mapPtr_454->unk4 = 0x200;
for (i = 0; i < UNK_545_UNK6_ARR_COUNT; i++) {
mapPtr_454->unk6[i] = 0;
groundBg->unk52C.unk14(groundBg->unk544, bmaData, bmaHeader, groundBg->unk52C.unkE);
layerSpecs->numTiles = 512;
for (i = 0; i < MAX_BPA_SLOTS; i++) {
layerSpecs->bpaSlotNumTiles[i] = 0;
}
mapPtr_454->unkE = 250;
groundBg->unk464[0] = 12;
groundBg->unk464[1] = 0;
layerSpecs->numChunks = 250;
groundBg->bplHeader.numPalettes = 12;
groundBg->bplHeader.hasPalAnimations = FALSE;
if (groundBg->unk43C != NULL) {
s32 i, j;
const RGB_Union *strPtr = groundBg->unk43C->data;
@ -524,7 +523,7 @@ void sub_80A3440(GroundBg *groundBg, s32 mapFileId_, const DungeonLocation *dung
sub3E0->unk1 = 0;
sub3E0->unk4 = 0;
sub3E0->unk2 = 0;
sub3E0->unk8 = NULL;
sub3E0->bpaFile = NULL;
sub3E0->unkC = 0;
sub3E0->unk14 = 0;
sub3E0->unk10 = 0;
@ -537,10 +536,10 @@ void sub_80A3440(GroundBg *groundBg, s32 mapFileId_, const DungeonLocation *dung
sub_80A3EB0(groundBg->unk488);
groundBg->unk52A = 1;
// bad sp alloc for compiler generated variables...
ASM_MATCH_TRICK(mapPtr_454->unk6[0]);
ASM_MATCH_TRICK(layerSpecs->bpaSlotNumTiles[0]);
}
void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, SubStruct_545 *a3)
void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, LayerSpecs *layerSpecs)
{
const u16 *src = src_;
u16 *dst = vramDst;
@ -549,7 +548,7 @@ void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, SubStruct_54
for (i = 0; i < 16; i++) {
*dst++ = 0;
}
for (id = 1; id < a3->unk4; id++) {
for (id = 1; id < layerSpecs->numTiles; id++) {
for (i = 0; i < 16; i++) {
*dst++ = *src++;
}
@ -561,7 +560,7 @@ void sub_80A37C4(void *vramDst, const u16 *src_, SubStruct_52C *a2, SubStruct_54
}
}
static void _UncompressCell(void *dst_, u16 *a1, const void *src_, SubStruct_52C *a3, SubStruct_545 *a4)
static void _UncompressCell(void *dst_, u16 *a1, const void *src_, SubStruct_52C *a3, LayerSpecs *layerSpecs)
{
s32 id, i;
s32 n;
@ -570,23 +569,23 @@ static void _UncompressCell(void *dst_, u16 *a1, const void *src_, SubStruct_52C
u16 *dst = dst_;
u16 r6 = (a3->unk0 << 12) | a3->unk4;
if (a4->unk0 == 2 && a4->unk2 == 2) {
if (layerSpecs->unk0 == 2 && layerSpecs->unk2 == 2) {
*a1 = 1;
n = 4;
}
else if (a4->unk0 == 3 && a4->unk2 == 3) {
else if (layerSpecs->unk0 == 3 && layerSpecs->unk2 == 3) {
*a1 = 2;
n = 9;
}
else {
*a1 = 0;
FatalError(DEBUG_LOC_PTR("../ground/ground_bg.c", 1184, "_UncompressCell"), _("GroundBg cell type error %d %d"), a4->unk0, a4->unk2);
FatalError(DEBUG_LOC_PTR("../ground/ground_bg.c", 1184, "_UncompressCell"), _("GroundBg cell type error %d %d"), layerSpecs->unk0, layerSpecs->unk2);
}
for (i = 0; i < 9; i++) {
*dst++ = 0;
}
for (id = 1; id < a4->unkE; id++) {
for (id = 1; id < layerSpecs->numChunks; id++) {
for (i = 0; i < n; i++) {
*dst++ = *src++ + r6;
}
@ -601,19 +600,18 @@ static void _UncompressCell(void *dst_, u16 *a1, const void *src_, SubStruct_52C
}
}
// Tilemap decompression algorhitm?
static const u8 *sub_80A3908(u16 **dstArray, const void *src_, SubStruct_52C *a2, SubStruct_448 *mapPtr_448)
static const u8 *BmaLayerNrlDecompressor(u16 **dstArray, const void *bmaData, SubStruct_52C *a2, BmaHeader *bmaHeader)
{
s32 i, j, k, l;
const u8 *src = src_;
const u8 *src = bmaData;
for (i = 0; i < a2->unkC; i++) {
u16 *dst = dstArray[i];
for (j = 0; j < mapPtr_448->unk5; j++) {
for (j = 0; j < bmaHeader->mapHeightChunks; j++) {
k = 0;
if (j == 0) {
while (k < mapPtr_448->unk4) {
while (k < bmaHeader->mapWidthChunks) {
s32 val = *src++;
if (val > 191) {
for (l = 191; l < val; l++) {
@ -642,7 +640,7 @@ static const u8 *sub_80A3908(u16 **dstArray, const void *src_, SubStruct_52C *a2
}
else {
u16 *ptrVal = dst - 64;
while (k < mapPtr_448->unk4) {
while (k < bmaHeader->mapWidthChunks) {
s32 val = *src++;
if (val > 191) {
for (l = 191; l < val; l++) {
@ -768,10 +766,10 @@ static void sub_80A3D40(SubStruct_488 *map488, GroundBg *groundBg, s32 a2, s32 a
map488->unk2 = a2;
map488->unk4 = a3;
map488->unk6 = a4;
map488->unk8 = groundBg->unk448.unk4;
map488->unkC = groundBg->unk448.unk5;
map488->unk10.x = groundBg->unk448.unk0 * 8;
map488->unk10.y = groundBg->unk448.unk1 * 8;
map488->unk8 = groundBg->bmaHeader.mapWidthChunks;
map488->unkC = groundBg->bmaHeader.mapHeightChunks;
map488->unk10.x = groundBg->bmaHeader.mapWidthTiles * 8;
map488->unk10.y = groundBg->bmaHeader.mapHeightTiles * 8;
map488->unk1C = groundBg->unk548;
for (i = 0, j = a2; i < a3 && j < groundBg->unk52C.unkC; i++, j++) {
@ -1251,22 +1249,22 @@ void sub_80A4580(GroundBg *groundBg, s32 id, PixelPos *pixPos)
void sub_80A4608(GroundBg *groundBg, PixelPos *dstPos)
{
dstPos->x = groundBg->unk448.unk0;
dstPos->y = groundBg->unk448.unk1;
dstPos->x = groundBg->bmaHeader.mapWidthTiles;
dstPos->y = groundBg->bmaHeader.mapHeightTiles;
}
UNUSED static void sub_80A4620(GroundBg *groundBg, PixelPos *dstPos)
{
dstPos->x = groundBg->unk448.unk0 * 8;
dstPos->y = groundBg->unk448.unk1 * 8;
dstPos->x = groundBg->bmaHeader.mapWidthTiles * 8;
dstPos->y = groundBg->bmaHeader.mapHeightTiles * 8;
}
void GetDungeonBounds(GroundBg *groundBg, PixelPos *dstPos1, PixelPos *dstPos2)
{
dstPos1->x = 0;
dstPos1->y = 0;
dstPos2->x = groundBg->unk448.unk0 << 11;
dstPos2->y = groundBg->unk448.unk1 << 11;
dstPos2->x = groundBg->bmaHeader.mapWidthTiles << 11;
dstPos2->y = groundBg->bmaHeader.mapHeightTiles << 11;
}
u8 sub_80A4660(GroundBg *groundBg, u8 bits, PixelPos *pixPos1, PixelPos *boundary)
@ -1337,13 +1335,13 @@ void sub_80A4764(GroundBg *groundBg)
if (groundBg->mapFileId == -1)
return;
if (groundBg->unk464[1] != 0) {
if (groundBg->bplHeader.hasPalAnimations) {
s32 i;
SubStruct_0 *sub0Ptr = groundBg->unk0;
const u16 *ptr = groundBg->unk46C;
const s16 *ptr = groundBg->unk46C;
u16 r6 = groundBg->unk52C.unk0 * 16;
for (i = 0; i < groundBg->unk464[0]; i++, sub0Ptr++, ptr += 2, r6 += 16) {
for (i = 0; i < groundBg->bplHeader.numPalettes; i++, sub0Ptr++, ptr += 2, r6 += 16) {
if (sub0Ptr->unk4 != NULL && --sub0Ptr->unk2 <= 0) {
if (--sub0Ptr->unk0 <= 0) {
if (groundBg->unk471) {
@ -1398,7 +1396,7 @@ void sub_80A4764(GroundBg *groundBg)
if (sub3E0Ptr->unk0 && sub3E0Ptr->unk4-- <= 0) {
sub3E0Ptr->unk14 += 4;
sub3E0Ptr->unk1C += (sub3E0Ptr->unk24 / 2) * 2;
if (++sub3E0Ptr->unk2 >= sub3E0Ptr->unkC->unk2) {
if (++sub3E0Ptr->unk2 >= sub3E0Ptr->unkC->numFrames) {
sub3E0Ptr->unk14 = sub3E0Ptr->unk10;
sub3E0Ptr->unk1C = sub3E0Ptr->unk18;
sub3E0Ptr->unk2 = 0;

File diff suppressed because it is too large Load Diff