GBDK Manual
GBDK Manual
4.2.0
1 General Documentation 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 About the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 About GBDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Historical Info and Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Getting Started 3
2.1 1. Download a Release and unzip it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Known Issue: Windows and folder names with spaces on non-C drives . . . . . . . . . . . . 3
2.2 2. Compile Example projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.1 Windows (without Make installed): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.2 Linux / macOS / Windows with Make installed: . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 3. Use a Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 4. If you use GBTD / GBMB, get the fixed version . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.5 5. Review Coding Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.6 6. Hardware and Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.7 7. Set up C Source debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.8 8. Try a GBDK Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.9 9. Read up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.10 10. Need help? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11 Migrating From Pre-GBDK-2020 Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.1 Also see: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.2 Use auto-banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.3 Non-standard types (UINT8, etc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.4 If using GBTD / GBMB, get the fixed version . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.5 LCC and SDCC flags that are not needed . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.6 ROM Header Settings (such as Color, SGB, etc) . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.7 GBDK Header include changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.8 Include .h headers, not .c source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.9 Use the Template Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.11.10 Use hUGEtracker instead of gbt_player . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
ii
4 Using GBDK 9
4.1 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.1 Available Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.2 Adding your own interrupt handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.3 Using your own Interrupt Dispatcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.4 Returning from Interrupts and STAT mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 What GBDK does automatically and behind the scenes . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.1 NES console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.2 OAM (VRAM Sprite Attribute Table) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.3 Graphics Tile Maps and Data on Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.4 Font tiles when using stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.5 Default Interrupt Service Handlers (ISRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.6 Ensuring Safe Access to Graphics Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3 Compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.4 Copying Functions to RAM and HIRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.5 Mixing C and Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.5.1 Inline ASM within C source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.5.2 In Separate ASM files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.6 Including binary files in C source with incbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.7 Known Issues and Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.7.1 SDCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5 Coding Guidelines 13
5.1 Learning C / C fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1.1 General C tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.1.2 Embedded C introductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.1.3 Game Boy games in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.2 Understanding the hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3 Writing optimal C code for the Game Boy and SDCC . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.1 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.2 Avoid Reading from VRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.4 Code structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.3.5 GBDK API/Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3.6 Toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3.7 Constants, Signed-ness and Overflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.3.8 Chars and vararg functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4 When C isn't fast enough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.4.1 Variables and registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.4.2 Segments / Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
iii
7 GBDK Toolchain 26
7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.2 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.3 Changing Important Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.4 Compiling programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.4.1 Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.4.2 Using Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.4.3 Linker Files and ROM Auto Banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.5 Build Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.5.1 lcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.5.2 sdcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.3 sdasgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.4 bankpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.5 sdldgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.6 ihxcheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.7 makebin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.6 GBDK Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
iv
7.6.1 GBCompress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.6.2 png2asset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.6.3 makecom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.6.4 png2hicolorgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
9 Example Programs 45
9.1 banks (various projects) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9.2 comm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9.3 crash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9.4 colorbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9.5 dscan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9.6 filltest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.7 fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.8 galaxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.9 gb-dtmf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.10 gbdecompress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.11 irq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.12 large map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
9.13 metasprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
v
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
vi
13 Toolchain settings 68
13.1 lcc settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
13.2 sdcc settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
13.3 sdasgb settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
13.4 sdasz80 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
13.5 sdas6500 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
13.6 bankpack settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
13.7 sdldgb settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
13.8 sdldz80 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
13.9 sdld6808 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
13.10 ihxcheck settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
13.11 makebin settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
13.12 makecom settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
13.13 gbcompress settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
13.14 png2asset settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
13.15 png2hicolorgb settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
14 Todo List 75
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
vii
15 Module Index 76
15.1 C modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
17 File Index 76
17.1 File List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
18 Module Documentation 78
18.1 List of gbdk fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
18.1.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
18.1.2 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
20 File Documentation 86
20.1 docs/pages/01_getting_started.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 86
20.2 docs/pages/02_links_and_tools.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 86
20.3 docs/pages/03_using_gbdk.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
viii
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
ix
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
x
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
xi
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
xii
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
1 General Documentation 1
Index 361
1 General Documentation
• Getting Started
• Using GBDK
• Coding Guidelines
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
2
• GBDK Toolchain
• Example Programs
• Toolchain settings
1.1 Introduction
Welcome to GBDK-2020! The best thing to do is head over to the Getting Started section to get up and running.
If you are upgrading please check GBDK Release Notes and Migrating to new GBDK Versions
This documentation is partially based on material written by the original GBDK authors in 1999 and updated for
GBDK-2020. The API docs are automatically generated from the C header files using Doxygen.
GBDK-2020 is an updated version of the original GBDK with a modernized SDCC toolchain and many API improve-
ments and fixes. It can be found at: https://github.com/gbdk-2020/gbdk-2020/.
The original GBDK sources, documentation and website are at: http://gbdk.sourceforge.net/
The GameBoy Developer's Kit (GBDK, GBDK-2020) is used to develop games and programs for the Nintendo
Game Boy (and some other consoles) in C and assembly. GBDK includes a set of libraries for the most common
requirements and generates image files for use with a real GameBoy or emulators.
GBDK features:
• Support for multiple consoles: Game Boy, Analogue Pocket, Mega Duck, Master System and Game Gear
and NES
GBDK is freeware. Most of the tooling code is under the GPL. The runtime libraries should be under the LGPL.
Please consider mentioning GBDK in the credits of projects made with it.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
1.4 Historical Info and Links 3
2 Getting Started
Follow the steps in this section to start using GBDK-2020.
2.1.1 Known Issue: Windows and folder names with spaces on non-C drives
There is a known issue on Windows where sdcc will fail when run from folder names with spaces on non-C drives.
For the time being the workaround is as follows (with D:\My Stuff\ as an example folder):
• Run Windows Command as administrator
– Output: The volume state is: 1 (8dot3 name creation is disabled). The registry state is: 2 (Per volume
setting - the default). Based on the above settings, 8dot3 name creation is disabled on D:
– Output: The volume state is: 0 (8dot3 name creation is enabled). The registry state is: 2 (Per volume
setting - the default). Based on the above settings, 8dot3 name creation is enabled on D:
• Only folders created AFTER the setting has been enabled will get 8.3 filename support, renaming folders
does NOT appear to generate 8.3 filename support. However it is possible to manually generate a short path
name for an existing folder:
This should build the example project. You can also navigate into other example project folders and build in the
same way.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
4
This should build all of the examples sequentially. You can also navigate into an individual example project's folder
and build it by typing make.
2.2.2.1 macOS security warnings If you get a security warning on macOS that says ("`... developer cannot be
verified, macOS cannot verify that this app is free from malware`"), it does not mean that GBDK is malware. It just
means the GBDK toolchain binaries are not signed by Apple, so it won't run them without an additional step.
You will need to unquarrantine the files in the bin folder in order to run them. This can be fixed using the following
steps.
Open a terminal and navigate to the gbdk bin folder ("bin/" under your GBDK-2020 install folder). Then type:
xattr -d com.apple.quarantine *
2. If you moved the folder out of the GBDK examples then you must update the GBDK path variable and/or the
path to LCC in the Makefile or compile.bat so that it will still build correctly.
3. Type make on the command line in that folder to verify it still builds.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
2.7 7. Set up C Source debugging 5
• See how to set the compatibility type in the cartridge header. Read more about hardware differences in the
Pandocs
• Note: Tutorials (or parts of them) may be based on the older GBDK from the 2000's before it was updated to
be GBDK-2020. The general principles are all the same, but the setup and parts of the toolchain (compiler/etc)
may be somewhat different and some links may be outdated (pointing to the old GBDK or old tools).
• Learn about the Game Boy hardware by reading through the Pandocs technical reference.
• Coding Guidelines
GBDK-2020 now supports auto-banking (rom_autobanking). In most cases using auto-banking will be easier and
less error prone than manually assigning source and assets to banks.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
6
The old GBDK types UINT8, INT8, UINT16, INT16 are non-standard and less portable.
The following should be used instead: uint8_t, int16_t, uint16_t, int32_t, uint32_t and bool.
These are standard types defined in stdint.h (#include <stdint.h>) and stdbool.h (#include
<stdbool.h>).
If you plan to use GBTD / GBMB for making graphics, make sure to get the version with the const fix and other
improvements. See const_gbtd_gbmb.
The following flag is no longer needed with lcc and sdcc, it can be removed without any loss of performance.
• -DUSE_SFR
Setting ROM bytes directly with -Wl-yp0x<address>=0x<value> is no longer supported. Instead use
makebin flags. For example, use -Wm-yC instead of -Wl-yp0x143=0xC0. See faq_gb_type_header_setting.
The following header files which are now cross platform were moved from gb/ to gbdk/: bcd.h, console.h,
far_ptr.h, font.h, gbdecompress.h, gbdk-lib.h, incbin.h, metasprites.h, platform.h,
version.h
Do not #include .c source files into other .c source files. Instead create .h header files for them and include
those.
• https://www.tutorialspoint.com/cprogramming/c_header_files.htm
Modern project templates are included with GBDK-2020. Using them (and their Makefile or compile.bat) as a
starting point for projects is recommended and can help ensure better default settings and project organization.
hUGEtracker and its driver hUGEdriver are smaller, more efficient and more versatile than gbt_player.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
3.1 SDCC Compiler Suite User Manual 7
3.5 Tutorials
• Larold's Jubilant Junkyard Tutorials
Several walk throughs about the fundamentals of developing for the Game Boy with GBDK-2020. There are
simple examples with source code.
https://laroldsjubilantjunkyard.com/tutorials/
• Gaming Monsters Tutorials
Several video tutorials and code for making games with GBDK/GBDK-2020.
https://www.youtube.com/playlist?list=PLeEj4c2zF7PaFv5MPYhNAkBGrkx4i←-
PGJo
https://github.com/gingemonster/GamingMonstersGameBoySampleCode
• Pocket Leage Tutorial
https://blog.ty-porter.dev/development/2021/04/04/writing-a-gameboy-game-in-2021-pt
html
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8
• GBT Player
A .mod converter and music driver that works with GBDK and RGBDS.
https://github.com/AntonioND/gbt-player
Docs from GBStudio that should mostly apply:
https://www.gbstudio.dev/docs/music/
3.9 Emulators
• BGB
Accurate emulator, has useful debugging tools.
http://bgb.bircd.org/
• Emulicious
An accurate emulator with extensive tools including source level debugging.
https://emulicious.net/
• romusage
Calculate used and free space in banks (ROM/RAM) and warn about errors such as bank overflows.
https://github.com/bbbbbr/romusage
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
3.11 Optimizing Assembly 9
• src2sym.pl
Add line-by-line C source code to the main symbol file in a BGB compatible format. This allows for C source-
like debugging in BGB in a limited way. https://gbdev.gg8.se/forums/viewtopic.←-
php?id=710
4 Using GBDK
4.1 Interrupts
Interrupts allow execution to jump to a different part of your code as soon as an external event occurs - for example
the LCD entering the vertical blank period, serial data arriving or the timer reaching its end count. For an example
see the irq.c sample project.
Interrupts in GBDK are handled using the functions disable_interrupts(), enable_interrupts(), set_interrupts(uint8_t ier)
and the interrupt service routine (ISR) linkers add_VBL(), add_TIM, add_low_priority_TIM, add_LCD, add_SIO
and add_JOY which add interrupt handlers for the vertical blank, timer, LCD, serial link and joypad interrupts
respectively.
Since an interrupt can occur at any time an Interrupt Service Request (ISR) cannot take any arguments or return
anything. Its only way of communicating with the greater program is through the global variables. When interacting
with those shared ISR global variables from main code outside the interrupt, it is a good idea to wrap them in a
critical {} section in case the interrupt occurs and modifies the variable while it is being used.
Interrupts should be disabled before adding ISRs. To use multiple interrupts, logical OR the relevant IFLAGs to-
gether.
ISRs should be kept as small and short as possible, do not write an ISR so long that the Game Boy hardware
spends all of its time servicing interrupts and has no time spare for the main code.
For more detail on the Game Boy interrupts consider reading about them in the Pandocs.
The GameBoy hardware can generate 5 types of interrupts. Custom Interrupt Service Routines (ISRs) can be
added in addition to the built-in ones available in GBDK.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
10
– The default SIO ISR gets installed automatically if any of the standard SIO calls are used (send_byte(),
receive_byte()).
– Once installed the default SIO ISR cannot be removed. Only secondary chained SIO ISRs (added with
add_SIO() ) can be removed.
– See add_SIO() and remove_SIO()
– Example project: comm
It is possible to install your own interrupt handlers (in C or in assembly) for any of these interrupts. Up to 4 chained
handlers may be added, with the last added being called last. If the remove_VBL() function is to be called, only
three may be added for VBL.
Interrupt handlers are called in sequence. To install a new interrupt handler, do the following:
1. Write a function (say foo()) that takes no parameters, and that returns nothing. Remember that the code
executed in an interrupt handler must be short.
2. Inside a __critical { ... } section, install your interrupt handling routines using the add_XXX()
function, where XXX is the interrupt that you want to handle.
3. Enable interrupts for the IRQ you want to handle, using the set_interrupts() function. Note that the VBL
interrupt is already enabled before the main() function is called. If you want to set the interrupts before main()
is called, you must install an initialization routine.
See the irq example project for additional details for a complete example.
If you want to use your own Interrupt Dispatcher instead of the GBDK chained dispatcher (for improved perfor-
mance), then don't call the add_...() function for the respective interrupt and its dispatcher won't be installed.
• For the SIO interrupt, also do not make any standard SIO calls to avoid having its dispatcher installed.
By default when an Interrupt handler completes and is ready to exit it will check STAT_REG and only return at the
BEGINNING of either LCD Mode 0 or Mode 1. This helps prevent graphical glitches caused when an ISR interrupts
a graphics operation in one mode but returns in a different mode for which that graphics operation is not allowed.
You can change this behavior using nowait_int_handler() which does not check STAT_REG before returning. Also
see wait_int_handler().
For implementation details on the NES console in GBDK, see the NES entry in Supported Consoles & Cross Compiling
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
4.3 Compression 11
GBDK sets up a Shadow OAM which gets copied automatically to the hardware OAM by the default V-Blank ISR.
The Shadow OAM allows updating sprites without worrying about whether it is safe to write to them or not based on
the hardware LCD mode.
Including stdio.h and using functions such as printf() will use a large number of the background tiles for font charac-
ters. If stdio.h is not included then that space will be available for use with other tiles instead.
• V-Blank: A default V-Blank ISR is installed on startup which copies the Shadow OAM to the hardware OAM
and increments the global sys_time variable once per frame.
• Serial Link I/O: If any of the GBDK serial link functions are used such as send_byte() and receive_byte(), the
default SIO serial link handler will be installed automatically at compile-time.
• APA Graphics Mode: When this mode is used (via drawing.h) custom VBL and LCD ISRs handlers will
be installed (drawing_vbl and drawing_lcd). Changing the mode to (mode(M_TEXT_OUT);) will
cause them to be de-installed. These handlers are used to change the tile data source at start-of-frame and
mid-frame so that 384 background tiles can be used instead of the typical 256.
There are certain times during each video frame when memory and registers relating to graphics are "busy" and
should not be read or written to (otherwise there may be corrupt or dropped data). GBDK handles this automatically
for most graphics related API calls. It also ensures that ISR handlers return in such a way that if they interrupted a
graphics access then it will only resume when access is allowed.
The ISR return behavior can be turned off using the nowait_int_handler.
For more details see the related Pandocs section: https://gbdev.io/pandocs/Accessing_VRAM←-
_and_OAM.html
4.3 Compression
For programs that would benefit from compression GBDK includes the gbcompress utility and companion API
functions.
In addition to the built-in compression unapack is another option:
Use of 1-bpp tile pattern data may be combined with the compression described above to save even more space,
however that approach requires using an intermediary RAM buffer before the tile pattern data can be written to
VRAM with the set_∗_1bpp_data() functions.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12
• Declare a pointer-to-function variable, and set it to the address of the function to call.
• Declare the function as extern, and set its address at link time using the -Wl-gXXX=# flag (where XXX is the
name of the function, and # is its address).
The second approach is slightly more efficient. Both approaches are demonstrated in the ram_function.c
example.
• For additional detail see the links_sdcc_docs and SDCC Calling Conventions.
• The optional NAKED keyword may be used to indicate that the funtion setup and return should have no
handling done by the compiler, and will instead be handled entirely by user code.
• If the entire function preserves some registers the optional PRESERVES_REGS keyword may be used as
additional hinting for the compiler. For example PRESERVES_REGS(b, c). By default it is assumed by
the compiler that no registers are preserved.
Example:
__asm__("nop");
Another Example:
void some_c_function()
{
// Optionally do something
__asm
(ASM code goes here)
__endasm;
}
It is possible to assemble and link files written in ASM alongside files written in C.
• Parameters will be passed, registers saved and results returned in a manner based on the SDCC Calling Convention
used and how the function is declared.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
4.6 Including binary files in C source with incbin 13
main()
{
uint16_t i;
i = add(1, 3);
}
add.s
.globl _add
.area _CODE
_add: ; uint16_t add(uint16_t First, uint16_t Second)
;
; In this particular example there is no use and modification of the stack
; No need to save and restore registers
;
; For calling convention __sdcccall(1)
; - first 16 bit param is passed in DE
; - second 16 bit param is passed in BC
; Return result in BC
ld c, l
ld b, h
ret ; 16 bit values are returned in BC
• Const arrays declared with somevar[n] = {x} will NOT get initialized with value x. This may change
when the SDCC RLE initializer is fixed. Use memset for now if you need it.
• SDCC banked calls and far_pointers in GBDK only save one byte for the ROM bank, so for example they are
limited to bank 15 max for MBC1 and bank 255 max for MBC5. See banked_calls for more details.
• In SDCC pre-initializing a variable assigned to SRAM with -Wf-ba∗ will force that variable to be in WRAM
instead.
– The following is a workaround for initializing a variable in SRAM. It assignes value 0xA5 to a variable in
bank 0 and assigned to address 0xA000 using the AT() directive:
// Workaround for initializing variable in SRAM
// (MBC RAM and Bank needs to get enabled during GSINIT loading)
static uint8_t AT(0x0000) __rRAMG = 0x0a; // Enable SRAM
static uint8_t AT(0x4000) __rRAMB = 0x00; // Set SRAM bank 0
// Now SRAM is enabled so the variable can get initialized
uint8_t AT(0xA000) initialized_sram_var = 0xA5u;
5 Coding Guidelines
5.1 Learning C / C fundamentals
Writing games and other programs with GBDK will be much easier with a basic understanding of the C language.
In particular, understanding how to use C on "Embedded Platforms" (small computing systems, such as the Game
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
14
Boy) can help you write better code (smaller, faster, less error prone) and avoid common pitfalls.
• https://www.learn-c.org/
• https://www.tutorialspoint.com/cprogramming/index.htm
• https://www.chiark.greenend.org.uk/∼sgtatham/cdescent/
• http://dsp-book.narod.ru/CPES.pdf
• https://www.phaedsys.com/principals/bytecraft/bytecraftdata/bcfirststeps.←-
pdf
• https://gbdev.io/resources.html#c
5.3 Writing optimal C code for the Game Boy and SDCC
The following guidelines can result in better code for the Game Boy, even though some of the guidance may be
contrary to typical advice for general purpose computers that have more resources and speed.
5.3.1 Tools
5.3.1.1 GBTD / GBMB, Arrays and the "const" keyword Important: The old GBTD/GBMB fails to include the
const keyword when exporting to C source files for GBDK. That causes arrays to be created in RAM instead of
ROM, which wastes RAM, uses a lot of ROM to initialize the RAM arrays and slows the compiler down a lot.
__Use of toxa's updated GBTD/GBMB is highly recommended.__
If you wish to use the original tools, you must add the const keyword every time the graphics are re-exported to C
source files.
In general avoid reading from VRAM since that memory is not accessible at all times. If GBDK a API function which
reads from VRAM (such as get_bkg_tile_xy()) is called during a video mode when VRAM is not accessible, then
that function call will delay until VRAM becomes accessible again. This can cause unnecessary slowdowns when
running programs on the Game Boy. It is also not supported by GBDK on the NES platform.
Instead it is better to store things such as map data in general purpose RAM which does not have video mode
access limitations.
For more information about video modes and VRAM access see the pan docs:
https://gbdev.io/pandocs/STAT.html#stat-modes
5.3.3 Variables
• Use 8-bit values as much as possible. They will be much more efficient and compact than 16 and 32 bit types.
• Prefer unsigned variables to signed ones: the code generated will be generally more efficient, especially
when comparing two values.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
5.3 Writing optimal C code for the Game Boy and SDCC 15
• Use explicit types so you always know the size of your variables. int8_t, uint8_t, int16_←-
t, uint16_t, int32_t, uint32_t and bool. These are standard types defined in stdint.h
(#include <stdint.h>) and stdbool.h (#include <stdbool.h>).
• Global and local static variables are generally more efficient than local non-static variables (which go on the
stack and are slower and can result in slower code).
• const keyword: use const for arrays, structs and variables with read-only (constant) data. It will reduce
ROM, RAM and CPU usage significantly. Non-const values are loaded from ROM into RAM inefficiently,
and there is no benefit in loading them into the limited available RAM if they aren't going to be changed.
• When modifying variables that are also changed in an Interrupt Service Routine (ISR), wrap them
the relevant code block in a __critical { } block. See http://sdcc.sourceforge.←-
net/doc/sdccman.pdf#section.3.9
• When using constants and literals the U, L and UL postfixes can be used.
• A fixed point type (fixed) is included with GBDK when precision greater than whole numbers is required for
8 bit range values (since floating point is not included in GBDK).
• Do not #include .c source files into other .c source files. Instead create .h header files for them and in-
clude those. https://www.tutorialspoint.com/cprogramming/c_header_files.←-
htm
• Instead of using a blocking delay() for things such as sprite animations/etc (which can prevent the rest of the
game from continuing) many times it's better to use a counter which performs an action once every N frames.
sys_time may be useful in these cases.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
16
• When processing for a given frame is done and it is time to wait before starting the next frame, vsync() can
be used. It uses HALT to put the CPU into a low power state until processing resumes. The CPU will wake
up and resume processing at the end of the current frame when the Vertical Blanking interrupt is triggered.
• Minimize use of multiplication, modulo with non-powers of 2, and division with non-powers of 2. These
operations have no corresponding CPU instructions (software functions), and hence are time costly.
• Use inline functions if the function is short (with the inline keyword, such as inline uint8_t my←-
Function() { ... }).
• Do not use recursive functions.
• stdio.h: If you have other ways of printing text, avoid including stdio.h and using functions such as printf().
Including it will use a large number of the background tiles for font characters. If stdio.h is not included then
that space will be available for use with other tiles instead.
• drawing.h: The Game Boy graphics hardware is not well suited to frame-buffer style graphics such as the
kind provided in drawing.h. Due to that, most drawing functions (rectangles, circles, etc) will be slow . When
possible it's much faster and more efficient to work with the tiles and tile maps that the Game Boy hardware
is built around.
• waitpad() and waitpadup check for input in a loop that doesn't HALT at all, so the CPU will be maxed out until
it returns. One alternative is to write a function with a loop that checks input with joypad() and then waits a
frame using vsync() (which idles the CPU while waiting) before checking input again.
• joypad(): When testing for multiple different buttons, it's best to read the joypad state once into a variable and
then test using that variable (instead of making multiple calls).
5.3.6 Toolchain
– https://sdcc.sourceforge.net/doc/sdccman.pdf#section.1.1
– Note: by default GBDK enables --fsigned-char (via lcc) for SDCC
• Use profiling. Look at the ASM generated by the compiler, write several versions of a function, compare them
and choose the faster one.
• Use the SDCC --max-allocs-per-node flag with large values, such as 50000. --opt-code-speed
has a much smaller effect.
– GBDK-2020 (after v4.0.1) compiles the library with --max-allocs-per-node 50000, but it must
be turned on for your own code.
(example: lcc ... -Wf--max-allocs-per-node50000 or sdcc ... --max-allocs-per-node
50000).
– The other code/speed flags are --opt-code-speed or --opt-code-size.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
5.3 Writing optimal C code for the Game Boy and SDCC 17
• Learn some ASM and inspect the compiler output to understand what the compiler is doing and how your
code gets translated. This can help with writing better C code and with debugging.
There are a some scenarios where the compiler will warn about overflows with constants. They often have to do with
mixed signedness between constants and variables. To avoid problems use care about whether or not constants
are explicitly defined as unsigned and what type of variables they are used with.
WARNING: overflow in implicit constant conversion
• A constant can be used where the the value is too high (or low) for the storage medium causing an value
overflow.
– For example this constant value is too high since the max value for a signed 8 bit char is 127.
#define TOO_LARGE_CONST 255
int8_t signed_var = TOO_LARGE_CONST;
• This can also happen when constants are not explicitly declared as unsigned (and so may get treated by the
compiler as signed) and then added such that the resulting value exceeds the signed maximum.
– For example, this results in an warning even though the sum total is 254 which is less than the 255,
the max value for a unsigned 8 bit char variable.
#define CONST_UNSIGNED 127u
#define CONST_SIGNED 127
uint8_t unsigned_var = (CONST_SIGNED + CONST_UNSIGNED);
– It can be avoided by always using the unsigned u when the constant is intended for unsigned operations.
#define CONST_UNSIGNED 127u
#define CONST_ALSO_UNSIGNED 127u // <-- Added "u", now no warning
uint8_t unsigned_var = (CONST_UNSIGNED + CONST_ALSO_UNSIGNED);
Parameters (chars, ints, etc) to printf / sprintf should always be explicitly cast to avoid type related parameter passing
issues.
For example, below will result in the likely unintended output:
printf(str_temp, "%u, %d, %x\n", UINT16_MAX, INT16_MIN, UINT16_MAX);
// Will output: "65535, 0, 8000"
Instead this will give the intended output:
printf(str_temp, "%u, %d, %x\n", (uint16_t)UINT16_MAX, (int16_t)INT16_MIN, (uint16_t)UINT16_MAX);
// Will output: "65535, -32768, FFFF"
5.3.8.1 Chars In standard C when chars are passed to a function with variadic arguments (varargs, those
declared with ... as a parameter), such as printf(), those chars get automatically promoted to ints. For an 8
bit CPU such as the Game Boy's, this is not as efficient or desirable in most cases. So the default SDCC behavior,
which GBDK-2020 expects, is that chars will remain chars and not get promoted to ints when explicitly cast as
chars while calling a varargs function.
• They must be explicitly re-cast when passing them to a varargs function, even though they are already de-
clared as chars.
For example:
unsigned char i = 0x5A;
// NO:
// The char will get promoted to an int, producing incorrect printf output
// The output will be: 5A 00
printf("%hx %hx", i, i);
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
18
// YES:
// The char will remain a char and printf output will be as expected
// The output will be: 5A 5A
printf("%hx %hx", (unsigned char)i, (unsigned char)i);
Some functions that accept varargs:
Also See:
Getting at C variables is slightly tricky due to how local variables are allocated on the stack. However you shouldn't
be using the local variables of a calling function in any case. Global variables can be accessed by name by adding
an underscore.
The use of segments/areas for code, data and variables is more noticeable in assembler. GBDK and SDCC define
a number of default ones. The order they are linked is determined by crt0.s and is currently as follows for the Game
Boy and related clones.
• Banked ROM
– _CODE_x Places code in ROM other than Bank 0, where x is the 16kB bank number.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
5.4 When C isn't fast enough 19
The following is primarily oriented toward the Game Boy and related clones (sm83 devices), other targets such as
sms/gg may vary.
SDCC in common with almost all C compilers prepends a _ to any function names. For example the function
printf(...) begins at the label _printf::. Note that all functions are declared global.
Functions can be marked with OLDCALL which will cause them to use the __sdcccall(0) calling convention
(the format used prior to SDCC 4.2 & GBDK-2020 4.1.0).
Starting with SDCC 4.2 and GBDK-2020 4.1.0 the new default calling convention is__sdcccall(1).
For additional details about the calling convetions, see sections SM83 calling conventions and Z80,
Z180 and Z80N calling conventions in the SDCC manual.
• http://sdcc.sourceforge.net/doc/sdccman.pdf
• Section 4.3.9 isn't specific about it, but gbz80/sm83 generally share this subheading with z80 (Game
Boy is partially a sub-port of z80 in SDCC). https://sdcc.sourceforge.net/doc/sdccman.←-
pdf#subsection.4.3.9
5.4.3.1 Banked Calling Convention The following is primarily oriented toward the Game Boy and related clones
(sm83 devices), other targets such as sms/gg may vary.
Key Points:
• Function arguments (if present) are always placed on the stack, right to left without particular alignment
• A fixed stack offset (sm83:+4, z80:+3) is added by the Callee (to skip the pushed Caller Bank and
additional Trampoline Return Address)
• Return values follow the calling convention (__sdcccall(1), or __sdcccall(0) for OLDCALL)
Terminology:
• Trampoline: The intermediary which performs the bank switching and does hand-off between Caller
and Callee during the call and then return.
• Banked calls are performed via a trampoline in the non-banked region 0000-3ffff
– With it both calling conventions are supported: __sdcccall(1) (default) or __sdcccall(0) for
OLDCALL
• If --legacy-banking is specified to SDCC the __sdcc_bcall trampoline is used.
1. The Caller
• Function arguments (if present) are always placed on the stack, right to left without particular alignment
• The Bank of Callee function is placed into register E
• The Address of Callee function is placed in HL
• Calls the bank switch Trampoline (which adds Caller return address to the stack)
2. The Trampoline
• Saves the Current Bank onto the stack (pushed as AF, so 16 bits)
• Switches to the Bank of Callee function (in register E)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20
• Calls the Callee function address in HL (which adds Trampoline return address to the stack)
• SDCC will use an offset to skip the first N bytes of the stack
– For sm83 (GB/AP/DUCK): skip first 4 bytes
– For z80 (GG/SMS/etc): skip first 3 bytes
• Return values follow the calling convention (__sdcccall(1), or __sdcccall(0) for OLDCALL)
• Executes a return to Trampoline
4. The Trampoline
• Switches to the Bank of the Caller saved on the stack (and moves Stack Pointer past it)
• Executes a return to Caller
5. The Caller
Cartridges with no MBC controller are non-banked, they have 32K bytes of fixed ROM space and no switchable
banks. For these cartridges the ROM space between 0000h and 7FFFh can be treated as a single large bank
of 32K bytes, or as two contiguous banks of 16K bytes in Bank 0 at 0000h - 3FFFh and Bank 1 at 4000h to
7FFFh.
Cartridges with MBCs allow the the Game Boy to work with ROMS up to 8MB in size and with RAM up to 128kB.
Each bank is 16K Bytes. The following are usually true, with some exceptions:
• Bank 0 of the ROM is located in the region at 0000h - 3FFFh. It is fixed (non-banked) and cannot be
switched out for another bank.
• Banks 1 .. N can be switched into the upper region at 4000h - 7FFFh. The upper limit for N is
determined by the MBC used and available cartridge space.
• It is not necessary to manually assign Bank 0 for source files, that will happen by default if no bank is specified.
See the Pandocs for more details about the individual MBCs and their capabilities.
• The SWITCH_ROM() / ref SWITCH_RAM() macros work with MBC5 (up to ROM bank 255, SWITCH_ROM_MBC5_8M
may be used if a larger size is needed).
• MBC1 is not recommended. Some banks in it's range are unavailable. See pandocs for more details.
https://gbdev.io/pandocs/MBC1
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
6.2 Working with Banks 21
6.1.3.1 Bank 0 Size Limit and Overflows When Using MBCs When using MBCs and bank switching the space
used in the lower fixed Bank 0 must be <= 16K bytes. Otherwise it's data will overflow into Bank 1 and may be
overwriten or overwrite other data, and can get switched out when banks are changed.
See the FAQ entry about bank overflow errors.
6.1.3.2 Conserving Bank 0 for Important Functions and Data When using MBCs, Bank 0 is the only bank
which is always active and it's code can run regardless of what other banks are active. This means it is a limited
resource and should be prioritized for data and functions which must be accessible regardless of which bank is
currently active.
• Place the code for your ROM bank in one or several source files.
• Specify the ROM bank to use, either in the source file or at compile/link time.
• Specify the number of banks and MBC type during link time.
• When the program is running and wants to use data or call a function that is in a given bank, manually or
automatically set the desired bank to active.
The ROM and RAM bank for a source file can be set in a couple different ways. Multiple different banks cannot be
assigned inside the same source file (unless the __addressmod method is used), but multiple source files can
share the same bank.
If no ROM and RAM bank are specified for a file then the default _CODE, _BSS and _DATA segments are used.
Ways to set the ROM bank for a Source file:
• #pragma bank <N> at the start of a source file. Example (ROM bank 2): #pragma bank 2
• The lcc switch for ROM bank -Wf-bo<N>. Example (ROM bank 2): -Wf-bo2
• Using rom_autobanking
Note: You can use the NONBANKED keyword to define a function as non-banked if it resides in a source file which
has been assigned a bank.
• Using the lcc switch for Cartridge SRAM bank -Wf-ba<N>. Example (Cartridge SRAM bank 3): -Wf-ba3
6.2.3 Setting the MBC and number of ROM & RAM banks available
At the link stage this is done with lcc using pass-through switches for makebin.
• -Wm-yo<N> where <N> is the number of ROM banks. 2, 4, 8, 16, 32, 64, 128, 256, 512
• -Wm-yt<N> where <N> is the type of MBC cartridge (see chart below).
– Example: Wm-yt0x1A
• If passing the above arguments to makebin directly without using lcc, then the -Wm part should be omitted.
– Note: Some makebin switches (such as -yo A) require a space when passed directly. See
makebin-settings for details.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
22
The MBC settings below are available when using the makebin -Wl-yt<N> switch.
Source: Pandocs. Additional details available at Pandocs
For SMS/GG, the ROM file size must be at least 64K to enable mapper support for RAM banks in emulators.
• If the generated ROM is too small then -yo 4 for makebin (or -Wm-yo4 for LCC) can be used to set the
size to 64K.
Hex Code MBC Type SRAM Battery RTC Rumble Extra Max ROM Size (1)
0x00 ROM ONLY 32 K
0x01 MBC-1 (2) 2 MB
0x02 MBC-1 (2) SRAM 2 MB
0x03 MBC-1 (2) SRAM BATTERY 2 MB
0x05 MBC-2 256 K
0x06 MBC-2 BATTERY 256 K
0x08 ROM (3) SRAM 32 K
0x09 ROM (3) SRAM BATTERY 32 K
0x0B MMM01 8 MB / N
0x0C MMM01 SRAM 8 MB / N
0x0D MMM01 SRAM BATTERY 8 MB / N
0x0F MBC-3 BATTERY RTC 2 MB
0x10 MBC-3 (4) SRAM BATTERY RTC 2 MB
0x11 MBC-3 2 MB
0x12 MBC-3 (4) SRAM 2 MB
0x13 MBC-3 (4) SRAM BATTERY 2 MB
0x19 MBC-5 8 MB
0x1A MBC-5 SRAM 8 MB
0x1B MBC-5 SRAM BATTERY 8 MB
0x1C MBC-5 RUMBLE 8 MB
0x1D MBC-5 SRAM RUMBLE 8 MB
0x1E MBC-5 SRAM BATTERY RUMBLE 8 MB
0x20 MBC-6 ∼2MB
0x22 MBC-7 SRAM BATTERY RUMBLE SENSOR 2MB
0xFC POCKET CAMERA To Do
0xFD BANDAI TAMA5 To Do
0xFE HuC3 RTC To Do
0xFF HuC1 SRAM BATTERY IR To Do
1: Max possible size for MBC is shown. When used with generic SWITCH_ROM() the max size may be smaller.
For example:
• The max for MBC5 becomes Bank 255 (4MB). To use the full 8MB size of MBC5 see SWITCH_ROM_MBC5_8M().
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
6.2 Working with Banks 23
2: For MBC1 some banks in it's range are unavailable. See pandocs for more details https://gbdev.←-
io/pandocs/MBC1
3: No licensed cartridge makes use of this option. Exact behaviour is unknown.
4: MBC3 with RAM size 64 KByte refers to MBC30, used only in Pocket Monsters Crystal Version for Japan.
The bank number for a banked function, variable or source file can be stored and retrieved using the following
macros:
• BANKREF(): create a reference for retrieving the bank number of a variable or function
• BANKREF_EXTERN(): Make a BANKREF() reference residing in another source file accessible in the current
file for use with BANK().
– Placed in the non-banked lower 16K region (bank 0), regardless of the bank selected by its source file.
– Forces the .area to _HOME.
• <not-specified>:
– The function does not use sdcc banked calls (near instead of far).
– Placed in the bank selected by its source file (or compiler switches).
• When defined with the BANKED keyword. Example: void my_function() BANKED { do stuff
} in a source file which has had its bank set (see above).
• Using far_pointers
• When defined with an area set up using the __addressmod keyword (see the banks_new example
project and the SDCC manual for details).
• Using SWITCH_ROM() (and related functions for other MBCs) to manually switch in the required bank and
then call the function.
– The compiler and library will manage the bank switching automatically using the bank switching tram-
poline.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
24
– May only use data from fixed Bank 0 and the currently active bank.
– A NONBANKED wrapper function may be used to access data in other banks.
– Banks cannot be switched manually from inside a BANKED function (otherwise it will switch out it's own
function code as it is executing it, likely leading to a crash).
Limitations:
• SDCC banked calls and far_pointers in GBDK only save one byte for the ROM bank. So, for example, they
are limited to bank 31 max for MBC1 and bank 255 max for MBC5. This is due to the bank switching for
those MBCs requiring a second, additional write to select the upper bits for more banks (banks 32+ in MBC1
and banks 256+ in MBC5).
Calling Convention:
• For details see Banked Calling Convention
Data declared as const (read only) will be stored in ROM in the bank associated with it's source file (if none is
specified it defaults to Bank 0). If that bank is a switchable bank then the data is only accesible while the given bank
is active.
Far pointers include a segment (bank) selector so they are able to point to addresses (functions or data) outside of
the current bank (unlike normal pointers which are not bank-aware). A set of macros is provided by GBDK 2020 for
working with far pointers.
Warning: Do not call the far pointer function macros from inside interrupt routines (ISRs). The far pointer function
macros use a global variable that would not get restored properly if a function called that way was interrupted by
another one called the same way. However, they may be called recursively.
See FAR_CALL, TO_FAR_PTR and the banks_farptr example project.
You can manually switch banks using the SWITCH_ROM(), SWITCH_RAM(), and other related macros. See
banks.c project for an example.
Note: You can only do a switch_rom_bank call from non-banked _CODE since otherwise you would switch out the
code that was executing. Global routines that will be called without an expectation of bank switching should fit within
the limited 16k of non-banked _CODE.
In order to load Data in one bank from code running in another bank a NONBANKED wrapper function can be used.
It can save the current bank, switch to another bank, operate on some data, restore the original bank and then
return.
An example function which can :
• Load background data from any bank
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
6.3 Auto-Banking 25
The global variable _current_bank is updated automatically when calling SWITCH_ROM(), SWITCH_ROM_MBC1()
and SWITCH_ROM_MBC5, or when a BANKED function is called.
Normaly banked calls are used and the active bank does not need to be directly managed, but in the case that it
does the following shows how to save and restore it.
// The current bank can be saved
uint8_t _saved_bank = _current_bank;
// Call some function which changes the bank but does not restore it
// ...
// And then restored if needed
SWITCH_ROM(_saved_bank);
6.3 Auto-Banking
A ROM bank auto-assignment feature was added in GBDK 2020 4.0.2.
Instead of having to manually specify which bank a source file will reside in, the banks can be assigned automatically
to make the best use of space. The bank assignment operates on object files, after compiling/assembling and before
linking.
To turn on auto-banking, use the -autobank argument with lcc.
For a source example see the banks_autobank project.
In the source files you want auto-banked, do the following:
• Set the source file to be autobanked #pragma bank 255 (this sets the temporary bank to 255, which
bankpack then updates when repacking).
• Create a reference to store the bank number for that source file: BANKREF(<some-bank-reference-name>).
– More than one BANKREF() may be created per file, but they should always have unique names.
In the other source files you want to access the banked data from, do the following:
Example: level_1_map.c
#pragma bank 255
BANKREF(level_1_map)
...
const uint8_t level_1_map[] = {... some map data here ...};
Accessing that data: main.c
BANKREF_EXTERN(level_1_map)
...
SWITCH_ROM( BANK(level_1_map) );
// Do something with level_1_map[]
Features and Notes:
• Fixed banked source files can be used in the same project as auto-banked source files. The bankpack tool
will attempt to pack the auto-banked source files as efficiently as possible around the fixed-bank ones.
Recommended:
.c and .s -> (compiler) .o -> (bankpack) -> .rel -> (linker) ... -> .gb
• It is important because when bankpack assigns a bank for an autobanked (bank=255) object file (.o) it rewrites
the bank and will then no longer see the file as one that needs to be auto-banked. That file will then remain
in its previously assigned bank until a source change causes the compiler to rebuild it to an object file again
which resets its bank to 255.
• For example consider a fixed-bank source file growing too large to share a bank with an auto-banked source
file that was previously assigned to it. To avoid a bank overflow it would be important to have the auto-banked
file check every time whether it can share that bank or not.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
26
• The SWITCH_ROM_MBC5 macro is not interrupt-safe. If using less than 256 banks you may always use
SWITCH_ROM - that is faster. Even if you use mbc5 hardware chip in the cart.
• Banks_new: examples of using new bank assignment and calling conventions available in GBDK 2020 and
its updated SDCC version.
• Banks_farptr: using far pointers which have the bank number built into the pointer.
• Banks_autobank: shows how to use the bank auto-assignment feature in GBDK 2020 4.0.2 or later,
instead of having to manually specify which bank a source file will reside it.
7 GBDK Toolchain
7.1 Overview
GBDK 2020 uses the SDCC compiler along with some custom tools to build Game Boy ROMs.
• The typical order of tools called is as follows (when using lcc these steps are usually performed automatically).
1. Compile and assemble source files (.c, .s, .asm) with sdcc and sdasgb
2. Optional: perform auto banking with bankpack on the object files
3. Link the object files into .ihx file with sdldgb
4. Validate the .ihx file with ihxcheck
5. Convert the .ihx file to a ROM file (.gb, .gbc) with makebin
To see individual arguments and options for a tool, run that tool from the command line with either no arguments or
with -h.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
7.3 Changing Important Addresses 27
• _shadow_OAM
• .STACK
• .refresh_OAM
– Address to which the routine for refreshing OAM will be copied (must be in HIRAM). Default
– Default -Wl-g .refresh_OAM=0xFF80
• _DATA
• _CODE
• Compile the C source 'source.c', assemble and link it producing the Gameboy image 'image.gb'
• Assemble the file 'source.s' and link it producing the Gameboy image 'image.gb'
• Compile the C program 'source1.c' and assemble it producing the object file 'object1.o' for later linking.
• Assemble the file 'source2.s' producing the object file 'object2.o' for later linking
• Link the two object files 'object1.o' and 'object2.o' and produce the Gameboy image 'image.gb'
• Do all sorts of clever stuff by compiling then assembling source1.c, assembling source2.s and then linking
them together to produce image.gb.
Arguments to the assembler, linker, etc can be passed via lcc using -Wp..., -Wf..., -Wa... and -Wl... to pass
options to the pre-processor, compiler, assembler and linker respectively. Some common options are:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
28
-Wa-l
-Wl-m
-Wl-gvar=addr
For example, to compile the example in the memory section and to generate a listing and map file you would
use the following. Note the leading underscore that C adds to symbol names.
7.4.1 Makefiles
Please see the sample projects included with GBDK-2020 for a couple different examples of how to use Makefiles.
You may also want to read a tutorial on Makefiles. For example:
https://makefiletutorial.com/
https://www.tutorialspoint.com/makefile/index.htm
When bankpack is called through lcc it will now always use linkerfile output (-lkout=) for passing files to the linker
(all input object files and linkerfiles will get get consolidated to a single linkerfile).
Bankpack:
• -lkout=<filename> : Enables linkerfile output and sets name (only one can be specified). ALL loaded
object files, both from the command line and any loaded from linkerfiles will have their names written to this
single output.
LCC + Bankpack:
• lcc clears out the linker object file and linkerfile lists, then uses the single linkerfile generated by bankpack
lcc is the compiler driver (front end) for the GBDK/sdcc toolchain.
For detailed settings see lcc-settings
It can be used to invoke all the tools needed for building a rom. If preferred, the individual tools can be called directly.
• the -v flag can be used to show the exact steps lcc executes for a build
• lcc can compile, link and generate a binary in a single pass: lcc -o somerom.gb somesource.c
• lcc now has a -debug flag that will turn on the following recommended flags for debugging
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
7.5 Build Tools 29
7.5.2 sdcc
• Arguments can be passed to it through lcc using -Wf-<argument> and -Wp-<argument> (pre-
processor)
7.5.3 sdasgb
7.5.4 bankpack
7.5.5 sdldgb
7.5.6 ihxcheck
• It will warn if there are multiple writes to the same ROM address. This may indicate mistakes in the code or
ROM bank overflows
7.5.7 makebin
Converts .ihx files produced by sdldgb into ROM files (.gb, .gbc). Also used for setting some ROM header data.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
30
Compression utility.
For detailed settings see gbcompress-settings
Compresses (and decompresses) binary file data with the gbcompress algorithm (also used in GBTD/GBMB).
Decompression support is available in GBDK:
The utility can also compress (and decompress) using block style RLE encoding with the --alg=rle flag. De-
compression support is available in GBDK:
• rle_init(), rle_decompress()
7.6.2 png2asset
Tool for converting PNGs into GBDK format MetaSprites and Tile Maps.
• Convert single or multiple frames of graphics into metasprite structured data for use with the ...metasprite...()
functions.
• When -map is used, converts images into Tile Maps and matching Tile Sets
• Supports Game Boy 2bpp, GBC 4bpp, SGB 4bpp, and SMS/GG 4bpp
• The origin (pivot) for the metasprite is not required to be in the upper left-hand corner as with regular hardware
sprites. See -px and -py.
• The conversion process supports using both SPRITES_8x8 (-spr8x8) and SPRITES_8x16 mode
(-spr8x16). If 8x16 mode is used then the height of the metasprite must be a multiple of 16.
• Original Game Boy and Game Boy Pocket style hardware: DMG
7.6.2.1.2 Conversion Process png2asset accepts any png as input, although that does not mean any image
will be valid. The program will follow the next steps:
• If there are more than 4 colors in the palette it will throw an error.
• The palette will be sorted from darkest to lightest. If there is a transparent color that will be the first one (this
will create a palette that will also work with DMG devices).
• If there are more than 8 palettes the program will throw an error.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
7.6 GBDK Utilities 31
With all this, the program will generate a new indexed image (with palette), where each 4 colors define a palette and
all colors within a tile can only have colors from one of these palettes
It is also posible to pass a indexed 8-bit png with the palette properly sorted out, using -keep_palette_order
• Palettes will be extracted from the image palette in groups of 4 colors.
• Each tile can only have colors from one of these palettes per tile.
• Tiles will be matched without mirror, using vertical mirror, horizontal mirror or both (use -noflip to turn off
matching mirrored tiles).
• The palette won't be taken into account for matching, only the pixel color order, meaning there will be a match
between tiles using different palettes but looking identical on grayscale.
7.6.2.1.3 Maps Passing -map the png can be converted to a map that can be used in both the background and
the window. In this case, png2asset will generate:
• The palettes
• The tileset
• The map
– By default, an array of palette index for each tile. This is not the way the hardware works but it takes
less space and will create maps compatibles with both DMG and CGB devices.
– Passing -use_map_attributes will create an array of map attributes. It will also add mirroring info
for each tile and because of that maps created with this won't be compatible with DMG.
* Use -noflip to make background maps which are compatible with DMG devices.
7.6.2.1.4 Meta sprites By default the png will be converted to metasprites. The image will be subdivided into
meta sprites of -sw x -sh. In this case png2asset will generate:
• The metasprites, containing an array of:
– tile index
– y offset
– x offset
– flags, containing the mirror info, the palettes for both DMG and GBC and the sprite priority
7.6.2.1.5 Super Game Boy Borders (SGB) Screen border assets for the Super Game Boy can be generated
using png2asset.
The following flags should be used to perform the conversion:
• <input_border_file.png> -map -bpp 4 -max_palettes 4 -pack_mode sgb -use←-
_map_attributes -c <output_border_data.c>
• Where <input_border_file.png> is the image of the SGB border (256x224) and <output_←-
border_data.c> is the name of the source file to write the assets out to.
See the sgb_border example project for more details.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
32
7.6.3 makecom
Converts a binary .rom file to .msxdos com format, including splitting the banks up into separate files.
7.6.4 png2hicolorgb
An updated version of Glen Cook's Windows GUI "hicolour.exe" 1.2 conversion tool for the Game Boy Color. The
starting code base was the 1.2 release.
• For detailed settings see Hi Color on the Game Boy Color is a technique for displaying backgrounds with
thousands of colors instead being limtied to 32 colors for the entire screen background. It achieves this by
changing ∼16 colors of the background palette per scanline. The main tradeoffs are that it uses much of
the Game Boy's available cpu processing per frame and requires more ROM space. The tile patterns, map,
attributes and per-scanline palettes are pre-calculated using the PC based conversion tool.
7.6.4.1 Additional Details For technical details about the conversion process and rendering, see: https←-
://github.com/bbbbbr/png2hicolorgb
• Sega Consoles
• NES/Famicom (NES)
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. See below for available settings.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.2 Cross Compiling for Different Consoles 33
8.2.2 sdcc
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:
When linking:
MSXDOS requires an additional build step with makecom after makebin to create the final binary:
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
– lcc : -msm83:gb
– port:sm83, plat:gb
• Analogue Pocket
– lcc : -msm83:ap
– port:sm83, plat:ap
– lcc : -msm83:duck
– port:sm83, plat:duck
– lcc : -mz80:sms
– port:z80, plat:sms
– lcc : -mz80:gg
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
34
– port:z80, plat:gg
• NES
– lcc : -mmos6502:nes
– port:mos6502, plat:nes
• MSX DOS
– lcc : -mz80:msxdos
– port:z80, plat:msxdos
Constants that describe properties of the console hardware are listed below. Their values will change to reflect the
current console target that is being built.
• DEVICE_SCREEN_X_OFFSET, DEVICE_SCREEN_Y_OFFSET
• DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT
• DEVICE_SCREEN_BUFFER_WIDTH, DEVICE_SCREEN_BUFFER_HEIGHT
• DEVICE_SCREEN_MAP_ENTRY_SIZE
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.4 Using <gbdk/...> headers 35
• DEVICE_SPRITE_PX_OFFSET_X, DEVICE_SPRITE_PX_OFFSET_Y
• DEVICE_SCREEN_PX_WIDTH, DEVICE_SCREEN_PX_HEIGHT
• MAX_HARDWARE_SPRITES
• HARDWARE_SPRITE_CAN_FLIP_X, HARDWARE_SPRITE_CAN_FLIP_Y
Instead of
#include <gb/gb.h>
#include <gb/metasprites.h>
and
#include <sms/sms.h>
#include <sms/metasprites.h>
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_bkg_native_data() to load the assets tiles in native format
to the tile memory used for background tiles on that platform.
• Sprites:
– 256 tiles (upper 128 are shared with background) (amount is doubled in CGB mode)
– tile flipping/mirroring: yes
– 40 total, max 10 per line
– 2 x 4 color palette (color 0 transparent). 8 x 4 color palettes in CGB mode
• Background: 256 tiles (typical setup: upper 128 are shared with sprites) (amount is doubled in CGB mode)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
36
• SMS
• GG
NES/Famicom
• Sprites:
– 8x8 or 8x16
– 256 tiles
– tile flipping/mirroring: yes
– 64 total, max 8 per line
– 4 x 4 color palette (color 0 transparent)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.7 Using Game Boy Color (CGB) Features 37
GB/AP
– VRAM and some other display data / registers should only be written to when the STATF_B_BUSY bit
of STAT_REG is off. Most GBDK API calls manage this automatically.
SMS/GG
– Writing to the VDP should not be interrupted while an operation is already in progress (since that will
interfere with the internal data pointer causing data to be written to the wrong location).
– Recommended approach: Avoid writing to the VDP (tiles, map, scrolling, colors, etc) during an interrupt
routine (ISR).
– Alternative (requires careful implementation): Make sure writes to the VDP during an ISR are only
performed when the _shadow_OAM_OFF flag indicates it is safe to do so.
NES/Famicom
These are some of the main hardware differences between the Regular Game Boy and the Game Boy Color.
• IR Port
• Sprites:
– 2 banks x 256 tile patterns (2x as many) (typically upper 128 of each bank shared with background)
– 8 x 4 color palettes in CGB mode (BGR-555 per color, 32768 color choices)
• Background:
– 2 banks x 256 tile patterns (2x as many) (typically upper 128 of each bank shared with sprites)
– Second map bank for tile attributes (color, flipping/mirroring, priority, bank)
– 8 x 4 color palettes in CGB mode (BGR-555 per color, 32,768 color choices))
– BG and Window master priority
These are some of the main GBDK API features for the CGB. Many of the items listed below link to additional
information.
• Color:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
38
– set_bkg_palette(), set_bkg_palette_entry()
– set_sprite_palette(), set_sprite_palette_entry()
– set_default_palette()
– RGB(), RGB8(), RGBHTML()
Several examples in GBDK show how to use CGB features, including the following:
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.
– 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
• MBC1 and MBC5 are supported, MBC3 won't save and RTC doesn't progress when game is not running, the
HuC3 isn't supported at all (via JoseJX and sg).
• The IR port in CGB mode does not work as reliably as the Game Boy Color
In order for software to be easily ported to the Analogue Pocket, or to run on both, use the following practices.
8.8.1.3 Registers and Flags Use API defined registers and register flags instead of hardwired ones.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.8 Porting Between Supported Consoles 39
8.8.1.4 Boot logo As long as the target console is set during build time then the correct boot logo will be auto-
matically selected.
• The SMS/GG ROM file size must be at least 64K to enable mapper support for RAM banks in emulators.
– If the generated ROM is too small then -yo 4 for makebin (or -Wm-yo4 for LCC) can be used to set
the size to 64K.
• set_bkg_data() and set_sprite_data() will load 2bpp tile data in "Game Boy" format on both GB and SMS/GG.
• On the SMS/GG set_2bpp_palette() sets 4 colors that will be used when loading 2bpp assets with
set_bkg_data(). This allows GB assets to be easily colorized without changing the asset format. There is
some performance penalty for using the conversion.
8.8.2.2.2 Tile and Map Data in Native Format Use the following api calls when assets are avaialble in the native
format for each platform.
set_native_tile_data()
set_tile_map()
8.8.2.2.3 Emulated Game Boy Color map attributes on the SMS/Game Gear 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.
Note
Tile map attributes on SMS/Game Gear use different control bits than the Game Boy Color, so a modified
attribute map must be used.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
40
The NES graphics architecture is similar to the GB's. However, there are a number of design choices in the NES
hardware that make the NES a particularly cumbersome platform to develop for, and that will require special atten-
tion.
Most notably:
• PPU memory can only be written in a serial fashion using a data port at 0x2007 (PPUDATA)
• PPU memory can only be written to during vblank, or when manually disabling rendering via PPUMASK.
Hblank writes to PPU memory are not possible
• PPU memory write address is re-purposed for scrolling coordinates when rendering is enabled which means
PPU memory updates / scrolling must cooperate
• PPU internal palette memory is also mapped to external VRAM area making palette updates during rendering
very expensive and error-prone
• The base NES system has no support for any scanline interrupts. And cartridge mappers that add scanline
interrupts do so using wildly varying solutions
• There's no easy way to determine the current scanline or CPU-to-PPU alignment meaning timed code is often
required on the NES
• The PAL variant of the NES has very different CPU / PPU timings, as do the Dendy clone and other clone
systems
To provide an easier experience, gbdk-nes attempts to hide most of these quirks so that in theory the programming
experience for gbdk-nes should be as close as possible to that of the GB/GBC. However, to avoid surprises it is
recommended to familiarize yourself with the NES-specific quirks and implementation choices mentioned here.
This entire section is written as a guide on porting GB projects to NES. If you are new to GBDK, you may wish to
familiarize yourself with using GBDK for GB development first as the topics covered will make a lot more sense after
gaining experience with GB development.
8.8.3.1 Buffered mode vs direct mode On the GB, the vblank period serves as an optimal time to write data to
PPU memory, and PPU memory can also be written efficiently with VRAM DMA.
On the NES, writing PPU memory during the vblank period is not optional. Whenever rendering is turned on the
PPU is in a state where accessing PPU memory results in undefined behavior outside the short vblank period.
The NES also has no VRAM DMA hardware to help with data writes. This makes the vblank period not only more
precious, but important to never exceed to avoid glitched games.
To deal with this limitation, all functions in gbdk-nes that write to PPU memory can run in either Buffered or Direct
mode.
The good news is that switching between buffered and direct mode in gbdk-nes is usually done behind-the-scenes
and normally shouldn't affect your code too much, as long as you use the portable GBDK functions and macros to
do this.
• DISPLAY_ON / SHOW_BG / SHOW_SPR will all switch the system into buffered mode, allowing limited
amounts of transfers during vblank, not the display of graphics
• DISPLAY_OFF will switch the system into direct mode, allowing much larger/faster transfers while the screen
is blanked
The following sections describe how the buffered / direct modes work in more detail. As buffered / direct mode is
mostly hidden by the API calls, feel free to skip these sections if you wish.
8.8.3.1.1 Buffered mode implementation details To take maximum advantage of the short vblank period,
gbdk-nes implements the same system as nearly every other NES engine: An unrolled loop that pulls prepared
data bytes from the stack.
PLA
STA PPUDATA
...
PLA
STA PPUDATA
RTS
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.8 Porting Between Supported Consoles 41
The data structure to facilitate this is usually called a vram transfer buffer, often affectionately called a "popslide"
buffer after Damian Yerrick's implementation. This buffer essentially forms a list of commands where each comand
sets up a new PPU address and then writes a sequence of bytes with an auto-increment of either +1 or +32. Each
such command is often called a "stripe" in the nesdev community.
It starts at 0x100 and takes around half of the hardware stack page. You can think of the transfer buffer as a software-
implemented DMA that allows writing bytes at the optimal rate of 8 cycles / byte. (ignoring the PPU address setup
cost)
The buffer allows writing up to 32 continuous bytes at a time. This allows updating a full screen row / column, or two
8x8 tiles worth of tile data in one command / "stripe".
By doing writes to this buffer during game logic, your game will effectively keep writing data transfer commands for
the vblank NMI handler to process in the next vblank period, without having to wait until the vblank.
Given that transfer buffer only has space for around 100 data bytes, it is important to not overfill the buffer, as this
will bring code execution to a screeching halt, until the NMI handler empties the old contents of the buffer to free up
space to allow new commands to be written.
Buffered mode is typically used for scrolling updates or dynamically animated tiles, where only a small amount of
bytes need updating per frame.
8.8.3.1.2 Direct mode implementation details During direct mode, all graphics routines will write directly to the
PPUADDR / PPUDATA ports and the transfer buffer limit is never a concern because the transfer buffer is effectively
avoided.
Direct mode is typically used for initializing large amounts of tile data at boot and/or level loading time. Unless you
plan to have an animated loading screen and decompress a lot of data, it makes more sense to just fade the screen
to black and allow direct mode to write data as fast as possible.
8.8.3.1.3 Caveat: Make sure the transfer buffer is emptied before switching to direct mode Because the
switch to the direct mode is instant and doesn't wait for the next invocation of the vblank, it is possible to create
situations where there is still remaining data in the transfer buffer that would only get written once the system is
switched back to buffered mode.
To avoid this situation, make sure to always "drain" the buffer by doing a call to wait_vbl_done when you expect your
code to finish.
8.8.3.1.4 Caveat: Only update the PPU palette during buffered mode The oddity that PPU palette values are
accessed through the same mechanism as other PPU memory bytes comes with the side effect that the vblank NMI
handler will only write the palette values in buffered mode.
The reason for this design choice is two-fold:
• Having the NMI handler keep doing the palette updates when in direct mode would result in a race condition
when the NMI handler interrupts the direct mode code and messes with the PPUADDR state that the direct
mode code expects to remain unchanged
• Having the palette updates also switch to direct mode would run into another quirk of the system: Pointing
PPUADDR at palette registers when display is turned off will make the display output that palette color instead
of the common background color. The result would be glitchy artifacts on screen when updating the palette,
leading to slightly-glitchy looking game whenever the palette is updated with the screen off
To work around this, you are advised to never fully turn the display off during a palette fade. If you don't follow this
advice all your palette updates will get delayed until the screen is turned back on.
8.8.3.2 Shadow PPU registers Like the SMS, the NES hardware is designed to only allow loading the full X/Y
scroll on the very first scanline. i.e., under normal operation you are only allowed to change the Y-scroll once.
In contrast to the SMS, this limitation can be circumvented with a specific set of out-of-order writes to the
PPUSCROLL/PPUADDR registers, taking advantage of the quirk that the PPUADDR and PPUSCROLL share reg-
ister bits. But this write sequence is very timing-sensitive as the writes need to fall into (a smaller portion of) the
hblank period in order to avoid race conditions when the CPU and PPU both try to update the same register during
scanline rendering.
To simplify the programming interface, gbdk-nes functions like move_bkg / scroll_bkg only ever update shadow
registers in RAM. The vblank NMI handler will later pick these values up and write them to the actual PPU registers
registers.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
42
8.8.3.3 Implementation of (fake) vbl / lcd handlers GBDK provides an API for installing Interrupt Service
Routines that execute on start of vblank (VBL handler), or on a specific scanline (LCD handler).
But the base NES system has no suitable scanline interrupts that can provide such functionality. So instead, gbdk-
nes API allows fake handlers to be installed in the goal of keeping code compatible with other platforms.
• An installed VBL handler will be called immediately when calling wait_vbl_done. This handler should only
update PPU shadow registers
• An installed LCD handler for a specific scanline will be called after the vblank NMI handler has finished
execution, and will then manually run a delay loop to reach that scanline before calling your installed LCD
handler.
Because the LCD "ISR" is actually implemented with a delay loop, it will burn a lot of CPU cycles in the frame - the
further down the scanline is the larger the CPU cycle loss. In practice this makes this faked-LCD-ISR functionality
only suited for status bars at the top screen, or simple parallax cutscenes where the CPU has little else to do.
Note
The support for VBL and LCD handlers is currently under consideration and subject to change in newer
versions of gbdk-nes.
8.8.3.4 Caveat: Make sure to call wait_vbl_done on every frame On the GB, the call to wait_vbl_done is an
optional call that serves two purposes:
On gbdk-nes the second point is no longer true, because writes need to be made to the shadow registers before
wait_vbl_done is called.
But the wait_vbl_done call serves two other very important purposes:
A. It calls the optional VBL handler, where shadow registers can be written (and will later be picked up by the actual
vblank NMI handler) B. It calls flush_shadow_attributes so that updates to background attributes actually get written
to PPU memory
For these reasons you should always include a call to wait_vbl_done if you expect to see any graphical updates on
the screen.
8.8.3.5.2 Tile and Map Data in Native Format Use the following api calls when assets are avaialble in the native
format for each platform.
set_native_tile_data()
• GB/AP: loads 2bpp tiles data
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
8.8 Porting Between Supported Consoles 43
8.8.3.5.3 Game Boy Color map attributes on the NES 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 of setting VBK_REG to specify tile indices/attributes is not supported on the NES platform. Instead
the dedicated functions for attribute setting should be used. These will work on other platforms as well and are the
preferred way to set attributes.
To maintain API compatibility with other platforms that have attributes on an 8x8 grid specified with a whole byte per
attribute, the NES platform supports the dedicated calls for setting attributes on an 8x8 grid:
• set_bkg_attributes()
• set_bkg_submap_attributes()
• set_bkg_attribute_xy()
This allows code to for attribute setting to remain unchanged between platforms. The effect of using these calls is
that some attribute setting will be redundant due to the coarser attribute grid. i.e., setting the attribute at coordinates
(4, 4), (4,5), (5, 4) and (5, 5) will all set the same attribute.
There is one more platform specific difference to note: While the set_bkg_attribute_xy() function takes coordinates
on a 8x8 grid, the set_bkg_attributes() and set_bkg_submap_attributes() functions take a pointer to data in NES
packed attribute format, where each byte contains data for 4 16x16 attribute. i.e. a 32x32 region.
While this implementation detail of how the attribute map is encoded is usually hidden by the API functions it does
mean that code which manually tries to read the attribute data is NOT portable between NES/other platforms, and
is not recommended.
Note
Tile map attributes on NES are on a 16x16 grid and use different control bits than the Game Boy Color.
• NES 16x16 Tile Attributes are bit packed into 4 attributes per byte with each 16x16 area of a 32x32 pixel
block using the bits as follows:
– D1-D0: Top-left 16x16 pixels
– D3-D2: Top-right 16x16 pixels
– D5-D4: Bottom-left 16x16 pixels
– D7-D6: Bottom-right 16x16 pixels
– https://www.nesdev.org/wiki/PPU_attribute_tables
The Mega Duck is (for practical purposes) functionally identical to the Original Game Boy though it has a couple
changes listed below.
• MBC ROM bank switching register address: 0x0001 (many Game Boy MBCs use 0x2000 - 0x3FFF)
8.8.4.2 Best Practices 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).
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
44
8.8.4.3 Sound Register Value Changes There are two hardware changes which will not be handled automati-
cally when following the practices mentioned above.
These changes may be required when using existing Sound Effects and Music Drivers written for the Game Boy.
1. Registers NR12_REG, NR22_REG, NR42_REG, and NR43_REG have their contents nybble swapped.
• To maintain compatibility the value to write (or the value read) can be converted this way: ((uint8←-
_t)(value << 4) | (uint8_t)(value >> 4))
2. Register NR32_REG has the volume bit values changed.
8.8.4.4 Graphics Register Bit Changes These changes are handled automatically when their GBDK definitions
are used.
8.8.4.5 Detailed Register Address Changes These changes are handled automatically when their GBDK def-
initions are used.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
9 Example Programs 45
9 Example Programs
GBDK includes several example programs both in C and in assembly. They are located in the examples directory,
and in its subdirectories. They can be built by typing make in the correnponding directory.
9.2 comm
Illustrates how to use communication routines.
9.3 crash
Demonstrates how to use the optional GBDK crash handler which dumps debug info to the Game Boy screen in the
event of a program crash.
9.4 colorbar
The colorbar program, written by Mr. N.U. of TeamKNOx, illustrates the use of colors on a Color GameBoy.
9.5 dscan
Deep Scan is a game written by Mr. N.U. of TeamKNOx that supports the Color GameBoy. Your aim is to destroy the
submarines from your boat, and to avoid the projectiles that they send to you. The game should be self-explanatory.
The following keys are used:
RIGHT/LEFT : Move your boat
A/B : Send a bomb from one side of your boat
START : Start game or pause game
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
46
9.6 filltest
Demonstrates various graphics routines.
9.7 fonts
Examples of how to work with the built in font and printing features.
9.8 galaxy
A C translation of the space.s assembly program.
9.9 gb-dtmf
The gb-dtmf, written by Osamu Ohashi, is a Dual Tone Multi-Frequency (DTMF) generator.
9.10 gbdecompress
Demonstrates using gbdecompress to load a compressed tile set into VRAM.
9.11 irq
Illustrates how to install interrupt handlers.
9.13 metasprites
Demonstrates using the metasprite features to move and animate a large sprite.
• Press SELECT button to cycle the metasprite through Normal / Flip-Y / Flip-XY / Flip-X
9.15 paint
The paint example is a painting program. It supports different painting tools, drawing modes, and colors. At the
moment, it only paints individual pixels. This program illustrates the use of the full-screen drawing library. It also
illustrates the use of generic structures and big sprites.
Arrow keys : Move the cursor
SELECT : Display/hide the tools palette
A : Select tool
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
9.16 rand 47
9.16 rand
The rand program, written by Luc Van den Borre, illustrates the use of the GBDK random generator.
9.17 ram_fn
The ram_fn example illustrates how to copy functions to RAM or HIRAM, and how to call them from C.
9.18 rpn
A basic RPN calculator. Try entering expressions like 12 134∗ and then 1789+.
9.19 samptest
Demonstration of playing a sound sample.
9.21 sound
The sound example is meant for experimenting with the sound generator of the GameBoy (to use on a real Game←-
Boy). The four different sound modes of the GameBoy are available. It also demonstrates the use of bit fields in C
(it's a quick hack, so don't expect too much from the code). The following keys are used:
UP/DOWN : Move the cursor
RIGHT/LEFT : Increment/decrement the value
RIGHT/LEFT+A : Increment/decrement the value by 10
RIGHT/LEFT+B : Set the value to maximum/minimum
START : Play the current mode’s sound (or all modes if in control screen)
START+A : Play a little music with the current mode’s sound
SELECT : Change the sound mode (1, 2, 3, 4 and control)
SELECT+A : Dump the sound registers to the screen
9.22 space
The space example is an assembly program that demonstrates the use of sprites, window, background, fixed-point
values and more. The following keys are used:
Arrow keys : Change the speed (and direction) of the sprite
Arrow keys + A : Change the speed (and direction) of the window
Arrow keys + B : Change the speed (and direction) of the background
START : Open/close the door
SELECT : Basic fading effect
9.23 templates
Two basic template examples are provided as a starting place for writing your GBDK programs.
– The simplest way is to use the Game Boy sound hardware directly. See the Sound Example for a way
to test out sounds on the hardware.
– Further discussion on using the Sound Example rom can be found in the ZGB wiki. Note that some
example code there is ZGB specific and not part of the base GBDK API: https://github.←-
com/Zal0/ZGB/wiki/Sounds
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
48
10.2 Licensing
• What license information is required when distributing the compiled ROM (binary) of my game or program?
– There is no requirement to include or credit any of the GBDK-2020 licenses or authors, although credit
of GBDK-2020 is appreciated.
– This is different and separate from redistributing the GBDK-2020 dev environment itself (or the GBDK-
2020 sources) which does require the licenses.
– Use the makebin -yn flag. For example with lcc -Wm-yn"MYTITLE" or with makebin directly -yn
"MYTITLE". The maximum length is up to 15 characters, but may be shorter.
– See "0134-0143 - Title" in Pandocs for more details.
• How do I set SGB, Color only and Color compatibility in the ROM header?
– Use the following makebin flags. Prefix them with -Wm if using lcc.
• How do I set the ROM MBC type, and what MBC values are available to use with the -yt makebin flag?
– See setting_mbc_and_rom_ram_banks
10.5 Errors
• What does the error old "gbz80" SDCC PORT name specified (in "-mgbz80:gb").
Use "sm83" instead. You must update your build settings. mean?
– The PORT name for the Game Boy and related clones changed from gbz80 to sm83 in the SDCC
version used in GBDK-2020 4.1.0 and later. You must change your Makefile, Build settings, etc to use
the new name. Additional details in the Console Port and Platform Settings section.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
10.5 Errors 49
– You must rebuild the object files using sm83 with GBDK-2020 4.1.0 or later so that the linker is able
to use them with the other object files. Additional details in the Console Port and Platform Settings
section.
• What do these kinds of warnings / errors mean? WARNING: possibly wrote twice at addr
4000 (93->3E) Warning: Write from one bank spans into the next. 7ff7
-> 8016 (bank 1 -> 2)
– You may have a overflow in one of your ROM banks. If there is more data allocated to a bank than it can
hold it then will spill over into the next bank.
A common problem is when there is too much data in ROM0 (the lower 16K unbanked region) and it
spills over into ROM1 (the first upper 16K banked region). Make sure ROM0 has 16K or less in it.
The warnings are generated by ihxcheck during conversion of an .ihx file into a ROM file.
See the section ROM/RAM Banking and MBCs for more details about how banks work and what their
size is. You may want to use a tool such as romusage to calculate the amount of free and used space.
• What do the following kinds of warnings / errors mean? info 218: z80instructionSize()
failed to parse line node, assuming 999 bytes
– This is a known issue with SDCC, it should not cause actual problems and you can ignore the warning.
• Why is the compiler so slow, or why did it suddenly get much slower?
– This may happen if you have large initialized arrays declared without the const keyword. It's important
to use the const keyword for read-only data. See const_gbtd_gbmb and const_array_data
– It can also happen if C source files are #included into other C source files, or if there is a very large
source file.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
50
– You can use the lcc debug flag -debugto turn on debug output. It covers most uses and removes the
need to specify multiple flags such as -Wa-l -Wl-m -Wl-j.
• Is it possible to generate a debug symbol file (.sym) compatible with the bgb emulator?
– Yes, turn on .noi output (LCC argument: -Wl-j or -debug and then use -Wm-yS with LCC (or
-yS with makebin directly).
• How do I move the start of the DATA section and the Shadow OAM location?
– The default locations are: _shadow_OAM=0xC000 and 240 bytes after it _DATA=0xC0A0
– So, for example, if you wanted to move them both to start 256(0x100) bytes later, use these command
line arguments for LCC:
• What does this warning mean? WARNING: overflow in implicit constant conversion
• Known issue: SDCC may fail on Windows when run from folder names with spaces on non-C drives.
– Functions
– Variables
– To correctly pass chars/uint8s for printing, they must be explicitly re-cast as such when calling the
function. See docs_chars_varargs for more details.
• How can maps larger than 32x32 tiles be scrolled? & Why is the map wrapping around to the left side when
setting a map wider than 32 tiles with set_bkg_data()?
– The hardware Background map is 32 x 32 tiles. The screen viewport that can be scrolled around that
map is 20 x 18 tiles. In order to scroll around within a much larger map, new tiles must be loaded at the
edges of the screen viewport in the direction that it is being scrolled. set_bkg_submap can be used to
load those rows and columns of tiles from the desired sub-region of the large map.
– See the "Large Map" example program and set_bkg_submap().
– Writes that exceed coordinate 31 of the Background tile map on the x or y axis will wrap around to the
Left and Top edges.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
11 Migrating to new GBDK Versions 51
• When using gbt_player with music in banks, how can the current bank be restored after calling gbt_update()?
(since it changes the currently active bank without restoring it).
• How can CGB palettes and other sprite properties be used with metasprites?
• Weird things are happening to my sprite colors when I use png2asset and metasprites. What's going on and
how does it work?
• GBDK now requires ∼SDCC 4.3 or higher with GBDK-2020 patches for the z80 and NES
– While the old functions will continue to work for now, migration to new versions is strongly encouraged
– vsync(): replaces wait_vbl_done()
– set_default_palette(): replaces cgb_compatibility()
– move_metasprite_flipy(): replaces move_metasprite_hflip()
– move_metasprite_flipx(): replaces move_metasprite_vflip()
– move_metasprite_flipxy(): replaces move_metasprite_hvflip()
– move_metasprite_ex(): replaces move_metasprite()
• The unused -DINT_16_BITS argument was removed from the default SDCC compiler and preprocessor
arguments (used in pre-GBDK2020 gbdk/include-gb/types.h)
• SMS/GG
• GBDK now requires SDCC 4.2 or higher with GBDK-2020 patches for the z80 linker
• The default calling convention changed in SDCC 4.2, see Calling Conventions for more details.
– If you are linking to libraries compiled with an older version of SDCC / GBDK then you may have to
recompile them.
– If there are existing functions written in ASM which receive parameters they should also be reviewed
to make sure they work with the new __sdcccall(1) calling convention, or have their header dec-
laration changed to use OLDCALL.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
52
– If there are existing functions written in ASM which call other functions written in C the callee C
function should be declared OLDCALL.
– Function pointer declarations should be checked to see if they need OLDCALL added to the declaration.
• The SDCC PORT name for the Game Boy and related clones changed from gbz80 to sm83.
– Additional details in the Console Port and Platform Settings section and FAQ entry. lcc will error out if
the old PORT name is passed in.
– Now they are VBL: 4 user handlers, LCD: 3 user handlers, SIO/TIM/JOY: 4 user handlers
– Aliases for the BGB_∗ ones and a bgb_emu.h shim are present for backward compatibility, but updat-
ing to the new naming is recommended
• Variables in static storage are now initialized to zero per C standard (but remaining WRAM is not cleared)
• lcc : Changed default output format when not specified from .ihx to .gb (or other active rom extension)
• Variables in static storage are now initialized to zero per C standard (but remaining WRAM is not cleared)
• itoa(), uitoa(), ltoa(), ultoa() all now require a radix value (base) argument to be passed. On the Game Boy
and Analogue Pocket the parameter is required but not utilized.
• The following header files which are now cross platform were moved from gb/ to gbdk/←-
: bcd.h, console.h, far_ptr.h, font.h, gbdecompress.h, gbdk-lib.h, incbin.h,
metasprites.h, platform.h, version.h
– When including them use #include <gbdk/...> instead of #include <gb/>
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
11.1 GBDK-2020 versions 53
• Important! : The WRAM memory region is no longer automatically initialized to zeros during startup.
– Any variables which are declared without being initialized may have indeterminate values instead of
0 on startup. This might reveal previously hidden bugs in your code.
– Check your code for variables that are not initialized before use.
– In BGB you can turn on triggering exceptions (options panel) reading from unitialized RAM. This allows
for some additional runtime detection of uninitialized vars.
• In .ihx files, multiple writes to the same ROM address are now warned about using ihxcheck.
• set_∗_tiles() now wrap maps around horizontal and vertical boundaries correctly. Code relying on it
not wrapping correctly may be affected.
• The old linker link-gbz80 has been REMOVED, the linker sdldgb from SDCC is used.
– Due to the linker change, there are no longer warnings about multiple writes to the same ROM address.
• GBDK now generates .ihx files, those are converted to a ROM using makebin (lcc can do this automatically
in some use cases)
• OAM symbol has been renamed to _shadow_OAM, that allows accessing shadow OAM directly from C code
• Behavior formerly enabled by USE_SFR_FOR_REG is on by default now (no need to specify it, it isn't a
tested #ifdef anymore). check here why: https://gbdev.gg8.se/forums/viewtopic.←-
php?id=697
• LCC was upgraded to use SDCC v4.0. Makefile changes may be required
– The symbol format changed. To get bgb compatible symbols turn on .noi output (LCC argument:
-Wl-j or -debug) and use -Wm-yS
– ?? Suggested: With LCC argument: -Wa-l (sdasgb:-a All user symbols made global)
– In SDCC 3.6.0, the default for char changed from signed to unsigned.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
54
• Change your int variables to long if they have to be bigger than 255. If they should only contain values
between 0 and 255, use an unsigned int.
• If your application uses the delay function, you'll have to adapt your delay values.
• Several functions have new names. In particular some of them have been changed to macros (e.g. show_←-
bkg() is now SHOW_BKG).
• You will probably have to change the name of the header files that you include.
2023/08
• Includes SDCC version ∼4.3 with GBDK-2020 patches for Z80 and NES
– ( Patched SDCC Builds with support for Sega GG/SMS and the Nintendo NES are used. See
the github workflow for details
• Known Issues
– SDCC may fail on Windows when run from folder names with spaces on non-C drives.
• Library
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 55
• Toolchain / Utilities
– Added png2hicolorgb
– lcc
* Fixed --sdccbindir
* Removed the unused -DINT_16_BITS from the default SDCC compiler and preprocessor argu-
ments
* Improved improved Game Gear header compatibility (change header region code from 4 to 6)
– png2asset
* Warn if RAM banks specified and file size of ROM is less than the 64K required to enable them
with in emulators
– Added sdld6808 (for NES)
• Examples
– Fixed mkdir broken in some compile.bat files (remove unsupported -p flag during bat file conversion)
– Sound Test: Added MegaDuck support
– Wav Playback: Improved support on AGB/AGS hardware
– Metasprites: Added sub-palette switching for GBC and NES, software metasprite flipping for sms/gg
– Large Map: Added color for supported platforms
– LCD ISR Wobble: Improved interrupt flag settings
– Added GB-Type example
– Added Game Boy Color Hi-Color example using png2hicolorgb
• Docs:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
56
2022/11
• Library
2022/10
• Known Issues
– The compile.bat batch files for Windows use the an invalid -p option for mkdir
• Building GBDK
– The linux port of SDCC is custom built on Ubuntu 16.04 due to reduced GLIBC compatibility issues in
more recent SDCC project builds.
– Added Windows 32-Bit build
• Platforms
• Licensing
– Clarified licensing status with consent from GBDK original authors, added licensing folder to distribution
• Library
* VBK_BANK_0, VBK_BANK_1
* VBK_TILES, VBK_ATTRIBUTES
* BKGF_PRI, BKGF_YFLIP, BKGF_XFLIP, BKGF_BANK0, BKGF_BANK1
* BKGF_CGB_PAL0, BKGF_CGB_PAL1, BKGF_CGB_PAL2, BKGF_CGB_PAL3, BKGF_CGB_PAL4,
BKGF_CGB_PAL5, BKGF_CGB_PAL6, BKGF_CGB_PAL7
* VBK_TILES, VBK_ATTRIBUTES
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 57
• Toolchain / Utilities
– lcc
* Changed to Error out and warn when gbz80 port is used instead of sm83
– png2asset
* Added --bank=<num> Add Bank Ref: 1 - 511 (default is none, with --cout only)
* Fixed failure to flush data at end of compression (uncommitted bytes)
* Fixed Warning: File read size didn't match expected
– lcc
* When -autobank is specified lcc will automatically add -yoA for makebin if no -yo∗ entry is
present
* Fixed broken -E Preprocess only flag
– makecom
* Fixed (via sdcc) bug with -yp not always working correctly
· https://sourceforge.net/p/sdcc/code/12975/
– bankpack
• Examples
– Changed Logo example to use new GBDK logo art from user "Digit"
– Added example for APA image mode with more than 256 tiles
– Added SGB Sound Effects example
– Changed to new WAV sound example
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
58
• Docs
2022/02
• Building GBDK
– Changed to target older version of macOS (10.10) when building for better compatibility
• Platforms
– Added support for Mega Duck / Cougar Boy (duck). See Supported Consoles & Cross Compiling
• Library
– Added memcmp()
– Added add_low_priority_TIM() function for timer interrupts which allow nesting for GB/CGB
– Added set_bkg_based_tiles(), set_bkg_based_submap(), set_win_based_tiles(), set_win_based_submap()
for when a map's tiles don't start at VRAM index zero
– Added clock() for SMS/GG
– Added macro definitions for SDCC features:
* Aliases for the BGB_∗ ones and a bgb_emu.h shim are present for backward compatibility
– Changed headers to wrap SDCC specific features (such as NONBANKED) with #ifdef __SDCC
– Changed rand() and arand() to return uint8_t instead of int8_t (closer to the standard)
– Fixed declaration for PCM_SAMPLE and definition for AUD3WAVE
– Fixed definition of size_t to be unsigned int instead of int
– Fixed vmemcpy() and memmove() for SMS/GG
– Fixed random number generation for SMS/GG
– Fixed letter U appearing as K for min font
– Fixed define name in crash_handler.h
– Exposed __rand_seed
• Toolchain / Utilities
– png2asset
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 59
* Changed makebin flags to turn off Nintendo logo copy for GB/CGB (use version in crt instead)
* Fixed lcc handling of makebin -x∗ arguments
• Examples
• Docs
2021/09
• Known Issues
• Added support for new consoles. See Supported Consoles & Cross Compiling
• Library
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
60
– Changed itoa(), uitoa(), ltoa(), ultoa() to now require a radix value (base) argument to be passed. On
the Game Boy and Analogue Pocket the parameter is required but not utilized.
• Examples
– Added cross-platform examples (build for multiple consoles: gb, ap, sms, gg)
– Added sms, gg, pocket(ap) examples
– Added incbin example
– Added simple physics sub-pixel / fixed point math example
– Added rle decompression example
– Changed windows make.bat files to compile.bat
– Bug fixes and updates for existing examples
• Toolchain / Utilities
– png2asset
* Added C source array format output (–cout) (optional variable name argument –varname=)
* Added C source array format input (–cin) (experimental)
* Added block style rle compression and decompression mode: --alg=rle
* Fixed comrpession errors when input size was larger than 64k
• Docs
2021/06
• Library
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 61
– Added set_tile_data()
– Fixed SGB detection
– Fixed broken get_tiles() / set_tiles()
– Fixed broken token handling in gb_decompress_sprite_data() / gb_decompress_bkg_data() /
gb_decompress_win_data()
– Changed all headers to use standard stdint.h types (ex: uint8_t instead of UINT8/UBYTE)
– Made sample.h, cgb.h and sgb.h independent from gb.h
• Examples
• Toolchain / Utilities
– png2mtspr
* Added option to change default value for sprite property/attributes in (allows CGB palette, BG/WIN
priority, etc).
* Improved: Turn off suppression of "blank" metasprite frames (composed of entirely transparent
sprites)
* Fixed endless loop for png files taller than 255 pixels
– bankpack
2021/03
• Library
– Added set_vram_byte()
– Added set_bkg_tile_xy() / set_win_tile_xy()
– Added get_bkg_xy_addr() / get_win_xy_addr()
– Added set_bkg_submap() / set_win_submap()
– Added metasprite api support
– Added gb_decompress support
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
62
• Examples
• Toolchain / Utilities
• Docs
– Added extensive documentation (some of which is imported and updated from the old gbdk docs)
– Added PDF version of docs
2021/01/17
• Includes SDCC snapshot build version 12016 (has a fix for duplicate debug symbols generated from inlined
header functions which GBDK 4.0+ uses)
• Updated documentation
– Linking with stdio.h does not require that much ROM now
– Default font is changed to the smaller one (102 characters), that leaves space for user tiles
– Fixed broken support for multiplying longs
– memset/memcpy minor enhancements
– safer copy-to-VRAM functions
– loading of 1bit data fixed, also now it is possible to specify pixel color
– Improved code generation for the GBDK Library with SDCC switch on by default: --max-allocs-per-node
50000
– fixed wrong parameter offsets in hiramcpy() (broken ram_function example)
– Multiple minor improvements
• New bankpack feature, allows automatic bank allocation for data and code, see banks_autobank example,
feature is in beta state, use with care
• Lcc improvements
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 63
2020/11/14
• IHX is checked for correctness before the makebin stage. That allows to warn about overwriting the same
ROM addresses (SDCC toolchain does not check this anymore).
– set_∗_tiles() now wrap maps around horizontal and vertical boundaries correctly
– new fill_∗_rect() functions to clear rectangle areas
– runtime initialization code now does not initialize whole WRAM with zeros anymore, that allows BGB to
raise exceptions when code tries to read WRAM that was not written before.
– enhanced SGB support
* Fix -S flag
* Fix default stack location from 0xDEFF to 0xE000 (end of WRAM1)
* Fix cleanup of .adb files with -Wf–debug flag
* Fix output not working if target is -o some_filename.ihx
2020/10/01
• GBDK now requires SDCC 4.0.3 or higher, that has fully working toolchain. Old link-gbz80 linker is not used
anymore, sdldgb and makebin are used to link objects and produce binary roms; maccer tool is no longer
needed either
– SDCC 4.0.3 has much better code generator which produces smaller and faster code. Code is twice
faster
– SOURCE LEVEL DEBUGGING is possible now! Native toolchain produces ∗.CDB files that contain
detailed debug info. Look for EMULICIOUS extension for vs.code. It supports breakpoints, watches,
inspection of local variables, and more!
– SDCC 4.0.4 has fixed RGBDS support; library is not updated to support that in full yet, but it is possible
to assemble and link code emitted by SDCC with RGDBS
– New banked trampolines are used, they are faster and smaller
– New (old) initialization for non-constant arrays do NOT require 5 times larger rom space than initialized
array itself, SDCC even tries to compress the data
– itoa/ltoa functions were rewritten, div/mod is not required now which is about 10 times faster
– sprite functions are inline now, which is faster up to 12 times and produces the same or smaller code;
.OAM symbol is renamed into _shadow_OAM that allows accessing shadow OAM directly from C code
– interrupt handling was revised, it is now possible to make dedicated ISR's, that is important for time-
sensitive handlers such as HBlank.
– printf/sprintf were rewritten and splitted, print functions are twice faster now and also requre less rom
space if you use sprintf() only, say, in bgb_emu.h
– crash_handler.h - crash handler that allows to detect problems with ROMs after they are being released
(adapted handler, originally written by ISSOtm)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
64
• Revised examples
2020/06/05
• Interrupt handlers now wait for lcd controller mode 0 or 1 by default to prevent access to inaccessible VRAM
in several functions (like set_bkg_tiles)
2020/05/17
2020/05/16
• Banked functions are working! The patcher is fully integrated in link-gbz80, no extra tools are needed. It is
based on Toxa's work
• Behavior formerly enabled by USE_SFR_FOR_REG is on by default now (no need to specify it, it isn't a
tested #ifdef anymore). check here why: https://gbdev.gg8.se/forums/viewtopic.←-
php?id=697
• Fixed examples that were not compiling in the previous version and some improvements in a few of them.
Removed all warnings caused by changing to the new SDCC
• Fixed bug in lcc that was causing some files in the temp folder not being deleted
• Removed as-gbz80 (the lib is now compiled with sdasgb thanks to this workaround)
https←-
://github.com/gbdk-2020/gbdk-2020/commit/d2caafa4a66eb08998a14b258cb66af041a0e5c8
• Profile support with bgb emulator
– Basic support including <gb/bgb_emu.h> and using the macros BGB_PROFILE_BEGIN and BGB←-
_PROFILE_END. More info in this post https://gbdev.gg8.se/forums/viewtopic.←-
php?id=703
– For full profiling check this repo and this post
https://github.com/untoxa/bgb_←-
profiling_toolkit/blob/master/readme.md https://gbdev.gg8.se/forums/viewtopic.←-
php?id=710
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.2 Historical GBDK Release Notes 65
2020/04/12
• Updated SDCC to v.4.0
2020/04/12
• Initial GBDK-2020 release
Updated SDCC to v4.0 The new linker is not working so the old version is still there There is an issue with
sdagb compiling drawing.s (the JP in line 32 after ".org .MODE_TABLE+4∗.G_MODE" it's writing more than 4
bytes invading some addresses required by input.s:41) Because of this, all .s files in libc have been assembled
with the old as-gbz80 and that's why it is still included
17 April, 2000
Many changes.
• Code generated is now much more reliable and passes all of sdcc's regression suite.
• Stopped lcc with sdcc from leaking .cdb files all across /tmp.
• Added a new lexer to sdcc. Compiling files with large initalised arrays takes 31% of the time (well, at least
samptest.c does :)
This is an experimental release for those who feel keen. The main change is a new lexer (the first part in the
compilation process which recognises words and symbols like '!=' and 'char' and turns them into a token number)
which speeds up compilation of large initialised arrays like tile data by a factor of three. Please report any bugs that
show up - this is a big change.
I have also included a 'minimal' release for win32 users which omits the documentation, library sources, and exam-
ples. If this is useful I will keep doing it.
• Changed the ways globals are exported, reducing the amount of extra junk linked in.
• Turned on the optimisations in flex. Large constant arrays like tile data should compile a bit faster.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
66
• no$gmb doesn't support labels of > 32 chars. The linker now trims all labels to 31 chars long.
• Fixed + and - for any type where sizeof == 2 and one of the terms was on the stack. This includes pointers
and ints. Fixes the text output bug in the examples. Should be faster now as well. Note that + and - for longs
is still broken.
• Added basic far function support. Currently only works for isas and rgbasm. See examples/gb/far/∗
• bc is now only pushed if the function uses it. i.e. something like: int silly(int i) { return i; }
will not have the push bc; pop bc around it.
• Better rgbasm support. Basically: o Use "sdcc -mgbz80 --asm=rgbds file.c" for each file.c o Use "sdcc
-mgbz80 --asm=rgbds crt0.o gbz80.lib gb.lib file1.o file2.o..."
to link everything together. The .lib files are generated using astorgb.pl and sdcc to turn the gbdk libraries into
something rgbds compatible. The libraries are not fully tested. Trust nothing. But give it a go :)
– Fixed SCY_REG += 2, SCY_REG -= 5 (add and subtract in indirect space) as they were both quite
broken.
– externs and static's now work as expected.
– You can now specify which bank code should be put into using a #pragma e.g: #pragma bank=HOME
Under rgbds and asxxxx putting code in the HOME bank will force the code into bank 0 - useful for
library functions. The most recent #pragma bank= will be the one used for the whole file.
– Fixed an interesting bug in the caching of lit addresses
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
12.2 Historical GBDK Release Notes 67
– Added support for accessing high registers directly using the 'sfr' directive. See libc/gb/sfr.s and
gb/hardware.h for an example. It should be possible with a bit of work to make high ram directly usable
by the compiler; at the moment it is experimental. You can test sfr's by enabling USE_SFR_FOR_←-
REG=1
– Added remove_VBL etc functions.
– Documented the libs - see the gbdk-doc tarball distributed seperatly.
– Two dimensional arrays seem to be broken.
• Added multi-bank support into the compiler - The old -Wf-boxx and -Wf-baxx options now work
• Has preliminary support for generating rgbds and ISAS compatible assembler. Try -W–asm=rgbds or -W–
asm=isas. The ISAS code is untested as I dont have access to the real assembler.
• RSH is fixed
• AND is fixed
• The missing parts of 2.1.0's libs are there. Note: They are untested.
• There is a bug with cached computed values which are later used as pointers. When the value is first used
as a BYTE arg, then later as a pointer the pointer fails as the high byte was never computed and is now
missing. A temporary fix is to declare something appropriate as 'volatile' to stop the value being cached. See
dscan.c/bombs() for an example.
– Now auto detects where it is installed. This can be overridden using set GBDKDIR=...
– Problems with the installer (now uses WinZip)
– Problems with the temp directory Now scans TMP, TEMP, TMPDIR and finally c: tmp
– cygwin1.dll and 'make' are no longer required gbdk is now built using mingw32 which is win32 native
make.bat is automagically generated from the Makefile
– I've reverted to using WORD for signed 16 bit etc. GBDK_2_COMPAT is no longer required.
WORDS are now back to signed. GBDK_2_COMPAT is no longer needed. Temporary files are created in TMP,
TEMP, or TMPDIR instead of c: tmp The installer is no more as it's not needed. There is a WinZip wrapped
version for those with the extra bandwidth :). gbdk autodetects where it is installed - no more environment variables.
cygwin1.dll and make are no longer required - gbdk is now compiled with mingw32.
See the ChangeLog section in the README for more information.
21st March, 2000
Problems with the installer. It seems that the demo of InstallVISE has an unreasonably short time limit. I had planed
to use the demo until the license key came through, but there's no sign of the key yet and the 3 day evaluation is
up. If anyone knows of a free Windows installer with the ability to modify environment variables, please contact me.
I hear that temporarily setting you clock back to the 15th works...
18th March, 2000
libc5 version available / "Error creating temp file" Thanks to Rodrigo Couto there is now a Linux/libc5 version of
gbdk3-2.92 available - follow the download link above. At least it will be there when the main sourceforge site
comes back up... Also some people have reported a bug where the compiler reports '∗∗∗ Error creating temp file'.
Try typing "mkdir c: tmp" from a DOS prompt and see if that helps.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
68
– Fixed problem with registers being cached instead of being marked volatile.
– More register packing - should be a bit faster.
– You can now install somewhere except c: gbdk | /usr/lib/gbdk
– Arrays initialised with constant addresses a'la galaxy.c now work.
– Fixed minor bug with 104$: labels in as.
– Up to 167d/s...
The compiler is the same, but some of the libraries have been improved. memset() and memcpy() are much faster,
malloc() is fixed, and a high speed fixed block alternative malloc() was added.
13 Toolchain settings
13.1 lcc settings
./lcc [ option | file ]...
except for -l, options are processed left-to-right before files
unrecognized options are taken to be linker options
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
13.2 sdcc settings 69
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
70
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
13.3 sdasgb settings 71
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
72
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
13.8 sdldz80 settings 73
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
74
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
13.14 png2asset settings 75
14 Todo List
File far_ptr.h
Add link to a discussion about banking (such as, how to assign code and variables to banks)
Page ROM/RAM Banking and MBCs
Variables in RAM
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
76
15 Module Index
15.1 C modules
Here is a list of all modules:
__far_ptr 79
_fixed 80
atomic_flag 80
isr_nested_vector_t 81
isr_vector_t 81
joypads_t 81
metasprite_t 83
OAM_item_t 84
sfont_handle 85
17 File Index
17.1 File List
Here is a list of all files with brief descriptions:
gbdk-lib/include/assert.h 106
gbdk-lib/include/ctype.h 107
gbdk-lib/include/limits.h 254
gbdk-lib/include/rand.h 315
gbdk-lib/include/setjmp.h 317
gbdk-lib/include/stdarg.h 89
gbdk-lib/include/stdatomic.h 343
gbdk-lib/include/stdbool.h 344
gbdk-lib/include/stddef.h 344
gbdk-lib/include/stdint.h 345
gbdk-lib/include/stdio.h 351
gbdk-lib/include/stdlib.h 352
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
17.1 File List 77
gbdk-lib/include/stdnoreturn.h 356
gbdk-lib/include/string.h 100
gbdk-lib/include/time.h 356
gbdk-lib/include/typeof.h 357
gbdk-lib/include/types.h 106
gbdk-lib/include/asm/types.h 102
gbdk-lib/include/asm/mos6502/provides.h 86
gbdk-lib/include/asm/mos6502/stdarg.h 87
gbdk-lib/include/asm/mos6502/string.h 89
gbdk-lib/include/asm/mos6502/types.h 100
gbdk-lib/include/asm/sm83/provides.h 86
gbdk-lib/include/asm/sm83/stdarg.h 88
gbdk-lib/include/asm/sm83/string.h 93
gbdk-lib/include/asm/sm83/types.h 101
gbdk-lib/include/asm/z80/provides.h 87
gbdk-lib/include/asm/z80/stdarg.h 88
gbdk-lib/include/asm/z80/string.h 97
gbdk-lib/include/asm/z80/types.h 104
gbdk-lib/include/gb/bcd.h 108
gbdk-lib/include/gb/bgb_emu.h 110
gbdk-lib/include/gb/cgb.h 111
gbdk-lib/include/gb/crash_handler.h 117
gbdk-lib/include/gb/drawing.h 117
gbdk-lib/include/gb/emu_debug.h 122
gbdk-lib/include/gb/gb.h 124
gbdk-lib/include/gb/gbdecompress.h 173
gbdk-lib/include/gb/hardware.h 176
gbdk-lib/include/gb/isr.h 221
gbdk-lib/include/gb/metasprites.h 223
gbdk-lib/include/gb/sgb.h 243
gbdk-lib/include/gbdk/bcd.h 110
gbdk-lib/include/gbdk/console.h 245
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
78
gbdk-lib/include/gbdk/emu_debug.h 122
gbdk-lib/include/gbdk/far_ptr.h 247
gbdk-lib/include/gbdk/font.h 249
gbdk-lib/include/gbdk/gbdecompress.h 175
gbdk-lib/include/gbdk/gbdk-lib.h 251
gbdk-lib/include/gbdk/incbin.h 252
gbdk-lib/include/gbdk/metasprites.h 229
gbdk-lib/include/gbdk/platform.h 253
gbdk-lib/include/gbdk/rledecompress.h 253
gbdk-lib/include/gbdk/version.h 254
gbdk-lib/include/msx/hardware.h 199
gbdk-lib/include/msx/metasprites.h 230
gbdk-lib/include/msx/msx.h 256
gbdk-lib/include/nes/hardware.h 208
gbdk-lib/include/nes/metasprites.h 232
gbdk-lib/include/nes/nes.h 279
gbdk-lib/include/nes/rgb_to_nes_macro.h 315
gbdk-lib/include/sms/gbdecompress.h 175
gbdk-lib/include/sms/hardware.h 212
gbdk-lib/include/sms/metasprites.h 238
gbdk-lib/include/sms/sms.h 318
18 Module Documentation
18.1 List of gbdk fonts
18.1.1 Description
Variables
• uint8_t font_spect [ ]
• uint8_t font_italic [ ]
• uint8_t font_ibm [ ]
• uint8_t font_min [ ]
• uint8_t font_ibm_fixed [ ]
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
19 Data Structure Documentation 79
Data Fields
• FAR_PTR ptr
• struct {
void ∗ ofs
uint16_t seg
} segofs
• struct {
void(∗ fn )(void)
uint16_t seg
} segfn
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
80
• gbdk-lib/include/gbdk/far_ptr.h
Data Fields
• struct {
UBYTE l
UBYTE h
};
• struct {
UBYTE l
UBYTE h
}b
• UWORD w
Useful definition for working with 8 bit + 8 bit fixed point values
Use .w to access the variable as unsigned 16 bit type.
Use .b.h and .b.l (or just .h and .l) to directly access it's high and low unsigned 8 bit values.
• gbdk-lib/include/asm/types.h
Data Fields
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
19.4 isr_nested_vector_t Struct Reference 81
• gbdk-lib/include/stdatomic.h
Data Fields
• gbdk-lib/include/gb/isr.h
Data Fields
• uint8_t opcode
• void ∗ func
• gbdk-lib/include/gb/isr.h
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
82
Data Fields
• uint8_t npads
• union {
struct {
uint8_t joy0
uint8_t joy1
uint8_t joy2
uint8_t joy3
}
uint8_t joypads [4]
};
• union {
struct {
uint8_t joy0
uint8_t joy1
uint8_t joy2
uint8_t joy3
}
uint8_t joypads [4]
};
• union {
struct {
uint8_t joy0
uint8_t joy1
uint8_t joy2
uint8_t joy3
}
uint8_t joypads [4]
};
• union {
struct {
uint8_t joy0
uint8_t joy1
uint8_t joy2
uint8_t joy3
}
uint8_t joypads [4]
};
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
19.7 metasprite_t Struct Reference 83
• gbdk-lib/include/gb/gb.h
• gbdk-lib/include/msx/msx.h
• gbdk-lib/include/nes/nes.h
• gbdk-lib/include/sms/sms.h
Data Fields
• int8_t dy
• int8_t dx
• uint8_t dtile
• uint8_t props
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
Metasprite sub-item structure
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
84
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
• gbdk-lib/include/gb/metasprites.h
Data Fields
• uint8_t y
• uint8_t x
• uint8_t tile
• uint8_t prop
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
19.9 sfont_handle Struct Reference 85
Parameters
• gbdk-lib/include/gb/gb.h
• gbdk-lib/include/msx/msx.h
• gbdk-lib/include/nes/nes.h
Data Fields
• uint8_t first_tile
• void ∗ font
• gbdk-lib/include/gbdk/font.h
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
86
20 File Documentation
20.1 docs/pages/01_getting_started.md File Reference
20.2 docs/pages/02_links_and_tools.md File Reference
20.3 docs/pages/03_using_gbdk.md File Reference
20.4 docs/pages/04_coding_guidelines.md File Reference
20.5 docs/pages/05_banking_mbcs.md File Reference
20.6 docs/pages/06_toolchain.md File Reference
20.7 docs/pages/06b_supported_consoles.md File Reference
20.8 docs/pages/07_sample_programs.md File Reference
20.9 docs/pages/08_faq.md File Reference
20.10 docs/pages/09_migrating_new_versions.md File Reference
20.11 docs/pages/10_release_notes.md File Reference
20.12 docs/pages/20_toolchain_settings.md File Reference
20.13 docs/pages/docs_index.md File Reference
20.14 gbdk-lib/include/asm/mos6502/provides.h File Reference
Macros
• #define USE_C_MEMCPY 0
• #define USE_C_STRCPY 0
• #define USE_C_STRCMP 0
• #define USE_C_MEMCPY 0
• #define USE_C_STRCPY 0
• #define USE_C_STRCMP 0
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.16 gbdk-lib/include/asm/z80/provides.h File Reference 87
• #define USE_C_MEMCPY 0
• #define USE_C_STRCPY 0
• #define USE_C_STRCMP 1
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
88
Typedefs
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.20 gbdk-lib/include/stdarg.h File Reference 89
Macros
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
90
Parameters
dest Array to copy into
src Array to copy from
Returns
A pointer to dest
Parameters
s1 First string to compare
s2 Second string to compare
Returns:
• > 0 if s1 > s2
• 0 if s1 == s2
• < 0 if s1 < s2
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.21 gbdk-lib/include/asm/mos6502/string.h File Reference 91
Parameters
s Buffer to fill
c char value to fill with (truncated from int)
n Number of bytes to fill
Parameters
s Pointer to string to reverse.
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
92
char ∗ s1,
const char ∗ s2,
int n )
Concatenate at most n characters from string s2 onto the end of s1.
Parameters
Parameters
s1 First string to compare
s2 Second string to compare
n Max number of characters to compare
Returns:
• > 0 if s1 > s2
• 0 if s1 == s2
• < 0 if s1 < s2
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.22 gbdk-lib/include/asm/sm83/string.h File Reference 93
Parameters
Returns:
• 0 if buf1 == buf2
Functions
Variables
• char c
Parameters
dest Array to copy into
src Array to copy from
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
94
Returns
A pointer to dest
Parameters
s1 First string to compare
s2 Second string to compare
Returns:
• > 0 if s1 > s2
• 0 if s1 == s2
• < 0 if s1 < s2
Parameters
Parameters
s Buffer to fill
c char value to fill with (truncated from int)
n Number of bytes to fill
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.22 gbdk-lib/include/asm/sm83/string.h File Reference 95
Parameters
s Pointer to string to reverse.
Parameters
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
96
Parameters
s1 First string to compare
s2 Second string to compare
n Max number of characters to compare
Returns zero if the strings are identical, or non-zero if they are not (see below).
Returns:
• 0 if s1 == s2
Parameters
Parameters
Returns zero if the buffers are identical, or non-zero if they are not (see below).
Returns:
• 0 if buf1 == buf2
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.23 gbdk-lib/include/asm/z80/string.h File Reference 97
20.22.3.1 c void c
Functions
Parameters
dest Array to copy into
src Array to copy from
Returns
A pointer to dest
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
98
Parameters
s1 First string to compare
s2 Second string to compare
Returns:
• > 0 if s1 > s2
• 0 if s1 == s2
• < 0 if s1 < s2
Parameters
Parameters
s Buffer to fill
c char value to fill with (truncated from int)
n Number of bytes to fill
Parameters
s Pointer to string to reverse.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.23 gbdk-lib/include/asm/z80/string.h File Reference 99
Parameters
Parameters
Parameters
Parameters
s1 First string to compare
s2 Second string to compare
n Max number of characters to compare
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
100
Returns:
• > 0 if s1 > s2
• 0 if s1 == s2
• < 0 if s1 < s2
Parameters
Parameters
Returns:
• > 0 if buf1 > buf2
• 0 if buf1 == buf2
• #define __SIZE_T_DEFINED
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.26 gbdk-lib/include/asm/sm83/types.h File Reference 101
Typedefs
clock
• #define __SIZE_T_DEFINED
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
102
Typedefs
clock
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.27 gbdk-lib/include/asm/types.h File Reference 103
Data Structures
• union _fixed
Macros
• #define OLDCALL
• #define PRESERVES_REGS(...)
• #define NAKED
• #define SFR
• #define AT(A)
• #define NORETURN
• #define NONBANKED
• #define BANKED
• #define CRITICAL
• #define INTERRUPT
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
104
• #define Z88DK_CALLEE
• #define Z88DK_FASTCALL
• #define __SIZE_T_DEFINED
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.28 gbdk-lib/include/asm/z80/types.h File Reference 105
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
106
clock
Macros
• #define NULL 0
• #define FALSE 0
• #define TRUE 1
Typedefs
Basic types.
Directly include the port specific file.
Functions
• void __assert (const char ∗expression, const char ∗functionname, const char ∗filename, unsigned int
linenumber)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.31 gbdk-lib/include/ctype.h File Reference 107
Functions
Parameters
c Character to test
Parameters
c Character to test
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
108
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.32 gbdk-lib/include/gb/bcd.h File Reference 109
Macros
Typedefs
Functions
Parameters
i Numeric value to convert
value Pointer to a BCD variable to store the converted result
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
110
Parameters
sour Pointer to a BCD value to add to (and where the result is stored)
value Pointer to the BCD value to add to sour
Parameters
sour Pointer to a BCD value to subtract from (and where the result is stored)
value Pointer to the BCD value to subtract from sour
Parameters
• It can be the Index of the Font Tile '0' in VRAM to allow the buffer to be used directly with set_bkg_tiles.
• It can also be set to the ascii value for character '0' so that the buffer is a normal string that can be passed to
printf.
Shim for legacy use of bgb_emu.h which has been migrated to emu_debug.h
See the emu_debug example project included with gbdk.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 111
Macros
• #define RGB(r, g, b) ((uint16_t)((((b) & 0x1f) << 10) | ((uint16_t)(((g) & 0x1f) << 5)) | (((r) & 0x1f) << 0)))
• #define RGB8(r, g, b) (((uint16_t)((((b) >> 3) & 0x1f) << 10)) | ((uint16_t)((((g) >> 3) & 0x1f) << 5)) | (((r)
>> 3) & 0x1f))
• #define RGBHTML(RGB24bit) (RGB8((((RGB24bit) >> 16) & 0xff), (((RGB24bit) >> 8) & 0xff), ((RGB24bit)
& 0xff)))
• #define RGB_RED RGB(31, 0, 0)
• #define RGB_DARKRED RGB(15, 0, 0)
• #define RGB_GREEN RGB( 0, 31, 0)
• #define RGB_DARKGREEN RGB( 0, 15, 0)
• #define RGB_BLUE RGB( 0, 0, 31)
• #define RGB_DARKBLUE RGB( 0, 0, 15)
• #define RGB_YELLOW RGB(31, 31, 0)
• #define RGB_DARKYELLOW RGB(21, 21, 0)
• #define RGB_CYAN RGB( 0, 31, 31)
• #define RGB_AQUA RGB(28, 5, 22)
• #define RGB_PINK RGB(31, 0, 31)
• #define RGB_PURPLE RGB(21, 0, 21)
• #define RGB_BLACK RGB( 0, 0, 0)
• #define RGB_DARKGRAY RGB(10, 10, 10)
• #define RGB_LIGHTGRAY RGB(21, 21, 21)
• #define RGB_WHITE RGB(31, 31, 31)
• #define RGB_LIGHTFLESH RGB(30, 20, 15)
• #define RGB_BROWN RGB(10, 10, 0)
• #define RGB_ORANGE RGB(30, 20, 0)
• #define RGB_TEAL RGB(15, 15, 0)
Typedefs
Functions
• void set_bkg_palette (uint8_t first_palette, uint8_t nb_palettes, const palette_color_t ∗rgb_data) OLDCALL
• void set_sprite_palette (uint8_t first_palette, uint8_t nb_palettes, const palette_color_t ∗rgb_data) OLDCALL
• void set_bkg_palette_entry (uint8_t palette, uint8_t entry, uint16_t rgb_data) OLDCALL
• void set_sprite_palette_entry (uint8_t palette, uint8_t entry, uint16_t rgb_data) OLDCALL
• void cpu_slow (void)
• void cpu_fast (void)
• void set_default_palette (void)
• void cgb_compatibility (void)
• Use a value of 80h for games that support CGB and monochrome gameboys
(with Lcc: -Wm-yc, or makebin directly: -yc)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
112
Parameters
See also
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 113
Parameters
RGB24bit Bit packed RGB-888 color (0-255 for each color component).
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
114
Parameters
Writes nb_palettes to background palette data starting at first_palette, Palette data is sourced from rgb_data.
• Each Palette is 8 bytes in size: 4 colors x 2 bytes per palette color entry.
• Each color (4 per palette) is packed as BGR-555 format (1:5:5:5, MSBit [15] is unused).
See also
RGB(), set_bkg_palette_entry()
BKGF_CGB_PAL0, BKGF_CGB_PAL1, BKGF_CGB_PAL2, BKGF_CGB_PAL3
BKGF_CGB_PAL4, BKGF_CGB_PAL5, BKGF_CGB_PAL6, BKGF_CGB_PAL7
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 115
Parameters
Writes nb_palettes to sprite palette data starting at first_palette, Palette data is sourced from rgb_data.
• Each Palette is 8 bytes in size: 4 colors x 2 bytes per palette color entry.
• Each color (4 per palette) is packed as BGR-555 format (1:5:5:5, MSBit [15] is unused).
See also
RGB(), set_sprite_palette_entry()
OAMF_CGB_PAL0, OAMF_CGB_PAL1, OAMF_CGB_PAL2, OAMF_CGB_PAL3
OAMF_CGB_PAL4, OAMF_CGB_PAL5, OAMF_CGB_PAL6, OAMF_CGB_PAL7
Parameters
See also
set_bkg_palette(), RGB()
BKGF_CGB_PAL0, BKGF_CGB_PAL1, BKGF_CGB_PAL2, BKGF_CGB_PAL3
BKGF_CGB_PAL4, BKGF_CGB_PAL5, BKGF_CGB_PAL6, BKGF_CGB_PAL7
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
116
Parameters
See also
set_sprite_palette(), RGB()
OAMF_CGB_PAL0, OAMF_CGB_PAL1, OAMF_CGB_PAL2, OAMF_CGB_PAL3
OAMF_CGB_PAL4, OAMF_CGB_PAL5, OAMF_CGB_PAL6, OAMF_CGB_PAL7
• You can check to see if _cpu == CGB_TYPE before using this function.
See also
cpu_fast()
• Interrupts are temporarily disabled and then re-enabled during this call.
• You can check to see if _cpu == CGB_TYPE before using this function.
See also
cpu_slow(), _cpu
• You can check to see if _cpu == CGB_TYPE before using this function.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.36 gbdk-lib/include/gb/crash_handler.h File Reference 117
When crash_handler.h is included, a crash dump screen will be displayed if the CPU executes uninitalized memory
(with a value of 0xFF, the opcode for RST 38). A handler is installed for RST 38 that calls __HandleCrash().
#include <gb/crash_handler.h>
Also see the crash example project included with gbdk.
Macros
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
118
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.37 gbdk-lib/include/gb/drawing.h File Reference 119
See also
gotogxy()
Parameters
number number to print
radix radix (base) to print with
signed_value should be set to SIGNED or UNSIGNED depending on whether the number is signed or not
See also
gotogxy()
See also
gprintln(), gotogxy()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
120
Parameters
Currently supported:
• %c (character)
• %u (int)
• %d (int8_t)
• %o (int8_t as octal)
• %x (int8_t as hex)
• %s (string)
Returns
See also
gotogxy()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.37 gbdk-lib/include/gb/drawing.h File Reference 121
See also
gotogxy()
See also
wrtchr()
Parameters
forecolor The primary drawing color (outlines of rectangles with box(), letter color with gprintf(), etc).
backcolor Secondary or background color where applicable (fill color of rectangles with box() when M_FILL is
specifed, background color of text with gprintf(), etc).
mode Drawing style to use. Several settings are available SOLID, OR, XOR, AND.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
122
Shim for legacy use of gb/emu_debug.h which has been migrated to gbdk/emu_debug.h
See the emu_debug example project included with gbdk.
Macros
Functions
Debug window logging and profiling support for emulators (BGB, Emulicious, etc).
Also see the emu_debug example project included with gbdk.
See the BGB Manual for more information ("expressions, breakpoint conditions, and debug messages") http←-
://bgb.bircd.org/manual.html#expressions
Parameters
The following special parameters can be used when bracketed with "%" characters.
• CPU registers: AF, BC, DE, HL, SP, PC, B, C, D, E, H, L, A, ZERO, ZF, Z, CARRY, CY, IME, ALLREGS
• Other state values: ROMBANK, XRAMBANK, SRAMBANK, WRAMBANK, VRAMBANK, TOTALCLKS, LAST-
CLKS, CLKS2VBLANK
Example: print a message along with the currently active ROM bank.
EMU_MESSAGE("Current ROM Bank is: %ROMBANK%");
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.39 gbdk-lib/include/gbdk/emu_debug.h File Reference 123
See the BGB Manual for more information ("expressions, breakpoint conditions, and debug messages") http←-
://bgb.bircd.org/manual.html#expressions
See also
EMU_PROFILE_BEGIN(), EMU_PROFILE_END()
Parameters
MSG Quoted text string to display in the debug message window along with the result
To complete the profiling block and print the result call EMU_PROFILE_END.
See also
EMU_PROFILE_END(), EMU_MESSAGE()
Parameters
MSG Quoted text string to display in the debug message window along with the result
See also
EMU_PROFILE_BEGIN(), EMU_MESSAGE()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
124
Parameters
Does not return the number of characters printed. Result string MUST BE LESS OR EQUAL THAN 128 BYTES
LONG, INCLUDING THE TRAILIG ZERO BYTE!
Currently supported:
• %c (character)
• %u (unsigned int)
• %d (signed int)
• %s (string)
Warning: to correctly pass chars for printing as chars, they must be explicitly re-cast as such when calling the
function. See docs_chars_varargs for more details.
Data Structures
• struct joypads_t
• struct OAM_item_t
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 125
Macros
• #define NINTENDO
• #define GAMEBOY
• #define J_UP 0x04U
• #define J_DOWN 0x08U
• #define J_LEFT 0x02U
• #define J_RIGHT 0x01U
• #define J_A 0x10U
• #define J_B 0x20U
• #define J_SELECT 0x40U
• #define J_START 0x80U
• #define M_DRAWING 0x01U
• #define M_TEXT_OUT 0x02U
• #define M_TEXT_INOUT 0x03U
• #define M_NO_SCROLL 0x04U
• #define M_NO_INTERP 0x08U
• #define S_PALETTE 0x10U
• #define S_FLIPX 0x20U
• #define S_FLIPY 0x40U
• #define S_PRIORITY 0x80U
• #define S_PAL(n) n
• #define EMPTY_IFLAG 0x00U
• #define VBL_IFLAG 0x01U
• #define LCD_IFLAG 0x02U
• #define TIM_IFLAG 0x04U
• #define SIO_IFLAG 0x08U
• #define JOY_IFLAG 0x10U
• #define DMG_BLACK 0x03
• #define DMG_DARK_GRAY 0x02
• #define DMG_LITE_GRAY 0x01
• #define DMG_WHITE 0x00
• #define DMG_PALETTE(C0, C1, C2, C3) ((uint8_t)((((C3) & 0x03) << 6) | (((C2) & 0x03) << 4) | (((C1) &
0x03) << 2) | ((C0) & 0x03)))
• #define SCREENWIDTH DEVICE_SCREEN_PX_WIDTH
• #define SCREENHEIGHT DEVICE_SCREEN_PX_HEIGHT
• #define MINWNDPOSX DEVICE_WINDOW_PX_OFFSET_X
• #define MINWNDPOSY DEVICE_WINDOW_PX_OFFSET_Y
• #define MAXWNDPOSX (DEVICE_WINDOW_PX_OFFSET_X + DEVICE_SCREEN_PX_WIDTH - 1)
• #define MAXWNDPOSY (DEVICE_WINDOW_PX_OFFSET_Y + DEVICE_SCREEN_PX_HEIGHT - 1)
• #define DMG_TYPE 0x01
• #define MGB_TYPE 0xFF
• #define CGB_TYPE 0x11
• #define GBA_NOT_DETECTED 0x00
• #define GBA_DETECTED 0x01
• #define DEVICE_SUPPORTS_COLOR (_cpu == CGB_TYPE)
• #define IO_IDLE 0x00U
• #define IO_SENDING 0x01U
• #define IO_RECEIVING 0x02U
• #define IO_ERROR 0x04U
• #define CURRENT_BANK _current_bank
• #define BANK(VARNAME) ( (uint8_t) & __bank_ ## VARNAME )
• #define BANKREF(VARNAME)
• #define BANKREF_EXTERN(VARNAME) extern const void __bank_ ## VARNAME;
• #define SWITCH_ROM(b) (_current_bank = (b), rROMB0 = (b))
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
126
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 127
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
128
Variables
• uint8_t c
• uint8_t d
• uint8_t e
• uint8_t h
• uint8_t l
• uint8_t _cpu
• uint8_t _is_GBA
• volatile uint16_t sys_time
• volatile uint8_t _io_status
• volatile uint8_t _io_in
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 129
See also
joypad
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
130
See also
mode()
See also
mode()
See also
mode()
See also
set_sprite_prop().
See also
set_sprite_prop()
See also
set_sprite_prop()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 131
set_sprite_prop()
set_interrupts(),
add_VBL
set_interrupts(),
add_LCD
set_interrupts(),
add_TIM
set_interrupts(),
add_SIO
set_interrupts(),
add_JOY
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
132
Parameters
The resulting format is four greyscale colors packed into a single unsigned byte.
Example:
BGP_REG = DMG_PALETTE(DMG_BLACK, DMG_DARK_GRAY, DMG_LITE_GRAY, DMG_WHITE);
See also
move_win()
move_win()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 133
See also
move_win()
See also
move_win()
See also
_cpu
See also
_cpu
_cpu
See also
_cpu, _is_GBA
_cpu, _is_GBA
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
134
Parameters
VARNAME Name of the variable which has a __bank_VARNAME companion symbol which is adjusted by
bankpack
Use this to obtain the bank number from a bank reference created with BANKREF().
See also
BANKREF_EXTERN(), BANKREF()
Parameters
See also
More than one BANKREF() may be created per file, but each call should always use a unique VARNAME.
Use BANKREF_EXTERN() within another source file to make the variable and it's data accesible there.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 135
Parameters
This makes a BANKREF() reference in another source file accessible in the current file for use with BANK().
See also
BANKREF(), BANK()
Parameters
• When used with MBC5 the max bank is Bank 255 (4MB).
• For MBC1 some banks in it's range are unavailable (typically 0x20, 0x40, 0x60).
Note
See also
Parameters
See also
SWITCH_RAM_MBC1, SWITCH_RAM_MBC5
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
136
Parameters
Parameters
For MBC1 some banks in it's range are unavailable (typically 0x20, 0x40, 0x60).
See pandocs for more details https://gbdev.io/pandocs/MBC1
Parameters
SWITCH_RAM, SWITCH_RAM_MBC5
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 137
Parameters
Note
Note the order used here. Writing the other way around on a MBC1 always selects bank 1
See also
_current_bank
Parameters
• Banked SDCC calls are not supported if you use this macro.
• The active bank number is not tracked by _current_bank if you use this macro.
Note the order used here. Writing the other way around on a MBC1 always selects bank 1
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
138
See also
display_off, DISPLAY_OFF
display_off, DISPLAY_ON
hide_sprite, hide_sprites_range
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 139
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
140
Parameters
Parameters
See also
add_VBL()
See also
add_VBL()
See also
add_LCD(), remove_VBL()
See also
add_TIM(), remove_VBL()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 141
See also
add_SIO(),
remove_VBL()
The default SIO ISR gets installed automatically if any of the standard SIO calls are used (send_byte(),
receive_byte()).
Once installed the default SIO ISR cannot be removed. Only secondary chained SIO ISRs (added with add_SIO())
can be removed.
See also
add_JOY(), remove_VBL()
Parameters
h The handler to be called whenever a V-blank interrupt occurs.
Up to 4 handlers may be added, with the last added being called last.
Do not use the function definition attributes CRITICAL and INTERRUPT when declaring ISR functions added via
add_VBL() (or LCD, etc). Those attributes are only required when constructing a bare jump from the interrupt vector
itself (such as with ISR_VECTOR()).
ISR handlers added using add_VBL()/etc are instead called via the GBDK ISR dispatcher which makes the extra
function attributes unecessary.
Note
See also
ISR_VECTOR()
LYC may not trigger with scanline 0 in the same way as other scanlines due to particular behavior with scan-
lines 153 and 0. Instead, using an add_VBL() interrupt handler for start of frame behavior may be more
suitable.
Do not use the function definition attributes CRITICAL and INTERRUPT when declaring ISR functions added via
add_VBL() (or LCD, etc). Those attributes are only required when constructing a bare jump from the interrupt vector
itself (such as with ISR_VECTOR()).
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
142
ISR handlers added using add_VBL/LCD/etc are instead called via the GBDK ISR dispatcher which makes the extra
function attributes unecessary.
If this ISR is to be called once per each scanline then make sure that the time it takes to execute is less than the
duration of a scanline.
See also
See also
add_VBL
set_interrupts() with TIM_IFLAG, ISR_VECTOR()
See also
add_VBL
set_interrupts() with TIM_IFLAG, ISR_VECTOR()
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 143
See also
joypad(), add_VBL()
See also
wait_int_handler()
See also
Used by default at the end of interrupt chains to help prevent graphical glitches. The glitches are caused when an
ISR interrupts a graphics operation in one mode but returns in a different mode for which that graphics operation is
not allowed.
See also
nowait_int_handler()
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
144
See also
add_SIO(), remove_SIO()
set_interrupts() with SIO_IFLAG
See also
add_SIO(), remove_SIO()
set_interrupts() with SIO_IFLAG
Parameters
Normally only used for checking one key, but it will support many, even J_LEFT at the same time as J_RIGHT. :)
Note
Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns.
See also
joypad
J_START, J_SELECT, J_A, J_B, J_UP, J_DOWN, J_LEFT, J_RIGHT
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 145
Note
Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns.
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
Parameters
joypads pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with
joypad_init()
See also
joypad_init(), joypads_t
Note
Use CRITICAL {...} instead for creating a block of of code which should execute with interrupts temporarily
turned off.
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
146
Note
Use CRITICAL {...} instead for creating a block of of code which should execute with interrupts temporarily
turned off.
This function may be called as many times as you like; however the first call to enable_interrupts will re-enable them.
See also
Parameters
Note
This disables and then re-enables interrupts so it must be used outside of a critical section.
See also
enable_interrupts(), disable_interrupts()
VBL_IFLAG, LCD_IFLAG, TIM_IFLAG, SIO_IFLAG, JOY_IFLAG
DISPLAY_ON
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 147
Parameters
Parameters
addr address to write to
v value
Parameters
Returns
read value
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
148
Parameters
Parameters
• Foreground: DMG_BLACK
• Background: DMG_WHITE
Example:
// Use DMG_BLACK as the Foreground color and DMG_LITE_GRAY
// as the Background color when loading 1bpp tile data.
set_1bpp_colors(DMG_BLACK, DMG_LITE_GRAY);
See also
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data. Each Tile is 16 bytes in size (8x8
pixels, 2 bits-per-pixel).
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 149
Note
Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
GBC only: VBK_REG determines which bank of tile patterns are written to.
See also
set_win_data, set_tile_data
Parameters
Similar to set_bkg_data, except source data is 1 bit-per-pixel which gets expanded into 2 bits-per-pixel.
For a given bit that represent a pixel:
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
150
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Copies nb_tiles tiles from VRAM starting at first_tile, Tile data is copied into data.
Each Tile is 16 bytes, so the buffer pointed to by data should be at least nb_tiles x 16 bytes in size.
See also
get_win_data, get_data
Parameters
Entries are copied from map at tiles to the Background Tile Map starting at x, y writing across for w tiles and down
for h tiles.
Use set_bkg_submap() instead when:
• Source map is wider than 32 tiles.
• Writing a width that does not match the source map width and more than one row high at a time.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
Note
Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
• VBK_REG = VBK_TILES Tile Numbers are written
• Bit 6 - Vertical flip. Dictates which way up the tile is drawn vertically.
0: Normal
1: Flipped Vertically
• Bit 5 - Horizontal flip. Dictates which way up the tile is drawn horizontally.
0: Normal
1: Flipped Horizontally
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 151
• Bit 3 - Character Bank specification. Dictates from which bank of Background Tile Patterns the tile is taken.
0: Bank 0
1: Bank 1
• Bit 0 - Bits 0-2 indicate which of the 7 BKG colour palettes the tile is assigned.
See also
SHOW_BKG
set_bkg_data, set_bkg_submap, set_win_tiles, set_tiles
Parameters
This is identical to set_bkg_tiles() except that it adds the base_tile parameter for when a tile map's tiles don't start
at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
152
Parameters
Entries are copied from map at tiles to the Background Tile Map starting at x, y writing across for w tiles and down
for h tiles.
Use set_bkg_submap_attributes() instead when:
• Source map is wider than 32 tiles.
• Writing a width that does not match the source map width and more than one row high at a time.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
GBC Tile Attributes are defined as:
• Bit 7 - Priority flag. When this is set, it puts the tile above the sprites with colour 0 being transparent.
0: Below sprites
1: Above sprites
Note: SHOW_BKG needs to be set for these priorities to take place.
• Bit 6 - Vertical flip. Dictates which way up the tile is drawn vertically.
0: Normal
1: Flipped Vertically
• Bit 5 - Horizontal flip. Dictates which way up the tile is drawn horizontally.
0: Normal
1: Flipped Horizontally
• Bit 3 - Character Bank specification. Dictates from which bank of Background Tile Patterns the tile is taken.
0: Bank 0
1: Bank 1
• Bit 0 - Bits 0-2 indicate which of the 7 BKG colour palettes the tile is assigned.
See also
SHOW_BKG
set_bkg_data, set_bkg_submap_attributes, set_win_tiles, set_tiles
Note
On the Game Boy this is only usable in Game Boy Color mode
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 153
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Background Tile Map starting at x, y writing across for w tiles and down for h
tiles, using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates.
Range 0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates.
Range 0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map_w Width of source tile map in tiles. Range 1 - 255
base_tile Offset each tile ID entry of the source map by this value. Range 1 - 255
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
154
This is identical to set_bkg_submap() except that it adds the base_tile parameter for when a tile map's tiles don't
start at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map attribute data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Background Tile Map starting at x, y writing across for w tiles and down for h
tiles, using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_attributes, set_win_submap, set_tiles
Note
On the Game Boy this is only usable in Game Boy Color mode
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 155
uint8_t y,
uint8_t w,
uint8_t h,
uint8_t ∗ tiles )
Copies a rectangular region of Background Tile Map entries into a buffer.
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Entries are copied into tiles from the Background Tile Map starting at x, y reading across for w tiles and down for h
tiles.
One byte per tile.
The buffer pointed to by tiles should be at least x x y bytes in size.
See also
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
a tile attributes
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
156
Returns
returns the address of tile attribute, so you may use faster set_vram_byte() later
Note
On the Game Boy this is only usable in Game Boy Color mode
Parameters
x X-coordinate
y Y-coordinate
Returns
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Parameters
0,0 is the top left corner of the GB screen. The Background Layer wraps around the screen, so when part of it goes
off the screen it appears on the opposite side (factoring in the larger size of the Background Layer versus the screen
size).
The background layer is always under the Window Layer.
See also
SHOW_BKG, HIDE_BKG
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 157
Parameters
See also
move_bkg
Parameters
This is the same as set_bkg_data, since the Window Layer and Background Layer share the same Tile pattern data.
See also
set_bkg_data
set_win_tiles, set_bkg_data, set_data
SHOW_WIN, HIDE_WIN
Parameters
This is the same as set_bkg_1bpp_data, since the Window Layer and Background Layer share the same Tile pattern
data.
For a given bit that represent a pixel:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
158
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
This is the same as get_bkg_data, since the Window Layer and Background Layer share the same Tile pattern data.
See also
get_bkg_data, get_data
Parameters
Entries are copied from map at tiles to the Window Tile Map starting at x, y writing across for w tiles and down for
h tiles.
Use set_win_submap() instead when:
• Writing a width that does not match the source map width and more than one row high at a time.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 159
Note
Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
See also
Parameters
This is identical to set_win_tiles() except that it adds the base_tile parameter for when a tile map's tiles don't start
at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
Parameters
x X Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
160
Parameters
y Y Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Window Tile Map starting at x, y writing across for w tiles and down for h tiles,
using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_win_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
See set_bkg_tiles for details about CGB attribute maps with VBK_REG.
See also
Parameters
x X Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 -
255
y Y Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 -
255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map_w Width of source tile map in tiles. Range 1 - 255
base_tile Offset each tile ID entry of the source map by this value. Range 1 - 255
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 161
This is identical to set_win_submap() except that it adds the base_tile parameter for when a tile map's tiles don't
start at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Entries are copied into tiles from the Window Tile Map starting at x, y reading across for w tiles and down for h
tiles.
One byte per tile.
The buffer pointed to by tiles should be at least x x y bytes in size.
See also
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
162
Parameters
x X-coordinate
y Y-coordinate
Returns
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Parameters
x X coordinate for Left edge of the Window (actual displayed location will be X - 7)
y Y coordinate for Top edge of the Window
7,0 is the top left corner of the screen in Window coordinates. The Window is locked to the bottom right corner.
The Window is always over the Background layer.
See also
SHOW_WIN, HIDE_WIN
Parameters
See also
move_win
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 163
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data. Each Tile is 16 bytes in size (8x8
pixels, 2 bits-per-pixel).
Note
Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Parameters
Similar to set_sprite_data, except source data is 1 bit-per-pixel which gets expanded into 2 bits-per-pixel.
For a given bit that represent a pixel:
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
164
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Copies nb_tiles tiles from VRAM starting at first_tile, tile data is copied into data.
Each Tile is 16 bytes, so the buffer pointed to by data should be at least nb_tiles x 16 bytes in size.
Parameters
In 8x16 mode:
• The sprite will also display the next tile (tile + 1) directly below (y + 8) the first tile.
• The lower bit of the tile number is ignored: the upper 8x8 tile is (tile & 0xFE), and the lower 8x8 tile is (tile |
0x01).
• See: SPRITES_8x16
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 165
Sets the OAM Property Flags of sprite number nb to those defined in prop.
Parameters
• Bit 7 - Priority flag. When this is set the sprites appear behind the background and window layer.
0: infront
1: behind
• Bit 6 - Vertical flip. Dictates which way up the sprite is drawn vertically.
0: normal
1:upside down
• Bit 5 - Horizontal flip. Dictates which way up the sprite is drawn horizontally.
0: normal
1:back to front
• Bit 4 - DMG/Non-CGB Mode Only. Assigns either one of the two b/w palettes to the sprite.
0: OBJ palette 0
1: OBJ palette 1
• Bit 3 - GBC only. Dictates from which bank of Sprite Tile Patterns the tile is taken.
0: Bank 0
1: Bank 1
• Bit 0 - GBC only. Bits 0-2 indicate which of the 7 OBJ colour palettes the sprite is assigned.
Parameters
See also
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
166
Parameters
x X Position. Specifies the sprites horizontal position on the screen (minus 8).
An offscreen value (X=0 or X>=168) hides the sprite, but the sprite still affects the priority ordering - a
better way to hide a sprite is to set its Y-coordinate offscreen.
y Y Position. Specifies the sprites vertical position on the screen (minus 16).
An offscreen value (for example, Y=0 or Y>=160) hides the sprite.
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
See also
Parameters
See also
hide_sprites_range, HIDE_SPRITES
Parameters
vram_addr Pointer to destination VRAM Address
data Pointer to source buffer
len Number of bytes to copy
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 167
See also
Parameters
vram_addr Pointer to source VRAM Address
data Pointer to destination buffer
len Number of bytes to copy
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Copies len bytes from VRAM starting at vram_addr into a buffer at data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
See also
Parameters
Copies len bytes from or to VRAM starting at sour into a buffer or to VRAM at dest.
GBC only: VBK_REG determines which bank of tile patterns are written to.
• VBK_REG = VBK_BANK_0 indicates the first bank
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
168
Parameters
Entries are copied from tiles to Tile Map at address vram_addr starting at x, y writing across for w tiles and down
for h tiles.
One byte per source tile map entry.
There are two 32x32 Tile Maps in VRAM at addresses 9800h-9BFFh and 9C00h-9FFFh.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
See also
set_bkg_tiles, set_win_tiles
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 169
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Entries are copied into tiles from the Background Tile Map starting at x, y reading across for w tiles and down for h
tiles.
One byte per tile.
There are two 32x32 Tile Maps in VRAM at addresses 9800h - 9BFFh and 9C00h - 9FFFh.
The buffer pointed to by tiles should be at least x x y bytes in size.
See also
get_bkg_tiles, get_win_tiles
Parameters
When first_tile is larger than 256 on the GB/AP, it will write to sprite data instead of background data.
The bit depth of the source Tile Pattern data depends on which console is being used:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
170
uint8_t nb_tiles,
const uint8_t ∗ data ) [inline]
Sets VRAM Tile Pattern data for the Background / Window in the native format
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
See also
set_win_data, set_tile_data
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Parameters
Note
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 171
Parameters
Note
Parameters
Note
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
172
Parameters
20.40.5.1 c void c
20.40.5.2 d void d
20.40.5.3 e void e
20.40.5.4 h uint8_t h
20.40.5.5 l void l
Initial value:
{
__asm__("ei")
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.41 gbdk-lib/include/gb/gbdecompress.h File Reference 173
See also
20.40.5.13 b void b
Functions
See also
utility_gbcompress "gbcompress"
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
174
Parameters
sour Pointer to source gb-compressed data
dest Pointer to destination buffer/address
Will decompress all of it's data to destination without stopping until the end of compressed data is reached. It is not
possible to set a limit, so ensure the destination buffer has sufficient space to avoid an overflow.
See also
Parameters
sour Pointer to source gb-compressed data
dest Pointer to destination buffer/address
Returns
See also
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.42 gbdk-lib/include/gbdk/gbdecompress.h File Reference 175
uint8_t first_tile,
const uint8_t ∗ sour )
gb-decompress window tiles into VRAM
Parameters
This is the same as gb_decompress_bkg_data, since the Window Layer and Background Layer share the same Tile
pattern data.
Note: This function avoids writes during modes 2 & 3
Will decompress all of it's data to destination without stopping until the end of compressed data is reached. It is not
possible to set a limit, so ensure the destination buffer has sufficient space to avoid an overflow.
See also
Parameters
See also
Functions
Variables
• uint16_t c
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
176
Parameters
sour Pointer to source gb-compressed data
dest Pointer to destination buffer/address
Returns
See also
20.43.2.1 c uint16_t c
Macros
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 177
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
178
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 179
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
180
Variables
• __BYTES _VRAM [ ]
• __BYTES _VRAM8000 [ ]
• __BYTES _VRAM8800 [ ]
• __BYTES _VRAM9000 [ ]
• __BYTES _SCRN0 [ ]
• __BYTES _SCRN1 [ ]
• __BYTES _SRAM [ ]
• __BYTES _RAM [ ]
• __BYTES _RAMBANK [ ]
• __BYTES _OAMRAM [ ]
• __BYTE_REG _IO [ ]
• __BYTE_REG _AUD3WAVERAM [ ]
• __BYTE_REG _HRAM [ ]
• __BYTE_REG rRAMG
• __BYTE_REG rROMB0
• __BYTE_REG rROMB1
• __BYTE_REG rRAMB
• __REG P1_REG
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 181
• __REG SB_REG
• __REG SC_REG
• __REG DIV_REG
• __REG TIMA_REG
• __REG TMA_REG
• __REG TAC_REG
• __REG IF_REG
• __REG NR10_REG
• __REG NR11_REG
• __REG NR12_REG
• __REG NR13_REG
• __REG NR14_REG
• __REG NR21_REG
• __REG NR22_REG
• __REG NR23_REG
• __REG NR24_REG
• __REG NR30_REG
• __REG NR31_REG
• __REG NR32_REG
• __REG NR33_REG
• __REG NR34_REG
• __REG NR41_REG
• __REG NR42_REG
• __REG NR43_REG
• __REG NR44_REG
• __REG NR50_REG
• __REG NR51_REG
• __REG NR52_REG
• __BYTE_REG AUD3WAVE [16]
• __BYTE_REG PCM_SAMPLE [16]
• __REG LCDC_REG
• __REG STAT_REG
• __REG SCY_REG
• __REG SCX_REG
• __REG LY_REG
• __REG LYC_REG
• __REG DMA_REG
• __REG BGP_REG
• __REG OBP0_REG
• __REG OBP1_REG
• __REG WY_REG
• __REG WX_REG
• __REG KEY1_REG
• __REG VBK_REG
• __REG HDMA1_REG
• __REG HDMA2_REG
• __REG HDMA3_REG
• __REG HDMA4_REG
• __REG HDMA5_REG
• __REG RP_REG
• __REG BCPS_REG
• __REG BCPD_REG
• __REG OCPS_REG
• __REG OCPD_REG
• __REG SVBK_REG
• __REG PCM12_REG
• __REG PCM34_REG
• __REG IE_REG
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
182
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 183
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
184
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 185
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
186
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 187
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
188
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 189
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
190
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 191
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
192
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 193
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
194
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 195
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
196
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 197
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
198
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 199
Macros
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
200
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 201
Variables
• UBYTE shadow_VDP_R0
• UBYTE shadow_VDP_R1
• UBYTE shadow_VDP_R2
• UBYTE shadow_VDP_R3
• UBYTE shadow_VDP_R4
• UBYTE shadow_VDP_R5
• UBYTE shadow_VDP_R6
• UBYTE shadow_VDP_R7
• UBYTE shadow_VDP_RBORDER
• UBYTE shadow_VDP_R8
• UBYTE shadow_VDP_RSCX
• UBYTE shadow_VDP_R9
• UBYTE shadow_VDP_RSCY
• UBYTE shadow_VDP_R10
• const UBYTE _BIOS
• const UBYTE _SYSTEM
• volatile UBYTE VDP_ATTR_SHIFT
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
202
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 203
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
204
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 205
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
206
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 207
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
208
Macros
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.46 gbdk-lib/include/nes/hardware.h File Reference 209
Functions
Variables
• __SHADOW_REG shadow_PPUCTRL
• __SHADOW_REG shadow_PPUMASK
• __SHADOW_REG bkg_scroll_x
• __SHADOW_REG bkg_scroll_y
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
210
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.46 gbdk-lib/include/nes/hardware.h File Reference 211
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
212
Macros
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 213
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
214
Variables
• UBYTE shadow_VDP_R0
• UBYTE shadow_VDP_R1
• UBYTE shadow_VDP_R2
• UBYTE shadow_VDP_R3
• UBYTE shadow_VDP_R4
• UBYTE shadow_VDP_R5
• UBYTE shadow_VDP_R6
• UBYTE shadow_VDP_R7
• UBYTE shadow_VDP_RBORDER
• UBYTE shadow_VDP_R8
• UBYTE shadow_VDP_RSCX
• UBYTE shadow_VDP_R9
• UBYTE shadow_VDP_RSCY
• UBYTE shadow_VDP_R10
• const UBYTE _BIOS
• const UBYTE _SYSTEM
• volatile UBYTE VDP_ATTR_SHIFT
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 215
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
216
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 217
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
218
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 219
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
220
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.48 gbdk-lib/include/gb/isr.h File Reference 221
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
222
Data Structures
• struct isr_vector_t
• struct isr_nested_vector_t
Macros
Typedefs
Macros for creating raw interrupt service routines (ISRs) which do not use the default GBDK ISR dispatcher.
Handlers installed this way will have less overhead than ones which use the GBDK ISR dispatcher.
Parameters
ADDR Address of the interrupt vector, any of: VECTOR_STAT, VECTOR_TIMER, VECTOR_SERIAL,
VECTOR_JOYPAD
FUNC ISR function supplied by the user
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 223
Example:
#include <gb/isr.h>
void TimerISR() __critical __interrupt {
// some ISR code here
}
ISR_VECTOR(VECTOR_TIMER, TimerISR)
See also
ISR_NESTED_VECTOR, set_interrupts
Parameters
ADDR Address of the interrupt vector, any of: VECTOR_STAT, VECTOR_TIMER, VECTOR_SERIAL,
VECTOR_JOYPAD
FUNC ISR function
ISR_VECTOR
Data Structures
• struct metasprite_t
Macros
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
224
Functions
Variables
A metasprite is a larger sprite made up from a collection of smaller individual hardware sprites. Different frames of
the same metasprites can share tile data.
The api supports metasprites in both SPRITES_8x8 and SPRITES_8x16 mode. If 8x16 mode is used then the
height of the metasprite must be a multiple of 16.
The origin (pivot) for the metasprite is not required to be in the upper left-hand corner as with regular hardware
sprites.
Use the utility_png2asset tool to convert single or multiple frames of graphics into metasprite structured data for use
with the ...metasprite...() functions.
When using png2asset, it's common for the output of different frames to be composed of different numbers of
hardware sprites (since it's trying to create each frame as efficiently as possible). Due to that, it's good practice to
clear out (hide) unused sprites in the shadow_OAM that have been set by previous frames.
// Example:
// Hide rest of the hardware sprites, because amount
// of sprites differ between animation frames.
// (where hiwater == last hardware sprite used + 1)
hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
When the move_metasprite_∗() functions are called they update all properties for the affected sprites in the Shadow
OAM. This means any existing property flags set for a sprite (CGB palette, BG/WIN priority, Tile VRAM Bank) will
get overwritten.
How to use sprite property flags with metasprites:
• Primary method: Use the base_prop parameter for the move_metasprite_∗() functions.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 225
• Alternate method: The metasprite structures can have the property flags modified before compilation (such
as with -sp <props> in the png2asset tool).
The following functions only support hardware sprite flipping on the Game Boy / Mega Duck and NES. For other
consoles which do not have hardware sprite flipping see the cross-platform metasprite example for a workaround
(with some performance penalty).
• move_metasprite_flipx()
• move_metasprite_flipy()
• move_metasprite_flipxy()
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
226
Parameters
See also
hide_sprite, MAX_HARDWARE_SPRITES
Parameters
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (can be used to set palette, etc)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Moves metasprite to the absolute position x and y (with no flip on the X or Y axis). Hardware sprites are allocated
starting from base_sprite, using tiles starting from base_tile.
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as CGB Palette), see Metasprites and sprite properties.
Returns
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 227
uint8_t x,
uint8_t y ) [inline]
Obsolete. This function has been replaced by move_metasprite_ex()
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (can be used to set palette, etc)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as CGB palette), see Metasprites and sprite properties.
This function is only available on Game Boy and related clone consoles.
Returns
See also
move_metasprite()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
228
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (can be used to set palette, etc)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as CGB palette), see Metasprites and sprite properties.
This function is only available on Game Boy and related clone consoles.
Returns
See also
move_metasprite()
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (can be used to set palette, etc)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Same as move_metasprite(), but with the metasprite flipped by X and Y (horizontally and vertically).
Sets:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.50 gbdk-lib/include/gbdk/metasprites.h File Reference 229
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as CGB palette), see Metasprites and sprite properties.
This function is only available on Game Boy and related clone consoles.
Returns
See also
move_metasprite()
Parameters
Sets:
• __current_metasprite = metasprite;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
230
Data Structures
• struct metasprite_t
Macros
Typedefs
Functions
Variables
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.51 gbdk-lib/include/msx/metasprites.h File Reference 231
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
Parameters
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (unused on this platform)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Moves metasprite to the absolute position x and y (with no flip on the X or Y axis). Hardware sprites are allocated
starting from base_sprite, using tiles starting from base_tile.
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
232
Returns
Parameters
Sets:
• __current_metasprite = metasprite;
Data Structures
• struct metasprite_t
Macros
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 233
Typedefs
Functions
Variables
A metasprite is a larger sprite made up from a collection of smaller individual hardware sprites. Different frames of
the same metasprites can share tile data.
See the main metasprite docs under the game Boy platform for additional details.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
234
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
Parameters
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Moves metasprite to the absolute position x and y (with no flip on the X or Y axis). Hardware sprites are allocated
starting from base_sprite, using tiles starting from base_tile.
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 235
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
236
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 237
Parameters
Same as move_metasprite(), but with the metasprite flipped by X and Y (horizontally and vertically).
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Parameters
Sets:
• __current_metasprite = metasprite;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
238
Data Structures
• struct metasprite_t
Macros
Typedefs
Functions
Variables
A metasprite is a larger sprite made up from a collection of smaller individual hardware sprites. Different frames of
the same metasprites can share tile data.
See the main metasprite docs under the game Boy platform for additional details.
A metasprite is a larger sprite made up from a collection of smaller individual hardware sprites. Different frames of
the same metasprites can share tile data.
See the main metasprite docs under the game Boy platform for additional details.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.53 gbdk-lib/include/sms/metasprites.h File Reference 239
Parameters
Metasprites are built from multiple metasprite_t items (one for each sub-sprite) and a pool of tiles they reference. If
a metasprite has multiple frames then each frame will be built from some number of metasprite_t items (which may
vary based on how many sprites are required for that particular frame).
A metasprite frame is terminated with a {metasprite_end} entry.
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
240
uint16_t y ) [inline]
Moves metasprite to the absolute position x and y
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (unused on this platform)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Moves metasprite to the absolute position x and y (with no flip on the X or Y axis). Hardware sprites are allocated
starting from base_sprite, using tiles starting from base_tile.
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Returns
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (unused on this platform)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.53 gbdk-lib/include/sms/metasprites.h File Reference 241
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (unused on this platform)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
242
Parameters
metasprite Pointer to the first struct of the metasprite (for the desired frame)
base_tile Number of the first tile where the metasprite's tiles start
base_prop Base sprite property flags (unused on this platform)
base_sprite Number of the first hardware sprite to be used by the metasprite
x Absolute x coordinate of the sprite
y Absolute y coordinate of the sprite
Same as move_metasprite(), but with the metasprite flipped by X and Y (horizontally and vertically).
Sets:
• __current_metasprite = metasprite;
• __current_base_tile = base_tile;
Note: Overwrites OAM sprite properties (such as palette), see Metasprites and sprite properties.
Returns
See also
move_metasprite()
Parameters
Sets:
• __current_metasprite = metasprite;
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.54 gbdk-lib/include/gb/sgb.h File Reference 243
Macros
Functions
Variables
• uint8_t c
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
244
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.55 gbdk-lib/include/gbdk/console.h File Reference 245
Parameters
The first byte of packet should be a SGB command, then up to 15 bytes of command parameter data.
See the sgb_border GBDK example project for a demo of how to use these the sgb functions.
When using the SGB with a PAL SNES, a delay should be added just after program startup such as:
// Wait 4 frames
// For PAL SNES this delay is required on startup
for (uint8_t i = 4; i != 0; i--) wait_vbl_done();
See also
sgb_check()
20.54.4.1 c void c
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
246
See also
setchar()
See also
gotoxy()
See also
gotoxy()
See also
gotoxy()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.56 gbdk-lib/include/gbdk/far_ptr.h File Reference 247
Data Structures
• union __far_ptr
Macros
Typedefs
Functions
Variables
Far pointers include a segment (bank) selector so they are able to point to addresses (functions or data) outside of
the current bank (unlike normal pointers which are not bank-aware).
See the banks_farptr example project included with gbdk.
Todo Add link to a discussion about banking (such as, how to assign code and variables to banks)
Parameters
Returns
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
248
Parameters
Returns
Parameters
Returns
Parameters
type should match the definition of the function being called. For example:
// A function in bank 2
#pragma bank 2
uint16_t some_function(uint16_t param1, uint16_t param2) __banked { return 1; };
...
// Code elsewhere, such as unbanked main()
// This type declaration should match the above function
typedef uint16_t (*some_function_t)(uint16_t, uint16_t) __banked;
// Using FAR_CALL() with the above as *ptr*, *typ*, and two parameters.
result = FAR_CALL(some_function, some_function_t, 100, 50);
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.57 gbdk-lib/include/gbdk/font.h File Reference 249
Returns
Parameters
Returns
Data Structures
• struct sfont_handle
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
250
Macros
• #define FONT_256ENCODING 0
• #define FONT_128ENCODING 1
• #define FONT_NOENCODING 2
• #define FONT_COMPRESSED 4
Typedefs
Functions
Variables
• uint8_t font_spect [ ]
• uint8_t font_italic [ ]
• uint8_t font_ibm [ ]
• uint8_t font_min [ ]
• uint8_t font_ibm_fixed [ ]
Multiple font support for the GameBoy Michael Hope, 1999 [email protected]
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.58 gbdk-lib/include/gbdk/gbdk-lib.h File Reference 251
Parameters
Returns
See also
Parameters
Returns
See also
font_init(), font_load()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
252
Macros
• #define INCBIN_EXTERN(VARNAME)
• #define INCBIN_SIZE(VARNAME) ( (uint16_t) & __size_ ## VARNAME )
• #define BANK(VARNAME) ( (uint8_t) & __bank_ ## VARNAME )
• #define INCBIN(VARNAME, FILEPATH)
Allows binary data from other files to be included into a C source file.
It is implemented using asm .incbin and macros.
See the incbin example project for a demo of how to use it.
Parameters
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.60 gbdk-lib/include/gbdk/platform.h File Reference 253
Parameters
VARNAME Variable name to use
FILEPATH Path to the file which will be binary included into the C source file
filepath is relative to the working directory of the tool that is calling it (often a makefile's working directory), NOT to
the file it's being included into.
The variable name is not modified and can be used as-is.
See also
Use INCBIN_EXTERN() within another source file to make the variable and it's data accesible there.
Macros
• #define RLE_STOP 0
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
254
Parameters
See also
rle_decompress
Parameters
Returns
Before calling this function rle_init must be called one time to initialize the RLE decompressor.
Decompresses data which has been compressed with gbcompress using the --alg=rle argument.
See also
rle_init
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.63 gbdk-lib/include/limits.h File Reference 255
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
256
Data Structures
• struct joypads_t
• struct OAM_item_t
Macros
• #define MSX
• #define VBK_REG VDP_ATTR_SHIFT
• #define J_UP 0b00100000
• #define J_DOWN 0b01000000
• #define J_LEFT 0b00010000
• #define J_RIGHT 0b10000000
• #define J_A 0b00000001
• #define J_B 0b00000100
• #define J_SELECT 0b00001000
• #define J_START 0b00000010
• #define M_TEXT_OUT 0x02U
• #define M_TEXT_INOUT 0x03U
• #define M_NO_SCROLL 0x04U
• #define M_NO_INTERP 0x08U
• #define S_FLIPX 0x02U
• #define S_FLIPY 0x04U
• #define S_PALETTE 0x08U
• #define S_PRIORITY 0x10U
• #define S_PAL(n) n
• #define __WRITE_VDP_REG(REG, v) shadow_##REG=(v);__critical{VDP_CMD=(shadow_##REG),VDP←-
_CMD=REG;}
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 257
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
258
Typedefs
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 259
• void set_win_based_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles, uint8_t base_tile)
• void set_tile_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t ∗map)
Z88DK_CALLEE PRESERVES_REGS(iyh
• void set_tile_submap_compat (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t ∗map)
Z88DK_CALLEE PRESERVES_REGS(iyh
• void set_bkg_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w)
• void set_win_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w)
• void set_bkg_based_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w,
uint8_t base_tile)
• void set_win_based_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w,
uint8_t base_tile)
• void fill_rect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE PRESERVES_REGS(iyh
• void SET_SHADOW_OAM_ADDRESS (void ∗address)
• void set_sprite_tile (uint8_t nb, uint8_t tile)
• uint8_t get_sprite_tile (uint8_t nb)
• void set_sprite_prop (uint8_t nb, uint8_t prop)
• uint8_t get_sprite_prop (uint8_t nb)
• void move_sprite (uint8_t nb, uint8_t x, uint8_t y)
• void scroll_sprite (uint8_t nb, int8_t x, int8_t y)
• void hide_sprite (uint8_t nb)
• void set_vram_byte (uint8_t ∗addr, uint8_t v) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ set_attributed_tile_xy (uint8_t x, uint8_t y, uint16_t t) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ set_tile_xy (uint8_t x, uint8_t y, uint8_t t) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ get_bkg_xy_addr (uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh
Variables
• void c
• void d
• void e
• void iyh
• void iyl
• void h
• void l
• volatile uint16_t sys_time
• volatile uint8_t _current_bank
• uint16_t _current_2bpp_palette
• uint16_t _current_1bpp_colors
• uint8_t _map_tile_offset
• uint8_t _submap_tile_offset
• volatile struct OAM_item_t shadow_OAM [ ]
• volatile uint8_t _shadow_OAM_base
• volatile uint8_t _shadow_OAM_OFF
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
260
See also
joypad
See also
mode()
See also
mode()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 261
See also
mode()
See also
set_interrupts(),
add_VBL
See also
set_interrupts(),
add_LCD
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
262
See also
move_win()
See also
move_win()
See also
move_win()
See also
move_win()
See also
display_off, DISPLAY_OFF
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 263
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
HIDE_LEFT_COLUMN
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
264
Parameters
VARNAME Name of the variable which has a __bank_VARNAME companion symbol which is adjusted by
bankpack
Use this to obtain the bank number from a bank reference created with BANKREF().
See also
BANKREF_EXTERN(), BANKREF()
Parameters
See also
More than one BANKREF() may be created per file, but each call should always use a unique VARNAME.
Use BANKREF_EXTERN() within another source file to make the variable and it's data accesible there.
Parameters
This makes a BANKREF() reference in another source file accessible in the current file for use with BANK().
See also
BANKREF(), BANK()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 265
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
266
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 267
See also
Parameters
Note
This disables and then re-enables interrupts so it must be used outside of a critical section.
See also
enable_interrupts(), disable_interrupts()
VBL_IFLAG, LCD_IFLAG, TIM_IFLAG, SIO_IFLAG, JOY_IFLAG
add_VBL()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
268
See also
add_LCD(), remove_VBL()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 269
See also
DISPLAY_ON
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
270
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
Parameters
joypads pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with
joypad_init()
See also
joypad_init(), joypads_t
• Interrupts are temporarily disabled and then re-enabled during this call.
• You can check to see if _cpu == CGB_TYPE before using this function.
See also
cpu_slow(), _cpu
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 271
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
272
Parameters
dst destination VRAM Address
src Pointer to source buffer
size Number of bytes to copy
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 273
uint8_t y,
uint8_t w,
uint8_t h,
uint8_t map_w,
const uint8_t ∗ map )
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Background Tile Map starting at x, y writing across for w tiles and down for h
tiles, using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
274
Parameters
x X Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
y Y Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Window Tile Map starting at x, y writing across for w tiles and down for h tiles,
using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_win_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
See set_bkg_tiles for details about CGB attribute maps with VBK_REG.
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 275
uint8_t w,
uint8_t h,
const uint8_t ∗ map,
uint8_t map_w,
uint8_t base_tile ) [inline]
Parameters
In 8x16 mode:
• The sprite will also display the next tile (tile + 1) directly below (y + 8) the first tile.
• The lower bit of the tile number is ignored: the upper 8x8 tile is (tile & 0xFE), and the lower 8x8 tile is (tile |
0x01).
• See: SPRITES_8x16
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
276
uint8_t nb,
uint8_t prop ) [inline]
Parameters
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
See also
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 277
Parameters
addr address to write to
v value
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
278
20.64.5.1 c void c
20.64.5.2 d void d
20.64.5.3 e void e
20.64.5.6 h uint8_t h
20.64.5.7 l void l
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 279
This flag is modified by all MSX GBDK API calls that write to the VDP. It is set to DISABLED when they start and
ENABLED when they complete.
Note
It is recommended to avoid writing to the Video Display Processor (VDP) during an interrupt service routine
(ISR) since it can corrupt the VDP pointer of an VDP operation already in progress.
If it is necessary, this flag can be used during an ISR to determine whether a VDP operation is already in progress.
If the value is 1 then avoid writing to the VDP (tiles, map, scrolling, colors, etc).
// at the beginning of and ISR that would write to the VDP
if (_shadow_OAM_OFF) return;
See also
docs_consoles_safe_display_controller_access
Data Structures
• struct joypads_t
• struct OAM_item_t
Macros
• #define NINTENDO_NES
• #define RGB(r, g, b) RGB_TO_NES(((r) | ((g) << 2) | ((b) << 4)))
• #define RGB8(r, g, b) RGB_TO_NES((((r) >> 6) | (((g) >> 6) << 2) | (((b) >> 6) << 4)))
• #define RGBHTML(RGB24bit) RGB_TO_NES((((RGB24bit) >> 22) | ((((RGB24bit) & 0xFFFF) >> 14) <<
2) | ((((RGB24bit) & 0xFF) >> 6) << 4)))
• #define RGB_RED 0x16
• #define RGB_DARKRED 0x06
• #define RGB_GREEN 0x2A
• #define RGB_DARKGREEN 0x1A
• #define RGB_BLUE 0x12
• #define RGB_DARKBLUE 0x02
• #define RGB_YELLOW 0x28
• #define RGB_DARKYELLOW 0x18
• #define RGB_CYAN 0x2C
• #define RGB_AQUA 0x1C
• #define RGB_PINK 0x24
• #define RGB_PURPLE 0x14
• #define RGB_BLACK 0x0F
• #define RGB_DARKGRAY 0x00
• #define RGB_LIGHTGRAY 0x10
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
280
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 281
Typedefs
Functions
• void set_bkg_palette (uint8_t first_palette, uint8_t nb_palettes, const palette_color_t ∗rgb_data) OLDCALL
• void set_sprite_palette (uint8_t first_palette, uint8_t nb_palettes, const palette_color_t ∗rgb_data) OLDCALL
• void set_bkg_palette_entry (uint8_t palette, uint8_t entry, palette_color_t rgb_data) OLDCALL
• void set_sprite_palette_entry (uint8_t palette, uint8_t entry, palette_color_t rgb_data) OLDCALL
• void remove_VBL (int_handler h)
• void remove_LCD (int_handler h)
• void add_VBL (int_handler h)
• void add_LCD (int_handler h)
• void mode (uint8_t m) OLDCALL
• uint8_t get_mode (void) OLDCALL
• void delay (uint16_t d) OLDCALL
• uint8_t joypad (void) OLDCALL
• uint8_t waitpad (uint8_t mask) OLDCALL
• void waitpadup (void)
• uint8_t joypad_init (uint8_t npads, joypads_t ∗joypads) OLDCALL
• void joypad_ex (joypads_t ∗joypads) OLDCALL
• void enable_interrupts (void)
• void disable_interrupts (void)
• void vsync (void)
• void wait_vbl_done (void)
• void display_on (void)
• void display_off (void)
• void refresh_OAM (void)
• void set_vram_byte (uint8_t ∗addr, uint8_t v) OLDCALL
• uint8_t ∗ get_bkg_xy_addr (uint8_t x, uint8_t y) OLDCALL
• void set_2bpp_palette (uint16_t palette)
• void set_1bpp_colors_ex (uint8_t fgcolor, uint8_t bgcolor, uint8_t mode) OLDCALL
• void set_1bpp_colors (uint8_t fgcolor, uint8_t bgcolor)
• void set_bkg_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL
• void set_bkg_1bpp_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL
• void set_bkg_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles) OLDCALL
• void set_bkg_attributes_nes16x16 (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗attributes)
OLDCALL
• void set_bkg_attributes (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗attributes)
• void set_bkg_submap_attributes_nes16x16 (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map,
uint8_t map_w) OLDCALL
• void set_bkg_submap_attributes (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗attributes, uint8_t
map_w)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
282
• void set_bkg_based_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles, uint8_t base_tile)
• void set_bkg_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w) OLDCALL
• void set_bkg_based_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w,
uint8_t base_tile)
• void get_bkg_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t ∗tiles) OLDCALL
• uint8_t ∗ set_bkg_tile_xy (uint8_t x, uint8_t y, uint8_t t) OLDCALL
• void set_bkg_attribute_xy_nes16x16 (uint8_t x, uint8_t y, uint8_t a)
• void set_bkg_attribute_xy (uint8_t x, uint8_t y, uint8_t a)
• uint8_t get_bkg_tile_xy (uint8_t x, uint8_t y) OLDCALL
• void move_bkg (uint8_t x, uint8_t y)
• void scroll_bkg (int8_t x, int8_t y)
• void set_sprite_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL
• void set_sprite_1bpp_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL
• void SET_SHADOW_OAM_ADDRESS (void ∗address)
• void set_sprite_tile (uint8_t nb, uint8_t tile)
• uint8_t get_sprite_tile (uint8_t nb)
• void set_sprite_prop (uint8_t nb, uint8_t prop)
• uint8_t get_sprite_prop (uint8_t nb)
• void move_sprite (uint8_t nb, uint8_t x, uint8_t y)
• void scroll_sprite (uint8_t nb, int8_t x, int8_t y)
• void hide_sprite (uint8_t nb)
• void set_data (uint8_t ∗vram_addr, const uint8_t ∗data, uint16_t len) OLDCALL
• void set_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t ∗vram_addr, const uint8_t ∗tiles) OLDCALL
• void set_tile_data (uint16_t first_tile, uint8_t nb_tiles, const uint8_t ∗data)
• void set_bkg_native_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data)
• void set_sprite_native_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data)
• void set_native_tile_data (uint16_t first_tile, uint8_t nb_tiles, const uint8_t ∗data)
• void init_bkg (uint8_t c) OLDCALL
• void vmemset (void ∗s, uint8_t c, size_t n) OLDCALL
• void fill_bkg_rect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile) OLDCALL
• void flush_shadow_attributes (void) OLDCALL
• uint8_t _switch_prg0 (uint8_t bank) OLDCALL
Variables
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 283
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
284
joypad
mode()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 285
See also
mode()
See also
mode()
See also
set_sprite_prop().
See also
set_sprite_prop()
See also
set_sprite_prop()
See also
set_sprite_prop()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
286
Parameters
The resulting format is four greyscale colors packed into a single unsigned byte.
Example:
REG_BGP = DMG_PALETTE(DMG_BLACK, DMG_DARK_GRAY, DMG_LITE_GRAY, DMG_WHITE);
See also
Parameters
VARNAME Name of the variable which has a __bank_VARNAME companion symbol which is adjusted by
bankpack
Use this to obtain the bank number from a bank reference created with BANKREF().
See also
BANKREF_EXTERN(), BANKREF()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 287
Parameters
See also
More than one BANKREF() may be created per file, but each call should always use a unique VARNAME.
Use BANKREF_EXTERN() within another source file to make the variable and it's data accesible there.
Parameters
This makes a BANKREF() reference in another source file accessible in the current file for use with BANK().
See also
BANKREF(), BANK()
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
288
Parameters
See also
SWITCH_ROM_UNROM
Parameters
See also
display_off, DISPLAY_OFF
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 289
HIDE_LEFT_COLUMN
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
290
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 291
uint8_t nb_palettes,
const palette_color_t ∗ rgb_data )
See also
add_VBL()
See also
add_VBL()
See also
add_LCD(), remove_VBL()
Parameters
h The handler to be called whenever a V-blank interrupt occurs.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
292
Note
See also
ISR_VECTOR()
On the current NES implementation, this handler is actually faked, and called by the default VBL handler after
a manual delay loop. Only one such faked "interrupt" is possible per frame. This means the CPU cycles
wasted in the delay loop increase with higher values of _lcd_scanline. In practice, it makes this functionality
mostly suited for a top status bar.
See also
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 293
Reads and returns the current state of the joypad. Follows Nintendo's guidelines for reading the pad. Return value
is an OR of J_∗
When testing for multiple different buttons, it's best to read the joypad state once into a variable and then test using
that variable.
See also
See also
joypad
J_START, J_SELECT, J_A, J_B, J_UP, J_DOWN, J_LEFT, J_RIGHT
Waits until at least one of the buttons given in mask are pressed.
Parameters
Normally only used for checking one key, but it will support many, even J_LEFT at the same time as J_RIGHT. :)
Note
Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns.
See also
joypad
J_START, J_SELECT, J_A, J_B, J_UP, J_DOWN, J_LEFT, J_RIGHT
Waits until at least one of the buttons given in mask are pressed.
Note
Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
294
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
See also
joypad_init(), joypads_t
Polls all avaliable joypads (for the GB and ones connected via SGB)
Parameters
joypads pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with
joypad_init()
See also
joypad_init(), joypads_t
Parameters
joypads pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with
joypad_init()
See also
joypad_init(), joypads_t
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 295
Note
Use CRITICAL {...} instead for creating a block of of code which should execute with interrupts temporarily
turned off.
See also
Note
Use CRITICAL {...} instead for creating a block of of code which should execute with interrupts temporarily
turned off.
This function may be called as many times as you like; however the first call to enable_interrupts will re-enable them.
See also
See also
DISPLAY_ON
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
296
See also
DISPLAY_ON
See also
DISPLAY_ON
Parameters
addr address to write to
v value
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 297
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data. Each Tile is 16 bytes in size (8x8
pixels, 2 bits-per-pixel).
Note: Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
See also
set_tile_data
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data. Each Tile is 16 bytes in size (8x8
pixels, 2 bits-per-pixel).
Note
Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
GBC only: VBK_REG determines which bank of tile patterns are written to.
See also
set_win_data, set_tile_data
See also
Sets VRAM Tile Pattern data for the Background / Window using 1bpp source data
Parameters
Similar to set_bkg_data, except source data is 1 bit-per-pixel which gets expanded into 2 bits-per-pixel.
For a given bit that represent a pixel:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
298
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
• Writing a width that does not match the source map width and more than one row high at a time.
See also
SHOW_BKG
set_bkg_data, set_bkg_submap, set_win_tiles, set_tiles
Parameters
Entries are copied from map at tiles to the Background Tile Map starting at x, y writing across for w tiles and down
for h tiles.
Use set_bkg_submap() instead when:
• Writing a width that does not match the source map width and more than one row high at a time.
Note
Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 299
• Bit 7 - Priority flag. When this is set, it puts the tile above the sprites with colour 0 being transparent.
0: Below sprites
1: Above sprites
Note: SHOW_BKG needs to be set for these priorities to take place.
• Bit 6 - Vertical flip. Dictates which way up the tile is drawn vertically.
0: Normal
1: Flipped Vertically
• Bit 5 - Horizontal flip. Dictates which way up the tile is drawn horizontally.
0: Normal
1: Flipped Horizontally
• Bit 3 - Character Bank specification. Dictates from which bank of Background Tile Patterns the tile is taken.
0: Bank 0
1: Bank 1
• Bit 0 - Bits 0-2 indicate which of the 7 BKG colour palettes the tile is assigned.
See also
SHOW_BKG
set_bkg_data, set_bkg_submap, set_win_tiles, set_tiles
Parameters
Entries are copied from map at tiles to the Background Tile Map starting at x, y writing across for w tiles and down
for h tiles.
NES 16x16 Tile Attributes are tightly packed into 4 attributes per byte, with each 16x16 area of a 32x32 pixel block
using the bits as follows: D1-D0: Top-left 16x16 pixels D3-D2: Top-right 16x16 pixels D5-D4: Bottom-left 16x16
pixels D7-D6: Bottom-right 16x16 pixels
https://www.nesdev.org/wiki/PPU_attribute_tables
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
300
See also
SHOW_BKG
set_bkg_data, set_bkg_submap_attributes, set_win_tiles, set_tiles
• Writing a width that does not match the source map width and more than one row high at a time.
See also
SHOW_BKG
set_bkg_data, set_bkg_submap_attributes, set_win_tiles, set_tiles
Parameters
x X Start position in both the Source Attribute Map and hardware Background Map attribute
coordinates. Range 0 - 255
y Y Start position in both the Source Attribute Map and hardware Background Map attribute
coordinates. Range 0 - 255
w Width of area to set in Attributes. Range 1 - 127
h Height of area to set in Attributes. Range 1 - 127
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 127
_w
Entries are copied from map to the Background Attribute Map starting at x, y writing across for w tiles and down for
h attributes, using map_w as the rowstride for the source attribute map.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 301
The x and y parameters are in Source Attribute Map Attribute coordinates. The location tiles will be written to on
the hardware Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-15
(they are bit-masked: x & 0xF and y & 0xF). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Attribute Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source attribute map entry.
Writes that exceed coordinate 15/14 on the x / y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
302
This is identical to set_bkg_tiles() except that it adds the base_tile parameter for when a tile map's tiles don't start
at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Sets a rectangular area of the Background Tile Map using a sub-region from a source tile map. Useful for scrolling
implementations of maps larger than 32 x 32 tiles.
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Background Tile Map starting at x, y writing across for w tiles and down for h
tiles, using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 303
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Parameters
This is identical to set_bkg_submap() except that it adds the base_tile parameter for when a tile map's tiles don't
start at index zero. (For example, the tiles used by the map range from 100 -> 120 in VRAM instead of 0 -> 20).
See also
get_bkg_tile_xy, get_tiles
Copies a rectangular region of Background Tile Map entries into a buffer.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
304
Parameters
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Entries are copied into tiles from the Background Tile Map starting at x, y reading across for w tiles and down for h
tiles.
One byte per tile.
The buffer pointed to by tiles should be at least x x y bytes in size.
See also
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
a tile attributes
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 305
uint8_t x,
uint8_t y,
uint8_t a ) [inline]
Set single attribute data a on background layer at x,y
Please note that this is just a wrapper function for set_bkg_submap_attributes_nes16x16() and divides the coordi-
nates and dimensions by 2 to achieve this. It is intended to make code more portable by using the same coordinate
system that systems with the much more common 8x8 attribute resolution would use.
Parameters
x X-coordinate
y Y-coordinate
a tile attributes
Parameters
x X-coordinate
y Y-coordinate
Returns
Parameters
x X-coordinate
y Y-coordinate
Returns
Note
In general avoid reading from VRAM since that memory is not accessible at all times. It is also not supported
by GBDK on the NES platform. See coding guidelines for more details.
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
306
0,0 is the top left corner of the GB screen. The Background Layer wraps around the screen, so when part of it goes
off the screen it appears on the opposite side (factoring in the larger size of the Background Layer versus the screen
size).
The background layer is always under the Window Layer.
See also
SHOW_BKG, HIDE_BKG
Parameters
See also
move_bkg
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data. Each Tile is 16 bytes in size (8x8
pixels, 2 bits-per-pixel).
Note
Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 307
See also
Sets VRAM Tile Pattern data for Sprites using 1bpp source data
Parameters
Similar to set_sprite_data, except source data is 1 bit-per-pixel which gets expanded into 2 bits-per-pixel.
For a given bit that represent a pixel:
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
Parameters
In 8x16 mode:
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
308
• The sprite will also display the next tile (tile + 1) directly below (y + 8) the first tile.
• The lower bit of the tile number is ignored: the upper 8x8 tile is (tile & 0xFE), and the lower 8x8 tile is (tile |
0x01).
• See: SPRITES_8x16
Parameters
See also
Parameters
• Bit 7 - Priority flag. When this is set the sprites appear behind the background and window layer.
0: infront
1: behind
• Bit 6 - Vertical flip. Dictates which way up the sprite is drawn vertically.
0: normal
1:upside down
• Bit 5 - Horizontal flip. Dictates which way up the sprite is drawn horizontally.
0: normal
1:back to front
• Bit 4 - DMG/Non-CGB Mode Only. Assigns either one of the two b/w palettes to the sprite.
0: OBJ palette 0
1: OBJ palette 1
• Bit 3 - GBC only. Dictates from which bank of Sprite Tile Patterns the tile is taken.
0: Bank 0
1: Bank 1
• Bit 0 - GBC only. Bits 0-2 indicate which of the 7 OBJ colour palettes the sprite is assigned.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 309
Parameters
See also
Parameters
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
See also
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
310
See also
Parameters
Entries are copied from tiles to Tile Map at address vram_addr starting at x, y writing across for w tiles and down
for h tiles.
One byte per source tile map entry.
There are two 32x30 Tile Maps in VRAM at addresses 2000h-23FFh and 2400h-27FFh.
See also
set_bkg_tiles
See also
set_bkg_data, set_data
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 311
Sets VRAM Tile Pattern data for the Background in the native format
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
312
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
See also
set_tile_data
Sets VRAM Tile Pattern data for the Background / Window in the native format
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
See also
set_win_data, set_tile_data
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
Sets VRAM Tile Pattern data for Sprites in the native format
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 313
Parameters
When first_tile is larger than 256 on the GB/AP, it will write to sprite data instead of background data.
The bit depth of the source Tile Pattern data depends on which console is being used:
Parameters
Parameters
Note
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
314
Parameters
Note
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.66 gbdk-lib/include/nes/rgb_to_nes_macro.h File Reference 315
See also
• #define RGB_TO_NES(c)
Macros
Functions
Variables
• uint16_t __rand_seed
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
316
Author
Parameters
The seed should be different each time, otherwise the same pseudo-random sequence will be generated.
The DIV Register (DIV_REG) is sometimes used as a seed, particularly if read at some variable point in time (such
as when the player presses a button).
Only needs to be called once to initialize, but may be called again to re-initialize with the same or a different seed.
See also
rand(), randw()
Parameters
Note: initarand() calls initrand() with the same seed value, and uses rand() to initialize the random generator.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.68 gbdk-lib/include/setjmp.h File Reference 317
See also
• #define SP_SIZE 1
• #define BP_SIZE 0
• #define SPX_SIZE 0
• #define BPX_SIZE SPX_SIZE
• #define RET_SIZE 2
• #define setjmp(jump_buf) __setjmp(jump_buf)
Typedefs
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
318
Data Structures
• struct joypads_t
Macros
• #define SEGA
• #define VBK_REG VDP_ATTR_SHIFT
• #define J_UP 0b00000001
• #define J_DOWN 0b00000010
• #define J_LEFT 0b00000100
• #define J_RIGHT 0b00001000
• #define J_B 0b00010000
• #define J_A 0b00100000
• #define M_TEXT_OUT 0x02U
• #define M_TEXT_INOUT 0x03U
• #define M_NO_SCROLL 0x04U
• #define M_NO_INTERP 0x08U
• #define S_FLIPX 0x02U
• #define S_FLIPY 0x04U
• #define S_PALETTE 0x08U
• #define S_PRIORITY 0x10U
• #define S_PAL(n) 0
• #define __WRITE_VDP_REG(REG, v) shadow_##REG=(v);__critical{VDP_CMD=(shadow_##REG),VDP←-
_CMD=REG;}
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 319
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
320
Typedefs
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 321
• void set_data (uint16_t dst, const void ∗src, uint16_t size) Z88DK_CALLEE PRESERVES_REGS(iyh
• void vmemcpy (uint16_t dst, const void ∗src, uint16_t size) Z88DK_CALLEE PRESERVES_REGS(iyh
• void set_tile_map (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void set_tile_map_compat (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void set_bkg_based_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles, uint8_t base_tile)
• void set_win_based_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles, uint8_t base_tile)
• void set_bkg_attributes (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles)
• void set_tile_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t ∗map)
Z88DK_CALLEE PRESERVES_REGS(iyh
• void set_tile_submap_compat (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t ∗map)
Z88DK_CALLEE PRESERVES_REGS(iyh
• void set_bkg_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w)
• void set_win_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w)
• void set_bkg_based_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w,
uint8_t base_tile)
• void set_win_based_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w,
uint8_t base_tile)
• void set_bkg_submap_attributes (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w)
• void fill_rect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE PRESERVES_REGS(iyh
• void fill_rect_compat (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void SET_SHADOW_OAM_ADDRESS (void ∗address)
• void set_sprite_tile (uint8_t nb, uint8_t tile)
• uint8_t get_sprite_tile (uint8_t nb)
• void set_sprite_prop (uint8_t nb, uint8_t prop)
• uint8_t get_sprite_prop (uint8_t nb)
• void move_sprite (uint8_t nb, uint8_t x, uint8_t y)
• void scroll_sprite (uint8_t nb, int8_t x, int8_t y)
• void hide_sprite (uint8_t nb)
• void set_vram_byte (uint8_t ∗addr, uint8_t v) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ set_attributed_tile_xy (uint8_t x, uint8_t y, uint16_t t) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ set_tile_xy (uint8_t x, uint8_t y, uint8_t t) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ set_attribute_xy (uint8_t x, uint8_t y, uint8_t a) Z88DK_CALLEE PRESERVES_REGS(iyh
• uint8_t ∗ get_bkg_xy_addr (uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh
Variables
• void c
• void d
• void e
• void iyh
• void iyl
• void h
• void l
• volatile uint16_t sys_time
• uint16_t _current_2bpp_palette
• uint16_t _current_1bpp_colors
• uint8_t _map_tile_offset
• uint8_t _submap_tile_offset
• volatile uint8_t shadow_OAM [ ]
• volatile uint8_t _shadow_OAM_base
• volatile uint8_t _shadow_OAM_OFF
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
322
joypad
mode()
mode()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 323
See also
mode()
See also
set_interrupts(),
add_VBL
See also
set_interrupts(),
add_LCD
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
324
See also
move_win()
See also
move_win()
See also
move_win()
See also
move_win()
See also
display_off, DISPLAY_OFF
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 325
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
HIDE_LEFT_COLUMN
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
326
Parameters
VARNAME Name of the variable which has a __bank_VARNAME companion symbol which is adjusted by
bankpack
Use this to obtain the bank number from a bank reference created with BANKREF().
See also
BANKREF_EXTERN(), BANKREF()
Parameters
See also
More than one BANKREF() may be created per file, but each call should always use a unique VARNAME.
Use BANKREF_EXTERN() within another source file to make the variable and it's data accesible there.
Parameters
This makes a BANKREF() reference in another source file accessible in the current file for use with BANK().
See also
BANKREF(), BANK()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 327
Parameters
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
328
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 329
See also
Parameters
Note
This disables and then re-enables interrupts so it must be used outside of a critical section.
See also
enable_interrupts(), disable_interrupts()
VBL_IFLAG, LCD_IFLAG, TIM_IFLAG, SIO_IFLAG, JOY_IFLAG
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
330
See also
add_VBL()
See also
add_LCD(), remove_VBL()
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 331
DISPLAY_ON
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
332
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
Parameters
joypads pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with
joypad_init()
See also
joypad_init(), joypads_t
• Interrupts are temporarily disabled and then re-enabled during this call.
• You can check to see if _cpu == CGB_TYPE before using this function.
See also
cpu_slow(), _cpu
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 333
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
See also
set_tile_data
Sets VRAM Tile Pattern data for the Background / Window in the native format
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
334
See also
set_win_data, set_tile_data
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
Sets VRAM Tile Pattern data for Sprites in the native format
Parameters
Writes nb_tiles tiles to VRAM starting at first_tile, tile data is sourced from data.
GBC only: VBK_REG determines which bank of tile patterns are written to.
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 335
Parameters
dst destination VRAM Address
src Pointer to source buffer
size Number of bytes to copy
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
336
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 337
Parameters
x X Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
y Y Start position in both the Source Tile Map and hardware Background Map tile coordinates. Range
0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Background Tile Map starting at x, y writing across for w tiles and down for h
tiles, using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_bkg_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
See set_bkg_tiles for setting CGB attribute maps with VBK_REG.
See also
SHOW_BKG
set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
338
Parameters
x X Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
y Y Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255
w Width of area to set in tiles. Range 1 - 255
h Height of area to set in tiles. Range 1 - 255
map Pointer to source tile map data
map←- Width of source tile map in tiles. Range 1 - 255
_w
Entries are copied from map to the Window Tile Map starting at x, y writing across for w tiles and down for h tiles,
using map_w as the rowstride for the source tile map.
The x and y parameters are in Source Tile Map tile coordinates. The location tiles will be written to on the hardware
Background Map is derived from those, but only uses the lower 5 bits of each axis, for range of 0-31 (they are
bit-masked: x & 0x1F and y & 0x1F). As a result the two coordinate systems are aligned together.
In order to transfer tile map data in a way where the coordinate systems are not aligned, an offset from the Source
Tile Map pointer can be passed in: (map_ptr + x + (y ∗ map_width)).
For example, if you want the tile id at 1,2 from the source map to show up at 0,0 on the hardware Background Map
(instead of at 1,2) then modify the pointer address that is passed in: map_ptr + 1 + (2 ∗ map_width)
Use this instead of set_win_tiles when the source map is wider than 32 tiles or when writing a width that does not
match the source map width.
One byte per source tile map entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
• VBK_REG = VBK_TILES Tile Numbers are written
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 339
Parameters
In 8x16 mode:
• The sprite will also display the next tile (tile + 1) directly below (y + 8) the first tile.
• The lower bit of the tile number is ignored: the upper 8x8 tile is (tile & 0xFE), and the lower 8x8 tile is (tile |
0x01).
• See: SPRITES_8x16
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
340
Parameters
See also
Parameters
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
See also
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 341
Parameters
Parameters
addr address to write to
v value
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
t tile index
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
342
Parameters
x X-coordinate
y Y-coordinate
a tile attributes
Returns
returns the address of tile attribute, so you may use faster set_vram_byte() later
20.69.5.1 c void c
20.69.5.2 d void d
20.69.5.3 e void e
20.69.5.6 h uint8_t h
20.69.5.7 l void l
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.70 gbdk-lib/include/stdatomic.h File Reference 343
This flag is modified by all sms/gg GBDK API calls that write to the VDP. It is set to DISABLED when they start and
ENABLED when they complete.
Note
It is recommended to avoid writing to the Video Display Processor (VDP) during an interrupt service routine
(ISR) since it can corrupt the VDP pointer of an VDP operation already in progress.
If it is necessary, this flag can be used during an ISR to determine whether a VDP operation is already in progress.
If the value is 1 then avoid writing to the VDP (tiles, map, scrolling, colors, etc).
// at the beginning of and ISR that would write to the VDP
if (_shadow_OAM_OFF) return;
See also
docs_consoles_safe_display_controller_access
Data Structures
• struct atomic_flag
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
344
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 345
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
346
Typedefs
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 347
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
348
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 349
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
350
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.74 gbdk-lib/include/stdio.h File Reference 351
Functions
Parameters
c Character to print
Parameters
• %c (character)
• %u (unsigned int)
• %d (signed int)
• %s (string)
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
352
Warning: to correctly pass parameters (such as chars, ints, etc) all of them should always be explicitly cast as
when calling the function. See docs_chars_varargs for more details.
Parameters
Parameters
Reads until either a terminating newline or an EOF, which it replaces with '\0'. No check for buffer overrun is
performed.
Returns: Buffer pointed to by s
Macros
• #define __reentrant
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.75 gbdk-lib/include/stdlib.h File Reference 353
Parameters
Parameters
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
354
Parameters
See also
atoi()
Parameters
n Int to convert to a string
s String to store the converted number
radix Numerical base for converted number, ex: 10 is decimal base (parameter is required but not utilized on
Game Boy and Analogue Pocket)
Can be used with set_bkg_based_tiles() for printing if the digit character tiles are not ascii-mapped.
Returns: Pointer to converted string
Parameters
n Unsigned Int to convert to a string
s String to store the converted number
radix Numerical base for converted number, ex: 10 is decimal base (parameter is required but not utilized on
Game Boy and Analogue Pocket)
Can be used with set_bkg_based_tiles() for printing if the digit character tiles are not ascii-mapped.
Returns: Pointer to converted string
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.75 gbdk-lib/include/stdlib.h File Reference 355
Parameters
n Long int to convert to a string
s String to store the converted number
radix Numerical base for converted number, ex: 10 is decimal base (parameter is required but not utilized on
Game Boy and Analogue Pocket)
Can be used with set_bkg_based_tiles() for printing if the digit character tiles are not ascii-mapped.
Returns: Pointer to converted string
Parameters
n Unsigned Long Int to convert to a string
s String to store the converted number
radix Numerical base for converted number, ex: 10 is decimal base (parameter is required but not utilized on
Game Boy and Analogue Pocket)
Can be used with set_bkg_based_tiles() for printing if the digit character tiles are not ascii-mapped.
Returns: Pointer to converted string
Parameters
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
356
Parameters
Returns: Pointer to array entry that matches the search key. If key is not found, NULL is returned.
Parameters
Macros
• #define CLOCKS_PER_SEC 60
Typedefs
Functions
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.78 gbdk-lib/include/typeof.h File Reference 357
See also
sys_time, time()
Parameters
t If pointer t is not NULL, it's value will be set to the same seconds calculation as returned by the function.
sys_time, clock()
• #define TYPEOF_INT 1
• #define TYPEOF_SHORT 2
• #define TYPEOF_CHAR 3
• #define TYPEOF_LONG 4
• #define TYPEOF_FLOAT 5
• #define TYPEOF_FIXED16X16 6
• #define TYPEOF_BIT 7
• #define TYPEOF_BITFIELD 8
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
358
• #define TYPEOF_SBIT 9
• #define TYPEOF_SFR 10
• #define TYPEOF_VOID 11
• #define TYPEOF_STRUCT 12
• #define TYPEOF_ARRAY 13
• #define TYPEOF_FUNCTION 14
• #define TYPEOF_POINTER 15
• #define TYPEOF_FPOINTER 16
• #define TYPEOF_CPOINTER 17
• #define TYPEOF_GPOINTER 18
• #define TYPEOF_PPOINTER 19
• #define TYPEOF_IPOINTER 20
• #define TYPEOF_EEPPOINTER 21
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
20.78 gbdk-lib/include/typeof.h File Reference 359
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
Index
_AUD3WAVERAM __assert
hardware.h, 195 assert.h, 107
_BIOS __bool_true_false_are_defined
hardware.h, 208, 221 stdbool.h, 344
_HRAM __call__banked
hardware.h, 195 far_ptr.h, 249
_IO __call_banked_addr
hardware.h, 195 far_ptr.h, 249
_OAMRAM __call_banked_bank
hardware.h, 195 far_ptr.h, 249
_RAM __call_banked_ptr
hardware.h, 195 far_ptr.h, 249
_RAMBANK __current_base_prop
hardware.h, 195 metasprites.h, 229, 237
_SCRN0 __current_base_tile
hardware.h, 194 metasprites.h, 229, 232, 237, 242
_SCRN1 __current_metasprite
hardware.h, 195 metasprites.h, 229, 232, 237, 242
_SRAM __far_ptr, 79
hardware.h, 195 fn, 79
_SYSTEM ofs, 79
hardware.h, 208, 221 ptr, 79
_VRAM seg, 79
hardware.h, 194 segfn, 79
_VRAM8000 segofs, 79
hardware.h, 194 __memcpy
_VRAM8800 string.h, 90
hardware.h, 194 __rand_seed
_VRAM9000 rand.h, 317
hardware.h, 194 __reentrant
__BYTES stdlib.h, 353
hardware.h, 182, 201, 215 __render_shadow_OAM
__BYTE_REG metasprites.h, 229, 232, 237, 242
hardware.h, 182, 201, 215 __setjmp
__GBDK_VERSION setjmp.h, 318
version.h, 254 _cpu
__HandleCrash gb.h, 172
crash_handler.h, 117 _current_1bpp_colors
__PTRDIFF_T_DEFINED gb.h, 173
stddef.h, 344 msx.h, 278
__READ_VDP_REG nes.h, 315
msx.h, 261 sms.h, 342
sms.h, 323 _current_2bpp_palette
__REG msx.h, 278
hardware.h, 182, 209, 211, 212 sms.h, 342
__SHADOW_REG _current_bank
hardware.h, 209 gb.h, 173
__SIZE_T_DEFINED msx.h, 278
stddef.h, 344 nes.h, 314
types.h, 101, 102, 105 sms.h, 325
__WCHAR_T_DEFINED _fixed, 80
stddef.h, 344 b, 80
__WRITE_VDP_REG h, 80
msx.h, 261 l, 80
sms.h, 323 w, 80
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
362 INDEX
_io_in assert
gb.h, 172 assert.h, 107
_io_out assert.h
gb.h, 173 __assert, 107
_io_status assert, 107
gb.h, 172 AT
_is_GBA types.h, 103
gb.h, 172 atoi
_map_tile_offset stdlib.h, 353
gb.h, 173 atol
msx.h, 278 stdlib.h, 354
nes.h, 315 atomic_flag, 80
sms.h, 343 flag, 81
_shadow_OAM_OFF atomic_flag_clear
msx.h, 278 stdatomic.h, 343
sms.h, 343 atomic_flag_test_and_set
_shadow_OAM_base stdatomic.h, 343
gb.h, 173 AUD1SWEEP_DOWN
msx.h, 278 hardware.h, 184
nes.h, 315 AUD1SWEEP_LENGTH
sms.h, 343 hardware.h, 184
_submap_tile_offset AUD1SWEEP_TIME
gb.h, 173 hardware.h, 184
msx.h, 278 AUD1SWEEP_UP
nes.h, 315 hardware.h, 184
sms.h, 343 AUD3WAVE
_switch_prg0 hardware.h, 197
nes.h, 314 AUD4POLY_WIDTH_15BIT
hardware.h, 185
abs AUD4POLY_WIDTH_7BIT
stdlib.h, 353 hardware.h, 185
add_JOY AUDENA_OFF
gb.h, 142 hardware.h, 186
msx.h, 268 AUDENA_ON
sms.h, 330 hardware.h, 186
add_LCD AUDENV_DOWN
gb.h, 141 hardware.h, 192
msx.h, 268 AUDENV_LENGTH
nes.h, 292 hardware.h, 192
sms.h, 330 AUDENV_UP
add_low_priority_TIM hardware.h, 192
gb.h, 142 AUDENV_VOL
add_SIO hardware.h, 192
gb.h, 142 AUDHIGH_LENGTH_OFF
msx.h, 268 hardware.h, 192
sms.h, 330 AUDHIGH_LENGTH_ON
add_TIM hardware.h, 192
gb.h, 142 AUDHIGH_RESTART
msx.h, 268 hardware.h, 192
sms.h, 330 AUDLEN_DUTY_12_5
add_VBL hardware.h, 192
gb.h, 141 AUDLEN_DUTY_25
msx.h, 268 hardware.h, 192
nes.h, 291 AUDLEN_DUTY_50
sms.h, 330 hardware.h, 192
AND AUDLEN_DUTY_75
drawing.h, 118 hardware.h, 192
arand AUDLEN_LENGTH
rand.h, 317
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 363
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
364 INDEX
BOOLEAN cgb_compatibility
types.h, 104 cgb.h, 116
box sms.h, 332
drawing.h, 120 CGB_TYPE
BP_SIZE gb.h, 133
setjmp.h, 317 CHAR_BIT
BPX_SIZE limits.h, 255
setjmp.h, 317 CHAR_MAX
bsearch limits.h, 255
stdlib.h, 355 CHAR_MIN
BYTE limits.h, 255
types.h, 104 circle
drawing.h, 121
c clock
gb.h, 172 time.h, 357
gbdecompress.h, 176 clock_t
msx.h, 277 types.h, 101, 102, 105
sgb.h, 245 CLOCKS_PER_SEC
sms.h, 342 time.h, 357
string.h, 97 cls
calloc console.h, 246
stdlib.h, 355 color
cancel_pending_interrupts drawing.h, 121
gb.h, 143 COMPAT_PALETTE
msx.h, 268 gb.h, 138
sms.h, 330 msx.h, 265
cgb.h nes.h, 289
cgb_compatibility, 116 sms.h, 327
cpu_fast, 116 console.h
cpu_slow, 116 cls, 246
palette_color_t, 114 gotoxy, 246
RGB, 112 posx, 246
RGB8, 112 posy, 246
RGB_AQUA, 113 setchar, 246
RGB_BLACK, 113 cpu_fast
RGB_BLUE, 113 cgb.h, 116
RGB_BROWN, 114 msx.h, 270
RGB_CYAN, 113 sms.h, 332
RGB_DARKBLUE, 113 cpu_slow
RGB_DARKGRAY, 113 cgb.h, 116
RGB_DARKGREEN, 113 crash_handler.h
RGB_DARKRED, 113 __HandleCrash, 117
RGB_DARKYELLOW, 113 CRITICAL
RGB_GREEN, 113 types.h, 104
RGB_LIGHTFLESH, 114 ctype.h
RGB_LIGHTGRAY, 113 isalpha, 107
RGB_ORANGE, 114 isdigit, 108
RGB_PINK, 113 islower, 108
RGB_PURPLE, 113 isspace, 108
RGB_RED, 113 isupper, 107
RGB_TEAL, 114 tolower, 108
RGB_WHITE, 114 toupper, 108
RGB_YELLOW, 113 CURRENT_BANK
RGBHTML, 112 gb.h, 134
set_bkg_palette, 114 msx.h, 263
set_bkg_palette_entry, 115 nes.h, 286
set_default_palette, 116 sms.h, 326
set_sprite_palette, 114
set_sprite_palette_entry, 115 d
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 365
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
366 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 367
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
368 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 369
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
370 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 371
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
372 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 373
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
374 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 375
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
376 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 377
JOY_IFLAG joypads_t, 83
gb.h, 131 joypads_t, 81
msx.h, 262 joy0, 82
sms.h, 324 joy1, 82
JOY_P1_DOWN joy2, 83
hardware.h, 206, 219 joy3, 83
JOY_P1_LATCH joypads, 83
hardware.h, 202, 215 npads, 82
JOY_P1_LEFT
hardware.h, 206, 219 KEY1_REG
JOY_P1_LIGHT hardware.h, 198
hardware.h, 207, 220 KEY1F_DBLSPEED
JOY_P1_RIGHT hardware.h, 189
hardware.h, 206, 219 KEY1F_PREPARE
JOY_P1_SW1 hardware.h, 189
hardware.h, 206, 219
JOY_P1_SW2 l
hardware.h, 206, 219 _fixed, 80
JOY_P1_TRIGGER gb.h, 172
hardware.h, 206, 219 msx.h, 278
JOY_P1_UP sms.h, 342
hardware.h, 206, 219 labs
JOY_P2_DOWN stdlib.h, 353
hardware.h, 206, 219 LCD_IFLAG
JOY_P2_LATCH gb.h, 131
hardware.h, 202, 215 msx.h, 261
JOY_P2_LEFT sms.h, 323
hardware.h, 206, 219 LCDC_REG
JOY_P2_LIGHT hardware.h, 197
hardware.h, 207, 220 LCDCF_B_BG8000
JOY_P2_RIGHT hardware.h, 187
hardware.h, 206, 219 LCDCF_B_BG9C00
JOY_P2_SW1 hardware.h, 187
hardware.h, 206, 219 LCDCF_B_BGON
JOY_P2_SW2 hardware.h, 187
hardware.h, 207, 220 LCDCF_B_OBJ16
JOY_P2_TRIGGER hardware.h, 187
hardware.h, 207, 219 LCDCF_B_OBJON
JOY_P2_UP hardware.h, 187
hardware.h, 206, 219 LCDCF_B_ON
JOY_RESET hardware.h, 187
hardware.h, 207, 220 LCDCF_B_WIN9C00
joypad hardware.h, 187
gb.h, 144 LCDCF_B_WINON
msx.h, 269 hardware.h, 187
nes.h, 292 LCDCF_BG8000
sms.h, 331 hardware.h, 186
joypad_ex LCDCF_BG8800
gb.h, 145 hardware.h, 186
msx.h, 270 LCDCF_BG9800
nes.h, 294 hardware.h, 186
sms.h, 332 LCDCF_BG9C00
joypad_init hardware.h, 186
gb.h, 145 LCDCF_BGOFF
msx.h, 269 hardware.h, 187
nes.h, 293 LCDCF_BGON
sms.h, 331 hardware.h, 187
joypads LCDCF_OBJ16
hardware.h, 187
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
378 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 379
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
380 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 381
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
382 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 383
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
384 INDEX
PPUCTRL_INC32 putchar
hardware.h, 210 stdio.h, 351
PPUCTRL_NMI puts
hardware.h, 209 stdio.h, 352
PPUCTRL_SPR_8X16
hardware.h, 210 qsort
PPUCTRL_SPR_8X8 stdlib.h, 356
hardware.h, 209
PPUCTRL_SPR_CHR R0_CB_INPUT
hardware.h, 210 hardware.h, 203
PPUMASK_BLUE R0_CB_OUTPUT
hardware.h, 210 hardware.h, 203
PPUMASK_GREEN R0_DEFAULT
hardware.h, 210 hardware.h, 203, 217
PPUMASK_MONOCHROME R0_ES
hardware.h, 210 hardware.h, 203, 217
PPUMASK_RED R0_ES_OFF
hardware.h, 210 hardware.h, 203, 217
PPUMASK_SHOW_BG R0_HSCRL
hardware.h, 210 hardware.h, 216
PPUMASK_SHOW_BG_LC R0_HSCRL_INH
hardware.h, 210 hardware.h, 216
PPUMASK_SHOW_SPR R0_IE1
hardware.h, 210 hardware.h, 203, 216
PPUMASK_SHOW_SPR_LC R0_IE1_OFF
hardware.h, 210 hardware.h, 203, 216
PRESERVES_REGS R0_IE2
types.h, 103 hardware.h, 203
printf R0_IE2_OFF
stdio.h, 351 hardware.h, 203
prop R0_LCB
OAM_item_t, 85 hardware.h, 216
props R0_NO_LCB
metasprite_t, 84 hardware.h, 216
provides.h R0_SCR_MODE1
USE_C_MEMCPY, 86, 87 hardware.h, 203
USE_C_STRCMP, 86, 87 R0_SCR_MODE2
USE_C_STRCPY, 86, 87 hardware.h, 203
PSG_CH0 R0_SCR_MODE3
hardware.h, 202, 215 hardware.h, 203
PSG_CH1 R0_SS
hardware.h, 202, 216 hardware.h, 217
PSG_CH2 R0_SS_OFF
hardware.h, 202, 216 hardware.h, 216
PSG_CH3 R0_VSCRL
hardware.h, 202, 216 hardware.h, 216
PSG_LATCH R0_VSCRL_INH
hardware.h, 202, 215 hardware.h, 216
PSG_VOLUME R10_INT_EVERY
hardware.h, 203, 216 hardware.h, 206, 219
ptr R10_INT_OFF
__far_ptr, 79 hardware.h, 206, 219
PTRDIFF_MAX R1_DEFAULT
stdint.h, 348 hardware.h, 204, 217
PTRDIFF_MIN R1_DISP_OFF
stdint.h, 348 hardware.h, 204, 217
ptrdiff_t R1_DISP_ON
stddef.h, 345 hardware.h, 204, 217
R1_IE
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 385
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
386 INDEX
rAUDVOL RGB_BLACK
hardware.h, 185 cgb.h, 113
rBCPD nes.h, 283
hardware.h, 191 RGB_BLUE
rBCPS cgb.h, 113
hardware.h, 191 nes.h, 283
rBGP RGB_BROWN
hardware.h, 189 cgb.h, 114
rDIV RGB_CYAN
hardware.h, 182 cgb.h, 113
rDMA nes.h, 283
hardware.h, 189 RGB_DARKBLUE
realloc cgb.h, 113
stdlib.h, 355 nes.h, 283
receive_byte RGB_DARKGRAY
gb.h, 144 cgb.h, 113
refresh_OAM nes.h, 284
gb.h, 146 RGB_DARKGREEN
msx.h, 269 cgb.h, 113
nes.h, 296 nes.h, 283
sms.h, 331 RGB_DARKRED
remove_JOY cgb.h, 113
gb.h, 141 nes.h, 283
msx.h, 268 RGB_DARKYELLOW
sms.h, 330 cgb.h, 113
remove_LCD nes.h, 283
gb.h, 140 RGB_GREEN
msx.h, 267 cgb.h, 113
nes.h, 291 nes.h, 283
sms.h, 330 RGB_LIGHTFLESH
remove_SIO cgb.h, 114
gb.h, 140 RGB_LIGHTGRAY
msx.h, 268 cgb.h, 113
sms.h, 330 nes.h, 284
remove_TIM RGB_ORANGE
gb.h, 140 cgb.h, 114
msx.h, 268 RGB_PINK
sms.h, 330 cgb.h, 113
remove_VBL nes.h, 283
gb.h, 140 RGB_PURPLE
msx.h, 267 cgb.h, 113
nes.h, 291 nes.h, 283
sms.h, 329 RGB_RED
reset cgb.h, 113
gb.h, 146 nes.h, 283
RET_SIZE RGB_TEAL
setjmp.h, 317 cgb.h, 114
reverse RGB_TO_NES
string.h, 91, 95, 98 rgb_to_nes_macro.h, 315
RGB rgb_to_nes_macro.h
cgb.h, 112 RGB_TO_NES, 315
nes.h, 282 RGB_WHITE
RGB8 cgb.h, 114
cgb.h, 112 nes.h, 284
nes.h, 283 RGB_YELLOW
RGB_AQUA cgb.h, 113
cgb.h, 113 nes.h, 283
nes.h, 283 RGBHTML
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 387
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
388 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 389
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
390 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 391
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
392 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 393
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
394 INDEX
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 395
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
396 INDEX
time_t TYPEOF_GPOINTER
time.h, 357 typeof.h, 359
TMA_REG TYPEOF_INT
hardware.h, 195 typeof.h, 358
TO_FAR_PTR TYPEOF_IPOINTER
far_ptr.h, 247 typeof.h, 359
to_far_ptr TYPEOF_LONG
far_ptr.h, 249 typeof.h, 358
tolower TYPEOF_POINTER
ctype.h, 108 typeof.h, 359
toupper TYPEOF_PPOINTER
ctype.h, 108 typeof.h, 359
TRUE TYPEOF_SBIT
types.h, 106 typeof.h, 358
true TYPEOF_SFR
stdbool.h, 344 typeof.h, 358
typeof.h TYPEOF_SHORT
TYPEOF_ARRAY, 358 typeof.h, 358
TYPEOF_BIT, 358 TYPEOF_STRUCT
TYPEOF_BITFIELD, 358 typeof.h, 358
TYPEOF_CHAR, 358 TYPEOF_VOID
TYPEOF_CPOINTER, 359 typeof.h, 358
TYPEOF_EEPPOINTER, 359 types.h
TYPEOF_FIXED16X16, 358 __SIZE_T_DEFINED, 101, 102, 105
TYPEOF_FLOAT, 358 AT, 103
TYPEOF_FPOINTER, 359 BANKED, 104
TYPEOF_FUNCTION, 359 BOOLEAN, 104
TYPEOF_GPOINTER, 359 BYTE, 104
TYPEOF_INT, 358 clock_t, 101, 102, 105
TYPEOF_IPOINTER, 359 CRITICAL, 104
TYPEOF_LONG, 358 DWORD, 104
TYPEOF_POINTER, 359 FALSE, 106
TYPEOF_PPOINTER, 359 fixed, 104
TYPEOF_SBIT, 358 INT16, 101, 102, 105
TYPEOF_SFR, 358 INT32, 101, 102, 105
TYPEOF_SHORT, 358 INT8, 101, 102, 105
TYPEOF_STRUCT, 358 INTERRUPT, 104
TYPEOF_VOID, 358 LWORD, 104
TYPEOF_ARRAY NAKED, 103
typeof.h, 358 NONBANKED, 103
TYPEOF_BIT NORETURN, 103
typeof.h, 358 NULL, 106
TYPEOF_BITFIELD OLDCALL, 103
typeof.h, 358 POINTER, 106
TYPEOF_CHAR PRESERVES_REGS, 103
typeof.h, 358 SFR, 103
TYPEOF_CPOINTER size_t, 101, 102, 105
typeof.h, 359 TRUE, 106
TYPEOF_EEPPOINTER UBYTE, 104
typeof.h, 359 UDWORD, 104
TYPEOF_FIXED16X16 UINT16, 101, 102, 105
typeof.h, 358 UINT32, 101, 102, 105
TYPEOF_FLOAT UINT8, 101, 102, 105
typeof.h, 358 ULWORD, 104
TYPEOF_FPOINTER UWORD, 104
typeof.h, 359 WORD, 104
TYPEOF_FUNCTION Z88DK_CALLEE, 105
typeof.h, 359 Z88DK_FASTCALL, 105
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
INDEX 397
UBYTE UINT_MIN
types.h, 104 limits.h, 255
UCHAR_MAX UINTMAX_C
limits.h, 255 stdint.h, 349
UDWORD UINTMAX_MAX
types.h, 104 stdint.h, 348
UINT16 uintmax_t
types.h, 101, 102, 105 stdint.h, 350
UINT16_C UINTPTR_MAX
stdint.h, 349 stdint.h, 348
UINT16_MAX uintptr_t
stdint.h, 347 stdint.h, 350
uint16_t uitoa
stdint.h, 349 stdlib.h, 354
uint2bcd ULONG_MAX
bcd.h, 109 limits.h, 256
UINT32 ULONG_MIN
types.h, 101, 102, 105 limits.h, 256
UINT32_C ultoa
stdint.h, 349 stdlib.h, 355
UINT32_MAX ULWORD
stdint.h, 347 types.h, 104
uint32_t UNSIGNED
stdint.h, 350 drawing.h, 119
UINT8 USE_C_MEMCPY
types.h, 101, 102, 105 provides.h, 86, 87
UINT8_C USE_C_STRCMP
stdint.h, 349 provides.h, 86, 87
UINT8_MAX USE_C_STRCPY
stdint.h, 347 provides.h, 86, 87
uint8_t USHRT_MAX
stdint.h, 349 limits.h, 256
UINT_FAST16_MAX USHRT_MIN
stdint.h, 348 limits.h, 256
uint_fast16_t UWORD
stdint.h, 350 types.h, 104
UINT_FAST32_MAX
stdint.h, 348 va_arg
uint_fast32_t stdarg.h, 87, 88
stdint.h, 350 va_end
UINT_FAST8_MAX stdarg.h, 87–89
stdint.h, 348 va_list
uint_fast8_t stdarg.h, 87–89
stdint.h, 350 va_start
UINT_LEAST16_MAX stdarg.h, 87, 88
stdint.h, 347 VBK_ATTRIBUTES
uint_least16_t hardware.h, 189, 207, 220
stdint.h, 350 VBK_BANK_0
UINT_LEAST32_MAX hardware.h, 189
stdint.h, 347 VBK_BANK_1
uint_least32_t hardware.h, 189
stdint.h, 350 VBK_REG
UINT_LEAST8_MAX hardware.h, 198
stdint.h, 347 msx.h, 259
uint_least8_t sms.h, 322
stdint.h, 350 VBK_TILES
UINT_MAX hardware.h, 189, 207, 220
limits.h, 255 VBL_IFLAG
gb.h, 131
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen
398 INDEX
msx.h, 261 w
sms.h, 323 _fixed, 80
VDP_ATTR_SHIFT wait_int_handler
hardware.h, 208, 221 gb.h, 143
VDP_R0 wait_vbl_done
hardware.h, 203, 216 gb.h, 146
VDP_R1 msx.h, 269
hardware.h, 204, 217 nes.h, 295
VDP_R10 sms.h, 331
hardware.h, 206, 219 waitpad
VDP_R2 gb.h, 144
hardware.h, 204, 217 msx.h, 269
VDP_R3 nes.h, 293
hardware.h, 205, 218 sms.h, 331
VDP_R4 waitpadup
hardware.h, 205, 218 gb.h, 144
VDP_R5 msx.h, 269
hardware.h, 205, 218 nes.h, 293
VDP_R6 sms.h, 331
hardware.h, 205, 218 WCHAR_MAX
VDP_R7 stdint.h, 349
hardware.h, 205, 218 WCHAR_MIN
VDP_R8 stdint.h, 349
hardware.h, 205, 218 wchar_t
VDP_R9 stddef.h, 345
hardware.h, 206, 219 WHITE
VDP_RBORDER drawing.h, 118
hardware.h, 205, 218 WINT_MAX
VDP_REG_MASK stdint.h, 349
hardware.h, 203, 216 WINT_MIN
VDP_RSCX stdint.h, 349
hardware.h, 206, 218 WORD
VDP_RSCY types.h, 104
hardware.h, 206, 219 WRITE_VDP_CMD
VDP_SAT_TERM msx.h, 266
hardware.h, 207, 220 sms.h, 329
VECTOR_JOYPAD WRITE_VDP_DATA
isr.h, 222 msx.h, 267
VECTOR_SERIAL sms.h, 329
isr.h, 222 wrtchr
VECTOR_STAT drawing.h, 121
isr.h, 222 WX_REG
VECTOR_TIMER hardware.h, 198
isr.h, 222 WY_REG
version.h hardware.h, 198
__GBDK_VERSION, 254
vmemcpy x
gb.h, 167 OAM_item_t, 85
msx.h, 272 XOR
sms.h, 335 drawing.h, 118
vmemset
gb.h, 171 y
nes.h, 313 OAM_item_t, 85
vsync
Z88DK_CALLEE
gb.h, 146
types.h, 105
msx.h, 268
Z88DK_FASTCALL
nes.h, 295
types.h, 105
sms.h, 331
Generated on Wed Aug 9 2023 00:08:12 for GBDK 2020 Docs by Doxygen