Skip to content

Commit

Permalink
Use Draw1x1Shape everywhere instead of Alloc1x1Shape
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Aug 13, 2024
1 parent 367efb2 commit 53b95bc
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 122 deletions.
25 changes: 10 additions & 15 deletions src/actors/breakfire.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.IMPORT FuncA_Actor_CenterHitsTerrain
.IMPORT FuncA_Actor_HarmAvatarIfCollision
.IMPORT FuncA_Actor_NegateVelX
.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeLeftHalfTile
.IMPORT FuncA_Objects_MoveShapeUpOneTile
.IMPORT FuncA_Objects_SetShapePosToActorCenter
Expand All @@ -39,7 +39,6 @@
.IMPORT Ram_ActorState2_byte_arr
.IMPORT Ram_ActorVelX_i16_0_arr
.IMPORT Ram_ActorVelX_i16_1_arr
.IMPORT Ram_Oam_sObj_arr64
.IMPORTZP Zp_FrameCounter_u8

;;;=========================================================================;;;
Expand Down Expand Up @@ -149,26 +148,22 @@ _Expire:
bcs _Tall
_Short:
lda #2
sta T0 ; num tiles
sta T2 ; num tiles
lda #kTileIdObjBreakfireFirst + 4
sta T1 ; first tile ID
sta T3 ; first tile ID
bne _Loop ; unconditional
_Tall:
lda #3
sta T0 ; num tiles
sta T2 ; num tiles
lda #kTileIdObjBreakfireFirst + 2
sta T1 ; first tile ID
sta T3 ; first tile ID
_Loop:
jsr FuncA_Objects_Alloc1x1Shape ; preserves X and T0+, returns C and Y
bcs @continue
lda T1 ; tile ID
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjBreakfire
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
lda T3 ; param: tile ID
ldy #kPaletteObjBreakfire ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X and T2+
jsr FuncA_Objects_MoveShapeUpOneTile ; preserves X and T0+
dec T1 ; tile ID
dec T0 ; num tiles
dec T3 ; tile ID
dec T2 ; num tiles
bne _Loop
rts
.ENDPROC
Expand Down
19 changes: 7 additions & 12 deletions src/actors/explosion.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

.INCLUDE "../actor.inc"
.INCLUDE "../macros.inc"
.INCLUDE "../oam.inc"
.INCLUDE "../ppu.inc"
.INCLUDE "smoke.inc"

.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeDownByA
.IMPORT FuncA_Objects_MoveShapeLeftByA
.IMPORT FuncA_Objects_MoveShapeLeftOneTile
Expand All @@ -32,16 +31,17 @@
.IMPORT FuncA_Objects_MoveShapeUpOneTile
.IMPORT FuncA_Objects_SetShapePosToActorCenter
.IMPORT Func_InitActorDefault
.IMPORT Ram_ActorFlags_bObj_arr
.IMPORT Ram_ActorState1_byte_arr
.IMPORT Ram_ActorType_eActor_arr
.IMPORT Ram_Oam_sObj_arr64

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

;;; How long a smoke actor animates before disappearing, in frames.
kSmokeNumFrames = 12

;;; The OBJ palette number used for smoke explosion actors.
kPaletteObjExplosion = 0

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

.SEGMENT "PRG8"
Expand Down Expand Up @@ -108,16 +108,11 @@ _TopRight:
add #kTileHeightPx ; param: offset
jsr FuncA_Objects_MoveShapeUpByA ; preserves X
_DrawSmokeParticle:
jsr FuncA_Objects_Alloc1x1Shape ; preserves X
bcs @done
lda Ram_ActorState1_byte_arr, x
div #2
add #kTileIdObjSmokeFirst
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda Ram_ActorFlags_bObj_arr, x
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@done:
rts
add #kTileIdObjSmokeFirst ; param: tile ID
ldy #kPaletteObjExplosion ; param: object flags
jmp FuncA_Objects_Draw1x1Shape ; preserves X
.ENDPROC

;;;=========================================================================;;;
32 changes: 12 additions & 20 deletions src/devices/door.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
.INCLUDE "../oam.inc"
.INCLUDE "../ppu.inc"

.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeDownOneTile
.IMPORT FuncA_Objects_MoveShapeRightByA
.IMPORT FuncA_Objects_MoveShapeRightHalfTile
.IMPORT FuncA_Objects_MoveShapeUpOneTile
.IMPORT FuncA_Objects_SetShapePosToDeviceTopLeft
.IMPORT Ram_DeviceAnim_u8_arr
.IMPORT Ram_DeviceType_eDevice_arr
.IMPORT Ram_Oam_sObj_arr64

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

Expand Down Expand Up @@ -119,30 +118,23 @@ kPaletteObjDoorway = 0
beq _Done
;; Start drawing from the bottom of the doorway.
pha ; half-tiles
jsr FuncA_Objects_SetShapePosToDeviceTopLeft ; preserves X
jsr FuncA_Objects_MoveShapeDownOneTile ; preserves X
lda #kTileWidthPx / 2 ; param: offset
jsr FuncA_Objects_MoveShapeRightByA ; preserves X
jsr FuncA_Objects_SetShapePosToDeviceTopLeft ; preserves X and T0+
jsr FuncA_Objects_MoveShapeDownOneTile ; preserves X and T0+
jsr FuncA_Objects_MoveShapeRightHalfTile ; preserves X and T0+
pla ; half-tiles
_Loop:
pha ; half-tiles
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns C and Y
bcs @continue
pla ; half-tiles
pha ; half-tiles
cmp #2
blt @half
@full:
lda #kTileIdObjDoorwayFull
bne @setTileId ; unconditional
lda #kTileIdObjDoorwayFull ; param: tile ID
bne @draw ; unconditional
@half:
lda #kTileIdObjDoorwayHalf
@setTileId:
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjDoorway
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
jsr FuncA_Objects_MoveShapeUpOneTile
lda #kTileIdObjDoorwayHalf ; param: tile ID
@draw:
ldy #kPaletteObjDoorway ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X and T2+
jsr FuncA_Objects_MoveShapeUpOneTile ; preserves X and T0+
pla ; half-tiles
sub #2
blt _Done
Expand Down
13 changes: 4 additions & 9 deletions src/devices/lever.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
.INCLUDE "lever.inc"

.IMPORT FuncA_Machine_StartWaiting
.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeDownByA
.IMPORT FuncA_Objects_MoveShapeRightOneTile
.IMPORT FuncA_Objects_SetShapePosToDeviceTopLeft
.IMPORT Ram_DeviceAnim_u8_arr
.IMPORT Ram_DeviceTarget_byte_arr
.IMPORT Ram_Oam_sObj_arr64
.IMPORTZP Zp_RoomState

;;;=========================================================================;;;
Expand Down Expand Up @@ -208,21 +207,17 @@ _AdjustPosition:
@moveDown:
jsr FuncA_Objects_MoveShapeDownByA ; preserves X and T0+
_AllocateObject:
jsr FuncA_Objects_Alloc1x1Shape ; preserves X and T0+, returns C and Y
bcs @done
stx T2 ; device index
ldx T0 ; animation frame
lda T1 ; object flags
cpx #kLeverNumAnimFrames / 2
blt @noFlip
eor #bObj::FlipH
@noFlip:
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
lda _LeverTileIds_u8_arr, x
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
tay ; param: object flags
lda _LeverTileIds_u8_arr, x ; param: tile ID
ldx T2 ; device index
@done:
rts
jmp FuncA_Objects_Draw1x1Shape ; preserves X
_LeverTileIds_u8_arr:
.byte kTileIdObjLeverHandleDown
.byte kTileIdObjLeverHandleUp
Expand Down
22 changes: 8 additions & 14 deletions src/machines/bridge.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
.IMPORT FuncA_Machine_Error
.IMPORT FuncA_Machine_ReachedGoal
.IMPORT FuncA_Machine_StartWaiting
.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Alloc2x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_GetMachineLightTileId
.IMPORT FuncA_Objects_MoveShapeDownOneTile
.IMPORT FuncA_Objects_MoveShapeRightOneTile
Expand Down Expand Up @@ -210,23 +210,17 @@ _Delta_u8_arr:
.PROC FuncA_Objects_DrawBridgeMachine
ldy #sMachine::MainPlatform_u8
lda (Zp_Current_sMachine_ptr), y
sta T2 ; pivot platform index
_SegmentLoop:
pha ; pivot platform index
jsr FuncA_Objects_SetShapePosToPlatformTopLeft ; preserves X
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns Y and C
bcs @continue
lda #kTileIdObjBridgeSegment
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjBridgeSegment
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
pla ; pivot platform index
sta T0 ; pivot platform index
jsr FuncA_Objects_SetShapePosToPlatformTopLeft ; preserves X and T0+
lda #kTileIdObjBridgeSegment ; param: tile ID
ldy #kPaletteObjBridgeSegment ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X and T2+
dex
cpx T0 ; pivot platform index
cpx T2 ; pivot platform index
bne _SegmentLoop
_MainMachine:
tax ; param: platform index
;; At this point, X holds the machine's pivot (main) platform index.
jsr FuncA_Objects_SetShapePosToPlatformTopLeft
jsr FuncA_Objects_MoveShapeDownOneTile
ldy #sMachine::Flags_bMachine
Expand Down
42 changes: 12 additions & 30 deletions src/machines/crane.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
.INCLUDE "shared.inc"

.IMPORT FuncA_Machine_GetGenericMoveSpeed
.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Alloc2x2Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_DrawGirderPlatform
Expand Down Expand Up @@ -144,23 +143,14 @@ _Claw:
@done:
_RightClaw:
jsr FuncA_Objects_MoveShapeDownOneTile ; preserves X
jsr FuncA_Objects_Alloc1x1Shape ; preserves X; returns C and Y
bcs @done
txa ; tile ID
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjMachineLight | bObj::FlipH
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@done:
txa ; param: tile ID
ldy #kPaletteObjMachineLight | bObj::FlipH ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X
_LeftClaw:
jsr FuncA_Objects_MoveShapeLeftOneTile ; preserves X
jsr FuncA_Objects_Alloc1x1Shape ; preserves X; returns C and Y
bcs @done
txa ; tile ID
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjMachineLight
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@done:
rts
txa ; param: tile ID
ldy #kPaletteObjMachineLight ; param: object flags
jmp FuncA_Objects_Draw1x1Shape
.ENDPROC

;;; Draw implemention for trolley machines.
Expand Down Expand Up @@ -249,13 +239,9 @@ _DrawRope:
jsr FuncA_Objects_MoveShapeRightByA ; preserves X
@loop:
jsr FuncA_Objects_MoveShapeUpOneTile ; preserves X
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns C and Y
bcs @continue
lda #kTileIdObjCraneRope
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjRope
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
lda #kTileIdObjCraneRope ; param: tile ID
ldy #kPaletteObjRope ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X, returns C and Y
dex
bne @loop
_Return:
Expand All @@ -276,13 +262,9 @@ _Return:
jsr FuncA_Objects_MoveShapeRightByA ; preserves X
@loop:
jsr FuncA_Objects_MoveShapeDownOneTile ; preserves X
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns C and Y
bcs @continue
lda #kTileIdObjTrolleyRope
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjRope
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
lda #kTileIdObjTrolleyRope ; param: tile ID
ldy #kPaletteObjRope ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X
dex
bne @loop
rts
Expand Down
1 change: 0 additions & 1 deletion src/oam.asm
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ Ram_Oam_sObj_arr64: .res .sizeof(sObj) * kNumOamSlots
;;; @return C Set if no OAM slot was allocated, cleared otherwise.
;;; @return Y The OAM byte offset for the allocated object.
;;; @preserve X, T0+
.EXPORT FuncA_Objects_Alloc1x1Shape
.PROC FuncA_Objects_Alloc1x1Shape
;; If the shape is offscreen horizontally, return without allocating any
;; objects.
Expand Down
14 changes: 4 additions & 10 deletions src/platforms/girder.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
;;;=========================================================================;;;

.INCLUDE "../macros.inc"
.INCLUDE "../oam.inc"
.INCLUDE "../ppu.inc"

.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_MoveShapeRightOneTile
.IMPORT FuncA_Objects_SetShapePosToPlatformTopLeft
.IMPORT Ram_Oam_sObj_arr64
.IMPORT Ram_PlatformLeft_i16_0_arr
.IMPORT Ram_PlatformRight_i16_0_arr

Expand Down Expand Up @@ -59,13 +57,9 @@ kTileIdObjGirder = $04
@loop:
jsr FuncA_Objects_MoveShapeRightOneTile ; preserves X
@startLoop:
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns C and Y
bcs @continue
lda #kTileIdObjGirder
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjGirder
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
lda #kTileIdObjGirder ; param: tile ID
ldy #kPaletteObjGirder ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X
dex
bne @loop
rts
Expand Down
17 changes: 6 additions & 11 deletions src/rooms/mermaid_spring.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
.IMPORT FuncA_Machine_Error
.IMPORT FuncA_Machine_GenericTryMoveY
.IMPORT FuncA_Machine_PumpTick
.IMPORT FuncA_Objects_Alloc1x1Shape
.IMPORT FuncA_Objects_Draw1x1Shape
.IMPORT FuncA_Objects_DrawMonitorPlatform
.IMPORT FuncA_Objects_DrawPumpMachine
.IMPORT FuncA_Objects_DrawRocksPlatformHorz
Expand All @@ -66,7 +66,6 @@
.IMPORT Ram_DeviceType_eDevice_arr
.IMPORT Ram_MachineGoalVert_u8_arr
.IMPORT Ram_MachineStatus_eMachine_arr
.IMPORT Ram_Oam_sObj_arr64
.IMPORT Ram_PlatformLeft_i16_0_arr
.IMPORT Ram_PlatformLeft_i16_1_arr
.IMPORT Ram_PlatformTop_i16_0_arr
Expand Down Expand Up @@ -315,17 +314,13 @@ _Water:
;; Determine the width of the water in tiles, and draw that many objects.
ldx _WaterWidth_u8_arr, y
@loop:
jsr FuncA_Objects_Alloc1x1Shape ; preserves X, returns C and Y
bcs @continue
lda Zp_FrameCounter_u8
div #8
and #$03
.assert kTileIdObjPlatformHotSpringFirst & $03 = 0, error
ora #kTileIdObjPlatformHotSpringFirst
sta Ram_Oam_sObj_arr64 + sObj::Tile_u8, y
lda #kPaletteObjHotSpring | bObj::Pri
sta Ram_Oam_sObj_arr64 + sObj::Flags_bObj, y
@continue:
mod #4
.assert kTileIdObjPlatformHotSpringFirst .mod 4 = 0, error
ora #kTileIdObjPlatformHotSpringFirst ; param: tile ID
ldy #kPaletteObjHotSpring | bObj::Pri ; param: object flags
jsr FuncA_Objects_Draw1x1Shape ; preserves X
jsr FuncA_Objects_MoveShapeRightOneTile ; preserves X
dex
bne @loop
Expand Down

0 comments on commit 53b95bc

Please sign in to comment.