Add pack/unpack for data masks (#2163)

This commit is contained in:
GriffinR
2025-07-23 04:28:34 -04:00
committed by GitHub
parent 20012cba6e
commit 6f8a1bbdb8
12 changed files with 98 additions and 64 deletions

View File

@@ -7,19 +7,36 @@
#define MAPGRID_METATILE_ID_MASK 0x03FF // Bits 0-9
#define MAPGRID_COLLISION_MASK 0x0C00 // Bits 10-11
#define MAPGRID_ELEVATION_MASK 0xF000 // Bits 12-15
#define MAPGRID_METATILE_ID_SHIFT 0
#define MAPGRID_COLLISION_SHIFT 10
#define MAPGRID_ELEVATION_SHIFT 12
#define PACK_METATILE(metatileId) PACK(metatileId, MAPGRID_METATILE_ID_SHIFT, MAPGRID_METATILE_ID_MASK)
#define PACK_COLLISION(collision) PACK(collision, MAPGRID_COLLISION_SHIFT, MAPGRID_COLLISION_MASK)
#define PACK_ELEVATION(elevation) PACK(elevation, MAPGRID_ELEVATION_SHIFT, MAPGRID_ELEVATION_MASK)
#define UNPACK_METATILE(data) UNPACK(data, MAPGRID_METATILE_ID_SHIFT, MAPGRID_METATILE_ID_MASK)
#define UNPACK_COLLISION(data) UNPACK(data, MAPGRID_COLLISION_SHIFT, MAPGRID_COLLISION_MASK)
#define UNPACK_ELEVATION(data) UNPACK(data, MAPGRID_ELEVATION_SHIFT, MAPGRID_ELEVATION_MASK)
// An undefined map grid block has all metatile id bits set and nothing else
#define MAPGRID_UNDEFINED MAPGRID_METATILE_ID_MASK
// When setting impassability manually GF sets all the collision bits
#define MAPGRID_IMPASSABLE MAPGRID_COLLISION_MASK
// Masks/shifts for metatile attributes
// Metatile attributes consist of an 8 bit behavior value, 4 unused bits, and a 4 bit layer type value
// This is the data stored in each data/tilesets/*/*/metatile_attributes.bin file
#define METATILE_ATTR_BEHAVIOR_MASK 0x00FF // Bits 0-7
#define METATILE_ATTR_LAYER_MASK 0xF000 // Bits 12-15
#define METATILE_ATTR_BEHAVIOR_SHIFT 0
#define METATILE_ATTR_LAYER_SHIFT 12
#define PACK_BEHAVIOR(behavior) PACK(behavior, METATILE_ATTR_BEHAVIOR_SHIFT, METATILE_ATTR_BEHAVIOR_MASK)
#define PACK_LAYER_TYPE(layerType) PACK(layerType, METATILE_ATTR_LAYER_SHIFT, METATILE_ATTR_LAYER_MASK)
#define UNPACK_BEHAVIOR(data) UNPACK(data, METATILE_ATTR_BEHAVIOR_SHIFT, METATILE_ATTR_BEHAVIOR_MASK)
#define UNPACK_LAYER_TYPE(data) UNPACK(data, METATILE_ATTR_LAYER_SHIFT, METATILE_ATTR_LAYER_MASK)
enum {
METATILE_LAYER_TYPE_NORMAL, // Metatile uses middle and top bg layers
METATILE_LAYER_TYPE_COVERED, // Metatile uses bottom and middle bg layers

View File

@@ -119,6 +119,9 @@
#define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
#define T2_READ_PTR(ptr) (void *) T2_READ_32(ptr)
#define PACK(data, shift, mask) ( ((data) << (shift)) & (mask) )
#define UNPACK(data, shift, mask) ( ((data) & (mask)) >> (shift) )
// Macros for checking the joypad
#define TEST_BUTTON(field, button) ((field) & (button))
#define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button)