Page 1 of 1
Introducing My Annotated Trace Generator
Posted: Mon Feb 28, 2022 11:24 pm
by Okie
My script ( hopefully ) works on any disassembly that uses ASW. I could find annotated disassembler feature in an Emulator that works with ASW (AS.exe) . So I wrote a Lua script that takes two inputs. A trace file you made with gens-re-record and the games list file generated by ASW. It outputs to a new trace file, each line from the trace file with the correlating lines of code from this list file with labels symbols below the trace line . Followed by a empty new line. And continues doing this for every line in the trace file. Here is an example output from Sonic 3 and Knuckles:
Please let me know if a annotated disassembler that works with asw list files exists or if a similar parsing script / program, like this one exists .
The way the code works is it uses io library to scan the entire list file for every line In the trace file. It’s pretty slow , wasn’t sure if it’s how I m coding it ( scanning the file using I/O library the entire program instead of Saving the entire file in elements of a table. And create a new iOS handle re opening the list file , every time it goes to a new line in the trace file ) . Do I need to use C or can Lua easily for this task be blitz fast?
Re: Introducing My Annotated Trace Generator
Posted: Tue Mar 01, 2022 1:09 am
by Okie
Here is the code in its early stage . You put trace in the scripts directory and name it trace.log. Put list file also in same directory and rename it
Code: Select all
TraceFileHandle= assert(io.open("trace.log", "r"))
local TraceLines = TraceFileHandle:lines();
local Output = assert(io.open("Output.txt", "w"))
local CurrentTraceLineAddress = nil
local CurrentListLineAddress = nil
for CurrentTraceLine in TraceLines do
-- if the Gens trace files line started with nn:nnnn - the instructions address
if string.find(CurrentTraceLine,"^%x%x:%x%x%x%x") ~= nil then
-- get the address the instruction, formatting it to asw list files format for the instructions address
-- removing the : and any possible 0 in front of address
CurrentTraceLineAddress = string.sub(CurrentTraceLine,string.find(CurrentTraceLine,"^%x%x:%x%x%x%x"))
-- remove the :
CurrentTraceLineAddress = string.sub(CurrentTraceLineAddress,1,2) .. string.sub(CurrentTraceLineAddress,4,7)
-- do we need to format it, removing "0" in front of address
if CurrentTraceLineAddress ~= "000000" and string.find(CurrentTraceLineAddress,"^0+") ~= nil then
local __ , zeroTrailEnd = string.find(CurrentTraceLineAddress,"^0+")
CurrentTraceLineAddress = string.sub(CurrentTraceLineAddress,zeroTrailEnd+1,string.len(CurrentTraceLineAddress))
end
-- if address of the current line of the trace acde file is RAM, add 10 "F"
-- to front to make the RAM address follow the asw list format of the address
if tonumber(CurrentTraceLineAddress,16) >= 0xFF0000 then
CurrentTraceLineAddress = "FFFFFFFFFF" .. CurrentTraceLineAddress
end
-- Append THIS TRACE FILE LINE TO OUTPUT FILE
Output:write("\n" .. CurrentTraceLine .."\n")
local ListFileHandle = assert(io.open("list.lst", "r"));
local ListLines = ListFileHandle:lines();
for CurrentListLine in ListLines do
-- if the line in the list file has an adress for instruction then
-- Parse and get the Address of the instruction in the listing file
-- and check if it is the same address as the line in the trace file
if string.find(CurrentListLine,"/%s*%x+%s:") then
-- 40952/ 1EE94 : D640 add.w d0,d3
CurrentListLineAddress = string.sub(CurrentListLine,string.find(CurrentListLine,"/%s*%x+%s:"))
local CurrentListLineAddressStart = string.find(CurrentListLineAddress,"%x")
local CurrentListLineAddressEnd = string.len(CurrentListLineAddress) - 2
CurrentListLineAddress = string.sub(CurrentListLineAddress,CurrentListLineAddressStart,CurrentListLineAddressEnd)
-- if the trace and list file are the same address for the instruction
-- print(CurrentListLineAddress)
-- print(string.len(CurrentListLineAddress))
-- print(string.len(CurrentTraceLineAddress))
if CurrentListLineAddress == CurrentTraceLineAddress then
-- Then append this line in TRACE FILE TO OUTPUT FILE
Output:write(CurrentListLine.."\n")
end
end
end
ListFileHandle:close()
end
LINENUMBA = LINENUMBA + 1
end
TraceFileHandle:close()
Output:close()
Would very much appreciate all speed optimization advice to make run even faster.