Page 1 of 3
More MMC1 CHR bankswitching woes (On real hardware)
Posted: Sun Nov 16, 2014 11:41 pm
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

Real Hardware

(Uses the title screen CHR bank)
Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Sun Nov 16, 2014 11:57 pm
by lidnariq
Have you also configured the other MMC1 registers?
Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 12:20 am
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...)

Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 12:38 am
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).
Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 12:39 am
by lidnariq
Are you trying to use different background banks in different parts of the screen?
Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 12:43 am
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

Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 8:46 am
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.

Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 8:54 am
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:
Re: MMC1 CHR bankswitching woes (On real hardware)
Posted: Mon Nov 17, 2014 11:49 pm
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.
Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Wed Nov 19, 2014 11:39 pm
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
Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Thu Nov 20, 2014 3:13 pm
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).
Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Thu Nov 20, 2014 10:16 pm
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.
Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Thu Nov 20, 2014 10:20 pm
by lidnariq
Also, base 0, not base 1 ... if you have eight banks, they're numbered 0 through 7.
Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Sun Nov 23, 2014 10:34 am
by Vectrex2809
Actually, it was the number of banks again. Thanks for the replies

Re: More MMC1 CHR bankswitching woes (On real hardware)
Posted: Sun Nov 23, 2014 10:41 am
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
PS : Tu viens du Canton de Vaud toi aussi?