Put lua scrip in correct folder, fixed script not running after yielding with flag

This commit is contained in:
StevenPhang22 2022-11-20 11:13:21 -05:00
parent 72264ec5d6
commit 66ed3d6b58
5 changed files with 25 additions and 7 deletions

View File

@ -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.

View File

@ -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

View File

@ -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);

View File

@ -5446,6 +5446,7 @@ bool yieldFlag = false;
static int emugator_yieldwithflag(lua_State* L)
{
frameAdvanceWaiting = TRUE;
yieldFlag = true;
return lua_yield(L, 0);

View File

@ -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;