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.

342 lines
4.7KB

  1. .PAGE 'TST3'
  2. ;
  3. ;
  4. ; .A=#BUFFERS NEEDED
  5. ; SETS UP BUFFER # AND ALLOCATES LINDX
  6. GETWCH
  7. SEC ;SET .C=1 INDICATE WRITE
  8. BCS GETR2
  9. GETRCH
  10. CLC ;SET .C=0 INDICATE READ
  11. GETR2
  12. PHP ;SAVE R/W FLAG (.C)
  13. STA TEMP ;SAVE #BUFS NEEDED
  14. JSR FRECHN ;FREE ANY CHANNELS
  15. JSR FNDLNX ; GET NEXT LINDX OPEN
  16. STA LINDX
  17. LDX SA
  18. PLP
  19. BCC GETR55
  20. GETR52 ORA #$80
  21. GETR55 STA LINTAB,X ;SAVE LINDX IN LINTAB
  22. GETBF
  23. AND #$3F
  24. TAY ;NOW GET THE BUFFERS
  25. LDA #$FF
  26. STA BUF0,Y
  27. STA BUF1,Y
  28. STA SS,Y
  29. GETR3 DEC TEMP
  30. BMI GETR4
  31. JSR GETBUF
  32. BPL GETR5
  33. GBERR JSR RELBUF ; ERROR ,REL BUFS
  34. LDA #NOCHNL
  35. JMP CMDERR
  36. GETR5 STA BUF0,Y
  37. DEC TEMP
  38. BMI GETR4
  39. JSR GETBUF
  40. BMI GBERR
  41. STA BUF1,Y
  42. GETR4 RTS
  43. ;
  44. ; FREE CHANL ASSOCIATED WITH SA
  45. ; FREE READ AND WRITE CHANLS
  46. ; DONT FREE CHANL 15
  47. FRECHN LDA SA
  48. CMP #$F
  49. BNE FRECO
  50. RTS
  51. .SKIP
  52. FRECO
  53. FRERD
  54. FREWRT LDX SA
  55. LDA LINTAB,X
  56. CMP #$FF
  57. BEQ FRE25
  58. AND #$3F
  59. STA LINDX
  60. LDA #$FF
  61. STA LINTAB,X
  62. LDX LINDX
  63. LDA #0
  64. STA CHNRDY,X
  65. JSR RELBUF
  66. ;
  67. ; RELEASE THE LINDX
  68. ;
  69. RELINX LDX LINDX
  70. LDA #1
  71. REL15 DEX
  72. BMI REL10
  73. ASL A
  74. BNE REL15
  75. REL10 ORA LINUSE ;1=FREE 0=USED
  76. STA LINUSE
  77. FRE25 RTS
  78. ; GIVEN SA , FREE ITS READ CHANL
  79. ;
  80. ;
  81. ; RELEASE BUFFERS (LINDX)
  82. ;
  83. RELBUF LDX LINDX
  84. LDA BUF0,X
  85. CMP #$FF
  86. BEQ REL1
  87. PHA
  88. LDA #$FF
  89. STA BUF0,X
  90. PLA
  91. JSR FREBUF
  92. REL1 LDX LINDX
  93. LDA BUF1,X
  94. CMP #$FF
  95. BEQ REL2
  96. PHA
  97. LDA #$FF
  98. STA BUF1,X
  99. PLA
  100. JSR FREBUF
  101. REL2 LDX LINDX
  102. LDA SS,X
  103. CMP #$FF
  104. BEQ REL3
  105. PHA
  106. LDA #$FF
  107. STA SS,X
  108. PLA
  109. JSR FREBUF
  110. REL3 RTS
  111. ;
  112. ; GET A FREE BUFFER #
  113. ;
  114. ; REGS DESTROYED: .A .X
  115. ; OUT: .A,.X= BUF # OR $FF IF FAILED
  116. ; .N= 1 IF FAILED
  117. ;
  118. ; IF SUCCESSFUL INIT JOBS & LSTJOB
  119. ;
  120. GETBUF
  121. TYA ;SAVE .Y
  122. PHA
  123. LDY #1
  124. JSR FNDBUF
  125. BPL GBF1 ;FOUND ONE
  126. ;
  127. DEY
  128. JSR FNDBUF
  129. BPL GBF1 ;FOUND ONE
  130. ;
  131. JSR STLBUF ;STEAL ONE
  132. TAX ;TEST IT
  133. BMI GBF2 ;DIDN'T FIND ONE
  134. GBF1
  135. LDA JOBS,X
  136. BMI GBF1 ;WAIT FOR JOB FREE
  137. LDA DRVNUM
  138. STA JOBS,X ;CLEAR JOB QUEUE
  139. STA LSTJOB,X
  140. TXA
  141. ASL A
  142. TAY
  143. LDA #2
  144. STA BUFTAB,Y
  145. GBF2
  146. PLA
  147. TAY ;RESTORE .Y
  148. TXA ;EXIT WITH BUF # IN .A & CC SET
  149. RTS
  150. ;
  151. ;
  152. ; FIND A FREE BUF # & SET BIT IN BUFUSE
  153. ; ALL REGS USED
  154. ; IN: .Y= INDEX INTO BUFUSE
  155. ; OUT: .X= BUF # OR $FF IF FAILED
  156. ; .N= 1 IF FAILED
  157. ;
  158. FNDBUF
  159. LDX #7
  160. FB1
  161. LDA BUFUSE,Y ;SEARCH BUFUSE
  162. AND BMASK,X
  163. BEQ FB2 ;FOUND A FREE ONE
  164. ;
  165. DEX
  166. BPL FB1 ;UNTIL ALL BITS ARE TESTED
  167. ;
  168. RTS
  169. FB2 ;SET IT USED
  170. LDA BUFUSE,Y
  171. EOR BMASK,X ;SET BIT
  172. STA BUFUSE,Y
  173. TXA
  174. DEY
  175. BMI FB3 ;IF .Y THEN...
  176. CLC ;...ADD 8 MORE
  177. ADC #8
  178. FB3
  179. TAX ;LEAVE IN .X
  180. FRI20
  181. RTS
  182. ;
  183. FREIAC ;FREE INACTIVE BUFFER
  184. LDX LINDX
  185. LDA BUF0,X
  186. BMI FRI10
  187. ;
  188. TXA
  189. CLC
  190. ADC #MXCHNS+1
  191. TAX
  192. LDA BUF0,X
  193. BPL FRI20
  194. FRI10
  195. CMP #$FF
  196. BEQ FRI20
  197. ;
  198. PHA
  199. LDA #$FF
  200. STA BUF0,X
  201. PLA
  202. ; JMP FREBUF
  203. ;
  204. ;
  205. ;
  206. FREBUF AND #$F
  207. TAY
  208. INY
  209. LDX #16
  210. FREB1 ROR BUFUSE+1
  211. ROR BUFUSE
  212. DEY
  213. BNE FREB2
  214. CLC
  215. FREB2 DEX
  216. BPL FREB1
  217. RTS
  218. ;
  219. ;
  220. CLRCHN LDA #14
  221. STA SA
  222. CLRC1 JSR FRECHN
  223. DEC SA
  224. BNE CLRC1
  225. RTS
  226. ;
  227. CLDCHN LDA #14
  228. STA SA
  229. CLSD LDX SA
  230. LDA LINTAB,X
  231. CMP #$FF
  232. BEQ CLD2
  233. AND #$3F
  234. STA LINDX
  235. JSR GETACT
  236. TAX
  237. LDA LSTJOB,X
  238. AND #1
  239. CMP DRVNUM
  240. BNE CLD2
  241. JSR FRECHN
  242. CLD2 DEC SA
  243. BPL CLSD
  244. RTS
  245. ;
  246. ;********************************
  247. ;*********** S T L B U F ******
  248. ;********************************
  249. ;
  250. ; STEAL A BUFFER
  251. ;
  252. ; THIS RTN SEARCHES THE CHANNELS
  253. ; IN ORDER OF LEAST RECENTLY USED
  254. ; AND STEALS THE FIRST INACTIVE
  255. ; BUFFER IT FINDS.
  256. ;
  257. ; INPUT PARAMTERS:
  258. ; LRUTBL - LEAST RECENTYL
  259. ; USED TABLE
  260. ;
  261. ; OUTPUT PARAMTERS:
  262. ; A <== BUFFER #
  263. ;
  264. ; REGISTER USAGE:
  265. ; X - CHANNEL INDEX
  266. ; Y - LRUTBL INDEX
  267. ;
  268. ;*******************************
  269. ;
  270. STLBUF
  271. LDA T0
  272. PHA ;SAVE T0
  273. LDY #0
  274. STL05
  275. LDX LRUTBL,Y
  276. LDA BUF0,X
  277. BPL STL10 ;ACTIVE
  278. ;
  279. CMP #$FF
  280. BNE STL30 ;IT'S INACTIVE
  281. STL10
  282. TXA
  283. CLC
  284. ADC #MXCHNS+1
  285. TAX
  286. LDA BUF0,X
  287. BPL STL20
  288. CMP #$FF
  289. BNE STL30
  290. STL20
  291. INY
  292. CPY #MXCHNS-1
  293. BCC STL05
  294. LDX #$FF ;SET FAILURE
  295. BNE STL60 ;BRA
  296. STL30 ;STEAL THE BUFFER IF NO ERROR
  297. STX T0
  298. AND #$3F
  299. TAX
  300. STL40
  301. LDA JOBS,X
  302. BMI STL40 ;WAIT TILL DONE
  303. CMP #2 ;ERRORS?
  304. BCC STL50 ;OK
  305. LDX T0
  306. CPX #MXCHNS+1
  307. BCC STL10 ;CHECK OPPOSITE SLOT
  308. BCS STL20 ;CHECK ANOTHER CHANNEL
  309. ;
  310. ; FOUND ONE, SO LETS STEAL IT
  311. ;
  312. STL50
  313. LDY T0
  314. LDA #$FF
  315. STA BUF0,Y ;CLEAR SLOT
  316. STL60
  317. PLA
  318. STA T0
  319. TXA ;BUF # IN .A & SET CC'S
  320. RTS
  321. ;
  322. ;
  323. ;
  324. ; FIND A FREE LINDX TO USE
  325. ; MARK AS USED IN LINUSE
  326. ;
  327. FNDLNX LDY #0
  328. LDA #1
  329. FND10 BIT LINUSE ;1=FREE 0=USED
  330. BNE FND30
  331. INY
  332. ASL A
  333. BNE FND10
  334. LDA #NOCHNL ;NO FREE LINDX AVAILABLE
  335. JMP CMDERR
  336. FND30 EOR #$FF ;TOGGLE BIT MASK
  337. AND LINUSE ;MARK BIT USED
  338. STA LINUSE
  339. TYA ;RETURN LINDX IN .A
  340. RTS
  341. .END