Chr-Ram bankswitching

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

Post Reply
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Chr-Ram bankswitching

Post by JoeGtake2 » Wed Jun 07, 2017 7:01 am

Hey all! Project is winding down. Starting to add some unplanned *flair*. Figured I'd try my hand at injecting some animated background tiles, since I'm using UnRom512 and the mapper supports chr ram bankswitching.

But I'm running against a void in my conceptual understanding, I guess. The game uses CHR-Ram - I have a few banks full of background graphic data that routines load in chunks whenever and wherever needed. No problem.

My conceptual understanding is that I can set up multiple banks (when I load that graphic data, load it's *animated* frame to a different bank location), and then with an easy write to two bits in 8000, I can determine which bank is being pointed to to populate the pattern tables. I have that right? I mean - I get bankswitching fine...obviously, I bankswitch PRG data all over the place.

But I suppose I'm confused how/where to set up these banks in memory. I tried to sort of follow how PRG banks are established, but nothing I tried seemed to work right (most attempts led to gray screen).

Anyone want to give me an easy breakdown of how to set this up so I can test it out? Ultimately, I'm not sure the game needs it, but...might be nice, and now I want to understand it!

Thanks!

tepples
Posts: 21750
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Chr-Ram bankswitching

Post by tepples » Wed Jun 07, 2017 7:15 am

Switch to CHR bank 0
Load pattern table
Switch to CHR bank 1
Load pattern table
Switch to CHR bank 2
Load pattern table
Switch to CHR bank 3
Load pattern table
Load nametable
Load palette
Turn on display
Switch to CHR bank 0
Wait a few frames
Switch to CHR bank 1
Wait a few frames
Switch to CHR bank 2
Wait a few frames
Switch to CHR bank 3
Wait a few frames

Does this still give a gray screen?

If so, you might have forgotten that a write to the mapper port switches both the PRG bank (bits 4-0) and the CHR bank (bits 6-5). Try doing this from the fixed bank ($C000-$FFFF). And if that doesn't work, try making a minimal, complete, and verifiable example (MCVE), source code that builds yet is short enough for us to look at.

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Wed Jun 07, 2017 7:40 am

Yeah, I figure it's that simple. I'm a step before that, though. Where in memory are the CHR banks to set up in the first place? I guess that was the crux of my question.

Thanks, friend!

tepples
Posts: 21750
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Chr-Ram bankswitching

Post by tepples » Wed Jun 07, 2017 7:44 am

To write to CHR RAM bank 0, switch to CHR RAM bank 0 with a mapper write and then write to video memory $0000-$1FFF.
To write to CHR RAM bank 1, switch to CHR RAM bank 1 with a mapper write and then write to video memory $0000-$1FFF.
To write to CHR RAM bank 2, switch to CHR RAM bank 2 with a mapper write and then write to video memory $0000-$1FFF.
To write to CHR RAM bank 3, switch to CHR RAM bank 3 with a mapper write and then write to video memory $0000-$1FFF.

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Wed Jun 07, 2017 7:47 am

Ok cool...that's what I thought. I figured it was that easy.

I wonder if it's my emulator not emulating this. Hm.

tepples
Posts: 21750
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Chr-Ram bankswitching

Post by tepples » Wed Jun 07, 2017 7:53 am

Does your emulator correctly emulate Videomation? Or an Action 53 build including Sinking Feeling?

I have made CHR RAM bankswitching test ROMs for MMC3 and Action 53, but not UNROM 512.

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Wed Jun 07, 2017 8:50 am

Can't check right now, but essentially - what I'm trying is simply updating my bankswitch routine, or-ing in writes to bits 5 and 6 and storing them into the currentBank variable prior to the switch. It seems straight forward enough. But any time I make the bits anything other than 0, game freezes.

Without this ORA, the bankswitching routine works fine for PRG bankswitching.

tepples
Posts: 21750
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Chr-Ram bankswitching

Post by tepples » Wed Jun 07, 2017 8:54 am

If you're using a board that's not self-flashable, you need to avoid bus conflicts when changing the CHR bank. This makes your identity table for bus conflict avoidance four times as large, expanding it from 32 bytes to 128 bytes.

User avatar
Broke Studio
Formerly glutock
Posts: 164
Joined: Sat Aug 15, 2015 3:42 pm
Location: France
Contact:

Re: Chr-Ram bankswitching

Post by Broke Studio » Thu Jun 08, 2017 6:39 am

tepples wrote:Does your emulator correctly emulate Videomation? Or an Action 53 build including Sinking Feeling?

I have made CHR RAM bankswitching test ROMs for MMC3 and Action 53, but not UNROM 512.

Funny, I just made an UNROM 512 / mapper 30 test ROM today !
Hope it helps anyone ...

edit : it uses 1-screen arrangement though
mapper30-testROM-20170608.nes
UNROM 512 / mapper 30 test ROM
(512.02 KiB) Downloaded 113 times
My first game : Twin Dragons available at Broke Studio.

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Thu Jun 08, 2017 10:50 am

Drat. Curses. I was hoping it was the emulator, however, that test file seems to work fine (cycles through chr banks just dandy).

Huh.

Glutock - what does your bankswitch routine look like?

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Thu Jun 08, 2017 11:40 am

Disregard the whole thread. The problem was super simple. I didn't have the battery flag checked in the header, which ended up causing bus conflicts (Tepples, you mentioned this, and I didn't even think of it as a header issue! Good call)

Works fine now, and as expected.

Erockbrox
Posts: 312
Joined: Sun Nov 23, 2014 12:16 pm

Re: Chr-Ram bankswitching

Post by Erockbrox » Thu Jun 08, 2017 7:38 pm

Need NES game maker tools now....

NES homebrews for the rest of us non-programmers.

JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Chr-Ram bankswitching

Post by JoeGtake2 » Sat Jun 10, 2017 6:35 am

Improving on them every day :-) And the intent for them is absolutely to give new devs some confidence to eventually start getting deeper into the code and going crazy with it :-)

Post Reply