GBDK 2020 Docs API Documentation for GBDK 2020

gb.h
Go to the documentation of this file.
1
4 #ifndef _GB_H
5 #define _GB_H
6
7 #define __GBDK_VERSION 402
8
9 #include <types.h>
10 #include <gb/hardware.h>
11 #include <gb/sgb.h>
12 #include <gb/cgb.h>
13
27 #define J_START 0x80U
28 #define J_SELECT 0x40U
29 #define J_B 0x20U
30 #define J_A 0x10U
31 #define J_DOWN 0x08U
32 #define J_UP 0x04U
33 #define J_LEFT 0x02U
34 #define J_RIGHT 0x01U
35
40 #define M_DRAWING 0x01U
41 #define M_TEXT_OUT 0x02U
42 #define M_TEXT_INOUT 0x03U
43
48 #define M_NO_SCROLL 0x04U
49
52 #define M_NO_INTERP 0x08U
53
58 #define S_PALETTE 0x10U
59
62 #define S_FLIPX 0x20U
63
66 #define S_FLIPY 0x40U
67
71 #define S_PRIORITY 0x80U
72
73 /* Interrupt flags */
79 #define VBL_IFLAG 0x01U
80
83 #define LCD_IFLAG 0x02U
84
87 #define TIM_IFLAG 0x04U
88
91 #define SIO_IFLAG 0x08U
92
95 #define JOY_IFLAG 0x10U
96
97 /* Limits */
100 #define SCREENWIDTH 0xA0U
101
103 #define SCREENHEIGHT 0x90U
104
106 #define MINWNDPOSX 0x07U
107
109 #define MINWNDPOSY 0x00U
110
112 #define MAXWNDPOSX 0xA6U
113
115 #define MAXWNDPOSY 0x8FU
116
117
120 typedef void (*int_handler)(void) NONBANKED;
121
129 void remove_VBL(int_handler h) NONBANKED;
130
134 void remove_LCD(int_handler h) NONBANKED;
135
139 void remove_TIM(int_handler h) NONBANKED;
140
153 void remove_SIO(int_handler h) NONBANKED;
154
158 void remove_JOY(int_handler h) NONBANKED;
159
171 void add_VBL(int_handler h) NONBANKED;
172
189 void add_LCD(int_handler h) NONBANKED;
190
200 void add_TIM(int_handler h) NONBANKED;
201
202
212 void add_SIO(int_handler h) NONBANKED;
213
214
229 void add_JOY(int_handler h) NONBANKED;
230
231
247 void nowait_int_handler(void) NONBANKED;
248
249
262 void wait_int_handler(void) NONBANKED;
263
264
265
272 void mode(UINT8 m) NONBANKED;
273
278 UINT8 get_mode(void) NONBANKED __preserves_regs(b, c);
279
284 extern UINT8 _cpu;
285
288 #define DMG_TYPE 0x01
289
291 #define MGB_TYPE 0xFF
292
294 #define CGB_TYPE 0x11
295
302 extern volatile UINT16 sys_time;
303
304
305
313 void send_byte(void);
314
322 void receive_byte(void);
323
325 extern volatile UINT8 _io_status;
326
329 extern volatile UINT8 _io_in;
330
333 extern volatile UINT8 _io_out;
334
335 /* Status codes */
337 #define IO_IDLE 0x00U
338
339 #define IO_SENDING 0x01U
340
341 #define IO_RECEIVING 0x02U
342
343 #define IO_ERROR 0x04U
344
345
346
351 __REG _current_bank;
352
356 #define SWITCH_ROM_MBC1(b) \
357 _current_bank = (b), *(unsigned char *)0x2000 = (b)
358
362 #define SWITCH_RAM_MBC1(b) \
363 *(unsigned char *)0x4000 = (b)
364
367 #define ENABLE_RAM_MBC1 \
368 *(unsigned char *)0x0000 = 0x0A
369
372 #define DISABLE_RAM_MBC1 \
373 *(unsigned char *)0x0000 = 0x00
374
375 #define SWITCH_16_8_MODE_MBC1 \
376 *(unsigned char *)0x6000 = 0x00
377
378 #define SWITCH_4_32_MODE_MBC1 \
379 *(unsigned char *)0x6000 = 0x01
380
386 #define SWITCH_ROM_MBC5(b) \
387 _current_bank = (b), \
388 *(unsigned char *)0x3000 = 0, \
389 *(unsigned char *)0x2000 = (b)
390
397 #define SWITCH_ROM_MBC5_8M(b) \
398 *(unsigned char *)0x3000 = ((UINT16)(b) >> 8), \
399 *(unsigned char *)0x2000 = (b)
400
404 #define SWITCH_RAM_MBC5(b) \
405 *(unsigned char *)0x4000 = (b)
406
409 #define ENABLE_RAM_MBC5 \
410 *(unsigned char *)0x0000 = 0x0A
411
414 #define DISABLE_RAM_MBC5 \
415 *(unsigned char *)0x0000 = 0x00
416
417
418
423 void delay(UINT16 d) NONBANKED;
424
425
426
432 UINT8 joypad(void) NONBANKED __preserves_regs(b, c, h, l);
433
446 UINT8 waitpad(UINT8 mask) NONBANKED __preserves_regs(b, c);
447
453 void waitpadup(void) NONBANKED __preserves_regs(a, b, c, d, e, h, l);
454
460 typedef struct {
461 UINT8 npads;
462 union {
463 struct {
464 UINT8 joy0, joy1, joy2, joy3;
465 };
466 UINT8 joypads[4];
467 };
468 } joypads_t;
469
479 UINT8 joypad_init(UINT8 npads, joypads_t * joypads);
480
487 void joypad_ex(joypads_t * joypads);
488
489
490
494 void enable_interrupts(void) NONBANKED __preserves_regs(a, b, c, d, e, h, l);
495
503 void disable_interrupts(void) NONBANKED __preserves_regs(a, b, c, d, e, h, l);
504
511 void set_interrupts(UINT8 flags) NONBANKED __preserves_regs(b, c, d, e);
512
516 void reset(void) NONBANKED;
517
528 void wait_vbl_done(void) NONBANKED __preserves_regs(b, c, d, e, h, l);
529
535 void display_off(void) NONBANKED __preserves_regs(b, c, d, e, h, l);
536
537
538
544 void hiramcpy(UINT8 dst,
545 const void *src,
546 UINT8 n) NONBANKED __preserves_regs(b, c);
547
548
549
553 #define DISPLAY_ON \
554 LCDC_REG|=0x80U
555
559 #define DISPLAY_OFF \
560 display_off();
561
565 #define SHOW_BKG \
566 LCDC_REG|=0x01U
567
571 #define HIDE_BKG \
572 LCDC_REG&=0xFEU
573
577 #define SHOW_WIN \
578 LCDC_REG|=0x20U
579
583 #define HIDE_WIN \
584 LCDC_REG&=0xDFU
585
589 #define SHOW_SPRITES \
590 LCDC_REG|=0x02U
591
595 #define HIDE_SPRITES \
596 LCDC_REG&=0xFDU
597
601 #define SPRITES_8x16 \
602 LCDC_REG|=0x04U
603
607 #define SPRITES_8x8 \
608 LCDC_REG&=0xFBU
609
610
611
627 void set_bkg_data(UINT8 first_tile,
628 UINT8 nb_tiles,
629 unsigned char *data) NONBANKED __preserves_regs(b, c);
630
631
648 void set_bkg_1bit_data(UINT8 first_tile,
649 UINT8 nb_tiles,
650 unsigned char *data,
651 UINT8 color) NONBANKED __preserves_regs(b, c);
652
653
668 void get_bkg_data(UINT8 first_tile,
669 UINT8 nb_tiles,
670 unsigned char *data) NONBANKED __preserves_regs(b, c);
671
672
717 void set_bkg_tiles(UINT8 x,
718 UINT8 y,
719 UINT8 w,
720 UINT8 h,
721 unsigned char *tiles) NONBANKED __preserves_regs(b, c);
722
723
740 void get_bkg_tiles(UINT8 x,
741 UINT8 y,
742 UINT8 w,
743 UINT8 h,
744 unsigned char *tiles) NONBANKED __preserves_regs(b, c);
745
746
760 inline void move_bkg(UINT8 x, UINT8 y) {
761 SCX_REG=x, SCY_REG=y;
762 }
763
764
774 inline void scroll_bkg(INT8 x, INT8 y) {
775 SCX_REG+=x, SCY_REG+=y;
776 }
777
778
779
793 void set_win_data(UINT8 first_tile,
794 UINT8 nb_tiles,
795 unsigned char *data) NONBANKED __preserves_regs(b, c);
796
797
809 void set_win_1bit_data(UINT8 first_tile,
810 UINT8 nb_tiles,
811 unsigned char *data) NONBANKED __preserves_regs(b, c);
812
813
825 void get_win_data(UINT8 first_tile,
826 UINT8 nb_tiles,
827 unsigned char *data) NONBANKED __preserves_regs(b, c);
828
829
852 void set_win_tiles(UINT8 x,
853 UINT8 y,
854 UINT8 w,
855 UINT8 h,
856 unsigned char *tiles) NONBANKED __preserves_regs(b, c);
857
858
874 void get_win_tiles(UINT8 x,
875 UINT8 y,
876 UINT8 w,
877 UINT8 h,
878 unsigned char *tiles) NONBANKED __preserves_regs(b, c);
879
880
892 inline void move_win(UINT8 x, UINT8 y) {
893 WX_REG=x, WY_REG=y;
894 }
895
896
906 inline void scroll_win(INT8 x, INT8 y) {
907 WX_REG+=x, WY_REG+=y;
908 }
909
910
911
927 void set_sprite_data(UINT8 first_tile,
928 UINT8 nb_tiles,
929 unsigned char *data) NONBANKED __preserves_regs(b, c);
930
931
947 void set_sprite_1bit_data(UINT8 first_tile,
948 UINT8 nb_tiles,
949 unsigned char *data) NONBANKED __preserves_regs(b, c);
950
951
964 void get_sprite_data(UINT8 first_tile,
965 UINT8 nb_tiles,
966 unsigned char *data) NONBANKED __preserves_regs(b, c);
967
968
975 typedef struct OAM_item_t {
976 UINT8 y, x; //< X, Y Coordinates of the sprite on screen
977 UINT8 tile; //< Sprite tile number
978 UINT8 prop; //< OAM Property Flags
979 } OAM_item_t;
980
981
984 extern volatile struct OAM_item_t shadow_OAM[];
985
988 __REG _shadow_OAM_base;
989
992 #define DISABLE_OAM_DMA \
993 _shadow_OAM_base = 0
994
997 #define ENABLE_OAM_DMA \
998 _shadow_OAM_base = (UBYTE)((UWORD)&shadow_OAM >> 8)
999
1002 inline void SET_SHADOW_OAM_ADDRESS(void * address) {
1003 _shadow_OAM_base = (UBYTE)((UWORD)address >> 8);
1004 }
1005
1022 inline void set_sprite_tile(UINT8 nb, UINT8 tile) {
1023 shadow_OAM[nb].tile=tile;
1024 }
1025
1026
1033 inline UINT8 get_sprite_tile(UINT8 nb) {
1034 return shadow_OAM[nb].tile;
1035 }
1036
1037
1068 inline void set_sprite_prop(UINT8 nb, UINT8 prop){
1069 shadow_OAM[nb].prop=prop;
1070 }
1071
1072
1078 inline UINT8 get_sprite_prop(UINT8 nb){
1079 return shadow_OAM[nb].prop;
1080 }
1081
1082
1095 inline void move_sprite(UINT8 nb, UINT8 x, UINT8 y) {
1096 OAM_item_t * itm = &shadow_OAM[nb];
1097 itm->y=y, itm->x=x;
1098 }
1099
1100
1111 inline void scroll_sprite(UINT8 nb, INT8 x, INT8 y) {
1112 OAM_item_t * itm = &shadow_OAM[nb];
1113 itm->y+=y, itm->x+=x;
1114 }
1115
1116
1121 inline void hide_sprite(UINT8 nb) {
1122 shadow_OAM[nb].y = 0;
1123 }
1124
1125
1126
1139 void set_data(unsigned char *vram_addr,
1140 unsigned char *data,
1141 UINT16 len) NONBANKED __preserves_regs(b, c);
1142
1143
1156 void get_data(unsigned char *data,
1157 unsigned char *vram_addr,
1158 UINT16 len) NONBANKED __preserves_regs(b, c);
1159
1160
1181 void set_tiles(UINT8 x,
1182 UINT8 y,
1183 UINT8 w,
1184 UINT8 h,
1185 unsigned char *vram_addr,
1186 unsigned char *tiles) NONBANKED __preserves_regs(b, c);
1187
1188
1207 void get_tiles(UINT8 x,
1208 UINT8 y,
1209 UINT8 w,
1210 UINT8 h,
1211 unsigned char *tiles,
1212 unsigned char *vram_addr) NONBANKED __preserves_regs(b, c);
1213
1214
1215
1216
1222 void init_win(UINT8 c) NONBANKED __preserves_regs(b, c);
1223
1229 void init_bkg(UINT8 c) NONBANKED __preserves_regs(b, c);
1230
1238 void vmemset (void *s, UINT8 c, size_t n) NONBANKED __preserves_regs(b, c);
1239
1240
1241
1250 void fill_bkg_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b, c);
1251
1260 void fill_win_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b, c);
1261
1262 #endif /* _GB_H */
UINT8
unsigned char UINT8
Definition: types.h:21
reset
void reset(void) NONBANKED
get_bkg_tiles
void get_bkg_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *tiles) NONBANKED __preserves_regs(b
display_off
void display_off(void) NONBANKED __preserves_regs(b
OAM_item_t::tile
UINT8 tile
Definition: gb.h:977
hide_sprite
void hide_sprite(UINT8 nb)
Definition: gb.h:1121
remove_TIM
void remove_TIM(int_handler h) NONBANKED
OAM_item_t::y
UINT8 y
Definition: gb.h:976
joypad
UINT8 joypad(void) NONBANKED __preserves_regs(b
shadow_OAM
volatile struct OAM_item_t shadow_OAM[]
OAM_item_t
struct OAM_item_t OAM_item_t
_current_bank
__REG _current_bank
Definition: gb.h:351
UINT16
unsigned int UINT16
Definition: types.h:27
joypads_t
Definition: gb.h:460
WY_REG
__REG WY_REG
Definition: hardware.h:53
scroll_win
void scroll_win(INT8 x, INT8 y)
Definition: gb.h:906
get_tiles
void get_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *tiles, unsigned char *vram_addr) NONBANKED __preserves_regs(b
fill_bkg_rect
void fill_bkg_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b
set_bkg_tiles
void set_bkg_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *tiles) NONBANKED __preserves_regs(b
fill_win_rect
void fill_win_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b
wait_int_handler
void wait_int_handler(void) NONBANKED
disable_interrupts
void disable_interrupts(void) NONBANKED __preserves_regs(a
set_data
void set_data(unsigned char *vram_addr, unsigned char *data, UINT16 len) NONBANKED __preserves_regs(b
_shadow_OAM_base
__REG _shadow_OAM_base
Definition: gb.h:988
get_win_tiles
void get_win_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *tiles) NONBANKED __preserves_regs(b
set_win_1bit_data
void set_win_1bit_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
remove_LCD
void remove_LCD(int_handler h) NONBANKED
remove_JOY
void remove_JOY(int_handler h) NONBANKED
waitpadup
void waitpadup(void) NONBANKED __preserves_regs(a
set_interrupts
void set_interrupts(UINT8 flags) NONBANKED __preserves_regs(b
_io_out
volatile UINT8 _io_out
mode
void mode(UINT8 m) NONBANKED
joypads_t::joy3
UINT8 joy3
Definition: gb.h:464
add_TIM
void add_TIM(int_handler h) NONBANKED
get_data
void get_data(unsigned char *data, unsigned char *vram_addr, UINT16 len) NONBANKED __preserves_regs(b
move_sprite
void move_sprite(UINT8 nb, UINT8 x, UINT8 y)
Definition: gb.h:1095
__REG
#define __REG
Definition: hardware.h:12
nowait_int_handler
void nowait_int_handler(void) NONBANKED
add_SIO
void add_SIO(int_handler h) NONBANKED
l
UINT8 l
Definition: gb.h:432
waitpad
UINT8 waitpad(UINT8 mask) NONBANKED __preserves_regs(b
set_sprite_tile
void set_sprite_tile(UINT8 nb, UINT8 tile)
Definition: gb.h:1022
set_sprite_1bit_data
void set_sprite_1bit_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
set_bkg_data
void set_bkg_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
remove_SIO
void remove_SIO(int_handler h) NONBANKED
color
void color(UINT8 forecolor, UINT8 backcolor, UINT8 mode)
send_byte
void send_byte(void)
c
UINT8 c
Definition: gb.h:278
UBYTE
UINT8 UBYTE
Definition: types.h:45
set_win_data
void set_win_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
set_win_tiles
void set_win_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *tiles) NONBANKED __preserves_regs(b
enable_interrupts
void enable_interrupts(void) NONBANKED __preserves_regs(a
cgb.h
e
void e
Definition: gb.h:453
get_win_data
void get_win_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
set_tiles
void set_tiles(UINT8 x, UINT8 y, UINT8 w, UINT8 h, unsigned char *vram_addr, unsigned char *tiles) NONBANKED __preserves_regs(b
get_sprite_data
void get_sprite_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
SCX_REG
__REG SCX_REG
Definition: hardware.h:46
remove_VBL
void remove_VBL(int_handler h) NONBANKED
move_win
void move_win(UINT8 x, UINT8 y)
Definition: gb.h:892
SET_SHADOW_OAM_ADDRESS
void SET_SHADOW_OAM_ADDRESS(void *address)
Definition: gb.h:1002
sgb.h
get_sprite_tile
UINT8 get_sprite_tile(UINT8 nb)
Definition: gb.h:1033
int_handler
void(* int_handler)(void) NONBANKED
Definition: gb.h:120
_io_in
volatile UINT8 _io_in
OAM_item_t::prop
UINT8 prop
Definition: gb.h:978
joypads_t::npads
UINT8 npads
Definition: gb.h:461
set_bkg_1bit_data
void set_bkg_1bit_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data, UINT8 color) NONBANKED __preserves_regs(b
receive_byte
void receive_byte(void)
b
void b
Definition: gb.h:453
h
UINT8 h
Definition: gb.h:432
hardware.h
set_sprite_data
void set_sprite_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
d
void d
Definition: gb.h:453
_cpu
UINT8 _cpu
_io_status
volatile UINT8 _io_status
get_mode
UINT8 get_mode(void) NONBANKED __preserves_regs(b
vmemset
void vmemset(void *s, UINT8 c, size_t n) NONBANKED __preserves_regs(b
NONBANKED
#define NONBANKED
Definition: types.h:11
init_bkg
void init_bkg(UINT8 c) NONBANKED __preserves_regs(b
add_VBL
void add_VBL(int_handler h) NONBANKED
scroll_sprite
void scroll_sprite(UINT8 nb, INT8 x, INT8 y)
Definition: gb.h:1111
get_bkg_data
void get_bkg_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b
set_sprite_prop
void set_sprite_prop(UINT8 nb, UINT8 prop)
Definition: gb.h:1068
init_win
void init_win(UINT8 c) NONBANKED __preserves_regs(b
scroll_bkg
void scroll_bkg(INT8 x, INT8 y)
Definition: gb.h:774
add_JOY
void add_JOY(int_handler h) NONBANKED
UWORD
UINT16 UWORD
Definition: types.h:49
OAM_item_t::x
UINT8 x
Definition: gb.h:976
delay
void delay(UINT16 d) NONBANKED
hiramcpy
void hiramcpy(UINT8 dst, const void *src, UINT8 n) NONBANKED __preserves_regs(b
wait_vbl_done
void wait_vbl_done(void) NONBANKED __preserves_regs(b
joypad_ex
void joypad_ex(joypads_t *joypads)
WX_REG
__REG WX_REG
Definition: hardware.h:54
get_sprite_prop
UINT8 get_sprite_prop(UINT8 nb)
Definition: gb.h:1078
INT8
signed char INT8
Definition: types.h:18
OAM_item_t
Definition: gb.h:975
sys_time
volatile UINT16 sys_time
move_bkg
void move_bkg(UINT8 x, UINT8 y)
Definition: gb.h:760
joypad_init
UINT8 joypad_init(UINT8 npads, joypads_t *joypads)
add_LCD
void add_LCD(int_handler h) NONBANKED
SCY_REG
__REG SCY_REG
Definition: hardware.h:45