rom3 decomp start

This commit is contained in:
DizzyEggg 2017-10-13 17:22:50 +02:00
parent 428dd0e0a8
commit c78679ae66
30 changed files with 1160 additions and 2299 deletions

View File

@ -59,13 +59,13 @@ _08056F3E:
bl AllocZeroed
ldr r1, [r5]
str r0, [r1, 0x1C]
ldr r4, =gUnknown_020244A0
ldr r4, =gLinkBattleSendBuffer
movs r5, 0x80
lsls r5, 5
adds r0, r5, 0
bl AllocZeroed
str r0, [r4]
ldr r4, =gUnknown_020244A4
ldr r4, =gLinkBattleRecvBuffer
adds r0, r5, 0
bl AllocZeroed
str r0, [r4]
@ -160,11 +160,11 @@ _0805703C:
str r5, [r0, 0x1C]
bl Free
str r5, [r6]
ldr r4, =gUnknown_020244A0
ldr r4, =gLinkBattleSendBuffer
ldr r0, [r4]
bl Free
str r5, [r4]
ldr r4, =gUnknown_020244A4
ldr r4, =gLinkBattleRecvBuffer
ldr r0, [r4]
bl Free
str r5, [r4]

View File

@ -1801,7 +1801,7 @@ _0805E056:
movs r4, 0
cmp r4, r5
bcs _0805E076
ldr r7, =gBanksBySide
ldr r7, =gBanksByIdentity
ldr r6, =gUnknown_0832C108
_0805E060:
adds r0, r4, r7
@ -1874,14 +1874,14 @@ _0805E0F0:
_0805E100:
cmp r4, 0x4
bne _0805E110
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0]
b _0805E198
.pool
_0805E110:
cmp r4, 0x5
bne _0805E1AC
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0, 0x1]
b _0805E198
.pool
@ -1916,28 +1916,28 @@ _0805E150:
_0805E160:
cmp r4, 0x6
bne _0805E170
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0]
b _0805E198
.pool
_0805E170:
cmp r4, 0x7
bne _0805E180
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0, 0x1]
b _0805E198
.pool
_0805E180:
cmp r4, 0x8
bne _0805E190
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0, 0x2]
b _0805E198
.pool
_0805E190:
cmp r5, 0x9
bne _0805E1AC
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r0, [r0, 0x3]
_0805E198:
lsls r0, 3
@ -2038,7 +2038,7 @@ _0805E252:
_0805E260:
ldrb r0, [r4]
bl sub_8072B18
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
ldrb r1, [r4]
adds r0, r1, r0
ldrb r0, [r0]

View File

@ -5,8 +5,8 @@
.text
thumb_func_start sub_80A3934
sub_80A3934: @ 80A3934
thumb_func_start ClearBattleAnimationVars
ClearBattleAnimationVars: @ 80A3934
push {r4-r7,lr}
mov r7, r9
mov r6, r8
@ -84,7 +84,7 @@ _080A3994:
pop {r0}
bx r0
.pool
thumb_func_end sub_80A3934
thumb_func_end ClearBattleAnimationVars
thumb_func_start move_anim_start_t1
move_anim_start_t1: @ 80A3A10

View File

@ -10676,7 +10676,7 @@ _08103D54:
strh r0, [r3, 0x4]
b _08103DB6
_08103D5C:
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
ldr r0, =gAnimationBankTarget
ldrb r0, [r0]
adds r0, r1
@ -27474,7 +27474,7 @@ sub_810C560: @ 810C560
lsls r0, 8
strh r0, [r5, 0x3C]
_0810C594:
ldr r3, =gBanksBySide
ldr r3, =gBanksByIdentity
ldrb r0, [r7]
adds r0, r3
ldrb r1, [r0]
@ -27699,7 +27699,7 @@ _0810C736:
lsls r0, 24
cmp r0, 0
bne _0810C78C
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
ldrb r0, [r6]
adds r0, r1
ldrb r1, [r0]
@ -27843,7 +27843,7 @@ _0810C85A:
lsls r0, 24
cmp r0, 0
bne _0810C8B4
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
ldr r0, =gAnimationBankTarget
ldrb r0, [r0]
adds r0, r1
@ -28771,7 +28771,7 @@ _0810D000:
negs r0, r0
lsrs r4, r0, 16
_0810D012:
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
add r0, r8
ldrb r1, [r0]
adds r0, r7, 0

View File

@ -514,7 +514,7 @@ _08072694:
_08072716:
str r0, [sp]
_08072718:
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
add r0, r10
ldrb r1, [r0]
lsls r0, r1, 1

View File

@ -1275,7 +1275,7 @@ _080802AC:
strh r0, [r1]
adds r5, 0x1
_080802D4:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -1295,7 +1295,7 @@ _080802EC:
bl sub_807FD90
b _08080336
_08080302:
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r2, =gUnknown_020322A4
ldr r1, [r2]
adds r1, 0x7C
@ -6091,7 +6091,7 @@ _08082BEE:
lsls r0, 24
lsrs r5, r0, 24
_08082BF4:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -6104,7 +6104,7 @@ _08082C0C:
lsls r0, 24
lsrs r5, r0, 24
_08082C12:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -6118,7 +6118,7 @@ _08082C12:
cmp r0, 0
bne _08082C0C
_08082C2E:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -6132,7 +6132,7 @@ _08082C48:
lsls r0, 24
lsrs r5, r0, 24
_08082C4E:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -6149,7 +6149,7 @@ _08082C6A:
ldr r4, =gUnknown_03003110
adds r0, r4, 0
bl sub_8081F94
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0

View File

@ -1059,7 +1059,7 @@ _080B2C5C:
lsls r0, 24
lsrs r4, r0, 24
_080B2C7E:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -1361,7 +1361,7 @@ _080B2F0C:
movs r0, 0
mov r8, r0
mov r9, r0
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r5, r0, 24
movs r4, 0
@ -1980,11 +1980,11 @@ _080B3474:
bl sub_800B524
lsls r0, r4, 24
lsrs r0, 24
bl sub_800A5EC
bl ResetBlockReceivedFlag
adds r5, 0x1C
adds r4, 0x1
_080B349A:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -2080,7 +2080,7 @@ _080B3574:
beq _080B35F8
b _080B35FE
_080B357A:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r3, r0, 24
movs r4, 0

View File

@ -1048,7 +1048,7 @@ _080D8004:
bl sub_80DC594
bl sub_80DC5E8
bl sub_80DC7EC
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
strb r4, [r1]
movs r0, 0x1
strb r0, [r1, 0x1]
@ -13606,7 +13606,7 @@ sub_80DE864: @ 80DE864
movs r1, 0
movs r2, 0x14
bl memset
bl sub_80A3934
bl ClearBattleAnimationVars
ldr r1, =gBattleMonForms
movs r2, 0
adds r0, r1, 0x3

View File

@ -50,7 +50,7 @@ sub_80FC530: @ 80FC530
cmp r4, 0
beq _080FC552
adds r0, r5, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
movs r0, 0x1
b _080FC554
_080FC552:
@ -141,7 +141,7 @@ sub_80FC5DC: @ 80FC5DC
bl GetMultiplayerId
ldr r1, =gUnknown_02039F25
strb r0, [r1]
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r4, =gUnknown_02039F30
strb r0, [r4]
ldr r1, =gUnknown_02039F2A

View File

@ -492,7 +492,7 @@ sub_812287C: @ 812287C
bl Free
b _08122980
_081228B0:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
mov r9, r0

View File

@ -545,7 +545,7 @@ _08009888:
movs r6, 0
strh r0, [r4]
adds r0, r5, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
ldrh r0, [r4]
cmp r0, r8
beq _080098C4
@ -1371,8 +1371,8 @@ _08009FC4:
.pool
thumb_func_end sub_8009FAC
thumb_func_start sub_8009FCC
sub_8009FCC: @ 8009FCC
thumb_func_start GetLinkPlayerCount
GetLinkPlayerCount: @ 8009FCC
push {lr}
ldr r0, =gLinkVSyncDisabled
ldrb r0, [r0]
@ -1392,14 +1392,14 @@ _08009FEC:
_08009FF4:
pop {r1}
bx r1
thumb_func_end sub_8009FCC
thumb_func_end GetLinkPlayerCount
thumb_func_start sub_8009FF8
sub_8009FF8: @ 8009FF8
push {r4-r7,lr}
adds r6, r0, 0
adds r5, r1, 0
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r4, r0, 24
movs r2, 0
@ -1442,7 +1442,7 @@ sub_800A03C: @ 800A03C
thumb_func_start sub_800A040
sub_800A040: @ 800A040
push {lr}
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r0, 0x4
@ -1546,7 +1546,7 @@ _0800A0EA:
b _0800A22E
.pool
_0800A0FC:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
cmp r0, 0
bne _0800A10E
@ -1572,12 +1572,12 @@ _0800A130:
adds r5, 0x1C
adds r6, 0x1
_0800A134:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r6, r0
blt _0800A120
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r7, r0
@ -1714,12 +1714,12 @@ _0800A266:
lsls r0, 24
lsrs r4, r0, 24
_0800A26C:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
bcc _0800A24C
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r6, r0
@ -2181,8 +2181,8 @@ _0800A5E2:
.pool
thumb_func_end ResetBlockReceivedFlags
thumb_func_start sub_800A5EC
sub_800A5EC: @ 800A5EC
thumb_func_start ResetBlockReceivedFlag
ResetBlockReceivedFlag: @ 800A5EC
push {lr}
lsls r0, 24
lsrs r1, r0, 24
@ -2206,7 +2206,7 @@ _0800A616:
pop {r0}
bx r0
.pool
thumb_func_end sub_800A5EC
thumb_func_end ResetBlockReceivedFlag
thumb_func_start sub_800A620
sub_800A620: @ 800A620
@ -2697,7 +2697,7 @@ _0800A9E2:
lsrs r4, r0, 24
adds r5, 0x1
_0800A9EE:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -3044,7 +3044,7 @@ _0800AC96:
thumb_func_start sub_800ACAC
sub_800ACAC: @ 800ACAC
push {r4,lr}
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r2, r0, 24
movs r3, 0
@ -3142,7 +3142,7 @@ _0800AD72:
thumb_func_start sub_800AD88
sub_800AD88: @ 800AD88
push {r4,r5,lr}
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r3, r0, 24
movs r1, 0
@ -3239,7 +3239,7 @@ _0800AE46:
thumb_func_start sub_800AE5C
sub_800AE5C: @ 800AE5C
push {r4,lr}
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r2, r0, 24
movs r1, 0
@ -9671,7 +9671,7 @@ _0800E1C8:
lsls r0, 24
lsrs r5, r0, 24
_0800E1E6:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
subs r0, 0x1
@ -9965,7 +9965,7 @@ _0800E428:
ble _0800E3FC
mov r4, r9
_0800E434:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -10019,7 +10019,7 @@ _0800E4A6:
adds r5, 0x1C
adds r4, 0x1
_0800E4AC:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -13627,7 +13627,7 @@ sub_80102B8: @ 80102B8
bl sub_800FD14
strh r4, [r5]
_080102E6:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r2, r0, 24
movs r1, 0
@ -13734,7 +13734,7 @@ sub_8010390: @ 8010390
b _0801041C
.pool
_080103CC:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r2, r0, 24
movs r1, 0x1
@ -14607,7 +14607,7 @@ sub_8010A70: @ 8010A70
adds r1, r4, 0
bl CpuSet
movs r0, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
_08010A9C:
add sp, 0x4
pop {r4,r5}
@ -14683,7 +14683,7 @@ _08010B40:
b _08010CF0
_08010B4A:
adds r0, r4, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
movs r0, 0xF0
lsls r0, 7
bl sub_800FD14
@ -14713,7 +14713,7 @@ _08010B78:
b _08010CF0
_08010B8C:
adds r0, r4, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
lsls r2, r4, 8
ldr r0, =gBlockRecvBuffer
adds r2, r0
@ -14845,7 +14845,7 @@ _08010C94:
ldr r2, =0x0100007e
bl CpuSet
movs r0, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
ldr r1, =gUnknown_03005000
ldr r5, =0x00000ce8
adds r0, r1, r5
@ -14947,7 +14947,7 @@ _08010D82:
ldr r0, =gBlockRecvBuffer
bl sub_8010A14
movs r0, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
ldr r0, =gReceivedRemoteLinkPlayers
strb r4, [r0]
adds r0, r5, 0
@ -15290,7 +15290,7 @@ _08011048:
strb r0, [r1, 0x3]
adds r4, 0x1
_08011054:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -20950,12 +20950,12 @@ _08014138:
adds r5, 0x1C
adds r4, 0x1
_08014152:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
blt _08014138
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r0, 0x2
@ -21159,7 +21159,7 @@ sub_8014304: @ 8014304
strh r1, [r0]
ldr r0, =0x00004087
bl VarSet
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r1, =gUnknown_03005DB8
strb r0, [r1]
bl GetMultiplayerId
@ -39108,7 +39108,7 @@ sub_801D978: @ 801D978
push {lr}
lsls r0, 24
lsrs r0, 24
bl sub_800A5EC
bl ResetBlockReceivedFlag
pop {r0}
bx r0
thumb_func_end sub_801D978
@ -39697,7 +39697,7 @@ sub_801DDD0: @ 801DDD0
strb r5, [r4, 0x16]
movs r0, 0xFF
strb r0, [r4, 0x1A]
bl sub_8009FCC
bl GetLinkPlayerCount
strb r0, [r4, 0xD]
bl GetMultiplayerId
strb r0, [r4, 0x13]
@ -42285,7 +42285,7 @@ _0801F30A:
movs r0, 0x1
strh r0, [r4]
_0801F30E:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
adds r2, r0, 0
@ -42361,7 +42361,7 @@ _0801F3A2:
strh r1, [r4, 0x4]
lsls r0, r1, 24
lsrs r0, 24
bl sub_800A5EC
bl ResetBlockReceivedFlag
movs r1, 0x2
ldrsh r0, [r4, r1]
lsls r0, 8
@ -42446,7 +42446,7 @@ _0801F448:
ldrsh r0, [r4, r3]
cmp r0, 0
beq _0801F47C
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r0, 0x2
@ -45504,7 +45504,7 @@ _08020C8E:
b _08020CF8
.pool
_08020CAC:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
mov r8, r0
@ -53271,7 +53271,7 @@ _08024B2C:
_08024B6A:
ldr r0, [sp, 0x10]
strb r1, [r0]
bl sub_8009FCC
bl GetLinkPlayerCount
mov r1, r8
strb r0, [r1]
bl GetMultiplayerId
@ -57700,7 +57700,7 @@ _08026EF6:
adds r4, 0xC
adds r5, 0x1
_08026EFE:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -59511,7 +59511,7 @@ _08027C76:
thumb_func_start sub_8027D20
sub_8027D20: @ 8027D20
push {lr}
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r1, =gUnknown_02022C98
ldr r1, [r1]
adds r1, 0x24
@ -64891,7 +64891,7 @@ sub_802AA48: @ 802AA48
sub_802AA60: @ 802AA60
push {r4,lr}
adds r4, r0, 0
bl sub_8009FCC
bl GetLinkPlayerCount
movs r2, 0
strb r0, [r4, 0x5]
adds r1, r4, 0
@ -68775,7 +68775,7 @@ _0802C8A4:
thumb_func_start sub_802C8AC
sub_802C8AC: @ 802C8AC
push {lr}
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
pop {r1}

View File

@ -1135,7 +1135,7 @@ _080E76DC:
bl memcpy
_080E76E4:
mov r0, r8
bl sub_800A5EC
bl ResetBlockReceivedFlag
mov r0, r9
lsls r1, r0, 1
adds r1, r5, r1
@ -1162,7 +1162,7 @@ _080E7714:
lsrs r0, 24
mov r8, r0
_080E771C:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r8, r0
@ -1179,7 +1179,7 @@ _080E771C:
adds r1, 0x1
strh r1, [r0, 0x8]
_080E773E:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
ldr r4, [sp, 0x8]
@ -1312,7 +1312,7 @@ sub_80E7820: @ 80E7820
sub_80E7830: @ 80E7830
push {r4,lr}
adds r4, r0, 0
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r0, 0x3
@ -1738,7 +1738,7 @@ sub_80E7B60: @ 80E7B60
ldr r0, =gLinkPlayers
ldrh r0, [r0, 0x4]
bl SeedRng2
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r4, r0, 24
movs r0, 0
@ -1931,7 +1931,7 @@ _080E7CFA:
lsrs r0, 16
mov r8, r0
_080E7D04:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r8, r0
@ -3557,7 +3557,7 @@ sub_80E89AC: @ 80E89AC
adds r6, r0, 0
mov r8, r1
mov r9, r2
bl sub_8009FCC
bl GetLinkPlayerCount
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24

View File

@ -125,7 +125,7 @@ _08184EAC:
bl GetMultiplayerId
ldr r1, =gUnknown_0203C7B4
strb r0, [r1]
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
mov r10, r0
@ -505,7 +505,7 @@ _081851D0:
adds r4, 0x1C
adds r5, 0x1
_081851DA:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0

2239
asm/rom3.s

File diff suppressed because it is too large Load Diff

View File

@ -5399,7 +5399,7 @@ sub_8138240: @ 8138240
bl GetMultiplayerId
lsls r0, 24
lsrs r7, r0, 24
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r5, r0, 24
movs r4, 0
@ -11676,7 +11676,7 @@ _0813B62E:
ldrh r0, [r0]
strh r0, [r5]
movs r0, 0x1
bl sub_800A5EC
bl ResetBlockReceivedFlag
ldr r0, =gSpecialVar_0x8004
ldrh r0, [r0]
cmp r0, 0x1
@ -11756,7 +11756,7 @@ _0813B6E4:
ldrh r0, [r0]
strh r0, [r1]
movs r0, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
_0813B708:
ldr r1, =gTasks
lsls r0, r4, 2

View File

@ -1810,7 +1810,7 @@ _080A6A04:
GetBankSide: @ 80A6A30
lsls r0, 24
lsrs r0, 24
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
adds r0, r1
ldrb r1, [r0]
movs r0, 0x1
@ -1823,7 +1823,7 @@ GetBankSide: @ 80A6A30
GetBankIdentity: @ 80A6A44
lsls r0, 24
lsrs r0, 24
ldr r1, =gBanksBySide
ldr r1, =gBanksByIdentity
adds r0, r1
ldrb r0, [r0]
bx lr
@ -1840,7 +1840,7 @@ GetBankByIdentity: @ 80A6A54
ldrb r2, [r0]
cmp r1, r2
bcs _080A6A7E
ldr r4, =gBanksBySide
ldr r4, =gBanksByIdentity
ldrb r0, [r4]
cmp r0, r3
beq _080A6A7E
@ -1883,7 +1883,7 @@ sub_80A6A90: @ 80A6A90
b _080A6B18
.pool
_080A6ABC:
ldr r0, =gBanksBySide
ldr r0, =gBanksByIdentity
adds r0, r4, r0
ldrb r0, [r0]
cmp r0, 0xFF

View File

@ -4494,7 +4494,7 @@ sub_80EAF80: @ 80EAF80
bne _080EAF9A
b _080EB16A
_080EAF9A:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r0, 0x2

View File

@ -125,7 +125,7 @@ sub_8077234: @ 8077234
_08077250:
lsls r0, r4, 24
lsrs r0, 24
bl sub_800A5EC
bl ResetBlockReceivedFlag
_08077258:
pop {r4}
pop {r0}
@ -6603,7 +6603,7 @@ _0807A97C:
adds r4, 0x1C
adds r5, 0x1
_0807A980:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -6632,7 +6632,7 @@ _0807A9B0:
adds r4, 0x1C
adds r5, 0x1
_0807A9B4:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r5, r0
@ -12903,7 +12903,7 @@ _0807E504:
strb r6, [r0]
_0807E514:
movs r0, 0
bl sub_800A5EC
bl ResetBlockReceivedFlag
_0807E51A:
movs r0, 0x2
ands r0, r5
@ -12924,7 +12924,7 @@ _0807E51A:
strb r1, [r0]
_0807E53C:
movs r0, 0x1
bl sub_800A5EC
bl ResetBlockReceivedFlag
_0807E542:
pop {r4-r6}
pop {r0}

View File

@ -7992,7 +7992,7 @@ _080F0270:
lsls r0, 24
lsrs r4, r0, 24
_080F0276:
bl sub_8009FCC
bl GetLinkPlayerCount
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -8107,7 +8107,7 @@ sub_80F0358: @ 80F0358
str r0, [sp, 0x8]
add r0, sp, 0x1C
str r0, [sp, 0xC]
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r1, =gUnknown_03001174
strb r0, [r1]
_080F0384:
@ -9329,7 +9329,7 @@ sub_80F0D60: @ 80F0D60
str r0, [sp, 0x8]
add r0, sp, 0x1C
str r0, [sp, 0xC]
bl sub_8009FCC
bl GetLinkPlayerCount
ldr r1, =gUnknown_03001175
strb r0, [r1]
movs r0, 0

View File

@ -27,7 +27,9 @@
#define BIT_SIDE 0x1
#define BIT_MON 0x2
#define GET_BANK_IDENTITY(bank)((gBanksByIdentity[bank]))
#define GET_BANK_SIDE(bank)((GetBankIdentity(bank) & BIT_SIDE))
#define GET_BANK_SIDE2(bank)((GET_BANK_IDENTITY(bank) & BIT_SIDE))
#define BATTLE_TYPE_DOUBLE 0x0001
#define BATTLE_TYPE_LINK 0x0002
@ -654,7 +656,9 @@ struct BattleStruct
u8 field_1A1;
bool8 overworldWeatherDone;
u8 atkCancellerTracker;
u8 field_1A4[240];
u8 field_1A4[96];
u8 field_204[104];
u8 field_26C[40];
u8 field_294[4];
u8 field_298[8];
u8 field_2A0;
@ -891,6 +895,11 @@ struct BattleSpriteData
extern struct BattleSpriteData *gBattleSpritesDataPtr;
#define BATTLE_BUFFER_LINK_SIZE 0x1000
extern u8 *gLinkBattleSendBuffer;
extern u8 *gLinkBattleRecvBuffer;
// Move this somewhere else
#include "sprite.h"

View File

@ -17,6 +17,8 @@ void RunBattleScriptCommands_PopCallbacksStack(void);
void RunBattleScriptCommands(void);
u32 sub_80397C4(u32 setId, u32 tableId);
void sub_8039E9C(struct Sprite *sprite);
void nullsub_20(void);
void BeginBattleIntro(void);
extern const u8 gStatusConditionString_PoisonJpn[8];
extern const u8 gStatusConditionString_SleepJpn[8];

6
include/battle_anim.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef GUARD_BATTLE_ANIM_H
#define GUARD_BATTLE_ANIM_H
void ClearBattleAnimationVars(void);
#endif // GUARD_BATTLE_ANIM_H

View File

@ -46,7 +46,13 @@ struct ChooseMoveStruct
u8 monType2;
};
// rom3.s, emitters
// general functions
void HandleLinkBattleSetup(void);
void SetUpBattleVarsAndBirchZigzagoon(void);
void sub_8032768(void);
void sub_8033648(void);
// emitters
void EmitSetMonData(u8 bufferId, u8 request, u8 c, u8 bytes, void *data);
void EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct* disableStructPtr, u8 multihit);
void EmitHealthBarUpdate(u8 bufferId, u16 hpValue);
@ -86,4 +92,34 @@ void EmitResetActionMoveSelection(u8 bufferId, u8 caseId);
void EmitBallThrow(u8 bufferId, u8 caseId);
void EmitCmd_x21(u8 bufferId, u8 arg1, u16 arg2);
// player controller
void SetBankFuncToPlayerBufferRunCommand(void);
void nullsub_21(void);
void ActionSelectionCreateCursorAt(u8 cursorPos, u8 unused);
void ActionSelectionDestroyCursorAt(u8 cursorPos);
// recorded player controller
void SetBankFuncToRecordedPlayerBufferRunCommand(void);
// opponent controller
void SetBankFuncToOpponentBufferRunCommand(void);
// player partner controller
void SetBankFuncToPlayerPartnerBufferRunCommand(void);
// safari controller
void SetBankFuncToSafariBufferRunCommand(void);
// wally controller
void SetBankFuncToWallyBufferRunCommand(void);
// recorded opponent controller
void SetBankFuncToRecordedOpponentBufferRunCommand(void);
// link opponent
void SetBankFuncToLinkOpponentBufferRunCommand(void);
// link partner
void SetBankFuncToLinkPartnerBufferRunCommand(void);
#endif // GUARD_BATTLE_CONTROLLERS_H

View File

@ -141,6 +141,7 @@ extern u8 gShouldAdvanceLinkState;
extern struct LinkPlayer gLinkPlayers[];
extern u16 word_3002910[];
extern bool8 gReceivedRemoteLinkPlayers;
extern bool8 gLinkVSyncDisabled;
void Task_DestroySelf(u8);
void OpenLink(void);
@ -183,6 +184,12 @@ bool8 sub_800A520(void);
bool8 sub_8010500(void);
void sub_800DFB4(u8, u8);
void sub_800ADF8(void);
u8 sub_8009FCC(void);
u8 GetLinkPlayerCount(void);
void sub_800B488(void);
void sub_8009734(void);
void sub_800A620(void);
void sub_8011BD0(void);
u8 sub_800ABAC(void);
u8 sub_800ABBC(void);
#endif // GUARD_LINK_H

View File

@ -3,6 +3,7 @@
extern u32 gRecordedBattleRngSeed;
void sub_8184DA4(u8 arg0);
void sub_8185F84(void);
void sub_8184E58(void);
void RecordedBattle_SetBankAction(u8 bank, u8 action);
@ -15,5 +16,6 @@ u8 MoveRecordedBattleToSaveData(void);
void sub_818603C(u8);
void sub_8185FD0(void);
void sub_8186444(void);
void sub_8185EB8(void);
#endif // GUARD_RECORDED_BATTLE_H

View File

@ -54,6 +54,7 @@ SECTIONS {
asm/link.o(.text);
src/rtc.o(.text);
asm/main_menu.o(.text);
src/battle_controllers.o(.text);
asm/rom3.o(.text);
src/decompress.o(.text);
asm/battle_1.o(.text);

View File

@ -207,9 +207,6 @@ extern const u8 BattleScript_ActionSwitch[];
extern const u8 BattleScript_PrintFailedToRunString[];
// functions
extern void HandleLinkBattleSetup(void); // rom_3
extern void SetUpBattleVarsAndBirchZigzagoon(void); // rom_3
extern void sub_8032768(void); // rom_3
extern void dp12_8087EA4(void);
extern void sub_80356D0(void);
extern void GetFrontierTrainerName(u8* dst, u16 trainerId); // battle tower

928
src/battle_controllers.c Normal file
View File

@ -0,0 +1,928 @@
#include "global.h"
#include "battle.h"
#include "battle_controllers.h"
#include "link.h"
#include "task.h"
#include "battle_ai_script_commands.h"
#include "battle_anim.h"
#include "pokemon.h"
#include "species.h"
#include "recorded_battle.h"
#include "util.h"
extern u32 gBattleTypeFlags;
extern u32 gBattleExecBuffer;
extern void (*gBattleMainFunc)(void);
extern void (*gBattleBankFunc[BATTLE_BANKS_COUNT])(void);
extern u8 gBanksByIdentity[BATTLE_BANKS_COUNT];
extern u8 gActionSelectionCursor[BATTLE_BANKS_COUNT];
extern u8 gMoveSelectionCursor[BATTLE_BANKS_COUNT];
extern u8 gNoOfAllBanks;
extern u8 gActiveBank;
extern u8 gUnknown_0202428C;
extern u32 gUnknown_02022FF4;
extern u8 gUnknown_0203C7B4;
extern u16 gBattlePartyID[BATTLE_BANKS_COUNT];
extern u8 gBattleBufferA[BATTLE_BANKS_COUNT][0x200];
extern u8 gBattleBufferB[BATTLE_BANKS_COUNT][0x200];
extern u8 gUnknown_02022D08;
extern u8 gUnknown_02022D09;
extern u8 gUnknown_02022D0A;
extern u8 gBankAttacker;
extern u8 gBankTarget;
extern u8 gAbsentBankFlags;
extern u8 gEffectBank;
extern void task00_08081A90(u8 taskId); // cable_club
extern void sub_81B8D64(u8 bank, u8 arg1); // party_menu
// this file's funcionts
static void sub_8033244(void);
static void SetControllersVariablesInLinkBattle(void);
static void SetControllersVariables(void);
static void sub_8033050(void);
void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data);
static void Task_HandleSendLinkBuffersData(u8 taskId);
static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId);
void HandleLinkBattleSetup(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
if (gLinkVSyncDisabled)
sub_800B488();
if (!gReceivedRemoteLinkPlayers)
sub_8009734();
CreateTask(task00_08081A90, 0);
sub_8033244();
}
}
void SetUpBattleVarsAndBirchZigzagoon(void)
{
s32 i;
gBattleMainFunc = nullsub_20;
for (i = 0; i < BATTLE_BANKS_COUNT; i++)
{
gBattleBankFunc[i] = nullsub_21;
gBanksByIdentity[i] = 0xFF;
gActionSelectionCursor[i] = 0;
gMoveSelectionCursor[i] = 0;
}
HandleLinkBattleSetup();
gBattleExecBuffer = 0;
ClearBattleAnimationVars();
ClearBattleMonForms();
BattleAI_HandleItemUseBeforeAISetup(0xF);
if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE)
{
ZeroEnemyPartyMons();
CreateMon(&gEnemyParty[0], SPECIES_ZIGZAGOON, 2, 32, 0, 0, 0, 0);
i = 0;
SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &i);
}
gUnknown_02022FF4 = 0;
gUnknown_0202428C = 0;
}
void sub_8032768(void)
{
s32 i;
u8 *data;
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
sub_8184DA4(1);
else
sub_8184DA4(2);
if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED))
sub_8185EB8();
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
SetControllersVariablesInLinkBattle();
else
SetControllersVariables();
sub_8033050();
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
{
for (i = 0; i < gNoOfAllBanks; i++)
sub_81B8D64(i, 0);
}
for (i = 0; i < sizeof(gBattleStruct->field_1A4); i++)
*(gBattleStruct->field_1A4 + i) = 0;
for (i = 0; i < sizeof(gBattleStruct->field_204); i++)
*(gBattleStruct->field_204 + i) = 0;
}
static void SetControllersVariables(void)
{
s32 i;
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
{
gBattleMainFunc = BeginBattleIntro;
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
gBattleBankFunc[0] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToPlayerPartnerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
}
else
{
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToPlayerPartnerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
}
gNoOfAllBanks = 4;
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
gBattlePartyID[0] = 0;
gBattlePartyID[1] = 0;
gBattlePartyID[2] = 3;
gBattlePartyID[3] = 3;
}
else if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
gBattleMainFunc = BeginBattleIntro;
if (gBattleTypeFlags & BATTLE_TYPE_SAFARI)
gBattleBankFunc[0] = SetBankFuncToSafariBufferRunCommand;
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL)
gBattleBankFunc[0] = SetBankFuncToWallyBufferRunCommand;
else
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gNoOfAllBanks = 2;
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
if (gBattleTypeFlags & BATTLE_TYPE_x80000000)
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gNoOfAllBanks = 2;
}
else // see how the banks are switched
{
gBattleBankFunc[1] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[0] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_OPPONENT_MON1;
gNoOfAllBanks = 2;
}
}
else
{
gBattleBankFunc[0] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
}
}
}
else
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
gNoOfAllBanks = 4;
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
{
if (gBattleTypeFlags & BATTLE_TYPE_MULTI && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[0] = 0;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = 1;
gBattleBankFunc[2] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[2] = 2;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = 3;
gNoOfAllBanks = 4;
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
gBattlePartyID[0] = 0;
gBattlePartyID[1] = 0;
gBattlePartyID[2] = 3;
gBattlePartyID[3] = 3;
}
else if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
{
u8 var; // multiplayer Id in a recorded battle?
for (var = gUnknown_0203C7B4, i = 0; i < BATTLE_BANKS_COUNT; i++)
{
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
sub_81B8D64(gLinkPlayers[i].lp_field_18, 0);
break;
case 1:
case 2:
sub_81B8D64(gLinkPlayers[i].lp_field_18, 1);
break;
}
if (i == var)
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToRecordedPlayerBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_PLAYER_MON1;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_PLAYER_MON2;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
else if ((!(gLinkPlayers[i].lp_field_18 & 1) && !(gLinkPlayers[var].lp_field_18 & 1))
|| ((gLinkPlayers[i].lp_field_18 & 1) && (gLinkPlayers[var].lp_field_18 & 1)))
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToRecordedPlayerBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_PLAYER_MON1;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_PLAYER_MON2;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
else
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToRecordedOpponentBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_OPPONENT_MON1;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = IDENTITY_OPPONENT_MON2;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
}
}
else if (gBattleTypeFlags & BATTLE_TYPE_WILD)
{
gBattleBankFunc[0] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[2] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
gBattleBankFunc[1] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[3] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
}
else
{
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
}
}
else
{
gBattleBankFunc[1] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[3] = SetBankFuncToRecordedPlayerBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_PLAYER_MON2;
if (gBattleTypeFlags & BATTLE_TYPE_x2000000)
{
gBattleBankFunc[0] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToRecordedOpponentBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_OPPONENT_MON2;
}
else
{
gBattleBankFunc[0] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_OPPONENT_MON2;
}
}
}
}
}
static void SetControllersVariablesInLinkBattle(void)
{
s32 i;
u8 multiplayerId;
if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE))
{
if (gBattleTypeFlags & BATTLE_TYPE_WILD)
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gNoOfAllBanks = 2;
}
else
{
gBattleBankFunc[1] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[0] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_OPPONENT_MON1;
gNoOfAllBanks = 2;
}
}
else if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) && gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{
if (gBattleTypeFlags & BATTLE_TYPE_WILD)
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
gNoOfAllBanks = 4;
}
else
{
gBattleBankFunc[1] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[0] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[3] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[2] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_OPPONENT_MON2;
gNoOfAllBanks = 4;
}
}
else if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
{
if (gBattleTypeFlags & BATTLE_TYPE_WILD)
{
gBattleMainFunc = BeginBattleIntro;
gBattleBankFunc[0] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToLinkPartnerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
gNoOfAllBanks = 4;
}
else
{
gBattleBankFunc[0] = SetBankFuncToLinkPartnerBufferRunCommand;
gBanksByIdentity[0] = IDENTITY_PLAYER_MON1;
gBattleBankFunc[1] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[1] = IDENTITY_OPPONENT_MON1;
gBattleBankFunc[2] = SetBankFuncToPlayerBufferRunCommand;
gBanksByIdentity[2] = IDENTITY_PLAYER_MON2;
gBattleBankFunc[3] = SetBankFuncToLinkOpponentBufferRunCommand;
gBanksByIdentity[3] = IDENTITY_OPPONENT_MON2;
gNoOfAllBanks = 4;
}
sub_81B8D64(0, 0);
sub_81B8D64(1, 0);
sub_81B8D64(2, 1);
sub_81B8D64(3, 1);
gBattlePartyID[0] = 0;
gBattlePartyID[1] = 0;
gBattlePartyID[2] = 3;
gBattlePartyID[3] = 3;
}
else
{
multiplayerId = GetMultiplayerId();
if (gBattleTypeFlags & BATTLE_TYPE_WILD)
gBattleMainFunc = BeginBattleIntro;
for (i = 0; i < BATTLE_BANKS_COUNT; i++)
{
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
sub_81B8D64(gLinkPlayers[i].lp_field_18, 0);
break;
case 1:
case 2:
sub_81B8D64(gLinkPlayers[i].lp_field_18, 1);
break;
}
if (i == multiplayerId)
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToPlayerBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 0;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 2;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
else
{
if ((!(gLinkPlayers[i].lp_field_18 & 1) && !(gLinkPlayers[multiplayerId].lp_field_18 & 1))
|| ((gLinkPlayers[i].lp_field_18 & 1) && (gLinkPlayers[multiplayerId].lp_field_18 & 1)))
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToLinkPartnerBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 0;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 2;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
else
{
gBattleBankFunc[gLinkPlayers[i].lp_field_18] = SetBankFuncToLinkOpponentBufferRunCommand;
switch (gLinkPlayers[i].lp_field_18)
{
case 0:
case 3:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 1;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 0;
break;
case 1:
case 2:
gBanksByIdentity[gLinkPlayers[i].lp_field_18] = 3;
gBattlePartyID[gLinkPlayers[i].lp_field_18] = 3;
break;
}
}
}
}
gNoOfAllBanks = 4;
}
}
static void sub_8033050(void)
{
s32 i, j;
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
{
for (i = 0; i < gNoOfAllBanks; i++)
{
for (j = 0; j < 6; j++)
{
if (i < 2)
{
if (GET_BANK_SIDE2(i) == SIDE_PLAYER)
{
if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0)
{
gBattlePartyID[i] = j;
break;
}
}
else
{
if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0)
{
gBattlePartyID[i] = j;
break;
}
}
}
else
{
if (GET_BANK_SIDE2(i) == SIDE_PLAYER)
{
if (GetMonData(&gPlayerParty[j], MON_DATA_HP) != 0
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES) != SPECIES_NONE // Probably a typo by Game Freak. The rest use SPECIES2.
&& GetMonData(&gPlayerParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gPlayerParty[j], MON_DATA_IS_EGG) == 0
&& gBattlePartyID[i - 2] != j)
{
gBattlePartyID[i] = j;
break;
}
}
else
{
if (GetMonData(&gEnemyParty[j], MON_DATA_HP) != 0
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_NONE
&& GetMonData(&gEnemyParty[j], MON_DATA_SPECIES2) != SPECIES_EGG
&& GetMonData(&gEnemyParty[j], MON_DATA_IS_EGG) == 0
&& gBattlePartyID[i - 2] != j)
{
gBattlePartyID[i] = j;
break;
}
}
}
}
}
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS)
gBattlePartyID[1] = 0, gBattlePartyID[3] = 3;
}
}
void PrepareBufferDataTransfer(u8 bufferId, u8 *data, u16 size)
{
s32 i;
if (gBattleTypeFlags & BATTLE_TYPE_LINK)
{
PrepareBufferDataTransferLink(bufferId, size, data);
}
else
{
switch (bufferId)
{
case 0:
for (i = 0; i < size; i++)
{
gBattleBufferA[gActiveBank][i] = *data;
data++;
}
break;
case 1:
for (i = 0; i < size; i++)
{
gBattleBufferB[gActiveBank][i] = *data;
data++;
}
break;
}
}
}
static void sub_8033244(void)
{
gUnknown_02022D08 = CreateTask(Task_HandleSendLinkBuffersData, 0);
gTasks[gUnknown_02022D08].data[11] = 0;
gTasks[gUnknown_02022D08].data[12] = 0;
gTasks[gUnknown_02022D08].data[13] = 0;
gTasks[gUnknown_02022D08].data[14] = 0;
gTasks[gUnknown_02022D08].data[15] = 0;
gUnknown_02022D09 = CreateTask(Task_HandleCopyReceivedLinkBuffersData, 0);
gTasks[gUnknown_02022D09].data[12] = 0;
gTasks[gUnknown_02022D09].data[13] = 0;
gTasks[gUnknown_02022D09].data[14] = 0;
gTasks[gUnknown_02022D09].data[15] = 0;
gUnknown_02022D0A = 0;
}
enum
{
LINK_BUFF_BUFFER_ID,
LINK_BUFF_ACTIVE_BANK,
LINK_BUFF_ATTACKER,
LINK_BUFF_TARGET,
LINK_BUFF_SIZE_LO,
LINK_BUFF_SIZE_HI,
LINK_BUFF_ABSENT_BANK_FLAGS,
LINK_BUFF_EFFECT_BANK,
LINK_BUFF_DATA
};
void PrepareBufferDataTransferLink(u8 bufferId, u16 size, u8 *data)
{
s32 alignedSize;
s32 i;
alignedSize = size - size % 4 + 4;
if (gTasks[gUnknown_02022D08].data[14] + alignedSize + LINK_BUFF_DATA + 1 > BATTLE_BUFFER_LINK_SIZE)
{
gTasks[gUnknown_02022D08].data[12] = gTasks[gUnknown_02022D08].data[14];
gTasks[gUnknown_02022D08].data[14] = 0;
}
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_BUFFER_ID] = bufferId;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_ACTIVE_BANK] = gActiveBank;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_ATTACKER] = gBankAttacker;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_TARGET] = gBankTarget;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_SIZE_LO] = alignedSize;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_SIZE_HI] = (alignedSize & 0x0000FF00) >> 8;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_ABSENT_BANK_FLAGS] = gAbsentBankFlags;
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_EFFECT_BANK] = gEffectBank;
for (i = 0; i < size; i++)
gLinkBattleSendBuffer[gTasks[gUnknown_02022D08].data[14] + LINK_BUFF_DATA + i] = data[i];
gTasks[gUnknown_02022D08].data[14] = gTasks[gUnknown_02022D08].data[14] + alignedSize + LINK_BUFF_DATA;
}
static void Task_HandleSendLinkBuffersData(u8 taskId)
{
u16 var;
u16 blockSize;
switch (gTasks[taskId].data[11])
{
case 0:
gTasks[taskId].data[10] = 100;
gTasks[taskId].data[11]++;
break;
case 1:
gTasks[taskId].data[10]--;
if (gTasks[taskId].data[10] == 0)
gTasks[taskId].data[11]++;
break;
case 2:
if (gLinkVSyncDisabled)
{
gTasks[taskId].data[11]++;
}
else
{
if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
var = 2;
else
var = (gBattleTypeFlags & BATTLE_TYPE_MULTI) ? 4 : 2;
if (sub_800ABAC() >= var)
{
if (sub_800ABBC())
{
sub_800A620();
gTasks[taskId].data[11]++;
}
else
{
gTasks[taskId].data[11]++;
}
}
}
break;
case 3:
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
{
if (gTasks[taskId].data[13] == 0)
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
}
blockSize = (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8)) + LINK_BUFF_DATA;
SendBlock(bitmask_all_link_players_but_self(), &gLinkBattleSendBuffer[gTasks[taskId].data[15]], blockSize);
gTasks[taskId].data[11]++;
}
else
{
gTasks[taskId].data[13]--;
break;
}
}
break;
case 4:
if (sub_800A520())
{
blockSize = gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleSendBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8);
gTasks[taskId].data[13] = 1;
gTasks[taskId].data[15] = gTasks[taskId].data[15] + blockSize + LINK_BUFF_DATA;
gTasks[taskId].data[11] = 3;
}
break;
case 5:
gTasks[taskId].data[13]--;
if (gTasks[taskId].data[13] == 0)
{
gTasks[taskId].data[13] = 1;
gTasks[taskId].data[11] = 3;
}
break;
}
}
// fix me
void sub_8033648(void)
{
u8 i;
s32 j;
u16 r6;
u8 *recvBuffer;
u8 *dest;
u8 *src;
if (gReceivedRemoteLinkPlayers != 0 && (gBattleTypeFlags & BATTLE_TYPE_20))
{
sub_8011BD0();
for (i = 0; i < GetLinkPlayerCount(); i++)
{
if (GetBlockReceivedStatus() & gBitTable[i])
{
ResetBlockReceivedFlag(i);
recvBuffer = (u8 *)gBlockRecvBuffer[i];
#ifndef NONMATCHING
asm("");
recvBuffer = (u8 *)&gBlockRecvBuffer[i];
#endif
r6 = gBlockRecvBuffer[i][2];
if (gTasks[gUnknown_02022D09].data[14] + 9 + r6 > 0x1000)
{
gTasks[gUnknown_02022D09].data[12] = gTasks[gUnknown_02022D09].data[14];
gTasks[gUnknown_02022D09].data[14] = 0;
}
dest = &gLinkBattleRecvBuffer[gTasks[gUnknown_02022D09].data[14]];
src = recvBuffer;
for (j = 0; j < r6 + 8; j++)
dest[j] = src[j];
gTasks[gUnknown_02022D09].data[14] = gTasks[gUnknown_02022D09].data[14] + r6 + 8;
}
}
}
}
static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId)
{
u16 blockSize;
u8 bank;
u8 var;
if (gTasks[taskId].data[15] != gTasks[taskId].data[14])
{
if (gTasks[taskId].data[15] > gTasks[taskId].data[14]
&& gTasks[taskId].data[15] == gTasks[taskId].data[12])
{
gTasks[taskId].data[12] = 0;
gTasks[taskId].data[15] = 0;
}
bank = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_ACTIVE_BANK];
blockSize = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_LO] | (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_SIZE_HI] << 8);
switch (gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 0])
{
case 0:
if (gBattleExecBuffer & gBitTable[bank])
return;
memcpy(gBattleBufferA[bank], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 8], blockSize);
sub_803F850(bank);
if (!(gBattleTypeFlags & BATTLE_TYPE_WILD))
{
gBankAttacker = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 2];
gBankTarget = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 3];
gAbsentBankFlags = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 6];
gEffectBank = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 7];
}
break;
case 1:
memcpy(gBattleBufferB[bank], &gLinkBattleRecvBuffer[gTasks[taskId].data[15] + 8], blockSize);
break;
case 2:
var = gLinkBattleRecvBuffer[gTasks[taskId].data[15] + LINK_BUFF_DATA];
gBattleExecBuffer &= ~(gBitTable[bank] << (var * 4));
break;
}
gTasks[taskId].data[15] = gTasks[taskId].data[15] + blockSize + LINK_BUFF_DATA;
}
}

View File

@ -353,7 +353,7 @@ void sub_803F850(u8 arg0)
{
s32 i;
for (i = 0; i < sub_8009FCC(); i++)
for (i = 0; i < GetLinkPlayerCount(); i++)
gBattleExecBuffer |= gBitTable[arg0] << (i << 2);
gBattleExecBuffer &= ~(0x10000000 << arg0);

View File

@ -282,7 +282,7 @@ gNoOfAllBanks: @ 202406C
gBattlePartyID: @ 202406E
.space 0x8
gBanksBySide: @ 2024076
gBanksByIdentity: @ 2024076
.space 0x4
gActionsByTurnOrder: @ 202407A
@ -471,10 +471,10 @@ gBattleScripting: @ 2024474
gBattleStruct: @ 202449C
.space 0x4
gUnknown_020244A0: @ 20244A0
gLinkBattleSendBuffer: @ 20244A0
.space 0x4
gUnknown_020244A4: @ 20244A4
gLinkBattleRecvBuffer: @ 20244A4
.space 0x4
gBattleResources: @ 20244A8