cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

banks.c (1120B)


      1/** Note that this example is a bit old.  Try BANKED and NONBANKED
      2    as in banked/
      3 */
      4#include <gb/gb.h>
      5#include <stdint.h>
      6#include <stdio.h>
      7
      8int var_internal;  /* In internal RAM */
      9extern int var_0;  /* In external RAM bank 0 */
     10extern int var_1;  /* In external RAM bank 1 */
     11extern int var_2;  /* In external RAM bank 2 */
     12extern int var_3;  /* In external RAM bank 3 */
     13
     14void bank_1() BANKED;
     15void bank_2() BANKED;
     16void bank_3() BANKED;
     17
     18void bank_fixed(void) NONBANKED
     19{
     20  puts("I'm in fixed ROM");
     21}
     22
     23void print_var(uint8_t bank)
     24{
     25  SWITCH_RAM(bank);
     26  printf("Var_%u is %u\n");
     27}
     28
     29void main(void)
     30{
     31  puts("Program Start...");
     32
     33  ENABLE_RAM;
     34
     35  var_internal = 1;
     36  SWITCH_RAM(0);
     37  var_0 = 2;
     38  SWITCH_RAM(1);
     39  var_1 = 3;
     40  SWITCH_RAM(2);
     41  var_2 = 4;
     42  SWITCH_RAM(3);
     43  var_3 = 5;
     44
     45  bank_fixed();
     46  bank_1();
     47  bank_2();
     48  bank_3();
     49
     50  printf("Var is %u\n", var_internal);
     51  SWITCH_RAM(0);
     52  printf("Var_0 is %u\n", var_0);
     53  SWITCH_RAM(1);
     54  printf("Var_1 is %u\n", var_1);
     55  SWITCH_RAM(2);
     56  printf("Var_2 is %u\n", var_2);
     57  SWITCH_RAM(3);
     58  printf("Var_3 is %u\n", var_3);
     59
     60  puts("The End...");
     61}