From 4e51d019fd0c1d21aa8e965fd68dbacec39a2576 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 26 Apr 2021 12:14:45 +0200 Subject: Test screenblock entry demo --- src/common.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/common.h') diff --git a/src/common.h b/src/common.h index 35b4619..6047e5f 100644 --- a/src/common.h +++ b/src/common.h @@ -76,6 +76,20 @@ #define BG_V_SCROLL_2 *((vu16*)(0x04000012 + 0x0004 * 2)) #define BG_V_SCROLL_3 *((vu16*)(0x04000012 + 0x0004 * 3)) +// Screenblocks for BGs. +typedef u16 ScreenBlock[1024]; +#define SCREENBLOCK_MEM ((ScreenBlock*)MEM_VRAM) + +// Screenblock entry bits. +#define SCREENBLOCK_ENTRY_H_FLIP (1 << 0xA) +#define SCREENBLOCK_ENTRY_V_FLIP (1 << 0xB) +#define SCREENBLOCK_ENTRY_PAL(N) ((N) << 0xC) + +size_t se_index(size_t tile_x, size_t tile_y, size_t map_width) { + size_t sbb = ((tile_x >> 5) + (tile_y >> 5) * (map_width >> 5)); + return sbb * 1024 + ((tile_x & 31) + (tile_y & 31) * 32); +} + // Screen settings. #define SCREEN_WIDTH 240 #define SCREEN_HEIGHT 160 @@ -84,6 +98,9 @@ // (RGB) have a 0--31 range. For example, pure red would be rgb15(31, 0, 0). typedef u16 Color; +// A palette is composed of 16 colors, with color at index 0 being transparent. +typedef Color Palette[16]; + // // Tile memory access. // @@ -96,9 +113,6 @@ typedef struct Tile { typedef Tile TileBlock[512]; #define TILE_MEM ((TileBlock*) MEM_VRAM) -typedef u16 ScreenBlock[1024]; -#define SCREENBLOCK_MEM ((ScreenBlock*)MEM_VRAM) - // We can treat the screen as a HxW matrix. With the following macro we can // write a pixel to the screen at the (x, y) position using: // @@ -109,6 +123,8 @@ typedef Color Scanline[SCREEN_WIDTH]; #define SCREEN_BUFFER ((u16*) MEM_VRAM) #define PAL_BUFFER_BG ((u16*) MEM_PAL) #define PAL_BUFFER_SPRITES ((u16*) 0x05000200) +#define PAL_BANK_BG ((Palette*) MEM_PAL) +#define PAL_BANK_SPRITES ((Palette*) 0x05000200) // // Colors. @@ -277,5 +293,4 @@ key_hold(u32 key) { // Check if the given key/button is currently pressed. #define KEY_PRESSED(key) (~(KEY_INPUTS) & key) - #endif // GBAEXP_COMMON_H -- cgit v1.2.1