From b47c5a9cf7c06aa58b41f813cb388cf10a6ac403 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 29 Jul 2008 00:42:02 +0000 Subject: [PATCH] --- output/{ => luapack}/luapack.zip | Bin 634205 -> 632997 bytes src/auxlib.lua | 192 +++++++++++++++++++++++++++++++ src/lua-engine.cpp | 191 ++++++++++++++++-------------- vc8/archive.bat | 2 + vc8/fceux.vcproj | 22 ++++ vc8/upload.bat | 3 +- 6 files changed, 321 insertions(+), 89 deletions(-) rename output/{ => luapack}/luapack.zip (99%) create mode 100644 src/auxlib.lua diff --git a/output/luapack.zip b/output/luapack/luapack.zip similarity index 99% rename from output/luapack.zip rename to output/luapack/luapack.zip index 10aca5e49c34adde76fd75544036bc427643001b..fc0e90414e3b4164347d0f425316d4dbfad75e0d 100644 GIT binary patch delta 54 zcmcb6OKs^zwT2eP7N!>F7M2#)7Pc1l7LF~P980!$tl;cq5n*Lx00I#p>||kJU|Yfo GcBbi8dDzF*Rw-?y zHZPkdT@jl)Xv9P|?xIEg--q!RB-kb&lNMAL4u>D-959Eplm&9IOkUoqhq#I)m>B1ZUX~!G{X)t}mddeTccz=H##;b7^)RU#DH~qETgz+@>2A~et z<|xQ6=17Q+IU1s3PJq}Ym|lp$+)7NqC`(c>DVX9pfFC}8oK0ts z;(CAe<_#E0kvkrPAs7}SSBi#G0K`X#JOHkOC5j^)f&~sxmSVu3!8AjF#39~*l%s^F z0C6z7mQ%fo=WBKKa?Mw-?w#-T6ss4k7h;34fb?UmAbl81NH?ZZ&bLV?qzmKqU|buF z*Mo7*n63!4Ii-|8g7N=4j9=q?1yj|1t>1sIz5R6<#y<~6bL13EOF1*9>kQU0##7sb>9VFJgY09vjBm|m zyO^UO`(GfAg6No|Au8qsh+Tr|g$PXR)oTdkO-sFcX}2+V|2F3B-^To%8`dh$$_szi z3ddP}zsdz^wkTz#35u3fEAvuqX%kPNYsBoJtt^|i{=*WfAXGz0xQRsgBKa+EUpavAX{LL zH@pn1Q4Kos+C0hsglVZJs_O)&Y2I*UkO#$6iE=SJEL>67?<5Z?T3}k4G|d|Z|1>4& z)Z1tRzsw%*zRe!y@28z3lz^C>lQW;&H_oDn;>wD-Y!%))VD|+v4ryN^bxeP4W0#TA z$^?ak70tpClF&Rx7&qd1(vum3%%ko!tolD@}JIAC!Irb6;Po-avK)M1;? zV$eS-=Ik#YN%*BwRS( zF@aYtKoc_cXb|&NftTsWsZRR<#V;t`E+Uz@MJU{NWxAG%w-H)T;8-LuN}^cgP(Fe0 zAMZYYnL}rVl86YW$D1*%lQRIyw4Y?Y0rOlS&Wk(+Px8F2rlx<>CHn_i{KE>z;cvGF zqzQ`zOaTHE02BZK00;nhp87bHifIT~1ONb&8vp= 256 || y < FSettings.FirstSLine || y > FSettings.LastSLine) + if (x < 0 || x >= 256 || y < 0 || y >= 256) luaL_error(L,"bad coordinates"); gui_prepare(); @@ -727,14 +727,12 @@ static int gui_drawline(lua_State *L) { y1 = luaL_checkinteger(L,2); x2 = luaL_checkinteger(L,3); y2 = luaL_checkinteger(L,4); - y1 += FSettings.FirstSLine; - y2 += FSettings.FirstSLine; colour = gui_getcolour(L,5); - if (x1 < 0 || x1 >= 256 || y1 < FSettings.FirstSLine || y1 > FSettings.LastSLine) + if (x1 < 0 || x1 >= 256 || y1 < 0 || y1 >= 256) luaL_error(L,"bad coordinates"); - if (x2 < 0 || x2 >= 256 || y2 < FSettings.FirstSLine || y2 > FSettings.LastSLine) + if (x2 < 0 || x2 >= 256 || y2 < 0 || y2 >= 256) luaL_error(L,"bad coordinates"); gui_prepare(); @@ -800,14 +798,12 @@ static int gui_drawbox(lua_State *L) { y1 = luaL_checkinteger(L,2); x2 = luaL_checkinteger(L,3); y2 = luaL_checkinteger(L,4); - y1 += FSettings.FirstSLine; - y2 += FSettings.FirstSLine; colour = gui_getcolour(L,5); - if (x1 < 0 || x1 >= 256 || y1 < FSettings.FirstSLine || y1 > FSettings.LastSLine) + if (x1 < 0 || x1 >= 256 || y1 < 0 || y1 >= 256) luaL_error(L,"bad coordinates"); - if (x2 < 0 || x2 >= 256 || y2 < FSettings.FirstSLine || y2 > FSettings.LastSLine) + if (x2 < 0 || x2 >= 256 || y2 < 0 || y2 >= 256) luaL_error(L,"bad coordinates"); @@ -856,7 +852,7 @@ static int gui_gdscreenshot(lua_State *L) { // This is QUITE nasty... - const int width=256, height=1+FSettings.LastSLine-FSettings.FirstSLine; + const int width=256, height=256; // Stack allocation unsigned char *buffer = (unsigned char*)alloca(2+2+2+1+4 + (width*height*4)); @@ -883,7 +879,7 @@ static int gui_gdscreenshot(lua_State *L) { // Now we can actually save the image data int i = 0; int x,y; - for (y=FSettings.FirstSLine; y <= FSettings.LastSLine; y++) { + for (y=0; y < height; y++) { for (x=0; x < width; x++) { uint8 index = XBuf[y*256 + x]; @@ -929,14 +925,13 @@ static int gui_text(lua_State *L) { x = luaL_checkinteger(L,1); y = luaL_checkinteger(L,2); msg = luaL_checkstring(L,3); - y += FSettings.FirstSLine; - if (x < 0 || x >= 256 || y < FSettings.FirstSLine || y > FSettings.LastSLine) + if (x < 0 || x >= 256 || y < 0 || y >= 256) luaL_error(L,"bad coordinates"); gui_prepare(); - DrawTextTransWH(gui_data+y*256+x, 256, (uint8 *)msg, 0x20+0x80, 256 - x, 1 + FSettings.LastSLine - y); + DrawTextTransWH(gui_data+y*256+x, 256, (uint8 *)msg, 0x20+0x80, 256 - x, 256 - y); return 0; @@ -994,7 +989,7 @@ static int gui_gdoverlay(lua_State *L) { y = 0; } - for (sy += FSettings.FirstSLine; y < height && sy <= FSettings.LastSLine; y++, sy++) { + for (; y < height && sy < 256; y++, sy++) { if (baseX < 0) { x = -baseX; @@ -1436,13 +1431,13 @@ void FCEU_LuaFrameBoundary() { // printf("Lua Frame\n"); // HA! - if (!LUA || !luaRunning) + if (!L || !luaRunning) return; // Our function needs calling - lua_settop(LUA,0); - lua_getfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread); - lua_State *thread = lua_tothread(LUA,1); + lua_settop(L,0); + lua_getfield(L, LUA_REGISTRYINDEX, frameAdvanceThread); + lua_State *thread = lua_tothread(L,1); // Lua calling C must know that we're busy inside a frame boundary frameBoundary = TRUE; @@ -1456,8 +1451,8 @@ void FCEU_LuaFrameBoundary() { } else if (result != 0) { // Done execution by bad causes FCEU_LuaOnStop(); - lua_pushnil(LUA); - lua_setfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread); + lua_pushnil(L); + lua_setfield(L, LUA_REGISTRYINDEX, frameAdvanceThread); // Error? #ifdef WIN32 @@ -1496,7 +1491,7 @@ int FCEU_LoadLuaCode(const char *filename) { luaScriptName = strdup(filename); } - if (!LUA) { + if (!L) { #ifdef WIN32 HMODULE test = LoadLibrary("lua5.1.dll"); @@ -1508,59 +1503,65 @@ int FCEU_LoadLuaCode(const char *filename) { FreeLibrary(test); #endif - LUA = lua_open(); - luaL_openlibs(LUA); + L = lua_open(); + luaL_openlibs(L); - luaL_register(LUA, "FCEU", fceulib); - luaL_register(LUA, "memory", memorylib); - luaL_register(LUA, "joypad", joypadlib); - luaL_register(LUA, "savestate", savestatelib); - luaL_register(LUA, "movie", movielib); - luaL_register(LUA, "gui", guilib); + luaL_register(L, "FCEU", fceulib); + luaL_register(L, "memory", memorylib); + luaL_register(L, "joypad", joypadlib); + luaL_register(L, "savestate", savestatelib); + luaL_register(L, "movie", movielib); + luaL_register(L, "gui", guilib); - lua_pushcfunction(LUA, base_AND); - lua_setfield(LUA, LUA_GLOBALSINDEX, "AND"); - lua_pushcfunction(LUA, base_OR); - lua_setfield(LUA, LUA_GLOBALSINDEX, "OR"); - lua_pushcfunction(LUA, base_XOR); - lua_setfield(LUA, LUA_GLOBALSINDEX, "XOR"); - lua_pushcfunction(LUA, base_BIT); - lua_setfield(LUA, LUA_GLOBALSINDEX, "BIT"); + lua_pushcfunction(L, base_AND); + lua_setfield(L, LUA_GLOBALSINDEX, "AND"); + lua_pushcfunction(L, base_OR); + lua_setfield(L, LUA_GLOBALSINDEX, "OR"); + lua_pushcfunction(L, base_XOR); + lua_setfield(L, LUA_GLOBALSINDEX, "XOR"); + lua_pushcfunction(L, base_BIT); + lua_setfield(L, LUA_GLOBALSINDEX, "BIT"); + + lua_newtable(L); + lua_setglobal(L,"emu"); + lua_getglobal(L,"emu"); + lua_newtable(L); + lua_setfield(L,-2,"OnClose"); - lua_newtable(LUA); - lua_setfield(LUA, LUA_REGISTRYINDEX, memoryWatchTable); - lua_newtable(LUA); - lua_setfield(LUA, LUA_REGISTRYINDEX, memoryValueTable); + lua_newtable(L); + lua_setfield(L, LUA_REGISTRYINDEX, memoryWatchTable); + lua_newtable(L); + lua_setfield(L, LUA_REGISTRYINDEX, memoryValueTable); } // We make our thread NOW because we want it at the bottom of the stack. // If all goes wrong, we let the garbage collector remove it. - lua_State *thread = lua_newthread(LUA); + lua_State *thread = lua_newthread(L); // Load the data - int result = luaL_loadfile(LUA,filename); + int result = luaL_loadfile(L,filename); if (result) { #ifdef WIN32 // Doing this here caused nasty problems; reverting to MessageBox-from-dialog behavior. //StopSound();//StopSound(); //mbg merge 7/23/08 - MessageBox(NULL, lua_tostring(LUA,-1), "Lua load error", MB_OK | MB_ICONSTOP); + MessageBox(NULL, lua_tostring(L,-1), "Lua load error", MB_OK | MB_ICONSTOP); #else - fprintf(stderr, "Failed to compile file: %s\n", lua_tostring(LUA,-1)); + fprintf(stderr, "Failed to compile file: %s\n", lua_tostring(L,-1)); #endif // Wipe the stack. Our thread - lua_settop(LUA,0); + lua_settop(L,0); return 0; // Oh shit. } // Get our function into it - lua_xmove(LUA, thread, 1); + lua_xmove(L, thread, 1); // Save the thread to the registry. This is why I make the thread FIRST. - lua_setfield(LUA, LUA_REGISTRYINDEX, frameAdvanceThread); + lua_setfield(L, LUA_REGISTRYINDEX, frameAdvanceThread); // Initialize settings @@ -1601,12 +1602,26 @@ void FCEU_ReloadLuaCode() void FCEU_LuaStop() { // Kill it. - if (LUA) { - lua_close(LUA); // this invokes our garbage collectors for us - LUA = NULL; - FCEU_LuaOnStop(); + if (!L) return; + + //execute the user's shutdown callbacks + //onCloseCallback + lua_getglobal(L, "emu"); + lua_getfield(L, -1, "OnClose"); + lua_pushnil(L); + while (lua_next(L, -2) != 0) + { + lua_call(L,0,0); } + //sometimes iup uninitializes com + CoInitialize(0); + //lua_gc(L,LUA_GCCOLLECT,0); + + + lua_close(L); // this invokes our garbage collectors for us + L = NULL; + FCEU_LuaOnStop(); } /** @@ -1614,7 +1629,7 @@ void FCEU_LuaStop() { * */ int FCEU_LuaRunning() { - return LUA && luaRunning; + return L && luaRunning; } @@ -1644,7 +1659,7 @@ uint8 FCEU_LuaReadJoypad(int which) { * This function will not return true if a script is not running. */ int FCEU_LuaRerecordCountSkip() { - return LUA && luaRunning && skipRerecords; + return L && luaRunning && skipRerecords; } @@ -1656,32 +1671,32 @@ int FCEU_LuaRerecordCountSkip() { */ void FCEU_LuaGui(uint8 *XBuf) { - if (!LUA || !luaRunning) + if (!L || !luaRunning) return; // First, check if we're being called by anybody - lua_getfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable); + lua_getfield(L, LUA_REGISTRYINDEX, guiCallbackTable); - if (lua_isfunction(LUA, -1)) { + if (lua_isfunction(L, -1)) { // We call it now numTries = 1000; - int ret = lua_pcall(LUA, 0, 0, 0); + int ret = lua_pcall(L, 0, 0, 0); if (ret != 0) { #ifdef WIN32 //StopSound();//StopSound(); //mbg merge 7/23/08 - MessageBox(hAppWnd, lua_tostring(LUA, -1), "Lua Error in GUI function", MB_OK); + MessageBox(hAppWnd, lua_tostring(L, -1), "Lua Error in GUI function", MB_OK); #else - fprintf(stderr, "Lua error in gui.register function: %s\n", lua_tostring(LUA, -1)); + fprintf(stderr, "Lua error in gui.register function: %s\n", lua_tostring(L, -1)); #endif // This is grounds for trashing the function - lua_pushnil(LUA); - lua_setfield(LUA, LUA_REGISTRYINDEX, guiCallbackTable); + lua_pushnil(L); + lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable); } } // And wreak the stack - lua_settop(LUA, 0); + lua_settop(L, 0); if (gui_used == GUI_CLEAR) return; @@ -1695,14 +1710,14 @@ void FCEU_LuaGui(uint8 *XBuf) { // direct copy if (transparency == 0) { - for (y = FSettings.FirstSLine; y <= FSettings.LastSLine && y < 256; y++) { + for (y = 0; y < 256; y++) { for (x=0; x < 256; x++) { if (gui_data[y*256+x] != GUI_COLOUR_CLEAR) XBuf[y*256 + x] = gui_data[y*256+x]; } } } else { - for (y = FSettings.FirstSLine; y <= FSettings.LastSLine && y < 256; y++) { + for (y = 0; y < 256; y++) { for (x=0; x < 256; x++) { if (gui_data[y*256+x] != GUI_COLOUR_CLEAR) { uint8 rg, gg, bg, rx, gx, bx, r, g, b; diff --git a/vc8/archive.bat b/vc8/archive.bat index 726862f2..113b36e9 100644 --- a/vc8/archive.bat +++ b/vc8/archive.bat @@ -1,4 +1,6 @@ del /s fceux.zip cd ..\output ..\vc8\zip -X -9 -r ..\vc8\fceux.zip fceux.exe fceux.chm 7z.dll palettes +copy /y luapack\luapack.zip ..\vc8\ +..\vc8\zip -X -9 -r ..\vc8\luapack.zip auxlib.lua cd ..\vc8 \ No newline at end of file diff --git a/vc8/fceux.vcproj b/vc8/fceux.vcproj index e2d07e28..1aa5951e 100644 --- a/vc8/fceux.vcproj +++ b/vc8/fceux.vcproj @@ -2452,6 +2452,28 @@ RelativePath="..\src\asm.cpp" > + + + + + + + + diff --git a/vc8/upload.bat b/vc8/upload.bat index 25448ddd..42ba8407 100644 --- a/vc8/upload.bat +++ b/vc8/upload.bat @@ -1 +1,2 @@ -pscp -pw zzzap333 fceux.zip fceux@www.pi-r-squared.com:web/zip/fceux.zip \ No newline at end of file +pscp -pw zzzap333 fceux.zip fceux@www.pi-r-squared.com:web/zip/fceux.zip +pscp -pw zzzap333 luapack.zip fceux@www.pi-r-squared.com:web/lua/luapack.zip \ No newline at end of file