Example #1
0
def get_flat_opdata(OP_DATA):
    flat_opdata = {}
    for instr_data in list(OP_DATA.values()):
        for mnemonic, mnemonic_data in list(instr_data["mnemonic"].items()):
            for op_code, op_data in list(mnemonic_data["ops"].items()):
                op_data["mnemonic"] = mnemonic
                op_data["needs_ea"] = mnemonic_data["needs_ea"]
                for key in ("read_from_memory", "write_to_memory", "register"):
                    op_data[key] = mnemonic_data[key]
                flat_opdata[op_code] = op_data
    return flat_opdata
Example #2
0
def get_flat_opdata(OP_DATA):
    flat_opdata = {}
    for instr_data in OP_DATA.values():
        for mnemonic, mnemonic_data in instr_data["mnemonic"].items():
            for op_code, op_data in mnemonic_data["ops"].items():
                op_data["mnemonic"] = mnemonic
                op_data["needs_ea"] = mnemonic_data["needs_ea"]
                for key in ("read_from_memory", "write_to_memory", "register"):
                    op_data[key] = mnemonic_data[key]
                flat_opdata[op_code] = op_data
    return flat_opdata
Example #3
0
def generate_code(f):
    addr_modes = set()
    registers = set()
    variants = set()
    for instr_data in list(OP_DATA.values()):
        for mnemonic, mnemonic_data in list(instr_data["mnemonic"].items()):
            read_from_memory = mnemonic_data["read_from_memory"]
            write_to_memory = mnemonic_data["write_to_memory"]
            needs_ea = mnemonic_data["needs_ea"]
            register = mnemonic_data["register"]
            for op_code, op_data in list(mnemonic_data["ops"].items()):
                addr_mode = op_data["addr_mode"]
#                print(hex(op_code),

                if addr_mode is None:
                    # special function (RESET/ PAGE1,2) defined in InstructionBase
                    print("address mode is None:", mnemonic, op_data)
                    continue

                addr_mode = addr_mode.lower()

                variant = (addr_mode, needs_ea, register, read_from_memory, write_to_memory)
                # print(variant)
                variants.add(variant)

                if needs_ea and read_from_memory:
                    addr_modes.add("get_ea_m_%s" % addr_mode)
                elif needs_ea:
                    addr_modes.add("get_ea_%s" % addr_mode)
                elif read_from_memory:
                    addr_modes.add("get_m_%s" % addr_mode)

                if register is not None:
                    registers.add(register)

#                if (addr_mode and  needs_ea and  register and  read_from_memory and  write_to_memory) is None:

    variants = list(variants)
    variants.sort(key=lambda x: "".join(["%s" % i for i in x]))

    # for no, data in enumerate(variants):
    #     print(no, data)
    # print("+++++++++++++")

    for line in INIT_CODE.splitlines():
        f.write("%s\n" % line)

    for register in sorted([REGISTER_DICT[register] for register in registers]):
        f.write(
            "        self.%(r)s=self.cpu.%(r)s\n" % {
                "r": register,
            }
        )
    f.write("\n")

    for addr_mode in sorted(addr_modes):
        f.write(
            "        self.%(a)s=self.cpu.%(a)s\n" % {"a": addr_mode}
        )
    f.write("\n")

    for addr_mode, needs_ea, register, read_from_memory, write_to_memory in variants:
        func_name = build_func_name(addr_mode, needs_ea, register, read_from_memory, write_to_memory)

        f.write("    def %s(self, opcode):\n" % func_name)

        code = []

        if needs_ea and read_from_memory:
            code.append("ea, m = self.cpu.get_ea_m_%s()" % addr_mode)

        if write_to_memory:
            code.append("ea, value = self.instr_func(")
        else:
            code.append("self.instr_func(")
        code.append("    opcode=opcode,")

        if needs_ea and read_from_memory:
            code.append("    ea=ea,")
            code.append("    m=m,")
        elif needs_ea:
            code.append("    ea=self.get_ea_%s()," % addr_mode)
        elif read_from_memory:
            code.append("    m=self.get_m_%s()," % addr_mode)

        if register:
            code.append(
                "    register=self.%s," % REGISTER_DICT[register]
            )

        code.append(")")

        if write_to_memory == BYTE:
            code.append("self.write_byte(ea, value)")
        elif write_to_memory == WORD:
            code.append("self.write_word(ea, value)")

        for line in code:
            f.write("        %s\n" % line)

        f.write("\n")
Example #4
0
def generate_code(f):
    variants = set()
    for instr_data in list(OP_DATA.values()):
        for mnemonic, mnemonic_data in list(instr_data["mnemonic"].items()):
            read_from_memory = mnemonic_data["read_from_memory"]
            write_to_memory = mnemonic_data["write_to_memory"]
            needs_ea = mnemonic_data["needs_ea"]
            register = mnemonic_data["register"]
            for op_code, op_data in list(mnemonic_data["ops"].items()):
                addr_mode = op_data["addr_mode"]
                #                print hex(op_code),
                variants.add((addr_mode, needs_ea, register, read_from_memory,
                              write_to_memory))
                #                if (addr_mode and  needs_ea and  register and  read_from_memory and  write_to_memory) is None:
                if addr_mode is None:
                    print(mnemonic, op_data)


#    for no, data in enumerate(sorted(variants)):
#        print no, data
#    print"+++++++++++++"

    for line in INIT_CODE.splitlines():
        f.write("%s\n" % line)

    for addr_mode, ea, register, read, write in sorted(variants):
        if not addr_mode:
            # special function (RESET/ PAGE1,2) defined in InstructionBase
            continue

        func_name = build_func_name(addr_mode, ea, register, read, write)

        f.write("    def %s(self, opcode):\n" % func_name)

        code = []

        if ea and read:
            code.append("ea, m = self.cpu.get_ea_m_%s()" % addr_mode.lower())

        if write:
            code.append("ea, value = self.instr_func(")
        else:
            code.append("self.instr_func(")
        code.append("    opcode = opcode,")

        if ea and read:
            code.append("    ea = ea,")
            code.append("    m = m,")
        elif ea:
            code.append("    ea = self.cpu.get_ea_%s()," % addr_mode.lower())
        elif read:
            code.append("    m = self.cpu.get_m_%s()," % addr_mode.lower())

        if register:
            code.append("    register = self.cpu.%s," %
                        REGISTER_DICT[register])

        code.append(")")

        if write == BYTE:
            code.append("self.memory.write_byte(ea, value)")
        elif write == WORD:
            code.append("self.memory.write_word(ea, value)")

        for line in code:
            f.write("        %s\n" % line)

        f.write("\n")
Example #5
0
def generate_code(f):
    variants = set()
    for instr_data in list(OP_DATA.values()):
        for mnemonic, mnemonic_data in list(instr_data["mnemonic"].items()):
            read_from_memory = mnemonic_data["read_from_memory"]
            write_to_memory = mnemonic_data["write_to_memory"]
            needs_ea = mnemonic_data["needs_ea"]
            register = mnemonic_data["register"]
            for op_code, op_data in list(mnemonic_data["ops"].items()):
                addr_mode = op_data["addr_mode"]
                #                print hex(op_code),
                variants.add((addr_mode, needs_ea, register, read_from_memory, write_to_memory))
                #                if (addr_mode and  needs_ea and  register and  read_from_memory and  write_to_memory) is None:
                if addr_mode is None:
                    print(mnemonic, op_data)

    #    for no, data in enumerate(sorted(variants)):
    #        print no, data
    #    print"+++++++++++++"

    for line in INIT_CODE.splitlines():
        f.write("%s\n" % line)

    for addr_mode, ea, register, read, write in sorted(variants):
        if not addr_mode:
            # special function (RESET/ PAGE1,2) defined in InstructionBase
            continue

        func_name = build_func_name(addr_mode, ea, register, read, write)

        f.write("    def %s(self, opcode):\n" % func_name)

        code = []

        if ea and read:
            code.append("ea, m = self.cpu.get_ea_m_%s()" % addr_mode.lower())

        if write:
            code.append("ea, value = self.instr_func(")
        else:
            code.append("self.instr_func(")
        code.append("    opcode = opcode,")

        if ea and read:
            code.append("    ea = ea,")
            code.append("    m = m,")
        elif ea:
            code.append("    ea = self.cpu.get_ea_%s()," % addr_mode.lower())
        elif read:
            code.append("    m = self.cpu.get_m_%s()," % addr_mode.lower())

        if register:
            code.append("    register = self.cpu.%s," % REGISTER_DICT[register])

        code.append(")")

        if write == BYTE:
            code.append("self.memory.write_byte(ea, value)")
        elif write == WORD:
            code.append("self.memory.write_word(ea, value)")

        for line in code:
            f.write("        %s\n" % line)

        f.write("\n")