{"id":1070,"date":"2019-04-19T00:48:26","date_gmt":"2019-04-19T07:48:26","guid":{"rendered":"https:\/\/www.pagetable.com\/?p=1070"},"modified":"2019-04-19T00:48:26","modified_gmt":"2019-04-19T07:48:26","slug":"visualizing-commodore-1541-disk-contents","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=1070","title":{"rendered":"Visualizing Commodore 1541 Disk Contents"},"content":{"rendered":"<p><code>G64<\/code> files are C64\/1541 disk images that contain all bits as they are physically laid out on the 5\u00bc-inch floppy disk. Let&rsquo;s visualize them!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/input64.gif\" height=\"600\" width=\"600\" alt=\"\" \/><\/p>\n<p>This animation shows 28 regular Commodore 1541 disks.<\/p>\n<ul>\n<li>A disk contains 35 tracks, counting from the outside to the inside.<\/li>\n<li>Every track starts at the bottom and is read counter-clockwise<sup id=\"fnref:1\"><a href=\"#fn:1\" rel=\"footnote\">1<\/a><\/sup>.<\/li>\n<li>Green represents the data. Darker areas have more 0-bits.<\/li>\n<li>Red represents a longer sequence of 1-bits.<\/li>\n<li>Blue represents a longer sequence of 0-bits.<\/li>\n<\/ul>\n<h2 id=\"SYNC,-Sector-Headers-and-Data\">SYNC, Sector Headers and Data<\/h2>\n<p>Track 1 contains 21 sectors. Every sector is prefixed by two small red areas: These are the SYNC marks. The first SYNC marks the sector header, the second one the sector data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/sector.png\" height=\"140\" width=\"600\" alt=\"\" \/><\/p>\n<h2 id=\"Speed-Zones\">Speed Zones<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/sector_width.png\" height=\"326\" width=\"231\" alt=\"\" \/><\/p>\n<p>There are four different speed zones. The first 17 tracks (zone 3) are written at the highest speed: A sector occupies an angle of about 17 degrees. But on the last 5 tracks (zone 0), a sector occupies an angle of about 21 degrees. Yet the linear length of the sectors is about the same \u2013\u00a0that&rsquo;s the idea of the different speeds. Higher tracks are shorter, and they contain fewer sectors.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center;\"> Track   <\/th>\n<th style=\"text-align:center;\"> # Sectors <\/th>\n<th style=\"text-align:center;\"> Speed Zone <\/th>\n<th style=\"text-align:center;\"> \u00b5s\/Byte <\/th>\n<th style=\"text-align:center;\"> Raw Kbit\/Track <\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:center;\">  1 &#8211; 17 <\/td>\n<td style=\"text-align:center;\"> 21        <\/td>\n<td style=\"text-align:center;\"> 3          <\/td>\n<td style=\"text-align:center;\"> 26      <\/td>\n<td style=\"text-align:center;\"> 60.0           <\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center;\"> 18 &#8211; 24 <\/td>\n<td style=\"text-align:center;\"> 19        <\/td>\n<td style=\"text-align:center;\"> 2          <\/td>\n<td style=\"text-align:center;\"> 28      <\/td>\n<td style=\"text-align:center;\"> 55.8           <\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center;\"> 25 &#8211; 30 <\/td>\n<td style=\"text-align:center;\"> 18        <\/td>\n<td style=\"text-align:center;\"> 1          <\/td>\n<td style=\"text-align:center;\"> 30      <\/td>\n<td style=\"text-align:center;\"> 52.1           <\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center;\"> 31 &#8211; 35 <\/td>\n<td style=\"text-align:center;\"> 17        <\/td>\n<td style=\"text-align:center;\"> 0          <\/td>\n<td style=\"text-align:center;\"> 32      <\/td>\n<td style=\"text-align:center;\"> 48.8           <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"Tail-Gaps\">Tail Gaps<\/h2>\n<p>Towards the end of the tracks, there is some unused space. You can see this in the darker and more consistent shading in the image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/track_ends.png\" height=\"346\" width=\"280\" alt=\"\" \/><\/p>\n<p>About 5 to 10 degrees towards the end of each track are unused, because the space would not fit another sector. Speed zone 2 though looks like it could fit another sector, and in fact, DOS version 1 of the 2040 formatted tracks 18-24 with 20 sectors instead of 19, but this was too tight: If the motor speed was a little off, the last sector would overwrite sector 0.<\/p>\n<p>When a disk is formatted, the pattern of 0x55 (alternating 0 and 1 bits) is written into this area. As long as there are no valid sector headers in the unused space, it can contain anything. There are formatting programs that fill it with all SYNC marks instead:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/track_ends_3.png\" height=\"346\" width=\"280\" alt=\"\" \/><\/p>\n<p>On some disks, the empty area is about the same size for all tracks. <a href=\"https:\/\/csdb.dk\/release\/?id=90210\">Some formatting programs<\/a> add extra gaps between the sectors to minimize the tail gap:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/track_ends_2.png\" height=\"346\" width=\"280\" alt=\"\" \/><\/p>\n<h2 id=\"40-Tracks\">40 Tracks<\/h2>\n<p>The original 5\u00bc-inch &ldquo;minifloppy&rdquo; from 1976<sup id=\"fnref:2\"><a href=\"#fn:2\" rel=\"footnote\">2<\/a><\/sup> only supported 35 tracks, the 40 track disks <a href=\"https:\/\/en.wikipedia.org\/wiki\/History_of_the_floppy_disk\">came a little later<\/a>. For compatibility with existing disks<sup id=\"fnref:3\"><a href=\"#fn:3\" rel=\"footnote\">3<\/a><\/sup>, all 48 tpi Commodore 5\u00bc-inch drives only used 35 tracks, but some users and lots of games used 40 tracks by just extending the format (usually with the slowest speed zone) by 5 tracks.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/40tracks.gif\" height=\"600\" width=\"600\" alt=\"\" \/><\/p>\n<p>In this case, the sectors between tracks 31-35 and 36-40 are not visually aligned, because the 5 extra tracks were presumably formatted independently with a different program which used slightly different sector gaps.<\/p>\n<p>There is no specification for the format of the extra tracks. Here is an example that uses speed zone 1 (the second-highest one) with 18 sectors instead of 17:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/40tracks_2.gif\" height=\"600\" width=\"600\" alt=\"\" \/><\/p>\n<h2 id=\"Custom-Formats\">Custom Formats<\/h2>\n<p>Some games used completely custom formats:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"docs\/visualize_1541\/custom.png\" height=\"600\" width=\"600\" alt=\"\" \/><\/p>\n<p>This is the game &ldquo;Cosmic Relief&rdquo;, which seems to store 11 or 12 sectors per track, with sectors that are about 1.5 the size of regular sectors, and potentially a different encoding. Tracks 17 and 18 have to be in the standard format though: Track 18 contains the directory, and track 17 contains the loader for the custom format, in this case.<\/p>\n<p>Custom formats were usually used for copy protection. The 1541 does not have enough RAM to store the raw bitstream of one track, and the Commodore Serial Bus does not have the data rate to transfer it to the computer in real time. Therefore the only way to copy a disk is sector-by-sector, which only works if the sectors are in a format the copy program understands. <a href=\"https:\/\/www.pagetable.com\/?p=656\">Copy programs that supported parallel cables<\/a> defeated most of these protection schemes.<\/p>\n<h2 id=\"Create-Your-Own-Visualization\">Create Your Own Visualization<\/h2>\n<p>There are lots of copy protection tricks and custom formats that are interesting to look at this way. I have created a Python tool to create these image files from <code>G64<\/code> files:<\/p>\n<p><a href=\"https:\/\/github.com\/mist64\/visualize_1541\">https:\/\/github.com\/mist64\/visualize_1541<\/a><\/p>\n<p>Plase share your own results!<\/p>\n<div class=\"footnotes\">\n<hr\/>\n<ol>\n<li id=\"fn:1\">\n<p>From the drive head&rsquo;s point of view, a track is an infinite but repeating string of bits with no defined start. Many recording formats, including the MFM-based one of PC disks, used the index hole for a defined start point. The 1541 disk format does not make use of the index hole, so there is no defined track alignment: Any track can be arbitrarily rotated compared to the other tracks. <code>nibconvert<\/code> from the <a href=\"https:\/\/c64preservation.com\/nibtools\">nibtools<\/a> package by default writes <code>G64<\/code> files aligned to the longest gap, which will usually align to sector 0.<a href=\"#fnref:1\" rev=\"footnote\">&#8617;<\/a><\/p>\n<\/li>\n<li id=\"fn:2\">\n<p>and the SA-400\/SA-390 mechanism used in Commodore&rsquo;s dirst devices<a href=\"#fnref:2\" rev=\"footnote\">&#8617;<\/a><\/p>\n<\/li>\n<li id=\"fn:3\">\n<p>Another reason might have been that the extra tracks would have needed another, slower speed zone for the data to be safe, so it wasn&rsquo;t as easy as adding 40 track support to the firmware.<a href=\"#fnref:3\" rev=\"footnote\">&#8617;<\/a><\/p>\n<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>G64 files are C64\/1541 disk images that contain all bits as they are physically laid out on the 5\u00bc-inch floppy disk. Let&rsquo;s visualize them! This animation shows 28 regular Commodore 1541 disks. A disk contains 35 tracks, counting from the outside to the inside. Every track starts at the bottom and is read counter-clockwise1. Green &#8230; <a title=\"Visualizing Commodore 1541 Disk Contents\" class=\"read-more\" href=\"https:\/\/www.pagetable.com\/?p=1070\" aria-label=\"Read more about Visualizing Commodore 1541 Disk Contents\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8,13],"tags":[],"class_list":["post-1070","post","type-post","status-publish","format-standard","hentry","category-archeology","category-commodore","category-floppy-disks"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1070"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}