Skip to content

Commit

Permalink
Implement simpler conditional branches for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Mar 26, 2024
1 parent 8a1dfd3 commit 381f61a
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 353 deletions.
37 changes: 26 additions & 11 deletions src/dialog.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.INCLUDE "device.inc"
.INCLUDE "devices/dialog.inc"
.INCLUDE "dialog.inc"
.INCLUDE "flag.inc"
.INCLUDE "hud.inc"
.INCLUDE "joypad.inc"
.INCLUDE "macros.inc"
Expand Down Expand Up @@ -69,8 +70,7 @@
.IMPORT DataA_Dialog_MermaidHut4Florist_sDialog
.IMPORT DataA_Dialog_MermaidHut5Marie_sDialog
.IMPORT DataA_Dialog_MermaidHut5Nora_sDialog
.IMPORT DataA_Dialog_MermaidSpringAlex1_sDialog
.IMPORT DataA_Dialog_MermaidSpringAlex2_sDialog
.IMPORT DataA_Dialog_MermaidSpringAlex_sDialog
.IMPORT DataA_Dialog_MermaidSpringSign_sDialog
.IMPORT DataA_Dialog_MermaidVillageAlex_sDialog
.IMPORT DataA_Dialog_MermaidVillageBruno_sDialog
Expand Down Expand Up @@ -146,6 +146,7 @@
.IMPORT Func_AllocOneObject
.IMPORT Func_BufferPpuTransfer
.IMPORT Func_ClearRestOfOamAndProcessFrame
.IMPORT Func_IsFlagSet
.IMPORT Func_SetFlag
.IMPORT Func_TryPushAvatarHorz
.IMPORT Func_Window_GetRowPpuAddr
Expand Down Expand Up @@ -264,7 +265,6 @@ Zp_DialogTextCol_u8: .res 1
;;; dialog question, and is set to false ($00) whenever the player chooses
;;; "no". Dynamic dialog functions can read this variable to react to the
;;; player's choice.
.EXPORTZP Zp_DialogAnsweredYes_bool
Zp_DialogAnsweredYes_bool: .res 1

;;; A pointer to the next sDialog entry to execute.
Expand Down Expand Up @@ -474,8 +474,7 @@ _Finish:
d_entry t, MermaidHut4Florist, DataA_Dialog_MermaidHut4Florist_sDialog
d_entry t, MermaidHut5Marie, DataA_Dialog_MermaidHut5Marie_sDialog
d_entry t, MermaidHut5Nora, DataA_Dialog_MermaidHut5Nora_sDialog
d_entry t, MermaidSpringAlex1, DataA_Dialog_MermaidSpringAlex1_sDialog
d_entry t, MermaidSpringAlex2, DataA_Dialog_MermaidSpringAlex2_sDialog
d_entry t, MermaidSpringAlex, DataA_Dialog_MermaidSpringAlex_sDialog
d_entry t, MermaidSpringSign, DataA_Dialog_MermaidSpringSign_sDialog
d_entry t, MermaidVillageAlex, DataA_Dialog_MermaidVillageAlex_sDialog
d_entry t, MermaidVillageBruno, DataA_Dialog_MermaidVillageBruno_sDialog
Expand Down Expand Up @@ -788,7 +787,7 @@ _ReadPortraitByte:
cmp #ePortrait::NUM_VALUES
blt _SetPortrait
_DialogFunction:
tax ; entry kind (kDialogEntryCall or kDialogEntryFunc)
tax ; entry kind (kDialogEntryBranch/Call/Func/Goto)
lda (Zp_Next_sDialog_ptr), y
sta T0
iny
Expand All @@ -799,18 +798,34 @@ _DialogFunction:
beq @entryGoto
cpx #kDialogEntryFunc
beq @entryFunc
@entryCall:
jsr _UpdateDialogPointer
jsr _CallT1T0
jmp _ReadPortraitByte
cpx #kDialogEntryCall
beq @entryCall
@entryBranch:
lda (Zp_Next_sDialog_ptr), y
tax ; eFlag value to branch on
iny
jsr _UpdateDialogPointer ; preserves X and T0+
txa ; eFlag value to branch on
.assert eFlag::None = 0, error
bne @checkFlag
bit Zp_DialogAnsweredYes_bool
bmi @entryGoto
bpl _ReadPortraitByte ; unconditional
@checkFlag:
jsr Func_IsFlagSet ; preserves T0+, returns Z
beq _ReadPortraitByte
@entryGoto:
ldya T1T0
bmi @setNext ; unconditional (enforced by dlg_Goto macro)
bmi @setNext ; unconditional (enforced by dlg_Goto/dlg_If* macros)
@entryFunc:
jsr _CallT1T0 ; returns YA
@setNext:
stya Zp_Next_sDialog_ptr
jmp _ReadPortraitByte
@entryCall:
jsr _UpdateDialogPointer ; preserves T0+
jsr _CallT1T0
jmp _ReadPortraitByte
_CallT1T0:
jmp (T1T0)
_StartCutscene:
Expand Down
27 changes: 23 additions & 4 deletions src/dialog.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@

;;; Special constants used in place of an ePortrait value for doing dialog
;;; control flow.
.ASSERT $fa >= ePortrait::NUM_VALUES, error
.ASSERT $f9 >= ePortrait::NUM_VALUES, error
kDialogEntryBranch = $f9 ; conditionally jumps to a sDialog, else continues
kDialogEntryCall = $fa ; calls a function, then continues the sDialog
kDialogEntryFunc = $fb ; calls a function that returns next sDialog in YA
kDialogEntryGoto = $fc ; jumps to the specified sDialog
Expand Down Expand Up @@ -112,8 +113,7 @@ kDialogEntryCutscene = $ff ; ends the dialog and starts a new cutscene
MermaidHut4Florist
MermaidHut5Marie
MermaidHut5Nora
MermaidSpringAlex1
MermaidSpringAlex2
MermaidSpringAlex
MermaidSpringSign
MermaidVillageAlex
MermaidVillageBruno
Expand Down Expand Up @@ -209,6 +209,25 @@ kDialogTextYesNo = $ff
.addr LABEL
.ENDMACRO

;;; Expands to a sDialog entry that jumps to another sDialog entry if the
;;; specified flag is set, and otherwise continues to the next entry.
.MACRO dlg_IfSet FLAG, LABEL
.assert LABEL >= $8000, error
.byte kDialogEntryBranch
.addr LABEL
.byte eFlag::FLAG
.ENDMACRO

;;; Expands to a sDialog entry that jumps to another sDialog entry if the
;;; player answered "YES" to the previous YES/NO dialog question, and otherwise
;;; continues to the next entry.
.MACRO dlg_IfYes LABEL
.assert LABEL >= $8000, error
.byte kDialogEntryBranch
.addr LABEL
.byte 0
.ENDMACRO

;;; Expands to a sDialog entry that calls a dynamic dialog function.
.MACRO dlg_Func LABEL
.assert LABEL >= $8000, error
Expand All @@ -226,7 +245,7 @@ kDialogTextYesNo = $ff
;;; Expands to a sDialog entry that adds a quest marker before continuing.
.MACRO dlg_Quest FLAG
.byte kDialogEntryQuest
.byte FLAG
.byte eFlag::FLAG
.ENDMACRO

;;; Expands to a sDialog entry indicating the end of the dialog.
Expand Down
56 changes: 14 additions & 42 deletions src/rooms/city_building2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

.IMPORT DataA_Room_Building_sTileset
.IMPORT Data_Empty_sActor_arr
.IMPORT Data_Empty_sDialog
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeLeftByA
.IMPORT FuncA_Objects_SetShapePosToPlatformTopLeft
Expand All @@ -39,7 +38,6 @@
.IMPORT Func_SetFlag
.IMPORT Ppu_ChrObjCity
.IMPORT Sram_ProgressFlags_arr
.IMPORTZP Zp_DialogAnsweredYes_bool
.IMPORTZP Zp_FrameCounter_u8
.IMPORTZP Zp_RoomState

Expand Down Expand Up @@ -204,53 +202,27 @@ _Devices_sDevice_arr:

.EXPORT DataA_Dialog_CityBuilding2Screen_sDialog
.PROC DataA_Dialog_CityBuilding2Screen_sDialog
dlg_Func _InitialFunc
_InitialFunc:
;; If the eastern door in CityCenter has already been unlocked, display a
;; message to that effect.
flag_bit Sram_ProgressFlags_arr, eFlag::CityCenterDoorUnlocked
beq @doorStillLocked
;; For safety, connect the key generator (even though you shouldn't
;; normally be able to unlock the door without connecting the key generator
;; first).
ldx #eFlag::CityCenterKeygenConnected ; param: flag
jsr Func_SetFlag
ldya #_Unlocked_sDialog
rts
@doorStillLocked:
;; Otherwise, if the key generator has already been connected to the
;; western semaphore, display a message to that effect.
flag_bit Sram_ProgressFlags_arr, eFlag::CityCenterKeygenConnected
beq @notYetConnected
ldya #_AlreadyConnected_sDialog
rts
;; Otherwise, prompt the player to connect the key generator.
@notYetConnected:
ldya #_Unconnected_sDialog
rts
_Unconnected_sDialog:
dlg_IfSet CityCenterDoorUnlocked, _Unlocked_sDialog
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Locked_u8_arr
dlg_IfSet CityCenterKeygenConnected, _Connected_sDialog
_Unconnected_sDialog:
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Question_u8_arr
dlg_Func _QuestionFunc
_QuestionFunc:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #Data_Empty_sDialog
rts
@yes:
ldx #eFlag::CityCenterKeygenConnected ; param: flag
jsr Func_SetFlag
ldya #_NowConnected_sDialog
rts
_AlreadyConnected_sDialog:
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Locked_u8_arr
_NowConnected_sDialog:
dlg_IfYes _Connected_sDialog
dlg_Done
_Connected_sDialog:
dlg_Call _ConnectKeygen
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Connected_u8_arr
dlg_Done
_Unlocked_sDialog:
;; For safety, connect the key generator (even though you shouldn't
;; normally be able to unlock the door without connecting the key generator
;; first).
dlg_Call _ConnectKeygen
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Unlocked_u8_arr
dlg_Done
_ConnectKeygen:
ldx #eFlag::CityCenterKeygenConnected ; param: flag
jmp Func_SetFlag
.ENDPROC

;;;=========================================================================;;;
Expand Down
11 changes: 1 addition & 10 deletions src/rooms/city_building6.asm
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,7 @@ _Devices_sDevice_arr:

.EXPORT DataA_Dialog_CityBuilding6Screen_sDialog
.PROC DataA_Dialog_CityBuilding6Screen_sDialog
dlg_Func _InitialFunc
_InitialFunc:
;; If the door has already been unlocked, display a message to that effect.
flag_bit Sram_ProgressFlags_arr, eFlag::CityCenterDoorUnlocked
beq @doorStillLocked
ldya #_Unlocked_sDialog
rts
@doorStillLocked:
ldya #_Locked_sDialog
rts
dlg_IfSet CityCenterDoorUnlocked, _Unlocked_sDialog
_Locked_sDialog:
dlg_Text Screen, DataA_Text0_CityBuilding2Screen_Locked_u8_arr
dlg_Done
Expand Down
15 changes: 5 additions & 10 deletions src/rooms/city_outskirts.asm
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,10 @@ _Look_sCutscene:

.EXPORT DataA_Dialog_CityOutskirtsAlex1_sDialog
.PROC DataA_Dialog_CityOutskirtsAlex1_sDialog
dlg_Func @func
@func:
flag_bit Sram_ProgressFlags_arr, eFlag::CityOutskirtsTalkedToAlex
bne @meetAtHotSpring
ldya #_YouMadeIt_sDialog
rts
@meetAtHotSpring:
ldya #DataA_Dialog_CityOutskirtsMeetAtHotSpring_sDialog
rts
.linecont +
dlg_IfSet CityOutskirtsTalkedToAlex, \
DataA_Dialog_CityOutskirtsMeetAtHotSpring_sDialog
.linecont -
_YouMadeIt_sDialog:
dlg_Text ChildAlex, DataA_Text1_CityOutskirtsAlex_Part1_u8_arr
dlg_Text ChildAlex, DataA_Text1_CityOutskirtsAlex_Part2_u8_arr
Expand All @@ -398,7 +393,7 @@ _YouMadeIt_sDialog:
dlg_Text ChildAlex, DataA_Text1_CityOutskirtsAlex_Part4_u8_arr
dlg_Text ChildAlex, DataA_Text1_CityOutskirtsAlex_Part5_u8_arr
dlg_Call _MakeAlexFaceAnna
dlg_Quest eFlag::CityOutskirtsTalkedToAlex
dlg_Quest CityOutskirtsTalkedToAlex
dlg_Goto DataA_Dialog_CityOutskirtsMeetAtHotSpring_sDialog
_MakeAlexFaceAnna:
lda #$00
Expand Down
72 changes: 18 additions & 54 deletions src/rooms/core_boss.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
.INCLUDE "../scroll.inc"

.IMPORT DataA_Room_Core_sTileset
.IMPORT Data_Empty_sDialog
.IMPORT FuncA_Machine_BlasterHorzTryAct
.IMPORT FuncA_Machine_BlasterTickMirrors
.IMPORT FuncA_Machine_BlasterWriteRegMirrors
Expand Down Expand Up @@ -138,7 +137,6 @@
.IMPORTZP Zp_BreakerBeingActivated_eFlag
.IMPORTZP Zp_Camera_bScroll
.IMPORTZP Zp_Current_sMachine_ptr
.IMPORTZP Zp_DialogAnsweredYes_bool
.IMPORTZP Zp_FrameCounter_u8
.IMPORTZP Zp_Next_eCutscene
.IMPORTZP Zp_PointX_i16
Expand Down Expand Up @@ -2099,43 +2097,26 @@ _MakeFinalTerminalAppear:
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_Part1_u8_arr
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_Part2_u8_arr
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_Demand_u8_arr
dlg_Func _DemandFunc
_DemandFunc:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #_PreparedToFight_sDialog
rts
@yes:
ldya #_HandItOver_sDialog
rts
_HandItOver_sDialog:
dlg_IfYes _HandItOverQuestion_sDialog
_PreparedToFightQuestion_sDialog:
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_PreparedToFight_u8_arr
dlg_IfYes _BeginFight_sDialog
_HandItOverQuestion_sDialog:
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_HandItOver_u8_arr
dlg_Func _HandItOverFunc
_HandItOverFunc:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #_PreparedToFight_sDialog
rts
@yes:
dlg_IfYes _TossRemote_sDialog
dlg_Goto _PreparedToFightQuestion_sDialog
_BeginFight_sDialog:
dlg_Call _LockScrolling
dlg_Done
_TossRemote_sDialog:
dlg_Call _TossRemote
dlg_Done
_TossRemote:
lda #eGrontaPhase::GettingRemote
sta Zp_RoomState + sState::Current_eGrontaPhase
bne _EndDialogFunc ; unconditional
_PreparedToFight_sDialog:
dlg_Text OrcGronta, DataA_Text1_CoreBossGrontaIntro_PreparedToFight_u8_arr
dlg_Func _PreparedToFightFunc
_PreparedToFightFunc:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #_HandItOver_sDialog
rts
@yes:
_EndDialogFunc:
_LockScrolling:
lda #bScroll::LockHorz
sta Zp_Camera_bScroll
ldya #Data_Empty_sDialog
rts
.ENDPROC

Expand All @@ -2159,28 +2140,11 @@ _EndDialogFunc:
dlg_Text Screen, DataA_Text1_CoreBossScreen_Intro_u8_arr
_ReactivateQuestion_sDialog:
dlg_Text Screen, DataA_Text1_CoreBossScreen_Reactivate_u8_arr
dlg_Func @func
@func:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #_SelfDestructQuestion_sDialog
rts
@yes:
ldya #_ReactivateCutscene_sDialog
rts
dlg_IfYes _ReactivateCutscene_sDialog
_SelfDestructQuestion_sDialog:
dlg_Text Screen, DataA_Text1_CoreBossScreen_SelfDestruct_u8_arr
dlg_Func @func
@func:
bit Zp_DialogAnsweredYes_bool
bmi @yes
@no:
ldya #_ReactivateQuestion_sDialog
rts
@yes:
ldya #_SelfDestructCutscene_sDialog
rts
dlg_IfYes _SelfDestructCutscene_sDialog
dlg_Goto _ReactivateQuestion_sDialog
_ReactivateCutscene_sDialog:
dlg_Cutscene eCutscene::CoreBossFinaleReactivate
_SelfDestructCutscene_sDialog:
Expand Down
Loading

0 comments on commit 381f61a

Please sign in to comment.