GBDK 2020 Docs
4.1.1
API Documentation for GBDK 2020
|
#include <types.h>
#include <stdint.h>
#include <gbdk/version.h>
#include <nes/hardware.h>
#include <nes/rgb_to_nes_macro.h>
Go to the source code of this file.
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 |
#define | S_PRIORITY 0x20U |
#define | S_PAL(n) n |
#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 | CURRENT_BANK _current_bank |
#define | BANK(VARNAME) 0 |
#define | BANKREF(VARNAME) |
#define | BANKREF_EXTERN(VARNAME) extern const void __bank_ ## VARNAME; |
#define | SWITCH_ROM_DUMMY(b) |
#define | SWITCH_ROM SWITCH_ROM_DUMMY |
#define | DISPLAY_ON display_on(); |
#define | DISPLAY_OFF display_off(); |
#define | HIDE_LEFT_COLUMN shadow_PPUMASK &= ~(PPUMASK_SHOW_BG_LC | PPUMASK_SHOW_SPR_LC); \ |
#define | SHOW_LEFT_COLUMN shadow_PPUMASK |= (PPUMASK_SHOW_BG_LC | PPUMASK_SHOW_SPR_LC); |
#define | SHOW_BKG shadow_PPUMASK |= PPUMASK_SHOW_BG; |
#define | HIDE_BKG shadow_PPUMASK &= ~PPUMASK_SHOW_BG; |
#define | SHOW_SPRITES shadow_PPUMASK |= PPUMASK_SHOW_SPR; |
#define | HIDE_SPRITES shadow_PPUMASK &= ~PPUMASK_SHOW_SPR; |
#define | SPRITES_8x16 shadow_PPUCTRL |= PPUCTRL_SPR_8X16; |
#define | SPRITES_8x8 shadow_PPUCTRL &= ~PPUCTRL_SPR_8X16; |
#define | COMPAT_PALETTE(C0, C1, C2, C3) ((uint8_t)(((C3) << 6) | ((C2) << 4) | ((C1) << 2) | (C0))) |
#define | set_bkg_2bpp_data set_bkg_data |
#define | set_tile_map set_bkg_tiles |
#define | set_tile_submap set_bkg_submap |
#define | set_tile_xy set_bkg_tile_xy |
#define | set_sprite_2bpp_data set_sprite_data |
#define | DISABLE_OAM_DMA _shadow_OAM_base = 0 |
#define | DISABLE_VBL_TRANSFER DISABLE_OAM_DMA |
#define | ENABLE_OAM_DMA _shadow_OAM_base = (uint8_t)((uint16_t)&shadow_OAM >> 8) |
#define | ENABLE_VBL_TRANSFER ENABLE_OAM_DMA |
#define | MAX_HARDWARE_SPRITES 64 |
#define | HARDWARE_SPRITE_CAN_FLIP_X 1 |
#define | HARDWARE_SPRITE_CAN_FLIP_Y 1 |
#define | fill_rect fill_bkg_rect |
Typedefs | |
typedef uint8_t | palette_color_t |
typedef struct OAM_item_t | OAM_item_t |
Variables | |
volatile uint16_t | sys_time |
volatile uint8_t | _current_bank |
uint16_t | _current_1bpp_colors |
uint8_t | _map_tile_offset |
uint8_t | _submap_tile_offset |
volatile struct OAM_item_t | shadow_OAM [] |
uint8_t | _shadow_OAM_base |
NES specific functions.
#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 |
Common colors based on the EGA default palette.
Manually entered from https://www.nesdev.org/wiki/PPU_palettes#RGBI
#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 |
Screen modes. Normally used by internal functions only.
#define M_TEXT_OUT 0x02U |
#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_PALETTE 0x10U |
If this is set, sprite colours come from OBJ1PAL. Else they come from OBJ0PAL
#define S_FLIPX 0x40U |
If set the sprite will be flipped horizontally.
#define S_FLIPY 0x80U |
If set the sprite will be flipped vertically.
#define S_PRIORITY 0x20U |
If this bit is clear, then the sprite will be displayed on top of the background and window.
#define S_PAL | ( | n | ) | n |
Defines how palette number is encoded in OAM. Required for the png2asset tool's metasprite output.
#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))) |
Macro to create a DMG palette from 4 colors
C0 | Color for Index 0 |
C1 | Color for Index 1 |
C2 | Color for Index 2 |
C3 | Color for Index 3 |
The resulting format is four greyscale colors packed into a single unsigned byte.
Example:
#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 CURRENT_BANK _current_bank |
#define BANK | ( | VARNAME | ) | 0 |
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; |
#define SWITCH_ROM_DUMMY | ( | b | ) |
Dummy macro for no-bank-switching WIP prototype
b | ROM bank to switch to |
#define SWITCH_ROM SWITCH_ROM_DUMMY |
Makes default mapper switch the active ROM bank
b | ROM bank to switch to (max 255) |
#define DISPLAY_ON display_on(); |
Turns the display back on.
#define DISPLAY_OFF display_off(); |
Turns the display off immediately.
#define HIDE_LEFT_COLUMN shadow_PPUMASK &= ~(PPUMASK_SHOW_BG_LC | PPUMASK_SHOW_SPR_LC); \ |
Blanks leftmost column, so it is not garbaged when you use horizontal scroll
#define SHOW_LEFT_COLUMN shadow_PPUMASK |= (PPUMASK_SHOW_BG_LC | PPUMASK_SHOW_SPR_LC); |
Shows leftmost column
#define SHOW_BKG shadow_PPUMASK |= PPUMASK_SHOW_BG; |
Turns on the background layer. Sets bit 0 of the LCDC register to 1.
#define HIDE_BKG shadow_PPUMASK &= ~PPUMASK_SHOW_BG; |
Turns off the background layer. Sets bit 0 of the LCDC register to 0.
#define SHOW_SPRITES shadow_PPUMASK |= PPUMASK_SHOW_SPR; |
Turns on the sprites layer. Sets bit 1 of the LCDC register to 1.
#define HIDE_SPRITES shadow_PPUMASK &= ~PPUMASK_SHOW_SPR; |
Turns off the sprites layer. Clears bit 1 of the LCDC register to 0.
#define SPRITES_8x16 shadow_PPUCTRL |= PPUCTRL_SPR_8X16; |
Sets sprite size to 8x16 pixels, two tiles one above the other. Sets bit 2 of the LCDC register to 1.
#define SPRITES_8x8 shadow_PPUCTRL &= ~PPUCTRL_SPR_8X16; |
Sets sprite size to 8x8 pixels, one tile. Clears bit 2 of the LCDC register to 0.
#define COMPAT_PALETTE | ( | C0, | |
C1, | |||
C2, | |||
C3 | |||
) | ((uint8_t)(((C3) << 6) | ((C2) << 4) | ((C1) << 2) | (C0))) |
#define set_bkg_2bpp_data set_bkg_data |
#define set_tile_map set_bkg_tiles |
#define set_tile_submap set_bkg_submap |
#define set_tile_xy set_bkg_tile_xy |
#define set_sprite_2bpp_data set_sprite_data |
#define DISABLE_OAM_DMA _shadow_OAM_base = 0 |
#define DISABLE_VBL_TRANSFER DISABLE_OAM_DMA |
Disable OAM DMA copy each VBlank
#define ENABLE_OAM_DMA _shadow_OAM_base = (uint8_t)((uint16_t)&shadow_OAM >> 8) |
#define ENABLE_VBL_TRANSFER ENABLE_OAM_DMA |
Enable OAM DMA copy each VBlank and set it to transfer default shadow_OAM array
#define MAX_HARDWARE_SPRITES 64 |
Amount of hardware sprites in OAM
#define HARDWARE_SPRITE_CAN_FLIP_X 1 |
True if sprite hardware can flip sprites by X
#define HARDWARE_SPRITE_CAN_FLIP_Y 1 |
True if sprite hardware can flip sprites by Y
#define fill_rect fill_bkg_rect |
typedef uint8_t palette_color_t |
typedef struct OAM_item_t OAM_item_t |
Sprite Attributes structure
x | X Coordinate of the sprite on screen |
y | Y Coordinate of the sprite on screen - 1 |
tile | Sprite tile number (see set_sprite_tile) |
prop | OAM Property Flags (see set_sprite_prop) |
void set_bkg_palette | ( | uint8_t | first_palette, |
uint8_t | nb_palettes, | ||
palette_color_t * | rgb_data | ||
) |
void set_sprite_palette | ( | uint8_t | first_palette, |
uint8_t | nb_palettes, | ||
palette_color_t * | rgb_data | ||
) |
void set_bkg_palette_entry | ( | uint8_t | palette, |
uint8_t | entry, | ||
palette_color_t | rgb_data | ||
) |
void set_sprite_palette_entry | ( | uint8_t | palette, |
uint8_t | entry, | ||
palette_color_t | rgb_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
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. 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.
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.
Reads and returns the current state of the joypad.
Waits until at least one of the buttons given in mask are pressed.
Normally only used for checking one key, but it will support many, even J_LEFT at the same time as J_RIGHT. :)
Waits until at least one of the buttons given in mask are pressed.
mask | Bitmask indicating which buttons to wait for |
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.
Waits until at least one of the buttons given in mask are pressed.
void waitpadup | ( | void | ) |
Waits for the directional pad and all buttons to be released.
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
Polls all avaliable joypads (for the GB and ones connected via SGB)
joypads | pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with joypad_init() |
Polls all avaliable joypads
joypads | pointer to joypads_t structure to be filled with joypad statuses, must be previously initialized with joypad_init() |
|
inline |
Enables unmasked interrupts
|
inline |
Disables interrupts
This function may be called as many times as you like; however the first call to enable_interrupts will re-enable them.
void vsync | ( | void | ) |
Waits for the vertical blank interrupt.
This is often used in main loops to idle the CPU 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.
HALTs the CPU and waits for the vertical blank interrupt and then returns when all registered VBL ISRs have completed.
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.
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.
Waits until the VBL interrupt before turning the display off.
Turns the display off.
void refresh_OAM | ( | void | ) |
Copies data from shadow OAM to OAM
Set byte in vram at given memory location
addr | address to write to |
v | value |
|
inline |
Sets palette for 2bpp color translation for GG/SMS, does nothing on GB
Sets VRAM Tile Pattern data for the Background
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.
Sets VRAM Tile Pattern data for the Background / Window
first_tile | Index of the first tile to write |
nb_tiles | Number of tiles to write |
data | Pointer to (2 bpp) source tile data |
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.
Sets VRAM Tile Pattern data for the Background using 1bpp source data
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:
Sets VRAM Tile Pattern data for the Background / Window using 1bpp source data
first_tile | Index of the first Tile to write |
nb_tiles | Number of Tiles to write |
data | Pointer to (1bpp) source Tile Pattern data |
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.
Sets a rectangular region of Background Tile Map.
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:
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.
Sets a rectangular region of Background Tile Map.
x | X Start position in Background Map tile coordinates. Range 0 - 31 |
y | Y Start position in Background Map tile coordinates. Range 0 - 31 |
w | Width of area to set in tiles. Range 1 - 32 |
h | Height of area to set in tiles. Range 1 - 32 |
tiles | Pointer to source tile map data |
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:
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.
Note: Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table.
GBC only: VBK_REG determines whether Tile Numbers or Tile Attributes get set.
GBC Tile Attributes are defined as:
void set_bkg_attributes_nes16x16 | ( | uint8_t | x, |
uint8_t | y, | ||
uint8_t | w, | ||
uint8_t | h, | ||
const uint8_t * | attributes | ||
) |
Sets a rectangular region of Background Tile Map Attributes.
x | X Start position in Background Map tile coordinates. Range 0 - 15 |
y | Y Start position in Background Map tile coordinates. Range 0 - 14 |
w | Width of area to set in tiles. Range 1 - 16 |
h | Height of area to set in tiles. Range 1 - 15 |
attributes | Pointer to source tile map attribute data |
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.
NES 16x16 Tile Attributes are tightly packed into 4 attributes per byte, with each 16x16 area of a 32x32 pixel block using the bits as follows: D1-D0: Top-left 16x16 pixels D3-D2: Top-right 16x16 pixels D5-D4: Bottom-left 16x16 pixels D7-D6: Bottom-right 16x16 pixels
|
inline |
Sets a rectangular region of Background Tile Map Attributes.
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_attributes() instead when:
One byte per source tile map attribute entry.
Writes that exceed coordinate 31 on the x or y axis will wrap around to the Left and Top edges.
Please note that this is just a wrapper function for set_bkg_attributes_nes16x16 and divides the coordinates and dimensions by 2 to achieve this. It is intended to make code more portable by using the same coordinate system that systems with the much more common 8x8 attribute resolution would use.
void set_bkg_submap_attributes_nes16x16 | ( | uint8_t | x, |
uint8_t | y, | ||
uint8_t | w, | ||
uint8_t | h, | ||
const uint8_t * | map, | ||
uint8_t | map_w | ||
) |
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 30 tiles / 16x15 attributes.
x | X Start position in both the Source Attribute Map and hardware Background Map attribute coordinates. Range 0 - 255 |
y | Y Start position in both the Source Attribute Map and hardware Background Map attribute coordinates. Range 0 - 255 |
w | Width of area to set in Attributes. Range 1 - 127 |
h | Height of area to set in Attributes. Range 1 - 127 |
map | Pointer to source tile map data |
map_w | Width of source tile map in tiles. Range 1 - 127 |
Entries are copied from map to the Background Attribute Map starting at x, y writing across for w tiles and down for h attributes, using map_w as the rowstride for the source attribute map.
The x and y parameters are in Source Attribute Map Attribute 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-15 (they are bit-masked: x & 0xF
and y & 0xF
). 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 Attribute 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 attribute map entry.
Writes that exceed coordinate 15/14 on the x / 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 Background Tile Map attributes using a sub-region from a source tile map. Useful for scrolling implementations of maps larger than 32 x 30 tiles.
Please note that this is just a wrapper function for set_bkg_submap_attributes_nes16x16 and divides the coordinates and dimensions by 2 to achieve this. It is intended to make code more portable by using the same coordinate system that systems with the much more common 8x8 attribute resolution would use.
|
inline |
Sets a rectangular region of Background Tile Map. The offset value in base_tile is added to the tile ID for each map entry.
x | X Start position in Background Map tile coordinates. Range 0 - 31 |
y | Y Start position in Background Map tile coordinates. Range 0 - 31 |
w | Width of area to set in tiles. Range 1 - 32 |
h | Height of area to set in tiles. Range 1 - 32 |
tiles | Pointer to source tile map data |
base_tile | Offset each tile ID entry of the source map by this value. Range 1 - 255 |
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).
|
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.
@ param x X Start position in Background Map tile coordinates. Range 0 - 31 @ param y Y Start position in Background Map tile coordinates. Range 0 - 31 @ param w Width of area to set in tiles. Range 1 - 255 @ param h Height of area to set in tiles. Range 1 - 255 @ param map Pointer to source tile map data @ param 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.
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.
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 Background Tile Map using a sub-region from a source tile map. The offset value in base_tile is added to the tile ID for each map entry.
x | X Start position in Background Map tile coordinates. Range 0 - 31 |
y | Y Start position in Background Map tile coordinates. Range 0 - 31 |
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).
Copies a rectangular region of Background Tile Map entries into a buffer.
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.
Copies a rectangular region of Background Tile Map entries into a buffer.
x | X Start position in Background Map tile coordinates. Range 0 - 31 |
y | Y Start position in Background Map tile coordinates. Range 0 - 31 |
w | Width of area to copy in tiles. Range 0 - 31 |
h | Height of area to copy in tiles. Range 0 - 31 |
tiles | Pointer to destination buffer for Tile Map data |
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.
Set single tile t on background layer at x,y
x | X-coordinate |
y | Y-coordinate |
t | tile index |
Get single tile t on background layer at x,y
x | X-coordinate |
y | Y-coordinate |
Moves the Background Layer to the position specified in x and y in pixels.
x | X axis screen coordinate for Left edge of the Background |
y | Y axis screen coordinate for Top edge of the Background |
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.
Moves the Background relative to it's current position.
x | Number of pixels to move the Background on the X axis Range: -128 - 127 |
y | Number of pixels to move the Background on the Y axis Range: -128 - 127 |
Sets VRAM Tile Pattern data for Sprites
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.
Sets VRAM Tile Pattern data for Sprites
first_tile | Index of the first tile to write |
nb_tiles | Number of tiles to write |
data | Pointer to (2 bpp) source Tile Pattern data |
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.
Sets VRAM Tile Pattern data for Sprites using 1bpp source data
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:
Sets VRAM Tile Pattern data for Sprites using 1bpp source data
first_tile | Index of the first tile to write |
nb_tiles | Number of tiles to write |
data | Pointer to (1bpp) source Tile Pattern data |
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.
|
inline |
Enable OAM DMA copy each VBlank and set it to transfer any 256-byte aligned array
Sets sprite number nb__in the OAM to display tile number __tile.
nb | Sprite number, range 0 - 63 |
tile | Selects a tile (0 - 255) from PPU memory at 0000h - 0FFFh / 1000h - 1FFFh |
In 8x16 mode:
Returns the tile number of sprite number nb in the OAM.
nb | Sprite number, range 0 - 63 |
Sets the OAM Property Flags of sprite number nb to those defined in prop.
nb | Sprite number, range 0 - 39 |
prop | Property setting (see bitfield description) |
The bits in prop represent:
Returns the OAM Property Flags of sprite number nb.
nb | Sprite number, range 0 - 39 |
Moves sprite number nb to the x, y position on the screen.
nb | Sprite number, range 0 - 63 |
x | X Position. Specifies the sprites horizontal position on the screen (minus 8). |
y | Y Position. Specifies the sprites vertical position on the screen (minus 16). An offscreen value (Y>=240) 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 - 63 |
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 Y position 240.
nb | Sprite number, range 0 - 63 |
Copies arbitrary data to an address in VRAM without taking into account the state of LCDC bits 3 or 4.
Copies len bytes from a buffer at data to VRAM starting at vram_addr.
void set_tiles | ( | uint8_t | x, |
uint8_t | y, | ||
uint8_t | w, | ||
uint8_t | h, | ||
uint8_t * | vram_addr, | ||
const uint8_t * | tiles | ||
) |
Sets a rectangular region of Tile Map entries at a given VRAM Address.
x | X Start position in Map tile coordinates. Range 0 - 31 |
y | Y Start position in Map tile coordinates. Range 0 - 31 |
w | Width of area to set in tiles. Range 1 - 32 |
h | Height of area to set in tiles. Range 1 - 32 |
vram_addr | Pointer to destination VRAM Address |
tiles | Pointer to source Tile Map data |
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.
Sets VRAM Tile Pattern data starting from given base address without taking into account the state of PPUMASK.
Sets VRAM Tile Pattern data starting from given base address without taking into account the state of LCDC bit 4.
first_tile | Index of the first tile to write |
nb_tiles | Number of tiles to write |
data | Pointer to (2 bpp) source Tile Pattern data. |
base | MSB of the destination address in VRAM (usually 0x80 or 0x90 which gives 0x8000 or 0x9000) |
Sets VRAM Tile Pattern data in the native format
first_tile | Index of the first tile to write (0 - 511) |
nb_tiles | Number of tiles to write |
data | Pointer to source Tile Pattern data. |
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:
void init_bkg | ( | uint8_t | c | ) |
Initializes the entire Background Tile Map with Tile Number c
c | Tile number to fill with |
Note: This function avoids writes during modes 2 & 3
Fills the VRAM memory region s of size n with Tile Number c
s | Start address in VRAM |
c | Tile number to fill with |
n | Size of memory region (in bytes) to fill |
Note: This function avoids writes during modes 2 & 3
Fills a rectangular region of Tile Map entries for the Background layer with tile.
x | X Start position in Background Map tile coordinates. Range 0 - 31 |
y | Y Start position in Background Map tile coordinates. Range 0 - 31 |
w | Width of area to set in tiles. Range 0 - 31 |
h | Height of area to set in tiles. Range 0 - 31 |
tile | Fill value |
|
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 |
Tracks current active ROM bank
The active bank number is not tracked by _current_bank when SWITCH_ROM_MBC5_8M is used.
This variable is updated automatically when you call SWITCH_ROM_MBC1 or SWITCH_ROM_MBC5, SWITCH_ROM(), or call a BANKED function.
|
extern |
|
extern |
|
extern |
|
extern |
Shadow OAM array in WRAM, that is DMA-transferred into the real OAM each VBlank
|
extern |
MSB of shadow_OAM address is used by OAM DMA copying routine