Tilemap demo working!

This commit is contained in:
Scott Duensing 2024-01-15 18:43:21 -06:00
parent fbefb2b551
commit edf1c56956
8 changed files with 68 additions and 19 deletions

BIN
examples/tilemap/brita.tiles (Stored with Git LFS)

Binary file not shown.

View file

@ -64,6 +64,8 @@ int main(int argc, char *argv[]) {
FILE *out;
uint16_t tile;
int16_t byte;
uint16_t x;
uint16_t y;
if (argc != 2) {
printf("Usage: %s [mapfile]\n", argv[0]);
@ -86,11 +88,25 @@ int main(int argc, char *argv[]) {
return 3;
}
/*
while ((byte = fgetc(in)) != EOF) {
// We always use CLUT0, so there's no need to set it here.
tile = ((byte > 255 ? 1 : 0) << 8) | (byte & 0x00ff);
fwrite(&tile, sizeof(uint16_t), 1, out);
}
*/
// Ultima maps are actually 256 high. Skip last row.
for (y=0; y<255; y++) {
for (x=0; x<255; x++) {
byte = fgetc(in);
// We always use CLUT0, so there's no need to set it here.
tile = ((byte > 255 ? 1 : 0) << 8) | (byte & 0x00ff);
fwrite(&tile, sizeof(uint16_t), 1, out);
}
// Ultima maps are actually 256 wide. Skip last column.
fgetc(in);
}
fclose(out);
fclose(in);

BIN
examples/tilemap/rawdata/brita.tiles (Stored with Git LFS)

Binary file not shown.

BIN
examples/tilemap/rawdata/under.tiles (Stored with Git LFS)

Binary file not shown.

View file

@ -37,6 +37,8 @@ int main(void) {
byte g;
byte b;
uint32_t c;
uint16_t xs = 75;
uint16_t ys = 99;
f256Init();
@ -56,7 +58,39 @@ int main(void) {
tileDefineTileMap(0, MAP_BRITANIA, 16, 255, 255);
tileSetVisible(0, true);
//tileSetScroll(0, 0, 0, 0, 0);
tileSetScroll(0, 0, xs, 0, ys);
while(true) {
kernelCall(NextEvent);
if (kernelGetPending() > 0) {
if (kernelEvent(key.PRESSED)) {
switch (kernelEventData.key.ascii) {
case 'w':
case 'W':
ys--;
break;
case 'a':
case 'A':
xs--;
break;
case 's':
case 'S':
ys++;
break;
case 'd':
case 'D':
xs++;
break;
}
tileSetScroll(0, 0, xs, 0, ys);
textGotoXY(0, 0);
textPrintInt(xs);
textPrint(", ");
textPrintInt(ys);
textPrint(" ");
}
}
}
return 0;
}

BIN
examples/tilemap/under.tiles (Stored with Git LFS)

Binary file not shown.

View file

@ -38,8 +38,8 @@ void f256Init(void) {
// Swap I/O page 0 into bank 6. This is our normal state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0);
POKE(VKY_MSTR_CTRL_0, 15); // Enable text and bitmaps.
//POKE(VKY_MSTR_CTRL_0, 63); // Enable text and all graphics.
POKE(VKY_MSTR_CTRL_0, 63); // Enable text and all graphics.
//POKE(VKY_MSTR_CTRL_1, 0);
//POKE(VKY_MSTR_CTRL_1, 20); // Enable FON_OVLY and DBL_Y.
POKE(VKY_MSTR_CTRL_1, 4); // Enable DBL_Y.

View file

@ -24,23 +24,24 @@
#include "tile.h"
static byte _tileSize[3];
void tileDefineTileMap(byte t, uint32_t address, byte tileSize, uint16_t mapSizeX, uint16_t mapSizeY) {
// Map size is 10 bits. Docs are wrong.
_tileSize[t] = tileSize;
switch (t) {
case 0:
POKE(VKY_TM0_CTRL, (tileSize == 8 ? 1 : 0) << 4);
POKEA(VKY_TM0_ADDR_L, address);
POKEW(VKY_TM0_SIZE_X, mapSizeX);
POKEW(VKY_TM0_SIZE_Y, mapSizeY);
break;
case 1:
POKE(VKY_TM1_CTRL, (tileSize == 8 ? 1 : 0) << 4);
POKEA(VKY_TM1_ADDR_L, address);
POKEW(VKY_TM1_SIZE_X, mapSizeX);
POKEW(VKY_TM1_SIZE_Y, mapSizeY);
break;
case 2:
POKE(VKY_TM2_CTRL, (tileSize == 8 ? 1 : 0) << 4);
POKEA(VKY_TM2_ADDR_L, address);
POKEW(VKY_TM2_SIZE_X, mapSizeX);
POKEW(VKY_TM2_SIZE_Y, mapSizeY);
@ -113,19 +114,23 @@ void tileSetScroll(byte t, byte xPixels, uint16_t xTiles, byte yPixels, uint16_t
void tileSetVisible(byte t, bool v) {
switch (t) {
case 0:
POKE(VKY_TM0_CTRL, (PEEK(VKY_TM0_CTRL) & 0xfe) | v);
POKE(VKY_TM0_CTRL, ((_tileSize[0] == 8 ? 1 : 0) << 4) | v);
break;
case 1:
POKE(VKY_TM1_CTRL, (PEEK(VKY_TM1_CTRL) & 0xfe) | v);
POKE(VKY_TM1_CTRL, ((_tileSize[1] == 8 ? 1 : 0) << 4) | v);
break;
case 2:
POKE(VKY_TM2_CTRL, (PEEK(VKY_TM2_CTRL) & 0xfe) | v);
POKE(VKY_TM2_CTRL, ((_tileSize[2] == 8 ? 1 : 0) << 4) | v);
break;
}
}
void tileReset(void) {
// All maps 8x8 by default.
_tileSize[0] = 8;
_tileSize[1] = 8;
_tileSize[2] = 8;
// Hide all tilemaps.
tileSetVisible(0, false);
tileSetVisible(1, false);