git.y1.nz

gbdk-2020

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

commit 5e2daa6bf113141c4dd5d0f2437953e3925699c7
parent 414519ef5ac2eea7d281777e9348b3a2ccd95345
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Sat,  1 Jul 2023 01:22:34 -0700

Merge pull request #532 from bbbbbr/example_gbcheck

Example: gbcheck updates
Diffstat:
Dgbdk-lib/examples/gb/gbcheck/Makefile12------------
Dgbdk-lib/examples/gb/gbcheck/gbcheck.c24------------------------
Agbdk-lib/examples/gb/gbtype/Makefile37+++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/gb/gbtype/gbtype.c38++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/examples/gb/template_minimal/Makefile5+++--
Mgbdk-lib/examples/gb/template_subfolders/Makefile4+++-
6 files changed, 81 insertions(+), 39 deletions(-)

diff --git a/gbdk-lib/examples/gb/gbcheck/Makefile b/gbdk-lib/examples/gb/gbcheck/Makefile @@ -1,12 +0,0 @@ -CC = ../../../bin/lcc - -all: - $(CC) -Wm-ys -o gbcheck.gb gbcheck.c - -compile.bat: Makefile - @echo "REM Automatically generated from Makefile" > compile.bat - @make -sn | sed y/\\//\\\\/ | sed s/mkdir\ \-p/mkdir/ | grep -v make >> compile.bat - -clean: - rm -f *.o *.lst *.map *.gb *.ihx *.sym *.cdb *.adb *.asm - diff --git a/gbdk-lib/examples/gb/gbcheck/gbcheck.c b/gbdk-lib/examples/gb/gbcheck/gbcheck.c @@ -1,23 +0,0 @@ -#include <gbdk/platform.h> -#include <stdio.h> -void main(void) -{ - // Wait 4 frames - // For PAL SNES(SGB) this delay is required on startup - for (uint8_t i = 4; i != 0; i--) - vsync(); - uint8_t issgb = sgb_check();//sgb_check() is slow, so it's better to call it once and save the result to test with - if ((_cpu == DMG_TYPE) && (!issgb))printf("This is a DMG! (OG Game Boy)"); - else if ((_cpu == MGB_TYPE) && (!issgb))printf("This is a MGB! (Game Boy Pocket / Light)"); - //Super Game Boys below - else if ((_cpu == DMG_TYPE) && (issgb))printf("This is a SGB1!"); - else if ((_cpu == MGB_TYPE) && (issgb))printf("This is a SGB2!"); - //Game Boy Color - else if ((_cpu == CGB_TYPE) && (!_is_GBA))printf("This is a CGB! (Game Boy Color)"); - //The GBA acts like a Game Boy Color. Adding !_is_GBA will make sure this only shows on a GBC - else if(_is_GBA)printf("This is a GBA in CGB mode!"); - while(1) - { - vsync(); - } -} - diff --git a/gbdk-lib/examples/gb/gbtype/Makefile b/gbdk-lib/examples/gb/gbtype/Makefile @@ -0,0 +1,37 @@ +# +# Simple Makefile that compiles all .c and .s files in the same folder +# + +# If you move this project you can change the directory +# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" +GBDK_HOME = ../../../ + +LCC = $(GBDK_HOME)bin/lcc + +# Flag to enable optional Super Game Boy support in the ROM Cartridge header +LCCFLAGS = -Wm-ys + +# You can uncomment the line below to turn on debug output +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output + +# You can set the name of the .gb ROM file here +PROJECTNAME = gbtype + +BINS = $(PROJECTNAME).gb +CSOURCES := $(wildcard *.c) +ASMSOURCES := $(wildcard *.s) + +all: $(BINS) + +compile.bat: Makefile + @echo "REM Automatically generated from Makefile" > compile.bat + @make -sn | sed y/\\//\\\\/ | sed s/mkdir\ \-p/mkdir/ | grep -v make >> compile.bat + +# Compile and link all source files in a single call to LCC +$(BINS): $(CSOURCES) $(ASMSOURCES) + $(LCC) $(LCCFLAGS) -o $@ $(CSOURCES) $(ASMSOURCES) + +clean: + rm -f *.o *.lst *.map *.gb *.ihx *.sym *.cdb *.adb *.asm + diff --git a/gbdk-lib/examples/gb/gbtype/gbtype.c b/gbdk-lib/examples/gb/gbtype/gbtype.c @@ -0,0 +1,38 @@ +#include <gbdk/platform.h> +#include <gb/sgb.h> +#include <stdio.h> + +// In the Makefile the "-Wm-ys" flag is added to LCC when compiling +// to enable optional Super Game Boy support in the ROM Cartridge header + +void main(void) +{ + // Wait 4 frames + // For PAL SNES(SGB) this delay is required on startup + for (uint8_t i = 4; i != 0; i--) + vsync(); + + DISPLAY_ON; + + // sgb_check() is slow, so it's better to call it once and save the result to test with + uint8_t is_SGB = sgb_check(); + + if (is_SGB) { + // Super Game Boys + if (_cpu == DMG_TYPE) printf("This is a SGB 1!"); + else if (_cpu == MGB_TYPE) printf("This is a SGB 2!"); + } + else if (_cpu == DMG_TYPE) printf("This is a DMG! (OG Game Boy)"); + else if (_cpu == MGB_TYPE) printf("This is a MGB! (Game Boy Pocket / Light)"); + else if (_cpu == CGB_TYPE) { + // For Game Boy Color also check if it is a GBA in CGB mode + if (_is_GBA == GBA_DETECTED) printf("This is a GBA in CGB mode!"); + else printf("This is a CGB! (Game Boy Color)"); + } + + while(1) + { + vsync(); + } +} + diff --git a/gbdk-lib/examples/gb/template_minimal/Makefile b/gbdk-lib/examples/gb/template_minimal/Makefile @@ -9,7 +9,8 @@ GBDK_HOME = ../../../ LCC = $(GBDK_HOME)bin/lcc # You can uncomment the line below to turn on debug output -# LCC = $(LCC) -debug +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output # You can set the name of the .gb ROM file here PROJECTNAME = Example @@ -26,7 +27,7 @@ compile.bat: Makefile # Compile and link all source files in a single call to LCC $(BINS): $(CSOURCES) $(ASMSOURCES) - $(LCC) -o $@ $(CSOURCES) $(ASMSOURCES) + $(LCC) $(LCCFLAGS) -o $@ $(CSOURCES) $(ASMSOURCES) clean: rm -f *.o *.lst *.map *.gb *.ihx *.sym *.cdb *.adb *.asm diff --git a/gbdk-lib/examples/gb/template_subfolders/Makefile b/gbdk-lib/examples/gb/template_subfolders/Makefile @@ -11,7 +11,9 @@ LCC = $(GBDK_HOME)bin/lcc # You can set flags for LCC here # For example, you can uncomment the line below to turn on debug output -# LCCFLAGS = -debug +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output + # You can set the name of the .gb ROM file here PROJECTNAME = Example

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