summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTal Hayon <talhayon1@gmail.com>2022-01-25 00:52:18 +0200
committerTal Hayon <talhayon1@gmail.com>2022-01-25 00:52:18 +0200
commit6a10dfe491ce25bd9d434fab4082f1db3c666d1c (patch)
treeab12b2689ea02b500556887cda470d06b909e99f
parent97164d57cdbab0455d110cf811d6ae5254ceb871 (diff)
Match FindPalette
-rw-r--r--asm/non_matching/color/FindPalette.inc28
-rw-r--r--src/color.c15
2 files changed, 14 insertions, 29 deletions
diff --git a/asm/non_matching/color/FindPalette.inc b/asm/non_matching/color/FindPalette.inc
deleted file mode 100644
index c21b6db3..00000000
--- a/asm/non_matching/color/FindPalette.inc
+++ /dev/null
@@ -1,28 +0,0 @@
- .syntax unified
- push {lr}
- adds r2, r0, #0
- cmp r2, #5
- bhi _0801D116
- b _0801D12E
-_0801D112:
- adds r0, r1, #0
- b _0801D12E
-_0801D116:
- movs r1, #6
- ldr r0, _0801D130 @ =gPaletteList
- adds r0, #0x18
-_0801D11C:
- ldrh r3, [r0, #2]
- cmp r2, r3
- beq _0801D112
- adds r0, #4
- adds r1, #1
- cmp r1, #0xf
- bls _0801D11C
- movs r0, #1
- rsbs r0, r0, #0
-_0801D12E:
- pop {pc}
- .align 2, 0
-_0801D130: .4byte gPaletteList
- .syntax divided
diff --git a/src/color.c b/src/color.c
index 55671ee3..557cda39 100644
--- a/src/color.c
+++ b/src/color.c
@@ -29,7 +29,20 @@ ASM_FUNC("asm/non_matching/color/sub_0801D000.inc", void sub_0801D000(u32 a1));
ASM_FUNC("asm/non_matching/color/LoadObjPalette.inc", u32 LoadObjPalette(Entity* entity, u32 a2));
-ASM_FUNC("asm/non_matching/color/FindPalette.inc", s32 FindPalette(u32 a1));
+s32 FindPalette(u32 a1) {
+ u32 index;
+ Palette* palette;
+ if (a1 <= 5)
+ return a1;
+
+ for (index = 6, palette = gPaletteList; index < 0x10; index++) {
+ if (a1 == palette[index]._2) {
+ return index;
+ }
+ }
+
+ return -1;
+}
ASM_FUNC("asm/non_matching/color/FindFreeObjPalette.inc", u32 FindFreeObjPalette(u32 a1));