Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def add_block_data(self, block_length, data):
        """
        add a block of tokenized BASIC source code lines.

        >>> cfg = Dragon32Config
        >>> fc = FileContent(cfg)

        >>> block = [
        ... 0x1e,0x12,0x0,0xa,0x80,0x20,0x49,0x20,0xcb,0x20,0x31,0x20,0xbc,0x20,0x31,0x30,0x0,
        ... 0x0,0x0]
        >>> len(block)
        19
        >>> fc.add_block_data(19,iter(block))
        19 Bytes parsed
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10

        >>> block = iter([
        ... 0x1e,0x29,0x0,0x14,0x87,0x20,0x49,0x3b,0x22,0x48,0x45,0x4c,0x4c,0x4f,0x20,0x57,0x4f,0x52,0x4c,0x44,0x21,0x22,0x0,
        ... 0x0,0x0])
        >>> fc.add_block_data(999,block)
        25 Bytes parsed
        ERROR: Block length value 999 is not equal to parsed bytes!
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10
        20 PRINT I;"HELLO WORLD!"

        >>> block = iter([
        ... 0x1e,0x31,0x0,0x1e,0x8b,0x20,0x49,0x0,
        ... 0x0,0x0])
        >>> fc.add_block_data(10,block)
        10 Bytes parsed
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10
        20 PRINT I;"HELLO WORLD!"
        30 NEXT I


        Test function tokens in code

        >>> fc = FileContent(cfg)
        >>> data = iter([
        ... 0x1e,0x4a,0x0,0x1e,0x58,0xcb,0x58,0xc3,0x4c,0xc5,0xff,0x88,0x28,0x52,0x29,0x3a,0x59,0xcb,0x59,0xc3,0x4c,0xc5,0xff,0x89,0x28,0x52,0x29,0x0,
        ... 0x0,0x0
        ... ])
        >>> fc.add_block_data(30, data)
        30 Bytes parsed
        >>> fc.print_code_lines()
        30 X=X+L*SIN(R):Y=Y+L*COS(R)


        Test high line numbers

        >>> fc = FileContent(cfg)
        >>> data = [
        ... 0x1e,0x1a,0x0,0x1,0x87,0x20,0x22,0x4c,0x49,0x4e,0x45,0x20,0x4e,0x55,0x4d,0x42,0x45,0x52,0x20,0x54,0x45,0x53,0x54,0x22,0x0,
        ... 0x1e,0x23,0x0,0xa,0x87,0x20,0x31,0x30,0x0,
        ... 0x1e,0x2d,0x0,0x64,0x87,0x20,0x31,0x30,0x30,0x0,
        ... 0x1e,0x38,0x3,0xe8,0x87,0x20,0x31,0x30,0x30,0x30,0x0,
        ... 0x1e,0x44,0x27,0x10,0x87,0x20,0x31,0x30,0x30,0x30,0x30,0x0,
        ... 0x1e,0x50,0x80,0x0,0x87,0x20,0x33,0x32,0x37,0x36,0x38,0x0,
        ... 0x1e,0x62,0xf9,0xff,0x87,0x20,0x22,0x45,0x4e,0x44,0x22,0x3b,0x36,0x33,0x39,0x39,0x39,0x0,0x0,0x0
        ... ]
        >>> len(data)
        99
        >>> fc.add_block_data(99, iter(data))
        99 Bytes parsed
        >>> fc.print_code_lines()
        1 PRINT "LINE NUMBER TEST"
        10 PRINT 10
        100 PRINT 100
        1000 PRINT 1000
        10000 PRINT 10000
        32768 PRINT 32768
        63999 PRINT "END";63999
        """

        #         data = list(data)
        # #         print repr(data)
        #         print_as_hex_list(data)
        #         print_codepoint_stream(data)
        #         sys.exit()

        # create from codepoint list a iterator
        data = iter(data)

        byte_count = 0
        while True:
            try:
                line_pointer = get_word(data)
            except (StopIteration, IndexError) as err:
                log.error(
                    "No line pointer information in code line data. (%s)" %
                    err)
                break
#             print "line_pointer:", repr(line_pointer)
            byte_count += 2
            if not line_pointer:
                # arrived [0x00, 0x00] -> end of block
                break

            try:
                line_number = get_word(data)
            except (StopIteration, IndexError) as err:
                log.error(
                    "No line number information in code line data. (%s)" % err)
                break


#             print "line_number:", repr(line_number)
            byte_count += 2

            #             data = list(data)
            #             print_as_hex_list(data)
            #             print_codepoint_stream(data)
            #             data = iter(data)

            # get the code line:
            # new iterator to get all characters until 0x00 arraived
            code = iter(data.__next__, 0x00)

            code = list(code)  # for len()
            byte_count += len(code) + 1  # from 0x00 consumed in iter()

            #             print_as_hex_list(code)
            #             print_codepoint_stream(code)

            # convert to a plain ASCII string
            code = bytes2codeline(code)

            self.code_lines.append(CodeLine(line_pointer, line_number, code))

        print("%i Bytes parsed" % byte_count)
        if block_length != byte_count:
            print(
                "ERROR: Block length value %i is not equal to parsed bytes!" %
                block_length)
Esempio n. 6
0
    def add_block_data(self, block_length, data):
        """
        add a block of tokenized BASIC source code lines.

        >>> cfg = Dragon32Config
        >>> fc = FileContent(cfg)

        >>> block = [
        ... 0x1e,0x12,0x0,0xa,0x80,0x20,0x49,0x20,0xcb,0x20,0x31,0x20,0xbc,0x20,0x31,0x30,0x0,
        ... 0x0,0x0]
        >>> len(block)
        19
        >>> fc.add_block_data(19,iter(block))
        19 Bytes parsed
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10

        >>> block = iter([
        ... 0x1e,0x29,0x0,0x14,0x87,0x20,0x49,0x3b,0x22,0x48,0x45,0x4c,0x4c,0x4f,0x20,0x57,0x4f,0x52,0x4c,0x44,0x21,0x22,0x0,
        ... 0x0,0x0])
        >>> fc.add_block_data(999,block)
        25 Bytes parsed
        ERROR: Block length value 999 is not equal to parsed bytes!
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10
        20 PRINT I;"HELLO WORLD!"

        >>> block = iter([
        ... 0x1e,0x31,0x0,0x1e,0x8b,0x20,0x49,0x0,
        ... 0x0,0x0])
        >>> fc.add_block_data(10,block)
        10 Bytes parsed
        >>> fc.print_code_lines()
        10 FOR I = 1 TO 10
        20 PRINT I;"HELLO WORLD!"
        30 NEXT I


        Test function tokens in code

        >>> fc = FileContent(cfg)
        >>> data = iter([
        ... 0x1e,0x4a,0x0,0x1e,0x58,0xcb,0x58,0xc3,0x4c,0xc5,0xff,0x88,0x28,0x52,0x29,0x3a,0x59,0xcb,0x59,0xc3,0x4c,0xc5,0xff,0x89,0x28,0x52,0x29,0x0,
        ... 0x0,0x0
        ... ])
        >>> fc.add_block_data(30, data)
        30 Bytes parsed
        >>> fc.print_code_lines()
        30 X=X+L*SIN(R):Y=Y+L*COS(R)


        Test high line numbers

        >>> fc = FileContent(cfg)
        >>> data = [
        ... 0x1e,0x1a,0x0,0x1,0x87,0x20,0x22,0x4c,0x49,0x4e,0x45,0x20,0x4e,0x55,0x4d,0x42,0x45,0x52,0x20,0x54,0x45,0x53,0x54,0x22,0x0,
        ... 0x1e,0x23,0x0,0xa,0x87,0x20,0x31,0x30,0x0,
        ... 0x1e,0x2d,0x0,0x64,0x87,0x20,0x31,0x30,0x30,0x0,
        ... 0x1e,0x38,0x3,0xe8,0x87,0x20,0x31,0x30,0x30,0x30,0x0,
        ... 0x1e,0x44,0x27,0x10,0x87,0x20,0x31,0x30,0x30,0x30,0x30,0x0,
        ... 0x1e,0x50,0x80,0x0,0x87,0x20,0x33,0x32,0x37,0x36,0x38,0x0,
        ... 0x1e,0x62,0xf9,0xff,0x87,0x20,0x22,0x45,0x4e,0x44,0x22,0x3b,0x36,0x33,0x39,0x39,0x39,0x0,0x0,0x0
        ... ]
        >>> len(data)
        99
        >>> fc.add_block_data(99, iter(data))
        99 Bytes parsed
        >>> fc.print_code_lines()
        1 PRINT "LINE NUMBER TEST"
        10 PRINT 10
        100 PRINT 100
        1000 PRINT 1000
        10000 PRINT 10000
        32768 PRINT 32768
        63999 PRINT "END";63999
        """

#         data = list(data)
# #         print repr(data)
#         print_as_hex_list(data)
#         print_codepoint_stream(data)
#         sys.exit()

        # create from codepoint list a iterator
        data = iter(data)

        byte_count = 0
        while True:
            try:
                line_pointer = get_word(data)
            except (StopIteration, IndexError), err:
                log.error("No line pointer information in code line data. (%s)" % err)
                break
#             print "line_pointer:", repr(line_pointer)
            byte_count += 2
            if not line_pointer:
                # arrived [0x00, 0x00] -> end of block
                break

            try:
                line_number = get_word(data)
            except (StopIteration, IndexError), err:
                log.error("No line number information in code line data. (%s)" % err)
                break