Now Reading
Becoming 44% Extra Knowledge on a C64/1541 Floppy Disk – pagetable.com

Becoming 44% Extra Knowledge on a C64/1541 Floppy Disk – pagetable.com

2023-05-28 23:35:15

The bodily knowledge format on a Commodore 1541 5¼-inch floppy disk as utilized by the C64 is totally outlined in software program. The drive’s working system suits 170 KB on a disk. This text explores completely different methods, every with its professionals and cons, to suit as much as 246 KB.

Common 1541 Disk Format

These are the specs of the unique 5¼-inch “minifloppy” from 1976:

  • 35 tracks
  • radius of outermost observe: 57.150 mm
  • observe spacing: 1/48 inch (i.e. 48 tpi, tracks-per-inch)
  • observe capability: 50 Kbit/observe1 (= 25.4 bytes per millimeter on observe 35)

The Shugart SA-400 drive, which outlined the minifloppy, included a controller that formatted the disk with 90 KB. Like Apple, Commodore purchased simply the mechanism with out the controller (Shugart referred to as this the SA-390), and used its personal 6502-based system because the controller (which was cheaper) and outlined their very own format (which made higher use of the disk).

The Shugart format was utilizing the identical variety of sectors on every observe. However tracks on the surface are longer: observe 1 is 46% longer than observe 35. And if the fabric on the disk should be capable of maintain 50 Kbit on observe 35, it have to be secure to retailer 70 KBit on observe 1. The mixed size of all tracks is 10590 mm, so primarily based on the 50 KBit for observe 35, the entire disk can maintain 269 KB2, if each observe is learn and written at its particular person velocity.

Commodore selected to help 4 velocity zones. The quickest one on the surface tracks reads and writes a byte each 26 µs (at 300 rpm), the slowest one on the within does this each 32 µs.

Observe # Sectors Velocity Zone µs/Byte Uncooked Kbit/Observe
1 – 17 21 3 26 60.0
18 – 24 19 2 28 55.8
25 – 30 18 1 30 52.1
31 – 35 17 0 32 48.8

The next graph exhibits the info densities per millimeter for tracks 1 to 35. The 25.4 bytes per millimeter of the unique specification are by no means exceeded3. (An optimum scheme would max out the 25.4 bytes/mm on all tracks.)

It’s fascinating to notice that observe 18, which holds the filesystem metadata, and is subsequently a very powerful observe of the disk, has a comparably low density and will subsequently have greater reliability.

With the 17 to 21 sectors per observe, this makes a complete of 683 sectors of 256 bytes every, or 170.75 KB.

Tracks 36-41

Whereas the unique “minifloppy” disk format solely specified 35 tracks, later disks (with bigger cutouts) and drive mechanics supported 40 tracks.

Whereas the firmware of all 48 tpi Commodore 5¼-inch drives stayed with the unique 35 observe format, the mechanics of the 1541 and later drives are designed for 40 tracks, and in follow, all drives may even attain observe 41, and the magnetic layer of disks remains to be dependable on observe 41 as properly4.

There have all the time been quite a few instruments to format, learn and write knowledge in tracks 36-40 (or 41). They normally use velocity zone 0, the slowest one, so every observe suits one other 17 sectors, for a complete of 85 (or 102) further sectors, or 21 (25) KB. This can be a disk capability improve of 12% (15%).

It appears easy and secure to make use of the additional tracks (no less than till observe 40) like this, however the density used on these tracks truly exceeds the required 25.4 bytes per millimeter by as much as 8.7%

Max Velocity Zones

A extra radical method to becoming extra knowledge is to make use of the quickest velocity zone for all tracks. This fashion, each observe will maintain 21 sectors, for a complete disk capability of 861 sectors (215 KB) when utilizing 41 tracks.

(In follow, observe 18 of disks in a customized format should be formatted within the authentic format, in any other case the unique DOS received’t be capable of e.g. load the boot program of a sport or an utility. This limitation does after all not apply to further knowledge disks of a sport, or pure consumer knowledge disks.)

However it will exceed the required capability of the medium for tracks 18 and above: within the case of observe 41 even by 34%!

How dependable is a disk written with too excessive a density? Let’s do an experiment.

The next Python script will create an outline of an all-speed-zone-3 take a look at disk. Every of the 41 tracks comprises 21 sectors full of 0..255. In any other case, the disk is totally per the Commodore “2A” on-disk format.

print 'no-tracks 84'  
print 'track-size 7928'  
for observe in vary(1,42):  
    print 'observe {}'.format(observe)  
    print '   velocity 3'  
    print '   begin-at 0'  
    for sector in vary(0, 21):  
        print '   sync 40'  
        print '   gcr 08' # header  
        print '   begin-checksum'  
        print '      checksum {:02x}'.format(observe ^ sector)  
        print '      gcr {:02x}'.format(sector)  
        print '      gcr {:02x}'.format(observe)  
        print '      gcr 30 30' # ID  
        print '   end-checksum'  
        print '   gcr 0f 0f' # OFF bytes  
        print '   ; Trk {} Sec {}'.format(observe, sector)  
        print '   bytes 55 55 55 55 55 55 55 55 55' # hole  
        print '   sync 40'  
        print '   gcr 07' # knowledge  
        print '   begin-checksum'  
        print '      gcr',  
        for i in vary(0, 256):  
            print '{:02x}'.format(i),  
        print ''  
        print '      checksum 00'  
        print '   end-checksum'  
        print '   gcr 00 00' # OFF bytes  
        print '   bytes 55 55 55 55 55 55 55' # hole  
    print 'end-track'

The .TXT output of the script could be transformed right into a binary .G64 picture utilizing the superb g64conv utility. Utilizing a ZoomFloppy, nibtools and both a 1541 with a parallel cable mod or a 1571, you possibly can write this picture to disk (nibwrite), after which preserve studying it in a loop (nibread). I used to be capable of learn such a disk 1000 instances on a 1571 with none errors.

Minimizing Gaps

However there’s a technique to match 41 extra blocks (10.25 KB, 20% further) with out exceeceding the specs of 48 tpi disks – and nonetheless being learn suitable with the unique firmware.

Let’s take a look at observe 1 with its 21 sectors. For each sector, there’s a SYNC mark, a header, one other sync mark, and the sector knowledge.

This construction will get written when a disk is first formatted. When studying a sector, the drive appears for a SYNC sample, reads the header, which comprises amongst different knowledge the variety of the sector that follows, and if it’s the right sector quantity, it waits for one more SYNC mark and reads the sector knowledge.

When writing a sector, the drive additionally appears for the right header, after which overwrites the part afterwards, together with the SYNC mark.

Since it’s inconceivable to hit one explicit byte location when switching to jot down mode, there’s a 9 byte hole after the header, and one other hole (normally 8 bytes) after the sector contents5. It received’t matter if the newly written sector is a number of bytes too early or too late, as a result of it would solely spill into one of many two gaps:

As well as, there are “tail gaps” on the finish of every observe:

The lengths of the sectors in every velocity zone don’t add as much as the entire size of the observe. It’s because the tracks are usually not evenly divisible by their variety of sectors, and likewise to account for drives with barely incorrect motor speeds.

By minimzing a few of these accounting buildings and utilizing extra of the tail gaps for knowledge, it’s potential to suit one or two extra sectors onto every observe.

Knowledge Gaps

There are normally round 8 hole bytes after the sector knowledge. If we take away them, studying the disk won’t be impacted in any approach: After studying a sector, a drive by no means instantly reads the subsequent one, as a result of it must decode and transmit the info first. And even when it did, within the worst case, it would miss the subsequent sector, as a result of the subsequent header has arrived too rapidly, however it would catch it once more after one rotation.

Eradicating the hole after the sector knowledge will make appropriately writing to the disk inconceivable although. There may be little or no wiggle room for hitting the right vary of bytes when overwriting a sector. Overshooting the world will simply destroy the subsequent SYNC mark or the subsequent header, so the next sector received’t be readable any extra.

An ordinary disk has 9 hole bytes after the header. It’s not potential to fully take away it and nonetheless be suitable with the sector learn routines within the 1541 firmware: After the drive has learn the header, it must decode it and resolve whether or not that is the sector it’s on the lookout for. Whether it is, it would scan for the subsequent SYNC mark after which learn the info. However decoding and deciding takes time, and each 26 to 32 CPU clock cycles, the subsequent byte passes the learn head. So if there is no such thing as a hole, the SYNC mark can have handed the learn head earlier than the drive has made the choice to learn this sector.

With 2 hole bytes as a substitute of 9, the unique learn code nonetheless works, and so does most different third social gathering learn code.

Like eradicating the info hole, minimizing the hole after the header will even break writing, and this time horribly. When overwriting the sector, the unique firmware code will skip 9 bytes earlier than starting to jot down the SYNC mark and the sector knowledge. If there is no such thing as a hole on the finish of the info, it’s assured to overwrite the subsequent header. However even when there’s, when skipping the supposed header hole (“wait 9 bytes”), it’s truly skipping the SYNC mark and the start of the previous sector knowledge. So when the sector will get learn once more, the primary SYNC mark will get detected, however the knowledge is overwritten by the misaligned new sector knowledge.

See Also

SYNC Marks

The SYNC marks consists of sequences of consecutive 1-bits, which can not in any other case be a part of the info stream. For a SYNC to be detected, it must be no less than 10 bits lengthy. The unique firmware all the time writes 40 bits, however we are able to trim this right down to 16 bits, saving 2×3 bytes for each sector.

The Format

With a 2 byte header hole, no sector hole and 16 bit SYNC marks, we have now saved 18 bytes per sector. Now there’s area for another sector on tracks 1-17 and 25-35, and even two extra sectors on tracks 18-246.

The next python code will generate a .TXT take a look at file that may be transformed to a .G64 utilizing g64conv.

def speed_for_track(observe):  
    if observe < 18:  
        return 3  
    if observe < 25:  
        return 2  
    if observe < 31:  
        return 1  
    return 0

def sectors_for_track(observe):  
    return [18, 19, 21, 22][speed_for_track(track)]

    print 'no-tracks 84'  
    print 'track-size 7928'  
    for observe in vary(1, 36):  
        print 'observe {}'.format(observe)  
        print '   velocity '.format(speed_for_track(observe))  
        print '   begin-at 0'  
        for sector in vary(0, sectors_for_track(observe)):  
            print '   sync 16'  
            print '   gcr 08' # header  
            print '   begin-checksum'  
            print '      checksum {:02x}'.format(observe ^ sector)  
            print '      gcr {:02x}'.format(sector)  
            print '      gcr {:02x}'.format(observe)  
            print '      gcr 30 30' # ID  
            print '   end-checksum'  
            print '   gcr 0f 0f' # OFF bytes  
            print '   ; Trk {} Sec {}'.format(observe, sector)  
            print '   bytes 55 55' # hole  
            print '   sync 16'  
            print '   gcr 07' # knowledge  
            print '   begin-checksum'  
            print '      gcr',  
            for i in vary(0, 128):  
                print '{:02x} {:02x}'.format(observe, sector),  
            print ''  
            print '      checksum 00'  
            print '   end-checksum'  
            if observe >= 18:  
                print '   bits 1111'  
        print 'end-track'

Studying/Writing

The unique 1541 firmware can nonetheless learn all common sectors, however because it checks observe/sector numbers for validity, the brand new sectors received’t be authorized for normal recordsdata, and so they can’t be learn utilizing the U1 block learn command both. The interior “job queue” API received’t do that verify although. The next BASIC program will allocate buffer #2 (line 30), ship a learn command for observe T, sector S into buffer 2 (strains 40-50), watch for its completion (strains 60-70), and obtain and print the buffer (line 90-100).

10 t=18:s=19  
20 open1,8,15  
30 open2,8,2,"#2"  
40 print#1,"m-w"+chr$(10)+chr$(0)+chr$(2)+chr$(t)+chr$(s);  
50 print#1,"m-w"+chr$(2)+chr$(0)+chr$(1)+chr$(128);  
60 print#1,"m-r"+chr$(2)+chr$(0)+chr$(1);  
70 get#1,a$:a=asc(a$+chr$(0)):ifaand128thenprint".";:goto70  
80 ifa<>1thenprint"error ";a:finish  
90 print#1,"b-p 2 0"  
100 fori=0to255:get#2,a$:printasc(a$+chr$(0));:subsequent  
110 close2:close1

Since writing any sector will destroy it in addition to the next sectors, care have to be taken that the consumer doesn’t try to jot down to it. Commodore DOS shops a filesystem model identifier at observe 18, sector 0, offset 2. That is “A” (0x41) on the 1541. Overwriting this byte with another worth will tender write shield the disk: All write accesses by way of the filesystem API will fail with code 73, however it can not stop direct block writes (command U2).

So with the caveat of not having the ability to write to the disk any extra, we are able to create a disk with further sectors that may nonetheless be learn with the unique software program – an ideal use for sport disks, for instance. A sport might use a disk that makes use of the additional sectors on all tracks together with the listing observe (observe 18), and have the consumer load the preliminary boot program utilizing the unique 1541 DOS performance. (The boot program can not use any of the additional sectors.) Then, a quick loader would take over to load the precise sport program and knowledge. This may be any current quick loader with none variations, so long as it doesn’t verify for the validity of sector numbers.

Max Velocity Zones + Minimizing Gaps

We will additionally use the quickest velocity zone along with minimal gaps. This fashion, all tracks can have 22 sectors. With 41 tracks, that’s a complete of 924 sectors (231 KB), which is 241 further sectors, or 35% extra capability.

(Once more, if the disk is meant to be bootable, observe 18 must have the common format.)

Customized Format

The Commodore DOS format makes use of a SYNC-prefixed header and a separate SYNC-prefixed knowledge part, which is required in order that sectors could be rewritten reliably. If a disk shouldn’t be meant to be modified, we are able to change a sector to solely just about solely include a SYNC mark, its sector quantity, the 256 knowledge bytes and a checksum. The following sector can simply comply with with none hole.

This format is after all fully incompatible with Commodore DOS and requires importing customized learn code into the 1541.

Nevertheless it permits us to suit two further sectors per observe in comparison with the unique format.

def speed_for_track(observe):  
    if observe < 18:  
        return 3  
    if observe < 25:  
        return 2  
    if observe < 31:  
        return 1  
    return 0

def sectors_for_track(observe):  
    return [19, 20, 21, 23][speed_for_track(track)]

print 'no-tracks 84'  
print 'track-size 7928'  
for observe in vary(1, 36):  
    print 'observe {}'.format(observe)  
    print '   velocity '.format(speed_for_track(observe))  
    print '   begin-at 0'  
    for sector in vary(0, sectors_for_track(observe)):  
        print '   sync 16'  
        print '   gcr {:02x}'.format(sector)  
        print '   begin-checksum'  
        print '      gcr',  
        for i in vary(0, 128):  
            print '{:02x} {:02x}'.format(observe, sector),  
        print ''  
        print '      checksum 00'  
        print '   end-checksum'  
        print '   bits 1111'  
    print 'end-track'

Max Velocity Zones + Customized Format

Once more, we are able to use velocity zone 3 for all tracks, so all of them have 23 sectors every, for a complete of 943 sectors, or 38% greater than an everyday disk.

Theoretical Most

The customized format was nonetheless utilizing 256 byte sectors, every with a SYNC mark, a sector quantity and a checksum. What if we simply saved every part in a single large sector? We nonetheless want one SYNC mark on the observe, so we all know the place it begins, and with a purpose to reset the {hardware}’s bit alignment logic. Velocity zone 3 suits 7692 uncooked bytes onto a observe. No less than two bytes might be wanted for the SYNC mark, and with the info GCR-encoded (and the dimensions growing by 5/4), we can have 6152 bytes for knowledge, which is 24 sectors, with solely 8 bytes to spare. Writing such a disk is just potential if the drive is not any sooner than 0.1% above the required 300 rpm.

Penning this format onto all 41 tracks will give us 984 blocks (246 KB), or 44% extra.

print 'no-tracks 84'  
print 'track-size 7928'  
for observe in vary(1,42):  
    print 'observe {}'.format(observe)  
    print '   velocity 3'  
    print '   begin-at 0'  
    print '   sync 16'  
    print '      gcr',  
    for i in vary(0, 24 * 256):  
        print '{:02x}'.format(i & 0xff),  
    print ''  
    print 'end-track'

However studying might be tough and gradual. There is just one SYNC mark, so studying any portion of the observe will first require ready for the SYNC mark (1/10 sec on common). The one sector holds 6 KB of information, however the drive’s buffer RAM ist solely 2 KB complete, so it can not retailer the entire sector. It subsequently must skip any variety of bytes till the requested part knowledge stream is reached.

Utilizing 512 or 1024 byte sectors that may nonetheless match the drive’s RAM wouldn’t work although: The one large 6 KB sector simply barely match with solely 8 bytes to spare, breaking it up into smaller sectors would overflow the accessible area.

Comparability

The next desk is sorted by capability:

Methodology Capability (blocks) Capability % Appropriate with DOS Density Spec Compliant
Common Format 683 (170 KB) 100% sure sure
Minimizing Gaps 724 (181 KB) 106% read-only sure
Customized Format 753 (188 KB) 110% no sure
Tracks 36-41 785 (196 KB) 115% sure sort of
Minimizing Gaps + Tracks 36-41 832 (208 KB) 122% read-only sort of
Max Velocity Zones1 861 (215 KB) 126% no no
Customized Format + Tracks 36-41 867 (216 KB) 127% no sort of
Max Velocity Zones + Minimizing Gaps 902 (225 KB) 132% no no
Customized Format + Max Velocity Zones 943 (235 KB) 138% no no
Theoretical Most 984 (246 KB) 144% no no

The very best positive factors could be achieved by breaking the density spec, which will even make the disk incompatible with DOS. Utilizing tracks 36-41 and simply breaking the density spec somewhat will even assist rather a lot. Optimizing the on-disk knowledge buildings solely helps a bit, however within the case of “Minimizing Gaps” retains read-only DOS compatibility.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top