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/gb/apa_image/src/main.c

      1 #include <gbdk/platform.h>
      2 #include <gb/drawing.h>
      3 #include <stdint.h>
      4 
      5 #include <res/scenery.h>
      6 
      7 
      8 #define CGB_BKG_PAL_0 0u
      9 #define CGB_ONE_PAL   1u
     10 const palette_color_t cgb_pal_black[] = {RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK};
     11 
     12 
     13 void main(void)
     14 {
     15     // Set the screen to black via the palettes to hide the image draw
     16     if (_cpu == CGB_TYPE) {
     17         set_bkg_palette(BKGF_CGB_PAL0, CGB_ONE_PAL, cgb_pal_black);
     18     } else {
     19         BGP_REG = DMG_PALETTE(DMG_BLACK, DMG_BLACK, DMG_BLACK, DMG_BLACK);
     20     }
     21 
     22     // Display the image
     23     // This will automatically switch to APA graphics mode
     24     // and install it's start and mid-frame ISRs.
     25     draw_image(scenery_tiles);
     26     SHOW_BKG;
     27 
     28     // Then load the palettes at the start of a new frame
     29     vsync();
     30     if (_cpu == CGB_TYPE) {
     31         set_bkg_palette(BKGF_CGB_PAL0, CGB_ONE_PAL, scenery_palettes);
     32     } else {
     33         BGP_REG = DMG_PALETTE(DMG_WHITE, DMG_LITE_GRAY, DMG_DARK_GRAY, DMG_BLACK);
     34     }
     35 
     36 
     37     // Loop forever
     38     while(1) {
     39         // Main processing goes here
     40         // Done processing, yield CPU and wait for start of next frame
     41         vsync();
     42     }
     43 }

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