Trying to understand 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

Post Reply
User avatar
Kitty_Space_Program
Posts: 27
Joined: Mon Sep 21, 2020 7:42 am

Trying to understand bank switching

Post by Kitty_Space_Program » Wed Oct 14, 2020 8:04 pm

So when you want to do bank switching with the 002 mapper, how would you switch out the bank your using? Like if my first bank was reset and main menu, then I had a bank for the game and a bank for loading levels and level data, how would I got from one to the other?

lidnariq
Posts: 9774
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Trying to understand bank switching

Post by lidnariq » Wed Oct 14, 2020 8:07 pm

To get access to bank N in $8000-$BFFF, one writes N to a location in ROM that also contains N.

This is often something like

Code: Select all

Identity: .byte 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

Bankswtich: tax
 sta Identity,X
 rts

User avatar
tokumaru
Posts: 11891
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Trying to understand bank switching

Post by tokumaru » Wed Oct 14, 2020 8:46 pm

Be careful with where you place the identity table and the bankswitch code: they must be somewhere that will not change when the bankswitch happens, otherwise the program will crash. With mapper 2, this usually means putting them anywhere in the fixed bank (which gets mapped to $C000-$FFFF). On mappers without a fixed bank, you normally have to simulate one by replicating a piece of code and data at the same position in every bank.

unregistered
Posts: 1098
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Trying to understand bank switching

Post by unregistered » Thu Oct 15, 2020 1:02 pm

nesdev’s wiki Mapper 002 page:
http://wiki.nesdev.com/w/index.php/UxROM

nesdev’s wiki Mapper 002 bank change page:
http://wiki.nesdev.com/w/index.php/Programming_UNROM

:)

User avatar
Kitty_Space_Program
Posts: 27
Joined: Mon Sep 21, 2020 7:42 am

Re: Trying to understand bank switching

Post by Kitty_Space_Program » Mon Oct 19, 2020 6:43 am

lidnariq wrote:
Wed Oct 14, 2020 8:07 pm
To get access to bank N in $8000-$BFFF, one writes N to a location in ROM that also contains N.
When you do that, I heard it will go to the same address that your currently in. How do you control that? Do you have to use .org (in nesasm)

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

Re: Trying to understand bank switching

Post by Quietust » Mon Oct 19, 2020 6:56 am

Kitty_Space_Program wrote:
Mon Oct 19, 2020 6:43 am
lidnariq wrote:
Wed Oct 14, 2020 8:07 pm
To get access to bank N in $8000-$BFFF, one writes N to a location in ROM that also contains N.
When you do that, I heard it will go to the same address that your currently in. How do you control that? Do you have to use .org (in nesasm)
Tokumaru already answered your question:
tokumaru wrote:
Wed Oct 14, 2020 8:46 pm
Be careful with where you place the identity table and the bankswitch code: they must be somewhere that will not change when the bankswitch happens, otherwise the program will crash. With mapper 2, this usually means putting them anywhere in the fixed bank (which gets mapped to $C000-$FFFF). On mappers without a fixed bank, you normally have to simulate one by replicating a piece of code and data at the same position in every bank.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

Post Reply