|
GBDK 2020 Docs
API Documentation for GBDK 2020
|
As of version 4.0.5 GBDK includes support for other consoles in addition to the Game Boy.
While the GBDK API has many convenience functions that work the same or similar across different consoles, it's important to keep their different capabilities in mind when writing code intended to run on more than one. Some (but not all) of the differences are screen sizes, color abilities, memory layouts, processor type (z80 vs gbz80/sm83) and speed.
When compiling and building through lcc use the -m<port>:<plat> flag to select the desired console via it's port and platform combination.
When building directly with the sdcc toolchain, the following must be specified manually (when using lcc it will populate these automatically based on -m<port>:<plat>).
When compiling with sdcc:
-m<port>, -D__PORT_<port> and -D__TARGET_<plat>When assembling with sdasgb (for GB/AP) and sdasz80 (for SMS/GG):
-I<gbdk-path>lib/small/asxxxx/<plat>When linking with sdldgb (for GB/AP) and sdldz80 (for SMS/GG):
-k <gbdk-path>lib/small/asxxxx/<port>, -k <gbdk-path>lib/small/asxxxx/<plat>-l <port>.lib, -l <plat>.lib<gbdk-path>lib/small/asxxxx/<plat>/crt0.o-mgbz80:gbgbz80, plat:gb-mgbz80:apgbz80, plat:ap-mz80:smsz80, plat:sms-mz80:ggz80, plat:ggThere are several constant #defines that can be used to help select console specific code during compile time (with #ifdef, #ifndef) .
<gb/gb.h> is included (either directly or through <gbdk/platform.h>)NINTENDO will be #definedGAMEBOY will be #definedNINTENDO will be #definedANALOGUEPOCKET will be #defined<sms/sms.h > is included (either directly or through <gbdk/platform.h>)SEGA will be #definedMASTERSYSTEM will be #definedSEGA will be #definedGAMEGEAR will be #definedConstants that describe properties of the console hardware are listed below. Their values will change to reflect the current console target that is being built.
Some include files under <gbdk/..> are cross platform and others allow the build process to auto-select the correct include file for the current target port and platform (console).
For example, the following can be used
#include <gbdk/platform.h> #include <gbdk/metasprites.h>
Instead of
#include <gb/gb.h> #include <gb/metasprites.h>
and
#include <sms/sms.h> #include <sms/metasprites.h>
GBDK includes an number of cross platform example projects. These projects show how to write code that can be compiled and run on multiple different consoles (for example Game Boy and Game Gear) with, in some cases, minimal differences.
They also show how to build for multiple target consoles with a single build command and Makefile. The Makefile.targets allows selecting different port and plat settings when calling the build stages.
The Analogue Pocket is (for practical purposes) functionally identical to the Game Boy / Color, but has a couple altered register flag and address definitions and a different boot logo. In order for software to be easily ported to the Analogue Pocket, or to run on both, use the following practices.
Use API defined registers and register flags instead of hardwired ones
As long as the target console is set during build time then the correct boot logo will be automatically selected.
Use the following api calls when assets are avaialble in the native format for each platform.
There are also bit-depth specific API calls:
On the Game Boy Color, VBK_REG is used to select between the regular background tile map and the background attribute tile map (for setting tile color palette and other properties).
This behavior is emulated for the SMS/GG when using set_bkg_tiles() and VBK_REG. It allows writing a 1-byte tile map separately from a 1-byte attributes map.
The specs below reflect the typical configuration of hardware when used with GBDK and is not meant as a complete list of their capabilities.
GB/AP
SMS/GG
GB/AP
SMS/GG