development:csdk:2.0:codebanks
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| development:csdk:2.0:codebanks [2024/11/22 09:55] – created clyde | development:csdk:2.0:codebanks [2026/02/23 19:05] (current) – clyde | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| Functions and const variables have different markers in the form of Compiler Pragmas that should be wrapped around their definitions. See the [[https:// | Functions and const variables have different markers in the form of Compiler Pragmas that should be wrapped around their definitions. See the [[https:// | ||
| + | |||
| + | First, an example: | ||
| + | |||
| + | <code C> | ||
| + | #pragma rodata-name (push, " | ||
| + | |||
| + | const char longWindedDialogueText[] = " | ||
| + | |||
| + | #pragma rodata-name (pop) | ||
| + | |||
| + | #pragma code-name (push, " | ||
| + | |||
| + | void mySprawlingPlayerUpdateFunction() { | ||
| + | // absolutely massive switch block | ||
| + | // good lord so many if-statements | ||
| + | // did you really need to fully implement A-star | ||
| + | } | ||
| + | |||
| + | #pragma code-name (pop) | ||
| + | </ | ||
| + | |||
| + | Here we can see that '' | ||
| + | |||
| + | Now, if you simply call this function or access that data without any preparation you're gonna encounter unexpected behavior or crash. | ||
| + | |||
| + | To correctly access this data you'll need to use the [[development: | ||
| + | |||
| + | <code C> | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | //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(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== A warning ===== | ||
| + | |||
| + | You really don't want to call '' | ||
| + | |||
| + | <code C> | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | //" | ||
| + | //no pragmas around this, it should live in the default code bank | ||
| + | void mySprawlingPlayerUpdateFunction_wrapper() { | ||
| + | |||
| + | //Banking API provides a stack for storing the active bank | ||
| + | push_rom_bank(); | ||
| + | | ||
| + | change_rom_bank(BANK_PROG0); | ||
| + | | ||
| + | mySprawlingPlayerUpdateFunction(); | ||
| + | | ||
| + | //Pop the stack before returning from code that changes banks | ||
| + | pop_rom_bank(); | ||
| + | } | ||
| + | </ | ||
development/csdk/2.0/codebanks.1732269344.txt.gz · Last modified: 2024/11/22 09:55 by clyde
