From 8768ea1c5e7ad72772e5a96877c47d761f9ae6c2 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 15 Mar 2009 23:21:52 +0000 Subject: [PATCH] Lua - added FCEU.setreadonly() --- changelog.txt | 2 +- src/lua-engine.cpp | 12 ++++++++++-- src/movie.cpp | 24 ++++++++++++++++++++++++ src/movie.h | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4edd7497..24c79792 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,5 @@ ---version 2.0.4 yet to be released--- -15-mar-2009 - adelikat - Lua - added movie.rerecordcount(), movie.length(), FCEU.getreadonly() +15-mar-2009 - adelikat - Lua - added movie.rerecordcount(), movie.length(), FCEU.getreadonly(), FCEU.setreadonly() 14-mar-2009 - adelikat - Lua - added movie.active() - returns a bool value based on whether a movie is currently loaded 14-mar-2009 - adelikat - Fixed Joypad.set, it uses 3 values instead of 2 now. True will take control of a button and make it on, False will take control and make it off, and Nil will not take control (allowing the user to press the button) 14-mar-2009 - adelikat - Fix major crash issue where NROM game savestates were writing erroneous information if a non NROM game was loaded prior diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 2a839d48..a4906c7a 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -975,12 +975,19 @@ static int movie_length (lua_State *L) { //FCEU.getreadonly // //returns true is emulator is in read-only mode, false if it is in read+wrte -static int fceu_readonly (lua_State *L) { +static int fceu_getreadonly (lua_State *L) { lua_pushboolean(L, FCEUI_GetMovieToggleReadOnly()); return 1; } +static int fceu_setreadonly (lua_State *L) { + bool which = (lua_toboolean( L, 1 ) == 1); + FCEUI_SetMovieToggleReadOnly(which); + + return 0; +} + // Common code by the gui library: make sure the screen array is ready static void gui_prepare() { if (!gui_data) @@ -1828,7 +1835,8 @@ static const struct luaL_reg fceulib [] = { {"message", fceu_message}, {"lagcount", fceu_lagcount}, {"lagged", fceu_lagged}, - {"getreadonly", fceu_readonly}, + {"getreadonly", fceu_getreadonly}, + {"setreadonly", fceu_setreadonly}, {NULL,NULL} }; diff --git a/src/movie.cpp b/src/movie.cpp index 0d8340c9..632d317f 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1164,6 +1164,30 @@ bool FCEUI_GetMovieToggleReadOnly() return movie_readonly; } +void FCEUI_SetMovieToggleReadOnly(bool which) +{ + if (which) //If set to readonly + { + if (!movie_readonly) //If not already set + { + movie_readonly = true; + FCEU_DispMessage("Movie is now Read-Only."); + } + else //Else restate message + FCEU_DispMessage("Movie is Read-Only."); + } + else //If set to read+write + { + if (movie_readonly) //If not already set + { + movie_readonly = false; + FCEU_DispMessage("Movie is now Read+Write."); + } + else //Else restate message + FCEU_DispMessage("Movie is Read+Write."); + } +} + void FCEUI_MovieToggleReadOnly() { if(movie_readonly) diff --git a/src/movie.h b/src/movie.h index d3a9f332..bcd278e3 100644 --- a/src/movie.h +++ b/src/movie.h @@ -250,6 +250,7 @@ bool FCEUI_MovieGetInfo(FCEUFILE* fp, MOVIE_INFO& info, bool skipFrameCount = fa char* FCEUI_MovieGetCurrentName(int addSlotNumber); void FCEUI_MovieToggleReadOnly(void); bool FCEUI_GetMovieToggleReadOnly(); +void FCEUI_SetMovieToggleReadOnly(bool which); int FCEUI_GetMovieLength(); int FCEUI_GetMovieRerecordCount(); void FCEUI_MovieToggleFrameDisplay();