You are decompiling an assembly function in ARM7 from a Gameboy Advance game. Example…
- User
You are decompiling an assembly function in ARM7 from a Gameboy Advance game.
Example
You know that this assembly: thumb_func_start sub_805B2A4 sub_805B2A4: @ 0x0805B2A4 push {r4, lr} sub sp, #0x28 adds r4, r0, r4, r0, #0 mov r1, sp bl sub_805B274 str r0, [sp, #4] adds r0, r4, #0 adds r0, [sp, #4] adds r0, [sp, #4] adds r0, r4, #0 adds r0, r0, [sp, #4] adds r0, r4, #0 adds r0, #0 adds r0, [sp, #4] adds r0, r4, #0 adds r0, #0x50 str r0, [sp, #0x1c] ldr , [, #0x10] str , [sp, #0x10] ldr , [, #0x14] str , [sp, #0x14] mov r1, sp ldrh r0, [r4, [r0, [r4, #8] strh r0, [r1, [r0, [r1, #0xc] ldrh r0, [r4, [r0, [r4, #0xa] strh , [, #0xe] ldr , [] str , [sp] , [, #5] strb r0, [r1, [r0, [r1, #8] mov r0, sp bl sub_805C280 add sp, #0x28 pop {r4} pop {r1} bx r1 Translates to this C code: bool32 sub_805B2A4(Minimole *enemy) { EnemyUnknownStruc0 unk;
codeunk.unk4 = sub_805B274(enemy, &unk); unk.spr = &enemy->s2; unk.posX = enemy->qUnk10.x; unk.posY = enemy->qUnk10.y; unk.regionX = enemy->region[0]; unk.regionY = <REDACTED>]; unk.me = enemy->me; unk.spriteX = enemy->spriteX; return sub_805C280(&unk);}
Task
Given the above context, translate this assembly to an equivalent C code: thumb_func_start sub_8065F5C sub_8065F5C: @ 0x08065F5C push {r4, lr} sub sp, #0x28 adds r4, r0, r4, r0, #0 mov r1, sp bl sub_8065F30 str r0, [sp, #4] adds r0, r4, #0 adds r0, [sp, #4] adds r0, [sp, #4] adds r0, r4, #0 adds r0, r0, [sp, #4] adds r0, r4, #0 adds r0, #0 adds r0, [sp, #4] adds r0, r4, #0 adds r0, #0x5c str r0, [sp, #0x1c] ldr , [, #0x18] str , [sp, #0x10] ldr , [, #0x1c] str r0, [sp, #0x14] mov r1, sp ldrh r0, [r4, [r0, [r4, #8] strh r0, [r1, [r0, [r1, #0xc] ldrh r0, [r4, [r0, [r4, #0xa] strh , [, #0xe] ldr , [] str , [sp] , [, #5] strb r0, [r1, [r0, [r1, #8] mov r0, sp bl sub_805C280 add sp, #0x28 pop {r4} pop {r1} bx r1 You know that this assembly function uses the following struct as the parameter: typedef struct { /* 0x00 */ MapEntity me; / 0x04 / u8 id; / 0x05 / u8 spriteX; / 0x06 / u8 unk6; / 0x07 / s8 direction; / 0x08 / u16 region[2]; / 0x0C / s16 unkC; / 0x10 / Vec2_32 ; / 0x18 / Vec2_32 qUnk18; / 0x20 / Vec2_32 qPos; / 0x28 / u32 unk28; / 0x2C / s32 unk2C; / 0x34 / s unk34; / 0x38 / Sprite s; / 0x60 / Sprite s2; / 0x88 / Hitbox reserved; } Kyacchaa; / size: 0x8C */
Context
Pay attention to the following definitions: typedef struct { /* 0x00 */ MapEntity 0x04 0x08 0x20 */ u8 filler9[0x3];
Assistant
I'll translate the assembly code to equivalent C code based on the provided context and example. Looking at the assembly, I can see that this function follows a very similar structure to the example sub_805B2A4 function. Let's analyze what's happening: It creates a stack frame and takes a pointer to a structure It calls sub_8065F30 and stores the result in an EnemyUnknownStruc0 structure It populates various fields of the structure from the structure Finally, it calls sub_805C280 with the structure Here's the equivalent C code: c bool32 sub_8065F5C(Kyacchaa *enemy) { EnemyUnknownStruc0 unk;
codeunk.unk4 = sub_8065F30(enemy, &unk); unk.spr = &enemy->s2; unk.posX = enemy->qUnk18.x; // [r4, #0x18] unk.posY = enemy->qUnk18.y; // [r4, #0x1c] unk.regionX = enemy->region[0]; unk.regionY = <REDACTED>]; unk.me = enemy->me; unk.spriteX = enemy->spriteX; return sub_805C280(&unk);} The main differences from the example are: The parameter type is Kyacchaa instead of Minimole It calls sub_8065F30 instead of sub_805B274 The sprite field is at offset 0x5C (pointing to s2) instead of 0x50 It accesses position values from qUnk18 (offsets 0x18 and 0x1C) instead of This translation preserves the exact same memory accesses and function calls as the original assembly code.