pokecrystal/engine/link/mystery_gift.asm

1712 lines
26 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
DoMysteryGift:
2015-11-23 05:21:21 +00:00
call ClearTileMap
call ClearSprites
call WaitBGMap
2016-06-07 12:08:51 +00:00
call InitMysteryGiftLayout
2015-11-23 05:21:21 +00:00
hlcoord 3, 8
ld de, .String_PressAToLink_BToCancel
call PlaceString
call WaitBGMap
2017-12-24 17:47:30 +00:00
farcall PrepMysteryGiftDataToSend
2016-06-07 12:08:51 +00:00
call MysteryGift_ClearTrainerData
2015-11-23 05:21:21 +00:00
ld a, $2
ld [wca01], a
ld a, $14
ld [wca02], a
ldh a, [rIE]
2015-11-23 05:21:21 +00:00
push af
2015-12-15 01:06:41 +00:00
2015-11-23 05:21:21 +00:00
call Function104a95
2015-12-15 01:06:41 +00:00
2015-11-23 05:21:21 +00:00
ld d, a
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
pop af
ldh [rIE], a
2015-11-23 05:21:21 +00:00
push de
call ClearTileMap
call EnableLCD
call WaitBGMap
2016-06-06 22:23:00 +00:00
ld b, SCGB_DIPLOMA
2015-11-23 05:21:21 +00:00
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-15 01:06:41 +00:00
cp 3
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
ld a, [wMysteryGiftPlayerBackupItem]
2015-11-23 05:21:21 +00:00
and a
jp nz, .GiftWaiting
ld a, [wMysteryGiftPartnerBackupItem]
2015-11-23 05:21:21 +00:00
and a
jp nz, .FriendNotReady
ld a, [wc900]
2015-12-15 01:06:41 +00:00
cp 3
2015-11-23 05:21:21 +00:00
jr z, .skip_append_save
call .AddMysteryGiftPartnerID
ld a, [wc900]
2015-12-15 01:06:41 +00:00
cp 4
2015-11-23 05:21:21 +00:00
jr z, .skip_append_save
call .SaveMysteryGiftTrainerName
2017-12-24 17:47:30 +00:00
farcall RestoreMobileEventIndex
farcall StubbedTrainerRankings_MysteryGift
2017-12-24 17:47:30 +00:00
farcall BackupMobileEventIndex
2015-11-23 05:21:21 +00:00
.skip_append_save
2015-12-15 01:06:41 +00:00
ld a, [wMysteryGiftPartnerSentDeco]
2015-11-23 05:21:21 +00:00
and a
jr z, .item
2015-12-15 01:06:41 +00:00
ld a, [wMysteryGiftPartnerWhichDeco]
2015-11-23 05:21:21 +00:00
ld c, a
2017-12-24 17:47:30 +00:00
farcall MysteryGiftGetDecoration
2015-11-23 05:21:21 +00:00
push bc
call MysteryGift_CheckAndSetDecorationAlreadyReceived
2015-11-23 05:21:21 +00:00
pop bc
jr nz, .item
2017-12-24 17:47:30 +00:00
callfar GetDecorationName_c
2015-11-23 05:21:21 +00:00
ld h, d
ld l, e
2018-01-23 22:39:09 +00:00
ld de, wStringBuffer1
2015-11-23 05:21:21 +00:00
ld bc, ITEM_NAME_LENGTH
call CopyBytes
ld hl, .Text_SentToHome ; sent decoration to home
jr .PrintTextAndExit
.item
call GetMysteryGiftBank
2015-12-15 01:06:41 +00:00
ld a, [wMysteryGiftPartnerWhichItem]
2015-11-23 05:21:21 +00:00
ld c, a
2017-12-24 17:47:30 +00:00
farcall MysteryGiftGetItemHeldEffect
2015-11-23 05:21:21 +00:00
ld a, c
ld [sBackupMysteryGiftItem], a
ld [wNamedObjectIndexBuffer], a
call CloseSRAM
call GetItemName
ld hl, .Text_Sent ; sent item
jr .PrintTextAndExit
2018-06-24 14:09:41 +00:00
.LinkCanceled:
2015-11-23 05:21:21 +00:00
ld hl, .Text_LinkCanceled ; Link has been canceled
jr .PrintTextAndExit
2018-06-24 14:09:41 +00:00
.CommunicationError:
2015-11-23 05:21:21 +00:00
ld hl, .Text_CommunicationError ; Communication error
call PrintText
jp DoMysteryGift
2018-06-24 14:09:41 +00:00
.GiftWaiting:
2015-11-23 05:21:21 +00:00
ld hl, .Text_ReceiveGiftAtCounter ; receive gift at counter
jr .PrintTextAndExit
2018-06-24 14:09:41 +00:00
.FriendNotReady:
2015-11-23 05:21:21 +00:00
ld hl, .Text_FriendNotReady ; friend not ready
2018-06-24 14:09:41 +00:00
.PrintTextAndExit:
2015-11-23 05:21:21 +00:00
call PrintText
2017-12-29 18:22:33 +00:00
ld a, LCDC_DEFAULT
ldh [rLCDC], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.String_PressAToLink_BToCancel:
2015-11-23 05:21:21 +00:00
db "Press A to"
next "link IR-Device"
next "Press B to"
next "cancel it."
db "@"
2018-06-24 14:09:41 +00:00
.Text_LinkCanceled:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0436
db "@"
2018-06-24 14:09:41 +00:00
.Text_CommunicationError:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0454
db "@"
2018-06-24 14:09:41 +00:00
.Text_ReceiveGiftAtCounter:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c046a
db "@"
2018-06-24 14:09:41 +00:00
.Text_FriendNotReady:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c048e
db "@"
2018-06-24 14:09:41 +00:00
.Text_MaxFiveGifts:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c04a7
db "@"
2018-06-24 14:09:41 +00:00
.Text_MaxOneGiftPerPerson:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c04c6
db "@"
2018-06-24 14:09:41 +00:00
.Text_Sent:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c04e9
db "@"
2018-06-24 14:09:41 +00:00
.Text_SentToHome:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c04fa
db "@"
2018-06-24 14:09:41 +00:00
.CheckAlreadyGotFiveGiftsToday:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld a, [sNumDailyMysteryGiftPartnerIDs]
cp $5
jp CloseSRAM
2018-06-24 14:09:41 +00:00
.CheckAlreadyGotAGiftFromThatPerson:
2015-11-23 05:21:21 +00:00
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:
2015-11-23 05:21:21 +00:00
scf
.No:
2015-11-23 05:21:21 +00:00
jp CloseSRAM
2018-06-24 14:09:41 +00:00
.AddMysteryGiftPartnerID:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld hl, sNumDailyMysteryGiftPartnerIDs
ld a, [hl]
inc [hl]
ld hl, sDailyMysteryGiftPartnerIDs ; inc hl
ld e, a
ld d, $0
add hl, de
2015-12-27 02:59:03 +00:00
add hl, de
2015-11-23 05:21:21 +00:00
ld a, [wMysteryGiftPartnerID]
ld [hli], a
ld a, [wMysteryGiftPartnerID + 1]
ld [hl], a
jp CloseSRAM
2018-06-24 14:09:41 +00:00
.SaveMysteryGiftTrainerName:
2015-11-23 05:21:21 +00:00
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
2018-06-24 14:09:41 +00:00
Function104a95:
2015-11-23 05:21:21 +00:00
di
2017-12-24 17:47:30 +00:00
farcall ClearChannels
2015-11-23 05:21:21 +00:00
call Function104d5e
2016-06-07 12:08:51 +00:00
2015-11-23 05:21:21 +00:00
.loop2
call Function104d96
call Function104ddd
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $10
jp z, Function104bd0
cp $6c
jr nz, .loop2
2016-06-07 12:08:51 +00:00
ldh a, [hPrintNum9]
2015-11-23 05:21:21 +00:00
cp $2
jr z, Function104b22
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d56
jr nz, .ly_loop
call Function104b49
jp nz, Function104bd0
2016-06-07 12:08:51 +00:00
jr Function104b0a
; Delay frame
2015-11-23 05:21:21 +00:00
.ly_loop
ldh a, [rLY]
2017-12-29 17:53:21 +00:00
cp LY_VBLANK
2015-11-23 05:21:21 +00:00
jr c, .ly_loop
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
ld a, $c0
ld [$ff00+c], a
2016-06-07 12:08:51 +00:00
ld b, 240 ; This might have been intended as a 4-second timeout buffer.
; However, it is reset with each frame.
2015-11-23 05:21:21 +00:00
.loop3
push bc
2016-06-07 12:08:51 +00:00
call MysteryGift_ReadJoypad
2015-11-23 05:21:21 +00:00
ld b, $2
ld c, LOW(rRP)
2016-06-07 12:08:51 +00:00
; Delay frame
2015-11-23 05:21:21 +00:00
.ly_loop2
ld a, [$ff00+c]
and b
ld b, a
ldh a, [rLY]
2017-12-29 17:53:21 +00:00
cp LY_VBLANK
2015-11-23 05:21:21 +00:00
jr nc, .ly_loop2
.ly_loop3
ld a, [$ff00+c]
and b
ld b, a
ldh a, [rLY]
2017-12-29 17:53:21 +00:00
cp LY_VBLANK
2015-11-23 05:21:21 +00:00
jr c, .ly_loop3
2016-06-07 12:08:51 +00:00
2015-11-23 05:21:21 +00:00
ld a, b
pop bc
dec b
2016-06-07 12:08:51 +00:00
jr z, .loop2 ; we never jump here
2015-11-23 05:21:21 +00:00
or a
jr nz, .loop2
2016-06-07 12:08:51 +00:00
; Check if we've pressed the B button
ldh a, [hMGJoypadReleased]
2016-06-07 12:08:51 +00:00
bit B_BUTTON_F, a
2015-11-23 05:21:21 +00:00
jr z, .loop3
ld a, $10
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
jp Function104bd0
2018-06-24 14:09:41 +00:00
Function104b04:
2015-11-23 05:21:21 +00:00
call Function104b40
jp nz, Function104bd0
2018-06-24 14:09:41 +00:00
Function104b0a:
2015-11-23 05:21:21 +00:00
call Function104d38
jp nz, Function104bd0
call Function104b88
jp nz, Function104bd0
call Function104d43
jp nz, Function104bd0
call Function105033
jp Function104bd0
2018-06-24 14:09:41 +00:00
Function104b22:
2015-11-23 05:21:21 +00:00
call Function104b88
jp nz, Function104bd0
call Function104d43
jp nz, Function104bd0
call Function104b40
jp nz, Function104bd0
call Function104d38
jp nz, Function104bd0
call Function10502e
jp Function104bd0
2018-06-24 14:09:41 +00:00
Function104b40:
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d56
ret nz
2018-06-24 14:09:41 +00:00
Function104b49:
2015-11-23 05:21:21 +00:00
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
ldh a, [hPrintNum1]
2015-11-23 05:21:21 +00:00
cp $96
jp nz, Function104d32
ld a, $90
ldh [hPrintNum1], a
2015-11-23 05:21:21 +00:00
call Function104d38
ret nz
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
call Function104d43
ret nz
ld hl, wMysteryGiftTrainerData
ld a, [wca02]
ld b, a
call Function104d56
ret nz
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104b88:
2015-11-23 05:21:21 +00:00
ld a, $96
ldh [hPrintNum1], a
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
call Function104d43
ret nz
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d56
ret nz
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
ldh a, [hPrintNum1]
2015-11-23 05:21:21 +00:00
cp $90
jp nz, Function104d32
call Function104d38
ret nz
ld hl, wLinkData
2015-11-23 05:21:21 +00:00
ld a, [wca02]
ld b, a
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104bd0:
2015-11-23 05:21:21 +00:00
nop
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $10
2016-06-07 12:08:51 +00:00
jr z, .quit
2015-11-23 05:21:21 +00:00
cp $6c
2016-06-07 12:08:51 +00:00
jr nz, .quit
2015-11-23 05:21:21 +00:00
ld hl, wca01
dec [hl]
2016-06-07 12:08:51 +00:00
jr z, .quit
2015-11-23 05:21:21 +00:00
ld hl, wMysteryGiftTrainerData
2015-12-15 01:06:41 +00:00
ld de, wMysteryGiftPartnerData
ld bc, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData
2015-11-23 05:21:21 +00:00
call CopyBytes
ld a, [wMysteryGiftTrainerData]
cp $3
2016-06-07 12:08:51 +00:00
jr nc, .quit
2017-12-24 17:47:30 +00:00
farcall StagePartyDataForMysteryGift
2016-06-07 12:08:51 +00:00
call MysteryGift_ClearTrainerData
2015-11-23 05:21:21 +00:00
ld a, $26
ld [wca02], a
ldh a, [hPrintNum9]
2015-11-23 05:21:21 +00:00
cp $2
jr z, .asm_104c10
call Function104d43
jr nz, Function104bd0
jp Function104b04
2016-06-07 12:08:51 +00:00
2015-11-23 05:21:21 +00:00
.asm_104c10
call Function104d38
jr nz, Function104bd0
jp Function104b22
2016-06-07 12:08:51 +00:00
.quit
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
push af
call Function104da0
xor a
ldh [rIF], a
ldh a, [rIE]
2015-11-23 05:21:21 +00:00
or $1
ldh [rIE], a
2015-11-23 05:21:21 +00:00
ei
call DelayFrame
pop af
ret
2018-06-24 14:09:41 +00:00
Function104c2d:
2015-11-23 05:21:21 +00:00
di
2017-12-24 17:47:30 +00:00
farcall ClearChannels
2015-11-23 05:21:21 +00:00
call Function104d5e
.asm_104c37
call Function104d96
call Function104ddd
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $10
jp z, Function104d1c
cp $6c
jr nz, .asm_104c37
ldh a, [hPrintNum9]
2015-11-23 05:21:21 +00:00
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
2018-06-24 14:09:41 +00:00
Function104c8a:
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d56
ret nz
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
ldh a, [hPrintNum1]
2015-11-23 05:21:21 +00:00
cp $3c
jp nz, Function104d32
swap a
ldh [hPrintNum1], a
2015-11-23 05:21:21 +00:00
call Function104d38
ret nz
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
call Function104d43
ret nz
ld hl, wMysteryGiftTrainerData
ld a, [wca02]
ld b, a
call Function104d56
ret nz
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104cd2:
2015-11-23 05:21:21 +00:00
ld a, $3c
ldh [hPrintNum1], a
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
call Function104d43
ret nz
2015-12-15 01:06:41 +00:00
ld hl, hPrintNum1
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104d56
ret nz
call Function105033
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret nz
ldh a, [hPrintNum1]
2015-11-23 05:21:21 +00:00
swap a
cp $3c
jp nz, Function104d32
call Function104d38
ret nz
ld hl, wLinkData
2015-11-23 05:21:21 +00:00
ld a, [wca02]
ld b, a
call Function104d4e
ret nz
call Function10502e
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104d1c:
2015-11-23 05:21:21 +00:00
nop
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
push af
call Function104da0
xor a
ldh [rIF], a
ldh a, [rIE]
2015-11-23 05:21:21 +00:00
or $1
ldh [rIE], a
2015-11-23 05:21:21 +00:00
ei
call DelayFrame
pop af
ret
2018-06-24 14:09:41 +00:00
Function104d32:
2015-11-23 05:21:21 +00:00
ld a, $80
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
and a
ret
2018-06-24 14:09:41 +00:00
Function104d38:
2015-11-23 05:21:21 +00:00
call Function104d96
call Function104e46
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104d43:
2015-11-23 05:21:21 +00:00
call Function104d96
call Function104dfe
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104d4e:
2015-11-23 05:21:21 +00:00
call Function104e93
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104d56:
2015-11-23 05:21:21 +00:00
call Function104f57
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
cp $6c
ret
2018-06-24 14:09:41 +00:00
Function104d5e:
2015-11-23 05:21:21 +00:00
call Function104d74
ld a, $4
ldh [rIE], a
2015-11-23 05:21:21 +00:00
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
call Function104d96
xor a
ld b, a
.asm_104d6d
inc a
jr nz, .asm_104d6d
inc b
jr nz, .asm_104d6d
ret
2018-06-24 14:09:41 +00:00
Function104d74:
2015-11-23 05:21:21 +00:00
xor a
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
ld a, $fe
ldh [rTMA], a
ldh [rTIMA], a
2015-11-23 05:21:21 +00:00
ld a, $2
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
or $4
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104d86:
2015-11-23 05:21:21 +00:00
xor a
ldh [rTAC], a
ldh [rTMA], a
ldh [rTIMA], a
2015-11-23 05:21:21 +00:00
ld a, $2
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
or $4
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104d96:
2015-11-23 05:21:21 +00:00
ld a, $c0
call Function104e8c
ld a, $1
ldh [hPrintNum9], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104da0:
2015-11-23 05:21:21 +00:00
xor a
call Function104e8c
ld a, $2
ldh [rTAC], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104da9:
2015-11-23 05:21:21 +00:00
inc d
ret z
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
ld a, [$ff00+c]
bit 1, a
jr z, Function104da9
or a
ret
2018-06-24 14:09:41 +00:00
Function104db7:
2015-11-23 05:21:21 +00:00
inc d
ret z
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
ld a, [$ff00+c]
bit 1, a
jr nz, Function104db7
or a
ret
2018-06-24 14:09:41 +00:00
Function104dc5:
2015-11-23 05:21:21 +00:00
ld a, $c1
ld [$ff00+c], a
.wait
2015-11-23 05:21:21 +00:00
dec d
ret z
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
jr .wait
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function104dd1:
2015-11-23 05:21:21 +00:00
ld a, $c0
ld [$ff00+c], a
.wait
2015-11-23 05:21:21 +00:00
dec d
ret z
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
jr .wait
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function104ddd:
2015-11-23 05:21:21 +00:00
ld d, $0
ld e, d
ld a, $1
ldh [hPrintNum9], a
2015-12-07 03:36:09 +00:00
.loop
2016-06-07 12:08:51 +00:00
call MysteryGift_ReadJoypad
2015-11-23 05:21:21 +00:00
ld b, $2
ld c, LOW(rRP)
ldh a, [hMGJoypadReleased]
2016-06-07 12:08:51 +00:00
bit B_BUTTON_F, a
2015-12-07 03:36:09 +00:00
jr z, .next
2015-11-23 05:21:21 +00:00
ld a, $10
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2015-12-07 03:36:09 +00:00
.next
2015-11-23 05:21:21 +00:00
bit 0, a
2016-06-07 12:08:51 +00:00
jr nz, Function104e3a
2015-11-23 05:21:21 +00:00
ld a, [$ff00+c]
and b
2015-12-07 03:36:09 +00:00
jr nz, .loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function104dfe:
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
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
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
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
2018-06-24 14:09:41 +00:00
Function104e3a:
2016-06-07 12:08:51 +00:00
; Wait a random amount of time
2015-11-23 05:21:21 +00:00
call Random
ld e, a
and $f
ld d, a
2016-06-07 12:08:51 +00:00
.loop
2015-11-23 05:21:21 +00:00
dec de
ld a, d
or e
2016-06-07 12:08:51 +00:00
jr nz, .loop
2018-06-24 14:09:41 +00:00
Function104e46:
2015-11-23 05:21:21 +00:00
ld a, $2
ldh [hPrintNum9], a
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
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
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104e8c:
ldh [rRP], a
2015-11-23 05:21:21 +00:00
ld a, $ff
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104e93:
2015-11-23 05:21:21 +00:00
xor a
ldh [hPrintNum5], a
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
push hl
push bc
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
ld d, $3d
call Function104dd1
ld hl, hPrintNum2
2015-11-23 05:21:21 +00:00
ld a, $5a
ld [hli], a
ld [hl], b
dec hl
ld b, $2
call Function104ed6
pop bc
pop hl
call Function104ed6
ldh a, [hPrintNum5]
ldh [hPrintNum2], a
ldh a, [hPrintNum6]
ldh [hPrintNum3], a
2015-11-23 05:21:21 +00:00
push hl
ld hl, hPrintNum2
2015-11-23 05:21:21 +00:00
ld b, $2
call Function104ed6
2016-06-07 12:08:51 +00:00
ld hl, hMGStatusFlags
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104faf
ldh a, [hPrintNum2]
ldh [hPrintNum5], a
ldh a, [hPrintNum3]
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
pop hl
ret
2018-06-24 14:09:41 +00:00
Function104ed6:
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
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
ldh [rTMA], a
2015-11-23 05:21:21 +00:00
.asm_104eee
inc b
jr z, .asm_104f2e
ld a, $8
ldh [hPrintNum4], a
2015-11-23 05:21:21 +00:00
ld a, [hli]
ld e, a
ldh a, [hPrintNum5]
2015-11-23 05:21:21 +00:00
add e
ldh [hPrintNum5], a
ldh a, [hPrintNum6]
2018-02-04 18:16:40 +00:00
adc 0
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
.asm_104f02
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
ld a, $c1
ldh [rRP], a
2015-11-23 05:21:21 +00:00
ld d, $1
ld a, e
rlca
ld e, a
jr nc, .asm_104f13
inc d
.asm_104f13
ldh a, [rTIMA]
2015-11-23 05:21:21 +00:00
cp $f8
jr c, .asm_104f13
ld a, $c0
ldh [rRP], a
2015-11-23 05:21:21 +00:00
dec d
jr z, .asm_104f25
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
.asm_104f25
ldh a, [hPrintNum4]
2015-11-23 05:21:21 +00:00
dec a
jr z, .asm_104eee
ldh [hPrintNum4], a
2015-11-23 05:21:21 +00:00
jr .asm_104f02
.asm_104f2e
ld a, $fe
ldh [rTMA], a
2015-11-23 05:21:21 +00:00
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
halt
ld d, $5
call Function104dc5
ld d, $11
call Function104dd1
ret
2018-06-24 14:09:41 +00:00
Function104f42:
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
or $2
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104f49:
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
or $1
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104f50:
ldh a, [hMGStatusFlags]
2015-11-23 05:21:21 +00:00
or $80
ldh [hMGStatusFlags], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104f57:
2015-11-23 05:21:21 +00:00
xor a
ldh [hPrintNum5], a
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
push bc
push hl
ld hl, hPrintNum2
2015-11-23 05:21:21 +00:00
ld b, $2
call Function104faf
ldh a, [hPrintNum3]
ldh [hPrintNum8], a
2015-11-23 05:21:21 +00:00
ld b, a
pop hl
pop af
cp b
jp c, Function104f50
ldh a, [hPrintNum2]
2015-11-23 05:21:21 +00:00
cp $5a
jp nz, Function104f50
call Function104faf
ldh a, [hPrintNum5]
2015-11-23 05:21:21 +00:00
ld d, a
ldh a, [hPrintNum6]
2015-11-23 05:21:21 +00:00
ld e, a
push hl
push de
ld hl, hPrintNum2
2015-11-23 05:21:21 +00:00
ld b, $2
call Function104faf
pop de
ld hl, hPrintNum2
2015-11-23 05:21:21 +00:00
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
2016-06-07 12:08:51 +00:00
ld hl, hMGStatusFlags
2015-11-23 05:21:21 +00:00
ld b, $1
call Function104ed6
pop de
pop hl
ld a, d
ldh [hPrintNum5], a
2015-11-23 05:21:21 +00:00
ld a, e
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
Function104faf:
ld c, LOW(rRP)
2015-11-23 05:21:21 +00:00
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
ldh [hMGJoypadPressed + 2], a
2015-11-23 05:21:21 +00:00
call Function104d86
.asm_104fd2
inc b
jr z, .asm_10501a
ld a, $8
ldh [hPrintNum4], a
2015-11-23 05:21:21 +00:00
.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
ldh a, [hMGJoypadPressed + 2]
2015-11-23 05:21:21 +00:00
ld d, a
ldh a, [rTIMA]
ldh [hMGJoypadPressed + 2], a
2015-11-23 05:21:21 +00:00
sub d
cp $12
jr c, .asm_104ffd
set 0, e
jr .asm_104fff
.asm_104ffd
res 0, e
.asm_104fff
ldh a, [hPrintNum4]
2015-11-23 05:21:21 +00:00
dec a
ldh [hPrintNum4], a
2015-11-23 05:21:21 +00:00
jr z, .asm_10500b
ld a, e
rlca
ld e, a
jr .asm_104fd9
.asm_10500b
ld a, e
ld [hli], a
ldh a, [hPrintNum5]
2015-11-23 05:21:21 +00:00
add e
ldh [hPrintNum5], a
ldh a, [hPrintNum6]
2018-02-04 18:16:40 +00:00
adc 0
ldh [hPrintNum6], a
2015-11-23 05:21:21 +00:00
jr .asm_104fd2
.asm_10501a
call Function104d74
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
ld d, $0
call Function104da9
jp z, Function104f42
ld d, $10
call Function104dd1
ret
2018-06-24 14:09:41 +00:00
Function10502e:
2015-11-23 05:21:21 +00:00
ld b, $0
jp Function104e93
2018-06-24 14:09:41 +00:00
Function105033:
2015-11-23 05:21:21 +00:00
ld b, $0
jp Function104f57
2018-06-24 14:09:41 +00:00
MysteryGift_ReadJoypad:
2016-06-07 12:08:51 +00:00
; We can only get four inputs at a time.
; We take d-pad first for no particular reason.
ld a, R_DPAD
ldh [rJOYP], a
2016-06-07 12:08:51 +00:00
; Read twice to give the request time to take.
ldh a, [rJOYP]
ldh a, [rJOYP]
2016-06-07 12:08:51 +00:00
; The Joypad register output is in the lo nybble (inversed).
; We make the hi nybble of our new container d-pad input.
2015-11-23 05:21:21 +00:00
cpl
and $f
swap a
2016-06-07 12:08:51 +00:00
; We'll keep this in b for now.
2015-11-23 05:21:21 +00:00
ld b, a
2016-06-07 12:08:51 +00:00
; Buttons make 8 total inputs (A, B, Select, Start).
; We can fit this into one byte.
ld a, R_BUTTONS
ldh [rJOYP], a
2016-06-07 12:08:51 +00:00
; Wait for input to stabilize.
2015-11-23 05:21:21 +00:00
rept 6
ldh a, [rJOYP]
2015-11-23 05:21:21 +00:00
endr
2016-06-07 12:08:51 +00:00
; Buttons take the lo nybble.
2015-11-23 05:21:21 +00:00
cpl
and $f
or b
ld c, a
2016-06-07 12:08:51 +00:00
; To get the delta we xor the last frame's input with the new one.
ldh a, [hMGJoypadPressed]
2015-11-23 05:21:21 +00:00
xor c
2016-06-07 12:08:51 +00:00
; Released this frame:
2015-11-23 05:21:21 +00:00
and c
ldh [hMGJoypadReleased], a
2016-06-07 12:08:51 +00:00
; Pressed this frame:
2015-11-23 05:21:21 +00:00
ld a, c
ldh [hMGJoypadPressed], a
2015-11-23 05:21:21 +00:00
ld a, $30
2016-06-07 12:08:51 +00:00
; Reset the joypad register since we're done with it.
ldh [rJOYP], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
MysteryGift_CheckAndSetDecorationAlreadyReceived:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld d, $0
ld b, CHECK_FLAG
ld hl, sMysteryGiftDecorationsReceived
predef_id SmallFarFlagAction
2015-11-23 05:21:21 +00:00
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 SmallFarFlagAction
2015-11-23 05:21:21 +00:00
call CloseSRAM
xor a
ret
2018-06-24 14:09:41 +00:00
MysteryGift_CopyReceivedDecosToPC:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld c, $0
.loop
push bc
ld d, $0
ld b, CHECK_FLAG
ld hl, sMysteryGiftDecorationsReceived
predef SmallFarFlagAction
2015-11-23 05:21:21 +00:00
ld a, c
and a
pop bc
jr z, .skip
push bc
2017-12-24 17:47:30 +00:00
callfar SetSpecificDecorationFlag
2015-11-23 05:21:21 +00:00
pop bc
.skip
inc c
ld a, c
2017-12-27 16:56:03 +00:00
cp TrophyIDs - DecorationIDs
2015-11-23 05:21:21 +00:00
jr c, .loop
jp CloseSRAM
2018-06-24 14:09:41 +00:00
UnlockMysteryGift:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld hl, sMysteryGiftUnlocked
ld a, [hl]
inc a
jr nz, .ok
ld [hld], a
ld [hl], a
.ok
jp CloseSRAM
2018-06-24 14:09:41 +00:00
Function1050c8:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld a, [sNumDailyMysteryGiftPartnerIDs]
cp $ff
jr z, .okay
xor a
ld [sNumDailyMysteryGiftPartnerIDs], a
.okay
jp CloseSRAM
2018-06-24 14:09:41 +00:00
BackupMysteryGift:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld hl, sMysteryGiftItem
ld de, sBackupMysteryGiftItem
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp CloseSRAM
2018-06-24 14:09:41 +00:00
RestoreMysteryGift:
2015-11-23 05:21:21 +00:00
call GetMysteryGiftBank
ld hl, sBackupMysteryGiftItem
ld de, sMysteryGiftItem
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp CloseSRAM
2018-06-24 14:09:41 +00:00
MysteryGift_ClearTrainerData:
2015-11-23 05:21:21 +00:00
ld hl, wMysteryGiftTrainerData
xor a
2015-12-07 03:36:09 +00:00
ld b, wMysteryGiftTrainerDataEnd - wMysteryGiftTrainerData
.loop
2015-11-23 05:21:21 +00:00
ld [hli], a
dec b
2015-12-07 03:36:09 +00:00
jr nz, .loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
GetMysteryGiftBank:
2015-11-23 05:21:21 +00:00
ld a, BANK(sBackupMysteryGiftItem)
jp GetSRAMBank
2018-06-24 14:09:41 +00:00
StagePartyDataForMysteryGift:
2015-12-15 01:06:41 +00:00
; 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-23 05:21:21 +00:00
ld a, BANK(sPokemonData)
call GetSRAMBank
2015-12-15 01:06:41 +00:00
ld de, wMysteryGiftStaging
2018-01-23 22:39:09 +00:00
ld bc, sPokemonData + wPartyMons - wPokemonData
ld hl, sPokemonData + wPartySpecies - wPokemonData
2015-12-15 01:06:41 +00:00
.loop
2015-11-23 05:21:21 +00:00
ld a, [hli]
2015-12-15 01:06:41 +00:00
cp -1
jr z, .party_end
2015-11-23 05:21:21 +00:00
cp EGG
2015-12-15 01:06:41 +00:00
jr z, .next
2015-11-23 05:21:21 +00:00
push hl
2015-12-15 01:06:41 +00:00
; copy level
2015-11-23 05:21:21 +00:00
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
ld [de], a
inc de
2015-12-15 01:06:41 +00:00
; copy species
2015-11-23 05:21:21 +00:00
ld hl, MON_SPECIES
add hl, bc
ld a, [hl]
ld [de], a
inc de
2015-12-15 01:06:41 +00:00
; copy moves
2015-11-23 05:21:21 +00:00
ld hl, MON_MOVES
add hl, bc
push bc
ld bc, NUM_MOVES
call CopyBytes
pop bc
pop hl
2015-12-15 01:06:41 +00:00
.next
2015-11-23 05:21:21 +00:00
push hl
ld hl, PARTYMON_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
pop hl
2015-12-15 01:06:41 +00:00
jr .loop
.party_end
ld a, -1
2015-11-23 05:21:21 +00:00
ld [de], a
ld a, $26
ld [wca00], a
jp CloseSRAM
2018-06-24 14:09:41 +00:00
InitMysteryGiftLayout:
2015-11-23 05:21:21 +00:00
call ClearBGPalettes
call DisableLCD
ld hl, MysteryGiftGFX
2017-12-28 12:32:33 +00:00
ld de, vTiles2 tile $00
2015-11-23 05:21:21 +00:00
ld a, BANK(MysteryGiftGFX)
ld bc, MysteryGiftGFX.End - MysteryGiftGFX
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
call .Load5GFX
2015-11-23 05:21:21 +00:00
hlcoord 2, 2
ld a, $17
2015-12-15 01:06:41 +00:00
call .Load16GFX
2015-11-23 05:21:21 +00:00
hlcoord 2, 3
ld a, $27
2015-12-15 01:06:41 +00:00
call .Load16GFX
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
call .Load14Column
2015-11-23 05:21:21 +00:00
ld a, $9
hlcoord 18, 5
2015-12-15 01:06:41 +00:00
call .Load11Column
2015-11-23 05:21:21 +00:00
hlcoord 2, 5
ld a, $b
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 16
ld a, $7
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 5
ld a, $d
2015-12-15 01:06:41 +00:00
call .Load5GFX
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 15
ld a, $40
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 6
ld a, $3c
2015-12-15 01:06:41 +00:00
call .Load9Column
2015-11-23 05:21:21 +00:00
hlcoord 17, 6
ld a, $3e
2015-12-15 01:06:41 +00:00
call .Load9Column
2015-11-23 05:21:21 +00: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
2016-06-06 22:23:00 +00:00
ld b, SCGB_MYSTERY_GIFT
2015-11-23 05:21:21 +00:00
call GetSGBLayout
call SetPalettes
ret
2018-06-24 14:09:41 +00:00
.Load5GFX:
2015-12-15 01:06:41 +00:00
ld b, 5
jr .gfx_loop
2015-11-23 05:21:21 +00:00
2018-01-02 15:04:21 +00:00
.Unreferenced_Load6GFX:
2015-12-15 01:06:41 +00:00
ld b, 6
jr .gfx_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load16GFX:
2015-12-15 01:06:41 +00:00
ld b, 16
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.gfx_loop
2015-11-23 05:21:21 +00:00
ld [hli], a
inc a
dec b
2015-12-15 01:06:41 +00:00
jr nz, .gfx_loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.Load9Column:
2015-12-15 01:06:41 +00:00
ld b, 9
jr .col_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load11Column:
2015-12-15 01:06:41 +00:00
ld b, 11
jr .col_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load14Column:
2015-12-15 01:06:41 +00:00
ld b, 14
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.col_loop
2015-11-23 05:21:21 +00:00
ld [hl], a
2015-12-15 01:06:41 +00:00
ld de, SCREEN_WIDTH
2015-11-23 05:21:21 +00:00
add hl, de
dec b
2015-12-15 01:06:41 +00:00
jr nz, .col_loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.Load16Row:
2015-12-15 01:06:41 +00:00
ld b, 16
.row_loop
2015-11-23 05:21:21 +00:00
ld [hli], a
dec b
2015-12-15 01:06:41 +00:00
jr nz, .row_loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
MysteryGiftGFX:
INCBIN "gfx/mystery_gift/mystery_gift.2bpp"
.End
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function105688:
2015-11-23 05:21:21 +00:00
call ClearTileMap
call ClearSprites
call WaitBGMap
call Function1057d7
hlcoord 3, 8
2018-03-03 00:39:16 +00:00
ld de, String_PressAToLink_BToCancel_JP
2015-11-23 05:21:21 +00:00
call PlaceString
call WaitBGMap
call Function10578c
2016-06-07 12:08:51 +00:00
call MysteryGift_ClearTrainerData
2015-11-23 05:21:21 +00:00
ld a, $24
ld [wca02], a
ldh a, [rIE]
2015-11-23 05:21:21 +00:00
push af
call Function104c2d
ld d, a
xor a
ldh [rIF], a
2015-11-23 05:21:21 +00:00
pop af
ldh [rIE], a
2015-11-23 05:21:21 +00:00
ld a, d
cp $10
jp z, Function105712
cp $6c
jp nz, Function10571a
call Function1056eb
ld c, 60
call DelayFrames
call Function105777
2015-12-15 01:06:41 +00:00
ld hl, Text_ReceivedCard
2015-11-23 05:21:21 +00:00
call PrintText
ld de, wMysteryGiftTrainerData
2017-12-24 17:47:30 +00:00
farcall Function8ac70
2015-11-23 05:21:21 +00:00
ld a, c
ld [wDeciramBuffer], a
2015-12-15 01:06:41 +00:00
ld hl, Text_CardNotRegistered
2018-03-03 00:39:16 +00:00
jr c, PrintTextAndExit_JP
2015-12-15 01:06:41 +00:00
ld hl, Text_ListedCardAsNumber
2018-03-03 00:39:16 +00:00
jr PrintTextAndExit_JP
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function1056eb:
2018-01-10 18:47:57 +00:00
ld c, 16
.loop
2018-01-30 19:52:46 +00:00
ld hl, wVirtualOAMSprite00YCoord
2018-01-10 18:47:57 +00:00
ld b, 8
.dec_y_loop
2015-11-23 05:21:21 +00:00
dec [hl]
2018-01-10 18:47:57 +00:00
rept SPRITEOAMSTRUCT_LENGTH
2015-11-23 05:21:21 +00:00
inc hl
endr
dec b
2018-01-10 18:47:57 +00:00
jr nz, .dec_y_loop
2018-01-30 19:52:46 +00:00
ld hl, wVirtualOAMSprite08YCoord
2018-01-10 18:47:57 +00:00
ld b, 8
.inc_y_loop
2015-11-23 05:21:21 +00:00
inc [hl]
2018-01-10 18:47:57 +00:00
rept SPRITEOAMSTRUCT_LENGTH
2015-11-23 05:21:21 +00:00
inc hl
endr
dec b
2018-01-10 18:47:57 +00:00
jr nz, .inc_y_loop
2015-11-23 05:21:21 +00:00
dec c
ret z
push bc
ld c, 4
call DelayFrames
pop bc
2018-01-10 18:47:57 +00:00
jr .loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function105712:
2015-11-23 05:21:21 +00:00
call Function105777
2015-12-15 01:06:41 +00:00
ld hl, Text_MGLinkCanceled
2018-03-03 00:39:16 +00:00
jr PrintTextAndExit_JP
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
Function10571a:
2015-11-23 05:21:21 +00:00
call Function105777
2015-12-15 01:06:41 +00:00
ld hl, Text_MGCommError
2015-11-23 05:21:21 +00:00
call PrintText
jp Function105688
2018-06-24 14:09:41 +00:00
PrintTextAndExit_JP:
2015-11-23 05:21:21 +00:00
call PrintText
2017-12-29 18:22:33 +00:00
ld a, LCDC_DEFAULT
ldh [rLCDC], a
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
String_PressAToLink_BToCancel_JP:
2018-03-03 00:39:16 +00:00
db "エーボタン<WO>おすと"
next "つうしん<PKMN>おこなわれるよ!"
2018-03-03 00:39:16 +00:00
next "ビーボタン<WO>おすと"
next "つうしん<WO>ちゅうし します"
2015-11-23 05:21:21 +00:00
db "@"
2018-06-24 14:09:41 +00:00
Text_ReceivedCard:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c051a
db "@"
2018-06-24 14:09:41 +00:00
Text_ListedCardAsNumber:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0531
db "@"
2018-06-24 14:09:41 +00:00
Text_CardNotRegistered:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0555
db "@"
2018-06-24 14:09:41 +00:00
Text_MGLinkCanceled:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0573
db "@"
2018-06-24 14:09:41 +00:00
Text_MGCommError:
2015-11-23 05:21:21 +00:00
text_jump UnknownText_0x1c0591
db "@"
2018-06-24 14:09:41 +00:00
Function105777:
2015-11-23 05:21:21 +00:00
call ClearSprites
call ClearTileMap
call EnableLCD
call WaitBGMap
2016-06-06 22:23:00 +00:00
ld b, SCGB_DIPLOMA
2015-11-23 05:21:21 +00:00
call GetSGBLayout
call SetPalettes
ret
2018-06-24 14:09:41 +00:00
Function10578c:
ld de, wLinkData
2015-11-23 05:21:21 +00:00
ld a, BANK(sPlayerData)
call GetSRAMBank
2018-01-23 22:39:09 +00:00
ld hl, sPlayerData + wPlayerName - wPlayerData
2015-11-23 05:21:21 +00:00
ld bc, NAME_LENGTH
call CopyBytes
2018-01-23 22:39:09 +00:00
ld hl, sPlayerData + wPlayerID - wPlayerData
2015-11-23 05:21:21 +00:00
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 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
2015-11-23 05:21:21 +00:00
call GetSRAMBank
2018-01-09 03:48:58 +00:00
ld hl, $a603 ; address of MBC30 bank
2015-11-23 05:21:21 +00:00
ld bc, $8
call CopyBytes
2018-01-09 03:48:58 +00:00
ld hl, $a007 ; address of MBC30 bank
2015-11-23 05:21:21 +00:00
ld bc, $c
call CopyBytes
call CloseSRAM
ret
2018-06-24 14:09:41 +00:00
Function1057d7:
2015-11-23 05:21:21 +00:00
call ClearBGPalettes
call DisableLCD
ld hl, MysteryGiftJP_GFX
2017-12-28 12:32:33 +00:00
ld de, vTiles2 tile $00
2015-11-23 05:21:21 +00:00
ld a, BANK(MysteryGiftJP_GFX)
lb bc, 4, 0
call FarCopyBytes
2018-01-10 18:47:57 +00:00
ld hl, MysteryGiftJP_GFX + $40 tiles
2017-12-28 12:32:33 +00:00
ld de, vTiles0 tile $00
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
call .Load11Row
2015-11-23 05:21:21 +00:00
hlcoord 4, 3
ld a, $1e
2015-12-15 01:06:41 +00:00
call .Load12Row
2015-11-23 05:21:21 +00:00
hlcoord 4, 4
ld a, $2a
2015-12-15 01:06:41 +00:00
call .Load12Row
2015-11-23 05:21:21 +00:00
hlcoord 1, 2
ld [hl], $4
hlcoord 1, 3
ld a, $5
2015-12-15 01:06:41 +00:00
call .Load14Column
2015-11-23 05:21:21 +00:00
ld a, $9
hlcoord 18, 5
2015-12-15 01:06:41 +00:00
call .Load11Column
2015-11-23 05:21:21 +00:00
hlcoord 2, 5
ld a, $b
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 16
ld a, $7
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 5
ld a, $d
2015-12-15 01:06:41 +00:00
call .Load6Row
2015-11-23 05:21:21 +00: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-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 15
ld a, $3d
2015-12-15 01:06:41 +00:00
call .Load16Row
2015-11-23 05:21:21 +00:00
hlcoord 2, 6
ld a, $39
2015-12-15 01:06:41 +00:00
call .Load9Column
2015-11-23 05:21:21 +00:00
hlcoord 17, 6
ld a, $3b
2015-12-15 01:06:41 +00:00
call .Load9Column
2015-11-23 05:21:21 +00: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
2018-01-30 19:52:46 +00:00
ld de, wVirtualOAMSprite00
2015-12-15 01:06:41 +00:00
ld hl, .OAM_data
2018-01-10 18:47:57 +00:00
ld bc, 16 * SPRITEOAMSTRUCT_LENGTH
2015-11-23 05:21:21 +00:00
call CopyBytes
call EnableLCD
call WaitBGMap
ld b, $2
2017-12-24 17:47:30 +00:00
farcall GetMysteryGift_MobileAdapterLayout
2015-11-23 05:21:21 +00:00
jp SetPalettes
2018-06-24 14:09:41 +00:00
.Load6Row:
2015-12-15 01:06:41 +00:00
ld b, 6
jr .row_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load11Row:
2015-12-15 01:06:41 +00:00
ld b, 11
jr .row_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load12Row:
2015-12-15 01:06:41 +00:00
ld b, 12
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.row_loop
2015-11-23 05:21:21 +00:00
ld [hli], a
inc a
dec b
2015-12-15 01:06:41 +00:00
jr nz, .row_loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.Load9Column:
2015-12-15 01:06:41 +00:00
ld b, 9
jr .column_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load11Column:
2015-12-15 01:06:41 +00:00
ld b, 11
jr .column_loop
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.Load14Column:
2015-12-15 01:06:41 +00:00
ld b, 14
2015-11-23 05:21:21 +00:00
2018-06-24 14:09:41 +00:00
.column_loop
2015-11-23 05:21:21 +00:00
ld [hl], a
ld de, SCREEN_WIDTH
add hl, de
dec b
2015-12-15 01:06:41 +00:00
jr nz, .column_loop
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.Load16Row:
2015-12-15 01:06:41 +00:00
ld b, 16
.row_loop_no_inc
2015-11-23 05:21:21 +00:00
ld [hli], a
dec b
2015-12-15 01:06:41 +00:00
jr nz, .row_loop_no_inc
2015-11-23 05:21:21 +00:00
ret
2018-06-24 14:09:41 +00:00
.OAM_data:
2018-01-02 22:26:23 +00:00
dsprite 2, 1, 6, 4, $00, 0
dsprite 2, 1, 7, 4, $01, 0
dsprite 2, 1, 8, 4, $02, 0
dsprite 2, 1, 9, 4, $03, 0
dsprite 3, 1, 6, 4, $04, 0
dsprite 3, 1, 7, 4, $05, 0
dsprite 3, 1, 8, 4, $06, 0
dsprite 3, 1, 9, 4, $07, 0
dsprite 0, 1, 11, 4, $00, 0
dsprite 0, 1, 12, 4, $01, 0
dsprite 0, 1, 13, 4, $02, 0
dsprite 0, 1, 14, 4, $03, 0
dsprite 1, 1, 11, 4, $04, 0
dsprite 1, 1, 12, 4, $05, 0
dsprite 1, 1, 13, 4, $06, 0
dsprite 1, 1, 14, 4, $07, 0
2015-11-23 05:21:21 +00:00
; japanese mystery gift gfx
2018-06-24 14:09:41 +00:00
MysteryGiftJP_GFX:
INCBIN "gfx/mystery_gift/mystery_gift_jp.2bpp"