Hab das ganze nochmal neu gemacht und somit die meine Frage von vorhin fast überflüssig.
Mir ist nämlich aufgefallen, das ich bei cas2bas im Prinzip das selbe machen muß, wie bei wav2bas... Denn im Grunde ist es fast so:
.wav -> .cas -> .bas
Somit brauche ich fast nichs neu zu machen... Sieht z.Z. dann so aus:
https://github.com/jedie/PyDragon32/blo ... handler.py
Ich brauchte quasi nur den bit-sync Teil anders machen. Denn eigentlich brauche ich nur zu Überprüfen ob LeadIn und Sync-Byte vorhanden sind und das sieht nun so aus:
Code: Alles auswählen
def count_the_same(iterable, sentinel):
"""
>>> count_the_same([0x55,0x55,0x55,0x55,0x3C,"foo","bar"],0x55)
(4, 60)
>>> 0x3C == 60
True
"""
count = 0
x = None
for count, x in enumerate(iterable):
if x != sentinel:
break
return count, x
...
leadin_bytes_count, sync_byte = count_the_same(bitstream, self.cfg.LEAD_BYTE_CODEPOINT)
if leadin_bytes_count == 0:
log.error("Leadin byte not found in file!")
sys.exit(-1)
log.info("%s x leadin bytes (%s) found." % (leadin_bytes_count, hex(self.cfg.LEAD_BYTE_CODEPOINT)))
if sync_byte != self.cfg.SYNC_BYTE_CODEPOINT:
log.error("Sync byte wrong. Get %s but excepted %s" % (
hex(sync_byte), hex(self.cfg.SYNC_BYTE_CODEPOINT)
))
else:
log.debug("Sync %s byte, ok." % hex(self.cfg.SYNC_BYTE_CODEPOINT))
Insgesammt muß der ganze code nun mal aufgeräumt werden. Mache ich allerdings erst, wenn es denn mal läuft.
Noch sind Bugs drin:
Die Ausgaben von
.bas -> .cas sieht so aus:
sieht so aus:
Verbosity log level: DEBUG
logfile log level: INFO
filename 'HELLOWOR' from: ../test_files/HelloWorld1.bas
Create '../test.cas'...
filename block: ['HELLOWOR', '\x00', '\xff', '\x00', '\x0c', '\x00', '\x0c', '\x00']
yield 255x lead byte 0x55
yield sync byte 0x3c
yield block type 'filename block (0x00)'
yield block length 0xf (15Bytes)
content of 'filename block (0x00)':
-------------------------------------------------------------------------------
['HELLOWOR', '\x00', '\xff', '\x00', '\x0c', '\x00', '\x0c', '\x00']
-------------------------------------------------------------------------------
yield calculated checksum 0xf
yield magic byte 0x55
code: [13, 49, 48, 32, 70, 79, 82, 32, 73, 32, 61, 32, 49, 32, 84, 79, 32, 49, 48, 13, 50, 48, 32, 80, 82, 73, 78, 84, 32, 73, 59, 34, 72, 69, 76, 76, 79, 32, 87, 79, 82, 76, 68, 33, 34, 13, 51, 48, 32, 78, 69, 88, 84, 32, 73, 13, 0, 0]
yield 255x lead byte 0x55
yield sync byte 0x3c
yield block type 'data block (0x01)'
yield block length 0x3a (58Bytes)
content of 'data block (0x01)':
-------------------------------------------------------------------------------
['\r', '10 FOR I = 1 TO 10', '\r', '20 PRINT I;"HELLO WORLD!"', '\r', '30 NEXT I', '\r', '\x00', '\x00']
-------------------------------------------------------------------------------
yield calculated checksum 0x3b
yield magic byte 0x55
yield 255x lead byte 0x55
yield sync byte 0x3c
yield block type 'end-of-file block (0xff)'
yield block length 0x0 (0Bytes)
yield calculated checksum 0xff
yield magic byte 0x55
logger name: PyDC
Python dragon 32 converter 0.1.0.dev
-------------------------------------------------------------------------------
source file.......: ../test_files/HelloWorld1.bas
destination file..: ../test.cas
set log level to: 10
There exists 1 files:
Filename: 'HELLOWOR'
file type: BASIC programm (0x00)
is tokenized: False
code lines:
-------------------------------------------------------------------------------
10 FOR I = 1 TO 10
20 PRINT I;"HELLO WORLD!"
30 NEXT I
-------------------------------------------------------------------------------
File '../test.cas' saved.
und dann von .cas -> .bas so:
../PyDC_cli.py --verbosity=10 ../test.cas --dst=../test.bas
Verbosity log level: DEBUG
logfile log level: INFO
file sizes: 853 Bytes
255 x leadin bytes (0x55) found.
Sync 0x3c byte, ok.
raw block type: 0x0 (0)
Block length: 15Bytes, ok.
Block checksum 0xf is not equal with calculated checksum: 0x92
Magic Byte 0x55, ok.
filename data: ['HELLOWOR', '\x00', '\xff', '\x00', '\x0c', '\x00', '\x0c', '\x00']
file type: BASIC programm (0x00)
Raw ASCII flag is: 255
ASCII flag: ASCII BASIC (0xff)
Add file <BlockFile 'HELLOWOR'>
255 x leadin bytes (0x55) found.
Sync 0x3c byte, ok.
raw block type: 0x1 (1)
Block length: 58Bytes, ok.
Block checksum 0x3b is not equal with calculated checksum: 0x91
Magic Byte 0x55, ok.
255 x leadin bytes (0x55) found.
Sync 0x3c byte, ok.
raw block type: 0xff (255)
Block length: 0Bytes, ok.
Block checksum 0xff is ok.
Magic Byte 0x55, ok.
EOF-Block found
Create '../test_HELLOWOR.bas'...
logger name: PyDC
Python dragon 32 converter 0.1.0.dev
-------------------------------------------------------------------------------
source file.......: ../test.cas
destination file..: ../test.bas
set log level to: 10
_______________________________________________________________________________
*** block type: 0x0 (filename block (0x00))
Filename: 'HELLOWOR'
===============================================================================
_______________________________________________________________________________
*** block type: 0x1 (data block (0x01))
ERROR: Splitting linenumber in '\x00\x00': need more than 1 value to unpack
59 Bytes parsed
ERROR: Block length value 58 is not equal to parsed bytes!
*******************************************************************************
10 FOR I = 1 TO 10
20 PRINT I;"HELLO WORLD!"
30 NEXT I
*******************************************************************************
===============================================================================
_______________________________________________________________________________
*** block type: 0xff (end-of-file block (0xff))
File '../test_HELLOWOR.bas' saved.
Der eigentliche Code der rauskommt, ist ja schon mal der selbe. Allerdings die eine fehler aufgefallen... Evtl. nur Kleinigkeiten...