From e6635c70037dcf9830af3ea7fd364bed941b581c Mon Sep 17 00:00:00 2001 From: citrusbolt Date: Sat, 2 Mar 2024 15:26:27 -0700 Subject: [PATCH] Document more of `unk_200C5DC.c` --- payload/include/all.h | 6 +- payload/include/gba/io_reg.h | 9 ++ payload/include/unk_200C5DC.h | 25 +++- payload/src/all.c | 210 +++++++++++++++++----------------- payload/src/all4.c | 8 +- payload/src/main.c | 19 +-- payload/src/unk_200C5DC.c | 195 +++++++++++++++---------------- 7 files changed, 249 insertions(+), 223 deletions(-) diff --git a/payload/include/all.h b/payload/include/all.h index e8adcca..ae5bb05 100644 --- a/payload/include/all.h +++ b/payload/include/all.h @@ -34,7 +34,7 @@ struct MonData u32 setMailTo1:1; u32 preserveHeldItem:1; u32 heldItem:16; // 0x28 - u16 unk2A; + u16 unused; u16 moves[MAX_MON_MOVES]; // 0x2C , 0x2E , 0x30, 0x32 u8 pps[MAX_MON_MOVES]; // 0x34-0x37 u8 textBuffer[320]; @@ -46,7 +46,7 @@ struct MonLinkData u32 unk_03_0:7; u32 unk_03_7:1; u32 unk4:24; - u32 unk7:8; + u32 monCount:8; u32 personality; u32 otId; u16 species; @@ -71,7 +71,7 @@ struct MonLinkData u32 unk850_2:24; u32 *monPtr; u8 unk_858; - u8 unk_859; + u8 numMonsToSelect; u8 unk_85A; u8 species3; // Only 1 byte, so can not contain a Hoenn species u8 ALIGNED(4) giftRibbons[GIFT_RIBBONS_COUNT + 1]; // Aligned for u32 copy diff --git a/payload/include/gba/io_reg.h b/payload/include/gba/io_reg.h index f0bbec1..a2dada6 100644 --- a/payload/include/gba/io_reg.h +++ b/payload/include/gba/io_reg.h @@ -699,6 +699,15 @@ #define SIO_MULTI_DI_SHIFT 3 #define SIO_MULTI_DI_MASK 0x1 +// joy bus +#define JOYCNT_RESET (1 << 0) +#define JOYCNT_RECV_CMPLT (1 << 1) +#define JOYCNT_TRAN_CMPLT (1 << 2) +#define JOYCNT_RESET_IRQ (1 << 6) + +#define RCNT_JOYBUS1 (1 << 14) +#define RCNT_JOYBUS2 (1 << 15) + // keys #define A_BUTTON 0x0001 #define B_BUTTON 0x0002 diff --git a/payload/include/unk_200C5DC.h b/payload/include/unk_200C5DC.h index 8a90ae1..bcf1789 100644 --- a/payload/include/unk_200C5DC.h +++ b/payload/include/unk_200C5DC.h @@ -6,6 +6,21 @@ #define LOBBY_SAVEWARP (1 << 2) #define CHAMPION_SAVEWARP (1 << 7) +#define LINK_CMD_RESET 0x00 +#define LINK_CMD_0x01 0x01 +#define LINK_CMD_TRAN_PLAYER_DATA2 0x04 +#define LINK_CMD_RECV_GIFT_DATA 0x22 +#define LINK_CMD_TRAN_GIFT_DATA 0x33 +#define LINK_CMD_0x44 0x44 +#define LINK_CMD_RECV_PARTY_MON 0x55 +#define LINK_CMD_SOFT_RESET_ROM 0x60 +#define LINK_CMD_SOFT_RESET 0x61 +#define LINK_CMD_RECV_MON_DATA 0x66 +#define LINK_CMD_RECV_UNKNOWN 0x77 +#define LINK_CMD_RECV_TEXT 0x88 +#define LINK_CMD_TRAN_PLAYER_DATA1 0x99 +#define LINK_CMD_READ_INPUT 0xAA + struct TransferData { volatile u32 *data; @@ -18,7 +33,7 @@ struct TransferData u8 field14; u8 field15; u8 field16; - u8 field17; + u8 currentCmd; u8 field18; u8 fill19; u8 field20; @@ -30,11 +45,11 @@ struct TransferData u8 fill26; u8 fill27; u32 transferBytes; - u32 field32; + u32 gameCode; u32 field36; - u32 field40; - u32 field44; - u32 field48; + u32 lowerCaseGameCode; + u32 gameCode2; + u32 makerCode; }; extern volatile struct TransferData gTransferData; diff --git a/payload/src/all.c b/payload/src/all.c index 83333fd..f2587ab 100644 --- a/payload/src/all.c +++ b/payload/src/all.c @@ -64,7 +64,7 @@ struct Unk02021860Struct u8 unk118; u8 unk119; u8 unk11A; - u8 unk11B; + u8 selectedMon; u8 filler11C; u8 filler11D; u8 unk11E; @@ -72,8 +72,8 @@ struct Unk02021860Struct u8 unk120; u8 unk121; u8 unk122; - u8 unk123; - u8 unk124; + u8 numMonsToSelect; + u8 numMonsLeftToSelect; u8 unk125; }; @@ -651,7 +651,7 @@ void CreateMonIcon(struct Sprite *sprite) r1 = sprite->data[2] & 1; CopyMonIconToVram(ptr, r1); SetSpritePos(sprite, ptr->unk1, ptr->unk2); - if (gUnknown_02021860.unk11B == ptr->monId) + if (gUnknown_02021860.selectedMon == ptr->monId) { if (gUnknown_02021860.unk121 == 4) AddSpritePos(sprite, 0, -gUnknown_02021860.unk121); @@ -672,10 +672,10 @@ void sub_02000BFC(void) struct Window *win; s32 i; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { struct UnkSpriteMonIconStruct *ptr = &gUnknown_02021860.unk0[i]; - if (ptr->unk22 == gUnknown_02021860.unk124) + if (ptr->unk22 == gUnknown_02021860.numMonsLeftToSelect) { ptr->unk22 = 0; win = ptr->win; @@ -692,8 +692,8 @@ void sub_02000BFC(void) TextWindowSetXY(win, 0, 2); RenderText(win, gText_Number); } - gUnknown_02021860.unk124--; - gUnknown_02021860.unk11B = i; + gUnknown_02021860.numMonsLeftToSelect--; + gUnknown_02021860.selectedMon = i; break; } } @@ -744,12 +744,12 @@ void sub_02000D74(struct Unk02021860Struct *a0, const struct Unk02000D74Struct * CopyToBgTilemapBufferRect(3, coords->x, coords->y, r5->unk0, r5->unk1, (u16 *) (VRAM + 0x14000) + r5->unk2); if (r9->statusPrimary != STATUS_PRIMARY_FAINTED) { - if (a0->unk11B == monId) + if (a0->selectedMon == monId) SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 7); } else { - if (a0->unk11B == monId) + if (a0->selectedMon == monId) SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 9); else SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 5); @@ -836,12 +836,12 @@ void sub_02001258(struct Unk02021860Struct *a0, const struct Unk02000D74Struct * CopyToBgTilemapBufferRect(3, coords->x, coords->y, r5->unk0, r5->unk1, (u16 *) (VRAM + 0x14000) + r5->unk2); if (r9->statusPrimary != STATUS_PRIMARY_FAINTED) { - if (a0->unk11B == monId) + if (a0->selectedMon == monId) SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 7); } else { - if (a0->unk11B == monId) + if (a0->selectedMon == monId) SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 9); else SetBgTilemapBufferPaletteRect(3, coords->x, coords->y, r5->unk0, r5->unk1, 5); @@ -916,12 +916,12 @@ void sub_02001738(u32 selectMonsTextId) gUnknown_02021860.unk108 = AddWindow(0, &gUnknown_0201F8B0); SetTextColor(gUnknown_02021860.unk108, 1, 8); ClearWindowCharBuffer(gUnknown_02021860.unk108, 0xFFFF); - if (gUnknown_02021860.unk123 != 0) + if (gUnknown_02021860.numMonsToSelect != 0) { switch (selectMonsTextId) { case 0: - text[0] = gUnknown_02021860.unk123 + CHAR_0; + text[0] = gUnknown_02021860.numMonsToSelect + CHAR_0; text[1] = EOS; BufferString(0, text); RenderText(gUnknown_02021860.unk108, gText_SelectNumberPokemon); @@ -1120,38 +1120,38 @@ s32 sub_02001A8C(u32 monId) } else { - if (IsMonFainted(gUnknown_02021860.unk11B) == TRUE) + if (IsMonFainted(gUnknown_02021860.selectedMon) == TRUE) { PlaySE(SONG_SE_FAILURE); - sub_020019B4(gUnknown_02021860.unk11B, 10); + sub_020019B4(gUnknown_02021860.selectedMon, 10); i = 2; } - else if (gUnknown_02021860.unk122 == gUnknown_02021860.unk11B) + else if (gUnknown_02021860.unk122 == gUnknown_02021860.selectedMon) { PlaySE(SONG_SE_FAILURE); - sub_020019B4(gUnknown_02021860.unk11B, 11); + sub_020019B4(gUnknown_02021860.selectedMon, 11); i = 2; } else { - switch (sub_020064BC(gMonLinkData.unk4, gUnknown_02021860.unk11B)) + switch (sub_020064BC(gMonLinkData.unk4, gUnknown_02021860.selectedMon)) { case 0: PlaySE(SONG_SE_SELECT); - gMonLinkData.unk_87E = gUnknown_02021860.unk11B; + gMonLinkData.unk_87E = gUnknown_02021860.selectedMon; gMonLinkData.unk_87B = 2; return -1; case 1: PlaySE(SONG_SE_FAILURE); - sub_020019B4(gUnknown_02021860.unk11B, 13); + sub_020019B4(gUnknown_02021860.selectedMon, 13); break; case 2: PlaySE(SONG_SE_FAILURE); - sub_020019B4(gUnknown_02021860.unk11B, 11); + sub_020019B4(gUnknown_02021860.selectedMon, 11); break; case 3: PlaySE(SONG_SE_FAILURE); - sub_020019B4(gUnknown_02021860.unk11B, 12); + sub_020019B4(gUnknown_02021860.selectedMon, 12); break; } i = 2; @@ -1161,13 +1161,13 @@ s32 sub_02001A8C(u32 monId) case 4: PlaySE(SONG_SE_SELECT); FadeOut(); - gUnknown_02021860.unk11B = sub_020044F0(gUnknown_02021860.unk11B); - monId = gUnknown_02021860.unk11B; + gUnknown_02021860.selectedMon = sub_020044F0(gUnknown_02021860.selectedMon); + monId = gUnknown_02021860.selectedMon; if (gUnknown_02021860.unk11A == 1) { - if (gUnknown_02021860.unk11B == 0) + if (gUnknown_02021860.selectedMon == 0) gUnknown_02021860.unk11E = 2; - else if (gUnknown_02021860.unk11B == 1) + else if (gUnknown_02021860.selectedMon == 1) gUnknown_02021860.unk11E = 4; } sub_020017E8(&gUnknown_02021860); @@ -1274,7 +1274,7 @@ s32 sub_02001F04(s32 ret) case 3: if (var_24->unk22 == 0) { - if (gUnknown_02021860.unk124 == gUnknown_02021860.unk123) + if (gUnknown_02021860.numMonsLeftToSelect == gUnknown_02021860.numMonsToSelect) { PlaySE(SONG_SE_FAILURE); i = 1; @@ -1282,11 +1282,11 @@ s32 sub_02001F04(s32 ret) else { PlaySE(SONG_SE_SELECT); - var_24->unk22 = ++gUnknown_02021860.unk124; + var_24->unk22 = ++gUnknown_02021860.numMonsLeftToSelect; sub_02002EE0(var_24->win, var_24); REG_JOY_TRANS = 0x1000000; - if (gUnknown_02021860.unk124 == gUnknown_02021860.unk123) - gUnknown_02021860.unk11B = 6; + if (gUnknown_02021860.numMonsLeftToSelect == gUnknown_02021860.numMonsToSelect) + gUnknown_02021860.selectedMon = 6; i = 2; } } @@ -1303,23 +1303,23 @@ s32 sub_02001F04(s32 ret) var_24->unk22 = 0; sub_02002EE0(var_24->win, var_24); REG_JOY_TRANS = 0xFF000000; - gUnknown_02021860.unk124--; + gUnknown_02021860.numMonsLeftToSelect--; i = 2; } break; case 4: PlaySE(SONG_SE_SELECT); FadeOut(); - gUnknown_02021860.unk11B = sub_020044F0(gUnknown_02021860.unk11B); + gUnknown_02021860.selectedMon = sub_020044F0(gUnknown_02021860.selectedMon); if (gUnknown_02021860.unk11A == 1) { - if (gUnknown_02021860.unk11B == 0) + if (gUnknown_02021860.selectedMon == 0) gUnknown_02021860.unk11E = 2; - else if (gUnknown_02021860.unk11B == 1) + else if (gUnknown_02021860.selectedMon == 1) gUnknown_02021860.unk11E = 4; } sub_020017E8(&gUnknown_02021860); - ret = gUnknown_02021860.unk11B; + ret = gUnknown_02021860.selectedMon; var_24 = &gUnknown_02021860.unk0[ret]; i = 0; break; @@ -1360,7 +1360,7 @@ s32 sub_020023E8(void) } if (keys & A_BUTTON) { - if (gUnknown_02021860.unk11B == PARTY_SIZE) + if (gUnknown_02021860.selectedMon == PARTY_SIZE) { if (gUnknown_02021860.unk125 == 0) { @@ -1378,67 +1378,67 @@ s32 sub_020023E8(void) s32 var = 0; PlaySE(SONG_SE_SELECT); - var = sub_02001A8C(gUnknown_02021860.unk11B); + var = sub_02001A8C(gUnknown_02021860.selectedMon); if (var == -1) return -1; } } - monId = gUnknown_02021860.unk11B; + monId = gUnknown_02021860.selectedMon; if (keys & DPAD_UP) { PlaySE(SONG_SE_SELECT); - if (gUnknown_02021860.unk11B == 0) - gUnknown_02021860.unk11B = PARTY_SIZE; - else if (gUnknown_02021860.unk11B == PARTY_SIZE) - gUnknown_02021860.unk11B = gUnknown_02021860.unk120; + if (gUnknown_02021860.selectedMon == 0) + gUnknown_02021860.selectedMon = PARTY_SIZE; + else if (gUnknown_02021860.selectedMon == PARTY_SIZE) + gUnknown_02021860.selectedMon = gUnknown_02021860.unk120; else - gUnknown_02021860.unk11B--; - gUnknown_02021860.unk11E = r9[gUnknown_02021860.unk11B].a2; + gUnknown_02021860.selectedMon--; + gUnknown_02021860.unk11E = r9[gUnknown_02021860.selectedMon].a2; } if (keys & DPAD_DOWN) { PlaySE(SONG_SE_SELECT); - if (gUnknown_02021860.unk11B == gUnknown_02021860.unk120) - gUnknown_02021860.unk11B = PARTY_SIZE; - else if (gUnknown_02021860.unk11B == PARTY_SIZE) - gUnknown_02021860.unk11B = 0; + if (gUnknown_02021860.selectedMon == gUnknown_02021860.unk120) + gUnknown_02021860.selectedMon = PARTY_SIZE; + else if (gUnknown_02021860.selectedMon == PARTY_SIZE) + gUnknown_02021860.selectedMon = 0; else - gUnknown_02021860.unk11B++; - gUnknown_02021860.unk11E = r9[gUnknown_02021860.unk11B].a2; + gUnknown_02021860.selectedMon++; + gUnknown_02021860.unk11E = r9[gUnknown_02021860.selectedMon].a2; } if (keys & DPAD_LEFT) { PlaySE(SONG_SE_SELECT); - if (r9[gUnknown_02021860.unk11B].a1 != 0xFF) + if (r9[gUnknown_02021860.selectedMon].a1 != 0xFF) { - gUnknown_02021860.unk11E = gUnknown_02021860.unk11B; - gUnknown_02021860.unk11B = r9[gUnknown_02021860.unk11B].a1; + gUnknown_02021860.unk11E = gUnknown_02021860.selectedMon; + gUnknown_02021860.selectedMon = r9[gUnknown_02021860.selectedMon].a1; } } if (keys & DPAD_RIGHT) { PlaySE(SONG_SE_SELECT); - switch (r9[gUnknown_02021860.unk11B].a0) + switch (r9[gUnknown_02021860.selectedMon].a0) { case 0xFF: break; case 7: - gUnknown_02021860.unk11B = gUnknown_02021860.unk11E; - if (gUnknown_02021860.unk11B > gUnknown_02021860.unk120) + gUnknown_02021860.selectedMon = gUnknown_02021860.unk11E; + if (gUnknown_02021860.selectedMon > gUnknown_02021860.unk120) { - gUnknown_02021860.unk11B = gUnknown_02021860.unk120; - if (gUnknown_02021860.unk11A == 1 && gUnknown_02021860.unk11B == 1 && monId == 0) - gUnknown_02021860.unk11B = monId; + gUnknown_02021860.selectedMon = gUnknown_02021860.unk120; + if (gUnknown_02021860.unk11A == 1 && gUnknown_02021860.selectedMon == 1 && monId == 0) + gUnknown_02021860.selectedMon = monId; } break; default: - gUnknown_02021860.unk11B = r9[gUnknown_02021860.unk11B].a0; + gUnknown_02021860.selectedMon = r9[gUnknown_02021860.selectedMon].a0; break; } } - if (monId == gUnknown_02021860.unk11B) + if (monId == gUnknown_02021860.selectedMon) continue; if (monId != PARTY_SIZE) @@ -1455,11 +1455,11 @@ s32 sub_020023E8(void) SetBgTilemapBufferPaletteRect(1, 24, 18, 6, 2, 1); } - if (gUnknown_02021860.unk11B != PARTY_SIZE) + if (gUnknown_02021860.selectedMon != PARTY_SIZE) { - r4 = &var_24[gUnknown_02021860.unk11B]; + r4 = &var_24[gUnknown_02021860.selectedMon]; r5 = &gUnknown_0201F9B0[r4->a2]; - if (GetMonStatus(&gPlayerPartyPtr[gUnknown_02021860.unk11B]) != STATUS_PRIMARY_FAINTED) + if (GetMonStatus(&gPlayerPartyPtr[gUnknown_02021860.selectedMon]) != STATUS_PRIMARY_FAINTED) SetBgTilemapBufferPaletteRect(3, r4->a0, r4->a1, r5->unk0, r5->unk1, 7); else SetBgTilemapBufferPaletteRect(3, r4->a0, r4->a1, r5->unk0, r5->unk1, 9); @@ -1496,7 +1496,7 @@ inline void sub_02002F60(void) u32 bits = 0; u32 r6 = 0; - for (i = 1; i < gUnknown_02021860.unk124 + 1; i++) + for (i = 1; i < gUnknown_02021860.numMonsLeftToSelect + 1; i++) { s32 ret = sub_02002F38(i); if (ret != -1) @@ -1523,10 +1523,10 @@ s32 sub_020026F4(void) if (keys == 0) continue; - monId = gUnknown_02021860.unk11B; + monId = gUnknown_02021860.selectedMon; if (keys & B_BUTTON) { - if (gUnknown_02021860.unk124 != 0) + if (gUnknown_02021860.numMonsLeftToSelect != 0) { sub_02000BFC(); PlaySE(SONG_SE_SELECT); @@ -1540,9 +1540,9 @@ s32 sub_020026F4(void) } if (keys & A_BUTTON) { - if (gUnknown_02021860.unk11B == PARTY_SIZE) + if (gUnknown_02021860.selectedMon == PARTY_SIZE) { - if (gUnknown_02021860.unk124 != gUnknown_02021860.unk123) + if (gUnknown_02021860.numMonsLeftToSelect != gUnknown_02021860.numMonsToSelect) { PlaySE(SONG_SE_FAILURE); sub_02001738(1); @@ -1556,7 +1556,7 @@ s32 sub_020026F4(void) } else { - s32 var = sub_02001F04(gUnknown_02021860.unk11B); + s32 var = sub_02001F04(gUnknown_02021860.selectedMon); if (var == -1) return -1; else if (var != monId) @@ -1567,57 +1567,57 @@ s32 sub_020026F4(void) if (keys & DPAD_UP) { PlaySE(SONG_SE_SELECT); - if (gUnknown_02021860.unk11B == 0) - gUnknown_02021860.unk11B = PARTY_SIZE; - else if (gUnknown_02021860.unk11B == PARTY_SIZE) - gUnknown_02021860.unk11B = gUnknown_02021860.unk120; + if (gUnknown_02021860.selectedMon == 0) + gUnknown_02021860.selectedMon = PARTY_SIZE; + else if (gUnknown_02021860.selectedMon == PARTY_SIZE) + gUnknown_02021860.selectedMon = gUnknown_02021860.unk120; else - gUnknown_02021860.unk11B--; - gUnknown_02021860.unk11E = r9[gUnknown_02021860.unk11B].a2; + gUnknown_02021860.selectedMon--; + gUnknown_02021860.unk11E = r9[gUnknown_02021860.selectedMon].a2; } if (keys & DPAD_DOWN) { PlaySE(SONG_SE_SELECT); - if (gUnknown_02021860.unk11B == gUnknown_02021860.unk120) - gUnknown_02021860.unk11B = PARTY_SIZE; - else if (gUnknown_02021860.unk11B == PARTY_SIZE) - gUnknown_02021860.unk11B = 0; + if (gUnknown_02021860.selectedMon == gUnknown_02021860.unk120) + gUnknown_02021860.selectedMon = PARTY_SIZE; + else if (gUnknown_02021860.selectedMon == PARTY_SIZE) + gUnknown_02021860.selectedMon = 0; else - gUnknown_02021860.unk11B++; - gUnknown_02021860.unk11E = r9[gUnknown_02021860.unk11B].a2; + gUnknown_02021860.selectedMon++; + gUnknown_02021860.unk11E = r9[gUnknown_02021860.selectedMon].a2; } if (keys & DPAD_LEFT) { PlaySE(SONG_SE_SELECT); - if (r9[gUnknown_02021860.unk11B].a1 != 0xFF) + if (r9[gUnknown_02021860.selectedMon].a1 != 0xFF) { - gUnknown_02021860.unk11E = gUnknown_02021860.unk11B; - gUnknown_02021860.unk11B = r9[gUnknown_02021860.unk11B].a1; + gUnknown_02021860.unk11E = gUnknown_02021860.selectedMon; + gUnknown_02021860.selectedMon = r9[gUnknown_02021860.selectedMon].a1; } } if (keys & DPAD_RIGHT) { PlaySE(SONG_SE_SELECT); - switch (r9[gUnknown_02021860.unk11B].a0) + switch (r9[gUnknown_02021860.selectedMon].a0) { case 0xFF: break; case 7: - gUnknown_02021860.unk11B = gUnknown_02021860.unk11E; - if (gUnknown_02021860.unk11B > gUnknown_02021860.unk120) + gUnknown_02021860.selectedMon = gUnknown_02021860.unk11E; + if (gUnknown_02021860.selectedMon > gUnknown_02021860.unk120) { - gUnknown_02021860.unk11B = gUnknown_02021860.unk120; - if (gUnknown_02021860.unk11A == 1 && gUnknown_02021860.unk11B == 1 && monId == 0) - gUnknown_02021860.unk11B = monId; + gUnknown_02021860.selectedMon = gUnknown_02021860.unk120; + if (gUnknown_02021860.unk11A == 1 && gUnknown_02021860.selectedMon == 1 && monId == 0) + gUnknown_02021860.selectedMon = monId; } break; default: - gUnknown_02021860.unk11B = r9[gUnknown_02021860.unk11B].a0; + gUnknown_02021860.selectedMon = r9[gUnknown_02021860.selectedMon].a0; break; } } - if (monId == gUnknown_02021860.unk11B) + if (monId == gUnknown_02021860.selectedMon) continue; if (monId != PARTY_SIZE) @@ -1634,11 +1634,11 @@ s32 sub_020026F4(void) SetBgTilemapBufferPaletteRect(1, 24, 18, 6, 2, 1); } - if (gUnknown_02021860.unk11B != PARTY_SIZE) + if (gUnknown_02021860.selectedMon != PARTY_SIZE) { - r4 = &var_24[gUnknown_02021860.unk11B]; + r4 = &var_24[gUnknown_02021860.selectedMon]; r5 = &gUnknown_0201F9B0[r4->a2]; - if (GetMonStatus(&gPlayerPartyPtr[gUnknown_02021860.unk11B]) != STATUS_PRIMARY_FAINTED) + if (GetMonStatus(&gPlayerPartyPtr[gUnknown_02021860.selectedMon]) != STATUS_PRIMARY_FAINTED) SetBgTilemapBufferPaletteRect(3, r4->a0, r4->a1, r5->unk0, r5->unk1, 7); else SetBgTilemapBufferPaletteRect(3, r4->a0, r4->a1, r5->unk0, r5->unk1, 9); @@ -1667,7 +1667,7 @@ void sub_02002A9C(s32 a0, u32 a1, u32 a2) u32 status; gUnknown_02021860.unk122 = a1; - gUnknown_02021860.unk11B = 0; + gUnknown_02021860.selectedMon = 0; gUnknown_02021860.unk125 = a2; gUnknown_02021860.unk11A = 0; @@ -1685,7 +1685,7 @@ void sub_02002A9C(s32 a0, u32 a1, u32 a2) { case 0: gUnknown_02021860.unk118 = 0; - gUnknown_02021860.unk123 = 0; + gUnknown_02021860.numMonsToSelect = 0; sub_020017E8(&gUnknown_02021860); FadeIn(); sub_020023E8(); @@ -1693,10 +1693,10 @@ void sub_02002A9C(s32 a0, u32 a1, u32 a2) break; case 1: gUnknown_02021860.unk118 = 1; - gUnknown_02021860.unk123 = gMonLinkData.unk_859; - if (gUnknown_02021860.unk123 == 0 || gUnknown_02021860.unk123 > *gPlayerPartyCountPtr) - gUnknown_02021860.unk123 = *gPlayerPartyCountPtr; - gUnknown_02021860.unk124 = 0; + gUnknown_02021860.numMonsToSelect = gMonLinkData.numMonsToSelect; + if (gUnknown_02021860.numMonsToSelect == 0 || gUnknown_02021860.numMonsToSelect > *gPlayerPartyCountPtr) + gUnknown_02021860.numMonsToSelect = *gPlayerPartyCountPtr; + gUnknown_02021860.numMonsLeftToSelect = 0; for (i = 0; i < PARTY_SIZE; i++) { gUnknown_02021860.unk0[i].unk22 = 0; @@ -1919,13 +1919,13 @@ void sub_02002C44(void) { CpuFill16(0, &gUnknown_02021860, sizeof(gUnknown_02021860)); gUnknown_02021860.unk11A = 0; - gUnknown_02021860.unk11B = 0; + gUnknown_02021860.selectedMon = 0; gUnknown_02021860.unk11E = 1; } void sub_02002C80(void) { - gUnknown_02021860.unk11B = 0; + gUnknown_02021860.selectedMon = 0; if (gUnknown_02021860.unk11A == 0) gUnknown_02021860.unk11E = 1; else diff --git a/payload/src/all4.c b/payload/src/all4.c index 9354500..725dc3a 100644 --- a/payload/src/all4.c +++ b/payload/src/all4.c @@ -141,7 +141,7 @@ u32 sub_020047D4(void) else ClearWindowCharBuffer(gMessageWindowPtr, 0xFFFF); - gMonLinkData.unk_859 = 0; + gMonLinkData.numMonsToSelect = 0; gMonLinkData.transferComplete = 0; gMonLinkData.unk_87A = 0; gMonLinkData.unk84C_00 = 0; @@ -169,7 +169,7 @@ u32 sub_020047D4(void) while (r5 == 0) { DelayFrames(1); - if (gMonLinkData.unk_859 != 0 && GetUnknownBoolean() == 1) + if (gMonLinkData.numMonsToSelect != 0 && GetUnknownBoolean() == 1) r5 = 2; if (gMonLinkData.unk84C_00 == 1) { @@ -672,7 +672,7 @@ s32 sub_02005468(void) ClearWindowCharBuffer(gUnknown_02021A20.unk18, 0xFFFF); StringCopy(gStringBuffers[0], sub_0200531C(0)); StringCopy(gStringBuffers[1], sub_0200531C(1)); - if (gMonLinkData.unk7 == 4) + if (gMonLinkData.monCount == 4) { StringCopy(gStringBuffers[2], sub_0200531C(2)); StringCopy(gStringBuffers[3], sub_0200531C(3)); @@ -685,7 +685,7 @@ s32 sub_02005468(void) sub_02004F04(gUnknown_02021A20.unk18, gUnknown_0201FDF4, 4); gBgTilemapBufferTransferScheduled[3] = TRUE; gBgTilemapBufferTransferScheduled[2] = TRUE; - return gMonLinkData.unk7; + return gMonLinkData.monCount; } s32 sub_02005548(void) diff --git a/payload/src/main.c b/payload/src/main.c index f119d94..b532d08 100644 --- a/payload/src/main.c +++ b/payload/src/main.c @@ -19,11 +19,12 @@ struct RomHeader { - u8 a0[0xA8]; - u8 unkA8[8]; + u8 nintendoLogo[156]; + u8 gameTitle[12]; + u8 gameCode[8]; }; -extern void sub_0200D9EC(void); +extern void VBlankCB(void); extern const struct RomHeader gRomHeader; extern u8 gSaveStatus; extern u8 gUnknown_020217B8; @@ -33,7 +34,7 @@ extern struct Unk02021860Struct gUnknown_02021860; extern s32 sub_020063FC(void); extern s32 sub_020064BC(u32 a0, u32 a1); extern u32 sub_020044F0(u32 a0); -extern void sub_0200D924(const u8*); +extern void InitLink(const u8* gameCode); void sub_02002A9C(s32 a0, u32 a1, u32 a2); void sub_02002C44(void); @@ -111,15 +112,15 @@ void GF_Main(void) InitSound(); sub_02002C44(); SetKeyRepeatTiming(0x28, 5); - REG_IE = 1; + REG_IE = INTR_FLAG_VBLANK; REG_DISPSTAT = 8; REG_DISPCNT &= (0xFF7F); REG_IME = 1; SetPlayerLinkInfo(gSaveBlock2Ptr, gSaveBlock1Ptr, gSaveStatus); - sub_0200D924(gRomHeader.unkA8); + InitLink(gRomHeader.gameCode); - SetVBlankCallback(sub_0200D9EC); + SetVBlankCallback(VBlankCB); PauseSoundVSync(); GenerateFontHalfrowLookupTable((u32 *) 0x03004000); FadeOut(); @@ -235,8 +236,8 @@ _0200032C:\t\n\ ldrb r2, [r2]\t\n\ bl SetPlayerLinkInfo\t\n\ adds r0, r6, #0\t\n\ - bl sub_0200D924\t\n\ - ldr r0, =sub_0200D9EC\t\n\ + bl InitLink\t\n\ + ldr r0, =VBlankCB\t\n\ bl SetVBlankCallback\t\n\ bl PauseSoundVSync\t\n\ ldr r0, =0x03004000\t\n\ diff --git a/payload/src/unk_200C5DC.c b/payload/src/unk_200C5DC.c index 31c5246..2979519 100644 --- a/payload/src/unk_200C5DC.c +++ b/payload/src/unk_200C5DC.c @@ -527,7 +527,7 @@ static u8 GetRSPlayerMapType(struct SaveBlock1 *sav1) return 0; } -static void sub_0200CF50(u32 val) +static void ReceivePartyMon(u32 val) { u32 speciesLower1, speciesLower2, speciesUpper; @@ -549,7 +549,7 @@ static void sub_0200CF50(u32 val) gMonLinkData.speciesUpperByte = speciesUpper; gMonLinkData.monPtr = (void*) &gPlayerPartyPtr[gMonLinkData.monId]; - gTransferData.transferSize = 100; + gTransferData.transferSize = sizeof(struct Pokemon); gTransferData.transferBytes = 0; gTransferData.state++; break; @@ -572,13 +572,13 @@ static void sub_0200CF50(u32 val) if (gTransferData.transferBytes >= gTransferData.transferSize) { gMonLinkData.transferComplete = 1; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; } break; } } -void sub_0200D08C(u32 val) +static void ReceiveMonData(u32 val) { s32 i; @@ -614,7 +614,7 @@ void sub_0200D08C(u32 val) { gTransferData.transferBytes = 0; gTransferData.data = (void*) gMonLinkData.monName; - gTransferData.transferSize = gMonLinkData.unk7 * sizeof(struct MonName); + gTransferData.transferSize = gMonLinkData.monCount * sizeof(struct MonName); gTransferData.state++; } break; @@ -624,7 +624,7 @@ void sub_0200D08C(u32 val) if (gTransferData.transferBytes >= gTransferData.transferSize) { - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gMonLinkData.unk_87A = 1; } break; @@ -641,10 +641,10 @@ static inline void CopyN(s32 n, u8 *dst, const u8 *src) } } -void sub_0200D1AC(u32 val) +static void ReceiveGiftData(u32 val) { u8 *ptr = (u8 *)(gSaveBlock1Ptr) + gAgbPmRomParams->externalEventDataOffset; - // Note: cast is needed here to make the code match. The whole struct is declared as volatile, but unkStruct isn't treated as volatile in this function. + // Note: cast is needed here to make the code match. The whole struct is declared as volatile, but externalEventData isn't treated as volatile in this function. // It's possible only certain members of gMonLinkData were volatile. struct ExternalEventData2 *externalEventData = (struct ExternalEventData2 *) &gMonLinkData.externalEventData; @@ -693,12 +693,12 @@ void sub_0200D1AC(u32 val) { if (gMonLinkData.species3 == SPECIES_NONE) { - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gMonLinkData.unk_85A = 1; } else { - gTransferData.transferSize = 100; + gTransferData.transferSize = sizeof(struct Pokemon); gTransferData.transferBytes = 0; gTransferData.data = (void *) GetPtrToEmptyPartySlot(); gTransferData.state++; @@ -724,13 +724,13 @@ void sub_0200D1AC(u32 val) if (gTransferData.transferBytes >= gTransferData.transferSize) { gMonLinkData.unk_85A = 1; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; } break; } } -bool32 sub_0200D394(u32 val) +static bool32 ProcessReceiveCommand(u32 val) { u32 r3 = gTransferData.field12; @@ -742,19 +742,19 @@ bool32 sub_0200D394(u32 val) return FALSE; } - if (val == gTransferData.field40) + if (val == gTransferData.lowerCaseGameCode) { REG_JOYSTAT = 0x10; gTransferData.field36 = val; gTransferData.field12 = 1; - gTransferData.field17 = 1; + gTransferData.currentCmd = LINK_CMD_0x01; } - else if (val == gTransferData.field44) + else if (val == gTransferData.gameCode2) { REG_JOYSTAT = r3; gTransferData.field36 = val; gTransferData.field12 = 1; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; } else { @@ -767,108 +767,108 @@ bool32 sub_0200D394(u32 val) } else { - s32 r6 = gTransferData.field17; + s32 currentCmd = gTransferData.currentCmd; - switch (r6) + switch (currentCmd) { - case 0: + case LINK_CMD_RESET: val >>= 24; - if (val == 0xAA) + if (val == LINK_CMD_READ_INPUT) { REG_JOY_TRANS = (gHeldKeys << 0x10) | val; } - else if (val == 0x99) + else if (val == LINK_CMD_TRAN_PLAYER_DATA1) { gTransferData.data = (void *)GetPlayerLinkInfo(); REG_JOY_TRANS = val; - gTransferData.transferSize = 0x278; - gTransferData.transferBytes = r6; - gTransferData.field17 = 4; + gTransferData.transferSize = sizeof(struct PlayerLinkInfo); + gTransferData.transferBytes = currentCmd; // 0 + gTransferData.currentCmd = LINK_CMD_TRAN_PLAYER_DATA2; } - else if (val == 0x88) + else if (val == LINK_CMD_RECV_TEXT) { gTransferData.data = (void *) sub_0200CB34(0); SetUnknownBoolean(0); REG_JOY_TRANS = val; - gTransferData.transferSize = 0x780; - gTransferData.transferBytes = r6; - gTransferData.field17 = val; + gTransferData.transferSize = sizeof(*gUnknown_020241D0) * 6; + gTransferData.transferBytes = currentCmd; // 0 + gTransferData.currentCmd = val; } - else if (val == 0x77) + else if (val == LINK_CMD_RECV_UNKNOWN) { REG_JOY_TRANS = val; - gTransferData.field17 = val; + gTransferData.currentCmd = val; } - else if (val == 0x66) + else if (val == LINK_CMD_RECV_MON_DATA) { REG_JOY_TRANS = val; - gTransferData.field17 = val; + gTransferData.currentCmd = val; gTransferData.data = (void*) &gMonLinkData; - gTransferData.transferSize = 0x24; - gTransferData.transferBytes = r6; - gTransferData.state = r6; - gMonLinkData.unk_87A = r6; + gTransferData.transferSize = 0x24; // Everything before monData + gTransferData.transferBytes = currentCmd; // 0 + gTransferData.state = currentCmd; // 0 + gMonLinkData.unk_87A = currentCmd; // 0 } - else if (val == 0x55) + else if (val == LINK_CMD_RECV_PARTY_MON) { gMonLinkData.unk84C_00 = 1; gMonLinkData.transferComplete = 0; REG_JOY_TRANS = val; - gTransferData.field17 = val; - gTransferData.state = r6; + gTransferData.currentCmd = val; + gTransferData.state = currentCmd; // 0 } - else if (val == 0x44) + else if (val == LINK_CMD_0x44) { REG_JOY_TRANS = val; - gTransferData.field17 = val; + gTransferData.currentCmd = val; gMonLinkData.unk84C_02 = 1; gMonLinkData.unk84C_03 = 1; } - else if (val == 0x33 || val == 0x22) + else if (val == LINK_CMD_TRAN_GIFT_DATA || val == LINK_CMD_RECV_GIFT_DATA) { REG_JOY_TRANS = val; - gTransferData.field17 = val; + gTransferData.currentCmd = val; gTransferData.state = 0; } - else if (val == 0x60) + else if (val == LINK_CMD_SOFT_RESET_ROM) { REG_JOY_TRANS = val; REG_IME = 0; SoftResetRom(0); } - else if (val == 0x61) + else if (val == LINK_CMD_SOFT_RESET) { REG_JOY_TRANS = val; REG_IME = 0; SoftReset(0); } break; - case 136: + case LINK_CMD_RECV_TEXT: gTransferData.data[gTransferData.transferBytes / 4] = val; gTransferData.transferBytes += 4; if (gTransferData.transferBytes >= gTransferData.transferSize) { REG_JOYSTAT = 0; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gTransferData.field12 = 0; SetUnknownBoolean(1); } break; - case 119: + case LINK_CMD_RECV_UNKNOWN: gMonLinkData.unk_858 = val >> 24; - gMonLinkData.unk_859 = val; + gMonLinkData.numMonsToSelect = val; gMonLinkData.unk_878 = 1; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; break; - case 102: - sub_0200D08C(val); + case LINK_CMD_RECV_MON_DATA: + ReceiveMonData(val); break; - case 85: - sub_0200CF50(val); + case LINK_CMD_RECV_PARTY_MON: + ReceivePartyMon(val); break; - case 34: - sub_0200D1AC(val); + case LINK_CMD_RECV_GIFT_DATA: + ReceiveGiftData(val); break; default: goto RET_FALSE; // return FALSE doesn't match @@ -877,7 +877,7 @@ bool32 sub_0200D394(u32 val) return TRUE; } -void sub_0200D624(void) +static void TransmitGiftData(void) { bool32 gameClear; u32 joyTransVal; @@ -915,14 +915,14 @@ void sub_0200D624(void) if (gTransferData.transferBytes == gTransferData.transferSize) { - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gTransferData.field12 = 0; } break; } } -bool32 sub_0200D748(void) +static bool32 ProcessTransmitCommand(void) { if (gTransferData.field12 == 0) { @@ -938,9 +938,9 @@ bool32 sub_0200D748(void) } else { - switch (gTransferData.field17) + switch (gTransferData.currentCmd) { - case 4: + case LINK_CMD_TRAN_PLAYER_DATA2: if (gTransferData.transferBytes < gTransferData.transferSize) { REG_JOY_TRANS = gTransferData.data[gTransferData.transferBytes / 4]; @@ -949,23 +949,24 @@ bool32 sub_0200D748(void) else { REG_JOYSTAT = 0; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gTransferData.field12 = 0; } break; - case 0x33: - sub_0200D624(); + case LINK_CMD_RECV_GIFT_DATA: break; - case 0x44: + case LINK_CMD_TRAN_GIFT_DATA: + TransmitGiftData(); + break; + case LINK_CMD_0x44: gMonLinkData.unk84C_03 = 0; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; break; - case 0x55: - case 0x66: - case 0x60: - case 0x77: - case 0x88: - case 0x22: + case LINK_CMD_RECV_PARTY_MON: + case LINK_CMD_SOFT_RESET_ROM: + case LINK_CMD_RECV_MON_DATA: + case LINK_CMD_RECV_UNKNOWN: + case LINK_CMD_RECV_TEXT: break; default: return FALSE; @@ -974,18 +975,18 @@ bool32 sub_0200D748(void) return TRUE; } -void sub_0200D80C(void) +static void JoyBusVCOuntIntr(void) { u32 joyCnt = REG_JOYCNT; - if (!(joyCnt & 4) || sub_0200D748() != 0) + if (!(joyCnt & JOYCNT_TRAN_CMPLT) || ProcessTransmitCommand() != FALSE) { - if (!(joyCnt & 2)) + if (!(joyCnt & JOYCNT_RECV_CMPLT)) goto loc_200D850; gTransferData.field11 = 1; - if (sub_0200D394(REG_JOY_RECV) != 0) + if (ProcessReceiveCommand(REG_JOY_RECV) != FALSE) goto loc_200D850; } @@ -994,10 +995,10 @@ void sub_0200D80C(void) gTransferData.field13 = 0; loc_200D850: - if (joyCnt & 1) + if (joyCnt & JOYCNT_RESET) { u16 UNUSED joyRcv = REG_JOY_RECV; - REG_JOY_TRANS = gTransferData.field32; + REG_JOY_TRANS = gTransferData.gameCode; REG_JOYSTAT = 0; gTransferData.field12 = 0; gTransferData.field13 = 1; @@ -1008,33 +1009,33 @@ void sub_0200D80C(void) gTransferData.field15 = 0; } -void sub_0200D8A4(void) +static void InitJoyBus(void) { u16 UNUSED joyRcv; u16 ime = REG_IME; REG_IME = 0; if (gTransferData.field18 == 0) - REG_RCNT = 0x8000; - REG_RCNT = 0xC000; + REG_RCNT = RCNT_JOYBUS2; + REG_RCNT = RCNT_JOYBUS1 | RCNT_JOYBUS2; REG_JOYSTAT = 0; joyRcv = REG_JOY_RECV; REG_JOY_TRANS = 0; - REG_JOYCNT = 0x47; - REG_IF = 0x80; - REG_IE |= 0x80; + REG_JOYCNT = JOYCNT_RESET | JOYCNT_RECV_CMPLT | JOYCNT_TRAN_CMPLT | JOYCNT_RESET_IRQ; + REG_IF = INTR_FLAG_SERIAL; + REG_IE |= INTR_FLAG_SERIAL; gTransferData.field15 = 0; gTransferData.field12 = 0; gTransferData.field13 = 0; gTransferData.field18 = 0; - gTransferData.field17 = 0; + gTransferData.currentCmd = LINK_CMD_RESET; gTransferData.field11 = 0; REG_IME = ime; } -void sub_0200D924(const u8 *headerSth) +void InitLink(const u8 *gameCode) { s32 i; u16 ime = REG_IME; @@ -1047,26 +1048,26 @@ void sub_0200D924(const u8 *headerSth) } gTransferData.field18 = 1; - sub_0200D8A4(); - REG_IE |= 0x80; + InitJoyBus(); + REG_IE |= INTR_FLAG_SERIAL; - if (headerSth[0] == 0x54 && headerSth[1] == 0x45 && headerSth[2] == 0x53 && headerSth[3] == 0x54) + if (gameCode[0] == 'T' && gameCode[1] == 'E' && gameCode[2] == 'S' && gameCode[3] == 'T') gTransferData.field14 = 0xFE; else gTransferData.field14 = 0x28; - gTransferData.field32 = (headerSth[3] << 24) | (headerSth[2] << 16) | (headerSth[1] << 8) | (headerSth[0]); - gTransferData.field44 = gTransferData.field32; - gTransferData.field40 = gTransferData.field32 | 0x20202020; - gTransferData.field48 = (headerSth[4] << 24) | (headerSth[5] << 16) | (headerSth[6] << 8) | (headerSth[7]); - SetIntrFunc(0, sub_0200D80C); + gTransferData.gameCode = (gameCode[3] << 24) | (gameCode[2] << 16) | (gameCode[1] << 8) | (gameCode[0]); + gTransferData.gameCode2 = gTransferData.gameCode; + gTransferData.lowerCaseGameCode = gTransferData.gameCode | 0x20202020; // Turns upper case ASCII to lower case + gTransferData.makerCode = (gameCode[4] << 24) | (gameCode[5] << 16) | (gameCode[6] << 8) | (gameCode[7]); + SetIntrFunc(0, JoyBusVCOuntIntr); REG_IME = ime; } -bool32 sub_0200D9EC(void) +bool32 VBlankCB(void) { - if (*(u8*)(0x80000B2) != 0x96) + if (*(u8*)(0x80000B2) != 0x96) // gRomHeader.gameCode[6] != 0x96 SoftReset(0); if (gTransferData.field15 <= gTransferData.field14) @@ -1081,7 +1082,7 @@ bool32 sub_0200D9EC(void) SoftReset(0); } -void UNUSED sub_0200DA38(u8 *dst, const u8 *src, s32 n) +static void UNUSED CopyN2(u8 *dst, const u8 *src, s32 n) { CopyN(n, dst, src); }