Skip to content

Commit

Permalink
Corrected documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
njz3 committed Dec 27, 2020
1 parent e6252ee commit f5cba7d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 61 deletions.
3 changes: 2 additions & 1 deletion Scripts/lemans24.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Scripts/scudplus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 13 additions & 39 deletions Src/OSD/Scripting/IScripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions Src/OSD/Scripting/LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
49 changes: 35 additions & 14 deletions Src/OSD/Scripting/LuaEngine.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -53,6 +54,7 @@ extern "C"
}

#endif // __LUA_INC_H__
#pragma endregion

using namespace std;

Expand All @@ -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
*/

Expand Down Expand Up @@ -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];
};
Expand Down

0 comments on commit f5cba7d

Please sign in to comment.