home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / RexxInput / RI.S
Encoding:
Text File  |  1993-12-21  |  6.2 KB  |  371 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1993        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    DonĀ“t try to understand the code    *
  8. *                        *
  9. * Version 1.00    08/08/1993            *
  10. *                        *
  11. * BUGS:    Doesn't handle international character    *
  12. *    Upper/LowerCase translation.        *
  13. *                        *
  14. * Version 1.01    11/08/1993            *
  15. *                        *
  16. * BUGS:    Doesn't handle international character    *
  17. *    Upper/LowerCase translation.        *
  18. *                        *
  19. * Added a few things to make it safer to use.    *
  20. *                        *
  21. *************************************************
  22.  
  23.     INCLUDE    "JMPLibs.i"
  24.     INCLUDE    "exec/types.i"
  25.     INCLUDE    "libraries/dos.i"
  26.     INCLUDE    "devices/input.i"
  27.     INCLUDE    "devices/inputevent.i"
  28.     INCLUDE    "rexx/errors.i"
  29.     INCLUDE    "rexx/storage.i"
  30.  
  31.     INCLUDE    "XREF:2.0.xref"
  32.     INCLUDE    "XREF:exec.xref"
  33.     INCLUDE    "XREF:dos.xref"
  34.  
  35.     XREF    _InvertString
  36.     XREF    _FreeIEvents
  37.  
  38.     XDEF    _DOSBase
  39.     XDEF    _SysBase
  40.     XDEF    _CxBase
  41.  
  42. PROGVERSION:    macro
  43.         dc.b    "1.01 (11.08.93)"
  44.         endm
  45.  
  46.         section    RI,CODE
  47.  
  48.         push    d2-d7/a2-a6
  49.  
  50.         sub.l    a1,a1            ;Find our task
  51.         lib    Exec,FindTask
  52.         move.l    d0,OurTask
  53.  
  54.         openlib    Dos,NoDos
  55.         openlib    Commodities,NoCommodities
  56.  
  57.         move.l    $4,_SysBase
  58.         move.l    _DosBase,_DOSBase
  59.         move.l    _CommoditiesBase,_CxBase
  60.  
  61.         lib    Dos,Output
  62.         move.l    d0,_stdout
  63.  
  64.         lea.l    CLTemplate1,a0
  65.         move.l    a0,d1
  66.         lea.l    CLArray1,a0
  67.         move.l    a0,d2
  68.         clr.l    d3
  69.         lib    Dos,ReadArgs
  70.         move.l    d0,RDArgs1
  71.         beq    NoRDArgs
  72.  
  73. ;Check to see if a port with our name already exists
  74.  
  75.         lib    Exec,Forbid
  76.         move.l    PortPointer,a1
  77.         flib    Exec,FindPort
  78.         push    d0
  79.         flib    Exec,Permit
  80.  
  81.         pull    d0
  82.         tst.l    d0
  83.         bne    NoMsgPort2
  84.  
  85. ;Create AREXX message port
  86.  
  87.         lib    Exec,CreateMsgPort
  88.         move.l    d0,ARexxPort
  89.         beq    NoMsgPort
  90.  
  91.         move.l    ARexxPort,a1
  92.         move.l    PortPointer,a0
  93.         move.l    a0,LN_NAME(a1)
  94.         lib    Exec,AddPort
  95.  
  96. CheckMessages:    clr.l    d1            ;Set signals for
  97.         clr.l    d0
  98.         move.l    ARexxPort,a0        ;ARexx
  99.         move.b    MP_SIGBIT(a0),d1
  100.         bset.l    d1,d0
  101.         bset.l    #SIGBREAKB_CTRL_C,d0    ;and CTRL_C
  102.         lib    Exec,Wait
  103.  
  104.         cmp.l    #SIGBREAKF_CTRL_C,d0    ;If CTRL_C
  105.         beq    Break            ;go break
  106.  
  107.         move.l    ARexxPort,a0        ;If ARexx
  108.         move.b    MP_SIGBIT(a0),d1
  109.         btst    d1,d0
  110.         beq    CheckMessages
  111.  
  112.         bsr    DoARexx            ;Go do ARexx magic
  113.         tst.l    d0
  114.         bne    ShutDown
  115.         bra    CheckMessages
  116.  
  117. ;ARexx interface
  118.  
  119. DoARexx:    move.l    ARexxPort,a0
  120.         lib    Exec,GetMsg
  121.  
  122.         tst.l    d0
  123.         beq    DoARexx_OUT
  124.  
  125.         move.l    d0,a5
  126.         cmp.l    #RXCOMM,ACTION(a5)
  127.         bne    DoARexxReply
  128.  
  129.         lea.l    RexxQuit,a0
  130.         move.l    ARG0(a5),a1
  131.         bsr    CmpStrings
  132.         bne    DoRexxQuit
  133.  
  134.         move.l    ARG0(a5),a0
  135.         lea.l    StringBuffer,a1
  136.         bsr    CopyStrs
  137.  
  138.         bsr    SendEvents
  139.         clr.l    d2
  140.         tst.l    IEvents
  141.         bne    DoARexxOK
  142.  
  143. DoARexxFail:    move.l    #RC_FATAL,RESULT1(a5)
  144.         bra    DoARexxReply
  145.  
  146. DoARexxOK:    move.l    #RC_OK,RESULT1(a5)
  147. DoARexxReply:    move.l    a5,a1
  148.         lib    Exec,ReplyMsg
  149. DoARexx_OUT:    move.l    d2,d0
  150.         clr.l    IEvents
  151.         rts
  152.  
  153. DoRexxQuit:    move.l    #-1,d2
  154.         bra    DoARexxOK
  155.  
  156. ;SendEvents converts ARexx string to lower case and converts it into input
  157. ;events and merges these events into the input chain.
  158. ;
  159. ;Inputs    StringBuffer = String to send
  160.  
  161. SendEvents:    lea.l    StringBuffer,a0
  162.         bsr    MakeLowerCase
  163.  
  164. ;Convert string into Input Events
  165.  
  166.         move.l    #0,-(sp)
  167.         pea    StringBuffer
  168.         jsr    _InvertString
  169.         add.l    #8,sp
  170.         move.l    d0,IEvents
  171.         beq    SendEvents2
  172.  
  173. ;Send Input Events
  174.  
  175.         move.l    IEvents,a0
  176.         lib    Commodities,AddIEvents
  177.  
  178. ;Free Input Events
  179.  
  180.         move.l    IEvents,-(sp)
  181.         jsr    _FreeIEvents
  182.         add.l    #4,sp
  183. SendEvents2:    rts
  184.  
  185. ;Compares two strings.
  186. ;
  187. ;INPUT
  188. ;
  189. ;A0 String 1
  190. ;A1 String 2
  191. ;
  192. ;OUTPUT
  193. ;
  194. ;D0 = 0 if not same
  195. ;
  196. ;BUGS
  197. ;
  198. ;String 1 has to have NULL at end!
  199. ;
  200.  
  201. CmpStrings:    bsr    GetLength
  202.         move.l    d0,d4        ;length of string1 to d4
  203.         push    a0
  204.         move.l    a1,a0
  205.         bsr    GetLength
  206.         pull    a0
  207.         cmp.l    d4,d0        ;length of string2 in d3
  208.         bne    CmpStrings1.1
  209. CmpStrings1:    tst.b    (a0)
  210.         beq    CmpStrings2
  211.         cmp.b    (a0)+,(a1)+
  212.         beq    CmpStrings1
  213. CmpStrings1.1:    clr.l    d0
  214.         rts
  215. CmpStrings2:    move.l    #-1,d0
  216.         rts
  217.  
  218. ;Get length of text in given address
  219. ;
  220. ;Input a0 = Address of null terminated text string
  221. ;
  222. ;Result d0 = Length
  223.  
  224. GetLength:    push    a0
  225.         clr.l    d0
  226.         cmp.l    #$00,a0        ;fixes enforcer hit
  227.         beq    GetLength_OUT
  228. GetLength2:    add.l    #1,d0
  229.         tst.b    (a0)+
  230.         bne    GetLength2
  231.         sub.l    #1,d0        ;don't include NULL
  232. GetLength_OUT:    pull    a0
  233.         rts
  234.  
  235. ;Inputs    a0 = Pointer to NULL terminated string to convert
  236.  
  237. MakeLowerCase:    tst.b    (a0)
  238.         beq    MakeLowerCase3
  239.         cmp.b    #'A',(a0)
  240.         bcs    MakeLowerCase2
  241.         cmp.b    #'Z',(a0)
  242.         bhi    MakeLowerCase2
  243.         add.b    #32,(a0)
  244.  
  245. MakeLowerCase2:    add.l    #1,a0
  246.         bra    MakeLowerCase
  247.  
  248. MakeLowerCase3: rts
  249.  
  250. ;Copies bytes from a0 to a1 until NULL is reached or maximum amount of 
  251. ;255 bytes is copied. Destination will include NULL
  252. ;
  253. ;Inputs    a0 = Source
  254. ;    a1 = Destination
  255.  
  256. CopyStrs:    move.l    #255,d0
  257.  
  258. CopyStrs1:    tst.b    (a0)
  259.         beq    CopyStrs_OUT
  260.         move.b    (a0)+,(a1)+
  261.         sub.l    #1,d0
  262.         beq    CopyStrs_OUT
  263.         bra    CopyStrs1
  264. CopyStrs_OUT:    clr.b    (a1)
  265.         rts
  266.  
  267. ShutDown:    move.l    RDArgs1,d1
  268.         beq    ShutDown4000
  269.         lib    Dos,FreeArgs
  270.  
  271. ShutDown4000:
  272.  
  273. ShutDown3000:    move.l    ARexxPort,a1            ;Remove possible
  274.         cmp.l    #$00,a1                ;ports from lists
  275.         beq    ShutDown1000            ;and then delete
  276.         lib    Exec,RemPort            ;the ports
  277.  
  278.         move.l    ARexxPort,a0
  279.         lib    Exec,DeleteMsgPort
  280.  
  281. ShutDown1000:    closlib    Commodities
  282.         closlib    Dos
  283.         pull    d2-d7/a2-a6
  284.         clr.l    d0
  285.         rts
  286.  
  287. ;Error etc. messages
  288.  
  289. NoDos:        pull    d2-d7/a2-a6
  290.         move.l    #RETURN_FAIL,d0
  291.         rts
  292.  
  293. NoCommodities:    lea.l    NoCommoText1,a0
  294.         bsr    Printer
  295.         bra    ShutDown
  296.  
  297. NoRDArgs:    lib    Dos,IoErr
  298.         move.l    d0,d1
  299.         clr.l    d2
  300.         lib    Dos,PrintFault
  301.         bra    ShutDown
  302.  
  303. NoMsgPort:    lea.l    NoMsgPortText1,a0
  304.         bsr    Printer
  305.         bra    ShutDown
  306.  
  307. NoMsgPort2:    lea.l    NoMsgPortText2,a0
  308.         bsr    Printer
  309.         bra    ShutDown
  310.  
  311. Break:        lea.l    BreakText1,a0
  312.         bsr    Printer
  313.         bra    ShutDown
  314.  
  315. Printer:    printa    a0,_stdout
  316.         rts
  317.  
  318.  
  319. ;Structures
  320.  
  321. OurTask:    dc.l    0
  322. RDArgs1:    dc.l    0
  323. ARexxPort:    dc.l    0
  324. _stdout:    dc.l    0
  325. _SysBase:    dc.l    0
  326. _DOSBase:    dc.l    0
  327. _CxBase:    dc.l    0
  328.  
  329. ;Library stuff
  330.  
  331.         libnames
  332.  
  333. ;Options
  334.  
  335. CLArray1:
  336. PortPointer:    dc.l    ARexxPortName
  337.  
  338. ;Other stuff, part I
  339.  
  340. IEvents:    dc.l    0
  341.  
  342. ;Strings, error
  343.  
  344. BreakText1:    dc.b    "***Break: RexxInput",13,10,0
  345. NoMsgPortText1:    dc.b    "ERROR: Couldn't get message port!",13,10,0
  346. NoMsgPortText2: dc.b    "ERROR: An ARexx port with the specified name already exists!",13,10,0
  347. NoCommoText1:    dc.b    "ERROR: Couldn't open commodities.library",13,10,0
  348.  
  349.  
  350. ;Strings, names
  351.  
  352. CLTemplate1:    dc.b    "PORT",0
  353. RIVersion:    dc.b    "$VER: RexxInput "
  354.         PROGVERSION
  355.         dc.b    " (c) Copyright Tomi Blinnikka 1993",0
  356.  
  357. ;ARexx strings
  358.  
  359. ARexxPortName:    dc.b    "REXXINPUT",0
  360.  
  361. ;Misc
  362.  
  363. RexxQuit:    dc.b    "QUIT",0
  364.  
  365. ;Buffers
  366.  
  367. StringBuffer:    dcb.b    256,0
  368.  
  369.  
  370.         END
  371.