From 0f5391f53299e94a676e6fbb2c272f477af7261b Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Wed, 2 Nov 2022 21:38:48 -0400 Subject: [PATCH 1/9] added loadRom lua function --- output/luaScripts/DragAndDropROM.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 output/luaScripts/DragAndDropROM.lua diff --git a/output/luaScripts/DragAndDropROM.lua b/output/luaScripts/DragAndDropROM.lua new file mode 100644 index 00000000..064a6d4f --- /dev/null +++ b/output/luaScripts/DragAndDropROM.lua @@ -0,0 +1,22 @@ +--Written by Steven Phang +--EmuGators + +--You can change the number of controllers tracked here. +local roms = {} + +function loadROM(filename) + --Load ROM file into emulator + emu.loadrom(filename) + + local truncLoc = strfind (filename, '.') + local friendlyName = strsub(filename, 1, truncLoc) + emu.message('Successfully Loaded ' .. friendlyName); +end + +function SearchForROMS(string filepath) + local +end + +while true do + emu.frameadvance() +end \ No newline at end of file From e8e1d49ac570feceb8626367ec801c490a05398a Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Wed, 2 Nov 2022 22:44:52 -0400 Subject: [PATCH 2/9] Added to main loop --- output/luaScripts/DragAndDropROM.lua | 67 ++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/output/luaScripts/DragAndDropROM.lua b/output/luaScripts/DragAndDropROM.lua index 064a6d4f..67269220 100644 --- a/output/luaScripts/DragAndDropROM.lua +++ b/output/luaScripts/DragAndDropROM.lua @@ -2,21 +2,72 @@ --EmuGators --You can change the number of controllers tracked here. +require 'lfs' --Lua File Syayem, useful for searching file directories + local roms = {} +local framecount = 0 -function loadROM(filename) + +function loadRom(index) --Load ROM file into emulator - emu.loadrom(filename) + emu.loadrom(roms[index].path) + emu.message('Successfully Loaded ' .. roms[index].name) - local truncLoc = strfind (filename, '.') - local friendlyName = strsub(filename, 1, truncLoc) - emu.message('Successfully Loaded ' .. friendlyName); end -function SearchForROMS(string filepath) - local +function unloadRom(dummyPath) + --Load ROM file into emulator + emu.loadrom(dummyPath) + emu.message('Disk Ejected') + end +function SearchForROMS(filepath) + local count = 1; + for file in lfs.dir[filepath] do + if lfs.attributes(file,"mode") == "file" then + roms[count] = {} + roms[count].index = count + roms[count].path = file + + local truncLoc = strfind (filename, '.') + local friendlyName = strsub(filename, 1, truncLoc) + + roms[count].name = friendlyName + count = count + 1 + end + end +end + +--On startup +movie.load("loadingScreen.fm2") +local dummyPath = "dummy.fds" +local isLoadingScreen = true +unloadRom(dummyPath) + while true do - emu.frameadvance() + --TODO: Implement Logic to detect when ROM should be loaded (via GUI event) + --TODO: On 'Disk dragged to Console Event' toggle isLoadingScreen variable + -- and perform corresponding actions + + --Poll for GUI Event here, update isLoadingScreen if it occurs, then... + if isLoadingScreen --no disk loaded, play animation + if !movie.active() then + movie.play() + end + frameCount = frameCount + 1 + if framecount == movie.length() then + framecount = 0 + movie.replay() + end + else --disk loaded, stop animation + if !movie.active() then + movie.stop() + movie.close() + end + + loadRom(index) + end + + emu.frameadvance() end \ No newline at end of file From 9796b5bffed1610d67af4e138a0ebf99442295df Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Wed, 2 Nov 2022 22:53:44 -0400 Subject: [PATCH 3/9] Updated description comment --- output/luaScripts/DragAndDropROM.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/output/luaScripts/DragAndDropROM.lua b/output/luaScripts/DragAndDropROM.lua index 67269220..6eee9731 100644 --- a/output/luaScripts/DragAndDropROM.lua +++ b/output/luaScripts/DragAndDropROM.lua @@ -1,8 +1,8 @@ --Written by Steven Phang --EmuGators +--This script is a draft of the realistic disk loading system. ---You can change the number of controllers tracked here. -require 'lfs' --Lua File Syayem, useful for searching file directories +require 'lfs' --Lua File System, useful for searching file directories local roms = {} local framecount = 0 From 6a7ae42ff0dcbf8597d116a4654e97aeff12f3d2 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Mon, 14 Nov 2022 20:25:21 -0500 Subject: [PATCH 4/9] updated window title --- src/drivers/win/window.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 82c845b5..51cffe8e 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -196,6 +196,7 @@ string gettingstartedhelp = "Gettingstarted";//Getting Started void SetMainWindowText() { string str = FCEU_NAME_AND_VERSION; + if (newppu) str.append(" (New PPU)"); if (GameInfo) @@ -2746,10 +2747,15 @@ int CreateMainWindow() updateGameDependentMenusDebugger(); if (MainWindow_wndx==-32000) MainWindow_wndx=0; //Just in case if (MainWindow_wndy==-32000) MainWindow_wndy=0; + + //Added Emugators name to window title + string title = FCEU_NAME_AND_VERSION; + title.append(" (Emugators)"); + hAppWnd = CreateWindowEx( 0, "FCEUXWindowClass", - FCEU_NAME_AND_VERSION, + title.c_str(), WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS, /* Style */ MainWindow_wndx, MainWindow_wndy, From 5067de51a72a4f6f388cdad72461df2519bed269 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Tue, 15 Nov 2022 16:34:25 -0500 Subject: [PATCH 5/9] Changed how I was doing the window title, and added yieldwithflag lua hook --- output/luaScripts/DragAndDropROM.lua | 4 ++-- src/drivers/win/main.cpp | 13 +++++++++++++ src/drivers/win/window.cpp | 6 +----- src/lua-engine.cpp | 22 ++++++++++++++++++++++ src/version.h | 2 +- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/output/luaScripts/DragAndDropROM.lua b/output/luaScripts/DragAndDropROM.lua index 6eee9731..7356a36e 100644 --- a/output/luaScripts/DragAndDropROM.lua +++ b/output/luaScripts/DragAndDropROM.lua @@ -15,9 +15,9 @@ function loadRom(index) end -function unloadRom(dummyPath) +function unloadRom() --Load ROM file into emulator - emu.loadrom(dummyPath) + emu.unloadROM() emu.message('Disk Ejected') end diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 54147dbc..8873a879 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -965,6 +965,19 @@ doloopy: } else UpdateRawInputAndHotkeys(); + + extern bool yieldFlag; + if (yieldFlag) { + 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); + } + Sleep(50); if(!exiting) goto doloopy; diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 51cffe8e..036eee17 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -2748,14 +2748,10 @@ int CreateMainWindow() if (MainWindow_wndx==-32000) MainWindow_wndx=0; //Just in case if (MainWindow_wndy==-32000) MainWindow_wndy=0; - //Added Emugators name to window title - string title = FCEU_NAME_AND_VERSION; - title.append(" (Emugators)"); - hAppWnd = CreateWindowEx( 0, "FCEUXWindowClass", - title.c_str(), + FCEU_NAME_AND_VERSION, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS, /* Style */ MainWindow_wndx, MainWindow_wndy, diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 88950e61..1d45f0ec 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -5442,6 +5442,18 @@ static int cdl_resetcdlog(lua_State *L) return 0; } +bool yieldFlag = false; + +static int emugator_yieldwithflag(lua_State* L) +{ + yieldFlag = true; + + return lua_yield(L, 0); + + + // It's actually rather disappointing... +} + static int doPopup(lua_State *L, const char* deftype, const char* deficon) { @@ -6284,6 +6296,12 @@ static const struct luaL_reg cdloglib[] = { { NULL,NULL } }; +static const struct luaL_reg emugatorlib[] = { + {"yieldwithflag", emugator_yieldwithflag}, + {NULL,NULL} +}; + + void CallExitFunction() { if (!L) @@ -6446,8 +6464,12 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) luaL_register(L, "bit", bit_funcs); // LuaBitOp library lua_settop(L, 0); + luaL_register(L, "emugator", emugatorlib); // LuaBitOp library + lua_settop(L, 0); + // register a few utility functions outside of libraries (in the global namespace) lua_register(L, "print", print); + lua_register(L, "soup", print); //emugatordebug lua_register(L, "gethash", gethash), lua_register(L, "tostring", tostring); lua_register(L, "tobitstring", tobitstring); diff --git a/src/version.h b/src/version.h index 01c9daae..4a7316b7 100644 --- a/src/version.h +++ b/src/version.h @@ -69,7 +69,7 @@ #define FCEU_VERSION_MINOR_DECODE(x) ( (x / 100) % 100 ) #define FCEU_VERSION_PATCH_DECODE(x) (x % 100) -#define FCEU_VERSION_STRING "2.6.5" FCEU_SUBVERSION_STRING FCEU_FEATURE_STRING FCEU_COMPILER +#define FCEU_VERSION_STRING "2.6.5 (Emugators)" FCEU_SUBVERSION_STRING FCEU_FEATURE_STRING FCEU_COMPILER #define FCEU_NAME_AND_VERSION FCEU_NAME " " FCEU_VERSION_STRING #endif From 72264ec5d6d5576fd36637ae11833e6d01a1eae2 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Tue, 15 Nov 2022 16:41:28 -0500 Subject: [PATCH 6/9] added personal log --- emugator_log_sphang.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 emugator_log_sphang.txt diff --git a/emugator_log_sphang.txt b/emugator_log_sphang.txt new file mode 100644 index 00000000..e816c16e --- /dev/null +++ b/emugator_log_sphang.txt @@ -0,0 +1,26 @@ +Emugators Log - Steven Phang +11/15/2022 +If a lua script is ran without emu.frameadvance(), the whole program hangs, not just the game that is currently being played. For an unknwn reason, the text that is supposed to be displayed with the Emugators_HelloWorld.lua script is only displayed when a ROM is loaded. It disapears after the ROM is closed as well... I spoke with Carsten, and we discussed the idea of using a ROM to represent the DnD GUI. Automatically load this ROM at startup, and this would work nicely. Problem - I dont know how I would go about making the ROM... Regardless, I want to figure out what mechanism is responsible for clearing the screen and pausing the lua script on startup/when a ROM is closed. This may be the key to running the script without a ROM... + +This is the mechanism for clearing the screen when the ROM is closed... +See fceu.cpp > FCEU_CloseGame(void) + //clear screen when game is closed + extern uint8 *XBuf; + if (XBuf) + memset(XBuf, 0, 256 * 256); + +lua-engine.cpp is the most important file in our universe. It containes the bindings + +interesting... lua_yeild and lua_resume in ldo.c may be useful + +search emugatordebug comment for things that maybe should be removed for release + +steps to implement lua callable c++ function... +add new library (needs to be registered) or simply register new function with existing library (ex. emulib) contained in lua-engine.cpp + +ITS RUNNING BUT THERE IS NO FRAME TO ADVANCE!!!!! +emu.frameadvance causes the lua script to yield to main until another emulator frame is processed. Then, something hands control back to the script. But if no game is running (No ROM Loaded), main just updates the display then sleeps for a little bit. Question of the day is What is normally handing control back to the script? It has been staring me in the face all day...FCEU_LuaFrameBoundary() + +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? + From 66ed3d6b580f0b78ea6c7641ba0bb9aa65b22176 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Sun, 20 Nov 2022 11:13:21 -0500 Subject: [PATCH 7/9] 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; From 3f5f4fe7b913792afe371d0d45e8b76e79794394 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Tue, 22 Nov 2022 00:19:25 -0500 Subject: [PATCH 8/9] can draw to window after game closes --- emugator_log_sphang.txt | 10 ++++++++++ src/drivers/win/main.cpp | 32 ++++++++++++++++++-------------- src/fceu.cpp | 15 +++++++++++++++ src/fceu.h | 6 ++++++ src/lua-engine.cpp | 5 ++--- src/video.cpp | 5 +++++ src/video.h | 2 ++ 7 files changed, 58 insertions(+), 17 deletions(-) diff --git a/emugator_log_sphang.txt b/emugator_log_sphang.txt index 1bba51f7..6f2b5beb 100644 --- a/emugator_log_sphang.txt +++ b/emugator_log_sphang.txt @@ -30,3 +30,13 @@ Looks like the control is not properly being handed back to the lua scrip as I t 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. +11/20/2022 +I am going to fix this graphics bug today. I suspect that the buffer I am editing and the buffer that is actually being drawn are two seperate entities, which is causing it to look like my changes to the display buffer are not going through. + +From wikipedia "Bit blit (also written BITBLT, BIT BLT, BitBLT, Bit BLT, Bit Blt etc., which stands for bit block transfer) is a data operation commonly used in computer graphics in which several bitmaps are combined into one using a boolean function.[1]"... So that's what the blit function called in FCEUD_Update is doing. + +The call to RedrawWindow() after a game is closed in main() has the flags RDW_ERASE and RDW_INVALIDATE. The erase flag clears the window, and the invalidate flag seems to prevent the window from being edited (drawn over). The window must be in a "validated" state for the lua gui to show up. Aditionally, it appears that the screen must be cleared manually after the lua gui is drawn if no frame is emulated. + +11/21/2022 +I added a function to clear the screen to fceu.cpp. This is not necessary while a game is running (presumeably because game frame data overwrites what was previously there), but is necessary for drawing lua gui with nothing running. With this addition, this aspect of the project (being able to run lua + draw to the gui without a ROM loaded) is functional...but only if a ROM is first opened then closed. Even though I am drawing a new window when lua is loaded, it does not seem to work if loading a script before a game is initially loaded. Again, the script IS running properly... I need to investigate loading a ROM as well as how the main window is being drawn at launch... + diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 452edc2a..3f550b12 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -919,6 +919,7 @@ int main(int argc,char *argv[]) if (PauseAfterLoad) FCEUI_ToggleEmulationPause(); SetAutoFirePattern(AFon, AFoff); UpdateCheckedMenuItems(); + doloopy: UpdateFCEUWindow(); if(GameInfo) @@ -963,24 +964,27 @@ doloopy: //xbsave = NULL; RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); } - else - UpdateRawInputAndHotkeys(); + else if (luaYieldFlag) { + RedrawWindow(hAppWnd, 0, 0, RDW_ERASE | RDW_VALIDATE); - extern bool yieldFlag; - if (yieldFlag) { - yieldFlag = false; - //extern uint8* XBuf; - //memset(XBuf, -1, 256 * 256); - FCEU_LuaFrameBoundary(); + while (luaYieldFlag && !exiting) { + UpdateFCEUWindow(); + luaYieldFlag = false; + UpdateRawInputAndHotkeys(); - u8 dog[256*257]; - memset(dog, -1, 256 * 256);//128 - FCEU_LuaGui(dog); - FCEUD_BlitScreen(dog); + uint8* gfx = 0; + FCEUI_AdvanceNoFrame(&gfx); + FCEUD_BlitScreen(gfx); + + Sleep(50); + } } - + else { + UpdateRawInputAndHotkeys(); + } + Sleep(50); - if(!exiting) + if (!exiting) goto doloopy; DriverKill(); diff --git a/src/fceu.cpp b/src/fceu.cpp index 28396c34..3723a5d5 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -236,6 +236,13 @@ static void FCEU_CloseGame(void) } } +void FCEU_ClearScreen(void) { + //clear screen when game is closed + extern uint8* XBuf; + if (XBuf) + memset(XBuf, 0, 256 * 256); +} + uint64 timestampbase; @@ -254,6 +261,7 @@ static int RWWrap = 0; //mbg merge 7/18/06 docs //bit0 indicates whether emulation is paused //bit1 indicates whether emulation is in frame step mode +bool luaYieldFlag = false; int EmulationPaused = 0; bool frameAdvanceRequested=false; int frameAdvance_Delay_count = 0; @@ -871,6 +879,13 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski ProcessSubtitles(); } +void FCEUI_AdvanceNoFrame(uint8** pXBuf) { + FCEU_ClearScreen(); + FCEU_LuaFrameBoundary(); + FCEU_DrawLuaGui(); + *pXBuf = XBuf; +} + void FCEUI_CloseGame(void) { if (!FCEU_IsValidUI(FCEUI_CLOSEGAME)) return; diff --git a/src/fceu.h b/src/fceu.h index 7fec58c4..1d302911 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -72,6 +72,8 @@ extern uint8 qtaintramreg; extern uint8 *RAM; //shared memory modifications extern int EmulationPaused; +//Lua-engine (emugators) +extern bool luaYieldFlag; extern int frameAdvance_Delay; extern int RAMInitOption; @@ -148,6 +150,10 @@ void FCEU_TogglePPU(); void SetNESDeemph_OldHacky(uint8 d, int force); void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor); void FCEU_PutImage(void); + +void FCEUI_AdvanceNoFrame(uint8** pXBuf); // - emugator +void FCEU_ClearScreen(void); // -emugator + #ifdef FRAMESKIP void FCEU_PutImageDummy(void); #endif diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 602604b6..32a81f89 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -5442,12 +5442,10 @@ static int cdl_resetcdlog(lua_State *L) return 0; } -bool yieldFlag = false; - static int emugator_yieldwithflag(lua_State* L) { frameAdvanceWaiting = TRUE; - yieldFlag = true; + luaYieldFlag = true; return lua_yield(L, 0); @@ -6400,6 +6398,7 @@ void FCEU_LuaFrameBoundary() * * Returns true on success, false on failure. */ + int FCEU_LoadLuaCode(const char *filename, const char *arg) { if (!DemandLua()) diff --git a/src/video.cpp b/src/video.cpp index 5c231d59..623fb441 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -383,6 +383,11 @@ void FCEU_PutImage(void) } else DrawMessage(false); } + +void FCEU_DrawLuaGui(void) { + FCEU_LuaGui(XBuf); +} + void snapAVI() { //Update AVI diff --git a/src/video.h b/src/video.h index 7fbb6bad..c8cb2c83 100644 --- a/src/video.h +++ b/src/video.h @@ -7,6 +7,8 @@ int SaveSnapshot(char[]); void ResetScreenshotsCounter(); uint32 GetScreenPixel(int x, int y, bool usebackup); int GetScreenPixelPalette(int x, int y, bool usebackup); +void FCEU_DrawLuaGui(void); + //in case we need more flags in the future we can change the size here //bit0 : monochrome bit From 83ad2fc56e871a2b35610a0a4d64b089feee62a9 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Wed, 23 Nov 2022 17:43:16 -0500 Subject: [PATCH 9/9] Can successfully run scripts/draw to gui without ROM --- output/luaScripts/Emugators_HelloWorld.lua | 16 ++++++++++------ src/drivers/win/main.cpp | 9 ++++----- src/drivers/win/window.cpp | 3 ++- src/fceu.cpp | 10 +++++++--- src/fceu.h | 6 ++++-- src/ines.cpp | 4 ++-- src/lua-engine.cpp | 1 - src/palette.cpp | 12 ++++++++++++ 8 files changed, 41 insertions(+), 20 deletions(-) diff --git a/output/luaScripts/Emugators_HelloWorld.lua b/output/luaScripts/Emugators_HelloWorld.lua index 2eda165a..b3549bd7 100644 --- a/output/luaScripts/Emugators_HelloWorld.lua +++ b/output/luaScripts/Emugators_HelloWorld.lua @@ -1,10 +1,14 @@ - emu.print("okay, but where does this one go?") - local y = 6 + emu.print("Go Gators!") + local y = 0 + while(true) do gui.drawtext(0, y, "Hello World") - y = y + 1 - soup("this is cool") - emugator.yieldwithflag(); - + if(y < 256) then + y = y + 1 + else + y = 0 + end + print(y) + emugator.yieldwithflag(); -- call this if you want the script to run without emulation (game running) --emu.frameadvance() end \ No newline at end of file diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index 3f550b12..04a71586 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -965,18 +965,17 @@ doloopy: RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); } else if (luaYieldFlag) { - RedrawWindow(hAppWnd, 0, 0, RDW_ERASE | RDW_VALIDATE); - - while (luaYieldFlag && !exiting) { - UpdateFCEUWindow(); + FCEUI_ResetPalette(); + while (luaYieldFlag && !exiting && !GameInfo) { luaYieldFlag = false; + UpdateFCEUWindow(); UpdateRawInputAndHotkeys(); uint8* gfx = 0; FCEUI_AdvanceNoFrame(&gfx); FCEUD_BlitScreen(gfx); - Sleep(50); + Sleep(25); } } else { diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 036eee17..9cb516ad 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1167,6 +1167,7 @@ bool ALoad(const char *nameo, char* innerFilename, bool silent) updateGameDependentMenus(); updateGameDependentMenusDebugger(); EmulationPaused = oldPaused; + return true; } @@ -2703,7 +2704,7 @@ void ByebyeWindow() DestroyWindow(hAppWnd); } -/// reates the main window. +/// Creates the main window. /// @return Flag that indicates failure (0) or success (1) int CreateMainWindow() { diff --git a/src/fceu.cpp b/src/fceu.cpp index 3723a5d5..1c201f76 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -478,7 +478,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen if (fp->archiveFilename != "") GameInfo->archiveFilename = strdup(fp->archiveFilename.c_str()); GameInfo->archiveCount = fp->archiveCount; - + GameInfo->soundchan = 0; GameInfo->soundrate = 0; GameInfo->name = 0; @@ -487,7 +487,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen GameInfo->input[0] = GameInfo->input[1] = SI_UNSET; GameInfo->inputfc = SIFC_UNSET; GameInfo->cspecial = SIS_NONE; - + //try to load each different format bool FCEUXLoad(const char *name, FCEUFILE * fp); @@ -556,7 +556,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen } if (GameInfo->type != GIT_NSF && !disableAutoLSCheats) - FCEU_LoadGameCheats(0); + //FCEU_LoadGameCheats(0); if (AutoResumePlay) { @@ -886,6 +886,10 @@ void FCEUI_AdvanceNoFrame(uint8** pXBuf) { *pXBuf = XBuf; } +void FCEUI_ResetPalette(void) { + FCEU_ResetPalette(); +} + void FCEUI_CloseGame(void) { if (!FCEU_IsValidUI(FCEUI_CLOSEGAME)) return; diff --git a/src/fceu.h b/src/fceu.h index 1d302911..90e0b1ef 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -151,8 +151,10 @@ void SetNESDeemph_OldHacky(uint8 d, int force); void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor); void FCEU_PutImage(void); -void FCEUI_AdvanceNoFrame(uint8** pXBuf); // - emugator -void FCEU_ClearScreen(void); // -emugator +// - emugator +void FCEUI_AdvanceNoFrame(uint8** pXBuf); +void FCEU_ClearScreen(void); +void FCEUI_ResetPalette(void); #ifdef FRAMESKIP void FCEU_PutImageDummy(void); diff --git a/src/ines.cpp b/src/ines.cpp index 92fa0bdf..96caf1ab 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -940,9 +940,9 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { trainerpoo = NULL; ExtraNTARAM = NULL; return LOADER_HANDLED_ERROR; - + init_ok: - + GameInfo->mappernum = MapperNo; FCEU_LoadGameSave(&iNESCart); diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 32a81f89..91f862d2 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -6469,7 +6469,6 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) // register a few utility functions outside of libraries (in the global namespace) lua_register(L, "print", print); - lua_register(L, "soup", print); //emugatordebug lua_register(L, "gethash", gethash), lua_register(L, "tostring", tostring); lua_register(L, "tobitstring", tobitstring); diff --git a/src/palette.cpp b/src/palette.cpp index 35280df1..dfbff360 100644 --- a/src/palette.cpp +++ b/src/palette.cpp @@ -71,6 +71,7 @@ static pal *default_palette[8]= static void CalculatePalette(void); static void ChoosePalette(void); static void WritePalette(void); +static void UseDefaultPalette(void); //points to the actually selected current palette pal *palo = NULL; @@ -500,6 +501,11 @@ void FCEU_ResetPalette(void) ChoosePalette(); WritePalette(); } + else if (luaYieldFlag) { + UseDefaultPalette(); + WritePalette(); + } + } static void ChoosePalette(void) @@ -552,6 +558,12 @@ static void ChoosePalette(void) } } +static void UseDefaultPalette(void) { + palo = default_palette[default_palette_selection]; + //need to calcualte a deemph on the fly.. sorry. maybe support otherwise later + ApplyDeemphasisComplete(palo); +} + void WritePalette(void) { int x;