diff --git a/src/actor.asm b/src/actor.asm index 3fcc49b..7ee2752 100644 --- a/src/actor.asm +++ b/src/actor.asm @@ -26,6 +26,7 @@ .INCLUDE "macros.inc" .INCLUDE "ppu.inc" +.IMPORT FuncA_Actor_TickAllDevices .IMPORT FuncA_Actor_TickBadBat .IMPORT FuncA_Actor_TickBadBeetleHorz .IMPORT FuncA_Actor_TickBadBeetleVert @@ -701,20 +702,20 @@ _NoHit: D_END .ENDPROC -;;; Performs per-frame updates for each actor in the room. -.EXPORT FuncA_Actor_TickAllActors -.PROC FuncA_Actor_TickAllActors +;;; Performs per-frame updates for each device and actor in the room. +.EXPORT FuncA_Actor_TickAllDevicesAndActors +.PROC FuncA_Actor_TickAllDevicesAndActors ldx #kMaxActors - 1 @loop: jsr FuncA_Actor_TickOneActor ; preserves X dex bpl @loop - rts + jmp FuncA_Actor_TickAllDevices .ENDPROC -;;; Performs per-frame updates for each smoke actor in the room. -.EXPORT FuncA_Actor_TickAllSmokeActors -.PROC FuncA_Actor_TickAllSmokeActors +;;; Performs per-frame updates for each device and smoke actor in the room. +.EXPORT FuncA_Actor_TickAllDevicesAndSmokeActors +.PROC FuncA_Actor_TickAllDevicesAndSmokeActors ldx #kMaxActors - 1 @loop: lda Ram_ActorType_eActor_arr, x @@ -724,7 +725,7 @@ _NoHit: @continue: dex bpl @loop - rts + jmp FuncA_Actor_TickAllDevices .ENDPROC ;;; Performs per-frame updates for one actor. diff --git a/src/boss.asm b/src/boss.asm index e3d0225..39f3376 100644 --- a/src/boss.asm +++ b/src/boss.asm @@ -29,9 +29,11 @@ .INCLUDE "room.inc" .INCLUDE "sample.inc" +.IMPORT FuncA_Room_LockDoorDevice .IMPORT FuncA_Room_MachineResetHalt .IMPORT FuncA_Room_PlaySfxBreakerRising .IMPORT FuncA_Room_SpawnUpgradeDevice +.IMPORT FuncA_Room_UnlockDoorDevice .IMPORT Func_DivMod .IMPORT Func_FindEmptyActorSlot .IMPORT Func_GetRandomByte @@ -39,7 +41,6 @@ .IMPORT Func_InitActorSmokeExplosion .IMPORT Func_InitActorSmokeParticle .IMPORT Func_IsFlagSet -.IMPORT Func_LockDoorDevice .IMPORT Func_MarkRoomSafe .IMPORT Func_Noop .IMPORT Func_PlaySfxExplodeBig @@ -49,7 +50,6 @@ .IMPORT Func_SetFlag .IMPORT Func_SetMachineIndex .IMPORT Func_ShakeRoom -.IMPORT Func_UnlockDoorDevice .IMPORT Ram_ActorType_eActor_arr .IMPORT Ram_DeviceAnim_u8_arr .IMPORT Ram_DeviceTarget_byte_arr @@ -114,7 +114,7 @@ Zp_BossPhaseTimer_u8: .res 1 sta Zp_BossPhaseTimer_u8 ;; Lock the door for now. ldx #kBossDoorDeviceIndex ; param: device index - jsr Func_LockDoorDevice + jsr FuncA_Room_LockDoorDevice ;; Check if the boss has been defeated yet. ldy #sBoss::Boss_eFlag lda (Zp_Current_sBoss_ptr), y @@ -160,7 +160,7 @@ _BreakerAlreadyDone: sta Ram_DeviceType_eDevice_arr + kBossBreakerDeviceIndex ;; Unlock the door. ldx #kBossDoorDeviceIndex ; param: device index - jsr Func_UnlockDoorDevice + jsr FuncA_Room_UnlockDoorDevice ;; Set and return the initial phase. lda #eBossPhase::Done sta Zp_Boss_eBossPhase @@ -364,7 +364,7 @@ _FlipBreaker: bne @done ;; Unlock the door. ldx #kBossDoorDeviceIndex ; param: device index - jsr Func_UnlockDoorDevice + jsr FuncA_Room_UnlockDoorDevice ;; Proceed to the next phase. lda #eBossPhase::Done sta Zp_Boss_eBossPhase diff --git a/src/console.asm b/src/console.asm index 6d5a7a3..35e6f41 100644 --- a/src/console.asm +++ b/src/console.asm @@ -36,7 +36,7 @@ .INCLUDE "window.inc" .IMPORT DataA_Console_DiagramBank_u8_arr -.IMPORT FuncA_Actor_TickAllSmokeActors +.IMPORT FuncA_Actor_TickAllDevicesAndSmokeActors .IMPORT FuncA_Console_DrawFieldCursor .IMPORT FuncA_Console_MoveFieldCursor .IMPORT FuncA_Console_WriteDiagramTransferDataForCurrentMachine @@ -59,7 +59,6 @@ .IMPORT Func_SetLastSpawnPoint .IMPORT Func_SetMachineIndex .IMPORT Func_SetMusicVolumeForCurrentRoom -.IMPORT Func_TickAllDevices .IMPORT Func_Window_GetRowPpuAddr .IMPORT Func_Window_PrepareRowTransfer .IMPORT Func_Window_ScrollDown @@ -272,8 +271,7 @@ _Tick: ;;; Calls per-frame tick functions that should still happen even when the ;;; machine console is open. .PROC FuncM_ConsoleTick - jsr_prga FuncA_Actor_TickAllSmokeActors - jsr Func_TickAllDevices + jsr_prga FuncA_Actor_TickAllDevicesAndSmokeActors jsr_prga FuncA_Machine_ConsoleTickOrExecuteAll jmp_prga FuncA_Room_CallRoomTick .ENDPROC diff --git a/src/cutscene.asm b/src/cutscene.asm index 28e6cdb..6ef37b9 100644 --- a/src/cutscene.asm +++ b/src/cutscene.asm @@ -61,15 +61,14 @@ .IMPORT DataA_Cutscene_TownHouse4BreakerLava_sCutscene .IMPORT DataA_Cutscene_TownOutdoorsGetCaught_sCutscene .IMPORT DataA_Cutscene_TownOutdoorsOrcAttack_sCutscene -.IMPORT FuncA_Actor_TickAllActors -.IMPORT FuncA_Actor_TickAllSmokeActors +.IMPORT FuncA_Actor_TickAllDevicesAndActors +.IMPORT FuncA_Actor_TickAllDevicesAndSmokeActors .IMPORT FuncA_Avatar_RagdollMove .IMPORT FuncA_Room_CallRoomTick .IMPORT FuncM_DrawObjectsForRoomAndProcessFrame .IMPORT FuncM_ScrollTowardsGoal .IMPORT Func_PlaySfxSample .IMPORT Func_ShakeRoom -.IMPORT Func_TickAllDevices .IMPORT Main_Dialog_WithinCutscene .IMPORT Main_Explore_Continue .IMPORT Ram_ActorFlags_bObj_arr @@ -155,8 +154,7 @@ _GameLoop: jsr_prga FuncA_Cutscene_ExecuteAllForks ; returns C, T1T0, and Y bcs _Finish jsr FuncM_ScrollTowardsGoal - jsr_prga FuncA_Actor_TickCutsceneActors - jsr Func_TickAllDevices + jsr_prga FuncA_Actor_TickAllDevicesAndCutsceneActors _MaybeTickRoom: bit Zp_CutsceneFlags_bCutscene .assert bCutscene::RoomTick = bProc::Negative, error @@ -178,13 +176,13 @@ _Finish: .SEGMENT "PRGA_Actor" -;;; Ticks all actors if bCutscene::TickAllActors is set; otherwise, ticks smoke -;;; actors only. -.PROC FuncA_Actor_TickCutsceneActors +;;; Ticks all devices and actors if bCutscene::TickAllActors is set; otherwise, +;;; ticks devices and smoke actors only. +.PROC FuncA_Actor_TickAllDevicesAndCutsceneActors lda Zp_CutsceneFlags_bCutscene and #bCutscene::TickAllActors - jeq FuncA_Actor_TickAllSmokeActors - jmp FuncA_Actor_TickAllActors + jeq FuncA_Actor_TickAllDevicesAndSmokeActors + jmp FuncA_Actor_TickAllDevicesAndActors .ENDPROC ;;;=========================================================================;;; diff --git a/src/device.asm b/src/device.asm index cbaec01..f318a48 100644 --- a/src/device.asm +++ b/src/device.asm @@ -74,12 +74,12 @@ Ram_DeviceAnim_u8_arr: .res kMaxDevices ;;;=========================================================================;;; -.SEGMENT "PRG8" +.SEGMENT "PRGA_Actor" ;;; Decrements the animation counter for each device in the room (if that ;;; counter is nonzero; otherwise, leaves it at zero). -.EXPORT Func_TickAllDevices -.PROC Func_TickAllDevices +.EXPORT FuncA_Actor_TickAllDevices +.PROC FuncA_Actor_TickAllDevices ldx #kMaxDevices - 1 _Loop: ;; If the animation counter is nonzero, decrement it. @@ -100,6 +100,10 @@ _Continue: rts .ENDPROC +;;;=========================================================================;;; + +.SEGMENT "PRG8" + ;;; Returns the index of the device whose block the point stored in ;;; Zp_PointX_i16 and Zp_PointY_i16 is in, if any. ;;; @return N Set if there was no device nearby, cleared otherwise. diff --git a/src/devices/boiler.asm b/src/devices/boiler.asm index 5badae5..bc8538e 100644 --- a/src/devices/boiler.asm +++ b/src/devices/boiler.asm @@ -60,15 +60,13 @@ .EXPORT Func_EmitSteamRightFromPipe .PROC Func_EmitSteamRightFromPipe jsr Func_FindEmptyActorSlot ; preserves Y and T0+, returns C and X - bcs @done + bcs Func_DoNotEmitSteam ; preserves T0+ jsr Func_SetPointToPlatformCenter ; preserves X and T0+ lda #kTileWidthPx * 3 / 2 ; param: offset jsr Func_MovePointRightByA ; preserves X and T0+ jsr Func_SetActorCenterToPoint ; preserves X and T0+ lda #0 ; param: facing dir jmp Func_InitActorProjSteamHorz ; preserves T0+ - @done: - rts .ENDPROC ;;; Given an 8x8 pixel platform covering the end tile of an upward-facing pipe, @@ -78,13 +76,18 @@ .EXPORT Func_EmitSteamUpFromPipe .PROC Func_EmitSteamUpFromPipe jsr Func_FindEmptyActorSlot ; preserves Y and T0+, returns C and X - bcs @done + bcs Func_DoNotEmitSteam ; preserves T0+ jsr Func_SetPointToPlatformCenter ; preserves X and T0+ lda #kTileHeightPx * 3 / 2 ; param: offset jsr Func_MovePointUpByA ; preserves X and T0+ jsr Func_SetActorCenterToPoint ; preserves X and T0+ jmp Func_InitActorProjSteamUp ; preserves T0+ - @done: +.ENDPROC + +;;; No-op function for when a Func_EmitSteam* function above is unable to +;;; allocate an actor slot for the steam. +;;; @preserve T0+ +.PROC Func_DoNotEmitSteam rts .ENDPROC diff --git a/src/devices/door.asm b/src/devices/door.asm index a8d6d51..59b8553 100644 --- a/src/devices/door.asm +++ b/src/devices/door.asm @@ -50,30 +50,32 @@ kPaletteObjDoorway = 0 ;;;=========================================================================;;; -.SEGMENT "PRG8" +.SEGMENT "PRGA_Room" ;;; Locks a door device, if not locked already. ;;; @param X The device index for the (locked or unlocked) door. ;;; @preserve T0+ -.EXPORT Func_LockDoorDevice -.PROC Func_LockDoorDevice - lda #eDevice::Door1Locked - cmp Ram_DeviceType_eDevice_arr, x - beq @done - sta Ram_DeviceType_eDevice_arr, x - lda #kDoorAnimCountdown - sub Ram_DeviceAnim_u8_arr, x - sta Ram_DeviceAnim_u8_arr, x - @done: - rts +.EXPORT FuncA_Room_LockDoorDevice +.PROC FuncA_Room_LockDoorDevice + lda #eDevice::Door1Locked ; param: new device type + .assert eDevice::Door1Unlocked > 0, error + bne FuncA_Room_LockOrUnlockDoorDevice ; unconditional; preserves T0+ .ENDPROC ;;; Unlocks a door device, if not unlocked already. ;;; @param X The device index for the (locked or unlocked) door. ;;; @preserve T0+ -.EXPORT Func_UnlockDoorDevice -.PROC Func_UnlockDoorDevice - lda #eDevice::Door1Unlocked +.EXPORT FuncA_Room_UnlockDoorDevice +.PROC FuncA_Room_UnlockDoorDevice + lda #eDevice::Door1Unlocked ; param: new device type + fall FuncA_Room_LockOrUnlockDoorDevice ; preserves T0+ +.ENDPROC + +;;; Locks or unlocks a door device, if not already in the desired state. +;;; @param A The device type to change to (Door1Locked or Door1Unlocked). +;;; @param X The device index for the door. +;;; @preserve T0+ +.PROC FuncA_Room_LockOrUnlockDoorDevice cmp Ram_DeviceType_eDevice_arr, x beq @done sta Ram_DeviceType_eDevice_arr, x diff --git a/src/explore.asm b/src/explore.asm index 13327b1..a465d77 100644 --- a/src/explore.asm +++ b/src/explore.asm @@ -33,7 +33,7 @@ .INCLUDE "spawn.inc" .INCLUDE "tileset.inc" -.IMPORT FuncA_Actor_TickAllActors +.IMPORT FuncA_Actor_TickAllDevicesAndActors .IMPORT FuncA_Avatar_EnterRoomViaDoor .IMPORT FuncA_Avatar_EnterRoomViaPassage .IMPORT FuncA_Avatar_ExitRoomViaPassage @@ -64,7 +64,6 @@ .IMPORT Func_FindDeviceNearPoint .IMPORT Func_SetLastSpawnPointToActiveDevice .IMPORT Func_SetPointToAvatarCenter -.IMPORT Func_TickAllDevices .IMPORT Func_Window_Disable .IMPORT Func_Window_SetUpIrq .IMPORT Main_Breaker_UseDevice @@ -196,8 +195,7 @@ _CheckButtons: @continueExploring: _Tick: jsr FuncM_ScrollTowardsAvatar - jsr_prga FuncA_Actor_TickAllActors - jsr Func_TickAllDevices + jsr_prga FuncA_Actor_TickAllDevicesAndActors jsr_prga FuncA_Machine_ExecuteAll jsr_prga FuncA_Room_CallRoomTick ;; Check if the player avatar is dead: diff --git a/src/rooms/city_center.asm b/src/rooms/city_center.asm index 863eb7b..ae6fb5a 100644 --- a/src/rooms/city_center.asm +++ b/src/rooms/city_center.asm @@ -63,12 +63,12 @@ .IMPORT FuncA_Objects_SetShapePosToPlatformTopLeft .IMPORT FuncA_Room_MachineResetRun .IMPORT FuncA_Room_MachineSemaphoreReset +.IMPORT FuncA_Room_UnlockDoorDevice .IMPORT Func_GetRandomByte .IMPORT Func_Noop .IMPORT Func_PlaySfxExplodeBig .IMPORT Func_SetFlag .IMPORT Func_SetMachineIndex -.IMPORT Func_UnlockDoorDevice .IMPORT Main_Breaker_FadeBackToBreakerRoom .IMPORT Ppu_ChrObjCity .IMPORT Ppu_ChrObjParley @@ -650,7 +650,7 @@ _SetFlag: ldx #eFlag::CityCenterDoorUnlocked ; param: flag jsr Func_SetFlag ldx #kLockedDoorDeviceIndex ; param: device index - jsr Func_UnlockDoorDevice + jmp FuncA_Room_UnlockDoorDevice @done: rts .ENDPROC diff --git a/src/rooms/mermaid_hut4.asm b/src/rooms/mermaid_hut4.asm index c34c569..0d75cf5 100644 --- a/src/rooms/mermaid_hut4.asm +++ b/src/rooms/mermaid_hut4.asm @@ -84,12 +84,12 @@ .IMPORT DataA_Text1_MermaidHut4Florist_Zero2_u8_arr .IMPORT DataA_Text1_MermaidHut4Florist_Zero3_u8_arr .IMPORT FuncA_Objects_Draw1x1Shape +.IMPORT FuncA_Room_UnlockDoorDevice .IMPORT Func_CountDeliveredFlowers .IMPORT Func_DropFlower .IMPORT Func_IsFlagSet .IMPORT Func_Noop .IMPORT Func_SetFlag -.IMPORT Func_UnlockDoorDevice .IMPORT Ppu_ChrObjVillage .IMPORT Ram_DeviceType_eDevice_arr .IMPORT Sram_CarryingFlower_eFlag @@ -130,7 +130,7 @@ _Ext_sRoomExt: d_addr Passages_sPassage_arr_ptr, 0 d_addr Enter_func_ptr, FuncC_Mermaid_Hut4_EnterRoom d_addr FadeIn_func_ptr, Func_Noop - d_addr Tick_func_ptr, Func_Noop + d_addr Tick_func_ptr, FuncC_Mermaid_Hut4_TickRoom d_addr Draw_func_ptr, FuncC_Mermaid_Hut4_DrawRoom D_END _TerrainData: @@ -196,6 +196,16 @@ _Devices_sDevice_arr: rts .ENDPROC +;;; @prereq PRGA_Room is loaded. +.PROC FuncC_Mermaid_Hut4_TickRoom + flag_bit Sram_ProgressFlags_arr, eFlag::MermaidHut4OpenedCellar + beq @done + ldx #kCellarDoorDeviceIndex ; param: device index + jsr FuncA_Room_UnlockDoorDevice + @done: + rts +.ENDPROC + ;;; Allocates and populates OAM slots for this room. ;;; @prereq PRGA_Objects is loaded. .PROC FuncC_Mermaid_Hut4_DrawRoom @@ -383,8 +393,6 @@ _Eleven_sDialog: _Twelve_sDialog: dlg_Func @func @func: - ldx #kCellarDoorDeviceIndex ; param: device index - jsr Func_UnlockDoorDevice ldx #eFlag::MermaidHut4OpenedCellar ; param: flag jsr Func_SetFlag flag_bit Sram_ProgressFlags_arr, eFlag::UpgradeOpBeep