Merge pull request #8 from Cleverking2003/master

Decompile main.c
This commit is contained in:
jiangzhengwenjz 2020-04-28 21:02:38 +08:00 committed by GitHub
commit aff1deed07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 154 additions and 345 deletions

View File

@ -2152,348 +2152,3 @@ _08152776:
pop {r4, r5, r6, r7}
pop {r0}
bx r0
thumb_func_start sub_08152790
sub_08152790: @ 0x08152790
push {r4, r5, r6, r7, lr}
mov r7, sl
mov r6, sb
mov r5, r8
push {r5, r6, r7}
sub sp, #0xc
bl m4aMPlayAllStop
bl m4aSoundVSyncOff
ldr r1, _08152858 @ =gUnk_03003670
ldr r0, [r1]
str r0, [sp, #4]
movs r1, #0x80
lsls r1, r1, #8
orrs r0, r1
ldr r2, _08152858 @ =gUnk_03003670
str r0, [r2]
mov r1, sp
movs r2, #0x80
lsls r2, r2, #0x13
ldrh r0, [r2]
strh r0, [r1]
add r0, sp, #8
mov sl, r0
ldr r1, _0815285C @ =0x04000004
mov sb, r1
ldrh r0, [r1]
mov r2, sl
strh r0, [r2]
movs r0, #0x80
subs r1, #4
strh r0, [r1]
ldr r1, _08152860 @ =0x04000132
ldr r2, _08152864 @ =0x00008304
adds r0, r2, #0
strh r0, [r1]
ldr r5, _08152868 @ =0x04000208
movs r6, #0
strh r6, [r5]
mov r0, sb
strh r6, [r0]
mov r7, sp
adds r7, #2
ldr r4, _0815286C @ =0x04000200
ldrh r0, [r4]
strh r0, [r7]
movs r1, #0x80
lsls r1, r1, #5
adds r0, r1, #0
strh r0, [r4]
ldrh r0, [r4]
movs r2, #0x80
lsls r2, r2, #6
adds r1, r2, #0
orrs r0, r1
strh r0, [r4]
movs r0, #1
mov r8, r0
strh r0, [r5]
bl SoundBiasReset
svc #3
bl SoundBiasSet
strh r6, [r5]
ldrh r0, [r7]
strh r0, [r4]
mov r1, r8
strh r1, [r5]
mov r2, sl
ldrh r0, [r2]
mov r1, sb
strh r0, [r1]
bl VBlankIntrWait
mov r0, sp
ldrh r0, [r0]
movs r2, #0x80
lsls r2, r2, #0x13
strh r0, [r2]
ldr r0, [sp, #4]
ldr r1, _08152858 @ =gUnk_03003670
str r0, [r1]
ldr r2, _08152870 @ =gUnk_03002440
ldr r0, [r2]
ldr r1, _08152874 @ =0xFFFBFFFF
ands r0, r1
str r0, [r2]
bl m4aSoundVSyncOn
add sp, #0xc
pop {r3, r4, r5}
mov r8, r3
mov sb, r4
mov sl, r5
pop {r4, r5, r6, r7}
pop {r0}
bx r0
.align 2, 0
_08152858: .4byte gUnk_03003670
_0815285C: .4byte 0x04000004
_08152860: .4byte 0x04000132
_08152864: .4byte 0x00008304
_08152868: .4byte 0x04000208
_0815286C: .4byte 0x04000200
_08152870: .4byte gUnk_03002440
_08152874: .4byte 0xFFFBFFFF
thumb_func_start HBlankIntr
HBlankIntr: @ 0x08152878
push {r4, r5, r6, lr}
ldr r0, _081528B8 @ =0x04000006
ldrb r0, [r0]
adds r5, r0, #0
cmp r5, #0x9f
bhi _081528AA
movs r4, #0
ldr r0, _081528BC @ =gUnk_030024E4
ldrb r0, [r0]
cmp r4, r0
bhs _081528AA
ldr r6, _081528C0 @ =gUnk_03003A10
_08152890:
lsls r0, r4, #2
adds r0, r0, r6
ldr r1, [r0]
adds r0, r5, #0
bl _call_via_r1
adds r0, r4, #1
lsls r0, r0, #0x18
lsrs r4, r0, #0x18
ldr r0, _081528BC @ =gUnk_030024E4
ldrb r0, [r0]
cmp r4, r0
blo _08152890
_081528AA:
ldr r1, _081528C4 @ =0x04000202
movs r0, #2
strh r0, [r1]
pop {r4, r5, r6}
pop {r0}
bx r0
.align 2, 0
_081528B8: .4byte 0x04000006
_081528BC: .4byte gUnk_030024E4
_081528C0: .4byte gUnk_03003A10
_081528C4: .4byte 0x04000202
thumb_func_start VCountIntr
VCountIntr: @ 0x081528C8
ldr r1, _081528D0 @ =0x04000202
movs r0, #4
strh r0, [r1]
bx lr
.align 2, 0
_081528D0: .4byte 0x04000202
thumb_func_start Dma0Intr
Dma0Intr: @ 0x081528D4
ldr r1, _081528E0 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #1
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_081528E0: .4byte 0x04000202
thumb_func_start Dma1Intr
Dma1Intr: @ 0x081528E4
ldr r1, _081528F0 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #2
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_081528F0: .4byte 0x04000202
thumb_func_start Dma2Intr
Dma2Intr: @ 0x081528F4
ldr r1, _08152900 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #3
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_08152900: .4byte 0x04000202
thumb_func_start Dma3Intr
Dma3Intr: @ 0x08152904
ldr r1, _08152910 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #4
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_08152910: .4byte 0x04000202
thumb_func_start Timer0Intr
Timer0Intr: @ 0x08152914
ldr r1, _0815291C @ =0x04000202
movs r0, #8
strh r0, [r1]
bx lr
.align 2, 0
_0815291C: .4byte 0x04000202
thumb_func_start Timer1Intr
Timer1Intr: @ 0x08152920
ldr r1, _08152928 @ =0x04000202
movs r0, #0x10
strh r0, [r1]
bx lr
.align 2, 0
_08152928: .4byte 0x04000202
thumb_func_start Timer2Intr
Timer2Intr: @ 0x0815292C
ldr r1, _08152934 @ =0x04000202
movs r0, #0x20
strh r0, [r1]
bx lr
.align 2, 0
_08152934: .4byte 0x04000202
thumb_func_start Timer3IntrDummy
Timer3IntrDummy: @ 0x08152938
ldr r1, _08152940 @ =0x04000202
movs r0, #0x40
strh r0, [r1]
bx lr
.align 2, 0
_08152940: .4byte 0x04000202
thumb_func_start KeypadIntr
KeypadIntr: @ 0x08152944
ldr r1, _08152950 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #5
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_08152950: .4byte 0x04000202
thumb_func_start GamepakIntr
GamepakIntr: @ 0x08152954
ldr r1, _08152960 @ =0x04000202
movs r2, #0x80
lsls r2, r2, #6
adds r0, r2, #0
strh r0, [r1]
bx lr
.align 2, 0
_08152960: .4byte 0x04000202
thumb_func_start nullsub_142
nullsub_142: @ 0x08152964
bx lr
.align 2, 0
thumb_func_start sub_08152968
sub_08152968: @ 0x08152968
push {r4, lr}
sub sp, #4
ldr r1, _081529A0 @ =gUnk_0300248C
movs r0, #0
strb r0, [r1]
ldr r2, _081529A4 @ =gUnk_03002440
ldr r0, [r2]
movs r1, #9
rsbs r1, r1, #0
ands r0, r1
str r0, [r2]
movs r1, #0x20
ands r0, r1
adds r4, r2, #0
cmp r0, #0
bne _081529C0
ldr r1, _081529A8 @ =gUnk_03002484
ldr r0, [r1]
ldr r2, _081529AC @ =gUnk_03002760
cmp r0, r2
bne _081529B4
movs r3, #0xa0
lsls r3, r3, #2
adds r0, r2, r3
str r0, [r1]
ldr r0, _081529B0 @ =gUnk_03002EAC
str r2, [r0]
b _081529C0
.align 2, 0
_081529A0: .4byte gUnk_0300248C
_081529A4: .4byte gUnk_03002440
_081529A8: .4byte gUnk_03002484
_081529AC: .4byte gUnk_03002760
_081529B0: .4byte gUnk_03002EAC
_081529B4:
str r2, [r1]
ldr r1, _081529F4 @ =gUnk_03002EAC
movs r3, #0xa0
lsls r3, r3, #2
adds r0, r2, r3
str r0, [r1]
_081529C0:
ldr r0, [r4]
movs r1, #5
rsbs r1, r1, #0
ands r0, r1
str r0, [r4]
movs r0, #0x80
lsls r0, r0, #2
str r0, [sp]
ldr r1, _081529F8 @ =gUnk_030060B0
ldr r2, _081529FC @ =0x01000100
mov r0, sp
bl CpuFastSet
ldr r1, _08152A00 @ =gUnk_03006070
movs r0, #0
strb r0, [r1]
ldr r0, [r4]
movs r1, #0x11
rsbs r1, r1, #0
ands r0, r1
str r0, [r4]
add sp, #4
pop {r4}
pop {r0}
bx r0
.align 2, 0
_081529F4: .4byte gUnk_03002EAC
_081529F8: .4byte gUnk_030060B0
_081529FC: .4byte 0x01000100
_08152A00: .4byte gUnk_03006070
thumb_func_start AgbMain
AgbMain: @ 0x08152A04
push {lr}
bl sub_0815158C
bl sub_080001CC
bl sub_08151C54
pop {r0}
bx r0
.align 2, 0

View File

@ -357,6 +357,7 @@ void MPlayJumpTableCopy(void **mplayJumpTable);
void SampleFreqSet(u32 freq);
void m4aSoundVSyncOn(void);
void m4aSoundVSyncOff(void);
void m4aMPlayAllStop(void);
void m4aMPlayTempoControl(struct MusicPlayerInfo *mplayInfo, u16 tempo);
void m4aMPlayVolumeControl(struct MusicPlayerInfo *mplayInfo, u16 trackBits, u16 volume);

View File

@ -47,4 +47,8 @@ int MultiBoot(struct MultiBootParam *mp);
s32 Div(s32 num, s32 denom);
void SoundBiasReset(void);
void SoundBiasSet(void);
#endif // GUARD_GBA_SYSCALL_H

24
include/main.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef GUARD_MAIN_H
#define GUARD_MAIN_H
#include "global.h"
typedef void (*HBlankFunc)(u8);
extern u8 gUnk_0300248C;
extern u32 gUnk_03002440;
extern u32* gUnk_03002484;
extern u32 gUnk_03002760[0xa0];
extern u32* gUnk_03002EAC;
extern u8 gUnk_03006070;
extern u32 gUnk_030060B0[0x100];
extern u8 gUnk_030024E4;
extern HBlankFunc gUnk_03003A10[0xa0];
extern u32 gUnk_03003670;
extern u32 gUnk_03002440;
extern void sub_0815158C(void);
extern void sub_080001CC(void);
extern void sub_08151C54(void);
#endif

View File

@ -284,6 +284,7 @@ SECTIONS {
asm/m4a_asm.o(.text);
src/m4a.o(.text);
asm/main.o(.text);
src/main.o(.text);
asm/code_08152A18.o(.text);
src/multi_sio.o(.text);
src/multi_boot.o(.text);

124
src/main.c Normal file
View File

@ -0,0 +1,124 @@
#include "gba/m4a_internal.h"
#include "gba/syscall.h"
#include "global.h"
#include "main.h"
static inline void Sleep(void) {
asm("swi\t3");
}
void sub_08152790(void) {
vu16 dispcnt, ie;
vu32 unk3670;
vu16 dispstat;
m4aMPlayAllStop();
m4aSoundVSyncOff();
unk3670 = gUnk_03003670;
gUnk_03003670 |= 0x8000;
dispcnt = REG_DISPCNT;
dispstat = REG_DISPSTAT;
REG_DISPCNT = DISPCNT_FORCED_BLANK;
REG_KEYCNT = KEY_AND_INTR | L_BUTTON | R_BUTTON | SELECT_BUTTON;
REG_IME = 0;
REG_DISPSTAT = 0;
ie = REG_IE;
REG_IE = INTR_FLAG_KEYPAD;
REG_IE |= INTR_FLAG_GAMEPAK;
REG_IME = 1;
SoundBiasReset();
Sleep();
SoundBiasSet();
REG_IME = 0;
REG_IE = ie;
REG_IME = 1;
REG_DISPSTAT = dispstat;
VBlankIntrWait();
REG_DISPCNT = dispcnt;
gUnk_03003670 = unk3670;
gUnk_03002440 &= ~0x40000;
m4aSoundVSyncOn();
}
void HBlankIntr(void) {
u8 i;
u8 vcount = *(vu8*)REG_ADDR_VCOUNT;
if (vcount <= 0x9f) {
for (i = 0; i < gUnk_030024E4; i++) {
gUnk_03003A10[i](vcount);
}
}
REG_IF = INTR_FLAG_HBLANK;
}
void VCountIntr(void) {
REG_IF = INTR_FLAG_VCOUNT;
}
void Dma0Intr(void) {
REG_IF = INTR_FLAG_DMA0;
}
void Dma1Intr(void) {
REG_IF = INTR_FLAG_DMA1;
}
void Dma2Intr(void) {
REG_IF = INTR_FLAG_DMA2;
}
void Dma3Intr(void) {
REG_IF = INTR_FLAG_DMA3;
}
void Timer0Intr(void) {
REG_IF = INTR_FLAG_TIMER0;
}
void Timer1Intr(void) {
REG_IF = INTR_FLAG_TIMER1;
}
void Timer2Intr(void) {
REG_IF = INTR_FLAG_TIMER2;
}
void Timer3IntrDummy(void) {
REG_IF = INTR_FLAG_TIMER3;
}
void KeypadIntr(void) {
REG_IF = INTR_FLAG_KEYPAD;
}
void GamepakIntr(void) {
REG_IF = INTR_FLAG_GAMEPAK;
}
void nullsub_142(void) {
}
void sub_08152968(void) {
gUnk_0300248C = 0;
gUnk_03002440 &= ~8;
if (!(gUnk_03002440 & 0x20)) {
if (gUnk_03002484 == &gUnk_03002760[0]) {
gUnk_03002484 = &gUnk_03002760[0xa0];
gUnk_03002EAC = &gUnk_03002760[0];
}
else {
gUnk_03002484 = &gUnk_03002760[0];
gUnk_03002EAC = &gUnk_03002760[0xa0];
}
}
gUnk_03002440 &= ~4;
CpuFastFill(0x200, gUnk_030060B0, 0x400);
gUnk_03006070 = 0;
gUnk_03002440 &= ~0x10;
}
void AgbMain(void) {
sub_0815158C();
sub_080001CC();
sub_08151C54();
}