[4.5.x] Move doLoadScreen to Bank 16

JamesNES

Well-known member
After sharing it with CluckFox and Bucket Mouse in the Discord, we figured out that moving a big chunk of doLoadScreen.asm into Bank 16 is possible and saves a ton of space in the static bank (like 15%).

First you need to cut out the middle section of doLoadScreen.asm. By default it's line 50:

Code:
LoadBackgroundPalettes newPal
    JSR doWaitFrame
        ;; We wait this frame because the LoadBackgroundPalettes routine
        ;; sets bckpal variables and activates the update palette.
        ;; waiting this frame holds up on the next routine until the
        ;; background palettes are loaded into the PPU.
    ;LoadObjectPalettes #$00
 
    LoadObjectSubPalettes spriteSubPal1, #$00
    LoadObjectSubPalettes spriteSubPal2, #$04
    LoadObjectSubPalettes spriteSubPal3, #$08
    LoadObjectSubPalettes spriteSubPal4, #$0C

...

to just past line 414:

Code:
...
        LoadChrData temp, #$08, #$00, #$80, MonsterAddressLo, MonsterAddressHi, monsterTableOffset
        ;arg0 - bank where graphics live
        ;arg1 - row
        ;arg2 - column (by 10s...must end in zero)
        ;arg3 - how many tiles to load.  If 00, will load whole sheet.
        ;arg4 - Label in bank 16 table, low.
        ;arg5 - Label in bank 16 table, hi.
        ;arg6 - Bank 16 table offset
            JSR doWaitFrame

Paste this into a new file, adding

Code:
doLoadScreen16:

to the top of the file, and putting an RTS at the bottom. Save it in your project directory as doLoadScreen16.asm.

Back in doLoadScreen.asm, add this at line 39, where you removed all the code:

Code:
    SwitchBank #$16
    JSR doLoadScreen16
    ReturnBank

Next you need to include the new file in Bank 16.

In NES Maker, go to Project Settings -> Script Settings -> Add, then fill it out like this:

Name: Load Screen Bank 16
Define: SCR_LOADSCREEN16

Then hit okay. On the right, navigate to where you saved the doLoadScreen16.asm and double click it.

Next open bank 16, which is toward the top in the script list.

You want to add

Code:
.include SCR_LOADSCREEN16

in here. I add it with the other includes at line 494 so they're together, but I don't think it matters.

That should be it. The only issue we've found is if your screenbytes are loaded in Post Screen Load, you need to move them into Extra Screen Load, ie somewhere before the switch to bank 16.

Edit: an addendum from latatera, if your line counts don't match this might help find the right place to put it:

Back in doLoadScreen.asm, add this at line 39, where you removed all the code:
Code:
SwitchBank #$16
JSR doLoadScreen16
ReturnBank


Because line 39 wasn't the place on my file, and maybe some other people have the same issue.

Back in doLoadScreen.asm, add this after the line: .include SCR_EXTRA_SCREEN_LOAD

Edit: Baardbi has now made a great video walkthrough of this writeup:

 
Last edited:

Jonny

Well-known member
Thank you for sharing here. I miss a lot on Discord because I hardly go on there.
I really want to learn more about banks, is there some sort of breakdown of what is stored in each bank or is all that information available in NesMaker?
For example, I don't even know what the static bank is or what would be in it usually. :confused:
 

TakuikaNinja

Active member
What I do know is that the static bank includes important routines like the initialisation, main game loop, and NMI routines. DPCM samples also have to go in there if you're using them.
 

crazygrouptrio

Active member
Thank you for sharing here. I miss a lot on Discord because I hardly go on there.
I really want to learn more about banks, is there some sort of breakdown of what is stored in each bank or is all that information available in NesMaker?
For example, I don't even know what the static bank is or what would be in it usually. :confused:
First step, download the NES Space Checker by Shiru (shouldn't be hard to find via google) and load up your rom. This will show you all of your banks in your game and how much space is used and available in each of them.

In script settings (in 4.5.X) you can just look specifically at a bank to get an idea of what is handled where (Screendata, Sound, Physics, etc).

The Static bank is bank #$1F, the last one in the Space Checker. This is essentially the OS of your game. Basically this is the bank where data that must be accessed quickly or always on hand is stored, which unfortunately is a decent amount of stuff, as was mentioned above stuff like Initialization, NMI and DPCM samples which handle a lot of stuff that needs to be on hand. This is the bank people generally have issues with.

Another thing I've found is what your code is and how it's accessed can define whether or not the code can exist in another bank. For example, a toooon of stuff can be slapped into a monster action and stored in an empty bank (Bank #$1A is my go-to) and it will work in a lot of cases, whereas switching to the same code in an end action won't work. This is also true for Inputs that aren't tied to character actions/animations (like a warp button will work in another bank).

Storing data throughout your banks is pretty essential especially when you get near the end of your game and you find yourself running out of space.
Idk why I went into so much detail but there you go.
 
Last edited:

Jonny

Well-known member
Super helpful. I needed that detail even if just as a sanity check. You've made it sound actually achievable to move data around and actually understand what's going on. It doesn't feel like such a dark-art anymore when put in easy to understand terms to simply look in the banks and see whats going on in each.
I'll start with James' tutorial here and see what I can learn there. Cheers.
 

drexegar

Member
That makes a huge difference in the #1f bank, enough space to squeeze in some samples, its also doubles as a simple bankswitch tutorial for newbies as well!
 

Logana

Well-known member
@JamesNES Idk what happened, but I keep getting this error, where I put the code

SwitchBank #$16
JSR doLoadScreen16
ReturnBank

1620485745679.png
 

JamesNES

Well-known member
All I can think of is, did you put the doLoadScreen16 label at the top of DoLoadScreen16.asm?

If that's all good, you can upload your two asms and I can check them out for you.
 

Logana

Well-known member
I think the main issue I’m having is you didn’t explain what this “Save it in your project directory as doLoadScreen16.asm.” Ment because I have both files and they are good but I have no idea what this means or what I’m supposed to do with this
 

JamesNES

Well-known member
Ah that just meant save it anywhere handy, usually in like NES Maker\GameEngineData\Routines\BASE_4_5\Game. Anywhere you can easily assign it in script settings.
 

Logana

Well-known member
Idk whats wrong, also i have noo idea where i put the first peice of code, like you have a specific point to put the second code, but you never mention what to do with the first code other than saving it
 

Attachments

  • what am i doing wrong.zip
    2.2 KB · Views: 19

JamesNES

Well-known member
Your doLoadScreen is missing the bankswitch, which would be at line 50 on yours, but apart from that those files are both good, I added it and put both into a blank project and it works fine.

If it's more problems with setting up includes/file placement stuff maybe hitting me up on Discord next time you're on there, it'll be easier to explain that way. @JimboJames on Discord
 

Logana

Well-known member
Thx will check that out ASAP,
EDIT: it worked perfectly this time, but now im confused, I never actually had to assignt the script that had that part of the of the code where i added the bank switch which makes me confused on how it acceses that code
 
Last edited:

JamesNES

Well-known member
doLoadScreen is included automatically by LoadAllSubroutines.asm, though if you'd changed the name of it you'd have needed to change the name in that file too.
 

vanderblade

Active member
This worked fine in my run and gun game using the Metroidvania MOD, but I'm getting these errors in my brawler. I don't know why the label would already be defined in either. Any thoughts?

Screenshot (20).png
 

JamesNES

Well-known member
This worked fine in my run and gun game using the Metroidvania MOD, but I'm getting these errors in my brawler. I don't know why the label would already be defined in either. Any thoughts?

View attachment 5077

That's weird, as all the modules use the same doLoadScreen routine. If you attach those two asm files and the new one for bank 16 I could check it out for you
 

Jonny

Well-known member
It's not just a silly error like pasting script twice or anything? I've done that before.

I'm also using metroidvaina base and did not get these errors. Athough obviously, you could have different scripts to me.
 
Top Bottom