import sys
import time
import bracoujl.processor.gb_z80 as proc

dis = proc.CPU_CONF['disassembler']()

def disassemble(lines):
    res = ''
    for line in lines:
        op = proc.CPU_CONF['parse_line'](line)
        if op is None:
            continue
        res += '{:04X}'.format(op['pc']) + ' - ' + dis.disassemble(op) + '\n'
    res += '-' * 30
    return res

try:
    N = int(sys.argv[1])
except (ValueError, IndexError):
    N = -1

uniq, lines, count = set(), [], 0
for line in sys.stdin:
    if line == '--\n':
        tlines = disassemble(lines)
        if tlines not in uniq:
            uniq.add(tlines)
            print(tlines)
        lines = []
        if N == count:
            sys.exit(0)
        count += 1
    lines.append(line[:-1])

import argparse
import sys
import time
import bracoujl.processor.gb_z80 as proc

dis = proc.CPU_CONF['disassembler']()

def disassemble(lines, keep_logs=False):
    res = []
    for line in lines:
        op, gline = proc.CPU_CONF['parse_line'](line), ''
        if keep_logs:
            gline += line + (' | DIS: ' if op is not None else '')
        else:
            gline += '{:04X}'.format(op['pc']) + ' - '
        if op is not None:
            gline += dis.disassemble(op)
        res.append(gline)
    res.append('-' * 20)
    return '\n'.join(res)

uniq = set()
def display_lines(lines, **kwds):
    tlines = disassemble(lines, **kwds)
    if tlines not in uniq:
        uniq.add(tlines)
        print(tlines)
    return []

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Little disassembly helper.')
    parser.add_argument('-N', action='store', default=-1,
                        help='number of uniq blocks displayed')
    parser.add_argument('-k', '--keep-logs', action='store_true', default=False,
                        help='keep log lines')
    args = parser.parse_args(sys.argv[1:])

    lines, count = [], 0
    for line in sys.stdin:
        if line == '--\n':
            lines = display_lines(lines, keep_logs=args.keep_logs)
            if args.N == count:
                sys.exit(0)
            count += 1
        lines.append(line[:-1])

    if lines:
        display_lines(lines, keep_logs=args.keep_logs)

Fix and enhance disassemble miscellaneous script.
Fix and enhance disassemble miscellaneous script.

+ import argparse
  import sys
  import time
  import bracoujl.processor.gb_z80 as proc
  
  dis = proc.CPU_CONF['disassembler']()
  
- def disassemble(lines):
+ def disassemble(lines, keep_logs=False):
-     res = ''
+     res = []
      for line in lines:
-         op = proc.CPU_CONF['parse_line'](line)
+         op, gline = proc.CPU_CONF['parse_line'](line), ''
+         if keep_logs:
+             gline += line + (' | DIS: ' if op is not None else '')
+         else:
+             gline += '{:04X}'.format(op['pc']) + ' - '
-         if op is None:
+         if op is not None:
-             continue
-         res += '{:04X}'.format(op['pc']) + ' - ' + dis.disassemble(op) + '\n'
-     res += '-' * 30
-     return res
+             gline += dis.disassemble(op)
+         res.append(gline)
+     res.append('-' * 20)
+     return '\n'.join(res)
  
- try:
-     N = int(sys.argv[1])
- except (ValueError, IndexError):
-     N = -1
+ uniq = set()
+ def display_lines(lines, **kwds):
+     tlines = disassemble(lines, **kwds)
+     if tlines not in uniq:
+         uniq.add(tlines)
+         print(tlines)
+     return []
  
+ if __name__ == '__main__':
+     parser = argparse.ArgumentParser(description='Little disassembly helper.')
+     parser.add_argument('-N', action='store', default=-1,
+                         help='number of uniq blocks displayed')
+     parser.add_argument('-k', '--keep-logs', action='store_true', default=False,
+                         help='keep log lines')
+     args = parser.parse_args(sys.argv[1:])
- uniq, lines, count = set(), [], 0
- for line in sys.stdin:
-     if line == '--\n':
-         tlines = disassemble(lines)
-         if tlines not in uniq:
-             uniq.add(tlines)
-             print(tlines)
-         lines = []
-         if N == count:
-             sys.exit(0)
-         count += 1
-     lines.append(line[:-1])
  
+     lines, count = [], 0
+     for line in sys.stdin:
+         if line == '--\n':
+             lines = display_lines(lines, keep_logs=args.keep_logs)
+             if args.N == count:
+                 sys.exit(0)
+             count += 1
+         lines.append(line[:-1])
+ 
+     if lines:
+         display_lines(lines, keep_logs=args.keep_logs)
+ 
Fix and enhance disassemble miscellaneous script.
## Code Before:
import sys
import time
import bracoujl.processor.gb_z80 as proc

dis = proc.CPU_CONF['disassembler']()

def disassemble(lines):
    res = ''
    for line in lines:
        op = proc.CPU_CONF['parse_line'](line)
        if op is None:
            continue
        res += '{:04X}'.format(op['pc']) + ' - ' + dis.disassemble(op) + '\n'
    res += '-' * 30
    return res

try:
    N = int(sys.argv[1])
except (ValueError, IndexError):
    N = -1

uniq, lines, count = set(), [], 0
for line in sys.stdin:
    if line == '--\n':
        tlines = disassemble(lines)
        if tlines not in uniq:
            uniq.add(tlines)
            print(tlines)
        lines = []
        if N == count:
            sys.exit(0)
        count += 1
    lines.append(line[:-1])

## Instruction:
Fix and enhance disassemble miscellaneous script.
## Code After:
import argparse
import sys
import time
import bracoujl.processor.gb_z80 as proc

dis = proc.CPU_CONF['disassembler']()

def disassemble(lines, keep_logs=False):
    res = []
    for line in lines:
        op, gline = proc.CPU_CONF['parse_line'](line), ''
        if keep_logs:
            gline += line + (' | DIS: ' if op is not None else '')
        else:
            gline += '{:04X}'.format(op['pc']) + ' - '
        if op is not None:
            gline += dis.disassemble(op)
        res.append(gline)
    res.append('-' * 20)
    return '\n'.join(res)

uniq = set()
def display_lines(lines, **kwds):
    tlines = disassemble(lines, **kwds)
    if tlines not in uniq:
        uniq.add(tlines)
        print(tlines)
    return []

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Little disassembly helper.')
    parser.add_argument('-N', action='store', default=-1,
                        help='number of uniq blocks displayed')
    parser.add_argument('-k', '--keep-logs', action='store_true', default=False,
                        help='keep log lines')
    args = parser.parse_args(sys.argv[1:])

    lines, count = [], 0
    for line in sys.stdin:
        if line == '--\n':
            lines = display_lines(lines, keep_logs=args.keep_logs)
            if args.N == count:
                sys.exit(0)
            count += 1
        lines.append(line[:-1])

    if lines:
        display_lines(lines, keep_logs=args.keep_logs)
