Skip to content

Commit

Permalink
Bugfixes:
Browse files Browse the repository at this point in the history
* Use GAP-Flag for ASCII BASIC
* Don't yield magic byte at block end
* Don't yield machine code starting/loading address in BASIC files
  • Loading branch information
jedie committed Sep 9, 2013
1 parent 3de59b0 commit 981f745
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 38 deletions.
73 changes: 50 additions & 23 deletions PyDC/PyDC/CassetteObjects.py
Expand Up @@ -324,27 +324,33 @@ def create_from_wave(self, codepoints):
elif self.file_type == self.cfg.FTYPE_BIN:
raise NotImplementedError("Binary files are not supported, yet.")

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

log.info("ASCII flag: %s" % self.cfg.BASIC_TYPE_DICT[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))

codepoints = iter(codepoints)
# 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.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))
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)

Expand All @@ -359,18 +365,39 @@ def add_block_data(self, block_length, codepoints):
print "*"*79

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
codepoints.append(0x00) # one byte gap flag (00=no gaps, FF=gaps)
# FIXME, see: http://five.pairlist.net/pipermail/coco/2013-August/070938.html

# two bytes machine code starting address:
codepoints += [ord(self.filename[0]), ord(self.filename[1])]

# two bytes machine code loading address:
codepoints += [ord(self.filename[2]), ord(self.filename[3])]


# 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.cfg.GAPS)

# if self.ascii_flag == self.cfg.BASIC_ASCII:
# codepoints.append(self.cfg.GAPS)
# elif self.ascii_flag == self.cfg.BASIC_TOKENIZED:
# codepoints.append(self.cfg.NO_GAPS)
# else:
# raise NotImplementedError("Unknown BASIC type: '%s'" % hex(self.ascii_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
Expand Down Expand Up @@ -503,8 +530,8 @@ def block2codepoint_stream(self, block_type, block_codepoints):
checksum = checksum & 0xFF
log.debug("yield calculated checksum %s" % hex(checksum))
yield checksum
log.debug("yield magic byte %s" % hex(self.cfg.MAGIC_BYTE))
yield self.cfg.MAGIC_BYTE # 0x55
# log.debug("yield magic byte %s" % hex(self.cfg.MAGIC_BYTE))
# yield self.cfg.MAGIC_BYTE # 0x55
else:
log.debug("content of '%s':" % self.cfg.BLOCK_TYPE_DICT[block_type])
log.debug("-"*79)
Expand All @@ -520,8 +547,8 @@ def block2codepoint_stream(self, block_type, block_codepoints):
checksum = checksum & 0xFF
log.debug("yield calculated checksum %s" % hex(checksum))
yield checksum
log.debug("yield magic byte %s" % hex(self.cfg.MAGIC_BYTE))
yield self.cfg.MAGIC_BYTE # 0x55
# log.debug("yield magic byte %s" % hex(self.cfg.MAGIC_BYTE))
# yield self.cfg.MAGIC_BYTE # 0x55

def codepoint_stream(self):
if self.wav:
Expand Down
10 changes: 5 additions & 5 deletions PyDC/PyDC/bitstream_handler.py
Expand Up @@ -189,11 +189,11 @@ def get_block_info(self, codepoint_stream):

# 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))
# 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

Expand Down
6 changes: 4 additions & 2 deletions PyDC/PyDC/configs.py
Expand Up @@ -89,8 +89,6 @@ class Dragon32Config(BaseConfig):
SYNC_BYTE_CODEPOINT = 0x3C # 00111100
MAX_SYNC_BYTE_SEARCH = 600 # search size in **Bytes**

MAGIC_BYTE = 0x55 # 10101010

# Block types:
FILENAME_BLOCK = 0x00
DATA_BLOCK = 0x01
Expand Down Expand Up @@ -119,6 +117,10 @@ class Dragon32Config(BaseConfig):
BASIC_ASCII:"ASCII BASIC (0xff)",
}

# The gap flag
NO_GAPS = 0x00
GAPS = 0xff

BASIC_CODE_END = [0x00, 0x00] # Mark the end of the code


Expand Down
11 changes: 3 additions & 8 deletions PyDC/PyDC/tests.py
Expand Up @@ -150,17 +150,14 @@ def test_bas2cas01(self):
("<", "Sync byte 0x3C"),

("\x00", "block type: filename block (0x00)"),
("\x0f", "block length (15Bytes)"),
("\x0b", "block length (11Bytes)"),

("HELLOWOR", "filename"),
("\x00", "File type: BASIC programm (0x00)"),
("\xff", "format: ASCII BASIC (0xff)"),
("\x00", "gap flag (00=no gaps, FF=gaps)"),
("HE", "machine code starting address"),
("LL", "machine code loading address"),
("\xff", "gap flag (00=no gaps, FF=gaps)"),

("\x9f", "block checksum"),
("U", "magic byte block terminator 0x3C"),
("u", "block checksum"),

("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "35x Leadin bytes 0x55"),
("<", "Sync byte 0x3C"),
Expand All @@ -173,15 +170,13 @@ def test_bas2cas01(self):
),
("\x00\x00", "code end terminator"),
("\x91", "block checksum"),
("U", "magic byte block terminator 0x3C"),

("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "35x Leadin bytes 0x55"),
("<", "Sync byte 0x3C"),

("\xff", "block type: end-of-file block (0xff)"),
("\x00", "block length (0Bytes)"),
("\xff", "block checksum"),
("U", "magic byte block terminator 0x3C"),
)

dest_content = iter(dest_content)
Expand Down

0 comments on commit 981f745

Please sign in to comment.