From f5cba7d84829c6f9ba0f0d5533ead4d85dbdc4e7 Mon Sep 17 00:00:00 2001 From: Benjamin Maurin Date: Sun, 27 Dec 2020 10:54:22 +0100 Subject: [PATCH] Corrected documentation --- Scripts/lemans24.lua | 3 +- Scripts/scudplus.lua | 3 +- Src/OSD/Scripting/IScripting.h | 52 +++++++++------------------------ Src/OSD/Scripting/LuaEngine.cpp | 17 +++++++---- Src/OSD/Scripting/LuaEngine.h | 49 ++++++++++++++++++++++--------- 5 files changed, 63 insertions(+), 61 deletions(-) diff --git a/Scripts/lemans24.lua b/Scripts/lemans24.lua index ee725ad..cff19e3 100644 --- a/Scripts/lemans24.lua +++ b/Scripts/lemans24.lua @@ -30,8 +30,9 @@ function Frame() print("Drv=0x" .. string.format("%X", driveboard) .. " Lamps=0x") println(string.format("%X", lamps)) - local gameState = 0x16 + -- Do not known yet where to find the gamemode ... -- local gameState = PPC_Read8(0x5010A4) + local gameState = 0x16 -- println(gameState) if gameState==0x16 -- Ingame diff --git a/Scripts/scudplus.lua b/Scripts/scudplus.lua index ee725ad..cff19e3 100644 --- a/Scripts/scudplus.lua +++ b/Scripts/scudplus.lua @@ -30,8 +30,9 @@ function Frame() print("Drv=0x" .. string.format("%X", driveboard) .. " Lamps=0x") println(string.format("%X", lamps)) - local gameState = 0x16 + -- Do not known yet where to find the gamemode ... -- local gameState = PPC_Read8(0x5010A4) + local gameState = 0x16 -- println(gameState) if gameState==0x16 -- Ingame diff --git a/Src/OSD/Scripting/IScripting.h b/Src/OSD/Scripting/IScripting.h index 4ffb5ed..0778429 100644 --- a/Src/OSD/Scripting/IScripting.h +++ b/Src/OSD/Scripting/IScripting.h @@ -7,51 +7,25 @@ using namespace std; /* -From Nebula Model2 Emulator: - -LUA Scripts - -The emulator will load a script named the same than the romset, ended in .lua in the SCRIPTS folder (ex: daytona.lua) - -Each script can add some functions that will be called by the emulator: - -Init() - Called when the game has been loaded and is about to start - -Reset() - Called when the game has been reset (not on first reset, use Init for the first reset) - -Frame() - Called right after emulating a frame, and before starting video rendering - -PostDraw() - Called right after rendering the frame, and before blitting the frame to the screen (so you can add text - and other images to the rendered image - -End() - Called when the emulator is about to terminate the emulation (use for cleanup or data persistence) - -Inside the LUA scripts you can access the emulator by using some helper functions provided by the emulator: - - -ROM Access functions - -int Romset_ReadByte(int area,int offset) -int Romset_ReadWord(int area,int offset) -int Romset_ReadDWord(int area,int offset) - Read byte/word/dword from rom files at specified area and offset - -Romset_PatchByte(int area,int offset,int data) -Romset_PatchWord(int area,int offset,int data) -Romset_PatchDWord(int area,int offset,int data) - Write byte/word/dword to rom files at specified area and offset - + Support for scripting engine running at particular hooks in Model3 emulator. + - Initialize(), Load() are called when AttachScripting() is called by the + emulator once the game is loaded. + - The script command Init() is called rigth after Load(), also in + AttachScripting() + - Reset(), Frame(), PostDraw() and EndFrame() are called in Model3 emulator + either in RunFrame() or Reset() + - End() is called when the Model3 emulator is terminating. + + The SetGlobalXX methods are not used yet, but I put them just in case the + emulator should add or refresh global variables in the scripting engine while + it is running. */ class IScripting { public: virtual void Initialize(IEmulator* emulator) = 0; virtual void LoadScript(string filename) = 0; + virtual void SetGlobalString(string varname, string value) = 0; virtual void SetGlobalDouble(string varname, double value) = 0; virtual void SetGlobalInteger(string varname, long long value) = 0; diff --git a/Src/OSD/Scripting/LuaEngine.cpp b/Src/OSD/Scripting/LuaEngine.cpp index 39b591d..2886a2a 100644 --- a/Src/OSD/Scripting/LuaEngine.cpp +++ b/Src/OSD/Scripting/LuaEngine.cpp @@ -4,8 +4,8 @@ - -#pragma region Method registered in Lua +#pragma region Method registered in Lua +// print(string text) int LuaEngine::print(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -24,6 +24,7 @@ int LuaEngine::print(lua_State* lua) } return 0; } +// println(string text) int LuaEngine::println(lua_State* lua) { print(lua); printf("\n"); @@ -44,6 +45,7 @@ int LuaEngine::PPC_Read8(lua_State* lua) lua_pushinteger(lua, value); /* push result */ return 1; /* number of results */ } +// PPC_Write8(int addr, int data) int LuaEngine::PPC_Write8(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -68,6 +70,7 @@ int LuaEngine::PPC_Read16(lua_State* lua) lua_pushinteger(lua, value); /* push result */ return 1; /* number of results */ } +// PPC_Write16(int addr, int data) int LuaEngine::PPC_Write16(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -92,6 +95,7 @@ int LuaEngine::PPC_Read32(lua_State* lua) lua_pushinteger(lua, value); /* push result */ return 1; /* number of results */ } +// PPC_Write32(int addr, int data) int LuaEngine::PPC_Write32(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -103,8 +107,8 @@ int LuaEngine::PPC_Write32(lua_State* lua) me->_model3->Write32(addr, data); return 1; /* number of results */ } -// int PPC_Read64(int area, int offset) -// Lua handles 64 bits integer +// int PPC_Read64(int addr) +// Lua handles 64 bits integer using 0x notation int LuaEngine::PPC_Read64(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -116,6 +120,7 @@ int LuaEngine::PPC_Read64(lua_State* lua) lua_pushinteger(lua, value); /* push result */ return 1; /* number of results */ } +// PPC_Write64(int addr, int data) int LuaEngine::PPC_Write64(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -129,7 +134,7 @@ int LuaEngine::PPC_Write64(lua_State* lua) } -// int Gfx_SetWideScreen(int mode) +// Gfx_SetWideScreen(int mode) int LuaEngine::Gfx_SetWideScreen(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); @@ -146,7 +151,7 @@ int LuaEngine::Gfx_SetWideScreen(lua_State* lua) return 0; /* number of results */ } -// int Gfx_SetWideScreen(int mode) +// Gfx_SetWideScreen(int mode) int LuaEngine::Gfx_SetStretchBLow(lua_State* lua) { LuaEngine* me = (LuaEngine*)lua_touserdata(lua, lua_upvalueindex(1)); diff --git a/Src/OSD/Scripting/LuaEngine.h b/Src/OSD/Scripting/LuaEngine.h index c52786e..fc6bdec 100644 --- a/Src/OSD/Scripting/LuaEngine.h +++ b/Src/OSD/Scripting/LuaEngine.h @@ -1,7 +1,7 @@ #pragma once #include "IScripting.h" - +#pragma region All of this only to be able to get the definition of CModel3 #include "BlockFile.h" #include "Graphics/New3D/New3D.h" #include "Graphics/Render2D.h" @@ -41,8 +41,9 @@ #include "Network/NetBoard.h" #endif #include "Model3/Model3.h" +#pragma endregion - +#pragma region Lua's includes #ifndef __LUA_INC_H__ #define __LUA_INC_H__ extern "C" @@ -53,6 +54,7 @@ extern "C" } #endif // __LUA_INC_H__ +#pragma endregion using namespace std; @@ -78,23 +80,41 @@ PostDraw() Called right after rendering the frame, and before blitting the frame to the screen (so you can add text and other images to the rendered image +EndFrame() + Called when everything has been emulated (including sound, network), before the next frame will start + End() Called when the emulator is about to terminate the emulation (use for cleanup or data persistence) Inside the LUA scripts you can access the emulator by using some helper functions provided by the emulator: - -ROM Access functions - -int Romset_ReadByte(int area,int offset) -int Romset_ReadWord(int area,int offset) -int Romset_ReadDWord(int area,int offset) - Read byte/word/dword from rom files at specified area and offset - -Romset_PatchByte(int area,int offset,int data) -Romset_PatchWord(int area,int offset,int data) -Romset_PatchDWord(int area,int offset,int data) - Write byte/word/dword to rom files at specified area and offset +Helpers: +-------- +print(string text) +println(string text) + Output a text to Supermodel's console + +ROM Access functions: +--------------------- +int PPC_Read8(int addr) +int PPC_Read16(int addr) +int PPC_Read32(int addr) +int PPC_Read64(int addr) + Read byte/word/dword from ram or rom at specified address in the PPC addressing space + +PPC_Write8(int addr, int data) +PPC_Write16(int addr, int data) +PPC_Write32(int addr, int data) +PPC_Write64(int addr, int data) + Write byte/word/dword to ram or patch rom at specified address in the PPC addressing space + + +Tweaks: +------- +Gfx_SetWideScreen(int mode) + Change the "WideScreen" configuration flag in realtime +Gfx_SetStretchBLow(int mode) + Change the "WideBackground" configuration flag in realtime */ @@ -145,6 +165,7 @@ class LuaEngine : IScripting protected: CModel3* _model3; lua_State* _lua; + // Used as runtime flags to avoid running pcall() when the script or method does not exist bool ScriptLoaded; bool HasHook[6]; };