Bank Switching

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
Memblers
Site Admin
Posts: 3819
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Mon Feb 27, 2006 12:07 am

If you do use 32kB banks, you'd have a copy of the code in the same place in every bank (including the reset vector). Or in RAM.

And SUROM I think uses one of the extra CHR page select bits for PRG.

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Mon Feb 27, 2006 3:36 pm

Oh, I suppose you're right about the small routine thing. Yeah, I agree that that'd be alot better.

But when you're working on a project such as the one I'm working on, you NEED bankswitching. I'm working on a HUGE RPG, and when you get sucked into a battle, you'll want to switch banks, of course. And there'll be banks with enemy data in them that you'll want to copy data to RAM from, so bankswitching is absolutely neccisary.

Okay, I'm sorry, but really didn't understand what you guys were talking about by a copy of the same code in each bank in the same place when using 32k PRG banks. When you switch 32k PRG banks, is it like, you switch from bank 0 and 1 to 2 and 3 or something? Or like 0 and 1 to 4 and 5, or something like that? And you said that with SUROM they use one of the extra CHR bits to switch banks. How can you just manipulate the registers to use the CHR bits to bank switch? That doesn't make any sense. Please explain, if you will :).

User avatar
Memblers
Site Admin
Posts: 3819
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Tue Feb 28, 2006 1:47 am

Celius wrote: Okay, I'm sorry, but really didn't understand what you guys were talking about by a copy of the same code in each bank in the same place when using 32k PRG banks. When you switch 32k PRG banks, is it like, you switch from bank 0 and 1 to 2 and 3 or something? Or like 0 and 1 to 4 and 5, or something like that?
You switch from any bank, to any bank. The point to having code at the same address is so you can just jump or JSR to it from any bank. What I did in that code on one program was keep track of the current bank, push it on the stack, set the new bank and JSR to the (banked) subroutine, then comes back, restores the old bank, and RTS's back to wherever.
And you said that with SUROM they use one of the extra CHR bits to switch banks. How can you just manipulate the registers to use the CHR bits to bank switch? That doesn't make any sense. Please explain, if you will :).
It's just a matter of wiring on the board. They hooked one of the pins from the mapper up to the PRG instead of CHR chip, bankswitching output bits are just latched bits (basically one bit of memory) that could be hooked up to whatever.

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Tue Feb 28, 2006 3:34 pm

Okay, so when using 32k banks, you can have 512k of PRG right? Because this is neccissary for my project. And it's just for bankswitching right? Like you still have 16k banks, but you switch 32k at a time? Or what?

And how would you code a game that runs with SUROM to use the 2 CHR bits to do bankswitching?

EDIT: Also, I don't know if JSRing to banks is that neccissary. I think that having a routine like this:

Code: Select all

.org $8000
  jmp +

  ldx #5
;This is a routine that was jumped to with the value #$02 in A
- sta $E000
  lsr a
  dex
  bne -

+
 ;whatever code you want here
I'd have that at the beggining of every bank, so I could jmp to it with a specific value in A so it would switch banks. But I should have a routine that takes saved High/Low adresses and jumps to them. That'd be helpful.

User avatar
Dwedit
Posts: 4301
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Tue Feb 28, 2006 6:25 pm

There was also a pirate MMC3 variant that uses the CHR bankswitcher to switch which 512k the MMC3 sees, so it can have up to 1024k PRG (with 8k chr ram). Fceu emulates it on standard mmc3, other emulators don't.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Bregalad
Posts: 7872
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Fri Mar 03, 2006 2:03 am

SUROM is needed for 512kb. No matter if you use 32kb or 16kb banks. If you use 32kb, the lowest bankswitching bit is "forced" to be zero, no matter how it actually is. So switch the 32kb bank 2 (or 3, no matter) in $8000-$ffff will switch the 16kb bank 2 in $8000-$bfff and 16kb bank 3 in $c000-$fffff. In my opinion, using 32kb bank is crazy in most cases, except if you're doing very tricky tricks, and I'll think to only use 16kb banks if I were you. I really ask how most Rare games does to use only 32kb bankswitching.

But, it's up to you to plan your own bankswitching strategies to get a larger rom. You don't have to think the most tricky it is, the best it is, because it isn't. If using SOROM, a particular bit in MMC1 reg 2 or reg 3 sets the MSB of bankswitching, so you'll need to upload 2 MMC1 regs when bankswitching. It isn't very complicated. Also, you won't need destroy a Dragon Warrior 3 or 4 card to get a real SUROM board fortunately. You can modify a simple Zelda cart to have a SUROM configuration.
Life is complex: it has both real and imaginary components.

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

Post by tepples » Fri Mar 03, 2006 1:41 pm

Bregalad wrote:In my opinion, using 32kb bank is crazy in most cases, except if you're doing very tricky tricks, and I'll think to only use 16kb banks if I were you. I really ask how most Rare games does to use only 32kb bankswitching.
GNROM, BNROM, and the Color Dreams board also have 32 KB PRG bankswitching. As long as you're not using DMC, it's easy to work around the bankswitching limitation using jump tables in RAM or jump tables duplicated through the last 1 KB of each PRG bank.

User avatar
Bregalad
Posts: 7872
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Fri Mar 03, 2006 1:56 pm

Yeah, it is do-able, but it still is much easier to work with one hardwired bank, I think. 32kb banks maybe allow you to place all data and code related together in the same bank.
For example, you'll have 32kb with all maps and all code that do something with the maps, 32kb with all music and you music replay code, 32kb with all text of the games and all programm that shows text, etc...
If you want more than 32kb, you'll have to be very tricky.
In a standard configuration, you'd rather have data in the bankswitched part and code in the hardwired place, OR have both code and data bankswitched.
Life is complex: it has both real and imaginary components.

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Fri Mar 03, 2006 3:20 pm

Thanks for replies. But I'm just wondering if 32k banks are neccissary for SUROM? Do you NEED 32k banks for SUROM? If not, how would you CODE MMC1 to use the CHR bits for bankswitching?

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

Post by tepples » Fri Mar 03, 2006 4:35 pm

No, you don't need to use 32 KB banks with the high bit mappers, but it'd be wise to have mapper init code in each "fixed" bank.

User avatar
Bregalad
Posts: 7872
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Sat Mar 04, 2006 10:51 am

Celius wrote:Thanks for replies. But I'm just wondering if 32k banks are neccissary for SUROM? Do you NEED 32k banks for SUROM? If not, how would you CODE MMC1 to use the CHR bits for bankswitching?
Read this again :
--------------------------------------------------------------------------------

SUROM is needed for 512kb. No matter if you use 32kb or 16kb banks. If you use 32kb, the lowest bankswitching bit is "forced" to be zero, no matter how it actually is. So switch the 32kb bank 2 (or 3, no matter) in $8000-$ffff will switch the 16kb bank 2 in $8000-$bfff and 16kb bank 3 in $c000-$fffff. In my opinion, using 32kb bank is crazy in most cases, except if you're doing very tricky tricks, and I'll think to only use 16kb banks if I were you. I really ask how most Rare games does to use only 32kb bankswitching.
If you don't understand ask about what you don't understand and don't just re-ask the whole question.
Any I don't see what you mean by coding the MMC1. You just have to make sure to understand that one bits of the MMC1 registers that normally apply to CHR selection bits is the upper bit of the PRG-ROM selection value, and if you want more deail read the wiki or hack Dragon Warrior 3.
Life is complex: it has both real and imaginary components.

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Sat Mar 04, 2006 5:52 pm

Oh! So because you're using CHR RAM, and have 0 CHR banks, if you write to the CHR switching bit, it'll swap PRG instead of CHR banks?

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

Post by tepples » Sat Mar 04, 2006 7:14 pm

No, it's because the SUROM board is wired differently, such that the CHR high address pins go to PRG instead of CHR.

CHR RAM games using the MMC1 can be reconstructed from iNES files as follows:
  • Mapper 1, no CHR ROM, PRG ROM 16-256 KB => SNROM
  • Mapper 1, no CHR ROM, PRG ROM 512 KB => SUROM

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Sat Mar 04, 2006 7:41 pm

Okay, I'm going to ask my question, hopefully for the last time, but way clearer.

How is one supposed to code a game that runs with SUROM, and have it run on an emulator? I know you can rewire it on an actual cartridge, but how do you make it run via an emulator? How do you tell the ROM to use the CHR bit for PRG bankswitching? You can't just magicly have the ROM use the CHR bit for switching PRG banks, you have to do something to the ROM to have it do that. What is that something?

User avatar
Quietust
Posts: 1551
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust » Sat Mar 04, 2006 7:45 pm

Celius wrote:How do you tell the ROM to use the CHR bit for PRG bankswitching?
You make the PRG ROM 512KB long. Seriously, this is how most (if not all) emulators support the NES-SUROM board when presented as iNES mapper 1.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

Post Reply