foxygit / fake-08-xbox360 Log in
commit 1d2f66acb969b3fe563012d189dc638ea3f7d7ee
Author:     DPS2004 <dpsophinos@gmail.com>
AuthorDate: Wed Feb 16 08:29:25 2022 -0500
Commit:     DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon May 2 09:18:19 2022 -0400

    load terminal cart from pause menu
---
 source/FakoTerm.h             | 64 +++++++++++++++++++++++++++++++++++++++++++
 source/cart.cpp               |  7 ++++-
 source/logger.cpp             |  9 +++++-
 source/p8GlobalLuaFunctions.h |  3 +-
 source/picoluaapi.cpp         |  6 ++++
 source/picoluaapi.h           |  1 +
 source/vm.cpp                 | 21 ++++++++++++--
 source/vm.h                   |  2 ++
 8 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/source/FakoTerm.h b/source/FakoTerm.h
new file mode 100644
index 0000000..c4bd6c6
--- /dev/null
+++ b/source/FakoTerm.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <string>
+
+#ifndef VER_STR
+#define VER_STR "v0.0.0.0"
+#endif
+
+
+const char * fake08TermP8 = R"#(
+pico-8 cartridge // http://www.pico-8.com
+version 27
+__lua__
+local carts={}
+local numcarts = 0
+
+local cidx=0
+local carttoload = ""
+local t=0
+local linebuffer=""
+local line
+local bgcolor=5
+local runcmd=false
+
+--start customizable per platform
+cartpath = "sdmc:/p8carts/"
+selectbtn = "a"
+pausebtn = "start"
+versionstr = ")#" VER_STR  R"#("
+exitbtn = "l + r"
+sizebtn = "select to cycle screen sizes"
+--end customizable per platform
+
+function _init()
+	if __getbioserror then
+		linebuffer = __getbioserror()
+	end
+end
+
+function _update60()
+
+end
+
+function _draw()
+	cls(0)
+	spr(0, 1, 5, 6, 1)
+	color(7)
+	cursor(0, 6*3)
+	print("hello from terminal!")
+	print("currently in alpha (" .. versionstr .. ")")
+
+	print("> "..linebuffer, 0, line)
+
+end
+
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77777077777077007077777000000007777007777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077077077000000000077077077077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77777077777077770077770077777077077077777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077077077000000000077077077077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077007077777000000077770077770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+
+)#";
\ No newline at end of file
diff --git a/source/cart.cpp b/source/cart.cpp
index 27eebfb..cf7f1fb 100644
--- a/source/cart.cpp
+++ b/source/cart.cpp
@@ -22,6 +22,8 @@

 #include "FakoBios.h"

+#include "FakoTerm.h"
+

 static char const *legacyCompressionLut = "\n 0123456789abcdefghijklmnopqrstuvwxyz!#%(){}[]<>+=/*:;.,~_";

@@ -322,11 +324,14 @@ Cart::Cart(std::string filename, std::string cartDirectory){

     std::string firstFourChars = get_first_four_chars(FullCartPath);

-    if (FullCartPath == "__FAKE08-BIOS.p8" || firstFourChars == "pico"){
+    if (FullCartPath == "__FAKE08-BIOS.p8" || FullCartPath == "__FAKE08-TERM.p8" || firstFourChars == "pico"){
         std::string cartStr;

         if (FullCartPath == "__FAKE08-BIOS.p8") {
             cartStr = fake08BiosP8;
+        }
+		else if (FullCartPath == "__FAKE08-TERM.p8") {
+            cartStr = fake08TermP8;
         }
         else {
             cartStr = get_file_contents(FullCartPath.c_str());
diff --git a/source/logger.cpp b/source/logger.cpp
index 7fca0e3..d228665 100644
--- a/source/logger.cpp
+++ b/source/logger.cpp
@@ -5,7 +5,8 @@
 #include "logger.h"

 #define LOGGER_ENABLED true
-#define PRINT_TO_CONSOLE false
+
+#define PRINT_TO_CONSOLE true

 FILE * m_file = nullptr;
 bool m_enabled = false;
@@ -59,6 +60,9 @@ void Logger_Write(const char * format, ...)
 	vfprintf(stdout, format, args);
 	#endif
     #endif
+	#if PRINT_TO_CONSOLE
+	vfprintf(stdout, format, args);
+	#endif
 }

 void Logger_WriteUnformatted(const char * message)
@@ -75,6 +79,9 @@ void Logger_WriteUnformatted(const char * message)
 	fprintf(stdout, "%s", message);
 	#endif
     #endif
+	#if PRINT_TO_CONSOLE
+	fprintf(stdout, "%s", message);
+	#endif
 }

 void Logger_Exit()
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index 4abd10d..ad1873d 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -162,7 +162,8 @@ __f08_menu_items = {
     {nil, nil},
     {nil, nil},
     {"reset cart", __resetcart},
-    {"exit to menu", __loadbioscart}
+    {"exit to menu", __loadbioscart},
+    {"exit to terminal", __loadtermcart}
 }

 __f08_menu_selected = 0
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 0fdf57e..6d6e321 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -1291,6 +1291,12 @@ int loadbioscart(lua_State *L) {
     return 0;
 }

+int loadtermcart(lua_State *L) {
+    _vmForLuaApi->QueueCartChange("__FAKE08-TERM.p8");
+
+    return 0;
+}
+
 int togglepausemenu(lua_State *L) {
     _vmForLuaApi->togglePauseMenu();

diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index e62e8b4..c8a06c8 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -96,6 +96,7 @@ int listcarts(lua_State *L);

 int getbioserror(lua_State *L);
 int loadbioscart(lua_State *L);
+int loadtermcart(lua_State *L);
 int togglepausemenu(lua_State *L);
 int resetcart(lua_State *L);

diff --git a/source/vm.cpp b/source/vm.cpp
index 5c9696a..7c3fd0e 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -32,6 +32,7 @@
 using namespace z8;

 static const char BiosCartName[] = "__FAKE08-BIOS.p8";
+static const char TermCartName[] = "__FAKE08-TERM.p8";

 Vm::Vm(
     Host* host,
@@ -164,6 +165,7 @@ bool Vm::loadCart(Cart* cart) {
     lua_register(_luaState, "__listcarts", listcarts);
     lua_register(_luaState, "__getbioserror", getbioserror);
     lua_register(_luaState, "__loadbioscart", loadbioscart);
+    lua_register(_luaState, "__loadtermcart", loadtermcart);
     lua_register(_luaState, "__togglepausemenu", togglepausemenu);
     lua_register(_luaState, "__resetcart", resetcart);
     lua_register(_luaState, "load", load);
@@ -315,7 +317,7 @@ bool Vm::loadCart(Cart* cart) {


     //customize bios per host's requirements
-    if (cart->FullCartPath == BiosCartName) {
+    if (cart->FullCartPath == BiosCartName || cart->FullCartPath == TermCartName) {
         std::string customBiosLua = _host->customBiosLua();

         if (customBiosLua.length() > 0) {
@@ -340,7 +342,6 @@ bool Vm::loadCart(Cart* cart) {

 void Vm::LoadBiosCart(){
     CloseCart();
-
     Cart *cart = new Cart(BiosCartName, "");

     bool success = loadCart(cart);
@@ -350,10 +351,26 @@ void Vm::LoadBiosCart(){
     }
 }

+void Vm::LoadTermCart(){
+    CloseCart();
+
+    Cart *cart = new Cart(TermCartName, "");
+
+    bool success = loadCart(cart);
+
+    if (!success) {
+        CloseCart();
+    }
+}
+
 void Vm::LoadCart(std::string filename){
     if (filename == "__FAKE08-BIOS.p8") {
         LoadBiosCart();
         return;
+    }
+	if (filename == "__FAKE08-TERM.p8") {
+        LoadTermCart();
+        return;
     }
     Logger_Write("Loading cart %s\n", filename.c_str());
     CloseCart();
diff --git a/source/vm.h b/source/vm.h
index d3a6f74..40be66d 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -66,6 +66,8 @@ class Vm {
     ~Vm();

     void LoadBiosCart();
+
+    void LoadTermCart();

     void LoadCart(string filename);