Lua: Added getRomInfo/getLogWindowLog and changed getState to return doubles for apu channel frequencies

This commit is contained in:
Sour 2017-12-20 22:11:36 -05:00
parent b9053e3d5e
commit 50d7bbf492
7 changed files with 47 additions and 13 deletions

View file

@ -216,7 +216,7 @@ ApuDmcState DeltaModulationChannel::GetState()
{
ApuDmcState state;
state.BytesRemaining = _bytesRemaining;
state.Frequency = (uint32_t)(CPU::GetClockRate(GetNesModel()) / 32.0 / (_period + 1));
state.Frequency = CPU::GetClockRate(GetNesModel()) / 32.0 / (_period + 1);
state.IrqEnabled = _irqEnabled;
state.Loop = _loopFlag;
state.OutputVolume = _lastOutput;

View file

@ -21,7 +21,9 @@
#include "KeyManager.h"
#define lua_pushintvalue(name, value) lua_pushliteral(lua, #name); lua_pushinteger(lua, (int)value); lua_settable(lua, -3);
#define lua_pushdoublevalue(name, value) lua_pushliteral(lua, #name); lua_pushnumber(lua, (double)value); lua_settable(lua, -3);
#define lua_pushboolvalue(name, value) lua_pushliteral(lua, #name); lua_pushboolean(lua, (int)value); lua_settable(lua, -3);
#define lua_pushstringvalue(name, value) lua_pushliteral(lua, #name); lua_pushstring(lua, value.c_str()); lua_settable(lua, -3);
#define lua_starttable(name) lua_pushliteral(lua, name); lua_newtable(lua);
#define lua_endtable() lua_settable(lua, -3);
#define lua_readint(name, dest) lua_getfield(lua, -1, #name); dest = l.ReadInteger();
@ -95,6 +97,8 @@ int LuaApi::GetLibrary(lua_State *lua)
{ "setState", LuaApi::SetState },
{ "getState", LuaApi::GetState },
{ "getScriptDataFolder", LuaApi::GetScriptDataFolder },
{ "getRomInfo", LuaApi::GetRomInfo },
{ "getLogWindowLog", LuaApi::GetLogWindowLog },
{ NULL,NULL }
};
@ -631,6 +635,34 @@ int LuaApi::GetScriptDataFolder(lua_State *lua)
return l.ReturnCount();
}
int LuaApi::GetRomInfo(lua_State *lua)
{
LuaCallHelper l(lua);
checkparams();
lua_newtable(lua);
lua_pushstringvalue(name, Console::GetRomName());
lua_pushstringvalue(path, ((string)Console::GetRomPath()));
HashInfo hashInfo = Console::GetHashInfo();
lua_pushintvalue(fileCrc32Hash, hashInfo.Crc32Hash);
lua_pushstringvalue(fileSha1Hash, hashInfo.Sha1Hash);
lua_pushintvalue(prgChrCrc32Hash, hashInfo.PrgCrc32Hash);
lua_pushstringvalue(prgChrMd5Hash, hashInfo.PrgChrMd5Hash);
lua_pushintvalue(format, Console::GetRomFormat());
lua_pushboolvalue(isChrRam, Console::IsChrRam());
return 1;
}
int LuaApi::GetLogWindowLog(lua_State *lua)
{
LuaCallHelper l(lua);
checkparams();
l.Return(MessageManager::GetLog());
return l.ReturnCount();
}
int LuaApi::SetState(lua_State *lua)
{
LuaCallHelper l(lua);
@ -806,7 +838,7 @@ int LuaApi::GetState(lua_State *lua)
lua_starttable("triangle");
lua_pushboolvalue(enabled, state.APU.Triangle.Enabled);
lua_pushintvalue(frequency, state.APU.Triangle.Frequency);
lua_pushdoublevalue(frequency, state.APU.Triangle.Frequency);
PushLengthCounterState(lua, state.APU.Triangle.LengthCounter);
lua_pushintvalue(outputVolume, state.APU.Triangle.OutputVolume);
lua_pushintvalue(period, state.APU.Triangle.Period);
@ -815,7 +847,7 @@ int LuaApi::GetState(lua_State *lua)
lua_starttable("noise");
lua_pushboolvalue(enabled, state.APU.Noise.Enabled);
lua_pushintvalue(frequency, state.APU.Noise.Frequency);
lua_pushdoublevalue(frequency, state.APU.Noise.Frequency);
PushEnvelopeState(lua, state.APU.Noise.Envelope);
PushLengthCounterState(lua, state.APU.Noise.LengthCounter);
lua_pushboolvalue(modeFlag, state.APU.Noise.ModeFlag);
@ -826,7 +858,7 @@ int LuaApi::GetState(lua_State *lua)
lua_starttable("dmc");
lua_pushintvalue(bytesRemaining, state.APU.Dmc.BytesRemaining);
lua_pushintvalue(frequency, state.APU.Dmc.Frequency);
lua_pushdoublevalue(frequency, state.APU.Dmc.Frequency);
lua_pushboolvalue(irqEnabled, state.APU.Dmc.IrqEnabled);
lua_pushboolvalue(loop, state.APU.Dmc.Loop);
lua_pushintvalue(outputVolume, state.APU.Dmc.OutputVolume);
@ -850,7 +882,7 @@ void LuaApi::PushSquareState(lua_State *lua, ApuSquareState & state)
{
lua_pushintvalue(duty, state.Duty);
lua_pushintvalue(dutyPosition, state.DutyPosition);
lua_pushintvalue(frequency, state.Frequency);
lua_pushdoublevalue(frequency, state.Frequency);
lua_pushintvalue(period, state.Period);
lua_pushboolvalue(sweepEnabled, state.SweepEnabled);
lua_pushboolvalue(sweepNegate, state.SweepNegate);

View file

@ -65,7 +65,9 @@ public:
static int AddCheat(lua_State *lua);
static int ClearCheats(lua_State *lua);
static int GetScriptDataFolder(lua_State * lua);
static int GetScriptDataFolder(lua_State *lua);
static int GetRomInfo(lua_State *lua);
static int GetLogWindowLog(lua_State *lua);
static int SetState(lua_State *lua);
static int GetState(lua_State *lua);

View file

@ -91,7 +91,7 @@ public:
ApuNoiseState state;
state.Enabled = _enabled;
state.Envelope = ApuEnvelope::GetState();
state.Frequency = (uint32_t)((CPU::GetClockRate(GetNesModel()) / (_period + 1)) / (_modeFlag ? 93 : 1));
state.Frequency = CPU::GetClockRate(GetNesModel()) / (_period + 1) / (_modeFlag ? 93 : 1);
state.LengthCounter = ApuLengthCounter::GetState();
state.ModeFlag = _modeFlag;
state.OutputVolume = _lastOutput;

View file

@ -191,7 +191,7 @@ public:
state.DutyPosition = _dutyPos;
state.Enabled = _enabled;
state.Envelope = ApuEnvelope::GetState();
state.Frequency = (uint32_t)(CPU::GetClockRate(GetNesModel()) / 16.0 / (_realPeriod + 1));
state.Frequency = CPU::GetClockRate(GetNesModel()) / 16.0 / (_realPeriod + 1);
state.LengthCounter = ApuLengthCounter::GetState();
state.OutputVolume = _lastOutput;
state.Period = _realPeriod;

View file

@ -105,7 +105,7 @@ public:
{
ApuTriangleState state;
state.Enabled = _enabled;
state.Frequency = (uint32_t)(CPU::GetClockRate(GetNesModel()) / 32.0 / (_period + 1));
state.Frequency = CPU::GetClockRate(GetNesModel()) / 32.0 / (_period + 1);
state.LengthCounter = ApuLengthCounter::GetState();
state.OutputVolume = _lastOutput;
state.Period = _period;

View file

@ -168,7 +168,7 @@ struct ApuSquareState
bool Enabled;
uint8_t OutputVolume;
uint32_t Frequency;
double Frequency;
ApuLengthCounterState LengthCounter;
ApuEnvelopeState Envelope;
@ -180,7 +180,7 @@ struct ApuTriangleState
uint8_t SequencePosition;
bool Enabled;
uint32_t Frequency;
double Frequency;
uint8_t OutputVolume;
ApuLengthCounterState LengthCounter;
@ -193,7 +193,7 @@ struct ApuNoiseState
bool ModeFlag;
bool Enabled;
uint32_t Frequency;
double Frequency;
uint8_t OutputVolume;
ApuLengthCounterState LengthCounter;
@ -210,7 +210,7 @@ struct ApuDmcState
uint16_t Period;
uint16_t BytesRemaining;
uint32_t Frequency;
double Frequency;
uint8_t OutputVolume;
};