Page 1 of 6

New tape cleaner tool

Posted: 16 Nov 2018 01:48
by muldjord
UPDATE: Bill's TapeView is far superior to my own tool, and I highly recommend it over mine! So just updating this thread to direct anyone new to read through the pages of this thread to find the latest version of it. Thanks Bill for creating it! :arrow: :idea:

----------------
ORIGINAL POST:

Hi guys,
I've been working on a new wav tape cleaner software. So far I've tested it with most of the wav's from Claus' download page and it works well. It fails with Toado and Knuckles though so I'll look into that in coming versions.

Features include:
- Automatic baud rate detection based on pulses from the waiting tone.
- Segmented zero adjusting before analysis to ensure optimal pulse length detection.
- Built as a state machine, being somewhat aware of what it should be expecting next in the sample stream.
- Detection of short, medium and long pulses (not really sure what the long ones are for, but they exist).
- Separate vector output data meaning that I "build" the output from optimal pulses instead of just squaring the input directly.
- Should work for 22050 Hz files and up (But only tested thoroughly with Claus' 22050 Hz wav's). Currently requires mono files.

Future features would probably include:
- Game name detection output to terminal as a nice touch. In other words, I plan to read the bytes if I can. Any help with the tape format would be appreciated!!! I've been digging around for days looking for useful data on the byte layout in the Memotech tape format, but so far haven't really found anything that seems to fit what I see in Audacity. Paul ('thewiz') talked about bit shifting 7 times in a different thread, which tells me that it's probably fixed 8 bit based. My question then is: What does it use for start, stop and parity bits (if any)?
- If I get the byte reading to work properly, I also plan to make it possible to convert files back to binary. But that might be a bit above my skill level. We'll see.

The tool is called "tapeworm" as an ode to one of my favorite Memotech games back in the day. It was one of the games I could somehow "break" and be able to LIST the code for (I can't recall how I did that). I seem to recall a lot of basic being used in it (which I could somewhat understand at the grand old age of 6-9). So it's one of the reasons I got into programming in the first place. Not that I could program much at that age, but I found the BASIC code scrolling down the screen deeply fascinating.

Lastly, the tool is very unoptimized at the moment and some things needs fixing. But in its current state it will convert a lot of games perfectly simply by running it with "./tapeworm file.wav".

Check it out here if you like: https://github.com/muldjord/tapeworm

All it requires is libsndfile-dev package, so be sure to apt-get or yum it before make. It was written on Linux, but should work just fine on other platforms aswell, as long as you find a way to get libsndfile on there.

The files I've cleaned with the current version can be downloaded here: https://drive.google.com/drive/folders/ ... sp=sharing . Just be aware that I often delete and recreate them when I've made changes to the tool. So sometimes that folder might be empty.

Re: New tape cleaner tool

Posted: 16 Nov 2018 10:47
by Crazyboss
Hi Lars.

Nice you work on a new tool, but from now on I will release new games as Wav created by apptool, so the wav should be as clean as possible. I also have created new waves from previous games, and they all load nice on real hardware.

thewiz aka Paul Daniels, is the one to ask about tapeformat.

About Toado, i dont recall i had problems loading it, but i think two versions exists - actually 3 versions. One Loads directly, another one use the Continental Software loader (the MAP). And the 3rd is my transfer project i did back in the 2000s where i found .mtx files but we did not have any good emulators and i wanted to play the games so i found a way to transfer them from PC to Memotech using RS232 and save them as tapes (waves).

About "tapeworm", I recall its a basic game, he do something quite dangerous i think by poking the snakes position or so into memory, instead of use a ARRAY, not sure its a problem but it could overwrite the system area, maybe? The programmer, was one of the first programmers I located many years ago, and i did an "interview" by mail, which is at my very outdated www.mtxworld.dk homepage.

Re: New tape cleaner tool

Posted: 16 Nov 2018 11:49
by thewiz
Hi Lars,

Great that you have a new tool for converting wavs as I still have a number of wavs that I've not been able to convert. I've got some mp3s too which are known to work.

I will dig out the tape format and post it later today. Off for a flu jab now.

TTFN
Paul Daniels

Re: New tape cleaner tool

Posted: 16 Nov 2018 11:54
by muldjord
thewiz wrote: 16 Nov 2018 11:49 I will dig out the tape format and post it later today. Off for a flu jab now.
That would be very helpful. Thanks Paul! Good luck with the flu jab. :)

Re: New tape cleaner tool

Posted: 16 Nov 2018 12:02
by muldjord
Crazyboss wrote: 16 Nov 2018 10:47 Nice you work on a new tool, but from now on I will release new games as Wav created by apptool, so the wav should be as clean as possible. I also have created new waves from previous games, and they all load nice on real hardware.
Yes, that make sense. I mostly wrote this tool because I had problems loading several of the wav's for my video project, so I thought it would be a good opportunity to learn about the innards of the files. :)
Crazyboss wrote: 16 Nov 2018 10:47 About Toado, i dont recall i had problems loading it, but i think two versions exists - actually 3 versions. One Loads directly, another one use the Continental Software loader (the MAP). And the 3rd is my transfer project i did back in the 2000s where i found .mtx files but we did not have any good emulators and i wanted to play the games so i found a way to transfer them from PC to Memotech using RS232 and save them as tapes (waves).
Looking at the wav from your download page there seems to be a lot of flutter in the pulses, so it spits out faulty data with my current implementation (I actually can't recall if the original works for me, it might, but now the challenge is on, so I need to make the conversion work :) ).
Crazyboss wrote: 16 Nov 2018 10:47 About "tapeworm", I recall its a basic game, he do something quite dangerous i think by poking the snakes position or so into memory, instead of use a ARRAY, not sure its a problem but it could overwrite the system area, maybe? The programmer, was one of the first programmers I located many years ago, and i did an "interview" by mail, which is at my very outdated www.mtxworld.dk homepage.
Yes, I seem to recall talking about that interview many years back. Maybe I just got to see the code from when the Memotech from time to time would have loaded halfway bad data and exit to the READY prompt after loading. Sometimes you could then list a lot of the BASIC with LIST.

Re: New tape cleaner tool

Posted: 16 Nov 2018 13:59
by Crazyboss
thewiz wrote: 16 Nov 2018 11:49 Hi Lars,

Great that you have a new tool for converting wavs as I still have a number of wavs that I've not been able to convert. I've got some mp3s too which are known to work.

I will dig out the tape format and post it later today. Off for a flu jab now.

TTFN
Paul Daniels
Paul, is the missing conversions something we dont have have, if they can load into real hardware maybe its possible to dump them. You can try to mail them to me ?

About the flu jab, does it prevent a "MAN FLU" its quite dangerous :lol: :lol: :lol: :lol: :lol:

Re: New tape cleaner tool

Posted: 16 Nov 2018 14:48
by Bill B
From memory:

* A one is represented by a single cycle at 4.8kHz, and a zero by a single cycle at 2.4kHz. This means that the baud rate is approximate (and varies with the ratio of zeros / ones), unlike the BBC which uses two cycles of the high frequency tone to give a constant bit duration.
* I don't remember whether it is msb or lsb first, need to check the ROM listing.
* There is no parity or checksum.
* Your long pulse is probably the gap between blocks of data. I think BASIC programs save at least three blocks. Again need to check the ROM listing.

Regards,

Bill.

Re: New tape cleaner tool

Posted: 16 Nov 2018 16:32
by thewiz
Here are some calcualtions that might help:

The MTX tape routine works by configuring the CTC to interrupt on edge detection.
While waiting for the edge, register A is decremented.

No of cycles to execute "DEC A ; JP C, -3" - 14. It takes 14 cycles to decrement reg A.

22050 sample rate is 4E6/22050 = 182 cycles each. Therefore A decremented by 182/14 = 13 every sample.
44100 sample rate is 4E6/44100 = 91 cycles each. Therefore A decremented by 91/14 = 6.5 every sample.

22050 sample rate: 80 = 256 - 176 = 176 * 14 = 2464 Cycles = 2464 / 182 = 13 samples.
44100 sample rate: 80 = 256 - 176 = 176 * 14 = 2464 Cycles = 2464 / 91 = 27 samples.

A zero is 9 samples, meaning A = 256 - (13 * 9) = 256 - 117 = 139.
A one is 17 samples, meaning A = 256 - (13 * 17) = 256 - 221 = 35.

A zero is 18 samples, meaning A = 256 - (6.5 * 18) = 256 - 117 = 139.
A one is 34 samples, meaning A = 256 - (6.5 * 34) = 256 - 221 = 35.

80 - Middle value (MIDVAL)

A tape is made up of the following blocks:

Filename - 18 bytes made up of 0xff, 15 bytes for name, 16bit word containing SYSVAR
pause caused by 'LD DE,0000; DEC DE; LD A,D; OR E; JR NZ -5'. See below.
Sys vars - (0xfb40 - SYSVAR) bytes
Basic (includes noddy and arrays) - (ARRTOP) - (0x4000 is saved on a MTX512, else 0x8000). On MTX512, blocks are ordered in 0x4000 then 0x8000.
Basic vars - (CALCST) - (VARNAM) bytes
zero or more blocks of M/c

Note each block is split into subblocks 16384 bytes.
Calculations for pause:

'LD DE,0000; DEC DE; LD A,D; OR E; JR NZ -5'
10 6 4 4 7/12 (machine cycles)

= 10 + ((6 + 4 + 4 + 12) * 65535) + 7 = 13280951

= 13280951 / 182 = 72972 samples at 22050

= 13280951 / 91 = 145944 samples at 44100

A block is made up of:

1500 zeros followed by a one. Note when loading only a minimum of 256 zeros are required.
Bytes

The start of the lead in (1500 zeros), isn't very clean so you see a long spike first.

The bitshifting was due to dealing with glitches in the wav. If the glitch was in a section of text, it was possible to deal with it with just a single byte to recreate.

A refinement I made was to load the sysvars by searching for the SYSVARS value by converting to a stream of bits and incrementing a a bit until I found it. As you might imagine, it was slow but did work on some tapes.

I and email you my code if it would help.

Regards

Re: New tape cleaner tool

Posted: 16 Nov 2018 23:50
by muldjord
Paul, this is very helpful, thank you, I appreciate your help a lot. I would love to have the code to look over. You can mail it to me at muldjordlars [at] gmail [dot] com.

I will look over your input over the coming weeks and see what I can come up with. I love fiddling with this, and it's great for learning about the low level stuff that I don't usually deal with on a daily basis.

Bill, MSB or LSB would also be useful information, I'm guessing LSB as Paul could make out characters in hex by bitshifting directly.

Re: New tape cleaner tool

Posted: 17 Nov 2018 11:48
by Martin A
Looks like yes it is LSB first, the byte input and output routines both use RR C to shift bits into carry.

Code: Select all

.inbyte
LD   B,&08
.inby1
CALL inbit
RR   C
DJNZ inby1
RET

.outbyte
LD   B,&08
.outby1
RR   C
CALL outbit
DJNZ outby1
RET
Tape.DOC
Full tape source
(4.76 KiB) Downloaded 702 times