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.

tst3.src 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. freco
  52. frerd
  53. frewrt ldx sa
  54. lda lintab,x
  55. cmp #$ff
  56. beq fre25
  57. and #$3f
  58. sta lindx
  59. lda #$ff
  60. sta lintab,x
  61. ldx lindx
  62. lda #0
  63. sta chnrdy,x
  64. jsr relbuf
  65. ;
  66. ; release the lindx
  67. ;
  68. relinx ldx lindx
  69. lda #1
  70. rel15 dex
  71. bmi rel10
  72. asl a
  73. bne rel15
  74. rel10 ora linuse ; 1=free 0=used
  75. sta linuse
  76. fre25 rts
  77. ; given sa , free its read chanl
  78. ;
  79. ;
  80. ; release buffers (lindx)
  81. ;
  82. relbuf ldx lindx
  83. lda buf0,x
  84. cmp #$ff
  85. beq rel1
  86. pha
  87. lda #$ff
  88. sta buf0,x
  89. pla
  90. jsr frebuf
  91. rel1 ldx lindx
  92. lda buf1,x
  93. cmp #$ff
  94. beq rel2
  95. pha
  96. lda #$ff
  97. sta buf1,x
  98. pla
  99. jsr frebuf
  100. rel2 ldx lindx
  101. lda ss,x
  102. cmp #$ff
  103. beq rel3
  104. pha
  105. lda #$ff
  106. sta ss,x
  107. pla
  108. jsr frebuf
  109. rel3 rts
  110. ;
  111. ; get a free buffer #
  112. ;
  113. ; regs destroyed: .a .x
  114. ; out: .a,.x= buf # or $ff if failed
  115. ; .n= 1 if failed
  116. ;
  117. ; if successful init jobs & lstjob
  118. ;
  119. getbuf
  120. tya ; save .y
  121. pha
  122. ldy #1
  123. jsr fndbuf
  124. bpl gbf1 ; found one
  125. ;
  126. dey
  127. jsr fndbuf
  128. bpl gbf1 ; found one
  129. ;
  130. jsr stlbuf ; steal one
  131. tax ; test it
  132. bmi gbf2 ; didn't find one
  133. gbf1
  134. lda jobs,x
  135. bmi gbf1 ; wait for job free
  136. lda drvnum
  137. sta jobs,x ; clear job queue
  138. sta lstjob,x
  139. txa
  140. asl a
  141. tay
  142. lda #2
  143. sta buftab,y
  144. gbf2
  145. pla
  146. tay ; restore .y
  147. txa ; exit with buf # in .a & cc set
  148. rts
  149. ;
  150. ;
  151. ; find a free buf # & set bit in bufuse
  152. ; all regs used
  153. ; in: .y= index into bufuse
  154. ; out: .x= buf # or $ff if failed
  155. ; .n= 1 if failed
  156. ;
  157. fndbuf
  158. ldx #7
  159. fb1
  160. lda bufuse,y ; search bufuse
  161. and bmask,x
  162. beq fb2 ; found a free one
  163. ;
  164. dex
  165. bpl fb1 ; until all bits are tested
  166. ;
  167. rts
  168. fb2 ; set it used
  169. lda bufuse,y
  170. eor bmask,x ; set bit
  171. sta bufuse,y
  172. txa
  173. dey
  174. bmi fb3 ; if .y then...
  175. clc ; ...add 8 more
  176. adc #8
  177. fb3
  178. tax ; leave in .x
  179. fri20
  180. rts
  181. ;
  182. freiac ; free inactive buffer
  183. ldx lindx
  184. lda buf0,x
  185. bmi fri10
  186. ;
  187. txa
  188. clc
  189. adc #mxchns+1
  190. tax
  191. lda buf0,x
  192. bpl fri20
  193. fri10
  194. cmp #$ff
  195. beq fri20
  196. ;
  197. pha
  198. lda #$ff
  199. sta buf0,x
  200. pla
  201. ; jmp frebuf
  202. ;
  203. ;
  204. ;
  205. frebuf and #$f
  206. tay
  207. iny
  208. ldx #16
  209. freb1 ror bufuse+1
  210. ror bufuse
  211. dey
  212. bne freb2
  213. clc
  214. freb2 dex
  215. bpl freb1
  216. rts
  217. ;
  218. ;
  219. clrchn lda #14
  220. sta sa
  221. clrc1 jsr frechn
  222. dec sa
  223. bne clrc1
  224. rts
  225. ;
  226. cldchn lda #14
  227. sta sa
  228. clsd ldx sa
  229. lda lintab,x
  230. cmp #$ff
  231. beq cld2
  232. and #$3f
  233. sta lindx
  234. jsr getact
  235. tax
  236. lda lstjob,x
  237. and #1
  238. cmp drvnum
  239. bne cld2
  240. jsr frechn
  241. cld2 dec sa
  242. bpl clsd
  243. rts
  244. ;
  245. ;********************************
  246. ;*********** s t l b u f ******
  247. ;********************************
  248. ;
  249. ; steal a buffer
  250. ;
  251. ; this rtn searches the channels
  252. ; in order of least recently used
  253. ; and steals the first inactive
  254. ; buffer it finds.
  255. ;
  256. ; input paramters:
  257. ; lrutbl - least recentyl
  258. ; used table
  259. ;
  260. ; output paramters:
  261. ; a <== buffer #
  262. ;
  263. ; register usage:
  264. ; x - channel index
  265. ; y - lrutbl index
  266. ;
  267. ;*******************************
  268. ;
  269. stlbuf
  270. lda t0
  271. pha ; save t0
  272. ldy #0
  273. stl05
  274. ldx lrutbl,y
  275. lda buf0,x
  276. bpl stl10 ; active
  277. ;
  278. cmp #$ff
  279. bne stl30 ; it's inactive
  280. stl10
  281. txa
  282. clc
  283. adc #mxchns+1
  284. tax
  285. lda buf0,x
  286. bpl stl20
  287. cmp #$ff
  288. bne stl30
  289. stl20
  290. iny
  291. cpy #mxchns-1
  292. bcc stl05
  293. ldx #$ff ; set failure
  294. bne stl60 ; bra
  295. stl30 ; steal the buffer if no error
  296. stx t0
  297. and #$3f
  298. tax
  299. stl40
  300. lda jobs,x
  301. bmi stl40 ; wait till done
  302. ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  303. jmp ptch14 ; *ds rom 09/03/85*, save@ prob *GCB 11/20/86*
  304. nop ; fill
  305. ; cmp #2 ; errors?
  306. ; bcc stl50 ; ok
  307. ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  308. rtch14 ldx t0
  309. cpx #mxchns+1
  310. bcc stl10 ; check opposite slot
  311. bcs stl20 ; check another channel
  312. ;
  313. ; found one, so lets steal it
  314. ;
  315. stl50
  316. ldy t0
  317. lda #$ff
  318. sta buf0,y ; clear slot
  319. stl60
  320. pla
  321. sta t0
  322. txa ; buf # in .a & set cc's
  323. rts
  324. ;
  325. ;
  326. ;
  327. ; find a free lindx to use
  328. ; mark as used in linuse
  329. ;
  330. fndlnx ldy #0
  331. lda #1
  332. fnd10 bit linuse ; 1=free 0=used
  333. bne fnd30
  334. iny
  335. asl a
  336. bne fnd10
  337. lda #nochnl ; no free lindx available
  338. jmp cmderr
  339. fnd30 eor #$ff ; toggle bit mask
  340. and linuse ; mark bit used
  341. sta linuse
  342. tya ; return lindx in .a
  343. rts
  344. ; .end