Jump to content
IGNORED

How to do Efficient Bankswitching ?


dbks

Recommended Posts

Quick intro: I am new here and this is my first post. Awesome site. So a few days ago I started a quick 2600 project in bB. From googling I was eventually led here and I've enjoyed reading all these topics.

 

I am a decently experienced programmer who has used a variety of languages and bB was easy to jump into. However, I am still murky about bankswitching. Basically, how does one utilize it efficiently? I understand the mechanics behind it so I realize that it's best to be organized and efficient, but how?

 

Should I view the situation as each bank should be self contained, ie process only one 'mini' game where these 'mini' games are tied together to form the complete game? For example, let's say someone wanted to make a simple, retro rpg. Would world navigation subroutines be on one bank and inventory screen on another and, let's say, entering buildings and navigating the building on another, etc?

 

That seems logical and it would cut down on the bankswitching. But what if each time thru the game loop, you averaged n bankswitches. For what n is too high?

 

Do you ever intentionally duplicate subroutines on different banks just so you could avoid bankswitching?

 

I am trying to plan things well to avoid bankswitching, but sometimes it is unavoidable it seems. I realize that I will have to test these things as I progress, but some words of advice will greatly aid my learning curve, if someone cares to enlighten me.

 

Thanks.

  • Like 1
Link to comment
Share on other sites

Don't know about efficient, but if you are working on a fairly large game, the code for your main loop won't fit in one bank. For example, I had everything in one bank at the beginning, then I had to move all of my sound effects into another bank. After that, I had to start putting chunks of code from my main loop into a third bank. Now I'm using 3 banks for my code, one bank for the title screen, and the last bank is left empty for bB to use. That's 5 banks and I'll probably have to include other banks as my game gets larger.

  • Like 2
Link to comment
Share on other sites

Welcome!

 

First, there's no hard and fast rule how to organize things. You'll probably start out one way, and then later you'll reorganize, and then reorganize again. That's natural, and a consequence of each game being different.

 

If your game has a bunch of very different levels, then sticking each level's code in a bank of it's own is a good way to start.

 

Not all games are like that. RT's advice is a good default way to go. I keep a similar structure: one bank for the kernel, one for the titlescreen, one that contains the main game loop, and one or more for routines the other banks can call.

 

Yes, you should keep the bankswitches to a minimum. This can be accomplished by rolling a bunch of related routines together - instead of calling 3 different routines, call one and let it do the deciding in the other bank. This also helps with rom space, because bankswitching gosubs use a lot more rom than a regular gosub.

 

Duplicate subroutines in each bank is a common enough strategy, though you should try to avoid it if you can, due to the wasted space.

 

[edit - last thought. You can check if you're using too many cycles in Stella with Alt+L. If the scanline count moves over 262, you've used too many.]

Edited by RevEng
  • Like 3
Link to comment
Share on other sites

Thank you all for the good advice and welcome.

 

I already knew about the alt+L thing (as well as the other methods) mentioned on the bB info page, but it's good to keep this in mind as I progress on this project.

 

So thank you all very much. I think I have some good direction now and hope to show it off soon.

 

Best wishes.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...