User File #45899707267906862

Upload All User Files

#45899707267906862 - Print memory lua script for JPC-rr

printmemory.lua
Game: Unknown Game ( NES, see all files )
742 downloads
Uploaded 3/21/2018 2:08 AM by c-square (see all 10)
Prints a list of memory addresses
-- Uncomment only one of the following to set the values to print

--inputFilename="sq1-skimmer2.out" -- Prints values from an output file (searchmemory or searchdiffmemory)

--addressList = {246039,240192,240193,240183,240185,240159} -- Prints specific memory addresses

--for i=240140,240169 do -- Prints a range of consecutive addresses
--	table.insert(addressList, i)
--end


function rshift(x, by)
  return math.floor(x / 2 ^ by)
end

byteOld = {}
wordOld = {}

function string:split( inSplitPattern, outResults )
  if not outResults then
    outResults = { }
  end
  local theStart = 1
  local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  while theSplitStart do
    table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
    theStart = theSplitEnd + 1
    theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  end
  table.insert( outResults, string.sub( self, theStart ) )
  return outResults
end

-- Main
if inputFilename then
	print("Opening input file")
	inputBinary, error=io.open_read(inputFilename)
	print("Spitting input")
	searchStr = inputBinary.read()
	inputBinary:close()
	searchList = searchStr:split(",")
	print("Input split into " .. #searchList .. " items")
end
if not searchList then
	searchList={}
end
if addressList then
	for i,v in ipairs(addressList) do
		table.insert(searchList, v)
	end
end
while true do
	a, b = jpcrr.wait_event();
	if a == "lock" then
		if nowTick ~= jpcrr.clock_time() then
			nowTick=jpcrr.clock_time()
			--print("--- " .. nowTick .. " ---")
			for i,v in ipairs(searchList) do
				byteValue = jpcrr.read_byte(v)
				wordValue = jpcrr.read_word(v)
				if byteOld[v] == nil or byteOld[v] ~= byteValue or wordOld[v] == nil or wordOld[v] ~= wordValue then
					print("@" .. nowTick .. ": " .. v .. " -> " .. byteValue .. "|" .. wordValue )--.. " [" .. string.char(byteValue) .. "]")
					byteOld[v]=byteValue
					wordOld[v]=wordValue
				end
			end
		end
		jpcrr.release_vga();
	end
end