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

  1.           nam       Kermit68K
  2.           ttl       IO subroutines module
  3.  
  4. *         Kermit68K: source file K68IOF
  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     K68IOFunctions,0,0,Edition,0,0
  26.  
  27. ********************************* ConInp ******************************ok
  28. *                                                                     *
  29. *  Expect a character from the terminal line.                         *
  30. *                                                                     *
  31. *         Entry conditions : none                                     *
  32. *                                                                     *
  33. *         Exit  conditions : D0.B character received                  *
  34. *                            D1.B AllOk completion code               *
  35. *                                                                     *
  36. ***********************************************************************
  37. ConInp:   MOVEQ     #Terminal,D1       Terminal line I/O channel
  38.           BSR       InpChar            Try to read a character
  39.           TST.B     D1                 All ok ?
  40.           BNE.S     ConInp             No, assume not ready for input, wait
  41.           RTS                          Yes, return
  42.  
  43. ********************************* ConOut ******************************ok
  44. *                                                                     *
  45. *  Send a character to the terminal line.                             *
  46. *                                                                     *
  47. *         Entry conditions : D0.B character to send                   *
  48. *                                                                     *
  49. *         Exit  conditions : D0.B character just sent                 *
  50. *                            D1.B completion code                     *
  51. *                                                                     *
  52. ***********************************************************************
  53. ConOut:   MOVEQ     #Terminal,D1       Terminal line I/O channel
  54.           BSR       OutChar            Try to send the character
  55.           RTS                          Return completion code from OutChar
  56.  
  57. ********************************* HostOut *****************************ok
  58. *                                                                     *
  59. *  Send a character to the host line adding a parity bit.             *
  60. *                                                                     *
  61. *         Entry conditions : D0.B character to send                   *
  62. *                                                                     *
  63. *         Exit  conditions : D0.B character just sent                 *
  64. *                            D1.B completion code                     *
  65. *                                                                     *
  66. ***********************************************************************
  67. HostOut:  BSR       DoPrity            Add an appropriate parity bit
  68.           MOVEQ     #HostLine,D1       Terminal line I/O channel
  69.           BSR       OutChar            Try to send the character
  70.           RTS                          Return completion code from OutChar
  71.  
  72. ********************************* FileOut *****************************ok
  73. *                                                                     *
  74. *  Write a character to the current I/O file. If an error occurs      *
  75. *  during output then set an interruption flag to stop the file       *
  76. *  transfer.                                                          *
  77. *                                                                     *
  78. *         Entry conditions : D0.B character to send                   *
  79. *                                                                     *
  80. *         Exit  conditions : D0.B character just sent                 *
  81. *                            D1.B completion code                     *
  82. *                                                                     *
  83. ***********************************************************************
  84. FileOut:  MOVEQ     #IOFile,D1         Current file I/O channel
  85.           BSR       OutChar            Output the character to it
  86.           TST.B     D1                 Some error ?
  87.           BEQ.S     FileOut1           No, return
  88.           ST        CtlZSeen(A6)       Yes, interrupt the file transfer
  89. FileOut1  RTS
  90.  
  91. ******************************* ConWrite ******************************ok
  92. *                                                                     *
  93. *  Write a null terminated string on the terminal line.               *
  94. *                                                                     *
  95. *         Entry conditions : A0.L pointer to string buffer            *
  96. *                                                                     *
  97. *         Exit  conditions : D1.L destroyed                           *
  98. *                                                                     *
  99. ***********************************************************************
  100. ConWrite: MOVEQ     #Terminal,D1       Terminal line I/O channel
  101.           BSR.S     Write              Write now
  102.           RTS
  103.  
  104. ******************************* TypeUNum ******************************ok
  105. *                                                                     *
  106. *  Write a decimal unsigned number to the terminal line.              *
  107. *                                                                     *
  108. *         Entry conditions : D0.L number to be typed                  *
  109. *                                                                     *
  110. *         Exit  conditions : none                                     *
  111. *                                                                     *
  112. ***********************************************************************
  113. TypeUNum: MOVEM.L   D1-D3,-(A7)        Save working registers
  114.           SF        D1                 Unsigned conversion wanted
  115.           MOVEQ     #0,D2              Null field
  116.           MOVEQ     #10,D3             Base 10
  117.           LEA       DataBuf+34(A6),A0  Point to the end of a temporary buffer
  118.           BSR       IntToAs            Convert the number into a string
  119.           BSR       ConWrite           Write the obtained string
  120.           MOVEM.L   (A7)+,D1-D3        Restore working registers
  121.           RTS
  122.  
  123. ********************************* Write *******************************ok
  124. *                                                                     *
  125. *  Write a null terminated string on a logical channel.               *
  126. *                                                                     *
  127. *         Entry conditions : D1.B channel number                      *
  128. *                            A0.L pointer to string buffer            *
  129. *                                                                     *
  130. *         Exit  conditions : D1.B channel number                      *
  131. *                                                                     *
  132. ***********************************************************************
  133. Write:    MOVE.W    D2,-(A7)           Save working register
  134.           MOVE.B    D1,D2              Save channel number
  135. Write1    MOVE.B    (A0)+,D0           Get a character
  136.           BEQ.S     Write2             Leave if end of string reached
  137.           BSR       OutChar            Send the character, assume no errors
  138.           MOVE.B    D2,D1              Restore channel number
  139.           BRA.S     Write1             Repeat until end of string
  140. Write2    MOVE.W    (A7)+,D2           Restore working register
  141.           RTS
  142.  
  143. ********************************* NewLine *****************************ok
  144. *                                                                     *
  145. *  Send a newline sequence (CR+LF) to the terminal line.              *
  146. *                                                                     *
  147. *         Entry conditions : none                                     *
  148. *                                                                     *
  149. *         Exit  conditions : D0.L destroyed                           *
  150. *                                                                     *
  151. ***********************************************************************
  152. NewLine:  MOVE.L    D1,-(A7)           Save this register, destroyed by ConOut
  153.           MOVEQ     #Asc_CR,D0         Send a CR
  154.           BSR       ConOut
  155.           MOVEQ     #Asc_LF,D0         And then a LF
  156.           BSR       ConOut
  157.           MOVE.L    (A7)+,D1           Restore working register
  158.           RTS
  159.  
  160. ********************************* CCmdIn ******************************ok
  161. *                                                                     *
  162. *  Input a command line from the terminal line, store it to CmdBuf.   *
  163. *                                                                     *
  164. *         Entry conditions : none                                     *
  165. *                                                                     *
  166. *         Exit  conditions : D0.B completion code, false on EOF       *
  167. *                                                                     *
  168. ***********************************************************************
  169. CCmdIn:   MOVEM.L   A0-A1/D1-D3,-(A7)  Save working registers
  170.           LEA       CmdBuf(A6),A0      Start address
  171.           MOVEA.L   A0,A1              Save start address
  172. CCmdIn1   BSR       ConInp             Get a character
  173.           CMPI.B    #Asc_Sub,D0        EOF character ?
  174.           BEQ.S     CCmdIn10           Yes
  175.           CMPI.B    #Asc_CR,D0         CR ?
  176.           BEQ.S     CCmdIn8            Yes
  177.           CMPI.B    #Asc_LF,D0         CR ?
  178.           BEQ.S     CCmdIn8            Yes
  179.           CMPI.B    #Asc_FF,D0         CR ?
  180.           BEQ.S     CCmdIn8            Yes
  181.           CMPI.B    #Asc_Del,D0        Delete ?
  182.           BEQ.S     CCmdIn2            Yes
  183.           CMPI.B    #Asc_BS,D0         Backspace ?
  184.           BNE.S     CCmdIn3            No
  185. CCmdIn2   CMPA.L    A1,A0              At line begin ?
  186.           BEQ.S     CCmdIn1            Yes, no action
  187.           BSR.S     CCmdIn11           No, delete last character
  188.           BRA.S     CCmdIn1            Another character please !
  189. CCmdIn3   CMPI.B    #Asc_Can,D0        Ctrl X ?
  190.           BNE.S     CCmdIn5            No
  191. CCmdIn4   CMPA.L    A1,A0              At line begin ?
  192.           BEQ.S     CCmdIn1            Yes, exit
  193.           BSR.S     CCmdIn11           No, delete last character
  194.           BRA.S     CCmdIn4            Repeat until the whole line is deleted
  195. CCmdIn5   MOVE.B    D0,(A0)+           Store the character
  196.           CMPI.B    #' ',D0            Printable character ?
  197.           BGE.S     CCmdIn6            Yes, print it out
  198.           CMPI.B    #Asc_HT,D0         Horizontal tab ?
  199.           BEQ.S     CCmdIn6            Yes, print it out
  200.           ADDI.B    #64,D0             Make it printable
  201.           MOVEQ     #'^',D2            Prefix character for control
  202.           EXG       D0,D2              Exchange
  203.           BSR       ConOut             Output prefix
  204.           EXG       D0,D2              Exchange
  205. CCmdIn6   BSR       ConOut             Output character
  206. CCmdIn7   MOVE.L    A0,D3              Other characters to read ?
  207.           SUB.L     A1,D3
  208.           CMPI.W    #CmdBufLn,D3
  209.           BLT.S     CCmdIn1            Yes, again please !!!
  210. CCmdIn8   ST        D0                 Return a positive completion code
  211. CCmdIn9   CLR.B     (A0)+              Null as terminator
  212.           MOVEM.L   (A7)+,A0-A1/D1-D3  Restore working registers
  213.           RTS
  214. CCmdIn10  SF        D0                 Return a negative cc, EOF on input
  215.           BRA.S     CCmdIn9            Join common part
  216. CCmdIn11  MOVE.B    -(A0),D0           Back off
  217.           CMPI.B    #' ',D0            Printable character ?
  218.           BGE.S     CCmdIn12           Yes, only one character to delete
  219.           BSR.S     CCmdIn13           No, delete the prefix
  220. CCmdIn12  BSR.S     CCmdIn13           Delete character
  221.           RTS
  222. CCmdIn13  MOVEQ     #Asc_BS,D0         Delete the last character
  223.           BSR       ConOut
  224.           MOVEQ     #' ',D0
  225.           BSR       ConOut
  226.           MOVEQ     #Asc_BS,D0
  227.           BSR       ConOut
  228.           RTS
  229.  
  230. ********************************* FlCmdIn *****************************ok
  231. *                                                                     *
  232. *  Input a command line from a take file, store it to CmdBuf.         *
  233. *                                                                     *
  234. *         Entry conditions : D1.B take file channel number            *
  235. *                                                                     *
  236. *         Exit  conditions : D0.B completion code                     *
  237. *                            D1.B destroyed                           *
  238. *                            D2.B destroyed                           *
  239. *                            A0.L destroyed                           *
  240. *                                                                     *
  241. ***********************************************************************
  242. FlCmdIn:  LEA      CmdBuf(A6),A0       Pointer to target buffer
  243.           MOVE.B   D1,D2               Save the channel number
  244. FlCmdIn1  BSR      InpChar             Try to get a character
  245.           CMP.B    #AllOk,D1           Ok ?
  246.           BEQ.S    FlCmdIn3            Yes
  247.           CMP.B    #EndOfFil,D1        End of file ?
  248.           BEQ.S    FlCmdIn2            Yes, return the proper completion code
  249.           LEA      FlCmdStr(PC),A0     No, some error during read
  250.           BSR      ConWrite            Give this message
  251. FlCmdIn2  SF       D0
  252.           RTS
  253. FlCmdIn3  CMPI.B   #NewLinCh,D0        End of line ?
  254.           BEQ.S    FlCmdIn4            Yes, exit loop
  255.           MOVE.B   D0,(A0)+            No, store the character just read
  256.           MOVE.B   D2,D1               Reload channel number for the next read
  257.           BRA.S    FlCmdIn1            Stay in loop
  258. FlCmdIn4  CLR.B    (A0)                Terminate the command buffer
  259.           ST       D0                  Return a positive completion code
  260.           RTS
  261.  
  262. ********************************* McCmdIn *****************************ok
  263. *                                                                     *
  264. *  Input a command line from a macro, store it to CmdBuf.             *
  265. *                                                                     *
  266. *         Entry conditions : none                                     *
  267. *                                                                     *
  268. *         Exit  conditions : D0.B completion code                     *
  269. *                            A0.L destroyed                           *
  270. *                            A1.L destroyed                           *
  271. *                                                                     *
  272. ***********************************************************************
  273. McCmdIn:  LEA      CmdBuf(A6),A0       Pointer to target buffer
  274.           MOVEA.L  MacroPnt(A6),A1     Pointer to source buffer
  275.           TST.B    (A1)                Are we at the end of the macro body ?
  276.           BEQ.S    McCmdIn4            Yes, end of macro, return false
  277. McCmdIn1  MOVE.B   (A1)+,D0            Get a character
  278.           BEQ.S    McCmdIn2            If null, this is the last line
  279.           CMPI.B   #Asc_CR,D0          End of line ?
  280.           BEQ.S    McCmdIn3            Yes, ...
  281.           MOVE.B   D0,(A0)+            Store the character in target buffer
  282.           BRA.S    McCmdIn1            Loop until end of line
  283. McCmdIn2  SUBQ.L   #1,A1               Still point to the null, next time ...
  284. McCmdIn3  MOVE.L   A1,MacroPnt(A6)     Save the pointer to next macro line
  285.           CLR.B    (A0)                Terminate the command buffer
  286.           ST       D0                  Return a positive completion code
  287.           RTS
  288. McCmdIn4  SF       D0                  End of macro, return a negative cc
  289.           RTS
  290.  
  291. ********************************* SendPad *****************************ok
  292. *                                                                     *
  293. *  Send padding characters to the communication line.                 *
  294. *                                                                     *
  295. *         Entry conditions : none                                     *
  296. *                                                                     *
  297. *         Exit  conditions : D0.B destroyed                           *
  298. *                                                                     *
  299. ***********************************************************************
  300. SendPad:  MOVEM.L   D1-D2,-(A7)        Save working registers
  301.           CLR.W     D2                 Clear counter register
  302.           MOVE.B    OPadNumb(A6),D2    Number of padding char to send
  303.           BRA.S     SendPad2           Enter loop
  304. SendPad1  MOVE.B    OPadChar(A6),D0    Padding character to send
  305.           BSR       HostOut            Send padding character to host line
  306. SendPad2  DBF       D2,SendPad1        Repeat
  307.           MOVEM.L   (A7)+,D1-D2        Restore working registers
  308.           RTS
  309.  
  310. ********************************* TxPackt *****************************ok
  311. *                                                                     *
  312. *  Send the packet stored in SendBuf to the host line.                *
  313. *                                                                     *
  314. *         Entry conditions : none                                     *
  315. *                                                                     *
  316. *         Exit  conditions : none                                     *
  317. *                                                                     *
  318. ***********************************************************************
  319. TxPackt:  MOVEM.L   D1/A0,-(A7)        Save working registers
  320.           BSR       SendPad            Do any requested padding
  321.           LEA       SendBuf(A6),A0     Packet buffer start
  322. TxPackt1  MOVE.B    (A0)+,D0           Get a character
  323.           BEQ.S     TxPackt2           Leave if end of string reached
  324.           BSR       HostOut            Send the character
  325.           ADDQ.L    #1,ChrsSent(A6)    Increment chars sent this transaction
  326.           ADDQ.L    #1,TChsSent(A6)    Increment total characters sent
  327.           BRA.S     TxPackt1           Repeat until end of string
  328. TxPackt2  ADDQ.L    #1,PcksSent(A6)    Increment packets sent this trans
  329.           ADDQ.L    #1,TPckSent(A6)    Increment total packets sent
  330.           MOVEM.L   (A7)+,D1/A0        Restore working registers
  331.           RTS
  332.  
  333. ******************************** InpLine ******************************ok
  334. *                                                                     *
  335. *  Input a line (up to the break char) from the communication line.   *
  336. *                                                                     *
  337. *         Entry conditions : none                                     *
  338. *                                                                     *
  339. *         Exit  conditions : D0.L number of characters received       *
  340. *                            D1.B completion code                     *
  341. *                            A0.L destroyed                           *
  342. *                            D2.L destroyed                           *
  343. *                            D3.W destroyed                           *
  344. *                            D4.B destroyed                           *
  345. *                                                                     *
  346. ***********************************************************************
  347. InpLine:  LEA       RecBuf(A6),A0      Point to receive buffer
  348.           CLR.L     D2                 Clear the character counter
  349.           CLR.W     D3                 Clear the timeout counter
  350.           TST.B     TurnFlag(A6)       Is the turnaround handshake flag on ?
  351.           BEQ.S     InpLine0           No, look for Input EOL as terminator
  352.           MOVE.B    TurnChar(A6),D4    Yes, turnaround character as terminator
  353.           BRA.S     InpLine1
  354. InpLine0  MOVE.B    IEOL(A6),D4        Load the Input End Of Line character
  355. InpLine1  MOVE.B    ITimInt(A6),D3     Preset the timeout counter
  356. InpLine2  BSR       RdChrTO            Get a character
  357.           TST.B     D1                 Timed out ?
  358.           BNE.S     InpLine3           No, continue
  359.           DBF       D3,InpLine2        Yes, repeat unless timeout limit reached
  360.           SF        D1                 Provide a negative completion code
  361.           RTS
  362.  
  363. InpLine3  CMP.B     D4,D0              End Of Line or turnaround character ?
  364.           BEQ.S     InpLine4           Yes
  365.           MOVE.B    D0,(A0)+           No, got a character, save it
  366.           ADDQ.L    #1,D2              Increment the character counter
  367.           CMPI.B    #RBufLen,D2        Receive buffer full ?
  368.           BNE.S     InpLine1           No, again please !
  369. InpLine4  CLR.B     (A0)               Mark the end of buffer
  370.           ADD.L     D2,ChrsRecd(A6)    Increment chars received this transaction
  371.           ADD.L     D2,TChsRecd(A6)    Increment total characters received
  372.           MOVE.L    D2,D0              Return number of characters received
  373.           ST        D1                 Return a positive completion code
  374.           RTS
  375.  
  376. ******************************** RdChrTO ******************************ok
  377. *                                                                     *
  378. *  Called only by InpLine, read a character from the host line with   *
  379. *  1 second software timeout limit. Warning, this routine is          *
  380. *  absolutely provisory.                                              *
  381. *                                                                     *
  382. *         Entry conditions : none                                     *
  383. *                                                                     *
  384. *         Exit  conditions : D0.B character received                  *
  385. *                            D1.B completion code                     *
  386. *                                                                     *
  387. ***********************************************************************
  388. MaxIter   SET       10000              To set the timeout value
  389. *
  390. RdChrTO   MOVE.W    D2,-(A7)           Save the counter register
  391.           MOVE.W    #MaxIter,D2        Set up the timeout counter
  392. RdChrTO1  MOVEQ     #HostLine,D1       Try to read the host line
  393.           BSR       InpChar
  394.           TST.B     D1                 Check completion code
  395.           BEQ.S     RdChrTO2           Character received, handle 8th bit
  396.           DBF       D2,RdChrTO1        Timeout period expired ?
  397.           SF        D1                 Yes, return negative completion code
  398.           MOVE.W    (A7)+,D2           Restore the counter register
  399.           RTS
  400. RdChrTO2  BSR       HndlPar            Handle the parity bit
  401.           ST        D1                 Return positive completion code
  402.           MOVE.W    (A7)+,D2           Restore the counter register
  403.           RTS
  404.  
  405. ********************************* ChkInpF *****************************ok
  406. *                                                                     *
  407. *  Check if an input file exists and is readable.                     *
  408. *                                                                     *
  409. *         Entry conditions : none                                     *
  410. *                                                                     *
  411. *         Exit  conditions : D0.B completion code                     *
  412. *                                                                     *
  413. *                            -3 file exists but protected from read   *
  414. *                            -2 file exists but is not readable       *
  415. *                            -1 inexistent or inaccessable file       *
  416. *                             0 all ok                                *
  417. *                                                                     *
  418. *                            D1.L destroyed                           *
  419. *                            D2.B destroyed                           *
  420. *                                                                     *
  421. ***********************************************************************
  422. ChkInpF:  MOVEQ     #ReadOp,D0         Try to open for read the input file
  423.           MOVEQ     #IOFile,D1         Assign it to this channel number
  424.           BSR       FilOpen            Open now
  425.           TST.B     D0                 Some failure ?
  426.           BEQ.S     ChkInpF1           Yes, return this bad completion code
  427.           MOVEQ     #IOFile,D1         No, try to read a character
  428.           BSR       InpChar
  429.           MOVE.B    D1,D2              Save the returned completion code
  430.           MOVEQ     #IOFile,D1         Close the file just opened
  431.           BSR       FilClose
  432.           TST.B     D2                 The read was successful ?
  433.           BEQ.S     ChkInpF0           Yes, all ok
  434.           CMPI.B    #EndOfFil,D2       No, end of file ?
  435.           BEQ.S     ChkInpF0           Yes, the file is null, but ok
  436.           CMPI.B    #ResChan,D2        No privilege to read this file ?
  437.           BEQ.S     ChkInpF2           Yes, return this bad completion code
  438.           MOVEQ     #-2,D0             No, some other error, unreadable file cc
  439.           RTS
  440. ChkInpF0  MOVEQ     #0,D0              Return all ok
  441.           RTS
  442. ChkInpF1  MOVEQ     #-1,D0             Return inexistent file cc
  443.           RTS
  444. ChkInpF2  MOVEQ     #-3,D0             Return protected file cc
  445.           RTS
  446.  
  447. ********************************* ChkOutF *****************************ok
  448. *                                                                     *
  449. *  Check if an output file can be created.                            *
  450. *                                                                     *
  451. *         Entry conditions : none                                     *
  452. *                                                                     *
  453. *         Exit  conditions : D0.B completion code                     *
  454. *                                                                     *
  455. *                            -1 permission denied                     *
  456. *                             0 all ok                                *
  457. *                                                                     *
  458. ***********************************************************************
  459. ChkOutF:  MOVEQ     #0,D0              Always succeeds for now
  460.           RTS
  461.  
  462. ********************************* OpnInpF *****************************ok
  463. *                                                                     *
  464. *  Try to open an existing file for input.                            *
  465. *                                                                     *
  466. *         Entry conditions : A0.L pointer to the file name            *
  467. *                                                                     *
  468. *         Exit  conditions : A0.L pointer to the file name            *
  469. *                            D0.B completion code                     *
  470. *                            D1.L destroyed                           *
  471. *                                                                     *
  472. ***********************************************************************
  473. OpnInpF:  MOVE.B    MStrFlag(A6),D0    Input from memory string ?
  474.           BNE.S     OpnInpF1           Yes, return a positive cc
  475.           MOVEQ     #ReadOp,D0         Try to open the input file
  476.           MOVEQ     #IOFile,D1
  477.           BSR       FilOpen
  478.           TST.B     D0                 Open succeed ?
  479.           BEQ.S     OpnInpF1           Yes, return this completion code
  480.           BSR       CRemTLoc           No, convert name to local form
  481.           MOVEQ     #ReadOp,D0         Try again to open the input file
  482.           MOVEQ     #IOFile,D1
  483.           BSR       FilOpen
  484. OpnInpF1  RTS                          Return cc from FilOpen
  485.  
  486. ********************************* OpnOutF *****************************ok
  487. *                                                                     *
  488. *  Try to open an existing file for output.                           *
  489. *                                                                     *
  490. *         Entry conditions : A0.L pointer to the file name            *
  491. *                            A1.L pointer to the file name            *
  492. *                                 target buffer                       *
  493. *                                                                     *
  494. *         Exit  conditions : A0.L pointer to the file name target     *
  495. *                                 buffer containing the file name     *
  496. *                                 under wich the file was opened      *
  497. *                            D0.B completion code                     *
  498. *                            D1.L destroyed                           *
  499. *                                                                     *
  500. ***********************************************************************
  501. OpnOutF:  MOVE.B    TermOut(A6),D0     Terminal output wanted ?
  502.           BNE.S     OpnOutF3           Yes, return a positive cc
  503.           MOVE.B    CtlXSeen(A6),D0    Some interruption ?
  504.           OR.B      CtlZSeen(A6),D0
  505.           BNE.S     OpnOutF3           Yes, don't destroy existing file
  506.           EXG       A0,A1              Exchange buffers pointers
  507.           MOVEQ     #FilNamML,D0       Load buffers length
  508.           BSR       CopyStr            Fill target buffer, copy from source
  509.           TST.B     FNameCnv(A6)       File names conversion ?
  510.           BEQ.S     OpnOutF1           No, proceed
  511.           BSR       CRemTLoc           Yes, convert file name to local form
  512. OpnOutF1  TST.B     Warning(A6)        File collision avoidance ?
  513.           BEQ.S     OpnOutF2           No, proceed
  514.           BSR       ChkInpF            Yes, check if file exists
  515.           CMPI.B    #-1,D0             File exists ?
  516.           BEQ.S     OpnOutF2           No, proceed
  517.           BSR       NewName            Yes, make a new name
  518. OpnOutF2  MOVEQ     #WriteOp,D0        Finally open the file for output
  519.           MOVEQ     #IOFile,D1
  520.           BSR       FilOpen
  521. OpnOutF3  RTS                          Return the completion code
  522.  
  523. ********************************* ClsInpF *****************************ok
  524. *                                                                     *
  525. *  Close the current input file.                                      *
  526. *                                                                     *
  527. *         Entry conditions : none                                     *
  528. *                                                                     *
  529. *         Exit  conditions : D0.L destroyed                           *
  530. *                            D1.L destroyed                           *
  531. *                                                                     *
  532. ***********************************************************************
  533. ClsInpF:  TST.B     MStrFlag(A6)       Input from memory string ?
  534.           BEQ.S     ClsInpF1           No, close the input file
  535.           SF        MStrFlag(A6)       Yes, reset flag
  536.           BRA.S     ClsInpF2
  537. ClsInpF1  MOVEQ     #IOFile,D1         Close the output file
  538.           BSR       FilClose
  539. ClsInpF2  MOVE.B    CtlXSeen(A6),D0    File interrupt ...
  540.           OR.B      CtlZSeen(A6),D0    ... or file group interrupt ?
  541.           BNE.S     ClsInpF3           Yes, give discard message
  542.           MOVEQ     #FlTranOk,D0       No, give comforting messages
  543.           BSR       Screen
  544.           BRA.S     ClsInpF4
  545. ClsInpF3  MOVEQ     #FlDiscrd,D0       Give discard message
  546.           BSR       Screen
  547. ClsInpF4  SF        CtlXSeen(A6)       Reset file interrupt flag
  548.           CLR.B     FilName(A6)        Nullify current file name
  549.           RTS
  550.  
  551. ********************************* ClsOutF *****************************ok
  552. *                                                                     *
  553. *  Close the current output file.                                     *
  554. *                                                                     *
  555. *         Entry conditions : none                                     *
  556. *                                                                     *
  557. *         Exit  conditions : D0.L destroyed                           *
  558. *                            D1.L destroyed                           *
  559. *                            A0.L destroyed                           *
  560. *                                                                     *
  561. ***********************************************************************
  562. ClsOutF:  TST.B     TermOut(A6)        Output to the terminal line ?
  563.           BNE.S     ClsOutF3           Yes, just reset flag and return
  564.           LEA       FilName(A6),A0     No, point to current file name
  565.           TST.B     (A0)               File open ?
  566.           BEQ.S     ClsOutF1           No
  567.           MOVEQ     #IOFile,D1         Yes, close the output file
  568.           BSR       FilClose
  569.           MOVE.B    CtlXSeen(A6),D0    File interrupt ...
  570.           OR.B      CtlZSeen(A6),D0    ... or file group interrupt ?
  571.           BEQ.S     ClsOutF1           No, just keep it
  572.           TST.B     Keep(A6)           Yes, keeping incomplete files ?
  573.           BNE.S     ClsOutF1           Yes
  574.           BSR       FilDelet           No, discard it
  575.           MOVEQ     #FlDiscrd,D0       Give discard message
  576.           BSR       Screen
  577.           BRA.S     ClsOutF2           Nullify file name and return
  578. ClsOutF1  MOVEQ     #FlTranOk,D0       Give comforting messages
  579.           BSR       Screen
  580. ClsOutF2  CLR.B     (A0)               Nullify current file name
  581.           RTS
  582. ClsOutF3  SF        TermOut(A6)        Clear the terminal output flag
  583.           RTS
  584.  
  585. ********************************* ChekInt *****************************ok
  586. *                                                                     *
  587. *  Terminal interrupts handler.                                       *
  588. *                                                                     *
  589. *         Entry conditions : none                                     *
  590. *                                                                     *
  591. *         Exit  conditions : D0.L destroyed                           *
  592. *                            D1.L destroyed                           *
  593. *                            A1.L destroyed                           *
  594. *                                                                     *
  595. ***********************************************************************
  596. ChekInt:  TST.B     Local(A6)          Are we running in local mode ?
  597.           BEQ.S     ChekInt1           No, return
  598.           TST.B     Quiet(A6)          Quiet requested ?
  599.           BNE.S     ChekInt1           Yes, return
  600.           MOVEQ     #Terminal,D1       Try to get a character from terminal
  601.           BSR       InpChar
  602.           TST.B     D1                 Success ?
  603.           BNE.S     ChekInt1           No, return
  604.           CMPI.B    #Asc_Sub,D0        Control Z ?
  605.           BEQ.S     ChekInt2           Yes
  606.           CMPI.B    #Asc_Can,D0        Control X ?
  607.           BEQ.S     ChekInt3           Yes, set the file interrupt flag
  608.           CMPI.B    #Asc_DC2,D0        Control R ?
  609.           BEQ.S     ChekInt4           Yes, resend the last packet
  610.           MOVEQ     #Asc_Bel,D0        No, ignore, ring the bell
  611.           BSR       ConOut
  612. ChekInt1  RTS
  613.  
  614. ChekInt2  LEA       CnBchStr(PC),A1    Cancel batch
  615.           MOVEQ     #TxtDlBeg,D0       Give message
  616.           BSR       Screen
  617.           ST        CtlZSeen(A6)       Set the file batch interrupt flag
  618.           RTS
  619.  
  620. ChekInt3  LEA       CnFilStr(PC),A1    Cancel file
  621.           MOVEQ     #TxtDlBeg,D0       Give message
  622.           BSR       Screen
  623.           ST        CtlXSeen(A6)       Set the file interrupt flag
  624.           RTS
  625.  
  626. ChekInt4  LEA       ReSndStr(PC),A1    Resend packet
  627.           MOVEQ     #TxtDlBeg,D0       Give message
  628.           BSR       Screen
  629.           BSR       Resend             Resend the last packet
  630.           RTS
  631.  
  632. ********************************** Screen *****************************ok
  633. *                                                                     *
  634. *  Screen diplay routine.                                             *
  635. *                                                                     *
  636. *         Entry conditions : D0.B request code                        *
  637. *                            D1.B packet type or pseudotype           *
  638. *                            D2.B packet number                       *
  639. *                            D3.B packet length                       *
  640. *                            A1.L pointer to a string to write        *
  641. *                                                                     *
  642. *         Exit  conditions : none                                     *
  643. *                                                                     *
  644. ***********************************************************************
  645. ScrnMxLL  EQU       78                 Maximum line length
  646.  
  647. Screen:   TST.B     Display(A6)        The display flag is off ?
  648.           BEQ.S     Screen1            Yes, no update
  649.           TST.B     Quiet(A6)          Are we requested to be quiet ?
  650.           BEQ.S     Screen2            No, update the screen
  651. Screen1   RTS
  652.  
  653. Screen2   MOVEM.L   A0-A1/D1-D7,-(A7)  Save some registers
  654.           MOVE.B    LinLngth(A6),D6    Length of the current screen line
  655.           CLR.W     D4                 Compute the length of the passed string
  656. Screen3   TST.B     (A1,D4.W)          End of line ?
  657.           BEQ.S     Screen4            Yes, continue
  658.           ADDQ.B    #1,D4              No, count
  659.           BRA.S     Screen3            Repeat until end of line
  660.  
  661. Screen4   MOVEQ     #ScrnMxRq,D5       Maximum request code
  662.           CMP.W     D5,D0              Request code out of range ?
  663.           BHI       Screen30           Yes, return
  664.           ADD.W     D0,D0              No, scale it
  665.           MOVE.W    Screen5(PC,D0.W),D0 Relative address of the service routine
  666.           JMP       Screen5(PC,D0.W)   Jump to it
  667.  
  668. Screen5   DC.W      Screen6-Screen5    SFilName
  669.           DC.W      Screen7-Screen5    RFilName
  670.           DC.W      Screen9-Screen5    FlAsName
  671.           DC.W      Screen11-Screen5   XPckData
  672.           DC.W      Screen12-Screen5   FlTranOk
  673.           DC.W      Screen14-Screen5   FlDiscrd
  674.           DC.W      Screen16-Screen5   FlIntrrp
  675.           DC.W      Screen18-Screen5   FlSkippd
  676.           DC.W      Screen19-Screen5   PackType
  677.           DC.W      Screen22-Screen5   TranCmpl
  678.           DC.W      Screen23-Screen5   ErrMessg
  679.           DC.W      Screen24-Screen5   WarnMess
  680.           DC.W      Screen25-Screen5   UndelTxt
  681.           DC.W      Screen27-Screen5   TxtDlBeg
  682.           DC.W      Screen28-Screen5   TxtDlEnd
  683.  
  684. Screen6   LEA       ScrnStr1(PC),A0    Display outgoing file name
  685.           BRA.S     Screen8
  686.  
  687. Screen7   LEA       ScrnStr2(PC),A0    Display inbound file name
  688.  
  689. Screen8   BSR       NewLine            Display file name
  690.           BSR       ConWrite
  691.           MOVE.B    #10,D6
  692.           MOVEA.L   A1,A0
  693.           BSR       ConWrite
  694.           MOVEQ     #' ',D0
  695.           BSR       ConOut
  696.           ADD.B     D4,D6
  697.           ADDQ.B    #1,D6
  698.           BRA       Screen30
  699.  
  700. Screen9   MOVE.B    D4,D5              Display file as-name
  701.           ADD.B     D6,D5
  702.           CMPI.B    #ScrnMxLL-3,D5
  703.           BLS.S     Screen10
  704.           BSR       NewLine
  705.           CLR.B     D6
  706. Screen10  LEA       ScrnStr3(PC),A0
  707.           BSR       ConWrite
  708.           MOVEA.L   A1,A0
  709.           BSR       ConWrite
  710.           MOVEQ     #' ',D0
  711.           BSR       ConOut
  712.           ADD.B     D4,D6
  713.           ADDQ.B    #3+1,D6
  714.           CMPI.B    #ScrnMxLL,D6
  715.           BLS       Screen30
  716.           BSR       NewLine
  717.           CLR.B     D6
  718.           BRA       Screen30
  719.  
  720. Screen11  BSR       NewLine            Display X-packet data
  721.           MOVEA.L   A1,A0
  722.           BSR       ConWrite
  723.           BSR       NewLine
  724.           CLR.B     D6
  725.           BRA       Screen30
  726.  
  727. Screen12  CMPI.B    #ScrnMxLL-5,D6     Successful file transfer message
  728.           BLS.S     Screen13
  729.           BSR       NewLine
  730.           CLR.B     D6
  731. Screen13  LEA       ScrnStr4(PC),A0
  732.           BSR       ConWrite
  733.           ADDQ.B    #5,D6
  734.           BRA       Screen30
  735.  
  736. Screen14  CMPI.B    #ScrnMxLL-12,D6    File discarded message
  737.           BLS.S     Screen15
  738.           BSR       NewLine
  739.           CLR.B     D6
  740. Screen15  LEA       ScrnStr5(PC),A0
  741.           BSR       ConWrite
  742.           ADDI.B    #12,D6
  743.           BRA       Screen30
  744.  
  745. Screen16  CMPI.B    #ScrnMxLL-14,D6    File transfer interrupted message
  746.           BLS.S     Screen17
  747.           BSR       NewLine
  748.           CLR.B     D6
  749. Screen17  LEA       ScrnStr6(PC),A0
  750.           BSR       ConWrite
  751.           ADDI.B    #14,D6
  752.           BRA       Screen30
  753.  
  754. Screen18  BSR       NewLine            File skipped message
  755.           LEA       ScrnStr7(PC),A0
  756.           BSR       ConWrite
  757.           MOVEA.L   A1,A0
  758.           BSR       ConWrite
  759.           BSR       NewLine
  760.           CLR.B     D6
  761.           BRA       Screen30
  762.  
  763. *                                      Display packet type or pseudo-type
  764. Screen19  CMPI.B    #'Y',D1            ACK packet ?
  765.           BEQ       Screen30           Yes, return
  766.           CMPI.B    #'D',D1            Data packet ?
  767.           BNE.S     Screen20           No
  768.           ANDI.B    #3,D2              Yes, only display every 4 packets
  769.           BNE       Screen30           Return
  770.           MOVEQ     #'.',D0
  771.           BRA.S     Screen21
  772. Screen20  MOVE.B    D1,D0              Display the packet type
  773. Screen21  BSR       ConOut
  774.           ADDQ.B    #1,D6              Increment current line length
  775.           CMPI.B    #ScrnMxLL,D6       Near the right margin ?
  776.           BLS.S     Screen30           No, return
  777.           BSR       NewLine            Yes, start a new line
  778.           CLR.B     D6                 Reset the counter
  779.           BRA.S     Screen30
  780.  
  781. Screen22  MOVEQ     #Asc_Bel,D0        Transaction complete message (bell)
  782.           BSR       ConOut
  783.           BSR       NewLine            Start a new line
  784.           BRA.S     Screen30
  785.  
  786. Screen23  BSR       NewLine            Error message
  787.           MOVEQ     #'?',D0
  788.           BSR       ConOut
  789.           MOVEA.L   A1,A0
  790.           BSR       ConWrite
  791.           BSR       NewLine
  792.           CLR.B     D6
  793.           BRA.S     Screen30
  794.  
  795. Screen24  BSR       NewLine            Warning message
  796.           MOVEA.L   A1,A0
  797.           BSR       ConWrite
  798.           BSR       NewLine
  799.           CLR.B     D6
  800.           BRA.S     Screen30
  801.  
  802. Screen25  ADD.B     D4,D6              Undelimited text
  803.           CMPI.B    #ScrnMxLL,D6
  804.           BLS.S     Screen26
  805.           BSR       NewLine
  806.           MOVE.B    D4,D6
  807. Screen26  MOVEA.L   A1,A0
  808.           BSR       ConWrite
  809.           BRA.S     Screen30
  810.  
  811. Screen27  BSR       NewLine            Text delimited at beginning
  812.           MOVEA.L   A1,A0
  813.           BSR       ConWrite
  814.           MOVE.B    D4,D6
  815.           BRA.S     Screen30
  816.  
  817. Screen28  ADD.B     D4,D6              Text delimited at end
  818.           CMPI.B    #ScrnMxLL,D6
  819.           BLS.S     Screen29
  820.           BSR       NewLine
  821.           MOVE.B    D4,D6
  822. Screen29  MOVEA.L   A1,A0
  823.           BSR       ConWrite
  824.           BSR       NewLine
  825. *          BRA.S     Screen30
  826.  
  827. Screen30  MOVE.B    D6,LinLngth(A6)
  828.           MOVEM.L   (A7)+,A0-A1/D1-D7
  829.           RTS
  830.  
  831.           ends
  832.           END
  833.