diff --git a/Makefile b/Makefile index c079a5074..d94a4d9bf 100755 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ else CC1 := $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet LIBPATH := -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libc.a))" LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall - override CC1FLAGS += -mthumb -mthumb-interwork -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -Wimplicit -Wparentheses -Wunused -Werror -O2 + override CC1FLAGS += -mthumb -mthumb-interwork -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -Wimplicit -Wparentheses -Wunused -Werror -O2 -g -Wno-unused-variable -Wno-incompatible-pointer-types INCLUDE_DIRS := include INCLUDE_CPP_ARGS := $(INCLUDE_DIRS:%=-iquote %) INCLUDE_PATHS := $(INCLUDE_DIRS:%=-I %) diff --git a/include/code_800558C.h b/include/code_800558C.h index 838d53d78..e25068523 100644 --- a/include/code_800558C.h +++ b/include/code_800558C.h @@ -1,11 +1,11 @@ #ifndef GUARD_CODE_800558C_H #define GUARD_CODE_800558C_H -extern bool8 gUnknown_2026E38; -extern s16 *gUnknown_2026E3C; +extern bool8 gDrawWindow; +extern s16 *gWin0HPtr; extern s16 gUnknown_2026E4E; -extern s16 *gUnknown_203B078; +extern s16 *gWindowBgCopy; void sub_80057E8(void); void sub_8005838(s32 *, u8 kind); diff --git a/include/text_1.h b/include/text_1.h index 1ce9901e2..9e8438d25 100644 --- a/include/text_1.h +++ b/include/text_1.h @@ -43,7 +43,7 @@ extern void (*ScrollUpWindowFunc)(s32 windowId); extern void (*gIwramTextFunc3)(s32 a0); extern void (*gIwramTextFunc4)(s32 a0); -extern s16 gUnknown_3000E94[161]; +extern s16 gWindowBg[161]; extern const u32 gUnknown_80B853C[16]; extern const unkShiftData gCharMasksOffsets[8]; diff --git a/include/text_2.h b/include/text_2.h index 86f7caca3..96ee0d1c6 100644 --- a/include/text_2.h +++ b/include/text_2.h @@ -16,7 +16,7 @@ void sub_8007B7C(u32 a0, s32 x, s32 y, s32 a3, u32 color); // srcGFX: Each u32 is 8 packed pixels, 4 bits per pixel. void WriteGFXToBG0Window(u32 winID, u32 x, u32 y, u32 w, u32 h, u32 *srcGFX, u32 palNum); void sub_80087EC(s32 a0, s32 a1, s32 a2, s32 a3, s32 a4); -void sub_80089AC(const WindowTemplate *r4, DungeonPos *r5_Str); +void DrawWindowBg(const WindowTemplate *window, DungeonPos *pos); u32 DrawCharOnWindow(s32 x, s32 y, u32 chr, u32 color, u32 windowId); bool8 xxx_call_update_bg_vram(void); u32 DrawCharOnWindowInternal(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowId); diff --git a/src/code_800558C.c b/src/code_800558C.c index 5ff29b4c0..e4ea82a0b 100644 --- a/src/code_800558C.c +++ b/src/code_800558C.c @@ -4,27 +4,28 @@ #include "code_800558C.h" #include "math.h" -EWRAM_DATA bool8 gUnknown_2026E38 = FALSE; -EWRAM_DATA s16 *gUnknown_2026E3C = NULL; +EWRAM_DATA bool8 gDrawWindow = FALSE; +EWRAM_DATA s16 *gWin0HPtr = NULL; EWRAM_DATA static s32 sUnknown_2026E40 = 0; // Read from but never written to EWRAM_DATA static s32 sUnknown_2026E44 = 0; // Read from but never written to EWRAM_DATA static s32 sUnknown_2026E48 = 0; // Read from but never written to -EWRAM_DATA static bool8 sUnknown_2026E4C = FALSE; +EWRAM_DATA static bool8 sInitialized = FALSE; EWRAM_DATA s16 gUnknown_2026E4E = 0; -EWRAM_DATA static bool32 sUnknown_2026E50 = FALSE; -EWRAM_DATA static bool32 sUnknown_2026E54 = FALSE; -EWRAM_DATA static s16 *sUnknown_2026E58 = NULL; +EWRAM_DATA static bool32 sBoolUnk = FALSE; // Toggled but is never read +EWRAM_DATA static bool32 sBufferIdx = FALSE; // Write to sBuffer0 or sBuffer1 +EWRAM_DATA static s16 *sBufferPtr = NULL; UNUSED EWRAM_DATA static u32 sUnused0 = 0; -EWRAM_DATA static s16 sUnknown_2026E60[324] = {0}; // These might be [2][162] -EWRAM_DATA static s16 sUnknown_20270E8[324] = {0}; +EWRAM_DATA static s16 sBuffer0[324] = {0}; // These might be [2][162] +EWRAM_DATA static s16 sBuffer1[324] = {0}; -EWRAM_INIT s16 *gUnknown_203B078 = NULL; +EWRAM_INIT s16 *gWindowBgCopy = NULL; static const s16 gUnknown_80B8008[17] = {16, 12, 9, 7, 6, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0}; -#define UNK_TABLES_ARR_COUNT 160 +#define Y_MAX 160 -static const s16 gUnknown_80B802A[UNK_TABLES_ARR_COUNT] = { +// Dim edges of screen in corridors with 1 visibility +static const s16 sCorridorDim1[Y_MAX] = { 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, @@ -49,7 +50,8 @@ static const s16 gUnknown_80B802A[UNK_TABLES_ARR_COUNT] = { 0x100, 0x100, 0x100 }; -static const s16 gUnknown_80B816A[UNK_TABLES_ARR_COUNT] = { +// Dim edges of screen in corridors with 2 visibility +static const s16 sCorridorDim2[Y_MAX] = { 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, @@ -75,28 +77,28 @@ static const s16 gUnknown_80B816A[UNK_TABLES_ARR_COUNT] = { 0x100 }; -// Almost all 0x100 -static const s16 gUnknown_80B82AA[UNK_TABLES_ARR_COUNT] = { +// Almost all 0x100 (unused?) +static const s16 gUnknown_80B82AA[Y_MAX] = { [0 ... 2] = 0x100, [3] = 0x9392, - [4 ... UNK_TABLES_ARR_COUNT - 1] = 0x100 + [4 ... Y_MAX - 1] = 0x100 }; -// All zeroes -static const s16 gUnknown_80B83EA[UNK_TABLES_ARR_COUNT] = { - [0 ... UNK_TABLES_ARR_COUNT - 1] = 0 +// All zeroes (fallback?) +static const s16 sDefaultBgH[Y_MAX] = { + [0 ... Y_MAX - 1] = 0 }; // arm9.bin::02006154 void sub_80057E8(void) { - sUnknown_2026E4C = TRUE; - sUnknown_2026E54 = FALSE; - sUnknown_2026E50 = TRUE; - sUnknown_2026E58 = NULL; - gUnknown_2026E3C = NULL; - gUnknown_2026E38 = FALSE; + sInitialized = TRUE; + sBufferIdx = FALSE; + sBoolUnk = TRUE; + sBufferPtr = NULL; + gWin0HPtr = NULL; + gDrawWindow = FALSE; gUnknown_2026E4E = 0x60C; - gUnknown_203B078 = NULL; + gWindowBgCopy = NULL; } // arm9.bin::02005758 @@ -106,16 +108,16 @@ void sub_8005838(s32 *a0, u8 kind) s16 *dst; s32 i; - if (!sUnknown_2026E4C) + if (!sInitialized) kind = 0; - dst = !sUnknown_2026E54 ? sUnknown_2026E60 : sUnknown_20270E8; + dst = !sBufferIdx ? sBuffer0 : sBuffer1; - src1 = gUnknown_203B078; + src1 = gWindowBgCopy; if (src1 == NULL) - src1 = gUnknown_80B83EA; + src1 = sDefaultBgH; - sUnknown_2026E58 = dst; + sBufferPtr = dst; switch (kind) { case 0: @@ -155,7 +157,7 @@ void sub_8005838(s32 *a0, u8 kind) } break; case 1: - src2 = gUnknown_80B816A; + src2 = sCorridorDim2; for (i = 0; i < 10; i++) { *dst++ = *src1++; *dst++ = *src2++; @@ -192,7 +194,7 @@ void sub_8005838(s32 *a0, u8 kind) } break; case 2: - src2 = gUnknown_80B802A; + src2 = sCorridorDim1; for (i = 0; i < 10; i++) { *dst++ = *src1++; *dst++ = *src2++; @@ -437,10 +439,10 @@ void sub_8005838(s32 *a0, u8 kind) if (j >= 160) continue; - if (!sUnknown_2026E54) - sUnknown_2026E60[j * 2 + 1] = uVar7; + if (!sBufferIdx) + sBuffer0[j * 2 + 1] = uVar7; else - sUnknown_20270E8[j * 2 + 1] = uVar7; + sBuffer1[j * 2 + 1] = uVar7; } for (; k > r8; k--) { @@ -449,10 +451,10 @@ void sub_8005838(s32 *a0, u8 kind) if (k >= 160) continue; - if (!sUnknown_2026E54) - sUnknown_2026E60[k * 2 + 1] = uVar7; + if (!sBufferIdx) + sBuffer0[k * 2 + 1] = uVar7; else - sUnknown_20270E8[k * 2 + 1] = uVar7; + sBuffer1[k * 2 + 1] = uVar7; } } } @@ -464,19 +466,19 @@ void sub_8005838(s32 *a0, u8 kind) #if (GAME_VERSION == VERSION_RED) UNUSED static void sub_80060A8(void) { - gUnknown_2026E3C = sUnknown_2026E58; - sUnknown_2026E54 = !sUnknown_2026E54; - sUnknown_2026E50 = !sUnknown_2026E50; - gUnknown_2026E38 = FALSE; + gWin0HPtr = sBufferPtr; + sBufferIdx = !sBufferIdx; + sBoolUnk = !sBoolUnk; + gDrawWindow = FALSE; } #endif // arm9.bin::020056C0 void sub_80060EC(void) { - gUnknown_2026E3C = sUnknown_2026E58; - sUnknown_2026E54 = !sUnknown_2026E54; - sUnknown_2026E50 = !sUnknown_2026E50; + gWin0HPtr = sBufferPtr; + sBufferIdx = !sBufferIdx; + sBoolUnk = !sBoolUnk; SetBldAlphaReg((gUnknown_2026E4E & 0x1F00) >> 8, gUnknown_2026E4E & 0x1F); - gUnknown_2026E38 = TRUE; + gDrawWindow = TRUE; } diff --git a/src/cpu.c b/src/cpu.c index 58343c3b0..2a2204700 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -80,11 +80,11 @@ void VBlank_CB(void) REG_WINOUT = WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR | WINOUT_WIN01_BG3 | WINOUT_WIN01_BG2 | WINOUT_WIN01_BG0; REG_BLDCNT = gBldCnt; REG_BLDALPHA = gBldAlpha; - if (gUnknown_2026E38) { + if (gDrawWindow) { // Very interesting use of DmaCopy16 here. - DmaSet(0, &gUnknown_2026E3C[2], REG_ADDR_WIN0H, ((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_SRC_INC | DMA_DEST_RELOAD | DMA_16BIT) << 16) | 2); - REG_WIN0H = gUnknown_2026E3C[0]; - REG_WIN1H = gUnknown_2026E3C[1]; + DmaSet(0, &gWin0HPtr[2], REG_ADDR_WIN0H, ((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_SRC_INC | DMA_DEST_RELOAD | DMA_16BIT) << 16) | 2); + REG_WIN0H = gWin0HPtr[0]; + REG_WIN1H = gWin0HPtr[1]; REG_WIN0V = DISPLAY_HEIGHT; REG_WIN1V = DISPLAY_HEIGHT; } diff --git a/src/text_1.c b/src/text_1.c index a15312928..4c5dc9296 100644 --- a/src/text_1.c +++ b/src/text_1.c @@ -37,7 +37,7 @@ EWRAM_INIT void (*ScrollUpWindowFunc)(s32 windowId) = ScrollUpWindow; EWRAM_INIT void (*gIwramTextFunc3)(s32 a0) = sub_82729A4; EWRAM_INIT void (*gIwramTextFunc4)(s32 a0) = sub_8272A78; -IWRAM_DATA ALIGNED(4) s16 gUnknown_3000E94[161] = {0}; +IWRAM_DATA ALIGNED(4) s16 gWindowBg[161] = {0}; const u32 gUnknown_80B853C[16] = { @@ -160,7 +160,7 @@ void LoadCharmaps(void) gDrawTextShadow = 1; gTextShadowMask = 0x88888888; - gUnknown_203B078 = NULL; + gWindowBgCopy = NULL; gUnknown_20274A5 = FALSE; gUnknown_202B020 = 1; gUnknown_202B024 = 20; @@ -266,18 +266,18 @@ static void ShowWindowsInternal(const WindowTemplates *winTemplates, bool8 a1, b if (winTemplates->id[i].width != 0) { AddWindow(gWindows, (u32 *)VRAM, sWindowGFXPool, gBgTilemaps, sUnknown_80B8804[i], &winTemplates->id[i], a1, startTileNum, positionModifier, FALSE); - sub_80089AC(&winTemplates->id[i], positionModifier); + DrawWindowBg(&winTemplates->id[i], positionModifier); startTileNum += winTemplates->id[i].width * winTemplates->id[i].totalHeight; } } // Needed to account for weird compiler LDRs - ASM_MATCH_TRICK(gUnknown_203B078); - ASM_MATCH_TRICK(gUnknown_3000E94[0]); + ASM_MATCH_TRICK(gWindowBgCopy); + ASM_MATCH_TRICK(gWindowBg[0]); ASM_MATCH_TRICK(gUnknown_20274A5); - gUnknown_203B078 = gUnknown_3000E94; + gWindowBgCopy = gWindowBg; gUnknown_20274A5 = TRUE; } diff --git a/src/text_2.c b/src/text_2.c index 097dcb814..463ed0b61 100644 --- a/src/text_2.c +++ b/src/text_2.c @@ -1107,169 +1107,184 @@ void ResetWindowBgData(void) { s32 i; - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_3000E94); i++) { - gUnknown_3000E94[i] = 0xF0F0; + for (i = 0; i < ARRAY_COUNT_INT(gWindowBg); i++) { + gWindowBg[i] = 0xF0F0; } } -void sub_80089AC(const WindowTemplate *r4, DungeonPos *r5_Str) +void DrawWindowBg(const WindowTemplate *window, DungeonPos *pos) { - u8 *r6; + const u8 WINH_DEFAULT = 0xF0; + const s32 Y_MAX = 160; + u8 *windowArr; - if (r4->flags & WINTEMPLATE_FLAG_x40) + if (window->flags & WINTEMPLATE_FLAG_x40) return; - r6 = (u8*) gUnknown_3000E94; - if (r4->type == WINDOW_TYPE_WITHOUT_BORDER) { - s32 r12 = (r4->pos.x + r5_Str->x) * 8; - s32 r5 = (r4->pos.y + r5_Str->y) * 8; - s32 r7 = (r4->pos.x + r5_Str->x + r4->width) * 8; - s32 r2 = (r4->pos.y + r5_Str->y + r4->height) * 8; - if (r4->height != 0) { - if (r5 < 0) - r5 = 0; - if (r2 < 0) - r2 = 0; - if (r5 > 160) - r5 = 160; - if (r2 > 160) - r2 = 160; - while (r5 < r2) { - s32 id = r5 * 2; - if (r6[id] == 240 && r6[id + 1] == 240) { - r6[id++] = r7; - r6[id] = r12; + windowArr = (u8*) gWindowBg; + if (window->type == WINDOW_TYPE_WITHOUT_BORDER) { + s32 xStart = (window->pos.x + pos->x) * 8; + s32 yStart = (window->pos.y + pos->y) * 8; + s32 xEnd = (window->pos.x + pos->x + window->width) * 8; + s32 yEnd = (window->pos.y + pos->y + window->height) * 8; + if (window->height != 0) { + if (yStart < 0) + yStart = 0; + if (yEnd < 0) + yEnd = 0; + if (yStart > Y_MAX) + yStart = Y_MAX; + if (yEnd > Y_MAX) + yEnd = Y_MAX; + + // Draw window background + while (yStart < yEnd) { + s32 idx = yStart * 2; + if (windowArr[idx] == WINH_DEFAULT && windowArr[idx + 1] == WINH_DEFAULT) { + windowArr[idx++] = xEnd; // Right side of window + windowArr[idx] = xStart; // Left side of window } else { - if (r6[id] < r7) { - r6[id] = r7; + // Only allow window to expand in size? + // Right side of window + if (windowArr[idx] < xEnd) { + windowArr[idx] = xEnd; } - id++; - if (r6[id] > r12) { - r6[id] = r12; + idx++; + // Left side of window + if (windowArr[idx] > xStart) { + windowArr[idx] = xStart; } } - r5++; + yStart++; } } } - else if (r4->type == WINDOW_TYPE_WITH_HEADER) { + else if (window->type == WINDOW_TYPE_WITH_HEADER) { s32 i; - s32 r9 = ((r4->pos.x + r5_Str->x) * 8) - 5; - s32 r5 = ((r4->pos.y + r5_Str->y) * 8) - 4; - s32 var_24 = ((r4->pos.x + r5_Str->x + r4->width) * 8) + 5; - s32 r8 = ((r4->pos.y + r5_Str->y + r4->height) * 8) + 5; - s32 r12 = ((r4->pos.x + r5_Str->x) * 8) + 3; - const WindowHeader *r2 = r4->header; - s32 tmp = r2->width - 1; - s32 r10 = (((tmp + r2->count + 2) * 8) + r12) - 4; - s32 r4 = r9 + ((r2->currId + 1) * 8); - s32 r7 = (r4 + ((r2->width + 2) * 8)) - 4; + s32 xStart = ((window->pos.x + pos->x) * 8) - 5; + s32 yStart = ((window->pos.y + pos->y) * 8) - 4; + s32 xEnd = ((window->pos.x + pos->x + window->width) * 8) + 5; + s32 yEnd = ((window->pos.y + pos->y + window->height) * 8) + 5; + s32 allHeadersStart = ((window->pos.x + pos->x) * 8) + 3; + const WindowHeader *header = window->header; + s32 tmp = header->width - 1; + s32 allHeadersEnd = (((tmp + header->count + 2) * 8) + allHeadersStart) - 4; + s32 currHeaderStart = xStart + ((header->currId + 1) * 8); + s32 currHeaderEnd = (currHeaderStart + ((header->width + 2) * 8)) - 4; - if (r5 < 0) - r5 = 0; - if (r8 < 0) - r8 = 0; - if (r5 > 160) - r5 = 160; - if (r8 > 160) - r8 = 160; + if (yStart < 0) + yStart = 0; + if (yEnd < 0) + yEnd = 0; + if (yStart > Y_MAX) + yStart = Y_MAX; + if (yEnd > Y_MAX) + yEnd = Y_MAX; // BUG: The background array is 161 entries long, but this function will potentially write // up to index 160 + 12 = 172, overflowing the array. #ifdef UBFIX - if (r5 > 160 - 12) { - r5 = 160 - 12; + if (yStart > Y_MAX - 12) { + yStart = Y_MAX - 12; } #endif + // Draw extra header background for current tab + // For multi-tabbed windows, the current tab is taller, so need to draw an extra 4 pixels of BG for (i = 0; i < 4; i++) { - s32 id = r5 * 2; - if (r6[id] == 240 && r6[id + 1] == 240) { - r6[id++] = r7; - r6[id] = r4; + s32 idx = yStart * 2; + if (windowArr[idx] == WINH_DEFAULT && windowArr[idx + 1] == WINH_DEFAULT) { + windowArr[idx++] = currHeaderEnd; // Right side of window + windowArr[idx] = currHeaderStart; // Left side of window } else { - if (r6[id] < r7) { - r6[id] = r7; + // Only allow window to expand in size? + // Right side of window + if (windowArr[idx] < currHeaderEnd) { + windowArr[idx] = currHeaderEnd; } - id++; - if (r6[id] > r4) { - r6[id] = r4; + idx++; + // Left side of window + if (windowArr[idx] > currHeaderStart) { + windowArr[idx] = currHeaderStart; } } - r5++; - } - for (i = 0; i < 8; i++) { - s32 id = r5 * 2; - if (r6[id] == 240 && r6[id + 1] == 240) { - r6[id++] = r10; - r6[id] = r12; - } - else { - if (r6[id] < r10) { - r6[id] = r10; - } - id++; - if (r6[id] > r12) { - r6[id] = r12; - } - } - r5++; + yStart++; } - while (r5 < r8) { - s32 id = r5 * 2; - if (r6[id] == 240 && r6[id + 1] == 240) { - r6[id++] = var_24; - r6[id] = r9; + // Draw header background for all tabs + for (i = 0; i < 8; i++) { + s32 id = yStart * 2; + if (windowArr[id] == WINH_DEFAULT && windowArr[id + 1] == WINH_DEFAULT) { + windowArr[id++] = allHeadersEnd; // Right side of window + windowArr[id] = allHeadersStart; // Left side of window } else { - if (r6[id] < var_24) { - r6[id] = var_24; + if (windowArr[id] < allHeadersEnd) { + windowArr[id] = allHeadersEnd; } id++; - if (r6[id] > r9) { - r6[id] = r9; + if (windowArr[id] > allHeadersStart) { + windowArr[id] = allHeadersStart; } } - r5++; + yStart++; + } + + // Draw main window background + while (yStart < yEnd) { + s32 idx = yStart * 2; + if (windowArr[idx] == WINH_DEFAULT && windowArr[idx + 1] == WINH_DEFAULT) { + windowArr[idx++] = xEnd; // Right side of window + windowArr[idx] = xStart; // Left side of window + } + else { + if (windowArr[idx] < xEnd) { + windowArr[idx] = xEnd; + } + idx++; + if (windowArr[idx] > xStart) { + windowArr[idx] = xStart; + } + } + yStart++; } } else { - s32 r8 = ((r4->pos.x + r5_Str->x) * 8) - 5; - s32 r3 = ((r4->pos.y + r5_Str->y) * 8) - 5; - s32 r12 = ((r4->pos.x + r5_Str->x + r4->width) * 8) + 5; - s32 r5 = ((r4->pos.y + r5_Str->y + r4->height) * 8) + 5; - if (r4->height != 0) { - if (r4->type == 0) { - r3 += 8; - r5 = ((r4->pos.y + r5_Str->y + r4->height) * 8) - 3; + s32 xStart = ((window->pos.x + pos->x) * 8) - 5; + s32 yStart = ((window->pos.y + pos->y) * 8) - 5; + s32 xEnd = ((window->pos.x + pos->x + window->width) * 8) + 5; + s32 yEnd = ((window->pos.y + pos->y + window->height) * 8) + 5; + if (window->height != 0) { + if (window->type == WINDOW_TYPE_0) { + yStart += 8; + yEnd = ((window->pos.y + pos->y + window->height) * 8) - 3; } - if (r3 < 0) - r3 = 0; - if (r5 < 0) - r5 = 0; - if (r3 > 160) - r3 = 160; - if (r5 > 160) - r5 = 160; - while (r3 < r5) { - s32 id = r3 * 2; - if (r6[id] == 240 && r6[id + 1] == 240) { - r6[id++] = r12; - r6[id] = r8; + if (yStart < 0) + yStart = 0; + if (yEnd < 0) + yEnd = 0; + if (yStart > Y_MAX) + yStart = Y_MAX; + if (yEnd > Y_MAX) + yEnd = Y_MAX; + while (yStart < yEnd) { + s32 idx = yStart * 2; + if (windowArr[idx] == WINH_DEFAULT && windowArr[idx + 1] == WINH_DEFAULT) { + windowArr[idx++] = xEnd; // Right side of window + windowArr[idx] = xStart; // Left side of window } else { - if (r6[id] < r12) { - r6[id] = r12; + if (windowArr[idx] < xEnd) { + windowArr[idx] = xEnd; } - id++; - if (r6[id] > r8) { - r6[id] = r8; + idx++; + if (windowArr[idx] > xStart) { + windowArr[idx] = xStart; } } - r3++; + yStart++; } } }