commit c102e1b0a3d9f38517fb156143fc1235575d399a
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 9 16:01:51 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 9 16:01:51 2020 -0600
Untested loading of font sprite sheet
---
source/fontdata.h | 2 +-
source/graphics.c | 29 ++++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/source/fontdata.h b/source/fontdata.h
index 323c155..ba483a6 100644
--- a/source/fontdata.h
+++ b/source/fontdata.h
@@ -1,6 +1,6 @@
//taken from tac08: https://github.com/0xcafed00d/tac08
-#define FONT_SS_STR "(77700000000000000000000000000000000000000000000000700000700000007770000000000000707000000000000000000000000000007070000007000000\
+static const char FONT_SS_STR[] = "(77700000000000000000000000000000000000000000000000700000700000007770000000000000707000000000000000000000000000007070000007000000\
77700000777000007770000070700000707000007070000007700000770000007000000000700000777000000000000000000000000000007070000070700000\
77700000777000007070000007000000000000007070000077700000777000007000000000700000070000000700000000000000000000000000000007000000\
77700000777000007770000070700000707000007070000007700000770000007000000000700000777000000000000070000000770000000000000000000000\
diff --git a/source/graphics.c b/source/graphics.c
index 0b3e52b..6e4ce1d 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -46,10 +46,34 @@ uint8_t _pico8_fb[128*128];
GraphicsState _graphicsState;
+SpriteSheet _fontSpriteSheet;
+
+void copy_data_to_sprites(SpriteSheet *sprites, const char* data, size_t datalength, bool bits8) {
+ uint16_t i = 0;
+
+ for (size_t n = 0; n < datalength; n++) {
+ char buf[3] = {0};
+
+ if (data[n] > ' ') {
+ buf[0] = data[n++];
+ buf[1] = data[n];
+ uint8_t val = (uint8_t)strtol(buf, NULL, 16);
+ if (bits8) {
+ sprites->sprite_data[i++] = val;
+ } else {
+ sprites->sprite_data[i++] = val >> 4;
+ sprites->sprite_data[i++] = val & 0x0f;
+ }
+ }
+ }
+}
+
//call initialize to make sure defaults are correct
void initPico8Graphics() {
_graphicsState.bgColor = 0;
_graphicsState.color = 7;
+
+ copy_data_to_sprites(&_fontSpriteSheet, FONT_SS_STR, sizeof(FONT_SS_STR), false);
}
//start helper methods
@@ -207,6 +231,10 @@ void rectfill(short x1, short y1, short x2, short y2, uint8_t col) {
}
}
+void print(char* str, size_t strlength, short x, short y, uint8_t col){
+
+}
+
void flipBuffer(u8* fb) {
int x, y;
for(x = 0; x < 400; x++) {
@@ -221,7 +249,6 @@ void flipBuffer(u8* fb) {
}
}
}
-
}