home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / scanlib / ports.asm < prev    next >
Encoding:
Assembly Source File  |  1992-02-05  |  3.2 KB  |  151 lines

  1. ;---------------------------- PORT & IO FUNCTIONS --------------------------
  2. ;
  3. ; Functions for creating and deleting MsgPort's and IORequest's.
  4.  
  5.         far
  6.  
  7.         include 'exec/types.i'
  8.         include 'exec/memory.i'
  9.         include 'exec/ports.i'
  10.         include 'exec/lists.i'
  11.         include 'exec/io.i'
  12.  
  13.         include 'macros.i'
  14.  
  15.         xdef    CreatePort
  16.         xdef    CreateExtPort
  17.         xdef    DeletePort
  18.         xdef    CreateStdIO
  19.         xdef    CreateExtIO
  20.         xdef    DeleteIO
  21.  
  22.  
  23. CreatePort:       ; ( Name:a0, Pri:d0 )
  24.         move.l  #MP_SIZE,d1
  25.  
  26. CreateExtPort:    ; ( Name:a0, Pri:d0, Size:d1 )
  27.         movem.l d2-d5/a2/a6,-(sp)
  28.         move.l  a0,d3
  29.         move.b  d0,d4
  30.         move.l  d1,d5
  31.  
  32.         moveq   #-1,d0
  33.         exec    AllocSignal
  34.         cmpi.b  #-1,d0
  35.         beq     CreatePort_Err
  36.         move.b  d0,d2
  37.  
  38.         move.l  d5,d0
  39.         move.l  #MEMF_PUBLIC!MEMF_CLEAR,d1
  40.         exec    AllocMem
  41.         tst.l   d0
  42.         beq     CreatePort_Err
  43.         move.l  d0,a2
  44.  
  45.         move.l  d3,LN_NAME(a2)
  46.         move.b  d4,LN_PRI(a2)
  47.         move.b  #NT_MSGPORT,LN_TYPE(a2)
  48.         move.b  #PA_SIGNAL,MP_FLAGS(a2)
  49.         move.b  d2,MP_SIGBIT(a2)
  50.         sub.l   a1,a1
  51.         exec    FindTask
  52.         move.l  d0,MP_SIGTASK(a2)
  53.  
  54.         tst.l   d3
  55.         beq     CreatePortNoName
  56.         move.l  a2,a1
  57.         exec    AddPort
  58.         move.l  a2,d0
  59.         bra     CreatePort_End
  60.  
  61. CreatePortNoName:
  62.         lea     MP_MSGLIST(a2),a1
  63.         NEWLIST a1
  64.         move.l  a2,d0
  65.  
  66. CreatePort_End:
  67.         tst.l   d0
  68.         movem.l (sp)+,d2-d5/a2/a6
  69.         rts
  70.  
  71. CreatePort_Err:
  72.         moveq   #0,d0
  73.         bra     CreatePort_End
  74.  
  75.  
  76. ; DeletePort() - delete a port created with either CreatePort() OR
  77. ;                CreateExtPort() above.
  78. ;
  79. ; DeletePort (port)
  80. ;             a1
  81. ;
  82.  
  83.                 xdef    DeletePort
  84. DeletePort
  85.                 push    a2/a6
  86.  
  87.                 move.l  a1,a2
  88.                 tst.l   LN_NAME(a2)
  89.                 beq     1$
  90.                 exec    RemPort
  91.  
  92. 1$              move.b  MP_SIGBIT(a2),d0
  93.                 exec    FreeSignal
  94.  
  95.                 move.l  a2,a1
  96.                 move.l  #MP_SIZE,d0
  97.                 exec    FreeMem
  98.  
  99.                 pop     a2/a6
  100.                 rts
  101.  
  102.  
  103. CreateStdIO:      ; ( ReplyPort:a0 )
  104.         moveq   #IOSTD_SIZE,d0
  105.  
  106. CreateExtIO:      ; ( ReplyPort:a0, Size:d0 )
  107.         movem.l d2-d3,-(sp)
  108.         move.l  a0,d3
  109.         beq     CreateExtIO_Err
  110.         move.l  d0,d2
  111.  
  112.         move.l  #MEMF_PUBLIC!MEMF_CLEAR,d1
  113.         exec    AllocMem
  114.         tst.l   d0
  115.         beq     CreateExtIO_End
  116.         move.l  d0,a1
  117.  
  118.         move.b  #NT_MESSAGE,LN_TYPE(a1)
  119.         move.w  d2,MN_LENGTH(a1)
  120.         move.l  d3,MN_REPLYPORT(a1)
  121.  
  122. CreateExtIO_End:
  123.         tst.l   d0
  124.         movem.l (sp)+,d2-d3
  125.         rts
  126.  
  127. CreateExtIO_Err:
  128.         moveq   #0,d0
  129.         bra     CreateExtIO_End
  130.  
  131.  
  132.  
  133. ; DeleteIO() - delete either a standard IO request block or an extended
  134. ;              IO request block allocated with CreateStdIO() or
  135. ;              CreateExtIO() above.
  136. ;
  137. ; DeleteIO (req)
  138. ;           a1
  139. ;
  140.  
  141.                 xdef    DeleteIO
  142. DeleteIO
  143.                 moveq   #0,d0
  144.                 move.w  MN_LENGTH(a1),d0
  145.                 exec    FreeMem
  146.                 rts
  147.  
  148.  
  149.                 END
  150.  
  151.