Fixing bugs with pottery lottery

This commit is contained in:
aerinon
2022-01-13 15:03:20 -07:00
parent 149f19df83
commit 50dd0c7be4
4 changed files with 186 additions and 166 deletions

View File

@@ -1,180 +1,173 @@
; where we shove the decompressed graphics to send to WRAM
DynamicDropGFX = $7EF500
StandItemGFXIDs = $7E07E0 ; 0x8 bytes for IDs
StandingItemTransferGFX = $7E07E8 ; bit field for item transfers
SICharRecID = $7E07E9 ; ID of receipt item for temp use
SICharSource = $7E07EA ; source address of the sprite's graphics
SIVRAMAddr = $7E07ED ; VRAM address to write the next slot to
SIVRAMSlot = $7E07EF ; current vram slot to ask for
SprSIChar = $7E07F0 ; standing item character for draw routine
; 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
;===================================================================================================
; this will keep track of the above for each item
SprItemGFX = $7E0780
; this is the item requested and a flag
DynamicDropRequest = $7E1E71
DynamicDropQueue = $7E1E72
SpriteDraw_DynamicStandingItem:
JSL Sprite_PrepOAMCoord_long ; 06E41C
LDA.b $00 : STA.b ($90),Y
LDA.b $01 : CMP.b #$01
LDA.b #$01 : ROL : STA.b ($92)
INY
REP #$21
LDA.b $02 : ADC.w #$0010
CMP.w #$0100
SEP #$20 : BCS .off_screen
SBC.b #$0F : STA.b ($90),Y
INY
LDA.w SprDropsItem,X : STA.b ($90),Y
INY
LDA.b $05 : STA.b ($90),Y
.off_screen
JML SpriteDraw_Shadow_long ; 06DC5C
; Call from standing/dropped items to request a free slot in VRAM in underworld
; Enter with
; A = receipt ID
; X = sprite slot
; Come in with
; A = item receipt ID
; X = slot
RequestStandingItemVRAMSlot:
JSR SetSISource
JSR GetSIVRAMSlot
RTL
; Take 8-bit receipt ID and turn it into a 24-bit source graphics address
; how we use this is TBD
; we could set up a buffer of 8 24-bit addresses to reference during NMI
; and we may or may not do decompression from here
SetSISource:
STA.w SICharRecID
PHX ; make sure X is preserved during this
PLX
STA.w SICharSource+1
STY.w SICharSource+2 ; don't need to use Y, but just as an example
RTS
GetSIVRAMSlot:
SEP #$30
PHX
LDA.w SIVRAMSlot : TAX
STA.w DynamicDropQueue
LDA.b #$01
STA.w DynamicDropRequest
LDA.w DynamicDropGFXIndex
INC
CMP.b #$07 : BCC .fine
CMP.b #$05 : BCC .fine
LDA.b #$00
.fine
STA.w SIVRAMSlot
STA.w DynamicDropGFXIndex
STA.w SprItemGFX,X
; flag this slot for a transfer
LDA.l .eightbits,X
ORA.l StandingItemTransferGFX
STA.l StandingItemTransferGFX
; set grapgics ID to look up for NMI transfer
LDA.w SICharRecID
STA.w StandItemGFXIDs,X
; decompress graphics
PHX
LDX.w DynamicDropQueue
LDA.l .char,X
REP #$20
LDA.w #DynamicDropGFX-$7E9000
STA.l !TILE_UPLOAD_OFFSET_OVERRIDE
SEP #$20
LDA.w DynamicDropQueue
JSL.l GetSpriteID
JSL.l GetAnimatedSpriteTile_variable
SEP #$30
PLX
STA.w SprSIChar,X
RTL
RTS
.char
db $20
db $22
db $2C
db $CB
db $E0
db $E5
db $EE
.eightbits
db 1<<0
db 1<<1
db 1<<2
db 1<<3
db 1<<4
db 1<<5
db 1<<6
db 1<<7
;===================================================================================================
NMI_TransferSIGFX:
LDA.l StandingItemTransferGFX
BEQ .exit
TransferPotGFX:
SEP #$10
REP #$20
AND.w #$00FF
STA.b $00
LDX.w DynamicDropRequest
BEQ .no
LDY.b #$80 : STY.w $2115
STZ.w DynamicDropRequest
LDX.b #$00
LDA.w DynamicDropGFXIndex
ASL
TAX
LDA.l FreeUWGraphics,X
STA.w $2116
.next
LSR.b $00 : BEQ .done : BCC .skip
; calculate bottom row now
CLC : ADC.w #$0200>>1 : PHA
PHX
LDX.b #$7E : STX.w $4314
LDA.w #DynamicDropGFX : STA.w $4302
TXY
TXA : ASL : TAX
LDX.b #$80 : STX.w $2115
LDA.w #$1801 : STA.w $4300
LDA.l .addr,X : STA.w $2116
LDA.w #$0040 : STA.w $4305
LDY.b #$01
; get source address based on ID
LDA.w StandItemGFXIDs,Y
; code
STA.b $04 ; source address
STY.w $4344 ; source bank
STY.w $420B
STA.w $4305
LDY.b #$10 ; DMA trigger
STA.w $4342 ; save address
LDA.w #$1801 : STA.w $4340 ; DMA type
LDA.w #64 : STA.w $4345 ; DMA size
PLA
STA.w $2116
STY.w $420B
STA.w $4345 ; DMA size again
CLC
LDA.b $04 : ADC.w #$0200 : STA.w $4344 ; assuming we've got things in squares in ROM
STY.w $420B
PLX
.skip
INX
BRA .next
.done
SEP #$20
.exit
.no
RTL
.addr
FreeUWGraphics:
dw $8800>>1
dw $8840>>1
dw $8980>>1
dw $9960>>1
dw $9C00>>1
dw $9CA0>>1
dw $9DC0>>1
dw $9DC0>>1
;===================================================================================================
DrawPotItem:
JSL.l IsNarrowSprite : BCS .narrow
.full
LDA.b #$01 : STA $06
LDA #$0C : JSL.l OAM_AllocateFromRegionC
LDA #$02 : PHA
REP #$20
LDA.w #DynamicOAMTile_full
BRA .draw
.narrow
LDA.b #$02 : STA $06
LDA #$10 : JSL.l OAM_AllocateFromRegionC
LDA #$03 : PHA
REP #$20
LDA.w #DynamicOAMTile_thin
.draw
PHB : PHK : PLB
STA.b $08
LDA.w SprItemGFX,X
AND.w #$00FF
ASL : ASL : ASL : ASL
ADC.b $08
STA.b $08
SEP #$20
STZ.b $07
JSL Sprite_DrawMultiple_quantity_preset
LDA.b $90 : CLC : ADC.b #$08 : STA.b $90
INC.b $92
INC.b $92
PLB
PLA
RTL
DynamicOAMTile_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 $EE, $00, $20, $00
dw 0, 8 : db $FE, $00, $20, $00
DynamicOAMTile_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 $EE, $00, $20, $02
dd 0, 0

View File

@@ -31,7 +31,13 @@ org $06d18d ; <- 3518D - sprite_absorbable.asm : 274 (LDA $7EF36F : INC A : STA
JSL KeyGet
org $06f9f3 ; bank06.asm : 6732 (JSL Sprite_LoadProperties)
JSL LoadProperties_PreserveItemMaybe
JSL LoadProperties_PreserveCertainProps
org $008BAA ; NMI hook
JSL TransferPotGFX
org $06828A
JSL CheckSprite_Spawn
; refs to other functions
@@ -214,7 +220,8 @@ RevealSpriteDrop:
LDA #$02 : STA.l SpawnedItemFlag
STX SpawnedItemIndex
LDA.l SprItemReceipt, X : STA SpawnedItemID
LDA.b #$01 : STA $0CBA, X : RTL ; trigger the small key routines
LDA.b #$01 : STA $0CBA, X ; trigger the small key routines
LDA.b #$09 : STA $0DD0, X : RTL ; unstun if stunned
.normal
LDA.w $0CBA, X : BNE .no_forced_drop
RTL
@@ -233,25 +240,22 @@ db $40, $20
; Runs during Sprite_E4_SmallKey and duning Sprite_E5_BigKey spawns
ShouldSpawnItem:
LDA.l StandingItemsOn : BEQ .normal
; todo: check our sram table
; checking our sram table
PHX : PHY
REP #$30
LDA.b $A0 : ASL : TAY
LDA.l SpawnedItemIndex : ASL
TAX : LDA.l BitFieldMasks, X : STA $00
TYX
LDA.w SpawnedItemFlag : CMP #$0001 : BEQ +
LDA.l SpriteItemSRAM, X : BIT $00 : BEQ .notObtained
LDA.w SprItemIndex, X : AND #$00FF : ASL
PHX
TAX : LDA.l BitFieldMasks, X : STA $00
PLX ; restore X again
LDA.w SprItemFlags, X : AND #$00FF : CMP #$0001 : BEQ +
TYX : LDA.l SpriteItemSRAM, X : BIT $00 : BEQ .notObtained
BRA .obtained
+ LDA.l PotItemSRAM, X : BIT $00 : BEQ .notObtained
+ TYX : LDA.l PotItemSRAM, X : BIT $00 : BEQ .notObtained
.obtained
SEP #$30 : PLY : PLX : LDA #$01 : RTL ; already obtained
.notObtained
SEP #$30 : PLY : PLX
LDA.w SpawnedItemIndex : STA SprItemIndex, X
LDA.w SpawnedItemFlag : STA SprItemFlags, X
LDA.w SpawnedItemMWPlayer : STA SprItemMWPlayer, X
; todo: RequestStandingItemVRAMSlot instead? - need to see how often this is called
LDA #$00 : RTL
.normal
LDA.w $0403
@@ -277,13 +281,18 @@ MarkSRAMForItem:
SpriteKeyPrep:
LDA.w $0B9B : STA.w $0CBA, X ; what we wrote over
PHA
LDA.l SpawnedItemFlag : BEQ +
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
CMP #$24 : BNE ++ ; todo: check how the big key drop flows through this
PHA
JSL.l GetSpritePalette : STA $0F50, X ; setup the palette
PLA
CMP #$24 : BNE ++ ;
LDA $A0 : CMP.b #$80 : BNE +
LDA SpawnedItemFlag : BNE +
LDA #$24 ; it's the big key drop?
++ JSL PrepDynamicTile ; todo: remove in favor of RequestStandingItemVRAMSlot
++ JSL RequestStandingItemVRAMSlot
+ PLA
RTL
@@ -301,8 +310,7 @@ SpriteKeyDrawGFX:
JML Sprite_DrawAbsorbable
.jslrtsreturn
RTL
; todo : SpriteDraw_DynamicStandingItem here?
+ JSL DrawDynamicTile ; see DrawHeartPieceGFX if problems
+ JSL DrawPotItem
CMP #$03 : BNE +
PHA : LDA $0E60, X : ORA.b #$20 : STA $0E60, X : PLA
+ JSL.l Sprite_DrawShadowLong
@@ -357,12 +365,30 @@ BigKeyGet:
CLC : RTL
+ SEC : RTL
LoadProperties_PreserveItemMaybe:
LoadProperties_PreserveCertainProps:
LDA.l StandingItemsOn : BNE +
JML Sprite_LoadProperties
+ LDA $0F50, X : PHA
LDA $0E80, X : PHA
JSL Sprite_LoadProperties
PLA : STA $0e80, X
PLA : STA $0E80, X
PLA : STA $0F50, X
RTL
CheckSprite_Spawn:
JSL Sprite_SpawnDynamically
BMI .check
RTL
.check
PHA
LDA $0D : CMP #$08 : BNE +
LDA.b #$3C ; SFX2_3C - error beep
STA.w $012E
+ PLA
RTL
incsrc dynamic_si_vram.asm
;===================================================================================================
; Pot items
;===================================================================================================