Persist the running state on disconnection instead of enabling.

This commit is contained in:
Empathic Qubit 2021-11-05 02:24:30 +01:00
parent 168d9373b3
commit 0a62198348
2 changed files with 39 additions and 21 deletions

View file

@ -272,7 +272,9 @@ return function(server)
end end
local function processDisplayGet(command) local function processDisplayGet(command)
print("Taking screenshot")
if command.apiVersion < 0x02 then if command.apiVersion < 0x02 then
print("API Version error")
server.errorResponse(server.errorType.INVALID_API_VERSION, command.requestId) server.errorResponse(server.errorType.INVALID_API_VERSION, command.requestId)
return return
end end
@ -280,6 +282,7 @@ return function(server)
local infoLength = 13; local infoLength = 13;
local shot = emu.takeScreenshot() local shot = emu.takeScreenshot()
print("Screenshot taken")
local r = {} local r = {}
@ -781,7 +784,15 @@ return function(server)
command.type = server.readUint8(remainingHeader, 5) command.type = server.readUint8(remainingHeader, 5)
command.body = body command.body = body
print(string.format("Command start: %02x", command.type)) local prettyType = ""
for k, v in pairs(server.commandType) do
if v == command.type then
prettyType = k
break
end
end
print(string.format("Command start: %02x (%s)", command.type, prettyType))
local ct = command.type local ct = command.type
@ -851,11 +862,12 @@ return function(server)
return return
end end
server.running = false if server.running then
server.running = false
server.deregisterFrameCallback() server.deregisterFrameCallback()
emu.breakExecution() print("Break called by trap")
server.registerFrameCallback() emu.breakExecution()
end
end end
return me return me

View file

@ -206,8 +206,8 @@ local function initConnection()
end end
local function prepareCommand() local function prepareCommand()
initConnection()
if me.conn == nil then if me.conn == nil then
me.running = true
return return
end end
@ -222,7 +222,6 @@ local function prepareCommand()
return return
elseif status == "closed" then elseif status == "closed" then
me.conn = nil me.conn = nil
me.running = true
return return
end end
@ -257,17 +256,11 @@ end
me.deregisterFrameCallback = nil me.deregisterFrameCallback = nil
me.registerFrameCallback = nil me.registerFrameCallback = nil
local function frameHandle() local function frameHandle()
initConnection()
if me.conn == nil then
return
end
prepareCommand() prepareCommand()
if not me.running then if not me.running then
me.deregisterFrameCallback() me.deregisterFrameCallback()
print("Break called by frame")
emu.breakExecution() emu.breakExecution()
me.registerFrameCallback()
end end
end end
@ -280,42 +273,55 @@ function me.deregisterFrameCallback()
emu.removeEventCallback(frameCallback, emu.eventType.inputPolled) emu.removeEventCallback(frameCallback, emu.eventType.inputPolled)
end end
local lastTime = -1
local function breakHandle() local function breakHandle()
print("Break") local pc = emu.getState().cpu.pc
print(string.format("PC: %04x", pc))
if me.stepping then if me.stepping then
me.stepping = false me.stepping = false
commands.monitorOpened() commands.monitorOpened()
end end
local now = socket.gettime()
if lastTime ~= -1 then
print("Took "..(now - lastTime))
end
lastTime = now
print("Start loop")
print(tostring(me.running))
repeat repeat
prepareCommand() prepareCommand()
until me.running until me.running
print("End loop")
me.registerFrameCallback()
emu.resume() emu.resume()
end end
function me.start(host, port, waitForConnection) function me.start(host, port, waitForConnection)
me.stepping = false me.stepping = false
me.running = true
print("Binding to host '" ..host.. "' and port " ..port.. "...") print("Binding to host '" ..host.. "' and port " ..port.. "...")
me.server = assert(socket.tcp()) me.server = assert(socket.tcp())
assert(me.server:bind(host, port)) assert(me.server:bind(host, port))
assert(me.server:listen(32)) assert(me.server:listen(32))
local waitType = ""
if waitForConnection then if waitForConnection then
me.running = false
me.server:settimeout(-1) me.server:settimeout(-1)
waitType = "Waiting"
else else
me.running = true
me.server:settimeout(0) me.server:settimeout(0)
waitType = "Listening"
end end
local i, p = me.server:getsockname() local i, p = me.server:getsockname()
assert(i, p) assert(i, p)
print("Waiting for connection on " .. i .. ":" .. p .. "...") print(string.format("%s for connection on %s:%d...", waitType, i, p))
me.registerFrameCallback()
emu.addEventCallback(breakHandle, emu.eventType.codeBreak) emu.addEventCallback(breakHandle, emu.eventType.codeBreak)