home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / conread.r < prev    next >
Text File  |  1993-05-25  |  6KB  |  369 lines

  1.  
  2. ;---;  conread.r  ;------------------------------------------------------------
  3. *
  4. *    ****    READ FROM CONSOLE AND WAIT FOR OTHER SIGNALS    ****
  5. *
  6. *    Author        Stefan Walter
  7. *    Version        1.00
  8. *    Last Revision    19.06.92
  9. *    Identifier    cor_defined
  10. *       Prefix        cor_    (CON Read)
  11. *                 ¯¯  ¯
  12. *    Functions    InitConRead, ResetConRead, ReadCon, SetConRaw
  13. *
  14. *    Note:    Assumes that base of dos.library is in *dosbase and the flag
  15. *        *dosversion is set if version 36+.
  16. *
  17. *        This routines have been collected because Amiga DOS does not
  18. *        provide comfortable read functions which can wait on additional
  19. *        stuff. At the end, make sure, that no read function is sent
  20. *               when terminating!
  21. *
  22. ;------------------------------------------------------------------------------
  23.  
  24. ;------------------
  25.     ifnd    cor_defined
  26. cor_defined    =1
  27.  
  28. ;------------------
  29. cor_oldbase    equ __base
  30.     base    cor_base
  31. cor_base:
  32.  
  33. ;------------------
  34.  
  35. ;------------------------------------------------------------------------------
  36. *
  37. * INITCONREAD    Initializes packet sending. Either inits 1.2/1.3 selfmade
  38. *        packet or allocates dosobject.
  39. *
  40. * RESULT:    d0    0 if failure else <>0
  41. *
  42. ;------------------------------------------------------------------------------
  43.  
  44. ;------------------
  45. InitConRead:
  46.  
  47. ;------------------
  48. ; Start.
  49. ;
  50. \start:
  51.     movem.l    d1-a6,-(sp)
  52.     lea    cor_base(pc),a4
  53.  
  54. ;------------------
  55. ; Allocate signal for our port.
  56. ;
  57. \alloc:
  58.     move.l    4.w,a6
  59.     suba.l    a1,a1
  60.     jsr    -294(a6)        ;FindTask()
  61.     move.l    d0,d7
  62.     moveq    #-1,d0
  63.     jsr    -330(a6)        ;AllocSignal()
  64.     move.l    d0,cor_signal(a4)
  65.     bmi    \error
  66.  
  67. ;------------------
  68. ; Add port.
  69. ;
  70. \add:
  71.     lea    cor_port(pc),a1
  72.     move.l    4.w,a6
  73.     jsr    -354(a6)        ;AddPort()
  74.  
  75. ;------------------
  76. ; Init port.
  77. ;
  78. \initport:
  79.     lea    cor_port(pc),a0
  80.     move.b    cor_signal+3(pc),15(a0)
  81.     move.l    d7,16(a0)
  82.     clr.b    cor_sent(a4)        ;no packet on the way
  83.  
  84. ;------------------
  85. ; test version of dos.library
  86. ;
  87. \testdos:
  88.     move.l    dosbase(pc),a6
  89.     cmp.w    #$24,20(a6)        ;V36+ ?
  90.     sge    cor_dosflag(a4)
  91.     blt.s    \nodos20
  92.  
  93. ;------------------
  94. ; allocate dos object (3=packet)
  95. ;
  96. \isdos20:
  97.     moveq    #3,d1
  98.     jsr    -228(a6)        ;AllocDosObject()
  99.     tst.l    d0
  100.     beq.s    \close
  101.     move.l    d0,a0
  102.     moveq    #'R',d1
  103.     move.l    d1,8(a0)        ;set type
  104.     bra.s    \exit
  105.  
  106. ;------------------
  107. ; init 1.2/1.3 message system mix
  108. ;
  109. \nodos20:
  110.     lea    cor_messy(pc),a0
  111.     lea    cor_packet(pc),a1
  112.     move.l    a1,$a(a0)        ;packet
  113.     move.l    a0,(a1)            ;message
  114.     move.l    a1,d0
  115.  
  116. ;------------------
  117. ; installation done
  118. ;
  119. \exit:
  120.     move.l    d0,cor_pktptr(a4)
  121.     movem.l    (sp)+,d1-a6
  122.     rts
  123.  
  124. ;------------------
  125. ; installation failure
  126. ;
  127. \close:
  128.     move.l    cor_signal(pc),d0
  129.     move.l    4.w,a6
  130.     jsr    -336(a6)        ;FreeSignal()
  131.     lea    cor_port(pc),a1
  132.     jsr    -360(a6)
  133.  
  134. \error:
  135.     moveq    #0,d0
  136.     bra.s    \exit
  137.  
  138. ;------------------
  139.  
  140. ;------------------------------------------------------------------------------
  141. *
  142. * READCON    Reads from handler and waits for multiple signals
  143. *
  144. * INPUT:    d0    Mask with signals to wait for too
  145. *        d1    Handler
  146. *        d2    Buffer
  147. *        d3    Length
  148. *
  149. * RESULT:    d0    Read length or 0 if EOF, -1 if error
  150. *        d1    -1 if read valid else 0
  151. *        d2    Mask of signals arrived too
  152. *
  153. ;------------------------------------------------------------------------------
  154.  
  155. ;------------------
  156. ReadCon:
  157.  
  158. ;------------------
  159. ; start
  160. ;
  161. \start:
  162.     movem.l    d3-a6,-(sp)
  163.     lea    cor_base(pc),a4
  164.     move.l    d0,d7
  165.     tst.b    cor_sent(a4)
  166.     bne.s    \getmessy        ;packet allready sent
  167.  
  168. ;------------------
  169. ; fill in packet
  170. ;
  171. \fill:
  172.     move.l    cor_pktptr(pc),a0
  173.     lea    cor_port(pc),a2
  174.     move.l    (a0),a1
  175.     move.l    a2,14(a1)
  176.     move.l    d2,24(a0)        ;Buffer
  177.     move.l    d3,28(a0)        ;Length
  178.     lsl.l    #2,d1
  179.     move.l    d1,a2
  180.     move.l    8(a2),4(a0)        ;Console process ID
  181.     move.l    36(a2),20(a0)        ;Arg1 from filehandle
  182.     move.l    a0,d1
  183.  
  184. ;------------------
  185. ; switch to right routine
  186. ;
  187. \switch:
  188.     tst.b    cor_dosflag(a4)
  189.     beq.s    \nodos20
  190.  
  191. ;------------------
  192. ; 2.0 SendPkt()
  193. ;
  194. \isdos20:
  195.     move.l    dosbase(pc),a6
  196.     move.l    8(a2),d2
  197.     pea    cor_port(pc)
  198.     move.l    (sp)+,d3
  199.     jsr    -246(a6)        ;SendPkt()
  200.     bra.s    \getmessy
  201.  
  202. ;------------------
  203. ; use 1.2/1.3 system
  204. ;
  205. \nodos20:
  206.     lea    cor_port(pc),a2
  207.     move.l    4(a0),a1
  208.     exg.l    a1,a0
  209.     move.l    a2,4(a1)
  210.     move.l    (a1),a1
  211.     move.l    4.w,a6
  212.     jsr    -$16e(a6)        ;PutMsg()
  213.  
  214. ;------------------
  215. ; forbid
  216. ;
  217. \getmessy:
  218.     st    cor_sent(a4)
  219.     move.l    4.w,a6
  220.     jsr    -132(a6)        ;Forbid()
  221.  
  222. ;------------------
  223. ; wait for all signals
  224. ;
  225. \wait:
  226.     lea    cor_port(pc),a0
  227.     move.b    15(a0),d3
  228.     moveq    #0,d0
  229.     bset    d3,d0
  230.     or.l    d7,d0
  231.     jsr    -318(a6)        ;Wait()
  232.     bclr    d3,d0
  233.     beq.s    \noread
  234.     move.l    d0,d5
  235.  
  236. ;------------------
  237. ; get our message and check if it is it.
  238. ;
  239. \check:
  240.     lea    cor_port(pc),a0
  241.     jsr    -372(a6)        ;GetMsg()
  242.     tst.l    d0
  243.     bne.s    \gotmsg
  244.     tst.l    d5
  245.     bne.s    \noread
  246.     bra.s    \wait            ;signal came without msg =>wait again
  247. \gotmsg:
  248.     move.l    cor_pktptr(pc),a1
  249.     move.l    (a1),a0
  250.     cmp.l    a0,d0
  251.     bne.s    \check
  252.  
  253. ;------------------
  254. ; case 1: packet came in
  255. ;
  256. \camein:
  257.     move.l    d5,d2
  258.     moveq    #-1,d1
  259.     move.l    12(a1),d0        ;Res1=Length
  260.     sf    cor_sent(a4)        ;packet no longer sent
  261.     bra.s    \exit
  262.  
  263. ;------------------
  264. ; case 2: only other signals came in, no read result.
  265. ;
  266. \noread:
  267.     move.l    d0,d2
  268.     moveq    #0,d1
  269.     moveq    #0,d0
  270.  
  271. ;------------------
  272. ; exit
  273. ;
  274. \exit:
  275.     movem.l    d0-d2,-(sp)
  276.     jsr    -138(a6)
  277.     movem.l    (sp)+,d0-a6
  278.     rts
  279.     
  280. ;------------------
  281.  
  282. ;------------------------------------------------------------------------------
  283. *
  284. * RESETCONREAD    Resets packet sending. Frees dos object.
  285. *
  286. * RESULT:    All resources freed.
  287. *
  288. ;------------------------------------------------------------------------------
  289.  
  290. ;------------------
  291. resetconread:
  292.  
  293. ;------------------
  294. ; start
  295. ;
  296. \start:
  297.     movem.l    d0-a6,-(sp)
  298.            move.l    cor_pktptr(pc),d0      ;no packet installed
  299.     beq.s    \exit
  300.     lea    cor_dosflag(pc),a0
  301.     tst.b    (a0)
  302.     beq.s    \close
  303.  
  304. ;------------------
  305. ; FreeDosObject()
  306. ;
  307. \free:
  308.     move.l    dosbase(pc),a6
  309.     moveq    #3,d1
  310.     move.l    cor_pktptr(pc),d2
  311.     jsr    -234(a6)
  312.  
  313. ;------------------
  314. ; free signal
  315. ;
  316. \close:
  317.     move.l    cor_signal(pc),d0
  318.     move.l    4.w,a6
  319.     jsr    -336(a6)        ;FreeSignal()
  320.     lea    cor_port(pc),a1
  321.     jsr    -360(a6)
  322.  
  323. ;------------------
  324. ; exit
  325. ;
  326. \exit:
  327.     movem.l    (sp)+,d0-a6
  328.     rts
  329.  
  330. ;------------------
  331.  
  332. ;--------------------------------------------------------------------
  333.  
  334. ;------------------
  335. cor_dosflag:    dc.b    0
  336. cor_sent:    dc.b    0
  337. cor_pktptr:    dc.l    0
  338. cor_signal:    dc.l    0
  339.  
  340. ;------------------
  341. cor_port:    ds.b    14,0
  342.         dc.b    0,0        ;flag,sigbit
  343.         dc.l    0        ;sigtask
  344.         ds.b    14,0
  345.  
  346. ;------------------
  347.         align.l
  348. cor_messy:    dc.l    0,0
  349.         dc.b    5,0
  350.         dc.l    0    ;>packet
  351.         dc.l    0    ;>replyport
  352.         dc.w    20
  353. cor_packet:    dc.l    0    ;>messy
  354.         dc.l    0    ;>replyport
  355.         dc.l    'R'    ;>type
  356.         dc.l    0,0    ;Res
  357.         dc.l    0,0,0,0    ;Args
  358.  
  359. ;--------------------------------------------------------------------
  360.  
  361. ;------------------
  362.     base    cor_oldbase
  363.  
  364. ;------------------
  365.     endif
  366.  
  367.  end
  368.  
  369.