|
|
@ -11,10 +11,13 @@ |
|
|
|
|
|
|
|
map_t MAP; |
|
|
|
|
|
|
|
uint8_t pending_row[SCRN_VX_B]; |
|
|
|
#define ROW_BUFFER_SIZE (SCRN_X_B + 4) |
|
|
|
#define COL_BUFFER_SIZE (SCRN_Y_B + 4) |
|
|
|
|
|
|
|
uint8_t pending_row[ROW_BUFFER_SIZE]; |
|
|
|
uint16_t pending_row_dest; |
|
|
|
|
|
|
|
uint8_t pending_col[SCRN_VY_B]; |
|
|
|
uint8_t pending_col[COL_BUFFER_SIZE]; |
|
|
|
uint16_t pending_col_dest; |
|
|
|
|
|
|
|
static void map_write_row(uint16_t map_ptr, int8_t x0, int8_t y0); |
|
|
@ -30,10 +33,10 @@ void map_load(map_t *map) { |
|
|
|
// TODO: Update player state |
|
|
|
|
|
|
|
memcpy(VRAM_TILE_PTR(TILE_INDEX_BACKGROUND), (uint8_t *)MAP.tile_ptr, |
|
|
|
MAP.tile_count); |
|
|
|
MAP.tile_size); |
|
|
|
|
|
|
|
int8_t x0 = MAP.camera_x - INIT_SCX; |
|
|
|
int8_t y0 = MAP.camera_y - INIT_SCY; |
|
|
|
int8_t x0 = MAP.camera_x - INIT_SCX / 8; |
|
|
|
int8_t y0 = MAP.camera_y - INIT_SCY / 8; |
|
|
|
uint16_t map_ptr = _SCRN0; |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < SCRN_VY_B; ++i) { |
|
|
@ -41,11 +44,14 @@ void map_load(map_t *map) { |
|
|
|
map_ptr += SCRN_VX_B; |
|
|
|
y0++; |
|
|
|
} |
|
|
|
|
|
|
|
pending_row_dest = 0; |
|
|
|
pending_col_dest = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void map_update(void) { |
|
|
|
if (pending_row_dest != 0) { |
|
|
|
vram_enqueue_mem_xfer((uint8_t *)pending_row_dest, &pending_row[0], |
|
|
|
vram_enqueue_mem_xfer(XFER_TYPE_ROW, pending_row_dest, &pending_row[0], |
|
|
|
sizeof pending_row); |
|
|
|
pending_row_dest = 0; |
|
|
|
} |
|
|
@ -61,8 +67,8 @@ void map_update(void) { |
|
|
|
static void map_enqueue_row(uint16_t vram_ptr, int8_t x0, int8_t y0) { |
|
|
|
pending_row_dest = vram_ptr; |
|
|
|
|
|
|
|
if (y0 < 0 || y0 > MAP.map_height) { |
|
|
|
memset(&pending_row[0], 0, sizeof pending_row); |
|
|
|
if (y0 < 0 || y0 >= MAP.map_height) { |
|
|
|
memset(&pending_row[0], TILE_INDEX_BACKGROUND, sizeof pending_row); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -72,11 +78,13 @@ static void map_enqueue_row(uint16_t vram_ptr, int8_t x0, int8_t y0) { |
|
|
|
|
|
|
|
while (left > 0 && x0 < 0) { |
|
|
|
*row++ = TILE_INDEX_BACKGROUND; |
|
|
|
x0++; |
|
|
|
left--; |
|
|
|
} |
|
|
|
|
|
|
|
while (left > 0 && x0 < MAP.map_height) { |
|
|
|
*row++ = *map_ptr++; |
|
|
|
*row++ = TILE_INDEX_BACKGROUND + *map_ptr++; |
|
|
|
x0++; |
|
|
|
left--; |
|
|
|
} |
|
|
|
|
|
|
@ -87,9 +95,32 @@ static void map_enqueue_row(uint16_t vram_ptr, int8_t x0, int8_t y0) { |
|
|
|
} |
|
|
|
|
|
|
|
static void map_write_row(uint16_t vram_ptr, int8_t x0, int8_t y0) { |
|
|
|
map_enqueue_row(vram_ptr, x0, y0); |
|
|
|
memcpy((uint8_t *)pending_row_dest, &pending_row[0], sizeof pending_row); |
|
|
|
pending_row_dest = 0; |
|
|
|
uint8_t *row = (uint8_t *)vram_ptr; |
|
|
|
|
|
|
|
if (y0 < 0 || y0 >= MAP.map_height) { |
|
|
|
memset(row, TILE_INDEX_BACKGROUND, SCRN_VX_B); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t *map_ptr = (uint8_t *)(MAP.map_ptr + y0 * MAP.map_width); |
|
|
|
uint8_t left = SCRN_VX_B; |
|
|
|
|
|
|
|
while (left > 0 && x0 < 0) { |
|
|
|
*row++ = TILE_INDEX_BACKGROUND; |
|
|
|
x0++; |
|
|
|
left--; |
|
|
|
} |
|
|
|
|
|
|
|
while (left > 0 && x0 < MAP.map_height) { |
|
|
|
*row++ = TILE_INDEX_BACKGROUND + *map_ptr++; |
|
|
|
x0++; |
|
|
|
left--; |
|
|
|
} |
|
|
|
|
|
|
|
while (left > 0) { |
|
|
|
*row++ = TILE_INDEX_BACKGROUND; |
|
|
|
left--; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void map_write_col(uint16_t map_ptr, int8_t x0, int8_t y0) {} |