commit f35148e09746b5869f1ad8365036fc1ae0be6a7d
Author: DPS2004 <dpsophinos@gmail.com>
AuthorDate: Thu Mar 17 15:05:11 2022 -0400
Commit: DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon May 2 09:40:37 2022 -0400
add function to read label images to sprite data
(does not support .p8.png files, as they have no __label__ section)
---
source/FakoSettings.h | 20 +++++-
source/NoLabel.h | 135 +++++++++++++++++++++++++++++++++++++++++
source/cart.cpp | 2 +
source/cart.h | 2 +-
source/host.h | 10 +++
source/hostCommonFunctions.cpp | 36 ++++++++++-
source/picoluaapi.cpp | 15 +++++
source/picoluaapi.h | 4 ++
source/stringToDataHelpers.cpp | 42 +++++++++++++
source/stringToDataHelpers.h | 2 +
source/vm.cpp | 24 +++++++-
source/vm.h | 3 +
12 files changed, 288 insertions(+), 7 deletions(-)
diff --git a/source/FakoSettings.h b/source/FakoSettings.h
index 50d2aeb..83613e9 100644
--- a/source/FakoSettings.h
+++ b/source/FakoSettings.h
@@ -15,7 +15,6 @@ __lua__
--showpackinoptions = true
function _init()
-
if not __getsetting then
printh('not in fake-08 (or unimplemented...), stubbing get and set functions!')
function __getsetting(sn)
@@ -27,7 +26,18 @@ function _init()
printh('trying to set setting ' .. sn .. ' to '..v)
end
+ function refreshcolors()
+ pal(1, 1)
+ pal(7, 7)
+ end
+
+ else
+ function refreshcolors()
+ pal(1, __getsetting('p8_bgcolor'))
+ pal(7, __getsetting('p8_textcolor'))
+ end
end
+ refreshcolors()
settinglist = {'kbmode','resizekey','stretch','menustyle','bgcolor'}
settings = {}
@@ -67,7 +77,7 @@ function _init()
{
name = 'bg color',
vn = 'bgcolor',
- ch ={'gray','black','blue','green'}
+ ch ={'gray','black','blue','green','purple','white'}
}
}}
}
@@ -175,6 +185,9 @@ function updatecursor()
if inoption then
settings[cvariable] = cursorpos
__setsetting(cvariable,cursorpos-1)
+ if cvariable == 'bgcolor' then
+ refreshcolors()
+ end
else
add(path,cursorpos)
end
@@ -210,7 +223,8 @@ function drawcursor()
end
function _draw()
- cls(1)
+ cls()
+ rectfill(0,0,128,128,1)
spr(0,1,1,5,1)
diff --git a/source/NoLabel.h b/source/NoLabel.h
new file mode 100644
index 0000000..905feb0
--- /dev/null
+++ b/source/NoLabel.h
@@ -0,0 +1,135 @@
+#pragma once
+
+#include <string>
+
+
+const char * NoLabelString = R"#(
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66665555555555556666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666665555666655556666
+66665555555555556666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666665555666655556666
+66665555555555556666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666665555666655556666
+66665555555555556666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666665555666655556666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666555566666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666555566666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666668888888888888888888822226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666662222222222222222222222226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666662222222222222222222222226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666662222222222222222222222226666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666662222222222222222222222226666666666666666666666666666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+6666666666666666666666666666999999999999999999994444777777777777777777776666ffffffffffffffffffff44446666666666666666666666666666
+66666666666666666666666666664444444444444444444444447777777777777777777766664444444444444444444444446666666666666666666666666666
+66666666666666666666666666664444444444444444444444447777777777777777777766664444444444444444444444446666666666666666666666666666
+66666666666666666666666666664444444444444444444444447777777777777777777766664444444444444444444444446666666666666666666666666666
+66666666666666666666666666664444444444444444444444447777777777777777777766664444444444444444444444446666666666666666666666666666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+6666aaaaaaaaaaaaaaaaaaaa9999777777777777777777777777777777777777777777777777777777777777777777776666eeeeeeeeeeeeeeeeeeee88886666
+66669999999999999999999999996666666666666666666666667777777777777777777766666666666666666666666666668888888888888888888888886666
+66669999999999999999999999996666666666666666666666667777777777777777777766666666666666666666666666668888888888888888888888886666
+66669999999999999999999999996666666666666666666666667777777777777777777766666666666666666666666666668888888888888888888888886666
+66669999999999999999999999996666666666666666666666667777777777777777777766666666666666666666666666668888888888888888888888886666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+6666666666666666666666666666bbbbbbbbbbbbbbbbbbbb3333777777777777777777776666dddddddddddddddddddd11116666666666666666666666666666
+66666666666666666666666666663333333333333333333333336666666666666666666666661111111111111111111111116666666666666666666666666666
+66666666666666666666666666663333333333333333333333336666666666666666666666661111111111111111111111116666666666666666666666666666
+66666666666666666666666666663333333333333333333333336666666666666666666666661111111111111111111111116666666666666666666666666666
+66666666666666666666666666663333333333333333333333336666666666666666666666661111111111111111111111116666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666666666666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666666666666666
+6666666655556666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666666666555566666666
+6666555566665555666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666665555555555556666
+6666555566665555666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666665555555555556666
+6666555566665555666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666665555555555556666
+6666555566665555666666666666666666666666666666666666ccccccccccccccccccccdddd6666666666666666666666666666666666665555555555556666
+6666666655556666666666666666666666666666666666666666dddddddddddddddddddddddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666dddddddddddddddddddddddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666dddddddddddddddddddddddd6666666666666666666666666666666666666666555566666666
+6666666655556666666666666666666666666666666666666666dddddddddddddddddddddddd6666666666666666666666666666666666666666555566666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
+)#";
\ No newline at end of file
diff --git a/source/cart.cpp b/source/cart.cpp
index 0aaa4aa..0383df3 100644
--- a/source/cart.cpp
+++ b/source/cart.cpp
@@ -570,3 +570,5 @@ void Cart::setSfx(std::string sfxString) {
sfxIdx++;
}
}
+
+
diff --git a/source/cart.h b/source/cart.h
index 564916e..b5f9551 100644
--- a/source/cart.h
+++ b/source/cart.h
@@ -35,7 +35,7 @@ class Cart {
void setMusic(std::string musicString);
bool loadCartFromPng(std::string filename);
-
+
public:
Cart (std::string filename, std::string cartDirectory);
~Cart();
diff --git a/source/host.h b/source/host.h
index 2599050..c80ee75 100644
--- a/source/host.h
+++ b/source/host.h
@@ -37,6 +37,15 @@ enum KeyboardOption {
Lowercase
};
+enum BgColorOption {
+ Gray,
+ Black,
+ Blue,
+ Green,
+ Purple,
+ White
+};
+
class Host {
uint8_t currKDown;
uint8_t currKHeld;
@@ -56,6 +65,7 @@ class Host {
StretchOption stretch = PixelPerfectStretch;
KeyboardOption kbmode = Emoji;
ResizekeyOption resizekey = NoResize;
+ BgColorOption bgcolor = Gray;
float scaleX = 1.0;
float scaleY = 1.0;
diff --git a/source/hostCommonFunctions.cpp b/source/hostCommonFunctions.cpp
index d5c4d2f..e8eb978 100644
--- a/source/hostCommonFunctions.cpp
+++ b/source/hostCommonFunctions.cpp
@@ -22,7 +22,8 @@ std::string defaultIni =
"[settings]\n"
"stretch = 1\n"
"resizekey = 0\n"
-"kbmode = 0\n";
+"kbmode = 0\n"
+"bgcolor = 0\n";
void Host::setUpPaletteColors(){
_paletteColors[0] = COLOR_00;
@@ -155,7 +156,9 @@ void Host::loadSettingsIni(){
long kbmodeSetting = settingsIni.GetLongValue("settings", "kbmode", (long)Emoji);
kbmode = (KeyboardOption) kbmodeSetting;
-
+ //bgcolor
+ long bgcolorSetting = settingsIni.GetLongValue("settings", "bgcolor", (long)Gray);
+ bgcolor = (BgColorOption) bgcolorSetting;
}
void Host::saveSettingsIni(){
@@ -170,6 +173,7 @@ void Host::saveSettingsIni(){
settingsIni.SetLongValue("settings", "resizekey", resizekey);
settingsIni.SetLongValue("settings", "kbmode", kbmode);
+ settingsIni.SetLongValue("settings", "bgcolor", bgcolor);
std::string settingsIniStr = "";
settingsIni.Save(settingsIniStr, false);
@@ -220,6 +224,31 @@ int Host::getSetting(std::string sname) {
}else if(sname == "stretch"){
Logger_Write("Returning Stretch setting\n");
return stretch;
+ }else if(sname == "bgcolor"){
+ Logger_Write("Returning bg color setting\n");
+ return bgcolor;
+ }else if(sname == "p8_bgcolor"){
+
+ Logger_Write("Returning pico 8 bg color setting\n");
+ std::string bgcolorstr = std::to_string(bgcolor) + "\n";
+ Logger_Write(bgcolorstr.c_str());
+ switch(bgcolor)
+ {
+ case Gray: return 05;
+ case Black: return 00;
+ case Blue: return 01;
+ case Green: return 03;
+ case Purple: return 13;
+ case White: return 07;
+ default: return 02;
+ }
+ }else if(sname == "p8_textcolor"){
+ Logger_Write("Returning pico 8 text color setting\n");
+ if(bgcolor == White){
+ return 0;
+ }else{
+ return 7;
+ }
}else{
Logger_Write("Setting ");
Logger_Write(sname.c_str());
@@ -247,6 +276,9 @@ void Host::setSetting(std::string sname, int sval) {
//force change stretch
forceStretch(stretch);
+ }else if(sname == "bgcolor"){
+ Logger_Write("setting bgcolor\n");
+ bgcolor = (BgColorOption) sval;
}else{
Logger_Write("Setting ");
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 432e6f9..6dd642e 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -1344,4 +1344,19 @@ int setsetting(lua_State *L) {
_vmForLuaApi->setSetting(str,sval);
return 1;
+}
+
+int loadlabel(lua_State *L) {
+
+ const char * cartname = "";
+ if (lua_isstring(L, 1)){
+ cartname = lua_tolstring(L, 1, nullptr);
+ }
+ std::string filename = cartname;
+
+ bool mini = lua_toboolean(L,2);
+ int minioffset = lua_tonumber(L,3);
+
+ _vmForLuaApi->loadLabel(filename, mini, minioffset);
+ return 1;
}
\ No newline at end of file
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index 88056d7..ff91ba4 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -105,6 +105,10 @@ int resetcart(lua_State *L);
int getsetting(lua_State *L);
int setsetting(lua_State *L);
+//label
+
+int loadlabel(lua_State *L);
+
//system functions
int rnd(lua_State *L);
diff --git a/source/stringToDataHelpers.cpp b/source/stringToDataHelpers.cpp
index bddfcdf..36008d5 100644
--- a/source/stringToDataHelpers.cpp
+++ b/source/stringToDataHelpers.cpp
@@ -2,6 +2,8 @@
#include "stringToDataHelpers.h"
+#include "logger.h"
+
void copy_string_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string data) {
uint16_t i = 0;
@@ -27,6 +29,46 @@ void copy_string_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string dat
}
}
+void copy_mini_label_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string data, int labeloffset) {
+ int buffcount = 0;
+ int labelx = 0;
+ int labely = 0;
+ char buf[3] = {0};
+
+ for (size_t n = 0; n < data.length(); n++) {
+
+ if (data[n] > ' ') {
+
+ if (buffcount == 0) {
+ buf[1] = data[n];
+ }
+
+ if (buffcount == 4) {
+ buf[0] = data[n];
+ uint8_t val = (uint8_t)strtol(buf, NULL, 16);
+ if ((labelx + (labely * 16)) % 64 <= 15){
+ sprite_data[labeloffset + labelx + (labely * 16)] = val;
+ }
+ labelx++;
+
+ }
+
+ if(labelx == 16){
+ labely++;
+ labelx = 0;
+ }
+
+ buffcount++;
+
+ if (buffcount == 8){
+ buffcount = 0;
+ }
+
+ }
+ }
+}
+
+
void copy_string_to_memory(uint8_t* sprite_flag_data, std::string data) {
uint16_t i = 0;
diff --git a/source/stringToDataHelpers.h b/source/stringToDataHelpers.h
index 290a646..dfa8336 100644
--- a/source/stringToDataHelpers.h
+++ b/source/stringToDataHelpers.h
@@ -4,4 +4,6 @@
void copy_string_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string data);
+void copy_mini_label_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string data, int labeloffset);
+
void copy_string_to_memory(uint8_t* sprite_flag_data, std::string data);
\ No newline at end of file
diff --git a/source/vm.cpp b/source/vm.cpp
index 584e29c..675b742 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -15,6 +15,7 @@
#include "graphics.h"
#include "fontdata.h"
#include "cart.h"
+#include "stringToDataHelpers.h"
#include "picoluaapi.h"
#include "logger.h"
#include "Input.h"
@@ -22,6 +23,8 @@
#include "hostVmShared.h"
#include "emojiconversion.h"
+#include "NoLabel.h"
+
//extern "C" {
#include <lua.h>
#include <lualib.h>
@@ -173,7 +176,9 @@ bool Vm::loadCart(Cart* cart) {
//settings
lua_register(_luaState, "__getsetting", getsetting);
lua_register(_luaState, "__setsetting", setsetting);
-
+ //label
+ lua_register(_luaState, "__loadlabel", loadlabel);
+
//register global functions first, they will get local aliases when
//the rest of the api is registered
//graphics
@@ -1068,4 +1073,21 @@ void Vm::setSetting(std::string sname, int sval) {
_host->setSetting(sname,sval);
+}
+
+void Vm::loadLabel(std::string filename, bool mini, int minioffset) {
+
+ auto cartDir = _host->getCartDirectory();
+ Cart *labelcart = new Cart(filename, cartDir);
+ std::string labelstr = labelcart->LabelString;
+ if(labelstr.length() == 0){
+ labelstr = NoLabelString;
+ }
+ if (mini) {
+ copy_mini_label_to_sprite_memory(_memory->spriteSheetData, labelstr, minioffset);
+ } else {
+ copy_string_to_sprite_memory(_memory->spriteSheetData, labelstr);
+ }
+ delete labelcart;
+
}
\ No newline at end of file
diff --git a/source/vm.h b/source/vm.h
index 9d6e5ce..cef96d9 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -149,6 +149,9 @@ class Vm {
//settings
int getSetting(string sname);
void setSetting(string sname, int sval);
+
+ //label
+ void loadLabel(string filename, bool mini, int minioffset);
string getCartBreadcrumb();
string getCartParam();