commit ba17abff8ee08b4e785ef1563bd1dfd8203c5555
Author: DPS2004 <dpsophinos@gmail.com>
AuthorDate: Tue Mar 1 12:49:07 2022 -0500
Commit: DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon May 2 09:34:17 2022 -0400
start work on settings menu
---
platform/3ds/source/3dsHost.cpp | 2 +
source/FakoSettings.h | 198 ++++++++++++++++++++++++++++++++++++++++
source/FakoTerm.h | 64 -------------
source/cart.cpp | 8 +-
source/host.h | 9 ++
source/hostCommonFunctions.cpp | 21 ++++-
source/p8GlobalLuaFunctions.h | 2 +-
source/picoluaapi.cpp | 4 +-
source/picoluaapi.h | 2 +-
source/vm.cpp | 14 +--
source/vm.h | 2 +-
11 files changed, 242 insertions(+), 84 deletions(-)
diff --git a/platform/3ds/source/3dsHost.cpp b/platform/3ds/source/3dsHost.cpp
index 13b4f5e..92770ee 100644
--- a/platform/3ds/source/3dsHost.cpp
+++ b/platform/3ds/source/3dsHost.cpp
@@ -680,6 +680,8 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, uint8_t drawMod
flipHorizontal,
flipVertical);
}
+
+ //keyboard goes here probably
C2D_Flush();
diff --git a/source/FakoSettings.h b/source/FakoSettings.h
new file mode 100644
index 0000000..fcb4a57
--- /dev/null
+++ b/source/FakoSettings.h
@@ -0,0 +1,198 @@
+#pragma once
+
+#include <string>
+
+#ifndef VER_STR
+#define VER_STR "v0.0.0.0"
+#endif
+
+
+const char * fake08SettingsP8 = R"#(
+pico-8 cartridge // http://www.pico-8.com
+version 33
+__lua__
+function _init()
+
+ if not __fakogetsetting then
+ printh('not in fake-08 (or unimplemented...), stubbing get and set functions!')
+ function __fakogetsetting(sn)
+ printh('trying to get setting ' .. sn)
+ return 1
+ end
+
+ function __fakosetsetting(sn,v)
+ printh('trying to set setting ' .. sn .. ' to '..v)
+ end
+
+ end
+
+ settinglist = {'kbmode','enableresize','stretch','menustyle'}
+ settings = {}
+ for i,v in ipairs(settinglist) do
+ settings[v] = __fakogetsetting(v)
+ end
+
+ list = {
+ {name='input',ops = {
+ {
+ name = 'keyboard mode',
+ vn = 'kbmode',
+ ch ={'emoji','lowercase'}
+ }
+ }},
+ {name='audio',ops = {
+
+ }},
+ {name='video',ops = {
+ {
+ name = 'enable resize hotkeys',
+ vn = 'enableresize',
+ ch ={'no','yes'}
+ },
+ {
+ name = 'stretch mode',
+ vn = 'stretch',
+ ch ={'pixel perfect','pixel perfect stretch','stretch to fit','overflow stretch','alt screen pixel perfect','alt screen stretch'}
+ }
+ }},
+ {name='menu',ops = {
+ {
+ name = 'menu style',
+ vn = 'menustyle',
+ ch ={'classic','carts','splore'}
+ }
+ }}
+ }
+
+ path = {}
+
+ menuspace = 10
+ indent = 10
+ basex = 10
+ basey = 20
+
+ cursorpos = 1
+
+ cpath = nil
+ sectionname = nil
+ numitems = nil
+ inoption = false
+ cvariable = nil
+ cvalue = nil
+
+ refreshinfo()
+
+end
+-->8
+
+function refreshinfo()
+
+ cpath = list
+ sectionname = 'main'
+ for i,v in ipairs(path) do
+ cpath = cpath[v]
+ sectionname = cpath.name
+ cvariable = cpath.vn
+ cvalue = settings[cvariable]
+ if cpath.ops then
+ cpath = cpath.ops
+ inoption = false
+ end
+ if cpath.ch then
+ cpath = cpath.ch
+ inoption = true
+ end
+ end
+
+ numitems = #cpath + 1
+end
+
+function updatecursor()
+ cursorpos -= 1
+ if btnp( ⬆️ ) then
+ cursorpos -= 1
+ end
+ if btnp( ⬇️ ) then
+ cursorpos += 1
+ end
+ cursorpos = (cursorpos % numitems) + 1
+
+ if btnp( ❎ ) or btnp ( 🅾️ ) then
+ if cursorpos == numitems then -- back
+ cursorpos = deli(path)
+ if not cursorpos then
+ --exit to bios
+ __loadbioscart()
+ end
+ else
+ if inoption then
+ settings[cvariable] = cursorpos
+ __fakosetsetting(cvariable,cursorpos-1)
+ else
+ add(path,cursorpos)
+ end
+ end
+ refreshinfo()
+ end
+end
+
+function _update60()
+
+ updatecursor()
+
+end
+-->8
+
+function drawitem(n,y,x)
+ local yoffset = (menuspace*y)
+ color(7)
+ print(n,x,20+yoffset)
+ color(6)
+ line(4,22+yoffset,x-2,22+yoffset)
+ line(4,22+yoffset,4,22)
+ if cvalue == y then
+ line(x,18+yoffset,x + (4 * #n) - 2,18+yoffset)
+ line(x,26+yoffset,x + (4 * #n) - 2,26+yoffset)
+ end
+end
+
+function drawcursor()
+ spr(5,13,18+(menuspace*cursorpos),1,2)
+end
+
+function _draw()
+ cls(1)
+ spr(0,1,1,5,1)
+
+
+ color(7)
+ drawitem(sectionname,0,10)
+
+ local lasti = 0
+ if inoption then
+ for i,v in ipairs(cpath) do
+ drawitem(v,i,20)
+ lasti = i
+ end
+ else
+ for i,v in ipairs(cpath) do
+ drawitem(v.name,i,20)
+ lasti = i
+ end
+ end
+ lasti += 1
+ drawitem('back',lasti,20)
+ drawcursor()
+end
+__gfx__
+77777077777077007077777000000077770077771110000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077077077000000000770770770771771000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77777077777077770077770077770770770777770117100000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077077077000000000770770770770001710000000000000000000000000000000000000000000000000000000000000000000000000000000000
+77000077077077007077777000000777700777700000071000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000001710000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000117100000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000001771000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+
+)#";
\ No newline at end of file
diff --git a/source/FakoTerm.h b/source/FakoTerm.h
deleted file mode 100644
index c4bd6c6..0000000
--- a/source/FakoTerm.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#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 cf7f1fb..0aaa4aa 100644
--- a/source/cart.cpp
+++ b/source/cart.cpp
@@ -22,7 +22,7 @@
#include "FakoBios.h"
-#include "FakoTerm.h"
+#include "FakoSettings.h"
static char const *legacyCompressionLut = "\n 0123456789abcdefghijklmnopqrstuvwxyz!#%(){}[]<>+=/*:;.,~_";
@@ -324,14 +324,14 @@ Cart::Cart(std::string filename, std::string cartDirectory){
std::string firstFourChars = get_first_four_chars(FullCartPath);
- if (FullCartPath == "__FAKE08-BIOS.p8" || FullCartPath == "__FAKE08-TERM.p8" || firstFourChars == "pico"){
+ if (FullCartPath == "__FAKE08-BIOS.p8" || FullCartPath == "__FAKE08-SETTINGS.p8" || firstFourChars == "pico"){
std::string cartStr;
if (FullCartPath == "__FAKE08-BIOS.p8") {
cartStr = fake08BiosP8;
}
- else if (FullCartPath == "__FAKE08-TERM.p8") {
- cartStr = fake08TermP8;
+ else if (FullCartPath == "__FAKE08-SETTINGS.p8") {
+ cartStr = fake08SettingsP8;
}
else {
cartStr = get_file_contents(FullCartPath.c_str());
diff --git a/source/host.h b/source/host.h
index f9b3225..e1e9c64 100644
--- a/source/host.h
+++ b/source/host.h
@@ -6,6 +6,7 @@
#include "hostVmShared.h"
#include "Audio.h"
+
enum StretchOption {
PixelPerfect,
PixelPerfectStretch,
@@ -24,6 +25,10 @@ enum PackinLoadOption {
Loaded
};
#endif
+enum KeyboardOption {
+ Emoji,
+ Lowercase
+};
class Host {
uint8_t currKDown;
@@ -35,10 +40,14 @@ class Host {
bool lDown = false;
bool rDown = false;
bool stretchKeyPressed = false;
+
+
+ //settings
#if LOAD_PACK_INS
PackinLoadOption packinloaded = Unloaded;
#endif
StretchOption stretch = PixelPerfectStretch;
+ KeyboardOption kbmode = Emoji;
float scaleX = 1.0;
float scaleY = 1.0;
diff --git a/source/hostCommonFunctions.cpp b/source/hostCommonFunctions.cpp
index 102c304..8969617 100644
--- a/source/hostCommonFunctions.cpp
+++ b/source/hostCommonFunctions.cpp
@@ -18,6 +18,11 @@ using namespace std;
CSimpleIniA settingsIni;
+std::string defaultIni =
+"[settings]\n"
+"stretch = 1\n"
+"kbmode = 0\n";
+
void Host::setUpPaletteColors(){
_paletteColors[0] = COLOR_00;
_paletteColors[1] = COLOR_01;
@@ -118,18 +123,19 @@ void Host::unpackCarts(){
void Host::loadSettingsIni(){
std::string settingsIniStr = get_file_contents(_logFilePrefix + "settings.ini");
-
+
//File does not exist, fill string with defaults
if(settingsIniStr.length() == 0 ){
#if LOAD_PACK_INS
- settingsIniStr = "[settings]\nstretch = 1\npackinloaded = 0\n";
+ settingsIniStr = defaultIni + "packinloaded = 0\n";
#else
- settingsIniStr = "[settings]\nstretch = 1\n";
+ settingsIniStr = defaultIni;
#endif
}
settingsIni.LoadData(settingsIniStr);
-
+
+ //stretch
long stretchSetting = settingsIni.GetLongValue("settings", "stretch", (long)PixelPerfectStretch);
if (stretchSetting <= (int)AltScreenStretch){
stretch = (StretchOption) stretchSetting;
@@ -139,14 +145,21 @@ void Host::loadSettingsIni(){
long packinloadedSetting = settingsIni.GetLongValue("settings", "packinloaded", (long)Unloaded);
packinloaded = (PackinLoadOption) packinloadedSetting;
#endif
+ //kbmode
+ long kbmodeSetting = settingsIni.GetLongValue("settings", "kbmode", (long)Emoji);
+ kbmode = (KeyboardOption) kbmodeSetting;
}
void Host::saveSettingsIni(){
//write out settings to persist
+
settingsIni.SetLongValue("settings", "stretch", stretch);
+
#if LOAD_PACK_INS
settingsIni.SetLongValue("settings", "packinloaded", packinloaded);
#endif
+ settingsIni.SetLongValue("settings", "kbmode", kbmode);
+
std::string settingsIniStr = "";
settingsIni.Save(settingsIniStr, false);
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index ad1873d..25919b5 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -163,7 +163,7 @@ __f08_menu_items = {
{nil, nil},
{"reset cart", __resetcart},
{"exit to menu", __loadbioscart},
- {"exit to terminal", __loadtermcart}
+ {"exit to settings", __loadsettingscart}
}
__f08_menu_selected = 0
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 6d6e321..7564d81 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -1291,8 +1291,8 @@ int loadbioscart(lua_State *L) {
return 0;
}
-int loadtermcart(lua_State *L) {
- _vmForLuaApi->QueueCartChange("__FAKE08-TERM.p8");
+int loadsettingscart(lua_State *L) {
+ _vmForLuaApi->QueueCartChange("__FAKE08-SETTINGS.p8");
return 0;
}
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index c8a06c8..94116b9 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -96,7 +96,7 @@ int listcarts(lua_State *L);
int getbioserror(lua_State *L);
int loadbioscart(lua_State *L);
-int loadtermcart(lua_State *L);
+int loadsettingscart(lua_State *L);
int togglepausemenu(lua_State *L);
int resetcart(lua_State *L);
diff --git a/source/vm.cpp b/source/vm.cpp
index 7c3fd0e..5d529e9 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -32,7 +32,7 @@
using namespace z8;
static const char BiosCartName[] = "__FAKE08-BIOS.p8";
-static const char TermCartName[] = "__FAKE08-TERM.p8";
+static const char SettingsCartName[] = "__FAKE08-SETTINGS.p8";
Vm::Vm(
Host* host,
@@ -165,7 +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, "__loadsettingscart", loadsettingscart);
lua_register(_luaState, "__togglepausemenu", togglepausemenu);
lua_register(_luaState, "__resetcart", resetcart);
lua_register(_luaState, "load", load);
@@ -317,7 +317,7 @@ bool Vm::loadCart(Cart* cart) {
//customize bios per host's requirements
- if (cart->FullCartPath == BiosCartName || cart->FullCartPath == TermCartName) {
+ if (cart->FullCartPath == BiosCartName || cart->FullCartPath == SettingsCartName) {
std::string customBiosLua = _host->customBiosLua();
if (customBiosLua.length() > 0) {
@@ -351,10 +351,10 @@ void Vm::LoadBiosCart(){
}
}
-void Vm::LoadTermCart(){
+void Vm::LoadSettingsCart(){
CloseCart();
- Cart *cart = new Cart(TermCartName, "");
+ Cart *cart = new Cart(SettingsCartName, "");
bool success = loadCart(cart);
@@ -368,8 +368,8 @@ void Vm::LoadCart(std::string filename){
LoadBiosCart();
return;
}
- if (filename == "__FAKE08-TERM.p8") {
- LoadTermCart();
+ if (filename == "__FAKE08-SETTINGS.p8") {
+ LoadSettingsCart();
return;
}
Logger_Write("Loading cart %s\n", filename.c_str());
diff --git a/source/vm.h b/source/vm.h
index 40be66d..af9e481 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -67,7 +67,7 @@ class Vm {
void LoadBiosCart();
- void LoadTermCart();
+ void LoadSettingsCart();
void LoadCart(string filename);