From aaff8a197558902a1457feecc626aadc0ff652b5 Mon Sep 17 00:00:00 2001 From: codemann8 Date: Mon, 30 Jan 2023 10:34:48 -0600 Subject: [PATCH 1/3] Improved door landing Improved door landing --- LTTP_RND_GeneralBugfixes.asm | 6 ++++++ doorrando/drhooks.asm | 2 ++ doorrando/normal.asm | 26 +++++++++++++++++++++++++- doorrando/spiral.asm | 17 +++++++---------- dungeonmap.asm | 2 +- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/LTTP_RND_GeneralBugfixes.asm b/LTTP_RND_GeneralBugfixes.asm index 56dd2bf..8ebfb5e 100644 --- a/LTTP_RND_GeneralBugfixes.asm +++ b/LTTP_RND_GeneralBugfixes.asm @@ -519,6 +519,9 @@ Dungeon_SaveRoomData_justKeys: org $02B861 Dungeon_SaveRoomQuadrantData: +org $02C11D +CalculateTransitionLanding: + org $02D9B9 Underworld_LoadSpawnEntrance: @@ -657,6 +660,9 @@ OverworldMap_DarkWorldTilemap: org $0ABAB9 OverworldMap_LoadSprGfx: +org $8AE817 +DungeonMapBossRooms: + org $0CD7D1 NameFile_MakeScreenVisible: org $0CDB3E diff --git a/doorrando/drhooks.asm b/doorrando/drhooks.asm index 3022d71..efde673 100644 --- a/doorrando/drhooks.asm +++ b/doorrando/drhooks.asm @@ -54,6 +54,8 @@ org $82941a ; <- Bank02.asm : 3748 module 7.12.11 (LDA $0464 : BNE BRANCH_$11513 jsl StraightStairsTrapDoor : rts org $828b54 ; <- Bank02.asm : 2200 (JSL UseImplicitRegIndexedLocalJumpTable) jsl InroomStairsTrapDoor +org $82c146 +jsl HandleSpecialDoorLanding org $8289a0 ; JSL $0091C4 jsl QuadrantLoadOrderBeforeScroll diff --git a/doorrando/normal.asm b/doorrando/normal.asm index 13323d8..6666532 100644 --- a/doorrando/normal.asm +++ b/doorrando/normal.asm @@ -324,7 +324,7 @@ GetTileAttribute: { phk : pea.w .jslrtsreturn-1 pea.w $02802c - jml $02c11d ; mucks with x/y sets a to Tile Attribute, I think + jml CalculateTransitionLanding ; mucks with x/y sets a to Tile Attribute, I think .jslrtsreturn rts } @@ -416,4 +416,28 @@ InroomStairsTrapDoor: pla : pla : pla jsl StraightStairsTrapDoor_reset jml $028b15 ; just some RTS in bank 02 +} + +HandleSpecialDoorLanding: { + LDA.l $7F2000,X ; what we wrote over + SEP #$30 + JSL HandleIncomingDoorState + CMP #$34 : bne + ; inroom stairs + PHA : LDA #$26 : STA $045E : PLA + + +} + +; A = tiletype +HandleIncomingDoorState: +{ + PHA + LDA.l DRMode : BEQ .noDoor + PLA : PHA : AND.b #$FA : CMP.b #$80 : bne .noDoor + + .setDoorState + LDA.w $0418 : AND.b #$02 : BNE + : INC + + STA.b $6C + + .noDoor + PLA : RTL } \ No newline at end of file diff --git a/doorrando/spiral.asm b/doorrando/spiral.asm index e73b5e1..4ce37e2 100644 --- a/doorrando/spiral.asm +++ b/doorrando/spiral.asm @@ -207,19 +207,16 @@ InroomStairsWarp: { .normal lda $01 : sta $fe ; trap door lda $07 : sta $03 : beq + - ldy $a0 : cpy #$51 : beq .specialFix ; throne room - cpy #$02 : beq .specialFix ; sewers pull switch - cpy #$71 : beq .specialFix ; castle armory - lda #$e0 - bra ++ + lda $01 : and #$04 : bne .specialFix + lda #$e0 : bra ++ .specialFix - lda #$c8 - bra ++ + lda #$c8 : bra ++ + %StonewallCheck($43) - lda #$1b - ++ - sta $20 + lda $01 : and #$04 : bne + + lda #$1b : bra ++ + + lda #$33 + ++ sta $20 inc $07 : stz $02 : lda #$78 : sta $22 lda $01 : and #$03 : beq ++ cmp #$02 : !bge + diff --git a/dungeonmap.asm b/dungeonmap.asm index 39b4624..5ad5ea0 100644 --- a/dungeonmap.asm +++ b/dungeonmap.asm @@ -21,7 +21,7 @@ DoDungeonMapBossIcon: ; get dungeon boss room ++ REP #$30 - LDA.l $8AE817,X + LDA.l DungeonMapBossRooms, X ASL TAX From 2411d0344e97fcb33586a8c4cb382972c6cec97f Mon Sep 17 00:00:00 2001 From: aerinon Date: Fri, 17 Feb 2023 23:48:08 -0700 Subject: [PATCH 2/3] Minor optimization on handling special door landing --- doorrando/normal.asm | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/doorrando/normal.asm b/doorrando/normal.asm index 6666532..ceba175 100644 --- a/doorrando/normal.asm +++ b/doorrando/normal.asm @@ -421,23 +421,20 @@ InroomStairsTrapDoor: HandleSpecialDoorLanding: { LDA.l $7F2000,X ; what we wrote over SEP #$30 - JSL HandleIncomingDoorState + ; A = tiletype + HandleIncomingDoorState: + PHA + LDA.l DRMode : BEQ .noDoor + PLA : PHA : AND.b #$FA : CMP.b #$80 : bne .noDoor + + .setDoorState + LDA.w $0418 : AND.b #$02 : BNE + : INC + + STA.b $6C + + .noDoor + PLA CMP #$34 : bne + ; inroom stairs PHA : LDA #$26 : STA $045E : PLA + +RTL } - -; A = tiletype -HandleIncomingDoorState: -{ - PHA - LDA.l DRMode : BEQ .noDoor - PLA : PHA : AND.b #$FA : CMP.b #$80 : bne .noDoor - - .setDoorState - LDA.w $0418 : AND.b #$02 : BNE + : INC - + STA.b $6C - - .noDoor - PLA : RTL -} \ No newline at end of file From 096157e981ac52829b64268f1692e2948a51526e Mon Sep 17 00:00:00 2001 From: aerinon Date: Fri, 24 Feb 2023 14:22:42 -0700 Subject: [PATCH 3/3] Changes graphical status of standard exits when blocking exits in rain Fixes graphical issues with sanctuary and swamp hub lobbies Major fix for decoupled doors landing area Fix for multiworld absorbables --- doorrando/doorrando.asm | 1 + doorrando/drhooks.asm | 12 +- doorrando/edges.asm | 26 ++++ doorrando/entrance_fixes.asm | 274 +++++++++++++++++++++++++++++++++++ doorrando/normal.asm | 3 +- doorrando/overrides.asm | 20 --- keydrop/standing_items.asm | 7 +- 7 files changed, 316 insertions(+), 27 deletions(-) create mode 100644 doorrando/entrance_fixes.asm diff --git a/doorrando/doorrando.asm b/doorrando/doorrando.asm index 469af9d..2a2ff56 100644 --- a/doorrando/doorrando.asm +++ b/doorrando/doorrando.asm @@ -52,6 +52,7 @@ incsrc edges.asm incsrc math.asm incsrc hudadditions.asm incsrc dr_lobby.asm +incsrc entrance_fixes.asm warnpc $A79C00 incsrc doortables.asm diff --git a/doorrando/drhooks.asm b/doorrando/drhooks.asm index dce4ae3..b74c8a3 100644 --- a/doorrando/drhooks.asm +++ b/doorrando/drhooks.asm @@ -44,8 +44,6 @@ org $8293d1 ; <- 113d1 - Bank02.asm : 3683 (ADD $20 : STA $20 BRANCH_IOTA) jsl StraightStairsFix : nop org $829396 ; <- 11396 - Bank02.asm : 3641 (LDA $01C322, X) jsl StraightStairLayerFix -org $82c06d ; <- Bank02.asm : 9874 (LDX $0418, CMP.b #$02) -jsl DoorToStraight : nop org $82c092 ; STA $0020, Y : LDX #$00 jsl DoorToInroom : nop org $82c0f8 ; CMP $02C034, X @@ -175,9 +173,6 @@ JSL RetrieveBunnyState : NOP org $82d9ce ; <- Bank02.asm : Dungeon_LoadEntrance 10829 (STA $A0 : STA $048E) JSL CheckDarkWorldSpawn : NOP -org $81891e ; <- Bank 01.asm : 991 Dungeon_LoadType2Object (LDA $00 : XBA : AND.w #$00FF) -JSL RainPrevention : BCC + : RTS : NOP : + - org $9edabf ; <- sprite_energy_ball.asm : 86-7 Sprite_EnergyBall (LDA.b #$10 : LDX.b #$00) JSL StandardAgaDmg @@ -216,3 +211,10 @@ jsl CheckIfDoorsOpen bcs .normal rts .normal + +; fixes an issue with edges -> normal doors (bombable, dashable, keydoor) +org $82C06A +JSL TransitionCalculateLanding_Fix : NOP #2 + +org $82C157 +JSL AlwaysPushThroughFDoors diff --git a/doorrando/edges.asm b/doorrando/edges.asm index 58852b1..b7d11f1 100644 --- a/doorrando/edges.asm +++ b/doorrando/edges.asm @@ -1,4 +1,9 @@ +; defines +; Ram usage +EdgeToNormalFlag = $7E1200 + HorzEdge: + LDA.b #$00 : STA.l EdgeToNormalFlag cpy #$ff : beq + jsr DetectWestEdge : ldy #$02 : bra ++ + jsr DetectEastEdge @@ -13,6 +18,7 @@ HorzEdge: + clc : rts VertEdge: + LDA.b #$00 : STA.l EdgeToNormalFlag cpy #$ff : beq + jsr DetectNorthEdge : bra ++ + jsr DetectSouthEdge @@ -56,6 +62,7 @@ LoadEdgeRoomVert: lda $04 : and #$80 : bne .edge lda $04 : sta $01 ; load up flags in $01 and #$03 : cmp #$03 : beq .inroom + LDA.b #$01 : STA.l EdgeToNormalFlag ldy #$01 : jsr ShiftVariablesMainDir jsr PrepScrollToNormal bra .scroll @@ -296,4 +303,23 @@ DetectEastEdge: .end txa : rts +TransitionCalculateLanding_Fix: + LDA.l EdgeToNormalFlag : BEQ + + LDX.w $0418 : CPX.b #$01 : BNE + + LDA.b $20 : SBC #$08 : STA.b $20 + + PHK : PEA.w .jslrtsreturn-1 + PEA.w $02802C + JML CalculateTransitionLanding + .jslrtsreturn + LDX.w $0418 : CPX.b #$01 : BNE .zero ; the LDX is vanilla and needs to always run + LDA.l EdgeToNormalFlag : BEQ + + LDA.b $20 : ADC #$08 : STA.b $20 + .zero LDA.b #$00 : STA.l EdgeToNormalFlag + + JSL DoorToStraight +RTL +AlwaysPushThroughFDoors: + PHA : AND.b #$F0 : CMP.b #$F0 : BNE + + PLA : RTL + + PLA : AND.b #$8E : CMP.b #$80 + RTL diff --git a/doorrando/entrance_fixes.asm b/doorrando/entrance_fixes.asm new file mode 100644 index 0000000..7052972 --- /dev/null +++ b/doorrando/entrance_fixes.asm @@ -0,0 +1,274 @@ +;=================================================================================================== +; The only specific concern to keep in mind with this code is that your databank will be $00 +; Actually, it should be $80, if you're using my fastrom changes. +; +; Leave all your door data vanilla +; Do not try to adjust doors as I previously suggested (not worth the effort) +; We need a few hooks and some light hardcoding either way +; Might as well just do it in a brute, but reliable, way +; +; In brief, this is the hack we're making: +; 1) Let vanilla routines draw the door normally +; 2) Draw over what vanilla just drew +; 3) Hijack the door tile type routine +; and replace the vanilla value with that of solid collision +;=================================================================================================== +pushpc + +org $01892F +DoorDrawJankMove: + JML PrepDoorDraw + +.return + JSL AdjustEscapeDoorGraphics + RTS + +; we don't want to overwrite the JMP ($000E) that's already there +; Well, we could, but we don't need to +warnpc $018939 + +org $01BF43 + JSL AdjustEscapeDoorCollision + +pullpc + +;=================================================================================================== + +PrepDoorDraw: + ; first off, we need this routine to return to our jank hook + ; otherwise, finding a reliable place to put the graphics change check will be a pin + ; so push the address to return to the routine + + ; It's a lot to explain why this is necessary + ; Much easier to just tell you to look at $01890D in the disassembly + ; and you should understand the vanilla program flow we need to reject + PEA.w DoorDrawJankMove_return-1 + + ; copy vanilla code (but fast rom) + LDA.l $8186F0,X + STA.b $0E + + LDX.b $02 + LDA.b $04 + + ; and to execute the jump, we'll use the JMP ($000E) we carefully avoided overwriting + JML.l $818939 + +;=================================================================================================== + +; Adjustment stage 1: graphics +AdjustEscapeDoorGraphics: + JSR IdentifyBlockedEntrance + BCS .replace_graphics + JSR IdentifySancEntrance + BCS .fix_sanctuary_entrance + JSR IdentifySwampEntrance + BCS .fix_swamp_entrance + ; Do nothing + RTL + +;--------------------------------------------------------------------------------------------------- + +.replace_graphics ; for blocked doors + ; using the value in $19A0 should be fine for finding the graphics + ; the only caveat is that this appears to locate the tile just above the north-west corner + ; so below, I've indicated that offset with a +$xxx after the base tilemap buffer + ; The only odd thing I notice with this position is that some bad hardcoded adjust for + ; exploding walls that shouldn't affect how we use this value at all! + LDY.w $0460 ; get door index + + LDX.w $19A0-2,Y ; get tilemap index + + ; hardcoded shutter door graphics tile replacement + + ; the horizontal flips could easily be explicit LDAs + ; but it's probably best the door is symmetrical + ; using ORA makes your intent more clear + ; and gives you fewer values to change if you experiment with other graphics + + ; row 1 + LDA.w #$8838 + STA.l $7E2000+$080,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$086,X + + ; row 2 + LDA.w #$8828 + STA.l $7E2000+$100,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$106,X + + LDA.w #$8829 + STA.l $7E2000+$102,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$104,X + + ; the state of the A, X, and Y registers is irrelevant when we exit + ; they're all subsequently loaded with new values + RTL + +.fix_sanctuary_entrance + LDY.w $0460 ; get door index + LDX.w $19A0-2,Y ; get tilemap index + + ; row 0 + LDA.w #$14C4 + STA.l $7E2000+$000,X ; sanity check = should calculate to 7e3bbc + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$006,X + + LDA.w #$14C5 + STA.l $7E2000+$002,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$004,X + + ; row 1 + LDA.w #$14E8 + STA.l $7E2000+$082,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$084,X + + ; row 2 + LDA.w #$14F8 + STA.l $7E2000+$102,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$104,X + +.fix_swamp_entrance + LDY.w $0460 ; get door index + LDX.w $19A0-2,Y ; get tilemap index + + ; row 0 + LDA.w #$9DfC + STA.l $7E2000+$000,X + STA.l $7E2000+$002,X + STA.l $7E2000+$004,X + STA.l $7E2000+$006,X + + ; row 1 + LDA.w #$0908 + STA.l $7E2000+$080,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$086,X + + LDA.w #$14E8 + STA.l $7E2000+$082,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$084,X + + ; row 2 + LDA.w #$0918 + STA.l $7E2000+$100,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$106,X + + LDA.w #$14F8 + STA.l $7E2000+$102,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$104,X + + ; row 3 + LDA.w #$A82C + STA.l $7E2000+$180,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$186,X + + LDA.w #$A82D + STA.l $7E2000+$182,X + ORA.w #$4000 ; horizontally flip + STA.l $7E2000+$184,X + RTL + +IdentifySancEntrance: + LDA.b $A0 : CMP.w #$0012 : BNE + + LDA.b $0A : CMP.w #$0010 : BNE + + SEC : RTS + + CLC : RTS + +IdentifySwampEntrance: + LDA.b $A0 : CMP.w #$0036 : BNE + + LDA.b $0A : CMP.w #$0010 : BNE + + SEC : RTS + + CLC : RTS + +;=================================================================================================== + +; Leaving this here in case you desire a fully custom door later +; For now, we'll just hardcode the tiles, as I did above +; I put these in column order because that's how they're expected for the vanilla draw routines +; but I changed my mind on redefining things +; and am too lazy to change it to a row-wise listing +BlockedEntrance: + dw $8838, $8828, $A888 ; column 0 + dw $14E8, $8829, $C888 ; column 1 + dw $14E8, $8829, $A888 ; column 2 + dw $C838, $C828, $C888 ; column 3 + +;=================================================================================================== + +; Adjustment stage 2: collision +AdjustEscapeDoorCollision: + LSR ; vanilla shift + + ; save our parameters + ; but one or both of these may not be necessary depending on how you detect these doors + ; all that matters is that after identifying blockage, we have: + ; Y is the same as what we entered with + ; X has A>>1, for whatever A entered with + PHA + LDA.w $1980, Y ; grab door info (type) + AND.w #$00FF + STA.b $0A ; store in temporary variable + JSR IdentifyBlockedEntrance + + PLX ; this is a TAX in vanilla, just have X pull A instead + + BCS .block_entrance + + ; vanilla value + LDA.b $00 + + RTL + +.block_entrance + LDA.w #$0101 ; load tile type for solid collision + + RTL + +;=================================================================================================== + +; Enter with: +; $0A containing the door information: position and type bytes +; which should be from $1980, Y or [$B7], Y depending on where in the door process we are +; Exit with: +; carry clear - leave door alone +; carry set - block door +IdentifyBlockedEntrance: + LDA.l ProgressIndicator : AND.w #$00FF : CMP.w #$0002 : BCS .leave_alone ; only in rain states (0 or 1) + LDA.l ProgressFlags : AND.w #$0004 : BNE .leave_alone ; zelda's been rescued + LDA.l BlockSanctuaryDoorInRain : BEQ + ;flagged + LDA.b $A0 : CMP.w #$0012 : BNE + + ; we're in the sanctuary + ; this code could be removed because you can't reach sanc without zelda currently + ; but that's enforced in the logic, so this is to catch that case in case some mode allows it + LDA.l FollowerIndicator : AND.w #$00FF : CMP.w #$0001 : BEQ .leave_alone ; zelda is following + LDA.b $0A + CMP.w #$000A : BCC .leave_alone + CMP.w #$0014 : BCS .leave_alone + .block_door + SEC : RTS + + LDA.l BlockCastleDoorsInRain : AND.w #$00FF : BEQ .leave_alone + LDX #$FFFE + - INX #2 + LDA.l RemoveRainDoorsRoom, X : CMP.w #$FFFF : BEQ .leave_alone + CMP $A0 : BNE - + LDA.b $0A + CMP.w #$000A : BCC .continue + CMP.w #$0014 : BCS .continue + BRA .block_door + .continue + BRA - + .leave_alone + CLC : RTS + +;=================================================================================================== \ No newline at end of file diff --git a/doorrando/normal.asm b/doorrando/normal.asm index ceba175..c7626a4 100644 --- a/doorrando/normal.asm +++ b/doorrando/normal.asm @@ -364,7 +364,8 @@ DoorToStraight: lda $a0 : cmp #$51 : bne .skip lda #$04 : sta $4e .skip pla - .end ldx $0418 : cmp #$02 ;what we wrote over + ; the ldx $0418 is now taken care of by TransitionCalculateLanding_Fix + .end cmp #$02 ;what we wrote over rtl } diff --git a/doorrando/overrides.asm b/doorrando/overrides.asm index 820932a..234d614 100644 --- a/doorrando/overrides.asm +++ b/doorrando/overrides.asm @@ -93,26 +93,6 @@ RetrieveBunnyState: STA $5D + RTL -RainPrevention: - LDA $00 : XBA : AND #$00FF : STA.b $0A ; what we wrote over - PHA - LDA ProgressIndicator : AND #$00FF : CMP #$0002 : !BGE .done ; only in rain states (0 or 1) - LDA.l ProgressFlags : AND #$0004 : BNE .done ; zelda's been rescued - LDA.l BlockSanctuaryDoorInRain : BEQ + ;flagged - LDA $A0 : CMP #$0012 : BNE + ;we're in the sanctuary - LDA.l FollowerIndicator : AND #$00FF : CMP #$0001 : BEQ .done ; zelda is following - LDA $00 : AND #$00FF : CMP #$00A1 : BNE .done ; position is a1 - PLA : LDA #$0008 : RTL - + LDA.l BlockCastleDoorsInRain : AND #$00FF : BEQ .done ;flagged - LDX #$FFFE - - INX #2 : LDA.l RemoveRainDoorsRoom, X : CMP #$FFFF : BEQ .done - CMP $A0 : BNE - - SEP #$20 : LDA.l RainDoorMatch, X : CMP $00 : BNE .continue - INC.w $0460 : INC.w $0460 : REP #$20 : PLA : SEC : RTL - .continue - REP #$20 : BRA - - .done PLA : CLC : RTL - ; A should be how much dmg to do to Aga when leaving this function StandardAgaDmg: LDX.b #$00 ; part of what we wrote over diff --git a/keydrop/standing_items.asm b/keydrop/standing_items.asm index e1075b8..99349a3 100644 --- a/keydrop/standing_items.asm +++ b/keydrop/standing_items.asm @@ -229,6 +229,9 @@ LoadMultiWorldPotItem: PLX BRA SaveMajorItemDrop +MultiItemExit: + LDA.w #$0008 : STA.w $0B9C +RTL LoadMajorPotItem: INY : INY @@ -240,7 +243,9 @@ SaveMajorItemDrop: STA.w SpawnedItemID STX.w SpawnedItemIndex INC.w SpawnedItemFlag - TAY : LDA.w #$0008 + TAY + LDA.l SpawnedItemIsMultiWorld : BNE MultiItemExit + LDA.w #$0008 CPY.w #$0036 : BNE + ; Red Rupee LDA.w #$0016 : BRA .substitute + CPY.w #$0044 : BNE + ; 10 pack arrows