News:

11 March 2016 - Forum Rules

Main Menu

SMB1 Area Music Select Logic Changes

Started by SMB2J-2Q, August 26, 2022, 01:50:06 AM

Previous topic - Next topic

SMB2J-2Q

I would like to try to update the area music selection logic for Super Mario Bros. and Super Mario Bros. 2 (Japan) so that I can get the cloud/star music to play in the underground coin room areas (all grouped under area $c2 for SMB 1, or under area $43 or $45 for SMB2J).

The reason I want to make this change is because in Super Mario All-Stars, an entirely new theme is used in both the cloud levels and underground coin room areas.

I am wondering if this might work if I add the following underneath the logic for the cloud level logic?
ChkAreaType:
      ldy AreaType                  ;use AreaType as offset for music bit (0=water; 1=above ground; 2=underground; 3=castle)
      lda CloudTypeOverride         ;check for cloud type override if found
      bcs UndergroundCoinRoom
      ldy #$04                      ;play selection for cloud/star music if we're in this area
UndergroundCoinRoom:
      jsr LoadAreaPointer           
      lda #$c2                      ;check if we're in any underground coin room
      beq StoreMusic
      ldy #$04                      ;play cloud/star music if here
StoreMusic:
      lda MusicSelectData,y         ;otherwise play appropriate music for level type
      sta AreaMusicQueue            ;store in queue and leave
ExitGetM:
      rts

Thank you,



Ben

Ooxie

Have you tried it yet? If not, I would recommend removing the level data of a late stage, like 8-4, and replace it with your extra code and make sure to link it to the rest of the section dealing with the area music selection (through the use of the JSR instruction). This is because there is almost no available space left in the ROM, and so you cannot simply append some code underneath what exists. This will only be good for a quick test though (don't play up to 8-4!); for a final version you may have to remove some functionality from the game, or more likely expand it with a mapper.

I'm only speaking for Super Mario Bros. here, as I don't know Lost Levels enough, but something similar could be done if you also run out of space for the latter.

Just try it and tell us if it works!

SMB2J-2Q

#2
Quote from: Ooxie on August 27, 2022, 08:25:12 PMHave you tried it yet? If not, I would recommend removing the level data of a late stage, like 8-4, and replace it with your extra code and make sure to link it to the rest of the section dealing with the area music selection (through the use of the JSR instruction). This is because there is almost no available space left in the ROM, and so you cannot simply append some code underneath what exists. This will only be good for a quick test though (don't play up to 8-4!); for a final version you may have to remove some functionality from the game, or more likely expand it with a mapper.

I'm only speaking for Super Mario Bros. here, as I don't know Lost Levels enough, but something similar could be done if you also run out of space for the latter.

Just try it and tell us if it works!
For comparison, here is how the area music selection logic for both SMB1 and SMB:TLL is coded in SMAS.
Source: https://github.com/Maseya/SMAS-Disassembly/blob/master/Assembly/SMB1/code/b04/_b04.asm
; If it is a castle, change BG palette and music to
; Black and Castle (Also changes ground tileset) ($03)
BCS CODE_04C08C         ; $04:C07E: B0 0C
CMP #$19                ; $04:C080: C9 19

; If it is an underground (bonus room),change BG palette and music to
; Black and underground ($02)
BCS CODE_04C08E         ; $04:C082: B0 0A
CMP #$03                ; $04:C084: C9 03

; If it is any minor background, change BG palette and music to
; Light Blue and ground ($01)
BCS CODE_04C090         ; $04:C086: B0 08
CMP #$02                ; $04:C088: C9 02

; If it is any underwater stage, change BG palette and music to
; Light Blue and Underwater ($00)
BCC CODE_04C092         ; $04:C08A: 90 06

CODE_04C08C:
INC $BA                 ; $04:C08C: E6 BA

CODE_04C08E:
INC $BA                 ; $04:C08E: E6 BA

; Set BG palette and music

CODE_04C090:
INC $BA                 ; $04:C090: E6 BA

CODE_04C092:
LDA DATA_04C194,y       ; $04:C092: B9 94 C1
STA $FA                 ; $04:C095: 85 FA
LDA DATA_04C1B6,y       ; $04:C097: B9 B6 C1
STA $FB                 ; $04:C09A: 85 FB

CODE_04C09C:
LDA.b #DATA_04C194>>16  ; $04:C09C: A9 04

You can see that the instruction to change to the underwater music in this code is not quite correct, which may explain why the music doesn't change when you go to the underwater room in 8-4. Again, this may be fixed if you change the above code to:
; If it is a castle, change BG palette and music to
; Black and Castle (Also changes ground tileset) ($03)
BCS CODE_04C08E         ; $04:C07E: B0 0C
CMP #$19                ; $04:C080: C9 19

; If it is an underground (bonus room),change BG palette and music to
; Black and underground ($02)
BCS CODE_04C090         ; $04:C082: B0 0A
CMP #$03                ; $04:C084: C9 03

; If it is any minor background, change BG palette and music to
; Light Blue and ground ($01)
BCS CODE_04C092         ; $04:C086: B0 08
CMP #$02                ; $04:C088: C9 02

; If it is any underwater stage, change BG palette and music to
; Light Blue and Underwater ($00)
BCC CODE_04C094         ; $04:C08A: B0 06
CMP #$01               ; $04:C08C: C9 01

;castle music
CODE_04C08E:
INC $BA                 ; $04:C08E: E6 BA

;underground music
CODE_04C090:
INC $BA                 ; $04:C090: E6 BA

; Set BG palette and music

;ground music
CODE_04C092:
INC $BA                 ; $04:C092: E6 BA

;underwater music
CODE_04C094:
INC $BA                 ; $04:C094: E6 BA

CODE_04C096:
LDA DATA_04C198,y       ; $04:C096: B9 98 C1
STA $FA                 ; $04:C099: 85 FA
LDA DATA_04C1BA,y       ; $04:C09B: B9 BA C1
STA $FB                 ; $04:C09E: 85 FB

~Ben

Mattrizzle

You're right. The locations you have shown in the SMAS disassembly don't look right. I think whoever wrote those comments just made assumptions based on the way the NES versions work. It's different in the SNES ports.

These PAR cheat codes I made for disabling the bonus music changes should give you an idea where the proper code is in the (U) version of SMAS:

05C93380 Disable Underground Bonus Area Music Change (SMB)
05C8F90D Coin Heaven Bonuses use Starman Music (SMB)

0FD92A80+0FD92B08 Disable Bonus Area Music Change for Non-Coin Heaven Areas (SMB:LL)
0FD8F40D Coin Heaven Bonuses use Starman Music (SMB:LL)

SMB2J-2Q

#4
Quote from: Mattrizzle on August 31, 2022, 08:32:20 AMYou're right. The locations you have shown in the SMAS disassembly don't look right. I think whoever wrote those comments just made assumptions based on the way the NES versions work. It's different in the SNES ports.

These PAR cheat codes I made for disabling the bonus music changes should give you an idea where the proper code is in the (U) version of SMAS:

05C93380 Disable Underground Bonus Area Music Change (SMB)
05C8F90D Coin Heaven Bonuses use Starman Music (SMB)

0FD92A80+0FD92B08 Disable Bonus Area Music Change for Non-Coin Heaven Areas (SMB:LL)
0FD8F40D Coin Heaven Bonuses use Starman Music (SMB:LL)
Having just learned about this, I wonder what PAR code (or codes) will allow the Underwater Music to play in World 8-4's water area (in both SMB and SMB:LL), as was originally done in the NES SMB and FDS SMB2 respectively?

BTW, I found this on the same page you mention for SMB1 -- you can see that parts of the code below match that of the original NES SMB music data logic:
https://github.com/Maseya/SMAS-Disassembly/blob/master/Assembly/SMB1/code/b05/_b05.asm
; music select data
DATA_05C8F5:
db $03,$02,$06,$08,$01,$13

DATA_05C8FB:
PHB
PHK
PLB
PHX
LDA $0770
BEQ CODE_05C94D
LDA $0752
CMP #$02
BEQ CODE_05C91C
LDY #$05
LDA $0710
CMP #$06
BEQ CODE_05C918
CMP #$07
BNE CODE_05C91C

CODE_05C918:
LDY #$05
BRA CODE_05C925

; for coin heaven bonus stages
CODE_05C91C:
LDY $BA
LDA $0743
BEQ CODE_05C925
LDY #$04

; StoreMusic
CODE_05C925:
LDA $0F
CMP #$04
BEQ CODE_05C944
CMP #$05
BEQ CODE_05C944
LDA $DB
CMP #$1B
BNE CODE_05C939
LDA #$01
BRA CODE_05C93C

CODE_05C939:
LDA DATA_05C8F5,Y

CODE_05C93C:
LDX $0EDF
BNE CODE_05C944
STA $1602

CODE_05C944:
LDX $DB
CPX #$21
BNE CODE_05C94D
STA $0EDF

CODE_05C94D:
PLX
PLB
RTL
LDA $7FFB06
BPL CODE_05C958
LDA #$00

Whereas for SMB:LL, it is found here:
https://github.com/Maseya/SMAS-Disassembly/blob/master/Assembly/SMB2J/code/b0F/_b0F.asm
DATA_0FD8F0:
db $03,$02,$06,$08,$01,$13

DATA_0FD8F6:
PHB
PHK
PLB
PHX
LDA $0770
BEQ CODE_0FD94C
LDA $0752
CMP #$02
BEQ CODE_0FD913
LDY #$05
LDA $0710
CMP #$06
BEQ CODE_0FD91C
CMP #$07
BEQ CODE_0FD91C

CODE_0FD913:
LDY $BA
LDA $0743
BEQ CODE_0FD91C
LDY #$04

CODE_0FD91C:
LDA $0F
CMP #$04
BEQ CODE_0FD943
CMP #$05
BEQ CODE_0FD943
LDA $DB
CMP #$39
BEQ CODE_0FD939
CMP #$3B
BEQ CODE_0FD939
CMP #$3D
BEQ CODE_0FD939
LDA DATA_0FD8F0,Y
BRA CODE_0FD93B

CODE_0FD939:
LDA #$01

CODE_0FD93B:
LDX $0EDF
BNE CODE_0FD943
STA $1602

CODE_0FD943:
LDX $DB
CPX #$07
BNE CODE_0FD94C
STA $0EDF

CODE_0FD94C:
PLX
PLB
RTL

As you can see, the music select data logic for SMB:LL within SMAS more closely follows the original FDS version of SMB2. I wonder why there are slight differences in the same code for SMB1 within SMAS?

In both cases, the LDY instruction that begins the cloud type override check is a zero-page instruction ($BA) instead of a two-byte RAM address (which was $074E).

~Ben