GBDK Manual
GBDK Manual
4.1.1
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Getting Started 2
2.1 1. Download a Release and unzip it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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: . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 3. Use a Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 4. If you use GBTD / GBMB, get the fixed version . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.5 5. Review Coding Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.6 6. Hardware and Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.7 7. Set up C Source debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.8 8. Try a GBDK Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.9 9. Read up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.10 10. Need help? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.11 Migrating From Pre-GBDK-2020 Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.11.1 Also see: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.2 Use auto-banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.3 Non-standard types (UINT8, etc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.4 If using GBTD / GBMB, get the fixed version . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.5 LCC and SDCC flags that are not needed . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.6 ROM Header Settings (such as Color, SGB, etc) . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.7 GBDK Header include changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.8 Include .h headers, not .c source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.9 Use the Template Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.11.10 Use hUGEtracker instead of gbt_player . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
ii
4 Using GBDK 8
4.1 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.1 Available Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.2 Adding your own interrupt handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.3 Using your own Interrupt Dispatcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.4 Returning from Interrupts and STAT mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 What GBDK does automatically and behind the scenes . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.1 OAM (VRAM Sprite Attribute Table) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.2 Font tiles when using stdio.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.3 Default Interrupt Service Handlers (ISRs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.4 Ensuring Safe Access to Graphics Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 Copying Functions to RAM and HIRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.4 Mixing C and Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.4.1 Inline ASM within C source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.4.2 In Separate ASM files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.5 Including binary files in C source with incbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.6 Known Issues and Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.6.1 SDCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 Coding Guidelines 12
5.1 Learning C / C fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1.1 General C tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1.2 Embedded C introductions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1.3 Game Boy games in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 Understanding the hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.3 Writing optimal C code for the Game Boy and SDCC . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.3.1 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.3.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.3.3 Code structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.4 GBDK API/Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.5 Toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3.6 Constants, Signed-ness and Overflows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.3.7 Chars and vararg functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4 When C isn't fast enough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4.1 Calling convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4.2 Variables and registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4.3 Segments / Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
iii
7 GBDK Toolchain 23
7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.2 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.3 Changing Important Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.4 Compiling programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.4.1 Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.4.2 Using Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.4.3 Linker Files and ROM Auto Banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.5 Build Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.5.1 lcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.5.2 sdcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.5.3 sdasgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.5.4 bankpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.5.5 sdldgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.5.6 ihxcheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.5.7 makebin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.6 GBDK Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.6.1 GBCompress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.6.2 png2asset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.6.3 makecom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
iv
9 Example Programs 34
9.1 banks (various projects) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.2 comm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.3 crash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.4 colorbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.5 dscan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.6 filltest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.7 fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.8 galaxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.9 gb-dtmf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.10 gbdecompress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.11 irq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.12 large map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.13 metasprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.14 lcd isr wobble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.15 paint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.16 rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.17 ram_fn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.18 rpn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.19 samptest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.20 sgb (various) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
v
9.21 sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.22 space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.23 templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
vi
13 Toolchain settings 55
13.1 lcc settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
13.2 sdcc settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
13.3 sdasgb settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
13.4 sdasz80 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
13.5 bankpack settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
13.6 sdldgb settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
13.7 sdldz80 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
13.8 ihxcheck settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
13.9 makebin settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
13.10 makecom settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
13.11 gbcompress settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
13.12 png2asset settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
14 Todo List 61
15 Module Index 61
15.1 C modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
17 File Index 61
17.1 File List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
18 Module Documentation 64
18.1 List of gbdk fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
18.1.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
18.1.2 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
vii
20 File Documentation 72
20.1 docs/pages/01_getting_started.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.2 docs/pages/02_links_and_tools.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.3 docs/pages/03_using_gbdk.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.4 docs/pages/04_coding_guidelines.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.5 docs/pages/05_banking_mbcs.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.6 docs/pages/06_toolchain.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.7 docs/pages/06b_supported_consoles.md File Reference . . . . . . . . . . . . . . . . . . . . . . . 72
20.8 docs/pages/07_sample_programs.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.9 docs/pages/08_faq.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.10 docs/pages/09_migrating_new_versions.md File Reference . . . . . . . . . . . . . . . . . . . . . 72
20.11 docs/pages/10_release_notes.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.12 docs/pages/20_toolchain_settings.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . 72
20.13 docs/pages/docs_index.md File Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
20.14 gbdk-lib/include/asm/mos6502/provides.h File Reference . . . . . . . . . . . . . . . . . . . . . . 72
20.14.1 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
viii
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
ix
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
x
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
xi
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
xii
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
1 General Documentation 1
Index 327
1 General Documentation
• Getting Started
• Using GBDK
• Coding Guidelines
• GBDK Toolchain
• Example Programs
• Toolchain settings
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
2
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
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.
2 Getting Started
Follow the steps in this section to start using GBDK-2020.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
2.1 1. Download a Release and unzip it 3
compile
or
compile.bat
This should build the example project. You can also navigate into other example project folders and build in the
same way.
make
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. 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
4
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
2.11 Migrating From Pre-GBDK-2020 Tutorials 5
• 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.
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
6
hUGEtracker and its driver hUGEdriver are smaller, more efficient and more versatile than gbt_player.
• The SDCC assembler and linker (sdas / asxxxx and aslink) manual.
https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/sdas/doc/asmlnk.←-
txt
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/
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
3.6 Example code 7
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/
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
8
• romusage
Calculate used and free space in banks (ROM/RAM) and warn about errors such as bank overflows.
https://github.com/bbbbbr/romusage
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
4.1 Interrupts 9
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.
– The default SIO ISR gets installed automatically if any of the standard SIO calls are used. These calls
include add_SIO(), remove_SIO(), send_byte(), receive_byte().
– The default SIO ISR cannot be removed once installed. 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
10
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().
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
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
4.4 Mixing C and Assembly 11
__asm__("nop");
Another Example:
void some_c_function()
{
// Optionally do something
__asm
(ASM code goes here)
__endasm;
}
Todo This is from GBDK 2.x docs, verify it with GBDK-2020 and modern SDCC
It is possible to assemble and link files written in ASM alongside files written in C.
• Parameters are passed on the stack (starting at SP+2 because the return address is also saved on the stack).
• You can access GameBoy hardware registers using _reg_0xXX where XX is the register number (see
sound.c for an example).
• Registers must be preserved across function calls (you must store them at function begin, and restore them
at the end), except HL (and DE when the function returns a result).
i = add(1, 3);
}
add.s
.globl _add
_add: ; int16_t add(int16_t a, int16_t b)
; There is no register to save:
; BC is not used
; DE is the return register
; HL needs never to be saved
LDA HL,2(SP)
LD E,(HL) ; Get a in DE
INC HL
LD D,(HL)
INC HL
LD A,(HL) ; Get b in HL
INC HL
LD H,(HL)
LD L,A
ADD HL,DE ; Add DE to HL
LD D,H
LD E,L
; There is no register to restore
RET ; Return result in DE
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12
• 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.
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
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
5.3 Writing optimal C code for the Game Boy and SDCC 13
5.3.2 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.
• 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.
• For calculated values that don't change, pre-compute results once and store the result. Using lookup-tables
and the like can improve speed and reduce code size. Macros can sometimes help. It may be beneficial to
do the calculations with an outside tool and then include the result as C code in a const array.
• 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).
fixed player[2];
...
// Modify player position using its 16 bit representation
player[0].w += player_speed_x;
player[1].w += player_speed_y;
...
// Use only the upper 8 bits for setting the sprite position
move_sprite(0, player[0].h ,player[1].h);
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
14
• 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.
• When processing for a given frame is done and it is time to wait before starting the next frame, wait_vbl_done()
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 wait_vbl_done() (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.5 Toolchain
• 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).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
5.3 Writing optimal C code for the Game Boy and SDCC 15
• 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:
sprintf(str_temp, "%u, %d, %x\n", UINT16_MAX, INT16_MIN, UINT16_MAX);
printf("%s",str_temp);
// Will output: "65535, 0, 8000"
Instead this will give the intended output:
sprintf(str_temp, "%u, %d, %x\n", (uint16_t)UINT16_MAX, (int16_t)INT16_MIN, (uint16_t)UINT16_MAX);
printf("%s",str_temp);
// Will output: "65535, -32768, FFFF"
5.3.7.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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
16
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);
// 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:
For many applications C is fast enough but in intensive functions are sometimes better written in assembly. This
section deals with interfacing your core C program with fast assembly sub routines.
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 in 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 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
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
6 ROM/RAM Banking and MBCs 17
• Banked ROM
– _CODE_x Places code in ROM other than Bank 0, where x is the 16kB bank number.
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
6.1.3.1 Bank 0 Size Limit and Overlows 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
18
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.
The MBC settings below are available when using the makebin -Wl-yt<N> switch.
Source: Pandocs. Additional details available at Pandocs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
6.3 MBC Type Chart 19
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().
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20
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 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.
Non-banked functions (either in fixed Bank 0, or in an non-banked ROM with no MBC):
• May call functions in any bank: YES
– The compiler and library will manage the bank switching automatically using the bank switching tram-
poline.
– May only use data from Bank 0 and the currently active bank.
– A NONBANKED wrapper function may be used to access data in other banks.
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).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
6.3 MBC Type Chart 21
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 :
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);
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
22
6.4 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
6.6 Bank space usage 23
• 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.
• _shadow_OAM
• .STACK
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
24
• .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
• 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:
• To generate an assembler listing file.
-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.
lcc -Wa-l -Wl-m -Wl-g_snd_stat=0xff26 -o image.gb hardware.c
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
7.5 Build Tools 25
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:
• lkin=<filename> : Adds a input linkerfile (can specify multiple ones)
• -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 passes all input linkerfiles (from -Wl-f<name>) to bankpack (-lkin=)
• lcc clears out the linker object file and linkerfile lists, then uses the single linkerfile generated by bankpack
Also see the linkerfile example project.
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
7.5.2 sdcc
• Arguments can be passed to it through lcc using -Wf-<argument> and -Wp-<argument> (pre-
processor)
7.5.3 sdasgb
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
26
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.
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, see gb_decompress().
Can also compress (and decompress) using block style RLE encoding with the --alg=rle flag. Decompression
support is available in GBDK, see rle_decompress().
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
7.6 GBDK Utilities 27
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.
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
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
28
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:
– 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:
• 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.
7.6.3 makecom
Converts a binary .rom file to .msxdos com format, including splitting the banks up into separate files.
• Sega Consoles
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
8.2 Cross Compiling for Different Consoles 29
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.
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 assembling with sdasgb (for GB/AP) and sdasz80 (for SMS/GG):
When linking with sdldgb (for GB/AP) and sdldz80 (for SMS/GG or MSXDOS):
MSXDOS requires an additional build step with makecom after makebin to create the final binary:
The NES port has --no-peep specified (in lcc) due to a peephole related codegen bug in SDCC that has not yet
been merged.
• If you wish to build without that flag then SDCC can be called directly instead of through lcc.
• Alternately, custom peephole rules from a file can be passed in using -Wf--peep-file (lcc) or
--peep-file (sdcc).
Note: Starting with GBDK-2020 4.1.0 and SDCC 4.2, the Game Boy and related clones use sm83 for the port
instead of gbz80
– lcc : -msm83:gb
– port:sm83, plat:gb
• Analogue Pocket
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
30
– lcc : -msm83:ap
– port:sm83, plat:ap
– lcc : -msm83:duck
– port:sm83, plat:duck
– lcc : -mz80:sms
– port:z80, plat:sms
– lcc : -mz80:gg
– port:z80, plat:gg
• MSX DOS
– lcc : -mz80:msxdos
– port:z80, plat:msxdos
• NES
– lcc : -mmos6502:nes
– port:mos6502, plat:nes
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
8.4 Using <gbdk/...> headers 31
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
• DEVICE_SPRITE_PX_OFFSET_X, DEVICE_SPRITE_PX_OFFSET_Y
• DEVICE_SCREEN_PX_WIDTH, DEVICE_SCREEN_PX_HEIGHT
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_native_tile_data() to load the assets tiles in native format.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
32
– 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
Observed differences:
• MBC1 and MBC5 are supported, MBC3 won't save, the HuC3 isn't supported at all (via JoseJX)
• 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.
Use API defined registers and register flags instead of hardwired ones.
As long as the target console is set during build time then the correct boot logo will be automatically selected.
Use API defined registers and register flags instead of hardwired ones
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
8.9 Hardware Comparison 33
8.8.1.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.1.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.
• 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)
SMS/GG
• Sprites:
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
34
• SMS
• GG
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.
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
9.5 dscan 35
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:
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
36
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.
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:
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:
9.23 templates
Two basic template examples are provided as a starting place for writing your GBDK programs.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
10 Frequently Asked Questions (FAQ) 37
– 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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
38
– 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.
– One object file was compiled with the PORT setting as gbz80 (meaning a version of SDCC / GBDK-
2020 OLDER than GBDK-2020 4.1.0).
– The other had the PORT setting as sm83 (meaning GBDK-2020 4.1.0 or LATER).
– 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.
– This is a known issue with SDCC Peephole Optimizer parsing and can be ignored. A bug report has
been filed for it.
• 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. 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.
– Your program is using more banks than you have configured in the toolchain. Either the MBC type was
not set, or the number of banks or MBC type should be changed to provide more banks.
See the section setting_mbc_and_rom_ram_banks for more details.
• 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
10.6 API / Utilities 39
– 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
– 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.
• 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).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
40
• 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.2 or higher with GBDK-2020 patches for the 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.
– If there are existing functions written in ASM which call other functions written in C the callee C
function should be declared OLDCALL.
– If you are using tools such as rgb2sdas (from hUGETracker/Driver) you may need to edit the resulting
.o file and replace -mgbz80 with -msm83 in addition to using OLDCALL
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
11.1 GBDK-2020 versions 41
• 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
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
42
• 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.
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 43
2022/11
• Library
2022/10
• 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
• Toolchain / Utilities
– lcc
* Changed to Error out and warn when gbz80 port is used instead of sm83
– png2asset
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
44
* 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
• Docs
2022/02
• Building GBDK
– Changed to target older version of macOS (10.10) when building for better compatibility
• Platforms
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 45
– 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:
* #define SFR __sfr
* #define AT(A) __at(A)
– Added check for OAM overflow to metasprite calls for GB/CGB
– Added constant definitions PSG_LATCH, PSG_CH0, PSG_CH1, PSG_CH2, PSG_CH3, PSG_VOLUME
for SMS/GG
– Renamed bgb_emu.h to emu_debug.h and BGB_∗ functions to EMU_∗.
* 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
* Added SMS/GG graphics format support
* Added 4bpp and SGB borders
* Added warning when image size is not an even multiple of tile size
* Added -tile_origin offset option for when map tiles do not start at tile 0 in VRAM
* Added ∗_TILE_COUNT definition to output
* Fixed CGB ...s_map_attributes type definition in output
* Fixed values for num_palettes in output
* Fixed incorrect TILE_COUNT value when not -using_structs
– lcc
* 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
46
2021/09
• Known Issues
• Added support for new consoles. See Supported Consoles & Cross Compiling
• Library
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 47
* 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
• Examples
• Toolchain / Utilities
– png2mtspr
* Added option to change default value for sprite property/attributes in (allows CGB palette, BG/WIN
priority, etc).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
48
* Improved: Turn off suppression of "blank" metasprite frames (composed of entirely transparent
sprites)
* Fixed endless loop for png files taller than 255 pixels
– bankpack
* Fixed -yt mbc specifier to also accept Decimal
* Improved: bank ID can be used in same file it is declared. Requires SDCC 12238+ with -n option
to defer symbol resolution to link time.
– gbcompress
* Added C source input (expirimental) and output
* Added size #defines
– lcc
* Added -no-libs and -no-crt options
* Added support for .lk linker files (useful when number of files on lcc command line exceeds max
size on windows)
* Added support for converting .ihx to .gb
* Added rewrite .o files -> .rel for linking when called with -autobank and -Wb-ext=.rel
* Workaround makebin -Wl-yp formatting segfault
• Docs
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
– Added calloc / malloc / realloc / free and generic memmove
– Improved printf(): ignore %0 padding and %1-9 width specifier instead of not printing, support upper
case X
– Fixed line(): handle drawing when x1 is less than x2
• Examples
• Toolchain / Utilities
• Docs
– Added extensive documentation (some of which is imported and updated from the old gbdk docs)
– Added PDF version of docs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.1 GBDK-2020 Release Notes 49
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
50
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)
– improved and fixed string.h
– many other improvements and fixes - thanks to all contributors!
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.2 Historical GBDK Release Notes 51
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 BG←-
B_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
2020/04/12
2020/04/12
17 April, 2000
Many changes.
• Code generated is now much more reliable and passes all of sdcc's regression suite.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
52
• 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.
• Added model switching support –model-medium uses near (16 bit) pointers for data, and banked calls for any-
thing not declared as 'nonbanked' –model-small uses near (16 bit) pointers for data and calls. Nothing uses
banked calls. 'nonbanked' functions are still placed in HOME. Libraries are under lib/medium and lib/small.
• 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.
• 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 :)
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
12.2 Historical GBDK Release Notes 53
– 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
– 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_R←-
EG=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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
54
– 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 T←-
MP, 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.
– 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...
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
13 Toolchain settings 55
cvs.sdcc.sourceforge.net. I will be working on binaries for Win32 and a source tar ball soon. Please report any bugs
through the bugs link above.
31st Jan, 2000
Added Dermot's far pointer spec. It's mainly here for comment. If sdcc is ported to the Gameboy then I will be
looking for some way to do far calls.
8th Jan, 2000
Moved over to sourceforge.net. Thanks must go to David Pfeffer for gbdk's previous resting place, www.gbdev.org.
The transition is not complete, but cvs and web have been shifted. Note that the cvs download instructions are stale
- you should now look to cvs.gbdk.sourceforge.net. I am currently working on porting sdcc over to the Z80. David
Nathan is looking at porting it to the GB.
6th Jan, 2000
Icehawk wrote "I did write some rumble pack routines. Just make sure to remind people to add -Wl-yt0x1C or
-Wl-yt0x1D or -Wl-yt0x1E depending on sram and battery usage. Find the routines on my site (as usual). =)"
18th Oct, 1999
Bug tracking / FAQ up. Try the link on the left to report any bugs with GBDK. It's also the first place to look if your
having problems.
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
-A warn about nonANSI usage; 2nd -A warns more
-b emit expression-level profiling code; see bprint(1)
-Bdir/ use the compiler named ‘dir/rcc’
-c compile only
-dn set switch statement density to ‘n’
-debug Turns on --debug for compiler, -y (.cdb) and -j (.noi) for linker
-Dname -Dname=def define the preprocessor symbol ‘name’
-E only run preprocessor on named .c and .h files files -> stdout
--save-preproc Use with -E for output to *.i files instead of stdout
-g produce symbol table information for debuggers
-help or -? print this message
-Idir add ‘dir’ to the beginning of the list of #include directories
-K don’t run ihxcheck test on linker ihx output
-lx search library ‘x’
-m select port and platform: "-m[port]:[plat]" ports:sm83,z80,mos6502 plats:ap,duck,gb,sms,gg,nes
-N do not search the standard directories for #include files
-n emit code to check for dereferencing zero pointers
-no-crt do not auto-include the gbdk crt0.o runtime in linker list
-no-libs do not auto-include the gbdk libs in linker list
-O is ignored
-o file leave the output in ‘file’
-P print ANSI-style declarations for globals
-p -pg emit profiling code; see prof(1) and gprof(1)
-S compile to assembly language
-autobank auto-assign banks set to 255 (bankpack)
-static specify static libraries (default is dynamic)
-t -tname emit function tracing calls to printf or to ‘name’
-target name is ignored
-tempdir=dir place temporary files in ‘dir/’; default=/tmp
-Uname undefine the preprocessor symbol ‘name’
-v show commands as they are executed; 2nd -v suppresses execution
-w suppress warnings
-Woarg specify system-specific ‘arg’
-W[pfablim]arg pass ‘arg’ to the preprocessor, compiler, assembler, bankpack, linker, ihxcheck, or makebin
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
56
General options:
--help Display this help
-v --version Display sdcc’s version
--verbose Trace calls to the preprocessor, assembler, and linker
-V Execute verbosely. Show sub commands as they are run
-d Output list of macro definitions in effect. Use with -E
-D Define macro as in -Dmacro
-I Add to the include (*.h) path, as in -Ipath
-A
-U Undefine macro as in -Umacro
-M Preprocessor option
-W Pass through options to the pre-processor (p), assembler (a) or linker (l)
--include Pre-include a file during pre-processing
-S Compile only; do not assemble or link
-c --compile-only Compile and assemble, but do not link
-E --preprocessonly Preprocess only, do not compile
--c1mode Act in c1 mode. The standard input is preprocessed code, the output is assembly
code.
-o Place the output into the given path resp. file
-x Optional file type override (c, c-header or none), valid until the next -x
--print-search-dirs display the directories in the compiler’s search path
--vc messages are compatible with Micro$oft visual studio
--use-stdout send errors to stdout instead of stderr
--nostdlib Do not include the standard library directory in the search path
--nostdinc Do not include the standard include directory in the search path
--less-pedantic Disable some of the more pedantic warnings
--disable-warning <nnnn> Disable specific warning
--Werror Treat the warnings as errors
--debug Enable debugging symbol output
--cyclomatic Display complexity of compiled functions
--std-c89 Use ISO C90 (aka ANSI C89) standard (slightly incomplete)
--std-sdcc89 Use ISO C90 (aka ANSI C89) standard with SDCC extensions
--std-c95 Use ISO C95 (aka ISO C94) standard (slightly incomplete)
--std-c99 Use ISO C99 standard (incomplete)
--std-sdcc99 Use ISO C99 standard with SDCC extensions
--std-c11 Use ISO C11 standard (incomplete)
--std-sdcc11 Use ISO C11 standard with SDCC extensions (default)
--std-c2x Use ISO C2X standard (incomplete)
--std-sdcc2x Use ISO C2X standard with SDCC extensions
--fdollars-in-identifiers Permit ’$’ as an identifier character
--fsigned-char Make "char" signed by default
--use-non-free Search / include non-free licensed libraries and header files
Code generation options:
-m Set the port to use e.g. -mz80.
-p Select port specific processor e.g. -mpic14 -p16f84
--stack-auto Stack automatic variables
--xstack Use external stack
--int-long-reent Use reentrant calls on the int and long support functions
--float-reent Use reentrant calls on the float support functions
--xram-movc Use movc instead of movx to read xram (xdata)
--callee-saves <func[,func,...]> Cause the called function to save registers instead of the
caller
--fomit-frame-pointer Leave out the frame pointer.
--all-callee-saves callee will always save registers used
--stack-probe insert call to function __stack_probe at each function prologue
--no-xinit-opt don’t memcpy initialized xram from code
--no-c-code-in-asm don’t include c-code as comments in the asm file
--no-peep-comments don’t include peephole optimizer comments
--codeseg <name> use this name for the code segment
--constseg <name> use this name for the const segment
--dataseg <name> use this name for the data segment
Optimization options:
--nooverlay Disable overlaying leaf function auto variables
--nogcse Disable the GCSE optimisation
--nolabelopt Disable label optimisation
--noinvariant Disable optimisation of invariants
--noinduction Disable loop variable induction
--noloopreverse Disable the loop reverse optimisation
--no-peep Disable the peephole assembly file optimisation
--no-reg-params On some ports, disable passing some parameters in registers
--peep-asm Enable peephole optimization on inline assembly
--peep-return Enable peephole optimization for return instructions
--no-peep-return Disable peephole optimization for return instructions
--peep-file <file> use this extra peephole file
--opt-code-speed Optimize for code speed rather than size
--opt-code-size Optimize for code size rather than speed
--max-allocs-per-node Maximum number of register assignments considered at each node of the tree
decomposition
--nolospre Disable lospre
--allow-unsafe-read Allow optimizations to read any memory location anytime
--nostdlibcall Disable optimization of calls to standard library
Internal debugging options:
--dump-ast Dump front-end AST before generating i-code
--dump-i-code Dump the i-code structure at all stages
--dump-graphs Dump graphs (control-flow, conflict, etc)
--i-code-in-asm Include i-code as comments in the asm file
--fverbose-asm Include code generator comments in the asm output
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
13.3 sdasgb settings 57
Linker options:
-l Include the given library in the link
-L Add the next field to the library search path
--lib-path <path> use this path to search for libraries
--out-fmt-ihx Output in Intel hex format
--out-fmt-s19 Output in S19 hex format
--xram-loc <nnnn> External Ram start location
--xram-size <nnnn> External Ram size
--iram-size <nnnn> Internal Ram size
--xstack-loc <nnnn> External Stack start location
--code-loc <nnnn> Code Segment Location
--code-size <nnnn> Code Segment size
--stack-loc <nnnn> Stack pointer initial value
--data-loc <nnnn> Direct data start location
--idata-loc
--no-optsdcc-in-asm Do not emit .optsdcc in asm
Special options for the z80 port:
--callee-saves-bc Force a called function to always save BC
--portmode= Determine PORT I/O mode (z80/z180)
-bo <num> use code bank <num>
-ba <num> use data bank <num>
--asm= Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
--codeseg <name> use this name for the code segment
--constseg <name> use this name for the const segment
--dataseg <name> use this name for the data segment
--no-std-crt0 Do not link default crt0.rel
--reserve-regs-iy Do not use IY (incompatible with --fomit-frame-pointer)
--fno-omit-frame-pointer Do not omit frame pointer
--emit-externs Emit externs list in generated asm
--legacy-banking Use legacy method to call banked functions
--nmos-z80 Generate workaround for NMOS Z80 when saving IFF2
--sdcccall Set ABI version for default calling convention
--allow-undocumented-instructions Allow use of undocumented instructions
Special options for the sm83 port:
-bo <num> use code bank <num>
-ba <num> use data bank <num>
--asm= Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
--callee-saves-bc Force a called function to always save BC
--codeseg <name> use this name for the code segment
--constseg <name> use this name for the const segment
--dataseg <name> use this name for the data segment
--no-std-crt0 Do not link default crt0.rel
--legacy-banking Use legacy method to call banked functions
--sdcccall Set ABI version for default calling convention
Special options for the mos6502 port:
--model-small 8-bit address space for data
--model-large 16-bit address space for data (default)
--no-std-crt0 Do not link default crt0.rel
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
58
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
13.7 sdldz80 settings 59
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
60
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
14 Todo List 61
14 Todo List
Page Coding Guidelines
Update and verify this section for the modernized SDCC and toolchain
File far_ptr.h
Add link to a discussion about banking (such as, how to assign code and variables to banks)
15 Module Index
15.1 C modules
Here is a list of all modules:
__far_ptr 64
_fixed 65
atomic_flag 66
isr_nested_vector_t 66
isr_vector_t 66
joypads_t 67
metasprite_t 68
OAM_item_t 70
sfont_handle 71
17 File Index
17.1 File List
Here is a list of all files with brief descriptions:
gbdk-lib/include/assert.h 92
gbdk-lib/include/ctype.h 92
gbdk-lib/include/limits.h 232
gbdk-lib/include/rand.h 284
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
62
gbdk-lib/include/setjmp.h 286
gbdk-lib/include/stdarg.h 75
gbdk-lib/include/stdatomic.h 310
gbdk-lib/include/stdbool.h 311
gbdk-lib/include/stddef.h 311
gbdk-lib/include/stdint.h 312
gbdk-lib/include/stdio.h 318
gbdk-lib/include/stdlib.h 319
gbdk-lib/include/stdnoreturn.h 323
gbdk-lib/include/string.h 86
gbdk-lib/include/time.h 323
gbdk-lib/include/typeof.h 324
gbdk-lib/include/types.h 91
gbdk-lib/include/asm/types.h 88
gbdk-lib/include/asm/mos6502/provides.h 72
gbdk-lib/include/asm/mos6502/stdarg.h 73
gbdk-lib/include/asm/mos6502/string.h 75
gbdk-lib/include/asm/mos6502/types.h 86
gbdk-lib/include/asm/sm83/provides.h 72
gbdk-lib/include/asm/sm83/stdarg.h 74
gbdk-lib/include/asm/sm83/string.h 79
gbdk-lib/include/asm/sm83/types.h 87
gbdk-lib/include/asm/z80/provides.h 73
gbdk-lib/include/asm/z80/stdarg.h 74
gbdk-lib/include/asm/z80/string.h 82
gbdk-lib/include/asm/z80/types.h 90
gbdk-lib/include/gb/bcd.h 94
gbdk-lib/include/gb/bgb_emu.h 96
gbdk-lib/include/gb/cgb.h 96
gbdk-lib/include/gb/crash_handler.h 102
gbdk-lib/include/gb/drawing.h 102
gbdk-lib/include/gb/emu_debug.h 107
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
17.1 File List 63
gbdk-lib/include/gb/gb.h 110
gbdk-lib/include/gb/gbdecompress.h 153
gbdk-lib/include/gb/hardware.h 157
gbdk-lib/include/gb/isr.h 202
gbdk-lib/include/gb/metasprites.h 203
gbdk-lib/include/gb/sgb.h 220
gbdk-lib/include/gbdk/bcd.h 96
gbdk-lib/include/gbdk/console.h 223
gbdk-lib/include/gbdk/emu_debug.h 107
gbdk-lib/include/gbdk/far_ptr.h 224
gbdk-lib/include/gbdk/font.h 227
gbdk-lib/include/gbdk/gbdecompress.h 156
gbdk-lib/include/gbdk/gbdk-lib.h 229
gbdk-lib/include/gbdk/incbin.h 229
gbdk-lib/include/gbdk/metasprites.h 209
gbdk-lib/include/gbdk/platform.h 230
gbdk-lib/include/gbdk/rledecompress.h 230
gbdk-lib/include/gbdk/version.h 231
gbdk-lib/include/msx/hardware.h 179
gbdk-lib/include/msx/metasprites.h 209
gbdk-lib/include/msx/msx.h 233
gbdk-lib/include/nes/hardware.h 189
gbdk-lib/include/nes/metasprites.h 211
gbdk-lib/include/nes/nes.h 256
gbdk-lib/include/nes/rgb_to_nes_macro.h 284
gbdk-lib/include/sms/gbdecompress.h 156
gbdk-lib/include/sms/hardware.h 192
gbdk-lib/include/sms/metasprites.h 217
gbdk-lib/include/sms/sms.h 287
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
64
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 [ ]
Data Fields
• FAR_PTR ptr
• struct {
void ∗ ofs
uint16_t seg
} segofs
• struct {
void(∗ fn )()
uint16_t seg
} segfn
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
19.2 _fixed Union Reference 65
• 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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
66
• gbdk-lib/include/asm/types.h
Data Fields
• gbdk-lib/include/stdatomic.h
Data Fields
• gbdk-lib/include/gb/isr.h
Data Fields
• uint8_t opcode
• void ∗ func
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
19.6 joypads_t Struct Reference 67
• gbdk-lib/include/gb/isr.h
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
68
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
19.7 metasprite_t Struct Reference 69
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
70
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
19.9 sfont_handle Struct Reference 71
Parameters
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
72
• gbdk-lib/include/gbdk/font.h
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 1
• #define USE_C_MEMCPY 0
• #define USE_C_STRCPY 0
• #define USE_C_STRCMP 0
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.16 gbdk-lib/include/asm/z80/provides.h File Reference 73
• #define USE_C_MEMCPY 0
• #define USE_C_STRCPY 0
• #define USE_C_STRCMP 1
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
74
Typedefs
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.20 gbdk-lib/include/stdarg.h File Reference 75
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
76
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.21 gbdk-lib/include/asm/mos6502/string.h File Reference 77
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
78
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
Parameters
Returns:
• > 0 if buf1 > buf2
• 0 if buf1 == buf2
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.22 gbdk-lib/include/asm/sm83/string.h File Reference 79
Functions
Variables
• char c
Parameters
dest Array to copy into
src Array to copy from
Returns
A pointer to dest
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
80
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.22 gbdk-lib/include/asm/sm83/string.h File Reference 81
Parameters
Parameters
Parameters
Parameters
s1 First string to compare
s2 Second string to compare
n Max number of characters to compare
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
82
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
20.22.3.1 c void c
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.23 gbdk-lib/include/asm/z80/string.h File Reference 83
Functions
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
84
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.
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.23 gbdk-lib/include/asm/z80/string.h File Reference 85
Parameters
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
86
Parameters
Parameters
Returns:
• > 0 if buf1 > buf2
• 0 if buf1 == buf2
• #define __SIZE_T_DEFINED
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.26 gbdk-lib/include/asm/sm83/types.h File Reference 87
clock
• #define __SIZE_T_DEFINED
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
88
clock
Data Structures
• union _fixed
Macros
• #define OLDCALL
• #define PRESERVES_REGS(...)
• #define NAKED
• #define SFR
• #define AT(A)
• #define NONBANKED
• #define BANKED
• #define CRITICAL
• #define INTERRUPT
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.27 gbdk-lib/include/asm/types.h File Reference 89
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
90
• #define Z88DK_CALLEE
• #define Z88DK_FASTCALL
• #define __SIZE_T_DEFINED
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.29 gbdk-lib/include/types.h File Reference 91
See also
clock
Macros
• #define NULL 0
• #define FALSE 0
• #define TRUE 1
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
92
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.31 gbdk-lib/include/ctype.h File Reference 93
Functions
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
94
Parameters
c Character to test
Parameters
c Character to test
Parameters
c Character to test
Macros
Typedefs
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.32 gbdk-lib/include/gb/bcd.h File Reference 95
Parameters
i Numeric value to convert
value Pointer to a BCD variable to store the converted result
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
96
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.
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)
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 97
Typedefs
Functions
• Use a value of 80h for games that support CGB and monochrome gameboys
(with Lcc: -Wm-yc, or makebin directly: -yc)
Parameters
See also
Parameters
See also
Parameters
RGB24bit Bit packed RGB-888 color (0-255 for each color component).
See also
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 99
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
100
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.35 gbdk-lib/include/gb/cgb.h File Reference 101
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
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()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
102
• 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.
• void __HandleCrash ()
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.37 gbdk-lib/include/gb/drawing.h File Reference 103
• #define DKGREY 2
• #define BLACK 3
• #define M_NOFILL 0
• #define M_FILL 1
• #define SIGNED 1
• #define UNSIGNED 0
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
104
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.37 gbdk-lib/include/gb/drawing.h File Reference 105
See also
gotogxy()
See also
gprintln(), gotogxy()
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
106
gotogxy()
wrtchr()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.38 gbdk-lib/include/gb/emu_debug.h File Reference 107
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.
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
108
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, LA←-
STCLKS, CLKS2VBLANK
Example: print a message along with the currently active ROM bank.
EMU_MESSAGE("Current ROM Bank is: %ROMBANK%");
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.39 gbdk-lib/include/gbdk/emu_debug.h File Reference 109
So when running in Normal Speed mode (i.e. non-CGB doublespeed) the printed result should be divided by 2 to
get the actual ellapsed cycle count.
If running in CB Double Speed mode use the below call instead, it correctly compensates for the speed difference.
In this scenario, the result does not need to be divided by 2 to get the ellapsed cycle count.
EMU_MESSAGE("NOP TIME: %-4+LASTCLKS%");
See also
EMU_PROFILE_BEGIN(), EMU_MESSAGE()
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:
• %hx (char as hex)
• %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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
110
Data Structures
• struct joypads_t
• struct OAM_item_t
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 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 0x07U
• #define MINWNDPOSY 0x00U
• #define MAXWNDPOSX 0xA6U
• #define MAXWNDPOSY 0x8FU
• #define DMG_TYPE 0x01
• #define MGB_TYPE 0xFF
• #define CGB_TYPE 0x11
• #define GBA_NOT_DETECTED 0x00
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 111
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
112
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 113
• void set_win_1bpp_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL PRESERVES_REGS(b
• void get_win_data (uint8_t first_tile, uint8_t nb_tiles, uint8_t ∗data) OLDCALL PRESERVES_REGS(b
• void set_win_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗tiles) OLDCALL PRESERVES_REGS(b
• 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_win_submap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗map, uint8_t map_w) OLDCALL
• 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 get_win_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t ∗tiles) OLDCALL PRESERVES_REGS(b
• uint8_t ∗ set_win_tile_xy (uint8_t x, uint8_t y, uint8_t t) OLDCALL PRESERVES_REGS(b
• uint8_t get_win_tile_xy (uint8_t x, uint8_t y) OLDCALL PRESERVES_REGS(b
• void move_win (uint8_t x, uint8_t y)
• void scroll_win (int8_t x, int8_t y)
• void set_sprite_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL PRESERVES_REGS(b
• void set_sprite_1bpp_data (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data) OLDCALL PRESERVES_REGS(b
• void get_sprite_data (uint8_t first_tile, uint8_t nb_tiles, uint8_t ∗data) OLDCALL PRESERVES_REGS(b
• 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 PRESERVES_REGS(b
• void get_data (uint8_t ∗data, uint8_t ∗vram_addr, uint16_t len) OLDCALL PRESERVES_REGS(b
• void vmemcpy (uint8_t ∗dest, uint8_t ∗sour, uint16_t len) OLDCALL PRESERVES_REGS(b
• 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 (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data, uint8_t base) OLDCALL
PRESERVES_REGS(b
• void get_tiles (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t ∗vram_addr, uint8_t ∗tiles) OLDCALL
• void set_native_tile_data (uint16_t first_tile, uint8_t nb_tiles, const uint8_t ∗data)
• void init_win (uint8_t c) OLDCALL PRESERVES_REGS(b
• void init_bkg (uint8_t c) OLDCALL PRESERVES_REGS(b
• void vmemset (void ∗s, uint8_t c, size_t n) OLDCALL PRESERVES_REGS(b
• void fill_bkg_rect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile) OLDCALL PRESERVES_REGS(b
• void fill_win_rect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile) OLDCALL PRESERVES_REGS(b
Variables
• uint8_t c
• uint8_t _cpu
• uint8_t _is_GBA
• volatile uint16_t sys_time
• volatile uint8_t _io_status
• volatile uint8_t _io_in
• volatile uint8_t _io_out
• __REG _current_bank
• void l
• uint8_t h
• void b
• void d
• void e
• uint16_t _current_1bpp_colors
• uint8_t _map_tile_offset
• uint8_t _submap_tile_offset
• volatile struct OAM_item_t shadow_OAM [ ]
• __REG _shadow_OAM_base
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
114
See also
joypad
See also
mode()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 115
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
116
See also
set_interrupts(),
add_VBL
See also
set_interrupts(),
add_LCD
See also
set_interrupts(),
add_TIM
See also
set_interrupts(),
add_SIO
See also
set_interrupts(),
add_JOY
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 117
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
See also
move_win()
See also
move_win()
See also
move_win()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
118
See also
move_win()
See also
_cpu
See also
_cpu
See also
_cpu
See also
_cpu, _is_GBA
See also
_cpu, _is_GBA
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 119
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().
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
120
See also
BANKREF(), BANK()
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
• 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: Using SWITCH_ROM_MBC5_8M() should not be mixed with using SWITCH_ROM_MBC5() and
SWITCH_ROM().
See also
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 121
Parameters
See also
SWITCH_RAM_MBC1, SWITCH_RAM_MBC5
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
122
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
See also
display_off, DISPLAY_OFF
See also
display_off, DISPLAY_ON
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 123
See also
hide_sprite, hide_sprites_range
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
124
Parameters
See also
add_VBL()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 125
See also
add_VBL()
See also
add_LCD(), remove_VBL()
See also
add_TIM(), remove_VBL()
See also
add_SIO(),
remove_VBL()
The default SIO ISR gets installed automatically if any of the standard SIO calls are used. These calls include
add_SIO(), remove_SIO(), send_byte(), receive_byte().
The default SIO ISR cannot be removed once installed. 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()).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
126
ISR handlers added using add_VBL()/etc are instead called via the GBDK ISR dispatcher which makes the extra
function attributes unecessary.
Note: The default GBDK VBL is installed automatically.
See also
ISR_VECTOR()
See also
See also
add_VBL
set_interrupts() with TIM_IFLAG, ISR_VECTOR()
See also
add_VBL
set_interrupts() with TIM_IFLAG, ISR_VECTOR()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 127
See also
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()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
128
See also
See also
add_SIO(), remove_SIO()
set_interrupts() with SIO_IFLAG
See also
add_SIO(), remove_SIO()
set_interrupts() with SIO_IFLAG
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 129
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
130
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
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 131
See also
DISPLAY_ON
Parameters
Parameters
addr address to write to
v value
Parameters
Returns
read value
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
132
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).
Note: Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255.
GBC only: VBK_REG determines which bank of Background tile patterns are written to.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 133
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
134
uint8_t y,
uint8_t w,
uint8_t h,
const uint8_t ∗ tiles )
Sets a rectangular region of Background Tile Map.
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.
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 135
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
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)).
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
136
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 137
Parameters
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
Returns
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
138
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 139
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:
See set_1bpp_colors for details about setting the Foreground and Background colors.
See also
Parameters
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
140
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.
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 141
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
142
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
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 143
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
Returns
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
144
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 Background 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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 145
Parameters
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
146
• 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
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 147
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
See also
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
148
Parameters
vram_addr Pointer to source VRAM Address
data Pointer to destination buffer
len Number of bytes to copy
Copies len bytes from VRAM starting at vram_addr into a buffer at data.
GBC only: VBK_REG determines which bank of Background 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 Background tile patterns are written to.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 149
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
150
Parameters
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:
Parameters
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.40 gbdk-lib/include/gb/gb.h File Reference 151
Parameters
Parameters
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
152
20.40.5.1 c void c
See also
See also
See also
20.40.5.9 l uint8_t l
Initial value:
{
__asm__("ei")
20.40.5.10 h uint8_t h
20.40.5.11 b void b
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.41 gbdk-lib/include/gb/gbdecompress.h File Reference 153
20.40.5.12 d void d
20.40.5.13 e void e
Functions
Variables
• uint16_t c
See also
utility_gbcompress "gbcompress"
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
154
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
See also
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.41 gbdk-lib/include/gb/gbdecompress.h File Reference 155
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
156
Parameters
See also
20.41.3.1 c void c
Functions
Variables
• uint16_t c
Parameters
sour Pointer to source gb-compressed data
dest Pointer to destination buffer/address
Returns
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 157
See also
20.43.2.1 c uint16_t c
Macros
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
158
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 159
• #define LCDCF_B_WINON 5
• #define LCDCF_B_BG8000 4
• #define LCDCF_B_BG9C00 3
• #define LCDCF_B_OBJ16 2
• #define LCDCF_B_OBJON 1
• #define LCDCF_B_BGON 0
• #define rSTAT STAT_REG
• #define STATF_LYC 0b01000000
• #define STATF_MODE10 0b00100000
• #define STATF_MODE01 0b00010000
• #define STATF_MODE00 0b00001000
• #define STATF_LYCF 0b00000100
• #define STATF_HBL 0b00000000
• #define STATF_VBL 0b00000001
• #define STATF_OAM 0b00000010
• #define STATF_LCD 0b00000011
• #define STATF_BUSY 0b00000010
• #define STATF_B_LYC 6
• #define STATF_B_MODE10 5
• #define STATF_B_MODE01 4
• #define STATF_B_MODE00 3
• #define STATF_B_LYCF 2
• #define STATF_B_VBL 0
• #define STATF_B_OAM 1
• #define STATF_B_BUSY 1
• #define rSCY
• #define rSCX SCX_REG
• #define rLY LY_REG
• #define rLYC LYC_REG
• #define rDMA DMA_REG
• #define rBGP BGP_REG
• #define rOBP0 OBP0_REG
• #define rOBP1 OBP1_REG
• #define rWY WY_REG
• #define rWX WX_REG
• #define rKEY1 KEY1_REG
• #define rSPD KEY1_REG
• #define KEY1F_DBLSPEED 0b10000000
• #define KEY1F_PREPARE 0b00000001
• #define rVBK VBK_REG
• #define VBK_BANK_0 0
• #define VBK_TILES 0
• #define VBK_BANK_1 1
• #define VBK_ATTRIBUTES 1
• #define BKGF_PRI 0b10000000
• #define BKGF_YFLIP 0b01000000
• #define BKGF_XFLIP 0b00100000
• #define BKGF_BANK0 0b00000000
• #define BKGF_BANK1 0b00001000
• #define BKGF_CGB_PAL0 0b00000000
• #define BKGF_CGB_PAL1 0b00000001
• #define BKGF_CGB_PAL2 0b00000010
• #define BKGF_CGB_PAL3 0b00000011
• #define BKGF_CGB_PAL4 0b00000100
• #define BKGF_CGB_PAL5 0b00000101
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
160
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 161
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
• __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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
162
• __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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 163
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
164
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 165
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
166
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 167
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
168
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 169
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
170
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 171
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
172
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 173
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
174
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 175
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
176
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.44 gbdk-lib/include/gb/hardware.h File Reference 177
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
178
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 179
Macros
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
180
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 181
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
182
• 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 183
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
184
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 185
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
186
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.45 gbdk-lib/include/msx/hardware.h File Reference 187
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
188
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.46 gbdk-lib/include/nes/hardware.h File Reference 189
Macros
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
190
Variables
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.46 gbdk-lib/include/nes/hardware.h File Reference 191
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
192
Macros
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 193
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
194
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 195
• UBYTE shadow_VDP_RSCY
• UBYTE shadow_VDP_R10
• const UBYTE _BIOS
• const UBYTE _SYSTEM
• volatile UBYTE VDP_ATTR_SHIFT
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
196
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 197
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
198
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 199
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
200
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.47 gbdk-lib/include/sms/hardware.h File Reference 201
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
202
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 203
Parameters
ADDR Address of the interrupt vector, any of: VECTOR_STAT, VECTOR_TIMER, VECTOR_SERIAL,
VECTOR_JOYPAD
FUNC ISR function supplied by the user
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
204
#include <types.h>
#include <stdint.h>
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.
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)
for (uint8_t i = hiwater; i < 40; i++) shadow_OAM[i].y = 0;
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 205
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:
• Metsaprite structures can be copied into RAM so their property flags can be modified at runtime.
• The metasprite structures can have the property flags modified before compilation (such as with -sp
<props> in the png2asset tool).
• Update properties for the affected sprites after calling a move_metasprite_∗() function.
The following functions are only available for Game Boy and related clone consoles due to lack of hardware support
for sprite flipping in other consoles. See docs_consoles_supported_list
• move_metasprite_vflip()
• move_metasprite_hflip()
• move_metasprite_hvflip()
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
206
Parameters
See also
hide_sprite
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_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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.49 gbdk-lib/include/gb/metasprites.h File Reference 207
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_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 on the Y axis only.
Sets:
• __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_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 on the X axis only.
Sets:
• __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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
208
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_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 on both the X and Y axis.
Sets:
• __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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.50 gbdk-lib/include/gbdk/metasprites.h File Reference 209
20.49.8.4 c void c
Data Structures
• struct metasprite_t
Macros
Typedefs
Functions
Variables
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
210
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 211
Parameters
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
Sets:
• __current_metasprite = metasprite;
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
212
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.
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)
for (uint8_t i = hiwater; i < 64; i++) shadow_OAM[i].y = 0;
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 213
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 will get overwritten.
How to use sprite property flags with metasprites:
• Metsaprite structures can be copied into RAM so their property flags can be modified at runtime.
• The metasprite structures can have the property flags modified before compilation (such as with -sp
<props> in the png2asset tool).
• Update properties for the affected sprites after calling a move_metasprite_∗() function.
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
214
Parameters
Parameters
See also
hide_sprite
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_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 palette), see Metasprites and sprite properties.
Returns
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.52 gbdk-lib/include/nes/metasprites.h File Reference 215
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_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 on the Y axis only.
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
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_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 on the X axis only.
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()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
216
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_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 on both the X and Y axis.
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.53 gbdk-lib/include/sms/metasprites.h File Reference 217
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.
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
218
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.
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.53 gbdk-lib/include/sms/metasprites.h File Reference 219
UINT8 to )
Hides all hardware sprites in range from <= X < to
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_sprite Number of the first hardware sprite to be used by the metasprite
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
Sets:
• __current_metasprite = metasprite;
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
220
Macros
Functions
Variables
• uint8_t c
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.54 gbdk-lib/include/gb/sgb.h File Reference 221
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
222
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();
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.55 gbdk-lib/include/gbdk/console.h File Reference 223
See also
sgb_check()
20.54.4.1 c void c
Functions
See also
setchar()
See also
gotoxy()
See also
gotoxy()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
224
See also
gotoxy()
Data Structures
• union __far_ptr
Macros
Typedefs
Functions
• void __call__banked ()
• uint32_t to_far_ptr (void ∗ofs, uint16_t seg) OLDCALL
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)
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.56 gbdk-lib/include/gbdk/far_ptr.h File Reference 225
Parameters
Returns
Parameters
Returns
Parameters
Returns
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
226
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);
Returns
Parameters
Returns
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.57 gbdk-lib/include/gbdk/font.h File Reference 227
Data Structures
• struct sfont_handle
Macros
• #define FONT_256ENCODING 0
• #define FONT_128ENCODING 1
• #define FONT_NOENCODING 2
• #define FONT_COMPRESSED 4
Typedefs
Functions
• void font_init ()
• font_t font_load (void ∗font) OLDCALL
• font_t font_set (font_t font_handle) OLDCALL
• void font_color (uint8_t forecolor, uint8_t backcolor) OLDCALL
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 michaelh@earthling.net
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
228
Parameters
Returns
See also
Parameters
Returns
See also
font_init(), font_load()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.59 gbdk-lib/include/gbdk/incbin.h File Reference 229
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
230
Parameters
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.62 gbdk-lib/include/gbdk/version.h File Reference 231
Functions
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
232
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 233
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
234
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 235
Typedefs
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
236
• void set_tile_1bpp_data (uint16_t start, uint16_t ntiles, const void ∗src, uint16_t colors) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void set_bkg_1bpp_data (uint16_t start, uint16_t ntiles, const void ∗src)
• 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_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_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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 237
See also
joypad
See also
mode()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
238
mode()
mode()
set_interrupts(),
add_VBL
set_interrupts(),
add_LCD
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 239
See also
move_win()
See also
move_win()
See also
move_win()
See also
move_win()
See also
display_off, DISPLAY_OFF
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
240
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
See also
HIDE_LEFT_COLUMN
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 241
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
242
Parameters
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 243
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
244
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()
add_LCD(), remove_VBL()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 245
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
246
See also
DISPLAY_ON
Parameters
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 247
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
248
Parameters
dst destination VRAM Address
src Pointer to source buffer
size Number of bytes to copy
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 249
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
250
uint8_t h,
const uint8_t ∗ map,
uint8_t map_w ) [inline]
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)
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 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 251
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
252
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 253
Parameters
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
Parameters
addr address to write to
v value
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
254
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
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.64 gbdk-lib/include/msx/msx.h File Reference 255
20.64.5.7 l void l
See also
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;
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
256
See also
docs_consoles_safe_display_controller_access
Data Structures
• struct joypads_t
• struct OAM_item_t
Macros
• #define NINTENDO_ENTERTAINMENT_SYSTEM
• #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
• #define RGB_WHITE 0x30
• #define J_UP 0x10U
• #define J_DOWN 0x20U
• #define J_LEFT 0x40U
• #define J_RIGHT 0x80U
• #define J_A 0x01U
• #define J_B 0x02U
• #define J_SELECT 0x04U
• #define J_START 0x08U
• #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 0x40U
• #define S_FLIPY 0x80U
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 257
Typedefs
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
258
• void waitpadup ()
• uint8_t joypad_init (uint8_t npads, joypads_t ∗joypads) OLDCALL
• void joypad_ex (joypads_t ∗joypads) OLDCALL
• void enable_interrupts ()
• void disable_interrupts ()
• void wait_vbl_done ()
• void display_off ()
• void refresh_OAM ()
• 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 (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t ∗attributes) OLDCALL
• 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
• 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 (uint8_t first_tile, uint8_t nb_tiles, const uint8_t ∗data, uint8_t base) OLDCALL
• 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
Variables
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 259
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
260
See also
joypad
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 261
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
262
See also
set_sprite_prop()
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 263
Generated on Fri Nov 4 2022 20:51:36 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()
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 265
Parameters
See also
SWITCH_ROM_UNROM
See also
display_off, DISPLAY_OFF
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
See also
HIDE_LEFT_COLUMN
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
266
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 267
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
268
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.
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 269
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
Note
Use CRITICAL {...} instead for creating a block of of code which should execute with interrupts temporarily
turned off.
See also
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
270
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
See also
DISPLAY_ON
Parameters
addr address to write to
v value
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 271
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 Background tile patterns are written to.
• VBK_REG = VBK_BANK_0 indicates the first bank
See also
set_win_data, set_tile_data
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
272
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:
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 273
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.
• 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
274
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
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.
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 275
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
This is identical to set_bkg_submap() except that it adds the base_tile parameter for when a tile map's tiles don't
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
276
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
get_bkg_tile_xy, get_tiles
Parameters
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 277
Returns
returns the address of tile, so you may use faster set_vram_byte() later
Parameters
x X-coordinate
y Y-coordinate
Returns
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
278
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 Background tile patterns are written to.
See also
Sets VRAM Tile Pattern data for Sprites using 1bpp source data
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 279
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:
• 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
280
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 281
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
See also
Parameters
See also
Copies arbitrary data to an address in VRAM without taking into account the state of LCDC bits 3 or 4.
Parameters
vram_addr Pointer to destination VRAM Address
data Pointer to source buffer
len Number of bytes to copy
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
282
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
Sets VRAM Tile Pattern data starting from given base address without taking into account the state of LCDC bit 4.
Parameters
See also
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.65 gbdk-lib/include/nes/nes.h File Reference 283
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
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
284
Parameters
tile Fill value
• #define RGB_TO_NES(c)
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.67 gbdk-lib/include/rand.h File Reference 285
Macros
Functions
Variables
• uint16_t __rand_seed
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()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
286
Parameters
Note: initarand() calls initrand() with the same seed value, and uses rand() to initialize the random generator.
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 287
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
288
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 289
• #define COMPAT_PALETTE(C0, C1, C2, C3) (((uint16_t)(C3) << 12) | ((uint16_t)(C2) << 8) |
((uint16_t)(C1) << 4) | (uint16_t)(C0))
• #define set_bkg_tiles set_tile_map_compat
• #define set_win_tiles set_tile_map_compat
• #define fill_bkg_rect fill_rect_compat
• #define fill_win_rect fill_rect_compat
• #define DISABLE_VBL_TRANSFER _shadow_OAM_base = 0
• #define ENABLE_VBL_TRANSFER _shadow_OAM_base = (uint8_t)((uint16_t)&shadow_OAM >> 8)
• #define MAX_HARDWARE_SPRITES 64
• #define set_bkg_tile_xy set_tile_xy
• #define set_win_tile_xy set_tile_xy
• #define get_win_xy_addr get_bkg_xy_addr
Typedefs
Functions
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
290
• void set_tile_2bpp_data (uint16_t start, uint16_t ntiles, const void ∗src, uint16_t palette) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void set_bkg_data (uint16_t start, uint16_t ntiles, const void ∗src)
• void set_sprite_data (uint16_t start, uint16_t ntiles, const void ∗src)
• void set_bkg_2bpp_data (uint16_t start, uint16_t ntiles, const void ∗src)
• void set_sprite_2bpp_data (uint16_t start, uint16_t ntiles, const void ∗src)
• void set_1bpp_colors (uint8_t fgcolor, uint8_t bgcolor)
• void set_tile_1bpp_data (uint16_t start, uint16_t ntiles, const void ∗src, uint16_t colors) Z88DK_CALLEE
PRESERVES_REGS(iyh
• void set_bkg_1bpp_data (uint16_t start, uint16_t ntiles, const void ∗src)
• void set_sprite_1bpp_data (uint16_t start, uint16_t ntiles, const void ∗src)
• 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_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 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 ∗ 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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 291
• 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
See also
joypad
See also
mode()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
292
See also
mode()
See also
mode()
See also
set_interrupts(),
add_VBL
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 293
See also
set_interrupts(),
add_LCD
See also
move_win()
See also
move_win()
See also
move_win()
See also
move_win()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
294
See also
display_off, DISPLAY_OFF
See also
display_off, DISPLAY_ON
See also
SHOW_LEFT_COLUMN
HIDE_LEFT_COLUMN
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 295
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
296
This makes a BANKREF() reference in another source file accessible in the current file for use with BANK().
See also
BANKREF(), BANK()
Parameters
Parameters
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 297
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
298
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 299
See also
add_VBL()
See also
add_LCD(), remove_VBL()
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
300
See also
DISPLAY_ON
Parameters
Only required for joypad_ex, not required for calls to regular joypad()
Returns
See also
joypad_ex(), joypads_t
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 301
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
302
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 303
Parameters
dst destination VRAM Address
src Pointer to source buffer
size Number of bytes to copy
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
304
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 305
(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 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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
306
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 |
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 307
0x01).
• See: SPRITES_8x16
Parameters
See also
Parameters
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
308
Parameters
See also
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
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.69 gbdk-lib/include/sms/sms.h File Reference 309
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
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
310
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.71 gbdk-lib/include/stdbool.h File Reference 311
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
312
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 313
Typedefs
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
314
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 315
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
316
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.73 gbdk-lib/include/stdint.h File Reference 317
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
318
Functions
Parameters
c Character to print
Parameters
• %c (character)
• %u (unsigned int)
• %d (signed int)
• %s (string)
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.75 gbdk-lib/include/stdlib.h File Reference 319
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
320
• char ∗ ultoa (unsigned long n, char ∗s, unsigned char radix) OLDCALL
• void ∗ calloc (size_t nmemb, size_t size)
• void ∗ malloc (size_t size)
• void ∗ realloc (void ∗ptr, size_t size)
• void free (void ∗ptr)
• void ∗ bsearch (const void ∗key, const void ∗base, size_t nmemb, size_t size, int(∗compar)(const void ∗, const
void ∗) __reentrant)
• void qsort (void ∗base, size_t nmemb, size_t size, int(∗compar)(const void ∗, const void ∗) __reentrant)
Parameters
Parameters
Parameters
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.75 gbdk-lib/include/stdlib.h File Reference 321
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
322
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.76 gbdk-lib/include/stdnoreturn.h File Reference 323
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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
324
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
• #define TYPEOF_SBIT 9
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
20.78 gbdk-lib/include/typeof.h File Reference 325
• #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 Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
326
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
Index
_AUD3WAVERAM __bool_true_false_are_defined
hardware.h, 176 stdbool.h, 311
_BIOS __call__banked
hardware.h, 188, 201 far_ptr.h, 226
_HRAM __call_banked_addr
hardware.h, 176 far_ptr.h, 226
_IO __call_banked_bank
hardware.h, 176 far_ptr.h, 226
_OAMRAM __call_banked_ptr
hardware.h, 175 far_ptr.h, 226
_RAM __current_base_tile
hardware.h, 175 metasprites.h, 209, 211, 216, 220
_RAMBANK __current_metasprite
hardware.h, 175 metasprites.h, 208, 211, 216, 219
_SCRN0 __far_ptr, 64
hardware.h, 175 fn, 65
_SCRN1 ofs, 65
hardware.h, 175 ptr, 65
_SRAM seg, 65
hardware.h, 175 segfn, 65
_SYSTEM segofs, 65
hardware.h, 189, 201 __rand_seed
_VRAM rand.h, 286
hardware.h, 175 __reentrant
_VRAM8000 stdlib.h, 320
hardware.h, 175 __render_shadow_OAM
_VRAM8800 metasprites.h, 209, 211, 216, 220
hardware.h, 175 __setjmp
_VRAM9000 setjmp.h, 287
hardware.h, 175 _cpu
__BYTES gb.h, 152
hardware.h, 162, 182, 190, 195 _current_1bpp_colors
__BYTE_REG gb.h, 153
hardware.h, 162, 182, 190, 195 msx.h, 255
__GBDK_VERSION nes.h, 284
version.h, 232 sms.h, 309
__HandleCrash _current_2bpp_palette
crash_handler.h, 102 msx.h, 255
__PTRDIFF_T_DEFINED sms.h, 309
stddef.h, 311 _current_bank
__READ_VDP_REG gb.h, 152
msx.h, 238 msx.h, 255
sms.h, 292 nes.h, 284
__REG sms.h, 295
hardware.h, 162 _fixed, 65
__SIZE_T_DEFINED b, 66
stddef.h, 311 h, 65
types.h, 87, 88, 91 l, 65
__WCHAR_T_DEFINED w, 66
stddef.h, 311 _io_in
__WRITE_VDP_REG gb.h, 152
msx.h, 238 _io_out
sms.h, 292 gb.h, 152
__assert _io_status
assert.h, 92 gb.h, 152
328 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 329
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
330 INDEX
BYTE CHAR_MIN
types.h, 89 limits.h, 232
circle
c drawing.h, 106
gb.h, 151 clock
gbdecompress.h, 156, 157 time.h, 324
metasprites.h, 209 clock_t
msx.h, 254 types.h, 87, 88, 91
sgb.h, 223 CLOCKS_PER_SEC
sms.h, 309 time.h, 324
string.h, 82 cls
calloc console.h, 224
stdlib.h, 322 color
cancel_pending_interrupts drawing.h, 106
gb.h, 127 COMPAT_PALETTE
msx.h, 245 gb.h, 123
sms.h, 299 msx.h, 242
cgb.h nes.h, 266
cgb_compatibility, 102 sms.h, 297
cpu_fast, 101 console.h
cpu_slow, 101 cls, 224
palette_color_t, 99 gotoxy, 223
RGB, 97 posx, 223
RGB8, 98 posy, 223
RGB_AQUA, 99 setchar, 223
RGB_BLACK, 99 cpu_fast
RGB_BLUE, 98 cgb.h, 101
RGB_BROWN, 99 msx.h, 247
RGB_CYAN, 99 sms.h, 301
RGB_DARKBLUE, 99 cpu_slow
RGB_DARKGRAY, 99 cgb.h, 101
RGB_DARKGREEN, 98 crash_handler.h
RGB_DARKRED, 98 __HandleCrash, 102
RGB_DARKYELLOW, 99 CRITICAL
RGB_GREEN, 98 types.h, 89
RGB_LIGHTFLESH, 99 ctype.h
RGB_LIGHTGRAY, 99 isalpha, 93
RGB_ORANGE, 99 isdigit, 93
RGB_PINK, 99 islower, 93
RGB_PURPLE, 99 isspace, 93
RGB_RED, 98 isupper, 93
RGB_TEAL, 99 tolower, 94
RGB_WHITE, 99 toupper, 94
RGB_YELLOW, 99 CURRENT_BANK
RGBHTML, 98 gb.h, 119
set_bkg_palette, 100 msx.h, 240
set_bkg_palette_entry, 100 nes.h, 262
set_default_palette, 102 sms.h, 295
set_sprite_palette, 100
set_sprite_palette_entry, 101 d
cgb_compatibility gb.h, 152
cgb.h, 102 msx.h, 254
sms.h, 301 sms.h, 309
CGB_TYPE delay
gb.h, 118 gb.h, 128
CHAR_BIT msx.h, 246
limits.h, 232 nes.h, 267
CHAR_MAX sms.h, 300
limits.h, 232 DEVICE_SCREEN_BUFFER_HEIGHT
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 331
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
332 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 333
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
334 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 335
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
336 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 337
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
338 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 339
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
340 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 341
incbin.h int_fast32_t
BANK, 229 stdint.h, 317
INCBIN, 230 INT_FAST8_MAX
INCBIN_EXTERN, 229 stdint.h, 314
INCBIN_SIZE, 229 INT_FAST8_MIN
INCBIN_EXTERN stdint.h, 314
incbin.h, 229 int_fast8_t
INCBIN_SIZE stdint.h, 317
incbin.h, 229 int_handler
init_bkg gb.h, 124
gb.h, 150 msx.h, 243
nes.h, 283 sms.h, 297
init_win INT_LEAST16_MAX
gb.h, 150 stdint.h, 314
initarand INT_LEAST16_MIN
rand.h, 286 stdint.h, 314
initrand int_least16_t
rand.h, 285 stdint.h, 317
INT16 INT_LEAST32_MAX
types.h, 87, 88, 91 stdint.h, 314
INT16_C INT_LEAST32_MIN
stdint.h, 315 stdint.h, 314
INT16_MAX int_least32_t
stdint.h, 313 stdint.h, 317
INT16_MIN INT_LEAST8_MAX
stdint.h, 313 stdint.h, 314
int16_t INT_LEAST8_MIN
stdint.h, 316 stdint.h, 314
INT32 int_least8_t
types.h, 87, 88, 91 stdint.h, 317
INT32_C INT_MAX
stdint.h, 316 limits.h, 232
INT32_MAX INT_MIN
stdint.h, 314 limits.h, 232
INT32_MIN INTERRUPT
stdint.h, 313 types.h, 89
int32_t INTMAX_C
stdint.h, 316 stdint.h, 316
INT8 INTMAX_MAX
types.h, 87, 88, 91 stdint.h, 315
INT8_C INTMAX_MIN
stdint.h, 315 stdint.h, 315
INT8_MAX intmax_t
stdint.h, 313 stdint.h, 317
INT8_MIN INTPTR_MAX
stdint.h, 313 stdint.h, 315
int8_t INTPTR_MIN
stdint.h, 316 stdint.h, 315
INT_FAST16_MAX intptr_t
stdint.h, 314 stdint.h, 317
INT_FAST16_MIN IO_ERROR
stdint.h, 314 gb.h, 119
int_fast16_t IO_IDLE
stdint.h, 317 gb.h, 118
INT_FAST32_MAX IO_RECEIVING
stdint.h, 315 gb.h, 118
INT_FAST32_MIN IO_SENDING
stdint.h, 314 gb.h, 118
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
342 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 343
JOY_P2_LIGHT LCDCF_B_BG8000
hardware.h, 187, 200 hardware.h, 168
JOY_P2_RIGHT LCDCF_B_BG9C00
hardware.h, 187, 200 hardware.h, 168
JOY_P2_SW1 LCDCF_B_BGON
hardware.h, 187, 200 hardware.h, 168
JOY_P2_SW2 LCDCF_B_OBJ16
hardware.h, 187, 200 hardware.h, 168
JOY_P2_TRIGGER LCDCF_B_OBJON
hardware.h, 187, 200 hardware.h, 168
JOY_P2_UP LCDCF_B_ON
hardware.h, 187, 199 hardware.h, 168
JOY_RESET LCDCF_B_WIN9C00
hardware.h, 187, 200 hardware.h, 168
joypad LCDCF_B_WINON
gb.h, 128 hardware.h, 168
msx.h, 246 LCDCF_BG8000
nes.h, 267 hardware.h, 167
sms.h, 300 LCDCF_BG8800
joypad_ex hardware.h, 167
gb.h, 129 LCDCF_BG9800
msx.h, 246 hardware.h, 167
nes.h, 269 LCDCF_BG9C00
sms.h, 300 hardware.h, 167
joypad_init LCDCF_BGOFF
gb.h, 129 hardware.h, 168
msx.h, 246 LCDCF_BGON
nes.h, 268 hardware.h, 168
sms.h, 300 LCDCF_OBJ16
joypads hardware.h, 167
joypads_t, 68 LCDCF_OBJ8
joypads_t, 67
hardware.h, 167
joy0, 68
LCDCF_OBJOFF
joy1, 68
hardware.h, 167
joy2, 68
LCDCF_OBJON
joy3, 68
hardware.h, 167
joypads, 68
LCDCF_OFF
npads, 68
hardware.h, 167
LCDCF_ON
KEY1_REG
hardware.h, 178 hardware.h, 167
KEY1F_DBLSPEED LCDCF_WIN9800
hardware.h, 170 hardware.h, 167
KEY1F_PREPARE LCDCF_WIN9C00
hardware.h, 170 hardware.h, 167
LCDCF_WINOFF
l hardware.h, 167
_fixed, 65 LCDCF_WINON
gb.h, 152 hardware.h, 167
msx.h, 254 limits.h
sms.h, 309 CHAR_BIT, 232
labs CHAR_MAX, 232
stdlib.h, 320 CHAR_MIN, 232
LCD_IFLAG INT_MAX, 232
gb.h, 116 INT_MIN, 232
msx.h, 238 LONG_MAX, 233
sms.h, 292 LONG_MIN, 233
LCDC_REG SCHAR_MAX, 232
hardware.h, 178 SCHAR_MIN, 232
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
344 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 345
dtile, 70 MSX
dx, 70 msx.h, 237
dy, 70 msx.h
metasprites.h, 205, 210, 213, 218 __READ_VDP_REG, 238
props, 70 __WRITE_VDP_REG, 238
metasprites.h _current_1bpp_colors, 255
__current_base_tile, 209, 211, 216, 220 _current_2bpp_palette, 255
__current_metasprite, 208, 211, 216, 219 _current_bank, 255
__render_shadow_OAM, 209, 211, 216, 220 _map_tile_offset, 255
c, 209 _shadow_OAM_OFF, 255
hide_metasprite, 208, 211, 216, 219 _shadow_OAM_base, 255
hide_sprites_range, 206, 210, 213, 218 _submap_tile_offset, 255
iyl, 211, 220 add_JOY, 245
METASPR_ITEM, 205, 209, 213, 218 add_LCD, 245
METASPR_TERM, 205, 210, 213, 218 add_SIO, 245
metasprite_end, 205, 209, 213, 218 add_TIM, 245
metasprite_t, 205, 210, 213, 218 add_VBL, 245
move_metasprite, 206, 210, 214, 219 BANK, 241
move_metasprite_hflip, 207, 215 BANKREF, 241
move_metasprite_hvflip, 208, 215 BANKREF_EXTERN, 241
move_metasprite_vflip, 206, 214 c, 254
mfont_handle cancel_pending_interrupts, 245
font.h, 228 COMPAT_PALETTE, 242
MGB_TYPE cpu_fast, 247
gb.h, 118 CURRENT_BANK, 240
MINWNDPOSX d, 254
gb.h, 117 delay, 246
msx.h, 239 DEVICE_SUPPORTS_COLOR, 240
sms.h, 293 DISABLE_RAM, 242
MINWNDPOSY DISABLE_VBL_TRANSFER, 243
gb.h, 117 DISPLAY_OFF, 239
msx.h, 239 display_off, 245
sms.h, 293 DISPLAY_ON, 239
mode e, 254
gb.h, 127 EMPTY_IFLAG, 238
msx.h, 244 ENABLE_RAM, 242
nes.h, 267 ENABLE_VBL_TRANSFER, 243
sms.h, 298 fill_bkg_rect, 243
move_bkg fill_rect, 251
gb.h, 137 fill_win_rect, 243
msx.h, 245 get_bkg_xy_addr, 254
nes.h, 277 get_mode, 244
sms.h, 299 get_sprite_prop, 252
move_metasprite get_sprite_tile, 252
metasprites.h, 206, 210, 214, 219 get_win_xy_addr, 243
move_metasprite_hflip h, 254
metasprites.h, 207, 215 HIDE_BKG, 240
move_metasprite_hvflip HIDE_LEFT_COLUMN, 240
metasprites.h, 208, 215 hide_sprite, 253
move_metasprite_vflip HIDE_SPRITES, 240
metasprites.h, 206, 214 HIDE_WIN, 240
move_sprite int_handler, 243
gb.h, 146 iyh, 254
msx.h, 252 iyl, 254
nes.h, 280 J_A, 237
sms.h, 307 J_B, 237
move_win J_DOWN, 237
gb.h, 143 J_LEFT, 237
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
346 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 347
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
348 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 349
ofs PPUCTRL_NMI
__far_ptr, 65 hardware.h, 190
OLDCALL PPUCTRL_SPR_8X16
types.h, 89 hardware.h, 190
opcode PPUCTRL_SPR_8X8
isr_nested_vector_t, 66 hardware.h, 190
isr_vector_t, 67 PPUCTRL_SPR_CHR
OR hardware.h, 190
drawing.h, 103 PPUDATA
hardware.h, 191
P1_REG
PPUMASK
hardware.h, 176
hardware.h, 190
P1F_0
PPUMASK_BLUE
hardware.h, 163
hardware.h, 190
P1F_1
PPUMASK_GREEN
hardware.h, 163
hardware.h, 190
P1F_2
PPUMASK_MONOCHROME
hardware.h, 163
hardware.h, 191
P1F_3
PPUMASK_RED
hardware.h, 163
hardware.h, 190
P1F_4
PPUMASK_SHOW_BG
hardware.h, 163
hardware.h, 191
P1F_5
PPUMASK_SHOW_BG_LC
hardware.h, 163
hardware.h, 191
P1F_GET_BTN
PPUMASK_SHOW_SPR
hardware.h, 163
hardware.h, 190
P1F_GET_DPAD
PPUMASK_SHOW_SPR_LC
hardware.h, 163
hardware.h, 191
P1F_GET_NONE
hardware.h, 163 PPUSCROLL
palette_color_t hardware.h, 191
cgb.h, 99 PPUSTATUS
nes.h, 266 hardware.h, 191
PCM12_REG PRESERVES_REGS
hardware.h, 179 types.h, 89
PCM34_REG printf
hardware.h, 179 stdio.h, 318
PCM_SAMPLE prop
hardware.h, 178 OAM_item_t, 71
plot props
drawing.h, 105 metasprite_t, 70
plot_point provides.h
drawing.h, 105 USE_C_MEMCPY, 72, 73
pmfont_handle USE_C_STRCMP, 72, 73
font.h, 228 USE_C_STRCPY, 72, 73
POINTER PSG_CH0
types.h, 92 hardware.h, 183, 196
posx PSG_CH1
console.h, 223 hardware.h, 183, 196
posy PSG_CH2
console.h, 223 hardware.h, 183, 196
PPUADDR PSG_CH3
hardware.h, 191 hardware.h, 183, 196
PPUCTRL PSG_LATCH
hardware.h, 190 hardware.h, 183, 196
PPUCTRL_BG_CHR PSG_VOLUME
hardware.h, 190 hardware.h, 183, 196
PPUCTRL_INC32 ptr
hardware.h, 190 __far_ptr, 65
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
350 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 351
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
352 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 353
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
354 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 355
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
356 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 357
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
358 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 359
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
360 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 361
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
362 INDEX
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
INDEX 363
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen
364 INDEX
OAM_item_t, 71
Z88DK_CALLEE
types.h, 90
Z88DK_FASTCALL
types.h, 91
Generated on Fri Nov 4 2022 20:51:36 for GBDK 2020 Docs by Doxygen