GBDK 2020 Docs
4.1.1
API Documentation for GBDK 2020
|
As of version 4.1.0
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 capabilities, 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 its 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/<plat>
When linking with sdldgb (for GB/AP) and sdldz80 (for SMS/GG or MSXDOS):
-k <gbdk-path>lib/<port>
, -k <gbdk-path>lib/<plat>
-l <port>.lib
, -l <plat>.lib
<gbdk-path>lib/<plat>/crt0.o
MSXDOS requires an additional build step with makecom after makebin to create the final binary:
makecom <image.bin> [<image.noi>] <output.com>
The NES port has --no-peep
specified (in lcc) due to a peephole related codegen bug in SDCC that has not yet been merged.
-Wf--peep-file
(lcc) or --peep-file
(sdcc).Note: Starting with GBDK-2020 4.1.0 and SDCC 4.2, the Game Boy and related clones use sm83
for the port instead of gbz80
-msm83:gb
sm83
, plat:gb
-msm83:ap
sm83
, plat:ap
-msm83:duck
sm83
, plat:duck
-mz80:sms
z80
, plat:sms
-mz80:gg
z80
, plat:gg
-mz80:msxdos
z80
, plat:msxdos
-mmos6502:nes
mos6502
, plat:nes
There 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 #definedNINTENDO
will be #definedMEGADUCK
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 #defined<msx/msx.h>
is included (either directly or through <gbdk/platform.h>
)MSXDOS
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 cross-platform Logo
example project shows how assets can be managed for multiple different console targets together.
In the example utility_png2asset is used to generate assets in the native format for each console at compile-time from separate source PNG images. The Makefile is set to use the source PNG folder which matches the current console being compiled, and the source code uses set_native_tile_data() to load the assets tiles in native format.
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/DUCK
SMS/GG
GB/AP
SMS/GG
These are some of the main hardware differences between the Regular Game Boy and the Game Boy Color.
These are some of the main GBDK API features for the CGB. Many of the items listed below link to additional information.
set_bkg/win/sprite_*()
)#include <gb/cgb.h>
)Several examples in GBDK show how to use CGB features, including the following:
gb/colorbar
, gb/dscan
, cross-platform/large_map
, cross-platform/logo
, cross-platform/metasprites
The Analogue Pocket operating in .pocket
mode is (for practical purposes) functionally identical to the Game Boy / Color though it has a couple changes listed below. These are handled automatically in GBDK as long as the practices outlined below are followed.
0xFF4E
instead of 0xFF40
0x0104
:0x01, 0x10, 0xCE, 0xEF, 0x00, 0x00, 0x44, 0xAA, 0x00, 0x74, 0x00, 0x18, 0x11, 0x95, 0x00, 0x34, 0x00, 0x1A, 0x00, 0xD5, 0x00, 0x22, 0x00, 0x69, 0x6F, 0xF6, 0xF7, 0x73, 0x09, 0x90, 0xE1, 0x10, 0x44, 0x40, 0x9A, 0x90, 0xD5, 0xD0, 0x44, 0x30, 0xA9, 0x21, 0x5D, 0x48, 0x22, 0xE0, 0xF8, 0x60
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 Mega Duck is (for practical purposes) functionally identical to the Original Game Boy though it has a couple changes listed below.
0x0000
(on Game Boy: 0x0100
)0x0001
(many Game Boy MBCs use 0x2000 - 0x3FFF
)In order for software to be easily ported to the Mega Duck, or to run on both, use these practices. That will allow GBDK to automatically handle most of the differences (for the exceptions see Sound Register Value Changes).
There are two hardware changes which will not be handled automatically when following the practices mentioned above.
These changes may be required when using existing Sound Effects and Music Drivers written for the Game Boy.
((uint8_t)(value << 4) | (uint8_t)(value >> 4))
Game Boy: Bits:6..5 : 00 = mute, 01 = 100%, 10 = 50%, 11 = 25%
Mega Duck: Bits:6..5 : 00 = mute, 01 = 25%, 10 = 50%, 11 = 100%
(((~(uint8_t)value) + (uint8_t)0x20u) & (uint8_t)0x60u)
These changes are handled automatically when their GBDK definitions are used.
LCDC_REG Flag | Game Boy | Mega Duck | Purpose | |
---|---|---|---|---|
LCDCF_B_ON | .7 | .7 | (same) | Bit for LCD On/Off Select |
LCDCF_B_WIN9C00 | .6 | .3 | Bit for Window Tile Map Region Select | |
LCDCF_B_WINON | .5 | .5 | (same) | Bit for Window Display On/Off Control |
LCDCF_B_BG8000 | .4 | .4 | (same) | Bit for BG & Window Tile Data Region Select |
LCDCF_B_BG9C00 | .3 | .2 | Bit for BG Tile Map Region Select | |
LCDCF_B_OBJ16 | .2 | .1 | Bit for Sprites Size Select | |
LCDCF_B_OBJON | .1 | .0 | Bit for Sprites Display Visible/Hidden Select | |
LCDCF_B_BGON | .0 | .6 | Bit for Background Display Visible Hidden Select |
These changes are handled automatically when their GBDK definitions are used.
Register | Game Boy | Mega Duck |
---|---|---|
LCDC_REG | 0xFF40 | 0xFF10 |
STAT_REG | 0xFF41 | 0xFF11 |
SCY_REG | 0xFF42 | 0xFF12 |
SCX_REG | 0xFF43 | 0xFF13 |
LY_REG | 0xFF44 | 0xFF18 |
LYC_REG | 0xFF45 | 0xFF19 |
DMA_REG | 0xFF46 | 0xFF1A |
BGP_REG | 0xFF47 | 0xFF1B |
OBP0_REG | 0xFF48 | 0xFF14 |
OBP1_REG | 0xFF49 | 0xFF15 |
WY_REG | 0xFF4A | 0xFF16 |
WX_REG | 0xFF4B | 0xFF17 |
- | - | - |
NR10_REG | 0xFF10 | 0xFF20 |
NR11_REG | 0xFF11 | 0xFF22 |
NR12_REG | 0xFF12 | 0xFF21 |
NR13_REG | 0xFF13 | 0xFF23 |
NR14_REG | 0xFF14 | 0xFF24 |
- | - | - |
NR21_REG | 0xFF16 | 0xFF25 |
NR22_REG | 0xFF17 | 0xFF27 |
NR23_REG | 0xFF18 | 0xFF28 |
NR24_REG | 0xFF19 | 0xFF29 |
- | - | - |
NR30_REG | 0xFF1A | 0xFF2A |
NR31_REG | 0xFF1B | 0xFF2B |
NR32_REG | 0xFF1C | 0xFF2C |
NR33_REG | 0xFF1D | 0xFF2E |
NR34_REG | 0xFF1E | 0xFF2D |
- | - | - |
NR41_REG | 0xFF20 | 0xFF40 |
NR42_REG | 0xFF21 | 0xFF42 |
NR43_REG | 0xFF22 | 0xFF41 |
NR44_REG | 0xFF23 | 0xFF43 |
- | - | - |
NR50_REG | 0xFF24 | 0xFF44 |
NR51_REG | 0xFF25 | 0xFF46 |
NR52_REG | 0xFF26 | 0xFF45 |
- | - | - |