pokecrystal-board/engine/mail.asm

590 lines
9.1 KiB
NASM
Raw Normal View History

2015-11-17 14:56:49 -08:00
SendMailToPC: ; 4456e
ld a, MON_ITEM
call GetPartyParamLocation
ld d, [hl]
2017-12-24 09:47:30 -08:00
farcall ItemIsMail
2015-11-17 14:56:49 -08:00
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
2015-12-28 14:09:53 -08:00
ld [hl], 0
2015-11-17 14:56:49 -08:00
ld hl, sMailboxCount
inc [hl]
call CloseSRAM
xor a
ret
.full
scf
ret
; 445c0
2015-11-18 07:42:42 -08:00
DeleteMailFromPC: ; 445c0 (11:45c0)
; Shift all mail messages in the mailbox
2015-11-17 14:56:49 -08:00
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
2015-11-18 07:42:42 -08:00
cp MAILBOX_CAPACITY - 1
2015-11-17 14:56:49 -08:00
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
2017-12-24 09:47:30 -08:00
farcall ReadAnyMail
2015-11-17 14:56:49 -08:00
ret
2015-11-18 07:42:42 -08:00
MoveMailFromPCToParty: ; 44607
2015-11-17 14:56:49 -08:00
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
2015-11-18 07:42:42 -08:00
jp DeleteMailFromPC
2015-11-17 14:56:49 -08:00
; 44648 (11:4648)
GetMailboxCount: ; 44648
ld a, BANK(sMailboxCount)
call GetSRAMBank
ld a, [sMailboxCount]
ld c, a
jp CloseSRAM
; 44654
2015-11-18 07:42:42 -08:00
CheckPokeItem:: ; 44654
2015-11-17 14:56:49 -08:00
push bc
push de
2017-12-24 09:47:30 -08:00
farcall SelectMonFromParty
2015-11-17 14:56:49 -08:00
ld a, $2
2015-11-18 07:42:42 -08:00
jr c, .pop_return
2015-11-17 14:56:49 -08:00
ld a, [CurPartyMon]
ld hl, PartyMon1Item
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld d, [hl]
2017-12-24 09:47:30 -08:00
farcall ItemIsMail
2015-11-17 14:56:49 -08:00
ld a, $3
2015-11-18 07:42:42 -08:00
jr nc, .pop_return
2015-11-17 14:56:49 -08:00
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
2015-11-18 07:42:42 -08:00
; Compare the mail message, byte for byte, with the expected message.
ld a, MAIL_MSG_LENGTH
2015-11-17 14:56:49 -08:00
ld [wd265], a
2015-11-18 07:42:42 -08:00
.loop
2015-11-17 14:56:49 -08:00
ld a, [de]
ld c, a
ld a, b
call GetFarByte
cp "@"
2015-11-18 07:42:42 -08:00
jr z, .done
2015-11-17 14:56:49 -08:00
cp c
ld a, $0
2015-11-18 07:42:42 -08:00
jr nz, .close_sram_return
2015-11-17 14:56:49 -08:00
inc hl
inc de
ld a, [wd265]
dec a
ld [wd265], a
2015-11-18 07:42:42 -08:00
jr nz, .loop
2015-11-17 14:56:49 -08:00
2015-11-18 07:42:42 -08:00
.done
2017-12-24 09:47:30 -08:00
farcall CheckCurPartyMonFainted
2015-11-17 14:56:49 -08:00
ld a, $4
2015-11-18 07:42:42 -08:00
jr c, .close_sram_return
2015-11-17 14:56:49 -08:00
xor a
ld [wPokemonWithdrawDepositParameter], a
2017-12-24 09:47:30 -08:00
farcall RemoveMonFromPartyOrBox
2015-11-17 14:56:49 -08:00
ld a, $1
2015-11-18 07:42:42 -08:00
.close_sram_return
2015-11-17 14:56:49 -08:00
call CloseSRAM
2015-11-18 07:42:42 -08:00
jr .return
2015-11-17 14:56:49 -08:00
2015-11-18 07:42:42 -08:00
.pop_return
2015-11-17 14:56:49 -08:00
pop de
pop bc
2015-11-18 07:42:42 -08:00
.return
2015-11-17 14:56:49 -08:00
ld [ScriptVar], a
ret
; 446cc
2015-11-18 07:42:42 -08:00
GivePokeItem:: ; 446cc
ld a, [PartyCount]
dec a
push af
push bc
ld hl, PartyMon1Item
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop bc
ld [hl], b
pop af
push bc
push af
ld hl, sPartyMail
2015-12-29 10:15:58 -08:00
ld bc, MAIL_STRUCT_LENGTH
2015-11-18 07:42:42 -08:00
call AddNTimes
ld d, h
ld e, l
ld hl, wd002
2015-12-29 10:15:58 -08:00
ld bc, MAIL_MSG_LENGTH + 1
2015-11-18 07:42:42 -08:00
ld a, BANK(sPartyMail)
call GetSRAMBank
call CopyBytes
pop af
push af
ld hl, PartyMonOT
ld bc, NAME_LENGTH
call AddNTimes
2015-12-29 10:15:58 -08:00
ld bc, NAME_LENGTH - 1
2015-11-18 07:42:42 -08:00
call CopyBytes
pop af
ld hl, PartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
inc de
ld a, [CurPartySpecies]
ld [de], a
inc de
pop bc
ld a, b
ld [de], a
jp CloseSRAM
; 44725
BackupPartyMonMail: ; 44725
ld a, BANK(sPartyMail)
call GetSRAMBank
ld hl, sPartyMail
ld de, sPartyMailBackup
ld bc, 6 * MAIL_STRUCT_LENGTH
call CopyBytes
ld hl, sMailboxCount
ld de, sMailboxCountBackup
ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call CopyBytes
jp CloseSRAM
; 44745
RestorePartyMonMail: ; 44745 (11:4745)
ld a, BANK(sPartyMail)
call GetSRAMBank
ld hl, sPartyMailBackup
ld de, sPartyMail
ld bc, 6 * MAIL_STRUCT_LENGTH
call CopyBytes
ld hl, sMailboxCountBackup
ld de, sMailboxCount
ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call CopyBytes
jp CloseSRAM
DeletePartyMonMail: ; 44765 (11:4765)
ld a, BANK(sPartyMail)
call GetSRAMBank
xor a
ld hl, sPartyMail
ld bc, 6 * MAIL_STRUCT_LENGTH
call ByteFill
xor a
ld hl, sMailboxCount
ld bc, 1 + 10 * MAIL_STRUCT_LENGTH
call ByteFill
jp CloseSRAM
; 44781 (11:4781)
2015-11-18 10:01:55 -08:00
IsAnyMonHoldingMail: ; 44781
2015-11-18 07:42:42 -08:00
ld a, [PartyCount]
and a
2015-11-18 10:01:55 -08:00
jr z, .no_mons
2015-11-18 07:42:42 -08:00
ld e, a
ld hl, PartyMon1Item
2015-11-18 10:01:55 -08:00
.loop
2015-11-18 07:42:42 -08:00
ld d, [hl]
push hl
push de
2017-12-24 09:47:30 -08:00
farcall ItemIsMail
2015-11-18 07:42:42 -08:00
pop de
pop hl
ret c
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
dec e
2015-11-18 10:01:55 -08:00
jr nz, .loop
2015-11-18 07:42:42 -08:00
2015-11-18 10:01:55 -08:00
.no_mons
2015-11-18 07:42:42 -08:00
and a
ret
; 447a0
_KrisMailBoxMenu: ; 0x447a0
call InitMail
jr z, .nomail
call LoadStandardMenuDataHeader
call MailboxPC
jp CloseWindow
2015-11-18 07:42:42 -08:00
.nomail
ld hl, .EmptyMailboxText
jp MenuTextBoxBackup
; 0x447b4
.EmptyMailboxText: ; 0x447b4
2015-11-18 07:42:42 -08:00
text_jump _EmptyMailboxText
db "@"
InitMail: ; 0x447b9
2015-11-18 10:01:55 -08:00
; initialize wMailboxCount and beyond with incrementing values, one per mail
2015-11-18 07:42:42 -08:00
; set z if no mail
ld a, BANK(sMailboxCount)
call GetSRAMBank
ld a, [sMailboxCount]
call CloseSRAM
2015-11-18 10:01:55 -08:00
ld hl, wMailboxCount
2015-11-18 07:42:42 -08:00
ld [hli], a
and a
jr z, .done ; if no mail, we're done
2015-11-18 10:01:55 -08:00
; load values in memory with incrementing values starting at wMailboxCount
2015-11-18 07:42:42 -08:00
ld b, a
2015-11-18 10:01:55 -08:00
ld a, 1
2015-11-18 07:42:42 -08:00
.loop
ld [hli], a
inc a
dec b
jr nz, .loop
.done
2015-11-18 10:01:55 -08:00
ld [hl], -1 ; terminate
2015-11-18 07:42:42 -08:00
2015-11-18 10:01:55 -08:00
ld a, [wMailboxCount]
2015-11-18 07:42:42 -08:00
and a
ret
; 0x447da
2015-12-28 14:09:53 -08:00
MailboxPC_GetMailAuthor: ; 0x447da
2015-11-18 07:42:42 -08:00
dec a
ld hl, sMailbox1Author
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld a, BANK(sMailboxCount)
call GetSRAMBank
ld de, StringBuffer2
push de
ld bc, NAME_LENGTH - 1
call CopyBytes
ld a, "@"
ld [de], a
call CloseSRAM
pop de
ret
; 0x447fb
2015-12-28 14:09:53 -08:00
MailboxPC_PrintMailAuthor: ; 0x447fb
2015-11-18 07:42:42 -08:00
push de
ld a, [MenuSelection]
2015-12-28 14:09:53 -08:00
call MailboxPC_GetMailAuthor
2015-11-18 07:42:42 -08:00
pop hl
jp PlaceString
; 0x44806
MailboxPC: ; 0x44806
xor a
2017-12-26 17:33:41 -08:00
ld [OBPals palette 6], a
2015-12-28 14:09:53 -08:00
ld a, 1
2015-11-18 10:01:55 -08:00
ld [wCurMessageIndex], a
2015-11-18 07:42:42 -08:00
.loop
call InitMail
2015-12-28 14:09:53 -08:00
ld hl, .TopMenuDataHeader
2015-11-18 07:42:42 -08:00
call CopyMenuDataHeader
xor a
ld [hBGMapMode], a
call InitScrollingMenu
call UpdateSprites
2015-11-18 10:01:55 -08:00
ld a, [wCurMessageIndex]
2015-11-18 07:42:42 -08:00
ld [wMenuCursorBuffer], a
2017-12-26 17:33:41 -08:00
ld a, [OBPals palette 6]
2015-11-23 13:04:53 -08:00
ld [wMenuScrollPosition], a
2015-12-17 19:31:16 -08:00
call ScrollingMenu
2015-11-23 13:04:53 -08:00
ld a, [wMenuScrollPosition]
2017-12-26 17:33:41 -08:00
ld [OBPals palette 6], a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-11-18 10:01:55 -08:00
ld [wCurMessageIndex], a
2015-12-15 15:59:49 -08:00
ld a, [wMenuJoypad]
2015-12-28 14:09:53 -08:00
cp B_BUTTON
2015-11-18 07:42:42 -08:00
jr z, .exit
2015-12-28 14:09:53 -08:00
call .Submenu
2015-11-18 07:42:42 -08:00
jr .loop
.exit
xor a
ret
; 0x4484a
2015-12-28 14:09:53 -08:00
.Submenu: ; 0x4484a
ld hl, .SubMenuDataHeader
2015-11-18 07:42:42 -08:00
call LoadMenuDataHeader
2015-12-15 15:59:49 -08:00
call VerticalMenu
2015-11-18 07:42:42 -08:00
call ExitMenu
2015-12-28 14:09:53 -08:00
jr c, .subexit
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-11-18 07:42:42 -08:00
dec a
ld hl, .JumpTable
rst JumpTable
2015-12-28 14:09:53 -08:00
.subexit
2015-11-18 07:42:42 -08:00
ret
; 0x44861
.JumpTable:
2015-11-18 07:42:42 -08:00
dw .ReadMail
dw .PutInPack
dw .AttachMail
dw .Cancel
.ReadMail: ; 0x44869
2015-11-18 07:42:42 -08:00
call FadeToMenu
ld a, [MenuSelection]
dec a
ld b, a
call ReadMailMessage
jp CloseSubmenu
2015-11-18 07:42:42 -08:00
; 0x44877
.PutInPack: ; 0x44877
2015-11-18 07:42:42 -08:00
ld hl, .MessageLostText
call MenuTextBox
call YesNoBox
call ExitMenu
ret c
ld a, [MenuSelection]
dec a
call .GetMailType
2015-12-28 14:09:53 -08:00
ld a, 1
2015-11-18 07:42:42 -08:00
ld [wItemQuantityChangeBuffer], a
ld hl, NumItems
call ReceiveItem
jr c, .put_in_bag
ld hl, .PackFullText
jp MenuTextBoxBackup
.put_in_bag
ld a, [MenuSelection]
dec a
ld b, a
call DeleteMailFromPC
ld hl, .PutAwayText
jp MenuTextBoxBackup
; 0x448ac
.PutAwayText: ; 0x448ac
2015-11-18 07:42:42 -08:00
text_jump ClearedMailPutAwayText
db "@"
.PackFullText: ; 0x448b1
2015-11-18 07:42:42 -08:00
text_jump MailPackFullText
db "@"
.MessageLostText: ; 0x448b6
2015-11-18 07:42:42 -08:00
text_jump MailMessageLostText
db "@"
.GetMailType: ; 0x448bb
push af
ld a, BANK(sMailboxCount)
call GetSRAMBank
pop af
2015-11-22 21:21:21 -08:00
ld hl, sMailbox1Type
2015-11-18 07:42:42 -08:00
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld a, [hl]
ld [CurItem], a
jp CloseSRAM
; 0x448d2
.AttachMail: ; 0x448d2
2015-11-18 07:42:42 -08:00
call FadeToMenu
xor a
ld [PartyMenuActionText], a
call ClearBGPalettes
.try_again
2017-12-24 09:47:30 -08:00
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
2015-11-18 07:42:42 -08:00
call WaitBGMap
call SetPalettes
call DelayFrame
2017-12-24 09:47:30 -08:00
farcall PartyMenuSelect
2015-11-18 07:42:42 -08:00
jr c, .exit2
ld a, [CurPartySpecies]
cp EGG
jr z, .egg
ld a, MON_ITEM
call GetPartyParamLocation
ld a, [hl]
and a
jr z, .attach_mail
ld hl, .HoldingMailText
call PrintText
jr .try_again
.egg
ld hl, .EggText
call PrintText
jr .try_again
.attach_mail
ld a, [MenuSelection]
dec a
ld b, a
call MoveMailFromPCToParty
ld hl, .MailMovedText
call PrintText
.exit2
jp CloseSubmenu
2015-11-18 07:42:42 -08:00
; 0x4493c
.HoldingMailText: ; 0x4493c
2015-11-18 07:42:42 -08:00
text_jump MailAlreadyHoldingItemText
db "@"
.EggText: ; 0x44941
2015-11-18 07:42:42 -08:00
text_jump MailEggText
db "@"
.MailMovedText: ; 0x44946
2015-11-18 07:42:42 -08:00
text_jump MailMovedFromBoxText
db "@"
.Cancel:
2015-11-18 07:42:42 -08:00
ret
2015-12-28 14:09:53 -08:00
.TopMenuDataHeader: ; 0x4494c
2015-11-18 07:42:42 -08:00
db %01000000 ; flags
db 1, 8 ; start coords
2015-11-18 10:01:55 -08:00
db 10, 18 ; end coords
2015-12-28 14:09:53 -08:00
dw .TopMenuData2
2015-11-18 07:42:42 -08:00
db 1 ; default option
.TopMenuData2:
2015-11-18 07:42:42 -08:00
db %00010000 ; flags
db 4, 0 ; rows/columns?
db 1 ; horizontal spacing?
2015-11-18 10:01:55 -08:00
dbw 0, wMailboxCount ; text pointer
2015-12-28 14:09:53 -08:00
dba MailboxPC_PrintMailAuthor
dba NULL
dba NULL
2015-11-18 07:42:42 -08:00
2015-12-28 14:09:53 -08:00
.SubMenuDataHeader: ; 0x44964
2015-11-18 07:42:42 -08:00
db %01000000 ; flags
2015-12-28 14:09:53 -08:00
db 0, 0 ; start coords
db 9, 13 ; end coords
dw .SubMenuData2
2015-11-18 07:42:42 -08:00
db 1 ; default option
.SubMenuData2:
2015-11-18 07:42:42 -08:00
db %10000000 ; flags
db 4 ; items
db "READ MAIL@"
db "PUT IN PACK@"
db "ATTACH MAIL@"
db "CANCEL@"