home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / os968ka / k6ocm4.asm < prev    next >
Assembly Source File  |  2020-01-01  |  16KB  |  338 lines

  1.           nam       Kermit68K
  2.           ttl       Command line parser module
  3.  
  4. *         Kermit68K: source file K68CM4
  5. *
  6. * Author: Roberto Bagnara (Bagnara@Iboinfn.Bitnet),
  7. * Bologna University, Physics Department, July 1987.
  8. *
  9. * All rights reserved to Bologna University, Italy.
  10. *
  11. * Permission is granted to any individual or institution
  12. * to use, copy, or redistribute this software so long as
  13. * it  is not  sold for  profit, provided  this copyright
  14. * notice is retained.
  15. *
  16. * Modification History:
  17. *
  18. * Version  Date    Who              Comments
  19. *
  20. * 1.0.00   870701  Roberto Bagnara  First official release
  21.  
  22.           use       DefsFile
  23.  
  24. Edition   equ       0
  25.           psect     K68Commands4,0,0,Edition,0,0
  26.  
  27. ********************************** CmdLnP *****************************
  28. *                                                                     *
  29. *  Kermit68K command line parser.                                     *
  30. *                                                                     *
  31. *         Entry conditions : none                                     *
  32. *                                                                     *
  33. *         Exit  conditions : none                                     *
  34. *                                                                     *
  35. ***********************************************************************
  36. CmdLnP:   BSR       GetCmdLP           Try to get the command line pointer
  37.           TST.B     D0                 Success ?
  38.           BEQ       CmdLnP10           No, return
  39.           MOVEA.L   A0,A5              Yes, load pointer for parser functions
  40.           MOVEQ     #-1,D7             Say no protocol commands yet
  41.           SF        D5                 Set the connect before flag to false
  42.           SF        D6                 Set the connect after flag to false
  43. CmdLnP1   LEA       RecBuf(A6),A4      This pointer is used by DoCmLA
  44.           MOVEA.L   A4,A0              Put here the command line options
  45.           BSR       ParsWrd            Try to get a word from command line
  46.           TST.B     D0                 Success ?
  47.           BLT.S     CmdLnP2            No, exit loop
  48.           CMPI.B    #'-',(A4)+         Options begins with dash
  49.           BNE       DoCmLA4            Not an options, give usage info
  50.           BSR       DoCmLA             Got an option, handle it
  51.           BRA.S     CmdLnP1            Loop until the whole line is parsed
  52.  
  53. CmdLnP2   TST.B     Local(A6)          Are we running in local mode ?
  54.           BNE.S     CmdLnP4            Yes, no problem
  55.           CMPI.B    #SndSrvIS,D7       Are we issuing a get command ?
  56.           BEQ.S     CmdLnP3            Yes, fatal error
  57.           MOVEQ     #SndGCmdS,D7       Are we issuing a finish command ?
  58.           BEQ.S     CmdLnP3            Yes, fatal error
  59.           TST.B     D5                 Are we connecting trough the host line ?
  60.           BEQ.S     CmdLnP4            No, all ok
  61. CmdLnP3   LEA       LBReqStr(PC),A0    Give message about -l and -b need
  62.           BRA       FatalEr            Return to system
  63.  
  64. CmdLnP4   CMPI.B    #SndFileS,D7       Are we sending a file ?
  65.           BEQ.S     CmdLnP5            Yes, set the display flag
  66.           CMPI.B    #RecFileS,D7       Are we receiving a file ?
  67.           BEQ.S     CmdLnP5            Yes, set the display flag
  68.           CMPI.B    #SndSrvIS,D7       Are we getting a file ?
  69.           BEQ.S     CmdLnP5            Yes, set the display flag
  70.           TST.B     Argumnt2(A6)       No, has a file as-name been specified ?
  71.           BEQ.S     CmdLnP5            No, all is fine
  72.           LEA       ABadUStr(PC),A0    Yes, bad use of the -a option
  73.           BRA       FatalEr            Give message and exit the program
  74.  
  75. CmdLnP5   TST.B     Local(A6)          Are we running in local mode ?
  76.           BEQ.S     CmdLnP6            No
  77.           ST        Display(A6)        Yes, set the display flag on
  78. CmdLnP6   TST.B     TermOut(A6)        Are we outputting to the terminal ?
  79.           BEQ.S     CmdLnP7            No
  80.           SF        Display(A6)        Yes, set the display flag off
  81.  
  82. CmdLnP7   TST.B     Quiet(A6)          Has quiet been requested ?
  83.           BEQ.S     CmdLnP8            No
  84.           SF        Display(A6)        Yes, set the display flag off
  85.  
  86.           TST.B     D5                 Is the connect before flag on ?
  87.           BEQ.S     CmdLnP8            No
  88.           BSR       DoCONN             Yes, connect to the remote host
  89.  
  90. CmdLnP8   TST.B     D7                 We must invoke the protocol switcher ?
  91.           BLT.S     CmdLnP10           No, let's return
  92.           BSR       TrnsInit           Yes, initialize any protocol thing
  93.           BSR       KPSwtch            Enter the protocol switcher
  94.  
  95.           TST.B     D6                 Is the connect after flag on ?
  96.           BEQ.S     CmdLnP9            No, return the cc from the automaton
  97.           BSR       DoCONN             Yes, connect to the remote host
  98.           ST        D0                 Return a positive completion code
  99. CmdLnP9   BRA       SysExod
  100.  
  101. CmdLnP10  RTS
  102.  
  103. ********************************** DoCmLA *****************************
  104. *                                                                     *
  105. *  Handle command line arguments.                                     *
  106. *                                                                     *
  107. *         Entry conditions : A4.L pointer to a null terminated        *
  108. *                                 string containing the command line  *
  109. *                                 argument(s)                         *
  110. *                                                                     *
  111. *         Exit  conditions : none                                     *
  112. *                                                                     *
  113. ***********************************************************************
  114. DoCmLA    TST.B     (A4)               Null option ?
  115.           BEQ.S     DoCmLA4            Yes, give an error message
  116. DoCmLA1   MOVE.B    (A4)+,D0           Get the option letter
  117.           BNE.S     DoCmLA2            Not null, handle it
  118.           RTS                          End of option bundling, return
  119.  
  120. DoCmLA2   SUBI.B    #97,D0             Map the option letter from zero on
  121.           CMPI.B    #22,D0             Above 'w' ?
  122.           BHI       DoCmLA4            Yes, error
  123.           EXT.W     D0                 No, extend to word size
  124.           ADD.W     D0,D0              Scale by a factor of two
  125.           MOVE.W    DoCmLA3(PC,D0.W),D0 Load service routine relative address
  126.           JMP       DoCmLA3(PC,D0.W)   Jump to the option service routine
  127.  
  128. DoCmLA3   DC.W      DoCmLA16-DoCmLA3   -a option, file as-name
  129.           DC.W      DoCmLA14-DoCmLA3   -b option, line baud rate
  130.           DC.W      DoCmLA25-DoCmLA3   -c command, connect before
  131.           DC.W      DoCmLA4-DoCmLA3    -d invalid
  132.           DC.W      DoCmLA4-DoCmLA3    -e invalid
  133.           DC.W      DoCmLA24-DoCmLA3   -f option, finish remote server
  134.           DC.W      DoCmLA23-DoCmLA3   -g command, get file(s) from server
  135.           DC.W      DoCmLA18-DoCmLA3   -h request, give usage informations
  136.           DC.W      DoCmLA7-DoCmLA3    -i option, treate files as binary
  137.           DC.W      DoCmLA4-DoCmLA3    -j invalid
  138.           DC.W      DoCmLA20-DoCmLA3   -k command, receive file(s) to terminal
  139.           DC.W      DoCmLA11-DoCmLA3   -l option, set communication line
  140.           DC.W      DoCmLA4-DoCmLA3    -m invalid
  141.           DC.W      DoCmLA4-DoCmLA26   -n command, connect after
  142.           DC.W      DoCmLA4-DoCmLA3    -o invalid
  143.           DC.W      DoCmLA15-DoCmLA3   -p option, communication line parity
  144.           DC.W      DoCmLA9-DoCmLA3    -q option, be quiet
  145.           DC.W      DoCmLA19-DoCmLA3   -r command, receive file(s)
  146.           DC.W      DoCmLA21-DoCmLA3   -s command, send file(s)
  147.           DC.W      DoCmLA10-DoCmLA3   -t option, line turnaround handshake
  148.           DC.W      DoCmLA4-DoCmLA3    -u invalid
  149.           DC.W      DoCmLA4-DoCmLA3    -v invalid
  150.           DC.W      DoCmLA8-DoCmLA3    -w option, file collisions warnings
  151.  
  152. DoCmLA4   LEA       InvArStr(PC),A0    No, invalid argument, fatal error
  153.           BRA       FatalEr
  154. DoCmLA5   LEA       InvABStr(PC),A0    Invalid argument bundling, fatal error
  155.           BRA       FatalEr
  156. DoCmLA6   LEA       CnfAcStr(PC),A0    Conflicting commands, fatal error
  157.           BRA       FatalEr
  158.  
  159. *** -i image option ***
  160.  
  161. DoCmLA7   ST        Binary(A6)         Treat files as binary
  162.           BRA       DoCmLA1            See if options are bundled
  163.  
  164. *** -w warning option ***
  165.  
  166. DoCmLA8   ST        Warning(A6)        Give file collisions warnings
  167.           BRA       DoCmLA1            See if options are bundled
  168.  
  169. *** -q quiet option ***
  170.  
  171. DoCmLA9   ST        Quiet(A6)          Yes, be quiet during file transfers
  172.           BRA       DoCmLA1            See if options are bundled
  173.  
  174. *** -t line turnaround option ***
  175.  
  176. DoCmLA10  ST        Duplex(A6)         Set half duplex on
  177.           SF        Flow(A6)           Set flow control off
  178.           ST        TurnFlag(A6)       Set line turnaround handshake on
  179.           MOVE.B    Asc_DC1,TurnChar(A6) Set XON as the turnaround character
  180.           BRA       DoCmLA1            See if options are bundled
  181.  
  182. *** -l set line option ***
  183.  
  184. DoCmLA11  TST.B     (A4)               Invalid argument bundling ?
  185.           BNE.S     DoCmLA5            Yes, error
  186.  
  187.           LEA       DataBuf(A6),A0     No, put here the line name
  188.           BSR       ParsWrd            Get the line name, if any
  189.           TST.B     D0                 Has the line name been specified ?
  190.           BLT.S     DoCmLA12           No, error
  191.  
  192.           LEA       DataBuf(A6),A0     Reload pointer to the parsed line name
  193.           MOVEQ     #RdWrOp,D0         Try to open the new line
  194.           MOVEQ     #HostLine,D1       This is the channel number
  195.           BSR       FilOpen            Open, if possible
  196.           TST.B     D0                 Ok ?
  197.           BEQ.S     DoCmLA13           No, give an error message
  198.  
  199.           LEA       LineName(A6),A1    This is the line name string
  200.           EXG       A0,A1              Adjust pointers
  201.           MOVEQ     #LinNamML,D0       Maximum line name length
  202.           BSR       CopyStr            Copy now
  203.  
  204.           LEA       ConLinNm(PC),A1    Point to the console line name
  205.           BSR       CompStr            Compare the two line names
  206.           TST.B     D0                 Are equal ?
  207.           SEQ       Local(A6)          If not we are local, remote otherwise
  208.           BEQ       DoCmLA1            If local, leave speed unchanged
  209.           MOVE.L    #-1,Speed(A6)      If remote, say speed unknown
  210.           RTS
  211.  
  212. DoCmLA12  LEA       MisLNStr(PC),A0    Give missing line name error
  213.           BRA       FatalEr
  214. DoCmLA13  LEA       UnOpLStr(PC),A0    Give unable to open line error
  215.           BRA       FatalEr
  216.  
  217. *** -b set line baud rate option ***
  218.  
  219. DoCmLA14  TST.B     (A4)               Invalid argument bundling ?
  220.           BNE       DoCmLA5            Yes, error
  221.           MOVEQ     #50,D1             Valid range lower bound
  222.           MOVE.L    #19200,D2          Valid range upper bound
  223.           BSR       ParsNm             Try to get a valid number specification
  224.           TST.B     D1                 Valid number on input ?
  225.           BLT       FatalEr1           No, fatal error
  226.           BSR       ChkBaud            Check if requested speed is supported
  227.           TST.B     D1                 Ok ?
  228.           BEQ       FatalEr1           No, fatal error
  229.           MOVE.L    D0,Speed(A6)       Yes, set the baud rate variable
  230.           MOVE.L    D0,D2              Pass baud rate to ChanCtrl
  231.           MOVEQ     #HostLine,D1       Pass channel number to ChanCtrl
  232.           MOVEQ     #SetBaud,D0        Pass request code to ChanCtrl
  233.           BSR       ChanCtrl           Physically set the host line baud rate
  234.           RTS
  235.  
  236. *** -p set parity option ***
  237.  
  238. DoCmLA15  TST.B     (A4)               Invalid argument bundling ?
  239.           BNE       DoCmLA5            Yes, error
  240.           LEA       ParTable(PC),A1    No, point to the parity keywords table
  241.           ST        D1                 This keyword is mandatory
  242.           BSR       ParsKyW            Look for a valid parity specification
  243.           TST.B     D0                 Ok ?
  244.           BLT       FatalEr1           No, fatal error
  245.           MOVE.B    D0,Parity(A6)      Yes, set parity to the requested value
  246.           RTS
  247.  
  248. *** -a file as-name option ***
  249.  
  250. DoCmLA16  TST.B     (A4)               Invalid argument bundling ?
  251.           BNE       DoCmLA5            Yes, error
  252.           LEA       Argumnt2(A6),A0    No, put here the file as-name
  253.           BSR       ParsWrd            Get the file as-name, if any
  254.           TST.B     D0                 Has it been specified ?
  255.           BLT.S     DoCmLA17           No, error
  256.           RTS
  257.  
  258. DoCmLA17  LEA       MsFlNStr(PC),A0    Give missing file name error message
  259.           BSR       FatalEr
  260.  
  261. *** -h help request ***
  262.  
  263. DoCmLA18  LEA       UsageStr(PC),A0    Point to the usage string
  264.           BSR       ConWrite           Write it to the terminal
  265.           BRA       DoCmLA1            See if options are bundled
  266.  
  267. *** -r receive command ***
  268.  
  269. DoCmLA19  TST.B     D7                 Conflicting commands ?
  270.           BGE       DoCmLA6            Yes, error
  271.           MOVEQ     #RecInitS,D7       Start state for the protocol automaton
  272.           BRA       DoCmLA1            See if options are bundled
  273.  
  274. *** -k receive to terminal command ***
  275.  
  276. DoCmLA20  TST.B     D7                 Conflicting commands ?
  277.           BGE       DoCmLA6            Yes, error
  278.           ST        TermOut(A6)        We want output to the terminal line
  279.           MOVEQ     #RecInitS,D7       Start state for the protocol automaton
  280.           BRA       DoCmLA1            See if options are bundled
  281.  
  282. *** -s send command ***
  283.  
  284. DoCmLA21  TST.B     D7                 Conflicting commands ?
  285.           BGE       DoCmLA6            Yes, error
  286.           TST.B     (A4)               Invalid argument bundling ?
  287.           BNE       DoCmLA5            Yes, error
  288.           LEA       Argumnt1(A6),A0    Point to file name string
  289.           BSR       ParsInF            Try to get a valid input file name
  290.           TST.B     D0                 Some error ?
  291.           BLT.S     DoCmLA22           Yes
  292.           MOVEQ     #SndInitS,D7       No, Send-Init is the start state
  293.           RTS
  294. DoCmLA22  CMPI.B    #-3,D0             Has a file name been specified ?
  295.           BEQ.S     DoCmLA17           No, give missing file name message
  296.           RTS                          Yes, message already given, return
  297.  
  298. *** -g get command ***
  299.  
  300. DoCmLA23  TST.B     D7                 Conflicting commands ?
  301.           BGE       DoCmLA6            Yes, error
  302.           TST.B     (A4)               Invalid argument bundling ?
  303.           BNE       DoCmLA5            Yes, error
  304.           LEA       Argumnt1(A6),A0    Point to file name string
  305.           BSR       ParsWrd            Try to get a file name
  306.           TST.B     D0                 Missing file name ?
  307.           BLT.S     DoCmLA17           Yes, give error message
  308.           MOVE.B    #'R',ServrCmd(A6)  Get command
  309.           MOVEQ     #SndSrvIS,D7       Send-Server-Init is the start state
  310.           RTS
  311.  
  312. *** -f finish command ***
  313.  
  314. DoCmLA24  TST.B     D7                 Conflicting commands ?
  315.           BGE       DoCmLA6            Yes, error
  316.           SUBA.L    A2,A2              No arguments for SetGCmd
  317.           MOVEQ     #'F',D0            Finish server command
  318.           BSR       SetGCmd            Set up for generic commands
  319.           MOVEQ     #SndGCmdS,D7
  320.           BRA       DoCmLA1            See if options are bundled
  321.  
  322. *** -c connect before ***
  323.  
  324. DoCmLA25  ST        D5                 Set the connect before flag on
  325.           BRA       DoCmLA1            See if options are bundled
  326.  
  327. *** -n connect after ***
  328.  
  329. DoCmLA26  ST        D6                 Set the connect after flag on
  330.           BRA       DoCmLA1            See if options are bundled
  331.  
  332. FatalEr   BSR       ConWrite           Write the message
  333. FatalEr1  SF        D0                 Set a bad completion code
  334.           BRA       SysExod            Return it to system
  335.  
  336.           ends
  337.           END
  338.