diff --git a/.gitattributes b/.gitattributes index 83bffea..365ff3a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ +*.xcf filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text *.jpg filter=lfs diff=lfs merge=lfs -text *.gif filter=lfs diff=lfs merge=lfs -text @@ -8,3 +9,4 @@ *.map filter=lfs diff=lfs merge=lfs -text *.clut filter=lfs diff=lfs merge=lfs -text *.indexed filter=lfs diff=lfs merge=lfs -text +*.sprite filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index aba9957..e854154 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ intelFPGA_lite/ /header /imageconvert include/ +generated/ # Dumb QtCreator junk build-*/ diff --git a/examples/cube-pre/cube-pre.c b/examples/cube-pre/cube-pre.c index 43c08b0..3d12053 100644 --- a/examples/cube-pre/cube-pre.c +++ b/examples/cube-pre/cube-pre.c @@ -152,7 +152,6 @@ int main(void) { f256Init(); - textSetCursor(0); // No cursor. textSetColor(15, 0); // Clear two graphics pages. @@ -204,8 +203,6 @@ int main(void) { line[l][t].y2 = cubeProjY[edges[i + 1]]; l++; } - - kernelUpdate(); } textClear(); diff --git a/examples/sprites/CMakeLists.txt b/examples/sprites/CMakeLists.txt new file mode 100644 index 0000000..99ed457 --- /dev/null +++ b/examples/sprites/CMakeLists.txt @@ -0,0 +1,52 @@ +# +# 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. +# + + +# This is only to make my IDE happy. +# We can't actually build with it until I get llvm-mos integrated into +# toolchains. -- SCD + + +cmake_minimum_required(VERSION 3.22) +set(CMAKE_C_STANDARD 17) +project(helicopter) + +set(F256DIR ${CMAKE_SOURCE_DIR}/../..) + +set(DEFINES ${F256DIR}/include) +set(F256LIB ${F256DIR}/f256lib) + +set(HELICOPTER_SOURCE + ${F256LIB}/f256.h + ${F256LIB}/f256.c + helicopter.c +) + +add_executable(${CMAKE_PROJECT_NAME} + ${HELICOPTER_SOURCE} +) + +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC + ${CMAKE_SOURCE_DIR} + ${DEFINES} + ${F256LIB} +) diff --git a/examples/sprites/assets/apache-left-front.png b/examples/sprites/assets/apache-left-front.png new file mode 100644 index 0000000..88e4305 --- /dev/null +++ b/examples/sprites/assets/apache-left-front.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e694d644504948a9061bb77d503196d9967f560315fd9d13b50ce046785f1f17 +size 2465 diff --git a/examples/sprites/assets/apache-left.png b/examples/sprites/assets/apache-left.png new file mode 100644 index 0000000..abaca97 --- /dev/null +++ b/examples/sprites/assets/apache-left.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:690b2ff880ddb4a5125580cf608bd2fe16b15f9d170a90cb63c7aac230208127 +size 3268 diff --git a/examples/sprites/assets/apache-right-front.png b/examples/sprites/assets/apache-right-front.png new file mode 100644 index 0000000..8de9184 --- /dev/null +++ b/examples/sprites/assets/apache-right-front.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5d8a2f016f76bd9449ff3cd1734d6e858fed8d1711f479e6c9bb4791cac9830 +size 2481 diff --git a/examples/sprites/assets/apache-right.png b/examples/sprites/assets/apache-right.png new file mode 100644 index 0000000..ed8ba58 --- /dev/null +++ b/examples/sprites/assets/apache-right.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8460052017311222adc0a618464f3e77b2f1cd3034278f7813894d874e1d1bd9 +size 3246 diff --git a/examples/sprites/assets/apache.png b/examples/sprites/assets/apache.png new file mode 100644 index 0000000..fc9c61c --- /dev/null +++ b/examples/sprites/assets/apache.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b00d366f8d29498153644c81b8b40033663c0883072333a42ff024310357640d +size 4329 diff --git a/examples/sprites/assets/apache.xcf b/examples/sprites/assets/apache.xcf new file mode 100644 index 0000000..8844ea3 Binary files /dev/null and b/examples/sprites/assets/apache.xcf differ diff --git a/examples/sprites/build.sh b/examples/sprites/build.sh new file mode 100755 index 0000000..b3e55e9 --- /dev/null +++ b/examples/sprites/build.sh @@ -0,0 +1,58 @@ +#!/bin/bash -ex + +# +# 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. +# + + +PROJECT=helicopter +START=0x200 + + +F256=../.. +LLVM=${F256}/llvm-mos +SETTINGS=${LLVM}/mos-platform/f256k/lib/settings.ld +PATH=${LLVM}/bin:${PATH} + +echo "__f256_start = ${START};" > ${SETTINGS} + +CLANG="mos-f256k-clang -I${F256}/include -I${F256}/f256lib -O3" + +${CLANG} -c ${F256}/f256lib/f256.c +${CLANG} -c ${PROJECT}.c +${CLANG} -o ${PROJECT} ${PROJECT}.o f256.o + +mv -f ${PROJECT} ${PROJECT}.bin + +${F256}/header \ + pgz 24 \ + ${PROJECT}.pgz \ + ${START} \ + ${PROJECT}.bin ${START} \ + generated/apache-left.sprite 0x10000 \ + generated/apache-left-front.sprite 0x12800 \ + generated/apache-right-front.sprite 0x15000 \ + generated/apache-right.sprite 0x17800 \ + generated/apache-left.clut 0x1a000 + +llvm-nm ${PROJECT}.elf > ${PROJECT}.sym +llvm-objdump -d --print-imm-hex ${PROJECT}.elf > ${PROJECT}.lst +hexdump -C ${PROJECT}.pgz > ${PROJECT}.hex diff --git a/examples/sprites/foenixmgr.ini b/examples/sprites/foenixmgr.ini new file mode 100644 index 0000000..c6ab319 --- /dev/null +++ b/examples/sprites/foenixmgr.ini @@ -0,0 +1,7 @@ +[DEFAULT] +port=/dev/ttyUSB1 +labels=sample.lbl +flash_address=380000 +chunk_size=1024 +cpu=65c02 +data_rate=6000000 \ No newline at end of file diff --git a/examples/sprites/helicopter.c b/examples/sprites/helicopter.c new file mode 100644 index 0000000..a33458b --- /dev/null +++ b/examples/sprites/helicopter.c @@ -0,0 +1,271 @@ +/* + * 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 "f256.h" + + +#define SPRITE_COUNT 4 +#define SPRITE_SIZE 32 +#define SPRITE_WIDTH 5 +#define SPRITE_HEIGHT 2 + +#define SPR_LEFT 0 +#define SPR_LEFT_ADDR 0x10000 + +#define SPR_LEFT_FRONT 1 +#define SPR_LEFT_FRONT_ADDR 0x12800 + +#define SPR_RIGHT_FRONT 2 +#define SPR_RIGHT_FRONT_ADDR 0x15000 + +#define SPR_RIGHT 3 +#define SPR_RIGHT_ADDR 0x17800 + +#define SPR_CLUT 0x1a000 +#define SPR_CLUT_COLORS 32 + +#define TURN_SPEED 25 + + +static byte sprites[SPRITE_COUNT] = { SPR_LEFT, SPR_LEFT_FRONT, SPR_RIGHT_FRONT, SPR_RIGHT }; +static uint32_t spriteStartAddrs[SPRITE_COUNT] = { SPR_LEFT_ADDR, SPR_LEFT_FRONT_ADDR, SPR_RIGHT_FRONT_ADDR, SPR_RIGHT_ADDR }; +static uint32_t spriteAddrs[SPRITE_COUNT][SPRITE_WIDTH][SPRITE_HEIGHT]; +static byte spriteIds[SPRITE_COUNT][SPRITE_WIDTH][SPRITE_HEIGHT]; +static byte anyJoy; + + +void drawHelicopter(void) { + static byte last = SPR_RIGHT; // Last frame used, can be anything other than "frame". + static byte frame = SPR_RIGHT_FRONT; + static byte lag = 0; + static uint16_t xSize = (SPRITE_WIDTH * SPRITE_SIZE); + static uint16_t ySize = (SPRITE_HEIGHT * SPRITE_SIZE); + static uint16_t xPos = 96; // (352 / 2) - (xSize / 2); + static uint16_t yPos = 104; // (272 / 2) - (ySize / 2); + byte i; + byte j; + + // New frame? + if (last != frame) { + for (j=0; j 32) yPos--; + } + + if (anyJoy & JOY_DOWN) { + if (yPos + ySize < 271) yPos++; + } + + if (anyJoy & JOY_LEFT) { + if (xPos > 32) xPos--; + if (frame > SPR_LEFT) { + if (lag == 0) { + lag = TURN_SPEED; + } else { + lag--; + if (lag == 0) frame--; + } + } + } + + if (anyJoy & JOY_RIGHT) { + if (xPos + xSize < 351) xPos++; + if (frame < SPR_RIGHT) { + if (lag == 0) { + lag = TURN_SPEED; + } else { + lag--; + if (lag == 0) frame++; + } + } + } + + // Update sprite positions. + for (j=0; j generated/${NAME}.sprite + + rm generated/*.indexed +} + + +makeSprite apache-left +makeSprite apache-left-front +makeSprite apache-right-front +makeSprite apache-right diff --git a/examples/sprites/run.sh b/examples/sprites/run.sh new file mode 100755 index 0000000..659d6a2 --- /dev/null +++ b/examples/sprites/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# +# 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. +# + + +python ../../FoenixMgr/FoenixMgr/fnxmgr.py --run-pgz helicopter.pgz diff --git a/f256lib/graphics.c b/f256lib/graphics.c index 4badb69..6f1c253 100644 --- a/f256lib/graphics.c +++ b/f256lib/graphics.c @@ -85,7 +85,7 @@ void graphicsSetLayerBitmap(byte layer, byte which) { POKE(VKY_LAYER_CTRL_0, (PEEK(VKY_LAYER_CTRL_0) & 0x0f) | (which << 4)); break; case 2: - POKE(VKY_LAYER_CTRL_1, which); + POKE(VKY_LAYER_CTRL_1, which); //***TODO*** This doesn't work? break; } } diff --git a/f256lib/text.c b/f256lib/text.c index 4466f35..3ca4904 100644 --- a/f256lib/text.c +++ b/f256lib/text.c @@ -167,14 +167,24 @@ void textPrint(char *message) { void textPrintInt(int32_t value){ - char c[2]; - if (value < 0) { textPrint("-"); value = -value; } + textPrintUInt(value); +} - if (value > 9) textPrintInt(mathUnsignedDivision(value, 10)); + +void textPrintUInt(uint32_t value){ + char c[2]; + + if (value > 9) { + if (value > 65535) { + textPrintUInt(value / 10); // Can't use the coprocessor for uint32. + } else { + textPrintUInt(mathUnsignedDivision(value, 10)); + } + } c[0] = '0' + (value % 10); c[1] = 0; diff --git a/f256lib/text.h b/f256lib/text.h index cf0ff5b..c1c119c 100644 --- a/f256lib/text.h +++ b/f256lib/text.h @@ -65,6 +65,7 @@ void textGetXY(byte *x, byte *y); void textGotoXY(byte x, byte y); void textPrint(char *message); void textPrintInt(int32_t value); +void textPrintUInt(uint32_t value); void textReset(void); void textSetColor(byte f, byte b); void textSetCursor(byte c); diff --git a/tools/imageconvert/imageconvert.c b/tools/imageconvert/imageconvert.c index a4647dc..a9e08bf 100644 --- a/tools/imageconvert/imageconvert.c +++ b/tools/imageconvert/imageconvert.c @@ -30,11 +30,11 @@ #include "../shared/util.h" -int writeImage(byte *data, colorT *palette, int colors, char *filename, int xs, int ys, int width, int height) { +int writeImage(byte *data, int imageWidth, colorT *palette, int colors, char *filename, int xs, int ys, int width, int height) { int x; int y; int n; - byte *p; + int a; colorT c; FILE *out; @@ -46,16 +46,17 @@ int writeImage(byte *data, colorT *palette, int colors, char *filename, int xs, } for (y=ys; y