User Tools

Site Tools


development:csdk:2.0:codebanks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
development:csdk:2.0:codebanks [2024/11/22 10:10] clydedevelopment:csdk:2.0:codebanks [2026/02/23 19:05] (current) clyde
Line 35: Line 35:
 #include "gen/bank_nums.h" //Generated macros for named bank numbers #include "gen/bank_nums.h" //Generated macros for named bank numbers
  
 +//main is assumed to be in the boot bank
 +void main() {
 +    //If you only ever use one alternate code bank, you can just call change_rom_bank once.
 +    //SDK functions (should) all restore the active bank if they change banks internally
 +    change_rom_bank(BANK_PROG0);
 +    
 +    while(1) {
 +        mySprawlingPlayerUpdateFunction();
 +        
 +        //then the usual...
 +        await_vsync(1);
 +        flip_pages();
 +    }
 +}
 +</code>
 +
 +===== A warning =====
 +
 +You really don't want to call ''change_rom_bank'' or ''pop_rom_bank'' directly from code that lives in an alternate bank, since it'll disappear from under you as soon as either of those functions return. You can set up wrapper functions, also know as "trampolines" that live in the default code bank. Or just structure your code so that all your bank changes are called from the default code bank without explicitly setting up wrappers.
 +
 +<code C>
 +#include "gt/banking.h" //Banking API
 +#include "gen/bank_nums.h" //Generated macros for named bank numbers
 +
 +//"trampoline" function example
 //no pragmas around this, it should live in the default code bank //no pragmas around this, it should live in the default code bank
 void mySprawlingPlayerUpdateFunction_wrapper() { void mySprawlingPlayerUpdateFunction_wrapper() {
  
 +    //Banking API provides a stack for storing the active bank
     push_rom_bank();     push_rom_bank();
          
Line 44: Line 70:
     mySprawlingPlayerUpdateFunction();     mySprawlingPlayerUpdateFunction();
          
 +    //Pop the stack before returning from code that changes banks
     pop_rom_bank();     pop_rom_bank();
 } }
 </code> </code>
development/csdk/2.0/codebanks.1732270233.txt.gz · Last modified: 2024/11/22 10:10 by clyde