Commit: 367cbdf9e8209722ca95d9fef06375db5a0d4cf1 Parent: 1cbd58796f8ac1e59c3a1df5c70babb73a836410 Author: Vi Grey Date: 2020-09-16 15:39 UTC Summary: Make lua script timing more accurate bin/lua/fceux.lua | 11 ++++++----- bin/lua/mesen.lua | 11 ++++++----- lua/fceux.lua | 11 ++++++----- lua/mesen.lua | 11 ++++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bin/lua/fceux.lua b/bin/lua/fceux.lua index 7d79df6..8547a14 100644 --- a/bin/lua/fceux.lua +++ b/bin/lua/fceux.lua @@ -30,6 +30,7 @@ local PORT = 56502 local partial = "" local second = 0 local tcpCheckLastTimestamp = 0 +local dataLastTimestamp = 0 -- TCP request to HOST:PORT for ISS Data function getISSData() @@ -49,10 +50,9 @@ function writeBlankFrame() end socket.sleep(5) tcpCheckLastTimestamp = 0 - second = 0 end --- Write minute worth of ISS tracking data to input memory bytes +-- Write second worth of ISS tracking data to input memory bytes function writeSecondData(partial) local timestamp = os.time(os.date("!*t")) local timestampLast = os.time(os.date("!*t")) @@ -64,7 +64,7 @@ function writeSecondData(partial) timestamp = os.time(os.date("!*t")) socket.sleep(0.1) end - timestampLast = timestamp + dataLastTimestamp = timestamp end -- Run at beginning of frame @@ -72,10 +72,11 @@ function handleFrame() memory.writebyte(0, 1) second = second + 1 local timestampNow = os.time(os.date("!*t")) - if timestampNow - tcpCheckLastTimestamp > 59 then + if (timestampNow - dataLastTimestamp > 10) or + (timestampNow - tcpCheckLastTimestamp > 59) then tcpCheckLastTimestamp = timestampNow partial = getISSData() - second = 1 + second = 3 end if string.len(partial) > 600 then writeSecondData(partial) diff --git a/bin/lua/mesen.lua b/bin/lua/mesen.lua index a3a2736..72e39f0 100644 --- a/bin/lua/mesen.lua +++ b/bin/lua/mesen.lua @@ -30,6 +30,7 @@ local PORT = 56502 local partial = "" local second = 0 local tcpCheckLastTimestamp = 0 +local dataLastTimestamp = 0 -- TCP request to HOST:PORT for ISS Data function getISSData() @@ -49,10 +50,9 @@ function writeBlankFrame() end socket.sleep(5) tcpCheckLastTimestamp = 0 - second = 0 end --- Write minute worth of ISS tracking data to input memory bytes +-- Write second worth of ISS tracking data to input memory bytes function writeSecondData(partial) local timestamp = os.time(os.date("!*t")) local timestampLast = os.time(os.date("!*t")) @@ -64,7 +64,7 @@ function writeSecondData(partial) timestamp = os.time(os.date("!*t")) socket.sleep(0.1) end - timestampLast = timestamp + dataLastTimestamp = timestamp end -- Run at beginning of frame @@ -72,10 +72,11 @@ function handleFrame() emu.write(0, 1, emu.memType.cpu) second = second + 1 local timestampNow = os.time(os.date("!*t")) - if timestampNow - tcpCheckLastTimestamp > 59 then + if (timestampNow - dataLastTimestamp > 10) or + (timestampNow - tcpCheckLastTimestamp > 59) then tcpCheckLastTimestamp = timestampNow partial = getISSData() - second = 1 + second = 3 end if string.len(partial) > 600 then writeSecondData(partial) diff --git a/lua/fceux.lua b/lua/fceux.lua index 7d79df6..8547a14 100644 --- a/lua/fceux.lua +++ b/lua/fceux.lua @@ -30,6 +30,7 @@ local PORT = 56502 local partial = "" local second = 0 local tcpCheckLastTimestamp = 0 +local dataLastTimestamp = 0 -- TCP request to HOST:PORT for ISS Data function getISSData() @@ -49,10 +50,9 @@ function writeBlankFrame() end socket.sleep(5) tcpCheckLastTimestamp = 0 - second = 0 end --- Write minute worth of ISS tracking data to input memory bytes +-- Write second worth of ISS tracking data to input memory bytes function writeSecondData(partial) local timestamp = os.time(os.date("!*t")) local timestampLast = os.time(os.date("!*t")) @@ -64,7 +64,7 @@ function writeSecondData(partial) timestamp = os.time(os.date("!*t")) socket.sleep(0.1) end - timestampLast = timestamp + dataLastTimestamp = timestamp end -- Run at beginning of frame @@ -72,10 +72,11 @@ function handleFrame() memory.writebyte(0, 1) second = second + 1 local timestampNow = os.time(os.date("!*t")) - if timestampNow - tcpCheckLastTimestamp > 59 then + if (timestampNow - dataLastTimestamp > 10) or + (timestampNow - tcpCheckLastTimestamp > 59) then tcpCheckLastTimestamp = timestampNow partial = getISSData() - second = 1 + second = 3 end if string.len(partial) > 600 then writeSecondData(partial) diff --git a/lua/mesen.lua b/lua/mesen.lua index a3a2736..72e39f0 100644 --- a/lua/mesen.lua +++ b/lua/mesen.lua @@ -30,6 +30,7 @@ local PORT = 56502 local partial = "" local second = 0 local tcpCheckLastTimestamp = 0 +local dataLastTimestamp = 0 -- TCP request to HOST:PORT for ISS Data function getISSData() @@ -49,10 +50,9 @@ function writeBlankFrame() end socket.sleep(5) tcpCheckLastTimestamp = 0 - second = 0 end --- Write minute worth of ISS tracking data to input memory bytes +-- Write second worth of ISS tracking data to input memory bytes function writeSecondData(partial) local timestamp = os.time(os.date("!*t")) local timestampLast = os.time(os.date("!*t")) @@ -64,7 +64,7 @@ function writeSecondData(partial) timestamp = os.time(os.date("!*t")) socket.sleep(0.1) end - timestampLast = timestamp + dataLastTimestamp = timestamp end -- Run at beginning of frame @@ -72,10 +72,11 @@ function handleFrame() emu.write(0, 1, emu.memType.cpu) second = second + 1 local timestampNow = os.time(os.date("!*t")) - if timestampNow - tcpCheckLastTimestamp > 59 then + if (timestampNow - dataLastTimestamp > 10) or + (timestampNow - tcpCheckLastTimestamp > 59) then tcpCheckLastTimestamp = timestampNow partial = getISSData() - second = 1 + second = 3 end if string.len(partial) > 600 then writeSecondData(partial)