foxygit / fake-08-xbox360 Log in
commit 84e7756c63c3b621cb06335c1c8caeb9ba03a030
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 8 11:50:47 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 8 11:50:47 2020 -0600

    Add graphics state and ability to set color
---
 source/graphics.c | 13 ++++++++++++-
 source/graphics.h |  8 ++++++++
 source/main.c     |  4 +++-
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/source/graphics.c b/source/graphics.c
index 30b4b97..594f192 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -43,6 +43,13 @@ const Color PaletteColors[] = {

 uint16_t _pico8_fb[128*128];

+GraphicsState _graphicsState;
+
+void initPico8Graphics() {
+	_graphicsState.bgColor = 0;
+	_graphicsState.color = 7;
+}
+
 void swap(short *x, short *y) {
    short temp;
    temp = *x;
@@ -63,7 +70,7 @@ bool isOnScreen(short *x, short* y) {
 }

 void cls() {
-	memset(_pico8_fb, 0, sizeof(_pico8_fb));
+	memset(_pico8_fb, _graphicsState.bgColor, sizeof(_pico8_fb));
 }

 void pset(short x, short y, uint16_t col){
@@ -80,6 +87,10 @@ uint16_t pget(short x, short y){
 	return 0;
 }

+void color(uint16_t col){
+	_graphicsState.color = col;
+}
+
 void rect(short x1, short y1, short x2, short y2, uint16_t col) {
 	sortcoords(&x1, &x2);
 	sortcoords(&y1, &y2);
diff --git a/source/graphics.h b/source/graphics.h
index 52195bf..2048e3a 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -27,12 +27,20 @@ typedef struct {
 	char Alpha;
 } Color;

+typedef struct {
+    uint16_t color;
+    uint16_t bgColor;
+} GraphicsState;
+
+void initPico8Graphics();

 void cls();

 void pset(short x, short y, uint16_t col);
 uint16_t pget(short x, short y);

+void color(uint16_t c);
+
 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);

diff --git a/source/main.c b/source/main.c
index 06b1c6e..372caa2 100644
--- a/source/main.c
+++ b/source/main.c
@@ -17,8 +17,10 @@ int main(int argc, char **argv)
 	int frames = 0;
 	gfxInitDefault();

-	consoleInit(GFX_BOTTOM, NULL);
+	initPico8Graphics();

+	consoleInit(GFX_BOTTOM, NULL);
+
 	// Main loop
 	while (aptMainLoop())
 	{