News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)  (Read 1658 times)

RetroRain

  • Sr. Member
  • ****
  • Posts: 287
    • View Profile
I'm having trouble converting Super Mario Bros. 2 (USA) to MMC5.  When it boils down to it, I believe the problem is with the bankswitch routine.  I haven't had to actually convert a MMC3 mapper yet, but the bankswitch routine I have used, plus all of the alterations of it, have not yielded the results I'm looking for.

This is the SMB2 bankswitch routine for MMC3 (the original routine):

Code: [Select]
$FF85:8D F2 06  STA $06F2 = #$00     ; current switchable bank, from what I can tell.
$FF88:0A        ASL
$FF89:48        PHA
$FF8A:A9 86     LDA #$86
$FF8C:8D 00 80  STA $8000 = #$AD
$FF8F:68        PLA
$FF90:8D 01 80  STA $8001 = #$02
$FF93:09 01     ORA #$01
$FF95:48        PHA
$FF96:A9 87     LDA #$87
$FF98:8D 00 80  STA $8000 = #$AD
$FF9B:68        PLA
$FF9C:8D 01 80  STA $8001 = #$02
$FF9F:60        RTS

This is my MMC5 bankswitch routine:

Code: [Select]
STA $06F2 = #$00
ASL
PHA
ADC #$80
STA $5114 = #$00
ADC #$01 ; I have even tried ORA #$01, no go
STA $5115 = #$00
PLA
RTS

Alterations of my bankswitch routine include switching the ASL and PHA, removing the PHA and PLA altogether, removing the ASL, alternating the ADC #$01 to ORA #$01 and back, changing the PRG mode to 16K instead of MMC3's original 8K (since the last 2 8K banks are hardwired to $C000, and judging from SMB2's bankswitch routine, it is simply adding 1 to make both 8K switchable banks a 16K bank).

The titlescreen loads, but then the scanline clears it away with a red background.

I'm using 8K PRG mode, just like in MMC3, and $5114 and $5115 represent $8000-$9FFF and $A000-$BFFF respectively.

All I need to know, is if I'm doing something wrong with my bankswitch routine.  If I'm not, then the problem is not the bankswitch routine.  In which case, I don't know what is causing the problem.

I got the CHR Bankswitch routine down no problem.  So I'm confident it isn't that.  I really do think it is the PRG bankswitch routine.

Thanks.

Disch

  • Hero Member
  • *****
  • Posts: 2784
  • NES Junkie
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #1 on: September 25, 2015, 08:15:53 pm »
Your routine looks like it would work as long as A <= $7F on entry.

Though ADC is weird, you'd probably want ORA.  The goal is not to add a value, but is to flip on a specific bit:

Code: [Select]
STA $06F2
ASL A
ORA #$80
STA $5114
ORA #$01
STA $5115
AND #$7F
RTS

The last AND might not be necessary -- I only put it there in case the original game uses A after this routine exits.


Anyway -- my routine and your routine basically do the same thing -- only you mangle A on the routine's output.  That might make a difference, but I doubt it.

The problem is likely elsewhere in the conversion.

RetroRain

  • Sr. Member
  • ****
  • Posts: 287
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #2 on: September 25, 2015, 08:34:04 pm »
I just figured out what was causing the game to crash, but I don't know why.

There was absolutely nothing wrong with one of my variations of my bankswitch routine.  THIS right here works:

STA $06F2
ASL
ADC #$80
STA $5114
ORA #$01
STA $5115
RTS

Disch, where SMB2's bankswitch routine is, at $FF85, what I did was JSR to some free space elsewhere ($ED88), and put my bankswitch routine there, however, the game wouldn't run.

But when I decided to put my bankswitch routine at $FF85, where the original one was, the game runs!

I was trying to keep all of my code together (the mapper prep code, the PRG bankswitch routine, and the CHR bankswitch routine), but when I JSR'd to my free space to carry out the bankswitch routine, the game wouldn't run.

Why does JSR'ing elsewhere to carry out the bankswitch routine crash the game?  It shouldn't.
« Last Edit: September 25, 2015, 08:40:02 pm by Rockman »

Disch

  • Hero Member
  • *****
  • Posts: 2784
  • NES Junkie
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #3 on: September 25, 2015, 08:51:35 pm »
Quote
Why does JSR'ing elsewhere to carry out the bankswitch routine crash the game?  It shouldn't.

Maybe some code JSRs to the code after that first STA.


PS:  ADC is still weird in this context.

RetroRain

  • Sr. Member
  • ****
  • Posts: 287
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #4 on: September 25, 2015, 09:11:02 pm »
 I changed the other ADC to ORA.

So, the game now runs, but check this out:

The game loads all of the proper CHR pages into the pattern tables, but for whatever reason, they are not showing up right on the screen.





Now I have to go and track down why this is happening.

I wonder if SMB2 uses 8x16 sprite mode just like Zelda...


EDIT:

It figures... SMB2 is using 8x16 sprite mode. XD

Thanks for your help Disch! :)
« Last Edit: September 25, 2015, 09:28:31 pm by Rockman »

Disch

  • Hero Member
  • *****
  • Posts: 2784
  • NES Junkie
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #5 on: September 25, 2015, 09:29:47 pm »
The game loads all of the proper CHR pages into the pattern tables, but for whatever reason, they are not showing up right on the screen.

The second statement you said proves the first one to be false.   :P   If they were loaded correctly, it would be displaying properly.

Quote
I wonder if SMB2 uses 8x16 sprite mode just like Zelda...

Yes it does.

You can usually tell by the way the patterns look in the PPU viewer.  But one way to know for sure is to set a breakpoint on writes to $2000.  If it's being written to with bit 5 set ($20), the game uses 8x16 sprites.

RetroRain

  • Sr. Member
  • ****
  • Posts: 287
    • View Profile
Re: I'm having a tough time converting SMB2 (USA) to MMC5 (details inside)
« Reply #6 on: September 25, 2015, 10:13:50 pm »
The second statement you said proves the first one to be false.   :P

Damn it you got me again! :P lol