{"id":1782,"date":"2017-12-10T02:15:10","date_gmt":"2017-12-10T02:15:10","guid":{"rendered":"http:\/\/www.sydneysmith.com\/wordpress\/?p=1782"},"modified":"2017-12-10T02:15:10","modified_gmt":"2017-12-10T02:15:10","slug":"the-cromix-boot-sector","status":"publish","type":"post","link":"https:\/\/www.sydneysmith.com\/wordpress\/1782\/the-cromix-boot-sector\/","title":{"rendered":"The Cromix Boot Sector"},"content":{"rendered":"<p>Here&#8217;s what the Cromix boot sector (for Cromix 11.27) looks like and why &#8230;<!--more--><\/p>\n<p><code><\/p>\n<pre>\r\n                     Display of File BOOT1.BIN\r\n\r\n000000: 3E 01 D3 40 38 04 97 08  16 31 21 00 01 01 0F 02 >..@8....1!.....\r\n000010: 3E 7F D3 04 7A D3 34 79  D3 30 97 3D 20 FD DB 34 >...z.4y.0.= ..4\r\n000020: 1F 30 FB DB 30 E6 98 20  D7 78 D3 32 7A F6 80 D3 .0..0.. .x.2z...\r\n000030: 34 0E 33 3E 9C D3 30 DB  34 1F 38 05 ED A2 C3 B7 4.3>..0.4.8.....\r\n000040: 00 DB 30 CB 67 28 B9 C3  00 01 00 00 00 00 00 00 ..0.g(..........\r\n000050: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................\r\n000060: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 ................\r\n000070: 00 00 00 00 00 00 00 00  43 4C 44 53 44 44 E5 E5 ........CLDSDD..\r\n\r\n<\/pre>\n<p><\/code><br \/>\nYou can see the disk type label at bytes 120-127 (0x78..0x7F). It is a Cromix (&#8220;C&#8221;), Large (&#8220;L&#8221; aka 8 inch), double-sided (&#8220;DS&#8221;), double-density (&#8220;DD&#8221;) disk. If this isn&#8217;t present and correct then the boot sequence won&#8217;t work and parts of the OS and\/or utilities will get things wrong. That doesn&#8217;t apply to early versions of CDOS or to CP\/M but it does apply to CDOS 2.58 and Cromix.<\/p>\n<p>It would be elegant if just changing those few bytes changed the behaviour of the boot sector so you could use the same program on all boot sectors; but it isn&#8217;t quite that good. Just looking above, you can see much of the sector is zeros &#8211; so there isn&#8217;t a lot of bytes for &#8220;smarts&#8221;. Despite that, it does have some tied to the &#8220;DS&#8221; and &#8220;DD&#8221; bits. Where it fails to adapt is if you copy (or WRTSYS) between disk sizes (5->8 or 8->5).<\/p>\n<p>Here&#8217;s what the program does:<br \/>\n<code><\/p>\n<pre>\r\n                 ORG 0080H\r\n0080 3e 01       ld a,0x01      ; disable RDOS\r\n0082 d3 40       out (0x40),a\r\n\r\n0084 38 04       jr c,0x008a    ; if CY use supplied\r\n0086 97          sub a          ; default disk=0\r\n0087 08          ex af,af'      ; save for later\r\n0088 16 31       ld d,0x31      ; default cmd=motor+8\"+A \r\n\r\n008a 21 00 01    ld hl,0x0100   ; we're going to load to 100H\r\n008d 01 0f 02    ld bc,0x020f   ; B=sector 2, C=restore\r\n0090 3e 7f       ld a,0x7f      ; select side 0\r\n0092 d3 04       out (0x04),a\r\n\r\n0094 7a          ld a,d         ; 31=motor+8\"+A (or supplied)\r\n0095 d3 34       out (0x34),a\r\n0097 79          ld a,c         ; cmd. 0F=restore+verify+slow\r\n0098 d3 30       out (0x30),a\r\n\r\n009a 97          sub a          ; wait 256\r\n009b 3d          dec a\r\n009c 20 fd       jr nz,0x009b\r\n\r\n009e db 34       in a,(0x34)    ; wait for end of job, EOJ\r\n00a0 1f          rra\r\n00a1 30 fb       jr nc,0x009e\r\n\r\n00a3 db 30       in a,(0x30)    ; check result\r\n00a5 e6 98       and 0x98       ; notRdy+notFound+busy\r\n00a7 20 d7       jr nz,0x0080   ; problem. try again. CY=0 btw\r\n\r\n00a9 78          ld a,b         ; set sector (2 at start)\r\n00aa d3 32       out (0x32),a\r\n\r\n00ac 7a          ld a,d         ; motor+8\"+A (or supplied)\r\n00ad f6 80       or 0x80        ; turn on autowait\r\n00af d3 34       out (0x34),a\r\n\r\n00b1 0e 33       ld c,0x33      ; 33H is the disk data port\r\n00b3 3e 9c       ld a,0x9c      ; read records, head load\r\n00b5 d3 30       out (0x30),a   ; send the cmd\r\n\r\n00b7 db 34       in a,(0x34)    ; check for EOJ\r\n00b9 1f          rra\r\n00ba 38 05       jr c,0x00c1    ; read all sectors to end of track\r\n00bc ed a2       ini            ; read bytes to HL...\r\n00be c3 b7 00    jp 0x00b7      ; loop until EOJ\r\n\r\n00c1 db 30       in a,(0x30)    ; check result\r\n00c3 cb 67       bit 4,a        ; the \"not found\" bit\r\n00c5 28 b9       jr z,0x0080    ; error. try again\r\n00c7 c3 00 01    jp 0x0100      ; all ok. run what we loaded.\r\n00ca 00          nop\r\n00cb 00          nop\r\n...\r\n00f6 00          nop\r\n00f7 00          nop\r\n00f8 43 4C 44    DB 'CLDSDD',0xe5,0xe5\r\n00fb 53 44 44\r\n00fe e5 e5\r\n<\/pre>\n<p><\/code><br \/>\nThere&#8217;s a number of interesting things here:<br \/>\n&#8211; it only loads the rest of track 0 (CP\/M and CDOS use tracks 0 and 1 for 8&#8243; and 0-2 for 5&#8243;)<br \/>\n&#8211; it loads to 100H; instead of somewhere high<br \/>\n&#8211; despite my statement earlier, it doesn&#8217;t care about &#8220;CLDSDD&#8221;. (Other things do)<br \/>\n&#8211; it depends of the CY flag at startup (and A and D)<\/p>\n<p>Cromix is loading into bank 0 of memory. It has all of bank 0 to itself, so it can load anywhere it likes. In CP\/M and CDOS, 100H is reserved for user programs.<\/p>\n<p>I don&#8217;t have (and haven&#8217;t created) a disassembly of RDOS0312; but there is one for RDOS0252. It contains:<br \/>\n<code><\/p>\n<pre>\r\nC0FA:\tCALL\tckesc\t; look for escape\r\n\tCALL\tsetsel\r\n\tLD\tD,A\r\n\tLD\tA,(77H)\r\n\tEX\tAF,AF'\r\n\tCALL\tptfol\r\n\tDB      CR,'Standby',CR+msbon\r\n\tSCF\r\n\tJP\t80H\r\n<\/pre>\n<p><\/code><br \/>\nYou can see the value in D getting created (setsel), a value being saved in A&#8217;, and SCF just before running the boot sector. &#8220;ptfol&#8221; prints the following bytes (until one with the most significant bit set, msbon=0x80). CRs get printed as CR, LF. &#8220;setsel&#8221; builds a bit combination based on whether you&#8217;re booting from an 8&#8243; or 5&#8243; drive, which drive it is, and whether it is single density or double density. All those smarts are in RDOS (probably just based on what you typed in as the RDOS command\/s or defaults).<\/p>\n<p>For my purposes, to boot without RDOS, I patch the boot.hex program I use with z80sim to &#8220;NOP-out&#8221; the &#8220;JR C, 008AH&#8221; line. This means it boots from a single density, 8&#8243; track 0 in drivea.dsk. The image on the disk is unchanged so if you boot a disk within cromix &#8211; the SCF override still works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s what the Cromix boot sector (for Cromix 11.27) looks like and why &#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,59],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1782"}],"collection":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1782"}],"version-history":[{"count":3,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1782\/revisions"}],"predecessor-version":[{"id":1785,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/posts\/1782\/revisions\/1785"}],"wp:attachment":[{"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sydneysmith.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}