Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.


#1 2022-03-30 13:28:48

Registered: 2022-03-30
Posts: 12

Is bank switching expensive?

Basically I want to divide my world into different banks since they wont fit. in one.

But i fear what happens at a cross point where 4 sections are visible at once.
During the tile loading does bank switching multiple times a frame cause a problem ?

Or is this exactly how you would be expected to do it ?



#2 2022-03-31 10:33:01

Registered: 2008-02-22
Posts: 244

Re: Is bank switching expensive?

Well, it is as expensive as the overhead of the CPU instructions used to switch between the banks.

It could be as simple as...


    ld A,5
    ld [$2000],A

But in practice you also need to...
- Potentially keep track of which bank was previously selected, if you need to be able to return to that bank later. This is applicable if you have code in a selectable bank that can call other code in bank 0 to load data from another bank.
- Calculate which bank you want to read from.
- Calculate which other bank you want to read from. (For example if one bank contains metatile data, and the other bank contains the corresponding tile data.)

In general, you would need to actually benchmark/calculate the worst case runtime for your code, for example using breakpoints in BGB. It' may also be a good idea to plan ahead and make it possible to load data over multiple frames, ahead of scrolling in a certain direction.

For loading bulk data (ie loading a new level/screen) it's generally recommended to disable the LCD, which gives you uninterrupted access to VRAM. The screen will go blank during this time, but this generally isn't a problem during a screen transition.

Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb



#3 2022-04-09 15:06:49

Registered: 2022-03-30
Posts: 12

Re: Is bank switching expensive?

Ty i've been using it now in code to see how it goes.



Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson