avatar_cpcitor

Have Linux make a USB floppy drive write to a disk that a CPC can then read.

Started by cpcitor, 20:39, 19 October 17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cpcitor

I have a number of PC, including tower PCs with a real disk drive.

I was testing a number of floppy disks with a USB drive on my laptop PC (running Linux, of course).

Monitoring the USB drive activity.

In a terminal, I types this command so that the kernel tells me what happens:

dmesg -w


Inserting a HD floppy it says:

[148595.327894] sd 12:0:0:0: [sdb] Spinning up disk...
[148596.735933] sd 12:0:0:0: [sdb] 2880 512-byte logical blocks: (1.47 MB/1.41 MiB)


So I know the USB floppy device is /dev/sdb.

Probing for current disk format.

This commands probes for current disk format:
ufiformat -i /dev/sdb


Drive replies that it is formatted as regular HD floppy, and it can format to a number of variants.

vendor:  CITIZEN
product: X1DE-USB
write protect: off
media type: 2HD
status      block size   kb
formatted    2880  512 1440
formattable  2880  512 1440
formattable  1232 1024 1232
formattable  2400  512 1200


Formatting a disk.

I insert a DD floppy (actually a HD with a post-it covering the DD/HD hole).

Sure, USB floppy drives are restricted to common formats, and CPC's data and system/vendor formats aren't included.
But, good news: a USB floppy drive can format something that CPC's AMSDOS can read and recognize as what Amstrad calls IBM format.

I issue this command to format it simiarly to a CPC: -f 640 means same density as a CPC, but two sides, 80 tracks (AMSDOS would only use 40 tracks and one side at a time).

ufiformat -f 640 -V /dev/sdb

This formats and verifies (thanks to -V) !

geometry: track=80, head=2, sector=8, block=512
formatting track=00, head=0
...
verifying  track=00, head=0


Reading a CPC-compatible formatted disk content (low level).

Let's probe again.

ufiformat -i /dev/sdb


vendor:  CITIZEN
product: X1DE-USB
write protect: off
media type: 2DD
status      block size   kb
formatted    1280  512  640
formattable  1440  512  720
formattable  1280  512  640


The line formatted    1280  512  640 confirms.

There's no actual filesystem, only e5's:

hd /dev/sdb

00000000  e5 e5 e5 e5 e5 e5 e5 e5  e5 e5 e5 e5 e5 e5 e5 e5  |................|
*
000a0000


Detecting bad floppies

Beside noise patterns as the drive retries, Linux kernel tells this:

[149459.375068] sd 12:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[149459.375072] sd 12:0:0:0: [sdb] tag#0 Sense Key : Medium Error [current]
[149459.375074] sd 12:0:0:0: [sdb] tag#0 Add. Sense: Unrecovered read error
[149459.375077] sd 12:0:0:0: [sdb] tag#0 CDB: Read(10) 28 00 00 00 01 e0 00 00 f0 00 00 00
[149459.375079] blk_update_request: critical medium error, dev sdb, sector 682
[149482.416331] sd 12:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[149482.416335] sd 12:0:0:0: [sdb] tag#0 Sense Key : Medium Error [current]
[149482.416338] sd 12:0:0:0: [sdb] tag#0 Add. Sense: Unrecovered read error
[149482.416340] sd 12:0:0:0: [sdb] tag#0 CDB: Read(10) 28 00 00 00 02 b8 00 00 08 00 00 00
[149482.416342] blk_update_request: critical medium error, dev sdb, sector 698
[149482.416345] Buffer I/O error on dev sdb, logical block 87, async page read


Reading/writing the disk on a real CPC.

I insert the disk into a 3.5 drive fitted to my CPC, issue cat.

CPC accepts the disk as a IBM-formatted disk.

Reads and writes are slow, capacity is limited, but it works.

Success!

I asked the CPC to

save"screen",b,&c000,&4000

cat confirmed that data was written, load"screen" can read it again.


Having the PC read back what the CPC wrote.

When the disk was back in the USB drive, sure this command:

hd /dev/sdb

showed SCREEN and data. Not as a nice directory with files, rather a stream of bytes, but data is there!

Next steps

(Option 1) Write disc with actual content using USB drive

Next step is to generate IBM-format DSKs that I can write to the floppy with:

dd if=myIBMformatimage.dsk of=/dev/sdb

So far I couldn't have cpcxfs or iDSK produce a IBM-format DSK. If the image is fit for a CPC, it will work.

Once it works manually, I'm aiming at including that in https://github.com/cpcitor/cpc-dev-tool-chain and possibly https://github.com/lronaldo/cpctelera . At that point we'll be able to generate an image written to disk quickly and run it on a real CPC as an alternative to tape-style audio workflow.

(Option 2) Do similar job with a real disk drive (not USB) in a tower PC, preferably with option for data/system/vendor format.

Will use setfdprm to explain to Linux, ...

Will do as well as USB for IBM format, but what about other formats ?

I read hardware can do it, but no doc seem to consider sectors number that don't start from 1 (like 0x41, 0xC1).

Perhaps fdrawcmd or superformat will help... perhaps not.

(Option 3) Have Linux provide access to CPC-formatted floppy content like a regular directory

Technically it can be a FUSE (Filesystem in User SpacE) module that calls iDSK, cpcxfs or custom code to read and write.

As a result, we'll be able to open the disk in any file manager, see files, edit them with any editor, write back the result.
Open a terminal, cd into the CPC disk, list files, copy to/from with regular tools, use diff and other tools naturally.

Trying to create directories or write files with too long names should fail as expected.

Putting the disk back into a CPC would allow it to see the changes.
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made in 2013 the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC, later forked into CPCTelera.

cpcitor

With normal internal floppy drive: already done.

Quote from: cpcitor on 20:39, 19 October 17
(Option 2) Do similar job with a real disk drive (not USB) in a tower PC, preferably with option for data/system/vendor format.

Will use setfdprm to explain to Linux, ...

Will do as well as USB for IBM format, but what about other formats ?

I read hardware can do it, but no doc seem to consider sectors number that don't start from 1 (like 0x41, 0xC1).

Perhaps fdrawcmd or superformat will help... perhaps not.

As mentioned already in the forum and the wiki, this path is covered by dsktools.

The way is to call Linux's FDRAWCMD API which allows format, read and write of custom tracks.

Amstrad CPC mentioned in Linux kernel source code.

At linux/drivers/block/floppy.c line 435 · torvalds/linux, emphasis is mine:

Quote(...) For some CP/M and music sampler disks (such as Ensoniq EPS 16plus) it is 0 (represented as 0x01<<2).
For Amstrad CPC disks it is 0xC1 (represented as 0xC0<<2).

dsktools now hosted on github

Berlios no longer exists and thus neither https://developer.berlios.de/projects/dsktools/ there's still v0.2.3 source code without history on https://sourceforge.net/projects/dsktools.berlios/files/ and an automatically generated github repo of 0.2.4 with history on https://github.com/BackupTheBerlios/dsktools . I migrated the project to github: https://github.com/cpcitor/dsktools with credit to authors.
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made in 2013 the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC, later forked into CPCTelera.

Powered by SMFPacks Menu Editor Mod