/* * Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "tile.h" void tileDefineTileMap(byte t, uint32_t address, byte tileSize, uint16_t mapSizeX, uint16_t mapSizeY) { // Map size is 10 bits. Docs are wrong. switch (t) { case 0: POKE(VKY_TM0_CTRL, tileSize << 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 << 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 << 4); POKEA(VKY_TM2_ADDR_L, address); POKEW(VKY_TM2_SIZE_X, mapSizeX); POKEW(VKY_TM2_SIZE_Y, mapSizeY); break; } tileSetScroll(t, 0, 0, 0, 0); } void tileDefineTileSet(byte t, uint32_t address, bool square) { switch (t) { case 0: POKEA(VKY_TS0_ADDR_L, address); POKE(VKY_TS0_SQUARE, square << 3); break; case 1: POKEA(VKY_TS1_ADDR_L, address); POKE(VKY_TS1_SQUARE, square << 3); break; case 2: POKEA(VKY_TS2_ADDR_L, address); POKE(VKY_TS2_SQUARE, square << 3); break; case 3: POKEA(VKY_TS3_ADDR_L, address); POKE(VKY_TS3_SQUARE, square << 3); break; case 4: POKEA(VKY_TS4_ADDR_L, address); POKE(VKY_TS4_SQUARE, square << 3); break; case 5: POKEA(VKY_TS5_ADDR_L, address); POKE(VKY_TS5_SQUARE, square << 3); break; case 6: POKEA(VKY_TS6_ADDR_L, address); POKE(VKY_TS6_SQUARE, square << 3); break; case 7: POKEA(VKY_TS7_ADDR_L, address); POKE(VKY_TS7_SQUARE, square << 3); break; } } void tileSetScroll(byte t, byte xPixels, uint16_t xTiles, byte yPixels, uint16_t yTiles) { uint16_t scrollX = (xTiles << 4) + xPixels; uint16_t scrollY = (yTiles << 4) + yPixels; switch (t) { case 0: POKEW(VKY_TM0_POS_X_L, scrollX); POKEW(VKY_TM0_POS_Y_L, scrollY); break; case 1: POKEW(VKY_TM1_POS_X_L, scrollX); POKEW(VKY_TM1_POS_Y_L, scrollY); break; case 2: POKEW(VKY_TM2_POS_X_L, scrollX); POKEW(VKY_TM2_POS_Y_L, scrollY); break; } } void tileSetVisible(byte t, bool v) { switch (t) { case 0: POKE(VKY_TM0_CTRL, (PEEK(VKY_TM0_CTRL) & 0xfe) | v); break; case 1: POKE(VKY_TM1_CTRL, (PEEK(VKY_TM1_CTRL) & 0xfe) | v); break; case 2: POKE(VKY_TM2_CTRL, (PEEK(VKY_TM2_CTRL) & 0xfe) | v); break; } }