pokecrystal/engine/phone/phone.asm

733 lines
10 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
AddPhoneNumber::
2015-10-24 14:34:19 +00:00
call _CheckCellNum
jr c, .cant_add
call Phone_FindOpenSlot
jr nc, .cant_add
ld [hl], c
xor a
ret
.cant_add
scf
ret
2018-06-24 14:09:41 +00:00
DelCellNum::
2015-10-24 14:34:19 +00:00
call _CheckCellNum
jr nc, .not_in_list
xor a
ld [hl], a
ret
.not_in_list
scf
ret
2018-06-24 14:09:41 +00:00
CheckCellNum::
2015-10-24 14:34:19 +00:00
jp _CheckCellNum ; wtf
2018-06-24 14:09:41 +00:00
_CheckCellNum:
2015-10-24 14:34:19 +00:00
ld hl, wPhoneList
ld b, CONTACT_LIST_SIZE
.loop
ld a, [hli]
cp c
jr z, .got_it
dec b
jr nz, .loop
xor a
ret
.got_it
dec hl
scf
ret
2018-06-24 14:09:41 +00:00
Phone_FindOpenSlot:
2015-10-24 14:34:19 +00:00
call GetRemainingSpaceInPhoneList
ld b, a
ld hl, wPhoneList
.loop
ld a, [hli]
and a
jr z, .FoundOpenSpace
dec b
jr nz, .loop
xor a
ret
.FoundOpenSpace:
2015-10-24 14:34:19 +00:00
dec hl
scf
ret
2018-06-24 14:09:41 +00:00
GetRemainingSpaceInPhoneList:
2015-10-24 14:34:19 +00:00
xor a
2018-01-23 22:39:09 +00:00
ld [wBuffer1], a
2015-10-24 14:34:19 +00:00
ld hl, PermanentNumbers
.loop
ld a, [hli]
cp -1
jr z, .done
cp c
2018-01-11 06:45:27 +00:00
jr z, .continue
2015-10-24 14:34:19 +00:00
push bc
push hl
ld c, a
call _CheckCellNum
2018-01-11 06:45:27 +00:00
jr c, .permanent
2018-01-23 22:39:09 +00:00
ld hl, wBuffer1
2015-10-24 14:34:19 +00:00
inc [hl]
2018-01-11 06:45:27 +00:00
.permanent
2015-10-24 14:34:19 +00:00
pop hl
pop bc
2018-01-11 06:45:27 +00:00
.continue
2015-10-24 14:34:19 +00:00
jr .loop
.done
ld a, CONTACT_LIST_SIZE
2018-01-23 22:39:09 +00:00
ld hl, wBuffer1
2015-10-24 14:34:19 +00:00
sub [hl]
ret
2018-01-11 06:45:27 +00:00
INCLUDE "data/phone/permanent_numbers.asm"
2015-10-24 14:34:19 +00:00
2018-06-24 14:09:41 +00:00
FarPlaceString:
2015-10-24 14:34:19 +00:00
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
call PlaceString
pop af
rst Bankswitch
ret
2018-06-24 14:09:41 +00:00
CheckPhoneCall::
2015-10-24 14:34:19 +00:00
; Check if the phone is ringing in the overworld.
call CheckStandingOnEntrance
jr z, .no_call
call .timecheck
nop
jr nc, .no_call
call Random
ld b, a
and 50 percent
cp b
jr nz, .no_call
call GetMapPhoneService
2015-10-24 14:34:19 +00:00
and a
jr nz, .no_call
call GetAvailableCallers
call ChooseRandomCaller
jr nc, .no_call
ld e, a
call LoadCallerScript
ld a, BANK(Script_ReceivePhoneCall)
ld hl, Script_ReceivePhoneCall
call CallScript
scf
ret
.no_call
xor a
ret
2018-06-24 14:09:41 +00:00
.timecheck
2017-12-24 17:47:30 +00:00
farcall CheckReceiveCallTimer
2015-10-24 14:34:19 +00:00
ret
2018-06-24 14:09:41 +00:00
CheckPhoneContactTimeOfDay:
2015-10-24 14:34:19 +00:00
push hl
push bc
push de
push af
2017-12-24 17:47:30 +00:00
farcall CheckTime
2015-10-24 14:34:19 +00:00
pop af
2018-01-16 03:00:56 +00:00
and ANYTIME
2015-10-24 14:34:19 +00:00
and c
pop de
pop bc
pop hl
ret
2018-06-24 14:09:41 +00:00
ChooseRandomCaller:
2015-10-24 14:34:19 +00:00
; If no one is available to call, don't return anything.
2018-01-23 22:39:09 +00:00
ld a, [wEngineBuffer3]
2015-10-24 14:34:19 +00:00
and a
jr z, .NothingToSample
; Sample a random number between 0 and 31.
ld c, a
call Random
ld a, [hRandomAdd]
2015-10-24 14:34:19 +00:00
swap a
and $1f
; Compute that number modulo the number of available callers.
call SimpleDivide
; Return the caller ID you just sampled.
ld c, a
ld b, 0
2018-01-23 22:39:09 +00:00
ld hl, wEngineBuffer4
2015-10-24 14:34:19 +00:00
add hl, bc
ld a, [hl]
scf
ret
.NothingToSample:
2015-10-24 14:34:19 +00:00
xor a
ret
2018-06-24 14:09:41 +00:00
GetAvailableCallers:
2017-12-24 17:47:30 +00:00
farcall CheckTime
2015-10-24 14:34:19 +00:00
ld a, c
2018-01-23 22:39:09 +00:00
ld [wEngineBuffer1], a
ld hl, wEngineBuffer3
2015-10-24 14:34:19 +00:00
ld bc, 11
xor a
call ByteFill
ld de, wPhoneList
ld a, CONTACT_LIST_SIZE
.loop
2018-01-23 22:39:09 +00:00
ld [wEngineBuffer2], a
2015-10-24 14:34:19 +00:00
ld a, [de]
and a
jr z, .not_good_for_call
ld hl, PhoneContacts + PHONE_CONTACT_SCRIPT2_TIME
ld bc, PHONE_TABLE_WIDTH
call AddNTimes
2018-01-23 22:39:09 +00:00
ld a, [wEngineBuffer1]
2015-10-24 14:34:19 +00:00
and [hl]
jr z, .not_good_for_call
ld bc, PHONE_CONTACT_MAP_GROUP - PHONE_CONTACT_SCRIPT2_TIME
add hl, bc
2018-01-23 22:39:09 +00:00
ld a, [wMapGroup]
2015-10-24 14:34:19 +00:00
cp [hl]
jr nz, .different_map
inc hl
2018-01-23 22:39:09 +00:00
ld a, [wMapNumber]
2015-10-24 14:34:19 +00:00
cp [hl]
jr z, .not_good_for_call
.different_map
2018-01-23 22:39:09 +00:00
ld a, [wEngineBuffer3]
2015-10-24 14:34:19 +00:00
ld c, a
ld b, $0
inc a
2018-01-23 22:39:09 +00:00
ld [wEngineBuffer3], a
ld hl, wEngineBuffer4
2015-10-24 14:34:19 +00:00
add hl, bc
ld a, [de]
ld [hl], a
.not_good_for_call
inc de
2018-01-23 22:39:09 +00:00
ld a, [wEngineBuffer2]
2015-10-24 14:34:19 +00:00
dec a
jr nz, .loop
ret
2018-06-24 14:09:41 +00:00
CheckSpecialPhoneCall::
2015-10-24 14:34:19 +00:00
ld a, [wSpecialPhoneCallID]
and a
jr z, .NoPhoneCall
dec a
ld c, a
ld b, 0
ld hl, SpecialPhoneCallList
ld a, 6
call AddNTimes
ld a, [hli]
ld h, [hl]
ld l, a
call _hl_
jr nc, .NoPhoneCall
call .DoSpecialPhoneCall
inc hl
inc hl
2015-10-24 14:34:19 +00:00
ld a, [hli]
ld e, a
push hl
call LoadCallerScript
pop hl
2015-12-19 01:07:09 +00:00
ld de, wPhoneScriptPointer
2015-10-24 14:34:19 +00:00
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
ld a, BANK(.script)
ld hl, .script
call CallScript
scf
ret
.NoPhoneCall:
2015-10-24 14:34:19 +00:00
xor a
ret
.script
2015-10-24 14:34:19 +00:00
pause 30
jump Script_ReceivePhoneCall
2018-06-24 14:09:41 +00:00
.DoSpecialPhoneCall:
2015-10-24 14:34:19 +00:00
ld a, [wSpecialPhoneCallID]
dec a
ld c, a
ld b, 0
ld hl, SpecialPhoneCallList
ld a, 6
call AddNTimes
ret
2018-06-24 14:09:41 +00:00
SpecialCallOnlyWhenOutside:
ld a, [wEnvironment]
2015-10-24 14:34:19 +00:00
cp TOWN
jr z, .outside
cp ROUTE
jr z, .outside
xor a
ret
.outside
scf
ret
2018-06-24 14:09:41 +00:00
SpecialCallWhereverYouAre:
2015-10-24 14:34:19 +00:00
scf
ret
2018-06-24 14:09:41 +00:00
Function90199:
2015-10-24 14:34:19 +00:00
; Don't do the call if you're in a link communication
ld a, [wLinkMode]
and a
jr nz, .OutOfArea
; If you're in an area without phone service, don't do the call
call GetMapPhoneService
2015-10-24 14:34:19 +00:00
and a
jr nz, .OutOfArea
; If the person can't take a call at that time, don't do the call
ld a, b
ld [wCurrentCaller], a
ld hl, PhoneContacts
ld bc, PHONE_TABLE_WIDTH
call AddNTimes
ld d, h
ld e, l
ld hl, PHONE_CONTACT_SCRIPT1_TIME
add hl, de
ld a, [hl]
call CheckPhoneContactTimeOfDay
jr z, .OutOfArea
; If we're in the same map as the person we're calling,
; use the "Just talk to that person" script.
ld hl, PHONE_CONTACT_MAP_GROUP
add hl, de
2018-01-23 22:39:09 +00:00
ld a, [wMapGroup]
2015-10-24 14:34:19 +00:00
cp [hl]
jr nz, .GetPhoneScript
ld hl, PHONE_CONTACT_MAP_NUMBER
add hl, de
2018-01-23 22:39:09 +00:00
ld a, [wMapNumber]
2015-10-24 14:34:19 +00:00
cp [hl]
jr nz, .GetPhoneScript
ld b, BANK(PhoneScript_JustTalkToThem)
ld hl, PhoneScript_JustTalkToThem
jr .DoPhoneCall
.GetPhoneScript:
2015-10-24 14:34:19 +00:00
ld hl, PHONE_CONTACT_SCRIPT1_BANK
add hl, de
ld b, [hl]
ld hl, PHONE_CONTACT_SCRIPT1_ADDR_LO
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jr .DoPhoneCall
.OutOfArea:
2015-10-24 14:34:19 +00:00
ld b, BANK(UnknownScript_0x90209)
ld de, UnknownScript_0x90209
call ExecuteCallbackScript
ret
.DoPhoneCall:
2015-10-24 14:34:19 +00:00
ld a, b
2018-01-23 22:39:09 +00:00
ld [wPhoneScriptBank], a
2015-10-24 14:34:19 +00:00
ld a, l
2018-01-23 22:39:09 +00:00
ld [wPhoneCaller], a
2015-10-24 14:34:19 +00:00
ld a, h
2018-01-23 22:39:09 +00:00
ld [wPhoneCaller + 1], a
2015-10-24 14:34:19 +00:00
ld b, BANK(UnknownScript_0x90205)
ld de, UnknownScript_0x90205
call ExecuteCallbackScript
ret
UnknownScript_0x90205:
2015-10-24 14:34:19 +00:00
ptcall wd002
return
UnknownScript_0x90209:
2015-10-24 14:34:19 +00:00
scall UnknownScript_0x90657
return
2018-06-24 14:09:41 +00:00
LoadCallerScript:
2015-10-24 14:34:19 +00:00
nop
nop
ld a, e
ld [wCurrentCaller], a
and a
jr nz, .actualcaller
ld a, BANK(WrongNumber)
ld hl, WrongNumber
jr .proceed
.actualcaller
ld hl, PhoneContacts
ld bc, 12
ld a, e
call AddNTimes
ld a, BANK(PhoneContacts)
.proceed
2018-01-23 22:39:09 +00:00
ld de, wEngineBuffer2
2015-10-24 14:34:19 +00:00
ld bc, 12
call FarCopyBytes
ret
2018-06-24 14:09:41 +00:00
WrongNumber:
2015-10-24 23:49:19 +00:00
db TRAINER_NONE, PHONE_00
2015-10-24 14:34:19 +00:00
dba .script
.script
2015-10-24 14:34:19 +00:00
writetext .text
end
.text
2015-10-24 14:34:19 +00:00
; Huh? Sorry, wrong number!
text_jump UnknownText_0x1c5565
db "@"
Script_ReceivePhoneCall:
2018-01-12 06:40:20 +00:00
refreshscreen
2015-10-24 14:34:19 +00:00
callasm RingTwice_StartCall
2015-12-19 01:07:09 +00:00
ptcall wPhoneScriptPointer
2015-11-25 15:16:29 +00:00
waitbutton
2015-10-24 14:34:19 +00:00
callasm HangUp
2015-11-25 15:16:29 +00:00
closetext
2015-10-24 14:34:19 +00:00
callasm InitCallReceiveDelay
end
Script_SpecialBillCall::
2016-03-27 16:47:28 +00:00
callasm .LoadBillScript
2015-10-24 14:34:19 +00:00
jump Script_ReceivePhoneCall
.LoadBillScript:
2015-10-24 14:34:19 +00:00
ld e, PHONE_BILL
jp LoadCallerScript
UnknownScript_0x90261:
2016-03-27 16:47:28 +00:00
callasm .LoadElmScript
2015-10-24 14:34:19 +00:00
pause 30
jump Script_ReceivePhoneCall
.LoadElmScript:
2015-10-24 14:34:19 +00:00
ld e, PHONE_ELM
jp LoadCallerScript
2018-06-24 14:09:41 +00:00
RingTwice_StartCall:
2015-10-24 14:34:19 +00:00
call .Ring
call .Ring
farcall StubbedTrainerRankings_PhoneCalls
2015-10-24 14:34:19 +00:00
ret
2018-06-24 14:09:41 +00:00
.Ring:
2015-10-24 14:34:19 +00:00
call Phone_StartRinging
call Phone_Wait20Frames
call Phone_CallerTextboxWithName
call Phone_Wait20Frames
call Phone_CallerTextbox
call Phone_Wait20Frames
call Phone_CallerTextboxWithName
ret
2018-06-24 14:09:41 +00:00
Phone_CallerTextboxWithName:
2015-10-24 14:34:19 +00:00
ld a, [wCurrentCaller]
ld b, a
call Function90363
ret
2018-06-24 14:09:41 +00:00
PhoneCall::
2015-10-24 14:34:19 +00:00
ld a, b
2018-01-23 22:39:09 +00:00
ld [wPhoneScriptBank], a
2015-10-24 14:34:19 +00:00
ld a, e
2018-01-23 22:39:09 +00:00
ld [wPhoneCaller], a
2015-10-24 14:34:19 +00:00
ld a, d
2018-01-23 22:39:09 +00:00
ld [wPhoneCaller + 1], a
2015-10-24 14:34:19 +00:00
call Phone_FirstOfTwoRings
call Phone_FirstOfTwoRings
farcall StubbedTrainerRankings_PhoneCalls
2015-10-24 14:34:19 +00:00
ret
2018-06-24 14:09:41 +00:00
Phone_FirstOfTwoRings:
2015-10-24 14:34:19 +00:00
call Phone_StartRinging
call Phone_Wait20Frames
call Phone_CallerTextboxWithName2
call Phone_Wait20Frames
call Phone_CallerTextbox
call Phone_Wait20Frames
call Phone_CallerTextboxWithName2
ret
2018-06-24 14:09:41 +00:00
Phone_CallerTextboxWithName2:
2015-10-24 14:34:19 +00:00
call Phone_CallerTextbox
hlcoord 1, 2
2018-01-19 07:30:19 +00:00
ld [hl], "☎"
2015-10-24 14:34:19 +00:00
inc hl
inc hl
2018-01-23 22:39:09 +00:00
ld a, [wPhoneScriptBank]
2015-10-24 14:34:19 +00:00
ld b, a
2018-01-23 22:39:09 +00:00
ld a, [wPhoneCaller]
2015-10-24 14:34:19 +00:00
ld e, a
2018-01-23 22:39:09 +00:00
ld a, [wPhoneCaller + 1]
2015-10-24 14:34:19 +00:00
ld d, a
call FarPlaceString
ret
2018-06-24 14:09:41 +00:00
Phone_NoSignal:
2015-10-24 14:34:19 +00:00
ld de, SFX_NO_SIGNAL
call PlaySFX
jr Phone_CallEnd
2018-06-24 14:09:41 +00:00
HangUp::
2015-10-24 14:34:19 +00:00
call HangUp_Beep
call HangUp_Wait20Frames
Phone_CallEnd:
call HangUp_BoopOn
call HangUp_Wait20Frames
call HangUp_BoopOff
call HangUp_Wait20Frames
call HangUp_BoopOn
call HangUp_Wait20Frames
call HangUp_BoopOff
call HangUp_Wait20Frames
call HangUp_BoopOn
call HangUp_Wait20Frames
call HangUp_BoopOff
call HangUp_Wait20Frames
ret
2018-06-24 14:09:41 +00:00
Function90316:
2015-10-24 14:34:19 +00:00
ld de, SFX_SHUT_DOWN_PC
call PlaySFX
ret
2018-06-24 14:09:41 +00:00
HangUp_Beep:
2015-10-24 14:34:19 +00:00
ld hl, UnknownText_0x9032a
call PrintText
ld de, SFX_HANG_UP
call PlaySFX
ret
2018-06-24 14:09:41 +00:00
UnknownText_0x9032a:
2015-10-24 14:34:19 +00:00
text_jump UnknownText_0x1c5580
db "@"
2018-06-24 14:09:41 +00:00
HangUp_BoopOn:
2015-10-24 14:34:19 +00:00
ld hl, UnknownText_0x90336
call PrintText
ret
UnknownText_0x90336:
2015-10-24 14:34:19 +00:00
text_jump UnknownText_0x1c5588
db "@"
2018-06-24 14:09:41 +00:00
HangUp_BoopOff:
2015-10-24 14:34:19 +00:00
call SpeechTextBox
ret
2018-06-24 14:09:41 +00:00
Phone_StartRinging:
2015-10-24 14:34:19 +00:00
call WaitSFX
ld de, SFX_CALL
call PlaySFX
call Phone_CallerTextbox
call UpdateSprites
farcall PhoneRing_CopyTilemapAtOnce
2015-10-24 14:34:19 +00:00
ret
2018-06-24 14:09:41 +00:00
HangUp_Wait20Frames:
2015-10-24 14:34:19 +00:00
jr Phone_Wait20Frames
Phone_Wait20Frames:
2015-10-24 14:34:19 +00:00
ld c, 20
call DelayFrames
farcall PhoneRing_CopyTilemapAtOnce
2015-10-24 14:34:19 +00:00
ret
2018-06-24 14:09:41 +00:00
Function90363:
2015-10-24 14:34:19 +00:00
push bc
call Phone_CallerTextbox
hlcoord 1, 1
2018-01-19 07:30:19 +00:00
ld [hl], "☎"
2015-10-24 14:34:19 +00:00
inc hl
inc hl
2015-10-24 14:34:19 +00:00
ld d, h
ld e, l
pop bc
call Function90380
ret
2018-06-24 14:09:41 +00:00
Phone_CallerTextbox:
2015-10-24 14:34:19 +00:00
hlcoord 0, 0
ld b, 2
ld c, SCREEN_WIDTH - 2
call TextBox
ret
2018-06-24 14:09:41 +00:00
Function90380:
2015-10-24 14:34:19 +00:00
ld h, d
ld l, e
ld a, b
call GetCallerTrainerClass
call GetCallerName
ret
2018-06-24 14:09:41 +00:00
CheckCanDeletePhoneNumber:
2015-10-24 14:34:19 +00:00
ld a, c
call GetCallerTrainerClass
ld a, c
2016-01-10 04:41:03 +00:00
; and a
2015-10-24 14:34:19 +00:00
ret nz
ld a, b
2016-01-10 04:41:03 +00:00
cp PHONECONTACT_MOM
2015-10-24 14:34:19 +00:00
ret z
2016-01-10 04:41:03 +00:00
cp PHONECONTACT_ELM
2015-10-24 14:34:19 +00:00
ret z
ld c, $1
ret
2018-06-24 14:09:41 +00:00
GetCallerTrainerClass:
2015-10-24 14:34:19 +00:00
push hl
ld hl, PhoneContacts + PHONE_CONTACT_TRAINER_CLASS
ld bc, PHONE_TABLE_WIDTH
call AddNTimes
ld a, [hli]
ld b, [hl]
ld c, a
pop hl
ret
2018-06-24 14:09:41 +00:00
GetCallerName:
2015-10-24 14:34:19 +00:00
ld a, c
and a
jr z, .NotTrainer
call Phone_GetTrainerName
push hl
push bc
call PlaceString
ld a, ":"
ld [bc], a
pop bc
pop hl
ld de, SCREEN_WIDTH + 3
add hl, de
call Phone_GetTrainerClassName
call PlaceString
ret
.NotTrainer:
2015-10-24 14:34:19 +00:00
push hl
ld c, b
ld b, 0
ld hl, NonTrainerCallerNames
add hl, bc
add hl, bc
2015-10-24 14:34:19 +00:00
ld a, [hli]
ld e, a
ld d, [hl]
pop hl
call PlaceString
ret
2018-01-26 03:19:24 +00:00
INCLUDE "data/phone/non_trainer_names.asm"
2015-10-24 14:34:19 +00:00
2018-06-24 14:09:41 +00:00
Phone_GetTrainerName:
2015-10-24 14:34:19 +00:00
push hl
push bc
2017-12-24 17:47:30 +00:00
farcall GetTrainerName
2015-10-24 14:34:19 +00:00
pop bc
pop hl
ret
2018-06-24 14:09:41 +00:00
Phone_GetTrainerClassName:
2015-10-24 14:34:19 +00:00
push hl
push bc
2017-12-24 17:47:30 +00:00
farcall GetTrainerClassName
2015-10-24 14:34:19 +00:00
pop bc
pop hl
ret
2018-06-24 14:09:41 +00:00
GetCallerLocation:
2015-10-24 14:34:19 +00:00
ld a, [wCurrentCaller]
call GetCallerTrainerClass
ld d, c
ld e, b
push de
ld a, [wCurrentCaller]
ld hl, PhoneContacts + PHONE_CONTACT_MAP_GROUP
ld bc, PHONE_TABLE_WIDTH
call AddNTimes
ld b, [hl]
inc hl
ld c, [hl]
push bc
call GetWorldMapLocation
ld e, a
2017-12-24 17:47:30 +00:00
farcall GetLandmarkName
2015-10-24 14:34:19 +00:00
pop bc
pop de
ret
2018-01-10 00:51:30 +00:00
INCLUDE "data/phone/phone_contacts.asm"
2015-10-24 14:34:19 +00:00
2018-01-10 00:51:30 +00:00
INCLUDE "data/phone/special_calls.asm"
UnknownScript_0x90657:
2015-10-24 14:34:19 +00:00
writetext UnknownText_0x9065b
end
UnknownText_0x9065b:
2015-10-24 14:34:19 +00:00
; That number is out of the area.
text_jump UnknownText_0x1c558b
db "@"
PhoneScript_JustTalkToThem:
2015-10-24 14:34:19 +00:00
writetext UnknownText_0x90664
end
UnknownText_0x90664:
2015-10-24 14:34:19 +00:00
; Just go talk to that person!
text_jump UnknownText_0x1c55ac
db "@"
UnknownScript_0x90669:
2015-10-24 14:34:19 +00:00
writetext UnknownText_0x9066d
end
UnknownText_0x9066d:
2015-10-24 14:34:19 +00:00
; Thank you!
text_jump UnknownText_0x1c55ca
db "@"