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

  1. ;    M4RMT/ASM
  2. ;    REMOTE KERMIT COMMAND
  3. REMOTE    LD    A,CMKEY
  4.     LD    DE,RMTTAB
  5.     CALL    COMND
  6.     JP    KERMT2
  7.     LD    C,A        ;SAVE THE TYPE
  8.     CALL    NEWLIN
  9.     LD    B,0
  10.     LD    HL,RMTJTB    ;GET THE JUMP TABLE
  11.     ADD    HL,BC        ;COMPUTE THE ADDRESS
  12.     LD    A,'G'
  13.     LD    (PKTTYPE),A    ;Set to generic packet
  14.     JP    (HL)
  15. ;    REMOTE COMMAND JUMP TABLE
  16. RMTJTB    JP    RMTCWD        ;CHANGE WORKING DIRECTORIES
  17.     JP    RMTDEL        ;DELETE A FILE
  18.     JP    RMTDIR        ;DISPLAY A DIRECTORY
  19.     JP    RMTDSK        ;DO A REMOTE DISK ALLOCATION
  20.     JP    RMTHLP        ;GET REMOTE HELP
  21.     JP    RMTHST        ;DO REMOTE HOST COMMAND
  22.     JP    RMTKER        ;DO REMOTE KERMIT COMMAND
  23.     JP    RMTWHO        ;RUN A REMOTE PROGRAM
  24.     JP    RMTREN        ;SEND DATA TO A REMOTE PROGRAM
  25.     JP    RMTTYPE        ;DISPLAY A REMOTE FILE
  26.     JP    RMTCOPY        ;Copy a file
  27.     JP    RMTMSG        ;Send a message
  28.     JP    RMTSET        ;Set a variable
  29.     JP    RMTQUERY    ;Query a variable
  30.     JP    RMTCLOSE    ;Close the log
  31.     JP    RMTSEND        ;Send the log
  32.     JP    RMTSTART    ;Start logging
  33.     JP    RMTSTOP        ;Stop logging
  34.     JP    RMTLOGIN    ;Login to dedicated server
  35.     JP    RMTPRG        ;Remote program manipulation
  36.     JP    RMTSRV        ;Remote server status query
  37. ;
  38. ;    DO A GENERIC REMOTE COMMAND
  39. ;
  40. GENCMD    LD    DE,RMTDATA    ;Set the initial destination
  41.     LD    B,0        ;Set the initial counters
  42.     LD    (GENTYPE),A    ;Save the type
  43.     IFA    'J',GENCMD1    ;Jump if journaling
  44.     IFANOT    'V',GENCMD2    ;Jump if not variable
  45. GENCMD1    LD    A,C        ;Get the second attribute
  46.     LD    (DE),A        ;Store it
  47.     INC    DE        ;Point ahead
  48.     INC    B        ;Plus one for the extra attribute
  49. GENCMD2    LD    C,0        ;Reset the beginning field length
  50. GENCMD3    LD    (INITRMT),DE    ;Save the values
  51.     LD    (INITCNT),BC
  52.     CALL    ENCFLDS        ;Get the input fields
  53. GENCMD5    LD    A,'1'        ;SET CURRENT CHECK SUM
  54.     LD    (CURCHK),A
  55.     XOR    A        ;Set the packet number to zero
  56.     LD    (ARGBLK),A
  57.     NSTATE    'I'        ;Set the state to I-initiate
  58.     CALL    INIT        ;Initialize buffers
  59.     LD    HL,0        ;Set packet count to zero
  60.     LD    (NUMPKT),HL
  61.     LD    (NUMRTR),HL    ;Reset number of retries
  62.     XOR    A        ;Set mode to display on screen
  63.     LD    (DISFLG),A
  64.     LD    (PKTNUM),A    ;Zero current packet number
  65.     LD    (NUMTRY),A    ;Zero retries for current packet
  66.     LD    (CZSEEN),A
  67.     CALL    CLRPRT
  68.     CALL    PROTO
  69.     JP    KERMIT
  70. ;
  71. ;    State G of the protocol.   Build a G or C packet, and send it
  72. ;
  73. DOGEN    EQU    $
  74.     CALL    CHKTRYS        ;Check the retry count
  75.     LD    A,(PKTNUM)    ;Set the packet number to current
  76.     LD    (ARGBLK),A
  77.     LD    HL,FILBUF    ;Transfer data to the buffer
  78.     LD    DE,DATA        ;Get the DATA area
  79.     LD    A,(PKTTYPE)    ;Get the requested type, 'G' or 'C'
  80.     IFA    'C',DOGEN6    ;If COMMAND then jump
  81.     INC    DE        ;Point to data+1 if not remote host
  82. DOGEN6    LD    A,(GENLEN)    ;Get the length
  83.     IFZ    DOGEN1        ;Jump if no length
  84.     LD    C,A        ;Make BC the count
  85.     LD    B,0
  86.     LDIR            ;Move the bytes
  87. DOGEN1    LD    C,A        ;Store the length
  88.     LD    A,(PKTTYPE)    ;Check the type again
  89.     IFA    'C',DOGEN7    ;If COMMAND then jump
  90.     LD    A,(GENTYPE)    ;Get the GENERIC type
  91.     LD    (DATA),A    ;Store it
  92.     INC    C        ;Add one to DATA length
  93.     LD    A,'G'        ;Send a generic packet
  94. DOGEN7    PUSH    AF        ;Save the packet type
  95.     LD    A,C        ;Get the length of DATA
  96.     LD    (ARGBLK+1),A    ;Store it
  97.     LD    A,'1'        ;Always 1 character checksum
  98.     LD    (CURCHK),A
  99.     LD    A,(CHKTYP)    ;Get the desired checksum type
  100.     LD    (INICHK),A    ;Save it for later
  101.     POP    AF        ;Get the packet type back
  102.     CALL    SPACK        ;Send the packet
  103.     JP    ABORT        ;Abort on an error
  104.     RPACKET            ;Receive a packet
  105.     IFANOT    'S',DOGEN2    ;Skip if not send_init
  106.     LD    A,(ARGBLK+1)    ;Get the length
  107.     LD    HL,DATA        ;Get the DATA area
  108.     CALL    SPAR        ;Get parameters from packet
  109.     LD    HL,DATA        ;Get the DATA area
  110.     CALL    RPAR        ;Put our capabilities in
  111.     LD    (ARGBLK+1),A    ;Store the length that is returned
  112.     SPACKET    'Y'        ;Send ACK with parameters
  113.     LD    A,(INICHK)    ;Get the requested checksum type
  114.     LD    (CURCHK),A    ;Store it as current
  115.     NSTATE    'f'        ;Set state to file receive
  116.     RET            ;Return to protocol switch
  117. DOGEN2    IFANOT    'X',DOGEN3    ;X packet?  Jump if not
  118.     CALL    SETUPDIS    ;Set up for terminal display
  119.     CALL    PRTPKTOUT    ;Print the packet contents
  120.     CALL    DOINC        ;Increment everything
  121.     LD    (ARGBLK+1),A    ;A is zero, so use for zero length
  122.     SPACKET    'Y'        ;Send ACK
  123.     NSTATE    'd'        ;Set state to receive DATA
  124.     RET
  125. ;
  126. DOGEN3    IFANOT    'Y',DOGEN4    ;Jump if not ACK
  127.     CALL    NEWLIN        ;Get a new line for data
  128.     CALL    PRTPKTOUT    ;Print the packets contents on screen
  129.     NSTATE    'C'        ;Set state to complete
  130.     RET            ;Return to proto switch
  131. ;
  132. DOGEN4    CP    'N'        ;Was it NAK?
  133.     RET    Z        ;If so, stay in this state
  134.     IFANOT    'E',DOGEN5    ;If not Error packet, then go
  135.     CALL    ERROR        ;Print error message
  136.     CALL    NEWLIN        ;Get a new line
  137.     JP    KERMIT        ;Get a new command
  138. ;
  139. DOGEN5    STROUT    UNKNOWN        ;Print unknown packet type message
  140.     XOR    A
  141.     LD    (ARGBLK+1),A    ;Set DATA length to zero
  142.     SPACKET    'E'        ;Send an error packet
  143.     JP    KERMIT        ;Get a new command
  144. ;
  145. ;    Do remote directory
  146. ;
  147. RMTDIR    EQU    $
  148.     GENCASE    'D',1
  149. ;
  150. ;    Remote delete file
  151. ;
  152. RMTDEL    EQU    $
  153.     GENCASE    'E',1
  154. ;
  155. ;    Remote disk utilization
  156. ;
  157. RMTDSK    EQU    $
  158.     GENCASE    'U',1
  159. ;
  160. ;    Remote Help
  161. ;
  162. RMTHLP    EQU    $
  163.     GENCASE    'H',1
  164. ;
  165. ;    Remote Program control
  166. ;
  167. RMTPRG    EQU    $
  168.     GENCASE    'P',2
  169. ;
  170. ;    Remote Kermit Command
  171. ;
  172. RMTKER    EQU    $
  173.     GENCASE    'P',1
  174. ;
  175. ;    Remote type command
  176. ;
  177. RMTTYPE    EQU    $
  178.     GENCASE    'T',1
  179. ;
  180. ;    Remote who command
  181. ;
  182. RMTWHO    EQU    $
  183.     GENCASE    'W',2
  184. ;
  185. ;    Remote change directory
  186. ;
  187. RMTCWD    EQU    $
  188.     GENCASE    'C',2
  189. ;
  190. ;    Remote rename a file
  191. ;
  192. RMTREN    EQU    $
  193.     GENCASE    'R',2
  194. ;
  195. ;    Remote copy a file
  196. ;
  197. RMTCOPY    EQU    $
  198.     GENCASE    'K',2
  199. ;
  200. ;    Remote send a message
  201. ;
  202. RMTMSG    EQU    $
  203.     GENCASE    'M',2
  204. ;
  205. ;    Remote set a variable
  206. ;
  207. RMTSET    EQU    $
  208.     LD    C,'S'
  209.     GENCASE    'V',2
  210. ;
  211. ;    Remote query a variable
  212. ;
  213. RMTQUERY    EQU    $
  214.     LD    C,'Q'
  215.     GENCASE    'V',2
  216. ;
  217. ;    Remote close the log file
  218. ;
  219. RMTCLOSE    EQU    $
  220.     LD    C,'c'
  221.     GENCASE    'J',1
  222. ;
  223. ;    Remote send log file
  224. ;
  225. RMTSEND    EQU    $
  226.     LD    C,'s'
  227.     GENCASE    'J',1
  228. ;
  229. ;    Remote start logging
  230. ;
  231. RMTSTART    EQU    $
  232.     LD    C,'+'
  233.     GENCASE    'J',1
  234. ;
  235. ;    Remote stop logging
  236. ;
  237. RMTSTOP    EQU    $
  238.     LD    C,'-'
  239.     GENCASE    'J',1
  240. ;
  241. ;    Remote login
  242. ;
  243. RMTLOGIN    EQU    $
  244.     GENCASE    'l',3
  245. ;
  246. ;    Remote server status query
  247. ;
  248. RMTSRV    EQU    $
  249.     GENCASE    'Q',1
  250. ;
  251. ;    Remote host command
  252. ;
  253. RMTHST    EQU    $
  254.     LD    DE,FILBUF
  255.     LD    A,CMTXT
  256.     CALL    COMND
  257.     JP    KERMT2
  258.     LD    (TEMP4),A
  259.     LD    A,CMCFM
  260.     CALL    COMND
  261.     JP    KERMT3
  262.     LD    A,(TEMP4)
  263.     LD    (GENLEN),A
  264.     LD    C,A
  265.     LD    B,0
  266.     LD    HL,FILBUF
  267.     ADD    HL,BC
  268.     LD    (HL),0
  269.     LD    A,1
  270.     LD    (FLDLEN),A
  271.     LD    A,'C'
  272.     LD    (PKTTYPE),A
  273.     JP    GENCMD5
  274. ;
  275. ;    Get users response, and put it into the buffer
  276. ;
  277. ENCFLDS    LD    A,CMTXT
  278.     LD    DE,DATA        ;Get the text
  279.     CALL    COMND
  280.     JP    KERMT2
  281.     CALL    ENCOLEN        ;Length encode each argument
  282.     JP    GETFIELD1    ;On error jump
  283.     LD    HL,RMTDATA    ;Get the input buffer
  284.     CALL    ENCSTR        ;Encode the contents
  285.     LD    A,(SIZE)    ;Get the length
  286.     LD    (GENLEN),A    ;Save it for later
  287.     RET            ;Return
  288. ;
  289. GETFIELD1    EQU    $    ;Bad string found in encodelen
  290.     STROUT    TOOLONG        ;Print string too long message
  291.     JP    KERMIT        ;Abort completely
  292. ;
  293. ;    Protocol switch code
  294. ;
  295. PROTO    EQU    $
  296.     LD    A,(STATE)
  297.     SWITCH    'D',SDATA    ;Send data
  298.     SWITCH    'F',SFILE    ;Send file
  299.     SWITCH    'T',SNDTRAN    ;Transition from 'F' to 'D'
  300.     SWITCH    'Z',SEOF    ;Send EOF
  301.     SWITCH    'S',SINIT    ;Send init
  302.     SWITCH    'B',SEOT    ;End of transmittion
  303.     SWITCH    'C',COMP    ;Completed
  304.     SWITCH    'A',SABORT    ;Abort
  305.     SWITCH    'd',RDATA    ;Receive data
  306.     SWITCH    'f',RFILE    ;Receive file
  307.     SWITCH    't',RECTRAN    ;Transition from 'f' to 'd'
  308.     SWITCH    'R',RINIT    ;Receive init
  309.     SWITCH    'r',RINITF    ;Receive init with filename (GET command)
  310.     SWITCH    'G',DOGEN    ;Generic server command
  311.     SWITCH    'I',IINIT    ;Generic init packet
  312.     CALL    SABORT        ;Bad protocol state
  313.     JP    KERMIT        ;Abort
  314. ;
  315. ;    SEND    I-INITIATE
  316. ;
  317. IINIT    CALL    CHKTRYS        ;Check retry threshold
  318.     LD    A,'1'        ;RESET TO USE SINGLE CHARACTER CHECKSUM
  319.     LD    (CURCHK),A    ;FOR STARTUP
  320.     LD    A,(CHKTYP)    ;GET OUR DESIRED BLOCK CHECK TYPE
  321.     LD    (INICHK),A    ;Store it as the initial value
  322.     LD    HL,DATA        ;GET A POINTER TO OUR DATA BLOCK.
  323.     CALL    RPAR        ;SET UP THE PARAMETER INFORMATION.
  324.     LD    (ARGBLK+1),A    ;SAVE THE NUMBER OF ARGUMENTS.
  325.     LD    A,(PKTNUM)    ;GET THE PACKET NUMBER.
  326.     LD    (ARGBLK),A
  327.     SPACKET    'I'        ;Send the I packet
  328.     RPACKET            ;Get the answer packet
  329.     CP    'Y'        ;Is it an ACK?
  330.     JP    NZ,IINIT3    ;IF NOT TRY NEXT.
  331.     CALL    CHKBLK
  332.     RET    NZ         ;IF NOT TRY AGAIN.
  333.     CALL    DOINC
  334.     LD    A,(ARGBLK+1)    ;GET THE NUMBER OF PIECES OF DATA.
  335.     LD    HL,DATA        ;POINTER TO THE DATA.
  336.     CALL    SPAR        ;READ IN THE DATA.
  337.     LD    A,(INICHK)    ;GET THE AGREED UPON BLOCK-CHECK-TYPE
  338.     LD    (CURCHK),A    ;STORE AS TYPE TO USE FOR PACKETS NOW
  339.     NSTATE    'G'
  340.     RET    
  341. IINIT3    IFANOT    'N',IINIT4    ;NAK?
  342.     CALL    UPDRTR        ;UPDATE THE NUMBER OF RETRIES.
  343.     RET
  344. IINIT4    CP    'E'        ;IS IT AN ERROR PACKET.
  345.     JP    NZ,ABORT    ;JUMP IF NOT
  346.     LD    A,80        ;SET UP ALL DEFAULT PARAMETERS
  347.     LD    (SPSIZ),A
  348.     XOR    A
  349.     LD    (SPAD),A
  350.     LD    (SPADCH),A
  351.     LD    A,13
  352.     LD    (SEOL),A
  353.     LD    A,'1'
  354.     LD    (CURCHK),A
  355.     LD    A,'#'
  356.     LD    (SQUOTE),A
  357.     NSTATE    'G'
  358.     RET
  359. ;
  360. ;    This routine encodes the length of the blank separated fields
  361. ;    into a packet for the generic routines.  If there are more
  362. ;    blank separated fields than FLDLEN says there should be, the
  363. ;    remaining fields are added to the end of the last field,
  364. ;    separated by blanks.
  365. ;
  366. ENCOLEN    LD    HL,DATA        ;Get the source
  367.     LD    DE,(INITRMT)    ;Get the initial location
  368.     LD    BC,(INITCNT)    ;Get the initial counters
  369.     PUSH    DE        ;Save the store address for length
  370.     PUSH    BC
  371.     INC    DE        ;Point to where the data goes
  372.     LD    A,(FLDLEN)    ;Get the number of fields
  373.     LD    B,A        ;Put it into the counter
  374.     POP    AF        ;Get the initial length
  375.     LD    (FLDLEN),A    ;Set the length to zero initially
  376. ENCLEN1    LD    A,(HL)        ;Get a character
  377.     IFANOT    20H,ENCLEN4    ;Jump if not space
  378. ENCLEN2    INC    HL        ;Point to next character
  379.     IFA    (HL),ENCLEN2    ;Loop while we are looking at a space
  380.     DJNZ    ENCLEN3        ;See if we have done all fields
  381.     INC    B        ;Reset the counter back to one if so
  382.     LD    (DE),A        ;Store a space
  383.     INC    DE        ;Point to next place to store at
  384.     INC    C        ;Increment the field length
  385.     JR    ENCLEN1        ;Process next character
  386. ENCLEN3    LD    A,C        ;Get the field length
  387.     TOCHAR            ;Make it printable
  388.     EX    (SP),HL        ;Get the store address for the length
  389.     LD    (HL),A        ;Store the length byte
  390.     POP    HL        ;Restore the old HL
  391.     PUSH    DE        ;Save the new length byte address
  392.     INC    DE        ;Point to the data store address
  393.     LD    C,0        ;Reset the count of characters
  394.     LD    A,(FLDLEN)    ;Get the total length
  395.     INC    A        ;Add one to the length
  396.     LD    (FLDLEN),A    ;Store the new length
  397.     JR    NZ,ENCLEN1    ;Continue if OK
  398.     POP    DE        ;Restore the stack
  399.     RET            ;Return error
  400. ENCLEN4    JR    C,ENCLEN5    ;If this is a control character then stop
  401.     INC    C        ;Correct for the comming decrement
  402.     LDI            ;Move one char, and increment counter
  403.     INC    C        ;Plus one more for the length
  404.     LD    A,(FLDLEN)    ;Get the length
  405.     INC    A        ;Add one for current character
  406.     LD    (FLDLEN),A    ;Store the new length
  407.     JR    NZ,ENCLEN1    ;Top of the loop if no overflow
  408.     POP    DE        ;Restore the stack
  409.     RET            ;Return error
  410. ENCLEN5    POP    HL        ;Get the length address
  411.     LD    A,C        ;Get the length
  412.     TOCHAR            ;Make it printable
  413.     LD    (HL),A        ;Store this fields length
  414.     XOR    A        ;Terminate the packet
  415.     LD    (DE),A
  416.     LD    A,(FLDLEN)    ;Get the overall length
  417.     LD    (GENLEN),A    ;Save it for later
  418.     OR    A        ;Is it a null length string?
  419.     JP    Z,RSKP        ;Return if it is
  420.     INC    A        ;Add one to length for field length byte
  421.     CP    MAXPKT-4    ;Too big for packet?
  422.     RET    P        ;Return error if string too long
  423.     LD    (GENLEN),A    ;Save it
  424.     JP    RSKP        ;Return to the caller
  425. ;end of file
  426.