ref: 27ef600ace40671a78f5bb3a71f507e42c175f50
parent: e88c88ff2015a55ff0d04f9ac1dc55d7f0567f7c
author: PikalaxALT <PikalaxALT@gmail.com>
date: Tue Nov 17 12:56:49 EST 2015
Here's the mail it never fails
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -32,6 +32,10 @@
MONS_PER_BOX EQU 20
NUM_BOXES EQU 14
+MAIL_STRUCT_LENGTH EQU $2f
+MAILBOX_CAPACITY EQU 10
+
; hall of fame
HOF_MON_LENGTH = 1 + 2 + 2 + 1 + (PKMN_NAME_LENGTH +- 1) ; species, id, dvs, level, nick
HOF_LENGTH = 1 + HOF_MON_LENGTH * PARTY_LENGTH + 1 ; win count, party, terminator
--- a/constants/pokemon_constants.asm
+++ b/constants/pokemon_constants.asm
@@ -291,7 +291,6 @@
MON_SDF EQUS "(PartyMon1SpclDef - PartyMon1)"
BOXMON_STRUCT_LENGTH EQUS "(PartyMon1End - PartyMon1)"
PARTYMON_STRUCT_LENGTH EQUS "(PartyMon1StatsEnd - PartyMon1)"
-SCRATCHMON_STRUCT_LENGTH EQUS "(PartyMon1StatsEnd - PartyMon1Item)"
const_value SET 1
const MONMENU_CUT ; 1
--- a/engine/breeding/egg.asm
+++ b/engine/breeding/egg.asm
@@ -192,7 +192,7 @@
call ResetWindow
call LoadStandardMenuDataHeader
call Function16f70
- call Function2b4d
+ call ExitAllMenus
call RestartMapMusic
jp LoadMoveSprites
; 16f70
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -834,9 +834,9 @@
ld de, wc9f4
ld a, $20
call Function28682
- ld a, BANK(sPartyScratch1)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld b, PARTY_LENGTH
.loop2
push bc
@@ -847,7 +847,7 @@
pop bc
dec b
jr nz, .loop2
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld b, PARTY_LENGTH
.loop3
push bc
@@ -859,7 +859,7 @@
dec b
jr nz, .loop3
ld b, PARTY_LENGTH
- ld de, sPartyScratch1
+ ld de, sPartyMail
ld hl, wc9f9
.loop4
push bc
@@ -883,7 +883,7 @@
.next
pop de
- ld hl, SCRATCHMON_STRUCT_LENGTH
+ ld hl, MAIL_STRUCT_LENGTH
add hl, de
ld d, h
ld e, l
@@ -1744,15 +1744,15 @@
jp Function28ea3
.asm_28c7b
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld a, [wd002]
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
- ld a, BANK(sPartyScratch1)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
ld d, h
ld e, l
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
add hl, bc
ld a, [wd002]
ld c, a
@@ -1762,24 +1762,24 @@
cp $6
jr z, .asm_28ca6
push bc
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
pop bc
jr .asm_28c96
.asm_28ca6
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld a, [PartyCount]
dec a
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
push hl
ld hl, wc9f4
ld a, [wd003]
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
pop de
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
call CloseSRAM
ld hl, PlayerName
--- /dev/null
+++ b/engine/mail.asm
@@ -1,0 +1,190 @@
+SendMailToPC: ; 4456e
+ ld a, MON_ITEM
+ call GetPartyParamLocation
+ ld d, [hl]
+ callba ItemIsMail
+ jr nc, .full
+ call GetMailboxCount
+ cp MAILBOX_CAPACITY
+ jr nc, .full
+ ld bc, MAIL_STRUCT_LENGTH
+ ld hl, sMailbox
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld a, [CurPartyMon]
+ ld bc, MAIL_STRUCT_LENGTH
+ ld hl, sPartyMail
+ call AddNTimes
+ push hl
+ ld a, BANK(sMailboxCount)
+ call GetSRAMBank
+ ld bc, MAIL_STRUCT_LENGTH
+ call CopyBytes
+ pop hl
+ xor a
+ ld bc, MAIL_STRUCT_LENGTH
+ call ByteFill
+ ld a, MON_ITEM
+ call GetPartyParamLocation
+ ld [hl], $0
+ ld hl, sMailboxCount
+ inc [hl]
+ call CloseSRAM
+ xor a
+ ret
+
+.full
+ scf
+ ret
+; 445c0
+
+Function445c0: ; 445c0 (11:45c0)
+ ld a, BANK(sMailboxCount)
+ call GetSRAMBank
+ ld a, b
+ push bc
+ ld hl, sMailbox
+ ld bc, MAIL_STRUCT_LENGTH
+ call AddNTimes
+ push hl
+ add hl, bc
+ pop de
+ pop bc
+.loop
+ ld a, b
+ cp $9
+ jr z, .done
+ push bc
+ ld bc, MAIL_STRUCT_LENGTH
+ call CopyBytes
+ pop bc
+ inc b
+ jr .loop
+.done
+ ld h, d
+ ld l, e
+ xor a
+ ld bc, MAIL_STRUCT_LENGTH
+ call ByteFill
+ ld hl, sMailboxCount
+ dec [hl]
+ jp CloseSRAM
+; 445f4 (11:45f4)
+
+ReadMailMessage: ; 445f4
+ ld a, b
+ ld hl, sMailbox
+ ld bc, MAIL_STRUCT_LENGTH
+ call AddNTimes
+ ld d, h
+ ld e, l
+ callba ReadAnyMail
+ ret
+
+Function44607: ; 44607
+ ld a, BANK(sMailboxCount)
+ call GetSRAMBank
+ push bc
+ ld a, b
+ ld bc, MAIL_STRUCT_LENGTH
+ ld hl, sMailbox
+ call AddNTimes
+ push hl
+ ld a, [CurPartyMon]
+ ld bc, MAIL_STRUCT_LENGTH
+ ld hl, sPartyMail
+ call AddNTimes
+ ld d, h
+ ld e, l
+ pop hl
+ push hl
+ ld bc, MAIL_STRUCT_LENGTH
+ call CopyBytes
+ pop hl
+ ld de, PARTYMON_STRUCT_LENGTH - MON_MOVES
+ add hl, de
+ ld d, [hl]
+ ld a, [CurPartyMon]
+ ld hl, PartyMon1Item
+ ld bc, PARTYMON_STRUCT_LENGTH
+ call AddNTimes
+ ld [hl], d
+ call CloseSRAM
+ pop bc
+ jp Function445c0
+; 44648 (11:4648)
+
+GetMailboxCount: ; 44648
+ ld a, BANK(sMailboxCount)
+ call GetSRAMBank
+ ld a, [sMailboxCount]
+ ld c, a
+ jp CloseSRAM
+; 44654
+
+Function44654:: ; 44654
+ push bc
+ push de
+ callba SelectMonFromParty
+ ld a, $2
+ jr c, .asm_446c6
+ ld a, [CurPartyMon]
+ ld hl, PartyMon1Item
+ ld bc, PARTYMON_STRUCT_LENGTH
+ call AddNTimes
+ ld d, [hl]
+ callba ItemIsMail
+ ld a, $3
+ jr nc, .asm_446c6
+ ld a, BANK(sPartyMail)
+ call GetSRAMBank
+ ld a, [CurPartyMon]
+ ld hl, sPartyMail
+ ld bc, MAIL_STRUCT_LENGTH
+ call AddNTimes
+ ld d, h
+ ld e, l
+ pop hl
+ pop bc
+
+ ld a, $20
+ ld [wd265], a
+.asm_44691
+ ld a, [de]
+ ld c, a
+ ld a, b
+ call GetFarByte
+ cp "@"
+ jr z, .asm_446ab
+ cp c
+ ld a, $0
+ jr nz, .asm_446c1
+ inc hl
+ inc de
+ ld a, [wd265]
+ dec a
+ ld [wd265], a
+ jr nz, .asm_44691
+
+.asm_446ab
+ callba CheckCurPartyMonFainted
+ ld a, $4
+ jr c, .asm_446c1
+ xor a
+ ld [wPokemonWithdrawDepositParameter], a
+ callba Functione039
+ ld a, $1
+
+.asm_446c1
+ call CloseSRAM
+ jr .asm_446c8
+
+.asm_446c6
+ pop de
+ pop bc
+
+.asm_446c8
+ ld [ScriptVar], a
+ ret
+; 446cc
--- a/engine/mart.asm
+++ b/engine/mart.asm
@@ -377,7 +377,7 @@
.loop
call BuyMenuLoop ; menu loop
jr nc, .loop
- call Function2b3c
+ call ReturnToCallingMenu
ret
; 15c7d
--- a/engine/pokecenter_pc.asm
+++ b/engine/pokecenter_pc.asm
@@ -140,7 +140,7 @@
call PC_PlayChoosePCSound
call FadeToMenu
callba _HallOfFamePC
- call Function2b3c
+ call ReturnToCallingMenu
and a
ret
; 156ab
@@ -323,7 +323,7 @@
jr .asm_157da
.asm_157e4
- call Function2b3c
+ call ReturnToCallingMenu
xor a
ret
; 0x157e9
@@ -403,7 +403,7 @@
jr .asm_15868
.asm_15878
- call Function2b3c
+ call ReturnToCallingMenu
xor a
ret
; 0x1587d
@@ -442,7 +442,7 @@
jr .asm_1589c
.asm_158b3
- call Function2b3c
+ call ReturnToCallingMenu
.asm_158b6
xor a
@@ -450,7 +450,7 @@
; 0x158b8
Function158b8: ; 0x158b8
- callba Function129d5
+ callba HasNoItems
ret nc
ld hl, UnknownText_0x158c7
call MenuTextBoxBackup
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -1,4 +1,4 @@
-Function14a1a: ; 14a1a
+SaveMenu: ; 14a1a
call LoadStandardMenuDataHeader
callba Function5e9a
call SpeechTextBox
@@ -30,7 +30,7 @@
call Function14e13
call SaveBackupPokemonData
call SaveBackupChecksum
- callba BackupScratchmons
+ callba BackupPartyMonMail
callba Function1406a
call ClearWRAMStateAfterSave
ret
@@ -106,7 +106,7 @@
call SaveBackupPlayerData
call SaveBackupPokemonData
call SaveBackupChecksum
- callba BackupScratchmons
+ callba BackupPartyMonMail
callba BackupMobileEventIndex
callba Function1406a
call LoadBox
@@ -284,7 +284,7 @@
call SaveBackupPokemonData
call SaveBackupChecksum
call UpdateStackTop
- callba BackupScratchmons
+ callba BackupPartyMonMail
callba BackupMobileEventIndex
callba Function1406a
ld a, BANK(s1_be45)
@@ -630,7 +630,7 @@
call LoadPlayerData
call LoadPokemonData
call LoadBox
- callba RestoreScratchmons
+ callba RestorePartyMonMail
callba RestoreMobileEventIndex
callba Function1050ea
call ValidateBackupSave
@@ -647,7 +647,7 @@
call LoadBackupPlayerData
call LoadBackupPokemonData
call LoadBox
- callba RestoreScratchmons
+ callba RestorePartyMonMail
callba RestoreMobileEventIndex
callba Function1050ea
call ValidateSave
--- a/engine/selectmenu.asm
+++ b/engine/selectmenu.asm
@@ -158,7 +158,7 @@
call ResetWindow
call FadeToMenu
call DoItemEffect
- call Function2b3c
+ call ReturnToCallingMenu
call LoadMoveSprites
and a
ret
--- a/engine/specials.asm
+++ b/engine/specials.asm
@@ -216,7 +216,7 @@
ld a, [ScriptVar]
ld [wd265], a
callba Functionfb877
- call Function2b4d
+ call ExitAllMenus
ret
; c252
@@ -288,7 +288,7 @@
Special_TownMap: ; c2c0
call FadeToMenu
callba _TownMap
- call Function2b4d
+ call ExitAllMenus
ret
; c2cd
@@ -295,7 +295,7 @@
Special_UnownPrinter: ; c2cd
call FadeToMenu
callba UnownPrinter
- call Function2b4d
+ call ExitAllMenus
ret
; c2da
@@ -302,7 +302,7 @@
Special_DisplayLinkRecord: ; c2da
call FadeToMenu
callba DisplayLinkRecord
- call Function2b4d
+ call ExitAllMenus
ret
; c2e7
@@ -383,7 +383,7 @@
callba Functione1190
ld a, [wd0ec]
ld [ScriptVar], a
- call Function2b4d
+ call ExitAllMenus
ret
; c373
@@ -425,7 +425,7 @@
ld l, a
pop af
rst FarCall
- call Function2b4d
+ call ExitAllMenus
ret
; c3ae
@@ -629,7 +629,7 @@
Diploma: ; c49f
call FadeToMenu
callba _Diploma
- call Function2b4d
+ call ExitAllMenus
ret
; c4ac
@@ -636,7 +636,7 @@
PrintDiploma: ; c4ac
call FadeToMenu
callba _PrintDiploma
- call Function2b4d
+ call ExitAllMenus
ret
; c4b9
--- a/engine/startmenu.asm
+++ b/engine/startmenu.asm
@@ -422,7 +422,7 @@
; Retire from the bug catching contest.
ld hl, .EndTheContestText
- call Function12cf5
+ call StartMenuYesNo
jr c, .DontEndContest
ld a, BANK(BugCatchingContestReturnToGateScript)
ld hl, BugCatchingContestReturnToGateScript
@@ -444,7 +444,7 @@
; Save the game.
call BufferScreen
- callba Function14a1a
+ callba SaveMenu
jr nc, .asm_12919
ld a, 0
ret
@@ -468,8 +468,8 @@
; Player status.
call FadeToMenu
- callba Function25105
- call Function2b3c
+ callba TrainerCard
+ call ReturnToCallingMenu
ld a, 0
ret
; 12937
@@ -483,7 +483,7 @@
call FadeToMenu
callba Pokedex
- call Function2b3c
+ call ReturnToCallingMenu
.asm_12949
ld a, 0
@@ -495,7 +495,7 @@
call FadeToMenu
callba PokeGear
- call Function2b3c
+ call ReturnToCallingMenu
ld a, 0
ret
; 1295b
@@ -507,12 +507,13 @@
callba Pack
ld a, [wcf66]
and a
- jr nz, .asm_12970
- call Function2b3c
+ jr nz, .used_item
+ call ReturnToCallingMenu
ld a, 0
ret
-.asm_12970
- call Function2b4d
+
+.used_item
+ call ExitAllMenus
ld a, 4
ret
; 12976
@@ -556,7 +557,7 @@
jr z, .quit
.return
- call Function2b3c
+ call ReturnToCallingMenu
ld a, 0
ret
@@ -563,12 +564,12 @@
.quit
ld a, b
push af
- call Function2b4d
+ call ExitAllMenus
pop af
ret
; 129d5
-Function129d5: ; 129d5
+HasNoItems: ; 129d5
ld a, [NumItems]
and a
ret nz
@@ -580,15 +581,15 @@
ret nz
ld hl, TMsHMs
ld b, NUM_TMS + NUM_HMS
-.asm_129e9
+.loop
ld a, [hli]
and a
- jr nz, .asm_129f2
+ jr nz, .done
dec b
- jr nz, .asm_129e9
+ jr nz, .loop
scf
ret
-.asm_129f2
+.done
and a
ret
@@ -882,7 +883,7 @@
jr .asm_12c08
.asm_12bf4
- call Function12cea
+ call GiveItemToPokemon
ld hl, MadeHoldText
call MenuTextBoxBackup
call GivePartyItem
@@ -897,10 +898,10 @@
ld [wd265], a
call GetItemName
ld hl, SwitchAlreadyHoldingText
- call Function12cf5
+ call StartMenuYesNo
jr c, .asm_12c4b
- call Function12cea
+ call GiveItemToPokemon
ld a, [wd265]
push af
ld a, [CurItem]
@@ -907,7 +908,7 @@
ld [wd265], a
pop af
ld [CurItem], a
- call Function12cdf
+ call ReceiveItemFromPokemon
jr nc, .asm_12c3c
ld hl, TookAndMadeHoldText
@@ -920,7 +921,7 @@
.asm_12c3c
ld a, [wd265]
ld [CurItem], a
- call Function12cdf
+ call ReceiveItemFromPokemon
ld hl, ItemStorageIsFullText
call MenuTextBoxBackup
@@ -953,7 +954,7 @@
jr z, .asm_12c8c
ld [CurItem], a
- call Function12cdf
+ call ReceiveItemFromPokemon
jr nc, .asm_12c94
callba ItemIsMail
@@ -1045,7 +1046,7 @@
; 12cdf
-Function12cdf: ; 12cdf
+ReceiveItemFromPokemon: ; 12cdf
ld a, $1
ld [wItemQuantityChangeBuffer], a
ld hl, NumItems
@@ -1053,13 +1054,13 @@
; 12cea
-Function12cea: ; 12cea (4:6cea)
+GiveItemToPokemon: ; 12cea (4:6cea)
ld a, $1
ld [wItemQuantityChangeBuffer], a
ld hl, NumItems
jp TossItem
-Function12cf5: ; 12cf5
+StartMenuYesNo: ; 12cf5
call MenuTextBox
call YesNoBox
jp ExitMenu
@@ -1071,7 +1072,7 @@
callba Function11e75
ld hl, PlayerName
ld de, wd023
- ld bc, $a
+ ld bc, NAME_LENGTH - 1
call CopyBytes
ld hl, PlayerID
ld bc, $2
@@ -1082,14 +1083,14 @@
ld a, [CurItem]
ld [de], a
ld a, [CurPartyMon]
- ld hl, sPartyScratch1
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMail
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, wd002
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld a, BANK(sPartyScratch1)
+ ld bc, MAIL_STRUCT_LENGTH
+ ld a, BANK(sPartyMail)
call GetSRAMBank
call CopyBytes
call CloseSRAM
@@ -1127,11 +1128,11 @@
.take
ld hl, .sendmailtopctext
- call Function12cf5
+ call StartMenuYesNo
jr c, .RemoveMailToBag
ld a, [CurPartyMon]
ld b, a
- callba Function4456e
+ callba SendMailToPC
jr c, .MailboxFull
ld hl, .sentmailtopctext
call MenuTextBoxBackup
@@ -1144,12 +1145,12 @@
.RemoveMailToBag
ld hl, .mailwilllosemessagetext
- call Function12cf5
+ call StartMenuYesNo
jr c, .done
call GetPartyItemLocation
ld a, [hl]
ld [CurItem], a
- call Function12cdf
+ call ReceiveItemFromPokemon
jr nc, .BagIsFull
call GetPartyItemLocation
ld [hl], $0
--- a/engine/trainer_card.asm
+++ b/engine/trainer_card.asm
@@ -1,4 +1,4 @@
-Function25105: ; 25105
+TrainerCard: ; 25105
ld a, [VramState]
push af
xor a
@@ -211,16 +211,18 @@
ld hl, hJoyLast
ld a, [hl]
and D_LEFT
- jr nz, .asm_2528d
+ jr nz, .left
ld a, [hl]
and D_RIGHT
- jr nz, .asm_25293
+ jr nz, .right
ret
-.asm_2528d
+
+.left
ld a, $2
ld [wJumptableIndex], a
ret
-.asm_25293
+
+.right
ld a, $0
ld [wJumptableIndex], a
ret
@@ -466,24 +468,26 @@
jr Function25448
Function25448: ; 25448 (9:5448)
+; copy flag array pointer
ld a, [hli]
ld e, a
ld a, [hli]
+; get flag array
ld d, a
ld a, [de]
ld c, a
ld de, Sprites
ld b, 8
-.asm_25453
+.loop
srl c
push bc
- jr nc, .asm_25472
+ jr nc, .skip_badge
push hl
- ld a, [hli]
+ ld a, [hli] ; y
ld b, a
- ld a, [hli]
+ ld a, [hli] ; x
ld c, a
- ld a, [hli]
+ ld a, [hli] ; pal
ld [wcf66], a
ld a, [wcf64]
add l
@@ -495,23 +499,23 @@
ld [wcf65], a
call Function2547b
pop hl
-.asm_25472
- ld bc, $b
+.skip_badge
+ ld bc, $b ; 3 + 2 * 4
add hl, bc
pop bc
dec b
- jr nz, .asm_25453
+ jr nz, .loop
ret
Function2547b: ; 2547b (9:547b)
ld a, [wcf65]
and $80
- jr nz, .asm_25487
- ld hl, Unknown_254a7
- jr .asm_2548a
-.asm_25487
- ld hl, Unknown_254b8
-.asm_2548a
+ jr nz, .xflip
+ ld hl, .facing1
+ jr .loop
+.xflip
+ ld hl, .facing2
+.loop
ld a, [hli]
cp $ff
ret z
@@ -518,10 +522,12 @@
add b
ld [de], a
inc de
+
ld a, [hli]
add c
ld [de], a
inc de
+
ld a, [wcf65]
and $7f
add [hl]
@@ -528,27 +534,29 @@
ld [de], a
inc hl
inc de
+
ld a, [wcf66]
add [hl]
ld [de], a
inc hl
inc de
- jr .asm_2548a
+ jr .loop
; 254a7 (9:54a7)
-Unknown_254a7: ; 254a7
- db $00, $00, $00, $00
- db $00, $08, $01, $00
- db $08, $00, $02, $00
- db $08, $08, $03, $00
- db $ff
+.facing1: ; 254a7
+ ; y, x, tile, OAM attributes
+ db 0, 0, 0, 0
+ db 0, 8, 1, 0
+ db 8, 0, 2, 0
+ db 8, 8, 3, 0
+ db -1
-Unknown_254b8: ; 254b8
- db $00, $00, $01, $20
- db $00, $08, $00, $20
- db $08, $00, $03, $20
- db $08, $08, $02, $20
- db $ff
+.facing2: ; 254b8
+ db 0, 0, 1, X_FLIP
+ db 0, 8, 0, X_FLIP
+ db 8, 0, 3, X_FLIP
+ db 8, 8, 2, X_FLIP
+ db -1
Unknown_254c9: ; 254c9
; Template OAM data for each badge on the trainer card.
@@ -560,43 +568,43 @@
dw JohtoBadges
; Zephyrbadge
- db $68, $18, $00
+ db $68, $18, 0
db $00, $20, $24, $20 | $80
db $00, $20, $24, $20 | $80
; Hivebadge
- db $68, $38, $00
+ db $68, $38, 0
db $04, $20, $24, $20 | $80
db $04, $20, $24, $20 | $80
; Plainbadge
- db $68, $58, $00
+ db $68, $58, 0
db $08, $20, $24, $20 | $80
db $08, $20, $24, $20 | $80
; Fogbadge
- db $68, $78, $00
+ db $68, $78, 0
db $0c, $20, $24, $20 | $80
db $0c, $20, $24, $20 | $80
; Mineralbadge
- db $80, $38, $00
+ db $80, $38, 0
db $10, $20, $24, $20 | $80
db $10, $20, $24, $20 | $80
; Stormbadge
- db $80, $18, $00
+ db $80, $18, 0
db $14, $20, $24, $20 | $80
db $14, $20, $24, $20 | $80
; Glacierbadge
- db $80, $58, $00
+ db $80, $58, 0
db $18, $20, $24, $20 | $80
db $18, $20, $24, $20 | $80
; Risingbadge
; X-flips on alternate cycles.
- db $80, $78, $00
+ db $80, $78, 0
db $1c, $20, $24, $20 | $80
db $1c | $80, $20, $24, $20 | $80
; 25523
--- a/home/map.asm
+++ b/home/map.asm
@@ -2014,7 +2014,7 @@
; 2b3c
-Function2b3c:: ; 2b3c
+ReturnToCallingMenu:: ; 2b3c
call ClearBGPalettes
call Function2bae
call UpdateSprites
@@ -2023,7 +2023,7 @@
jr Function2b5c
; 2b4d
-Function2b4d:: ; 2b4d
+ExitAllMenus:: ; 2b4d
call ClearBGPalettes
call Call_ExitMenu
call Function2bae
--- a/main.asm
+++ b/main.asm
@@ -285,7 +285,7 @@
callba InitDecorations
- callba DeleteScratchmons
+ callba DeletePartyMonMail
callba DeleteMobileEventIndex
@@ -9297,14 +9297,14 @@
ld a, [wLinkMode]
and a
ret nz
- ld a, BANK(sPartyScratch1)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
ld hl, PartyCount
ld a, [CurPartyMon]
cp [hl]
jr z, .asm_e131
- ld hl, sPartyScratch1
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMail
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
push hl
add hl, bc
@@ -9314,11 +9314,11 @@
.asm_e11a
push bc
push hl
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
pop hl
push hl
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
add hl, bc
pop de
pop bc
@@ -9789,7 +9789,7 @@
ld de, StringBuffer1
call InitName
ld a, $4 ; XXX could this be in bank 4 in pokered?
- ld hl, Function2b4d
+ ld hl, ExitAllMenus
rst FarCall
ret
; e3fd
@@ -9841,7 +9841,7 @@
; 0xe43f
Functione43f: ; e43f (3:643f)
- call Function2b3c
+ call ReturnToCallingMenu
ret
Functione443: ; e443 (3:6443)
@@ -10414,7 +10414,7 @@
INCLUDE "engine/namingscreen.asm"
-Function11e75: ; 11e75 (4:5e75)
+Function11e75: ; 11e75 (mail?)
ld hl, wc6d0
ld [hl], e
inc hl
@@ -17957,198 +17957,8 @@
PokedexDataPointerTable: ; 0x44378
INCLUDE "data/pokedex/entry_pointers.asm"
+INCLUDE "engine/mail.asm"
-Function4456e: ; 4456e
- ld a, MON_ITEM
- call GetPartyParamLocation
- ld d, [hl]
- callba ItemIsMail
- jr nc, .asm_445be
- call Function44648
- cp $a
- jr nc, .asm_445be
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld hl, s0_a835
- call AddNTimes
- ld d, h
- ld e, l
- ld a, [CurPartyMon]
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld hl, sPartyScratch1
- call AddNTimes
- push hl
- ld a, BANK(s0_a834)
- call GetSRAMBank
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call CopyBytes
- pop hl
- xor a
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call ByteFill
- ld a, MON_ITEM
- call GetPartyParamLocation
- ld [hl], $0
- ld hl, s0_a834
- inc [hl]
- call CloseSRAM
- xor a
- ret
-
-.asm_445be
- scf
- ret
-; 445c0
-
-Function445c0: ; 445c0 (11:45c0)
- ld a, BANK(s0_a834)
- call GetSRAMBank
- ld a, b
- push bc
- ld hl, s0_a835
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call AddNTimes
- push hl
- add hl, bc
- pop de
- pop bc
-.loop
- ld a, b
- cp $9
- jr z, .done
- push bc
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call CopyBytes
- pop bc
- inc b
- jr .loop
-.done
- ld h, d
- ld l, e
- xor a
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call ByteFill
- ld hl, s0_a834
- dec [hl]
- jp CloseSRAM
-; 445f4 (11:45f4)
-
-ReadMailMessage: ; 445f4
- ld a, b
- ld hl, s0_a835
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call AddNTimes
- ld d, h
- ld e, l
- callba ReadAnyMail
- ret
-
-Function44607: ; 44607
- ld a, BANK(s0_a834)
- call GetSRAMBank
- push bc
- ld a, b
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld hl, s0_a835
- call AddNTimes
- push hl
- ld a, [CurPartyMon]
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld hl, sPartyScratch1
- call AddNTimes
- ld d, h
- ld e, l
- pop hl
- push hl
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call CopyBytes
- pop hl
- ld de, PARTYMON_STRUCT_LENGTH - MON_MOVES
- add hl, de
- ld d, [hl]
- ld a, [CurPartyMon]
- ld hl, PartyMon1Item
- ld bc, PARTYMON_STRUCT_LENGTH
- call AddNTimes
- ld [hl], d
- call CloseSRAM
- pop bc
- jp Function445c0
-; 44648 (11:4648)
-
-Function44648: ; 44648
- ld a, BANK(s0_a834)
- call GetSRAMBank
- ld a, [s0_a834]
- ld c, a
- jp CloseSRAM
-; 44654
-
-Function44654:: ; 44654
- push bc
- push de
- callba SelectMonFromParty
- ld a, $2
- jr c, .asm_446c6
- ld a, [CurPartyMon]
- ld hl, PartyMon1Item
- ld bc, PARTYMON_STRUCT_LENGTH
- call AddNTimes
- ld d, [hl]
- callba ItemIsMail
- ld a, $3
- jr nc, .asm_446c6
- ld a, BANK(sPartyScratch1)
- call GetSRAMBank
- ld a, [CurPartyMon]
- ld hl, sPartyScratch1
- ld bc, SCRATCHMON_STRUCT_LENGTH
- call AddNTimes
- ld d, h
- ld e, l
- pop hl
- pop bc
-
- ld a, $20
- ld [wd265], a
-.asm_44691
- ld a, [de]
- ld c, a
- ld a, b
- call GetFarByte
- cp "@"
- jr z, .asm_446ab
- cp c
- ld a, $0
- jr nz, .asm_446c1
- inc hl
- inc de
- ld a, [wd265]
- dec a
- ld [wd265], a
- jr nz, .asm_44691
-
-.asm_446ab
- callba CheckCurPartyMonFainted
- ld a, $4
- jr c, .asm_446c1
- xor a
- ld [wPokemonWithdrawDepositParameter], a
- callba Functione039
- ld a, $1
-
-.asm_446c1
- call CloseSRAM
- jr .asm_446c8
-
-.asm_446c6
- pop de
- pop bc
-
-.asm_446c8
- ld [ScriptVar], a
- ret
-; 446cc
-
GivePokeItem:: ; 446cc
ld a, [PartyCount]
dec a
@@ -18162,7 +17972,7 @@
pop af
push bc
push af
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld bc, $2f
call AddNTimes
ld d, h
@@ -18169,7 +17979,7 @@
ld e, l
ld hl, wd002
ld bc, $21
- ld a, BANK(sPartyScratch1)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
call CopyBytes
pop af
@@ -18199,43 +18009,43 @@
; 44725
-BackupScratchmons: ; 44725
- ld a, BANK(sPartyScratch1)
+BackupPartyMonMail: ; 44725
+ ld a, BANK(sPartyMail)
call GetSRAMBank
- ld hl, sPartyScratch1
- ld de, sPartyScratch2
- ld bc, 6 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMail
+ ld de, sPartyMailBackup
+ ld bc, 6 * MAIL_STRUCT_LENGTH
call CopyBytes
- ld hl, s0_a834
- ld de, s0_aa0b
- ld bc, 1 + 10 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sMailboxCount
+ ld de, sMailboxCountBackup
+ ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call CopyBytes
jp CloseSRAM
; 44745
-RestoreScratchmons: ; 44745 (11:4745)
- ld a, BANK(sPartyScratch1)
+RestorePartyMonMail: ; 44745 (11:4745)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
- ld hl, sPartyScratch2
- ld de, sPartyScratch1
- ld bc, 6 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMailBackup
+ ld de, sPartyMail
+ ld bc, 6 * MAIL_STRUCT_LENGTH
call CopyBytes
- ld hl, s0_aa0b
- ld de, s0_a834
- ld bc, 1 + 10 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sMailboxCountBackup
+ ld de, sMailboxCount
+ ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call CopyBytes
jp CloseSRAM
-DeleteScratchmons: ; 44765 (11:4765)
- ld a, BANK(sPartyScratch1)
+DeletePartyMonMail: ; 44765 (11:4765)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
xor a
- ld hl, sPartyScratch1
- ld bc, 6 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMail
+ ld bc, 6 * MAIL_STRUCT_LENGTH
call ByteFill
xor a
- ld hl, s0_a834
- ld bc, 1 + 10 * SCRATCHMON_STRUCT_LENGTH
+ ld hl, sMailboxCount
+ ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call ByteFill
jp CloseSRAM
; 44781 (11:4781)
@@ -18284,9 +18094,9 @@
InitMail: ; 0x447b9
; initialize wd0f2 and beyond with incrementing values, one per mail
; set z if no mail
- ld a, BANK(s0_a834)
+ ld a, BANK(sMailboxCount)
call GetSRAMBank
- ld a, [s0_a834]
+ ld a, [sMailboxCount]
call CloseSRAM
ld hl, wd0f2
ld [hli], a
@@ -18312,10 +18122,10 @@
Function447da: ; 0x447da
dec a
- ld hl, s0_a835 + MON_HP - 1
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld hl, sMailbox + MON_HP - 1
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
- ld a, BANK(s0_a834)
+ ld a, BANK(sMailboxCount)
call GetSRAMBank
ld de, StringBuffer2
push de
@@ -18396,7 +18206,7 @@
dec a
ld b, a
call ReadMailMessage
- jp Function2b3c
+ jp ReturnToCallingMenu
; 0x44877
.PutInPack ; 0x44877
@@ -18439,10 +18249,10 @@
.Function448bb: ; 0x448bb
push af
- ld a, BANK(s0_a834)
+ ld a, BANK(sMailboxCount)
call GetSRAMBank
pop af
- ld hl, s0_a835 + $2e
+ ld hl, sMailbox + $2e
ld bc, $2f
call AddNTimes
ld a, [hl]
@@ -18455,7 +18265,7 @@
xor a
ld [PartyMenuActionText], a
call ClearBGPalettes
-.asm_448dc
+.try_again
callba Function5004f
callba Function50405
callba Function503e0
@@ -18465,25 +18275,25 @@
call SetPalettes
call DelayFrame
callba PartyMenuSelect
- jr c, .asm_44939
+ jr c, .exit
ld a, [CurPartySpecies]
cp EGG
- jr z, .asm_44923
+ jr z, .egg
ld a, MON_ITEM
call GetPartyParamLocation
ld a, [hl]
and a
- jr z, .asm_4492b
+ jr z, .attach_mail
ld hl, .HoldingMailText
call PrintText
- jr .asm_448dc
+ jr .try_again
-.asm_44923
+.egg
ld hl, .EggText
call PrintText
- jr .asm_448dc
+ jr .try_again
-.asm_4492b
+.attach_mail
ld a, [MenuSelection]
dec a
ld b, a
@@ -18491,8 +18301,8 @@
ld hl, .MailMovedText
call PrintText
-.asm_44939
- jp Function2b3c
+.exit
+ jp ReturnToCallingMenu
; 0x4493c
.HoldingMailText ; 0x4493c
@@ -18720,7 +18530,7 @@
ld [ScriptVar], a
.asm_492a1
- call Function2b3c
+ call ReturnToCallingMenu
ret
; 492a5
@@ -19924,7 +19734,7 @@
jr c, .asm_4a974
.asm_4a990
- call Function2b3c
+ call ReturnToCallingMenu
ld hl, wd002
ld a, -1
ld bc, 3
@@ -19937,7 +19747,7 @@
jr c, .asm_4a9b0
call Function4a9d7
jr c, .asm_4a974
- call Function2b3c
+ call ReturnToCallingMenu
and a
.asm_4a9af
@@ -24838,27 +24648,27 @@
pop de
ld hl, wd002
call .CopyName
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld a, [Buffer2] ; wd1eb (aliases: MovementType)
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
push hl
ld de, wd002
- ld bc, SCRATCHMON_STRUCT_LENGTH
- ld a, BANK(sPartyScratch1)
+ ld bc, MAIL_STRUCT_LENGTH
+ ld a, BANK(sPartyMail)
call GetSRAMBank
call CopyBytes
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld a, [Buffer3]
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
pop de
push hl
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
pop de
ld hl, wd002
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
call CloseSRAM
pop bc
@@ -31402,8 +31212,8 @@
ReadPartyMonMail: ; b9229
ld a, [CurPartyMon]
- ld hl, sPartyScratch1
- ld bc, SCRATCHMON_STRUCT_LENGTH
+ ld hl, sPartyMail
+ ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
@@ -31416,7 +31226,7 @@
call LoadFontsExtra
pop de
push de
- ld a, BANK(sPartyScratch1)
+ ld a, BANK(sPartyMail)
call GetSRAMBank
callba Function1de5c8
call CloseSRAM
@@ -41337,24 +41147,25 @@
; 1de5c8
Function1de5c8: ; 1de5c8
+; reads mail message at de
ld c, $0
ld hl, $29
add hl, de
ld a, [hli]
- cp $84
+ cp "E"
ret nz
ld a, [hli]
inc c
- cp $85
+ cp "F"
ret z
inc c
- cp $86
+ cp "G"
ret z
inc c
- cp $88
+ cp "I"
ret z
inc c
- cp $92
+ cp "S"
ret z
ld c, $0
ret
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -2523,7 +2523,7 @@
db -1
Unknown_100feb: ; 100feb
- dbwww $00, sPartyScratch1, SCRATCHMON_STRUCT_LENGTH * PARTY_LENGTH, NULL
+ dbwww $00, sPartyMail, MAIL_STRUCT_LENGTH * PARTY_LENGTH, NULL
db -1
Unknown_100ff3: ; 100ff3
--- a/misc/mobile_46.asm
+++ b/misc/mobile_46.asm
@@ -5842,7 +5842,7 @@
call FadeToMenu
callab InefficientlyClear121BytesAtwc300
call Function11ac51
- call Function2b3c
+ call ReturnToCallingMenu
ret
; 11ac51
@@ -7697,7 +7697,7 @@
ld [de], a
.asm_11b872
- call Function2b3c
+ call ReturnToCallingMenu
call RestartMapMusic
ret
; 11b879
@@ -7919,7 +7919,7 @@
call CopyBytes
ld a, "@"
ld [de], a
- ld hl, sPartyScratch1
+ ld hl, sPartyMail
ld bc, PARTYMON_STRUCT_LENGTH - 1
ld a, [wcd2a]
.loop5
--- a/misc/mobile_5c.asm
+++ b/misc/mobile_5c.asm
@@ -278,7 +278,7 @@
call FadeToMenu
call Function17021e
call Function1704f1
- call Function2b3c
+ call ReturnToCallingMenu
ret
; 1704f1
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -324,7 +324,7 @@
ld [de], a
.asm_17d180
- call Function2b3c
+ call ReturnToCallingMenu
call RestartMapMusic
ret
; 17d187
@@ -562,7 +562,7 @@
ld [MusicFadeIDHi], a
call PlayMusic
call ReturnToMapFromSubmenu
- call Function2b3c
+ call ReturnToCallingMenu
ret
; 17d314
@@ -4674,7 +4674,7 @@
call Function17f555
pop af
ld [rSVBK], a
- call Function2b4d
+ call ExitAllMenus
ret
; 17f555
--- a/sram.asm
+++ b/sram.asm
@@ -9,12 +9,54 @@
SECTION "SRAM Bank 0", SRAM [$a600], BANK [0]
-sPartyScratch1:: ds 6 * SCRATCHMON_STRUCT_LENGTH
-sPartyScratch2:: ds 6 * SCRATCHMON_STRUCT_LENGTH
-s0_a834:: ds 1
-s0_a835:: ds 10 * SCRATCHMON_STRUCT_LENGTH
-s0_aa0b:: ds 1
-s0_aa0c:: ds 10 * SCRATCHMON_STRUCT_LENGTH
+mailmsg: MACRO
+\1Message:: ds $20
+\1Author:: ds NAME_LENGTH
+ ds 3
+\1MailType:: ds 1
+endm
+
+sPartyMail::
+sPartyMon1Mail:: mailmsg sPartyMon1Mail
+sPartyMon2Mail:: mailmsg sPartyMon2Mail
+sPartyMon3Mail:: mailmsg sPartyMon3Mail
+sPartyMon4Mail:: mailmsg sPartyMon4Mail
+sPartyMon5Mail:: mailmsg sPartyMon5Mail
+sPartyMon6Mail:: mailmsg sPartyMon6Mail
+
+sPartyMailBackup::
+sPartyMon1MailBackup:: mailmsg sPartyMon1MailBackup
+sPartyMon2MailBackup:: mailmsg sPartyMon2MailBackup
+sPartyMon3MailBackup:: mailmsg sPartyMon3MailBackup
+sPartyMon4MailBackup:: mailmsg sPartyMon4MailBackup
+sPartyMon5MailBackup:: mailmsg sPartyMon5MailBackup
+sPartyMon6MailBackup:: mailmsg sPartyMon6MailBackup
+
+sMailboxCount:: ds 1
+sMailbox::
+sMailbox1:: mailmsg sMailbox1
+sMailbox2:: mailmsg sMailbox2
+sMailbox3:: mailmsg sMailbox3
+sMailbox4:: mailmsg sMailbox4
+sMailbox5:: mailmsg sMailbox5
+sMailbox6:: mailmsg sMailbox6
+sMailbox7:: mailmsg sMailbox7
+sMailbox8:: mailmsg sMailbox8
+sMailbox9:: mailmsg sMailbox9
+sMailbox10:: mailmsg sMailbox10
+
+sMailboxCountBackup:: ds 1
+sMailboxBackup::
+sMailbox1Backup:: mailmsg sMailbox1Backup
+sMailbox2Backup:: mailmsg sMailbox2Backup
+sMailbox3Backup:: mailmsg sMailbox3Backup
+sMailbox4Backup:: mailmsg sMailbox4Backup
+sMailbox5Backup:: mailmsg sMailbox5Backup
+sMailbox6Backup:: mailmsg sMailbox6Backup
+sMailbox7Backup:: mailmsg sMailbox7Backup
+sMailbox8Backup:: mailmsg sMailbox8Backup
+sMailbox9Backup:: mailmsg sMailbox9Backup
+sMailbox10Backup:: mailmsg sMailbox10Backup
sMysteryGiftItem:: ds 1
s0_abe3:: ds 1