Merged in DR v1.4.1.6

This commit is contained in:
codemann8
2024-02-23 10:57:24 -06:00
235 changed files with 30100 additions and 17937 deletions

View File

@@ -1,100 +1,77 @@
; where we shove the decompressed graphics to send to WRAM
DynamicDropGFX = $7ECC00
; this will just count from 0 to 4 to determine which slot we're using
; we're expecting 5 items max per room, and order is irrelevant
; we just need to keep track of where they go
DynamicDropGFXIndex = $7E1E70
!DynamicDropGFXSlotCount_UW = (FreeUWGraphics_end-FreeUWGraphics)>>1
!DynamicDropGFXSlotCount_OW = (FreeOWGraphics_end-FreeOWGraphics)>>1
; this will keep track of the above for each item
SprItemGFX = $7E0780
; this is the item requested and a flag (we anticipate no more than 3 requests to be active, but built to support 8)
DynamicDropRequest = $7E1E71 ; bitfield indicating which request slot to process
DynamicDropQueue = $7E1E72 ; 0x08 bytes, occupies 1 byte for each slot in the request queue (loot id at first, but stores GFX index)
; Come in with
; A = item receipt ID
; X = sprite slot
RequestSlottedTile:
RequestStandingItemVRAMSlot:
PHX : PHY
PHA
LDA.b #$01 : STA.w !SPRITE_REDRAW, X
LDA.b #$01 : STA.w SprRedrawFlag, X
JSL Sprite_IsOnscreen : BCC ++
; skip sending the request if busy with other things
LDA.b $11 : CMP.b #$21 : BCS ++ ; skip if OW is loading Map16 GFX ; TODO: Figure out how to allow submodule 22, check DMA status instead
LDA.b $5D : CMP.b #$14 : BEQ ++ ; skip if we're mid-mirror
LDA.b $1B : BEQ + ; OW current doesn't occupy any slots that medallion gfx do
LDA.b GameSubMode : CMP.b #$21 : BCS ++ ; skip if OW is loading Map16 GFX ; TODO: Figure out how to allow submodule 22, check DMA status instead
LDA.b LinkState : CMP.b #$14 : BEQ ++ ; skip if we're mid-mirror
LDA.b IndoorsFlag : BEQ + ; OW current doesn't occupy any slots that medallion gfx do
CMP.b #$08 : BCC + : CMP.b #$0A+1 : BCS + ; skip if we're mid-medallion
++ PLA : JMP .return
+
LDA.w $0E20, X : CMP.b #$C0 : BNE + ; if catfish
LDA.w SpriteTypeTable, X : CMP.b #$C0 : BNE + ; if catfish
TYX
+ CMP.b #$52 : BNE + ; if zora
TYX
+
LDA.b 1,S : JSL.l GetSpritePalette : STA.w $0F50, X ; setup the palette
LDA.b 1,S : PHX : JSL GetSpritePalette : PLX : STA.w SpriteOAMProp, X ; setup the palette
PLA
; gfx that are already present, use that instead of a new slot
CMP.b #$34 : BCC + : CMP.b #$36+1 : BCS + ; if rupees, use animated rupee OAM slot
LDA.b $1B : BEQ ++
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : STA.w SprItemGFX,X
JMP .success
+ CMP.b #$A0 : BCC + : CMP.b #$AF+1 : BCS + ; if key, use key OAM slot
LDY.b $5D : CPY.b #$19 : BCC ++ : CPY.b #$1A+1 : BCS ++ ; if getting tablet item, don't use key slot
LDY.b LinkState : CPY.b #$19 : BCC ++ : CPY.b #$1A+1 : BCS ++ ; if getting tablet item, don't use key slot
BRA +
++
LDA.b $1B : BEQ ++
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : INC : STA.w SprItemGFX,X
+++ INC #2 : STA.w SprItemGFX,X
JMP .success
+ CMP.b #$B5 : BNE + ; if good bee, use bee OAM slot
LDA.b $1B : BEQ ++
+ CMP.b #$D6 : BNE + ; if good bee, use bee OAM slot
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : INC : INC : STA.w SprItemGFX,X
+++ INC #3 : STA.w SprItemGFX,X
JMP .success
+ CMP.b #$B2 : BNE + ; if fairy, use fairy OAM slot
LDA.b $1B : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : INC : STA.w SprItemGFX,X
JMP .success
+ CMP.b #$B1 : BNE + ; if apple, use apple OAM slot
LDA.b $1B : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : INC : INC : STA.w SprItemGFX,X
JMP .success
+ CMP.b #$6A : BNE + ; if triforce, use cutscene OAM slot
PHA
LDA.b $1B : BEQ ++
+ CMP.b #$D2 : BNE + ; if fairy, use fairy OAM slot
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC : STA.w SprItemGFX,X
JMP .initRequest ; don't jump to end, we need the TF GFX to draw at $E7
JMP .success
+ CMP.b #$D1 : BNE + ; if apple, use apple OAM slot
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
+++ INC #2 : STA.w SprItemGFX,X
JMP .success
+
PHA
LDA.w DynamicDropGFXIndex
INC
PHX
LDX.b $1B : BEQ +
LDX.b IndoorsFlag : BEQ +
CMP.b #!DynamicDropGFXSlotCount_UW : BCC .setIndex
BRA ++
+ CMP.b #!DynamicDropGFXSlotCount_OW : BCC .setIndex
@@ -107,11 +84,11 @@ RequestSlottedTile:
PHX
; loop thru other sprites, check if any use the same gfx slot
LDY.b #$0F
- TYA : CMP 1,S : BEQ + ; don't check self
LDA.w $0DD0,Y : BEQ +
LDA.w !SPRITE_REDRAW, Y : BNE +
- TYA : CMP.b 1,S : BEQ + ; don't check self
LDA.w SpriteAITable,Y : BEQ +
LDA.w SprRedrawFlag, Y : BNE +
LDA.w SprItemGFX,Y : CMP.w DynamicDropGFXIndex : BNE +
LDA.w $0E20,Y ; don't need E5 enemy big key drop and E9 powder item
LDA.w SpriteTypeTable,Y ; don't need E5 enemy big key drop and E9 powder item
CMP.b #$EB : BEQ ++ ; heart piece
CMP.b #$E4 : BEQ ++ ; enemy drop
CMP.b #$3B : BEQ ++ ; bonk item
@@ -119,8 +96,8 @@ RequestSlottedTile:
BRA +
++
; slot already in use, use overflow slot
LDA.b #$02 : STA.w !SPRITE_REDRAW, X
LDA.b $1B : BEQ ++
LDA.b #$02 : STA.w SprRedrawFlag, X
LDA.b IndoorsFlag : BEQ ++
LDA.b #!DynamicDropGFXSlotCount_UW
BRA +++
++ LDA.b #!DynamicDropGFXSlotCount_OW
@@ -129,110 +106,34 @@ RequestSlottedTile:
+ DEY : BPL -
PLX
.initRequest
PHX
LDY.b #$00
LDA.w DynamicDropRequest
- LSR : INY : BCS -
CPY.b #$08 : BCC +
; all request slots occupied, exit without drawing
PLX : PLA
LDY.b #$FE ; indicate failure
BRA .return
+ TYX
LDA.b #$00 : SEC
- ROL : DEX : BNE -
DEY ; y = slot index, a = new request bit flag
ORA.w DynamicDropRequest
STA.w DynamicDropRequest
PLX
.initRequest
PLA
STA.w DynamicDropQueue,Y
; decompress graphics
PHX : PHY
REP #$20
LDA.w #DynamicDropGFX-$7E9000
TYX : BEQ +
- CLC : ADC.w #$0080 : DEX : BNE -
+ STA.l !TILE_UPLOAD_OFFSET_OVERRIDE
SEP #$20
LDA.w DynamicDropQueue,Y
JSL.l GetSpriteID
JSL.l GetAnimatedSpriteTile_variable
PHX ;: PHY
; unsure about substitution rules here, because they aren't skipped properly for MW yet
JSL AttemptItemSubstitution
JSL ResolveLootIDLong
JSL ResolveBeeTrapLong
REP #$30
ASL : TAX
LDA.l StandingItemGraphicsOffsets,X : LDX.w ItemStackPtr : STA.l ItemGFXStack,X
LDA.w DynamicDropGFXIndex : AND.w #$000F : ASL : TAX
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.l FreeUWGraphics,X : BRA ++
+ LDA.l FreeOWGraphics,X
++ LDX.w ItemStackPtr : STA.l ItemTargetStack,X
TXA : INC #2 : STA.w ItemStackPtr
SEP #$30
PLY : PLX
LDA.w DynamicDropQueue,Y : PHA ; we want A to return the loot id
LDA.w SprItemGFX,X : STA.w DynamicDropQueue,Y
PLA
PLX
.success
STZ.w !SPRITE_REDRAW, X
STZ.w SprRedrawFlag, X
.return
PLY : PLX
RTL
;===================================================================================================
TransferPotGFX:
SEP #$10
REP #$20
LDA.w DynamicDropRequest : AND.w #$00FF
BEQ .no
.next
LDY.b #$00
- INY : LSR : BCC -
PHY
LDA.w #$0000
- ROL : DEY : BNE -
PLY
DEY ; y = slot index, a = request bit flag
EOR.w DynamicDropRequest : STA.w DynamicDropRequest
LDA.w DynamicDropQueue,Y
ASL
TAX
LDA.b $1B : AND.w #$00FF : BEQ +
LDA.l FreeUWGraphics,X
BRA ++
+ LDA.l FreeOWGraphics,X
++ STA.w $2116
; calculate bottom row now
CLC : ADC.w #$0200>>1 : PHA
LDX.b #$7E : STX.w $4314
LDA.w #DynamicDropGFX
CPY.b #$00 : BEQ +
- CLC : ADC.w #$0080 : DEY : BNE -
+ STA.w $4302
LDX.b #$80 : STX.w $2115
LDA.w #$1801 : STA.w $4300
LDA.w #$0040 : STA.w $4305
LDY.b #$01
STY.w $420B
STA.w $4305
PLA
STA.w $2116
STY.w $420B
LDA.w DynamicDropRequest : AND.w #$00FF
BNE .next
.no
RTL
FreeUWGraphics:
dw $8800>>1
dw $8840>>1
@@ -244,7 +145,6 @@ FreeUWGraphics:
; add new slots above this line
.end
dw $0000 ; overflow slot, intentionally blank
dw $9CE0>>1 ; Triforce
; above this line, add slots that we want to draw to specific slots
FreeOWGraphics:
@@ -257,7 +157,6 @@ FreeOWGraphics:
; add new slots above this line
.end
dw $0000 ; overflow slot, intentionally blank
dw $9CE0>>1 ; Triforce
; above this line, add slots that we want to draw to specific slots
;===================================================================================================
@@ -265,94 +164,103 @@ FreeOWGraphics:
; A = item receipt ID
; X = sprite slot
; Returns with Carry flag set if gfx drawing was skipped
DrawSlottedTile:
DrawPotItem:
PHA
; TODO: allow drawing if gfx are not using a VRAM slot that changes during medallion
LDA.b $5D : CMP.b #$08 : BCC + : CMP.b #$0A+1 : BCS + ; skip if we're mid-medallion
PLA : SEC : RTL
+
PLA
STA.b $07 ; store loot ID temporarily, will get overwritten in Sprite_DrawMultiple_quantity_preset call
JSL.l IsNarrowSprite : BCS .narrow
PHX
JSL AttemptItemSubstitution
JSL ResolveLootIDLong
TAX
LDA.l BeeTrapDisguise : BEQ +
TAX
+ STA.b Scrap07 ; store loot ID temporarily, will get overwritten in Sprite_DrawMultiple_quantity_preset call
LDA.l SpriteProperties_standing_width,X : BEQ .narrow
; TODO: Instead of loading the whole fixed 16 bytes from DynamicOAMTile**_** into !SPRITE_DYNAMIC_OAM
; 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
LDA.b #$01 : STA $06
LDA #$0C : JSL.l OAM_AllocateFromRegionC
LDA #$02 : PHA
PLX
LDA.b #$01 : STA.b Scrap06
LDA.b #$0C : JSL OAM_AllocateFromRegionC
LDA.b #$02 : PHA
REP #$20
LDA.b $1B : AND.w #$00FF : BEQ +
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.w #DynamicOAMTileUW_full
BRA .transfer
+ LDA.w #DynamicOAMTileOW_full
BRA .transfer
.narrow
LDA.b #$02 : STA $06
LDA #$10 : JSL.l OAM_AllocateFromRegionC
LDA #$03 : PHA
PLX
LDA.b #$02 : STA.b Scrap06
LDA.b #$10 : JSL OAM_AllocateFromRegionC
LDA.b #$03 : PHA
REP #$20
LDA.b $1B : AND.w #$00FF : BEQ +
LDA.b IndoorsFlag : AND.w #$00FF : BEQ +
LDA.w #DynamicOAMTileUW_thin
BRA .transfer
+ LDA.w #DynamicOAMTileOW_thin
.transfer
STA.b $08
STA.b Scrap08
LDA.w SprItemGFX,X
AND.w #$00FF
ASL : ASL : ASL : ASL
ADC.b $08
STA.b $08
PHK : PLY : STY.b $0A
LDY #$7E : PHB : PHY : PLB
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 !SPRITE_DYNAMIC_OAM,Y
- LDA.b [$08],Y : STA.w SpriteDynamicOAM,Y
DEY : DEY : BPL -
LDA.w SprItemFlags, X : AND.w #$00FF : BNE .draw
LDA.b $06 : LSR : BCC +
LDA.b Scrap06 : LSR : BCC +
; full
LDA.w #$0000
STA.w !SPRITE_DYNAMIC_OAM : STA.w !SPRITE_DYNAMIC_OAM+2
STA.w SpriteDynamicOAM : STA.w SpriteDynamicOAM+2
BRA .draw
+ ; narrow
LDA.w $0E20, X : AND.w #$00FF : CMP.w #$003B : BEQ .draw ; bonk item
LDA.b $A0 : CMP.w #$0120 : BNE +
LDA.b $1B : BNE .draw ; good bee statue
LDA.w SpriteTypeTable, X : AND.w #$00FF : CMP.w #$003B : BEQ .draw ; bonk item
LDA.b RoomIndex : CMP.w #$0120 : BNE +
LDA.b IndoorsFlag : BNE .draw ; good bee statue
+
; TODO: Figure out how to target bottle vendor fish item better than this
LDA.b $8A : AND.w #$00FF : CMP.w #$0018 : BNE +
LDA.b $1B : BEQ .draw ; bottle vendor key
LDA.b OverworldIndex : AND.w #$00FF : CMP.w #$0018 : BNE +
LDA.b IndoorsFlag : BEQ .draw ; bottle vendor key
+
LDA.w #$0004
STA.w !SPRITE_DYNAMIC_OAM : STA.w !SPRITE_DYNAMIC_OAM+8
STA.w SpriteDynamicOAM : STA.w SpriteDynamicOAM+8
.draw
; special handling
LDY.b $07 : CPY.b #$B2 : BNE + ; fairy
LDA.b $1A : AND.w #$0020 : BEQ ++ ; alternate every 32 frames
LDA.w !SPRITE_DYNAMIC_OAM+4 : CLC : ADC.w #$02 ; use other fairy GFX
STA.w !SPRITE_DYNAMIC_OAM+4
++ LDA.b $1A : SEC : SBC.w #$10 : AND.w #$0020 : BEQ + ; alternate every 32 frames
LDA.w !SPRITE_DYNAMIC_OAM+2 : SEC : SBC.w #$02 ; move fairy up 2 pixels
STA.w !SPRITE_DYNAMIC_OAM+2
LDY.b Scrap07 : CPY.b #$B2 : BNE + ; fairy
LDA.b FrameCounter : AND.w #$0020 : BEQ ++ ; alternate every 32 frames
LDA.w SpriteDynamicOAM+4 : CLC : ADC.w #$02 ; use other fairy GFX
STA.w SpriteDynamicOAM+4
++ LDA.b FrameCounter : SEC : SBC.w #$10 : AND.w #$0020 : BEQ + ; alternate every 32 frames
LDA.w SpriteDynamicOAM+2 : SEC : SBC.w #$02 ; move fairy up 2 pixels
STA.w SpriteDynamicOAM+2
+ CPY.b #$B5 : BNE + ; good bee
LDA.b $1A : AND.w #$0020 : BEQ ++ ; alternate every 32 frames
LDA.w !SPRITE_DYNAMIC_OAM+12 : SEC : SBC.w #$10 ; use other fairy GFX
STA.w !SPRITE_DYNAMIC_OAM+12
++ LDA.b $1A : SEC : SBC.w #$10 : AND.w #$0020 : BEQ + ; alternate every 32 frames
LDA.w !SPRITE_DYNAMIC_OAM+10 : SEC : SBC.w #$02 ; move fairy up 2 pixels
STA.w !SPRITE_DYNAMIC_OAM+10
LDA.b FrameCounter : AND.w #$0020 : BEQ ++ ; alternate every 32 frames
LDA.w SpriteDynamicOAM+12 : SEC : SBC.w #$10 ; use other fairy GFX
STA.w SpriteDynamicOAM+12
++ LDA.b FrameCounter : SEC : SBC.w #$10 : AND.w #$0020 : BEQ + ; alternate every 32 frames
LDA.w SpriteDynamicOAM+10 : SEC : SBC.w #$02 ; move fairy up 2 pixels
STA.w SpriteDynamicOAM+10
+
LDA.w #!SPRITE_DYNAMIC_OAM : STA.b $08
LDA.w #SpriteDynamicOAM : STA.b Scrap08
SEP #$20
STZ.b $07
LDA.b #$00 : STA.l !SKIP_EOR
STZ.b Scrap07
LDA.b #$00 : STA.l SpriteSkipEOR
JSL Sprite_DrawMultiple_quantity_preset
PLB
@@ -422,9 +330,6 @@ DynamicOAMTileUW_full:
dw -4, -1 : db $A0, $00, $20, $02 ; overflow slot
dd 0, 0
dw -4, -1 : db $E7, $00, $20, $02 ; triforce
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
@@ -492,9 +397,6 @@ DynamicOAMTileOW_full:
dw 0, 0 : db $A0, $00, $20, $02 ; overflow slot
dd 0, 0
dw 0, 0 : db $E7, $00, $20, $02 ; triforce
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
@@ -504,7 +406,7 @@ DynamicOAMTileOW_full:
dd 0, 0
ConditionalPushBlockTransfer:
LDA.b $1B : BNE +
LDA.b IndoorsFlag : BNE +
LDA.b #$0F ; don't transfer push block when on the OW
BRA .return-3
+
@@ -514,7 +416,7 @@ RTL
pushpc
; fix Arghuss/Zora splash graphics
org $068595
org $868595
db $E7, $E7, $E7, $E7, $E7, $C0, $C0
pullpc

View File

@@ -22,6 +22,9 @@ org $86F976
org $86E3C4
JSL RevealSpriteDrop2 : NOP
org $86F933
JSL PikitOverride
org $86926e ; <- 3126e - sprite_prep.asm : 2664 (LDA $0B9B : STA $0CBA, X)
JSL SpriteKeyPrep : NOP #2
@@ -40,13 +43,11 @@ org $86d180
org $86d18d ; <- 3518D - sprite_absorbable.asm : 274 (LDA $7EF36F : INC A : STA $7EF36F)
JSL KeyGet
org $86f9f3 ; bank06.asm : 6732 (JSL Sprite_LoadProperties)
org $86f9f3 ; bank06.asm : 6732 (JSL SpritePrep_LoadProperties)
JSL LoadProperties_PreserveCertainProps
org $808BAA ; NMI hook
JSL TransferPotGFX
org $86828A
Sprite_SpawnSecret_SpriteSpawnDynamically:
JSL CheckSprite_Spawn
org $87B169
@@ -73,67 +74,29 @@ org $8681F4
Sprite_SpawnSecret_pool_ID:
org $868283
Sprite_SpawnSecret_NotRandomBush:
org $86828A
Sprite_SpawnSecret_SpriteSpawnDynamically:
org $8682A5
Sprite_SpawnSecret_SetCoords:
org $86d23a
Sprite_DrawAbsorbable:
org $9eff81
Sprite_DrawRippleIfInWater:
org $8db818
Sprite_LoadProperties:
org $86D038
KeyRoomFlagMasks:
org $80FDEE
InitializeMirrorHDMA:
org $80E3C4
LoadCommonSprites_long:
; defines
; Ram usage
SpawnedItemID = $7E0720 ; 0x02
SpawnedItemIndex = $7E0722 ; 0x02
SpawnedItemIsMultiWorld = $7E0724 ; 0x02
SpawnedItemFlag = $7E0726 ; 0x02 - one for pot, 2 for sprite drop
; (flag used as a bitmask in conjunction with StandingItemCounterMask)
SpawnedItemMWPlayer = $7E0728 ; 0x02
; clear all of them in a loop during room load
SprDropsItem = $7E0730 ; 0x16
SprItemReceipt = $7E0740 ; 0x16
SprItemIndex = $7E0750
SprItemMWPlayer = $7E0760 ; 0x16
SprItemFlags = $7E0770 ; 0x16 (used for both pots and drops) (combine with SprDropsItem?)
org $89D62E
UWSpritesPointers: ; 0x250 bytes for 0x128 rooms' 16-bit pointers
; todo: move sprites
;org $09D62E
;UWSpritesPointers ; 0x250 bytes for 0x128 rooms' 16-bit pointers
;org $09D87E
;UWPotsPointers ; 0x250 bytes for 0x128 rooms' 16-bit pointers
;org $09DACE
;UWPotsData ; variable number of bytes (max 0x11D1) for all pots data
;org $A88000
;UWSpritesData ; variable number of bytes (max 0x2800) for all sprites and sprite drop data
; First $2800 bytes of this bank (28) is reserved for the sprite tables
;org $09C297
;LDA.w UWSpritesPointers,Y
;org $01E6BF ; not sure this code is reachable anymore
;LDA.l UWPotsPointers,X
;STA.b $00
;LDA.w #UWPotsPointers>>16
; $2800 bytes reserved for sprites
; temporary pot table until sprites get moved:
org $A88000
org $89D87E
UWPotsPointers: ; 0x250 bytes for 0x128 rooms' 16-bit pointers
org $A88250
UWPotsData:
org $89DACE
UWPotsData: ; variable number of bytes (max 0x11D1) for all pots data
org $A88000
UWSpritesData: ; variable number of bytes (max 0x2800) for all sprites and sprite drop data
; First $2800 bytes of this bank (28) is reserved for the sprite tables
; $2800 bytes reserved for sprites
org $A8A800
;tables:
@@ -161,17 +124,67 @@ PotCollectionRateTable:
; Reserved $250 296 * 2
org $A8ACB0
UWEnemyItemFlags:
; Reserved $250 296 * 2
org $A8AF00
UWSpecialFlagIndex:
; Reserved $128 (296)
; Initial table indexed by room id
; Special values: $FF indicates the room can use the UWEnemyItemFlags table
; Any other value tell you where to start in the special table
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF
org $A8B028
UWSpecialFlag:
; reserved exactly $100 or 256 bytes for now estimated usage is at 159 bytes right now
; Simple mask table, 3 bytes per entry: 1st byte what dungeon it applies, if $FF, then the list is done
; Lists that has even numbers of entries will end with $FF $FF to keep everything 2 byte aligned
; (if not matched, assume mask of value 0)
; 2nd and 3rd bytes are the mask
; For indicator idea:
; EOR between a mask and the equivalent SRAM should result in zero if all items are obtained
; For whether to spawn:
; $FF indicates a spawn without further checking, otherwise need to check the mask in the simple table
; this should be checked in addition to SRAM
org $A8B128
RevealPotItem:
STA.b $04 ; save tilemap coordinates
STA.b Scrap04 ; save tilemap coordinates
STZ.w SpawnedItemFlag
STZ.w SpawnedItemMWPlayer
LDA.w $0B9C : AND.w #$FF00 : STA.w $0B9C
LDA.b $A0 : ASL : TAX
LDA.b RoomIndex : ASL : TAX
LDA.l UWPotsPointers,X : STA.b $00 ; we may move this
LDA.w #UWPotsPointers>>16 : STA.b $02
LDA.l UWPotsPointers,X : STA.b Scrap00 ; we may move this
LDA.w #UWPotsPointers>>16 : STA.b Scrap02
LDY.w #$FFFD : LDX.w #$FFFF
@@ -183,40 +196,41 @@ RevealPotItem:
INX
STA.w $08 ; remember the exact value
STA.w Scrap08 ; remember the exact value
AND.w #$3FFF
CMP.b $04 : BNE .next_pot ; not the correct value
CMP.b Scrap04 : BNE .next_pot ; not the correct value
STZ.w SpawnedItemIsMultiWorld
BIT.b $08
BIT.b Scrap08
BVS LoadMultiWorldPotItem
BMI LoadMajorPotItem
.normal_secret
STA $08
STA.b Scrap08
PHX : PHY
; set bit and count if first time lifting this pot
TXA : ASL : TAX : LDA.l BitFieldMasks, X : STA $0A
LDA.b $A0 : ASL : TAX
TXA : ASL : TAX : LDA.l BitFieldMasks, X : STA.b Scrap0A
LDA.b RoomIndex : ASL : TAX
JSR ShouldCountNormalPot : BCC .obtained
LDA.l RoomPotData, X : BIT $0A : BNE .obtained
ORA $0A : STA RoomPotData, X
LDA.l RoomPotData, X : BIT.b Scrap0A : BNE .obtained
ORA.b Scrap0A : STA.l RoomPotData, X
; increment dungeon counts
SEP #$30
LDA $040C : CMP #$FF : BEQ +
BNE ++
INC #2 ; treat sewers as HC
++ LSR : TAX : LDA DungeonLocationsChecked, X : INC : STA DungeonLocationsChecked, X
SEP #$10
LDX.w DungeonID : CPX.b #$FF : BEQ +
CPX.b #$00 : BNE ++
INX #2 ; treat sewers as HC
++ LDA.l DungeonLocationsChecked, X : INC : STA.l DungeonLocationsChecked, X
; Could increment GT Tower Pre Big Key but we aren't showing that stat right now
+ REP #$30
LDA TotalItemCounter : INC : STA TotalItemCounter ; Increment Item Total
+ REP #$10
LDA.l TotalItemCounter : INC : STA.l TotalItemCounter ; Increment Item Total
INC.w UpdateHUDFlag
.obtained
PLY : PLX
PLA ; remove the JSL return lower 16 bits
LDA $08
PEA.w $01E6E2-1 ; change return address to go back to the vanilla routine
LDA.b Scrap08
PEA.w RevealPotItem_found_match-1 ; return to vanilla routine
.exit
RTL
@@ -260,34 +274,34 @@ SaveMajorItemDrop:
LDA.w #$0018 : BRA .substitute
+ CPY.w #$0031 : BNE + ; 10 pack bombs
LDA.w #$0019 : BRA .substitute
+ CPY.w #$00B1 : BNE + ; Apples
+ CPY.w #$00D1 : BNE + ; Apples
LDA.w #$001A : BRA .substitute
+ CPY.w #$00B0 : BNE + ; Bee Trap
+ CPY.w #$00D0 : BNE + ; Bee Trap
LDA.w #$001B : BRA .substitute
+ CPY.w #$00B5 : BNE + ; Good Bee
+ CPY.w #$00D6 : BNE + ; Good Bee
LDA.w #$001C : BRA .substitute
+ STA $0B9C ; indicates we should use the key routines or a substitute
+ STA.w $0B9C ; indicates we should use the key routines or a substitute
RTL
.substitute
PHA
TXA : ASL : STA.b $00
LDA.w #$001F : SBC $00
TAX : LDA.l BitFieldMasks, X : STA $00
LDA.b $A0 : ASL : TAX
TXA : ASL : STA.b Scrap00
LDA.w #$001F : SBC.b Scrap00
TAX : LDA.l BitFieldMasks, X : STA.b Scrap00
LDA.b RoomIndex : ASL : TAX
LDA.l $7EF580, X
AND.b $00
AND.b Scrap00
BNE .exit
LDA.l $7EF580, X : ORA $00 : STA.l $7EF580, X
PLA : STA $0B9C
LDA.l $7EF580, X : ORA.b Scrap00 : STA.l $7EF580, X
PLA : STA.w $0B9C
RTL
.exit
PLA : STZ.w $0B9C
RTL
ShouldCountNormalPot:
INY : INY : LDA [$00], Y : AND #$00FF : CMP #$0080 : BCS .clear
INY : INY : LDA.b [$00], Y : AND.w #$00FF : CMP.w #$0080 : BCS .clear
LDA.l PotCountMode : BEQ .clear
LDA.l PotCollectionRateTable, X : BIT $0A : BEQ .clear ; don't count if clear
LDA.l PotCollectionRateTable, X : BIT.b Scrap0A : BEQ .clear ; don't count if clear
.set
SEC
RTS
@@ -297,222 +311,399 @@ RTS
IncrementCountsForSubstitute:
PHX : REP #$30
LDA.w SpawnedItemIndex : ASL : TAX : LDA.l BitFieldMasks, X : STA $0A
LDA.b $A0 : ASL : TAX
LDA.l RoomPotData, X : BIT $0A : BNE .obtained
ORA $0A : STA RoomPotData, X
SEP #$30
LDA $040C : CMP #$FF : BEQ +
BNE ++
INC #2 ; treat sewers as HC
++ LSR : TAX : LDA DungeonLocationsChecked, X : INC : STA DungeonLocationsChecked, X
LDA.w SpawnedItemIndex : ASL : TAX : LDA.l BitFieldMasks, X : STA.b Scrap0A
LDA.b RoomIndex : ASL : TAX
LDA.l RoomPotData, X : BIT.b Scrap0A : BNE .obtained
ORA.b Scrap0A : STA.l RoomPotData, X
SEP #$10
LDX.w DungeonID : CPX.b #$FF : BEQ +
CPX.b #$00 : BNE ++
INX #2 ; treat sewers as HC
++ LDA.l DungeonLocationsChecked, X : INC : STA.l DungeonLocationsChecked, X
; Could increment GT Tower Pre Big Key but we aren't showing that stat right now
+ REP #$30
LDA TotalItemCounter : INC : STA TotalItemCounter ; Increment Item Total
+
LDA.l TotalItemCounter : INC : STA.l TotalItemCounter ; Increment Item Total
INC.w UpdateHUDFlag
.obtained
SEP #$30 : PLX
RTS
ClearSpriteData:
STZ.b $02 : STZ.b $03 ; what we overrode
STZ.b Scrap03 ; what we overrode # we no longer need STZ $02 see underworld_sprite_hooks
.shared:
PHX
LDA #$00 : LDX #$00
LDA.b #$00 : LDX.b #$00
.loop
STA SprDropsItem, X : STA SprItemReceipt, X : STA SprItemIndex, X
STA SprItemMWPlayer, X : STA SprItemFlags, X
INX : CPX #$10 : BCC .loop
STA.w SprDropsItem, X : STA.w SprItemReceipt, X : STA.w SprItemIndex, X
STA.w SprItemMWPlayer, X : STA.w SprItemFlags, X
INX : CPX.b #$10 : BCC .loop
JSR SetupEnemyDropIndicator
PLX
RTL
ClearSpriteData2:
LDA.b #$82 : STA.b $99
LDA.b #$82 : STA.b CGWSELQ
JMP ClearSpriteData_shared
; this routine determines whether enemies still have drops or not
; and sets EnemyDropIndicator appropriately
; uses X register, assumes flags are (MX) but (mX) is fine
SetupEnemyDropIndicator:
REP #$20
LDA.w #!BlankTile : STA.w EnemyDropIndicator
LDX.b IndoorsFlag : BEQ .done
; do we have a flag for enemy drops on? could check it here
LDA.w DungeonID : AND.w #$00FF : CMP.w #$00FF : BEQ .skipCompassChecks
; compass checks
; does compass for dungeon exist?
LSR : TAX : LDA.l ExistsTransfer, X : TAX : LDA.l CompassExists, X : BEQ .skipCompassChecks
; do we have the compass
; todo: sewers?
LDA.l CompassField : LDX.w DungeonID : AND.l DungeonMask, X : BEQ .done
.skipCompassChecks
; either we're in a cave ($040C: $FF), compass doesn't exist, or we have the compass
; check if there are enemy drops
LDA.b Scrap02 : PHA : REP #$10 ; store 02/03 for later
LDX.b RoomIndex : LDA.l UWSpecialFlagIndex, X : AND.w #$00FF ; determine if special case or not
CMP.w #$00FF : BEQ .loadNormalFlags
JSR FetchBitmaskForSpecialCase
PHA : LDA.b RoomIndex : ASL : TAX : PLA
BRA .testAgainstMask
.loadNormalFlags
TXA : ASL : TAX : LDA.l UWEnemyItemFlags, X
.testAgainstMask
STA.b Scrap02 : LDA.l SpriteDropData, X : AND.b Scrap02 : EOR.b Scrap02
BEQ .cleanup
LDA.w #!BlueSquare : STA.w EnemyDropIndicator
.cleanup
SEP #$10 : PLA : STA.b Scrap02
.done
SEP #$20
RTS
; Runs during sprite load of the room
LoadSpriteData:
INY : INY
LDA.b ($00), Y
CMP #$F3 : BCC .normal
LDA.b [$00], Y
CMP.b #$F3 : BCC .normal
PHA
DEC.b $02 ; standing items shouldn't consume a sprite slot
LDX.b $02
CMP #$F9 : BNE .not_multiworld
DEY : LDA.b ($00), Y : STA.l SprItemMWPlayer, X
LDA.b #$02 : STA.l SprDropsItem, X : BRA .common
DEC.b Scrap03 ; standing items shouldn't consume a sprite slot
LDX.b Scrap03 ; these were changed to $03, for moved sprites
CMP.b #$F9 : BNE .not_multiworld
DEY : LDA.b [$00], Y : STA.w SprItemMWPlayer, X
LDA.b #$02 : STA.w SprDropsItem, X : BRA .common
.not_multiworld
LDA.b #$00 : STA.l SprItemMWPlayer, X
LDA.b #$01 : STA.l SprDropsItem, X
LDA.b #$00 : STA.w SprItemMWPlayer, X
LDA.b #$01 : STA.w SprDropsItem, X
DEY
.common
DEY : LDA.b ($00), Y : STA.l SprItemReceipt, X
DEY : LDA.b [$00], Y : STA.w SprItemReceipt, X
STA.b Scrap0E
LDA.w SprItemMWPlayer, X : BNE + ; skip if multiworld
PHX
LDX.b #$00 ; see if the item should be replaced by an absorbable
- CPX.b #$1A : BCS .done
LDA.l MinorForcedDrops, X
CMP.b Scrap0E : BEQ ++
INX #2 : BRA -
++ PLX : LDA.w SprItemFlags, X : ORA.b #$80 : STA.w SprItemFlags, X : PHX
.done PLX
+
INY : INY
PLA
PLA : PLA ; remove the JSL return lower 16 bits
PEA.w $09C344-1 ; change return address to exit from Underworld_LoadSingleSprite
PEA.w $89C344-1 ; change return address to exit from Underworld_LoadSingleSprite
RTL
.normal
RTL
; Run when a sprite dies ... Sets Flag to #$02 and Index to sprite slot for
RevealSpriteDrop:
LDA.l SprDropsItem, X : BEQ .normal
LDA #$02 : STA.l SpawnedItemFlag
LDA.w SprDropsItem, X : BNE CheckIfDropValid
JMP DoNormalDrop
CheckIfDropValid:
LDA.w SprItemFlags, X : BIT.b #$80 : BNE .do_the_drop ; it's a minor item
JSR CheckIfDropsInThisLocation : BCC DoNormalDrop
.do_the_drop
;This section sets up the drop
LDA.b #$02 : STA.w SpawnedItemFlag
STX.w SpawnedItemIndex
LDA.l SprItemReceipt, X : STA SpawnedItemID
LDA.l SprItemMWPlayer, X : STA SpawnedItemMWPlayer
LDA.w SprItemReceipt, X : STA.w SpawnedItemID
LDA.w SprItemMWPlayer, X : STA.w SpawnedItemMWPlayer
LDY.b #$01 ; trigger the small key routines
LDA SpawnedItemID : CMP #$32 : BNE +
LDA.w SpawnedItemID : STA.b Scrap00 : CMP.b #$32 : BNE +
LDA.l StandingItemsOn : BNE +
INY ; big key routine
+ RTL ; unstun if stunned
.normal
LDY.w $0CBA, X : BEQ .no_forced_drop
+
PHX
LDA.w SpawnedItemMWPlayer : BNE .done ; abort check for absorbables it belong to someone else
LDX.b #$00 ; see if the item should be replaced by an absorbable
- CPX.b #$1A : BCS .done
LDA.l MinorForcedDrops, X
CMP.b Scrap00 : BNE +
INX : LDA.l MinorForcedDrops, X : STA.b Scrap00
PLX : PLA : PLA : PEA.w PrepareEnemyDrop-1 ; change call stack for PrepareEnemyDrop
JSR IncrementCountForMinor
LDA.b Scrap00 : RTL
+ INX #2 : BRA -
.done PLX
RTL ; unstun if stunned
DoNormalDrop:
SEP #$30
LDY.w SpriteForceDrop, X : BEQ .no_forced_drop
RTL
.no_forced_drop
PLA : PLA ; remove the JSL return lower 16 bits
PEA.w $06F996-1 ; change return address to .no_forced_drop of (Sprite_DoTheDeath)
PEA.w $86F996-1 ; change return address to .no_forced_drop of (Sprite_DoTheDeath)
RTL
RevealSpriteDrop2:
LDY.w SprDropsItem, X : BEQ .normal
BRA .no_forced_drop
.normal
LDY.w $0CBA, X : BEQ .no_forced_drop
LDY.w SpriteForceDrop, X : BEQ .no_forced_drop
RTL
.no_forced_drop
PLA : PLA ; remove the JSL return lower 16 bits
PEA.w $06E3CE-1 ; change return address to .no_forced_drop of (Sprite_DoTheDeath)
PEA.w $86E3CE-1 ; change return address to .no_forced_drop of (Sprite_DoTheDeath)
RTL
PikitOverride:
CMP.b #$AA : BNE .no_pikit_drop
LDY.w $0E90,X : BEQ .no_pikit_drop
CPY.b #$04 : BEQ .normal_pikit
LDA.w SprDropsItem, X : BEQ .normal_pikit
JSR CheckIfDropsInThisLocation : BCC .normal_pikit
.no_pikit_drop
PLA : PLA : PEA.w Sprite_DoTheDeath_NotAPikitDrop-1
RTL
.normal_pikit
PLA : PLA : PEA.w Sprite_DoTheDeath_PikitDrop-1
RTL
; output - carry clear if the enemy doesn't drop, set if it does
CheckIfDropsInThisLocation:
REP #$30 : PHX ; save it for later
TXA : ASL : TAX : LDA.l BitFieldMasks, X : STA.b Scrap00 ; stores the bitmask for the specific drop
; check sram, if gotten, run normal
LDA.b RoomIndex : ASL : TAX : LDA.l SpriteDropData, X : PLX ; restore X in case we're done
BIT.b Scrap00 : BNE .normal_drop ; zero indicates the item has not been obtained
PHX ; save it for later
LDX.b RoomIndex : LDA.l UWSpecialFlagIndex, X : AND.w #$00FF
CMP.w #$00FF : BEQ + ; $FF indicates the EnemyItemFlags are sufficient
JSR FetchBitmaskForSpecialCase
BRA .test
+ TXA : ASL : TAX : LDA.l UWEnemyItemFlags, X
.test PLX : BIT.b Scrap00 : BEQ .normal_drop ; zero indicates the enemy doesn't drop
.valid
SEP #$30 : SEC
RTS
.normal_drop
SEP #$30 : CLC
RTS
; input - A the index from UWSpecialFlagIndex
; uses X for loop, $02 for comparing first byte to dungeon
; output - A the correct bitmask
FetchBitmaskForSpecialCase:
ASL : TAX
LDA.w DungeonID : BNE + ; here and branch to different function?
INC #2 ; move sewers to HC
+ CMP.w #$00FF : BNE + ; check if we are in a cave
LDA.l PreviousOverworldDoor : AND.w #$00FF ; use this instead of dungeon id
+ STA.b Scrap02
- LDA.l UWSpecialFlag, X : AND.w #$00FF
CMP.w #$00FF : BNE + ; if the value is FF we are done, use 0 as bitmask
LDA.w #$0000 : RTS
+ CMP.b Scrap02 : BNE + ; if the value matches the dungeon, use next 2 bytes as bitmask
INX : LDA.l UWSpecialFlag, X : RTS
+ INX #3 : BRA - ; else move to the next row
MinorForcedDrops:
; Item ID -> Sprite ID
db $27, $DC ; BOMB REFILL 1
db $28, $DD ; BOMB REFILL 4
db $31, $DE ; BOMB REFILL 8
db $34, $D9 ; GREEN RUPEE ($34)
db $35, $DA ; BLUE RUPEE ($35)
db $36, $DB ; RED RUPEE ($36)
db $42, $D8 ; HEART ($42)
db $44, $E2 ; ARROW REFILL 10 ($44)
db $45, $DF ; SMALL MAGIC DECANTER ($45)
db $D2, $E3 ; FAERIE ($D2)
db $D3, $0B ; CUCCO ($D3)
db $D4, $E0 ; LARGE MAGIC DECANTER ($D4)
db $D5, $E1 ; ARROW REFILL 5 (x$D5)
IncrementCountForMinor:
PHX : REP #$30
LDA.w SpawnedItemIndex : ASL : TAX : LDA.l BitFieldMasks, X : STA.b Scrap0A
LDA.b RoomIndex : ASL : TAX
LDA.l SpriteDropData, X : BIT.b Scrap0A : BNE .obtained
ORA.b Scrap0A : STA.l SpriteDropData, X
SEP #$10
JSR SetupEnemyDropIndicator
REP #$20
LDX.w DungeonID : CPX.b #$FF : BEQ +
CPX.b #$00 : BNE ++
INX #2 ; treat sewers as HC
++ LDA.l DungeonLocationsChecked, X : INC : STA.l DungeonLocationsChecked, X
; Could increment GT Tower Pre Big Key but we aren't showing that stat right now
+
LDA.l TotalItemCounter : INC : STA.l TotalItemCounter ; Increment Item Total
INC.w UpdateHUDFlag
.obtained
SEP #$30 : PLX
RTS
BitFieldMasks:
dw $8000, $4000, $2000, $1000, $0800, $0400, $0200, $0100
dw $0080, $0040, $0020, $0010, $0008, $0004, $0002, $0001
; Runs during Sprite_E4_SmallKey and during Sprite_E5_BigKey spawns
ShouldSpawnItem:
LDA $048E : CMP.b #$87 : BNE + ; check for hera basement cage
LDA $A8 : AND.b #$03 : CMP.b #$02 : BNE + ; we're not in that quadrant
LDA.w $0403 : AND.w KeyRoomFlagMasks,Y : RTL
LDA.w RoomIndexMirror : CMP.b #$87 : BNE + ; check for hera basement cage
CPX.b #$0A : BNE + ; the hera basement key is always sprite 0x0A
LDA.b $A8 : AND.b #$03 : CMP.b #$02 : BNE + ; we're not in that quadrant
LDA.w RoomItemsTaken : AND.w KeyRoomFlagMasks,Y : RTL
+
; checking our sram table
PHX : PHY
REP #$30
LDA.b $A0 : ASL : TAY
LDA.w SprItemIndex, X : AND #$00FF : ASL
LDA.b RoomIndex : ASL : TAY
LDA.w SprItemIndex, X : AND.w #$00FF : ASL
PHX
TAX : LDA.l BitFieldMasks, X : STA $00
TAX : LDA.l BitFieldMasks, X : STA.b Scrap00
PLX ; restore X again
LDA.w SprItemFlags, X : AND #$00FF : CMP #$0001 : BEQ +
TYX : LDA.l SpritePotData, X : BIT $00 : BEQ .notObtained
LDA.w SprItemFlags, X : BIT.w #$0001 : BNE +
TYX : LDA.l SpriteDropData, X : BIT.b Scrap00 : BEQ .notObtained
BRA .obtained
+ TYX : LDA.l RoomPotData, X : BIT $00 : BEQ .notObtained
+ TYX : LDA.l RoomPotData, X : BIT.b Scrap00 : BEQ .notObtained
.obtained
SEP #$30 : PLY : PLX : LDA #$01 : RTL ; already obtained
SEP #$30 : PLY : PLX : LDA.b #$01 : RTL ; already obtained
.notObtained
SEP #$30 : PLY : PLX
LDA #$00
LDA.b #$00
RTL
MarkSRAMForItem:
LDA $048E : CMP.b #$87 : BNE + ; check for hera basement cage
LDA $A8 : AND.b #$03 : CMP.b #$02 : BNE +
LDA.w $0403 : ORA.w KeyRoomFlagMasks, Y : RTL
LDA.b RoomIndex : CMP.b #$87 : BNE + ; check for hera basement cage
CPX.b #$0A : BNE + ; the hera basement key is always sprite 0x0A
LDA.b $A8 : AND.b #$03 : CMP.b #$02 : BNE +
LDA.w RoomItemsTaken : ORA.w KeyRoomFlagMasks, Y : RTL
+ PHX : PHY : REP #$30
LDA.b $A0 : ASL : TAY
LDA.l SpawnedItemIndex : ASL
TAX : LDA.l BitFieldMasks, X : STA $00
LDA.b RoomIndex : ASL : TAY
LDA.w SpawnedItemIndex : ASL
TAX : LDA.l BitFieldMasks, X : STA.b Scrap00
TYX
LDA.w SpawnedItemFlag : CMP #$0001 : BEQ +
LDA SpritePotData, X : ORA $00 : STA SpritePotData, X : BRA .end
+ LDA RoomPotData, X : ORA $00 : STA RoomPotData, X
LDA.w SpawnedItemFlag : CMP.w #$0001 : BEQ +
LDA.l SpriteDropData, X : ORA.b Scrap00 : STA.l SpriteDropData, X
SEP #$10 : JSR SetupEnemyDropIndicator
BRA .end
+ LDA.l RoomPotData, X : ORA.b Scrap00 : STA.l RoomPotData, X
.end
SEP #$30 : PLY : PLX
LDA.w $0403
LDA.w RoomItemsTaken
RTL
SpriteKeyPrep:
LDA.w $0B9B : STA.w $0CBA, X ; what we wrote over
LDA.w $0B9B : STA.w SpriteForceDrop, X ; what we wrote over
PHA
LDA $A0 : CMP #$87 : BNE .continue
LDA $A9 : ORA $AA : AND #$03 : CMP #$02 : BNE .continue
LDA #$00 : STA.w SpawnedItemFlag : STA SprItemFlags, X
LDA #$24 : STA $0E80, X
BRA +
LDA.b RoomIndex : CMP.b #$87 : BNE .continue
CPX.b #$0A : BNE .continue ; the hera basement key is always sprite 0x0A
LDA.b LinkQuadrantH : ORA.b LinkQuadrantV : AND.b #$03 : CMP.b #$02 : BNE .continue
LDA.b #$00 : STA.w SpawnedItemFlag : STA.w SprItemFlags, X
LDA.b #$24 : STA.w SpriteItemType, X
BRA +
.continue
LDA.w SpawnedItemIndex : STA SprItemIndex, X
LDA.w SpawnedItemMWPlayer : STA SprItemMWPlayer, X
LDA.w SpawnedItemFlag : STA SprItemFlags, X : BEQ +
LDA.l SpawnedItemID : STA $0E80, X
LDA.w SpawnedItemIndex : STA.w SprItemIndex, X
LDA.w SpawnedItemMWPlayer : STA.w SprItemMWPlayer, X : STA.w !MULTIWORLD_SPRITEITEM_PLAYER_ID
LDA.w SpawnedItemFlag : STA.w SprItemFlags, X : BEQ +
LDA.w SpawnedItemID : STA.w SpriteItemType, X
PHA : PHY : PHX
JSL GetSpritePalette : PLX : STA.w SpriteOAMProp, X ; setup the palette
PLY : PLA
CMP #$24 : BNE ++ ;
JSL.l GetSpritePalette : STA.w $0F50, X ; setup the palette
LDA $A0 : CMP.b #$80 : BNE +
LDA SpawnedItemFlag : BNE +
LDA #$24 ; it's the big key drop?
++ JSL RequestSlottedTile
PHX : JSL GetSpritePalette : PLX : STA.w SpriteOAMProp, X ; setup the palette
LDA.b RoomIndex : CMP.b #$80 : BNE +
LDA.w SpawnedItemFlag : BNE +
LDA.b #$24 ; it's the big key drop?
++ JSL RequestStandingItemVRAMSlot
+ PLA
RTL
SpriteKeyDrawGFX:
JSL Sprite_DrawRippleIfInWater
PHA
LDA.w !SPRITE_REDRAW, X : BEQ +
LDA $0E80, X
JSL RequestSlottedTile
LDA.w !SPRITE_REDRAW, X : CMP.b #$02 : BEQ +
JSL Sprite_DrawRippleIfInWater
PHA
LDA.l SprItemMWPlayer, X : STA.w !MULTIWORLD_SPRITEITEM_PLAYER_ID
LDA.w SprRedrawFlag, X : BEQ +
LDA.w SpriteItemType, X
JSL RequestStandingItemVRAMSlot
LDA.w SprRedrawFlag, X : CMP.b #$02 : BEQ +
BRA .skipDraw
+ LDA $0E80, X
+ LDA.w SpriteItemType, X
CMP.b #$24 : BNE +
LDA $A0 : CMP #$80 : BNE ++
LDA SpawnedItemFlag : BNE ++
LDA #$24 : BRA +
LDA.b RoomIndex : CMP.b #$80 : BNE ++
LDA.w SpawnedItemFlag : BNE ++
LDA.b #$24 : BRA +
++ PLA
PHK : PEA.w .jslrtsreturn-1
PEA.w $068014 ; an rtl address - 1 in Bank06
PEA.w $868014 ; an rtl address - 1 in Bank06
JML Sprite_DrawAbsorbable
.jslrtsreturn
RTL
+ JSL DrawSlottedTile : BCS .skipDraw
+ JSL DrawPotItem : BCS .skipDraw
; draw shadow
CMP #$03 : BNE +
PHA : LDA $0E60, X : ORA.b #$20 : STA $0E60, X : PLA
+ JSL.l Sprite_DrawShadowLong
CMP.b #$03 : BNE +
PHA : LDA.w SpriteControl, X : ORA.b #$20 : STA.w SpriteControl, X : PLA
+ JSL Sprite_DrawShadowLong
.skipDraw
PLA
RTL
PLA : RTL
KeyGet:
LDA CurrentSmallKeys ; what we wrote over
LDA.l CurrentSmallKeys ; what we wrote over
PHA
LDA.l StandingItemsOn : BNE +
PLA : RTL
+ LDY $0E80, X
LDA SprItemIndex, X : STA SpawnedItemIndex
LDA SprItemFlags, X : STA SpawnedItemFlag
LDA $A0 : CMP #$87 : BNE + ;check for hera cage
LDA SpawnedItemFlag : BNE + ; if it came from a pot, it's fine
+ LDY.w SpriteItemType, X
LDA.w SprItemIndex, X : STA.w SpawnedItemIndex
LDA.w SprItemFlags, X : STA.w SpawnedItemFlag
LDA.b RoomIndex : CMP.b #$87 : BNE + ;check for hera cage
LDA.w SpawnedItemFlag : BNE + ; if it came from a pot, it's fine
JSR ShouldKeyBeCountedForDungeon : BCC ++
JSL CountChestKeyLong
++ PLA : RTL
+ STY $00
LDA SprItemMWPlayer, X : STA !MULTIWORLD_ITEM_PLAYER_ID : BNE .receive
+ STY.b Scrap00
LDA.w SprItemMWPlayer, X : STA.l !MULTIWORLD_ITEM_PLAYER_ID : BNE .receive
PHX
LDA $040C : CMP #$FF : BNE +
LDA $00 : CMP.b #$AF : BNE .skip
LDA CurrentGenericKeys : INC : STA CurrentGenericKeys
LDA $00 : BRA .countIt
LDA.w DungeonID : CMP.b #$FF : BNE +
LDA.b Scrap00 : CMP.b #$AF : BNE .skip
LDA.l CurrentGenericKeys : INC : STA.l CurrentGenericKeys
LDA.b Scrap00 : BRA .countIt
+ LSR : TAX
LDA $00 : CMP.l KeyTable, X : BNE +
LDA.b Scrap00 : CMP.l KeyTable, X : BNE +
.countIt
LDA.l StandingItemCounterMask : AND SpawnedItemFlag : BEQ ++
JSL.l FullInventoryExternal : JSL CountChestKeyLong
LDA.l StandingItemCounterMask : AND.w SpawnedItemFlag : BEQ ++
JSL AddInventory
++ PLX : PLA : RTL
+ CMP.b #$AF : beq .countIt ; universal key
CMP.b #$24 : beq .countIt ; small key for this dungeon
.skip PLX
.receive
JSL $0791b3 ; Player_HaltDashAttackLong
JSL.l Link_ReceiveItem
JSL Player_HaltDashAttackLong
TYA : JSL.l AttemptItemSubstitution : JSL.l ResolveLootIDLong : TAY
JSL Link_ReceiveItem
PLA : DEC : RTL
KeyTable:
@@ -521,32 +712,32 @@ db $A0, $A0, $A2, $A3, $A4, $A5, $A6, $A7, $A8, $A9, $AA, $AB, $AC, $AD
; Input Y - the item type
ShouldKeyBeCountedForDungeon:
PHX
LDA $040C : CMP #$FF : BEQ .done
LDA.w DungeonID : CMP.b #$FF : BEQ .done
LSR : TAX
TYA : cmp KeyTable, X : BNE +
- PLX : SEC : RTS
+ CMP.B #$24 : BEQ -
+ CMP.b #$24 : BEQ -
.done
PLX : CLC : RTS
BigKeyGet:
LDY $0E80, X
CPY #$32 : BNE +
STZ $02E9 : LDY.b #$32 ; what we wrote over
LDY.w SpriteItemType, X
CPY.b #$32 : BNE +
STZ.w ItemReceiptMethod : LDY.b #$32 ; what we wrote over
PHX : JSL Link_ReceiveItem : PLX ; what we wrote over
CLC : RTL
+ SEC : RTL
LoadProperties_PreserveCertainProps:
LDA $0E20, X : CMP #$E4 : BEQ +
CMP #$E5 : BEQ +
JML Sprite_LoadProperties
+ LDA $0F50, X : PHA
LDA $0E80, X : PHA
JSL Sprite_LoadProperties
PLA : STA $0E80, X
PLA : STA $0F50, X
LDA.w SpriteTypeTable, X : CMP.b #$E4 : BEQ +
CMP.b #$E5 : BEQ +
JML SpritePrep_LoadProperties
+ LDA.w SpriteOAMProp, X : PHA
LDA.w SpriteItemType, X : PHA
JSL SpritePrep_LoadProperties
PLA : STA.w SpriteItemType, X
PLA : STA.w SpriteOAMProp, X
RTL
SubstitionFlow:
@@ -575,7 +766,7 @@ SubstituteSpriteId:
+ LDA.b #$01
CPY.b #$18 : BCC +
LDA.b #$05
+ STA.b $0D
+ STA.b Scrap0D
JSR IncrementCountsForSubstitute
PHB : PHK : PLB
LDA.w SubstitionTable-$16, Y ; Do substitute
@@ -588,51 +779,51 @@ CheckSprite_Spawn:
JSL Sprite_SpawnDynamically
BMI .check
PHX
TYX : JSL.l Sprite_LoadProperties
TYX : JSL SpritePrep_LoadProperties
PLX
JSL.l GoldBee_SpawnSelf_SetProperties
JSL GoldBee_SpawnSelf_SetProperties
PLA : PLA : PLA ; pop the return address
PHX : LDX.b #$03
JML Sprite_SpawnSecret_SetCoords
+ CPY.b #$1A : BCC + ; all other non-normal pot sprite spawns
JSL Sprite_SpawnDynamically
BMI .check
LDA.b #$10 : STA.b $0D ; lets the outside code treat this sprite like a Stal (most normal table values)
LDA.b #$10 : STA.b Scrap0D ; lets the outside code treat this sprite like a Stal (most normal table values)
RTL
+
JSL Sprite_SpawnDynamically
BMI .check
RTL
.check
LDA $0D : CMP #$08 : BNE +
LDA $0372 : BNE .error
LDX #$0F
LDA.b Scrap0D : CMP #$08 : BNE +
LDA.w LinkDashing : BNE .error
LDX.b #$0F
; loop looking for a Sprite with state 0A (carried by the player)
- LDA $0DD0, X : CMP #$0A : BEQ .foundIt
- LDA.w SpriteAITable, X : CMP.b #$0A : BEQ .foundIt
DEX : BMI .error : BRA -
.foundIt
LDA #$00 : STZ $0DD0, X
LDA #$E4 : JSL Sprite_SpawnDynamically
LDA.b #$00 : STZ.w SpriteAITable, X
LDA.b #$E4 : JSL Sprite_SpawnDynamically
BMI .error
LDA #$40 : TSB $0308 : RTL
LDA.b #$40 : TSB.w AButtonAct : RTL
.error
LDA.b #$3C ; SFX2_3C - error beep
STA.w $012E
+ LDA #$FF
STA.w SFX2
+ LDA.b #$FF
RTL
PreventPotSpawn:
LDA #$40 : BIT $0308 : BEQ +
STZ $0308 : RTL
+ LDA.b #$80 : STA.w $0308 ; what we wrote over
LDA.b #$40 : BIT.w AButtonAct : BEQ +
STZ.w AButtonAct : RTL
+ LDA.b #$80 : STA.w AButtonAct ; what we wrote over
RTL
PreventPotSpawn2:
LDA $0308 : BEQ +
LDA.b #$01 : TSB.b $50 ; what we wrote over
LDA.w AButtonAct : BEQ +
LDA.b #$01 : TSB.b LinkStrafe ; what we wrote over
+ RTL
CheckIfPotIsSpecial:
@@ -656,21 +847,21 @@ org $868072
JSL SetBottleVendorKey : NOP #4
pullpc
SetBottleVendorKey:
LDA.w $0E20,Y : CMP.b #$E4 : BNE +
LDA.w SpriteTypeTable,Y : CMP.b #$E4 : BNE +
; small key from bottle vendor
LDA.b #$AF : STA.w $0E80,Y
LDA.b #$01 : STA.w !SPRITE_REDRAW, Y
LDA.b #$AF : STA.w SpriteItemType,Y
LDA.b #$01 : STA.w SprRedrawFlag, Y
BRA .shift
+ CMP.b #$DE : BEQ .return
CMP.b #$E2 : BEQ .return
; shift narrow sprite to left by 4
.shift
LDA.b $00 : CLC : ADC.b #$04 : STA.w $0D10,Y ; what we wrote over
LDA.b Scrap00 : CLC : ADC.b #$04 : STA.w SpritePosXLow,Y ; what we wrote over
.return
RTL
ConditionalLoadCommonSprites_Do3To4Low:
LDA.b $10 : CMP.b #$01 : BEQ + ; what we wrote over
LDA.b GameMode : CMP.b #$01 : BEQ + ; what we wrote over
CMP.b #$0E : BEQ ++
JML LoadCommonSprites_Prep3To4Low
+ JML LoadCommonSprites_in_file_select