News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

Bug with Super Missile Fix

Started by dewhi100, March 11, 2018, 02:12:13 PM

Previous topic - Next topic

dewhi100

I sometimes get a black screen when using the Super Missile Fix patch. It's happened in a couple places in the game. The easiest place to replicate it is the Kraid fight before he stands up. Spamming supers, tapping jump, and looking left/right will do it. Jumping and spamming missiles at his face later in the fight does it too. One other place where it happened is when fighting the kihunters on the way to Kraid.

I want to be more ambitious with including mods to the game, and this one is a must when using Fusion-Style supers, since you'll see both projectiles when using that patch. Plus, having a patch out there that breaks the game is just bad anyway.

Does it maybe happen when there are a lot of sprites onscreen? This is one thought I have since it's easiest to trigger when Kraid is rising up. The thing is, there's actually one *less* item on the screen due to the patch... Does the patch write to RAM that the vanilla game sometimes tries to use? I don't know enough to say.

The bug happens when patched to a vanilla ROM. JAM and Kejardon made it, but IDK if they're still active any more. Can anyone give their ideas? I don't want to have to disassemble this whole thing (It's IPS only :/).

Quote58

I disassembled it (using the banklog vanilla code as a base) when adding it to project base, and included crashtour's fix as well. However, iirc it still crashed under certain conditions. I haven't gotten around to fixing it yet, but here's the code if you want to take a look. I'm pretty sure this is all of it, but I haven't looked it over so if it isn't all of it I'll get the rest later. I also don't remember if this has any changes by me in it, but I *think* this is just the regular patch + crash's bug fix. The variable names should be self explanatory, but if you don't know what one of them is I'll list them out.
[spoiler]
; --- Kejardon (with bug fix by crashtour) ---
org $90B005
JSR $B329
LDA !Proj_direction,x : AND #$000F
ASL A : TAX
JSR ($B033,x)
JSR $B16A : BCC + ;checks if out of bounds
JSL $90ADB7 ;deletes the projectile if it is
+
RTS

org $90B2F6
PHP : REP #$30
PHX : PHY
LDA $0C7C,x : BNE +
INC : STA $0C7C,x
LDA #$0100 : STA $16
STX $12
JSR $B1F3 ;sets the initial speed of a projectile
BRA ++
+
JSR $B329
++
PLY : PLX
PLP
RTS

org $90B366 ;vertical collision detection
LDX $0DDE
LDA !Proj_type,x : AND #$0F00
CMP #$0200 ;check if projectile is a super missile
BNE +++
LDA !Proj_Yspeed,x : BPL +
EOR #$FFFF
INC A
+
AND #$FF00 : CMP #$0B00 : BMI +++ ;if speed >= B pixels per frame
XBA : SEC : SBC #$000A ;check collision at speed-A pixels earlier
STA $12
LDA $0B78,x : PHA ;save previous position
BIT !Proj_Yspeed,x : BMI + ;check direction
SEC : SBC $12
BRA ++
+
CLC : ADC $12
++
STA $0B78,x ;move position back according to direction
JSL $94A4D9 ;collision detection
LDA !Proj_type,x : AND #$0F00
CMP #$0800
PLA : BCS +++ ;if collided, counter is set, rts
STA $0B78,x ;else restore old position, counter is clear, rts
+++
RTS

org $90B406 ;horizontal collision detection
LDX $0DDE
LDA !Proj_type,x : AND #$0F00
CMP #$0200 ;check if projectile is a super missile
BNE +++
LDA !Proj_Xspeed,x : BPL +
EOR #$FFFF
INC A
+
AND #$FF00 : CMP #$0B00 : BMI +++ ;if speed >= B pixels per frame
XBA : SEC : SBC #$000A ;check collision at speed-A pixels earlier
STA $12
LDA $0B64,x : PHA ;save previous position
BIT !Proj_Xspeed,x : BMI + ;check direction
SEC : SBC $12
BRA ++
+
CLC : ADC $12
++
STA $0B64,x ;move position back according to direction
JSL $94A46F ;collision detection
LDA !Proj_type,x : AND #$0F00
CMP #$0800
PLA : BCS +++ ;if collided, counter is set, rts
STA $0B64,x ;else restore old position, counter is clear, rts
+++
RTS
[/spoiler]

P.JBoy

That disassembly is vanilla Kej's patch but with these parts removed:

org $90AC61
DB $00 ;Just canceling a branch that's now unneeded since Super Missiles take one slot

org $90AE19
DB $80,$02 ;BRA #$02. Skipping a JSL that causes a small graphic glitch.
;I'm a bit worried this may cause problems elsewhere, but it seems fine.

org $90B362
RTS ;End of projectile acceleration code, go back to $90B005


I'm not sure if those removals are a result of any fixes or anything.

Crash's fix (if it's the one mentioned here anyway) isn't there. For that, you'll want to replace the code listing at $90B005 with

org $90AFE5
; PJ: editor's note, I've added in this preceding code to fix a crash due to an unfixed branch
LDA $0C04,x
AND #$00F0
BNE Delete
DEC $0C90,x
BNE +
LDA #$0002
STA $0C90,x
JSL $90B657
LDX $0DDE
+
; PJ: end
JSR $B329
LDA $0C04,X ;Skipped the rest of old code that created the second projectile
AND #$000F
ASL
TAX
JSR ($B033,x)
JSR $B16A ;Check if out of bounds
BCC SkipDelete
Delete:
JSL $90ADB7 ;Delete *just this* projectile if out of bounds.
SkipDelete:
RTS

...

dewhi100

#3
Cool, thanks guys. I will consolidate these into a new ROM and see how it performs.

Now I wonder: why go to the trouble of making a duplicate SM projectile? Wouldn't it be easier to just populate one? Unless they're trying to reduce your rate of fire in a very ghetto way or something...

EDIT: @Quote58 Applying that ASM makes the game stay at a silent black screen after the Nintendo logo. @P.JBoy I replaced the code snippet at #90B005 with your code but it is still a black screen. What did I do wrong?