News:

11 March 2016 - Forum Rules

Main Menu

Super Mario Bros. Fixes

Started by SMB2J-2Q, March 18, 2021, 11:52:18 PM

Previous topic - Next topic

SMB2J-2Q

I wonder what you think of the SNES' take on these routines for SMB1?
; Player action - Player changes size

CODE_03B26E:
LDA $0747               ; $03:B26E: AD 47 07
CMP #$F8                ; $03:B271: C9 F8
BNE CODE_03B278         ; $03:B273: D0 03
JMP CODE_03B290         ; $03:B275: 4C 90 B2

CODE_03B278:
CMP #$C4                ; $03:B278: C9 C4
BNE CODE_03B27F         ; $03:B27A: D0 03
JSR CODE_03B2AE         ; $03:B27C: 20 AE B2

CODE_03B27F:
RTS                     ; $03:B27F: 60

; Player action - player has injury invincibility

CODE_03B280:
LDA $0747               ; $03:B280: AD 47 07
CMP #$F0                ; $03:B283: C9 F0
BCS CODE_03B28E         ; $03:B285: B0 07
CMP #$C8                ; $03:B287: C9 C8
BEQ CODE_03B2AE         ; $03:B289: F0 23
JMP CODE_03AFF4         ; $03:B28B: 4C F4 AF

CODE_03B28E:
BNE CODE_03B2A3         ; $03:B28E: D0 13

CODE_03B290:
LDY $070B               ; $03:B290: AC 0B 07
BNE CODE_03B2A3         ; $03:B293: D0 0E
STY $070D               ; $03:B295: 8C 0D 07
INC $070B               ; $03:B298: EE 0B 07
LDA $0754               ; $03:B29B: AD 54 07
EOR #$01                ; $03:B29E: 49 01
STA $0754               ; $03:B2A0: 8D 54 07

CODE_03B2A3:
RTS                     ; $03:B2A3: 60

; Player action - player dies

CODE_03B2A4:
LDA $0747               ; $03:B2A4: AD 47 07
CMP #$F0                ; $03:B2A7: C9 F0
BCS CODE_03B308         ; $03:B2A9: B0 5D
JMP CODE_03AFF4         ; $03:B2AB: 4C F4 AF

CODE_03B2AE:
STZ $0747               ; $03:B2AE: 9C 47 07
JSL CODE_049A88         ; $03:B2B1: 22 88 9A 04
LDA #$08                ; $03:B2B5: A9 08
STA $0F                 ; $03:B2B7: 85 0F
RTS                     ; $03:B2B9: 60

; Player action - player obtains fireflower

CODE_03B2BA:
LDA $0747               ; $03:B2BA: AD 47 07
CMP #$C0                ; $03:B2BD: C9 C0
BEQ CODE_03B2FA         ; $03:B2BF: F0 39
EOR #$FF                ; $03:B2C1: 49 FF
ASL A                   ; $03:B2C3: 0A

CODE_03B2C4:
ASL A                   ; $03:B2C4: 0A
ASL A                   ; $03:B2C5: 0A
ASL A                   ; $03:B2C6: 0A
PHY                     ; $03:B2C7: 5A
PHX                     ; $03:B2C8: DA
REP #$30                ; $03:B2C9: C2 30
AND #$0060              ; $03:B2CB: 29 60 00
TAX                     ; $03:B2CE: AA
LDA $0753               ; $03:B2CF: AD 53 07
AND #$00FF              ; $03:B2D2: 29 FF 00
BEQ CODE_03B2DD         ; $03:B2D5: F0 06
TXA                     ; $03:B2D7: 8A
CLC                     ; $03:B2D8: 18
ADC #$0020              ; $03:B2D9: 69 20 00
TAX                     ; $03:B2DC: AA

CODE_03B2DD:
LDY #$01E0              ; $03:B2DD: A0 E0 01

CODE_03B2E0:
LDA.l DATA_05ED40,x     ; $03:B2E0: BF 40 ED 05
STA $1000,y             ; $03:B2E4: 99 00 10
INX                     ; $03:B2E7: E8
INX                     ; $03:B2E8: E8
INY                     ; $03:B2E9: C8
INY                     ; $03:B2EA: C8
CPY #$0200              ; $03:B2EB: C0 00 02
BNE CODE_03B2E0         ; $03:B2EE: D0 F0
SEP #$30                ; $03:B2F0: E2 30
PLX                     ; $03:B2F2: FA
PLY                     ; $03:B2F3: 7A
LDA #$01                ; $03:B2F4: A9 01
STA $1200               ; $03:B2F6: 8D 00 12
RTS                     ; $03:B2F9: 60

CODE_03B2FA:
JSR CODE_03B2AE         ; $03:B2FA: 20 AE B2

CODE_03B2FD:
LDA $0256               ; $03:B2FD: AD 56 02
AND #$F1                ; $03:B300: 29 F1
ORA #$0E                ; $03:B302: 09 0E
STA $0256               ; $03:B304: 8D 56 02
RTS                     ; $03:B307: 60

CODE_03B308:
RTS                     ; $03:B308: 60

~Ben

SMB2J-2Q

For TakuikaNinja:

I referred to your updated code about the new music additions, and the one for the underground music replacement doesn't work for me yet. Please try to let me know what else I should be doing in order to make it work.

The specific code in question:
BonusMusicFlag      = $03f0
CastleMusicOverride = $06b7

GetAreaMusic:
[...]
ChkAreaType: ldy #$04               
             lda BonusMusicFlag      ;check for any bonus type level (except underwater)
             bne StoreMusic          ;if not found, skip
             dey                     ;otherwise decrement Y to play castle music
             lda CastleMusicOverride ;if we're in underwater section of world 8-4
             bne StoreMusic          ;if not, skip
             ldy AreaType            ;use area type as offset for music bit
StoreMusic:  lda MusicSelectData,y   ;and load correct music for specific area type
             sta AreaMusicQueue      ;store in queue, then leave
ExitGetM:    rts

and...
StoreFore:
[...]
            sta CloudTypeOverride   ;otherwise store value in other place
            sta BonusMusicFlag      ;and set bonus music flag
            lda #$00
StoreStyle: [...]
            lda AreaPointer         ;get area pointer
            and #%01111111          ;and mask out bit 7
            cmp #$42                ;check for any underground coin room
            bne NotUndergroundBonus ;if not found, branch to next routine
            sta BonusMusicFlag      ;otherwise load bonus music
NotUndergroundBonus:
            cmp #$02                ;check for underwater room of world 8-4
            bne Not8Castle          ;if not found, skip
            sta CastleMusicOverride ;if yes, load castle music instead of water music
Not8Castle: rts

Thank you,



Ben (SMB2J-2Q)

TakuikaNinja

Quote from: SMB2J-2Q on May 14, 2023, 02:24:43 AMFor TakuikaNinja:

I referred to your updated code about the new music additions, and the one for the underground music replacement doesn't work for me yet. Please try to let me know what else I should be doing in order to make it work.

The specific code in question:
BonusMusicFlag      = $03f0
CastleMusicOverride = $06b7

GetAreaMusic:
[...]
ChkAreaType: ldy #$04               
             lda BonusMusicFlag      ;check for any bonus type level (except underwater)
             bne StoreMusic          ;if not found, skip
             dey                     ;otherwise decrement Y to play castle music
             lda CastleMusicOverride ;if we're in underwater section of world 8-4
             bne StoreMusic          ;if not, skip
             ldy AreaType            ;use area type as offset for music bit
StoreMusic:  lda MusicSelectData,y   ;and load correct music for specific area type
             sta AreaMusicQueue      ;store in queue, then leave
ExitGetM:    rts

and...
StoreFore:
[...]
            sta CloudTypeOverride   ;otherwise store value in other place
            sta BonusMusicFlag      ;and set bonus music flag
            lda #$00
StoreStyle: [...]
            lda AreaPointer         ;get area pointer
            and #%01111111          ;and mask out bit 7
            cmp #$42                ;check for any underground coin room
            bne NotUndergroundBonus ;if not found, branch to next routine
            sta BonusMusicFlag      ;otherwise load bonus music
NotUndergroundBonus:
            cmp #$02                ;check for underwater room of world 8-4
            bne Not8Castle          ;if not found, skip
            sta CastleMusicOverride ;if yes, load castle music instead of water music
Not8Castle: rts

Thank you,



Ben (SMB2J-2Q)
You can't use $3f0 as that is overwritten with VRAM buffer contents or cleared before the music is set.

SMB2J-2Q

#123
Quote from: TakuikaNinja on May 14, 2023, 07:40:10 AMYou can't use $3f0 as that is overwritten with VRAM buffer contents or cleared before the music is set.
Thank you... will try a different RAM address, then.

UPDATE: Tried that with a new RAM address, the unused $078c, and now it works (for the underground coin rooms)!

UPDATE 2: Changed the RAM address for "CastleMusicOverride" to $06b7, and now 8-4's underwater room plays the castle music as expected. Turns out I should not use RAM addresses so close to one another.

UPDATE 3: Turns out my earlier suggestion for adding an ORA for "CloudTypeOverride" after the LDA for "BonusMusicFlag" did the trick: now finally the correct bonus music is heard in the coin heaven levels!

Work so far:



~Ben

shanem

#124
@SMB2J-2Q,

Wouldn't it just be better to learn assembly and figure it out and ask for help when you need it? You're basically asking people for all the answers. You PM'd me about the same thing a little while ago.

If you need a guide, here's one: http://www.6502.org/tutorials/6502opcodes.html

SMB2J-2Q

#125
Quote from: shanem on May 14, 2023, 05:36:24 PM@SMB2J-2Q,

Wouldn't it just be better to learn assembly and figure it out and ask for help when you need it? You're basically asking people for all the answers. You PM'd me about the same thing a little while ago.

If you need a guide, here's one: http://www.6502.org/tutorials/6502opcodes.html
Shane,

I apologize, and I still need to catch up on learning Z80 for Super Mario Bros. Deluxe.

UPDATE: Everything is OK now; I've corrected the following code so everything works perfectly now in the respected areas:

UPDATE 2: Moved 'BonusMusicFlag' from RAM $078c to $06c9 (from the 'DoNothing' code), so the ORA to $0743 is now no longer needed.

GetAreaMusic:
...
ChkAreaType: ldy #$04
             lda BonusMusicFlag      ;check for bonus music flag
             bne StoreMusic          ;branch if not set
             dey
             lda CastleMusicOverride ;check for castle music override if we're in world 8-4's
             bne StoreMusic          ;underwater room, and branch if not set
             ldy AreaType            ;otherwise load area type as offset for music bit
StoreMusic:  lda MusicSelectData,y   ;and load appropriate music specific to area type
             sta AreaMusicQueue
ExitGetM:    rts

~Ben

shanem

Here's my fix to the wall jump and wall clipping. It took me weeks to debug this and perfect it. This was the hardest glitch I've ever fixed. No wonder Nintendo has left it in all subsequent 2-D Mario games! I'm giving this with a couple other of my fixes:


;new RAM offsets
AxeFlag               = $4c
InvincibilityTimer    = $50

Wall clipping/wall jump fix:

DoFootCheck:
          lda #$08                   ;SM load value to specifically prevent wall clipping from the leftmost screen             
          ldy Player_OffscreenBits   ;SM load player offscreen bits
          beq WJChk                  ;SM branch if bits not set to continue with walljump check
  ldy SideCollisionTimer     ;SM otherwise load the side collision timer
  beq BlockBuffOGVal         ;SM branch if player is not getting sucked into the wall to use original value
  bne BlockBuffWJFVal+2      ;SM branch unconditionally if set to prevent being sucked into the wall
WJChk:    ldy Player_Y_Speed         ;SM get player's vertical speed
  beq BlockBuffOGVal         ;SM if standing on solid ground
          bmi BlockBuffOGVal         ;SM or jumping upward, branch
  lda AxeFlag                ;SM load the axe flag
  beq BlockBuffWJFVal        ;SM branch if not set
  lda Player_Pos_ForScroll   ;SM otherwise check current player's position
  cmp #$e0                   ;SM against being right next to the axe
  bcs BlockBuffOGVal         ;SM branch if carry set to prevent Bowser and axe collision at the same time
BlockBuffWJFVal:
  lda #$0a                   ;SM otherwise load new value here
  ldy #$05                   ;SM and here to fix walljump glitch
  bne StoreBlockBuffVal      ;SM unconditional branch
BlockBuffOGVal:
  lda #$0c                   ;SM load the default values here
  ldy #$03                   ;SM and here
StoreBlockBuffVal:
  sta BlockBuffer_X_Adder+2  ;SM store the values at these six addresses
  sta BlockBuffer_X_Adder+9  ;SM for each occurrence of player
  sta BlockBuffer_X_Adder+16 ;SM big, swimming or small
  sty BlockBuffer_X_Adder+1  ;SM A register holds left block values
  sty BlockBuffer_X_Adder+8  ;SM and Y register for the right block ones
  sty BlockBuffer_X_Adder+15 ;SM then continue on with original code
  ldy $eb                    ;get block buffer adder offset

Vine of the dead fix:
AutoClimb: lda #%00001000         ;set controller bits override to up
           sta JoypadOverride
           sta InvincibilityTimer ;SM also set invincibility timer
   ldy #$03               ;set player state to climbing
           sty Player_State
           jmp AutoControlPlayer

Prevents Mario getting injured when going into pipes before warping as well as prevent oddities like Mario skidding and not crouching if big when entering pipes:

VerticalPipeEntry:     
      ldy #$01                    ;load Y register with value
      sty InvincibilityTimer      ;SM set invincibility timer
      lda PlayerSize              ;SM load player size flag (small=#1 big=#0)
      eor #%00000001              ;SM invert bit 0
      sta CrouchingFlag           ;SM store the value here
      dey                         ;SM Y = 0
      sty Player_X_Speed          ;SM clear horizontal speed
      inc Player_Y_Position       ;SM move the player downward vertically
      jsr ScrollHandler           ;do sub to scroll screen with saved force if necessary
      ldy #$00                    ;load default mode of entry

CheckForJumping:
sty InvincibilityTimer    ;SM clear invincibility timer
lda JumpspringAnimCtrl    ;if jumpspring animating,
        bne NoJump                ;skip ahead to something else
        lda A_B_Buttons           ;check for A button press

InjurePlayer:                    ;hurt player
      lda InvincibilityTimer     ;SM check again to see if any of the three
      ora InjuryTimer            ;invincibility timers have expired, branch if not
      ora StarInvincibleTimer
      bne ExInjColRoutines

This needs to be done in this order:
HandleAxeMetatile:
       lda #$01               ;SM load value
       sta InvincibilityTimer ;SM set invincibility timer
       lsr
       sta OperMode_Task   ;reset secondary mode
       lda #$02
       sta OperMode        ;set primary mode to victory mode

AxeObj:
      inc AxeFlag         ;SM do this before rest of code

Credit me if used.