home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Painting / DIGIPAINTIII.DMS / in.adf / HeyStuff / hey.asm < prev    next >
Encoding:
Assembly Source File  |  1989-07-12  |  4.6 KB  |  169 lines

  1. ****** This program's (this section and all modules on disk) source code is
  2. ******       Copyright © 1987,1988 by Jamie D. Purdon  (Cleveland, Ohio)
  3. *** builds
  4. * msg    {
  5. *        standard msg node
  6. *        'REMO'
  7. *        'remainder of cmdline'
  8. *    }
  9. *** sends msg to port named on cmdline
  10. *** cmdline:  1> hey hp Quit
  11. *             +- ---+
  12. *             |     msg
  13. *             +port
  14.  
  15.     section    Startup,CODE
  16.  
  17.     include "exec/types.i"
  18.     include "exec/nodes.i"
  19.     include "exec/lists.i"
  20.     include "exec/ports.i"
  21.     ;include "exec/tasks.i"
  22.     include "exec/execbase.i"
  23.     include "libraries/dosextens.i"    ; for pr_... process struct
  24.     include "exec/memory.i" ;for AllocMem types
  25.     ;include "exec/funcdef.i" 
  26.     include "libraries/dos.i" 
  27.  
  28.  
  29.  STRUCTURE MyVariables,0 ;<<=THIS IS WHERE WE POINT A5 (BP) ....
  30.  LONG CmdLineLen_ original, from dos or zero
  31.  LONG CmdLineAdr_ original, from dos or modified -> icon name
  32.  LONG HostPort_            ;HostPort, which we look for...
  33.  STRUCT HostPortName_,40    ;name of port to send msg to
  34.  STRUCT OnlyPort_,MP_SIZE    ;standard exec message port
  35.  STRUCT CustMsg_,128        ;lotsa room, msgs are small anyway
  36.  LABEL BP_SIZEOF    ;size of scratch / bss section / variables
  37.  
  38. BP equr A5
  39. CALLIB macro
  40.   ifnd _LVO\1
  41.     xref    _LVO\1
  42.   endc
  43.     jsr    _LVO\1(a6)
  44.     endm
  45.  
  46. ******************** Start of Code *************************
  47.  
  48. ;Allocate a 'basepage' and point A5 to it
  49. start:    move.l    $0004,a6        ;we only need exec calls!
  50.     movem.l    d0/a0,-(sp)        ;cmdline args if any
  51.     move.l    #((BP_SIZEOF+7)&$ffffFFF8),d0    ;basepage size, roundup 2xlword
  52.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;pub for msg=shared mem
  53.     CALLIB    AllocMem
  54.     tst.l    d0            ;set/clr zero flag
  55.     move.l    d0,BP            ;register A5, basepage, vars at +offsets
  56.     movem.l    (sp)+,d0/a0        ;cmdline args if any (moveM no Z effect)
  57.     beq    nomem_atall        ;abort!, no base avail!
  58.  
  59. ;Ensure CLI-type startup (any shell should work)
  60.     movem.l d0/a0,CmdLineLen_(BP)
  61.     move.l    ThisTask(a6),A4        ;execbase, us, we're alive, right?
  62.     tst.l    pr_CLI(A4)        ;A4=OUR TASK do we have a cli struct?
  63.     beq    Boom            ;boom. (from wbench?), CLI ONLY!!!
  64.  
  65. ;Grab portname from cmd line
  66.     lea    HostPortName_(BP),a1    ;a0=cmdline ptr
  67. grabname:
  68.     move.b    (a0)+,d1    ;char from cmdline
  69.     beq.s    endname
  70.     cmp.b    #$0a,d1
  71.     beq.s    endname
  72.     cmp.b    #' ',d1
  73.     beq.s    endname
  74.     move.b    d1,(a1)+    ;...to string at end of custmsg
  75.     subq    #1,d0
  76.     bne.s    grabname
  77. endname:        ;string 'HostPortName' on basepage, a0=resta cmd line
  78.     clr.b    (a1)    ;NULL to end 'HostPortName'
  79.  
  80. ;Copy rest of cmd line to custom message
  81.     lea    CustMsg_(BP),a1    ;A1=msgptr
  82.     move.b    #NT_MESSAGE,LN_TYPE(a1)    ;fill in (alloc'd clear) msg struct
  83.     lea    OnlyPort_(BP),a2
  84.     move.l    a2,MN_REPLYPORT(a1)    ;point back to our port for reply
  85.  
  86.     lea    MN_SIZE(a1),a2    ;a2=ptr end of message
  87.     move.l    a2,LN_NAME(a1)    ;name of 'our' msg...
  88.     move.l    #'REMO',(a2)+    ;gonna builda name
  89.  
  90.     subq    #1,d0    ;d0=db' type loop ctr, LEN of remainder of cmd line
  91. grabcl:    move.b    (a0)+,d1    ;char from cmd line
  92.     beq.s    endmsg
  93.     cmp.b    #$0a,d1        ;eol?
  94.     beq.s    endmsg
  95.     move.b    d1,(a2)+
  96.     dbf    d0,grabcl
  97. endmsg:            ;string 'HostPortName' on basepage
  98.  
  99.     lea    HostPortName_(BP),a1
  100.     CALLIB    FindPort
  101.     move.l    d0,HostPort_(BP)    ;HostPort's msg port
  102.     beq    Boom
  103.  
  104. ;Make a port named "REMOblahblah" ANNOUNCE OURSELVES
  105.     LEA    OnlyPort_(BP),a2    ;A2=PORT
  106.     moveq    #-1,d0
  107.     CALLIB    AllocSignal    ;d0=return
  108.     moveq    #-1,d1
  109.     cmp.l    d0,d1    ;-1 indicates bad signal
  110.     beq    Boom
  111.     move.b    d0,MP_SIGBIT(a2)
  112.     move.b    #PA_SIGNAL,MP_FLAGS(a2)
  113.     move.b    #NT_MSGPORT,LN_TYPE(a2)
  114.     clr.b    LN_PRI(a2)
  115.     move.l    A4,MP_SIGTASK(a2)    ;task cached at start....
  116.  
  117.     lea    MP_MSGLIST(a2),a0    ;new port's list header
  118.     NEWLIST    a0            ;use macro from exec/lists.i
  119.  
  120.     lea    CustMsg_(BP),a1        ;A1=msgptr
  121.     lea    MN_SIZE(a1),a1    ;stringptr 'REMO'blahblah
  122.     move.l    a1,LN_NAME(a2)        ;portname=
  123.  
  124.     move.l    a2,a1            ;A2=A1=PORT
  125.     CALLIB    AddPort to the system list, let everyone see I'm here...
  126.  
  127. ;Send CustMsg to HostPort
  128.     move.l    HostPort_(BP),a0    ;HostPort's port
  129.     lea    CustMsg_(BP),a1
  130.     CALLIB    PutMsg            ;send msg to HostPort
  131.  
  132. waitonm:
  133.     lea    OnlyPort_(BP),a0
  134.     CALLIB    WaitPort
  135.     lea    OnlyPort_(BP),a0
  136.     CALLIB    GetMsg
  137.     tst.l    d0        ;we got a signal, did we get a mesg?
  138.     beq.s    waitonm
  139.     move.l    d0,a1        ;msgptr in a1 for ReplyMsg call
  140.     ;lea    CustMsg_(BP),a2    ;our msg, did it come back?
  141.     ;cmp.l    a1,a2
  142.     cmp.b    #NT_REPLYMSG,LN_TYPE(a1) ;=NT_REPLYMSG (back from HostPort?)
  143.     beq.s    endsig
  144.     CALLIB    ReplyMsg    ;be polite and reply all unknown msgs
  145.     bra.s    waitonm
  146. endsig:        ;got a 'reply' back from HostPort to 'our' msg
  147.  
  148.     lea    OnlyPort_(BP),a1
  149.     CALLIB    RemPort
  150.  
  151.     lea    OnlyPort_(BP),a1
  152.     moveq    #0,d0    ;Clear upper 3/4 of d0
  153.     move.b    MP_SIGBIT(a1),d0
  154.     beq.s    9$
  155.     CALLIB    FreeSignal
  156. 9$
  157. Boom:
  158.     move.l    BP,a1
  159.     move.l    #((BP_SIZEOF+7)&$ffffFFF8),d0    ;basepage size, roundup 2xlword
  160.     CALLIB    FreeMem
  161.  
  162.     moveq    #0,d0    ;error code?
  163.     rts    ;th-th-th-that's all folks
  164.  
  165. nomem_atall:
  166.     moveq    #103,d0    ;nomem?
  167.     rts
  168.  
  169.   END