Пример #1
0
def trace_code(pc, data, marks, points, labels):
    """Follows a line of code until an unconditional branch or invalid opcode"""

    while not marks[pc]:
        op = data[pc]
        opinfo = nestech.cpu_opcodes[op]
        length = 1 + nestech.cpu_addr_modes[opinfo[1]].get_length()
        mneumonic = opinfo[0]
        

        if op in branches:
            marks[pc] = True
            if not marks[nestech.rel_addr(pc, data)]:
                points.insert(0,nestech.rel_addr(pc, data))
            if not nestech.rel_addr(pc, data) in labels:
                labels.insert(0,nestech.rel_addr(pc, data))
            pc += length

        elif op in jsr:
            marks[pc] = True
            if not marks[nestech.abs_addr(pc, data)]:
                points.insert(0,nestech.abs_addr(pc, data))
            if not nestech.abs_addr(pc, data) in labels:
                labels.insert(0,nestech.abs_addr(pc, data))
            pc += length

        elif op in jump_absolute:
            marks[pc] = True
            if not marks[nestech.abs_addr(pc, data)]:
                points.insert(0,nestech.abs_addr(pc, data))
            if not nestech.abs_addr(pc, data) in labels:
                labels.insert(0,nestech.abs_addr(pc, data))
            return

        elif op in jump_indirect:
            marks[pc] = True
            return

        elif op in return_ops:
            marks[pc] = True
            return

        elif not mneumonic == 'und':
            addr_mode = nestech.cpu_addr_modes[opinfo[1]].get_name()
            # may change to 'absolute ' if want to just do indexed
            if 'absolute' in addr_mode:
                addr = nestech.abs_addr(pc, data)
                if 0x8000 <= addr and addr <= 0xffff:
                    labels.insert(0,addr)
            marks[pc] = True
            pc += length
        else:
            return 
Пример #2
0
        if op in redir_ops:
            if named_labels.has_key(int(arg[1:], 16)):
                arg = named_label[int(arg[1:], 16)]
                code_string = 4*' ' + mneumonic  + ' ' + arg 
                code_string += (16-len(arg))*' ' + '; $%04x' % (pc)
            else:
                arg = arg[1:].upper()
                code_string = 4*' ' + mneumonic  + ' ' + 'L' + arg 
                code_string += 11*' ' + '; $%04x' % (pc)

        elif 'absolute' in addr_mode:
            if named_labels.has_key(int(arg[1:5], 16)):
                arg = named_label[int(arg[1:], 16)]
                code_string = 4*' ' + mneumonic + ' ' +  arg 
                code_string += (16-len(arg))*' ' + '; $%04x' % (pc)
            elif nestech.abs_addr(pc, prg_data) in labels:
                arg = arg[1:5].upper() + arg[5:]
                code_string = 4*' ' + mneumonic + ' ' + 'L' + arg 
                code_string += (16 - len(arg) - 1)*' ' + '; $%04x' % (pc)
            else:
                code_string = 4*' ' + mneumonic + ' ' + arg 
                code_string += (16 - len(arg))*' ' + '; $%04x' % (pc)

        else:
            code_string = 4*' ' + mneumonic  + ' ' + arg 
            code_string += (16 - len(arg))*' ' + '; $%04x' % (pc)

        output_file.write(code_string + '\n')
        pc += length

output_file.write('\n\n')