diff options
Diffstat (limited to 'gflib')
-rw-r--r-- | gflib/bg.c | 106 | ||||
-rw-r--r-- | gflib/bg.h | 2 | ||||
-rw-r--r-- | gflib/dma3_manager.c | 118 | ||||
-rw-r--r-- | gflib/malloc.c | 2 | ||||
-rw-r--r-- | gflib/sprite.c | 48 | ||||
-rw-r--r-- | gflib/sprite.h | 1 | ||||
-rw-r--r-- | gflib/string_util.h | 8 | ||||
-rw-r--r-- | gflib/text.c | 247 | ||||
-rw-r--r-- | gflib/text.h | 18 | ||||
-rw-r--r-- | gflib/window.c | 104 | ||||
-rw-r--r-- | gflib/window.h | 10 |
11 files changed, 333 insertions, 331 deletions
diff --git a/gflib/bg.c b/gflib/bg.c index 66dd81a25..ec7c2113b 100644 --- a/gflib/bg.c +++ b/gflib/bg.c @@ -9,20 +9,20 @@ struct BgControl { struct BgConfig { - u16 visible:1; - u16 unknown_1:1; - u16 screenSize:2; - u16 priority:2; - u16 mosaic:1; - u16 wraparound:1; + u8 visible:1; + u8 unknown_1:1; + u8 screenSize:2; + u8 priority:2; + u8 mosaic:1; + u8 wraparound:1; - u16 charBaseIndex:2; - u16 mapBaseIndex:5; - u16 paletteMode:1; + u8 charBaseIndex:2; + u8 mapBaseIndex:5; + u8 paletteMode:1; - u8 unknown_2; - u8 unknown_3; - } configs[4]; + u8 unknown_2; // Assigned to but never read + u8 unknown_3; // Assigned to but never read + } configs[NUM_BACKGROUNDS]; u16 bgVisibilityAndMode; }; @@ -39,8 +39,8 @@ struct BgConfig2 }; static struct BgControl sGpuBgConfigs; -static struct BgConfig2 sGpuBgConfigs2[4]; -static u32 sDmaBusyBitfield[4]; +static struct BgConfig2 sGpuBgConfigs2[NUM_BACKGROUNDS]; +static u32 sDmaBusyBitfield[NUM_BACKGROUNDS]; u32 gUnneededFireRedVariable; @@ -55,7 +55,7 @@ void ResetBgs(void) static void SetBgModeInternal(u8 bgMode) { - sGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8; + sGpuBgConfigs.bgVisibilityAndMode &= ~0x7; sGpuBgConfigs.bgVisibilityAndMode |= bgMode; } @@ -66,13 +66,11 @@ u8 GetBgMode(void) void ResetBgControlStructs(void) { - struct BgConfig* bgConfigs = &sGpuBgConfigs.configs[0]; - struct BgConfig zeroedConfig = sZeroedBgControlStruct; int i; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BACKGROUNDS; i++) { - bgConfigs[i] = zeroedConfig; + sGpuBgConfigs.configs[i] = sZeroedBgControlStruct; } } @@ -102,17 +100,17 @@ static void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 { if (charBaseIndex != 0xFF) { - sGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3; + sGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex; } if (mapBaseIndex != 0xFF) { - sGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F; + sGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex; } if (screenSize != 0xFF) { - sGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3; + sGpuBgConfigs.configs[bg].screenSize = screenSize; } if (paletteMode != 0xFF) @@ -122,12 +120,12 @@ static void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 if (priority != 0xFF) { - sGpuBgConfigs.configs[bg].priority = priority & 0x3; + sGpuBgConfigs.configs[bg].priority = priority; } if (mosaic != 0xFF) { - sGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1; + sGpuBgConfigs.configs[bg].mosaic = mosaic; } if (wraparound != 0xFF) @@ -175,36 +173,30 @@ u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode) u16 offset; s8 cursor; - if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) - { - switch (mode) - { - case 0x1: - offset = sGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE; - break; - case 0x2: - offset = sGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE; - break; - default: - cursor = -1; - goto end; - } + if (IsInvalidBg(bg) || !sGpuBgConfigs.configs[bg].visible) + return -1; + switch (mode) + { + case 0x1: + offset = sGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE; offset = destOffset + offset; - cursor = RequestDma3Copy(src, (void*)(offset + BG_VRAM), size, 0); - if (cursor == -1) - { return -1; - } - } - else - { - return -1; + break; + case 0x2: + offset = sGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE; + offset = destOffset + offset; + cursor = RequestDma3Copy(src, (void*)(offset + BG_VRAM), size, 0); + if (cursor == -1) + return -1; + break; + default: + cursor = -1; + break; } -end: return cursor; } @@ -254,17 +246,17 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC switch (sGpuBgConfigs.bgVisibilityAndMode & 0x7) { + default: + case 0: + return; case 1: if (bg != 2) return; break; case 2: - if (bg < 2 || bg > 3) + if (bg != 2 && bg != 3) return; break; - case 0: - default: - return; } src.texX = srcCenterX; @@ -290,7 +282,7 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC bool8 IsInvalidBg(u8 bg) { - if (bg > 3) + if (bg >= NUM_BACKGROUNDS) return TRUE; else return FALSE; @@ -306,7 +298,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable) int i; ResetBgs(); - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BACKGROUNDS; i++) { sDmaBusyBitfield[i] = 0; } @@ -325,7 +317,7 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT for (i = 0; i < numTemplates; i++) { bg = templates[i].bg; - if (bg < 4) + if (bg < NUM_BACKGROUNDS) { SetBgControlAttributes(bg, templates[i].charBaseIndex, @@ -351,7 +343,7 @@ void InitBgFromTemplate(const struct BgTemplate *template) { u8 bg = template->bg; - if (bg < 4) + if (bg < NUM_BACKGROUNDS) { SetBgControlAttributes(bg, template->charBaseIndex, @@ -697,7 +689,7 @@ s32 ChangeBgY(u8 bg, s32 value, u8 op) return sGpuBgConfigs2[bg].bg_y; } -s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) +s32 ChangeBgY_ScreenOff(u8 bg, s32 value, u8 op) { u8 mode; u16 temp1; @@ -1239,7 +1231,7 @@ u32 GetBgType(u8 bg) bool32 IsInvalidBg32(u8 bg) { - if (bg > 3) + if (bg >= NUM_BACKGROUNDS) return TRUE; else return FALSE; diff --git a/gflib/bg.h b/gflib/bg.h index 3c7eee292..58fd1282c 100644 --- a/gflib/bg.h +++ b/gflib/bg.h @@ -59,7 +59,7 @@ u16 GetBgAttribute(u8 bg, u8 attributeId); s32 ChangeBgX(u8 bg, s32 value, u8 op); s32 GetBgX(u8 bg); s32 ChangeBgY(u8 bg, s32 value, u8 op); -s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op); +s32 ChangeBgY_ScreenOff(u8 bg, s32 value, u8 op); s32 GetBgY(u8 bg); void SetBgAffine(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle); u8 Unused_AdjustBgMosaic(u8 a1, u8 a2); diff --git a/gflib/dma3_manager.c b/gflib/dma3_manager.c index 43744883f..d774efe8c 100644 --- a/gflib/dma3_manager.c +++ b/gflib/dma3_manager.c @@ -8,88 +8,90 @@ #define DMA_REQUEST_COPY16 3 #define DMA_REQUEST_FILL16 4 -BSS_DATA struct +struct Dma3Request { const u8 *src; u8 *dest; u16 size; u16 mode; u32 value; -} gDma3Requests[MAX_DMA_REQUESTS]; +}; -static volatile bool8 gDma3ManagerLocked; -static u8 gDma3RequestCursor; +static struct Dma3Request sDma3Requests[MAX_DMA_REQUESTS]; + +static vbool8 sDma3ManagerLocked; +static u8 sDma3RequestCursor; void ClearDma3Requests(void) { int i; - gDma3ManagerLocked = TRUE; - gDma3RequestCursor = 0; + sDma3ManagerLocked = TRUE; + sDma3RequestCursor = 0; for (i = 0; i < MAX_DMA_REQUESTS; i++) { - gDma3Requests[i].size = 0; - gDma3Requests[i].src = NULL; - gDma3Requests[i].dest = NULL; + sDma3Requests[i].size = 0; + sDma3Requests[i].src = NULL; + sDma3Requests[i].dest = NULL; } - gDma3ManagerLocked = FALSE; + sDma3ManagerLocked = FALSE; } void ProcessDma3Requests(void) { u16 bytesTransferred; - if (gDma3ManagerLocked) + if (sDma3ManagerLocked) return; bytesTransferred = 0; // as long as there are DMA requests to process (unless size or vblank is an issue), do not exit - while (gDma3Requests[gDma3RequestCursor].size != 0) + while (sDma3Requests[sDma3RequestCursor].size != 0) { - bytesTransferred += gDma3Requests[gDma3RequestCursor].size; + bytesTransferred += sDma3Requests[sDma3RequestCursor].size; if (bytesTransferred > 40 * 1024) return; // don't transfer more than 40 KiB if (*(u8 *)REG_ADDR_VCOUNT > 224) return; // we're about to leave vblank, stop - switch (gDma3Requests[gDma3RequestCursor].mode) + switch (sDma3Requests[sDma3RequestCursor].mode) { case DMA_REQUEST_COPY32: // regular 32-bit copy - Dma3CopyLarge32_(gDma3Requests[gDma3RequestCursor].src, - gDma3Requests[gDma3RequestCursor].dest, - gDma3Requests[gDma3RequestCursor].size); + Dma3CopyLarge32_(sDma3Requests[sDma3RequestCursor].src, + sDma3Requests[sDma3RequestCursor].dest, + sDma3Requests[sDma3RequestCursor].size); break; case DMA_REQUEST_FILL32: // repeat a single 32-bit value across RAM - Dma3FillLarge32_(gDma3Requests[gDma3RequestCursor].value, - gDma3Requests[gDma3RequestCursor].dest, - gDma3Requests[gDma3RequestCursor].size); + Dma3FillLarge32_(sDma3Requests[sDma3RequestCursor].value, + sDma3Requests[sDma3RequestCursor].dest, + sDma3Requests[sDma3RequestCursor].size); break; case DMA_REQUEST_COPY16: // regular 16-bit copy - Dma3CopyLarge16_(gDma3Requests[gDma3RequestCursor].src, - gDma3Requests[gDma3RequestCursor].dest, - gDma3Requests[gDma3RequestCursor].size); + Dma3CopyLarge16_(sDma3Requests[sDma3RequestCursor].src, + sDma3Requests[sDma3RequestCursor].dest, + sDma3Requests[sDma3RequestCursor].size); break; case DMA_REQUEST_FILL16: // repeat a single 16-bit value across RAM - Dma3FillLarge16_(gDma3Requests[gDma3RequestCursor].value, - gDma3Requests[gDma3RequestCursor].dest, - gDma3Requests[gDma3RequestCursor].size); + Dma3FillLarge16_(sDma3Requests[sDma3RequestCursor].value, + sDma3Requests[sDma3RequestCursor].dest, + sDma3Requests[sDma3RequestCursor].size); break; } // Free the request - gDma3Requests[gDma3RequestCursor].src = NULL; - gDma3Requests[gDma3RequestCursor].dest = NULL; - gDma3Requests[gDma3RequestCursor].size = 0; - gDma3Requests[gDma3RequestCursor].mode = 0; - gDma3Requests[gDma3RequestCursor].value = 0; - gDma3RequestCursor++; - - if (gDma3RequestCursor >= MAX_DMA_REQUESTS) // loop back to the first DMA request - gDma3RequestCursor = 0; + sDma3Requests[sDma3RequestCursor].src = NULL; + sDma3Requests[sDma3RequestCursor].dest = NULL; + sDma3Requests[sDma3RequestCursor].size = 0; + sDma3Requests[sDma3RequestCursor].mode = 0; + sDma3Requests[sDma3RequestCursor].value = 0; + sDma3RequestCursor++; + + if (sDma3RequestCursor >= MAX_DMA_REQUESTS) // loop back to the first DMA request + sDma3RequestCursor = 0; } } @@ -98,30 +100,30 @@ s16 RequestDma3Copy(const void *src, void *dest, u16 size, u8 mode) int cursor; int i = 0; - gDma3ManagerLocked = TRUE; - cursor = gDma3RequestCursor; + sDma3ManagerLocked = TRUE; + cursor = sDma3RequestCursor; while (i < MAX_DMA_REQUESTS) { - if (gDma3Requests[cursor].size == 0) // an empty request was found. + if (sDma3Requests[cursor].size == 0) // an empty request was found. { - gDma3Requests[cursor].src = src; - gDma3Requests[cursor].dest = dest; - gDma3Requests[cursor].size = size; + sDma3Requests[cursor].src = src; + sDma3Requests[cursor].dest = dest; + sDma3Requests[cursor].size = size; if (mode == 1) - gDma3Requests[cursor].mode = DMA_REQUEST_COPY32; + sDma3Requests[cursor].mode = DMA_REQUEST_COPY32; else - gDma3Requests[cursor].mode = DMA_REQUEST_COPY16; + sDma3Requests[cursor].mode = DMA_REQUEST_COPY16; - gDma3ManagerLocked = FALSE; + sDma3ManagerLocked = FALSE; return cursor; } if (++cursor >= MAX_DMA_REQUESTS) // loop back to start. cursor = 0; i++; } - gDma3ManagerLocked = FALSE; + sDma3ManagerLocked = FALSE; return -1; // no free DMA request was found } @@ -130,31 +132,31 @@ s16 RequestDma3Fill(s32 value, void *dest, u16 size, u8 mode) int cursor; int i = 0; - cursor = gDma3RequestCursor; - gDma3ManagerLocked = TRUE; + cursor = sDma3RequestCursor; + sDma3ManagerLocked = TRUE; while (i < MAX_DMA_REQUESTS) { - if (gDma3Requests[cursor].size == 0) // an empty request was found. + if (sDma3Requests[cursor].size == 0) // an empty request was found. { - gDma3Requests[cursor].dest = dest; - gDma3Requests[cursor].size = size; - gDma3Requests[cursor].mode = mode; - gDma3Requests[cursor].value = value; + sDma3Requests[cursor].dest = dest; + sDma3Requests[cursor].size = size; + sDma3Requests[cursor].mode = mode; + sDma3Requests[cursor].value = value; if(mode == 1) - gDma3Requests[cursor].mode = DMA_REQUEST_FILL32; + sDma3Requests[cursor].mode = DMA_REQUEST_FILL32; else - gDma3Requests[cursor].mode = DMA_REQUEST_FILL16; + sDma3Requests[cursor].mode = DMA_REQUEST_FILL16; - gDma3ManagerLocked = FALSE; + sDma3ManagerLocked = FALSE; return cursor; } if (++cursor >= MAX_DMA_REQUESTS) // loop back to start. cursor = 0; i++; } - gDma3ManagerLocked = FALSE; + sDma3ManagerLocked = FALSE; return -1; // no free DMA request was found } @@ -166,7 +168,7 @@ s16 CheckForSpaceForDma3Request(s16 index) { while (i < MAX_DMA_REQUESTS) { - if (gDma3Requests[i].size != 0) + if (sDma3Requests[i].size != 0) return -1; i++; } @@ -174,7 +176,7 @@ s16 CheckForSpaceForDma3Request(s16 index) } else // check the specified request { - if (gDma3Requests[index].size != 0) + if (sDma3Requests[index].size != 0) return -1; return 0; } diff --git a/gflib/malloc.c b/gflib/malloc.c index 4d1a9fe5c..38fc8939e 100644 --- a/gflib/malloc.c +++ b/gflib/malloc.c @@ -2,7 +2,7 @@ static void *sHeapStart; static u32 sHeapSize; -static u32 malloc_c_unused_0300000c; // needed to align dma3_manager.o(.bss) +static u32 sFiller; // needed to align dma3_manager.o(.bss) #define MALLOC_SYSTEM_ID 0xA3A3 diff --git a/gflib/sprite.c b/gflib/sprite.c index c7e3d09a3..f97ecc712 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -33,6 +33,12 @@ struct SpriteCopyRequest u16 size; }; +struct OamDimensions32 +{ + s32 width; + s32 height; +}; + struct OamDimensions { s8 width; @@ -240,25 +246,28 @@ static const AffineAnimCmdFunc sAffineAnimCmdFuncs[] = AffineAnimCmd_frame, }; -static const s32 sUnknown_082EC6F4[3][4][2] = +static const struct OamDimensions32 sOamDimensions32[3][4] = { + [ST_OAM_SQUARE] = { - {8, 8}, - {0x10, 0x10}, - {0x20, 0x20}, - {0x40, 0x40}, + [SPRITE_SIZE(8x8)] = { 8, 8 }, + [SPRITE_SIZE(16x16)] = { 16, 16 }, + [SPRITE_SIZE(32x32)] = { 32, 32 }, + [SPRITE_SIZE(64x64)] = { 64, 64 }, }, + [ST_OAM_H_RECTANGLE] = { - {0x10, 8}, - {0x20, 8}, - {0x20, 0x10}, - {0x40, 0x20}, + [SPRITE_SIZE(16x8)] = { 16, 8 }, + [SPRITE_SIZE(32x8)] = { 32, 8 }, + [SPRITE_SIZE(32x16)] = { 32, 16 }, + [SPRITE_SIZE(64x32)] = { 64, 32 }, }, + [ST_OAM_V_RECTANGLE] = { - {8, 0x10}, - {8, 0x20}, - {0x10, 0x20}, - {0x20, 0x40}, + [SPRITE_SIZE(8x16)] = { 8, 16 }, + [SPRITE_SIZE(8x32)] = { 8, 32 }, + [SPRITE_SIZE(16x32)] = { 16, 32 }, + [SPRITE_SIZE(32x64)] = { 32, 64 }, }, }; @@ -443,6 +452,10 @@ void SortSprites(void) // Although this doesn't result in a bug in the ROM, // the behavior is undefined. j--; +#ifdef UBFIX + if (j == 0) + break; +#endif sprite1 = &gSprites[sSpriteOrder[j - 1]]; sprite2 = &gSprites[sSpriteOrder[j]]; @@ -652,8 +665,7 @@ void ResetOamRange(u8 a, u8 b) for (i = a; i < b; i++) { - struct OamData *oamBuffer = gMain.oamBuffer; - oamBuffer[i] = *(struct OamData *)&gDummyOamData; + gMain.oamBuffer[i] = *(struct OamData *)&gDummyOamData; } } @@ -1233,14 +1245,14 @@ void obj_update_pos2(struct Sprite *sprite, s32 a1, s32 a2) u32 matrixNum = sprite->oam.matrixNum; if (a1 != 0x800) { - var0 = sUnknown_082EC6F4[sprite->oam.shape][sprite->oam.size][0]; + var0 = sOamDimensions32[sprite->oam.shape][sprite->oam.size].width; var1 = var0 << 8; var2 = (var0 << 16) / gOamMatrices[matrixNum].a; sprite->pos2.x = sub_8007E28(var1, var2, a1); } if (a2 != 0x800) { - var0 = sUnknown_082EC6F4[sprite->oam.shape][sprite->oam.size][1]; + var0 = sOamDimensions32[sprite->oam.shape][sprite->oam.size].height; var1 = var0 << 8; var2 = (var0 << 16) / gOamMatrices[matrixNum].d; sprite->pos2.y = sub_8007E28(var1, var2, a2); @@ -1320,7 +1332,7 @@ void ApplyAffineAnimFrameRelativeAndUpdateMatrix(u8 matrixNum, struct AffineAnim s16 ConvertScaleParam(s16 scale) { s32 val = 0x10000; - return val / scale; + return SAFE_DIV(val, scale); } void GetAffineAnimFrame(u8 matrixNum, struct Sprite *sprite, struct AffineAnimFrameCmd *frameCmd) diff --git a/gflib/sprite.h b/gflib/sprite.h index c9ba9585d..4a3b48225 100644 --- a/gflib/sprite.h +++ b/gflib/sprite.h @@ -2,6 +2,7 @@ #define GUARD_SPRITE_H #define MAX_SPRITES 64 +#define SPRITE_NONE 0xFF #define SPRITE_INVALID_TAG 0xFFFF struct SpriteSheet diff --git a/gflib/string_util.h b/gflib/string_util.h index b921d2391..229193d52 100644 --- a/gflib/string_util.h +++ b/gflib/string_util.h @@ -1,10 +1,10 @@ #ifndef GUARD_STRING_UTIL_H #define GUARD_STRING_UTIL_H -extern u8 gStringVar1[]; -extern u8 gStringVar2[]; -extern u8 gStringVar3[]; -extern u8 gStringVar4[]; +extern u8 gStringVar1[0x100]; +extern u8 gStringVar2[0x100]; +extern u8 gStringVar3[0x100]; +extern u8 gStringVar4[0x3E8]; enum StringConvertMode { diff --git a/gflib/text.c b/gflib/text.c index 4cbad1376..eb993c421 100644 --- a/gflib/text.c +++ b/gflib/text.c @@ -21,8 +21,8 @@ static u16 gLastTextFgColor; static u16 gLastTextShadowColor; const struct FontInfo *gFonts; -u8 gUnknown_03002F84; -struct Struct_03002F90 gUnknown_03002F90; +u8 gDisableTextPrinters; +struct TextGlyph gCurGlyph; TextFlags gTextFlags; const u8 gFontHalfRowOffsets[] = @@ -165,7 +165,6 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi { int i; u16 j; - u8 *ptr; if (!gFonts) return FALSE; @@ -205,7 +204,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2); gTextPrinters[printerTemplate->windowId].active = 0; } - gUnknown_03002F84 = 0; + gDisableTextPrinters = 0; return TRUE; } @@ -213,7 +212,7 @@ void RunTextPrinters(void) { int i; - if (gUnknown_03002F84 == 0) + if (gDisableTextPrinters == 0) { for (i = 0; i < NUM_TEXT_PRINTERS; ++i) { @@ -462,9 +461,9 @@ u8 GetLastTextColor(u8 colorType) } } -inline static void GLYPH_COPY(u8 *windowTiles, u32 widthOffset, u32 j, u32 i, u32 *ptr, s32 width, s32 height) +inline static void GLYPH_COPY(u8 *windowTiles, u32 widthOffset, u32 j, u32 i, u32 *glyphPixels, s32 width, s32 height) { - u32 xAdd, yAdd, r5, bits, toOrr, dummyX; + u32 xAdd, yAdd, pixelData, bits, toOrr, dummyX; u8 *dst; xAdd = j + width; @@ -472,69 +471,69 @@ inline static void GLYPH_COPY(u8 *windowTiles, u32 widthOffset, u32 j, u32 i, u3 dummyX = j; for (; i < yAdd; i++) { - r5 = *ptr++; + pixelData = *glyphPixels++; for (j = dummyX; j < xAdd; j++) { - if ((toOrr = r5 & 0xF)) + if ((toOrr = pixelData & 0xF)) { dst = windowTiles + ((j / 8) * 32) + ((j % 8) / 2) + ((i / 8) * widthOffset) + ((i % 8) * 4); bits = ((j & 1) * 4); *dst = (toOrr << bits) | (*dst & (0xF0 >> bits)); } - r5 >>= 4; + pixelData >>= 4; } } } void CopyGlyphToWindow(struct TextPrinter *textPrinter) { - struct Window *win; - struct WindowTemplate *winTempl; - u32 *unkStruct; + struct Window *window; + struct WindowTemplate *template; + u32 *glyphPixels; u32 currX, currY, widthOffset; - s32 r4, r0; + s32 glyphWidth, glyphHeight; u8 *windowTiles; - win = &gWindows[textPrinter->printerTemplate.windowId]; - winTempl = &win->window; + window = &gWindows[textPrinter->printerTemplate.windowId]; + template = &window->window; - if ((r4 = (winTempl->width * 8) - textPrinter->printerTemplate.currentX) > gUnknown_03002F90.width) - r4 = gUnknown_03002F90.width; + if ((glyphWidth = (template->width * 8) - textPrinter->printerTemplate.currentX) > gCurGlyph.width) + glyphWidth = gCurGlyph.width; - if ((r0 = (winTempl->height * 8) - textPrinter->printerTemplate.currentY) > gUnknown_03002F90.height) - r0 = gUnknown_03002F90.height; + if ((glyphHeight = (template->height * 8) - textPrinter->printerTemplate.currentY) > gCurGlyph.height) + glyphHeight = gCurGlyph.height; currX = textPrinter->printerTemplate.currentX; currY = textPrinter->printerTemplate.currentY; - unkStruct = (u32 *)&gUnknown_03002F90.unk0; - windowTiles = win->tileData; - widthOffset = winTempl->width * 32; + glyphPixels = gCurGlyph.gfxBufferTop; + windowTiles = window->tileData; + widthOffset = template->width * 32; - if (r4 < 9) + if (glyphWidth < 9) { - if (r0 < 9) + if (glyphHeight < 9) { - GLYPH_COPY(windowTiles, widthOffset, currX, currY, unkStruct, r4, r0); + GLYPH_COPY(windowTiles, widthOffset, currX, currY, glyphPixels, glyphWidth, glyphHeight); } else { - GLYPH_COPY(windowTiles, widthOffset, currX, currY, unkStruct, r4, 8); - GLYPH_COPY(windowTiles, widthOffset, currX, currY + 8, unkStruct + 16, r4, r0 - 8); + GLYPH_COPY(windowTiles, widthOffset, currX, currY, glyphPixels, glyphWidth, 8); + GLYPH_COPY(windowTiles, widthOffset, currX, currY + 8, glyphPixels + 16, glyphWidth, glyphHeight - 8); } } else { - if (r0 < 9) + if (glyphHeight < 9) { - GLYPH_COPY(windowTiles, widthOffset, currX, currY, unkStruct, 8, r0); - GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY, unkStruct + 8, r4 - 8, r0); + GLYPH_COPY(windowTiles, widthOffset, currX, currY, glyphPixels, 8, glyphHeight); + GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY, glyphPixels + 8, glyphWidth - 8, glyphHeight); } else { - GLYPH_COPY(windowTiles, widthOffset, currX, currY, unkStruct, 8, 8); - GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY, unkStruct + 8, r4 - 8, 8); - GLYPH_COPY(windowTiles, widthOffset, currX, currY + 8, unkStruct + 16, 8, r0 - 8); - GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY + 8, unkStruct + 24, r4 - 8, r0 - 8); + GLYPH_COPY(windowTiles, widthOffset, currX, currY, glyphPixels, 8, 8); + GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY, glyphPixels + 8, glyphWidth - 8, 8); + GLYPH_COPY(windowTiles, widthOffset, currX, currY + 8, glyphPixels + 16, 8, glyphHeight - 8); + GLYPH_COPY(windowTiles, widthOffset, currX + 8, currY + 8, glyphPixels + 24, glyphWidth - 8, glyphHeight - 8); } } } @@ -543,7 +542,7 @@ void ClearTextSpan(struct TextPrinter *textPrinter, u32 width) { struct Window *window; struct Bitmap pixels_data; - struct Struct_03002F90 *gUnk; + struct TextGlyph *glyph; u8* glyphHeight; if (gLastTextBgColor != 0) @@ -553,8 +552,8 @@ void ClearTextSpan(struct TextPrinter *textPrinter, u32 width) pixels_data.width = window->window.width << 3; pixels_data.height = window->window.height << 3; - gUnk = &gUnknown_03002F90; - glyphHeight = &gUnk->height; + glyph = &gCurGlyph; + glyphHeight = &glyph->height; FillBitmapRect4Bit( &pixels_data, @@ -1016,8 +1015,8 @@ u16 RenderText(struct TextPrinter *textPrinter) break; case CHAR_KEYPAD_ICON: currChar = *textPrinter->printerTemplate.currentChar++; - gUnknown_03002F90.width = DrawKeypadIcon(textPrinter->printerTemplate.windowId, currChar, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY); - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width + textPrinter->printerTemplate.letterSpacing; + gCurGlyph.width = DrawKeypadIcon(textPrinter->printerTemplate.windowId, currChar, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY); + textPrinter->printerTemplate.currentX += gCurGlyph.width + textPrinter->printerTemplate.letterSpacing; return 0; case EOS: return 1; @@ -1051,8 +1050,8 @@ u16 RenderText(struct TextPrinter *textPrinter) if (textPrinter->minLetterSpacing) { - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width; - width = textPrinter->minLetterSpacing - gUnknown_03002F90.width; + textPrinter->printerTemplate.currentX += gCurGlyph.width; + width = textPrinter->minLetterSpacing - gCurGlyph.width; if (width > 0) { ClearTextSpan(textPrinter, width); @@ -1062,9 +1061,9 @@ u16 RenderText(struct TextPrinter *textPrinter) else { if (textPrinter->japanese) - textPrinter->printerTemplate.currentX += (gUnknown_03002F90.width + textPrinter->printerTemplate.letterSpacing); + textPrinter->printerTemplate.currentX += (gCurGlyph.width + textPrinter->printerTemplate.letterSpacing); else - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width; + textPrinter->printerTemplate.currentX += gCurGlyph.width; } return 0; case 1: @@ -1235,7 +1234,6 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) bool8 isJapanese; int minGlyphWidth; u32 (*func)(u16 glyphId, bool32 isJapanese); - s32 result; int localLetterSpacing; u32 lineWidth; const u8 *bufferPointer; @@ -1400,8 +1398,7 @@ s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing) if (lineWidth > width) return lineWidth; - else - return width; + return width; } u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str) @@ -1419,9 +1416,9 @@ u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str) fgColor = TEXT_COLOR_WHITE; bgColor = TEXT_COLOR_TRANSPARENT; - shadowColor = TEXT_COLOR_LIGHT_GREY; + shadowColor = TEXT_COLOR_LIGHT_GRAY; - GenerateFontHalfRowLookupTable(TEXT_COLOR_WHITE, TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GREY); + GenerateFontHalfRowLookupTable(TEXT_COLOR_WHITE, TEXT_COLOR_TRANSPARENT, TEXT_COLOR_LIGHT_GRAY); strLocal = str; strPos = 0; @@ -1501,8 +1498,8 @@ u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str) DecompressGlyphFont1(temp, 1); break; } - CpuCopy32(gUnknown_03002F90.unk0, pixels, 0x20); - CpuCopy32(gUnknown_03002F90.unk40, pixels + 0x20, 0x20); + CpuCopy32(gCurGlyph.gfxBufferTop, pixels, 0x20); + CpuCopy32(gCurGlyph.gfxBufferBottom, pixels + 0x20, 0x20); pixels += 0x40; break; } @@ -1594,30 +1591,30 @@ void DecompressGlyphFont0(u16 glyphId, bool32 isJapanese) if (isJapanese == 1) { glyphs = gFont0JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & 0xF)); - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 12; // gGlyphHeight + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); + gCurGlyph.width = 8; + gCurGlyph.height = 12; } else { glyphs = gFont0LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont0LatinGlyphWidths[glyphId]; + gCurGlyph.width = gFont0LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gCurGlyph.width <= 8) { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); } else { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); + DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8); } - gUnknown_03002F90.height = 13; + gCurGlyph.height = 13; } } @@ -1635,32 +1632,31 @@ void DecompressGlyphFont7(u16 glyphId, bool32 isJapanese) if (isJapanese == TRUE) { - int eff; - glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & (eff = 0xF))); // shh, no questions, only matching now - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 15; // gGlyphHeight + glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId % 0x10)); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); + gCurGlyph.width = 8; + gCurGlyph.height = 15; } else { glyphs = gFont7LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont7LatinGlyphWidths[glyphId]; + gCurGlyph.width = gFont7LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gCurGlyph.width <= 8) { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); } else { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); + DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8); } - gUnknown_03002F90.height = 15; + gCurGlyph.height = 15; } } @@ -1679,30 +1675,30 @@ void DecompressGlyphFont8(u16 glyphId, bool32 isJapanese) if (isJapanese == TRUE) { glyphs = gFont0JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & 0xF)); - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 12; // gGlyphHeight + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); + gCurGlyph.width = 8; + gCurGlyph.height = 12; } else { glyphs = gFont8LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont8LatinGlyphWidths[glyphId]; + gCurGlyph.width = gFont8LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gCurGlyph.width <= 8) { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); } else { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); + DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8); } - gUnknown_03002F90.height = 12; + gCurGlyph.height = 12; } } @@ -1721,32 +1717,32 @@ void DecompressGlyphFont2(u16 glyphId, bool32 isJapanese) if (isJapanese == TRUE) { glyphs = gFont2JapaneseGlyphs + (0x100 * (glyphId >> 0x3)) + (0x10 * (glyphId & 0x7)); - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); // gUnknown_03002F90 + 0x40 - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x20 - DecompressGlyphTile(glyphs + 0x88, gUnknown_03002F90.unk60); // gUnknown_03002F90 + 0x60 - gUnknown_03002F90.width = gFont2JapaneseGlyphWidths[glyphId]; // gGlyphWidth - gUnknown_03002F90.height = 14; // gGlyphHeight + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); // gCurGlyph + 0x20 + DecompressGlyphTile(glyphs + 0x88, gCurGlyph.gfxBufferBottom + 8); // gCurGlyph + 0x60 + gCurGlyph.width = gFont2JapaneseGlyphWidths[glyphId]; + gCurGlyph.height = 14; } else { glyphs = gFont2LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont2LatinGlyphWidths[glyphId]; + gCurGlyph.width = gFont2LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gCurGlyph.width <= 8) { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); } else { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); + DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8); } - gUnknown_03002F90.height = 14; + gCurGlyph.height = 14; } } @@ -1764,32 +1760,31 @@ void DecompressGlyphFont1(u16 glyphId, bool32 isJapanese) if (isJapanese == TRUE) { - int eff; - glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & (eff = 0xF))); // shh, no questions, only matching now - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 15; // gGlyphHeight + glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId % 0x10)); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); + gCurGlyph.width = 8; + gCurGlyph.height = 15; } else { glyphs = gFont1LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont1LatinGlyphWidths[glyphId]; + gCurGlyph.width = gFont1LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gCurGlyph.width <= 8) { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); } else { - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8); + DecompressGlyphTile(glyphs + 0x10, gCurGlyph.gfxBufferBottom); + DecompressGlyphTile(glyphs + 0x18, gCurGlyph.gfxBufferBottom + 8); } - gUnknown_03002F90.height = 15; + gCurGlyph.height = 15; } } @@ -1806,8 +1801,8 @@ void DecompressGlyphFont9(u16 glyphId) const u16* glyphs; glyphs = gFont9JapaneseGlyphs + (0x100 * (glyphId >> 4)) + (0x8 * (glyphId & 0xF)); - DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); - gUnknown_03002F90.width = 8; - gUnknown_03002F90.height = 12; + DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop); + DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom); + gCurGlyph.width = 8; + gCurGlyph.height = 12; } diff --git a/gflib/text.h b/gflib/text.h index 723a2fc0e..3edd0fc62 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -71,7 +71,7 @@ // #define CHAR_i_ACUTE 0x6F // -#define CHAR_UNK_SPACER 0x77 +#define CHAR_GENDERLESS 0x77 // Empty space for lack of gender icon // #define CHAR_UP_ARROW 0x79 #define CHAR_DOWN_ARROW 0x7A @@ -233,8 +233,8 @@ #define TEXT_COLOR_TRANSPARENT 0x0 #define TEXT_COLOR_WHITE 0x1 -#define TEXT_COLOR_DARK_GREY 0x2 -#define TEXT_COLOR_LIGHT_GREY 0x3 +#define TEXT_COLOR_DARK_GRAY 0x2 +#define TEXT_COLOR_LIGHT_GRAY 0x3 #define TEXT_COLOR_RED 0x4 #define TEXT_COLOR_LIGHT_RED 0x5 #define TEXT_COLOR_GREEN 0x6 @@ -360,20 +360,18 @@ typedef struct { bool8 forceMidTextSpeed:1; } TextFlags; -struct Struct_03002F90 +struct TextGlyph { - u32 unk0[8]; - u32 unk20[8]; - u32 unk40[8]; - u32 unk60[8]; + u32 gfxBufferTop[16]; + u32 gfxBufferBottom[16]; u8 width; u8 height; }; extern TextFlags gTextFlags; -extern u8 gUnknown_03002F84; -extern struct Struct_03002F90 gUnknown_03002F90; +extern u8 gDisableTextPrinters; +extern struct TextGlyph gCurGlyph; void SetFontsPointer(const struct FontInfo *fonts); void DeactivateAllTextPrinters(void); diff --git a/gflib/window.c b/gflib/window.c index 7c87ea86d..b03b513da 100644 --- a/gflib/window.c +++ b/gflib/window.c @@ -4,12 +4,12 @@ #include "bg.h" #include "blit.h" -u32 filler_03002F58; -u32 filler_03002F5C; +u32 gUnusedWindowVar1; +u32 gUnusedWindowVar2; // This global is set to 0 and never changed. u8 gTransparentTileNumber; -u32 filler_03002F64; -void *gUnknown_03002F70[4]; +u32 gUnusedWindowVar3; +void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS]; extern u32 gUnneededFireRedVariable; #define WINDOWS_MAX 32 @@ -23,7 +23,7 @@ static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId); static const struct WindowTemplate sDummyWindowTemplate = DUMMY_WIN_TEMPLATE; -static void nullsub_8(void) +static void DummyWindowBgTilemap(void) { } @@ -38,22 +38,22 @@ bool16 InitWindows(const struct WindowTemplate *templates) u8* allocatedTilemapBuffer; int allocatedBaseBlock; - for (i = 0; i < 0x4; ++i) + for (i = 0; i < NUM_BACKGROUNDS; ++i) { bgTilemapBuffer = GetBgTilemapBuffer(i); if (bgTilemapBuffer != NULL) - gUnknown_03002F70[i] = nullsub_8; + gWindowBgTilemapBuffers[i] = DummyWindowBgTilemap; else - gUnknown_03002F70[i] = bgTilemapBuffer; + gWindowBgTilemapBuffers[i] = bgTilemapBuffer; } - for (i = 0; i < 0x20; ++i) + for (i = 0; i < WINDOWS_MAX; ++i) { gWindows[i].window = sDummyWindowTemplate; gWindows[i].tileData = NULL; } - for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].bg) + for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < WINDOWS_MAX; ++i, bgLayer = templates[i].bg) { if (gUnneededFireRedVariable == 1) { @@ -62,7 +62,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) return FALSE; } - if (gUnknown_03002F70[bgLayer] == NULL) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); @@ -79,19 +79,19 @@ bool16 InitWindows(const struct WindowTemplate *templates) for (j = 0; j < attrib; ++j) allocatedTilemapBuffer[j] = 0; - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); } } - allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (templates[i].width * templates[i].height))); + allocatedTilemapBuffer = AllocZeroed((u16)(32 * (templates[i].width * templates[i].height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; } return FALSE; @@ -127,7 +127,7 @@ u16 AddWindow(const struct WindowTemplate *template) } if (win == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -137,10 +137,10 @@ u16 AddWindow(const struct WindowTemplate *template) allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); if (allocatedBaseBlock == -1) - return 0xFF; + return WINDOW_NONE; } - if (gUnknown_03002F70[bgLayer] == NULL) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); @@ -149,26 +149,26 @@ u16 AddWindow(const struct WindowTemplate *template) allocatedTilemapBuffer = AllocZeroed(attrib); if (allocatedTilemapBuffer == NULL) - return 0xFF; + return WINDOW_NONE; for (i = 0; i < attrib; ++i) allocatedTilemapBuffer[i] = 0; - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); } } - allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (template->width * template->height))); + allocatedTilemapBuffer = AllocZeroed((u16)(32 * (template->width * template->height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; } - return 0xFF; + return WINDOW_NONE; } gWindows[win].tileData = allocatedTilemapBuffer; @@ -196,7 +196,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) } if (win == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -206,7 +206,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); if (allocatedBaseBlock == -1) - return 0xFF; + return WINDOW_NONE; } gWindows[win].window = *template; @@ -233,10 +233,10 @@ void RemoveWindow(u8 windowId) if (GetNumActiveWindowsOnBg(bgLayer) == 0) { - if (gUnknown_03002F70[bgLayer] != nullsub_8) + if (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = 0; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = NULL; } } @@ -251,16 +251,16 @@ void FreeAllWindowBuffers(void) { int i; - for (i = 0; i < 4; ++i) + for (i = 0; i < NUM_BACKGROUNDS; ++i) { - if (gUnknown_03002F70[i] != NULL && gUnknown_03002F70[i] != nullsub_8) + if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != DummyWindowBgTilemap) { - Free(gUnknown_03002F70[i]); - gUnknown_03002F70[i] = NULL; + Free(gWindowBgTilemapBuffers[i]); + gWindowBgTilemapBuffers[i] = NULL; } } - for (i = 0; i < 0x20; ++i) + for (i = 0; i < WINDOWS_MAX; ++i) { if (gWindows[i].tileData != NULL) { @@ -448,16 +448,16 @@ void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 void CopyToWindowPixelBuffer(u8 windowId, const void *src, u16 size, u16 tileOffset) { if (size != 0) - CpuCopy16(src, gWindows[windowId].tileData + (0x20 * tileOffset), size); + CpuCopy16(src, gWindows[windowId].tileData + (32 * tileOffset), size); else - LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset)); + LZ77UnCompWram(src, gWindows[windowId].tileData + (32 * tileOffset)); } // Sets all pixels within the window to the fillValue color. void FillWindowPixelBuffer(u8 windowId, u8 fillValue) { int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height; - CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize); + CpuFastFill8(fillValue, gWindows[windowId].tileData, 32 * fillSize); } #define MOVE_TILES_DOWN(a) \ @@ -599,7 +599,7 @@ static u8 GetNumActiveWindowsOnBg(u8 bgId) return windowsNum; } -static void nullsub_9(void) +static void DummyWindowBgTilemap8Bit(void) { } @@ -610,15 +610,15 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) u8* memAddress; u8 bgLayer; - for (windowId = 0; windowId < 32; windowId++) + for (windowId = 0; windowId < WINDOWS_MAX; windowId++) { if (gWindows[windowId].window.bg == 0xFF) break; } if (windowId == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; - if (gUnknown_03002F70[bgLayer] == 0) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attribute != 0xFFFF) @@ -626,22 +626,22 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) s32 i; memAddress = Alloc(attribute); if (memAddress == NULL) - return 0xFF; + return WINDOW_NONE; for (i = 0; i < attribute; i++) // if we're going to zero out the memory anyway, why not call AllocZeroed? memAddress[i] = 0; - gUnknown_03002F70[bgLayer] = memAddress; + gWindowBgTilemapBuffers[bgLayer] = memAddress; SetBgTilemapBuffer(bgLayer, memAddress); } } - memAddress = Alloc((u16)(0x40 * (template->width * template->height))); + memAddress = Alloc((u16)(64 * (template->width * template->height))); if (memAddress == NULL) { - if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gUnknown_03002F70[bgLayer] != nullsub_9) + if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap8Bit) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = NULL; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = NULL; } - return 0xFF; + return WINDOW_NONE; } else { @@ -656,7 +656,7 @@ void FillWindowPixelBuffer8Bit(u8 windowId, u8 fillValue) s32 i; s32 size; - size = (u16)(0x40 * (gWindows[windowId].window.width * gWindows[windowId].window.height)); + size = (u16)(64 * (gWindows[windowId].window.width * gWindows[windowId].window.height)); for (i = 0; i < size; i++) gWindows[windowId].tileData[i] = fillValue; } @@ -691,7 +691,7 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u void CopyWindowToVram8Bit(u8 windowId, u8 mode) { sWindowPtr = &gWindows[windowId]; - sWindowSize = 0x40 * (sWindowPtr->window.width * sWindowPtr->window.height); + sWindowSize = 64 * (sWindowPtr->window.width * sWindowPtr->window.height); switch (mode) { diff --git a/gflib/window.h b/gflib/window.h index 10e447789..3eac75a28 100644 --- a/gflib/window.h +++ b/gflib/window.h @@ -37,6 +37,8 @@ struct WindowTemplate 0, \ } +#define WINDOW_NONE 0xFF + struct Window { struct WindowTemplate window; @@ -70,9 +72,9 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u void CopyWindowToVram8Bit(u8 windowId, u8 mode); extern struct Window gWindows[]; -extern void* gUnknown_03002F70[]; -extern u32 filler_03002F58; -extern u32 filler_03002F5C; -extern u32 filler_03002F64; +extern void* gWindowBgTilemapBuffers[]; +extern u32 gUnusedWindowVar1; +extern u32 gUnusedWindowVar2; +extern u32 gUnusedWindowVar3; #endif // GUARD_WINDOW_H |