summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorentrpntr <entrpntr@gmail.com>2020-05-08 13:19:28 -0400
committerentrpntr <entrpntr@gmail.com>2020-05-08 13:22:30 -0400
commitc4c838855a18dd928d49487e5f7fd02d65ce4766 (patch)
tree43b50c09e10e3a72e59348e6ea655b4544abd568
parent1220198362a209647b6491cb088e1e04204208cb (diff)
Add engine/phone/phone.asm.
-rw-r--r--constants/wram_constants.asm2
-rw-r--r--data/phone/non_trainer_names.asm13
-rw-r--r--data/phone/permanent_numbers.asm4
-rw-r--r--data/phone/phone_contacts.asm49
-rw-r--r--data/phone/special_calls.asm17
-rw-r--r--engine/phone/phone.asm732
-rwxr-xr-xmacros/wram.asm6
-rw-r--r--main.asm152
-rw-r--r--wram.asm91
9 files changed, 996 insertions, 70 deletions
diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm
index ec956c5e..a56a59aa 100644
--- a/constants/wram_constants.asm
+++ b/constants/wram_constants.asm
@@ -118,6 +118,8 @@ DAY EQU 1 << DAY_F
NITE EQU 1 << NITE_F
DARKNESS EQU 1 << DARKNESS_F
+ANYTIME EQU MORN | DAY | NITE
+
; wPlayerSpriteSetupFlags::
PLAYERSPRITESETUP_FACING_MASK EQU %11
PLAYERSPRITESETUP_FEMALE_TO_MALE_F EQU 2
diff --git a/data/phone/non_trainer_names.asm b/data/phone/non_trainer_names.asm
new file mode 100644
index 00000000..4159014a
--- /dev/null
+++ b/data/phone/non_trainer_names.asm
@@ -0,0 +1,13 @@
+NonTrainerCallerNames:
+; entries correspond to PHONECONTACT_* constants
+ dw .none
+ dw .mom
+ dw .bikeshop
+ dw .bill
+ dw .elm
+
+.none: db "----------@"
+.mom: db "MOM@"
+.bill: db "BILL@"
+.elm: db "PROF.ELM@"
+.bikeshop: db "BIKE SHOP@"
diff --git a/data/phone/permanent_numbers.asm b/data/phone/permanent_numbers.asm
new file mode 100644
index 00000000..98c6212d
--- /dev/null
+++ b/data/phone/permanent_numbers.asm
@@ -0,0 +1,4 @@
+PermanentNumbers:
+ db PHONECONTACT_MOM
+ db PHONECONTACT_ELM
+ db -1 ; end
diff --git a/data/phone/phone_contacts.asm b/data/phone/phone_contacts.asm
new file mode 100644
index 00000000..d2b2c7a7
--- /dev/null
+++ b/data/phone/phone_contacts.asm
@@ -0,0 +1,49 @@
+phone: MACRO
+; trainer class, trainer id, map, callee time, callee script, caller time, caller script
+ db \1, \2
+ map_id \3
+ db \4
+ dba \5
+ db \6
+ dba \7
+ENDM
+
+PhoneContacts:
+; entries correspond to PHONE_* constants
+ phone TRAINER_NONE, PHONE_00, N_A, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone TRAINER_NONE, PHONECONTACT_MOM, PLAYERS_HOUSE_1F, ANYTIME, MomPhoneCalleeScript, 0, UnusedPhoneScript
+ phone TRAINER_NONE, PHONECONTACT_BIKESHOP, OAKS_LAB, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone TRAINER_NONE, PHONECONTACT_BILL, N_A, ANYTIME, BillPhoneCalleeScript, 0, BillPhoneCallerScript
+ phone TRAINER_NONE, PHONECONTACT_ELM, ELMS_LAB, ANYTIME, ElmPhoneCalleeScript, 0, ElmPhoneCallerScript
+ phone SCHOOLBOY, JACK1, NATIONAL_PARK, ANYTIME, JackPhoneCalleeScript, ANYTIME, JackPhoneCallerScript
+ phone POKEFANF, BEVERLY1, NATIONAL_PARK, ANYTIME, BeverlyPhoneCalleeScript, ANYTIME, BeverlyPhoneCallerScript
+ phone SAILOR, HUEY1, OLIVINE_LIGHTHOUSE_2F, ANYTIME, HueyPhoneCalleeScript, ANYTIME, HueyPhoneCallerScript
+ phone TRAINER_NONE, PHONE_00, N_A, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone TRAINER_NONE, PHONE_00, N_A, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone TRAINER_NONE, PHONE_00, N_A, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone COOLTRAINERM, GAVEN3, ROUTE_26, ANYTIME, GavenPhoneCalleeScript, ANYTIME, GavenPhoneCallerScript
+ phone COOLTRAINERF, BETH1, ROUTE_26, ANYTIME, BethPhoneCalleeScript, ANYTIME, BethPhoneCallerScript
+ phone BIRD_KEEPER, JOSE2, ROUTE_27, ANYTIME, JosePhoneCalleeScript, ANYTIME, JosePhoneCallerScript
+ phone COOLTRAINERF, REENA1, ROUTE_27, ANYTIME, ReenaPhoneCalleeScript, ANYTIME, ReenaPhoneCallerScript
+ phone YOUNGSTER, JOEY1, ROUTE_30, ANYTIME, JoeyPhoneCalleeScript, ANYTIME, JoeyPhoneCallerScript
+ phone BUG_CATCHER, WADE1, ROUTE_31, ANYTIME, WadePhoneCalleeScript, ANYTIME, WadePhoneCallerScript
+ phone FISHER, RALPH1, ROUTE_32, ANYTIME, RalphPhoneCalleeScript, ANYTIME, RalphPhoneCallerScript
+ phone PICNICKER, LIZ1, ROUTE_32, ANYTIME, LizPhoneCalleeScript, ANYTIME, LizPhoneCallerScript
+ phone HIKER, ANTHONY2, ROUTE_33, ANYTIME, AnthonyPhoneCalleeScript, ANYTIME, AnthonyPhoneCallerScript
+ phone CAMPER, TODD1, ROUTE_34, ANYTIME, ToddPhoneCalleeScript, ANYTIME, ToddPhoneCallerScript
+ phone PICNICKER, GINA1, ROUTE_34, ANYTIME, GinaPhoneCalleeScript, ANYTIME, GinaPhoneCallerScript
+ phone JUGGLER, IRWIN1, ROUTE_35, ANYTIME, IrwinPhoneCalleeScript, ANYTIME, IrwinPhoneCallerScript
+ phone BUG_CATCHER, ARNIE1, ROUTE_35, ANYTIME, ArniePhoneCalleeScript, ANYTIME, ArniePhoneCallerScript
+ phone SCHOOLBOY, ALAN1, ROUTE_36, ANYTIME, AlanPhoneCalleeScript, ANYTIME, AlanPhoneCallerScript
+ phone TRAINER_NONE, PHONE_00, N_A, 0, UnusedPhoneScript, 0, UnusedPhoneScript
+ phone LASS, DANA1, ROUTE_38, ANYTIME, DanaPhoneCalleeScript, ANYTIME, DanaPhoneCallerScript
+ phone SCHOOLBOY, CHAD1, ROUTE_38, ANYTIME, ChadPhoneCalleeScript, ANYTIME, ChadPhoneCallerScript
+ phone POKEFANM, DEREK1, ROUTE_39, ANYTIME, DerekPhoneCalleeScript, ANYTIME, DerekPhoneCallerScript
+ phone FISHER, CHRIS1, ROUTE_42, ANYTIME, ChrisPhoneCalleeScript, ANYTIME, ChrisPhoneCallerScript
+ phone POKEMANIAC, BRENT1, ROUTE_43, ANYTIME, BrentPhoneCalleeScript, ANYTIME, BrentPhoneCallerScript
+ phone PICNICKER, TIFFANY3, ROUTE_43, ANYTIME, TiffanyPhoneCalleeScript, ANYTIME, TiffanyPhoneCallerScript
+ phone BIRD_KEEPER, VANCE1, ROUTE_44, ANYTIME, VancePhoneCalleeScript, ANYTIME, VancePhoneCallerScript
+ phone FISHER, WILTON1, ROUTE_44, ANYTIME, WiltonPhoneCalleeScript, ANYTIME, WiltonPhoneCallerScript
+ phone BLACKBELT_T, KENJI3, ROUTE_45, ANYTIME, KenjiPhoneCalleeScript, ANYTIME, KenjiPhoneCallerScript
+ phone HIKER, PARRY1, ROUTE_45, ANYTIME, ParryPhoneCalleeScript, ANYTIME, ParryPhoneCallerScript
+ phone PICNICKER, ERIN1, ROUTE_46, ANYTIME, ErinPhoneCalleeScript, ANYTIME, ErinPhoneCallerScript
diff --git a/data/phone/special_calls.asm b/data/phone/special_calls.asm
new file mode 100644
index 00000000..826a5d28
--- /dev/null
+++ b/data/phone/special_calls.asm
@@ -0,0 +1,17 @@
+specialcall: MACRO
+; condition, contact, script
+ dw \1
+ db \2
+ dba \3
+ENDM
+
+SpecialPhoneCallList:
+; entries correspond to SPECIALCALL_* constants
+ specialcall SpecialCallOnlyWhenOutside, PHONECONTACT_ELM, ElmPhoneCallerScript
+ specialcall SpecialCallOnlyWhenOutside, PHONECONTACT_ELM, ElmPhoneCallerScript
+ specialcall SpecialCallOnlyWhenOutside, PHONECONTACT_ELM, ElmPhoneCallerScript
+ specialcall SpecialCallOnlyWhenOutside, PHONECONTACT_ELM, ElmPhoneCallerScript
+ specialcall SpecialCallWhereverYouAre, PHONECONTACT_ELM, ElmPhoneCallerScript
+ specialcall SpecialCallWhereverYouAre, PHONECONTACT_BIKESHOP, BikeShopPhoneCallerScript
+ specialcall SpecialCallWhereverYouAre, PHONECONTACT_MOM, MomPhoneLectureScript
+ specialcall SpecialCallOnlyWhenOutside, PHONECONTACT_ELM, ElmPhoneCallerScript
diff --git a/engine/phone/phone.asm b/engine/phone/phone.asm
new file mode 100644
index 00000000..8ae66def
--- /dev/null
+++ b/engine/phone/phone.asm
@@ -0,0 +1,732 @@
+AddPhoneNumber::
+ call _CheckCellNum
+ jr c, .cant_add
+ call Phone_FindOpenSlot
+ jr nc, .cant_add
+ ld [hl], c
+ xor a
+ ret
+
+.cant_add
+ scf
+ ret
+
+DelCellNum::
+ call _CheckCellNum
+ jr nc, .not_in_list
+ xor a
+ ld [hl], a
+ ret
+
+.not_in_list
+ scf
+ ret
+
+CheckCellNum::
+ jp _CheckCellNum ; useless
+
+_CheckCellNum:
+ 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
+
+Phone_FindOpenSlot:
+ 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:
+ dec hl
+ scf
+ ret
+
+GetRemainingSpaceInPhoneList:
+ xor a
+ ld [wBuffer1], a
+ ld hl, PermanentNumbers
+.loop
+ ld a, [hli]
+ cp -1
+ jr z, .done
+ cp c
+ jr z, .continue
+
+ push bc
+ push hl
+ ld c, a
+ call _CheckCellNum
+ jr c, .permanent
+ ld hl, wBuffer1
+ inc [hl]
+.permanent
+ pop hl
+ pop bc
+
+.continue
+ jr .loop
+
+.done
+ ld a, CONTACT_LIST_SIZE
+ ld hl, wBuffer1
+ sub [hl]
+ ret
+
+INCLUDE "data/phone/permanent_numbers.asm"
+
+FarPlaceString:
+ ldh a, [hROMBank]
+ push af
+ ld a, b
+ rst Bankswitch
+
+ call PlaceString
+
+ pop af
+ rst Bankswitch
+ ret
+
+CheckPhoneCall::
+; 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
+ 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
+
+.timecheck
+ farcall CheckReceiveCallTimer
+ ret
+
+; unused
+ ret
+
+UnusedInitCallReceiveDelay:
+ farcall InitCallReceiveDelay
+ ret
+
+CheckPhoneContactTimeOfDay:
+ push hl
+ push bc
+ push de
+ push af
+
+ farcall CheckTime
+ pop af
+ and ANYTIME
+ and c
+
+ pop de
+ pop bc
+ pop hl
+ ret
+
+ChooseRandomCaller:
+; If no one is available to call, don't return anything.
+ ld a, [wNumAvailableCallers]
+ and a
+ jr z, .NothingToSample
+
+; Store the number of available callers in c.
+ ld c, a
+; Sample a random number between 0 and 31.
+ call Random
+ ldh a, [hRandomAdd]
+ 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
+ ld hl, wAvailableCallers
+ add hl, bc
+ ld a, [hl]
+ scf
+ ret
+
+.NothingToSample:
+ xor a
+ ret
+
+GetAvailableCallers:
+ farcall CheckTime
+ ld a, c
+ ld [wCheckedTime], a
+ ld hl, wNumAvailableCallers
+ ld bc, CONTACT_LIST_SIZE + 1
+ xor a
+ call ByteFill
+ ld de, wPhoneList
+ ld a, CONTACT_LIST_SIZE
+
+.loop
+ ld [wPhoneListIndex], a
+ ld a, [de]
+ and a
+ jr z, .not_good_for_call
+ ld hl, PhoneContacts + PHONE_CONTACT_SCRIPT2_TIME
+ ld bc, PHONE_CONTACT_SIZE
+ call AddNTimes
+ ld a, [wCheckedTime]
+ and [hl]
+ jr z, .not_good_for_call
+ ld bc, PHONE_CONTACT_MAP_GROUP - PHONE_CONTACT_SCRIPT2_TIME
+ add hl, bc
+ ld a, [wMapGroup]
+ cp [hl]
+ jr nz, .different_map
+ inc hl
+ ld a, [wMapNumber]
+ cp [hl]
+ jr z, .not_good_for_call
+.different_map
+ ld a, [wNumAvailableCallers]
+ ld c, a
+ ld b, $0
+ inc a
+ ld [wNumAvailableCallers], a
+ ld hl, wAvailableCallers
+ add hl, bc
+ ld a, [de]
+ ld [hl], a
+.not_good_for_call
+ inc de
+ ld a, [wPhoneListIndex]
+ dec a
+ jr nz, .loop
+ ret
+
+CheckSpecialPhoneCall::
+ 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
+ ld a, [hli]
+ ld e, a
+ push hl
+ call LoadCallerScript
+ pop hl
+ ld de, wCallerContact + PHONE_CONTACT_SCRIPT2_BANK
+ 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:
+ xor a
+ ret
+
+.script
+ pause 30
+ sjump Script_ReceivePhoneCall
+
+.DoSpecialPhoneCall:
+ ld a, [wSpecialPhoneCallID]
+ dec a
+ ld c, a
+ ld b, 0
+ ld hl, SpecialPhoneCallList
+ ld a, 6
+ call AddNTimes
+ ret
+
+SpecialCallOnlyWhenOutside:
+ ld a, [wEnvironment]
+ cp TOWN
+ jr z, .outside
+ cp ROUTE
+ jr z, .outside
+ xor a
+ ret
+
+.outside
+ scf
+ ret
+
+SpecialCallWhereverYouAre:
+ scf
+ ret
+
+Function90199:
+ ; 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
+ 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 [wCurCaller], a
+ ld hl, PhoneContacts
+ ld bc, PHONE_CONTACT_SIZE
+ 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
+ ld a, [wMapGroup]
+ cp [hl]
+ jr nz, .GetPhoneScript
+ ld hl, PHONE_CONTACT_MAP_NUMBER
+ add hl, de
+ ld a, [wMapNumber]
+ cp [hl]
+ jr nz, .GetPhoneScript
+ ld b, BANK(PhoneScript_JustTalkToThem)
+ ld hl, PhoneScript_JustTalkToThem
+ jr .DoPhoneCall
+
+.GetPhoneScript:
+ 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:
+ ld b, BANK(LoadOutOfAreaScript)
+ ld de, LoadOutOfAreaScript
+ call ExecuteCallbackScript
+ ret
+
+.DoPhoneCall:
+ ld a, b
+ ld [wPhoneScriptBank], a
+ ld a, l
+ ld [wPhoneCaller], a
+ ld a, h
+ ld [wPhoneCaller + 1], a
+ ld b, BANK(LoadPhoneScriptBank)
+ ld de, LoadPhoneScriptBank
+ call ExecuteCallbackScript
+ ret
+
+LoadPhoneScriptBank:
+ memcall wPhoneScriptBank
+ return
+
+LoadOutOfAreaScript:
+ scall PhoneOutOfAreaScript
+ return
+
+LoadCallerScript:
+ nop
+ nop
+ ld a, e
+ ld [wCurCaller], a
+ and a
+ jr nz, .actualcaller
+ ld hl, WrongNumber
+ ld a, BANK(WrongNumber)
+ jr .proceed
+
+.actualcaller
+ ld hl, PhoneContacts
+ ld bc, PHONE_CONTACT_SIZE
+ ld a, e
+ call AddNTimes
+ ld a, BANK(PhoneContacts)
+.proceed
+ ld de, wCallerContact
+ ld bc, PHONE_CONTACT_SIZE
+ call FarCopyBytes
+ ret
+
+WrongNumber:
+ db TRAINER_NONE, PHONE_00
+ dba .script
+.script
+ writetext .PhoneWrongNumberText
+ end
+.PhoneWrongNumberText:
+ text_far _PhoneWrongNumberText
+ text_end
+
+Script_ReceivePhoneCall:
+ refreshscreen
+ callasm RingTwice_StartCall
+ memcall wCallerContact + PHONE_CONTACT_SCRIPT2_BANK
+ waitbutton
+ callasm HangUp
+ closetext
+ callasm InitCallReceiveDelay
+ end
+
+Script_SpecialBillCall::
+ callasm .LoadBillScript
+ sjump Script_ReceivePhoneCall
+
+.LoadBillScript:
+ ld e, PHONE_BILL
+ jp LoadCallerScript
+
+LoadElmCallScript:
+ callasm .LoadElmScript
+ pause 30
+ sjump Script_ReceivePhoneCall
+
+.LoadElmScript:
+ ld e, PHONE_ELM
+ jp LoadCallerScript
+
+RingTwice_StartCall:
+ call .Ring
+; fall through (rings a second time)
+.Ring:
+ call Phone_StartRinging
+ call Phone_Wait20Frames
+ call Phone_CallerTextboxWithName
+ call Phone_Wait20Frames
+ call Phone_CallerTextbox
+ call Phone_Wait20Frames
+ call Phone_CallerTextboxWithName
+ ret
+
+Phone_CallerTextboxWithName:
+ ld a, [wCurCaller]
+ ld b, a
+ call Function90363
+ ret
+
+PhoneCall::
+ ld a, b
+ ld [wPhoneScriptBank], a
+ ld a, e
+ ld [wPhoneCaller], a
+ ld a, d
+ ld [wPhoneCaller + 1], a
+ call Phone_Ring
+; fall through (rings a second time)
+Phone_Ring:
+ call Phone_StartRinging
+ call Phone_Wait20Frames
+ call Phone_CallerTextboxWithName2
+ call Phone_Wait20Frames
+ call Phone_CallerTextbox
+ call Phone_Wait20Frames
+ call Phone_CallerTextboxWithName2
+ ret
+
+Phone_CallerTextboxWithName2:
+ call Phone_CallerTextbox
+ hlcoord 1, 2
+ ld [hl], "☎"
+ inc hl
+ inc hl
+ ld a, [wPhoneScriptBank]
+ ld b, a
+ ld a, [wPhoneCaller]
+ ld e, a
+ ld a, [wPhoneCaller + 1]
+ ld d, a
+ call FarPlaceString
+ ret
+
+Phone_NoSignal:
+ ld de, SFX_NO_SIGNAL
+ call PlaySFX
+ jr Phone_CallEnd
+
+HangUp::
+ 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
+
+Function90316:
+ ld de, SFX_SHUT_DOWN_PC
+ call PlaySFX
+ ret
+
+HangUp_Beep:
+ ld hl, PhoneClickText
+ call PrintText
+ ld de, SFX_HANG_UP
+ call PlaySFX
+ ret
+
+PhoneClickText:
+ text_far _PhoneClickText
+ text_end
+
+HangUp_BoopOn:
+ ld hl, PhoneEllipseText
+ call PrintText
+ ret
+
+PhoneEllipseText:
+ text_far _PhoneEllipseText
+ text_end
+
+HangUp_BoopOff:
+ call SpeechTextbox
+ ret
+
+Phone_StartRinging:
+ call WaitSFX
+ ld de, SFX_CALL
+ call PlaySFX
+ call Phone_CallerTextbox
+ call UpdateSprites
+ farcall PhoneRing_CopyTilemapAtOnce
+ ret
+
+HangUp_Wait20Frames:
+ jr Phone_Wait20Frames
+
+Phone_Wait20Frames:
+ ld c, 20
+ call DelayFrames
+ farcall PhoneRing_CopyTilemapAtOnce
+ ret
+
+Function90363:
+ push bc
+ call Phone_CallerTextbox
+ hlcoord 1, 1
+ ld [hl], "☎"
+ inc hl
+ inc hl
+ ld d, h
+ ld e, l
+ pop bc
+ call Function90380
+ ret
+
+Phone_CallerTextbox:
+ hlcoord 0, 0
+ ld b, 2
+ ld c, SCREEN_WIDTH - 2
+ call Textbox
+ ret
+
+Function90380:
+ ld h, d
+ ld l, e
+ ld a, b
+ call GetCallerTrainerClass
+ call GetCallerName
+ ret
+
+CheckCanDeletePhoneNumber:
+ ld a, c
+ call GetCallerTrainerClass
+ ld a, c
+ ; and a
+ ret nz
+ ld a, b
+ cp PHONECONTACT_MOM
+ ret z
+ cp PHONECONTACT_ELM
+ ret z
+ ld c, $1
+ ret
+
+GetCallerTrainerClass:
+ push hl
+ ld hl, PhoneContacts + PHONE_CONTACT_TRAINER_CLASS
+ ld bc, PHONE_CONTACT_SIZE
+ call AddNTimes
+ ld a, [hli]
+ ld b, [hl]
+ ld c, a
+ pop hl
+ ret
+
+GetCallerName:
+ 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:
+ push hl
+ ld c, b
+ ld b, 0
+ ld hl, NonTrainerCallerNames
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld e, a
+ ld d, [hl]
+ pop hl
+ call PlaceString
+ ld a, ":"
+ ld [bc], a
+ ret
+
+INCLUDE "data/phone/non_trainer_names.asm"
+
+Phone_GetTrainerName:
+ push hl
+ push bc
+ farcall GetTrainerName
+ pop bc
+ pop hl
+ ret
+
+Phone_GetTrainerClassName:
+ push hl
+ push bc
+ farcall GetTrainerClassName
+ pop bc
+ pop hl
+ ret
+
+GetCallerLocation:
+ ld a, [wCurCaller]
+ call GetCallerTrainerClass
+ ld d, c
+ ld e, b
+ push de
+ ld a, [wCurCaller]
+ ld hl, PhoneContacts + PHONE_CONTACT_MAP_GROUP
+ ld bc, PHONE_CONTACT_SIZE
+ call AddNTimes
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ push bc
+ call GetWorldMapLocation
+ ld e, a
+ farcall GetLandmarkName
+ pop bc
+ pop de
+ ret
+
+INCLUDE "data/phone/phone_contacts.asm"
+
+INCLUDE "data/phone/special_calls.asm"
+
+PhoneOutOfAreaScript:
+ writetext PhoneOutOfAreaText
+ end
+
+PhoneOutOfAreaText:
+ text_far _PhoneOutOfAreaText
+ text_end
+
+PhoneScript_JustTalkToThem:
+ writetext PhoneJustTalkToThemText
+ end
+
+PhoneJustTalkToThemText:
+ text_far _PhoneJustTalkToThemText
+ text_end
+
+PhoneThankYouTextScript:
+ writetext PhoneThankYouText
+ end
+
+PhoneThankYouText:
+ text_far _PhoneThankYouText
+ text_end
diff --git a/macros/wram.asm b/macros/wram.asm
index 1e7ab534..39f6ebad 100755
--- a/macros/wram.asm
+++ b/macros/wram.asm
@@ -387,9 +387,3 @@ battle_bg_effect: MACRO
\1_02:: ds 1
\1_03:: ds 1
endm
-
-warp_struct: MACRO
-\1WarpNumber:: ds 1
-\1MapGroup:: ds 1
-\1MapNumber:: ds 1
-ENDM
diff --git a/main.asm b/main.asm
index c2e2d3e0..7214f87d 100644
--- a/main.asm
+++ b/main.asm
@@ -495,7 +495,9 @@ _HallOfFamePC::
SECTION "bank23", ROMX
SaveMenu_CopyTilemapAtOnce::
- dr $8c000, $8c17a
+ dr $8c000, $8c0b9
+PhoneRing_CopyTilemapAtOnce::
+ dr $8c0b9, $8c17a
ResetClock_::
dr $8c17a, $8c310
DeleteSaveData_::
@@ -584,24 +586,7 @@ ENDC
SECTION "bank24", ROMX
-AddPhoneNumber::
- dr $90000, $9000f
-DelCellNum::
- dr $9000f, $90019
-CheckCellNum::
- dr $90019, $90074
-CheckPhoneCall::
- dr $90074, $9013e
-CheckSpecialPhoneCall::
- dr $9013e, $9025d
-Script_SpecialBillCall::
- dr $9025d, $90298
-PhoneCall::
- dr $90298, $902df
-HangUp::
- dr $902df, $90414
-GetCallerLocation::
- dr $90414, $90641
+INCLUDE "engine/phone/phone.asm"
InitClock::
dr $90641, $908dc
SetDayOfWeek::
@@ -938,7 +923,134 @@ INCLUDE "data/text/battle.asm"
SECTION "bank41", ROMX
- dr $104000, $10614d
+UnusedPhoneScript::
+ dr $104000, $104004
+MomPhoneCalleeScript::
+ dr $104004, $104124
+MomPhoneLectureScript::
+ dr $104124, $104137
+BillPhoneCalleeScript::
+ dr $104137, $104172
+BillPhoneCallerScript::
+ dr $104172, $104177
+ElmPhoneCalleeScript::
+ dr $104177, $1041e1
+ElmPhoneCallerScript::
+ dr $1041e1, $10422a
+JackPhoneCalleeScript::
+ dr $10422a, $104234
+JackPhoneCallerScript::
+ dr $104234, $104256
+BeverlyPhoneCalleeScript::
+ dr $104256, $104260
+BeverlyPhoneCallerScript::
+ dr $104260, $104282
+HueyPhoneCalleeScript::
+ dr $104282, $10428c
+HueyPhoneCallerScript::
+ dr $10428c, $1042a7
+GavenPhoneCalleeScript::
+ dr $1042a7, $1042b1
+GavenPhoneCallerScript::
+ dr $1042b1, $1042d3
+BethPhoneCalleeScript::
+ dr $1042d3, $1042dd
+BethPhoneCallerScript::
+ dr $1042dd, $1042ff
+JosePhoneCalleeScript::
+ dr $1042ff, $104309
+JosePhoneCallerScript::
+ dr $104309, $104332
+ReenaPhoneCalleeScript::
+ dr $104332, $10433c
+ReenaPhoneCallerScript::
+ dr $10433c, $10435e
+JoeyPhoneCalleeScript::
+ dr $10435e, $104368
+JoeyPhoneCallerScript::
+ dr $104368, $104390
+WadePhoneCalleeScript::
+ dr $104390, $1043b5
+WadePhoneCallerScript::
+ dr $1043b5, $1043f8
+RalphPhoneCalleeScript::
+ dr $1043f8, $104402
+RalphPhoneCallerScript::
+ dr $104402, $104446
+LizPhoneCalleeScript::
+ dr $104446, $104450
+LizPhoneCallerScript::
+ dr $104450, $104478
+AnthonyPhoneCalleeScript::
+ dr $104478, $104482
+AnthonyPhoneCallerScript::
+ dr $104482, $1044c4
+ToddPhoneCalleeScript::
+ dr $1044c4, $1044ce
+ToddPhoneCallerScript::
+ dr $1044ce, $1044f6
+GinaPhoneCalleeScript::
+ dr $1044f6, $104506
+GinaPhoneCallerScript::
+ dr $104506, $104534
+IrwinPhoneCalleeScript::
+ dr $104534, $104544
+IrwinPhoneCallerScript::
+ dr $104544, $10456c
+ArniePhoneCalleeScript::
+ dr $10456c, $104576
+ArniePhoneCallerScript::
+ dr $104576, $1045b2
+AlanPhoneCalleeScript::
+ dr $1045b2, $1045bc
+AlanPhoneCallerScript::
+ dr $1045bc, $1045de
+DanaPhoneCalleeScript::
+ dr $1045de, $1045e8
+DanaPhoneCallerScript::
+ dr $1045e8, $10460a
+ChadPhoneCalleeScript::
+ dr $10460a, $104614
+ChadPhoneCallerScript::
+ dr $104614, $104650
+DerekPhoneCalleeScript::
+ dr $104650, $104675
+DerekPhoneCallerScript::
+ dr $104675, $1046b2
+ChrisPhoneCalleeScript::
+ dr $1046b2, $1046bc
+ChrisPhoneCallerScript::
+ dr $1046bc, $1046de
+BrentPhoneCalleeScript::
+ dr $1046de, $1046e8
+BrentPhoneCallerScript::
+ dr $1046e8, $104711
+TiffanyPhoneCalleeScript::
+ dr $104711, $10471b
+TiffanyPhoneCallerScript::
+ dr $10471b, $104744
+VancePhoneCalleeScript::
+ dr $104744, $10474e
+VancePhoneCallerScript::
+ dr $10474e, $104770
+WiltonPhoneCalleeScript::
+ dr $104770, $10477a
+WiltonPhoneCallerScript::
+ dr $10477a, $1047b8
+KenjiPhoneCalleeScript::
+ dr $1047b8, $1047c2
+KenjiPhoneCallerScript::
+ dr $1047c2, $1047e4
+ParryPhoneCalleeScript::
+ dr $1047e4, $1047ee
+ParryPhoneCallerScript::
+ dr $1047ee, $10482a
+ErinPhoneCalleeScript::
+ dr $10482a, $104834
+ErinPhoneCallerScript::
+ dr $104834, $104a80
+BikeShopPhoneCallerScript::
+ dr $104a80, $10614d
SECTION "bank6c", ROMX
diff --git a/wram.asm b/wram.asm
index 9260211f..f6ae9477 100644
--- a/wram.asm
+++ b/wram.asm
@@ -4,6 +4,7 @@ INCLUDE "macros/wram.asm"
INCLUDE "vram.asm"
+
SECTION "Audio RAM", WRAM0
wMusic::
@@ -183,6 +184,7 @@ wc1fd:: ds 1 ; c1fd
wc1fe:: ds 1 ; c1fe
wc1ff:: ds 1 ; c1ff
+
SECTION "GBC Palettes", WRAM0
; eight 4-color palettes each
@@ -191,6 +193,7 @@ wOBPals1:: ds 8 palettes ; c240
wBGPals2:: ds 8 palettes ; c280
wOBPals2:: ds 8 palettes ; c2c0
+
SECTION "Sprites", WRAM0
wVirtualOAM:: ; c300
@@ -899,6 +902,7 @@ ENDU
ENDU ; cc20
+
SECTION "Video", WRAM0
; wBGMapBuffer
@@ -1258,6 +1262,11 @@ wMartItem9BCD:: ds 3
wMartItem10BCD:: ds 3
NEXTU ; ceed
+; phone call data
+wPhoneScriptBank:: db
+wPhoneCaller:: dw
+
+NEXTU ; ceed
; radio data
wCurRadioLine:: db
wNextRadioLine:: db
@@ -1416,6 +1425,18 @@ NEXTU ; cf29
wJumpStdScriptBuffer:: ds 3
NEXTU ; cf29
+; phone script data
+wCheckedTime:: db
+wPhoneListIndex:: db
+wNumAvailableCallers:: db
+wAvailableCallers:: ds CONTACT_LIST_SIZE
+
+NEXTU ; cf29
+; phone caller contact
+ ds 1
+wCallerContact:: ds PHONE_CONTACT_SIZE
+
+NEXTU ; cf29
; backup menu data
ds 7
wMenuCursorBufferBackup:: db
@@ -1543,6 +1564,7 @@ wcffc:: ds 1 ; cffc
wcffd:: ds 1 ; cffd
wUnusedCFFE:: dw ; cffe
+
SECTION "WRAM 1", WRAMX
wd000:: ds 1 ; d000
@@ -1932,7 +1954,9 @@ wOptions2:: ; d19e
wOptionsEnd::
+
SECTION "Game Data", WRAMX
+
wGameData::
wPlayerData::
wPlayerData1::
@@ -2564,49 +2588,23 @@ wd9b9:: ds 1 ; d9b9
wd9ba:: ds 1 ; d9ba
wd9bb:: ds 1 ; d9bb
wd9bc:: ds 1 ; d9bc
+
wStepCount:: db ; d9bd
wPoisonStepCount:: db ; d9be
ds 2
wHappinessStepCount:: db ; d9c1
ds 1
+
wParkBallsRemaining::
wSafariBallsRemaining:: db ; d9c3
wSafariTimeRemaining:: dw ; d9c4
-wd9c6:: ds 1 ; d9c6
-wd9c7:: ds 1 ; d9c7
-wd9c8:: ds 1 ; d9c8
-wd9c9:: ds 1 ; d9c9
-wd9ca:: ds 1 ; d9ca
-wd9cb:: ds 1 ; d9cb
-wd9cc:: ds 1 ; d9cc
-wd9cd:: ds 1 ; d9cd
-wd9ce:: ds 1 ; d9ce
-wd9cf:: ds 1 ; d9cf
-wd9d0:: ds 1 ; d9d0
-wd9d1:: ds 1 ; d9d1
-wd9d2:: ds 1 ; d9d2
-wd9d3:: ds 1 ; d9d3
-wd9d4:: ds 1 ; d9d4
-wd9d5:: ds 1 ; d9d5
-wd9d6:: ds 1 ; d9d6
-wd9d7:: ds 1 ; d9d7
-wd9d8:: ds 1 ; d9d8
-wd9d9:: ds 1 ; d9d9
-wd9da:: ds 1 ; d9da
-wd9db:: ds 1 ; d9db
-wd9dc:: ds 1 ; d9dc
-wd9dd:: ds 1 ; d9dd
-wd9de:: ds 1 ; d9de
-wd9df:: ds 1 ; d9df
-wd9e0:: ds 1 ; d9e0
-wd9e1:: ds 1 ; d9e1
-wd9e2:: ds 1 ; d9e2
-wd9e3:: ds 1 ; d9e3
-wd9e4:: ds 1 ; d9e4
-wd9e5:: ds 1 ; d9e5
-wd9e6:: ds 1 ; d9e6
+
+wPhoneList:: ds CONTACT_LIST_SIZE ; d9c6
+; d9d0
+ ds 23
+
wLuckyNumberShowFlag:: ds 1 ; d9e7
-wd9e8:: ds 1 ; d9e8
+ ds 1
wLuckyIDNumber:: dw ; d9e9
wRepelEffect:: db ; If a Repel is in use, it contains the nr of steps it's still active
@@ -2614,32 +2612,36 @@ wBikeStep:: dw
wPlayerData3End::
wPlayerDataEnd::
-
wCurMapData::
wVisitedSpawns:: ds 4 ; flag_array NUM_SPAWNS ; d9ee
- warp_struct wDig ; d9f2
+wDigWarpNumber:: db ; d9f2
+wDigMapGroup:: db ; d9f3
+wDigMapNumber:: db ; d9f4
+; used on maps like second floor pokécenter, which are reused, so we know which
+; map to return to
wBackupWarpNumber:: db ; d9f5
wBackupMapGroup:: db ; d9f6
wBackupMapNumber:: db ; d9f7
-wd9f8:: ds 1 ; d9f8
-wd9f9:: ds 1 ; d9f9
-wd9fa:: ds 1 ; d9fa
+ ds 3
+
wLastSpawnMapGroup:: db
wLastSpawnMapNumber:: db
+
wd9fd:: ds 1 ; d9fd
wd9fe:: ds 1 ; d9fe
-wWarpNumber:: ds 1 ; d9ff
-wMapGroup:: ds 1 ; da00
-wMapNumber:: ds 1 ; da01
-wYCoord:: ds 1 ; da02
-wXCoord:: ds 1 ; da03
+wWarpNumber:: db ; d9ff
+wMapGroup:: db ; da00
+wMapNumber:: db ; da01
+wYCoord:: db ; da02
+wXCoord:: db ; da03
wScreenSave:: ds SCREEN_META_WIDTH * SCREEN_META_HEIGHT
wCurMapDataEnd::
+
SECTION "Party", WRAMX
wPokemonData::
@@ -2793,6 +2795,7 @@ ENDU ; df01
wPokemonDataEnd::
wGameDataEnd::
+
SECTION "Stack", WRAMX
wStackTop::