More MMC1 CHR bankswitching woes (On real hardware)

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

More MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

I have a little n00b question regarding the MMC1. When I bankswitch the CHR background like this

LDA #%00000010 ;Swap background
JSR Background_Select ;Go to $C000 bankswitching subroutine

;Rest of code here

Background_Select:
STA $C000
LSR A
STA $C000
LSR A
STA $C000
LSR A
STA $C000
LSR A
STA $C000
RTS

It works fine on an emulator. However, on real hardware, it seems like there is no such thing, the name entry screen of Deal or no Deal keeps the title background CHR bank. What am I doing wrong?

Here are the pics

Emu
Image
Real Hardware
Image (Uses the title screen CHR bank)
Last edited by Vectrex2809 on Tue Nov 18, 2014 1:31 am, edited 1 time in total.
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by lidnariq »

Have you also configured the other MMC1 registers?
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

You mean the PRG bank, Sprites CHR bank and $8000? I did.
Here it is (sorry for the pic. My Iphone didn't want to select the text...)
Image
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by thefox »

If you're using a flash cart to test, make sure the number of CHR banks in your ROM is a power of two (1, 2, 4, 8, and so on).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by lidnariq »

Are you trying to use different background banks in different parts of the screen?
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

lidnariq wrote:Are you trying to use different background banks in different parts of the screen?
Nope. I think Fox is right though, I have 5 CHR banks in my game. Gonna fix that this evening and I'll update you guys :)
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by 3gengames »

You also need to initialize the first background, too. Boot state is random, y ou have to set up everything how you want it first before you can assume any graphics will show. :)
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by tepples »

3gengames wrote:You also need to initialize the first background, too. Boot state is random, y ou have to set up everything how you want it first before you can assume any graphics will show. :)
I assume that's what this is for:

Code: Select all

  LDA #%00000001
  JSR Sprite_Select
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

Hey,
It seems like it works now... Kinda. I still have one bankswitching problem. At some point in the game, you have to select a character. There are 6 banks with five characters in each bank. On an emulator, it works as it should (Starts at bank 03, then goes to bank 04, etc. until bank 8). On real hardware (Tried the Everdrive and the PowerPak), it starts at bank 03, then goes back to bank 00 for some reason, then bank 01, but finishes with bank 08 as it should. Anyone knows what's wrong?

Code: Select all


  LDA buttons
  AND #%00000001
  BEQ NoCharRightUnpressed  ;Not the best way of doing this, I know
  LDA rightpressed                  ;If right is already pressed, don't do the folowing
  BNE NoCharRight                  ;There are better ways to do this, I should change it...
  INC rightpressed
  INC CharNumber
  LDA CaseCharacter               ;Characters are like 3x6 metatiles, this seems to work
  CLC
  ADC #$03
  STA CaseCharacter
  CMP #$6E
  BCC .nochange3
  LDA #$60
  STA CaseCharacter
  INC CaseGraphicBank              ;Here's the main culprit >:(. On real hardware, goes back to zero...
  LDA CaseGraphicBank
  CMP #$09                               ;If higher than $08, set $03
  BNE .chrbankok3
  LDA #$03
  STA CaseGraphicBank
.chrbankok3                              ;There used to be the CHR bank switch subroutine here, but I put it at the beginning of the char selection routine in order to fix a minor glitch
.nochange3
  LDA Character_Palette             ;Sets the palette for the characters. This seems to work too
  CLC
  ADC #$03
  CMP #PALETTEEND
  BCC .nopalend
  LDA #$00
.nopalend
  STA Character_Palette
This is the routine to go to the next character. The routine when pressed left looks similar except it's kind of the opposite thing that happens. Tell me if you need me to post more code. I'll take my src with me today :) Thanks everyone! You've been of great help so far.
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

Rewrote my routine, but I have the same problem on real hardware using flashcarts... Please help me :)

Code: Select all

  LDX CharNumber
  LDA case_bank,x
  JSR Background_Select   ;$C000 MMC1 writes

;Blahblahblahworkingcodeblahblahblah

case_bank:
  .db $03,$03,$03,$03,$03,$04,$04,$04,$04,$04,$05,$05,$05,$05,$05
  .db $06,$06,$06,$06,$06,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08
Do you know what's wrong?

--Vec
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by Bregalad »

Pehaps you shoud describe us more in detail what
1) what you are trying to do
2) what do you exepct your results to be
and
3) what is wrong with your actual results

so we can have a clue how to help you ? Just some code is not enough.

The only 2 tricks with the MMC1 are
1) You need to "reset" the mapper at startup (but you only have to do it once, as long as you're sure you always write in bulks of 5 writes)
2) You should not use the mapper in the interrupt routine at the same time you use it in the main program. If you do that, both writes can (and will) conflict. Even if you don't write to the same MMC1 register : The MMC1 has only one "shift register" for input, and the 4 real (internal) registers are written to after the last write of the bunch of 5.

PS : Also you didn't mention which emulators you used, but you should really debug with Nintendulator which is the most accurate to real hardware. When there is a different between real hardware and normal emulators, often Nintendulator and Nestopia are the 2 only ones to emulate the "correct" behaviour (but Nestopia has no debugger).
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by Dwedit »

The number of PRG or CHR banks must be a power or 2. So you can't have 5 banks, need to pad it with empty banks to 8.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by lidnariq »

Also, base 0, not base 1 ... if you have eight banks, they're numbered 0 through 7.
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

Actually, it was the number of banks again. Thanks for the replies :)
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: More MMC1 CHR bankswitching woes (On real hardware)

Post by Vectrex2809 »

Bregalad wrote:Pehaps you shoud describe us more in detail what
1) what you are trying to do
2) what do you exepct your results to be
and
3) what is wrong with your actual results

so we can have a clue how to help you ? Just some code is not enough.

The only 2 tricks with the MMC1 are
1) You need to "reset" the mapper at startup (but you only have to do it once, as long as you're sure you always write in bulks of 5 writes)
2) You should not use the mapper in the interrupt routine at the same time you use it in the main program. If you do that, both writes can (and will) conflict. Even if you don't write to the same MMC1 register : The MMC1 has only one "shift register" for input, and the 4 real (internal) registers are written to after the last write of the bunch of 5.

PS : Also you didn't mention which emulators you used, but you should really debug with Nintendulator which is the most accurate to real hardware. When there is a different between real hardware and normal emulators, often Nintendulator and Nestopia are the 2 only ones to emulate the "correct" behaviour (but Nestopia has no debugger).
I used FCEUX and NEStopia. I'm gonna give Nintendulator a go, thanks for the advice. I also heard about puNes being accurate, is that the case?
As for next time, I'm going to ask questions in a better way, sorry for the confusion :P

PS : Tu viens du Canton de Vaud toi aussi?
Post Reply