Skip to content

Commit

Permalink
Free up more space in PRG8 segment
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Oct 17, 2024
1 parent 3b62e40 commit c6f1118
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 60 deletions.
17 changes: 9 additions & 8 deletions src/actor.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -724,7 +725,7 @@ _NoHit:
@continue:
dex
bpl @loop
rts
jmp FuncA_Actor_TickAllDevices
.ENDPROC

;;; Performs per-frame updates for one actor.
Expand Down
10 changes: 5 additions & 5 deletions src/boss.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
.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
.IMPORT Func_InitActorDefault
.IMPORT Func_InitActorSmokeExplosion
.IMPORT Func_InitActorSmokeParticle
.IMPORT Func_IsFlagSet
.IMPORT Func_LockDoorDevice
.IMPORT Func_MarkRoomSafe
.IMPORT Func_Noop
.IMPORT Func_PlaySfxExplodeBig
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/console.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/cutscene.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

;;;=========================================================================;;;
Expand Down
10 changes: 7 additions & 3 deletions src/device.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions src/devices/boiler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
32 changes: 17 additions & 15 deletions src/devices/door.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/explore.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/rooms/city_center.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/rooms/mermaid_hut4.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6f1118

Please sign in to comment.