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.

tstfnd.src 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. .page ' tstfnd '
  2. ; next track & sector
  3. ; returns next available track & sector
  4. ; given current t & s
  5. ;
  6. ; allocation is from track 18
  7. ; towards 1 & 35, by full tracks
  8. nxtts
  9. jsr gethdr
  10. lda #3
  11. sta temp
  12. lda #1 ; set no write bam
  13. ora wbam
  14. sta wbam
  15. nxtds
  16. nxt1
  17. lda temp
  18. pha ; save temp
  19. jsr setbam
  20. pla
  21. sta temp ; restore temp
  22. lda (bmpnt),y
  23. bne fndnxt
  24. lda track
  25. cmp dirtrk
  26. beq nxterr
  27. bcc nxt2
  28. inc track
  29. lda track
  30. cmp maxtrk
  31. bne nxt1
  32. ldx dirtrk
  33. dex
  34. stx track
  35. lda #0
  36. sta sector
  37. dec temp
  38. bne nxt1
  39. nxterr lda #dskful
  40. jsr cmderr
  41. nxt2 dec track
  42. bne nxt1
  43. ldx dirtrk
  44. inx
  45. stx track
  46. lda #0
  47. sta sector
  48. dec temp
  49. bne nxt1
  50. beq nxterr
  51. ;
  52. ; find the next optimum sector
  53. ; next sector=current sector+n
  54. ;
  55. fndnxt lda sector
  56. clc
  57. adc secinc
  58. sta sector
  59. lda track
  60. jsr maxsec
  61. sta lstsec
  62. sta cmd
  63. cmp sector
  64. bcs fndn0
  65. sec
  66. lda sector
  67. sbc lstsec
  68. sta sector
  69. beq fndn0
  70. dec sector
  71. fndn0
  72. jsr getsec
  73. beq fndn2
  74. fndn1
  75. jmp wused
  76. fndn2
  77. lda #0
  78. sta sector
  79. jsr getsec
  80. bne fndn1
  81. jmp derr
  82. ;
  83. ;
  84. ; returns optimum initial track,sector
  85. ;
  86. intts
  87. lda #1
  88. ora wbam
  89. sta wbam
  90. lda r0
  91. pha ; save temp var
  92. ;r0:= 1
  93. lda #1
  94. sta r0
  95. its1 ; track:= dirtrk-r0
  96. lda dirtrk
  97. sec
  98. sbc r0
  99. sta track
  100. ;if t>0
  101. bcc its2
  102. beq its2
  103. ;then begin
  104. jsr setbam ; set the bam pointer
  105. ;if @b{.y} then goto fndsec
  106. lda (bmpnt),y
  107. bne fndsec
  108. ;end
  109. its2 ; track:= dirtrk+r0
  110. lda dirtrk
  111. clc
  112. adc r0
  113. sta track
  114. ;r0:= r0+1
  115. inc r0
  116. ;if track >=maxtrk then cmder2(systs)
  117. cmp maxtrk
  118. bcc its3
  119. ;
  120. lda #systs
  121. jsr cmder2
  122. its3
  123. jsr setbam ; set ptr
  124. ;if @b{.y}=0 then goto its1
  125. lda (bmpnt),y
  126. beq its1
  127. fndsec
  128. pla
  129. sta r0 ; restore r0
  130. lda #0
  131. sta sector
  132. jsr getsec
  133. beq fnd2
  134. jmp wused
  135. ;
  136. fnd2
  137. derr
  138. lda #direrr
  139. jsr cmder2
  140. ;
  141. ;
  142. ; set bam and find available sector
  143. ; starting at sector
  144. ;
  145. getsec
  146. jsr setbam
  147. tya
  148. pha ; save .y
  149. jsr avck ; check bits & count
  150. ;
  151. lda track
  152. jsr maxsec
  153. sta lstsec ; save max sector #
  154. pla
  155. sta temp ; temp:= old .y for freus3
  156. gs10
  157. lda sector
  158. cmp lstsec
  159. bcs gs20
  160. ;
  161. jsr freus3
  162. bne gs30
  163. ;
  164. inc sector
  165. bne gs10 ; bra
  166. gs20
  167. lda #0
  168. gs30
  169. rts ; (z=1): used
  170. ;bit map validity check
  171. avck
  172. lda temp
  173. pha ; save temp
  174. lda #0
  175. sta temp ; temp:=0
  176. ;for .y:=bamsiz to 1 do;
  177. ldy bamsiz
  178. dey
  179. ac10 ; for .x:=7 to 0 do;
  180. ldx #7 ; count the bits
  181. ac20 ; if @b{.y} & bmask{x}
  182. ; then temp:=temp+1
  183. lda (bmpnt),y
  184. and bmask,x
  185. beq ac30
  186. inc temp
  187. ac30 ; end .x
  188. dex
  189. bpl ac20
  190. ;end .y
  191. dey
  192. bne ac10
  193. ;if @b{.y} <> temp
  194. ; then cmder2(direrr);
  195. lda (bmpnt),y
  196. cmp temp
  197. bne ac40 ; counts do not match
  198. ;
  199. pla
  200. sta temp ; restore temp
  201. rts
  202. ac40
  203. lda #direrr
  204. jsr cmder2
  205. ; .a=track # ,returns #sectors on this track
  206. maxsec ldx nzones
  207. max1 cmp trknum-1,x
  208. dex
  209. bcs max1
  210. lda numsec,x
  211. rts
  212. ;
  213. ;.end