Tuesday, April 19, 2016

Slamy STM32 Floppy Controller - Part 1


Back then i had quite some struggle getting old games to work again. My dad once brought me to an Amiga distributor and i was allowed to buy a game. I chose "Enchanted Land" a disk which years after that refuses to load.

I remember that i got my first way around issues like that sometimes after that. There was a program called "Amiga Explorer" allowing me to write ADF files using a windows tool with the same name and a server running on my Amiga 500 communicating over the RS232 port.
This way i could play some of my games again but.... i had to work with sometimes faulty cracked version.

At that time i also read about the Catweasel controller, a PCI card with a flexible floppy controller design allowing a more easier way to write disks back in a direct way from the PC.

That was about 10 years ago....

An half year ago or so i read about Kryoflux. This powerful device which is mostly designed to preserve dying floppy media for future generations also had writing capabilities.
The price was not that high but i didn't knew if it would suit my needs as i had mostly the intent of writing images back.
Also i was very interested in the techniques used around that time so a new tinkering project was on its way.

Atari ST - ISO sectors and MFM stuff (starting from 2016-02-07)

During February 2016 i decided to give it a go and started at the hardware design.
During 2014 I did make a floppy controller with an FPGA to write Atari ST compatible disks so i had already some knowledge on that matter. As FPGA development is rather tedious and modern controllers have become very fast i decided to go for an ARM instead.

My choice fell on the very cheap STM32F4 discovery board. It costed about 12€ and is equipped with an STM32 clocked at 168 MHz. What a beast !!!
Another very important feature was the integrated debugging and flash circuit and a USB OTG controller for getting image data from a PC.

I ported my original C code running on the plasma mips softcore from opencores to the STM32 and implemented the MFM decoder using the integrated timer.
For USB communication i used the stack of https://github.com/MaJerle. It's a modifed version of the OTG driver coming with the STM32F4 examples which luckily ran quite nice. (The original library from STM just refused to work)

And after some tinkering i was able to decode MFM and to parse the ISO floppy format making me able to read Atari ST and MS DOS disks in DD and HD. This page helped me a lot. Everything you need to know about MFM and ISO sectors.

So what comes next after reading? Writing of course! I've developed a linux driver to transfer image data from *.ST images to the controller which writes it track for track.
My Atari 1040STFM was quite happy about the result and played cracked versions of some games without problems.

Coming that far i decided to go for Amiga disks. The MFM used on my most beloved machine was quite different. Instead of encoding 8 bits to 16 MFM bits it used an odd and even way. When encoding 32 bits it first encoded the 16 odd bits and then the 16 even bits. Quite a hassle but possibly a style which had a better performance on the floppy controller design in the custom chips.

After basic writing of ADF files which are a binary representation of a standard Amiga DOS disk i finally went for the main goal.

Amiga IPF files (starting from 2016-03-06)

Original versions of amiga games usually come with a certain copy protection. Some use very long tracks with a reduced bitrate to get more data on a track than usual. An amiga couldn't write that. Turrican 1 and 2 are protected that way.
Others were protected using a varying bitrate. Speedlock is a protection which used that technique.
The ADF format is only capable of storing the payload data. No meta information is saved.
For everything else IPF files are used.
Soon i've discovered that http://fengestad.no/libfs-capsimage/ was all i needed. The capsimage library is a closed source manager for IPF track data which i decided to use.
What it basically does is giving back the raw MFM tracks and also with bitrate information for every MFM byte if specified by the image.
It took a few weeks of debugging and analyzing but it worked in the end. Writing back Turrican 1 and 2 (Long tracks) and Rodland (Speedlock) was possible using my so called "Slamy STM32 Floppy Controller".

This success gave me an amazing motivation and i went further.
I realized this wasn't a normal floppy controller anymore. This was called a floppy tracer, an industrial device to write mastered disks ! >:-)

To be continued.... Amstrad CPC and C64