Palette handling & sprite props data tables

Statically assign item data tables
Fix some save-related bugs
Fix dungeon item notice in "this dungeon" with free dungeon items
This commit is contained in:
cassidoxa
2023-08-01 17:13:47 -04:00
parent d3ed95d639
commit 8ed4cbda1d
19 changed files with 1693 additions and 1640 deletions

View File

@@ -8,33 +8,19 @@
GetSpriteID:
JSR.w AttemptItemSubstitution
JSR.w ResolveLootID
CMP.b #$16 : BEQ .bottle ; Bottle
CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle
CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle
CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle
CMP.b #$3C : BEQ .bottle ; Bee w/bottle
CMP.b #$3D : BEQ .bottle ; Fairy w/bottle
CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle
CMP.b #$6D : BEQ .server_F0 ; Server Request F0
CMP.b #$6E : BEQ .server_F1 ; Server Request F1
CMP.b #$6F : BEQ .server_F2 ; Server Request F2
CMP.b #$6D : BEQ .server_F0 ; Server Request F0
CMP.b #$6E : BEQ .server_F1 ; Server Request F1
CMP.b #$6F : BEQ .server_F2 ; Server Request F2
BRA .normal
.bottle
PHA : JSR.w CountBottles : CMP.l BottleLimit : !BLT +
PLA : LDA.l BottleLimitReplacement
JMP GetSpriteID
+
PLA : BRA .normal
.server_F0
JSL.l ItemVisualServiceRequest_F0
BRA .normal
.server_F1
JSL.l ItemVisualServiceRequest_F1
BRA .normal
.server_F0
JSL.l ItemVisualServiceRequest_F0
BRA .normal
.server_F1
JSL.l ItemVisualServiceRequest_F1
BRA .normal
.server_F2
JSL.l ItemVisualServiceRequest_F2
JSL.l ItemVisualServiceRequest_F2
.normal
PHX
TAX : LDA.l ItemReceipts_graphics, X ; look up item gfx
PLX
@@ -46,163 +32,18 @@ RTL
; out: A - Palette
;--------------------------------------------------------------------------------
GetSpritePalette:
JSR AttemptItemSubstitution
JSR.w ResolveLootID
JSR AttemptItemSubstitution
JSR.w ResolveLootID
.resolved
CMP.b #$16 : BEQ .bottle ; Bottle
CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle
CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle
CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle
CMP.b #$3C : BEQ .bottle ; Bee w/bottle
CMP.b #$3D : BEQ .bottle ; Fairy w/bottle
CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle
BRA .notBottle
.bottle
PHA : JSR.w CountBottles : CMP.l BottleLimit : !BLT +
PLA : LDA.l BottleLimitReplacement
JMP GetSpritePalette
+
PLA : .notBottle
PHX
TAX : LDA.l GfxPalettes, X ; look up item gfx
PLX
TAX
LDA.l SpriteProperties_standing_palette, X : BIT #$80 : BNE .load_palette
ASL
RTL
;---------------------------------------------------------------------------------------------------
;DATA - Loot Identifier to Sprite Palette
{
GfxPalettes:
db $00, $04, $02, $08, $04, $02, $08, $02
db $04, $02, $02, $02, $04, $04, $04, $08
db $08, $08, $02, $02, $04, $02, $02, $02
db $04, $02, $04, $02, $08, $08, $04, $02
db $0A, $02, $04, $02, $04, $04, $00, $04
db $04, $08, $02, $02, $08, $04, $02, $08
db $04, $04, $08, $08, $08, $04, $02, $08
db $02, $04, $08, $02, $04, $04, $02, $02
db $08, $08, $02, $04, $04, $08, $08, $08
db $04, $04, $04, $02, $08, $08, $08, $08
; db $04, $0A, $04, $02, $FF, $FF, $FF, $FF
db $04 ; Safe Master Sword
db $08, $08, $08, $08 ; Bomb & Arrow +5/+10
db $04, $00, $00 ; Programmable Items 1-3
db $02 ; Upgrade-Only Silver Arrows
db $06 ; 1 Rupoor
db $02 ; Null Item
db $02, $04, $08 ; Red, Blue & Green Clocks
db $FD, $FE, $FF, $FC ; Progressive Sword, Shield, Armor & Gloves
db $FA, $FB ; RNG Single & Multi
db $F8, $F8 ; Progressive Bow
db $00, $00, $00, $00 ; Unused
db $08, $08, $08 ; Goal Item Single, Multi & Alt Multi
db $04, $04, $04 ; Server Request F0, F1, F2
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Map
db $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04 ; Free Compass
;db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; *EVENT*
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Big Key
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Small Key
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused
db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused
}
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; IsNarrowSprite
; in: A - Loot ID
; out: Carry - 0 = Full, 1 = Narrow
;--------------------------------------------------------------------------------
IsNarrowSprite:
PHA : PHX
PHB : PHK : PLB
JSR AttemptItemSubstitution
;--------
CMP.b #$16 : BEQ .bottle ; Bottle
CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle
CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle
CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle
CMP.b #$3C : BEQ .bottle ; Bee w/bottle
CMP.b #$3D : BEQ .bottle ; Fairy w/bottle
CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle
BRA .notBottle
.bottle
JSR.w CountBottles : CMP.l BottleLimit : !BLT +
LDA.l BottleLimitReplacement
JSL.l IsNarrowSprite
JMP .done
+ : JMP .continue
.notBottle
CMP.b #$5E : BNE ++ ; Progressive Sword
LDA.l HighestSword : CMP.l ProgressiveSwordLimit : !BLT + ; Progressive Sword Limit
LDA.l ProgressiveSwordReplacement
JSL.l IsNarrowSprite
JMP .done
+ : JMP .continue
++ CMP.b #$5F : BNE ++ ; Progressive Shield
LDA.l HighestShield : BNE + : JMP .done ; No Shield
+ : CMP.l ProgressiveShieldLimit : !BLT .continue
LDA.l ProgressiveShieldReplacement
JSL.l IsNarrowSprite
JMP .done
++ CMP.b #$60 : BNE ++ ; Progressive Armor
LDA.l HighestMail : CMP.l ProgressiveArmorLimit : !BLT .continue
LDA.l ProgressiveArmorReplacement
JSL.l IsNarrowSprite
JMP .done
+
++ CMP.b #$62 : BNE ++ ; RNG Item (Single)
JSL.l GetRNGItemSingle : JMP .continue
++ CMP.b #$63 : BNE ++ ; RNG Item (Multi)
JSL.l GetRNGItemMulti
++ CMP.b #$64 : BEQ + ; Progressive Bow
CMP.b #$65 : BNE .continue ; Progressive Bow (alt)
+ : LDA.l BowEquipment : INC : LSR
CMP.l ProgressiveBowLimit : !BLT +
LDA.l ProgressiveBowReplacement
JSL.l IsNarrowSprite
JMP .done
.continue
;--------
LDX.b #$00 ; set index counter to 0
;----
-
CPX.b #$24 : !BGE .false ; finish if we've done the whole list
CMP.l .smallSprites, X : BNE + ; skip to next if we don't match
;--
SEC ; set true state
BRA .done ; we're done
;--
+
INX ; increment index
BRA - ; go back to beginning of loop
;----
.false
CLC
.done
PLB : PLX : PLA
.load_palette
JSL.l LoadItemPalette
ASL
RTL
;DATA - Half-Size Sprite Markers
{
.smallSprites
db $04, $07, $08, $09, $0A, $0B, $0C, $13
db $15, $18, $24, $2A, $34, $35, $36, $42
db $43, $45, $59, $A0, $A1, $A2, $A3, $A4
db $A5, $A6, $A7, $A8, $A9, $AA, $AB, $AC
db $AD, $AE, $AF, $FF, $FF, $FF, $FF, $FF
}
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; PrepDynamicTile
; in: A - Loot ID
@@ -210,11 +51,15 @@ RTL
PrepDynamicTile:
PHA : PHX : PHY : PHB
JSR.w ResolveLootID
-
JSR.w LoadDynamicTileOAMTable
JSL TransferItemReceiptToBuffer_using_ReceiptID
SEP #$30
PLB : PLY : PLX : PLA
RTL
.loot_resolved
PHA : PHX : PHY : PHB
BRA -
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
@@ -222,34 +67,31 @@ RTL
; in: A - Loot ID
;-------------------------------------------------------------------------------- 20/847B
LoadDynamicTileOAMTable:
PHA : PHP
PHA : PHP
REP #$20
LDA.w #$0000 : STA.l SpriteOAM : STA.l SpriteOAM+2
LDA.w #$0200 : STA.l SpriteOAM+6
SEP #$20
LDA.b #$24 : STA.l SpriteOAM+4
PHA
REP #$20 ; set 16-bit accumulator
LDA.w #$0000 : STA.l SpriteOAM
STA.l SpriteOAM+2
LDA.w #$0200 : STA.l SpriteOAM+6
SEP #$20 ; set 8-bit accumulator
LDA.b #$24 : STA.l SpriteOAM+4
LDA.w SpriteItemType,X
JSL.l GetSpritePalette_resolved
STA.l SpriteOAM+5 : STA.l SpriteOAM+13
PHX
LDA.l SpriteProperties_standing_width,X : BEQ .narrow
BRA .done
LDA.b $01,s
.narrow
REP #$20
LDA.w #$0400 : STA.l SpriteOAM+7 : STA.l SpriteOAM+14
LDA.w #$0800 : STA.l SpriteOAM+9
LDA.w #$3400 : STA.l SpriteOAM+11
SEP #$20
LDA.b #$04 : STA.l SpriteOAM
JSL.l GetSpritePalette_resolved
STA.l SpriteOAM+5 : STA.l SpriteOAM+13
PLA
JSL.l IsNarrowSprite : BCS .narrow
BRA .done
.narrow
REP #$20 ; set 16-bit accumulator
LDA.w #$0000 : STA.l SpriteOAM+7
STA.l SpriteOAM+14
LDA.w #$0800 : STA.l SpriteOAM+9
LDA.w #$3400 : STA.l SpriteOAM+11
.done
PLP : PLA
.done
PLX
PLP : PLA
RTS
;--------------------------------------------------------------------------------
@@ -261,58 +103,66 @@ RTS
; This wastes two OAM slots if you don't want a shadow - fix later - I wrote "fix later" over a year ago and it's still not fixed (Aug 6, 2017) - lol (May 25th, 2019)
;-------------------------------------------------------------------------------- 2084B8
DrawDynamicTile:
JSL.l IsNarrowSprite : BCS .narrow
PHX
TAX
LDA.l SpriteProperties_standing_width,X : BEQ .narrow
.full
LDA.b #$01 : STA.b Scrap06
LDA.b #$0C : JSL.l OAM_AllocateFromRegionC
LDA.b #$02 : PHA
BRA .draw
.full
PLX
LDA.b #$01 : STA.b Scrap06
LDA.b #$0C : JSL.l OAM_AllocateFromRegionC
LDA.b #$02 : PHA
BRA .draw
.narrow
LDA.b #$02 : STA.b Scrap06
LDA.b #$10 : JSL.l OAM_AllocateFromRegionC
LDA.b #$03 : PHA
.narrow
PLX
LDA.b #$02 : STA.b Scrap06
LDA.b #$10 : JSL.l OAM_AllocateFromRegionC
LDA.b #$03 : PHA
.draw
LDA.b #SpriteOAM>>0 : STA.b Scrap08
LDA.b #SpriteOAM>>8 : STA.b Scrap09
STZ.b Scrap07
LDA.b #$7E : PHB : PHA : PLB
LDA.b #$01 : STA.l SpriteSkipEOR
JSL Sprite_DrawMultiple_quantity_preset
LDA.b #$00 : STA.l SpriteSkipEOR
PLB
.draw
LDA.b #SpriteOAM>>0 : STA.b Scrap08
LDA.b #SpriteOAM>>8 : STA.b Scrap09
STZ.b Scrap07
LDA.b #$7E : PHB : PHA : PLB
LDA.b #$01 : STA.l SpriteSkipEOR
JSL Sprite_DrawMultiple_quantity_preset
LDA.b #$00 : STA.l SpriteSkipEOR
PLB
LDA.b OAMPtr : !ADD.b #$08 : STA.b OAMPtr ; leave the pointer in the right spot to draw the shadow, if desired
LDA.b OAMPtr+2 : INC #2 : STA.b OAMPtr+2
PLA
LDA.b OAMPtr : !ADD.b #$08 : STA.b OAMPtr ; leave the pointer in the right spot to draw the shadow, if desired
LDA.b OAMPtr+2 : INC #2 : STA.b OAMPtr+2
PLA
RTL
;--------------------------------------------------------------------------------
DrawDynamicTileNoShadow:
JSL.l IsNarrowSprite : BCS .narrow
PHX
TAX
LDA.l SpriteProperties_standing_width,X : BEQ .narrow
.full
LDA.b #$01 : STA.b Scrap06
LDA.b #$04 : JSL.l OAM_AllocateFromRegionC
BRA .draw
.full
PLX
LDA.b #$01 : STA.b Scrap06
LDA.b #$04 : JSL.l OAM_AllocateFromRegionC
BRA .draw
.narrow
LDA.b #$02 : STA.b Scrap06
LDA.b #$08 : JSL.l OAM_AllocateFromRegionC
.narrow
PLX
LDA.b #$02 : STA.b Scrap06
LDA.b #$08 : JSL.l OAM_AllocateFromRegionC
.draw
LDA.b #SpriteOAM>>0 : STA.b Scrap08
LDA.b #SpriteOAM>>8 : STA.b Scrap09
STZ.b Scrap07
LDA.b #$7E : PHB : PHA : PLB
LDA.b #$01 : STA.l SpriteSkipEOR
JSL Sprite_DrawMultiple_quantity_preset
LDA.l Bob : BNE + : LDA.b #$00 : STA.l SpriteSkipEOR : + ; Bob fix is conditional
PLB
.draw
LDA.b #SpriteOAM>>0 : STA.b Scrap08
LDA.b #SpriteOAM>>8 : STA.b Scrap09
STZ.b Scrap07
LDA.b #$7E : PHB : PHA : PLB
LDA.b #$01 : STA.l SpriteSkipEOR
JSL Sprite_DrawMultiple_quantity_preset
LDA.l Bob : BNE + : LDA.b #$00 : STA.l SpriteSkipEOR : + ; Bob fix is conditional
PLB
LDA.b OAMPtr : !ADD.b #$08 : STA.b OAMPtr
LDA.b OAMPtr+2 : INC #2 : STA.b OAMPtr+2
LDA.b OAMPtr : !ADD.b #$08 : STA.b OAMPtr
LDA.b OAMPtr+2 : INC #2 : STA.b OAMPtr+2
RTL
;--------------------------------------------------------------------------------
@@ -400,70 +250,10 @@ SkipDrawEOR:
LDA.b ($08), Y : EOR.w Scrap04 ; thing we wrote over
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; CountBits
; in: A(b) - Byte to count bits in
; out: A(b) - sum of bits
; caller is responsible for setting 8-bit mode and preserving X and Y
;--------------------------------------------------------------------------------
;CountBits:
; PHX
; TAX ; Save a copy of value
; LSR #4 ; Shift down hi nybble, Leave <3> in C
; PHA ; And save <7:4> in Stack
; TXA ; Recover value
; AND.b #$07 ; Put out <2:0> in X
; TAX ; And save in X
; LDA.l NybbleBitCounts, X ; Fetch count for <2:0>
; PLX ; get <7:4>
; ADC.l NybbleBitCounts, X ; Add count for S & C
; PLX
;RTL
; Look up table of bit counts in the values $00-$0F
NybbleBitCounts:
db #00, #01, #01, #02, #01, #02, #02, #03, #01, #02, #02, #03, #02, #03, #03, #04
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; HexToDec
; in: A(w) - Word to Convert
; out: HexToDecDigit1 - HexToDecDigit5 (high - low)
;--------------------------------------------------------------------------------
;HexToDec:
; PHA
; PHA
; LDA.w #$9090
; STA.l HexToDecDigit1 : STA.l HexToDecDigit3 : STA.l HexToDecDigit4 ; clear digit storage
; PLA
; -
; CMP.w #10000 : !BLT +
; PHA : SEP #$20 : LDA.l HexToDecDigit1 : INC : STA.l HexToDecDigit1 : REP #$20 : PLA
; !SUB.w #10000 : BRA -
; + -
; CMP.w #1000 : !BLT +
; PHA : SEP #$20 : LDA.l HexToDecDigit2 : INC : STA.l HexToDecDigit2 : REP #$20 : PLA
; !SUB.w #1000 : BRA -
; + -
; CMP.w #100 : !BLT +
; PHA : SEP #$20 : LDA.l HexToDecDigit3 : INC : STA.l HexToDecDigit3 : REP #$20 : PLA
; !SUB.w #100 : BRA -
; + -
; CMP.w #10 : !BLT +
; PHA : SEP #$20 : LDA.l HexToDecDigit4 : INC : STA.l HexToDecDigit4 : REP #$20 : PLA
; !SUB.w #10 : BRA -
; + -
; CMP.w #1 : !BLT +
; PHA : SEP #$20 : LDA.l HexToDecDigit5 : INC : STA.l HexToDecDigit5 : REP #$20 : PLA
; !SUB.w #1 : BRA -
; +
; PLA
;RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; WriteVRAMStripe
; in: A(w) - VRAM Destination
@@ -530,7 +320,6 @@ RTL
;It is followed by a single tile (word). Combining this this with the D bit makes it easy to draw large horizontal or vertical runs of a tile without using much space. Geat for erasing or drawing horizontal or verical box edges.
;================================================================================
DynamicDrawCleanup:
PHA
REP #$20
@@ -547,3 +336,45 @@ DynamicDrawCleanup:
PLA
RTL
;------------------------------------------------------------------------------
CheckReceivedItemPropertiesBeforeLoad:
LDA.b RoomIndex : BEQ .normalCode
LDA.l RoomFade : BNE .load_palette
LDA.l SpriteProperties_chest_palette,X : BIT #$80 : BNE .load_palette
.normalCode
RTL
.load_palette
JSL.l LoadItemPalette
RTL
;------------------------------------------------------------------------------
LoadItemPalette:
; In: X - Loot ID
; Out: A - Sprite palette index
PHX : PHY : PHB
LDA.b #PalettesVanillaBank>>16 : STA.b Scrap0C
LDA.b #$7E
PHA : PLB
REP #$30
TXA : ASL : TAX
LDA.l SpriteProperties_palette_addr,X : STA.b Scrap0A
LDY.w #$000E
LDA.w TransparencyFlag : BNE .SP05
-
LDA.b [Scrap0A], Y : STA.w PaletteBuffer+$0170,Y
DEY #2
BPL -
LDA.w #$0003
BRA .done
.SP05
-
LDA.b [Scrap0A], Y : STA.w PaletteBuffer+$01B0,Y
DEY #2
BPL -
LDA.w #$0005
.done
SEP #$30
PLB : PLY : PLX
INC.b NMICGRAM
RTL