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/gbtype/gbtype.c

      1 #include <gbdk/platform.h>
      2 #include <gb/sgb.h>
      3 #include <stdio.h>
      4 
      5 // In the Makefile the "-Wm-ys" flag is added to LCC when compiling
      6 // to enable optional Super Game Boy support in the ROM Cartridge header
      7 
      8 void main(void)
      9 {
     10     // Wait 4 frames
     11     // For PAL SNES(SGB) this delay is required on startup
     12     for (uint8_t i = 4; i != 0; i--)
     13         vsync();
     14 
     15     DISPLAY_ON;
     16 
     17     // sgb_check() is slow, so it's better to call it once and save the result to test with
     18     uint8_t is_SGB = sgb_check();
     19 
     20     if (is_SGB) {
     21         // Super Game Boys
     22         if      (_cpu == DMG_TYPE) printf("This is a SGB 1!");
     23         else if (_cpu == MGB_TYPE) printf("This is a SGB 2!");
     24     }
     25     else if (_cpu == DMG_TYPE) printf("This is a DMG! (OG Game Boy)");
     26     else if (_cpu == MGB_TYPE) printf("This is a MGB! (Game Boy Pocket / Light)");
     27     else if (_cpu == CGB_TYPE) {
     28         // For Game Boy Color also check if it is a GBA in CGB mode
     29         if (_is_GBA == GBA_DETECTED) printf("This is a GBA in CGB mode!");
     30         else         printf("This is a CGB! (Game Boy Color)");
     31     }
     32 
     33     while(1)
     34     {
     35         vsync();
     36     }
     37 }
     38 

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