PyDC converter (was: dragon 32 cassette format ?)

Hardware Hacking, Programming and Game Solutions/Cheats
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

Status update:

I have reimplement the WAVE2Bitstream stuff in: https://github.com/jedie/PyDragon32/blo ... tstream.py

With https://github.com/jedie/PyDragon32/com ... 1c84c3b0a7 i start to add Visual-Text-Debugging :shock:

The new implementation has a "auto sync bitstream" function. So the ugly even_odd bool parameter is not needed.

Debugging looks like this:

Code: Select all

|                                      |            *                         |
|                                      |             *                        |
|                                      |             *                        |
|                                      |             *                        |
|                                      |          *                           |
|                                      |       *                              |
|                                      |    *                                 |
|                                 *    |                                      |
|                              *       |                                      |
|                             *        |                                      |
|                             *        |                                      |
|                            *         |                                      |
|                               *      |                                      |
|                                *     |                                      |
|                                 *    |                                      |
|                                      |    *                                 |
|                                      |      *                               |
|                                      |       *                              |
|                                      |         *                            |
bit 1 at 1868 in 19Samples = 2321Hz
|                                      |          *                           |
|                                      |            *                         |
|                                      |             *                        |
|                                      |            *                         |
|                                      |             *                        |
|                                      |             *                        |
|                                      |            *                         |
|                                      |            *                         |
|                                      |          *                           |
|                                      |        *                             |
|                                      |       *                              |
|                                      |     *                                |
|                                      |    *                                 |
|                                 *    |                                      |
|                                 *    |                                      |
|                               *      |                                      |
|                             *        |                                      |
|                             *        |                                      |
|                            *         |                                      |
|                            *         |                                      |
|                            *         |                                      |
|                            *         |                                      |
|                             *        |                                      |
|                              *       |                                      |
|                               *      |                                      |
|                                *     |                                      |
|                                  *   |                                      |
|                                      |      *                               |
|                                      |        *                             |
bit 0 at 1897 in 29Samples = 1520Hz
|                                      |           *                          |
|                                      |            *                         |
|                                      |            *                         |
|                                      |            *                         |
|                                      |         *                            |
|                                      |      *                               |
|                                      |   *                                  |
|                                 *    |                                      |
|                              *       |                                      |
|                            *         |                                      |
|                            *         |                                      |
|                            *         |                                      |
|                               *      |                                      |
|                                *     |                                      |
|                                 *    |                                      |
|                                      |    *                                 |
|                                      |     *                                |
|                                      |      *                               |
|                                      |         *                            |
bit 1 at 1916 in 19Samples = 2321Hz
Hope that this can help me to debug...
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: dragon 32 cassette format ?

Post by tormod »

Sarah wrote:
tormod wrote:For instance I have some WAV's of whole cassettes that I want to extract all the files from (CAS would do). I tried DC.EXE for this (running in DOSEMU) with variable luck, and that program is anyway dead (no source) I believe.
Oh, that's too bad! R.I.P. :(

I do have the DC source; some of it was used as the initial basis for DCWIN (which also has improvements and new features for controlling leader lengths)
Well, if there is source code around, the program is maybe not dead after all? Are these sources something you can share with us?
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

have spent too many time, but i will have a useable state...

current code: https://github.com/jedie/PyDragon32/com ... 8f4dd87bac

Have started to implement the BAS2WAVE code (For debugging): Only the bitstream2WAVE part is missing.

Unfortunately, wave2bas works only with the test file "HelloWorld1 xroar.wav" correctly. The other test files have a good filename block data, but the code is corrupt :(

Think the wave2bitstream part is not good enough :(
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

jedie wrote:Unfortunately, wave2bas works only with the test file "HelloWorld1 xroar.wav" correctly. The other test files have a good filename block data, but the code is corrupt :(
Now it works with all files! :D

Missing part is the checksum stuff... Then a cli and gui will be come next.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
robcfg
Posts: 1532
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden
Contact:

Re: dragon 32 cassette format ?

Post by robcfg »

Checking that is easy too.

For every block you have to sum all bytes from the block, plus the block type number plus the size of the block and do an AND 0xFF.

Then you check the calculated number against the checksum byte (that is, the last before the trailing 0x55), and if they are the same, theoretically the block is Ok.

Beware that the checksum algorithm is quite bad, and you can have errors that result on the same checksum number. Nothing you can do about it.
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

Is on my TODO ;)

I add a command line interface with https://github.com/jedie/PyDragon32/com ... 14c28e036f :

Code: Select all

usage: PyDC_cli.py [-h] [-v] [--verbosity {0,10,20,30,40,50}]
                   [--logfile {0,10,20,30,40,50}]
                   [--hz_variation HZ_VARIATION]
                   [--min_volume_ratio MIN_VOLUME_RATIO]
                   [--avg_count AVG_COUNT] [--end_count END_COUNT]
                   [--mid_count MID_COUNT]
                   src dst

Python dragon 32 converter

positional arguments:
  src                   Source filename (.wav/.bas)
  dst                   Destination filename (.wav/.bas)

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --verbosity {0,10,20,30,40,50}
                        verbosity level to stdout (lower == more output!)
                        (default: 30)
  --logfile {0,10,20,30,40,50}
                        verbosity level to log file (lower == more output!)
                        (default: 20)
  --hz_variation HZ_VARIATION
                        How much Hz can signal scatter to match 1 or 0 bit ?
                        (default: 450)
  --min_volume_ratio MIN_VOLUME_RATIO
                        percent volume to ignore sample (default: 5)
  --avg_count AVG_COUNT
                        How many samples should be merged into a average
                        value? (default: 0)
  --end_count END_COUNT
                        Sample count that must be pos/neg at once (default: 2)
  --mid_count MID_COUNT
                        Sample count that can be around null (default: 1)
Example:

Code: Select all

~$ python PyDC_cli.py FooBar.wav FooBar.bas
See: README -> https://github.com/jedie/PyDragon32/blo ... DME.creole


Only wav2bas is implemented, yet.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

robcfg wrote:For every block you have to sum all bytes from the block, plus the block type number plus the size of the block and do an AND 0xFF.

Then you check the calculated number against the checksum byte (that is, the last before the trailing 0x55), and if they are the same, theoretically the block is Ok.
Done: https://github.com/jedie/PyDragon32/com ... 84a#L1R215

How can i build the checksum in the other way? (for bas2wav)

btw. have check Dragon Data Ltd - Examples from the Manual - 39~58 [run].wav, again. Interesting: the first sync-byte is after 4134Bytes, therefore it has round 517 Leading Bytes :o
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
robcfg
Posts: 1532
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden
Contact:

Re: dragon 32 cassette format ?

Post by robcfg »

How can i build the checksum in the other way? (for bas2wav)
Well, when you are writing the blocks, you have the data, you know the data size, and the block type, so just compute it the same way as when checking a block during loading and save it following the data, and add the final 0x55 trail byte.
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: dragon 32 cassette format ?

Post by jedie »

That's clear. What not clear is the AND 0xFF thing.

...some min later...

Ah!

Code: Select all

for i in xrange(250,265):
    print i, i & 0xff
output:

Code: Select all

250 250
251 251
252 252
253 253
254 254
255 255
256 0
257 1
258 2
259 3
260 4
261 5
262 6
263 7
264 8
It makes that the value starts from 0 after arrive 255...

OK, then it's clear what i have todo ;)
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
robcfg
Posts: 1532
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden
Contact:

Re: dragon 32 cassette format ?

Post by robcfg »

It makes that the value starts from 0 after arrive 255...
That is a side-effect, the intention is to isolate the lower 8 bits of the value. Obviously, with 8 bits you can only go from 0 to 255...
Post Reply