---------------------------------------------------------- -- DSM import function (TODO: add reset/LID/MIC) ---------------------------------------------------------- function dsmImport(path) local file = io.open(path, "r") if file == nil then return nil end local line = file:read("*l") local dsm = {} local f = 1 dsm.frame = {} while line do if string.sub(line, 1, 1) == "|" then local padOfs = string.find(line, "|", 2) + 1 local buttonMappings = { "right", "left", "down", "up", "start", "select", "B", "A", "Y", "X", "L", "R", "debug" } dsm.frame[f] = {} dsm.frame[f].cmd = tonumber(string.sub(line, 2, padOfs - 2)) for i = 0, #buttonMappings - 1 do s = string.sub(line, padOfs + i, padOfs + i); dsm.frame[f][buttonMappings[i+1]] = ((s~="." and s~=" ") and true or nil) end dsm.frame[f].touchX = tonumber(string.sub(line, padOfs + 13, padOfs + 15)) dsm.frame[f].touchY = tonumber(string.sub(line, padOfs + 17, padOfs + 19)) dsm.frame[f].isTouch = ((tonumber(string.sub(line, padOfs + 21, padOfs + 21))~=0) and true or false) f = f + 1 end line = file:read("*l") end file:close() return dsm end local dsm = dsmImport("a.dsm") print(#dsm.frame .. " frames")