home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT14 / DSKDSR.ARK < prev    next >
Text File  |  2006-10-19  |  12KB  |  444 lines

  1. ?
  2. How to Disk DSR by Mack McCormack
  3.  
  4. This is the second tutorial for the
  5. advanced asembly language programmer.
  6. The subject by request is disk DSR
  7. routines at the disk ROM and direct
  8. access to the controller chip level. In
  9. reviewing the information I have on the
  10. subject I find that the entire scope is
  11. covered in five books for a total of
  12. about 2,000 pages. Obviously, I must
  13. limit my discussion. I'll break this
  14. into several sub-series.  One final
  15. point please, I enjoy sharing the
  16. information I have learned with others
  17. but have heard very little from the
  18. advanced programmers. If you already
  19. know all this information and would
  20. like to see something else tell me or
  21. if you would rather not bother at all
  22. tell me and I'll concentrate on the
  23. novices (that appears to be where the
  24. real nterest is.)
  25.  
  26.      The dik DSR is developed on three
  27. levels:
  28.  
  29.  
  30.      Level 1 - Basic disk functions.
  31. Sector Read/Write, head contro, drive
  32. selections, track formatting an buffer
  33. allocation
  34.  
  35.  
  36.      Level 2 - The "file" concept. Each
  37. file is assessible by its name and an
  38. offset of a 256-byte block relative to
  39. th beginning of the file.
  40.  
  41.  
  42.      Level 3 - Extension to the user
  43. level. Fixed or variable length records
  44. or files.
  45.  
  46.  
  47.      One other level which you won't
  48. find documented is direct access to the
  49. controller chip in the controller card.
  50.  
  51.      I intend to confine my discussion
  52. to level 1 and chip level routines. Due
  53. to length, this tutorial will discuss
  54. sector I/O. Followed in subsequent
  55. tutorials with formatting, direct file
  56. access, and buffer allocation (ie. CALL
  57. FILES).
  58.  
  59.      There are three different
  60. controller chips contained in the three
  61. different controller cards on the market
  62. (TI, CorComp, MYARC). The chips are all
  63. made by Western Digital. They are the WD
  64. 1771, WD 2793, and the WD 1770
  65. respectively. Once again I will limit
  66. this tutorial to the TI controller card
  67. and its chip.  Everything in this
  68. tutorial will pertain to all three cards
  69. except direct access to the controller
  70. chip and its associated commands. If you
  71. own one of these other cards and need
  72. additional information let me know but I
  73. will not release proprietary information
  74. on these two cards.
  75.  
  76.      First lets review the TI
  77. controller card features and ROM. As you
  78. know it can control up to 3 DS/SD
  79. drives. There are 40 tracks per drive
  80. and 9 sectors per track. Each sector is
  81. 256 bytes in length. Track 0 is closest
  82. to the outside and track 39 nearest the
  83. center of the disk. There is a built in
  84. DSR ROM which contains 6 level one
  85. routines which may be executed by
  86. branching to them.  These will
  87. accomplish almost all we need to do
  88. except things like track I/O, Volume
  89. Information Block update and others. To
  90. get at these routines you must access
  91. the Floppy Disk Controller (FDC) chip
  92. directly. To accomplish this we need to
  93. know how the FDC chip accesses the drive
  94. and build from there. These are some of
  95. the features of th WD 1771 chip.
  96. Automatic track seek with verification,
  97. in the read/write mode singl/multiple
  98. sector read/write with automatic sector
  99. seek.  Writes entire track for
  100. formatting.  Programable track to track
  101. step times.  Six registers:
  102.  
  103.      Data shift register - Assembles
  104. serial data from the disk read and
  105. transfers during write.
  106.  
  107.      Data Register - 8 bit holding
  108. register during read/write operations.
  109. During a seek command it contains the
  110. desired track position.
  111.  
  112.      Track Register - 8 bit register
  113. that contains the track number of the
  114. current read/write head position.
  115. Incremented by one as the head steps in
  116. toward track 39 and decremented by one
  117. towards track 00. Contents are compared
  118. with the disk track number in the ID
  119. field during read, write and verify.
  120.  
  121.      Sector Register - 8 bit register
  122. for holding the desired sector
  123. position. Contents compared with the
  124. disk sector ID field during read and
  125. write operations.
  126.  
  127.      Command Register - 8 bit register
  128. for the command to be executed.
  129.  
  130.      Status Register - 8 bit register
  131. to hold drive status.
  132.  
  133.      Much more on these registers as
  134. the tutorials progress.
  135.  
  136.  
  137.      There are eleven commands
  138. available:
  139.  
  140.                      Bits
  141. Type Command         7 6 5 4 3 2 1 0
  142. _______________________________________
  143.  
  144. I    Restore         0 0 0 0 h V r1r0
  145.  
  146. I    Seek            0 0 0 1 h V r1r0
  147.  
  148. I    Step            0 0 1 u h V r1r0
  149.  
  150. I    Step In         0 1 0 u h V r1r0
  151.  
  152. I    Step Out        0 1 1 u h V r1r0
  153.  
  154. II   Read Command    1 0 0 m b E 0 0
  155.  
  156. II   Write Command   1 0 1 m b E a1a2
  157.  
  158. III  Read Address    1 1 0 0 0 E 0 0
  159.  
  160. III  Read Track      1 1 1 0 0 1 0 s
  161.  
  162. III  Write Track     1 1 1 1 0 1 0 0
  163.  
  164. IV   Force Interrupt 1 1 0 1 I3I2I1I4
  165.  
  166.  
  167.  
  168. Plug in the appropriate values by type
  169. command:
  170.  
  171.  
  172. Type I
  173.  
  174. h = Head load flag. 1-beginning. 2-not
  175.     beginning.
  176.  
  177. V =Verify. 1-verify on last track.
  178.     0-no verify.
  179.  
  180. r1r0 = Stepping motor rate. 0 0 - 6ms.
  181.     1 0 - 10ms. 1 1 - 20ms.
  182.  
  183. u = Update flag. 1-update track
  184.     register. 0-no update.
  185.  
  186. Note: Head step times are based on the
  187. 1 MHz clock contained in the controller
  188. card.
  189.  
  190.  
  191. Type II
  192.  
  193. m = multiple record. 0-single.
  194.     1-multiple.
  195.  
  196. b = Block length flag. 1-IBM format
  197.     (256 Byte). Other flags only if
  198.     need to know.
  199. a1a0 = Data Address Mark 00->FB(Data
  200.     Mark)
  201.  
  202.  
  203. Type III
  204.  
  205. s = Synchronize Flag. 0-Single density.
  206.  
  207. Type IV (interrupt condition flags)
  208.  
  209. I0 = 1, not ready to transisition.
  210.  
  211. I1 = 1, Ready to not ready transisition
  212.  
  213. I2 = 1, Index Pulse
  214.  
  215. I3 = 1, Immediate Interrupt
  216.  
  217. E = Enable head load and 10 msec delay
  218.  
  219.     1-delay. 0-head already loaded no
  220.     delay.
  221.  
  222. This all seems confusing now but before
  223. its all over you should have a better
  224. understanding.
  225.  
  226.      Head loading means the read/write
  227. heads are placed in contact with the
  228. disk (the click you hear when the drive
  229. activates) and data may be transfered.
  230. The head stays loaded until a command
  231. is received to unload or until timeout
  232. occurs (2 disk revolutions).
  233.  
  234.      I suppose this is the best place
  235. to cover the disk format. Have you ever
  236. wondered what's in between the data
  237. fields (256 bytes), well here it is.
  238. Stick with this series and well write a
  239. program to directly look at that data
  240. with a track read command.
  241.  
  242.  
  243. Number of Bytes  Whats There
  244.  
  245.      12          Index Gap. >FF
  246.  
  247.       6          Sync >00
  248.  
  249. * Sector begins here. Repeat 9 times *
  250.  
  251.       1          ID Single density >FE
  252.  
  253.       1          Track Address >00->27
  254.  
  255.       1          Side >00
  256.  
  257.       1          Sector Address >00->08
  258.  
  259.       1          Sector Len >01
  260.  
  261.       2          Cycle Redundancy Check
  262.                  >F7
  263.  
  264.      11          Data Separator >FF
  265.  
  266.       6          Sync >00
  267.  
  268.       1          Data Address Mark >FB
  269.  
  270.     256          File Data
  271.  
  272.       2          CRC >F7
  273.  
  274. * Sector ends here *
  275.  
  276.      36          Data Separator >FF
  277.  
  278.     240          End of track fill >FF
  279.  
  280. From this you can see there are 3177
  281. bytes per track but only 2304 are actual
  282. data bytes.
  283.  
  284. So far we've covered the basic
  285. background.  We will discuss what each
  286. of these more as we proceed.
  287.  
  288.      There are three ways to perform a
  289. sector I/O.  You may us the DSRLNK,
  290. access the disk ROM without DSRLNK, or
  291. access the controller chip directly.
  292. Lets examine the first two methods.
  293.  
  294.      Sector I/O is commonly refered to
  295. as subprogram 010. All arguments for
  296. the I/O are passed thru the FAC block
  297. in CPU RAM (>834A). Here's how it maps
  298. out:
  299.  
  300. >834A-4B {Address of actual sector
  301.          accessed when complete.}
  302.  
  303.  
  304. >834C    Disk drive 1,2, or 3.
  305.  
  306.  
  307. >834D    Read/Write 0=write. <>0=read
  308.  
  309.  
  310. >834E-4F VDP Buffer Address (256 byte
  311.          size).
  312.  
  313.  
  314. >8350-51 Sector Number
  315.  
  316.  
  317. Error codes returned at >8350 after
  318. operation. 0=no error. 1=error.
  319.  
  320.  
  321.  
  322. ****************************************
  323. *                                      *
  324. *       SECTOR I/O ROUTINE DEMO        *
  325. *        USING  DSRLNK                 *
  326. *          BY MACK MCCORMICK           *
  327. *                                      *
  328. ****************************************
  329.        DEF  SECTOR
  330.        REF  VMBW,VMBR,DSRLNK
  331.  
  332. PABI   DATA >0110        SUBPROGRAM 010
  333. CPUBUF BSS  256          CPU BUFFER
  334.  
  335.  
  336. SECTOR LI   R0,>F80      ADDRESS OF PAB
  337.        LI   R1,PABI      PAB
  338.        LI   R2,2         TWO BYTES
  339.        BLWP @VMBW        WRITE PAB TO VDP
  340.        LI   R1,>0101
  341.        MOV  R1,@>834C    /DISK DRIVE 1, <>0=READ
  342.        LI   R1,>1000
  343.        MOV  R1,@>834E    /VDP BUFFER START ADDRESS/ AT LEAST 256K
  344.        CLR  R1
  345.        MOV  R1,@>8350    /LOOK AT SECTOR 0
  346.        LI   R1,>F80
  347.        MOV  R1,@>8356    POINT TO THE PAB AT >8356
  348.        BLWP @DSRLNK      ACCESS THE DISK
  349.        DATA >A           USE DISK DSR SUBROUTINES
  350. * NORMALLY YOU WOULD CHECK FOR ERRORS AT >8350 HERE
  351. * YOU COULD ALSO CHECK >834A FOR ACTUAL SECTOR READ
  352.  
  353. *------------------------------*
  354. *  PUT IT UP ON THE SCREEN     *
  355. *-----------------------------*
  356.        LI   R0,>1000     VDP BUFFER ADDRESS
  357.        LI   R1,CPUBUF    CPU BUFFER ADDRESS
  358.        LI   R2,256       MOVE 256 BYTES DOWN
  359.        BLWP @VMBR
  360. *THIS WOULD BE THE PLACE TO MANIPULATE DATA BEFORE WRITING IT BACK UP
  361.        CLR  R0           SIT POSITION 0
  362.        BLWP @VMBW        WRITE UP TO SCREEN IMAGE TABLE
  363. *------------------------------*
  364. *  WRITE BACK OUT TO DISK      *
  365. *------------------------------*
  366.        LI   R1,>0100     /DISK 1, WRITE/
  367.        MOV  R1,@>834C
  368.        BLWP @DSRLNK      WRITE IT BACK OUT
  369.        DATA >A
  370.        JMP  $            YOU WOULD EXIT THE PROGRAM HERE
  371.        END
  372. * YOU CAN SEE HOW EASY IT IS TO WRITE A SECTOR COPIER JUST FROM THIS SHORT CODE
  373. * ADD A FEW WHISTLES AND BELLS AND YOU HAVE A FIRST CLASS PRODUCT
  374.  
  375.  
  376.  
  377. ****************************************
  378. *            2D EXAMPLE                *
  379. *   SECTOR I/O ROUTINE DEMO USING      *
  380. *        DIRECT ROM ACCESS             *
  381. *   ACCOMPANIES SECTOR I/O TUTORIAL    *
  382. *                                      *
  383. ****************************************
  384.        DEF  SECTOR
  385.        REF  VMBW,VMBR,GPLWS
  386.  
  387. SUBR   DATA >0110        SUBPROGRAM 010
  388. CPUBUF BSS  256          CPU BUFFER
  389. MYREG  BSS  >20          MY WORKSPACE
  390.  
  391.  
  392. SECTOR LWPI GPLWS
  393.  
  394.        LI   R1,>0101
  395.        MOV  R1,@>834C    /DISK DRIVE 1, <>0=READ
  396.        LI   R1,>1000
  397.        MOV  R1,@>834E    /VDP BUFFER START ADDRESS/ AT LEAST 256K
  398.        CLR  R1
  399.        MOV  R1,@>8350    /LOOK AT SECTOR 0
  400.        LI   R12,>1100    SET CRU REGISTER TO BASE ADDRESS OF >1100 DSK DSR ROM
  401.        SBO  0            PAGE INTHE DISK DSR ROM TO >4000
  402.  
  403. * Of course you could eliminate the next five instructions and manually scan the
  404. * DSR ROM for the word which immediately proceeds >0110 and loaded R9 with that
  405. * value which is >56DC in the case of the CorComp card and BL directly to it.
  406. * I scanned the link table so this program could be used with other DSR
  407. * subroutines and with all controller cards.
  408.        LI   R9,>4000     BEGINNING OF DISK DSR ROM
  409. NEXT   C    *R9+,@SUBR   SEARCH LINK TABLE FOR ENTRY POINT
  410.        JNE  NEXT
  411.        AI   R9,-4        SUBTRACT 4 FOR ENTRY POINT
  412.        MOV  *R9,R9       GET THE ENTRY POINT ADDRESS
  413.        BL   *R9          BRANCH TO THE ROUTINE
  414.  
  415. * NORMALLY YOU WOULD CHECK FOR ERRORS AT >8350 HERE
  416. * YOU COULD ALSO CHECK >834A FOR ACTUAL SECTOR READ
  417.  
  418. *------------------------------*
  419. *  PUT IT UP ON THE SCREEN     *
  420. *------------------------------*
  421.        NOP               NOP IS REQUIRED HERE BECAUSE THE DSR ROUTINE INCT's THE
  422. *                        RT ADDRESS
  423.        LI   R0,>1000     VDP BUFFER ADDRESS
  424.        LI   R1,CPUBUF    CPU BUFFER ADDRESS
  425.        LI   R2,256       MOVE 256 BYTES DOWN
  426.        BLWP @VMBR
  427. *THIS WOULD BE THE PLACE TO MANIPULATE DATA BEFORE WRITING IT BACK UP
  428.        CLR  R0           SIT POSITION 0
  429.        BLWP @VMBW        WRITE UP TO SCREEN IMAGE TABLE
  430. *-----------------------------*
  431. *  WRITE BACK OUT TO DISK      *
  432. *------------------------------*
  433.        LI   R1,>0100     /DISK 1, WRITE/
  434.        MOV  R1,@>834C
  435.        BL   *R9
  436.        SBZ  0            PAGE OUT DISK DSR
  437.        JMP  $            YOU WOULD EXIT THE PROGRAM HERE
  438.        END
  439.  
  440.  
  441. Download complete.  Turn off Capture File.
  442.  
  443.  
  444.