pokecrystal-board/engine/mysterygift.asm

1712 lines
26 KiB
NASM
Raw Normal View History

2015-11-22 21:21:21 -08:00
DoMysteryGift: ; 1048ba (41:48ba)
call ClearTileMap
call ClearSprites
call WaitBGMap
call Function105153
hlcoord 3, 8
ld de, .String_PressAToLink_BToCancel
call PlaceString
call WaitBGMap
callba Function2c642
call Function1050fb
ld a, $2
ld [wca01], a
ld a, $14
ld [wca02], a
ld a, [rIE]
push af
2015-12-14 17:06:41 -08:00
2015-11-22 21:21:21 -08:00
call Function104a95
2015-12-14 17:06:41 -08:00
2015-11-22 21:21:21 -08:00
ld d, a
xor a
ld [rIF], a
pop af
ld [rIE], a
push de
call ClearTileMap
call EnableLCD
call WaitBGMap
ld b, SCGB_08
call GetSGBLayout
call SetPalettes
pop de
hlcoord 2, 8
ld a, d
ld de, .Text_LinkCanceled ; Link has been canceled
cp $10
jp z, .LinkCanceled
cp $6c
jp nz, .CommunicationError
ld a, [wc900]
2015-12-14 17:06:41 -08:00
cp 3
2015-11-22 21:21:21 -08:00
jr z, .skip_checks
call .CheckAlreadyGotFiveGiftsToday
ld hl, .Text_MaxFiveGifts ; Only 5 gifts a day
jp nc, .PrintTextAndExit
call .CheckAlreadyGotAGiftFromThatPerson
ld hl, .Text_MaxOneGiftPerPerson ; Only one gift a day per person
jp c, .PrintTextAndExit
.skip_checks
2015-12-14 17:06:41 -08:00
ld a, [wMysteryGiftPlayerBackupItem]
2015-11-22 21:21:21 -08:00
and a
jp nz, .GiftWaiting
ld a, [wc912]
and a
jp nz, .FriendNotReady
ld a, [wc900]
2015-12-14 17:06:41 -08:00
cp 3
2015-11-22 21:21:21 -08:00
jr z, .skip_append_save
call .AddMysteryGiftPartnerID
ld a, [wc900]
2015-12-14 17:06:41 -08:00
cp 4
2015-11-22 21:21:21 -08:00
jr z, .skip_append_save
call .SaveMysteryGiftTrainerName
callba RestoreMobileEventIndex
callba MobileFn_1060a9
callba BackupMobileEventIndex
.skip_append_save
2015-12-14 17:06:41 -08:00
ld a, [wMysteryGiftPartnerSentDeco]
2015-11-22 21:21:21 -08:00
and a
jr z, .item
2015-12-14 17:06:41 -08:00
ld a, [wMysteryGiftPartnerWhichDeco]
2015-11-22 21:21:21 -08:00
ld c, a
callba MysteryGiftGetDecoration
push bc
call Function105069
pop bc
jr nz, .item
callab GetDecorationName_c
ld h, d
ld l, e
ld de, StringBuffer1
ld bc, ITEM_NAME_LENGTH
call CopyBytes
ld hl, .Text_SentToHome ; sent decoration to home
jr .PrintTextAndExit
.item
call GetMysteryGiftBank
2015-12-14 17:06:41 -08:00
ld a, [wMysteryGiftPartnerWhichItem]
2015-11-22 21:21:21 -08:00
ld c, a
callba MysteryGiftGetItemHeldEffect
ld a, c
ld [sBackupMysteryGiftItem], a
ld [wNamedObjectIndexBuffer], a
call CloseSRAM
call GetItemName
ld hl, .Text_Sent ; sent item
jr .PrintTextAndExit
.LinkCanceled: ; 1049af (41:49af)
ld hl, .Text_LinkCanceled ; Link has been canceled
jr .PrintTextAndExit
.CommunicationError: ; 1049b4 (41:49b4)
ld hl, .Text_CommunicationError ; Communication error
call PrintText
jp DoMysteryGift
.GiftWaiting: ; 1049bd (41:49bd)
ld hl, .Text_ReceiveGiftAtCounter ; receive gift at counter
jr .PrintTextAndExit
.FriendNotReady: ; 1049c2 (41:49c2)
ld hl, .Text_FriendNotReady ; friend not ready
.PrintTextAndExit: ; 1049c5 (41:49c5)
call PrintText
ld a, $e3
ld [rLCDC], a
ret
; 1049cd (41:49cd)
.String_PressAToLink_BToCancel: ; 1049cd
db "Press A to"
next "link IR-Device"
next "Press B to"
next "cancel it."
db "@"
; 1049fd
.Text_LinkCanceled: ; 1049fd
text_jump UnknownText_0x1c0436
db "@"
; 104a02
.Text_CommunicationError: ; 104a02
text_jump UnknownText_0x1c0454
db "@"
; 104a07
.Text_ReceiveGiftAtCounter: ; 104a07
text_jump UnknownText_0x1c046a
db "@"
; 104a0c
.Text_FriendNotReady: ; 104a0c
text_jump UnknownText_0x1c048e
db "@"
; 104a11
.Text_MaxFiveGifts: ; 104a11
text_jump UnknownText_0x1c04a7
db "@"
; 104a16
.Text_MaxOneGiftPerPerson: ; 104a16
text_jump UnknownText_0x1c04c6
db "@"
; 104a1b
.Text_Sent: ; 104a1b
text_jump UnknownText_0x1c04e9
db "@"
; 104a20
.Text_SentToHome: ; 104a20
text_jump UnknownText_0x1c04fa
db "@"
; 104a25
.CheckAlreadyGotFiveGiftsToday: ; 104a25 (41:4a25)
call GetMysteryGiftBank
ld a, [sNumDailyMysteryGiftPartnerIDs]
cp $5
jp CloseSRAM
.CheckAlreadyGotAGiftFromThatPerson: ; 104a30 (41:4a30)
call GetMysteryGiftBank
ld a, [wMysteryGiftPartnerID]
ld b, a
ld a, [wMysteryGiftPartnerID + 1]
ld c, a
ld a, [sNumDailyMysteryGiftPartnerIDs]
ld d, a
ld hl, sDailyMysteryGiftPartnerIDs
.loop
ld a, d
and a
jr z, .No
ld a, [hli]
cp b
jr nz, .skip
ld a, [hl]
cp c
jr z, .Yes
.skip
inc hl
dec d
jr .loop
.Yes
scf
.No
jp CloseSRAM
.AddMysteryGiftPartnerID: ; 104a56 (41:4a56)
call GetMysteryGiftBank
ld hl, sNumDailyMysteryGiftPartnerIDs
ld a, [hl]
inc [hl]
ld hl, sDailyMysteryGiftPartnerIDs ; inc hl
ld e, a
ld d, $0
rept 2
add hl, de
endr
ld a, [wMysteryGiftPartnerID]
ld [hli], a
ld a, [wMysteryGiftPartnerID + 1]
ld [hl], a
jp CloseSRAM
.SaveMysteryGiftTrainerName: ; 104a71 (41:4a71)
call GetMysteryGiftBank
ld a, $1
ld [sMysteryGiftTrainerHouseFlag], a
ld hl, wMysteryGiftPartnerName
ld de, sMysteryGiftPartnerName
ld bc, NAME_LENGTH
call CopyBytes
ld a, $1
ld [de], a
inc de
ld hl, wMysteryGiftTrainerData
ld bc, (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2
call CopyBytes
jp CloseSRAM
Function104a95: ; 104a95 (41:4a95)
di
callba ClearChannels
call Function104d5e
.loop2
call Function104d96
call Function104ddd
ld a, [hPrintNum10]
cp $10
jp z, Function104bd0
cp $6c
jr nz, .loop2
ld a, [hPrintNum9]
cp $2
jr z, Function104b22
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d56
jr nz, .ly_loop
call Function104b49
jp nz, Function104bd0
jr asm_104b0a
.ly_loop
ld a, [rLY]
cp $90
jr c, .ly_loop
ld c, rRP % $100
ld a, $c0
ld [$ff00+c], a
ld b, $f0
.loop3
push bc
call Function105038
ld b, $2
ld c, rRP % $100
.ly_loop2
ld a, [$ff00+c]
and b
ld b, a
ld a, [rLY]
cp $90
jr nc, .ly_loop2
.ly_loop3
ld a, [$ff00+c]
and b
ld b, a
ld a, [rLY]
cp $90
jr c, .ly_loop3
ld a, b
pop bc
dec b
jr z, .loop2
or a
jr nz, .loop2
ld a, [hMoneyTemp + 1]
bit 1, a
jr z, .loop3
ld a, $10
ld [hPrintNum10], a
jp Function104bd0
Function104b04: ; 104b04 (41:4b04)
call Function104b40
jp nz, Function104bd0
asm_104b0a: ; 104b0a (41:4b0a)
call Function104d38
jp nz, Function104bd0
call Function104b88
jp nz, Function104bd0
call Function104d43
jp nz, Function104bd0
call Function105033
jp Function104bd0
Function104b22: ; 104b22 (41:4b22)
call Function104b88
jp nz, Function104bd0
call Function104d43
jp nz, Function104bd0
call Function104b40
jp nz, Function104bd0
call Function104d38
jp nz, Function104bd0
call Function10502e
jp Function104bd0
Function104b40: ; 104b40 (41:4b40)
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d56
ret nz
Function104b49: ; 104b49 (41:4b49)
call Function105033
ld a, [hPrintNum10]
cp $6c
ret nz
2015-12-14 17:06:41 -08:00
ld a, [hPrintNum1]
2015-11-22 21:21:21 -08:00
cp $96
jp nz, Function104d32
ld a, $90
2015-12-14 17:06:41 -08:00
ld [hPrintNum1], a
2015-11-22 21:21:21 -08:00
call Function104d38
ret nz
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret nz
call Function104d43
ret nz
ld hl, wMysteryGiftTrainerData
ld a, [wca02]
ld b, a
call Function104d56
ret nz
call Function105033
ld a, [hPrintNum10]
cp $6c
ret
Function104b88: ; 104b88 (41:4b88)
ld a, $96
2015-12-14 17:06:41 -08:00
ld [hPrintNum1], a
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret nz
call Function104d43
ret nz
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d56
ret nz
call Function105033
ld a, [hPrintNum10]
cp $6c
ret nz
2015-12-14 17:06:41 -08:00
ld a, [hPrintNum1]
2015-11-22 21:21:21 -08:00
cp $90
jp nz, Function104d32
call Function104d38
ret nz
ld hl, OverworldMap
ld a, [wca02]
ld b, a
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret
Function104bd0: ; 104bd0 (41:4bd0)
nop
ld a, [hPrintNum10]
cp $10
jr z, .asm_104c18
cp $6c
jr nz, .asm_104c18
ld hl, wca01
dec [hl]
jr z, .asm_104c18
ld hl, wMysteryGiftTrainerData
2015-12-14 17:06:41 -08:00
ld de, wMysteryGiftPartnerData
ld bc, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData
2015-11-22 21:21:21 -08:00
call CopyBytes
ld a, [wMysteryGiftTrainerData]
cp $3
jr nc, .asm_104c18
2015-12-14 17:06:41 -08:00
callba StagePartyDataForMysteryGift
2015-11-22 21:21:21 -08:00
call Function1050fb
ld a, $26
ld [wca02], a
ld a, [hPrintNum9]
cp $2
jr z, .asm_104c10
call Function104d43
jr nz, Function104bd0
jp Function104b04
.asm_104c10
call Function104d38
jr nz, Function104bd0
jp Function104b22
.asm_104c18
ld a, [hPrintNum10]
push af
call Function104da0
xor a
ld [rIF], a
ld a, [rIE]
or $1
ld [rIE], a
ei
call DelayFrame
pop af
ret
Function104c2d: ; 104c2d (41:4c2d)
di
callba ClearChannels
call Function104d5e
.asm_104c37
call Function104d96
call Function104ddd
ld a, [hPrintNum10]
cp $10
jp z, Function104d1c
cp $6c
jr nz, .asm_104c37
ld a, [hPrintNum9]
cp $2
jr z, .asm_104c6c
call Function104c8a
jp nz, Function104d1c
call Function104d38
jp nz, Function104d1c
call Function104cd2
jp nz, Function104d1c
call Function104d43
jp nz, Function104d1c
call Function105033
jp Function104d1c
.asm_104c6c
call Function104cd2
jp nz, Function104d1c
call Function104d43
jp nz, Function104d1c
call Function104c8a
jp nz, Function104d1c
call Function104d38
jp nz, Function104d1c
call Function10502e
jp Function104d1c
Function104c8a: ; 104c8a (41:4c8a)
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d56
ret nz
call Function105033
ld a, [hPrintNum10]
cp $6c
ret nz
2015-12-14 17:06:41 -08:00
ld a, [hPrintNum1]
2015-11-22 21:21:21 -08:00
cp $3c
jp nz, Function104d32
swap a
2015-12-14 17:06:41 -08:00
ld [hPrintNum1], a
2015-11-22 21:21:21 -08:00
call Function104d38
ret nz
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret nz
call Function104d43
ret nz
ld hl, wMysteryGiftTrainerData
ld a, [wca02]
ld b, a
call Function104d56
ret nz
call Function105033
ld a, [hPrintNum10]
cp $6c
ret
Function104cd2: ; 104cd2 (41:4cd2)
ld a, $3c
2015-12-14 17:06:41 -08:00
ld [hPrintNum1], a
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret nz
call Function104d43
ret nz
2015-12-14 17:06:41 -08:00
ld hl, hPrintNum1
2015-11-22 21:21:21 -08:00
ld b, $1
call Function104d56
ret nz
call Function105033
ld a, [hPrintNum10]
cp $6c
ret nz
2015-12-14 17:06:41 -08:00
ld a, [hPrintNum1]
2015-11-22 21:21:21 -08:00
swap a
cp $3c
jp nz, Function104d32
call Function104d38
ret nz
ld hl, OverworldMap
ld a, [wca02]
ld b, a
call Function104d4e
ret nz
call Function10502e
ld a, [hPrintNum10]
cp $6c
ret
Function104d1c: ; 104d1c (41:4d1c)
nop
ld a, [hPrintNum10]
push af
call Function104da0
xor a
ld [rIF], a
ld a, [rIE]
or $1
ld [rIE], a
ei
call DelayFrame
pop af
ret
Function104d32: ; 104d32 (41:4d32)
ld a, $80
ld [hPrintNum10], a
and a
ret
Function104d38: ; 104d38 (41:4d38)
call Function104d96
call Function104e46
ld a, [hPrintNum10]
cp $6c
ret
Function104d43: ; 104d43 (41:4d43)
call Function104d96
call Function104dfe
ld a, [hPrintNum10]
cp $6c
ret
Function104d4e: ; 104d4e (41:4d4e)
call Function104e93
ld a, [hPrintNum10]
cp $6c
ret
Function104d56: ; 104d56 (41:4d56)
call Function104f57
ld a, [hPrintNum10]
cp $6c
ret
Function104d5e: ; 104d5e (41:4d5e)
call Function104d74
ld a, $4
ld [rIE], a
xor a
ld [rIF], a
call Function104d96
xor a
ld b, a
.asm_104d6d
inc a
jr nz, .asm_104d6d
inc b
jr nz, .asm_104d6d
ret
Function104d74: ; 104d74 (41:4d74)
xor a
ld [rTAC], a
ld a, $fe
ld [rTMA], a
ld [rTIMA], a
ld a, $2
ld [rTAC], a
or $4
ld [rTAC], a
ret
Function104d86: ; 104d86 (41:4d86)
xor a
ld [rTAC], a
ld [rTMA], a
ld [rTIMA], a
ld a, $2
ld [rTAC], a
or $4
ld [rTAC], a
ret
Function104d96: ; 104d96 (41:4d96)
ld a, $c0
call Function104e8c
ld a, $1
ld [hPrintNum9], a
ret
Function104da0: ; 104da0 (41:4da0)
xor a
call Function104e8c
ld a, $2
ld [rTAC], a
ret
Function104da9: ; 104da9 (41:4da9)
inc d
ret z
xor a
ld [rIF], a
halt
ld a, [$ff00+c]
bit 1, a
jr z, Function104da9
or a
ret
Function104db7: ; 104db7 (41:4db7)
inc d
ret z
xor a
ld [rIF], a
halt
ld a, [$ff00+c]
bit 1, a
jr nz, Function104db7
or a
ret
Function104dc5: ; 104dc5 (41:4dc5)
ld a, $c1
ld [$ff00+c], a
.asm_104dc8
dec d
ret z
xor a
ld [rIF], a
halt
jr .asm_104dc8
Function104dd1: ; 104dd1 (41:4dd1)
ld a, $c0
ld [$ff00+c], a
.asm_104dd4
dec d
ret z
xor a
ld [rIF], a
halt
jr .asm_104dd4
Function104ddd: ; 104ddd (41:4ddd)
ld d, $0
ld e, d
ld a, $1
ld [hPrintNum9], a
2015-12-06 19:36:09 -08:00
.loop
2015-11-22 21:21:21 -08:00
call Function105038
ld b, $2
ld c, rRP % $100
ld a, [hMoneyTemp + 1]
bit 1, a
2015-12-06 19:36:09 -08:00
jr z, .next
2015-11-22 21:21:21 -08:00
ld a, $10
ld [hPrintNum10], a
ret
2015-12-06 19:36:09 -08:00
.next
2015-11-22 21:21:21 -08:00
bit 0, a
jr nz, asm_104e3a
ld a, [$ff00+c]
and b
2015-12-06 19:36:09 -08:00
jr nz, .loop
2015-11-22 21:21:21 -08:00
Function104dfe: ; 104dfe (41:4dfe)
ld c, rRP % $100
ld d, $0
ld e, d
call Function104db7
jp z, Function104f42
ld d, e
call Function104da9
jp z, Function104f42
call Function104db7
jp z, Function104f42
call Function104da9
jp z, Function104f42
ld a, $6c
ld [hPrintNum10], a
ld d, $3d
call Function104dd1
ld d, $5
call Function104dc5
ld d, $15
call Function104dd1
ld d, $5
call Function104dc5
ld d, $5
call Function104dd1
ret
asm_104e3a: ; 104e3a (41:4e3a)
call Random
ld e, a
and $f
ld d, a
.asm_104e41
dec de
ld a, d
or e
jr nz, .asm_104e41
Function104e46: ; 104e46 (41:4e46)
ld a, $2
ld [hPrintNum9], a
ld c, $56
ld d, $0
ld e, d
ld d, $3d
call Function104dd1
ld d, $5
call Function104dc5
ld d, $15
call Function104dd1
ld d, $5
call Function104dc5
ld d, $5
call Function104dd1
ld d, e
call Function104db7
jp z, Function104f42
ld d, e
call Function104da9
jp z, Function104f42
call Function104db7
jp z, Function104f42
call Function104da9
jp z, Function104f42
ld d, $3d
call Function104dd1
ld a, $6c
ld [hPrintNum10], a
ret
Function104e8c: ; 104e8c (41:4e8c)
ld [rRP], a
ld a, $ff
ld [hPrintNum10], a
ret
Function104e93: ; 104e93 (41:4e93)
xor a
ld [hDivisor], a
ld [hMathBuffer], a
push hl
push bc
ld c, $56
ld d, $3d
call Function104dd1
ld hl, hQuotient ; $ffb4 (aliases: hMultiplicand)
ld a, $5a
ld [hli], a
ld [hl], b
dec hl
ld b, $2
call Function104ed6
pop bc
pop hl
call Function104ed6
ld a, [hDivisor]
ld [hQuotient], a
ld a, [hMathBuffer]
ld [$ffb5], a
push hl
ld hl, hQuotient ; $ffb4 (aliases: hMultiplicand)
ld b, $2
call Function104ed6
ld hl, hPrintNum10
ld b, $1
call Function104faf
ld a, [hQuotient]
ld [hDivisor], a
ld a, [$ffb5]
ld [hMathBuffer], a
pop hl
ret
Function104ed6: ; 104ed6 (41:4ed6)
ld c, $56
ld d, $5
call Function104dd1
ld d, $5
call Function104dc5
ld d, $15
call Function104dd1
ld a, b
cpl
ld b, a
ld a, $f4
ld [rTMA], a
.asm_104eee
inc b
jr z, .asm_104f2e
ld a, $8
ld [$ffb6], a
ld a, [hli]
ld e, a
ld a, [hDivisor]
add e
ld [hDivisor], a
ld a, [hMathBuffer]
adc $0
ld [hMathBuffer], a
.asm_104f02
xor a
ld [rIF], a
halt
ld a, $c1
ld [rRP], a
ld d, $1
ld a, e
rlca
ld e, a
jr nc, .asm_104f13
inc d
.asm_104f13
ld a, [rTIMA]
cp $f8
jr c, .asm_104f13
ld a, $c0
ld [rRP], a
dec d
jr z, .asm_104f25
xor a
ld [rIF], a
halt
.asm_104f25
ld a, [$ffb6]
dec a
jr z, .asm_104eee
ld [$ffb6], a
jr .asm_104f02
.asm_104f2e
ld a, $fe
ld [rTMA], a
xor a
ld [rIF], a
halt
ld d, $5
call Function104dc5
ld d, $11
call Function104dd1
ret
Function104f42: ; 104f42 (41:4f42)
ld a, [hPrintNum10]
or $2
ld [hPrintNum10], a
ret
Function104f49: ; 104f49 (41:4f49)
ld a, [hPrintNum10]
or $1
ld [hPrintNum10], a
ret
Function104f50: ; 104f50 (41:4f50)
ld a, [hPrintNum10]
or $80
ld [hPrintNum10], a
ret
Function104f57: ; 104f57 (41:4f57)
xor a
ld [hDivisor], a
ld [hMathBuffer], a
push bc
push hl
ld hl, hQuotient ; $ffb4 (aliases: hMultiplicand)
ld b, $2
call Function104faf
ld a, [$ffb5]
ld [$ffba], a
ld b, a
pop hl
pop af
cp b
jp c, Function104f50
ld a, [hQuotient]
cp $5a
jp nz, Function104f50
call Function104faf
ld a, [hDivisor]
ld d, a
ld a, [hMathBuffer]
ld e, a
push hl
push de
ld hl, hQuotient ; $ffb4 (aliases: hMultiplicand)
ld b, $2
call Function104faf
pop de
ld hl, hQuotient ; $ffb4 (aliases: hMultiplicand)
ld a, [hli]
xor d
ld b, a
ld a, [hl]
xor e
or b
call nz, Function104f49
push de
ld d, $3d
call Function104dd1
ld hl, hPrintNum10
ld b, $1
call Function104ed6
pop de
pop hl
ld a, d
ld [hDivisor], a
ld a, e
ld [hMathBuffer], a
ret
Function104faf: ; 104faf (41:4faf)
ld c, rRP % $100
ld d, $0
call Function104db7
jp z, Function104f42
ld d, $0
call Function104da9
jp z, Function104f42
ld d, $0
call Function104db7
jp z, Function104f42
ld a, b
cpl
ld b, a
xor a
ld [hMoneyTemp + 2], a
call Function104d86
.asm_104fd2
inc b
jr z, .asm_10501a
ld a, $8
ld [$ffb6], a
.asm_104fd9
ld d, $0
.asm_104fdb
inc d
jr z, .asm_104fe5
ld a, [$ff00+c]
bit 1, a
jr z, .asm_104fdb
ld d, $0
.asm_104fe5
inc d
jr z, .asm_104fed
ld a, [$ff00+c]
bit 1, a
jr nz, .asm_104fe5
.asm_104fed
ld a, [hMoneyTemp + 2]
ld d, a
ld a, [rTIMA]
ld [hMoneyTemp + 2], a
sub d
cp $12
jr c, .asm_104ffd
set 0, e
jr .asm_104fff
.asm_104ffd
res 0, e
.asm_104fff
ld a, [$ffb6]
dec a
ld [$ffb6], a
jr z, .asm_10500b
ld a, e
rlca
ld e, a
jr .asm_104fd9
.asm_10500b
ld a, e
ld [hli], a
ld a, [hDivisor]
add e
ld [hDivisor], a
ld a, [hMathBuffer]
adc $0
ld [hMathBuffer], a
jr .asm_104fd2
.asm_10501a
call Function104d74
xor a
ld [rIF], a
ld d, $0
call Function104da9
jp z, Function104f42
ld d, $10
call Function104dd1
ret
Function10502e: ; 10502e (41:502e)
ld b, $0
jp Function104e93
Function105033: ; 105033 (41:5033)
ld b, $0
jp Function104f57
Function105038: ; 105038 (41:5038)
ld a, $20
ld [rJOYP], a
rept 2
ld a, [rJOYP]
endr
cpl
and $f
swap a
ld b, a
ld a, $10
ld [rJOYP], a
rept 6
ld a, [rJOYP]
endr
cpl
and $f
or b
ld c, a
ld a, [hMoneyTemp]
xor c
and c
ld [hMoneyTemp + 1], a
ld a, c
ld [hMoneyTemp], a
ld a, $30
ld [rJOYP], a
ret
Function105069: ; 105069 (41:5069)
call GetMysteryGiftBank
ld d, $0
ld b, CHECK_FLAG
ld hl, sMysteryGiftDecorationsReceived
predef_id FlagPredef
push hl
push bc
call Predef
call CloseSRAM
ld a, c
and a
pop bc
pop hl
ret nz
call GetMysteryGiftBank
ld b, SET_FLAG
predef FlagPredef
call CloseSRAM
xor a
ret
Function105091: ; 105091 (41:5091)
call GetMysteryGiftBank
ld c, $0
.loop
push bc
ld d, $0
ld b, CHECK_FLAG
ld hl, sMysteryGiftDecorationsReceived
predef FlagPredef
ld a, c
and a
pop bc
jr z, .skip
push bc
callab SetSpecificDecorationFlag
pop bc
.skip
inc c
ld a, c
cp Trophys - DecorationIDs
jr c, .loop
jp CloseSRAM
Special_UnlockMysteryGift: ; 1050b9
call GetMysteryGiftBank
ld hl, sMysteryGiftUnlocked
ld a, [hl]
inc a
jr nz, .ok
ld [hld], a
ld [hl], a
.ok
jp CloseSRAM
; 1050c8
Function1050c8: ; 1050c8
call GetMysteryGiftBank
ld a, [sNumDailyMysteryGiftPartnerIDs]
cp $ff
jr z, .okay
xor a
ld [sNumDailyMysteryGiftPartnerIDs], a
.okay
jp CloseSRAM
; 1050d9
BackupMysteryGift: ; 1050d9
call GetMysteryGiftBank
ld hl, sMysteryGiftItem
ld de, sBackupMysteryGiftItem
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp CloseSRAM
; 1050ea
RestoreMysteryGift: ; 1050ea (41:50ea)
call GetMysteryGiftBank
ld hl, sBackupMysteryGiftItem
ld de, sMysteryGiftItem
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp CloseSRAM
Function1050fb: ; 1050fb (41:50fb)
ld hl, wMysteryGiftTrainerData
xor a
2015-12-06 19:36:09 -08:00
ld b, wMysteryGiftTrainerDataEnd - wMysteryGiftTrainerData
.loop
2015-11-22 21:21:21 -08:00
ld [hli], a
dec b
2015-12-06 19:36:09 -08:00
jr nz, .loop
2015-11-22 21:21:21 -08:00
ret
GetMysteryGiftBank: ; 105106
ld a, BANK(sBackupMysteryGiftItem)
jp GetSRAMBank
; 10510b
2015-12-14 17:06:41 -08:00
StagePartyDataForMysteryGift: ; 10510b (41:510b)
; You will be sending this data to your mystery gift partner.
; Structure is the same as a trainer with species and moves
; defined.
2015-11-22 21:21:21 -08:00
ld a, BANK(sPokemonData)
call GetSRAMBank
2015-12-14 17:06:41 -08:00
ld de, wMysteryGiftStaging
2015-11-22 21:21:21 -08:00
ld bc, sPokemonData + PartyMons - wPokemonData
ld hl, sPokemonData + PartySpecies - wPokemonData
2015-12-14 17:06:41 -08:00
.loop
2015-11-22 21:21:21 -08:00
ld a, [hli]
2015-12-14 17:06:41 -08:00
cp -1
jr z, .party_end
2015-11-22 21:21:21 -08:00
cp EGG
2015-12-14 17:06:41 -08:00
jr z, .next
2015-11-22 21:21:21 -08:00
push hl
2015-12-14 17:06:41 -08:00
; copy level
2015-11-22 21:21:21 -08:00
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
ld [de], a
inc de
2015-12-14 17:06:41 -08:00
; copy species
2015-11-22 21:21:21 -08:00
ld hl, MON_SPECIES
add hl, bc
ld a, [hl]
ld [de], a
inc de
2015-12-14 17:06:41 -08:00
; copy moves
2015-11-22 21:21:21 -08:00
ld hl, MON_MOVES
add hl, bc
push bc
ld bc, NUM_MOVES
call CopyBytes
pop bc
pop hl
2015-12-14 17:06:41 -08:00
.next
2015-11-22 21:21:21 -08:00
push hl
ld hl, PARTYMON_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
pop hl
2015-12-14 17:06:41 -08:00
jr .loop
.party_end
ld a, -1
2015-11-22 21:21:21 -08:00
ld [de], a
ld a, $26
ld [wca00], a
jp CloseSRAM
Function105153: ; 105153 (41:5153)
call ClearBGPalettes
call DisableLCD
ld hl, MysteryGiftGFX
ld de, VTiles2 tile $00
ld a, BANK(MysteryGiftGFX)
2015-12-14 17:06:41 -08:00
ld bc, MysteryGiftGFXEnd - MysteryGiftGFX
2015-11-22 21:21:21 -08:00
call FarCopyBytes
hlcoord 0, 0
ld a, $42
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
call ByteFill
hlcoord 3, 7
lb bc, 9, 15
call ClearBox
hlcoord 0, 0
ld a, $0
ld [hli], a
inc a
ld [hl], a
hlcoord 0, 1
inc a
ld [hli], a
inc a
ld [hl], a
hlcoord 7, 1
ld a, $12
2015-12-14 17:06:41 -08:00
call .Load5GFX
2015-11-22 21:21:21 -08:00
hlcoord 2, 2
ld a, $17
2015-12-14 17:06:41 -08:00
call .Load16GFX
2015-11-22 21:21:21 -08:00
hlcoord 2, 3
ld a, $27
2015-12-14 17:06:41 -08:00
call .Load16GFX
2015-11-22 21:21:21 -08:00
hlcoord 9, 4
ld a, $37
ld [hli], a
inc a
ld [hl], a
hlcoord 1, 2
ld [hl], $4
hlcoord 1, 3
ld a, $5
2015-12-14 17:06:41 -08:00
call .Load14Column
2015-11-22 21:21:21 -08:00
ld a, $9
hlcoord 18, 5
2015-12-14 17:06:41 -08:00
call .Load11Column
2015-11-22 21:21:21 -08:00
hlcoord 2, 5
ld a, $b
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 16
ld a, $7
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 5
ld a, $d
2015-12-14 17:06:41 -08:00
call .Load5GFX
2015-11-22 21:21:21 -08:00
hlcoord 7, 5
ld [hl], $c
hlcoord 18, 5
ld [hl], $a
hlcoord 18, 16
ld [hl], $8
hlcoord 1, 16
ld [hl], $6
hlcoord 2, 6
ld a, $3a
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 15
ld a, $40
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 6
ld a, $3c
2015-12-14 17:06:41 -08:00
call .Load9Column
2015-11-22 21:21:21 -08:00
hlcoord 17, 6
ld a, $3e
2015-12-14 17:06:41 -08:00
call .Load9Column
2015-11-22 21:21:21 -08:00
hlcoord 2, 6
ld [hl], $39
hlcoord 17, 6
ld [hl], $3b
hlcoord 2, 15
ld [hl], $3f
hlcoord 17, 15
ld [hl], $41
call EnableLCD
call WaitBGMap
ld b, SCGB_1D
call GetSGBLayout
call SetPalettes
ret
2015-12-14 17:06:41 -08:00
.Load5GFX: ; 10522e (41:522e)
ld b, 5
jr .gfx_loop
2015-11-22 21:21:21 -08:00
; 105232 (41:5232)
2015-12-14 17:06:41 -08:00
.Load6GFX: ; unreferenced
ld b, 6
jr .gfx_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load16GFX: ; 105236 (41:5236)
ld b, 16
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.gfx_loop: ; 105238 (41:5238)
2015-11-22 21:21:21 -08:00
ld [hli], a
inc a
dec b
2015-12-14 17:06:41 -08:00
jr nz, .gfx_loop
2015-11-22 21:21:21 -08:00
ret
2015-12-14 17:06:41 -08:00
.Load9Column: ; 10523e (41:523e)
ld b, 9
jr .col_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load11Column: ; 105242 (41:5242)
ld b, 11
jr .col_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load14Column: ; 105246 (41:5246)
ld b, 14
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.col_loop: ; 105248 (41:5248)
2015-11-22 21:21:21 -08:00
ld [hl], a
2015-12-14 17:06:41 -08:00
ld de, SCREEN_WIDTH
2015-11-22 21:21:21 -08:00
add hl, de
dec b
2015-12-14 17:06:41 -08:00
jr nz, .col_loop
2015-11-22 21:21:21 -08:00
ret
2015-12-14 17:06:41 -08:00
.Load16Row: ; 105251 (41:5251)
ld b, 16
.row_loop
2015-11-22 21:21:21 -08:00
ld [hli], a
dec b
2015-12-14 17:06:41 -08:00
jr nz, .row_loop
2015-11-22 21:21:21 -08:00
ret
MysteryGiftGFX: ; 105258
INCBIN "gfx/misc/mystery_gift.2bpp"
2015-12-14 17:06:41 -08:00
MysteryGiftGFXEnd:
2015-11-22 21:21:21 -08:00
Function105688: ; 105688 (41:5688)
call ClearTileMap
call ClearSprites
call WaitBGMap
call Function1057d7
hlcoord 3, 8
ld de, String_10572e
call PlaceString
call WaitBGMap
call Function10578c
call Function1050fb
ld a, $24
ld [wca02], a
ld a, [rIE]
push af
call Function104c2d
ld d, a
xor a
ld [rIF], a
pop af
ld [rIE], a
ld a, d
cp $10
jp z, Function105712
cp $6c
jp nz, Function10571a
call Function1056eb
ld c, 60
call DelayFrames
call Function105777
2015-12-14 17:06:41 -08:00
ld hl, Text_ReceivedCard
2015-11-22 21:21:21 -08:00
call PrintText
ld de, wMysteryGiftTrainerData
callba Function8ac70
ld a, c
ld [wd265], a
2015-12-14 17:06:41 -08:00
ld hl, Text_CardNotRegistered
2015-11-22 21:21:21 -08:00
jr c, asm_105726
2015-12-14 17:06:41 -08:00
ld hl, Text_ListedCardAsNumber
2015-11-22 21:21:21 -08:00
jr asm_105726
Function1056eb: ; 1056eb (41:56eb)
ld c, $10
.asm_1056ed
ld hl, Sprites
ld b, $8
.asm_1056f2
dec [hl]
rept 4
inc hl
endr
dec b
jr nz, .asm_1056f2
ld hl, Sprites + $20
ld b, $8
.asm_1056ff
inc [hl]
rept 4
inc hl
endr
dec b
jr nz, .asm_1056ff
dec c
ret z
push bc
ld c, 4
call DelayFrames
pop bc
jr .asm_1056ed
Function105712: ; 105712 (41:5712)
call Function105777
2015-12-14 17:06:41 -08:00
ld hl, Text_MGLinkCanceled
2015-11-22 21:21:21 -08:00
jr asm_105726
Function10571a: ; 10571a (41:571a)
call Function105777
2015-12-14 17:06:41 -08:00
ld hl, Text_MGCommError
2015-11-22 21:21:21 -08:00
call PrintText
jp Function105688
asm_105726: ; 105726 (41:5726)
call PrintText
ld a, $e3
ld [rLCDC], a
ret
; 10572e (41:572e)
String_10572e: ; 10572e
db "エーボタン¯おすと"
2015-12-14 17:06:41 -08:00
next "つうしん<PKMN>おこなわれるよ!"
2015-11-22 21:21:21 -08:00
next "ビーボタン¯おすと"
next "つうしん¯ちゅうし します"
db "@"
; 10575e
2015-12-14 17:06:41 -08:00
Text_ReceivedCard: ; 10575e
2015-11-22 21:21:21 -08:00
text_jump UnknownText_0x1c051a
db "@"
2015-12-14 17:06:41 -08:00
Text_ListedCardAsNumber: ; 105763
2015-11-22 21:21:21 -08:00
text_jump UnknownText_0x1c0531
db "@"
2015-12-14 17:06:41 -08:00
Text_CardNotRegistered: ; 105768
2015-11-22 21:21:21 -08:00
text_jump UnknownText_0x1c0555
db "@"
2015-12-14 17:06:41 -08:00
Text_MGLinkCanceled: ; 10576d
2015-11-22 21:21:21 -08:00
text_jump UnknownText_0x1c0573
db "@"
2015-12-14 17:06:41 -08:00
Text_MGCommError: ; 105772
2015-11-22 21:21:21 -08:00
text_jump UnknownText_0x1c0591
db "@"
; 105777
Function105777: ; 105777 (41:5777)
call ClearSprites
call ClearTileMap
call EnableLCD
call WaitBGMap
ld b, SCGB_08
call GetSGBLayout
call SetPalettes
ret
Function10578c: ; 10578c (41:578c)
ld de, OverworldMap
ld a, BANK(sPlayerData)
call GetSRAMBank
ld hl, sPlayerData + PlayerName - wPlayerData
ld bc, NAME_LENGTH
call CopyBytes
ld hl, sPlayerData + PlayerID - wPlayerData
ld bc, 2
call CopyBytes
ld hl, sPlayerData + wSecretID - wPlayerData
ld bc, 2
call CopyBytes
call CloseSRAM
ld a, BANK(sCrystalData)
call GetSRAMBank
ld a, [sCrystalData + 0]
ld [de], a
inc de
ld a, $4
call GetSRAMBank
ld hl, $a603
ld bc, $8
call CopyBytes
ld hl, $a007
ld bc, $c
call CopyBytes
call CloseSRAM
ret
Function1057d7: ; 1057d7 (41:57d7)
call ClearBGPalettes
call DisableLCD
ld hl, MysteryGiftJP_GFX
ld de, VTiles2 tile $00
ld a, BANK(MysteryGiftJP_GFX)
lb bc, 4, 0
call FarCopyBytes
ld hl, MysteryGiftJP_GFX + $400
ld de, VTiles0 tile $00
ld a, BANK(MysteryGiftJP_GFX)
ld bc, $80
call FarCopyBytes
hlcoord 0, 0
ld a, $3f
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
call ByteFill
hlcoord 3, 7
lb bc, 9, 15
call ClearBox
hlcoord 0, 0
ld a, $0
ld [hli], a
inc a
ld [hl], a
hlcoord 0, 1
inc a
ld [hli], a
inc a
ld [hl], a
hlcoord 4, 2
ld a, $13
2015-12-14 17:06:41 -08:00
call .Load11Row
2015-11-22 21:21:21 -08:00
hlcoord 4, 3
ld a, $1e
2015-12-14 17:06:41 -08:00
call .Load12Row
2015-11-22 21:21:21 -08:00
hlcoord 4, 4
ld a, $2a
2015-12-14 17:06:41 -08:00
call .Load12Row
2015-11-22 21:21:21 -08:00
hlcoord 1, 2
ld [hl], $4
hlcoord 1, 3
ld a, $5
2015-12-14 17:06:41 -08:00
call .Load14Column
2015-11-22 21:21:21 -08:00
ld a, $9
hlcoord 18, 5
2015-12-14 17:06:41 -08:00
call .Load11Column
2015-11-22 21:21:21 -08:00
hlcoord 2, 5
ld a, $b
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 16
ld a, $7
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 5
ld a, $d
2015-12-14 17:06:41 -08:00
call .Load6Row
2015-11-22 21:21:21 -08:00
hlcoord 8, 5
ld [hl], $c
hlcoord 18, 5
ld [hl], $a
hlcoord 18, 16
ld [hl], $8
hlcoord 1, 16
ld [hl], $6
hlcoord 2, 6
ld a, $37
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 15
ld a, $3d
2015-12-14 17:06:41 -08:00
call .Load16Row
2015-11-22 21:21:21 -08:00
hlcoord 2, 6
ld a, $39
2015-12-14 17:06:41 -08:00
call .Load9Column
2015-11-22 21:21:21 -08:00
hlcoord 17, 6
ld a, $3b
2015-12-14 17:06:41 -08:00
call .Load9Column
2015-11-22 21:21:21 -08:00
hlcoord 2, 6
ld [hl], $36
hlcoord 17, 6
ld [hl], $38
hlcoord 2, 15
ld [hl], $3c
hlcoord 17, 15
ld [hl], $3e
ld de, Sprites
2015-12-14 17:06:41 -08:00
ld hl, .OAM_data
2015-11-22 21:21:21 -08:00
ld bc, $40
call CopyBytes
call EnableLCD
call WaitBGMap
ld b, $2
2015-12-16 18:57:42 -08:00
callba GetMysteryGift_MobileAdapterLayout
2015-11-22 21:21:21 -08:00
jp SetPalettes
2015-12-14 17:06:41 -08:00
.Load6Row: ; 1058c6 (41:58c6)
ld b, 6
jr .row_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load11Row: ; 1058ca (41:58ca)
ld b, 11
jr .row_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load12Row: ; 1058ce (41:58ce)
ld b, 12
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.row_loop: ; 1058d0 (41:58d0)
2015-11-22 21:21:21 -08:00
ld [hli], a
inc a
dec b
2015-12-14 17:06:41 -08:00
jr nz, .row_loop
2015-11-22 21:21:21 -08:00
ret
2015-12-14 17:06:41 -08:00
.Load9Column: ; 1058d6 (41:58d6)
ld b, 9
jr .column_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load11Column: ; 1058da (41:58da)
ld b, 11
jr .column_loop
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.Load14Column: ; 1058de (41:58de)
ld b, 14
2015-11-22 21:21:21 -08:00
2015-12-14 17:06:41 -08:00
.column_loop: ; 1058e0 (41:58e0)
2015-11-22 21:21:21 -08:00
ld [hl], a
ld de, SCREEN_WIDTH
add hl, de
dec b
2015-12-14 17:06:41 -08:00
jr nz, .column_loop
2015-11-22 21:21:21 -08:00
ret
2015-12-14 17:06:41 -08:00
.Load16Row: ; 1058e9 (41:58e9)
ld b, 16
.row_loop_no_inc
2015-11-22 21:21:21 -08:00
ld [hli], a
dec b
2015-12-14 17:06:41 -08:00
jr nz, .row_loop_no_inc
2015-11-22 21:21:21 -08:00
ret
; 1058f0 (41:58f0)
2015-12-14 17:06:41 -08:00
.OAM_data: ; 1058f0
dsprite 2, 1, 6, 4, $00, $00
dsprite 2, 1, 7, 4, $01, $00
dsprite 2, 1, 8, 4, $02, $00
dsprite 2, 1, 9, 4, $03, $00
dsprite 3, 1, 6, 4, $04, $00
dsprite 3, 1, 7, 4, $05, $00
dsprite 3, 1, 8, 4, $06, $00
dsprite 3, 1, 9, 4, $07, $00
dsprite 0, 1, 11, 4, $00, $00
dsprite 0, 1, 12, 4, $01, $00
dsprite 0, 1, 13, 4, $02, $00
dsprite 0, 1, 14, 4, $03, $00
dsprite 1, 1, 11, 4, $04, $00
dsprite 1, 1, 12, 4, $05, $00
dsprite 1, 1, 13, 4, $06, $00
dsprite 1, 1, 14, 4, $07, $00
2015-11-22 21:21:21 -08:00
; japanese mystery gift gfx
MysteryGiftJP_GFX: ; 105930
INCBIN "gfx/misc/mystery_gift_jp.2bpp"