From 66bbdea85f5dafc776d4f3cc9168301132d1fdc1 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Wed, 8 Dec 2021 09:18:42 +0100 Subject: [PATCH] [BUG] memcpy minor bug [FEAT] boot sequence --- ascii.cpp | 8 ++++---- lua.cpp | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ascii.cpp b/ascii.cpp index 1bd026d..35daa69 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -133,7 +133,7 @@ int main(int argc,char*argv[]) { romcpy(); reinit(); debug("ASCII SYSTEM BOOTING..."); - lua_init(lua_filename); + lua_init(NULL); lua_call_init(); while(!exit) { @@ -472,8 +472,8 @@ void poke(uint16_t addr, uint8_t val) { } void memcpy(uint16_t dst, uint16_t src, uint16_t size) { - if (dst <= src) return; - if (src+size>=dst) return; + if ((dst<=src) && (dst+size>=src)) return; + if ((dst>=src) && (src+size>=dst)) return; SDL_memcpy(&mem[dst], &mem[src], size); } @@ -496,7 +496,7 @@ void setmode(const uint8_t mode) { } void load(const char* str) { - SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1); + if (str!=NULL) SDL_strlcpy(lua_filename, str, SDL_strlen(str)+1); should_reset = true; } diff --git a/lua.cpp b/lua.cpp index f41db62..ef1c027 100644 --- a/lua.cpp +++ b/lua.cpp @@ -227,7 +227,7 @@ extern "C" { } static int cpp_load(lua_State *L) { - const char* str = luaL_checkstring(L, 1); + const char* str = luaL_optstring(L, 1, NULL); load(str); return 0; } @@ -268,18 +268,30 @@ bool lua_is_playing() { return lua_state == STATE_PLAYING; } +const char boot[] = "function init()setmode(1)cls()memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(8)print('v0.5.1',26,8)w=0 end function update()w=w+1 if w>90 then cls()load()end end"; + void lua_init(const char* filename, const bool start_playing) { if (lua_state != STATE_STOPPED) lua_quit(); L = luaL_newstate(); init_exists = update_exists = false; bool file_loaded = true; - if (luaL_loadfile(L, filename)) { - debug("ERROR LOADING GAME"); - debug(lua_tostring(L, -1)); - lua_pop(L,1); - setmode(0); - file_loaded = false; + if (filename == NULL) { + if (luaL_loadstring(L, boot)) { + debug("BOOT ERROR"); + debug(lua_tostring(L, -1)); + lua_pop(L,1); + setmode(0); + file_loaded = false; + } + } else { + if (luaL_loadfile(L, filename)) { + debug("ERROR LOADING GAME"); + debug(lua_tostring(L, -1)); + lua_pop(L,1); + setmode(0); + file_loaded = false; + } } lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls");