Skip to content

Commit

Permalink
WIP- celeste is loading from bios
Browse files Browse the repository at this point in the history
  • Loading branch information
jtothebell committed Mar 2, 2024
1 parent e3e5961 commit b488d07
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 44 deletions.
8 changes: 5 additions & 3 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ Graphics::Graphics(std::string fontdata, PicoRam* memory) {


uint8_t* Graphics::GetP8FrameBuffer(){
return _memory->hwState.screenDataMemMapping == 0
? _memory->spriteSheetData
: _memory->screenBuffer;
// return _memory->hwState.screenDataMemMapping == 0
// ? _memory->spriteSheetData
// : _memory->screenBuffer;
//not sure why this memory is wrong? maybe need to fix memory reset on cart load
return _memory->screenBuffer;
}

uint8_t* Graphics::GetP8SpriteSheetBuffer(){
Expand Down
74 changes: 50 additions & 24 deletions source/p8GlobalLuaFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ sub = string.sub
pack = table.pack
unpack = table.unpack
function cartdata(s)
if __cartdata() then
print('cartdata() can only be called once')
abort()
return false
end
-- PICO-8 documentation: id is a string up to 64 characters long
if #s == 0 or #s > 64 then
print('cart data id too long')
abort()
return false
end
-- PICO-8 documentation: legal characters are a..z, 0..9 and underscore (_)
-- PICO-8 changelog: allow '-' in cartdat() names
if string.match(s, '[^-abcdefghijklmnopqrstuvwxyz0123456789_]') then
print('cart data id: bad char')
abort()
return false
end
return __cartdata(s)
end
--Button emoji variables
⬅️ = 0
➡️ = 1
Expand Down Expand Up @@ -384,16 +406,24 @@ end
--todo: make this bettter/verify the list
function __is_api(funcname)
local picofuncnames = {
time = 1, t = 1, sub = 1, chr = 1, ord = 1, tostr = 1, tonum = 1,
add = 1, del = 1, deli = 1, clip = 1, color = 1, pal = 1, palt = 1,
fillp = 1, pget = 1, pset = 1, sget = 1, sset = 1, fget = 1,
fset = 1, circ = 1, circfill = 1, rect = 1, rectfill = 1, oval = 1,
ovalfill = 1, line = 1, spr = 1, sspr = 1, mget = 1, mset = 1,
tline = 1, peek = 1, poke = 1, peek2 = 1, poke2 = 1, peek4 = 1,
poke4 = 1, memcpy = 1, memset = 1, max = 1, min = 1, mid = 1, flr = 1,
ceil = 1, cos = 1, sin = 1, atan2 = 1, rnd = 1, srand = 1, band = 1,
bor = 1, bxor = 1, bnot = 1, shl = 1, shr = 1, lshr = 1, rotl = 1, rotr = 1,
local picofuncnames = {
assert = 1, getmetatable = 1, next = 1, ipairs = 1, pairs = 1, rawequal = 1,
rawlen = 1, rawget = 1, rawset = 1, setmetatable = 1, type = 1, pack = 1, unpack = 1,
load = 1, print = 1,
max = 1, min = 1, mid = 1, ceil = 1, flr = 1, cos = 1, sin = 1, atan2 = 1, sqrt = 1,
abs = 1, sgn = 1, band = 1, bor = 1, bxor = 1, bnot = 1, shl = 1, shr = 1, lshr = 1,
rotl = 1, rotr = 1, tostr = 1, tonum = 1, srand = 1, rnd = 1, ord = 1, chr = 1,
split = 1,
run = 1, reload = 1, dget = 1, dset = 1, peek = 1, peek2 = 1, peek4 = 1,
poke = 1, poke2 = 1, poke4 = 1, memcpy = 1, memset = 1, stat = 1, printh = 1, extcmd = 1,
_update_buttons = 1, btn = 1, btnp = 1, cursor = 1, camera = 1, circ = 1, circfill = 1,
clip = 1, cls = 1, color = 1, fillp = 1, fget = 1, fset = 1, line = 1, map = 1, mget = 1,
mset = 1, oval = 1, ovalfill = 1, pal = 1, palt = 1, pget = 1, pset = 1, rect = 1, rectfill = 1,
serial = 1, sget = 1, sset = 1, spr = 1, sspr = 1, music = 1, sfx = 1, time = 1, tline = 1,
cocreate = 1, coresume = 1, costatus = 1, yield = 1, trace = 1, stop = 1,
count = 1, add = 1, sub = 1, foreach = 1, all = 1, del = 1, deli = 1, t = 1, dget = 1,
dset = 1, cartdata = 1, load = 1, save = 1, info = 1, abort = 1, folder = 1,
resume = 1, reboot = 1, dir = 1, ls = 1, flip = 1, mapdraw = 1, menuitem = 1
}
return picofuncnames[funcname] == 1
end
Expand Down Expand Up @@ -428,6 +458,7 @@ function __z8_reset_cartdata()
end
function __z8_run_cart(cart_code)
printh("run cart func")
local glue_code = [[--
if (_init) _init()
if _update or _update60 or _draw then
Expand All @@ -443,6 +474,7 @@ function __z8_run_cart(cart_code)
_update_buttons()
end
if (_draw and do_frame) _draw()
printh("game loop about to yield")
yield()
end
end
Expand Down Expand Up @@ -518,17 +550,15 @@ function __z8_boot_sequence()
[36] = function() local notes = { 0x.5dde, 0x5deb.5be3, 0x.5fef, 0x.57ef, 0x.53ef }
for j=0,#notes-1 do poke4(0x3200+j*4,notes[j+1]) end poke(0x3241, 0x0a)
sfx(0)
local logo = "###### #### ### ###### #### ### "
.. " ## ## ## ## ## ## ## ## ##"
.. " ### ##### ##### ## ## ## ### ### "
.. " ### ## #### ## ### ## ## ##"
.. "###### ##### ## ## ###### #####"
.. "###### ##### ## ## #### ### "
local logo = "###### ### ## ## #### #### ### "
.. "## ## ## ## ## ## ## ## ## ## "
.. "##### ##### ##### ##### ### ## ## ##### "
.. "## ## ## #### ## ## ## ## ## "
.. "## ## ## ## ## ##### #### ### "
.. " "
for j=0,#logo-1 do pset(j%42,6+j/42,sub(logo,j+1,j+1)=='#'and 7) end
local a = {0,0,12,0,0,0,13,7,11,0,14,7,7,7,10,0,15,7,9,0,0,0,8,0,0}
for j=0,#a-1 do pset(41+j%5,2+j/5,a[j+1]) end end,
[45] = function() color(6) print("\n\n\nzepto-8 0.0.0 alpha") end,
[50] = function() print("(c) 2016-20 sam hocevar et al.\n") end,
end,
[45] = function() color(6) print("\n\n\nfake-08 0.0.0") end,
[52] = function() print("type help for help\n") end,
}
Expand Down Expand Up @@ -560,10 +590,6 @@ local function do_command(cmd)
print_clear('load <filename>')
print_clear('run')
print_clear('')
color(12)
print_clear('example: load #15133')
print_clear(' load #dancer')
print_clear('')
else
color(14)
print_clear('syntax error')
Expand Down
2 changes: 1 addition & 1 deletion source/picoluaapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ int reload(lua_State *L) {
int cartdata(lua_State *L) {
bool result = false;

if (lua_gettop(L) > 0) {
if (lua_gettop(L) > 0 && lua_isstring(L, 1)) {
std::string key = lua_tolstring(L, 1, nullptr);
result = _vmForLuaApi->vm_cartdata(key);
}
Expand Down
31 changes: 15 additions & 16 deletions source/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool _initializeLuaState(lua_State* luaState) {
lua_register(luaState, "__loadsettingscart", loadsettingscart);
lua_register(luaState, "__togglepausemenu", togglepausemenu);
lua_register(luaState, "__resetcart", resetcart);
//lua_register(luaState, "load", load);
lua_register(luaState, "__load", load);

//settings
lua_register(luaState, "__getsetting", getsetting);
Expand Down Expand Up @@ -122,12 +122,12 @@ bool _initializeLuaState(lua_State* luaState) {
lua_register(luaState, "peek2", peek2);
lua_register(luaState, "poke2", poke2);
lua_register(luaState, "peek4", peek4);
lua_register(luaState, "poke4", poke4);
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, "cartdata", cartdata);
lua_register(luaState, "__cartdata", cartdata);
lua_register(luaState, "dget", dget);
lua_register(luaState, "dset", dset);
Expand Down Expand Up @@ -375,16 +375,6 @@ bool Vm::loadCart(Cart* cart) {
_cartChangeQueued = false;
abortLua = false;

Logger_Write("getting global z8 run cart\n");
// Load cartridge code and call __z8_run_cart() on it
lua_getglobal(_luaState, "__z8_run_cart");
Logger_Write("got global z8 run cart\n");
lua_pushstring(_luaState, cart->LuaString.c_str());
Logger_Write("pushed cart lua string\n");
lua_pcall(_luaState, 1, 0, 0);
Logger_Write("called z8 run cart\n");



//customize bios per host's requirements
if (cart->FullCartPath == DefaultCartName || cart->FullCartPath == SettingsCartName) {
Expand Down Expand Up @@ -1074,9 +1064,13 @@ void Vm::update_buttons() {
// }

void Vm::vm_run() {
if (_loadedCart) {
loadCart(_loadedCart);
}
// if (_loadedCart) {
// loadCart(_loadedCart);
// }

lua_getglobal(_luaState, "__z8_run_cart");
lua_pushstring(_luaState, _loadedCart->LuaString.c_str());
lua_pcall(_luaState, 1, 0, 0);
}

void Vm::vm_extcmd(std::string cmd){
Expand All @@ -1099,6 +1093,11 @@ void Vm::vm_load(std::string filename, std::string breadcrumb, std::string param
}

QueueCartChange(filename);
LoadCart(_nextCartKey);


//todo: don't call this here? probably need to change load to not clear out some memory?
vm_run();
}

void Vm::vm_reset(){
Expand Down

0 comments on commit b488d07

Please sign in to comment.