git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/examples/cross-platform/incbin/src/main.c

      1 #include <gbdk/platform.h>
      2 #include <stdint.h>
      3 
      4 #include <gbdk/incbin.h>
      5 
      6 INCBIN(logo_tiles_data, "res/gbdk2020.bin") // Variable name to use, Path to file
      7 INCBIN_EXTERN(logo_tiles_data)              // Extern declarations for binary data
      8 
      9 INCBIN(logo_map, "res/gbdk2020_map.bin")
     10 INCBIN_EXTERN(logo_map)
     11 
     12 INCBIN(blank_tile_data, "res/blanktile.bin")
     13 INCBIN_EXTERN(blank_tile_data)
     14 
     15 
     16 #define TILE_BYTES 16 // 16 bytes per background tile
     17 
     18 
     19 // Since incbin just includes a binary file (the logo tiles)
     20 // a map needs to be created for them. For this example
     21 // the tiles are non-deduplciated, so a array of incrementing
     22 // values can be used. There are 84 tiles.
     23 #define LOGO_MAP_WIDTH  7u
     24 #define LOGO_MAP_HEIGHT 12u
     25 #define LOGO_MAP_X      (20u - LOGO_MAP_WIDTH) / 2u  // Center on X axis
     26 #define LOGO_MAP_Y      (18u - LOGO_MAP_HEIGHT) / 2u // Center on Y axis
     27 
     28 void init_gfx(void) {
     29     // Load a single clear background tile at location 0x80 and clear/fill the map with it
     30     set_bkg_data(0x80u, 1u, blank_tile_data); // The first 0x80u here is the tile ID
     31     fill_bkg_rect(0u, 0u, DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT, 0x80u);   // The last 0x80u here is the tile ID 
     32 
     33     // Load logo background tiles and map
     34     // They start at 0u
     35     set_bkg_data(0u, INCBIN_SIZE(logo_tiles_data) / TILE_BYTES, logo_tiles_data);
     36     set_bkg_tiles(LOGO_MAP_X, LOGO_MAP_Y,
     37                   LOGO_MAP_WIDTH, LOGO_MAP_HEIGHT,
     38                   logo_map);
     39 
     40     // Turn the background map on to make it visible
     41     SHOW_BKG;
     42 }
     43 
     44 
     45 
     46 void main(void)
     47 {
     48     init_gfx();
     49 
     50     // Loop forever
     51     while(1) {
     52 
     53         // Game main loop processing goes here
     54 
     55         // Done processing, yield CPU and wait for start of next frame
     56         vsync();
     57     }
     58 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.