commit a0e061fd4b2e034c9b6368c0d76de4c88d4c916e
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 9 09:44:54 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 9 09:44:54 2020 -0600
use 8 bit ints instead of 16; add fontdata
---
source/fontdata.h | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
source/graphics.c | 21 ++++-----
source/graphics.h | 25 ++++++-----
3 files changed, 152 insertions(+), 20 deletions(-)
diff --git a/source/fontdata.h b/source/fontdata.h
new file mode 100644
index 0000000..323c155
--- /dev/null
+++ b/source/fontdata.h
@@ -0,0 +1,126 @@
+
+//taken from tac08: https://github.com/0xcafed00d/tac08
+#define FONT_SS_STR "(77700000000000000000000000000000000000000000000000700000700000007770000000000000707000000000000000000000000000007070000007000000\
+77700000777000007770000070700000707000007070000007700000770000007000000000700000777000000000000000000000000000007070000070700000\
+77700000777000007070000007000000000000007070000077700000777000007000000000700000070000000700000000000000000000000000000007000000\
+77700000777000007770000070700000707000007070000007700000770000007000000000700000777000000000000070000000770000000000000000000000\
+77700000000000000000000000000000000000000000000000700000700000000000000077700000070000000000000007000000770000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000070000007070000070700000777000007070000077000000070000000700000007000000707000000000000000000000000000000000000000700000\
+00000000070000007070000077700000770000000070000077000000700000007000000000700000070000000700000000000000000000000000000007000000\
+00000000070000000000000070700000077000000700000077000000000000007000000000700000777000007770000000000000777000000000000007000000\
+00000000000000000000000077700000777000007000000070700000000000007000000000700000070000000700000007000000000000000000000007000000\
+00000000070000000000000070700000070000007070000077700000000000000700000007000000707000000000000070000000000000000700000070000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+77700000770000007770000077700000707000007770000070000000777000007770000077700000000000000000000000700000000000007000000077700000\
+70700000070000000070000000700000707000007000000070000000007000007070000070700000070000000700000007000000777000000700000000700000\
+70700000070000007770000007700000777000007770000077700000007000007770000077700000000000000000000070000000000000000070000007700000\
+70700000070000007000000000700000007000000070000070700000007000007070000000700000070000000700000007000000777000000700000000000000\
+77700000777000007770000077700000007000007770000077700000007000007770000000700000000000007000000000700000000000007000000007000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+07000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+70700000777000007700000077700000770000007770000077700000777000007070000077700000777000007070000070000000777000007700000007700000\
+70700000707000007700000070000000707000007700000077000000700000007070000007000000070000007700000070000000777000007070000070700000\
+70000000777000007070000070000000707000007000000070000000707000007770000007000000070000007070000070000000707000007070000070700000\
+07700000707000007770000077700000770000007770000070000000777000007070000077700000770000007070000077700000707000007070000077000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007700000070000000077000000700000000000000\
+77700000070000007770000007700000777000007070000070700000707000007070000070700000777000007000000007000000007000007070000000000000\
+70700000707000007070000070000000070000007070000070700000707000000700000077700000007000007000000007000000007000000000000000000000\
+77700000770000007700000000700000070000007070000077700000777000007070000000700000700000007000000007000000007000000000000000000000\
+70000000077000007070000077000000070000000770000007000000777000007070000077700000777000007700000000700000077000000000000077700000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+07000000777000007770000007700000770000007770000077700000077000007070000077700000777000007070000070000000777000007700000007700000\
+00700000707000007070000070000000707000007000000070000000700000007070000007000000070000007070000070000000777000007070000070700000\
+00000000777000007700000070000000707000007700000077000000700000007770000007000000070000007700000070000000707000007070000070700000\
+00000000707000007070000070000000707000007000000070000000707000007070000007000000070000007070000070000000707000007070000070700000\
+00000000707000007770000007700000777000007770000070000000777000007070000077700000770000007070000077700000707000007070000077000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+77700000070000007770000007700000777000007070000070700000707000007070000070700000777000000770000007000000770000000000000000000000\
+70700000707000007070000070000000070000007070000070700000707000007070000070700000007000000700000007000000070000000070000007000000\
+77700000707000007700000077700000070000007070000070700000707000000700000077700000070000007700000007000000077000007770000070700000\
+70000000770000007070000000700000070000007070000077700000777000007070000000700000700000000700000007000000070000007000000070700000\
+70000000077000007070000077000000070000000770000007000000777000007070000077700000777000000770000007000000770000000000000077700000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+77777770707070707000007007777700700070000070000000777000077077000077700000777000007770000777770077777770000777000777770000070000\
+77777770070707007777777077000770007000700077770007770700077777000770770000777000077777007770077070777070000700007700077000777000\
+77777770707070707077707077000770700070000077700007777700077777007770777007777700777777707700077077777770000700007707077007777700\
+77777770070707007077707077707770007000700777700007777700007770000770770000777000070707007770077070000070077700007700077000777000\
+77777770707070700777770007777700700070000000700000777000000700000077700000707000070777000777770077777770077700000777770000070000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000077777000007000007777700077777000000000000000000077777007777777070707070077700007000000000777000000700000777007007000700\
+00000000770077700077700000777000777077707070000070007000770707700000000070707070007000007000700000000000077770000070000077777070\
+70707070770007707777777000070000770007700700707007070700777077707777777070707070077770007000070007777700000700000777770007007000\
+00000000770077700777770000777000770007700000070000700070770707700000000070707070707707007070070000000700007007007070007007007000\
+00000000077777000700070007777700077777000000000000000000077777007777777070707070077007000700000000077000070770000770070007070000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00777000000077000700070007770000077777000700000000070000070070000077770000700000007000000077770007777700000700000700077007077770\
+07777700007700000707777000007000000700000700000007777700077777000000700007770000777777007700007000007000000777007777000007000070\
+00777000070000000700070000000000077700000700000000070000070070000777777000707700007770000000007000070000007000000700070007000000\
+07000000007700000700070007000000700000000700070000770000070000000007000007000000000077000000070000070000070000007007770007070000\
+00777000000077000700700000777700077770000077700000070000007770000000777007007770077770000007700000007000007777000007707007007770\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+70070000070077000077770007007000770007000077000000000000707777000077700007700000007007000707000007777000007007000707770000070000\
+07777700770700700707007007077700070007700000000000770000700070000777770000700700077700700077770000700000077777700770707000077700\
+77070070077000707007007007007000070007000007000007007000707777000007000007777770007000000707707007777000007007700700707000070000\
+70770770770007707007007007077700070007000707070070000700700770000777700007700700077000700770007000700070000700000000770007777000\
+07700770070007700770070007077070007770007077007000000070707707700077070000007000007777000000770000077700000700000007000007700700\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00070000070000000077770000700000007777000700770007770000070000000000000000000000000000000000000007777700000077000007000000777000\
+07000000070007000000700007707700000070007707007000700770077700000000000007070000007000000700000000000700077700000777770000070000\
+07777700070007000077777000770700007777700770007000777000070070000777000077777000777700000777000000707000000700000000070000070000\
+00000700007007000700777007700700070000707700070000070700700070700000700007077000707070000700000000700000000700000000700000070000\
+00777000000070000000770000700770000077000700700000077770700077000007000000700000707700007077700007000000000700000077000007777700\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00007000007000000070000000700000007000000777770000700700000700000777770000700000070007000077777000777000070700700077700000700000\
+07777770077777000777700000777700007777700000070007777770070070000000070007777770007007000070007000070000070700700000000000700000\
+00077000007007000007000007000700070070000000070000700700007000000000700000700700000007000700707007777700000007000777770000777000\
+07707000070007000777770000007000000070000000070000000700000007700007700000700000000070000000077000070000000070000007000000700700\
+00077000070077000007000000070000000700000777770000007000007770000770070000077700000700000000700000700000007700000070000000700000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00070000000000000777770000070000000007000000700007000000077777000077000000070000077777000077770000070000000000700777770000707770\
+07777700007770000000070007777700000007000070070007007700000007000700700007777700000007000000000000700000000707000007000007770070\
+00070000000000000007070000000700000070000070070007770000000007007000070000070000007070000777770000700700000070000777777000700700\
+00070000000000000000770077777070000700000700007007000000000070000000007007070700000700000000000007000770000707700007000000070000\
+00700000077777000077000000070000077000000700007000777700007700000000000070770070000070000777700007777070077000000000777000070000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00077770077770000077700000700700007070000700000007777770077777000777770070000000000000000000000000000000000000000007000000070000\
+00000070000070000000000000700700007070000700000007000070070007000000070007000000707070000700000000000000077700000070000000007000\
+00000700077777000777770000700700007070000700000007000070000007000777770000007000000070007777700007770000077770007700077077000770\
+00000700000070000000070000000700007070700700770007000070000070000000070000070000000700000700700000070000000700000000700000700000\
+00777770077770000007700000077000070077000777000007777770000700000007700077700000077000000070000007777000077700000007000000070000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)";
diff --git a/source/graphics.c b/source/graphics.c
index 9b369d4..0b3e52b 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -5,6 +5,7 @@
#include <string.h>
#include "graphics.h"
+#include "fontdata.h"
/*
@@ -41,7 +42,7 @@ const Color PaletteColors[] = {
};
-uint16_t _pico8_fb[128*128];
+uint8_t _pico8_fb[128*128];
GraphicsState _graphicsState;
@@ -87,13 +88,13 @@ void cls() {
memset(_pico8_fb, _graphicsState.bgColor, sizeof(_pico8_fb));
}
-void pset(short x, short y, uint16_t col){
+void pset(short x, short y, uint8_t col){
if (isOnScreen(&x, &y)){
_pico8_fb[(x * 128) + y] = col;
}
}
-uint16_t pget(short x, short y){
+uint8_t pget(short x, short y){
if (isOnScreen(&x, &y)){
return _pico8_fb[(x * 128) + y];
}
@@ -101,11 +102,11 @@ uint16_t pget(short x, short y){
return 0;
}
-void color(uint16_t col){
+void color(uint8_t col){
_graphicsState.color = col;
}
-void line (short x1, short y1, short x2, short y2, uint16_t col) {
+void line (short x1, short y1, short x2, short y2, uint8_t col) {
sortPointsLtoR(&x1, &y1, &x2, &y2);
float run = x2 - x1;
@@ -131,7 +132,7 @@ void line (short x1, short y1, short x2, short y2, uint16_t col) {
}
}
-void circ(short ox, short oy, short r, uint16_t col){
+void circ(short ox, short oy, short r, uint8_t col){
short x = r;
short y = 0;
short decisionOver2 = 1-x;
@@ -159,7 +160,7 @@ void circ(short ox, short oy, short r, uint16_t col){
}
-void circfill(short ox, short oy, short r, uint16_t col){
+void circfill(short ox, short oy, short r, uint8_t col){
if (r == 0) {
pset(ox, oy, col);
}
@@ -183,7 +184,7 @@ void circfill(short ox, short oy, short r, uint16_t col){
}
-void rect(short x1, short y1, short x2, short y2, uint16_t col) {
+void rect(short x1, short y1, short x2, short y2, uint8_t col) {
sortCoordsForRect(&x1, &y1, &x2, &y2);
for (short i = x1; i <= x2; i++) {
@@ -196,7 +197,7 @@ void rect(short x1, short y1, short x2, short y2, uint16_t col) {
}
-void rectfill(short x1, short y1, short x2, short y2, uint16_t col) {
+void rectfill(short x1, short y1, short x2, short y2, uint8_t col) {
sortCoordsForRect(&x1, &y1, &x2, &y2);
for (short i = x1; i <= x2; i++) {
@@ -211,7 +212,7 @@ void flipBuffer(u8* fb) {
for(x = 0; x < 400; x++) {
for(y = 0; y < 240; y++) {
if (x < 128 && y < 128) {
- uint16_t c = _pico8_fb[x*128 + y];
+ uint8_t c = _pico8_fb[x*128 + y];
Color col = PaletteColors[c];
fb[((x*240)+ (239 - y))*3+0] = col.Blue;
diff --git a/source/graphics.h b/source/graphics.h
index 92e2d88..9cd4c80 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -28,25 +28,30 @@ typedef struct {
} Color;
typedef struct {
- uint16_t color;
- uint16_t bgColor;
+ uint8_t color;
+ uint8_t bgColor;
} GraphicsState;
+typedef struct {
+ uint8_t sprite_data[128 * 128];
+ uint8_t flags[256];
+} SpriteSheet;
+
void initPico8Graphics();
void cls();
-void pset(short x, short y, uint16_t col);
-uint16_t pget(short x, short y);
+void pset(short x, short y, uint8_t col);
+uint8_t pget(short x, short y);
-void color(uint16_t c);
+void color(uint8_t c);
-void line (short x1, short y1, short x2, short y2, uint16_t col);
+void line (short x1, short y1, short x2, short y2, uint8_t col);
-void circ(short ox, short oy, short r, uint16_t col);
-void circfill(short ox, short oy, short r, uint16_t col);
+void circ(short ox, short oy, short r, uint8_t col);
+void circfill(short ox, short oy, short r, uint8_t col);
-void rect(short x1, short y1, short x2, short y2, uint16_t col);
-void rectfill(short x1, short y1, short x2, short y2, uint16_t col);
+void rect(short x1, short y1, short x2, short y2, uint8_t col);
+void rectfill(short x1, short y1, short x2, short y2, uint8_t col);
void flipBuffer(u8* fb);
\ No newline at end of file