joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.79k stars 382 forks source link

Floppy disk "bad sector" emulation (and other tricks to run copy protected games) #444

Open joncampbell123 opened 6 years ago

joncampbell123 commented 6 years ago

It just occurred to me while watching "Ancient DOS Games" that it might help old copy-protected titles if DOSBox-X could accept a list of bad sectors to emulate alongside a floppy disk image.

The list would be a simple list of sectors as a text file (C/H/S) that should return an error on read instead of returning the data.

It was common for titles in the 80s to have deliberate bad sectors to detect copies.

sikthehedgehog commented 6 years ago

I was under the impression that the way those worked was by just marking the sectors as bad in the FAT (rather than actually being bad sectors), so using a stock FAT driver would report them as unusable but parsing the filesystem on your own could let you by-pass that (effectively making them uncopyable through naive means).

Actually making sectors bad probably would have been a pain to pull off at the factory. Though I guess it's possible somebody tried malformed sectors (the same way some floppies have non-standard sector sizes to squeeze in some more KB).

joncampbell123 commented 6 years ago

@sikthehedgehog No. If it was just a "bad sector" (a cluster marked invalid) in the FAT, a 1:1 copy of the disk would preserve that, FAT table included.

joncampbell123 commented 6 years ago

http://diskpreservation.com/dp.php?pg=protection_atari

http://www.sierrahelp.com/AGI/CopyProtection/index.html

http://www.os2museum.com/wp/lotus-1-2-3-r3-copy-protection/

https://en.wikipedia.org/wiki/Bad_sector#Copy_protection

ssokolow commented 6 years ago

To make it easy for people to dump disks with protections that don't rely on low-level trickery (like the linked example of Lotus 1-2-3 protection that has to work on both DOS and the more restrictive OS/2 APIs), one thing I'd suggest is support for parsing the .log files that GNU ddrescue can write.

As an example, while I don't yet know if that's the only mechanism used, here's what The Four Crystals of Trazere, Disk 1 of 2, looks like when dumped using GNU ddrescue and a USB floppy drive. (Which I did to ensure that the data will be safe even if the disk starts to go before I finish backing up my floppies and come back around to try harder on the problematic ones.)

# Rescue Logfile. Created by GNU ddrescue version 1.17
# Command line: ddrescue --direct -M -r 5 /dev/sdi TRAZERE1.img TRAZERE1.log
# current_pos  current_status
0x00058C00     +
#      pos        size  status
0x00000000  0x00057C00  +
0x00057C00  0x00000200  -
0x00057E00  0x00000200  +
0x00058000  0x00000200  -
0x00058200  0x00000200  +
0x00058400  0x00000200  -
0x00058600  0x00000200  +
0x00058800  0x00000200  -
0x00058A00  0x00000200  +
0x00058C00  0x00000200  -
0x00058E00  0x0005B200  +

This is intended to be machine-readable, since it's specifically used that way by GNU ddrescue if you want to do a quick pass over a dying drive to grab as much as possible, then run ddrescue a second time in "subdivide the bad extents to get as much as possible" mode.

Since I initially tried copying it on my Win98SE retro-PC using the final, freeware release of VGACopy (vgacp625.zip), I can tell you that the pattern thus described is a disk in good health (ie. No tracks or sectors marked as "weak" or retried) with a specific, single track, which alternates, 1-for-1, between good and bad sectors.

rderooy commented 4 years ago

Would it not be better to support an existing disk format that supports copy protected disks instead?

Looking around there is Teledisk (TD0), ImageDisk (IMD), Snatchit (CP2) which are able to support some, but not all copy protected disk formats apparently.

And then there is TransCopy (IMG), which supports most copy protections it seems, and lastly there is Kryoflux but that one creates rather large (and numerous) files.

sofakng commented 3 years ago

I'd also love to see support for Kryoflux or HFE(v3) image formats. These formats allow for all (?) copy protection methods to be supported.

I don't like using cracks/patches if I don't need to and this support would be fantastic.

joncampbell123 commented 3 years ago

I could do Kryoflux (read only at least), I have one of those and I've been imaging most of my floppies with it lately. I even wrote my own code to parse the raw flux format their tool puts out: https://github.com/joncampbell123/floppytools

sofakng commented 3 years ago

I could do Kryoflux (read only at least), I have one of those and I've been imaging most of my floppies with it lately. I even wrote my own code to parse the raw flux format their tool puts out: https://github.com/joncampbell123/floppytools

That would be fantastic! read-only is probably all that anybody really needs.

If you need any help testing I also have several images I could use.

Thanks again very much!

pgalbraith commented 2 years ago

I could do Kryoflux (read only at least), I have one of those and I've been imaging most of my floppies with it lately. I even wrote my own code to parse the raw flux format their tool puts out: https://github.com/joncampbell123/floppytools

Wow Jon this would be amazing, I hope you can find time :-)