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

Author Topic: Dragon Warrior IV MMC5  (Read 1841 times)

Dracula X

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • My YouTube Page for ROM hacking
Dragon Warrior IV MMC5
« on: October 25, 2019, 11:03:53 am »
I'm actually finished converting Dragon Warrior IV from MMC1 to MMC5 but I think I ran into a problem. When the game finished showing the first screen, the game will not show the title screen.

Here is a list of codes that I never worked on before.
This might be a reason:

Code: [Select]
1F:C0E9: A9 40     LDA #$40
 1F:C0EB: 8D 02 05  STA $0502 = #$4C
 1F:C0EE: A9 00     LDA #$00
 1F:C0F0: 8D FF FF  STA $FFFF = #$C4
 1F:C0F3: 8D FF FF  STA $FFFF = #$C4
 1F:C0F6: 8D FF FF  STA $FFFF = #$C4
 1F:C0F9: 8D FF FF  STA $FFFF = #$C4
 1F:C0FC: A9 01     LDA #$01
 1F:C0FE: 8D FF FF  STA $FFFF = #$C4
 1F:C101: 4C 01 C1  JMP $C101

Bankswitch code in $3Cxxx and $7Cxxx

Code: [Select]
1F:FF91: 8D 07 05  STA $0507 = #$00
 1F:FF94: 48        PHA
 1F:FF95: AD 01 05  LDA $0501 = #$00
 1F:FF98: 29 EF     AND #$EF
 1F:FF9A: 8D 01 05  STA $0501 = #$00
 1F:FF9D: 68        PLA
 1F:FF9E: 48        PHA
 1F:FF9F: 29 10     AND #$10
 1F:FFA1: 0D 01 05  ORA $0501 = #$00
 1F:FFA4: 8D 01 05  STA $0501 = #$00
 1F:FFA7: 68        PLA
 1F:FFA8: 29 0F     AND #$0F
 1F:FFAA: EA        NOP
 1F:FFAB: EA        NOP
 1F:FFAC: 8D FF FF  STA $FFFF = #$C4
 1F:FFAF: 4A        LSR
 1F:FFB0: 8D FF FF  STA $FFFF = #$C4
 1F:FFB3: 4A        LSR
>1F:FFB4: 8D FF FF  STA $FFFF = #$C4
 1F:FFB7: 4A        LSR
 1F:FFB8: 8D FF FF  STA $FFFF = #$C4
 1F:FFBB: 4A        LSR
 1F:FFBC: 8D FF FF  STA $FFFF = #$C4
 1F:FFBF: AD 01 05  LDA $0501 = #$00
 1F:FFC2: 8D FF BF  STA $BFFF = #$BF
 1F:FFC5: 4A        LSR
 1F:FFC6: 8D FF BF  STA $BFFF = #$BF
 1F:FFC9: 4A        LSR
 1F:FFCA: 8D FF BF  STA $BFFF = #$BF
 1F:FFCD: 4A        LSR
 1F:FFCE: 8D FF BF  STA $BFFF = #$BF
 1F:FFD1: 4A        LSR
 1F:FFD2: 8D FF BF  STA $BFFF = #$BF
 1F:FFD5: EA        NOP
 1F:FFD6: EA        NOP
 1F:FFD7: 60        RTS -----------------------------------------

I'm not sure if Disch's code is the reason:

Code: [Select]
bankswitch: ;PRG Bankswitch Routine is at $CEA5 ffb0
EOR $0501               ; use EOR magic to extract 5th bit from 06C8
AND #$0F                ;   without using additional RAM
EOR $0501

AND #$1F                ; only care about 5 bit page number
ASL A                   ; double for MMC5
ORA #$80                ; set 'we want ROM' bit
STA $5115               ; swap $8000-BFFF page

LDA $0501               ; get 5th bit (desired 256K block)
AND #$10                ; isolate it
ORA #$1F                ; last page in 256K block, also set 'we want ROM' bit $4F didn't work on this game
ASL A                   ; double it for MMC5
STA $5117               ; swap $C000-FFFF page

RTS

Or this might be the reason:

Code: [Select]
  07C99F: 08        PHP
  07C9A0: AD 07 05  LDA $0507 = #$19
  07C9A3: 8D CC 07  STA $07CC = #$00
  07C9A6: A9 0F     LDA #$0F
  07C9A8: 8D 07 05  STA $0507 = #$19
  07C9AB: EA        NOP
  07C9AC: EA        NOP
  07C9AD: A9 00     LDA #$00
  07C9AF: 8D 01 05  STA $0501 = #$10
  07C9B2: 85 39     STA $39 = #$10
  07C9B4: 8D FF BF  STA $BFFF = #$BF
  07C9B7: 4A        LSR
  07C9B8: 8D FF BF  STA $BFFF = #$BF
  07C9BB: 4A        LSR
  07C9BC: 8D FF BF  STA $BFFF = #$BF
  07C9BF: 4A        LSR
  07C9C0: 8D FF BF  STA $BFFF = #$BF
  07C9C3: 4A        LSR
  07C9C4: 8D FF BF  STA $BFFF = #$BF
  07C9C7: EA        NOP
  07C9C8: EA        NOP
  07C9C9: AD CA 07  LDA $07CA = #$00
  07C9CC: 28        PLP
  07C9CD: 20 00 00  JSR $0000
  07C9D0: 08        PHP
  07C9D1: 8D CA 07  STA $07CA = #$00
  07C9D4: A9 10     LDA #$10
  07C9D6: 8D 01 05  STA $0501 = #$10
  07C9D9: 85 39     STA $39 = #$10
  07C9DB: EA        NOP
  07C9DC: EA        NOP
  07C9DD: 8D FF BF  STA $BFFF = #$BF
  07C9E0: 4A        LSR
  07C9E1: 8D FF BF  STA $BFFF = #$BF
  07C9E4: 4A        LSR
  07C9E5: 8D FF BF  STA $BFFF = #$BF
  07C9E8: 4A        LSR
  07C9E9: 8D FF BF  STA $BFFF = #$BF
  07C9EC: 4A        LSR
  07C9ED: 8D FF BF  STA $BFFF = #$BF
  07C9F0: EA        NOP
  07C9F1: EA        NOP
  07C9F2: AD CC 07  LDA $07CC = #$00
  07C9F5: 20 91 FF  JSR $FF91
  07C9F8: AD CA 07  LDA $07CA = #$00
  07C9FB: 28        PLP
  07C9FC: 60        RTS -----------------------------------------
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2746
  • NES Junkie
    • View Profile
Re: Dragon Warrior IV MMC5
« Reply #1 on: October 25, 2019, 02:28:04 pm »
Code: [Select]
ORA #$1F                ; last page in 256K block, also set 'we want ROM' bit $4F didn't work on this game
Why did you change this to $1F?


More specifically... ask yourself what you were trying to do.  Then ask what that actually does.

Dracula X

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • My YouTube Page for ROM hacking
Re: Dragon Warrior IV MMC5
« Reply #2 on: October 25, 2019, 02:34:20 pm »
When I had it on $4F, the game won't load. What I'm trying to do is to get the title screen to load.
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2746
  • NES Junkie
    • View Profile
Re: Dragon Warrior IV MMC5
« Reply #3 on: October 25, 2019, 02:41:27 pm »
Well, I meant what do you want the code to do vs. what is that code actually doing.

If something is broken, just trying random values and hoping it will fix the problem will almost never work.  You have to analyze the code, figure out where it's going wrong and change things with a plan rather than guessing.


Specifically, by changing that to $1F, you are effectively ALWAYS swapping that bank to the 7Cxxx range, thereby eliminating the 3Cxxx/7Cxxx swap that was originally intended to be there.
« Last Edit: October 25, 2019, 02:48:13 pm by Disch »

Dracula X

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • My YouTube Page for ROM hacking
Re: Dragon Warrior IV MMC5
« Reply #4 on: October 25, 2019, 07:41:22 pm »
Heres what the code is doing since I found out that there's nothing wrong with the code.

While watching the 6502 debugger in FCEUX, if I leave the value to $4F, the bank will load to $0F instead of $1F. I'm still looking into this.

I did a breakpoint in $8000-$FFFF range and the bank will load at $0F first. So I'll see what's going on.
« Last Edit: October 25, 2019, 07:50:06 pm by Dracula X »
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2746
  • NES Junkie
    • View Profile
Re: Dragon Warrior IV MMC5
« Reply #5 on: October 25, 2019, 08:13:47 pm »
On MMC1, whether 0F or 1F is swapped into the C000-FFFF slot depends on whether or not pages 0-F or 10-1F are swapped into the 8000-BFFF slot.

One way to imagine this is the 512K PRG is split into two 256K blocks.  The $C000-FFFF range is always set to the last page in the current block.  So it will either be page $0F or $1F depending on which block is selected.

On MMC1, the game selects the block by writing to $BFFF.  If it writes $0x, it wants the first block, if it writes $1x, it wants the second block.


The code I provided assumes the desired block was stored in RAM (based on the code you posted, it looks like address $0501)

Code: [Select]
LDA $0501               ; bit 4 of this value is the block the game wants
AND #$10                ; isolate that bit
ORA #$0F                ; or with #$0F to select the last page IN THAT BLOCK
        ASL A                   ; shift it left because MMC5 expects an 8k page number
        ORA #$80                ; turn on the 'we want ROM' bit
        STA $5117               ; swap page into $C000-FFFF slot

Although my original code combined both of those ORAs (hence $4F instead of $0F, since the following ASL will change that 4 to an 8 )


I don't think this code is your problem.  If the game is crashing, there must be something else going on.


Is the original game writing to BFFF anywhere else?  You'll have to capture all of those writes and translate them into MMC5 equivalents.
« Last Edit: October 25, 2019, 08:29:14 pm by Disch »

Dracula X

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • My YouTube Page for ROM hacking
Re: Dragon Warrior IV MMC5
« Reply #6 on: October 25, 2019, 09:17:09 pm »
Thanks for the code! Your new code works, but the same thing keeps on happening. I think this might be the reason and the other one:

Code: [Select]
  07C99F: 08        PHP
  07C9A0: AD 07 05  LDA $0507 = #$19
  07C9A3: 8D CC 07  STA $07CC = #$00
  07C9A6: A9 0F     LDA #$0F
  07C9A8: 8D 07 05  STA $0507 = #$19
  07C9AB: EA        NOP
  07C9AC: EA        NOP
  07C9AD: A9 00     LDA #$00
  07C9AF: 8D 01 05  STA $0501 = #$10
  07C9B2: 85 39     STA $39 = #$10
  07C9B4: 8D FF BF  STA $BFFF = #$BF
  07C9B7: 4A        LSR
  07C9B8: 8D FF BF  STA $BFFF = #$BF
  07C9BB: 4A        LSR
  07C9BC: 8D FF BF  STA $BFFF = #$BF
  07C9BF: 4A        LSR
  07C9C0: 8D FF BF  STA $BFFF = #$BF
  07C9C3: 4A        LSR
  07C9C4: 8D FF BF  STA $BFFF = #$BF
  07C9C7: EA        NOP
  07C9C8: EA        NOP
  07C9C9: AD CA 07  LDA $07CA = #$00
  07C9CC: 28        PLP
  07C9CD: 20 00 00  JSR $0000
  07C9D0: 08        PHP
  07C9D1: 8D CA 07  STA $07CA = #$00
  07C9D4: A9 10     LDA #$10
  07C9D6: 8D 01 05  STA $0501 = #$10
  07C9D9: 85 39     STA $39 = #$10
  07C9DB: EA        NOP
  07C9DC: EA        NOP
  07C9DD: 8D FF BF  STA $BFFF = #$BF
  07C9E0: 4A        LSR
  07C9E1: 8D FF BF  STA $BFFF = #$BF
  07C9E4: 4A        LSR
  07C9E5: 8D FF BF  STA $BFFF = #$BF
  07C9E8: 4A        LSR
  07C9E9: 8D FF BF  STA $BFFF = #$BF
  07C9EC: 4A        LSR
  07C9ED: 8D FF BF  STA $BFFF = #$BF
  07C9F0: EA        NOP
  07C9F1: EA        NOP
  07C9F2: AD CC 07  LDA $07CC = #$00
  07C9F5: 20 91 FF  JSR $FF91
  07C9F8: AD CA 07  LDA $07CA = #$00
  07C9FB: 28        PLP
  07C9FC: 60        RTS -----------------------------------------

And this:

Code: [Select]
1F:C0E9: A9 40     LDA #$40
 1F:C0EB: 8D 02 05  STA $0502 = #$4C
 1F:C0EE: A9 00     LDA #$00
 1F:C0F0: 8D FF FF  STA $FFFF = #$C4
 1F:C0F3: 8D FF FF  STA $FFFF = #$C4
 1F:C0F6: 8D FF FF  STA $FFFF = #$C4
 1F:C0F9: 8D FF FF  STA $FFFF = #$C4
 1F:C0FC: A9 01     LDA #$01
 1F:C0FE: 8D FF FF  STA $FFFF = #$C4
 1F:C101: 4C 01 C1  JMP $C101
I do not do other games that have already been done.

Disch

  • Hero Member
  • *****
  • Posts: 2746
  • NES Junkie
    • View Profile
Re: Dragon Warrior IV MMC5
« Reply #7 on: October 25, 2019, 10:46:56 pm »
OK so anything that is writing to the $8000-FFFF range is MMC1 stuff.  If this is a mapper hack you need to replace that code with something that has the same effect on MMC5.  So really, you need to understand how both MMC1 and MMC5 work in order to make this kind of hack.

That said... take a look at the sections of code that are writing to those registers.  There are 3 that you just posted:

First:
Code: [Select]
  07C9AD: A9 00     LDA #$00
  07C9AF: 8D 01 05  STA $0501 = #$10
  07C9B2: 85 39     STA $39 = #$10
  07C9B4: 8D FF BF  STA $BFFF = #$BF
  07C9B7: 4A        LSR
  07C9B8: 8D FF BF  STA $BFFF = #$BF
  07C9BB: 4A        LSR
  07C9BC: 8D FF BF  STA $BFFF = #$BF
  07C9BF: 4A        LSR
  07C9C0: 8D FF BF  STA $BFFF = #$BF
  07C9C3: 4A        LSR
  07C9C4: 8D FF BF  STA $BFFF = #$BF

Second:
Code: [Select]
  07C9D4: A9 10     LDA #$10
  07C9D6: 8D 01 05  STA $0501 = #$10
  07C9D9: 85 39     STA $39 = #$10
  07C9DB: EA        NOP
  07C9DC: EA        NOP
  07C9DD: 8D FF BF  STA $BFFF = #$BF
  07C9E0: 4A        LSR
  07C9E1: 8D FF BF  STA $BFFF = #$BF
  07C9E4: 4A        LSR
  07C9E5: 8D FF BF  STA $BFFF = #$BF
  07C9E8: 4A        LSR
  07C9E9: 8D FF BF  STA $BFFF = #$BF
  07C9EC: 4A        LSR
  07C9ED: 8D FF BF  STA $BFFF = #$BF

Third:
Code: [Select]
1F:C0EE: A9 00     LDA #$00
 1F:C0F0: 8D FF FF  STA $FFFF = #$C4
 1F:C0F3: 8D FF FF  STA $FFFF = #$C4
 1F:C0F6: 8D FF FF  STA $FFFF = #$C4
 1F:C0F9: 8D FF FF  STA $FFFF = #$C4
 1F:C0FC: A9 01     LDA #$01
 1F:C0FE: 8D FF FF  STA $FFFF = #$C4


Knowing what you know about $0501, $BFFF, and $FFFF ... what are each of these sections of code trying to do?

I'm trying really hard not to just give you a direct solution -- I want to help guide you to find it yourself.