示例#1
0
    def get_block_info(self, codepoint_stream):
        block_type = next(codepoint_stream)
        log.info("raw block type: %s (%s)" %
                 (hex(block_type), repr(block_type)))

        block_length = next(codepoint_stream)

        # Get the complete block content
        codepoints = tuple(itertools.islice(codepoint_stream, block_length))

        try:
            verbose_block_type = self.cfg.BLOCK_TYPE_DICT[block_type]
        except KeyError:
            log.error("Blocktype unknown!")
            print pformat_codepoints(codepoints)
            sys.exit()
            verbose_block_type = hex(block_type)

#         log.debug("content of '%s':" % verbose_block_type)
#         log.debug("-"*79)
#         log.debug(pformat_codepoints(codepoints))
#         log.debug("-"*79)

        real_block_len = len(codepoints)
        if real_block_len == block_length:
            log.info("Block length: %sBytes, ok." % block_length)
        else:
            log.error("Block should be %sBytes but are: %sBytes!" %
                      (block_length, real_block_len))

        # Check block checksum

        origin_checksum = next(codepoint_stream)

        calc_checksum = sum([codepoint for codepoint in codepoints])
        calc_checksum += block_type
        calc_checksum += block_length
        calc_checksum = calc_checksum & 0xFF

        if calc_checksum == origin_checksum:
            log.info("Block checksum %s is ok." % hex(origin_checksum))
        else:
            log.error(
                "Block checksum %s is not equal with calculated checksum: %s" %
                (hex(origin_checksum), hex(calc_checksum)))

        # Check if the magic byte exists


#         magic_byte = next(codepoint_stream)
#         if magic_byte != self.cfg.MAGIC_BYTE:
#             log.error("Magic Byte %s is not %s" % (hex(magic_byte), hex(self.cfg.MAGIC_BYTE)))
#         else:
#             log.info("Magic Byte %s, ok." % hex(magic_byte))

        return block_type, block_length, codepoints
示例#2
0
    def get_block_info(self, codepoint_stream):
        block_type = next(codepoint_stream)
        log.info("raw block type: %s (%s)" % (hex(block_type), repr(block_type)))

        block_length = next(codepoint_stream)

        # Get the complete block content
        codepoints = tuple(itertools.islice(codepoint_stream, block_length))

        try:
            verbose_block_type = self.cfg.BLOCK_TYPE_DICT[block_type]
        except KeyError:
            log.error("Blocktype unknown!")
            print pformat_codepoints(codepoints)
            sys.exit()
            verbose_block_type = hex(block_type)

#         log.debug("content of '%s':" % verbose_block_type)
#         log.debug("-"*79)
#         log.debug(pformat_codepoints(codepoints))
#         log.debug("-"*79)

        real_block_len = len(codepoints)
        if real_block_len == block_length:
            log.info("Block length: %sBytes, ok." % block_length)
        else:
            log.error("Block should be %sBytes but are: %sBytes!" % (block_length, real_block_len))

        # Check block checksum

        origin_checksum = next(codepoint_stream)

        calc_checksum = sum([codepoint for codepoint in codepoints])
        calc_checksum += block_type
        calc_checksum += block_length
        calc_checksum = calc_checksum & 0xFF

        if calc_checksum == origin_checksum:
            log.info("Block checksum %s is ok." % hex(origin_checksum))
        else:
            log.error("Block checksum %s is not equal with calculated checksum: %s" % (
                hex(origin_checksum), hex(calc_checksum)
            ))

        # Check if the magic byte exists

#         magic_byte = next(codepoint_stream)
#         if magic_byte != self.cfg.MAGIC_BYTE:
#             log.error("Magic Byte %s is not %s" % (hex(magic_byte), hex(self.cfg.MAGIC_BYTE)))
#         else:
#             log.info("Magic Byte %s, ok." % hex(magic_byte))

        return block_type, block_length, codepoints
示例#3
0
    def get_filename_block_as_codepoints(self):
        """
        TODO: Support tokenized BASIC. Now we only create ASCII BASIC.
        """
        codepoints = []
        codepoints += list(string2codepoint(self.filename.ljust(8, " ")))
        codepoints.append(self.cfg.FTYPE_BASIC)  # one byte file type
        codepoints.append(self.cfg.BASIC_ASCII)  # one byte ASCII flag

        # one byte gap flag (0x00=no gaps, 0xFF=gaps)
        # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4231&p=9110#p9110
        codepoints.append(self.gap_flag)

        # machine code starting/loading address
        if self.file_type != self.cfg.FTYPE_BASIC:  # BASIC programm (0x00)
            codepoints = iter(codepoints)

            self.start_address = get_word(codepoints)
            log.info("machine code starting address: %s" %
                     hex(self.start_address))

            self.load_address = get_word(codepoints)
            log.info("machine code loading address: %s" %
                     hex(self.load_address))
        else:
            # not needed in BASIC files
            # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4341&p=9109#p9109
            pass

        log.debug("filename block: %s" % pformat_codepoints(codepoints))
        return codepoints
示例#4
0
    def get_filename_block_as_codepoints(self):
        """
        TODO: Support tokenized BASIC. Now we only create ASCII BASIC.
        """
        codepoints = []
        codepoints += list(string2codepoint(self.filename.ljust(8, " ")))
        codepoints.append(self.cfg.FTYPE_BASIC) # one byte file type
        codepoints.append(self.cfg.BASIC_ASCII) # one byte ASCII flag

        # one byte gap flag (0x00=no gaps, 0xFF=gaps)
        # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4231&p=9110#p9110
        codepoints.append(self.gap_flag)

        # machine code starting/loading address
        if self.file_type != self.cfg.FTYPE_BASIC: # BASIC programm (0x00)
            codepoints = iter(codepoints)

            self.start_address = get_word(codepoints)
            log.info("machine code starting address: %s" % hex(self.start_address))

            self.load_address = get_word(codepoints)
            log.info("machine code loading address: %s" % hex(self.load_address))
        else:
            # not needed in BASIC files
            # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4341&p=9109#p9109
            pass

        log.debug("filename block: %s" % pformat_codepoints(codepoints))
        return codepoints
示例#5
0
    def create_from_wave(self, codepoints):

        log.debug("filename data: %s" % pformat_codepoints(codepoints))

        raw_filename = codepoints[:8]

        self.filename = codepoints2string(raw_filename).rstrip()
        print("\nFilename: %s" % repr(self.filename))

        self.file_type = codepoints[8]

        if not self.file_type in self.cfg.FILETYPE_DICT:
            raise NotImplementedError(
                "Unknown file type %s is not supported, yet." %
                hex(self.file_type))

        log.info("file type: %s" % self.cfg.FILETYPE_DICT[self.file_type])

        if self.file_type == self.cfg.FTYPE_DATA:
            raise NotImplementedError("Data files are not supported, yet.")
        elif self.file_type == self.cfg.FTYPE_BIN:
            raise NotImplementedError("Binary files are not supported, yet.")

        self.ascii_flag = codepoints[9]
        log.info("Raw ASCII flag is: %s" % repr(self.ascii_flag))
        if self.ascii_flag == self.cfg.BASIC_TOKENIZED:
            self.is_tokenized = True
        elif self.ascii_flag == self.cfg.BASIC_ASCII:
            self.is_tokenized = False
        else:
            raise NotImplementedError("Unknown BASIC type: '%s'" %
                                      hex(self.ascii_flag))

        log.info("ASCII flag: %s" % self.cfg.BASIC_TYPE_DICT[self.ascii_flag])

        self.gap_flag = codepoints[10]
        log.info("gap flag is %s (0x00=no gaps, 0xff=gaps)" %
                 hex(self.gap_flag))

        # machine code starting/loading address
        if self.file_type != self.cfg.FTYPE_BASIC:  # BASIC programm (0x00)
            codepoints = iter(codepoints)

            self.start_address = get_word(codepoints)
            log.info("machine code starting address: %s" %
                     hex(self.start_address))

            self.load_address = get_word(codepoints)
            log.info("machine code loading address: %s" %
                     hex(self.load_address))
        else:
            # not needed in BASIC files
            # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4341&p=9109#p9109
            pass

        self.file_content = FileContent(self.cfg)
示例#6
0
    def create_from_wave(self, codepoints):

        log.debug("filename data: %s" % pformat_codepoints(codepoints))

        raw_filename = codepoints[:8]

        self.filename = codepoints2string(raw_filename).rstrip()
        print "\nFilename: %s" % repr(self.filename)

        self.file_type = codepoints[8]

        if not self.file_type in self.cfg.FILETYPE_DICT:
            raise NotImplementedError(
                "Unknown file type %s is not supported, yet." % hex(self.file_type)
            )

        log.info("file type: %s" % self.cfg.FILETYPE_DICT[self.file_type])

        if self.file_type == self.cfg.FTYPE_DATA:
            raise NotImplementedError("Data files are not supported, yet.")
        elif self.file_type == self.cfg.FTYPE_BIN:
            raise NotImplementedError("Binary files are not supported, yet.")

        self.ascii_flag = codepoints[9]
        log.info("Raw ASCII flag is: %s" % repr(self.ascii_flag))
        if self.ascii_flag == self.cfg.BASIC_TOKENIZED:
            self.is_tokenized = True
        elif self.ascii_flag == self.cfg.BASIC_ASCII:
            self.is_tokenized = False
        else:
            raise NotImplementedError("Unknown BASIC type: '%s'" % hex(self.ascii_flag))

        log.info("ASCII flag: %s" % self.cfg.BASIC_TYPE_DICT[self.ascii_flag])

        self.gap_flag = codepoints[10]
        log.info("gap flag is %s (0x00=no gaps, 0xff=gaps)" % hex(self.gap_flag))

        # machine code starting/loading address
        if self.file_type != self.cfg.FTYPE_BASIC: # BASIC programm (0x00)
            codepoints = iter(codepoints)

            self.start_address = get_word(codepoints)
            log.info("machine code starting address: %s" % hex(self.start_address))

            self.load_address = get_word(codepoints)
            log.info("machine code loading address: %s" % hex(self.load_address))
        else:
            # not needed in BASIC files
            # http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4341&p=9109#p9109
            pass

        self.file_content = FileContent(self.cfg)
示例#7
0
    def buffer_block(self, block_type, block_length, block_codepoints):

        block = tuple(itertools.islice(block_codepoints, block_length))
        log.debug("pprint block: %s" % pformat_codepoints(block))

        if block_type == self.cfg.EOF_BLOCK:
            self.buffer2file()
            return
        elif block_type == self.cfg.FILENAME_BLOCK:
            self.buffer2file()
            self.current_file = CassetteFile(self.cfg)
            self.current_file.create_from_wave(block)
            log.info("Add file %s" % repr(self.current_file))
            self.files.append(self.current_file)
        elif block_type == self.cfg.DATA_BLOCK:
            # store code until end marker
            self.buffer += block
            self.buffered_block_length += block_length
        else:
            raise TypeError("Block type %s unkown!" & hex(block_type))
示例#8
0
    def buffer_block(self, block_type, block_length, block_codepoints):

        block = tuple(itertools.islice(block_codepoints, block_length))
        log.debug("pprint block: %s" % pformat_codepoints(block))

        if block_type == self.cfg.EOF_BLOCK:
            self.buffer2file()
            return
        elif block_type == self.cfg.FILENAME_BLOCK:
            self.buffer2file()
            self.current_file = CassetteFile(self.cfg)
            self.current_file.create_from_wave(block)
            log.info("Add file %s" % repr(self.current_file))
            self.files.append(self.current_file)
        elif block_type == self.cfg.DATA_BLOCK:
            # store code until end marker
            self.buffer += block
            self.buffered_block_length += block_length
        else:
            raise TypeError("Block type %s unkown!" & hex(block_type))