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

Author Topic: MMC5 Bankswitch Help  (Read 287 times)

Dracula X

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • My YouTube Page for ROM hacking
MMC5 Bankswitch Help
« on: October 16, 2019, 10:26:26 am »
Before I go further, If I use this code for Dragon Warrior for example:
Code: [Select]

ff96:
        pha
asl
ora #$80
sta $5115
pla
rts

The game will crash.


If I use this code:
Code: [Select]

ff96:       
asl
ora #$80
sta $5115
rts

The game will work fine but some things will not work normally.

If I use it this way:
Code: [Select]
jsr bankswitchThe game will work fine.
« Last Edit: October 16, 2019, 01:02:18 pm by Dracula X »
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2737
  • NES Junkie
    • View Profile
Re: MMC5 Bankswitch Help
« Reply #1 on: October 16, 2019, 06:22:25 pm »
Is there a question here?


This post is a little confusing.  I gather that you are converting Dragon Warrior to MMC5.  And I researched on my own that Dragon Warrior is MMC1, so you're doing an MMC1->MMC5 conversion.

But then you say you got it to work by JSRing to 'bankswitch'?  But you never say what 'bankswitch' is.

So is the problem solved?  Do you still need help?  I'm very confused.

nesrocks

  • Hero Member
  • *****
  • Posts: 606
    • View Profile
    • nesrocks.com
Re: MMC5 Bankswitch Help
« Reply #2 on: October 16, 2019, 06:28:11 pm »
It seems like you're confused by RTS and JSR.

RTS will fiddle with the stack, so to keep the stack healthy you use it with a JSR first. If you don't want to use JSR, then at the end of the new code you need to branch back to path using a branch instruction, or JMP instead of RTS.

This seems too basic for OP's experience, but that's what it seems.

Dracula X

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • My YouTube Page for ROM hacking
Re: MMC5 Bankswitch Help
« Reply #3 on: October 16, 2019, 06:47:19 pm »
Some games have codes like this:
Code: [Select]
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  rts

Dragon Warrior have something like this:
Code: [Select]
ff91:
  sta $6004
  nop
  nop


ff96:
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  lsr a
  sta $ffff
  nop
  nop
  rts

What I'm trying to do is find a way to use that location instead of jsr to another location without no problems.
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2737
  • NES Junkie
    • View Profile
Re: MMC5 Bankswitch Help
« Reply #4 on: October 16, 2019, 07:00:20 pm »
So the functionally equivalent MMC5 bankswap code would be this:

Code: [Select]
PHA
ASL A
ORA #$80
STA $5115
PLA
LSR A
LSR A
LSR A
LSR A
RTS

But.. since A is not likely to be greater than $0F upon entry to this routine, you might be able to get away with this instead:

Code: [Select]
ASL A
ORA #$80
STA $5115
LDA #0
RTS

The key thing to note here is that the original routine is swapping in PRG, yes, but it is also modifying A.  And code that uses this routing might be relying on the fact that A has been modified.

Dracula X

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • My YouTube Page for ROM hacking
Re: MMC5 Bankswitch Help
« Reply #5 on: October 16, 2019, 11:22:08 pm »
Thank you! The second code seems to work pretty good. I'll be using this for Dragon Warrior NES games.

I should point out that it might not work for all games.
« Last Edit: October 17, 2019, 12:05:08 am by Dracula X »
I do not do other games that have already been done.