main: primitive map scrolling
This commit is contained in:
parent
8682decd56
commit
d8fb314a79
47
main.cpp
47
main.cpp
@ -79,21 +79,17 @@ uint32_t cell_data(const start_size_t& buf, const uint32_t top)
|
||||
|
||||
constexpr inline void render_block(const uint32_t base_pattern,
|
||||
const tileset_t& tileset,
|
||||
const uint32_t map_x,
|
||||
const uint32_t map_y,
|
||||
const int32_t map_x,
|
||||
const int32_t map_y,
|
||||
const uint8_t block)
|
||||
{
|
||||
for (uint32_t block_y = 0; block_y < 4; block_y++) {
|
||||
for (uint32_t block_x = 0; block_x < 4; block_x++) {
|
||||
const uint32_t block_ix = 4 * block_y + block_x;
|
||||
const uint8_t tile_xy = tileset.blockset.start[block * 4 * 4 + block_ix];
|
||||
for (int32_t block_y = 0; block_y < 4; block_y++) {
|
||||
for (int32_t block_x = 0; block_x < 4; block_x++) {
|
||||
const int32_t block_ix = 4 * block_y + block_x;
|
||||
const uint8_t tile_ix = tileset.blockset.start[block * 4 * 4 + block_ix];
|
||||
|
||||
const uint8_t tile_x = (tile_xy >> 0) & 0xf;
|
||||
const uint8_t tile_y = (tile_xy >> 4) & 0xf;
|
||||
const uint32_t tile_ix = tile_y * 16 + tile_x;
|
||||
|
||||
const uint32_t cell_y = map_y * 4 + block_y;
|
||||
const uint32_t cell_x = map_x * 4 + block_x;
|
||||
const int32_t cell_y = map_y * 4 + block_y;
|
||||
const int32_t cell_x = map_x * 4 + block_x;
|
||||
// assumes NBG0 map plane_a is at offset 0
|
||||
vdp2.vram.u16[64 * (cell_y % 64) + (cell_x % 64)] = (base_pattern & 0xfff) + tile_ix;
|
||||
//vdp2.vram.u32[64 * cell_y + cell_x] = base_pattern + tile_ix;
|
||||
@ -250,16 +246,14 @@ static uint16_t scroll = 0;
|
||||
|
||||
void render_map()
|
||||
{
|
||||
/*
|
||||
if (++scroll > 60) {
|
||||
if (++scroll > 64) {
|
||||
scroll = 0;
|
||||
state.player.x += 1;
|
||||
state.player.y += 1;
|
||||
}
|
||||
*/
|
||||
|
||||
vdp2.reg.SCXIN0 = state.player.x * 16;
|
||||
vdp2.reg.SCYIN0 = state.player.y * 16;
|
||||
vdp2.reg.SCXIN0 = (state.player.x - 1) * 16 + (scroll / 4);
|
||||
vdp2.reg.SCYIN0 = (state.player.y - 1) * 16 + (scroll / 4);
|
||||
/*
|
||||
vdp2.reg.WPSX0 = 80 << 1;
|
||||
vdp2.reg.WPSY0 = 48;
|
||||
@ -273,15 +267,22 @@ void render_map()
|
||||
const uint32_t base_pattern = state.draw.base_pattern.tilesets[map.tileset];
|
||||
vdp2.reg.PNCN0 = PNCN0__N0PNB__1WORD | PNCN0__N0CNSM | PNCN0__N0SCN((base_pattern >> 10) & 0x1f);
|
||||
|
||||
int32_t origin_x = state.player.x;
|
||||
int32_t origin_y = state.player.y;
|
||||
int32_t origin_x = state.player.x / 2;
|
||||
int32_t origin_y = state.player.y / 2;
|
||||
int32_t offset_x = state.player.x & 1;
|
||||
int32_t offset_y = state.player.y & 1;
|
||||
|
||||
for (int32_t y = origin_y - 5; y <= origin_y + 6; y++) {
|
||||
for (int32_t x = origin_x - 5; x <= origin_x + 5; x++) {
|
||||
const uint8_t block =
|
||||
(x < static_cast<int32_t>(map.width) && y < static_cast<int32_t>(map.height) && x > 0 && y > 0)
|
||||
fill<uint32_t>(vdp2.vram.u32, 0, 64 * 64 * 2);
|
||||
|
||||
for (int32_t y = origin_y - 3 + offset_x; y <= (origin_y + 2 + offset_x); y++) {
|
||||
for (int32_t x = origin_x - 3 + offset_y; x <= (origin_x + 3 + offset_y); x++) {
|
||||
const uint8_t block = ( (x < static_cast<int32_t>(map.width))
|
||||
&& (y < static_cast<int32_t>(map.height))
|
||||
&& (x >= 0)
|
||||
&& (y >= 0))
|
||||
? map.blocks.start[map.width * y + x]
|
||||
: border_block;
|
||||
//const uint8_t block = map.blocks.start[map.width * 0 + 0];
|
||||
|
||||
render_block(base_pattern,
|
||||
tilesets[map.tileset],
|
||||
|
Loading…
x
Reference in New Issue
Block a user