Restructured GFX drawing routine to a more generic approach

This commit is contained in:
codemann8
2024-03-25 14:28:03 -05:00
parent 6e4b109058
commit b71b48b4b1
4 changed files with 97 additions and 191 deletions

View File

@@ -33,12 +33,6 @@ LoadBonkItemGFX_inner:
JSR LoadBonkItem
STA.w SprSourceItemId, X
JSL RequestStandingItemVRAMSlot
PHA : PHX
LDA.w SprItemReceipt,X : TAX
LDA.l SpriteProperties_standing_width,X : BNE +
LDA.b #$00 : STA.l SpriteDynamicOAM : STA.l SpriteDynamicOAM+8
+
PLX : PLA
RTL
;--------------------------------------------------------------------------------
DrawBonkItemGFX:

View File

@@ -58,7 +58,12 @@ DrawHeartPieceGFX:
TAX
LDA.l SpriteProperties_standing_width,X : BNE +
PLX
REP #$20 : LDA.b RoomIndex : CMP.w #$0120 : SEP #$20 : BNE .prepShadow
LDA.b IndoorsFlag : BNE .draw ; skip "shadow" change in good bee room
.prepShadow
LDA.w SpriteControl, X : ORA.b #$20 : STA.w SpriteControl, X
.draw
PLA
JSL DrawPotItem
REP #$21

View File

@@ -153,17 +153,15 @@ RequestStandingItemVRAMSlot:
;===================================================================================================
FreeUWGraphics:
dw $8800>>1
dw $8840>>1
dw $8980>>1
dw $9960>>1 ; Arghuss Splash apparently
dw $9C00>>1
; dw $9CA0>>1
dw $9DC0>>1
dw $8800>>1 ; Shovel Dirt
dw $8840>>1 ; (Unused)
dw $8980>>1 ; (Unused)
dw $9960>>1 ; Arghuss/Zora Splash
dw $9C00>>1 ; Heart Piece
; dw $9CA0>>1 ; Apple
dw $9DC0>>1 ; Whirlpool
; add new slots above this line
.end
dw $0000 ; overflow slot, intentionally blank
; above this line, add slots that we want to draw to specific slots
FreeOWGraphics:
dw $8180>>1 ; Push Block
@@ -174,8 +172,36 @@ FreeOWGraphics:
;dw $9DC0>>1 ; Whirlpool
; add new slots above this line
.end
dw $0000 ; overflow slot, intentionally blank
; above this line, add slots that we want to draw to specific slots
FixedItemGraphics:
dw $9400>>1 ; (overflow full slot)
dw $9D40>>1 ; Fairy
dw $9CA0>>1 ; Apple
.thin
dw $9C60>>1 ; (overflow thin slot)
dw $8160>>1 ; Rupee
dw $8D60>>1 ; Key
dw $9C80>>1 ; Bee
; Below are the two default 16-byte tables that are loaded
; into SpriteDynamicOAM, and adjustments are applied afterwards
; Format of SpriteDynamicOAM:
; First 8 bytes are the top half, last 8 bytes are bottom half (unused by 16x16 gfx)
; X Offset (2 bytes)
; Y Offset (2 bytes)
; - these offsets are relative to its normal draw position
; VRAM Location (1 byte) - relative to $8000, every 8x8 tile
; increments by 1 (ie. small key is $6B)
; Palette Data (1 byte)
; TBD (2 bytes)
DynamicOAMTile_thin:
dw 4, 0 : db $00, $00, $20, $00
dw 4, 8 : db $00, $00, $20, $00
DynamicOAMTile_full:
dw 0, -1 : db $00, $00, $20, $02
dd 0, 0
;===================================================================================================
; Come in with
@@ -207,19 +233,12 @@ DrawPotItem:
+
LDA.l SpriteProperties_standing_width,X : BEQ .narrow
; TODO: Instead of loading the whole fixed 16 bytes from DynamicOAMTile**_** into SpriteDynamicOAM
; Do something more like how DrawDynamicTile does it
; Then we won't need all the separate DynamicOAMTile**_** tables
.full
PLX
LDA.b #$01 : STA.b Scrap06
LDA.b #$0C : JSL OAM_AllocateFromRegionC
LDA.b #$02 : PHA
REP #$20
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.w #DynamicOAMTileUW_full
BRA .transfer
+ LDA.w #DynamicOAMTileOW_full
REP #$20 : LDA.w #DynamicOAMTile_full
BRA .transfer
.narrow
@@ -227,51 +246,74 @@ DrawPotItem:
LDA.b #$02 : STA.b Scrap06
LDA.b #$10 : JSL OAM_AllocateFromRegionC
LDA.b #$03 : PHA
REP #$20
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.w #DynamicOAMTileUW_thin
BRA .transfer
+ LDA.w #DynamicOAMTileOW_thin
REP #$20 : LDA.w #DynamicOAMTile_thin
.transfer
STA.b Scrap08
LDA.w SprItemGFXSlot,X
AND.w #$00FF
ASL : ASL : ASL : ASL
ADC.b Scrap08
STA.b Scrap08
PHK : PLY : STY.b Scrap0A
LDY.b #$7E : PHB : PHY : PLB
; transfer fixed table data into WRAM
LDY.b #$0E
- LDA.b [$08],Y : STA.w SpriteDynamicOAM,Y
DEY : DEY : BPL -
LDA.w SprItemFlags, X : AND.w #$00FF : BNE .draw
LDA.b Scrap06 : LSR : BCC +
; full
LDA.w #$0000
STA.w SpriteDynamicOAM : STA.w SpriteDynamicOAM+2
BRA .draw
+ ; narrow
LDA.w SpriteTypeTable, X : AND.w #$00FF : CMP.w #$003B : BEQ .draw ; bonk item
LDA.b RoomIndex : CMP.w #$0120 : BNE +
LDA.b IndoorsFlag : BEQ .draw ; good bee statue
+
LDA.b OverworldIndex : AND.w #$00FF : CMP.w #$0018 : BNE +
LDA.w SpriteTypeTable, X : AND.w #$00FF : CMP.w #$00E4 : BEQ .draw ; bottle vendor key
+
LDA.w #$0004
STA.w SpriteDynamicOAM : STA.w SpriteDynamicOAM+8
LDY.b #FreeUWGraphics>>16 : PHB : PHY : PLB
LDA.w SprItemGFXSlot,X : AND.w #$00FF : ASL : TAY
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
CPY.b #(FreeUWGraphics_end-FreeUWGraphics) : BCC ++
TYA : SEC : SBC.w #(FreeUWGraphics_end-FreeUWGraphics) : TAY : BRA .fixed
++ LDA.w FreeUWGraphics, Y : BRA .setVRAM
+ CPY.b #(FreeOWGraphics_end-FreeOWGraphics) : BCC ++
TYA : SEC : SBC.w #(FreeOWGraphics_end-FreeOWGraphics) : TAY : BRA .fixed
++ LDA.w FreeOWGraphics, Y : BRA .setVRAM
.draw
.fixed
LDA.b Scrap06 : LSR : BCC +
LDA.w FixedItemGraphics, Y : BRA .setVRAM
+ LDA.w FixedItemGraphics_thin, Y
.setVRAM
LSR #4 : AND.w #$FBFF : PLB : PHA
STA.w SpriteDynamicOAM+4
LDA.b Scrap06 : LSR : PLA : BCS .adjustFull
; narrow
CLC : ADC.w #$0010 : STA.w SpriteDynamicOAM+12
CMP.w #$00F4 : BNE +
; exception for good bee, needs blank tile on top
LDA.w #$007C : STA.w SpriteDynamicOAM+4
+
.adjust
LDA.w SpriteTypeTable, X : AND.w #$00FF : CMP.w #$003B : BNE +
LDA.b RoomIndex : CMP.w #$0107 : BNE .shiftLeft ; bonk item
LDA.w SpriteTypeTable, X : AND.w #$00FF
+ CMP.w #$00E4 : BNE +
LDA.b OverworldIndex : AND.w #$00FF : CMP.w #$0018 : BEQ .shiftLeft ; bottle vendor key
+
.adjustFull
LDA.b RoomIndex : CMP.w #$0087 : BNE +
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.w SpriteTypeTable, X : AND.w #$00FF : CMP.w #$00EB : BEQ .drawSpecial
LDA.w SprItemFlags, X : AND.w #$00FF : BEQ .shiftUpLeft ; hera cage item
BRA .drawSpecial
+
LDA.w SprItemFlags, X : AND.w #$00FF : BEQ .drawSpecial
.shiftUpLeft
DEC.w SpriteDynamicOAM+2 : DEC.w SpriteDynamicOAM+10
.shiftLeft
LDA.w SpriteDynamicOAM : SEC : SBC.w #$0004
STA.w SpriteDynamicOAM : STA.w SpriteDynamicOAM+8
.drawSpecial
; special animation handling
LDY.b Scrap07 : CPY.b #$D2 : BNE + ; fairy
LDY.w SpriteDirectionTable, X : BEQ ++ : CPY.b #$03 : BEQ ++ ; use other fairy GFX
LDA.w SpriteDynamicOAM+4 : CLC : ADC.w #$0002 : STA.w SpriteDynamicOAM+4
++ CPY.b #$02 : BCC .skipSpecial ; move fairy up 2 pixels
++ CPY.b #$02 : BCC .draw ; move fairy up 2 pixels
LDA.w SpriteDynamicOAM+2 : SEC : SBC.w #$0002 : STA.w SpriteDynamicOAM+2
BRA .skipSpecial
BRA .draw
+ CPY.b #$D6 : BNE + ; good bee
LDY.w SpriteDirectionTable, X : BEQ ++ : CPY.b #$03 : BEQ ++ ; use other bee GFX
LDA.w SpriteDynamicOAM+12 : SEC : SBC.w #$0010 : STA.w SpriteDynamicOAM+12
@@ -279,7 +321,7 @@ DrawPotItem:
LDA.w SpriteDynamicOAM+10 : SEC : SBC.w #$0002 : STA.w SpriteDynamicOAM+10
+
.skipSpecial
.draw
LDA.w #SpriteDynamicOAM : STA.b Scrap08
SEP #$20
STZ.b Scrap07
@@ -294,140 +336,6 @@ DrawPotItem:
CLC
RTL
DynamicOAMTileUW_thin:
dw 0, 0 : db $40, $00, $20, $00
dw 0, 8 : db $50, $00, $20, $00
dw 0, 0 : db $42, $00, $20, $00
dw 0, 8 : db $52, $00, $20, $00
dw 0, 0 : db $4C, $00, $20, $00
dw 0, 8 : db $5C, $00, $20, $00
dw 0, 0 : db $CB, $00, $20, $00
dw 0, 8 : db $DB, $00, $20, $00
dw 0, 0 : db $E0, $00, $20, $00
dw 0, 8 : db $F0, $00, $20, $00
dw 0, 0 : db $EE, $00, $20, $00
dw 0, 8 : db $FE, $00, $20, $00
; add new slots above this line
dw 0, 0 : db $E3, $00, $20, $00 ; overflow slot
dw 0, 8 : db $F3, $00, $20, $00
; above this line, add slots that we want to draw to specific slots
dw 0, 0 : db $0B, $00, $20, $00 ; animated rupees slot
dw 0, 8 : db $1B, $00, $20, $00
dw 0, 0 : db $6B, $00, $20, $00 ; key
dw 0, 8 : db $7B, $00, $20, $00
dw 0, 0 : db $7C, $00, $20, $00 ; good bee
dw 0, 8 : db $F4, $00, $20, $00
DynamicOAMTileUW_full:
dw -4, -1 : db $40, $00, $20, $02
dd 0, 0
dw -4, -1 : db $42, $00, $20, $02
dd 0, 0
dw -4, -1 : db $4C, $00, $20, $02
dd 0, 0
dw -4, -1 : db $CB, $00, $20, $02
dd 0, 0
dw -4, -1 : db $E0, $00, $20, $02
dd 0, 0
dw -4, -1 : db $EE, $00, $20, $02
dd 0, 0
; add new rotating slots above this line
dw -4, -1 : db $A0, $00, $20, $02 ; overflow slot
dd 0, 0
; above this line, add slots that we want to draw to specific slots
dw -4, -1 : db $EA, $00, $20, $02 ; fairy
dd 0, 0
dw -4, -1 : db $E5, $00, $20, $02 ; apple
dd 0, 0
DynamicOAMTileOW_thin:
dw 0, 0 : db $0C, $00, $20, $00
dw 0, 8 : db $1C, $00, $20, $00
; dw 0, 0 : db $40, $00, $20, $00
; dw 0, 8 : db $50, $00, $20, $00
dw 0, 0 : db $CB, $00, $20, $00
dw 0, 8 : db $DB, $00, $20, $00
dw 0, 0 : db $E0, $00, $20, $00
dw 0, 8 : db $F0, $00, $20, $00
;dw 0, 0 : db $E5, $00, $20, $00
;dw 0, 8 : db $F5, $00, $20, $00
;dw 0, 0 : db $EE, $00, $20, $00
;dw 0, 8 : db $FE, $00, $20, $00
; add new slots above this line
dw 0, 0 : db $E3, $00, $20, $00 ; overflow slot
dw 0, 8 : db $F3, $00, $20, $00
; above this line, add slots that we want to draw to specific slots
dw 0, 0 : db $0B, $00, $20, $00 ; animated rupees slot
dw 0, 8 : db $1B, $00, $20, $00
dw 0, 0 : db $6B, $00, $20, $00 ; key
dw 0, 8 : db $7B, $00, $20, $00
dw 0, 0 : db $7C, $00, $20, $00 ; good bee
dw 0, 8 : db $F4, $00, $20, $00
DynamicOAMTileOW_full:
dw 0, 0 : db $0C, $00, $20, $02
dd 0, 0
; dw 0, 0 : db $40, $00, $20, $02
; dd 0, 0
dw 0, 0 : db $CB, $00, $20, $02
dd 0, 0
dw 0, 0 : db $E0, $00, $20, $02
dd 0, 0
;dw 0, 0 : db $E5, $00, $20, $02
;dd 0, 0
;dw 0, 0 : db $EE, $00, $20, $02
;dd 0, 0
; add new slots above this line
dw 0, 0 : db $A0, $00, $20, $02 ; overflow slot
dd 0, 0
; above this line, add slots that we want to draw to specific slots
dw 0, 0 : db $EA, $00, $20, $02 ; fairy
dd 0, 0
dw 0, 0 : db $E5, $00, $20, $02 ; apple
dd 0, 0
DynamicDropGFXClear:
PHA : PHX
LDX.b #$0E

View File

@@ -522,7 +522,6 @@ Setup_ShopItemCollisionHitbox:
!ADD ($00), Y
!ADD.w #$0002 ; a small negative margin
; TODO: add 4 for a narrow item
SEP #$20 ; set 8-bit accumulator
; store hitbox X