SMB2J Skid Sound Help

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

SMB2J Skid Sound Help

Post by ShaneM »

I was wondering what I would have to do to activate skid sound while wind is blowing (such as in 5-1). When wind blows skid sound is disabled, but it works in Allstars version. I'm thinking this could be done in hex editing, what should I look for in my hex editor? Thanks.
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: SMB2J Skid Sound Help

Post by mikejmoffitt »

If you're trying to enable the skid sound in Super Mario Bros 2 (J) during all conditions, to first understand what causes it to be disabled at all is the most important. Without any reference materials I would think that during the conditions it considers skidding, it checks if there is no wind, and if the comparison is equal it will play the sound. You would want to figure out how the game represents the presence of wind, and see what it might check in memory to determine if it is appropriate to play the sound. Finally, you would figure out where it is doing checks on that area of memory, and possibly replace the check with a NOP or some other technique to effectively disable the check (remove the BEQ/BNE/whatever it does with the results of the check since the state of the flag may be ambiguous without that check!).

The hex editor is many steps too far ahead; with a disassembly of the game this job would be easier but looking for a few instructions would not be out of the question in this case.

EDIT: I'm very tired and apologize beforehand for a very poorly written post; I hope this is helpful at all in getting a vague idea of what to do :/
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

I plan to learn assembly this year, but I was wondering if there is a way to work this without assembly, I know it would be tougher but I am willing to work around. I know the disassembly would be easier, so any more ideas for working without disassembly? Strictly hex editing.
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

So would anybody be interested in helping me find these offsets? Thank you all for your time. :)
User avatar
Movax12
Posts: 541
Joined: Sun Jan 02, 2011 11:50 am

Re: SMB2J Skid Sound Help

Post by Movax12 »

Unless your really lucky and someone wants to sift through the machine code/disassembly for you, you are probably going to have to learn some 6502. It's not as hard as you might think, and you might as well start learning it now. Something like a color (that you asked about earlier) is more likely to be data stored and not so hard to figure out, but something like this could be due to the preference in the logic given to the 'wind' sound. (As was said.) This would require someone to figure out how that logic works, and how to change it. Then you'll have some values and offsets.
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

I am using win7 ultimate, what is the first thing I should do/learn to progress in find this hex offset/6502 code?
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: SMB2J Skid Sound Help

Post by Kasumi »

Read this guide: http://nesdev.com/6502guid.txt

Ask questions if you don't understand something. But do try to puzzle them out for a while, before asking.

Download the macroassembler from here. (Should work on windows 7, but I've never tried it on that.)

To get started with the macro assembler type this:

Code: Select all

      . org $8000
Underneath that you'll be able to type out the instructions mentioned in the guide to see how they behave.

Here's a dead simple program to start.

Code: Select all

      .org $8000
      lda #$FF
      lda #$00
You'll notice this program even gives you info about each instruction you type!

Press F7. (Simulator, assemble) Press F6. (Simulator, debugger) A yellow arrow will appear to the left of the first instruction. Press F11. (Simulator, step into) It will run the instruction the yellow arrow was next to. Note the change in the "CPU registers & status" box. Press F11 again. It will run the next instruction. Again note the changes.

You can use this to test out instructions in that guide. The guide will tell you want they do, and you can verify this using the macro assembler. You can add more instructions to your test program and change it. You just need to reassemble it. (F7) and step through it again. If there's something you don't understand, ask. You can view RAM in the macroassembler. Note that when you store a number to RAM, it actually goes there. Not too much mystery.

The next step would be to use your knowledge of assembly language to accomplish simple tasks. Like say... loading #$FF into the accumulator if the number in Y is greater than #$7F. When you can read and understand 6502 assembly, you can learn to use a debugger.

Note: The following "debugger" steps are pretty brief. I'll be happy to go into more detail when you've picked up some assembly knowledge.

I guess I'd attempt to find the RAM location where Mario's velocity is, since playing a skid code would likely be very close to a read from that RAM. You could also try to find out how sound effects are triggered. There are lots of ways to figure it out.

You can even log all the code run in a frame where a skid happened, and then one where you want a skid to happen. Compare the two. Find out why it skipped the code that played the sound effect. Figure out how you would make it always happen based on the code that's there. (with the extra restriction that new code be the exact same amount of bytes as the old code) Then hex edit the new opcodes.

But you have to start with an understanding of the assembly language instructions. Get those down, ask questions about them. The debugger stuff can come later.
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

Kasumi, sent you PM.
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

I think I found the area for skid sound in wind in sm2main.asm by Beneficii:

-----------------------------------------------------------------------------------

WindSfxData:
.byte $37, $46, $55, $64, $74, $83, $93, $a2, $b1
.byte $c0, $d0, $e0, $f1, $f1, $f2, $e2, $e2, $c3
.byte $a3, $84, $64, $44, $35, $25

BrickShatterFreqData:
.byte $01, $0e, $0e, $0d, $0b, $06, $0c, $0f, $0a
.byte $09, $03, $0d, $08, $0d, $06, $0c

SlideFreqData:
.byte $47, $49, $42, $4a, $43, $4b

PlaySlide:
sty NoiseSoundBuffer
lda #$06
sta Noise_SfxLenCounter

ContinueSlide:
lda Noise_SfxLenCounter
tay
lda SlideFreqData-1,y
sta SND_TRIANGLE_REG+2
lda #%00011000
sta SND_TRIANGLE_REG
sta SND_TRIANGLE_REG+3
bne DecrementSfx3Length

PlayBrickShatter:
sty NoiseSoundBuffer
lda #$20
sta Noise_SfxLenCounter

ContinueBrickShatter:
lda Noise_SfxLenCounter
lsr
bcc DecrementSfx3Length
tay
ldx BrickShatterFreqData,y
lda BrickShatterEnvData,y

PlayNoiseSfx:
sta SND_NOISE_REG
stx SND_NOISE_REG+2
lda #%00011000
sta SND_NOISE_REG+3

DecrementSfx3Length:
dec Noise_SfxLenCounter
bne ExSfx3
lda #%11110000
sta SND_NOISE_REG
lda #$00
sta SND_TRIANGLE_REG
lda #$00
sta NoiseSoundBuffer
ExSfx3:
rts

NoiseTriSfxHandler:
lda NoiseSoundBuffer
bmi ContinueSlide
ldy NoiseSoundQueue
bmi PlaySlide
lsr NoiseSoundQueue
bcs PlayBrickShatter
lsr
bcs ContinueBrickShatter
lsr NoiseSoundQueue
bcs PlayKoopaFlame
lsr
bcs ContinueKoopaFlame
lsr
bcs ContinueWind
lsr NoiseSoundQueue
bcs PlayWind
ExNH:
rts

PlayKoopaFlame:
sty NoiseSoundBuffer
lda #$40
sta Noise_SfxLenCounter

ContinueKoopaFlame:
lda Noise_SfxLenCounter
lsr
tay
ldx #%00001111
lda KoopaFlameEnvData-1,y

PlayWSfx:
bne PlayNoiseSfx

PlayWind:
sty NoiseSoundBuffer
lda #$c0
sta Noise_SfxLenCounter

ContinueWind:
lsr NoiseSoundQueue
bcc ExSfx3
lda Noise_SfxLenCounter
lsr
lsr
lsr
tay
lda WindSfxData,y
and #%00001111
ora #%00010000
tax
lda WindSfxData,y
lsr
lsr
lsr
lsr
ora #%00010000
bne PlayWSfx

;-----------------------------------------------------------------------------------

ContinueMusic:
jmp HandleSquare2Music

MusicHandler:
lda


Does this look right? at PlayWSfx:
bne PlayNoiseSfx
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: SMB2J Skid Sound Help

Post by mikejmoffitt »

Replace it with a NOP or some such and see what happens. That does look like what you are looking for.
User avatar
ShaneM
Posts: 353
Joined: Wed Apr 04, 2012 4:15 pm
Location: United States of America (USA)
Contact:

Re: SMB2J Skid Sound Help

Post by ShaneM »

Replace what exactly with NOP?
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: SMB2J Skid Sound Help

Post by mikejmoffitt »

the bne PlayNoiseSfx in PlayWSfx... it is possible you may need to do more than that, however.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: SMB2J Skid Sound Help

Post by Kasumi »

This has been half solved in PM. In the interest of public knowledge:

Code: Select all

0C550                       lda $07f9;This checks if wind is active. 
0C553 F0 33                     	beq $c588;If it's zero, wind is not active. And it branches to an RTS.
0C555 A9 04                     	lda #$04;Otherwise, it loads the wind sound effect ID 
0C557 85 FD                     	sta $fd;and stores it here, so it knows what to play.
0C559 20 A1 C5                  	jsr $c5a1;I have zero idea what this or any of the following does.
;So it's removed for brevity
0C588 60                        	rts
My idea for the fix was to just check $FD for the sound skid sound effect which was #%10000000 after the program so...

Code: Select all

lda $07f9;This checks if wind is active. 
beq $c588;If it's zero, wind is not active. And it branches to an RTS.
lda $FD
bmi c588;If skid, skip wind
Except I can't insert bytes at that location, since it's not fully labeled. Everything after the change would be blown up.
So, I copy pasted the entire routine to the end of that segment of ROM under a label called "windcode:" (updating the branches to actual labels in the process), and changed

Code: Select all

0C550                       lda $07f9;This checks if wind is active. 
to

Code: Select all

0C550                       jmp windcode
I removed everything after jmp windcode, and padded it. I hoped there was enough space for the doubled up routine. There wasn't.

So I checked how much space I actually did have, and there was enough for a tiny routine at the end of that segment of ROM. Just not for all of it.

So I removed the padding and put the routine back where it was, except for jmp windcode in place of lda $07f9.
Then I tried this:

Code: Select all

windcode:
	lda $07f9
	beq skipwind
	lda $FD
	bmi skipwind
	jmp $c555
skipwind:
	rts
That worked, except that when you skidded that actual wind leaves disappeared. I had no idea what made the leaves blow, and didn't want to look too hard into it, so I honestly just made a guess.

Code: Select all

windcode:
	lda $07f9
	beq skipwind
	lda $FD
	bmi windnosound
	jmp $c555
windnosound:
	jmp $c559
skipwind:
	rts
I figured when a skid was playing, I would just jmp past the code I thought was sound related. So, when wind was blowing and the skid sound was playing, it would hopefully do the stuff that makes those leaves. That seemed to work. But only for some levels apparently. I guess I have to find similar code in another location, and hope there's enough room in those sections for rom for my sloppy windcode label. :lol:
Post Reply