Beispiel #1
0
def emit_opcode_table(out, idic, prefix, links, preamble):
    """emit a function table for each opcode with this prefix"""
    out.indent(2)
    label = '_%s' % ''.join(['%02x' % byte for byte in prefix])
    out.put('self.opcodes%s = (\n' % (label, '')[len(label) == 1])
    out.indent(1)

    for opcode in range(0x100):
        code = list(prefix)
        code.append(opcode)
        # disassemble the instruction
        mem = memory.ram(4)
        mem.load(0, code)
        (operation, operands, nbytes) = z80da.disassemble(mem, 0)
        # add the instruction to the dictionary
        inst = ' '.join((operation, operands))
        label = ''.join(['%02x' % byte for byte in code])

        if opcode in links:
            out.put('self._execute_%s,' % label)
            out.pad(36)
            out.put('# 0x%02x execute %s prefix\n' % (opcode, label))
        else:
            # add the inst/label to the dictionary if it is unique
            if idic.has_key(inst) == False:
                idic[inst] = (label, code, preamble)
            out.put('self._ins_%s,' % idic[inst][0])
            out.pad(36)
            out.put('# 0x%02x %s\n' % (opcode, inst))

    out.outdent(1)
    out.put(')\n')
    out.outdent(2)
Beispiel #2
0
def emit_opcode_table(out, idic, prefix, links, preamble):
    """emit a function table for each opcode with this prefix"""
    out.indent(2)
    label = '_%s' % ''.join(['%02x' % byte for byte in prefix])
    out.put('self.opcodes%s = (\n' % (label, '')[len(label) == 1])
    out.indent(1)

    for opcode in range(0x100):
        code = list(prefix)
        code.append(opcode)
        # disassemble the instruction
        mem = memory.ram(4)
        mem.load(0, code)
        (operation, operands, nbytes) = z80da.disassemble(mem, 0)
        # add the instruction to the dictionary
        inst = ' '.join((operation, operands))
        label = ''.join(['%02x' % byte for byte in code])

        if opcode in links:
            out.put('self._execute_%s,' % label)
            out.pad(36)
            out.put('# 0x%02x execute %s prefix\n' % (opcode, label))
        else:
            # add the inst/label to the dictionary if it is unique
            if idic.has_key(inst) == False:
                idic[inst] = (label, code, preamble)
            out.put('self._ins_%s,' % idic[inst][0])
            out.pad(36)
            out.put('# 0x%02x %s\n' % (opcode, inst))

    out.outdent(1)
    out.put(')\n')
    out.outdent(2)
Beispiel #3
0
 def da(self, adr):
     """
     Disassemble the instruction at mem[adr].
     Return the operation, operands and number of bytes.
     """
     return z80da.disassemble(self.mem, adr)
Beispiel #4
0
 def da(self, adr):
     """
     Disassemble the instruction at mem[adr].
     Return the operation, operands and number of bytes.
     """
     return z80da.disassemble(self.mem, adr)
Beispiel #5
0
#print(disassemble(fileContent,0x38))
if mem[0x38] == 0xC3:
    print('Interruption #38 Handler: JP', hx(mem[0x39] + 256 * mem[0x3a]))

pcstack = []
if 'start_adresses' in args:
    for a in args['start_adresses']:
        pcstack.append(int(a, 16))

#Start parsing
while len(pcstack) > 0:
    start_pc = pc = pcstack.pop(0)
    while True:
        # decoder l'instruction en PC de facon simple
        try:
            op = disassemble(mem, pc)
            (opcode, data, sz) = op
            if args['verbose'] > 2:
                print(hx(pc), op, hx(mem[pc]))
        except Exception as e:
            print(e, pc)
            break

        if memcode[pc] < 0:
            break

        if memcode[pc] > 1:  # and memcode[pc]!=1:
            print(hx(start_pc), hx(pc),
                  'Warning: Jumping in the middle of an instruction!')
            break