Merge branch 'OWMain' into overworld_kara

This commit is contained in:
2023-02-26 14:30:05 -06:00
10 changed files with 375 additions and 59 deletions

View File

@@ -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

View File

@@ -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
@@ -56,11 +54,6 @@ org $828b54 ; <- Bank02.asm : 2200 (JSL UseImplicitRegIndexedLocalJumpTable)
jsl InroomStairsTrapDoor
org $82c146
jsl HandleSpecialDoorLanding
org $82c23a
HandleIncomingDoorStateLocal:
jsl HandleIncomingDoorState : rts
org $82c172
jsr HandleIncomingDoorStateLocal
org $8289a0 ; JSL $0091C4
jsl QuadrantLoadOrderBeforeScroll
@@ -180,12 +173,11 @@ 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
org $89F7B2 ; 09F7B2 Module17_01 S&Q
JSL StandardSaveAndQuit
org $89a681 ; < - similar to talalong.asm : 1157 (JSL Main_ShowTextMessage)
JSL BlindsAtticHint : NOP #2
@@ -219,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

View File

@@ -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

View File

@@ -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
;===================================================================================================

View File

@@ -296,7 +296,6 @@ StraightStairsAdj:
stz $046d
.noScroll
jsr GetTileAttribute : tax
jsl HandleIncomingDoorState
lda $11 : cmp #$12 : beq .goingNorth
lda $a2 : cmp #$51 : bne ++
rep #$20 : lda #$0018 : !add $20 : sta $20 : sep #$20 ; special fix for throne room
@@ -365,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
}
@@ -422,20 +422,19 @@ InroomStairsTrapDoor:
HandleSpecialDoorLanding: {
LDA.l $7F2000,X ; what we wrote over
SEP #$30
CMP #$34 : bne + ; inroom stairs
PHA : LDA #$26 : STA $045E : PLA
+
}
; Y = tiletype, also written to $4E
HandleIncomingDoorState:
{
; A = tiletype
HandleIncomingDoorState:
PHA
LDA.l DRMode : BEQ .noDoor
CPY.b #$01 : !bge .noDoor
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
STY.b $4E : TYA ; what we wrote over
PLY : RTL
}
.noDoor
PLA
CMP #$34 : bne + ; inroom stairs
PHA : LDA #$26 : STA $045E : PLA
+ RTL
}

View File

@@ -94,26 +94,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
@@ -121,6 +101,14 @@ StandardAgaDmg:
LDA.b #$10 ; hurt him!
+ RTL ; A is zero if the AND results in zero and then Agahnim's invincible!
StandardSaveAndQuit:
LDA.b #$0F : STA.b $95 ; what we wrote over
LDA.l ProgressFlags : AND #$04 : BNE +
LDA.l DRMode : BEQ +
LDA.l StartingEntrance : CMP.b #$02 : BCC +
LDA.b #$03 : STA.l StartingEntrance ; set spawn to uncle if >=
+ RTL
; note: this skips both maiden dialog triggers if the hole is open
BlindsAtticHint:
REP #$20

View File

@@ -188,6 +188,9 @@ db Password_Tilemap>>16
org $0CD527 ; <- 65527 : Bank0C.asm : 2913 (LDA.w #$0004 : STA $02) [LDA.w #$0006 : STA $02]
JSL.l DrawPlayerFile : NOP ; hijack hearts draw routine to draw a full inventory
; Random incredible patch that I should add right now - File Select Fairy
org $1BF029+1 : db $10
org $0ccdd5 ; Bank0C.asm:1881 (LDX.w #$00FD)
JSL.l AltBufferTable : NOP #8 ; Selection screen
org $0cd393 ; Bank0c.asm:2674 (LDX.w #$00FD)
@@ -1290,6 +1293,9 @@ org $08D395 ; <- 45395 - ancilla_bird_travel_intro.asm : 253
JSL.l UpgradeFlute
NOP #2
;--------------------------------------------------------------------------------
org $07A408 ; LDA.l $7EF34C
JSL.l FluteCallForDuck
;--------------------------------------------------------------------------------
org $05E4D7 ; <- 2E4D7 - sprite_witch.asm : 213
JSL.l RemoveMushroom
NOP #2

View File

@@ -337,9 +337,9 @@ AddInventory:
LDA PreMirrorLocations : INC : STA PreMirrorLocations ; Increment Pre Mirror Counter
SEP #$20
+
LDA FluteEquipment : BNE + ; Check for Mirror
LDA FluteEquipment : BNE + ; Check for Flute
REP #$20
LDA PreFluteLocations : INC : STA PreFluteLocations ; Increment Pre Mirror Counter
LDA PreFluteLocations : INC : STA PreFluteLocations ; Increment Pre Flute Counter
SEP #$20
+
REP #$20
@@ -841,6 +841,22 @@ UpgradeFlute:
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; FluteCallForDuck:
;--------------------------------------------------------------------------------
; sets A to #$02 to ignore summoning the duck
FluteCallForDuck:
LDA.l WarningFlags : AND.b #$20 : BNE .vanilla ; glitched modes allowed flute in rain state
LDA.l ProgressIndicator : CMP.b #$02 : BCS .vanilla ; must rescue Zelda first
.noDuck
LDA.b #$02 : RTL
.vanilla
LDA.l FluteEquipment ; what we wrote over
RTL
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
; CheckKeys:
;--------------------------------------------------------------------------------

View File

@@ -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

View File

@@ -608,16 +608,18 @@ OWEdgeTransition:
}
OWSpecialExit:
{
PHY
LDY.b #$00
LDA.w $0418 : LSR : BNE +
LDY.w $0704 : BRA ++
+
LDA.w $0704 : BNE ++
LDY.b #$02
++
JSR OWWorldTerrainUpdate
PLY
LDA.l OWMode : ORA.l OWMode+1 : BEQ .vanilla
PHY
LDY.b #$00
LDA.w $0418 : LSR : BNE +
LDY.w $0704 : BRA ++
+
LDA.w $0704 : BNE ++
LDY.b #$02
++
JSR OWWorldTerrainUpdate
PLY
.vanilla
LDA.l $7EFD40,X ; what we wrote over
RTL
}