commit dba476d24cc7ecaeee94e0c305178f17ab90a34b
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Tue Apr 14 17:07:05 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Tue Apr 14 17:07:05 2020 -0600
Start cart loading process and add simple test flag
---
Makefile | 2 +-
source/cart.cpp | 32 +++++++++++++++++
source/cart.h | 27 ++++++++++++++
source/fakecart.h | 2 ++
source/filehelpers.cpp | 19 ++++++++++
source/filehelpers.h | 3 ++
source/fontdata.h | 2 ++
source/graphics.h | 1 +
source/main.cpp | 26 ++++++++++++--
source/picointernals.cpp | 7 ++++
source/picointernals.h | 6 +++-
source/tests/cart_test.cpp | 12 +++++++
source/tests/cart_test.h | 5 +++
source/tests/test_switch.h | 4 +++
testcart.p8 | 90 ++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 234 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index a86e57e..87beee4 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ include $(DEVKITARM)/3ds_rules
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
-SOURCES := source
+SOURCES := source source/tests
DATA := data
INCLUDES := include
GRAPHICS := gfx
diff --git a/source/cart.cpp b/source/cart.cpp
new file mode 100644
index 0000000..335b4e5
--- /dev/null
+++ b/source/cart.cpp
@@ -0,0 +1,32 @@
+#include <string>
+
+#include "cart.h"
+#include "filehelpers.h"
+
+#include "tests/test_switch.h"
+#if _TEST
+#include "tests/cart_test.h"
+#endif
+
+void LoadCart(std::string filename){
+ auto cartStr = get_file_contents(filename.c_str());
+
+ /*
+ PicoCart cart = {
+ filename,
+ cartStr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr
+ };
+ */
+
+
+ #if _TEST
+ verifyFullCartText(cartStr);
+
+ #endif
+
+ //return cart;
+}
\ No newline at end of file
diff --git a/source/cart.h b/source/cart.h
new file mode 100644
index 0000000..b5db05b
--- /dev/null
+++ b/source/cart.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <string>
+
+#include "graphics.h"
+
+
+struct PicoCart {
+ std::string Filename;
+
+ std::string FullCartString;
+
+ std::string SpriteSheetString;
+
+ std::string SpriteFlagsString;
+
+ std::string MapString;
+
+ std::string LuaScript;
+
+
+ //SpriteSheet CartSpriteSheet;
+ //uint8_t map_data[128 * 128];
+};
+
+
+void LoadCart(std::string filename);
\ No newline at end of file
diff --git a/source/fakecart.h b/source/fakecart.h
index 9691428..cfe2acc 100644
--- a/source/fakecart.h
+++ b/source/fakecart.h
@@ -1,2 +1,4 @@
+#pragma once
+
void _draw();
void _update();
\ No newline at end of file
diff --git a/source/filehelpers.cpp b/source/filehelpers.cpp
new file mode 100644
index 0000000..62af738
--- /dev/null
+++ b/source/filehelpers.cpp
@@ -0,0 +1,19 @@
+#include <string>
+#include <fstream>
+
+//http://insanecoding.blogspot.com/2011/11/how-to-read-in-file-in-c.html
+std::string get_file_contents(std::string filename){
+ std::ifstream in(filename, std::ios::in | std::ios::binary);
+ if (in)
+ {
+ std::string contents;
+ in.seekg(0, std::ios::end);
+ contents.resize(in.tellg());
+ in.seekg(0, std::ios::beg);
+ in.read(&contents[0], contents.size());
+ in.close();
+ return(contents);
+ }
+
+ return "";
+}
\ No newline at end of file
diff --git a/source/filehelpers.h b/source/filehelpers.h
new file mode 100644
index 0000000..8bde6c1
--- /dev/null
+++ b/source/filehelpers.h
@@ -0,0 +1,3 @@
+#include <string>
+
+std::string get_file_contents(std::string filename);
\ No newline at end of file
diff --git a/source/fontdata.h b/source/fontdata.h
index ae6f424..a6f7f1a 100644
--- a/source/fontdata.h
+++ b/source/fontdata.h
@@ -1,3 +1,5 @@
+#pragma once
+
#include <string>
std::string get_font_data();
\ No newline at end of file
diff --git a/source/graphics.h b/source/graphics.h
index 616c002..6d7b333 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -1,3 +1,4 @@
+#pragma once
#include <string>
diff --git a/source/main.cpp b/source/main.cpp
index a6681f5..f6460f1 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -1,14 +1,19 @@
-#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <3ds.h>
+
+#include <string>
#include "graphics.h"
#include "fakecart.h"
#include "picointernals.h"
+//this has the macro _TEST defined in it
+#include "tests/test_switch.h"
+
int main(int argc, char* argv[])
{
int frames = 0;
@@ -16,7 +21,20 @@ int main(int argc, char* argv[])
initPicoInternals();
+ //test or not both hardcoded to loading test cart as of now
+ #if _TEST
+ int bgcolor = 255;
consoleInit(GFX_BOTTOM, NULL);
+
+ printf("testing console printing\n");
+ printf("bgcolor %d\n", bgcolor);
+
+ loadcart("testcart.p8");
+
+ #else
+ loadcart("testcart.p8");
+ int bgcolor = 0;
+ #endif
// Main loop
while (aptMainLoop())
@@ -38,8 +56,12 @@ int main(int argc, char* argv[])
_update();
uint8_t* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
+ //clear whole top framebuffer
+ memset(fb, bgcolor, 240*400*3);
+
+ //uint8_t* fb_b = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
//clear whole framebuffer
- memset(fb, 192, 240*400*3);
+ //memset(fb_b, bgcolor, 240*320*3);
//cart draw
_draw();
diff --git a/source/picointernals.cpp b/source/picointernals.cpp
index fad26a8..cef1017 100644
--- a/source/picointernals.cpp
+++ b/source/picointernals.cpp
@@ -3,10 +3,17 @@
#include "picointernals.h"
#include "graphics.h"
#include "fontdata.h"
+#include "cart.h"
void initPicoInternals() {
auto fontdata = get_font_data();
initPico8Graphics(fontdata);
+}
+
+void loadcart(std::string filename){
+ //auto cart = LoadCart(filename);
+ LoadCart(filename);
+
}
\ No newline at end of file
diff --git a/source/picointernals.h b/source/picointernals.h
index 26b9aad..569ac2b 100644
--- a/source/picointernals.h
+++ b/source/picointernals.h
@@ -1 +1,5 @@
-void initPicoInternals();
\ No newline at end of file
+#pragma once
+
+void initPicoInternals();
+
+void loadcart(std::string filename);
\ No newline at end of file
diff --git a/source/tests/cart_test.cpp b/source/tests/cart_test.cpp
new file mode 100644
index 0000000..d45e368
--- /dev/null
+++ b/source/tests/cart_test.cpp
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <3ds.h>
+
+#include <string>
+
+#include "cart_test.h"
+
+bool verifyFullCartText(std::string cartText){
+ printf("test printing from cart_test.cpp\n");
+ printf(cartText.c_str());
+ return true;
+}
diff --git a/source/tests/cart_test.h b/source/tests/cart_test.h
new file mode 100644
index 0000000..82fbc8a
--- /dev/null
+++ b/source/tests/cart_test.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include <string>
+
+bool verifyFullCartText(std::string cartText);
diff --git a/source/tests/test_switch.h b/source/tests/test_switch.h
new file mode 100644
index 0000000..609931e
--- /dev/null
+++ b/source/tests/test_switch.h
@@ -0,0 +1,4 @@
+#pragma once
+
+//if this is set to 1, test cases will be run on the test cart
+#define _TEST 1
\ No newline at end of file
diff --git a/testcart.p8 b/testcart.p8
new file mode 100644
index 0000000..90e4a37
--- /dev/null
+++ b/testcart.p8
@@ -0,0 +1,90 @@
+pico-8 cartridge // http://www.pico-8.com
+version 18
+__lua__
+local r1x0 = 10
+local r1y0 = 10
+local r1x1 = 50
+local r1y1 = 50
+local r1c = 2
+
+local r2x0 = 60
+local r2y0 = 60
+local r2x1 = 100
+local r2y1 = 100
+local r2c = 3
+
+local r1dx = .5
+local r1dy = 2
+
+local r2dx = 2
+local r2dy = 2
+
+function _draw()
+ cls()
+
+ rectfill(0, 0, 127, 127, 0)
+
+ print("abcdefghijklmnopqrstuvwxyz", 0, 0, 7)
+
+ rectfill(50, -1, 60, 10, 11)
+
+ rectfill(r1x0, r1y0, r1x1, r1y1, r1c)
+
+ rect(r2x0, r2y0, r2x1, r2y1, r2c)
+
+ pset(40, 10, 13)
+
+ line(120, 10, 120, 120, 14)
+
+ line(0, 0, 20, 20, 15)
+
+ line(0, 20, 20, 0, 15)
+
+ line(20, 30, 0, 20, 12)
+
+ line(0, 30, 20, 20, 12)
+
+ circ(90, 90, 30, 8)
+
+ circfill(100, 100, 15, 9)
+
+ print("test str", 64, 64, 7)
+
+ spr(7, 40, 40, 1, 1, false, false)
+end
+
+function _update()
+ if (r1x0 < 0 or r1x1 > 127) then
+ r1dx = -1 * r1dx;
+ end
+ if (r1y0 < 0 or r1y1 > 127) then
+ r1dy = -1 * r1dy;
+ end
+ if (r2x0 < 0 or r2x1 > 127) then
+ r2dx = -1 * r2dx;
+ end
+ if (r2y0 < 0 or r2y1 > 127) then
+ r2dy = -1 * r2dy;
+ end
+ r1x0 = r1dx + r1x0
+ r1x1 = r1dx + r1x1
+ r1y0 = r1dy + r1y0
+ r1y1 = r1dy + r1y1
+end
+__gfx__
+e0000000000000000000000007700770000770000000000000000000000660005000000500000000000000000000000000000000000000000000000000000000
+00000000000000067000000078877887077777700500000000000050800660085005500500000000000000000000000000000000000000000000000000000000
+0070070000000006600000007888888707bbbb700500000000000050600550065055550500000000000000000000000000000000000000000000000000000000
+000770000000000660000000078888707bbbbbb70500000000000050600550065550055500000000000000000000000000000000000000000000000000000000
+000770000000000660000000078888707bbbbbb70500000550000050600660065555555500000000000000000000000000000000000000000000000000000000
+0070070000000066670000000078870007bbbb700500005555000050666cc66650b55b0500000000000000000000000000000000000000000000000000000000
+00000000008000666600080000077000077777700550055555500050666cc6665006600500000000000000000000000000000000000000000000000000000000
+0000000080d00065d6000d0800000000000770000555555555555550000660005000000500000000000000000000000000000000000000000000000000000000
+0b00080060d0006556000d0600000000000000000550055665500550000000000000000000000000000000000000000000000000000000000000000000000000
+0b00080060ddd065560ddd0600000000000000000500005555000050000000000000000000000000000000000000000000000000000000000000000000000000
+0b000800600ddd6556ddd00600000000000000000500008558000050000000000000000000000000000000000000000000000000000000000000000000000000
+0b000800666666666666666600000000000000000500000000000050000000000000000000000000000000000000000000000000000000000000000000000000
+00000000666866666666666600000000000000000500000000000050000000000000000000000000000000000000000000000000000000000000000000000000
+000000000666666cc666666000000000000000000500000000000050000000000000000000000000000000000000000000000000000000000000000000000000
+000000000006666cc666600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000666600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000