コード例 #1
0
    def __iter__(self):
        """TBW"""
        self.assert_valid()

        if self.first == self.last:
            raise StopIteration

        with RomImage(self.title) as mem:
            self.mapper = make_mapper(header=get_snes_header(mem))
            addr = self.addr
            mem.seek(self.mapper.from_cpu(addr))
            yield from self._do_iterate(mem, addr)
コード例 #2
0
    def setup(self, mem):
        """Setup this instance.

        Args:
          mem (mmap): The input stream of ROM.
        """

        self.mapper = make_mapper(header=get_snes_header(mem))

        self._setup_huffman_tree(mem)
        self._setup_shiftbit_array(mem)

        self.assert_valid()
コード例 #3
0
ファイル: parser.py プロジェクト: showa-yojyo/dqutils
    def _do_parse(self, input_string, table):
        """Parse an XML object and return a table data.

        Args:
          input_string (string): An XML string.
          table (Table): An empty instance of class `Table`.

        Returns:
          None
        """

        dom = parse_xml(input_string)

        # Handle the <struct> element in the XML tree.
        node = dom.getElementsByTagName('struct')[0]
        cpu_addr, record_size, record_num = XmlParser.get_struct_info(node)
        members = [XmlParser.get_member_info(i)
                   for i in node.getElementsByTagName('member')]

        title = dom.getElementsByTagName('rom')[0].getAttribute('name')

        # Read ROM image and list the records.
        with RomImage(title) as mem:
            mapper = make_mapper(header=get_snes_header(mem))

            # Locate the address of the array on ROM image.
            mem.seek(mapper.from_cpu(cpu_addr))

            # Obtain each byte sequence.
            rows = []
            for _ in range(record_num):
                byte_string = mem.read(record_size)
                rows.append(
                    [i.process(byte_string) for i in members])

        table.cpu_addr = cpu_addr
        table.record_size = record_size
        table.columns = members
        table.rows = rows

        assert len(rows) == record_num