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

Author Topic: Need a quick help on Ninja Gaiden MMC1 to MMc5  (Read 1121 times)

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
Need a quick help on Ninja Gaiden MMC1 to MMc5
« on: March 22, 2020, 10:20:06 pm »
Before I release a bugfix for this hack, I need to know what to put here with MMC5 equivalents or something else:

Mirroring for cut scenes?
Code: [Select]
  0101F9: 8D FF 9F  STA $9FFF = #$00
  0101FC: 4A        LSR
  0101FD: 8D FF 9F  STA $9FFF = #$00
  010200: 4A        LSR
  010201: 8D FF 9F  STA $9FFF = #$00
  010204: 4A        LSR
  010205: 8D FF 9F  STA $9FFF = #$00
  010208: 4A        LSR
  010209: 8D FF 9F  STA $9FFF = #$00
  01020C: 60        RTS -----------------------------------------

Main CHR Left
Main CHR Right
Main Bankswitch

Code: [Select]
  01C010: 8D FF BF  STA $BFFF = #$FF
  01C013: 4A        LSR
  01C014: 8D FF BF  STA $BFFF = #$FF
  01C017: 4A        LSR
  01C018: 8D FF BF  STA $BFFF = #$FF
  01C01B: 4A        LSR
  01C01C: 8D FF BF  STA $BFFF = #$FF
  01C01F: 4A        LSR
  01C020: 8D FF BF  STA $BFFF = #$FF
  01C023: 60        RTS -----------------------------------------
  01C024: 8D FF DF  STA $DFFF = #$85
  01C027: 4A        LSR
  01C028: 8D FF DF  STA $DFFF = #$85
  01C02B: 4A        LSR
  01C02C: 8D FF DF  STA $DFFF = #$85
  01C02F: 4A        LSR
  01C030: 8D FF DF  STA $DFFF = #$85
  01C033: 4A        LSR
  01C034: 8D FF DF  STA $DFFF = #$85
  01C037: 60        RTS -----------------------------------------
  01C038: 85 5C     STA $5C = #$04
  01C03A: 8D FF FF  STA $FFFF = #$FA
  01C03D: 4A        LSR
  01C03E: 8D FF FF  STA $FFFF = #$FA
  01C041: 4A        LSR
  01C042: 8D FF FF  STA $FFFF = #$FA
  01C045: 4A        LSR
  01C046: 8D FF FF  STA $FFFF = #$FA
  01C049: 4A        LSR
  01C04A: 8D FF FF  STA $FFFF = #$FA
  01C04D: 60        RTS -----------------------------------------

I'm not sure what this is:
Code: [Select]
  01C04E: 78        SEI
  01C04F: D8        CLD
  01C050: 2C 02 20  BIT PPU_STATUS = #$40
  01C053: 10 FB     BPL $C040
  01C055: 2C 02 20  BIT PPU_STATUS = #$40
  01C058: 10 FB     BPL $C045
  01C05A: A2 FF     LDX #$FF
  01C05C: 9A        TXS
  01C05D: E8        INX
  01C05E: 8E FF 9F  STX $9FFF = #$00
  01C061: E8        INX
  01C062: 8E FF 9F  STX $9FFF = #$00
  01C065: 8E FF 9F  STX $9FFF = #$00
  01C068: 8E FF 9F  STX $9FFF = #$00
  01C06B: 8E FF 9F  STX $9FFF = #$00
  01C06E: CA        DEX
  01C06F: 8E 15 40  STX APU_STATUS = #$0F

Not sure what to put here because it doesn't look like the one's at the first code:
JSR $C02A
JMP $D8E8
Code: [Select]
  01D8E5: A2 00     LDX #$00
  01D8E7: 8E FF FF  STX $FFFF = #$FA
  01D8EA: E8        INX
  01D8EB: 8E FF FF  STX $FFFF = #$FA
  01D8EE: CA        DEX
  01D8EF: 8E FF FF  STX $FFFF = #$FA
  01D8F2: 8E FF FF  STX $FFFF = #$FA
  01D8F5: 8E FF FF  STX $FFFF = #$FA

JSR $C02A
JMP $F495
Code: [Select]
  01F494: A9 00     LDA #$00
  01F496: 8D FF FF  STA $FFFF = #$FA
  01F499: 8D FF FF  STA $FFFF = #$FA
  01F49C: 8D FF FF  STA $FFFF = #$FA
  01F49F: 8D FF FF  STA $FFFF = #$FA
  01F4A2: 8D FF FF  STA $FFFF = #$FA

LDA #$01
JSR $C02A
JMP $F50B
Code: [Select]
  01F509: A2 01     LDX #$01
  01F50B: 8E FF FF  STX $FFFF = #$FA
  01F50E: CA        DEX
  01F50F: 8E FF FF  STX $FFFF = #$FA
  01F512: 8E FF FF  STX $FFFF = #$FA
  01F515: 8E FF FF  STX $FFFF = #$FA
  01F518: 8E FF FF  STX $FFFF = #$FA

I know what to do with this here:
Code: [Select]
  01F5BC: A5 5A     LDA $5A = #$00
  01F5BE: 8D FF DF  STA $DFFF = #$85
  01F5C1: 4A        LSR
  01F5C2: 8D FF DF  STA $DFFF = #$85
  01F5C5: 4A        LSR
  01F5C6: 8D FF DF  STA $DFFF = #$85
  01F5C9: 4A        LSR
  01F5CA: 8D FF DF  STA $DFFF = #$85
  01F5CD: 4A        LSR
  01F5CE: 8D FF DF  STA $DFFF = #$85
  01F5D1: A5 57     LDA $57 = #$00
  01F5D3: 8D FF BF  STA $BFFF = #$FF
  01F5D6: 4A        LSR
  01F5D7: 8D FF BF  STA $BFFF = #$FF
  01F5DA: 4A        LSR
  01F5DB: 8D FF BF  STA $BFFF = #$FF
  01F5DE: 4A        LSR
  01F5DF: 8D FF BF  STA $BFFF = #$FF
  01F5E2: 4A        LSR
  01F5E3: 8D FF BF  STA $BFFF = #$FF

JSR $C02A
Code: [Select]
  01F5FA: A9 00     LDA #$00
  01F5FC: 8D FF FF  STA $FFFF = #$FA
  01F5FF: 8D FF FF  STA $FFFF = #$FA
  01F602: 8D FF FF  STA $FFFF = #$FA
  01F605: 8D FF FF  STA $FFFF = #$FA
  01F608: 8D FF FF  STA $FFFF = #$FA

Code: [Select]
  01F948: A2 01     LDX #$01
  01F94A: 8E FF FF  STX $FFFF = #$FA
  01F94D: CA        DEX
  01F94E: 8E FF FF  STX $FFFF = #$FA
  01F951: 8E FF FF  STX $FFFF = #$FA
  01F954: 8E FF FF  STX $FFFF = #$FA
  01F957: 8E FF FF  STX $FFFF = #$FA

I know what to do here:
Code: [Select]
> 01F9AA: 8D FF BF  STA $BFFF = #$FF
  01F9AD: 4A        LSR
  01F9AE: 8D FF BF  STA $BFFF = #$FF
  01F9B1: 4A        LSR
  01F9B2: 8D FF BF  STA $BFFF = #$FF
  01F9B5: 4A        LSR
  01F9B6: 8D FF BF  STA $BFFF = #$FF
  01F9B9: 4A        LSR
  01F9BA: 8D FF BF  STA $BFFF = #$FF
  01F9BD: A5 59     LDA $59 = #$1E
  01F9BF: 8D FF DF  STA $DFFF = #$85
  01F9C2: 4A        LSR
  01F9C3: 8D FF DF  STA $DFFF = #$85
  01F9C6: 4A        LSR
  01F9C7: 8D FF DF  STA $DFFF = #$85
  01F9CA: 4A        LSR
  01F9CB: 8D FF DF  STA $DFFF = #$85
  01F9CE: 4A        LSR
  01F9CF: 8D FF DF  STA $DFFF = #$85

I know what to do here except for the first part:
LDA #$03
Code: [Select]
  01F9F9: A2 01     LDX #$01
  01F9FB: 8E FF FF  STX $FFFF = #$FA
  01F9FE: 8E FF FF  STX $FFFF = #$FA
  01FA01: CA        DEX
  01FA02: 8E FF FF  STX $FFFF = #$FA
  01FA05: 8E FF FF  STX $FFFF = #$FA
  01FA08: 8E FF FF  STX $FFFF = #$FA
  01FA0B: 20 00 80  JSR $8000
  01FA0E: A5 5C     LDA $5C = #$04
  01FA10: 8D FF FF  STA $FFFF = #$FA
  01FA13: 4A        LSR
  01FA14: 8D FF FF  STA $FFFF = #$FA
  01FA17: 4A        LSR
  01FA18: 8D FF FF  STA $FFFF = #$FA
  01FA1B: 4A        LSR
  01FA1C: 8D FF FF  STA $FFFF = #$FA
  01FA1F: 4A        LSR
  01FA20: 8D FF FF  STA $FFFF = #$FA

I'm not sure where is the main Mirroring code is so I have to make a customized code.
That's all the info that I have.
« Last Edit: March 22, 2020, 10:29:24 pm by Dracula X »

Disch

  • Hero Member
  • *****
  • Posts: 2786
  • NES Junkie
    • View Profile
Re: Need a quick help on Ninja Gaiden MMC1 to MMc5
« Reply #1 on: March 24, 2020, 07:05:24 pm »
I'm going to avoid giving out direct code for this one because I think you can manage it yourself.


The weird thing about MMC1 regs is that they have to be written to one bit at a time, in sets of 5.  So when you see any write to the $8000-FFFF range, only the low bit matters*.

So for example.... the "typical" case looks like this:
Code: [Select]
LDA #$13   ; same value to write in A.  $13 = %00010011

; we need to perform 5 writes to get MMC1 to recognize this.  Each write takes the low bit of the written value
;  games will usually alternate between STA/LSR... each LSR shifting down the bits so the next one is written on the
;  next STA

STA $9FFF  ; A=%00010011  <- low bit is 1, therefore 1 gets put in the reg
           ;  new MMC1 reg contents = ????1
           ;                              ^

LSR A      ; now A=%00001001 <- low bit still 1...
STA $9FFF  ;  new MMC1 reg = ???11
           ;                    ^

LSR A      ; now A=%00000100 <- low bit is now 0
STA $9FFF  ; new MMC1 reg = ??011
           ;                  ^

LSR A      ; now A=%00000010 <- low bit is 0
STA $9FFF  ; new MMC1 reg = ?0011
           ;                 ^

LSR A      ; now A=%00000001 <- low bit is 1
STA $9FFF  ; new MMC1 reg = 10011
           ;                ^
           ; all 5 bits written -- so this write is complete and %10011 (or $13) is the value written to the register.

Knowing that, we can figure out what something like this is doing:
Code: [Select]
01C05A: A2 FF     LDX #$FF          ; X=$FF
01C05C: 9A        TXS
01C05D: E8        INX               ; X=$00
01C05E: 8E FF 9F  STX $9FFF = #$00  ; low bit of X=0 -- mmc1 reg = ????0
01C061: E8        INX               ; X=$01
01C062: 8E FF 9F  STX $9FFF = #$00  ; low bit of X=1 -- mmc1 reg = ???10
01C065: 8E FF 9F  STX $9FFF = #$00  ; low bit of X=1 -- mmc1 reg = ??110
01C068: 8E FF 9F  STX $9FFF = #$00  ; low bit of X=1 -- mmc1 reg = ?1110
01C06B: 8E FF 9F  STX $9FFF = #$00  ; low bit of X=1 -- mmc1 reg = 11110

; As you can see, the code effectively wrote $1E to the $9FFF register


You should be able to figure out what writes to $9FFF accomplish (they are CHR swapping, IIRC, but double check on the wiki).  And you should be able to figure out how to mimic that on MMC5 easily enough.





*(The high bit matters too, but if the high bit is set, the game is resetting the mapper which is probably only going to happen once at startup and therefore you can probably ignore it)
« Last Edit: March 24, 2020, 08:41:01 pm by Disch »

Dracula X

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • My YouTube Page for ROM hacking
Re: Need a quick help on Ninja Gaiden MMC1 to MMc5
« Reply #2 on: March 24, 2020, 11:40:18 pm »
Thanks for the info! I can actually ignore this for now.