[SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

[SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 6:46 am

I am playing with a CNROM (03) configuration, the real console w/ Everdrive N8 and every other emulator i've tried bankswitches fine, even some obscure ones; except for FCEUX. I am using $8000, but have tried other addresses too with no luck. Are there known issues with this?

EDIT = Solved! Thank you!

TL;DR- Bus Conflicts. Make sure your ROM value matches your register write value when bankswitching as a precaution. For example, if you want to switch to CHR bank $03, if you store to $8003, make sure that ROM value is $03.
Last edited by Controllerhead on Tue Aug 18, 2020 1:09 pm, edited 21 times in total.
Image

User avatar
aa-dav
Posts: 102
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by aa-dav » Tue Aug 18, 2020 7:03 am

Do you pay attention to the fact this mapper has bus conflicts?

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 7:07 am

aa-dav wrote:
Tue Aug 18, 2020 7:03 am
Do you pay attention to the fact this mapper has bus conflicts?
No i didn't consider that honestly. It does work in Mesen and the real console, though, maybe Everdrive doesn't emulate bus conflicts? What should i consider?
Image

User avatar
dougeff
Posts: 2735
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by dougeff » Tue Aug 18, 2020 7:11 am

Put an array of constants at $8000

.byte 0,1,2,3

Put the CHR bank # in A and X

then write to $8000, x

STA $8000, x
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
aa-dav
Posts: 102
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by aa-dav » Tue Aug 18, 2020 7:33 am

Controllerhead wrote:
Tue Aug 18, 2020 7:07 am
...maybe Everdrive doesn't emulate bus conflicts?
I think you have proved it.

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 7:44 am

dougeff wrote:
Tue Aug 18, 2020 7:11 am
Good Advice
Ok, that works, Thanks Doug! You the man.

Though, honestly, i am not sure why... Is there somewhere i can read up on this? It also seems like i have to update the bank every frame, and even then, it keeps wanting to jump away to bank 0, presumably... EDIT: Nope. Coding error.
aa-dav wrote:
Tue Aug 18, 2020 7:33 am
Controllerhead wrote:
Tue Aug 18, 2020 7:07 am
...maybe Everdrive doesn't emulate bus conflicts?
I think you have proved it.
Doing Gods work over here :roll:

It has dawned on me that it will be important to flash EEPROM chips and test real boards, at some point, and not take Mesen and Everdrive, even on real hardware, as fact.
EDIT: You can emulate bus conflicts with an iNES 2.0 header: viewtopic.php?p=254858#p254858
Last edited by Controllerhead on Tue Aug 18, 2020 1:13 pm, edited 5 times in total.
Image

User avatar
aa-dav
Posts: 102
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by aa-dav » Tue Aug 18, 2020 8:03 am

Controllerhead wrote:
Tue Aug 18, 2020 7:44 am
Is there somewhere i can read up on this?
https://wiki.nesdev.com/w/index.php/Bus_conflict
In short: simple mappers didn't prevent ROM from being read and ROM do read even then you write to it (just didn't respect R/W line for simplicity, again). All of this causes 'mixing' of byte from ROM and value you write to mapper on the data bus. So you must provide that these bytes are the same and this will do the trick.

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 8:30 am

Gotcha. Register write value and ROM value should match as a good safety measure. If conflict, zero wins (usually). Thank you! ...I still don't understand why the CHR bank wants to jump away sometimes when i am not updating it though... EDIT: It doesn't. Coding error.

I will be sure to test real boards in the future ...just need a chip flasher and maybe a nice solder vacuum. I'll get those soon. I have plenty of boards =p
Last edited by Controllerhead on Tue Aug 18, 2020 1:06 pm, edited 1 time in total.
Image

Fiskbit
Posts: 153
Joined: Sat Nov 18, 2017 9:15 pm

Re: [SOLVED ...almost] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Fiskbit » Tue Aug 18, 2020 11:32 am

FYI, NES 2.0 submappers allow you to specify whether a CNROM game does or does not have bus conflicts. Since you're using iNES, it's unspecified and thus reasonable for emulators to default to the setting that results in the widest compatibility.

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: [SOLVED ...almost] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 11:48 am

Fiskbit wrote:
Tue Aug 18, 2020 11:32 am
FYI, NES 2.0 submappers allow you to specify whether a CNROM game does or does not have bus conflicts.
I just read that! I now have iNes 2.0 and bus conflicts enabled (i think), but, I can't seem to get Mesen to "glitch" the way that FCEUX does as far as the CHR bank switching; which makes me wonder if the bank switching strangeness in my code is a CNROM "thing" or a FCEUX "thing"... i wish i had a EEPROM flasher... soon... EDIT: It was a My Code "thing"

This is my header:

Code: Select all

; 4E 45 53 1A 02 04 31 0C 00 00 20 00 00 00 00 00
; * 0C in $07 should enable iNes 2.0, and 20 in $0A should enable bus conflicts 
; * ...is that right? 
; * EDIT: Nope. This is wrong. See next post.
Last edited by Controllerhead on Tue Aug 18, 2020 1:15 pm, edited 5 times in total.
Image

Fiskbit
Posts: 153
Joined: Sat Nov 18, 2017 9:15 pm

Re: [SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Fiskbit » Tue Aug 18, 2020 12:02 pm

The NES 2.0 identifier requires setting bits 3:2 of byte 7 to 10; you have them as 11. The submapper number is also in byte 8, not byte A. Fixing those, your glitchy ROM glitches as expected.

The CHR bank won't change unless you do writes to $8000-FFFF, so if it's changing unexpectedly, then you're either changing it somewhere in the code that you've forgotten about, or you have a bug that's resulting in writes to this region that you don't intend. If you set a write breakpoint on $8000-FFFF and exclude the current bankswap code with condition OpPC != $E36A, you'll see that you're occasionally writing #$02 to $8000 at $EAE2.

Somewhat unrelated, I strongly recommend setting the various developer options in Mesen under Options -> Emulation -> Advanced. You'll find, for example, that if you randomize RAM on power-on, your intro screen will have significant garbage on it because you're assuming everything is 0, which isn't accurate. You can also notice this by resetting.

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: [SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 12:25 pm

Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
The NES 2.0 identifier requires setting bits 3:2 of byte 7 to 10; you have them as 11 ... The submapper number is also in byte 8, not byte A. Fixing those, your glitchy ROM glitches as expected.
I figured my header was wrong, glad i posted it. Thanks.
Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
If you set a write breakpoint on $8000-FFFF and exclude the current bankswap code with condition OpPC != $E36A, you'll see that you're occasionally writing #$02 to $8000 at $EAE2.
Ah, right. I was trying to "solve" it by setting the CHR bank after a Sprite 0 "miss" thinking that was the culprit...
Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
The CHR bank won't change unless you do writes to $8000-FFFF, so if it's changing unexpectedly, then you're either changing it somewhere in the code that you've forgotten about, or you have a bug that's resulting in writes to this region that you don't intend.
Hmm... maybe ill set write breakpoints on all of ROM, and make sure i'm not erroneously updating the RAM value that holds the CHR bank... Weird that it works fine without bus conflicts? I'll investigate.
EDIT: Solved. I'm good now!
Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
you're assuming everything (in vRAM) is 0, which isn't accurate.
Yeah. Zeroing out vRAM on RESET is on the list of things to do ...I'm gonna take care of that now. Good call.
Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
developer options in Mesen under Options -> Emulation -> Advanced
I'm gonna play with those today. Thanks!

EDIT:
Fiskbit wrote:
Tue Aug 18, 2020 12:02 pm
The CHR bank won't change unless you do writes to $8000-FFFF, so if it's changing unexpectedly, then you're either changing it somewhere in the code that you've forgotten about
....Yeah that was it. I'm 100% good now. Thank you!
Last edited by Controllerhead on Tue Aug 18, 2020 12:49 pm, edited 2 times in total.
Image

Fiskbit
Posts: 153
Joined: Sat Nov 18, 2017 9:15 pm

Re: [SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Fiskbit » Tue Aug 18, 2020 12:35 pm

It works fine without bus conflicts because this code is writing #$02 (the correct bank) to $8000, which contains 0, so bus conflicts cause the mapper to see 0 instead of 2.

A couple things about header information. Mesen has logs under Tools -> Log Window that will show you the settings it is using when loading a game, based on the header and (if applicable) the NES 2.0 database, which can override the header because headers often contain incorrect information. There's also a header viewer/editor under Debug -> Edit iNES Header.

User avatar
Controllerhead
Posts: 148
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: [SOLVED] FCEUX - CNROM (03) Won't Bankswitch CHR

Post by Controllerhead » Tue Aug 18, 2020 12:57 pm

Fiskbit wrote:
Tue Aug 18, 2020 12:35 pm
It works fine without bus conflicts because this code is writing #$02 (the correct bank) to $8000, which contains 0, so bus conflicts cause the mapper to see 0 instead of 2.
Ooooohhhhhhhh :idea: Gotcha. I'm clear on that. Thanks for the explanation!
Fiskbit wrote:
Tue Aug 18, 2020 12:35 pm
A couple things about header information. Mesen has logs under Tools -> Log Window that will show you the settings it is using when loading a game, based on the header and (if applicable) the NES 2.0 database, which can override the header because headers often contain incorrect information. There's also a header viewer/editor under Debug -> Edit iNES Header.
Thanks for the tip!
...There are so many wonderful Mesen things i am not taking advantage of currently. That needs to change!
Image

Post Reply