commit d8a2606dbd4bf8b2960bfa7bb7c75ce35e00e838
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Mon Jan 15 11:11:35 2024 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Mon Jan 15 11:11:35 2024 -0700
WIP- zepto bios loading and running
---
platform/SDL2Desktop/source/SDL2Host.cpp | 7 +++----
source/host.h | 2 +-
source/main.cpp | 2 +-
source/p8GlobalLuaFunctions.h | 20 ++++++++++++++++++--
source/vm.cpp | 9 +++------
5 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/platform/SDL2Desktop/source/SDL2Host.cpp b/platform/SDL2Desktop/source/SDL2Host.cpp
index ff308f1..35dd687 100644
--- a/platform/SDL2Desktop/source/SDL2Host.cpp
+++ b/platform/SDL2Desktop/source/SDL2Host.cpp
@@ -43,9 +43,8 @@ string _desktopSdl2customBiosLua = "cartpath = \"~/p8carts/\"\n"
"exitbtn = \"close window\"\n"
"sizebtn = \"\"";
-Host::Host()
+Host::Host(int windowWidth, int windowHeight)
{
-
SDL_DisplayMode current;
SDL_Init(SDL_INIT_VIDEO);
@@ -62,8 +61,8 @@ Host::Host()
SDL_Log("Display #%d: current display mode is %dx%dpx @ %dhz.", 0, current.w, current.h, current.refresh_rate);
}
- int WINDOW_SIZE_X=current.w;
- int WINDOW_SIZE_Y=current.h;
+ int WINDOW_SIZE_X=windowWidth == 0 ? current.w : windowWidth;
+ int WINDOW_SIZE_Y=windowHeight == 0 ? current.h : windowHeight;
struct stat st = {0};
diff --git a/source/host.h b/source/host.h
index 9af8a66..b7c2948 100644
--- a/source/host.h
+++ b/source/host.h
@@ -97,7 +97,7 @@ class Host {
Color _paletteColors[144];
public:
- Host();
+ Host(int windowWidth = 0, int windowHeight = 0);
void setUpPaletteColors();
void oneTimeSetup(Audio* audio);
diff --git a/source/main.cpp b/source/main.cpp
index e669fed..c331048 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -20,7 +20,7 @@
int main(int argc, char* argv[])
{
- Host *host = new Host();
+ Host *host = new Host(780, 780);
PicoRam *memory = new PicoRam();
Audio *audio = new Audio(memory);
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index 5f836b5..b9b9f80 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -341,6 +341,23 @@ eris.restore_all = function(persisted)
end
end
+function __z8_strlen(s)
+ return #string.gsub(s, '[\128-\255]', 'XX')
+end
+
+-- Stubs for unimplemented functions
+local function stub(s)
+ return function(a) __stub(s.."("..(a and '"'..tostr(a)..'"' or "")..")") end
+end
+save = stub("save")
+info = stub("info")
+abort = stub("abort")
+folder = stub("folder")
+resume = stub("resume")
+reboot = stub("reboot")
+dir = stub("dir")
+ls = dir
+
function flip()
_update_buttons()
yield()
@@ -478,8 +495,7 @@ function __z8_tick()
if __z8_stopped then
__z8_stopped = false -- FIXME: what now?
elseif not ret then
- -- FIXME: I use __stub because printh() prints nothing in Visual Studio
- __stub(tostr(err))
+ printh(tostr(err))
end
return 0
end
diff --git a/source/vm.cpp b/source/vm.cpp
index 0de0ec1..aa5fcdc 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -249,7 +249,9 @@ bool Vm::Initialize() {
//load in global lua fuctions for pico 8- part of this is setting a local variable
//with the same name as all the globals we just registered
//auto convertedGlobalLuaFunctions = convert_emojis(p8GlobalLuaFunctions);
+
auto convertedP8Bios = charset::utf8_to_pico8(p8Bios);
+
int loadedBiosResult = luaL_dostring(_luaState, convertedP8Bios.c_str());
if (loadedBiosResult != LUA_OK) {
@@ -740,24 +742,21 @@ void Vm::deserializeCartDataToMemory(std::string cartDataStr) {
}
bool Vm::Step(){
- Logger_Write("getting __z8_tick\n");
bool ret = false;
lua_getglobal(_luaState, "__z8_tick");
int status = lua_pcall(_luaState, 0, 1, 0);
if (status != LUA_OK)
{
- Logger_Write("error calling tick");
char const *message = lua_tostring(_luaState, -1);
+ Logger_Write("error calling tick function: %s\n", message);
_cartLoadError = "Error in main loop: " + std::string(message);
}
else
{
- Logger_Write("successfully called __z8_tick\n");
ret = (int)lua_tonumber(_luaState, -1) >= 0;
}
lua_pop(_luaState, 1);
- Logger_Write("end of Step()\n");
return ret;
}
@@ -929,13 +928,11 @@ void Vm::GameLoop() {
//it should update call the pico part of scanInput and set the values in memory
//then we don't need to pass them in here
//UpdateAndDraw();
- Logger_Write("Step()");
Step();
uint8_t* picoFb = GetPicoInteralFb();
uint8_t* screenPaletteMap = GetScreenPaletteMap();
- Logger_Write("drawframe()");
_host->drawFrame(picoFb, screenPaletteMap, _memory->drawState.drawMode);
if (_host->shouldFillAudioBuff()) {