Skip to content

Commit

Permalink
Refactor a few more rooms to make space in PRGA_Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Aug 2, 2024
1 parent c8cb6da commit 5836590
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 212 deletions.
102 changes: 48 additions & 54 deletions src/rooms/boss_crypt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ _Ext_sRoomExt:
d_addr Actors_sActor_arr_ptr, Data_Empty_sActor_arr
d_addr Devices_sDevice_arr_ptr, _Devices_sDevice_arr
d_addr Passages_sPassage_arr_ptr, 0
d_addr Enter_func_ptr, FuncC_Boss_Crypt_EnterRoom
d_addr Enter_func_ptr, FuncA_Room_BossCrypt_EnterRoom
d_addr FadeIn_func_ptr, FuncA_Terrain_BossCrypt_FadeInRoom
d_addr Tick_func_ptr, FuncA_Room_BossCrypt_TickRoom
d_addr Draw_func_ptr, FuncA_Objects_DrawBoss
Expand All @@ -301,7 +301,7 @@ _Machines_sMachine_arr:
d_addr TryMove_func_ptr, FuncA_Machine_BossCryptWinch_TryMove
d_addr TryAct_func_ptr, FuncA_Machine_BossCryptWinch_TryAct
d_addr Tick_func_ptr, FuncC_Boss_CryptWinch_Tick
d_addr Draw_func_ptr, FuncA_Objects_BossCryptWinch_Draw
d_addr Draw_func_ptr, FuncC_Boss_CryptWinch_Draw
d_addr Reset_func_ptr, FuncC_Boss_CryptWinch_Reset
D_END
.assert * - :- <= kMaxMachines * .sizeof(sMachine), error
Expand Down Expand Up @@ -492,35 +492,12 @@ _Inner:
rts
.ENDPROC

;;; Room init function for the BossCrypt room.
;;; @prereq PRGA_Room is loaded.
.PROC FuncC_Boss_Crypt_EnterRoom
jsr FuncC_Boss_Crypt_SetBossEyeDir
_InitBoss:
ldax #DataC_Boss_Crypt_sBoss ; param: sBoss ptr
jsr FuncA_Room_InitBoss ; sets Z if boss is alive
bne _BossIsDead
_BossIsAlive:
lda #eBossMode::Firing
sta Zp_RoomState + sState::Current_eBossMode
lda #kBossInitHealth
sta Zp_RoomState + sState::BossHealth_u8
lda #120 ; 2 seconds
sta Zp_RoomState + sState::BossCooldown_u8
lda #kBossInitPosX
sta Zp_RoomState + sState::BossGoalPosX_u8
lda #kBossInitPosY
sta Zp_RoomState + sState::BossGoalPosY_u8
_BossIsDead:
rts
.ENDPROC

;;; Performs per-frame upates for the boss in this room.
;;; @prereq PRGA_Room is loaded.
.PROC FuncC_Boss_Crypt_TickBoss
jsr FuncC_Boss_Crypt_CheckForSpikeballHit
jsr FuncC_Boss_Crypt_MoveBossTowardGoal
jsr FuncC_Boss_Crypt_SetBossEyeDir
jsr FuncA_Room_BossCrypt_SetBossEyeDir
_CoolDown:
lda Zp_RoomState + sState::BossCooldown_u8
beq _CheckMode
Expand Down Expand Up @@ -820,24 +797,6 @@ _ApplyDragY:
rts
.ENDPROC

;;; Sets Boss_eEyeDir so that the boss's eye is looking at the player avatar.
;;; Note that this is called from the room's Enter_func_ptr, so no PRGA bank
;;; can be assumed.
.PROC FuncC_Boss_Crypt_SetBossEyeDir
ldy #kBossBodyPlatformIndex ; param: platform index
jsr Func_SetPointToPlatformCenter
jsr Func_GetAngleFromPointToAvatar ; returns A
add #$50
div #$20
tax
lda _Dir_eEyeDir_arr8, x
sta Zp_RoomState + sState::Boss_eEyeDir
rts
_Dir_eEyeDir_arr8:
.byte eEyeDir::Down, eEyeDir::Right, eEyeDir::Right, eEyeDir::DownRight
.byte eEyeDir::Down, eEyeDir::DownLeft, eEyeDir::Left, eEyeDir::Left
.ENDPROC

;;; A template (with unset payload bytes) for a pair of PPU transfer entries
;;; for changing the BG tiles of the boss's eye.
.PROC DataC_Boss_CryptEyeTransferTemplate_arr
Expand Down Expand Up @@ -994,10 +953,55 @@ _EyeOffsetY_u8_arr:
D_END
.ENDPROC

.PROC FuncC_Boss_CryptWinch_Draw
ldx #kSpikeballPlatformIndex ; param: spikeball platform index
jmp FuncA_Objects_DrawWinchMachineWithSpikeball
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Room"

;;; Room init function for the BossCrypt room.
.PROC FuncA_Room_BossCrypt_EnterRoom
_InitBoss:
ldax #DataC_Boss_Crypt_sBoss ; param: sBoss ptr
jsr FuncA_Room_InitBoss ; sets Z if boss is alive
beq _BossIsAlive
_BossIsDead:
rts
_BossIsAlive:
lda #eBossMode::Firing
sta Zp_RoomState + sState::Current_eBossMode
lda #kBossInitHealth
sta Zp_RoomState + sState::BossHealth_u8
lda #120 ; 2 seconds
sta Zp_RoomState + sState::BossCooldown_u8
lda #kBossInitPosX
sta Zp_RoomState + sState::BossGoalPosX_u8
lda #kBossInitPosY
sta Zp_RoomState + sState::BossGoalPosY_u8
fall FuncA_Room_BossCrypt_SetBossEyeDir
.ENDPROC

;;; Sets Boss_eEyeDir so that the boss's eye is looking at the player avatar.
;;; Note that this is called from the room's Enter_func_ptr, so no PRGA bank
;;; can be assumed.
.PROC FuncA_Room_BossCrypt_SetBossEyeDir
ldy #kBossBodyPlatformIndex ; param: platform index
jsr Func_SetPointToPlatformCenter
jsr Func_GetAngleFromPointToAvatar ; returns A
add #$50
div #$20
tax
lda _Dir_eEyeDir_arr8, x
sta Zp_RoomState + sState::Boss_eEyeDir
rts
_Dir_eEyeDir_arr8:
.byte eEyeDir::Down, eEyeDir::Right, eEyeDir::Right, eEyeDir::DownRight
.byte eEyeDir::Down, eEyeDir::DownLeft, eEyeDir::Left, eEyeDir::Left
.ENDPROC

;;; Room tick function for the BossCrypt room.
.PROC FuncA_Room_BossCrypt_TickRoom
.assert eBossMode::Dead = 0, error
Expand Down Expand Up @@ -1166,16 +1170,6 @@ _Return:

;;;=========================================================================;;;

.SEGMENT "PRGA_Objects"

;;; Draws the BossCryptWinch machine.
.PROC FuncA_Objects_BossCryptWinch_Draw
ldx #kSpikeballPlatformIndex ; param: spikeball platform index
jmp FuncA_Objects_DrawWinchMachineWithSpikeball
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGE_Irq"

;;; HBlank IRQ handler function for the top of the boss's zone in the BossCrypt
Expand Down
18 changes: 7 additions & 11 deletions src/rooms/boss_mine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ _Machines_sMachine_arr:
d_addr TryMove_func_ptr, FuncA_Machine_BossMineCrane_TryMove
d_addr TryAct_func_ptr, FuncC_Boss_MineCrane_TryAct
d_addr Tick_func_ptr, FuncA_Machine_BossMineCrane_Tick
d_addr Draw_func_ptr, FuncA_Objects_BossMineCrane_Draw
d_addr Draw_func_ptr, FuncC_Boss_MineCrane_Draw
d_addr Reset_func_ptr, FuncC_Boss_MineCrane_InitReset
D_END
.assert * - :- <= kMaxMachines * .sizeof(sMachine), error
Expand Down Expand Up @@ -989,6 +989,12 @@ _StartWaiting:
jmp FuncA_Machine_StartWaiting
.ENDPROC

.PROC FuncC_Boss_MineCrane_Draw
jsr FuncA_Objects_DrawCraneMachine
ldx #kTrolleyPlatformIndex ; param: pulley platform index
jmp FuncA_Objects_DrawCraneRopeToPulley
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Room"
Expand Down Expand Up @@ -1377,13 +1383,3 @@ _Error:
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Objects"

.PROC FuncA_Objects_BossMineCrane_Draw
jsr FuncA_Objects_DrawCraneMachine
ldx #kTrolleyPlatformIndex ; param: pulley platform index
jmp FuncA_Objects_DrawCraneRopeToPulley
.ENDPROC

;;;=========================================================================;;;
98 changes: 49 additions & 49 deletions src/rooms/mine_east.asm
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ _Machines_sMachine_arr:
d_byte ScrollGoalY_u8, $10
d_byte RegNames_u8_arr4, 0, 0, 0, "Z"
d_byte MainPlatform_u8, kHoistPlatformIndex
d_addr Init_func_ptr, FuncC_Mine_EastHoist_InitReset
d_addr Init_func_ptr, FuncA_Room_MineEastHoist_InitReset
d_addr ReadReg_func_ptr, FuncC_Mine_EastHoist_ReadReg
d_addr WriteReg_func_ptr, Func_Noop
d_addr TryMove_func_ptr, FuncA_Machine_MineEastHoist_TryMove
d_addr TryAct_func_ptr, FuncA_Machine_Error
d_addr Tick_func_ptr, FuncA_Machine_MineEastHoist_Tick
d_addr Draw_func_ptr, FuncA_Objects_MineEastHoist_Draw
d_addr Reset_func_ptr, FuncC_Mine_EastHoist_InitReset
d_addr Draw_func_ptr, FuncC_Mine_EastHoist_Draw
d_addr Reset_func_ptr, FuncA_Room_MineEastHoist_InitReset
D_END
.assert * - :- = kLiftMachineIndex * .sizeof(sMachine), error
D_STRUCT sMachine
Expand All @@ -157,14 +157,14 @@ _Machines_sMachine_arr:
d_byte ScrollGoalY_u8, $50
d_byte RegNames_u8_arr4, 0, 0, 0, "Y"
d_byte MainPlatform_u8, kLiftPlatformIndex
d_addr Init_func_ptr, FuncC_Mine_EastLift_InitReset
d_addr Init_func_ptr, FuncA_Room_MineEastLift_InitReset
d_addr ReadReg_func_ptr, FuncC_Mine_EastLift_ReadReg
d_addr WriteReg_func_ptr, Func_Noop
d_addr TryMove_func_ptr, FuncA_Machine_MineEastLift_TryMove
d_addr TryAct_func_ptr, FuncA_Machine_Error
d_addr Tick_func_ptr, FuncA_Machine_MineEastLift_Tick
d_addr Draw_func_ptr, FuncA_Objects_DrawLiftMachine
d_addr Reset_func_ptr, FuncC_Mine_EastLift_InitReset
d_addr Reset_func_ptr, FuncA_Room_MineEastLift_InitReset
D_END
.assert * - :- <= kMaxMachines * .sizeof(sMachine), error
_Platforms_sPlatform_arr:
Expand Down Expand Up @@ -265,25 +265,13 @@ _Passages_sPassage_arr:
.assert * - :- <= kMaxPassages * .sizeof(sPassage), error
.ENDPROC

.PROC FuncC_Mine_EastHoist_InitReset
lda #kHoistInitGoalZ
sta Ram_MachineGoalVert_u8_arr + kHoistMachineIndex
rts
.ENDPROC

.PROC FuncC_Mine_EastHoist_ReadReg
lda Ram_PlatformTop_i16_0_arr + kLowerGirderPlatformIndex
sub #kLowerGirderMinPlatformTop - kTileHeightPx
div #kBlockHeightPx
rts
.ENDPROC

.PROC FuncC_Mine_EastLift_InitReset
lda #kLiftInitGoalY
sta Ram_MachineGoalVert_u8_arr + kLiftMachineIndex
rts
.ENDPROC

.PROC FuncC_Mine_EastLift_ReadReg
.assert kLiftMaxPlatformTop + kTileHeightPx < $100, error
lda #kLiftMaxPlatformTop + kTileHeightPx
Expand All @@ -292,6 +280,50 @@ _Passages_sPassage_arr:
rts
.ENDPROC

.PROC FuncC_Mine_EastHoist_Draw
_Pulley:
ldx #kPulleyPlatformIndex ; param: platform index
ldy Ram_PlatformTop_i16_0_arr + kUpperGirderPlatformIndex ; param: rope
jsr FuncA_Objects_DrawHoistPulley
_LowerGirder:
ldx #kLowerGirderPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawGirderPlatform
jsr FuncA_Objects_MoveShapeLeftHalfTile
ldx #kGirderSpacingTiles - 1
@loop:
jsr FuncA_Objects_MoveShapeUpOneTile
ldy #kPaletteObjHoistRope ; param: object flags
lda #kTileIdObjHoistRopeVert ; param: tile ID
jsr FuncA_Objects_Draw1x1Shape ; preserves X
dex
bne @loop
_UpperGirder:
ldx #kUpperGirderPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawGirderPlatform
jsr FuncA_Objects_MoveShapeLeftHalfTile
ldx #kPulleyPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawHoistRopeToPulley
_Hoist:
lda Ram_PlatformTop_i16_0_arr + kUpperGirderPlatformIndex ; param: rope
jmp FuncA_Objects_DrawHoistMachine
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Room"

.PROC FuncA_Room_MineEastHoist_InitReset
lda #kHoistInitGoalZ
sta Ram_MachineGoalVert_u8_arr + kHoistMachineIndex
rts
.ENDPROC

.PROC FuncA_Room_MineEastLift_InitReset
lda #kLiftInitGoalY
sta Ram_MachineGoalVert_u8_arr + kLiftMachineIndex
rts
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Machine"
Expand Down Expand Up @@ -321,35 +353,3 @@ _Passages_sPassage_arr:
.ENDPROC

;;;=========================================================================;;;

.SEGMENT "PRGA_Objects"

.PROC FuncA_Objects_MineEastHoist_Draw
_Pulley:
ldx #kPulleyPlatformIndex ; param: platform index
ldy Ram_PlatformTop_i16_0_arr + kUpperGirderPlatformIndex ; param: rope
jsr FuncA_Objects_DrawHoistPulley
_LowerGirder:
ldx #kLowerGirderPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawGirderPlatform
jsr FuncA_Objects_MoveShapeLeftHalfTile
ldx #kGirderSpacingTiles - 1
@loop:
jsr FuncA_Objects_MoveShapeUpOneTile
ldy #kPaletteObjHoistRope ; param: object flags
lda #kTileIdObjHoistRopeVert ; param: tile ID
jsr FuncA_Objects_Draw1x1Shape ; preserves X
dex
bne @loop
_UpperGirder:
ldx #kUpperGirderPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawGirderPlatform
jsr FuncA_Objects_MoveShapeLeftHalfTile
ldx #kPulleyPlatformIndex ; param: platform index
jsr FuncA_Objects_DrawHoistRopeToPulley
_Hoist:
lda Ram_PlatformTop_i16_0_arr + kUpperGirderPlatformIndex ; param: rope
jmp FuncA_Objects_DrawHoistMachine
.ENDPROC

;;;=========================================================================;;;
Loading

0 comments on commit 5836590

Please sign in to comment.