home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / trs80model4 / m4get.asm < prev    next >
Assembly Source File  |  1986-10-21  |  20KB  |  688 lines

  1. ;    M4GET/ASM
  2. ;    RECEIVE    COMMAND
  3. READ    EQU    $
  4.     CALL    NEWLIN
  5.     NSTATE    'R'        ;Set initial protocol state
  6.     LD    DE,DATA        ;WHERE TO PUT THE TEXT (IF ANY.)
  7.     LD    A,CMTXT
  8.     CALL    COMND        ;GET EITHER SOME TEXT OR A CONFIRM.
  9.     JP    KERMT3        ;DIDN'T GET ANYTHING.
  10.     OR    A        ;GET ANY CHARS?
  11.     JR    Z,READ1        ;NOPE, JUST A REGULAR SEND.
  12.     LD    (ARGBLK+1),A    ;STORE THE NUMBER OF CHARS.
  13.     LD    (TEMP4),A    ;Save the length
  14.     EX    DE,HL       ;GET POINTER INTO HL.
  15.     LD    (HL),EOS    ;Put in the print terminator
  16.     NSTATE    'r'        ;Set state to receive init with file
  17. READ1    CALL    INIT        ;Clear input line and init buffers
  18.     LD    HL,0        ;Reset all the flags
  19.     LD    (NUMPKT),HL    ;SET THE NUMBER OF PACKETS TO ZERO.
  20.     LD    (NUMRTR),HL    ;SET THE NUMBER OF RETRIES TO ZERO.
  21.     LD    (KTRANS),HL
  22.     XOR    A
  23.     LD    (PKTNUM),A    ;SET THE PACKET NUMBER TO ZERO.
  24.     LD    (NUMTRY),A    ;SET THE NUMBER OF TRIES TO ZERO.
  25.     LD    (CZSEEN),A    ;Reset the control-Z seen flag
  26.     LD    A,'R'        ;Get the state character
  27.     LD    (DISFLG),A    ;Set the display flag
  28.     CALL    CONDCHR        ;Display it as well
  29.     CALL    CLRPRT        ;CLEAR OUT THE COMMUNICATIONS PORT
  30.     STROUT    HELPMSG
  31.     CALL    PROTO
  32.     JP    KERMIT
  33. ;
  34. ;    This is the complete state
  35. ;
  36. COMP    EQU    $
  37.     LD    DE,INFMS3    ;PUT IN "COMPLETE" MESSAGE.
  38.     LD    A,(CZSEEN)
  39.     OR    A        ;...
  40.     JR    Z,COMP1
  41.     XOR    A        ;YES, CLEAR FLAG.
  42.     LD    (CZSEEN),A
  43.     LD    DE,INMS13    ;ISSUE "INTERRUPTED" MESSAGE.
  44. COMP1    LD    A,(DISFLG)    ;But only if we are supposed to
  45.     OR    A
  46.     CALL    NZ,FINMES    ;PRINT COMPLETION MESSAGE
  47.     JP    KERMIT
  48. ;
  49. ;    This is the abort state
  50. ;
  51. SABORT    EQU    $
  52.     LD    DE,INFMS4    ;Message to print
  53.     JR    COMP1        ;Go print it conditionally
  54. ;
  55. ;    Initialize the buffers, and clear the line
  56. ;
  57. INIT    XOR    A        ;BUFFER SIZE.
  58.     LD    (CHRCNT),A    ;NUMBER OF CHARS LEFT.
  59.     LD    HL,BUFF        ;ADDR FOR BEGINNING.
  60.     LD    (BUFPNT),HL    ;STORE ADDR FOR BEGINNING.
  61.     CALL    CLRPRT
  62.     RET    
  63. ;
  64. ;    RECEIVE    ROUTINES
  65. ;
  66. ;    RECEIVE    INIT with no previous file header
  67. ;
  68. RINIT    CALL    CHKTRYS        ;Check retry threshold
  69.     LD    A,'1'        ;RESET BLOCK CHECK TYPE TO SINGLE CHAR
  70.     LD    (CURCHK),A    ;STORE AS CURRENT TYPE FOR INITIALIZATION
  71.     CALL    RPACK        ;GET A PACKET.
  72.     JP    NAK        ;TRASHED PACKET NAK, RETRY.
  73.     JR    RINIT_1
  74. ;
  75. ;    This entry point is for GET's.  The file name is in DATA, and
  76. ;    and 'R' packet will be sent out to ask for the file.
  77. ;
  78. RINITF    CALL    CHKTRYS        ;Check retry threshold
  79.     LD    A,'1'        ;START WITH SINGLE CHARACTER CHECKSUM
  80.     LD    (CURCHK),A    ;SAVE THE TYPE
  81.     LD    A,(TEMP4)    ;Get the length
  82.     LD    (ARGBLK+1),A    ;Put it in the packet
  83.     XOR    A        ;Start at packet zero
  84.     LD    (ARGBLK),A
  85.     LD    A,'R'        ;Send RECV INIT
  86.     CALL    SPACK
  87.     JP    RECABORT    ;Die if SEND fails
  88.     LD    A,'1'        ;Reset the blk check type to 1
  89.     LD    (CURCHK),A    ;Store it
  90.     CALL    RPACK        ;Get a packet
  91.     JP    QUIT        ;Trashed, return to protocol
  92.     JR    RINIT_1        ;Join other code
  93. ;
  94. ;    Common receive init code
  95. ;
  96. RINIT_1    EQU    $
  97.     IFANOT    'S',RINIT3    ;Send initiate packet?
  98.     LD    A,(NUMTRY)    ;GET THE NUMBER OF TRIES.
  99.     LD    (OLDTRY),A    ;SAVE IT.
  100.     XOR    A
  101.     LD    (NUMTRY),A    ;RESET THE NUMBER OF TRIES.
  102.     LD    A,(ARGBLK)    ;RETURNED PACKET NUMBER.  (SYNC THEM.)
  103.     CALL    INCPKT        ;Increment the packet number
  104.     CALL    INCDISPKT
  105.     LD    A,(ARGBLK+1)    ;GET THE NUMBER OF ARGUMENTS RECEIVED.
  106.     LD    HL,DATA        ;GET A POINTER TO THE DATA.
  107.     CALL    SPAR        ;GET THE DATA INTO THE PROPER VARIABLES.
  108.     LD    HL,DATA        ;GET A POINTER TO OUR DATA BLOCK.
  109.     CALL    RPAR        ;SET UP THE RECEIVE PARAMETERS.
  110.     LD    (ARGBLK+1),A    ;STORE THE RETURNED NUMBER OF ARGUMENTS.
  111.     LD    A,'Y'        ;ACKNOWLEDGE PACKET.
  112.     CALL    SPACK        ;SEND THE PACKET.
  113.     JP    RECABORT        ;FAILED, ABORT.
  114.     LD    A,(INICHK)
  115.     LD    (CURCHK),A    ;FOR ALL FUTURE PACKETS
  116.     NSTATE    'f'
  117.     LD    A,'F'
  118.     CALL    CONDCHR        ;Display which packet
  119.     RET    
  120. RINIT3    IFANOT    'E',NAK_0    ;Is it a NAK ?
  121.     CALL    ERROR
  122.     JP    RECABORT
  123. ;
  124. ;    THESE ARE SOME UTILITY ROUTINES.
  125. ;
  126. ;    RECABORT
  127. ;
  128. RECABORT    EQU    $
  129.     LD    IX,RTRANS    ;Get the receive data area
  130.     CALL    UPDTRANS    ;Update the transfer statics
  131. ABORT    NSTATE    'A'        ;Set state to abort
  132. ABORT_1    LD    A,(LOGTRAN)    ;Check if logging active
  133.     CP    1        ;Is it on?
  134.     RET    NZ        ;Return if not
  135.     LD    DE,TRFCB    ;Get the FCB
  136.     TRLOG    TRANABRT,ABORT_2;Log the aborted message
  137.     RET            ;Return
  138. ;
  139. ;    Close up after a tranaction log error
  140. ;
  141. ABORT_2    XOR    A        ;Reset the logging active flag
  142.     LD    (LOGTRAN),A
  143.     LD    DE,TRFCB    ;Close the log file
  144.     CALL    XCLOSE
  145.     RET
  146. ;
  147. ;    SNDABORT
  148. ;
  149. SNDABORT    NSTATE    'A'
  150.     LD    IX,STRANS
  151.     CALL    UPDTRANS
  152.     JP    ABORT_1
  153. ;
  154. ;    Nack a packet.
  155. ;
  156. NAK_0    XOR    A        ;Reset to first packet
  157.     LD    (PKTNUM),A    ;Set the packet number
  158.     JR    NAK        ;Join NAK code
  159. ;
  160. NAK_RTR    CALL    UPDRTR        ;Update retries
  161. ;
  162. NAK    LD    A,(PKTNUM)    ;GET THE PACKET NUMBER WE'RE WAITING FOR.
  163.     LD    (ARGBLK),A
  164.     XOR    A        ;NO DATA.
  165.     LD    (ARGBLK+1),A
  166.     LD    A,'N'        ;NAK THAT PACKET.
  167.     CALL    SPACK
  168.     JP    RECABORT        ;GIVE UP.
  169.     LD    A,'N'        ;Display NAKed character
  170.     CALL    CONDCHR
  171.     RET            ;GO AROUND AGAIN.
  172. ;
  173. ;    Update the retry count
  174. ;
  175. UPDRTR    EQU    $
  176.     LD    HL,(NUMRTR)
  177.     INC    HL        ;INCREMENT THE NUMBER OF RETRIES
  178.     LD    (NUMRTR),HL
  179.     RET    
  180. ;
  181. ;    THIS ROUTINE SETS UP THE DATA FOR INIT PACKET (EITHER THE
  182. ;    SEND_INIT OR ACK PACKET).
  183. ;
  184. RPAR    ADDPUT    RPSIZ        ;GET THE RECEIVE PACKET SIZE.
  185.     ADDPUT    STIME        ;Add send timeout
  186.     ADDPUT    RPAD        ;Add padding amount
  187.     LD    A,(RPADCH)    ;Get the pad character
  188.     ADD    A,100O        ;UNCONTROL IT.
  189.     PUTHL    A        ;Put the pad character in
  190.     ADDPUT    REOL        ;Put the end of line character
  191.     LD    A,(RQUOTE)    ;GET THE QUOTE CHAR.
  192.     PUTHL    A
  193.     LD    A,(EBQFLG)    ;Is eighth bit quoting on?
  194.     IFZ    RPAR1        ;If not, then say no
  195.     PUTHL    'Y'        ;Say yes to anything
  196.     JR    RPAR2
  197. RPAR1    PUTHL    'N'        ;Say no eighth bit quoting
  198. RPAR2    LD    A,(INICHK)    ;Check type
  199.     PUTHL    A
  200.     LD    A,(RPTQ)    ;Get the repeat quote
  201.     PUTHL    A
  202.     LD    A,9        ;Nine pieces of data
  203.     RET    
  204. ;
  205. ;    Tochar() A, and store indirect HL, then increment HL
  206. ;
  207. TCHPUT    ADD    A,' '        ;Tochar(A)
  208.     PUTHL    A        ;Store it, and increment
  209.     RET            ;Return
  210. ;
  211. ;    THIS ROUTINE READS IN ALL THE SEND_INIT PACKET INFORMATION.
  212. ;
  213. SPAR    LD    (TEMP4),A    ;Save the number of arguments
  214.     PUSH    BC
  215.     XOR    A
  216.     LD    B,A
  217.     LD    (RPTFLG),A    ;Set everything to default
  218.     CALL    CHKSPAR        ;Check number of characters in packet
  219.     LD    A,(HL)        ;Get THEIR Max packet size
  220.     SUB    20H        ;Make it real
  221.     LD    (SPSIZ),A    ;Save the value
  222.     CALL    CHKSPAR        ;Check the count
  223.     GETHL    A
  224.     SUB    20H        ;Make it real
  225.     LD    (RTIME),A    ;Send packet timeout value
  226.     CALL    CHKSPAR        ;Check the count
  227.     GETHL    A
  228.     SUB    20H        ;Make it real
  229.     LD    (SPAD),A    ;Save the padding character
  230.     CALL    CHKSPAR        ;Check the count of characters
  231.     GETHL    A
  232.     ADD    A,100O        ;RE-CONTROLIFY IT.
  233.     AND    7FH        ;Keep us honest
  234.     LD    (SPADCH),A    ;Save the padding character
  235.     CALL    CHKSPAR        ;Check the count
  236.     GETHL    A
  237.     SUB    20H        ;Make it the real value
  238.     LD    (SEOL),A    ;Save the value
  239.     CALL    CHKSPAR        ;Check the count
  240.     GETHL    A
  241.     LD    (SQUOTE),A    ;Save it
  242.     CALL    CHKSPAR        ;Check the count
  243.     INC    HL
  244.     LD    A,(EBQFLG)
  245.     IFZ    SPAR7
  246.     LD    A,(HL)
  247.     IFA    'Y',SPAR4
  248.     IFANOT    'N',SPAR5
  249.     XOR    A
  250.     JR    SPAR6
  251. SPAR4    LD    A,'&'
  252. SPAR5    LD    (EBQ),A
  253. SPAR6    LD    (EBQFLG),A
  254. SPAR7    CALL    CHKSPAR        ;Check the count
  255.     GETHL    A
  256.     LD    C,A        ;COPY VALUE
  257.     LD    A,(CHKTYP)    ;GET OUR TYPE
  258.     IFA    C,SPAR8
  259.     LD    A,'1'        ;NO, USE SINGLE CHARACTER
  260. SPAR8    LD    (INICHK),A
  261.     CALL    CHKSPAR        ;Check the count
  262.     GETHL    A
  263.     IFA    ' ',SPAR10
  264.     LD    C,A
  265.     LD    (RPTQ),A    ;Save it
  266.     LD    (RPTFLG),A
  267. SPAR10    EQU    $
  268.     POP    BC
  269.     RET            ;AND RETURN
  270. ;
  271. ;    Check the count of characters left in the packet.
  272. ;
  273. CHKSPAR    EQU    $
  274.     LD    A,(TEMP4)
  275.     INC    B
  276.     CP    B
  277.     RET    P
  278.     POP    HL        ;Remove return address
  279.     POP    BC        ;Restore original BC
  280.     RET            ;Return to caller
  281. ;
  282. ;    RECEIVE    FILE
  283. ;
  284. RFILE    CALL    CHKTRYS        ;Check retry threshold
  285.     CALL    RPACK        ;GET A PACKET.
  286.     JP    NAK        ;TRASHED PACKET NAK, RETRY.
  287.     IFANOT    'S',RFILE2    ;If not send init, then jump
  288.     CALL    CHKOLD        ;Make sure we have not surpassed retries
  289.     CALL    CHKBLKDEC    ;Check if previous packet number
  290.     JP    NZ,NAK_RTR    ;No, NAK it, and try again
  291.     CALL    UPDRTR        ;Update the retry count.
  292.     LD    HL,DATA        ;Get the data address
  293.     CALL    RPAR        ;Set up the parameter information
  294.     LD    (ARGBLK+1),A    ;Save the number of bytes in the packet
  295.     LD    A,'Y'        ;Acknowledge with parameters
  296.     CALL    SPACK        ;Send the packet
  297.     JP    RECABORT    ;Send failed, abort
  298.     LD    A,'S'        ;Show the state as still send init
  299.     CALL    CONDCHR
  300.     RET    
  301. ;
  302. RFILE2    IFANOT    'Z',RFILE3    ;EOF packet?  Jump if not
  303.     CALL    CHKOLD        ;Check retry treshold
  304.     CALL    CHKBLKDEC    ;Was it previous packet in sequence?
  305.     JP    NZ,NAK_RTR    ;No, NAK it and try again
  306.     CALL    UPDRTR        ;Update the number of retries
  307.     XOR    A        ;Set length to zero
  308.     LD    (ARGBLK+1),A    ;No data
  309.     LD    A,'Y'        ;Send an ACK
  310.     CALL    SPACK        ;Send the packet
  311.     JP    RECABORT    ;Send failed, abort
  312.     LD    A,'Z'        ;Show state as EOF
  313.     CALL    CONDCHR
  314.     RET    
  315. RFILE3    IFANOT    'F',RFILE4    ;Jump if not FILE header packet
  316.     CALL    CHKBLK        ;Check packet number against current
  317.     JP    NZ,NAK_RTR    ;If not the same, then NAK and try again
  318.     CALL    INCPKT        ;Increment the packet number
  319.     CALL    INCDISPKT    ;Increment the real packet count
  320.     LD    A,'F'
  321.     LD    (DISFLG),A    ;Set the non-generic mode flag
  322.     CALL    CONDCHR        ;Print the state character
  323.     CALL    GOFIL        ;Get the file
  324.     JP    RECABORT    ;Abort on an error
  325.     CALL    INIT        ;Initialize everything else
  326.     CALL    NUM2OLD        ;Reset the retry number
  327.     LD    (ARGBLK+1),A    ;On return, A is zero, so NO DATA
  328.     LD    A,'Y'        ;Send an ACK
  329.     CALL    SPACK        ;Send the packet
  330.     JP    RECABORT    ;Send failed, abort
  331.     NSTATE    't'        ;Set the state to receive transition
  332.     LD    A,(CZSEEN)    ;Check if user requested EOF or EOT
  333.     CP    'Z'        ;Was it EOF?
  334.     RET    Z        ;If it was EOF, then not yet
  335.     XOR    A        ;Otherwise, must be EOT, so reset
  336.     LD    (CZSEEN),A    ;Reset the flag
  337.     RET            ;And return, ignoring other states
  338. RFILE4    IFANOT    'B',RFILE5    ;Jump if not EOT
  339.     CALL    CONDCHR        ;Display the state
  340.     CALL    CHKBLK        ;Check packet number against current
  341.     JP    NZ,NAK_RTR    ;If not right, then NAK and try again
  342.     XOR    A        ;Set data length to zero
  343.     LD    (ARGBLK+1),A    ;Store it for later
  344.     LD    A,'Y'        ;Send an ACK
  345.     CALL    SPACK        ;Send the packet
  346.     JP    RECABORT    ;Send failed, abort
  347.     NSTATE    'C'        ;Set state to complete
  348.     RET            ;Return to caller
  349. RFILE5    CP    'X'        ;Type on tty packet?
  350.     JP    NZ,BADERROR    ;Bad packet if not
  351.     CALL    CHKBLK        ;Make sure the packet number is right
  352.     RET    NZ        ;Return if not
  353.     CALL    SETUPDIS    ;Set up to type on terminal
  354.     CALL    PRTPKTOUT    ;Print the packet contents
  355.     CALL    NEWLIN        ;Get a newline
  356.     CALL    NUM2OLD        ;Get new retry count
  357.     LD    (ARGBLK+1),A    ;Zero length (A is zero on return)
  358.     LD    A,'Y'        ;Send an ACK
  359.     CALL    SPACK        ;Send the packet
  360.     JP    RECABORT    ;Quit if send fails
  361.     LD    A,(PKTNUM)    ;Get the packet number
  362.     CALL    INCPKT        ;Add one
  363.     CALL    INCDISPKT    ;Increment count for display
  364.     NSTATE    'd'        ;Set the state to receive data
  365.     RET            ;Return to protocol switch
  366. ;
  367. ;    Transition between receive file, and receive data
  368. ;
  369. RECTRAN    EQU    $
  370.     STROUT    KERREC        ;Print the receiving message
  371.     STROUT    TFILNAM        ;Print the name of the file
  372.     LD    A,(TRANLOG)    ;Get the flag
  373.     IFZ    RTRAN_1        ;Test the flag and jump if not set
  374.     LD    DE,TRFCB    ;Get the FCB
  375.     TRLOG    KERREC,RTRAN_3    ;Log the string
  376.     TRLOG    TFILNAM,RTRAN_3    ;Log the file name
  377.     TRLOG    TIMEMES,RTRAN_3    ;Log the time message
  378.     CALL    PRTTIME        ;Print the current time
  379. RTRAN_1    EQU    $
  380.     LD    DE,FCB        ;Get the file FCB address
  381.     LD    (RFIDCB),DE    ;Save it as the output FCB
  382.     CALL    RSETPKT        ;Reset the packet coding routines
  383.     NSTATE    'd'        ;Set the state to receive data
  384.     RET
  385. ;
  386. ;    Clean up on log file failure
  387. ;
  388. RTRAN_3    XOR    A        ;Clear A
  389.     LD    (TRANLOG),A    ;Reset the logging flag
  390.     LD    DE,TRFCB    ;Get the FCB
  391.     CALL    XCLOSE
  392.     JR    RTRAN_1        ;Ignore rest of logging code
  393. ;
  394. ;    RECEIVE    DATA
  395. ;
  396. RDATA    CALL    CHKTRYS        ;Check the retry threshold
  397.     CALL    RPACK        ;Get a packet
  398.     JP    NAK        ;NAK it if bad packet
  399.     IFANOT    'D',RDATA2    ;If not data check others
  400. RDAT11    CALL    CHKBLK        ;Check packet number against current
  401.     JR    Z,RDAT14    ;Jump if current packet
  402.     CALL    CHKOLD        ;Check tries
  403.     CALL    CHKBLKDEC    ;Check packet number against previous
  404.     JP    NZ,NAK_RTR    ;Was not previous, so NAK it and retry
  405.     CALL    UPDRTR        ;Update the number of retries
  406.     XOR    A        ;Clear A
  407.     LD    (NUMTRY),A    ;Reset the number of tries
  408.     LD    (ARGBLK+1),A    ;Set the data length to zero
  409.     LD    A,'Y'        ;Send ACK packet
  410.     CALL    SPACK        ;Send the packet
  411.     JP    RECABORT    ;Send failed, abort
  412.     LD    A,'%'        ;Say we already saw this packet
  413.     CALL    CONDCHR        ;and just stay in the same state
  414.     RET            ;Next packet
  415. RDAT14    CALL    INCPKT        ;Increment the packet number
  416.     CALL    INCDISPKT    ;Increment the real packet count
  417.     LD    A,(NUMTRY)    ;Get the number of retries
  418.     LD    (OLDTRY),A    ;Save it
  419.     LD    A,(ARGBLK+1)    ;Get the length of the data
  420.     CALL    PTCHR        ;Decode the data packet and write it out
  421.     JP    RECABORT    ;Can't write to output, abort
  422.     XOR    A        ;Clear A
  423.     LD    (NUMTRY),A    ;Reset the number of tries
  424.     LD    (ARGBLK+1),A    ;Set data length to zero
  425.     LD    C,A        ;Make C zero
  426.     LD    A,(CZSEEN)    ;Check the flag
  427.     IFZ    RDAT15        ;If nothing, then skip
  428.     LD    C,A        ;Get the character typed
  429.     LD    A,1        ;One data character
  430.     LD    (ARGBLK+1),A    ;Set the length
  431.     LD    A,C        ;Get the data character
  432.     LD    (DATA),A    ;Store the character
  433. RDAT15    LD    A,'Y'        ;Send an ACK (Possibly with data)
  434.     CALL    SPACK        ;Send the packet
  435.     JP    RECABORT    ;Send failed, abort
  436.     LD    A,(NUMPKT)    ;Time to log the progress?
  437.     AND    3        ;Only every 4 packets
  438.     RET    NZ        ;Return if not time
  439.     LD    A,'.'        ;Get the character
  440.     CALL    CONDCHR        ;Log it if not doing 'X' packet
  441.     RET    
  442. RDATA2    IFANOT    'F',RDATA3    ;File header?  Jump if not
  443.     CALL    CHKOLD        ;Check against previous retries
  444.     CALL    CHKBLKDEC    ;Check packet number against previous
  445.     JP    NZ,NAK_RTR    ;If not previous, then NAK and try again
  446.     CALL    UPDRTR        ;Update the number of retries
  447.     XOR    A        ;Clear A
  448.     LD    (NUMTRY),A    ;Reset the number of retries
  449.     LD    (ARGBLK+1),A    ;Set the length to zero
  450.     LD    A,'Y'        ;Send an ACK
  451.     CALL    SPACK        ;Send the packet
  452.     JP    RECABORT    ;Send failed, abort
  453.     LD    A,'%'        ;Already saw this one.
  454.     CALL    CONDCHR        ;Tell the user
  455.     RET    
  456. RDATA3    CP    'Z'        ;If not EOF then jump
  457.     JP    NZ,RDATA4
  458.     CALL    CONDCHR        ;Display the new state
  459.     CALL    CHKBLK        ;Check packet number against current
  460.     JP    NZ,NAK_RTR    ;If not, then NAK and try again
  461.     CALL    INCPKT        ;Increment the packet number
  462.     CALL    INCDISPKT    ;Increment the real packet count
  463.     LD    A,(ARGBLK+1)    ;Get the length of the data
  464.     IFANOT    1,RDAT35    ;Jump if packet length not 1
  465.     LD    A,(DATA)    ;Just one, get the data
  466.     IFANOT    'D',RDAT36    ;Is it discard?  Jump if not
  467.     LD    A,(TRANLOG)    ;Check if loggin active
  468.     IFZ    RDAT31
  469.     LD    DE,TRFCB    ;Get the log file FCB
  470.     TRLOG    TRANCANC,RDAT39    ;Print canceled message
  471. RDAT31    LD    A,(DISCARD)    ;Check users preference for incompletes
  472.     IFZ    RDAT35        ;Jump if no discard
  473.     CALL    CHKFCB        ;Is this FCB or *SO?
  474.     JR    NZ,RDAT36    ;Jump if no remove, and don't close either
  475.     CALL    XREMOVE        ;Remove it
  476.     JR    Z,RDAT32    ;Jump if remove succeeded
  477.     CALL    XERROR0        ;Print system error message
  478.     JR    RDAT36        ;Join other code
  479. RDAT32    STROUT    RMMES        ;Print the message
  480.     LD    A,(TRANLOG)    ;Check if loggin active
  481.     IFZ    RDAT36
  482.     LD    DE,TRFCB
  483.     TRLOG    RMMES,RDAT39
  484.     JR    RDAT36        ;Join the other code
  485. RDAT35    CALL    CHKFCB        ;Check for file FCB, don't close *SO
  486.     CALL    Z,XCLOSE    ;Conditionally close the FILE
  487. RDAT36    XOR    A        ;Reset the EOF seen flag
  488.     LD    (CZSEEN),A
  489.     CALL    NUM2OLD        ;Reset the number of retries
  490.     LD    (ARGBLK+1),A    ;Set the length to zero
  491.     LD    A,'Y'        ;Send an ACK
  492.     CALL    SPACK        ;Send the packet
  493.     JP    RECABORT    ;Send failed, abort
  494.     NSTATE    'f'        ;Set state to receive file
  495.     LD    IX,RTRANS    ;Get the receive statistics address
  496.     CALL    UPDTRANS    ;Update the transfer statistics
  497.     RET    
  498. ;
  499. ;    Close up on a transaction log error
  500. ;
  501. RDAT39    XOR    A        ;Reset the logging flag
  502.     LD    (TRANLOG),A
  503.     LD    DE,TRFCB    ;Close the file
  504.     CALL    XCLOSE
  505.     JR    RDAT36        ;Rejoin code
  506. ;
  507. RDATA4    CP    'X'        ;Is it End Of Transmission?
  508.     JP    NZ,BADERROR    ;If not, then bad packet
  509.     CALL    CHKBLKDEC    ;Check if previous sequence number
  510.     RET    NZ        ;Return if not
  511.     XOR    A        ;Clear A
  512.     LD    (ARGBLK+1),A    ;Set the length to zero
  513.     LD    A,'Y'        ;Send an ACK
  514.     CALL    SPACK        ;Send the packet
  515.     JP    RECABORT    ;Send failed, abort
  516.     RET            ;Return to protocol
  517. ;
  518. ;    Check received packet number against previous
  519. ;
  520. CHKBLKDEC    EQU    $
  521.     LD    A,(PKTNUM)    ;Get the current packet number
  522.     DEC    A        ;Minus one for previous
  523.     JR    CHKBLK_1    ;Join other code
  524. ;
  525. ;    Check the current packet number against that received
  526. ;
  527. CHKBLK    EQU    $
  528.     LD    A,(PKTNUM)    ;Get the current number
  529. CHKBLK_1    LD    B,A    ;Copy it to B
  530.     LD    A,(ARGBLK)    ;Get the received packet number
  531.     CP    B        ;Are they the same
  532.     RET            ;Return the condition codes
  533. ;
  534. ;    Check for too many retries based on previous knowledge
  535. ;
  536. CHKOLD    EQU    $
  537.     LD    A,(MAXTRY)    ;Get the max number of tries
  538.     LD    B,A        ;Save it
  539.     LD    A,(OLDTRY)    ;Check against old max
  540.     CP    B        ;Set the condition bits
  541.     JR    C,CHKOLD1    ;Jump if less than
  542.     POP    DE        ;Remove the return address
  543.     LD    DE,ERMS10    ;Get the message
  544.     CALL    ERROR3        ;Display the error message
  545.     JP    RECABORT    ;Change the state to abort
  546. CHKOLD1    INC    A        ;Increment the number of tries
  547.     LD    (OLDTRY),A    ;Save the updated number of tries.
  548.     RET            ;Return normally
  549. ;
  550. ;    Set up for a REMOTE command.  The RFILE FCB is pointed at
  551. ;    the *SO device, so that data received goes to the screen,
  552. ;    rather than to a file.
  553. ;
  554. SETUPDIS    EQU    $
  555.     LD    DE,(TMODCB)    ;Get the current output DCB address
  556.     LD    (RFIDCB),DE    ;Make it the current received file output
  557.     XOR    A        ;Reset the 'display' flag
  558.     LD    (DISFLG),A
  559.     CALL    NEWLIN        ;Get a fresh line
  560.     RET            ;Return to caller
  561. ;
  562. ;    Conditionally display the string pointed to by DE based on the
  563. ;    DISFLG which is active only during non REMOTE transactions.  This
  564. ;    makes REMOTE command pleasingly silent so that only the output
  565. ;    of the requested operation is seen.
  566. ;
  567. CONDIS    EQU    $
  568.     PUSH    AF        ;Save A and the flags
  569.     LD    A,(DISFLG)    ;Get the 'display' flag
  570.     OR    A        ;Is it set?
  571.     CALL    NZ,PRTSTR    ;If so, then print the string
  572.     POP    AF        ;Restore the flags and A
  573.     RET            ;Return to caller
  574. ;
  575. ;    Print the contents of the PACKET data area to the
  576. ;    screen.
  577. ;
  578. PRTPKTOUT    EQU    $
  579.     LD    HL,DATA        ;Get the start of the string
  580.     LD    A,(ARGBLK+1)    ;Get the length
  581.     OR    A
  582.     RET    Z        ;Return if no data
  583.     LD    C,A        ;Get the LSB into C
  584.     LD    B,0        ;Make BC a 16 bit offset
  585.     ADD    HL,BC        ;HL is now the address past the end
  586.     LD    (HL),EOS    ;Terminator for printing
  587.     STROUT    DATA
  588.     JP    NEWLIN        ;Print a new line and return
  589. ;
  590. ;    Update byte counters, IX MUST point to send or receive
  591. ;    counter.  We mod HL with 1K to get the remainder, and use
  592. ;    the rest to sum into the current total.  The remainder of
  593. ;    HL mod 1024 is tucked away, but not forgotten.
  594. ;
  595. UPDTRANS    EQU    $
  596.     LD    HL,(KTRANS)    ;Calculate new total transfered
  597.     LD    C,(IX+2)    ;Get the overflow counter
  598.     LD    B,(IX+3)
  599.     ADD    HL,BC        ;Compute the total
  600.     XOR    A        ;Reset the falg
  601.     CALL    C,ADD64K    ;Add 64k if addition overflows
  602.     LD    A,H        ;Get the high byte
  603.     AND    3        ;Save the 2 lower order bits for mod 1024
  604.     LD    B,A        ;Put them in B
  605.     LD    C,L        ;Put the other 8 bits into C
  606.     LD    (IX+2),C    ;Store the new overflow (HL mod 1024)
  607.     LD    (IX+3),B
  608.     LD    A,H        ;Trim to 1K multiple
  609.     AND    0FCH        ;A is now 4 times the number of Kbytes
  610.     LD    L,A        ;Put it into L
  611.     LD    H,0        ;Make H zero
  612.     SRL    L        ;Divide by 4 to align
  613.     SRL    L
  614.     LD    C,(IX)        ;Get the total so far
  615.     LD    B,(IX+1)
  616.     ADD    HL,BC        ;Compute the new total Kbyte
  617.     LD    (IX),L        ;Put it back
  618.     LD    (IX+1),H    ;ignoring any overflow
  619.     CALL    TRANSCNT    ;Log the transaction size if logging
  620.     LD    HL,0        ;Set the counter to zero
  621.     LD    (KTRANS),HL
  622.     LD    (CURTRANS),HL    ;Reset current counters
  623.     LD    (CURTRANS+2),HL
  624.     RET            ;Return to the caller
  625. ;
  626. ;    Log the size of the last transaction to the logfile
  627. ;
  628. TRANSCNT    EQU    $
  629.     PUSH    AF        ;Save A and the FLAGS
  630.     LD    A,(TRANLOG)    ;Is tranaction logging in progress?
  631.     IFZ    TRANSC_10    ;Jump if not active
  632.     PUSH    HL
  633.     PUSH    DE
  634.     PUSH    BC
  635.     LD    HL,(CURTRANS+2)    ;Get the number of K transfered
  636.     LD    A,H
  637.     OR    L        ;Is it zero?
  638.     JR    Z,TRANSC_3    ;Jump if it is
  639.     CALL    NUM2BUFF    ;Put the number in the buffer
  640.     LD    DE,TRFCB    ;Get the FCB address
  641.     CALL    OUTLOG        ;Log the number of K transfered
  642.     JP    TRANSC_20    ;Close up on an error
  643.     TRLOG    KPLUS,TRANSC_20    ;Log the 'K + ' string
  644. TRANSC_3    EQU    $
  645.     LD    HL,(CURTRANS)    ;Get the value
  646.     CALL    NUM2BUFF    ;Make it printable
  647.     LD    DE,TRFCB    ;Get the output FCB
  648.     CALL    OUTLOG        ;Log the number of left over bytes
  649.     JP    TRANSC_20    ;Close up on an error
  650.     TRLOG    BYTESMES,TRANSC_20;Log the 'bytes transferred' message
  651.     TRLOG    TIMEMES,TRANSC_20; Log the time message
  652.     CALL    PRTTIME        ;Print the current time
  653. TRANSC_9    EQU    $
  654.     POP    BC        ;Restore the registers
  655.     POP    DE
  656.     POP    HL
  657. TRANSC_10    EQU    $
  658.     POP    AF    ;Restore A and flags
  659.     RET            ;Return to caller
  660. TRANSC_20    EQU    $
  661.     LD    DE,TRFCB
  662.     CALL    XCLOSE
  663.     XOR    A
  664.     LD    (TRANLOG),A
  665.     JP    TRANSC_9
  666. ;
  667. ;    Convert binary to ascii, NO leading spaces
  668. ;
  669. NUM2BUFF    EQU    $
  670.     PUSH    DE        ;Save DE
  671.     PUSH    BC        ;and BC
  672.     LD    DE,NBUFF    ;Get the data buffer
  673.     PUSH    DE        ;Save it for later
  674.     CALL    XHEXDEC
  675.     EX    DE,HL
  676.     LD    (HL),EOS    ;Terminate the buffer
  677.     POP    HL        ;Get the start back
  678.     LD    A,' '        ;Character to skip over
  679. N2B_1    EQU    $
  680.     IFANOT    (HL),N2B_2    ;Jump if passed last
  681.     INC    HL        ;Point to next
  682.     JR    N2B_1        ;Back to test
  683. N2B_2    EQU    $
  684.     POP    BC        ;Restore the registers
  685.     POP    DE
  686.     RET            ;Return to caller
  687. ;end of file
  688.