first pokeathlon function

This commit is contained in:
NathanFallet 2025-11-03 21:11:07 +01:00
parent f1ad0903e3
commit c3124406a2
6 changed files with 198 additions and 143 deletions

View File

@ -4,147 +4,6 @@
.text
thumb_func_start PokeathlonCourse_Init
PokeathlonCourse_Init: ; 0x021E5900
push {r3, r4, r5, r6, lr}
sub sp, #0x14
mov r2, #0x72
add r5, r0, #0
mov r0, #3
mov r1, #0x5c
lsl r2, r2, #0xc
bl Heap_Create
mov r1, #0xd7
add r0, r5, #0
lsl r1, r1, #4
mov r2, #0x5c
bl OverlayManager_CreateAndGetData
mov r2, #0xd7
mov r1, #0
lsl r2, r2, #4
add r4, r0, #0
bl MI_CpuFill8
mov r0, #0xa1
mov r1, #0x5c
lsl r0, r0, #2
str r1, [r4, r0]
add r0, r5, #0
bl OverlayManager_GetArgs
mov r2, #0x7e
lsl r2, r2, #2
add r5, sp, #4
ldr r6, _021E5A28 ; =ov96_0221A7E4
str r0, [r4, r2]
add r3, r5, #0
ldmia r6!, {r0, r1}
stmia r5!, {r0, r1}
ldmia r6!, {r0, r1}
stmia r5!, {r0, r1}
add r1, r4, r2
add r0, r3, #0
mov r2, #0x5c
bl OverlayManager_New
mov r1, #0xa
lsl r1, r1, #6
str r0, [r4, r1]
add r0, r1, #0
mov r5, #0
sub r0, #0xa0
str r5, [r4, r0]
add r0, r1, #0
sub r0, #0x88
ldr r0, [r4, r0]
ldr r0, [r0, #4]
cmp r0, #1
bne _021E597E
mov r5, #1
bl sub_02037454
ldr r1, _021E5A2C ; =0x000001EE
strb r0, [r4, r1]
mov r1, #4
b _021E5986
_021E597E:
mov r0, #1
sub r1, #0x92
strb r0, [r4, r1]
mov r1, #3
_021E5986:
ldr r0, _021E5A30 ; =0x0000072A
strb r1, [r4, r0]
bl ov96_021E8A24
add r6, r0, #0
bl ov96_021E8A2C
add r1, r0, #0
mov r0, #0xa1
lsl r0, r0, #2
ldr r0, [r4, r0]
add r2, r4, #0
str r0, [sp]
add r0, r6, #0
add r3, r5, #0
bl ov96_021E8770
mov r1, #0xa2
lsl r1, r1, #2
str r0, [r4, r1]
mov r1, #0xf1
lsl r1, r1, #2
ldr r0, _021E5A34 ; =ov96_0221A984
add r1, r4, r1
bl ov96_021E5C80
ldr r1, _021E5A38 ; =0x000003CA
mov r3, #0
sub r0, r1, #6
add r2, r4, r0
add r0, r1, #0
strb r3, [r4, r1]
sub r0, #0x16
str r2, [r4, r0]
sub r1, #0xa
add r0, r4, #0
str r3, [r4, r1]
bl ov96_021E5C90
mov r0, #0x5c
bl ov96_021E92E0
ldr r1, _021E5A3C ; =0x00000614
str r0, [r4, r1]
mov r0, #0x7e
lsl r0, r0, #2
ldr r0, [r4, r0]
ldr r0, [r0, #4]
cmp r0, #1
beq _021E59FE
mov r0, #1
bl TextFlags_SetCanABSpeedUpPrint
mov r0, #0
bl TextFlags_SetAutoScrollParam
mov r0, #1
bl TextFlags_SetCanTouchSpeedUpPrint
b _021E5A10
_021E59FE:
mov r0, #0
bl TextFlags_SetCanABSpeedUpPrint
mov r0, #1
bl TextFlags_SetAutoScrollParam
mov r0, #0
bl TextFlags_SetCanTouchSpeedUpPrint
_021E5A10:
add r0, r4, #0
mov r1, #0
bl ov96_021E5DFC
add r0, r4, #0
mov r1, #0
bl ov96_021E5DE0
mov r0, #1
add sp, #0x14
pop {r3, r4, r5, r6, pc}
nop
_021E5A28: .word ov96_0221A7E4
_021E5A2C: .word 0x000001EE
_021E5A30: .word 0x0000072A
_021E5A34: .word ov96_0221A984
_021E5A38: .word 0x000003CA
_021E5A3C: .word 0x00000614
thumb_func_end PokeathlonCourse_Init
thumb_func_start PokeathlonCourse_Main
PokeathlonCourse_Main: ; 0x021E5A40
@ -108361,6 +108220,7 @@ _0221A7D8:
.byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.word 0
.global ov96_0221A7E4
ov96_0221A7E4: ; 0x0221A7E4
.word ov97_0221E5C0
.word ov97_0221E5D4
@ -108487,6 +108347,7 @@ ov96_0221A95C: ; 0x0221A95C
.byte 0x01, 0x02, 0x09, 0x04, 0x02, 0x06, 0x05, 0x03, 0x00, 0x07, 0x03, 0x09, 0x09, 0x08, 0x04, 0x01
.byte 0x06, 0x03, 0x07, 0x00
.global ov96_0221A984
ov96_0221A984: ; 0x0221A984
.word ov96_021E67C4
.word ov96_021E6814

View File

@ -31,7 +31,7 @@
#include "overlay_73.h"
#include "overlay_86.h"
#include "overlay_87.h"
#include "overlay_96.h"
#include "pokeathlon/pokeathlon.h"
#include "overlay_99.h"
#include "overlay_trainer_card.h"
#include "party_menu.h"

View File

@ -0,0 +1,91 @@
#ifndef POKEHEARTGOLD_POKEATHLON_H
#define POKEHEARTGOLD_POKEATHLON_H
#include "overlay_manager.h"
// Forward declarations
typedef struct PokeathlonCourseWork PokeathlonCourseWork;
typedef struct PokeathlonCourseArgs PokeathlonCourseArgs;
// Pokeathlon course arguments structure
struct PokeathlonCourseArgs {
u8 filler_0[4]; // 0x000
u32 field_4; // 0x004 - Mode flag (1 = special mode)
// ... more fields to be discovered
};
// Pokeathlon course work structure (0xD70 = 3440 bytes)
struct PokeathlonCourseWork {
u8 data[0xD70]; // Complete work structure (will be refined during decompilation)
};
// Helper inline functions to access work structure fields
// These will be replaced with proper struct members as we discover the layout
static inline u32 *PokeathlonWork_GetHeapIdPtr(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x284); // 0xa1 << 2
}
static inline PokeathlonCourseArgs **PokeathlonWork_GetArgsPtr(PokeathlonCourseWork *work) {
return (PokeathlonCourseArgs **)((u8 *)work + 0x1F8); // 0x7e << 2
}
static inline OverlayManager **PokeathlonWork_GetSubOverlayPtr(PokeathlonCourseWork *work) {
return (OverlayManager **)((u8 *)work + 0x280); // 0xa << 6
}
static inline u8 *PokeathlonWork_GetField15CPtr(PokeathlonCourseWork *work) {
return (u8 *)work + 0x15C;
}
static inline u8 *PokeathlonWork_GetField1EEPtr(PokeathlonCourseWork *work) {
return (u8 *)work + 0x1EE;
}
static inline u8 *PokeathlonWork_GetField72APtr(PokeathlonCourseWork *work) {
return (u8 *)work + 0x72A;
}
static inline u32 *PokeathlonWork_GetField3C0Ptr(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x3C0);
}
static inline u32 *PokeathlonWork_GetField614Ptr(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x614);
}
static inline u32 *PokeathlonWork_GetField288Ptr(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x1E0); // 0xa << 6 - 0xa0 for state field
}
static inline u32 *PokeathlonWork_GetField3B4Ptr(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x3B4); // 0xa << 6 - 0x88
}
static inline void **PokeathlonWork_GetField3C4Ptr(PokeathlonCourseWork *work) {
return (void **)((u8 *)work + 0x3C4); // 0xf1 << 2 + 0x3c
}
static inline u32 *PokeathlonWork_GetField3C0Ptr2(PokeathlonCourseWork *work) {
return (u32 *)((u8 *)work + 0x3C0); // 0xf1 << 2 + 0x38 - 0xa
}
static inline u8 *PokeathlonWork_GetField3CAPtr(PokeathlonCourseWork *work) {
return (u8 *)work + 0x3CA;
}
// Function declarations
BOOL PokeathlonCourse_Init(OverlayManager *man, int *state);
BOOL PokeathlonCourse_Main(OverlayManager *man, int *state);
BOOL PokeathlonCourse_Exit(OverlayManager *man, int *state);
// Internal overlay 96 functions (stubs for now, in assembly)
void ov96_021E5C80(const void *src, void *dest);
void ov96_021E5C90(PokeathlonCourseWork *work);
void *ov96_021E8770(int a0, int a1, PokeathlonCourseWork *work, int a3, int heapId);
int ov96_021E8A24(void);
int ov96_021E8A2C(void);
void *ov96_021E92E0(u8 heapId);
void ov96_021E5DFC(PokeathlonCourseWork *work, int param);
void ov96_021E5DE0(PokeathlonCourseWork *work, int param);
#endif // POKEHEARTGOLD_POKEATHLON_H

View File

@ -1109,6 +1109,7 @@ Overlay OVY_95
Overlay OVY_96
{
After main
Object src/pokeathlon/pokeathlon_course.o
Object asm/overlay_96.o
}
Overlay OVY_97

View File

@ -52,7 +52,7 @@
#include "overlay_73.h"
#include "overlay_86.h"
#include "overlay_87.h"
#include "overlay_96.h"
#include "pokeathlon/pokeathlon.h"
#include "overlay_99.h"
#include "overlay_manager.h"
#include "overlay_trainer_card.h"

View File

@ -0,0 +1,102 @@
#include "nitro/mi/memory.h"
#include "global.h"
#include "pokeathlon/pokeathlon.h"
#include "heap.h"
#include "render_text.h"
#include "unk_02035900.h"
// External overlay 97 function declarations (in assembly for now)
extern int ov97_0221E5C0(OverlayManager *man, int *state); // Init
extern int ov97_0221E5D4(OverlayManager *man, int *state); // Main/Exec
extern int ov97_0221E69C(OverlayManager *man, int *state); // Exit
// Data tables in assembly
extern const OverlayManagerTemplate ov96_0221A7E4; // Sub-overlay template
extern const void *ov96_0221A984; // Other data table
BOOL PokeathlonCourse_Init(OverlayManager *man, int *state) {
PokeathlonCourseWork *work;
PokeathlonCourseArgs *args;
OverlayManager *subOverlay;
int specialMode;
OverlayManagerTemplate subTemplate;
void *system;
int param1, param2;
// Create heap
Heap_Create(HEAP_ID_3, HEAP_ID_92, 0x72000);
// Allocate and zero work structure
work = OverlayManager_CreateAndGetData(man, sizeof(PokeathlonCourseWork), HEAP_ID_92);
MI_CpuFill8(work, 0, sizeof(PokeathlonCourseWork));
// Store heap ID
*PokeathlonWork_GetHeapIdPtr(work) = HEAP_ID_92;
// Get arguments
args = OverlayManager_GetArgs(man);
*PokeathlonWork_GetArgsPtr(work) = args;
// Copy sub-overlay template
subTemplate = ov96_0221A7E4;
// Create sub-overlay manager
subOverlay = OverlayManager_New(&subTemplate, PokeathlonWork_GetArgsPtr(work), HEAP_ID_92);
*PokeathlonWork_GetSubOverlayPtr(work) = subOverlay;
// Initialize state
specialMode = 0;
*PokeathlonWork_GetField288Ptr(work) = specialMode;
args = *PokeathlonWork_GetArgsPtr(work);
param1 = args->field_4;
// Check mode
if (param1 == 1) {
specialMode = 1;
*PokeathlonWork_GetField1EEPtr(work) = sub_02037454();
*PokeathlonWork_GetField72APtr(work) = 4;
} else {
*PokeathlonWork_GetField1EEPtr(work) = 1;
*PokeathlonWork_GetField72APtr(work) = 3;
}
// Initialize subsystems
param1 = ov96_021E8A24();
param2 = ov96_021E8A2C();
system = ov96_021E8770(param1, param2, work, specialMode, *PokeathlonWork_GetHeapIdPtr(work));
*((void **)((u8 *)work + 0x288)) = system; // field_288
// More initialization
ov96_021E5C80(&ov96_0221A984, PokeathlonWork_GetField3C4Ptr(work));
// Additional setup
*PokeathlonWork_GetField3CAPtr(work) = 0;
*((void **)((u8 *)work + 0x3B4)) = PokeathlonWork_GetField3C4Ptr(work);
*((u32 *)((u8 *)work + 0x3C0)) = 0;
ov96_021E5C90(work);
system = ov96_021E92E0(HEAP_ID_92);
*PokeathlonWork_GetField614Ptr(work) = (u32)system;
// Text flags setup based on mode
if ((*PokeathlonWork_GetArgsPtr(work))->field_4 != 1) {
TextFlags_SetCanABSpeedUpPrint(TRUE);
TextFlags_SetAutoScrollParam(0);
TextFlags_SetCanTouchSpeedUpPrint(TRUE);
} else {
TextFlags_SetCanABSpeedUpPrint(FALSE);
TextFlags_SetAutoScrollParam(1);
TextFlags_SetCanTouchSpeedUpPrint(FALSE);
}
// Final initialization
ov96_021E5DFC(work, 0);
ov96_021E5DE0(work, 0);
return TRUE;
}