diff --git a/f256lib/f256.c b/f256lib/f256.c index 798b73f..bc9d2bf 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -23,17 +23,40 @@ #include "f256.h" + +#ifndef WITHOUT_KERNEL #include "kernel.c" +#endif +#ifndef WITHOUT_DMA #include "dma.c" +#endif +#ifndef WITHOUT_MATH #include "math.c" +#endif +#ifndef WITHOUT_RANDOM #include "random.c" +#endif +#ifndef WITHOUT_TEXT #include "text.c" +#endif +#ifndef WITHOUT_BITMAP #include "bitmap.c" +#endif +#ifndef WITHOUT_TILE #include "tile.c" +#endif +#if !(defined WITHOUT_BITMAP || defined WITHOUT_TILE || defined WITHOUT_SPRITE) #include "graphics.c" +#endif +#ifndef WITHOUT_SPRITE #include "sprite.c" +#endif +#ifndef WITHOUT_FILE #include "file.c" +#endif +#ifndef WITHOUT_PLATFORM #include "platform.c" +#endif void f256Init(void) { @@ -54,14 +77,30 @@ void f256Init(void) { //POKE(MMU_MEM_BANK_6, 6); // Don't use this - it's for the micro kernel. //POKE(MMU_MEM_BANK_7, 7); // Don't use this - it's for the micro kernel. +#ifndef WITHOUT_KERNEL kernelReset(); +#endif +#if !(defined WITHOUT_BITMAP || defined WITHOUT_TILE || defined WITHOUT_SPRITE) graphicsReset(); +#endif +#ifndef WITHOUT_TEXT textReset(); +#endif +#ifndef WITHOUT_BITMAP bitmapReset(); +#endif +#ifndef WITHOUT_TILE tileReset(); +#endif +#ifndef WITHOUT_SPRITE spriteReset(); +#endif +#ifndef WITHOUT_FILE fileReset(); +#endif +#ifndef WITHOUT_RANDOM randomReset(); +#endif } diff --git a/f256lib/f256.h b/f256lib/f256.h index ceb4ecf..2d1f4d1 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -154,7 +154,58 @@ typedef struct colorS { #define SET_BIT(x, pos) (x |= (1U << pos)) -extern byte SOF; +// Work out configuration DEFINEs. +#ifdef WITHOUT_GRAPHICS +#define WITHOUT_BITMAP +#define WITHOUT_TILE +#define WITHOUT_SPRITE +#endif + +#ifndef WITHOUT_FILE // File requires Kernel +#undef WITHOUT_KERNEL +#endif + +#ifndef WITHOUT_TEXT // Text requries Math +#undef WITHOUT_MATH +#endif + +#ifndef WITHOUT_BITMAP // Bitmap requries Math +#undef WITHOUT_MATH +#endif + +#ifndef WITHOUT_KERNEL +#include "kernel.h" +#endif +#ifndef WITHOUT_DMA +#include "dma.h" +#endif +#ifndef WITHOUT_MATH +#include "math.h" +#endif +#ifndef WITHOUT_RANDOM +#include "random.h" +#endif +#ifndef WITHOUT_TEXT +#include "text.h" +#endif +#ifndef WITHOUT_BITMAP +#include "bitmap.h" +#endif +#ifndef WITHOUT_TILE +#include "tile.h" +#endif +#if !(defined WITHOUT_BITMAP || defined WITHOUT_TILE || defined WITHOUT_SPRITE) +#include "graphics.h" +#endif +#ifndef WITHOUT_SPRITE +#include "sprite.h" +#endif +#ifndef WITHOUT_FILE +#include "file.h" +#endif +#ifndef WITHOUT_PLATFORM +#include "platform.h" +#endif void f256Init(void); @@ -164,19 +215,6 @@ void FAR_POKE(uint32_t address, byte value); void FAR_POKEW(uint32_t address, uint16_t value); -#include "kernel.h" -#include "dma.h" -#include "math.h" -#include "random.h" -#include "text.h" -#include "bitmap.h" -#include "tile.h" -#include "graphics.h" -#include "sprite.h" -#include "file.h" -#include "platform.h" - - #ifdef __cplusplus } #endif diff --git a/f256lib/file.c b/f256lib/file.c index 40727f4..4bbc9c9 100644 --- a/f256lib/file.c +++ b/f256lib/file.c @@ -178,17 +178,18 @@ char *fileOpenDir(char *name) { int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd) { char *data = (char *)buf; - int16_t gathered = 0; + int16_t read = 0; + uint16_t bytes = nbytes * nmemb; int16_t returned; - uint16_t bytes = nbytes * nmemb; - while (gathered < bytes) { - returned = kernelRead(*fd, data + gathered, bytes - gathered); - if (returned <= 0) return -1; - gathered += returned; + while (read < bytes) { + returned = kernelRead(*fd, data + read, bytes - read); + if (returned < 0) return -1; + if (returned == 0) break; + read += returned; } - return nmemb; + return read / nbytes; } @@ -384,7 +385,7 @@ int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd) { bytes -= written; } - return nmemb; + return total / nbytes; }