Skip to content

Commit

Permalink
WIP- Fix lots of build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jtothebell committed Jan 15, 2024
1 parent d8a2606 commit 59f06d6
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 236 deletions.
2 changes: 1 addition & 1 deletion platform/3ds/source/3dsHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void audioSetup(){



Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
_logFilePrefix = "sdmc:/3ds/fake08/";

_cartDirectory = "/p8carts";
Expand Down
2 changes: 1 addition & 1 deletion platform/bittboy/source/BittBoyHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void _changeStretch(StretchOption newStretch){



Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
#ifdef _BITTBOY
_cartDirectory = "/mnt/roms/PICO-8";
_logFilePrefix = "/mnt/emus/pico8/";
Expand Down
2 changes: 1 addition & 1 deletion platform/funkey-s/source/FunkeyHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void audioSetup(){
}


Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
#ifdef _BITTBOY
_cartDirectory = "/mnt/roms/PICO-8";
#else
Expand Down
2 changes: 1 addition & 1 deletion platform/gcw0/source/ODHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void _changeStretch(StretchOption newStretch){



Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
#ifdef _GCW0
_cartDirectory = "/media/sdcard/roms/PICO8";
_logFilePrefix = "/media/sdcard/roms/PICO8/";
Expand Down
2 changes: 1 addition & 1 deletion platform/libretro/libretrohost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void setCartDirectory(std::string dir) {



Host::Host() { }
Host::Host(int windowWidth, int windowHeight) { }


void Host::oneTimeSetup(Audio* audio){
Expand Down
2 changes: 1 addition & 1 deletion platform/miyoomini/source/MiyooMiniHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void _changeStretch(StretchOption newStretch){



Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
#ifdef _DESKTOP
std::string home = getenv("HOME");

Expand Down
2 changes: 1 addition & 1 deletion platform/switch/source/SwitchHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ uint8_t ConvertInputToP8(u64 input){
return result;
}

Host::Host()
Host::Host(int windowWidth, int windowHeight)
{
struct stat st = {0};

Expand Down
2 changes: 1 addition & 1 deletion platform/vita/source/VitaHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ string _desktopSdl2customBiosLua = "cartpath = \"ux0:/p8carts/\"\n"
"pausebtn = \"start\"";


Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
//make sure directories exists
sceIoMkdir("ux0:/data/", 0777);
sceIoMkdir("ux0:/data/fake08/", 0777);
Expand Down
2 changes: 1 addition & 1 deletion platform/wiiu/source/WiiUHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void _changeStretch(StretchOption newStretch){
flip = SDL_FLIP_NONE;
}

Host::Host() {
Host::Host(int windowWidth, int windowHeight) {
struct stat st = {0};

int res = chdir("fs:/vol/external01");
Expand Down
2 changes: 1 addition & 1 deletion platform/windows/source/WindowsHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ string _desktopSdl2customBiosLua = "cartpath = \"AppData\"\n"



Host::Host()
Host::Host(int windowWidth, int windowHeight)
{
struct stat st = {0};

Expand Down
1 change: 1 addition & 0 deletions source/fontdata.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <cstdint>

std::string get_font_data();

Expand Down
1 change: 1 addition & 0 deletions source/nibblehelpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <cstdint>

//for 1 byte (8 bit) indexes, 128x64
//should be the equivalent of return y * 64 + (x / 2);
Expand Down
1 change: 1 addition & 0 deletions source/stringToDataHelpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <cstdint>

void copy_string_to_sprite_memory(uint8_t sprite_data[128 * 64], std::string data);

Expand Down
171 changes: 2 additions & 169 deletions source/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ bool Vm::Initialize() {

//stubbed in graphics:
lua_register(_luaState, "fillp", fillp);
//lua_register(_luaState, "flip", flip);

//input
lua_register(_luaState, "btn", btn);
Expand Down Expand Up @@ -328,144 +327,6 @@ bool Vm::loadCart(Cart* cart) {
_cartChangeQueued = false;
abortLua = false;

// initialize Lua interpreter
_luaState = luaL_newstate();

lua_setpico8memory(_luaState, (uint8_t *)&_memory->data);
// load Lua base libraries (print / math / etc)
luaL_openlibs(_luaState);
lua_pushglobaltable(_luaState);

//system
//must be registered before loading globals for pause menu to work
lua_register(_luaState, "__listcarts", listcarts);
lua_register(_luaState, "__getbioserror", getbioserror);
lua_register(_luaState, "__loaddefaultcart", loaddefaultcart);
lua_register(_luaState, "__loadsettingscart", loadsettingscart);
lua_register(_luaState, "__togglepausemenu", togglepausemenu);
lua_register(_luaState, "__resetcart", resetcart);
//lua_register(_luaState, "load", load);

//settings
lua_register(_luaState, "__getsetting", getsetting);
lua_register(_luaState, "__setsetting", setsetting);

lua_register(_luaState, "__installpackins", installpackins);

//label
lua_register(_luaState, "__loadlabel", loadlabel);

lua_register(_luaState, "__getlualine", getlualine);

//register global functions first, they will get local aliases when
//the rest of the api is registered
//graphics
lua_register(_luaState, "cls", cls);
lua_register(_luaState, "pset", pset);
lua_register(_luaState, "pget", pget);
lua_register(_luaState, "color", color);
lua_register(_luaState, "line", line);
lua_register(_luaState, "tline", tline);
lua_register(_luaState, "circ", circ);
lua_register(_luaState, "circfill", circfill);
lua_register(_luaState, "oval", oval);
lua_register(_luaState, "ovalfill", ovalfill);
lua_register(_luaState, "rect", rect);
lua_register(_luaState, "rectfill", rectfill);
lua_register(_luaState, "print", print);
lua_register(_luaState, "cursor", cursor);
lua_register(_luaState, "spr", spr);
lua_register(_luaState, "sspr", sspr);
lua_register(_luaState, "fget", fget);
lua_register(_luaState, "fset", fset);
lua_register(_luaState, "sget", sget);
lua_register(_luaState, "sset", sset);
lua_register(_luaState, "camera", camera);
lua_register(_luaState, "clip", clip);

lua_register(_luaState, "pal", pal);
lua_register(_luaState, "palt", palt);

lua_register(_luaState, "mget", mget);
lua_register(_luaState, "mset", mset);
lua_register(_luaState, "map", gfx_map);
lua_register(_luaState, "mapdraw", gfx_map);

//stubbed in graphics:
lua_register(_luaState, "fillp", fillp);
//lua_register(_luaState, "flip", flip);

//input
lua_register(_luaState, "btn", btn);
lua_register(_luaState, "btnp", btnp);

lua_register(_luaState, "time", time);
lua_register(_luaState, "t", time);

//audio:
lua_register(_luaState, "music", music);
lua_register(_luaState, "sfx", sfx);

//memory
lua_register(_luaState, "cstore", cstore);
lua_register(_luaState, "memcpy", api_memcpy);
lua_register(_luaState, "memset", api_memset);
lua_register(_luaState, "peek", peek);
lua_register(_luaState, "poke", poke);
lua_register(_luaState, "peek2", peek2);
lua_register(_luaState, "poke2", poke2);
lua_register(_luaState, "peek4", peek4);
lua_register(_luaState, "poke4", poke4);
lua_register(_luaState, "reload", reload);
lua_register(_luaState, "reset", reset);

//cart data
lua_register(_luaState, "cartdata", cartdata);
lua_register(_luaState, "dget", dget);
lua_register(_luaState, "dset", dset);

//
lua_register(_luaState, "printh", printh);
lua_register(_luaState, "stat", stat);
lua_register(_luaState, "_update_buttons", _update_buttons);
lua_register(_luaState, "run", run);
lua_register(_luaState, "extcmd", extcmd);
lua_register(_luaState, "_set_fps", setFps);

//rng
lua_register(_luaState, "rnd", rnd);
lua_register(_luaState, "srand", srand);

//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 convertedGlobalLuaFunctions = charset::utf8_to_pico8(p8Bios);
int loadedGlobals = luaL_dostring(_luaState, convertedGlobalLuaFunctions.c_str());

if (loadedGlobals != LUA_OK) {
_cartLoadError = "ERROR loading pico 8 lua globals";
Logger_Write("ERROR loading pico 8 lua globals\n");
Logger_Write("Error: %s\n", lua_tostring(_luaState, -1));
lua_pop(_luaState, 1);

return false;
}

// Push the eris.init_persist_all function on the top of the lua stack (or nil if it doesn't exist)
// we call this function to establish the default global state of things not to save in the save state
// needs to be called after globals are loaded but before the cart is run, or _init is called
//TODO: move these calls to the glue code?
lua_getglobal(_luaState, "eris");
lua_getfield(_luaState, -1, "init_persist_all");

if (lua_pcall(_luaState, 0, 0, 0)){
Logger_Write("Error setting up lua persistence: %s\n", lua_tostring(_luaState, -1));
lua_pop(_luaState, 1);
return false;
}

//pop the eris.init_persist_all fuction off the stack now that we're done with it
lua_pop(_luaState, 1);

//need to add game loop to the bottom of the cart code
const char* gameLoop = R"#(
Expand Down Expand Up @@ -533,34 +394,6 @@ end

#endif

// Push the _init function on the top of the lua stack (or nil if it doesn't exist)
// lua_getglobal(_luaState, "_init");

// if (lua_isfunction(_luaState, -1)) {
// if (lua_pcall(_luaState, 0, 0, 0)){
// _cartLoadError = lua_tostring(_luaState, -1);
// Logger_Write("Error: %s\n", lua_tostring(_luaState, -1));
// lua_pop(_luaState, 1);
// QueueCartChange(BiosCartName);
// return false;
// }
// }

// //pop the _init fuction off the stack now that we're done with it
// lua_pop(_luaState, 0);



//check for update, mark correct target fps
// lua_getglobal(_luaState, "_update60");
// if (lua_isfunction(_luaState, -1)) {
// _targetFps = 60;
// }
// else {
// _targetFps = 30;
// }
// lua_pop(_luaState, 0);


//customize bios per host's requirements
if (cart->FullCartPath == DefaultCartName || cart->FullCartPath == SettingsCartName) {
Expand Down Expand Up @@ -920,9 +753,9 @@ void Vm::GameLoop() {
//is this better at the end of the loop?
//_host->waitForTargetFps();

//if (_host->shouldQuit()) break; // break in order to return to hbmenu
if (_host->shouldQuit()) break; // break in order to return to hbmenu
//this should probably be handled just in the host class
//_host->changeStretch();
_host->changeStretch();

//update buttons needs to be callable from the cart, and also flip
//it should update call the pico part of scanInput and set the values in memory
Expand Down
2 changes: 1 addition & 1 deletion test/cartloadingtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ string checkCart(Vm* vm, string cartDirectory, string cart){
}
else
{
vm->UpdateAndDraw();
vm->Step();

if (vm->GetBiosError() != "") {
vm->GetBiosError();
Expand Down
Loading

0 comments on commit 59f06d6

Please sign in to comment.