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

    use shorts instead of chars to avoid overflows
---
 source/fakecart.c |  6 ++++--
 source/graphics.c | 10 +++++-----
 source/graphics.h |  4 ++--
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/source/fakecart.c b/source/fakecart.c
index cb68ad7..fe29565 100644
--- a/source/fakecart.c
+++ b/source/fakecart.c
@@ -30,9 +30,11 @@ void _draw() {

     rectfill(0, 0, 127, 127, 10);

-    rectfill((int)r1x0, (int)r1y0, (int)r1x1, (int)r1y1, r1c);
+    rectfill(50, -1, 60, 10, 11);

-    rectfill((int)r2x1, (int)r2y1, (int)r2x0, (int)r2y0, r2c);
+    rectfill((short)r1x0, (short)r1y0, (short)r1x1, (short)r1y1, r1c);
+
+    rectfill((short)r2x1, (short)r2y1, (short)r2x0, (short)r2y0, r2c);
 }

 void _update() {
diff --git a/source/graphics.c b/source/graphics.c
index 06fe22e..a0c70a6 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -43,8 +43,8 @@ const Color PaletteColors[] = {

 uint16_t _pico8_fb[128*128];

-void swap(char *x, char *y) {
-   char temp;
+void swap(short *x, short *y) {
+   short temp;
    temp = *x;
    *x = *y;
    *y = temp;
@@ -52,7 +52,7 @@ void swap(char *x, char *y) {
    return;
 }

-void sortcoords(char *expectedLower, char *expectedHigher){
+void sortcoords(short *expectedLower, short *expectedHigher){
 	if (*expectedHigher < *expectedLower) {
 		swap(expectedLower, expectedHigher);
 	}
@@ -62,7 +62,7 @@ void cls() {
 	memset(_pico8_fb, 0, sizeof(_pico8_fb));
 }

-void rect(char x, char y, char x1, char y1, uint16_t col) {
+void rect(short x, short y, short x1, short y1, uint16_t col) {
 	/*
 	char w = x1 - x;
 	char h = y1 - y;
@@ -74,7 +74,7 @@ void rect(char x, char y, char x1, char y1, uint16_t col) {

 }

-void rectfill(char x1, char y1, char x2, char y2, uint16_t col) {
+void rectfill(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 6be0e66..9e8e6ef 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -30,7 +30,7 @@ typedef struct {

 void cls();

-void rect(char x0, char y0, char x1, char y1, uint16_t col);
-void rectfill(char x, char y, char x1, char y1, uint16_t col);
+void rect(short x0, short y0, short x1, short y1, uint16_t col);
+void rectfill(short x, short y, short x1, short y1, uint16_t col);

 void flipBuffer(u8* fb);
\ No newline at end of file