From 8486c2e37560a25c81556eb8048eed850bd46f92 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 10 Jan 2024 20:44:16 -0600 Subject: [PATCH] Sprite support. --- f256lib/f256.c | 3 +++ f256lib/f256.h | 1 + f256lib/sprite.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ f256lib/sprite.h | 48 +++++++++++++++++++++++++++++++++++++++ f256lib/tile.c | 8 +++++++ f256lib/tile.h | 1 + 6 files changed, 120 insertions(+) create mode 100644 f256lib/sprite.c create mode 100644 f256lib/sprite.h diff --git a/f256lib/f256.c b/f256lib/f256.c index 4115ef3..11bebec 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -31,6 +31,7 @@ #include "bitmap.c" #include "tile.c" #include "graphics.c" +#include "sprite.c" void f256Init(void) { @@ -58,4 +59,6 @@ void f256Init(void) { graphicsReset(); textReset(); bitmapReset(); + tileReset(); + spriteReset(); } diff --git a/f256lib/f256.h b/f256lib/f256.h index a559c4e..17a416f 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -112,6 +112,7 @@ void f256Init(void); #include "bitmap.h" #include "tile.h" #include "graphics.h" +#include "sprite.h" #ifdef __cplusplus diff --git a/f256lib/sprite.c b/f256lib/sprite.c new file mode 100644 index 0000000..5dba3d7 --- /dev/null +++ b/f256lib/sprite.c @@ -0,0 +1,59 @@ +/* + * 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 "sprite.h" + + +#define OFF_SPR_ADL_L 1 +#define OFF_SPR_POS_X_L 4 +#define OFF_SPR_POS_Y_L 6 + + +void spriteDefine(byte s, uint32_t address, byte size, byte CLUT, byte layer) { + uint16_t sprite = VKY_SP0_CTRL + (s << 3); + + POKE(sprite, (size << 5) | (layer << 3) | (CLUT << 1)); + POKEA(sprite + OFF_SPR_ADL_L, address); +} + + +void spriteSetPosition(byte s, uint16_t x, uint16_t y) { + uint16_t sprite = VKY_SP0_CTRL + (s << 3); + + POKEW(sprite + OFF_SPR_POS_X_L, x); + POKEW(sprite + OFF_SPR_POS_Y_L, y); +} + + +void spriteSetVisible(byte s, bool v) { + uint16_t sprite = VKY_SP0_CTRL + (s << 3); + + POKE(sprite, (PEEK(sprite) & 0xfe) | v); +} + + +void spriteReset(void) { + byte x; + // Hide all sprites. + for (x=0; x<64; x++) spriteSetVisible(x, false); +} diff --git a/f256lib/sprite.h b/f256lib/sprite.h new file mode 100644 index 0000000..a9137b7 --- /dev/null +++ b/f256lib/sprite.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + + +#ifndef SPRITE_H +#define SPRITE_H + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +#include "f256.h" + + +void spriteDefine(byte s, uint32_t address, byte size, byte CLUT, byte layer); +void spriteSetPosition(byte s, uint16_t x, uint16_t y); +void spriteSetVisible(byte s, bool v); +void spriteReset(void); + + +#ifdef __cplusplus +} +#endif + + +#endif // SPRITE_H diff --git a/f256lib/tile.c b/f256lib/tile.c index b99d82c..cb9b3db 100644 --- a/f256lib/tile.c +++ b/f256lib/tile.c @@ -123,3 +123,11 @@ void tileSetVisible(byte t, bool v) { break; } } + + +void tileReset(void) { + // Hide all tilemaps. + tileSetVisible(0, false); + tileSetVisible(1, false); + tileSetVisible(2, false); +} diff --git a/f256lib/tile.h b/f256lib/tile.h index 5015f18..4cdd057 100644 --- a/f256lib/tile.h +++ b/f256lib/tile.h @@ -38,6 +38,7 @@ void tileDefineTileMap(byte t, uint32_t address, byte tileSize, uint16_t mapSize void tileDefineTileSet(byte t, uint32_t address, bool square); void tileSetScroll(byte t, byte xPixels, uint16_t xTiles, byte yPixels, uint16_t yTiles); void tileSetVisible(byte t, bool v); +void tileReset(void); #ifdef __cplusplus