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.

218 lines
2.8KB

  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. .SKIP
  66. SEC
  67. LDA SECTOR
  68. SBC LSTSEC
  69. STA SECTOR
  70. BEQ FNDN0
  71. .SKIP
  72. DEC SECTOR
  73. FNDN0
  74. JSR GETSEC
  75. BEQ FNDN2
  76. FNDN1
  77. JMP WUSED
  78. FNDN2
  79. LDA #0
  80. STA SECTOR
  81. JSR GETSEC
  82. BNE FNDN1
  83. JMP DERR
  84. ;
  85. ;
  86. ; RETURNS OPTIMUM INITIAL TRACK,SECTOR
  87. ;
  88. INTTS
  89. LDA #1
  90. ORA WBAM
  91. STA WBAM
  92. LDA R0
  93. PHA ;SAVE TEMP VAR
  94. ;R0:= 1
  95. LDA #1
  96. STA R0
  97. ITS1 ;TRACK:= DIRTRK-R0
  98. LDA DIRTRK
  99. SEC
  100. SBC R0
  101. STA TRACK
  102. ;IF T>0
  103. BCC ITS2
  104. BEQ ITS2
  105. ;THEN BEGIN
  106. JSR SETBAM ;SET THE BAM POINTER
  107. ;IF @B[.Y] THEN GOTO FNDSEC
  108. LDA (BMPNT),Y
  109. BNE FNDSEC
  110. ;END
  111. ITS2 ;TRACK:= DIRTRK+R0
  112. LDA DIRTRK
  113. CLC
  114. ADC R0
  115. STA TRACK
  116. ;R0:= R0+1
  117. INC R0
  118. ;IF TRACK >=MAXTRK THEN CMDER2(SYSTS)
  119. CMP MAXTRK
  120. BCC ITS3
  121. ;
  122. LDA #SYSTS
  123. JSR CMDER2
  124. ITS3
  125. JSR SETBAM ;SET PTR
  126. ;IF @B[.Y]=0 THEN GOTO ITS1
  127. LDA (BMPNT)Y
  128. BEQ ITS1
  129. FNDSEC
  130. PLA
  131. STA R0 ;RESTORE R0
  132. LDA #0
  133. STA SECTOR
  134. JSR GETSEC
  135. BEQ FND2
  136. JMP WUSED
  137. ;
  138. FND2
  139. DERR
  140. LDA #DIRERR
  141. JSR CMDER2
  142. ;
  143. ;
  144. ; SET BAM AND FIND AVAILABLE SECTOR
  145. ; STARTING AT SECTOR
  146. ;
  147. GETSEC
  148. JSR SETBAM
  149. TYA
  150. PHA ;SAVE .Y
  151. JSR AVCK ;CHECK BITS & COUNT
  152. ;
  153. LDA TRACK
  154. JSR MAXSEC
  155. STA LSTSEC ;SAVE MAX SECTOR #
  156. PLA
  157. STA TEMP ;TEMP:= OLD .Y FOR FREUS3
  158. GS10
  159. LDA SECTOR
  160. CMP LSTSEC
  161. BCS GS20
  162. ;
  163. JSR FREUS3
  164. BNE GS30
  165. ;
  166. INC SECTOR
  167. BNE GS10 ;BRA
  168. GS20
  169. LDA #0
  170. GS30
  171. RTS ;(Z=1): USED
  172. .SKIP
  173. ;BIT MAP VALIDITY CHECK
  174. AVCK
  175. LDA TEMP
  176. PHA ;SAVE TEMP
  177. LDA #0
  178. STA TEMP ;TEMP:=0
  179. ;FOR .Y:=BAMSIZ TO 1 DO;
  180. LDY BAMSIZ
  181. DEY
  182. AC10 ;FOR .X:=7 TO 0 DO;
  183. LDX #7 ;COUNT THE BITS
  184. AC20 ;IF @B[.Y] & BMASK[X]
  185. ; THEN TEMP:=TEMP+1
  186. LDA (BMPNT)Y
  187. AND BMASK,X
  188. BEQ AC30
  189. INC TEMP
  190. AC30 ;END .X
  191. DEX
  192. BPL AC20
  193. ;END .Y
  194. DEY
  195. BNE AC10
  196. ;IF @B[.Y] <> TEMP
  197. ; THEN CMDER2(DIRERR);
  198. LDA (BMPNT)Y
  199. CMP TEMP
  200. BNE AC40 ;COUNTS DO NOT MATCH
  201. ;
  202. PLA
  203. STA TEMP ;RESTORE TEMP
  204. RTS
  205. AC40
  206. LDA #DIRERR
  207. JSR CMDER2
  208. .SKIP
  209. ; .A=TRACK # ,RETURNS #SECTORS ON THIS TRACK
  210. MAXSEC LDX NZONES
  211. MAX1 CMP TRKNUM-1,X
  212. DEX
  213. BCS MAX1
  214. LDA NUMSEC,X
  215. RTS
  216. ;
  217. .END