faster HUD

This commit is contained in:
spannerisms
2022-12-05 02:01:46 -05:00
parent 0397623340
commit 918173523f
7 changed files with 356 additions and 274 deletions

View File

@@ -145,7 +145,6 @@ incsrc hashalphabet.asm
incsrc inverted.asm
incsrc invertedmaps.asm
incsrc newhud.asm
incsrc compasses.asm
incsrc save.asm
incsrc password.asm
incsrc enemy_adjustments.asm

View File

@@ -1,52 +0,0 @@
DrawDungeonCompassCounts:
LDX.b IndoorsFlag : BNE + : RTL : + ; Skip if outdoors
; extra hard safeties for getting dungeon ID to prevent crashes
PHA
LDA.w DungeonID : AND.w #$00FE : TAX ; force dungeon ID to be multiple of 2
PLA
CPX.b #$1B : BCS .done ; Skip if not in a valid dungeon ID
BIT.w #$0002 : BNE ++ ; if CompassMode==2, we don't check for the compass
LDA.l CompassField : AND.l DungeonItemMasks, X ; Load compass values to A, mask with dungeon item masks
BEQ .done ; skip if we don't have compass
++
TXA : LSR : TAX
BNE +
INC
+
LDA.l CompassTotalsWRAM, X : AND.w #$00FF
SEP #$20
JSR HudHexToDec2Digit
REP #$20
PHX
LDX.b Scrap06 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$9A
LDX.b Scrap07 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$9C
PLX
LDA.l DungeonLocationsChecked, X : AND.w #$00FF
SEP #$20
JSR HudHexToDec2Digit
REP #$20
LDX.b Scrap06 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$94 ; Draw the item count
LDX.b Scrap07 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$96
LDA.w #$2830 : STA.l HUDTileMapBuffer+$98 ; draw the slash
.done
RTL
DungeonItemMasks: ; these are dungeon correlations to $7EF364 - $7EF369 so it knows where to store compasses, etc
dw $8000, $4000, $2000, $1000, $0800, $0400, $0200, $0100
dw $0080, $0040, $0020, $0010, $0008, $0004
;--------------------------------------------------------------------------------
InitCompassTotalsRAM:
LDX.b #$00
-
LDA.l CompassTotalsROM, X : STA.l CompassTotalsWRAM, X
INX
CPX.b #$0F : !BLT -
RTL

View File

@@ -905,10 +905,6 @@ LDA.w AddReceivedItemExpanded_item_masks, X
org $098769 ; 48769 - ancilla_init.asm:1005 (LDA .item_graphics_indices, Y)
LDA.w ItemReceipts_graphics, Y
org $09878C
JSL TransferItemReceiptToBuffer_using_GraphicsID
org $09884D ; 4884D - ancilla_init.asm:1137 (LDA $836C, Y)
LDA.w ItemReceipts_offset_y, Y
org $09885B ; 4885B - ancilla_init.asm:1139 (LDA .x_offsets, X) - I think the disassembly is wrong here, should have been LDA .x_offsets, Y
@@ -2489,3 +2485,36 @@ if !FEATURE_NEW_TEXT
org $0EF285
JSL RenderCharSetColorExtended_close : NOP
endif
;===================================================================================================
; Item decompression/loading
;===================================================================================================
; mushroom - are these even necessary in rando?
org $0283CF : JSL TransferItemReceiptToBuffer_using_GraphicsID
org $02ADB6 : JSL TransferItemReceiptToBuffer_using_GraphicsID
org $02ADE9 : JSL TransferItemReceiptToBuffer_using_GraphicsID
; big key
org $069261 : JSL TransferItemReceiptToBuffer_using_GraphicsID
; falling items
org $08CAE9 : JSL TransferItemReceiptToBuffer_using_GraphicsID
org $098BD2 : JSL TransferItemReceiptToBuffer_using_GraphicsID
; misc
org $09878C : JSL TransferItemReceiptToBuffer_using_GraphicsID
; pond items
org $098A4D : JSL TransferItemReceiptToBuffer_using_GraphicsID
org $098AEE : JSL TransferItemReceiptToBuffer_using_GraphicsID
; flute
org $098C85 : JSL TransferItemReceiptToBuffer_using_GraphicsID
; gt cutscene
org $099BBE : JSL TransferItemReceiptToBuffer_using_GraphicsID

View File

@@ -67,8 +67,24 @@ Init_PostRAMClear:
JSL MSUInit
JSL InitRNGPointerTable
JSL InitCompassTotalsRAM
JSR InitCompassTotalsRAM
JSL DecompressAllItemGraphics
JML $00D463 ; The original target of the jump table that we hijacked
;---------------------------------------------------------------------------------------------------
InitCompassTotalsRAM:
LDX.b #$0F
.next
LDA.l CompassTotalsROM,X
STA.l CompassTotalsWRAM,X
DEX
BPL .next
RTS
;===================================================================================================

View File

@@ -1,259 +1,340 @@
InfiniteTile = $2431
BlankTile = $207F
SlashTile = $2830
PTile = $296C
CTile = $295F
;===================================================================================================
NewDrawHud:
SEP #$30
;================================================================================
; Draw bomb count
;================================================================================
PHB
LDA.l InfiniteBombs : BNE .infinite_bombs
.finite_bombs
LDA.l BombsEquipment ; bombs
JSR HudHexToDec2Digit ;requires 8 bit registers!
REP #$20
LDX.b Scrap06 : TXA : ORA.w #$2490 : STA.l HUDBombCount ; Draw bombs 10 digit
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDBombCount+2 ; Draw bombs 1 digit
BRA +
SEP #$30
REP #$10
.infinite_bombs
REP #$20
LDA.w #$2431 : STA.l HUDBombCount ; infinity (left half)
INC A : STA.l HUDBombCount+2 ; infinity (right half)
+
LDA.b #$7E
PHA
PLB
;================================================================================
; Draw rupee counter
;================================================================================
;===================================================================================================
LDA.l DisplayRupees ; Drawing bombs (above) always ends with 16-bit A, so, no need to REP here
JSR HudHexToDec4Digit
LDX.b Scrap04 : TXA : ORA.w #$2490 : STA.l HUDRupees ; 1000s
LDX.b Scrap05 : TXA : ORA.w #$2490 : STA.l HUDRupees+2 ; 100s
LDX.b Scrap06 : TXA : ORA.w #$2490 : STA.l HUDRupees+4 ; 10s
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDRupees+6 ; 1s
NewHUD_DrawBombs:
LDA.l InfiniteBombs : BEQ .finite
;================================================================================
; Draw arrow count
;================================================================================
.infinite
LDY.w #InfiniteTile+0
LDX.w #InfiniteTile+1
SEP #$20
LDA.l ArrowMode : BNE +
LDA.l InfiniteArrows : BNE .infinite_arrows
.finite_arrows
LDA.l CurrentArrows ; arrows
JSR HudHexToDec2Digit
REP #$20
LDX.b Scrap06 : TXA : ORA.w #$2490 : STA.l HUDArrowCount ; Draw arrows 10 digit
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDArrowCount+2 ; Draw arrows 1 digit
BRA +
BRA .draw
.infinite_arrows
REP #$20
LDA.w #$2431 : STA.l HUDArrowCount ; infinity (left half)
INC A : STA.l HUDArrowCount+2 ; infinity (right half)
+
.finite
LDA.w BombsEquipment
JSR HUDHex2Digit
;================================================================================
; Draw Goal Item Indicator
;================================================================================
.draw
STY.w HUDBombCount+0
STX.w HUDBombCount+2
REP #$20
LDA.l GoalItemRequirement : BNE + : JMP .done : + ; Star Meter
;===================================================================================================
LDA.l GoalCounter
JSR HudHexToDec4Digit
LDA.l GoalItemIcon : STA.l HUDGoalIndicator ; draw star icon
LDX.b Scrap05 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+2 ; draw 100's digit
LDX.b Scrap06 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+4 ; draw 10's digit
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+6 ; draw 1's digit
LDA.l GoalItemRequirement : CMP.w #$FFFF : BEQ .skip
LDA.l GoalItemRequirement
JSR HudHexToDec4Digit
LDA.w #$2830 : STA.l HUDGoalIndicator+8 ; draw slash
LDX.b Scrap05 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+10 ; draw 100's digit
LDX.b Scrap06 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+12 ; draw 10's digit
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDGoalIndicator+14 ; draw 1's digit
BRA .done
.skip
LDA.w #$207F ; transparent tile
STA.l HUDGoalIndicator+8
STA.l HUDGoalIndicator+10
STA.l HUDGoalIndicator+12
.done
;================================================================================
; Draw Dungeon Compass Counts
;================================================================================
LDA.l CompassMode : AND.w #$00FF : BEQ + ; skip if CompassMode is 0.
JSL.l DrawDungeonCompassCounts ; compasses.asm
+
;================================================================================
; Draw key count
;================================================================================
SEP #$20
LDA.l CurrentSmallKeys : CMP.b #$FF : BEQ .not_in_dungeon
.in_dungeon
JSR HudHexToDec2Digit : REP #$20
; if 10s digit is 0, draw transparent tile instead of 0
LDX.b Scrap06 : TXA : BNE +
LDA.w #$007F
+
ORA.w #$2490 : STA.l HUDKeyDigits
; 1s digit
LDX.b Scrap07 : TXA : ORA.w #$2490 : STA.l HUDKeyDigits+2
BRA .done_keys
.not_in_dungeon
NewHUD_DrawRupees:
REP #$20
;in the overworld, draw transparent tiles instead of key count
LDA.w #$247F : STA.l HUDKeyDigits : STA.l HUDKeyDigits+2
STA.l HUDKeyIcon
LDA.w DisplayRupees
JSR HUDHex4Digit
.done_keys
LDA.b Scrap04 : TAX : STX.w HUDRupees+0 ; 1000s
LDA.b Scrap05 : TAX : STX.w HUDRupees+2 ; 100s
LDA.b Scrap06 : TAX : STX.w HUDRupees+4 ; 10s
LDA.b Scrap07 : TAX : STX.w HUDRupees+6 ; 1s
;===================================================================================================
;--------------------------------------------------------------------------------
; Draw pendant/crystal icon
;--------------------------------------------------------------------------------
!P_ICON = $296C
!C_ICON = $295F
NewHUD_DrawArrows:
SEP #$20
LDA.b IndoorsFlag : BEQ .noprize
LDX.w DungeonID
CPX #$1A : !BGE .noprize
CPX #$04 : !BLT .noprize
CPX #$08 : BEQ .noprize
LDA.l ArrowMode
BNE NewHUD_DrawGoal
LDA.b GameMode : CMP.b #$12 : BEQ .noprize
LDA.l InfiniteArrows : BEQ .finite
.infinite
LDY.w #InfiniteTile+0
LDX.w #InfiniteTile+1
BRA .draw
.finite
LDA.w CurrentArrows
JSR HUDHex2Digit
.draw
STY.w HUDArrowCount+0
STX.w HUDArrowCount+2
;===================================================================================================
NewHUD_DrawGoal:
REP #$20
LDA.l GoalItemRequirement
BEQ .no_goal
LDA.l GoalItemIcon
STA.w HUDGoalIndicator
LDA.w #SlashTile
STA.w HUDGoalIndicator+8
LDA.l GoalCounter
JSR HUDHex4Digit
LDA.b Scrap05 : TAX : STX.w HUDGoalIndicator+2 ; draw 100's digit
LDA.b Scrap06 : TAX : STX.w HUDGoalIndicator+4 ; draw 10's digit
LDA.b Scrap07 : TAX : STX.w HUDGoalIndicator+6 ; draw 1's digit
REP #$20
LDA.l GoalItemRequirement
CMP.w #$FFFF
BNE .real_goal
LDX.w #BlankTile
STX.w HUDGoalIndicator+10
STX.w HUDGoalIndicator+12
STX.w HUDGoalIndicator+14
.no_goal
SEP #$20
BRA NewHUD_DrawKeys
.real_goal
JSR HUDHex4Digit
LDA.b Scrap05 : TAX : STX.w HUDGoalIndicator+10 ; draw 100's digit
LDA.b Scrap06 : TAX : STX.w HUDGoalIndicator+12 ; draw 10's digit
LDA.b Scrap07 : TAX : STX.w HUDGoalIndicator+14 ; draw 1's digit
;===================================================================================================
NewHUD_DrawKeys:
LDA.l CurrentSmallKeys
CMP.b #$FF
BNE .in_dungeon
LDY.w #BlankTile
STY.w HUDKeyIcon
STY.w HUDKeyDigits+0
STY.w HUDKeyDigits+2
BRA NewHUD_DrawCompassCount
.in_dungeon
JSR HUDHex2Digit
CPY.w #$2490
BNE .real_10s
LDY.w #BlankTile
.real_10s
STY.w HUDKeyDigits+0
STX.w HUDKeyDigits+2
;===================================================================================================
NewHUD_DrawCompassCount:
LDA.b IndoorsFlag
BNE .indoors
JMP NewHUD_DrawMagicMeter
.indoors
LDA.l CompassMode
BEQ NewHUD_DrawPrizeIcon
SEP #$30
; force dungeon ID to a multiple of 2
LDA.w DungeonID
CMP.b #$1B : BCS NewHUD_DrawPrizeIcon ; skip if invalid dungeon
AND.b #$FE : TAX
LSR : TAY ; save reduced ID in Y
; no compass needed if this bit is set
LDA.l CompassMode
BIT.b #$02
BNE .draw_compass_count
LDA.l CompassField
AND.l DungeonItemMasks,X
BEQ NewHUD_DrawPrizeIcon
.draw_compass_count
TYX
BNE .not_sewers
INX
.not_sewers
LDA.l DungeonLocationsChecked, X
PHA
LDA.l CompassTotalsWRAM,X
JSR HUDHex2Digit
STY.w HUDTileMapBuffer+$9A
STX.w HUDTileMapBuffer+$9C
LDX.w #SlashTile
STX.w HUDTileMapBuffer+$98
PLA
JSR HUDHex2Digit
STY.w HUDTileMapBuffer+$94
STX.w HUDTileMapBuffer+$96
;===================================================================================================
NewHUD_DrawPrizeIcon:
LDA.b GameMode
CMP.b #$12
BEQ .no_prize
LDA.w DungeonID
CMP.b #$1A : BCS .no_prize
CMP.b #$04 : BCC .no_prize
CMP.b #$08 : BNE .dungeon
.no_prize
LDY.w #BlankTile
BRA .draw_prize
.dungeon
SEP #$30
TAX
LSR
TAY
LDA.l MapMode
REP #$20
BEQ .drawprize
REP #$30
LDA.l MapField
AND.l DungeonItemMasks,X
BEQ .noprize
.drawprize
TXA : LSR : TAX
LDA.l CrystalPendantFlags_2, X
AND.w #$0040 : BNE .is_crystal
SEP #$20
BEQ .no_prize
LDA.w #!P_ICON
BRA .doneprize
TYX
LDA.l CrystalPendantFlags_2,X
AND.b #$40
BNE .crystal
.is_crystal
LDA.w #!C_ICON
BRA .doneprize
LDY.w #PTile
BRA .draw_prize
.noprize
REP #$20
LDA.w #$207F
.crystal
LDY.w #CTile
.doneprize
STA.l HUDPrizeIcon
.draw_prize
STY.w HUDPrizeIcon
;===================================================================================================
;--------------------------------------------------------------------------------
; Draw Magic Meter
DrawMagicMeter_mp_tilemap = $0DFE0F
;--------------------------------------------------------------------------------
LDA.l CurrentMagic : AND.w #$00FF ; crap we wrote over when placing the hook for OnDrawHud
!ADD #$0007
AND.w #$FFF8
TAX ; end of crap
LDA.l InfiniteMagic : AND.w #$00FF : BNE + : JMP .green : +
SEP #$20 : LDA.b #$80 : STA.l CurrentMagic : REP #$30 ; set magic to max
LDX.w #$0080 ; load full magic meter graphics
LDA.b FrameCounter : AND.w #$000C : LSR #2
BEQ .red
CMP.w #0001 : BEQ .yellow
CMP.w #0002 : BNE + : JMP .green : +
.blue
LDA.l DrawMagicMeter_mp_tilemap+0, X : AND.w #$EFFF : STA.l HUDTileMapBuffer+$46
LDA.l DrawMagicMeter_mp_tilemap+2, X : AND.w #$EFFF : STA.l HUDTileMapBuffer+$86
LDA.l DrawMagicMeter_mp_tilemap+4, X : AND.w #$EFFF : STA.l HUDTileMapBuffer+$C6
LDA.l DrawMagicMeter_mp_tilemap+6, X : AND.w #$EFFF : STA.l HUDTileMapBuffer+$06
RTL
.red
LDA.l DrawMagicMeter_mp_tilemap+0, X : AND.w #$E7FF : STA.l HUDTileMapBuffer+$46
LDA.l DrawMagicMeter_mp_tilemap+2, X : AND.w #$E7FF : STA.l HUDTileMapBuffer+$86
LDA.l DrawMagicMeter_mp_tilemap+4, X : AND.w #$E7FF : STA.l HUDTileMapBuffer+$C6
LDA.l DrawMagicMeter_mp_tilemap+6, X : AND.w #$E7FF : STA.l HUDTileMapBuffer+$06
RTL
.yellow
LDA.l DrawMagicMeter_mp_tilemap+0, X : AND.w #$EBFF : STA.l HUDTileMapBuffer+$46
LDA.l DrawMagicMeter_mp_tilemap+2, X : AND.w #$EBFF : STA.l HUDTileMapBuffer+$86
LDA.l DrawMagicMeter_mp_tilemap+4, X : AND.w #$EBFF : STA.l HUDTileMapBuffer+$C6
LDA.l DrawMagicMeter_mp_tilemap+6, X : AND.w #$EBFF : STA.l HUDTileMapBuffer+$0106
RTL
.orange
LDA.l DrawMagicMeter_mp_tilemap+0, X : AND.w #$E3FF : STA.l HUDTileMapBuffer+$46
LDA.l DrawMagicMeter_mp_tilemap+2, X : AND.w #$E3FF : STA.l HUDTileMapBuffer+$86
LDA.l DrawMagicMeter_mp_tilemap+4, X : AND.w #$E3FF : STA.l HUDTileMapBuffer+$C6
LDA.l DrawMagicMeter_mp_tilemap+6, X : AND.w #$E3FF : STA.l HUDTileMapBuffer+$0106
RTL
.green
LDA.l DrawMagicMeter_mp_tilemap+0, X : STA.l HUDTileMapBuffer+$46
LDA.l DrawMagicMeter_mp_tilemap+2, X : STA.l HUDTileMapBuffer+$86
LDA.l DrawMagicMeter_mp_tilemap+4, X : STA.l HUDTileMapBuffer+$C6
LDA.l DrawMagicMeter_mp_tilemap+6, X : STA.l HUDTileMapBuffer+$0106
RTL
NewHUD_DrawMagicMeter:
SEP #$31
LDA.l CurrentMagic
ADC.b #$06 ; carry set by above for +1 to get +7
AND.b #$F8
TAY
;================================================================================
; 16-bit A, 8-bit X
; in: A(b) - Byte to Convert
; out: $04 - $07 (high - low)
;================================================================================
HudHexToDec4Digit:
JSL HexToDec
LDA.l InfiniteMagic
BEQ .set_index
REP #$20
.infinite_magic
LDA.b #$80
STA.l CurrentMagic
TAY
LDA.l HexToDecDigit2
STA.b Scrap04
LDA.b FrameCounter
AND.b #$0C
LSR
LDA.l HexToDecDigit4
STA.b Scrap06
.set_index ; this branch is always 0000 when taken
TAX
RTS
LDA.l MagicMeterColorMasks,X
;================================================================================
; 8-bit registers
; in: A(b) - Byte to Convert
; out: $06 - $07 (high - low)
;================================================================================
HudHexToDec2Digit:
PHP
TYX
TAY : AND.l DrawMagicMeter_mp_tilemap+0,X : STA.w HUDTileMapBuffer+$046
TYA : AND.l DrawMagicMeter_mp_tilemap+0,X : STA.w HUDTileMapBuffer+$086
TYA : AND.l DrawMagicMeter_mp_tilemap+0,X : STA.w HUDTileMapBuffer+$0C6
TYA : AND.l DrawMagicMeter_mp_tilemap+0,X : STA.w HUDTileMapBuffer+$106
REP #$30
PHX
;===================================================================================================
AND.w #$00FF
NewHUD_DoneDrawing:
PLB
RTL
;===================================================================================================
MagicMeterColorMasks:
dw $FFFF ; green - KEEP GREEN FIRST
dw $EFFF ; blue
dw $E7FF ; red
dw $EBFF ; yellow
dw $E3FF ; orange
;===================================================================================================
; Exits with:
; X - ones place tile
; Y - tens place tile
;===================================================================================================
NOP ; this nop makes HUDHex2Digit be at $B00B
HUDHex2Digit:
SEP #$30 ; clear high byte of X and Y and make it so they don't get B
ASL
TAX
SEP #$20
REP #$10
LDA.b #$24 ; tile props in high byte
XBA
LDA.l FastHexTable,X
LSR
LSR
LSR
LSR
ORA.b #$90
TAY
LDA.l FastHexTable,X
AND.b #$0F
STA.b Scrap07
ORA.b #$90
TAX
LDA.l FastHexTable,X
LSR
LSR
LSR
LSR
RTS
;================================================================================
HUDHex4Digit:
JSL HexToDec
REP #$30
LDA.l HexToDecDigit2
ORA.w #$9090
STA.b Scrap04
LDA.l HexToDecDigit4
ORA.w #$9090
STA.b Scrap06
PLX
PLP
LDA.w #$2400
SEP #$20
RTS
;===================================================================================================

View File

@@ -212,7 +212,7 @@ endmacro
!ColonOffset = $83
!PeriodOffset = $80
BlankTile = $883D
BlankCreditsTile = $883D
RenderCreditsStatCounter:
PHB
@@ -309,7 +309,7 @@ RenderCreditsStatCounter:
AND.w #$00FF
CMP.b RemoveZero
BNE +
LDA.w #BlankTile
LDA.w #BlankCreditsTile
BRA ++
+ DEC.b RemoveZero
CLC
@@ -320,7 +320,7 @@ RenderCreditsStatCounter:
AND.w #$00FF
CMP.b RemoveZero
BNE +
LDA.w #BlankTile
LDA.w #BlankCreditsTile
BRA ++
+ DEC.b RemoveZero
CLC
@@ -331,7 +331,7 @@ RenderCreditsStatCounter:
AND.w #$00FF
CMP.b RemoveZero
BNE +
LDA.w #BlankTile
LDA.w #BlankCreditsTile
BRA ++
+ DEC.b RemoveZero
CLC

View File

@@ -1033,7 +1033,16 @@ dw $0000 : db $00 : dw $0000, $0000, $0000, $0000, $0000, $0000, $0000 : db $00,
dw $0000 : db $00 : dw $0000, $0000, $0000, $0000, $0000, $0000, $0000 : db $00, $00, $00
dw $0000 : db $00 : dw $0000, $0000, $0000, $0000, $0000, $0000, $0000 : db $00, $00, $00
;--------------------------------------------------------------------------------
; 0x1802A0 - 0x1802FF (unused)
; 0x1802A0 - 0x1802BF
;---------------------------------------------------------------------------------
; these are dungeon correlations to $7EF364 - $7EF369 so it knows where to store compasses, etc
DungeonItemMasks:
dw $8000, $4000, $2000, $1000, $0800, $0400, $0200, $0100
dw $0080, $0040, $0020, $0010, $0008, $0004
;--------------------------------------------------------------------------------
; 0x1802C0 - 0x1802FF (unused)
;---------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; $308300 (0x180300) - $30834F (0x18034F)
org $308300 ; PC 0x180300