home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / decpro300 / prosnd.mac < prev    next >
Text File  |  2020-01-01  |  8KB  |  312 lines

  1.     .TITLE    KERSND - Send/Receive on XK port
  2.     .SBTTL    Robert McQueen/Nick Bush/Stuart Hecht/David Stevens
  3.  
  4. ; Version number
  5.  
  6.     .IDENT    /1.0.03/
  7.  
  8. ; Directives
  9.  
  10.     .LIBRARY /KERMLB/        ; Pro/Kermit macro library
  11.  
  12.     .SBTTL    Revision History
  13.  
  14. ;++
  15. ; 1.0.000    By: Robert C. McQueen        On: 1-December-1983
  16. ;        Create this module from other modules
  17. ;
  18. ; 1.0.01    By: Robert C. McQueen        On: 6-March-1984
  19. ;        Remove ABORTFLAG checks (obs).
  20. ;
  21. ; 1.0.02    By: Robert C. McQueen        On: 14-March-1984
  22. ;        Add ABORT flag and check it in RECEIVE.  This will allow
  23. ;        the user to abort the KERFIL process from KERMIT.
  24. ;
  25. ; 1.0.03    By: Robert C. McQueen        On: 22-May-1984
  26. ;        Fix off by one in the counting of characters received.
  27. ;        RECEIVE was only allowing 93 not 94.
  28. ;--
  29.  
  30.  
  31.     .SBTTL    .MCALLs for RSX directives
  32.  
  33. ; The following are the various MCALLs that KERXK uses.
  34.  
  35.     .MCALL    QIOW$S            ; QIO and wait
  36.     .MCALL    QIOW$C            ; QIO and wait
  37.     .MCALL    MRKT$S            ; Set a mark time request
  38.     .MCALL    CMKT$S            ; Cancel mark time requests
  39.     .MCALL    RDEF$S            ; Read event flags
  40.  
  41. ; The following causes the KERMIT definitions to be read and defined
  42.  
  43.     .MCALL    KERDEF            ; Get the KERMIT definitions
  44.     KERDEF                ; Define all of the KERMIT symbols
  45.     .MCALL    BLSRTN            ; Macro to define entry point
  46.  
  47.     .SBTTL    Bliss interface routines -- SEND
  48.  
  49. ; This routine will send a message to the remote Kermit
  50. ;
  51. ;    INPUT:    The address of the buffer and the length to be
  52. ;            sent must be on the stack under the return address
  53. ;
  54. ;    STACK:    return address
  55. ;        number of characters to send
  56. ;        buffer address
  57. ;
  58. ;    OUTPUT:    The message is sent to the remote Kermit
  59. ;        Nothing is changed in this routine
  60. ;
  61. ;    REGISTERS destroyed:    NONE
  62. ;
  63.  
  64.     .PSECT    $CODE$,  RO 
  65.  
  66.     BLSRTN    SEND,2,<BUFADR,BUFLEN> ; Define the routine entry point
  67. ;
  68. ; First clear out any pending input from the XK.  This kills garbage that has
  69. ; shown up while we were processing things.
  70.  
  71.     JSR    PC,XK.CIB        ; Clear the buffer
  72.  
  73. ; Now just send the buffer
  74.  
  75.     MOV    BUFADR(SP),R0        ; Get the buffer address
  76.     MOV    BUFLEN(SP),R1        ; Get the buffer length
  77.     QIOW$S    #IO.WAL,#XKLUN,#XKWEFN,,#IOSTAT,,<R0,R1>
  78.  
  79.     MOV    #ABORTED,R0        ; Assume it didn't work
  80.  
  81.     TST    $DSW            ; Check if directive worked
  82.     BMI    90$            ; No, give up
  83.  
  84.     TSTB    IOSTAT            ; Compare to see if error
  85.     BMI    90$            ; If no error then skip
  86.  
  87.     MOV    #KNORMAL,R0        ; All ok
  88. 90$:    RTS    PC            ; Return to sender
  89.  
  90.     .SBTTL    Bliss Interface -- RECIEVE - Read XK characters
  91.  
  92. ; This routine will receive a message from the remote Kermit
  93. ;
  94. ;    INPUT:    The address of the buffer must be on
  95. ;            the stack under the return address
  96. ;
  97. ;    STACK:    return address
  98. ;        address of number of characters (returned)
  99. ;        buffer address
  100. ;
  101. ;    OUTPUT:    The message is received from the remote Kermit
  102. ;        The length of the buffer is put on the stack
  103. ;
  104. ;    REGISTERS destroyed:    NONE
  105. ;
  106.  
  107.     .PSECT    $CODE$,  RO 
  108.  
  109.     BLSRTN    RECEIVE,3,<RCVBUF,RCVLEN> ; Define the entry point
  110.  
  111.     JSR    PC,XK.TIM        ; Start timer
  112.     MOV    R0,R2            ; Copy the timeout value for XK.INP
  113.  
  114. 10$:    MOV    RCVBUF(SP),R1        ; Point at first byte of buffer
  115.     CLR    R3            ; Clear count of characters we have seen
  116.     RDEF$S    #GENEFN            ; Check to see if time is up
  117.     CMP    $DSW,#IS.SET        ; If set then
  118.     BEQ    80$            ;   branch to timeout exit
  119.  
  120.     JSR    PC,XK.INP        ; Get a character
  121.     BCS    85$            ; If we got an error, return it
  122.  
  123.     CMP    #TRUE,ABORT        ; Was this aborted?
  124.     BEQ    85$            ; Yes, just exit
  125.  
  126.     TST    R0            ; Check if any characters read
  127.     BEQ    10$            ; No, try again
  128.  
  129.     CMPB    @R1,RCV.SOH        ; Check for start of header
  130.     BNE    10$            ; If not, check timeout and try again
  131.     INC    R1            ; Point at next character
  132.     INC    R3            ; Got one character
  133.  
  134. ; Here after we have gotten the start of packet character.  Now pick up the
  135. ;rest
  136.  
  137. 20$:    RDEF$S    #GENEFN            ; Check to see if time is up
  138.     CMP    $DSW,#IS.SET        ; If set then
  139.     BEQ    80$            ;   branch to timeout exit
  140. ;
  141. ; Check if someone requested an abort by typing the key
  142. ;
  143.     JSR    PC,XK.INP        ; Get another character
  144.     BCS    85$            ; If I/O fails, abort
  145.  
  146.     CMP    #TRUE,ABORT        ; Was this aborted?
  147.     BEQ    85$            ; Yes, just exit
  148.  
  149.     TST    R0            ; Check if we got something
  150.     BEQ    20$            ; No, try again
  151.  
  152.     CMPB    @R1,RCV.SOH        ; Check for start of header
  153.     BEQ    10$            ; Restart buffer if so
  154.  
  155.     INC    R3            ; Count the character
  156.  
  157.     CMPB    (R1)+,RCV.EOL        ; Get end of line character?
  158.     BEQ    90$            ; Yes, go return
  159.  
  160.     CMP    R3,#MAX.MSG        ; Fill buffer completly yet?
  161.     BLE    20$            ; If not, just get next character
  162.  
  163.     DEC    R1            ; Otherwise, back up one character
  164.     BR    20$            ; And try again
  165.  
  166. ; Here if we ran out of time.  Return the timeout
  167.  
  168. 80$:    MOV    #TIMEOUT,R0        ; Get the status
  169.     RTS    PC            ; And return
  170.  
  171. ; Here if we got some error that makes it impossible to continue the transfer
  172. ; Return "Aborted"
  173.  
  174. 85$:    MOV    #ABORTED,R0        ; Give up
  175.     RTS    PC            ; Let caller figure out how
  176.  
  177. ;
  178. ; Here when we got the end of line character.  Save the count
  179. ;
  180.  
  181. 90$:    MOV    R3,@RCVLEN(SP)        ; Save the character count
  182.     MOV    #KNORMAL,R0        ; Give good return
  183. 99$:    RTS    PC            ; Return to sender
  184.  
  185.     .SBTTL    Bliss interface -- IBM_WAIT - Wait for the IBM character
  186.  
  187. ;++
  188. ; This routine will wait for the IBM turn around character.  Currently
  189. ; this routine is just a dummy
  190. ;--
  191.  
  192.     .PSECT    $CODE$,  RO 
  193.  
  194. BLSRTN    IBM.WAIT,2,,<CHAR>
  195.     JSR    PC,XK.TIM        ; Set up our timeout
  196.     MOV    R0,R2            ; Copy QIO timeout parameter
  197.     MOV    #CHAR,R1        ; Get address of our temp
  198.     ADD    SP,R1            ;  .  .  .
  199.  
  200. 10$:    RDEF$S    #GENEFN            ; Check to see if time is up
  201.     CMP    $DSW,#IS.SET        ; If set then
  202.     BEQ    80$            ;   branch to timeout exit
  203.  
  204.     JSR    PC,XK.INP        ; Read a character
  205.     BCS    85$            ; If error, return it
  206.  
  207.     TST    R0            ; Check if we got anything
  208.     BEQ    10$            ; No, try again
  209.  
  210.     BIC    #200,@R1        ; Clear the parity bit
  211.     CMPB    @R1,IBM.CHAR        ; This the character we want?
  212.     BNE    10$            ; No, try again    
  213.  
  214.     MOV    #KNORMAL,R0        ; Yes, return normal
  215.     RTS    PC            ; And return
  216.  
  217. ; Here if we timed out while waiting.  Return the status
  218.  
  219. 80$:    MOV    #TIMEOUT,R0        ; Get the status value
  220.     RTS    PC            ; And return
  221.  
  222. ; Here if the QIO failed
  223.  
  224. 85$:    MOV    #ABORTED,R0        ; Just give up
  225.     RTS    PC            ; And return
  226.  
  227. .SBTTL    CRCCLC - Calculate the CRC-CCITT for a string
  228.  
  229. ;
  230. ; Subroutine to calculate the CRC (using CCITT polynomial) for a string
  231. ; of bytes.
  232. ;
  233. ; Call:
  234. ;    MOV    #Address,-(SP)    ; Address of string
  235. ;    MOV    Length,-(SP)    ; Length of string
  236. ;    JSR    PC,CRCCLC    ; Determine CRC
  237. ;                ; Returned in R0
  238. ;
  239. ;From BLISS:
  240. ;    CRC=CRCCLC(.Address,.Length)
  241. ;
  242.     LEN=14            ; Offset to length
  243.     ADDR=16            ; Offset to address
  244.  
  245. CRCCLC::JSR    R1,$SAVE4    ; Save R1-R4
  246.     MOV    LEN(SP),R4    ; Get the length of the string
  247.     MOV    ADDR(SP),R3    ; And the address
  248.     MOV    #0,R1        ; Initial CRC value is 0
  249.  
  250. ; Now loop for all of the characters in the string
  251.  
  252. 10$:    MOVB    (R3)+,R0    ; Get a character
  253.  
  254.     XOR    R1,R0        ; Include new byte
  255.     MOV    R0,R2        ; Get a copy
  256.     BIC    #^C17,R0    ; Extract 4 low bits
  257.     ASL    R0        ; Byte address to word index
  258.     MOV    CRCTB2(R0),R0    ; Get the table entry
  259.     BIC    #^C360,R2    ; Get high four bits
  260.     ASH    #-3,R2        ; Shift over for table offset
  261.     MOV    CRCTAB(R2),R2    ; Get the other half
  262.     XOR    R2,R0        ; XOR modifier values
  263.     CLRB    R1        ; Clear low byte of CRC
  264.     SWAB    R1        ; Put high byte in low byte
  265.     XOR    R0,R1        ; Produce new CRC
  266.  
  267.     SOB    R4,10$        ; Loop for all bytes of the string
  268.     MOV    R1,R0        ; Return the result in R0
  269.     RTS    PC        ; ANd return
  270.  
  271. ; Data tables for CRC-CCITT
  272.  
  273.     .PSECT    $PLIT$,  RO ,  D  
  274.  
  275. CRCTAB:    .WORD    0
  276.     .WORD    10201
  277.     .WORD    20402
  278.     .WORD    30603
  279.     .WORD    41004
  280.     .WORD    51205
  281.     .WORD    61406
  282.     .WORD    71607
  283.     .WORD    102010
  284.     .WORD    112211
  285.     .WORD    122412
  286.     .WORD    132613
  287.     .WORD    143014
  288.     .WORD    153215
  289.     .WORD    163416
  290.     .WORD    173617
  291.  
  292. CRCTB2:    .WORD    0
  293.     .WORD    10611
  294.     .WORD    21422
  295.     .WORD    31233
  296.     .WORD    43044
  297.     .WORD    53655
  298.     .WORD    62466
  299.     .WORD    72277
  300.     .WORD    106110
  301.     .WORD    116701
  302.     .WORD    127532
  303.     .WORD    137323
  304.     .WORD    145154
  305.     .WORD    155745
  306.     .WORD    164576
  307.     .WORD    174367
  308.  
  309.     .SBTTL    End of KERSND
  310.  
  311.     .END
  312.