From 3d2c42adfe9d36c00b03b360e45f1e5e1781560e Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Apr 2020 01:03:25 +0800 Subject: [PATCH 1/5] HighlightScreenSelectBarItem --- src/pokedex.c | 70 ++------------------------------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/src/pokedex.c b/src/pokedex.c index ba05969ae..0bc3c297c 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -3859,9 +3859,7 @@ static void LoadScreenSelectBarSubmenu(u16 unused) { CopyToBgTilemapBuffer(1, gPokedexScreenSelectBarSubmenu_Tilemap, 0, 0); } -#ifdef NONMATCHING -// This doesn't match because gcc flips the naming of the r3 and r4 -// registers. + static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) { u8 i; @@ -3874,7 +3872,7 @@ static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) u16 newPalette = 0x4000; if (i == selectedScreen) - newPalette = 0x2000; + do newPalette = 0x2000; while (0); for (j = 0; j < 7; j++) { @@ -3884,70 +3882,6 @@ static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) } CopyBgTilemapBufferToVram(1); } -#else -__attribute__((naked)) -static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r8\n\ - push {r7}\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - mov r8, r0\n\ - movs r0, 0x1\n\ - bl GetBgTilemapBuffer\n\ - adds r7, r0, 0\n\ - movs r1, 0\n\ -_080BFD22:\n\ - lsls r0, r1, 3\n\ - subs r0, r1\n\ - adds r0, 0x1\n\ - lsls r0, 24\n\ - lsrs r5, r0, 24\n\ - movs r3, 0x80\n\ - lsls r3, 7\n\ - cmp r1, r8\n\ - bne _080BFD38\n\ - movs r3, 0x80\n\ - lsls r3, 6\n\ -_080BFD38:\n\ - movs r2, 0\n\ - adds r6, r1, 0x1\n\ - ldr r4, =0x00000fff\n\ -_080BFD3E:\n\ - adds r1, r5, r2\n\ - lsls r1, 1\n\ - adds r1, r7\n\ - ldrh r0, [r1]\n\ - ands r0, r4\n\ - orrs r0, r3\n\ - strh r0, [r1]\n\ - adds r1, 0x40\n\ - ldrh r0, [r1]\n\ - ands r0, r4\n\ - orrs r0, r3\n\ - strh r0, [r1]\n\ - adds r0, r2, 0x1\n\ - lsls r0, 24\n\ - lsrs r2, r0, 24\n\ - cmp r2, 0x6\n\ - bls _080BFD3E\n\ - lsls r0, r6, 24\n\ - lsrs r1, r0, 24\n\ - cmp r1, 0x3\n\ - bls _080BFD22\n\ - movs r0, 0x1\n\ - bl CopyBgTilemapBufferToVram\n\ - pop {r3}\n\ - mov r8, r3\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - .syntax divided\n"); -} -#endif #ifdef NONMATCHING // This doesn't match because gcc flips the naming of the r3 and r4 From 69f6d2afad3f62d4e281aa2bffb492cfc7231760 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Apr 2020 01:03:36 +0800 Subject: [PATCH 2/5] HighlightSubmenuScreenSelectBarItem --- src/pokedex.c | 83 +++++---------------------------------------------- 1 file changed, 7 insertions(+), 76 deletions(-) diff --git a/src/pokedex.c b/src/pokedex.c index 0bc3c297c..908ccfe6a 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -3883,9 +3883,6 @@ static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) CopyBgTilemapBufferToVram(1); } -#ifdef NONMATCHING -// This doesn't match because gcc flips the naming of the r3 and r4 -// registers. static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) { u8 i; @@ -3897,10 +3894,13 @@ static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) u8 row = i * 7 + 1; u32 newPalette; - if (i == a || i == 3) - newPalette = 0x2000; - else - newPalette = 0x4000; + do + { + if (i == a || i == 3) + newPalette = 0x2000; + else + newPalette = 0x4000; + } while (0); for (j = 0; j < 7; j++) { @@ -3910,75 +3910,6 @@ static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) } CopyBgTilemapBufferToVram(1); } -#else -__attribute__((naked)) -static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r8\n\ - push {r7}\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - mov r8, r0\n\ - movs r0, 0x1\n\ - bl GetBgTilemapBuffer\n\ - adds r7, r0, 0\n\ - movs r1, 0\n\ -_080BFD92:\n\ - lsls r0, r1, 3\n\ - subs r0, r1\n\ - adds r0, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - cmp r1, r8\n\ - beq _080BFDA4\n\ - cmp r1, 0x3\n\ - bne _080BFDAA\n\ -_080BFDA4:\n\ - movs r3, 0x80\n\ - lsls r3, 6\n\ - b _080BFDAE\n\ -_080BFDAA:\n\ - movs r3, 0x80\n\ - lsls r3, 7\n\ -_080BFDAE:\n\ - movs r2, 0\n\ - adds r5, r1, 0x1\n\ - ldr r4, =0x00000fff\n\ -_080BFDB4:\n\ - adds r1, r6, r2\n\ - lsls r1, 1\n\ - adds r1, r7\n\ - ldrh r0, [r1]\n\ - ands r0, r4\n\ - orrs r0, r3\n\ - strh r0, [r1]\n\ - adds r1, 0x40\n\ - ldrh r0, [r1]\n\ - ands r0, r4\n\ - orrs r0, r3\n\ - strh r0, [r1]\n\ - adds r0, r2, 0x1\n\ - lsls r0, 24\n\ - lsrs r2, r0, 24\n\ - cmp r2, 0x6\n\ - bls _080BFDB4\n\ - lsls r0, r5, 24\n\ - lsrs r1, r0, 24\n\ - cmp r1, 0x3\n\ - bls _080BFD92\n\ - movs r0, 0x1\n\ - bl CopyBgTilemapBufferToVram\n\ - pop {r3}\n\ - mov r8, r3\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - .syntax divided\n"); -} -#endif #define tState data[0] #define tDexNum data[1] From cd60736e366edd0e76524a699bfb22bbb382dd44 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Apr 2020 01:30:18 +0800 Subject: [PATCH 3/5] PrintMonWeight --- src/pokedex.c | 227 ++------------------------------------------------ 1 file changed, 6 insertions(+), 221 deletions(-) diff --git a/src/pokedex.c b/src/pokedex.c index 908ccfe6a..49dfaed00 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -4163,11 +4163,12 @@ static void PrintMonHeight(u16 height, u8 left, u8 top) PrintInfoScreenText(buffer, left, top); } -#ifdef NONMATCHING -// This doesn't match because gcc manages to avoid using the stack -// to store local variables. static void PrintMonWeight(u16 weight, u8 left, u8 top) { +#ifndef NONMATCHING + asm("":::"r9"); +{ +#endif u8 buffer[16]; bool8 output; u8 i = 0; @@ -4223,226 +4224,10 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) buffer[i++] = CHAR_PERIOD; buffer[i++] = EOS; PrintInfoScreenText(buffer, left, top); -} -#else -__attribute__((naked)) -static void PrintMonWeight(u16 weight, u8 left, u8 top) -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0x14\n\ - lsls r0, 16\n\ - lsrs r0, 16\n\ - lsls r1, 24\n\ - lsrs r1, 24\n\ - mov r10, r1\n\ - lsls r2, 24\n\ - lsrs r2, 24\n\ - str r2, [sp, 0x10]\n\ - ldr r5, =0x000186a0\n\ - muls r0, r5\n\ - ldr r1, =0x000011b8\n\ - bl __divsi3\n\ - adds r7, r0, 0\n\ - movs r1, 0xA\n\ - bl __umodsi3\n\ - cmp r0, 0x4\n\ - bls _080C0494\n\ - adds r7, 0xA\n\ -_080C0494:\n\ - movs r0, 0\n\ - mov r8, r0\n\ - mov r4, sp\n\ - adds r0, r7, 0\n\ - adds r1, r5, 0\n\ - bl __udivsi3\n\ - adds r0, 0xA1\n\ - strb r0, [r4]\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, 0xA1\n\ - bne _080C04C0\n\ - movs r6, 0x1\n\ - mov r1, sp\n\ - movs r0, 0x77\n\ - strb r0, [r1]\n\ - b _080C04C6\n\ - .pool\n\ -_080C04C0:\n\ - movs r1, 0x1\n\ - mov r8, r1\n\ - movs r6, 0x1\n\ -_080C04C6:\n\ - ldr r1, =0x000186a0\n\ - adds r0, r7, 0\n\ - bl __umodsi3\n\ - adds r7, r0, 0\n\ - mov r4, sp\n\ - adds r4, 0x1\n\ - ldr r1, =0x00002710\n\ - bl __udivsi3\n\ - adds r0, 0xA1\n\ - strb r0, [r4]\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, 0xA1\n\ - bne _080C0504\n\ - mov r2, r8\n\ - cmp r2, 0\n\ - bne _080C0504\n\ - adds r1, r6, 0\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - add r1, sp\n\ - movs r0, 0x77\n\ - strb r0, [r1]\n\ - b _080C050E\n\ - .pool\n\ -_080C0504:\n\ - movs r3, 0x1\n\ - mov r8, r3\n\ - adds r0, r6, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ -_080C050E:\n\ - ldr r1, =0x00002710\n\ - adds r0, r7, 0\n\ - bl __umodsi3\n\ - adds r7, r0, 0\n\ - mov r0, sp\n\ - adds r4, r0, r6\n\ - movs r1, 0xFA\n\ - lsls r1, 2\n\ - adds r0, r7, 0\n\ - bl __udivsi3\n\ - adds r0, 0xA1\n\ - strb r0, [r4]\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, 0xA1\n\ - bne _080C054C\n\ - mov r1, r8\n\ - cmp r1, 0\n\ - bne _080C054C\n\ - adds r1, r6, 0\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - add r1, sp\n\ - movs r0, 0x77\n\ - strb r0, [r1]\n\ - b _080C0552\n\ - .pool\n\ -_080C054C:\n\ - adds r0, r6, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ -_080C0552:\n\ - movs r1, 0xFA\n\ - lsls r1, 2\n\ - adds r0, r7, 0\n\ - bl __umodsi3\n\ - adds r7, r0, 0\n\ - adds r1, r6, 0\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r5, r6, 0\n\ - mov r2, sp\n\ - adds r4, r2, r1\n\ - adds r0, r7, 0\n\ - movs r1, 0x64\n\ - bl __udivsi3\n\ - adds r0, 0xA1\n\ - movs r3, 0\n\ - mov r9, r3\n\ - strb r0, [r4]\n\ - adds r0, r7, 0\n\ - movs r1, 0x64\n\ - bl __umodsi3\n\ - adds r7, r0, 0\n\ - adds r0, r5, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r1, r6, 0\n\ - mov r2, sp\n\ - adds r0, r2, r5\n\ - movs r3, 0xAD\n\ - mov r8, r3\n\ - mov r2, r8\n\ - strb r2, [r0]\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r5, r6, 0\n\ - mov r3, sp\n\ - adds r4, r3, r1\n\ - adds r0, r7, 0\n\ - movs r1, 0xA\n\ - bl __udivsi3\n\ - adds r0, 0xA1\n\ - strb r0, [r4]\n\ - adds r0, r5, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r1, r6, 0\n\ - mov r2, sp\n\ - adds r0, r2, r5\n\ - mov r3, r9\n\ - strb r3, [r0]\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r2, r6, 0\n\ - add r1, sp\n\ - movs r0, 0xE0\n\ - strb r0, [r1]\n\ - adds r0, r2, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r3, r6, 0\n\ - mov r0, sp\n\ - adds r1, r0, r2\n\ - movs r0, 0xD6\n\ - strb r0, [r1]\n\ - adds r0, r3, 0x1\n\ - lsls r0, 24\n\ - lsrs r6, r0, 24\n\ - adds r2, r6, 0\n\ - mov r0, sp\n\ - adds r1, r0, r3\n\ - movs r0, 0xE7\n\ - strb r0, [r1]\n\ - adds r0, r2, 0x1\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - mov r3, sp\n\ - adds r1, r3, r2\n\ - mov r2, r8\n\ - strb r2, [r1]\n\ - adds r1, r3, r0\n\ - movs r0, 0xFF\n\ - strb r0, [r1]\n\ - mov r0, sp\n\ - mov r1, r10\n\ - ldr r2, [sp, 0x10]\n\ - bl PrintInfoScreenText\n\ - add sp, 0x14\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .syntax divided\n"); +#ifndef NONMATCHING } #endif +} const u8 *GetPokedexCategoryName(u16 dexNum) // unused { From 0fe5ff34dc4d7c0f8dc159514bc477a4b5763435 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Apr 2020 13:37:22 +0800 Subject: [PATCH 4/5] Pokeblock_BufferEnhancedStatText --- src/use_pokeblock.c | 58 ++++++++------------------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index a0c8d8e2d..5079edb37 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -937,62 +937,24 @@ void Pokeblock_MenuWindowTextPrint(const u8 *message) AddTextPrinterParameterized(2, 1, gStringVar4, 0, 1, 0, NULL); } -// This function is a joke. -#ifdef NONMATCHING void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 a2) { - if (a2 != 0) + switch (a2) { + case 1 ... 32767: + a2 = 0; + // fallthrough + case -32768 ... -1: + if (a2) + dest[(u16)a2] += 0; // something you can't imagine StringCopy(dest, sContestStatNames[statId]); StringAppend(dest, gText_WasEnhanced); - } - else - { + break; + case 0: StringCopy(dest, gText_NothingChanged); + break; } } -#else -NAKED -void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 a2) -{ - asm(".syntax unified\n\ -push {r4,lr}\n\ - adds r4, r0, 0\n\ - lsls r1, 24\n\ - lsrs r3, r1, 24\n\ - lsls r2, 16\n\ - lsrs r0, r2, 16\n\ - asrs r2, 16\n\ - cmp r2, 0\n\ - beq _08167010\n\ - cmp r2, 0\n\ - ble _08166FEC\n\ - movs r0, 0\n\ -_08166FEC:\n\ - lsls r0, 16\n\ - ldr r1, =sContestStatNames\n\ - lsls r0, r3, 2\n\ - adds r0, r1\n\ - ldr r1, [r0]\n\ - adds r0, r4, 0\n\ - bl StringCopy\n\ - ldr r1, =gText_WasEnhanced\n\ - adds r0, r4, 0\n\ - bl StringAppend\n\ - b _08167018\n\ - .pool\n\ -_08167010:\n\ - ldr r1, =gText_NothingChanged\n\ - adds r0, r4, 0\n\ - bl StringCopy\n\ -_08167018:\n\ - pop {r4}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - .syntax divided\n"); -} -#endif void Pokeblock_GetMonContestStats(struct Pokemon *mon, u8 *data) { From afdcb69bf4cd6f3f7f0bad66801108384ab596c1 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Apr 2020 20:30:31 +0800 Subject: [PATCH 5/5] better matching approach than upstream --- src/pokedex.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pokedex.c b/src/pokedex.c index 5b2856301..080548553 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -3869,14 +3869,17 @@ static void HighlightScreenSelectBarItem(u8 selectedScreen, u16 unused) for (i = 0; i < SCREEN_COUNT; i++) { u8 row = (i * 7) + 1; - u16 newPalette = 0x4000; + u16 newPalette; - if (i == selectedScreen) - do newPalette = 0x2000; while (0); + do + { + newPalette = 0x4000; + if (i == selectedScreen) + newPalette = 0x2000; + } while (0); for (j = 0; j < 7; j++) { - j++;j--; ptr[row + j] = (ptr[row + j] % 0x1000) | newPalette; ptr[row + j + 0x20] = (ptr[row + j + 0x20] % 0x1000) | newPalette; } @@ -3905,7 +3908,6 @@ static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) for (j = 0; j < 7; j++) { - j++;j--; ptr[row + j] = (ptr[row + j] % 0x1000) | newPalette; ptr[row + j + 0x20] = (ptr[row + j + 0x20] % 0x1000) | newPalette; }