[BUG] memcpy minor bug
[FEAT] boot sequence
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
14
lua.cpp
14
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,12 +268,23 @@ 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 (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));
|
||||
@@ -281,6 +292,7 @@ void lua_init(const char* filename, const bool start_playing) {
|
||||
setmode(0);
|
||||
file_loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushcfunction(L,cpp_cls); lua_setglobal(L, "cls");
|
||||
lua_pushcfunction(L,cpp_ink); lua_setglobal(L, "ink");
|
||||
|
||||
Reference in New Issue
Block a user