From 66ed3d6b580f0b78ea6c7641ba0bb9aa65b22176 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Sun, 20 Nov 2022 11:13:21 -0500 Subject: [PATCH] Put lua scrip in correct folder, fixed script not running after yielding with flag --- emugator_log_sphang.txt | 6 ++++++ output/luaScripts/Emugators_HelloWorld.lua | 10 ++++++++++ src/drivers/win/main.cpp | 13 +++++++------ src/lua-engine.cpp | 1 + src/video.cpp | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 output/luaScripts/Emugators_HelloWorld.lua diff --git a/emugator_log_sphang.txt b/emugator_log_sphang.txt index e816c16e..1bba51f7 100644 --- a/emugator_log_sphang.txt +++ b/emugator_log_sphang.txt @@ -23,4 +23,10 @@ emu.frameadvance causes the lua script to yield to main until another emulator f adding FCEU_LuaFrameBoundary(); to main before it sleeps will allow the lua script to keep running. So we could have a function like emu.frameadvanceAlways() or something that sets a flag that enables FCEU_LuaFrameBoundary() to be called in main (since we dont really want this behavior for ALL lus scripts)... OR maybe add an emu.updateDisplay() function that will allow the display to refresh without yeilding control to main. I think I prefer this option... *Note: the script still cant draw images on the GUI unless a ROM is loaded with this current method...why? +TODO: figure out how to get draw functions reflected on GUI with no ROM loaded. Come up with better function names, maybe plan out the organization a bit better. Add unload ROM function. + +11/18/2022 +Looks like the control is not properly being handed back to the lua scrip as I thought it was. I think there is another flag that is checked that is preventing it from returning. + +Indeed there was, it works now!frameAdvanceWaiting must be set to true to indicate a thread is waiting to run after a frame is emulated. diff --git a/output/luaScripts/Emugators_HelloWorld.lua b/output/luaScripts/Emugators_HelloWorld.lua new file mode 100644 index 00000000..2eda165a --- /dev/null +++ b/output/luaScripts/Emugators_HelloWorld.lua @@ -0,0 +1,10 @@ + emu.print("okay, but where does this one go?") + local y = 6 +while(true) do + gui.drawtext(0, y, "Hello World") + y = y + 1 + soup("this is cool") + emugator.yieldwithflag(); + + --emu.frameadvance() +end \ No newline at end of file diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 8873a879..452edc2a 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -968,14 +968,15 @@ doloopy: extern bool yieldFlag; if (yieldFlag) { + yieldFlag = false; + //extern uint8* XBuf; + //memset(XBuf, -1, 256 * 256); FCEU_LuaFrameBoundary(); - extern uint8* XBuf; - int32* sound = 0; ///contains sound data buffer - int32 ssize = 0; ///contains sound samples count - //if (XBuf) - // memset(XBuf, 0, 256 * 256); - FCEUD_Update(XBuf, sound, ssize); + u8 dog[256*257]; + memset(dog, -1, 256 * 256);//128 + FCEU_LuaGui(dog); + FCEUD_BlitScreen(dog); } Sleep(50); diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 1d45f0ec..602604b6 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -5446,6 +5446,7 @@ bool yieldFlag = false; static int emugator_yieldwithflag(lua_State* L) { + frameAdvanceWaiting = TRUE; yieldFlag = true; return lua_yield(L, 0); diff --git a/src/video.cpp b/src/video.cpp index e3814460..5c231d59 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -487,7 +487,7 @@ static int WritePNGChunk(FILE *fp, uint32 size, const char *type, uint8 *data) return 1; } -uint32 GetScreenPixel(int x, int y, bool usebackup) { +uint32 GetScreenPixel(int x, int y, bool usebackup) { uint8 r,g,b;