program banks

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
johnnystarr
Posts: 22
Joined: Thu Dec 27, 2012 8:15 pm

program banks

Post by johnnystarr »

I am currently using NESASM, and I am restructuring the code from the Nerdy Nights tutorial to
use separate files. I have taken the code from the tutorial that very simply displays a 2 x 2 sprite that
moves when you use the controller.

I have read up on the NESASM readme file and I still don't grasp the .bank directive.

The problem I am faced with, is when or where to .include my source files.
I include my NMI routine right where the tutorial had it posted and it works fine.

I guess my question is a bit more oriented about program memory as well. Like, if i .org at $E000,
does my ROM reserve $E000 - $E0FF at that bank?

Can I just .include all my files at the beginning of my main file?


PS: I am planning on converting my code to ASM6 because it has some neat features. Are there any suggestions
or things I need to keep in mind?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: program banks

Post by 3gengames »

.bank is just selecting from an 8K bank. .org says "This is where this location in ROM starts" basically. Banks in NESASM are 8KB.so .ORG would reserve $E000-$FFFF, not 256 bytes.
User avatar
Movax12
Posts: 529
Joined: Sun Jan 02, 2011 11:50 am

Re: program banks

Post by Movax12 »

An .org directive tells the assembler what values to use when labels are replaced with absolute values.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: program banks

Post by thefox »

Movax12 wrote:An .org directive tells the assembler what values to use when labels are replaced with absolute values.
In some (most?) assemblers (but not CA65, because you shouldn't be using .org in it anyways), it also adds padding up to the new location.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: program banks

Post by tokumaru »

johnnystarr wrote:I have read up on the NESASM readme file and I still don't grasp the .bank directive.
From what I understand, NESASM requires the .bank directive to organize your ROMs into "blocks" of 8KB. AFAIK, it can't automatically rollover to the next bank in case you reach the end of the current one, so you really need a ton of .bank directives.
I guess my question is a bit more oriented about program memory as well. Like, if i .org at $E000,
does my ROM reserve $E000 - $E0FF at that bank?
.org doesn't reserve anything. It's purpose is to tell the assembler where in the address space of the target machine's memory the program is supposed to be loaded, so it can calculate the correct addresses for labels. The first .org in the program just sets the initial address, but any .org after that pads the ROM up until the specified location, to ensure that the code/data that follows it does indeed fall into the desired place.
Can I just .include all my files at the beginning of my main file?
That depends on what the included files contain. If it's just subroutines and interrupt/NMI handlers and you're not using bankswitching, yeah, they can go anywhere. Things get more complicated once bankswitching comes into play, because you may have to deal with reset stubs and tampoline code (which must be at specific locations of every bank) and keep track of which banks are mapped at any given time (e.g. if you put an interrupt handler in a bank that's not mapped in when an interrupt fires your game will most likely crash).
I am planning on converting my code to ASM6 because it has some neat features.
I'd say that's a good idea. If you need some reference, here are some templates I made a while back.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: program banks

Post by 3gengames »

It errors when code swaps over to another bank, not sure if it assembles. But INCBIN's roll over to every consecutive bank.
Post Reply