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

Author Topic: I'm having trouble with MMC5's 2K CHR Switching (solved)  (Read 2662 times)

RetroRain

  • Sr. Member
  • ****
  • Posts: 286
    • View Profile
I'm having trouble with MMC5's 2K CHR Switching (solved)
« on: February 16, 2015, 12:36:10 pm »
I'm having a little bit of trouble with MMC5's CHR-ROM switching.  More specifically, switching 2K CHR pages.

; set chr mode to 2, to enable 2K switching
LDA #$02
STA $5101 = #$FC

; load chr page #$22, and write it to $0000-$07FF
LDA #$22
STA $5121 = #$FC

; load chr page #$2A, and write it to $0800-$0FFF
LDA #$2A
STA $5123 = #$FC



; this code right here works fine.  It sets the mode to 1 (4K switching),
; and then writes chr page #$12 to $1000-$1FFF
LDA #$01
STA $5101 = #$FC
LDA #$12
STA $5127 = #$FC

The result is this:



The nesdev wiki article mentions $5130, which I have messed with.  I may not be doing it right, but I'm not sure if I need it either.  I have no problems doing 8K and 4K switching.  But 2K and 1K seem don't seem to be working.

Any help would be greatly appreciated.

Thanks.
« Last Edit: February 16, 2015, 09:08:41 pm by Rockman »

Bregalad

  • Hero Member
  • *****
  • Posts: 2641
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching
« Reply #1 on: February 16, 2015, 02:01:30 pm »
Contrary to (almost) all other NES mappers, CHR bank are counted as actual banks, that is, the size of the switched bank matters for the number you'll going to put. In other words, the MMC5 automatically shifts the value left when using a bank size greater than 1k (if this makes sense to you).

In your particular case, I belive you should use $24 and $25 instead of of $22 and $2a, and you'd have the same result as the below code.

RetroRain

  • Sr. Member
  • ****
  • Posts: 286
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching
« Reply #2 on: February 16, 2015, 02:41:21 pm »
I already knew this.  It doesn't work anyway.  I've been messing with the register $5130, and I'm not having any luck.

Dr. Floppy

  • Restricted Access
  • Hero Member
  • *
  • Posts: 972
  • Make America GREAT Again!
    • View Profile
    • BaddestHacks.net
Re: I'm having trouble with MMC5's 2K CHR Switching
« Reply #3 on: February 16, 2015, 04:15:48 pm »
What's the total size of your game, both PRG- and CHR-ROM? Also, do you have 8x16 sprites enabled?

RetroRain

  • Sr. Member
  • ****
  • Posts: 286
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching
« Reply #4 on: February 16, 2015, 05:06:12 pm »
The ROM is Megaman 2.
Mapper is MMC5.
The total size is 1.25 MB (1,281 KB)
PRG banks: 16 x 16kb
CHR banks: 128 x 8kb
8 x 8 sprites (not 8 x 16)

CHR-ROM size was maxed out, where-as PRG-ROM was not expanded at all.

I am currently converting Megaman 2 to CHR-ROM.  This project depends on me being able to swap 2K CHR banks.  If I can't do it, I'm screwed.

I messed with register $5130 so many times.  And I tried all variations of $5130 in conjuction with the chr bank numbers, adding two $5130s, omitting them completely, putting the chr bank numbers in $5130 instead, and making the chr bank addresses 0, etc.  NOTHING WORKS.

The game doesn't want to do 2K CHR switches.  It will only do 8K or 4K.  And I followed the wiki.nesdev article, and I have had nothing but success up until now.  There is no reason why my code shouldn't be working.  But it doesn't.

I'm actually stuck on this.  I wouldn't ask for help if I didn't need it.

Thanks.

EDIT

Okay, apparently you can't load two 2K CHR banks on the left side of the PPU, and then switch the mode to 4K, and load the 4K bank on the right side of the PPU.  I don't know why you can't, but you can't.  So, I'll just deal with it.

Thanks guys.
« Last Edit: February 16, 2015, 09:08:15 pm by Rockman »

Bregalad

  • Hero Member
  • *****
  • Posts: 2641
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching (solved)
« Reply #5 on: February 17, 2015, 06:41:56 am »
I strongly suspect that no emulator implements the $5130 behaviour since no (commercial) games ever used this register for CHR switches. Do you test in emulator only ?

Also, why do you edit the title to say "solved" if your problem isn't solved ?

RetroRain

  • Sr. Member
  • ****
  • Posts: 286
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching (solved)
« Reply #6 on: February 17, 2015, 12:58:05 pm »
Also, why do you edit the title to say "solved" if your problem isn't solved ?

Because my problem IS solved.  I got the game to do 2K switches.  The reason why it wasn't working is because there was a conflict with the CHR modes, which was causing the CHR problems.  $5130 wasn't needed at all.

Bregalad

  • Hero Member
  • *****
  • Posts: 2641
    • View Profile
Re: I'm having trouble with MMC5's 2K CHR Switching (solved)
« Reply #7 on: February 17, 2015, 02:56:59 pm »
Oh I misread your "EDIT" part. Of course when you change the switching mode it changes everything like on all other mappers in existence.

tomaitheous

  • Hero Member
  • *****
  • Posts: 543
    • View Profile
    • PC Engine Dev
Re: I'm having trouble with MMC5's 2K CHR Switching (solved)
« Reply #8 on: February 22, 2015, 06:58:00 pm »
Because my problem IS solved.  I got the game to do 2K switches.  The reason why it wasn't working is because there was a conflict with the CHR modes, which was causing the CHR problems.  $5130 wasn't needed at all.
It's not really a conflict at all, when you think about it. Rather, it makes perfect sense. If you're in 4k mode, why would the mapper care about values in the regs of the lesser 2k sub segments, etc? I mean, you're in 4k mode because you want to swap in/out 4k at a time. The value in $5121 is irrelevant in 4k mode, so it's ignored and $5123 is read from instead (and as a 4k bank number) - etc. So when you switch modes, everything gets re-initialized for the correct mapping. Though, 're-initialize' is probably the wrong description for how it actually works on a low level, because those memory mapped regs are probably thee very same regs (not copies) that are used for the full address calculation in real time (no need to over engineer things).