You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lccfmt1.src 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. .page 'lcc.fmt1'
  2. ;
  3. fmtvar =$620 ; put format vars in jump buffer
  4. cnt = fmtvar
  5. num = fmtvar+1
  6. trys = fmtvar+3
  7. tral = fmtvar+4
  8. dtrck= fmtvar+6
  9. remdr= fmtvar+7
  10. sect = fmtvar+8
  11. ;
  12. ;
  13. ;
  14. ;* format routine for lcc
  15. ;*
  16. ;*
  17. ;*
  18. ;
  19. ;
  20. ;
  21. code
  22. formt lda ftnum ; test if formatting begun
  23. bpl l213 ; yes
  24. ;
  25. ldx drive ; no,start up by bumping
  26. lda #$60 ; status=stepping
  27. sta drvst,x
  28. ;
  29. lda #1 ; drive track =1
  30. sta drvtrk,x
  31. sta ftnum ; start on track 1
  32. ;
  33. lda #256-92 ; bump back 45 steps
  34. sta steps
  35. ;
  36. lda dskcnt ; set phase a
  37. and #$ff-$03
  38. sta dskcnt
  39. ;
  40. ;
  41. lda #10 ; 10 errors allowed
  42. sta cnt
  43. ;
  44. lda #<4000 ; first guess at track size
  45. sta num
  46. lda #>4000
  47. sta num+1
  48. ;
  49. jmp end ; back to controller
  50. ;
  51. ;
  52. ;
  53. l213 ldy #0 ; test if on right track number
  54. cmp (hdrpnt),y
  55. beq l214
  56. ;
  57. sta (hdrpnt),y ; goto right track
  58. jmp end
  59. ;
  60. ;
  61. l214 lda dskcnt ; test for write protect
  62. and #$10
  63. bne topp ; its ok
  64. ;
  65. lda #8 ; write protect error
  66. jmp fmterr
  67. ;
  68. topp jsr synclr ; erase track with sync
  69. ;
  70. jsr wrtnum ; write out num syncs
  71. ;
  72. lda #$55 ; write out num non sync
  73. sta data2
  74. ;
  75. jsr wrtnum
  76. ;
  77. jsr kill ; kill write
  78. ;
  79. jsr sync ; find sync
  80. ;
  81. lda #$40 ; set timer mode
  82. ora acr1
  83. sta acr1
  84. ;
  85. lda #100-2 ; set up 100us timer
  86. sta t1ll1 ; cont mode timer
  87. lda #0
  88. sta t1hl1 ; hi latch
  89. sta t1hc1 ; get attention of '22
  90. ;
  91. ;
  92. ;
  93. ldy #0 ; time the sync and nonsync segments
  94. ldx #0
  95. ;
  96. fwait bit dskcnt ; wait for sync
  97. bmi fwait
  98. ;
  99. fwait2 bit dskcnt ; wait for no sync
  100. bpl fwait2
  101. ;
  102. f000 lda t1lc1 ; reset ifr
  103. ;
  104. f001 bit dskcnt ; time nonsync area
  105. bpl f005 ; time until sync found
  106. ;
  107. lda ifr1 ; test for time out
  108. asl a
  109. bpl f001 ; not yet
  110. ;
  111. inx ; .x is lsb
  112. bne f000
  113. iny ; .y is msb
  114. bne f000
  115. ;
  116. lda #tolong ; cant find sync
  117. jmp fmterr
  118. ;
  119. f005 stx t2 ; save time
  120. sty t2+1
  121. ;
  122. ldx #0 ; time sync area
  123. ldy #0
  124. ;
  125. f006 lda t1lc1 ; reset ifr
  126. ;
  127. f007 bit dskcnt ; test for no sync
  128. bmi f009
  129. ;
  130. lda ifr1 ; test for time out
  131. asl a
  132. bpl f007
  133. ;
  134. inx ; count up another 100us
  135. bne f006
  136. iny ; msb
  137. bne f006
  138. ;
  139. lda #tolong ; cant be this long
  140. jmp fmterr
  141. ;
  142. ;
  143. ;* now calc the difference between
  144. ;* sync and nonsync and adjust
  145. ;* num accordingly
  146. ;
  147. f009 sec ; t1-t2
  148. txa
  149. sbc t2
  150. tax
  151. sta t1
  152. ;
  153. tya
  154. sbc t2+1
  155. tay
  156. sta t1+1
  157. ;
  158. bpl f013 ; get abs(t1-t2)
  159. ;
  160. eor #$ff ; make +
  161. tay
  162. txa
  163. eor #$ff
  164. tax
  165. inx
  166. bne f013
  167. iny
  168. ;
  169. f013 tya ; test if abs(t1-t2)<4, that is close enough
  170. bne f014 ; msb must be 0
  171. ;
  172. cpx #4 ; test lsb < 4
  173. bcc count ; its there
  174. ;
  175. f014 asl t1 ; num=num+(diff/2)
  176. rol t1+1
  177. ;
  178. clc
  179. lda t1
  180. adc num
  181. sta num
  182. ;
  183. lda t1+1
  184. adc num+1
  185. sta num+1
  186. ;
  187. jmp topp ; try again sam
  188. ;
  189. ;
  190. count ldx #0 ; now count #bytes in data segment
  191. ldy #0
  192. clv
  193. ;
  194. cnt10 lda dskcnt ; test for sync
  195. bpl cnt20 ; found sync
  196. bvc cnt10 ; test if byte time
  197. ;
  198. clv ; yes, count it
  199. inx
  200. bne cnt10 ; keep counting
  201. iny
  202. bne cnt10 ; to many ?
  203. ;
  204. lda #tomany ; tomany counts
  205. jmp fmterr
  206. ;
  207. cnt20 txa ; #bytes=count*2
  208. asl a
  209. sta tral+1
  210. ;
  211. tya
  212. rol a
  213. sta tral
  214. ;
  215. lda #$ff-$40 ; clear cont mode
  216. and acr1
  217. sta acr1
  218. ;
  219. ;
  220. ;.end