banks.c (1714B)
1#include <gbdk/platform.h> 2#include <stdint.h> 3#include <stdio.h> 4 5// The header files below include provide bank references for the 6// banked const vars and functions in the other source files 7#include "srcfile_1.h" 8#include "srcfile_2.h" 9#include "srcfile_3.h" 10#include "srcfile_4_not-autobanked.h" 11 12 13// Non-banked const 14const uint8_t some_const_var_0 = 0; 15 16// Non-banked function 17void bank_fixed(void) NONBANKED 18{ 19 puts("I'm in fixed ROM"); 20} 21 22void main(void) 23{ 24 uint8_t _saved_bank; 25 26 #ifndef MSXDOS // TODO 27 set_default_palette(); 28 #endif 29 printf("Program Start...\n\n"); 30 31 // Call the functions, unbanked first then the banked ones 32 bank_fixed(); 33 34 func_1(); 35 func_2(); 36 func_3(); 37 func_4(); 38 39 printf("\n"); 40 41 42 // Print the const vars, unbanked first then the banked ones 43 printf("Const0= %u nonbanked\n", some_const_var_0); 44 45 SWITCH_ROM(BANK(some_const_var_1)); 46 printf("Const1= %u in bank %hu\n", some_const_var_1, BANK(some_const_var_1)); 47 SWITCH_ROM(BANK(some_const_var_2)); 48 printf("Const2= %u in bank %hu\n", some_const_var_2, BANK(some_const_var_2)); 49 SWITCH_ROM(BANK(some_const_var_3)); 50 printf("Const3= %u in bank %hu\n", some_const_var_3, BANK(some_const_var_3)); 51 52 // If you want to temporarily save and then restore the previous active bank: 53 // 54 55 // Save the currently active bank 56 _saved_bank = _current_bank; 57 58 // Switch to the desired one 59 SWITCH_ROM(BANK(some_const_var_4)); 60 printf("Const4= %u in bank %hu\n", some_const_var_4, BANK(some_const_var_4)); 61 62 // Then restore the previous bank 63 SWITCH_ROM(_saved_bank); 64 65 66 67 printf("\n"); 68 puts("The End..."); 69 70 // Loop forever 71 while(1) { 72 73 // Yield CPU till the end of each frame 74 wait_vbl_done(); 75 } 76}