User File #44479929346959023

Upload All User Files

#44479929346959023 - Run TAS Script for JPC-rr

runtasscript.lua
Game: Unknown Game ( NES, see all files )
773 downloads
Uploaded 1/16/2018 3:34 AM by c-square (see all 10)
Use this file to run tas scripts in JPC-rr. Needs fileio.lua to run.
dofile("fileio.lua");
scriptFile = "input.tas" -- This is the TAS Script you want to run

print("-- Loading & Parsing Script File.  Do not start movie yet. --")

scriptLines = readInputFile(scriptFile)

print("-- Parsing Script File --")
commands={}
values={}
lineNumber=1
-- Parse Script
index=0
while scriptLines[lineNumber] ~= nil do
	if string.sub(scriptLines[lineNumber],1,1) ~= ":" then
		index=index+1
		parse = scriptLines[lineNumber]:split(":")
		commands[index] = parse[1]
		values[index] = parse[2]
	end
	lineNumber=lineNumber+1
end

nowTick=0
index=1
frameAdvance=0

print("-- Loading & Parsing Complete.  Start Movie Running to Begin Running Script. --")

while true do
	a, b = jpcrr.wait_event();
	if a == "lock" then
		if nowTick ~= jpcrr.clock_time() then
			nowTick=jpcrr.clock_time()
			-- Just frame advance
			if frameAdvance > 0 then
				print("FAdv: " .. frameAdvance) 
				frameAdvance = frameAdvance - 1
				if frameAdvance == 0 then
					index=index+1
				end
			elseif commands[index] == nil then
				print("-- Script Complete.  Terminate Lua Script. --")
				jpcrr.pc_stop()
			else 
				-- Process Command
				while commands[index] ~= nil do
					print(index.. " - Command: " .. commands[index]) 
					if commands[index] == "FAdv" then
						print("FAdv = " .. values[index]) 
						frameAdvance = frameAdvance + math.max(0, tonumber(values[index])-1)
						if frameAdvance == 0 then
							index=index+1
						end
						break
					elseif commands[index] == "Type" then
						letter=1
						while letter <= string.len(values[index]) do
							word=""
							if string.sub(values[index],letter,letter) ~= "<" then
								word = string.sub(values[index],letter,letter)
							else
								while string.sub(values[index],letter,letter) ~= nil and string.sub(values[index],letter,letter) ~= ">" do
									word = word .. string.sub(values[index],letter,letter)
									letter=letter+1
								end
								word = word .. ">"
							end
							print("Typing: " .. word) 
							keyedge = getKeyedge(word)
							jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard","KEYEDGE",keyedge)
							letter=letter+1
						end				
					elseif commands[index] == "MClick" then
						print("Mouse Click: " .. values[index]) 
						jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard","MOUSEBUTTON",values[index])
					elseif commands[index] == "MXMove" then
						print("Mouse X: '" .. values[index].."'") 
						jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard","XMOUSEMOTION",values[index])
					elseif commands[index] == "MYMove" then
						print("Mouse Y: '" .. values[index].."'") 
						jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard","YMOUSEMOTION",values[index])
					elseif commands[index] == "Save" then
						print("Save #" .. values[index] .. ": Using XMouseMotion 0")
						jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard","XMOUSEMOTION",0)
					elseif commands[index] == "Pause" then
						print("Pausing")
						jpcrr.pc_stop()
					else
						print ("ERROR! Unknown command: " .. commands[index])
					end
					index = index + 1
				end
			end
		end
		jpcrr.release_vga();
	end
end