From a2020c9c76455494e936a57566136b344aff3da4 Mon Sep 17 00:00:00 2001 From: cassidoxa Date: Thu, 23 Feb 2023 20:46:40 -0500 Subject: [PATCH 1/3] Add HUD map mode flag, "chest key" totals table, and seen-counter flags for tracking --- compasses.asm | 13 +++++++---- events.asm | 2 +- init.asm | 2 +- inventory.asm | 2 ++ newitems.asm | 64 +++++++++++++++++++++++++++++++++++++++++++++------ ram.asm | 6 +++-- sram.asm | 4 +++- tables.asm | 10 ++++++-- 8 files changed, 85 insertions(+), 18 deletions(-) diff --git a/compasses.asm b/compasses.asm index b9b418a..e55fafa 100644 --- a/compasses.asm +++ b/compasses.asm @@ -42,11 +42,16 @@ DungeonItemMasks: ; these are dungeon correlations to $7EF364 - $7EF369 so it kn dw $8000, $4000, $2000, $1000, $0800, $0400, $0200, $0100 dw $0080, $0040, $0020, $0010, $0008, $0004 ;-------------------------------------------------------------------------------- -InitCompassTotalsRAM: - LDX.b #$00 +InitDungeonCounts: + LDX.b #$0F - LDA.l CompassTotalsROM, X : STA.l CompassTotalsWRAM, X - INX - CPX.b #$0F : !BLT - + DEX + BPL - + LDX.b #$0F + - + LDA.l ChestKeys, X : STA.l MapTotalsWRAM, X + DEX + BPL - RTL diff --git a/events.asm b/events.asm index 4c402dd..0831112 100644 --- a/events.asm +++ b/events.asm @@ -16,7 +16,7 @@ JML.l ReturnFromOnDrawHud ;-------------------------------------------------------------------------------- OnDungeonEntrance: STA.l PegColor ; thing we wrote over - JSL MaybeFlagCompassTotalEntrance + JSL MaybeFlagDungeonTotalsEntrance RTL ;-------------------------------------------------------------------------------- OnPlayerDead: diff --git a/init.asm b/init.asm index 0f1d33a..e717b4c 100644 --- a/init.asm +++ b/init.asm @@ -67,6 +67,6 @@ Init_PostRAMClear: JSL MSUInit JSL InitRNGPointerTable - JSL InitCompassTotalsRAM + JSL InitDungeonCounts JML $00D463 ; The original target of the jump table that we hijacked diff --git a/inventory.asm b/inventory.asm index 4e4ae52..64c34ac 100644 --- a/inventory.asm +++ b/inventory.asm @@ -408,6 +408,7 @@ AddInventory: JSR .incrementBigKey JMP .done + CPY.b #$33 : BNE + ; Map + JSL MaybeFlagMapTotalPickup JSR .incrementMap JMP .done + CPY.b #$37 : !BLT + ; Items $37 - $39 - Pendants @@ -492,6 +493,7 @@ AddInventory: JMP .done + CPY.b #$70 : !BLT + ; Items $70 - $7F - Free Maps CPY.b #$80 : !BGE + + JSL MaybeFlagMapTotalPickup JSR .incrementMap JMP .done + CPY.b #$80 : !BLT + ; Items $80 - $8F - Free Compasses diff --git a/newitems.asm b/newitems.asm index 6d53808..0826564 100644 --- a/newitems.asm +++ b/newitems.asm @@ -1087,14 +1087,23 @@ MaybeFlagCompassTotalPickup: .done RTL ;-------------------------------------------------------------------------------- -; Set the compass count display flag if we're entering a dungeon and alerady have -; that compass -MaybeFlagCompassTotalEntrance: - LDX.w DungeonID : CPX.b #$FF : BEQ .done ; Skip if we're not entering dungeon - LDA.l CompassMode : AND.w #$000F : BEQ .done ; Skip if we're not showing compass counts - CMP.w #$0002 : BEQ .countShown +; Set the dungeon item count display flags if we're entering a dungeon and have the +; corresponding dungeon item +MaybeFlagDungeonTotalsEntrance: + LDX.w DungeonID : CPX.b #$FF : BEQ .done ; Skip if we're not entering dungeon + LDA.l CompassMode : AND.w #$000F : BEQ .maps ; Skip if we're not showing compass counts + JSR.w FlagCompassCount + .maps + LDA.l MapHUDMode : AND.w #$000F : BEQ .done + LDX.w DungeonID + JSR.w FlagMapCount + .done +RTL +;-------------------------------------------------------------------------------- +FlagCompassCount: + CMP.w #$0002 : BEQ .compassShown LDA.l CompassField : AND.l DungeonItemMasks, X : BEQ .done ; skip if we don't have compass - .countShown + .compassShown SEP #$20 TXA : LSR : STA.b Scrap04 : LDA.b #$0F : !SUB Scrap04 ; Compute flag index CMP.b #$08 : !BGE ++ @@ -1109,5 +1118,46 @@ MaybeFlagCompassTotalEntrance: ORA.l CompassCountDisplay+1 : STA.l CompassCountDisplay+1 REP #$20 .done +RTS +;-------------------------------------------------------------------------------- +FlagMapCount: + CMP.w #$0002 : BEQ .mapShown + LDA.l MapField : AND.l DungeonItemMasks, X : BEQ .done ; skip if we don't have map + .mapShown + SEP #$20 + TXA : LSR : STA.b Scrap04 : LDA.b #$0F : !SUB Scrap04 ; Compute flag index + CMP.b #$08 : !BGE ++ + %ValueShift() + ORA.l MapCountDisplay : STA.l MapCountDisplay + REP #$20 + BRA .done + ++ + !SUB #$08 + %ValueShift() + BIT.b #$C0 : BEQ + : LDA.b #$C0 : + ; Make Hyrule Castle / Sewers Count for Both + ORA.l MapCountDisplay+1 : STA.l MapCountDisplay+1 + REP #$20 + .done +RTS +;-------------------------------------------------------------------------------- +MaybeFlagMapTotalPickup: + LDA.l MapMode : AND.b #$0F : BEQ .done + LDA.w DungeonID : CMP.b #$FF : BEQ .done + LSR : STA.b Scrap04 : LDA.b #$0F : !SUB Scrap04 ; Compute flag "index" + CPY.b #$25 : BEQ .setFlag ; Set flag if it's a compass for this dungeon + STA.b Scrap04 + TYA : AND.b #$0F : CMP.b Scrap04 : BNE .done ; Check if map is for this dungeon + .setFlag + CMP.b #$08 : !BGE ++ + %ValueShift() + ORA.l MapCountDisplay : STA.l MapCountDisplay + BRA .done + ++ + !SUB #$08 + %ValueShift() + BIT.b #$C0 : BEQ + : LDA.b #$C0 : + ; Make Hyrule Castle / Sewers Count for Both + ORA.l MapCountDisplay+1 : STA.l MapCountDisplay+1 + .done RTL ;-------------------------------------------------------------------------------- + diff --git a/ram.asm b/ram.asm index 64a6ec3..0b75f5f 100644 --- a/ram.asm +++ b/ram.asm @@ -544,8 +544,9 @@ RxStatus: skip 1 ; TxBuffer: skip $7F ; TxStatus: skip 1 ; skip $10 ; Unused -CompassTotalsWRAM: skip $10 ; skip $10 -skip $40 ; Reserved for general dungeon tracking data. May have over +CompassTotalsWRAM: skip $10 ; \ Compass and map dungeon HUD display totals. Placed in WRAM +MapTotalsWRAM: skip $10 ; / on boot for tracking. +skip $30 ; Reserved for general dungeon tracking data. May have over ; allocated here. Feel free to reassign. skip $40 ; Unused skip $260 ; Unused @@ -913,6 +914,7 @@ endmacro %assertRAM(TxBuffer, $7F5380) %assertRAM(TxStatus, $7F53FF) %assertRAM(CompassTotalsWRAM, $7F5410) +%assertRAM(MapTotalsWRAM, $7F5420) %assertRAM(DialogBuffer, $7F5700) %assertRAM(MiniGameTime, $7FFE00) %assertRAM(MiniGameTimeFinal, $7FFE04) diff --git a/sram.asm b/sram.asm index ce6c039..e7c852e 100644 --- a/sram.asm +++ b/sram.asm @@ -317,7 +317,8 @@ HeartPieceCounter: skip 1 ; Total Number of heartpieces collected (integer CrystalCounter: skip 1 ; Total Number of crystals collected (integer) DungeonsCompleted: skip 2 ; Bitfield indicating whether a dungeon's prize has been collected. ; This has the same shape as the dungeon item bitfields. -skip 44 ; Unused +MapCountDisplay: skip 2 ; +skip 42 ; Unused ServiceSequence: ; See servicerequest.asm ServiceSequenceRx: skip 8 ; Service sequence receive ServiceSequenceTx: skip 8 ; Service sequence transmit @@ -602,6 +603,7 @@ endmacro %assertSRAM(HeartPieceCounter, $7EF470) %assertSRAM(CrystalCounter, $7EF471) %assertSRAM(DungeonsCompleted, $7EF472) +%assertSRAM(MapCountDisplay, $7EF474) ;-------------------------------------------------------------------------------- %assertSRAM(ServiceSequence, $7EF4A0) %assertSRAM(ServiceSequenceRx, $7EF4A0) diff --git a/tables.asm b/tables.asm index 8fbc02b..c3f80f0 100644 --- a/tables.asm +++ b/tables.asm @@ -118,9 +118,11 @@ org $308038 ; PC 0x180038 LampConeSewers: db #$01 ; #$00 = Off - #$01 = On (default) ;-------------------------------------------------------------------------------- -; 0x180039 - 0x18003A (Unused) +; 0x180039 - 0x180039 (Unused) ;-------------------------------------------------------------------------------- -org $30803B ; PC 0x18003B - PC 0x18003C +org $30803A ; PC 0x18003B - PC 0x18003C +MapHUDMode: +db #$00 ; #$00 = Off (default) - #$01 = Display Dungeon Count w/Map - #$02 = Display Dungeon Count Always MapMode: db #$00 ; #$00 = Always On (default) - #$01 = Require Map Item CompassMode: @@ -2544,6 +2546,10 @@ org $30F000 ; PC 0x187000-0x18700F CompassTotalsROM: db $08, $08, $06, $06, $02, $0A, $0E, $08, $08, $08, $06, $08, $0C, $1B, $00, $00 +org $30F010 +ChestKeys: ; PC 0x187010-0x18701F +db $01, $01, $00, $01, $02, $01, $06, $03, $03, $02, $01, $01, $04, $04, $00, $00 + ;-------------------------------------------------------------------------------- ; 0x187010 - 187FFF (unused) ;-------------------------------------------------------------------------------- From 068d4c244915a819cf374d91885986822608bc94 Mon Sep 17 00:00:00 2001 From: cassidoxa Date: Thu, 23 Feb 2023 21:46:27 -0500 Subject: [PATCH 2/3] Port map key counter on HUD from DR --- compasses.asm | 51 +++++++++++++++++++++++++++++++++++++-------------- newhud.asm | 4 +--- tables.asm | 2 +- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/compasses.asm b/compasses.asm index e55fafa..0dbc4ac 100644 --- a/compasses.asm +++ b/compasses.asm @@ -1,22 +1,24 @@ -DrawDungeonCompassCounts: +DrawDungeonItemCounts: 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 + TXA : LSR : TAX : BNE + + INC ; Count sewer as Hyrule Castle + + + JSR.w DrawCompassCounts + JSR.w DrawMapCounts + .done +RTL - BIT.w #$0002 : BNE ++ ; if CompassMode==2, we don't check for the compass +DrawCompassCounts: + PHX + LDA.l CompassMode : 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 @@ -25,18 +27,39 @@ DrawDungeonCompassCounts: 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 + PLX +RTS - .done -RTL +DrawMapCounts: + PHX + LDA.l MapHUDMode : BIT.w #$0002 : BNE + ; if MapHUDMode==2, we don't check for map + LDA.l MapField : AND.l DungeonItemMasks, X ; Load map values to A, mask with dungeon item masks + BEQ .done ; skip if we don't have map + + + LDA.l MapTotalsWRAM, X : AND.w #$00FF + SEP #$20 + JSR HudHexToDec2Digit + REP #$20 + PHX + LDX.b Scrap07 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$A6 + PLX + LDA.l DungeonCollectedKeys, X : AND.w #$00FF + SEP #$20 + JSR HudHexToDec2Digit + REP #$20 + LDX.b Scrap07 : TXA : ORA.w #$2400 : STA.l HUDTileMapBuffer+$A2 + LDA.w #$2830 : STA.l HUDTileMapBuffer+$A4 ; draw the slash + .done + PLX +RTS 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 diff --git a/newhud.asm b/newhud.asm index 68a0b12..5bcfef0 100644 --- a/newhud.asm +++ b/newhud.asm @@ -85,9 +85,7 @@ NewDrawHud: ;================================================================================ ; Draw Dungeon Compass Counts ;================================================================================ - LDA.l CompassMode : AND.w #$00FF : BEQ + ; skip if CompassMode is 0. - JSL.l DrawDungeonCompassCounts ; compasses.asm - + + JSL.l DrawDungeonItemCounts ; compasses.asm ;================================================================================ ; Draw key count diff --git a/tables.asm b/tables.asm index c3f80f0..556b7bc 100644 --- a/tables.asm +++ b/tables.asm @@ -118,7 +118,7 @@ org $308038 ; PC 0x180038 LampConeSewers: db #$01 ; #$00 = Off - #$01 = On (default) ;-------------------------------------------------------------------------------- -; 0x180039 - 0x180039 (Unused) +; 0x180039 (Unused) ;-------------------------------------------------------------------------------- org $30803A ; PC 0x18003B - PC 0x18003C MapHUDMode: From d76d4b4254e1738bb8ae326e619ed17d82269390 Mon Sep 17 00:00:00 2001 From: cassidoxa Date: Fri, 24 Feb 2023 16:09:07 -0500 Subject: [PATCH 3/3] Skip HUD count drawing routine if nothing enabled --- newhud.asm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/newhud.asm b/newhud.asm index 5bcfef0..d952675 100644 --- a/newhud.asm +++ b/newhud.asm @@ -85,7 +85,9 @@ NewDrawHud: ;================================================================================ ; Draw Dungeon Compass Counts ;================================================================================ - JSL.l DrawDungeonItemCounts ; compasses.asm + LDA.l CompassMode : ORA.l MapHUDMode : BIT #$0003 : BEQ + + JSL.l DrawDungeonItemCounts ; compasses.asm + + ;================================================================================ ; Draw key count