From 3909b6408c0125fe311d49a3029a2806993615f7 Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Thu, 29 Nov 2018 19:24:28 +0800 Subject: Fix alloc.c as per #386, define INVALID_ constants and rename malloc to alloc as per #325 Some of the INVALID_ are likely erroneously placed, due to lack of documentation --- src/window.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/window.c') diff --git a/src/window.c b/src/window.c index 8efd1c281..d5b996df1 100644 --- a/src/window.c +++ b/src/window.c @@ -1,6 +1,6 @@ #include "global.h" #include "window.h" -#include "malloc.h" +#include "alloc.h" #include "bg.h" #include "blit.h" @@ -52,12 +52,12 @@ bool16 InitWindows(const struct WindowTemplate *templates) 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 != INVALID_U8 && i < 0x20; ++i, bgLayer = templates[i].bg) { if (gUnneededFireRedVariable == 1) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, templates[i].width * templates[i].height, 0); - if (allocatedBaseBlock == -1) + if (allocatedBaseBlock == INVALID_S32) return FALSE; } @@ -65,7 +65,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) { attrib = GetBgAttribute(bgLayer, 0x8); - if (attrib != 0xFFFF) + if (attrib != INVALID_U16) { allocatedTilemapBuffer = AllocZeroed(attrib); @@ -121,12 +121,12 @@ u16 AddWindow(const struct WindowTemplate *template) for (win = 0; win < WINDOWS_MAX; ++win) { - if ((bgLayer = gWindows[win].window.bg) == 0xFF) + if ((bgLayer = gWindows[win].window.bg) == INVALID_U8) break; } if (win == WINDOWS_MAX) - return 0xFF; + return INVALID_U8; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -135,20 +135,20 @@ u16 AddWindow(const struct WindowTemplate *template) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); - if (allocatedBaseBlock == -1) - return 0xFF; + if (allocatedBaseBlock == INVALID_S32) + return INVALID_U8; } if (gUnknown_03002F70[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, 0x8); - if (attrib != 0xFFFF) + if (attrib != INVALID_U16) { allocatedTilemapBuffer = AllocZeroed(attrib); if (allocatedTilemapBuffer == NULL) - return 0xFF; + return INVALID_U8; for (i = 0; i < attrib; ++i) allocatedTilemapBuffer[i] = 0; @@ -167,7 +167,7 @@ u16 AddWindow(const struct WindowTemplate *template) Free(gUnknown_03002F70[bgLayer]); gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; } - return 0xFF; + return INVALID_U8; } gWindows[win].tileData = allocatedTilemapBuffer; @@ -190,12 +190,12 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) for (win = 0; win < WINDOWS_MAX; ++win) { - if (gWindows[win].window.bg == 0xFF) + if (gWindows[win].window.bg == INVALID_U8) break; } if (win == WINDOWS_MAX) - return 0xFF; + return INVALID_U8; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -204,8 +204,8 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); - if (allocatedBaseBlock == -1) - return 0xFF; + if (allocatedBaseBlock == INVALID_S32) + return INVALID_U8; } gWindows[win].window = *template; @@ -609,21 +609,21 @@ u16 AddWindow8Bit(struct WindowTemplate *template) for (windowId = 0; windowId < 32; windowId++) { - if (gWindows[windowId].window.bg == 0xFF) + if (gWindows[windowId].window.bg == INVALID_U8) break; } if (windowId == WINDOWS_MAX) - return 0xFF; + return INVALID_U8; bgLayer = template->bg; if (gUnknown_03002F70[bgLayer] == 0) { u16 attribute = GetBgAttribute(bgLayer, 8); - if (attribute != 0xFFFF) + if (attribute != INVALID_U16) { s32 i; memAddress = Alloc(attribute); if (memAddress == NULL) - return 0xFF; + return INVALID_U8; 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; @@ -638,7 +638,7 @@ u16 AddWindow8Bit(struct WindowTemplate *template) Free(gUnknown_03002F70[bgLayer]); gUnknown_03002F70[bgLayer] = NULL; } - return 0xFF; + return INVALID_U8; } else { -- cgit v1.2.3 From f9ff7316d5c7277eb7482e30121388cd65f4ecfc Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Wed, 5 Dec 2018 22:31:01 +0800 Subject: Remove uses of INVALID_ defines, clean up some arrays with constants, and spaces -> tabs --- src/window.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/window.c') diff --git a/src/window.c b/src/window.c index d5b996df1..4e1a38eff 100644 --- a/src/window.c +++ b/src/window.c @@ -52,12 +52,12 @@ bool16 InitWindows(const struct WindowTemplate *templates) gWindows[i].tileData = NULL; } - for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != INVALID_U8 && i < 0x20; ++i, bgLayer = templates[i].bg) + for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].bg) { if (gUnneededFireRedVariable == 1) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, templates[i].width * templates[i].height, 0); - if (allocatedBaseBlock == INVALID_S32) + if (allocatedBaseBlock == -1) return FALSE; } @@ -65,7 +65,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) { attrib = GetBgAttribute(bgLayer, 0x8); - if (attrib != INVALID_U16) + if (attrib != 0xFFFF) { allocatedTilemapBuffer = AllocZeroed(attrib); @@ -121,12 +121,12 @@ u16 AddWindow(const struct WindowTemplate *template) for (win = 0; win < WINDOWS_MAX; ++win) { - if ((bgLayer = gWindows[win].window.bg) == INVALID_U8) + if ((bgLayer = gWindows[win].window.bg) == 0xFF) break; } if (win == WINDOWS_MAX) - return INVALID_U8; + return 0xFF; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -135,20 +135,20 @@ u16 AddWindow(const struct WindowTemplate *template) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); - if (allocatedBaseBlock == INVALID_S32) - return INVALID_U8; + if (allocatedBaseBlock == -1) + return 0xFF; } if (gUnknown_03002F70[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, 0x8); - if (attrib != INVALID_U16) + if (attrib != 0xFFFF) { allocatedTilemapBuffer = AllocZeroed(attrib); if (allocatedTilemapBuffer == NULL) - return INVALID_U8; + return 0xFF; for (i = 0; i < attrib; ++i) allocatedTilemapBuffer[i] = 0; @@ -167,7 +167,7 @@ u16 AddWindow(const struct WindowTemplate *template) Free(gUnknown_03002F70[bgLayer]); gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; } - return INVALID_U8; + return 0xFF; } gWindows[win].tileData = allocatedTilemapBuffer; @@ -190,12 +190,12 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) for (win = 0; win < WINDOWS_MAX; ++win) { - if (gWindows[win].window.bg == INVALID_U8) + if (gWindows[win].window.bg == 0xFF) break; } if (win == WINDOWS_MAX) - return INVALID_U8; + return 0xFF; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -204,8 +204,8 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) { allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); - if (allocatedBaseBlock == INVALID_S32) - return INVALID_U8; + if (allocatedBaseBlock == -1) + return 0xFF; } gWindows[win].window = *template; @@ -609,21 +609,21 @@ u16 AddWindow8Bit(struct WindowTemplate *template) for (windowId = 0; windowId < 32; windowId++) { - if (gWindows[windowId].window.bg == INVALID_U8) + if (gWindows[windowId].window.bg == 0xFF) break; } if (windowId == WINDOWS_MAX) - return INVALID_U8; + return 0xFF; bgLayer = template->bg; if (gUnknown_03002F70[bgLayer] == 0) { u16 attribute = GetBgAttribute(bgLayer, 8); - if (attribute != INVALID_U16) + if (attribute != 0xFFFF) { s32 i; memAddress = Alloc(attribute); if (memAddress == NULL) - return INVALID_U8; + return 0xFF; 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; @@ -638,7 +638,7 @@ u16 AddWindow8Bit(struct WindowTemplate *template) Free(gUnknown_03002F70[bgLayer]); gUnknown_03002F70[bgLayer] = NULL; } - return INVALID_U8; + return 0xFF; } else { -- cgit v1.2.3