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 script works but was an over night . Will upload it soon!
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 list.lst Code (Text): 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.
My code currently doesn’t work 100 percent of the time because the code section of the list file has variation to the format. For instance some lines depth for include (n) at the beginning of the line. Is it easily possible with all the variations of the asw compiler to correctly finds all the code section of the list code correlating. Also is there annotated disassembler for sonic or any asw assembled rom using list file? Or any other method of seeing labels and such whether runtime in emulator or in trace ? Also, I have optimized the code to run many many times faster . My test ran in couple seconds for my revision vs minutes of above code. Will post it soon.