GBDK 2020 Docs  4.1.1
API Documentation for GBDK 2020
incbin.h
Go to the documentation of this file.
1 
10 #ifndef _INCBIN_H
11 #define _INCBIN_H
12 
13 #include <stdint.h>
14 
15 
25 #define INCBIN_EXTERN(VARNAME) extern const uint8_t VARNAME[]; \
26 extern const void __size_ ## VARNAME; \
27 extern const void __bank_ ## VARNAME;
28 
37 #define INCBIN_SIZE(VARNAME) ( (uint16_t) & __size_ ## VARNAME )
38 
47 #ifndef BANK
48 #define BANK(VARNAME) ( (uint8_t) & __bank_ ## VARNAME )
49 #endif
50 
68 #if defined(__TARGET_nes)
69 // mos6502 target does not support banking yet - omit "__banked" keyword, and assume bank is 0 in asm code
70 #define INCBIN(VARNAME, FILEPATH) void __func_ ## VARNAME(void) __naked { \
71 __asm \
72 _ ## VARNAME:: \
73 1$: \
74  .incbin FILEPATH \
75 2$: \
76  ___size_ ## VARNAME = (2$-1$) \
77  .globl ___size_ ## VARNAME \
78  .local b___func_ ## VARNAME \
79  ___bank_ ## VARNAME = 0 \
80  .globl ___bank_ ## VARNAME \
81 __endasm; \
82 }
83 #else
84 // Use __banked keyword and 'b' prefix for other targets
85 #define INCBIN(VARNAME, FILEPATH) void __func_ ## VARNAME(void) __banked __naked { \
86 __asm \
87 _ ## VARNAME:: \
88 1$: \
89  .incbin FILEPATH \
90 2$: \
91  ___size_ ## VARNAME = (2$-1$) \
92  .globl ___size_ ## VARNAME \
93  .local b___func_ ## VARNAME \
94  ___bank_ ## VARNAME = b___func_ ## VARNAME \
95  .globl ___bank_ ## VARNAME \
96 __endasm; \
97 }
98 #endif
99 
100 #endif // _INCBIN_H