gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/gbdk/incbin.h
1 /** @file gbdk/incbin.h
2
3 Allows binary data from other files to be included
4 into a C source file.
5
6 It is implemented using asm .incbin and macros.
7
8 See the `incbin` example project for a demo of how to use it.
9 */
10 #ifndef _INCBIN_H
11 #define _INCBIN_H
12
13 #include <stdint.h>
14
15
16 /** Creates extern entries for accessing a INCBIN() generated
17 variable and it's size in another source file.
18
19 @param VARNAME Name of the variable used with INCBIN
20
21 An entry is created for the variable and it's size variable.
22
23 @ref INCBIN(), INCBIN_SIZE()
24 */
25 #define INCBIN_EXTERN(VARNAME) extern const uint8_t VARNAME[]; \
26 extern const void __size_ ## VARNAME; \
27 extern const void __bank_ ## VARNAME;
28
29 /** Obtains the __size in bytes__ of the INCBIN() generated data
30
31 @param VARNAME Name of the variable used with INCBIN
32
33 Requires @ref INCBIN_EXTERN() to have been called earlier in the source file
34
35 @ref INCBIN(), INCBIN_EXTERN()
36 */
37 #define INCBIN_SIZE(VARNAME) ( (uint16_t) & __size_ ## VARNAME )
38
39 /** Obtains the __bank number__ of the INCBIN() generated data
40
41 @param VARNAME Name of the variable used with INCBIN
42
43 Requires @ref INCBIN_EXTERN() to have been called earlier in the source file
44
45 @ref INCBIN(), INCBIN_EXTERN()
46 */
47 #ifndef BANK
48 #define BANK(VARNAME) ( (uint8_t) & __bank_ ## VARNAME )
49 #endif
50
51 /** Includes binary data into a C source file
52
53 @param VARNAME Variable name to use
54 @param FILEPATH Path to the file which will be binary included into the C source file
55
56 __filepath__ is relative to the working directory of the tool
57 that is calling it (often a makefile's working directory), __NOT__
58 to the file it's being included into.
59
60 The variable name is not modified and can be used as-is.
61
62 The INCBIN() macro will declare the @ref BANK() and @ref INCBIN_SIZE()
63 helper symbols. Then if @ref INCBIN_EXTERN() is used in the header then
64 those helper macros can be used in the application code.
65 - @ref INCBIN_SIZE() for obtaining the size of the included data.
66 - @ref BANK() for obtaining the bank number of the included data.
67
68 Use @ref INCBIN_EXTERN() within another source file
69 to make the variable and it's data accessible there.
70
71 ==============
72
73 */
74 #define INCBIN(VARNAME, FILEPATH) void __func_ ## VARNAME(void) __banked __naked { \
75 __asm \
76 _ ## VARNAME:: \
77 1$: \
78 .incbin FILEPATH \
79 2$: \
80 ___size_ ## VARNAME = (2$-1$) \
81 .globl ___size_ ## VARNAME \
82 .local b___func_ ## VARNAME \
83 ___bank_ ## VARNAME = b___func_ ## VARNAME \
84 .globl ___bank_ ## VARNAME \
85 __endasm; \
86 }
87
88 #endif // _INCBIN_H
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.