From 961ab7ccaf4d175189cd42fcddca1336f3d91bad Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Wed, 17 Oct 2018 11:28:27 +0800 Subject: Fix makefile and decompile some functions. Partial memory.c, save.c and bg_palette_buffer.c decompilation, along with some asm/ cleanup. --- src/bg_palette_buffer.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/bg_palette_buffer.c (limited to 'src/bg_palette_buffer.c') diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c new file mode 100644 index 0000000..5e078a0 --- /dev/null +++ b/src/bg_palette_buffer.c @@ -0,0 +1,102 @@ +#include "global.h" + +extern u16 gBGPaletteBuffer[512]; +extern bool8 gBGPaletteUsed[32]; + +extern void CpuCopy(void* src, void* dest, u32 size); + +/* +void InitBGPaletteBuffer(void) +{ + u16 color = 0; + u16* ptr; + u32 i; + bool8 paletteUsed; + + u8* p; + + ptr = gUnknown_20251F0; + + i = 0x80; + i <<= 2; + + do { + *ptr++ = color; + i--; + } while (i); + + paletteUsed = TRUE; + + p = gUnknown_20251D0; + p += 31; + + do + *p-- = paletteUsed; + while ((s32) p >= (s32) &gUnknown_20251D0); +} +void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a3, u8 *a4) +{ + if (a3 < 0) { + a3 = 0; + } + if (a3 > 31) { + a3 = 31; + } + gBGPaletteUsed[index / 16] = 1; + if (!a4) { + gBGPaletteBuffer[index] = ((RGBArray[2] * a3 / 256 & 0x1F) << 10) | ((RGBArray[1] * a3 / 256 & 0x1F) << 5) | (RGBArray[0] * a3 / 256 & 0x1F); + } + else + { + gBGPaletteBuffer[index] = ((a4[4 * RGBArray[2] + 2] * a3 / 256 & 0x1F) << 10) | ((a4[4 * RGBArray[1] + 1] * a3 / 256 & 0x1F) << 5) | (a4[4 * RGBArray[0]] * a3 / 256 & 0x1F); + } +} +*/ + +void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray) +{ + gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteBuffer[index] = (colorArray[2] >> 3) << 10 | (colorArray[1] >> 3) << 5 | colorArray[0] >> 3; +} + +void SetBGPaletteBufferColor(s32 index, u16 *color) +{ + gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteBuffer[index] = *color; +} + +void nullsub_4() +{ + +} +void nullsub_5(void) +{ + +} +void nullsub_143(void) +{ + +} + +void TransferBGPaletteBuffer(void) +{ + u32 i; + s32 paletteBufferIndex; + u16 *dest; + + i = 0; + paletteBufferIndex = 0; + dest = (u16 *)PLTT; + do + { + if (gBGPaletteUsed[i]) + { + gBGPaletteUsed[i] = 0; + CpuCopy(dest, &gBGPaletteBuffer[paletteBufferIndex], sizeof(u16) * 16); + } + ++i; + dest += 16; + paletteBufferIndex += 16; + } + while ( paletteBufferIndex < 512 ); +} \ No newline at end of file -- cgit v1.2.3 From f4ef62bb4134498a4b4a9c4d61b99bda24c98680 Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Sun, 18 Nov 2018 16:23:57 +0800 Subject: Renamed primary heap variables and partial cleanup m4a.s --- src/bg_palette_buffer.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/bg_palette_buffer.c') diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c index 5e078a0..6301bfa 100644 --- a/src/bg_palette_buffer.c +++ b/src/bg_palette_buffer.c @@ -1,7 +1,10 @@ #include "global.h" -extern u16 gBGPaletteBuffer[512]; -extern bool8 gBGPaletteUsed[32]; +#define BG_PALETTE_BUFFER_SIZE 512 +#define BG_PALETTE_BUFFER_CHUNK_SIZE 16 + +extern u16 gBGPaletteBuffer[BG_PALETTE_BUFFER_SIZE]; +extern bool8 gBGPaletteUsed[BG_PALETTE_BUFFER_SIZE / BG_PALETTE_BUFFER_CHUNK_SIZE]; extern void CpuCopy(void* src, void* dest, u32 size); @@ -55,13 +58,13 @@ void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a3, u8 *a4) void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray) { - gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE; gBGPaletteBuffer[index] = (colorArray[2] >> 3) << 10 | (colorArray[1] >> 3) << 5 | colorArray[0] >> 3; } void SetBGPaletteBufferColor(s32 index, u16 *color) { - gBGPaletteUsed[index / 16] = TRUE; + gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE; gBGPaletteBuffer[index] = *color; } @@ -98,5 +101,5 @@ void TransferBGPaletteBuffer(void) dest += 16; paletteBufferIndex += 16; } - while ( paletteBufferIndex < 512 ); -} \ No newline at end of file + while ( paletteBufferIndex < BG_PALETTE_BUFFER_SIZE ); +} -- cgit v1.2.3 From c7045ae3694f677b634f3908c1ea935c2998727e Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Tue, 20 Nov 2018 13:17:30 +0800 Subject: Identify, split, decompile m4a, and more ResetSprites, gCharMemCursor, gSpriteCount; analysed subheaps; identified more file pointers --- src/bg_palette_buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/bg_palette_buffer.c') diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c index 6301bfa..e36176d 100644 --- a/src/bg_palette_buffer.c +++ b/src/bg_palette_buffer.c @@ -18,7 +18,7 @@ void InitBGPaletteBuffer(void) u8* p; - ptr = gUnknown_20251F0; + ptr = gBGPaletteBuffer; i = 0x80; i <<= 2; @@ -30,12 +30,12 @@ void InitBGPaletteBuffer(void) paletteUsed = TRUE; - p = gUnknown_20251D0; + p = gBGPaletteUsed; p += 31; do *p-- = paletteUsed; - while ((s32) p >= (s32) &gUnknown_20251D0); + while ((s32) p >= (s32) &gBGPaletteUsed); } void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a3, u8 *a4) { -- cgit v1.2.3 From a611b9673e73eeb74af802250d9fee5157f76a20 Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Wed, 21 Nov 2018 18:48:01 +0800 Subject: "Finish" decompiling bg_palette_buffer.s and m4a_2.s, and rename text variables We all have our breaking points :matchlikethis: --- src/bg_palette_buffer.c | 165 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 154 insertions(+), 11 deletions(-) (limited to 'src/bg_palette_buffer.c') diff --git a/src/bg_palette_buffer.c b/src/bg_palette_buffer.c index e36176d..9917adf 100644 --- a/src/bg_palette_buffer.c +++ b/src/bg_palette_buffer.c @@ -8,9 +8,12 @@ extern bool8 gBGPaletteUsed[BG_PALETTE_BUFFER_SIZE / BG_PALETTE_BUFFER_CHUNK_SIZ extern void CpuCopy(void* src, void* dest, u32 size); -/* +#ifndef NONMATCHING +NAKED +#endif void InitBGPaletteBuffer(void) { +#ifdef NONMATCHING u16 color = 0; u16* ptr; u32 i; @@ -36,25 +39,165 @@ void InitBGPaletteBuffer(void) do *p-- = paletteUsed; while ((s32) p >= (s32) &gBGPaletteUsed); +#else + asm_unified("\tpush {lr}\n" + "\tmovs r2, 0\n" + "\tldr r1, =gBGPaletteBuffer\n" + "\tmovs r0, 0x80\n" + "\tlsls r0, 2\n" + "_0800463E:\n" + "\tstrh r2, [r1]\n" + "\tadds r1, 0x2\n" + "\tsubs r0, 0x1\n" + "\tcmp r0, 0\n" + "\tbne _0800463E\n" + "\tldr r1, =gBGPaletteUsed\n" + "\tmovs r2, 0x1\n" + "\tadds r0, r1, 0\n" + "\tadds r0, 0x1F\n" + "_08004650:\n" + "\tstrb r2, [r0]\n" + "\tsubs r0, 0x1\n" + "\tcmp r0, r1\n" + "\tbge _08004650\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" + "\t.pool"); +#endif } -void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a3, u8 *a4) + +#ifndef NONMATCHING +NAKED +#endif +void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a1, u8 *a2) { - if (a3 < 0) { - a3 = 0; +#ifdef NONMATCHING + if (a1 < 0) { + a1 = 0; } - if (a3 > 31) { - a3 = 31; + if (a1 > 31) { + a1 = 31; } gBGPaletteUsed[index / 16] = 1; - if (!a4) { - gBGPaletteBuffer[index] = ((RGBArray[2] * a3 / 256 & 0x1F) << 10) | ((RGBArray[1] * a3 / 256 & 0x1F) << 5) | (RGBArray[0] * a3 / 256 & 0x1F); + if (!a2) { + gBGPaletteBuffer[index] = ((RGBArray[2] * a1 / 256 & 0x1F) << 10) | ((RGBArray[1] * a1 / 256 & 0x1F) << 5) | (RGBArray[0] * a1 / 256 & 0x1F); } else { - gBGPaletteBuffer[index] = ((a4[4 * RGBArray[2] + 2] * a3 / 256 & 0x1F) << 10) | ((a4[4 * RGBArray[1] + 1] * a3 / 256 & 0x1F) << 5) | (a4[4 * RGBArray[0]] * a3 / 256 & 0x1F); + gBGPaletteBuffer[index] = ((a2[4 * RGBArray[2] + 2] * a1 / 256 & 0x1F) << 10) | ((a2[4 * RGBArray[1] + 1] * a1 / 256 & 0x1F) << 5) | (a2[4 * RGBArray[0]] * a1 / 256 & 0x1F); } +#else + asm_unified("\tpush {r4-r7,lr}\n" + "\tadds r4, r0, 0\n" + "\tadds r5, r1, 0\n" + "\tcmp r2, 0\n" + "\tbge _08004670\n" + "\tmovs r2, 0\n" + "_08004670:\n" + "\tcmp r2, 0x1F\n" + "\tble _08004676\n" + "\tmovs r2, 0x1F\n" + "_08004676:\n" + "\tldr r1, =gBGPaletteUsed\n" + "\tadds r0, r4, 0\n" + "\tcmp r4, 0\n" + "\tbge _08004680\n" + "\tadds r0, 0xF\n" + "_08004680:\n" + "\tasrs r0, 4\n" + "\tadds r0, r1\n" + "\tmovs r1, 0x1\n" + "\tstrb r1, [r0]\n" + "\tcmp r3, 0\n" + "\tbne _080046D4\n" + "\tldr r0, =gBGPaletteBuffer\n" + "\tlsls r1, r4, 1\n" + "\tadds r6, r1, r0\n" + "\tldrb r0, [r5, 0x2]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _0800469C\n" + "\tadds r0, 0xFF\n" + "_0800469C:\n" + "\tasrs r0, 8\n" + "\tmovs r3, 0x1F\n" + "\tands r0, r3\n" + "\tlsls r4, r0, 10\n" + "\tldrb r0, [r5, 0x1]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _080046AE\n" + "\tadds r0, 0xFF\n" + "_080046AE:\n" + "\tasrs r0, 8\n" + "\tands r0, r3\n" + "\tlsls r1, r0, 5\n" + "\torrs r1, r4\n" + "\tldrb r0, [r5]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _080046C0\n" + "\tadds r0, 0xFF\n" + "_080046C0:\n" + "\tasrs r0, 8\n" + "\tands r0, r3\n" + "\torrs r1, r0\n" + "\tstrh r1, [r6]\n" + "\tb _08004722\n" + "\t.align 2, 0\n" + "\t.pool\n" + "_080046D4:\n" + "\tldr r1, =gBGPaletteBuffer\n" + "\tlsls r0, r4, 1\n" + "\tadds r7, r0, r1\n" + "\tldrb r0, [r5, 0x2]\n" + "\tlsls r0, 2\n" + "\tadds r0, r3\n" + "\tldrb r0, [r0, 0x2]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _080046EA\n" + "\tadds r0, 0xFF\n" + "_080046EA:\n" + "\tasrs r0, 8\n" + "\tmovs r4, 0x1F\n" + "\tands r0, r4\n" + "\tlsls r6, r0, 10\n" + "\tldrb r0, [r5, 0x1]\n" + "\tlsls r0, 2\n" + "\tadds r0, r3\n" + "\tldrb r0, [r0, 0x1]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _08004702\n" + "\tadds r0, 0xFF\n" + "_08004702:\n" + "\tasrs r0, 8\n" + "\tands r0, r4\n" + "\tlsls r1, r0, 5\n" + "\torrs r1, r6\n" + "\tldrb r0, [r5]\n" + "\tlsls r0, 2\n" + "\tadds r0, r3\n" + "\tldrb r0, [r0]\n" + "\tmuls r0, r2\n" + "\tcmp r0, 0\n" + "\tbge _0800471A\n" + "\tadds r0, 0xFF\n" + "_0800471A:\n" + "\tasrs r0, 8\n" + "\tands r0, r4\n" + "\torrs r1, r0\n" + "\tstrh r1, [r7]\n" + "_08004722:\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.align 2, 0\n" + "\t.pool"); +#endif } -*/ void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray) { @@ -68,7 +211,7 @@ void SetBGPaletteBufferColor(s32 index, u16 *color) gBGPaletteBuffer[index] = *color; } -void nullsub_4() +void nullsub_4(void) { } -- cgit v1.2.3