From edf1c56956d8e1a1797e7c4b31cf7f902867774c Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 15 Jan 2024 18:43:21 -0600 Subject: [PATCH] Tilemap demo working! --- examples/tilemap/brita.tiles | 4 ++-- examples/tilemap/makemap.c | 16 +++++++++++++ examples/tilemap/rawdata/brita.tiles | 3 --- examples/tilemap/rawdata/under.tiles | 3 --- examples/tilemap/u5map.c | 36 +++++++++++++++++++++++++++- examples/tilemap/under.tiles | 4 ++-- f256lib/f256.c | 4 ++-- f256lib/tile.c | 17 ++++++++----- 8 files changed, 68 insertions(+), 19 deletions(-) delete mode 100644 examples/tilemap/rawdata/brita.tiles delete mode 100644 examples/tilemap/rawdata/under.tiles diff --git a/examples/tilemap/brita.tiles b/examples/tilemap/brita.tiles index 9875a5b..16a828b 100644 --- a/examples/tilemap/brita.tiles +++ b/examples/tilemap/brita.tiles @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a5e230d028deb92665457135dd11ff79139da6e8346e018ef8762d63061f7297 -size 131072 +oid sha256:e97de5c400f276767e5b5a9d40587780e00097a00d65cff65df600788f1d17c7 +size 130050 diff --git a/examples/tilemap/makemap.c b/examples/tilemap/makemap.c index da9a64c..f84a9e2 100644 --- a/examples/tilemap/makemap.c +++ b/examples/tilemap/makemap.c @@ -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); diff --git a/examples/tilemap/rawdata/brita.tiles b/examples/tilemap/rawdata/brita.tiles deleted file mode 100644 index 9875a5b..0000000 --- a/examples/tilemap/rawdata/brita.tiles +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a5e230d028deb92665457135dd11ff79139da6e8346e018ef8762d63061f7297 -size 131072 diff --git a/examples/tilemap/rawdata/under.tiles b/examples/tilemap/rawdata/under.tiles deleted file mode 100644 index 1b433c8..0000000 --- a/examples/tilemap/rawdata/under.tiles +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:417d15adcad737e65c35be36ab5ab92a0844ec6d096017c48c41ff704bc4ee7b -size 131072 diff --git a/examples/tilemap/u5map.c b/examples/tilemap/u5map.c index cdca0d5..fba5bb8 100644 --- a/examples/tilemap/u5map.c +++ b/examples/tilemap/u5map.c @@ -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; } diff --git a/examples/tilemap/under.tiles b/examples/tilemap/under.tiles index 1b433c8..3be1145 100644 --- a/examples/tilemap/under.tiles +++ b/examples/tilemap/under.tiles @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:417d15adcad737e65c35be36ab5ab92a0844ec6d096017c48c41ff704bc4ee7b -size 131072 +oid sha256:e18ce635b65aaf45d60ed8225af70a2abab0472e7a89296892878615245f444c +size 130050 diff --git a/f256lib/f256.c b/f256lib/f256.c index 2d3f1c8..8a6a2ce 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -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. diff --git a/f256lib/tile.c b/f256lib/tile.c index 924af74..e8e1fde 100644 --- a/f256lib/tile.c +++ b/f256lib/tile.c @@ -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);