home *** CD-ROM | disk | FTP | other *** search
/ CBM Funet Archive / cbm-funet-archive-2003.iso / cbm / documents / projects / drives / 64hdproj.sfx / c2sec.src next >
Encoding:
Text File  |  1990-02-12  |  8.1 KB  |  342 lines

  1. ;bput"c2sec.src
  2. ;rput"c2sec.src
  3. ;
  4. ;+++++++++++++++++++++++++++++++++
  5. ;+ sector, sat, and disk address +
  6. ;+ routines.                     +
  7. ;+ entry points:                 +
  8. ;+* sec2cyldcb - convert secnum to   +
  9. ;+    msbsec, lsb, head format.  +
  10. ;+* sec2cyldcb1 - convert cylmsb and  +
  11. ;+    sector number to msbsec    +
  12. ;+    format with output in      +
  13. ;+    cylmsb.                    +
  14. ;+* sectr2cylindr - convert secnum to   +
  15. ;+    cylmsb, cyllsb, head,      +
  16. ;+    sector.                    +
  17. ;+* sat2sector  - convert satsec,     +
  18. ;+    satbyt, and satbit to a    +
  19. ;+    sector number.             +
  20. ;+* sector2sat - convert secnum to   +
  21. ;+    sat entry.  input is x -   +
  22. ;+    hi byte of secnum, a - mid +
  23. ;+    byte of secnum, and y - low+
  24. ;+    byte of secnum.            +
  25. ;+* cyl2sectordcb - convert dcb format  +
  26. ;+    disk address to secnum.    +
  27. ;+    input: a - drive-head      +
  28. ;+           x - msb cylinder    +
  29. ;+           y - lsb cylinder    +
  30. ;+* cylinder2sectr - convert head, cyllsb+
  31. ;+    cylmsb, & sector to secnum.+
  32. ;+++++++++++++++++++++++++++++++++
  33. ;
  34. ;+++++++++++++++++++++++++++++++++
  35. ;+the following areas are used by+
  36. ;+ these subroutines.            +
  37. ;+-------------------------------+
  38. ;+ shifts 1 byte work            +
  39. ;+ worka  3 byte work area       +
  40. ;+ workb  2 byte work area       +
  41. ;+ workc  2 byte work area       +
  42. ;+ secnum 3 byte sector number in+
  43. ;+          hi, med, lo format   +
  44. ;+ satsec 1 byte sat sector      +
  45. ;+ satbyt 2 byte byte offset in  +
  46. ;+          sat sector. hi, lo   +
  47. ;+ satbit 1 byte bit mask of sat +
  48. ;+          sector byte          +
  49. ;+ cylmsb 1 byte msb of cylinder +
  50. ;+ cyllsb 1 byte lsb of cylinder +
  51. ;+ head   1 byte head number     +
  52. ;+ sector 1 byte sector number   +
  53. ;+ sectrk 1 byte number of       +
  54. ;+          sectors per track    +
  55. ;+ seccyl 1 byte number of       +
  56. ;+          sectors per cylinder +
  57. ;+++++++++++++++++++++++++++++++++
  58. ;
  59. ;
  60. ;+++++++++++++++++++++++++++++++++
  61. ;+ convert relative sector number+
  62. ;+ to cylinder, head and sector. +
  63. ;+                               +
  64. ;+ input - field secnum which    +
  65. ;+  contains the relative sector.+
  66. ;+                               +
  67. ;+ output - fields head, cyllsb, +
  68. ;+  cylmsb, and sector filled and+
  69. ;+  a - head number              +
  70. ;+  y - cylinder lsb             +
  71. ;+  x - sector and cyl msb       +
  72. ;+++++++++++++++++++++++++++++++++
  73. ;
  74. ;
  75. sec2cyldcb jsr sectr2cylindr ;go convert
  76. sec2cyldcb1 ldx #6 ;put chr in dcb form
  77.  lda cylmsb
  78. shiftmsbleft asl a
  79.  dex
  80.  bne shiftmsbleft
  81.  ora sector
  82.  sta cylmsb
  83.  rts ;tis done
  84. ;
  85. sectr2cylindr lda #0 ;zero work, etc.
  86.  sta workb
  87.  sta workb+1
  88.  sta workc+1
  89.  sta head
  90.  sta cylmsb
  91.  sta cyllsb
  92.  ldx #2 ;move secnum to work a
  93. movesecnum2a lda secnum,x
  94.  sta worka,x
  95.  dex
  96.  bpl movesecnum2a
  97.  jsr defset ;get ptr to parmtab
  98.  lda ptscyl,x ;get sector per cyl
  99.  sta workc ;times hex 100
  100.  inc workb ;make counter 256
  101.  ldx #9 ;prime count down
  102. calccylinder jsr dividesector ;go subtract
  103.  bcc updateoperands
  104.  lda workb+1
  105.  clc
  106.  adc cyllsb
  107.  sta cyllsb
  108.  lda workb
  109.  adc cylmsb
  110.  sta cylmsb
  111.  jmp calccylinder ;go see if more
  112. ;
  113. updateoperands lsr workb ;adjust adder
  114.  ror workb+1
  115.  lsr workc ;shift divisor
  116.  ror workc+1
  117.  dex
  118.  bne calccylinder ;try some more
  119.  lda #17 ;get num sec per trk
  120.  sta workc+1 ;in subtractor
  121. calculatehead jsr dividesector ;go subtract
  122.  bcc savesectornum ;go if done
  123.  inc head
  124.  bne calculatehead
  125. savesectornum lda worka+2 ;get sector num
  126.  sta sector
  127.  rts
  128. ;
  129. ;
  130. ;+++++++++++++++++++++++++++++++++
  131. ;+ subtract workc from work a if +
  132. ;+ worka >= workc                +
  133. ;+ return carry set   for didit. +
  134. ;+ return carry clear for small. +
  135. ;+++++++++++++++++++++++++++++++++
  136. ;
  137. dividesector lda worka ;check hi sec byt
  138.  bne subtractem
  139.  lda worka+1 ;check second byte
  140.  cmp workc ;for <=
  141.  bcc dividereturn ;go if too small
  142.  bne subtractem ;go not equal
  143.  lda worka+2 ;check low byte
  144.  cmp workc+1
  145.  bcc dividereturn ;too small go on
  146. subtractem lda worka+2 ;subtract
  147.  sec
  148.  sbc workc+1
  149.  sta worka+2
  150.  lda worka+1
  151.  sbc workc
  152.  sta worka+1
  153.  lda worka
  154.  sbc #0
  155.  sta worka
  156.  sec
  157. dividereturn rts
  158. ;
  159. ;+++++++++++++++++++++++++++++++++
  160. ;+ convert satsec, satbyt, and   +
  161. ;+ satbit to relative sector #.  +
  162. ;+                               +
  163. ;+ input - fields satsec, satbyt +
  164. ;+    and satbit.                +
  165. ;+                               +
  166. ;+ output- relative sector in    +
  167. ;+ secnum.                       +
  168. ;+++++++++++++++++++++++++++++++++
  169. ;
  170. sat2sector lda #0 ;init sector num
  171.  sta secnum
  172.  ldx #4 ;number to shift
  173.  lda satsec ;get field
  174. shiftsatseclf asl a
  175.  rol secnum
  176.  dex
  177.  bne shiftsatseclf
  178.  sta secnum+1
  179.  lda satbyt ;get hi
  180.  sta worka
  181.  ldx #3 ;multiply by 8
  182.  lda satbyt+1 ;now lo byte offset
  183. shiftsatbytlf asl a
  184.  rol worka
  185.  dex
  186.  bne shiftsatbytlf
  187.  sta secnum+2
  188.  clc
  189.  lda worka ;add hi byte
  190.  adc secnum+1
  191.  sta secnum+1
  192.  lda satbit ;get the bit number
  193.  ldx #0
  194. shiftsatbitlf asl a ;shift till it goes
  195.  bcs addtosecnum ;out
  196.  inx
  197.  bne shiftsatbitlf
  198. addtosecnum txa ;set up for add
  199.  jmp addbyte2secnum
  200. ;clc
  201. ;adc secnum+2 ;add to total
  202. ;sta secnum+2
  203. ;bcc sat2secreturn
  204. ;inc secnum+1 ;else add overflow
  205. ;bne sat2secreturn
  206. ;inc secnum
  207. ;sat2secreturn rts ;return
  208. ;
  209. ;+++++++++++++++++++++++++++++++++
  210. ;+ convert sector number to sat  +
  211. ;+ entry.                        +
  212. ;+                               +
  213. ;+ input: a-middle byte of secnum+
  214. ;+        x-hi byte of secnum    +
  215. ;+        y-lo byte of secnum    +
  216. ;+                               +
  217. ;+                               +
  218. ;+ output: sat sector, byte, and +
  219. ;+         bit in byte.          +
  220. ;+ satsec - sector number of sate+
  221. ;+ satbyt - byte of sate         +
  222. ;+ satbit - bit of byte          +
  223. ;+++++++++++++++++++++++++++++++++
  224. ;
  225. sector2sat sta satsec ;a has middle byte
  226.  and #$0f ;isolate low 12 bits for  
  227.  sta satbyt ;for satbyt
  228.  txa ;get hi byte of secnum
  229.  ldx #4 ;need to shift for satsec
  230. divideby4096 lsr a ;satsec = int(secnum/4096)
  231.  ror satsec
  232.  dex
  233.  bne divideby4096 ;do all 4 shifts
  234.  tya ;get low byte of secnum
  235.  sta satbyt+1 ;put in offset
  236.  and #$07 ;isolate the bit number
  237.  tax ;now put bit in its place
  238.  lda #$80 ;prime bit
  239. shiftsec dex ;check if thru
  240.  bmi savesatbit
  241.  lsr a
  242.  bne shiftsec
  243. savesatbit sta satbit ;now have bit
  244.  ldx #3 ;now divide byte offset by 8
  245. dividsatbytby8 lsr satbyt
  246.  ror satbyt+1
  247.  dex
  248.  bne dividsatbytby8
  249.  rts
  250. ;
  251. ;+++++++++++++++++++++++++++++++++
  252. ;+ convert cylinder, head, sector+
  253. ;+ to sector number.             +
  254. ;+                               +
  255. ;+ there are 2 entries to this   +
  256. ;+ subroutine.                   +
  257. ;+ cyl2sectordcb - input is as follows  +
  258. ;+     a - drive-head byte       +
  259. ;+     x - msb-sector            +
  260. ;+     y - lsb cylinder          +
  261. ;+                               +
  262. ;+ cylinder2sectr - the following fields +
  263. ;+     must be initialized before+
  264. ;+     calling this entry.       +
  265. ;+  head, sector, cyllsb, cylmsb +
  266. ;+                               +
  267. ;+++++++++++++++++++++++++++++++++
  268. ;
  269. cyl2sectordcb sty cyllsb ;put in lsb of cylinder
  270.  and #$0f ;isolate just the head
  271.  sta head
  272.  txa ;get msb and sector
  273.  and #$1f ;isolate sector number
  274.  sta sector
  275.  txa ;now handle msb of cylinder
  276.  ldx #6 ;number of shifts
  277. shiftdownmsb lsr a
  278.  dex
  279.  bne shiftdownmsb
  280.  sta cylmsb ;put it away
  281. ;
  282. cylinder2sectr lda #0 ;clear the result field
  283.  sta secnum
  284.  sta secnum+1
  285.  sta secnum+2
  286.  ldy #8 ;prime shifts
  287.  jsr defset ;get parm tab offset
  288.  lda ptscyl,x ;and sector per cyl
  289.  sta workb
  290. muliplycylindr = * ;clear carry
  291.  lda cyllsb ;get low cyl number
  292.  sta worka+2
  293.  lda cylmsb ;get high cyl number
  294.  sta worka+1
  295.  lda #0 ;clear next work
  296.  sta worka
  297.  dey
  298.  asl workb ;shift sec/cyl
  299.  bcc anymoreshifts
  300.  tya ;move to x
  301.  tax
  302.  beq addtosecnum2
  303.  clc
  304. shiftworkal asl worka+2
  305.  rol worka+1
  306.  rol worka
  307.  dex
  308.  bne shiftworkal
  309. addtosecnum2 ldx #2
  310.  clc
  311. addtosecnumlp lda secnum,x
  312.  adc worka,x
  313.  sta secnum,x
  314.  dex
  315.  bpl addtosecnumlp
  316. anymoreshifts cpy #0 ;any more?
  317.  bne muliplycylindr
  318. ;+ add in head x sector per trk
  319.  ldx head ;get counter
  320.  beq addsect2secnum ;go if head 0
  321. addheadxsectrk lda #17 ;get sectors per track
  322.  jsr addbyte2secnum ;go add to total
  323.  dex
  324.  bne addheadxsectrk
  325. ;+ add the sector
  326. addsect2secnum lda sector
  327.  jsr addbyte2secnum
  328.  lda secnum
  329.  ldx secnum+1
  330.  ldy secnum+2
  331.  rts
  332. addbyte2secnum clc
  333.  adc secnum+2
  334.  sta secnum+2
  335.  bcc addalldone
  336.  inc secnum+1
  337.  bne addalldone
  338.  inc secnum
  339. addalldone = *
  340.  rts
  341. ;
  342. .end c2sec
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.