Skip to content

Instantly share code, notes, and snippets.

@digarok
Created July 14, 2021 16:02
Show Gist options
  • Save digarok/6cf911ed071e4f56a94fd07d8ada97a0 to your computer and use it in GitHub Desktop.
Save digarok/6cf911ed071e4f56a94fd07d8ada97a0 to your computer and use it in GitHub Desktop.
Take a list of assembly DEFINE BYTE statements ( " DB $2C") and print them at various grid sizes to look for patterns/alignment.
import fileinput,re,time
# parameters
pattern_DEFINE_BYTE='^.+DB\s+\$([a-fA-F0-9][a-fA-F0-9])'
pause_seconds=0.5
grid_range = range(4,33) # range is not inclusive
join_str = "" # change to comma if you want CSV
def print_chunked(datalist, chunksize):
for i in range(0, len(datalist), chunksize):
chunk = datalist[i:i+chunksize]
print(join_str.join(chunk))
for grid_x in grid_range:
scrape = []
for line in fileinput.input():
#print(line)
result = re.match(pattern_DEFINE_BYTE, line)
if result != None: # got a match so add it to list
scrape.append(result[1])
else: # no match
if len(scrape) > 0: # so print if we have any backlog
print_chunked(scrape, grid_x)
scrape = []
print(line) # print the unmatching line raw
if len(scrape) > 0: # print any remaining scraped values after EOF
print_chunked(scrape, grid_x)
print(f'grid_x={grid_x}') # tell the people how we doing
time.sleep(pause_seconds) # ZZzz..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment