Skip to content

Commit

Permalink
WIP- zepto bios loading and running
Browse files Browse the repository at this point in the history
  • Loading branch information
jtothebell committed Jan 15, 2024
1 parent 226dac5 commit d8a2606
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
7 changes: 3 additions & 4 deletions platform/SDL2Desktop/source/SDL2Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion source/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Host {
Color _paletteColors[144];

public:
Host();
Host(int windowWidth = 0, int windowHeight = 0);

void setUpPaletteColors();
void oneTimeSetup(Audio* audio);
Expand Down
2 changes: 1 addition & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 18 additions & 2 deletions source/p8GlobalLuaFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions source/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit d8a2606

Please sign in to comment.