Hello.

I've managed to write a new program designed for repairing .cas files. 
It is a beta version so it can have its ups and downs.



It is a soft of supplement for the wav2cas program. Those who used 
wav2cas know that the .wav to .cas conversion is subject to a lot of 
possible errors. Most of these errors are smal flaws that make correct 
readings impossible.The bigger the file, the more probable it is for an 
error to occur in the file as a whole. Most of these errors are easy to 
repair. It is quite obvious that if we make for example 3 .cas files out 
of the same program, there is a large chance, that they can be merged 
into one proper, error-free file. Manual repair is possible, but very 
arduous. So why can't we order this task to be done automatically? And 
that's exactly what i did...



The program is run by a script (maybe in the future I will write a GUI 
for all programs from the "cas" family) :

cas2cas file1.cas file2.cas file3.cas file_good.cas

The program can also accept the hex format as input / output (the 
default transmission speed is set to 600 bod's), for example :



cas2cas file1.hex file2.hex file3.hex file_good.hex

Of course we can mix "hex" and "cas". We can, for example, provide 2 
.cas files and one slightly modificated .hex file.

The correct code (according to the algorithm) will be saved in 
"file_good"



Tis program can also be used as a .hex to .cas and .cas to .hex 
converter. All we need to do is type the same name of the input file 3 
times in a row.

cas2cas file.hex file.hex file.hex file_good.hex



The output file is normalized (speed, inter record gaps), the checksum 
gets corrected (for standard blocks) so we can explore and poke around a 
little in the .cas file (file protection, invulnerability) and then 
generate a file containing proper checksums.



Now i will present the way my program does the conversion, so you can 
understand how to make the best use of it. If you have any interesting 
ideas please share them with me. This is only a beta version so i 
included the options which seemed the most usefull to me. The main idea 
was to make the program as automatic as possible.



The program loads a .cas or .hex file to the memory in the form of 
records. Analyzing starts from giving each record a status (a number) :

1 - if the record has a length of 132 and correct checksum

2 - if the record has a length of 132, but incorrect checksum

4 - if the record has different length, and correct checksum

5 - if the record has different length, and incorrect checksum



Then the program starts to scan all the records again, and if it finds a 
record with the status "5" it can change the status to "3" (record which 
should have had a 132 lenght) but only if at least one of the following 
records has the lenght of 132. This way we can check which blocks are 
incomplete.



Then we do the sorting. A block is chosen for the 3 available files 
according to priority.

If at least one of the files is a "1" than it will be chosen. If all of 
the files are "2" then all of them will be analyzed byte per byte and 
the most probable version will be chosen. Then the checksum correction 
is made. If a record with the status "3" is found (and no "1" records 
are available), a search for the missing string is done. When a status 
"4" record is found, it is left unchanged. If we get a status "5" record 
- there is nothing we can do. :(



The program can crash if there are to many "3" errors, because it is 
unable to find the begining of the next block. In some cases, manual 
corrections done using only your intuition (or at random ;D ) can fix 
the result - even one hex can count.



Next the inter record gaps are normalized, and the checksums are 
corrected. In the end the file gets saved. 

Update:
v 0.2
- Cas2Cas with -orgsp option
so, he don`t change aborts
