GBDK 2020 Docs
4.1.1
API Documentation for GBDK 2020
|
Go to the source code of this file.
Data Structures | |
struct | joypads_t |
Typedefs | |
typedef void(* | int_handler) (void) NONBANKED |
Variables | |
void | c |
void | d |
void | e |
void | iyh |
void | iyl |
void | h |
void | l |
volatile uint16_t | sys_time |
uint16_t | _current_2bpp_palette |
uint16_t | _current_1bpp_colors |
uint8_t | _map_tile_offset |
uint8_t | _submap_tile_offset |
volatile uint8_t | shadow_OAM [] |
volatile uint8_t | _shadow_OAM_base |
volatile uint8_t | _shadow_OAM_OFF |
SMS/GG specific functions.
#define SEGA |
#define VBK_REG VDP_ATTR_SHIFT |
#define J_UP 0b00000001 |
#define J_DOWN 0b00000010 |
#define J_LEFT 0b00000100 |
#define J_RIGHT 0b00001000 |
#define J_A 0b00010000 |
#define J_B 0b00100000 |
#define M_TEXT_OUT 0x02U |
Screen modes. Normally used by internal functions only.
#define M_TEXT_INOUT 0x03U |
#define M_NO_SCROLL 0x04U |
Set this in addition to the others to disable scrolling
If scrolling is disabled, the cursor returns to (0,0)
#define M_NO_INTERP 0x08U |
Set this to disable interpretation
#define S_FLIPX 0x02U |
If set the background tile will be flipped horizontally.
#define S_FLIPY 0x04U |
If set the background tile will be flipped vertically.
#define S_PALETTE 0x08U |
If set the background tile palette.
#define S_PRIORITY 0x10U |
If set the background tile priority.
#define S_PAL | ( | n | ) | 0 |
Dummy function used by other platforms. Required for the png2asset tool's metasprite output.
#define __WRITE_VDP_REG | ( | REG, | |
v | |||
) | shadow_##REG=(v);__critical{VDP_CMD=(shadow_##REG),VDP_CMD=REG;} |
#define __READ_VDP_REG | ( | REG | ) | shadow_##REG |
#define EMPTY_IFLAG 0x00U |
Disable calling of interrupt service routines
#define VBL_IFLAG 0x01U |
VBlank Interrupt occurs at the start of the vertical blank.
During this period the video ram may be freely accessed.
#define LCD_IFLAG 0x02U |
LCD Interrupt when triggered by the STAT register.
#define TIM_IFLAG 0x04U |
Does nothing on SMS/GG
#define SIO_IFLAG 0x08U |
Does nothing on SMS/GG
#define JOY_IFLAG 0x10U |
Does nothing on SMS/GG
#define SCREENWIDTH DEVICE_SCREEN_PX_WIDTH |
Width of the visible screen in pixels.
#define SCREENHEIGHT DEVICE_SCREEN_PX_HEIGHT |
Height of the visible screen in pixels.
#define MINWNDPOSX 0x00U |
The Minimum X position of the Window Layer (Left edge of screen)
#define MINWNDPOSY 0x00U |
The Minimum Y position of the Window Layer (Top edge of screen)
#define MAXWNDPOSX 0x00U |
The Maximum X position of the Window Layer (Right edge of screen)
#define MAXWNDPOSY 0x00U |
The Maximum Y position of the Window Layer (Bottom edge of screen)
#define DISPLAY_ON __WRITE_VDP_REG(VDP_R1, __READ_VDP_REG(VDP_R1) |= R1_DISP_ON) |
Turns the display back on.
#define DISPLAY_OFF display_off(); |
Turns the display off immediately.
#define HIDE_LEFT_COLUMN __WRITE_VDP_REG(VDP_R0, __READ_VDP_REG(VDP_R0) |= R0_LCB) |
Blanks leftmost column, so it is not garbaged when you use horizontal scroll
#define SHOW_LEFT_COLUMN __WRITE_VDP_REG(VDP_R0, __READ_VDP_REG(VDP_R0) &= (~R0_LCB)) |
Shows leftmost column
#define SHOW_BKG |
Turns on the background layer. Not yet implemented
#define HIDE_BKG |
Turns off the background layer. Not yet implemented
#define SHOW_WIN |
Turns on the window layer Not yet implemented
#define HIDE_WIN |
Turns off the window layer. Not yet implemented
#define SHOW_SPRITES |
Turns on the sprites layer. Not yet implemented
#define HIDE_SPRITES |
Turns off the sprites layer. Not yet implemented
#define SPRITES_8x16 __WRITE_VDP_REG(VDP_R1, __READ_VDP_REG(VDP_R1) |= R1_SPR_8X16) |
Sets sprite size to 8x16 pixels, two tiles one above the other.
#define SPRITES_8x8 __WRITE_VDP_REG(VDP_R1, __READ_VDP_REG(VDP_R1) &= (~R1_SPR_8X16)) |
Sets sprite size to 8x8 pixels, one tile.
#define DEVICE_SUPPORTS_COLOR (TRUE) |
Macro returns TRUE if device supports color (it always does on SMS/GG)
#define _current_bank MAP_FRAME1 |
Tracks current active ROM bank in frame 1
#define CURRENT_BANK MAP_FRAME1 |
#define BANK | ( | VARNAME | ) | ( (uint8_t) & __bank_ ## VARNAME ) |
Obtains the bank number of VARNAME
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().
#define BANKREF | ( | VARNAME | ) |
Creates a reference for retrieving the bank number of a variable or function
VARNAME | Variable name to use, which may be an existing identifier |
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.
#define BANKREF_EXTERN | ( | VARNAME | ) | extern const void __bank_ ## VARNAME; |
Makes switch the active ROM bank in frame 1
b | ROM bank to switch to |
#define SWITCH_ROM1 SWITCH_ROM |
Makes switch the active ROM bank in frame 2
b | ROM bank to switch to |
#define SWITCH_RAM | ( | b | ) | RAM_CONTROL=((b)&1)?RAM_CONTROL|RAMCTL_BANK:RAM_CONTROL&(~RAMCTL_BANK) |
Switches RAM bank
b | SRAM bank to switch to |
#define ENABLE_RAM RAM_CONTROL|=RAMCTL_RAM |
Enables RAM
#define DISABLE_RAM RAM_CONTROL&=(~RAMCTL_RAM) |
Disables RAM
#define set_bkg_palette_entry set_palette_entry |
#define set_sprite_palette_entry | ( | palette, | |
entry, | |||
rgb_data | |||
) | set_palette_entry(1,entry,rgb_data) |
#define set_bkg_palette set_palette |
#define set_sprite_palette | ( | first_palette, | |
nb_palettes, | |||
rgb_data | |||
) | set_palette(1,1,rgb_data) |
#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 |
Disable shadow OAM to VRAM copy on each VBlank
#define ENABLE_VBL_TRANSFER _shadow_OAM_base = (uint8_t)((uint16_t)&shadow_OAM >> 8) |
Enable shadow OAM to VRAM copy on each VBlank
#define MAX_HARDWARE_SPRITES 64 |
Amount of hardware sprites in OAM
#define HARDWARE_SPRITE_CAN_FLIP_X 0 |
True if sprite hardware can flip sprites by X
#define HARDWARE_SPRITE_CAN_FLIP_Y 0 |
True if sprite hardware can flip sprites by Y
#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 |
typedef void(* int_handler) (void) NONBANKED |
Interrupt handlers
void WRITE_VDP_CMD | ( | uint16_t | cmd | ) |
void WRITE_VDP_DATA | ( | uint16_t | data | ) |
void mode | ( | uint8_t | m | ) |
Set the current screen mode - one of M_* modes
Normally used by internal functions only.
uint8_t get_mode | ( | void | ) |
Returns the current mode
Returns the current mode
void set_interrupts | ( | uint8_t | flags | ) |
Clears any pending interrupts and sets the interrupt mask register IO to flags.
flags | A logical OR of *_IFLAGS |
void remove_VBL | ( | int_handler | h | ) |
Removes the VBL interrupt handler.
void remove_LCD | ( | int_handler | h | ) |
Removes the LCD interrupt handler.
void remove_TIM | ( | int_handler | h | ) |
void remove_SIO | ( | int_handler | h | ) |
void remove_JOY | ( | int_handler | h | ) |
void add_VBL | ( | int_handler | h | ) |
Adds a V-blank interrupt handler.
void add_LCD | ( | int_handler | h | ) |
Adds a LCD interrupt handler.
void add_TIM | ( | int_handler | h | ) |
Does nothing on SMS/GG
void add_SIO | ( | int_handler | h | ) |
Does nothing on SMS/GG
void add_JOY | ( | int_handler | h | ) |
Does nothing on SMS/GG
|
inline |
Cancel pending interrupts
void vsync | ( | void | ) |
HALTs the CPU and waits for the vertical blank interrupt.
This is often used in main loops to idle the CPU at low power until it's time to start the next frame. It's also useful for syncing animation with the screen re-draw.
Warning: If the VBL interrupt is disabled, this function will never return. If the screen is off this function returns immediately.
void wait_vbl_done | ( | void | ) |
Obsolete. This function has been replaced by vsync(), which has identical behavior.
|
inline |
Turns the display off.
void refresh_OAM | ( | void | ) |
Copies data from shadow OAM to OAM
void delay | ( | uint16_t | d | ) |
Delays the given number of milliseconds. Uses no timers or interrupts, and can be called with interrupts disabled
uint8_t joypad | ( | void | ) |
Reads and returns the current state of the joypad.
void waitpadup | ( | void | ) |
Waits for the directional pad and all buttons to be released.
Note: Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns.
Initializes joypads_t structure for polling multiple joypads
npads | number of joypads requested (1, 2 or 4) |
joypads | pointer to joypads_t structure to be initialized |
Only required for joypad_ex, not required for calls to regular joypad()
void joypad_ex | ( | joypads_t * | joypads | ) |
Polls all avaliable joypads
joypads | pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with joypad_init() |
void set_default_palette | ( | void | ) |
|
inline |
Obsolete. This function has been replaced by set_default_palette(), which has identical behavior.
|
inline |
Set CPU speed to fast (CGB Double Speed) operation.
On startup the CGB operates in Normal Speed Mode and can be switched into Double speed mode (faster processing but also higher power consumption). See the Pan Docs for more information about which hardware features operate faster and which remain at Normal Speed.
void set_palette | ( | uint8_t | first_palette, |
uint8_t | nb_palettes, | ||
palette_color_t * | rgb_data | ||
) |
|
inline |
Copies arbitrary data to an address in VRAM
dst | destination VRAM Address |
src | Pointer to source buffer |
size | Number of bytes to copy |
Copies size bytes from a buffer at _src__ to VRAM starting at dst.
|
inline |
|
inline |
|
inline |
void set_tile_submap | ( | uint8_t | x, |
uint8_t | y, | ||
uint8_t | w, | ||
uint8_t | h, | ||
uint8_t | map_w, | ||
const uint8_t * | map | ||
) |
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 | ||
) |
|
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.
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 |
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.
|
inline |
Sets a rectangular area of the Window Tile Map using a sub-region from a source tile map.
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 |
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.
|
inline |
|
inline |
|
inline |
|
inline |
Sets address of 256-byte aligned array of shadow OAM to be transferred on each VBlank
Sets sprite number nb__in the OAM to display tile number __tile.
nb | Sprite number, range 0 - 39 |
tile | Selects a tile (0 - 255) from memory at 8000h - 8FFFh In CGB Mode this could be either in VRAM Bank 0 or 1, depending on Bit 3 of the OAM Attribute Flag (see set_sprite_prop) |
In 8x16 mode:
Returns the tile number of sprite number nb in the OAM.
nb | Sprite number, range 0 - 39 |
Moves sprite number nb to the x, y position on the screen.
nb | Sprite number, range 0 - 39 |
x | X Position. Specifies the sprites horizontal position on the screen (minus 8). An offscreen value (X=0 or X>=168) hides the sprite, but the sprite still affects the priority ordering - a better way to hide a sprite is to set its Y-coordinate offscreen. |
y | Y Position. Specifies the sprites vertical position on the screen (minus 16). An offscreen value (for example, Y=0 or Y>=160) hides the sprite. |
Moving the sprite to 0,0 (or similar off-screen location) will hide it.
Moves sprite number nb relative to its current position.
nb | Sprite number, range 0 - 39 |
x | Number of pixels to move the sprite on the X axis Range: -128 - 127 |
y | Number of pixels to move the sprite on the Y axis Range: -128 - 127 |
|
inline |
Hides sprite number nb by moving it to zero position by Y.
nb | Sprite number, range 0 - 39 |
Set byte in vram at given memory location
addr | address to write to |
v | value |
Set single tile t with attributes on background layer at x,y
x | X-coordinate |
y | Y-coordinate |
t | tile index |
Set single tile t on background layer at x,y
x | X-coordinate |
y | Y-coordinate |
t | tile index |
void c |
void d |
void e |
void iyh |
uint8_t iyl |
uint8_t h |
void l |
|
extern |
Global Time Counter in VBL periods (60Hz)
Increments once per Frame
Will wrap around every ~18 minutes (unsigned 16 bits = 65535 / 60 / 60 = 18.2)
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
Shadow OAM array in WRAM, that is transferred into the real OAM each VBlank
|
extern |
MSB of shadow_OAM address is used by OAM copying routine
MSB of shadow_OAM address is used by OAM DMA copying routine
|
extern |
Flag for disabling of OAM copying routine
Values:
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.
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).