home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / trs80model4.zip / m4send.asm < prev    next >
Assembly Source File  |  1986-10-22  |  12KB  |  432 lines

  1. ;    M4SEND/ASM
  2. ;
  3. ;    SEND    COMMAND
  4. ;
  5. SEND    EQU    $
  6.     CALL    NEWLIN
  7.     LD    A,CMTXT        ;PARSE A TEXT STRING
  8.     LD    DE,MFNBUF    ;GIVE THE ADDRESS FOR THE STRING
  9.     PUSH    DE        ;Save it
  10.     CALL    COMND        ;GET THE INPUT
  11.     JP    KERMT2        ;GIVE UP ON BAD PARSE.
  12.     POP    HL        ;Get the pointer
  13.     LD    (MFNPTR),HL    ;Save it as the start
  14.     LD    A,1        ;Set the log names flag
  15.     LD    (LOGNAMES),A
  16.     CALL    BUILDF        ;Build a list doing wildcarding
  17.     LD    A,(FILECNT)    ;Get the number of files
  18.     IFNZ    SEND11        ;Jump if some files were found
  19.     STROUT    NOFILES        ;Print the message
  20.     JP    KERMIT
  21. SEND11    LD    (MFNPTR),HL    ;Save the start of the found list
  22.     CALL    MFNAME        ;Get the next from the list
  23.     JR    NC,SEND14    ;Jump if got a name
  24.     CALL    NEWLIN
  25.     LD    A,19        ;Issue system error, Illeagal filename
  26.     CALL    XERROR
  27.     JP    KERMIT        ;GET A NEW COMMAND
  28. SEND14    CALL    INIT        ;Clear the line and initialize buffers
  29.     XOR    A
  30.     LD    (PKTNUM),A
  31.     LD    (NUMTRY),A    ;SET THE NUMBER OF TRIES TO ZERO.
  32.     LD    HL,0
  33.     LD    (NUMPKT),HL    ;SET THE NUMBER OF PACKETS TO ZERO.
  34.     LD    (NUMRTR),HL    ;SET THE NUMBER OF RETRIES TO ZERO.
  35.     LD    (KTRANS),HL
  36.     LD    A,'1'        ;RESET TO USE SINGLE CHARACTER CHECKSUM
  37.     LD    (CURCHK),A    ;FOR STARTUP
  38.     NSTATE    'S'
  39.     LD    (DISFLG),A    ;Put in something non zero
  40.     CALL    CONDCHR        ;Display starting sendinit character 'S'
  41.     CALL    CLRPRT        ;CLEAR OUT ANY STACKED NAKS
  42.     STROUT    HELPMSG
  43.     CALL    PROTO        ;Do protocol states
  44.     JP    KERMIT        ;Return to Kermit
  45. ;
  46. ;    SEND ROUTINES
  47. ;    SEND INITIATE
  48. ;
  49. SINIT    CALL    CHKTRYS        ;Check retry threshold
  50.     LD    A,'1'        ;RESET TO USE SINGLE CHARACTER CHECKSUM
  51.     LD    (CURCHK),A    ;FOR STARTUP
  52.     LD    A,(CHKTYP)    ;GET OUR DESIRED BLOCK CHECK TYPE
  53.     LD    (INICHK),A
  54.     LD    HL,DATA        ;GET A POINTER TO OUR DATA BLOCK.
  55.     CALL    RPAR        ;SET UP THE PARAMETER INFORMATION.
  56.     LD    (ARGBLK+1),A    ;SAVE THE NUMBER OF ARGUMENTS.
  57.     LD    A,(NUMPKT)    ;GET THE PACKET NUMBER.
  58.     LD    (ARGBLK),A
  59.     SRPACK    'S'        ;Do send init, and get response
  60.     IFANOT    'Y',SINIT3    ;Was it an ACK? Jump if not
  61.     CALL    CHKBLK
  62.     RET    NZ         ;IF NOT TRY AGAIN.
  63.     CALL    DOINC        ;Increment and reset
  64.     LD    A,(ARGBLK+1)    ;GET THE NUMBER OF PIECES OF DATA.
  65.     LD    HL,DATA        ;POINTER TO THE DATA.
  66.     CALL    SPAR        ;READ IN THE DATA.
  67.     LD    A,(INICHK)    ;GET THE AGREED UPON BLOCK-CHECK-TYPE
  68.     LD    (CURCHK),A    ;STORE AS TYPE TO USE FOR PACKETS NOW
  69.     NSTATE    'F'        ;Set the state
  70.     CALL    CONDCHR
  71.     CALL    GETFIL        ;Open the file name given in FCB
  72.     JP    SNDABORT    ;Something is wrong if come to here
  73.     RET            ;Next state in protocol
  74. ;
  75. ;    Come here on bad answer to S packet
  76. ;
  77. SINIT3    CP    'N'        ;NAK?
  78.     JP    NZ,BADERROR    ;If not, then it is a fatal error
  79.     CALL    CONDCHR        ;Output N character
  80.     RET            ;Back to protocol
  81. ;
  82. ;    Terminate a transaction log because of an error
  83. ;
  84. ;
  85. ;    SEND FILE HEADER
  86. ;
  87. SFILE    CALL    CHKTRYS        ;Check retry threshold
  88.     XOR    A        ;CLEAR A
  89.     LD    (CZSEEN),A
  90.     LD    DE,DATA        ;GET A POINTER TO OUR DATA BLOCK.
  91.     LD    HL,MFREQ    ;Get filename
  92.     LD    BC,255        ;B must be zero, C must be big for LDI
  93. SF1    LD    A,(HL)
  94.     IFA    '/',SF2
  95.     IFA    ':',SF4
  96.     IFALT    ' ',SF4
  97.     LDI
  98.     INC    B
  99.     JR    SF1
  100. SF2    LD    (HL),'.'
  101.     LDI
  102.     INC    B
  103. SF3    LD    A,(HL)
  104.     IFALT    ' ',SF4
  105.     IFA    ':',SF4
  106.     LDI
  107.     INC    B
  108.     JR    SF3
  109. SF4    EQU    $
  110.     LD    (DATPTR),DE
  111.     LD    (FCBPTR),HL
  112.     LD    A,B        ;NUMBER OF CHAR IN FILE NAME.
  113.     LD    (ARGBLK+1),A
  114.     EX    DE,HL
  115.     LD    (HL),EOS    ;Put in the print terminator
  116.     LD    A,(PKTNUM)    ;GET THE PACKET NUMBER.
  117.     LD    (ARGBLK),A
  118.     SRPACK    'F'        ;Send file header and get response
  119.     IFANOT    'Y',SFILE2    ;Jump if not an ACK
  120.     CALL    CHKBLK        ;Check packet number
  121.     RET    NZ         ;Return if not the right one
  122. SFIL14    CALL    DOINC        ;Increment packet count
  123. SFIL15    CALL    RSETPKT        ;Reinitialize GETPKT()
  124.     CALL    GTCHR
  125.     JP    SFIL16        ;ERROR GO SEE IF ITS EOF.
  126.     JR    SFIL17        ;GOT THE CHARS, PROCEED.
  127. SFIL16    CP    0FFH        ;IS IT EOF?
  128.     JP    NZ,SNDABORT    ;IF NOT GIVE UP.
  129.     NSTATE    'Z'        ;Set EOF state
  130.     CALL    CONDCHR
  131.     RET    
  132. SFIL17    EQU    $
  133.     NSTATE    'T'        ;Set state to data send
  134.     LD    (DISFLG),A    ;Make sure display is on
  135.     RET    
  136. SFILE2    CP    'N'        ;NAK?
  137.     JP    NZ,BADERROR    ;TRY IF ERROR PACKET.
  138.     CALL    CONDCHR        ;Display the packet character
  139.     CALL    CHKBLKINC    ;Check NAK for packet N+1
  140.     RET    NZ         ;If not, then try to resend
  141.     JR    SFIL14        ;As good as an ACK, join the ack code
  142. ;
  143. ;    Send transition state from Send file to Send data
  144. ;
  145. SNDTRAN    EQU    $
  146.     STROUT    KERSND        ;Print SENDING message
  147.     STROUT    TFILNAM        ;Print the file name
  148.     LD    A,(TRANLOG)    ;Check if logging active
  149.     IFZ    SNDTRAN2    ;If not, then jump
  150.     LD    DE,TRFCB    ;Get the log file FCB
  151.     TRLOG    KERSND,SNDTRAN1    ;Log the SENDING=> message
  152.     TRLOG    TFILNAM,SNDTRAN1    ;Log the file name
  153.     TRLOG    TIMEMES,SNDTRAN1;Log the time: message
  154.     CALL    PRTTIME        ;Print the time
  155.     JR    SNDTRAN2    ;Join other code
  156. ;
  157. ;    Close up on a logging error
  158. ;
  159. SNDTRAN1    EQU    $
  160.     XOR    A        ;Reset the log open flag
  161.     LD    (TRANLOG),A
  162.     LD    DE,TRFCB    ;Close the log file
  163.     CALL    XCLOSE
  164. SNDTRAN2    EQU    $
  165.     NSTATE    'D'        ;Set the state to SEND DATA
  166.     RET
  167. ;
  168. ;    SEND DATA
  169. ;
  170. SDATA    CALL    CHKTRYS        ;Check the retry threshold
  171.     LD    DE,DATA        ;Get the data area
  172.     LD    HL,FILBUF    ;Get the file buffer
  173.     LD    A,(SIZE)    ;Get the number of bytes encoded
  174.     IFZ    SDAT11        ;Jump if there are none
  175.     LD    C,A        ;Put LSB into C
  176.     LD    B,0        ;Zero B
  177.     LDIR            ;Move the bytes
  178. SDAT11    LD    A,(SIZE)    ;Get the number of bytes back
  179.     LD    (ARGBLK+1),A    ;Store it as the length
  180.     LD    A,(PKTNUM)    ;Get the current packet number
  181.     LD    (ARGBLK),A    ;Put it in the packet
  182.     LD    A,'D'        ;Get the packet type
  183.     CALL    SPACK        ;Send a data packet
  184.     JP    SNDABORT    ;Abort if send fails
  185.     LD    A,(NUMPKT)    ;See if time to log progress
  186.     AND    3        ;Every 4 packets
  187.     LD    A,'.'        ;Get the character
  188.     CALL    Z,CONDCHR    ;Output if it is time
  189.     RPACKET            ;Get a packet
  190.     IFANOT    'Y',SDATA2    ;Jump if not an ACK
  191.     CALL    CHKBLK        ;See if proper packet number
  192.     RET    NZ         ;Wait for more if not right number
  193.     CALL    DOINC        ;Increment and reset
  194.     LD    A,(ARGBLK+1)    ;Get the length of packet
  195.     IFANOT    1,SDAT15    ;Jump if not 1 character
  196.     LD    A,(DATA)    ;Get the character sent in ACK
  197.     IFANOT    'Z',SDAT14    ;Is it end of file?  Jump if not
  198.     LD    (CZSEEN),A    ;Save it
  199.     JR    SDAT15        ;Continue
  200. SDAT14    IFANOT    'X',SDAT15    ;Was it EOT?  Jump if not
  201.     LD    (CZSEEN),A    ;Save it
  202. SDAT15    LD    A,(CZSEEN)    ;Get the character
  203.     IFZ    SDAT12        ;Jump if nothing there
  204.     CALL    CONDCHR        ;Display the character
  205.     NSTATE    'Z'        ;Set the state to EOF
  206.     RET            ;Return to protocol
  207. ;
  208. SDAT12    CALL    GTCHR        ;Get more data from input file
  209.     JP    SDAT13        ;Jump if error occurs (might be EOF)
  210.     RET            ;Continue sending
  211. ;
  212. SDAT13    CP    0FFH        ;Was the file error EOF?
  213.     JP    NZ,SNDABORT    ;If not, then file error, so abort
  214.     NSTATE    'Z'        ;Set state to EOF
  215.     CALL    CONDCHR        ;Output the state
  216.     RET            ;Return to protocol
  217. ;
  218. SDATA2    CP    'N'        ;Is it a NAK?
  219.     JP    NZ,BADERROR    ;Nope, check next type
  220.     CALL    CONDCHR        ;Display packet type
  221.     CALL    CHKBLKINC    ;NAK this packet plus one?
  222.     JR    Z,SDAT12    ;Just as good as an ACK, Join ACK code.
  223.     CALL    UPDRTR
  224.     RET
  225. ;
  226. ;    Send the EOF packet
  227. ;
  228. SEOF    CALL    CHKTRYS        ;Check the retry threshold
  229.     CALL    INITBLK        ;Initialize ARGBLK
  230.     LD    A,(CZSEEN)    ;Check for ABORT
  231.     IFZ    SEOF14        ;If not aborted, then keep going
  232.     LD    A,(TRANLOG)    ;Check if logging active
  233.     IFZ    SEOF10        ;Jump if no logging
  234.     LD    DE,TRFCB    ;Get the log file FCB
  235.     TRLOG    TRANCANC,SEOF19    ;Log the canceled message
  236. SEOF10    LD    A,(DISCARD)    ;Should the file be deleted?
  237.     IFZ    SEOF11        ;Skip delete if user want to keep it
  238.     LD    A,'D'        ;Tell other end to discard packet
  239.     LD    (DATA),A    ;Store the delete character
  240.     LD    A,1        ;Length is one character
  241. SEOF11    LD    (ARGBLK+1),A    ;Store the length
  242. SEOF14    SRPACK    'Z'        ;Send EOF, and get a response
  243.     IFANOT    'Y',SEOF2    ;Jump if not an ACK
  244.     CALL    CHKBLK        ;Check the packet number
  245.     RET    NZ         ;Return if not correct one
  246. SEOF12    CALL    DOINC        ;Increment and reset
  247.     CALL    CHKFCB        ;Check for file, don't close *SO
  248.     CALL    Z,XCLOSE    ;Conditionally close it
  249.     LD    A,(CZSEEN)    ;Did the user force us to stop?
  250.     IFA    'Z',SEOF13    ;Jump if EOF was signaled by user
  251.     CALL    MFNAME        ;Get a new file name
  252.     JR    C,SEOF13    ;Jump if no more
  253.     CALL    GETFIL        ;AND OPEN IT
  254.     JP    SNDABORT    ;SOMETHING IS WRONG, DIE.
  255.     XOR    A        ;CLEAR A
  256.     LD    (CZSEEN),A
  257.     NSTATE    'F'        ;Set state to file send
  258.     CALL    CONDCHR
  259.     LD    IX,STRANS    ;Update transmission information
  260.     CALL    UPDTRANS
  261.     RET            ;Continue protocol
  262. ;
  263. SEOF13    NSTATE    'B'        ;Set state to EOT
  264.     CALL    CONDCHR
  265.     LD    IX,STRANS    ;Update the transmission info
  266.     CALL    UPDTRANS
  267.     RET    
  268. ;
  269. SEOF2    CP    'N'        ;NAK?
  270.     JP    NZ,BADERROR    ;TRY AND SEE IF ITS AN ERROR PACKET.
  271.     CALL    CONDCHR
  272.     CALL    UPDRTR        ;UPDATE THE NUMBER OF RETRIES.
  273.     CALL    CHKBLKINC
  274.     RET    NZ        ;IF NOT GO TRY AGAIN.
  275.     JR    SEOF12        ;Just as good as an ACK
  276. ;
  277. SEOF19    XOR    A        ;Reset the log open flag
  278.     LD    (TRANLOG),A
  279.     LD    DE,TRFCB    ;Close the file
  280.     CALL    XCLOSE
  281.     JP    SEOF10        ;Join other code
  282. ;
  283. ;    Send EOT packet
  284. ;
  285. SEOT    CALL    CHKTRYS        ;Check the retry threshold
  286.     CALL    INITBLK        ;Initialize ARGBLK
  287.     SRPACK    'B'        ;Send END of BATCH and get response
  288.     IFANOT    'Y',SEOT2    ;Jump if not ACK
  289.     CALL    CHKBLK        ;Check the packet number
  290.     RET    NZ         ;Return if not correct
  291. SEOT12    CALL    DOINC        ;Increment and reset
  292.     NSTATE    'C'        ;Set state to complete
  293.     RET    
  294. SEOT2    CP    'N'        ;NAK?
  295.     JP    NZ,BADERROR    ;IS IT ERROR.
  296.     CALL    CONDCHR
  297.     CALL    UPDRTR        ;UPDATE THE NUMBER OF RETRIES.
  298.     CALL    CHKBLKINC
  299.     JP    Z,SEOT12    ;Good as an ACK, so continue
  300.     OR    A        ;Is the other end starting over?
  301.     JR    Z,SEOT12
  302.     RET
  303. ;
  304. ;    Check the retry threshold
  305. ;
  306. CHKTRYS    EQU    $        ;Check retry threshold
  307.     LD    A,(MAXTRY)    ;Get the maximum
  308.     LD    B,A        ;Save
  309.     LD    A,(NUMTRY)
  310.     IFALT    B,CHKTRYS1    ;Jump if not at limit
  311.     POP    DE        ;Remove the callers return addr
  312.     LD    DE,ERMS14    ;Print the error message
  313.     CALL    ERROR3
  314.     JP    SNDABORT    ;CHANGE THE STATE TO ABORT.
  315. CHKTRYS1    EQU    $
  316.     IFZ    CHKTRYS2    ;Jump if first try
  317.     PUSH    AF        ;Save the count
  318.     LD    A,'%'        ;Print retrying message
  319.     CALL    CONDCHR
  320.     POP    AF        ;Get the count back
  321. CHKTRYS2    EQU    $
  322.     INC    A        ;Increment it
  323.     LD    (NUMTRY),A    ;Save the new count
  324.     RET
  325. ;
  326. ;    Increment the packet count modulo 64, A already has the old one.
  327. ;
  328. INCPKT    INC    A
  329.     AND    3FH
  330.     LD    (PKTNUM),A
  331.     RET
  332. ;
  333. ;    Move numtry to oldtry and zero numtry
  334. ;
  335. NUM2OLD    EQU    $
  336.     LD    A,(NUMTRY)    ;GET THE NUMBER OF TRIES.
  337.     LD    (OLDTRY),A    ;SAVE IT.
  338.     XOR    A
  339.     LD    (NUMTRY),A    ;RESET THE NUMBER OF TRIES.
  340.     RET
  341. ;
  342. ;    Increment display packet count
  343. ;
  344. INCDISPKT    EQU    $
  345.     LD    HL,(NUMPKT)
  346.     INC    HL
  347.     LD    (NUMPKT),HL
  348.     RET
  349. ;
  350. ;    Do several things
  351. ;
  352. DOINC    CALL    INCPKT
  353.     CALL    INCDISPKT
  354.     JP    NUM2OLD
  355. ;
  356. ;    Check the packet number 'received plus 1' verses that sent
  357. ;    return their relation, eg <, >, =, <>.  This is used as a
  358. ;    method to determine that a NAK for packet N+1 is equivelent
  359. ;    to an ACK for packet N.
  360. ;
  361. CHKBLKINC    EQU    $
  362.     LD    A,(PKTNUM)    ;Get the current packet number
  363.     INC    A        ;Plus one
  364.     LD    B,A        ;Save it
  365.     LD    A,(ARGBLK)    ;Get the packet number returned
  366.     CP    B        ;Are they equal?
  367.     RET            ;Return the flags setting
  368. ;
  369. ;    Conditionally display the character in A based on the value
  370. ;    of DISFLG.  This is used to print the characters during transfers
  371. ;    that show the status of the transfer.  eg '.', 'Q', 'S', 'Z', etc
  372. ;
  373. CONDCHR    EQU    $
  374.     LD    C,A        ;Save the character
  375.     LD    A,(DISFLG)    ;Check if should display the character
  376.     OR    A        ;Set the flags
  377.     RET    Z        ;Return if flag not set
  378.     LD    A,C        ;Get the character back
  379.     JP    CONOUT        ;Print the terminal on the console
  380. ;
  381. RSETPKT    EQU    $
  382.     XOR    A        ;GET A ZERO.
  383.     LD    (EOFLAG),A    ;INDICATE NOT EOF.
  384.     LD    (SIZE),A    ;Nothing in packet buffer
  385.     LD    (OSIZE),A    ;No old length
  386.     LD    (LEFTOVER),A    ;No leftovers from previous packet
  387.     LD    (RPTCNT),A    ;No repeated characters yet
  388.     LD    (PREVCH),A    ;Reset any previous character knowledge
  389.     LD    HL,-1        ;Set NO next character
  390.     LD    (NEXT),HL
  391.     LD    (CH),HL
  392.     RET
  393. ;
  394. BADERROR    EQU    $
  395.     CP    'E'        ;IS IT AN ERROR PACKET.
  396.     JP    NZ,SNDABORT
  397.     CALL    ERROR
  398.     JP    SNDABORT
  399. ;
  400. INITBLK    EQU    $
  401.     LD    A,(PKTNUM)    ;GET THE PACKET NUMBER.
  402.     LD    (ARGBLK),A
  403.     XOR    A
  404.     LD    (ARGBLK+1),A    ;NO DATA.
  405.     RET
  406. PRTTIME    EQU    $
  407.     PUSH    AF        ;Save the regs
  408.     PUSH    BC
  409.     PUSH    HL
  410.     PUSH    DE        ;Save the FILE FCB
  411.     LD    HL,CLBUF    ;Get the character buffer
  412.     PUSH    HL        ;Save the address
  413.     CALL    XTIME        ;Get the time
  414.     LD    (HL),CR        ;Get a new line
  415.     INC    HL        ;Point to next pos
  416.     LD    (HL),EOS    ;Terminate the string
  417.     POP    HL        ;Get the string to print back
  418.     POP    DE        ;Get the log file FCB
  419.     CALL    OUTLOG
  420.     CALL    TIMCLOSE    ;Close up if error occurs
  421.     POP    HL        ;Restore the regs
  422.     POP    BC
  423.     POP    AF
  424.     RET
  425. ;
  426. TIMCLOSE    EQU    $
  427.     XOR    A        ;Reset the file open flag
  428.     LD    (LOGTRAN),A
  429.     LD    DE,TRFCB    ;Get the FCB
  430.     JP    XCLOSE        ;Close the file and return.
  431. ; end of file
  432.