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

  1. ;    M4MIT/ASM
  2. ;
  3.     ORG    6000H
  4. ;
  5. ;    Model 4(p) KERMIT by Gregg Wonderly
  6. ;
  7. ;    Version 5.2
  8. ;
  9. ;    Version 5.2 adds wild card send capabilities as well as fixes
  10. ;    to bugs.  M4CHGS/ASM contains a list of the changes made between
  11. ;    version 5.0, and 5.2.
  12. ;
  13. ;    This version is a radically modified and rewritten version
  14. ;    of the original TRS-80 KERMIT done by Stan Barber.  It has
  15. ;    numerous features and capabilities beyond that version due
  16. ;    to differences between the Model 3 and 4.
  17. ;
  18. ;    Get the macro definitions first
  19. ;
  20. *GET        M4EQU
  21. *GET        M4MAC
  22. ;
  23. ;    Entry point for execution
  24. ;
  25. START    LD    (OLDSP),SP    ;Save the current stack pointer for later
  26.     LD    SP,STACK    ;Set up the stack to our area
  27.     CALL    XFLAGS        ;Get the flags address in IY
  28.     LD    (FLAGS),IY    ;Save the flags for later
  29.     LD    HL,SWTBUF    ;Clear initial connect screen buffer
  30.     LD    DE,SWTBUF+1
  31.     LD    BC,1920        ;Byte counter
  32.     LD    (HL),' '    ;Clear the first character
  33.     LDIR            ;Copy it to the next
  34.     LD    B,1        ;Move low memory up above our code.
  35.     LD    HL,0        ;Select GET option of @HIGH$
  36.     CALL    XHIGH        ;Get the current LOW$
  37.     JP    NZ,BADMEM    ;Quit on an error
  38.     LD    (OLDLOW),HL    ;Save for restore on exit
  39.     LD    HL,TOPMEM    ;Get the last address used
  40.     CALL    XHIGH        ;Store it as the new LOW$
  41.     JP    NZ,BADMEM    ;Quit on an error
  42.     LD    E,'C'        ;Look for the *CL DCB
  43.     LD    D,'L'
  44.     CALL    XGTDCB        ;The address comes back in HL
  45.     LD    (CLDCB),HL    ;Save the address (May be wrong)
  46.     JR    NZ,NOCL        ;Now check for error...
  47.     LD    E,'S'        ;Look for the *SI DCB
  48.     LD    D,'I'
  49.     CALL    XGTDCB        ;The address comes back in HL
  50.     LD    (TMIDCB),HL    ;Store the result
  51.     JR    NZ,NOSI        ;Skip if NOT found or other error
  52.     LD    E,'S'        ;Look for the *SO DCB
  53.     LD    D,'O'
  54.     CALL    XGTDCB        ;The address comes back in HL
  55.     LD    (TMODCB),HL    ;Save the address
  56.     JR    NZ,NOSO        ;Jump if NOT found or other error
  57.     CALL    SETINT        ;Set up interupt receiver etc
  58.     XOR    A        ;ZERO A
  59.     LD    (FCB),A        ;SET FILE CLOSED FLAG
  60.     CALL    CMBLNK        ;CLEAR THE SCREEN
  61.     STROUT    INTRO        ;Print the intro message
  62.     CALL    CHKTAK        ;Check if there is a KERMIT/INI file
  63.     CALL    KERMIT        ;Start accepting commands.
  64.     JP    EXIT1        ;If control returns, then exit
  65. ;
  66. ;    Error messages printed when devices can not be found or allocated
  67. ;
  68. NOCL    LD    DE,CFCL        ;Error message (Can't find *CL DCB)
  69. PRTOOPS    CALL    PRTSTR        ;Print an OOPS message, and quit
  70.     JP    EXIT2        ;Finish cleaning up
  71. ;
  72. ;    No DCB for the SI device was found
  73. ;
  74. NOSI    LD    DE,CFSI        ;Get the message
  75.     JR    PRTOOPS        ;Go print it
  76. ;
  77. ;    No DCB for the SO device was found
  78. ;
  79. NOSO    LD    DE,CFSO        ;Get the message
  80.     JR    PRTOOPS        ;Go print it
  81. ;
  82. ;    Bad return code from @HIGH$ call
  83. ;
  84. BADMEM    CALL    XERROR0        ;Print a system error message
  85.     STROUT    NOMEM        ;Print the message
  86.     JP    XEXIT        ;Exit to TRSDOS
  87. ;
  88. ;    CLEAR THE SCREEN, SAVING DE
  89. ;
  90. CMBLNK    PUSH    DE        ;Save DE
  91.     STROUT    CLRTOP        ;Clear the screen
  92.     POP    DE        ;Restore DE
  93. QUIT    RET            ;Just a simple return for QUIT
  94. ;
  95. ;    KERMIT command processor
  96. ;    This is where each command originates.
  97. ;
  98. KERMIT    LD    SP,STACK    ;Set the stack back
  99.     LD    DE,FCB        ;Always close an open file
  100.     LD    A,(DE)        ;Get the flags byte
  101.     BIT    7,A        ;Is the file still open?
  102.     CALL    NZ,XCLOSE    ;Close it if it is
  103.     LD    DE,KERM        ;Get the prompt
  104.     CALL    PROMPT        ;Display it, and set up the parser
  105.     LD    DE,COMTAB    ;Get the primary command table
  106.     LD    A,CMKEY        ;Parse a keyword
  107.     CALL    COMND        ;Get a command or ERROR
  108.     JP    KERMT2        ;Abort on ERROR
  109.     LD    HL,KERMIT    ;Put on a return address for the
  110.     PUSH    HL        ;FINISH, LOGOUT, and BYE commands.
  111.     PUSH    HL
  112.     LD    HL,KERMTB    ;Get the JUMP table for these commands
  113.     LD    C,A        ;Make BC = A extended to 16 bits
  114.     LD    B,0        ;high byte is zero, (unsigned)
  115.     ADD    HL,BC        ;Calculate the effective address
  116.     JP    (HL)        ;Jump into the jump table
  117. ;
  118. ;    Jump table for primary commands
  119. ;
  120. KERMTB    JP    REMOTE        ;REMOTE
  121.     JP    EXIT        ;EXIT
  122.     JP    CONNECT        ;CONNECT
  123.     JP    LOG        ;LOG
  124.     JP    READ        ;RECEIVE
  125.     JP    SEND        ;SEND
  126.     JP    SETCOM        ;SET
  127.     JP    SHOW        ;SHOW
  128.     JP    STATUS        ;STATUS
  129.     JP    FINISH        ;FINISH
  130.     JP    LOGOUT        ;LOGOUT
  131.     JP    BYE        ;BYE
  132.     JP    DIR        ;DIRECTORY
  133.     JP    ERA        ;KILL
  134.     JP    LOCCOM        ;LOCAL
  135.     JP    SETCL        ;SETCOM
  136.     JP    TAKE        ;TAKE
  137.     JP    INPUT        ;INPUT
  138.     JP    OUTPUT        ;OUTPUT
  139.     JP    PAUSE        ;PAUSE
  140.     JP    PULSE        ;PULSE
  141.     JP    CLEARC        ;CLEAR
  142.     JP    CLSFLS        ;CLOSE
  143.     JP    ECHO        ;Type text to screen
  144. ;
  145. ;    Echo text to screen
  146. ;
  147. ECHO    EQU    $
  148.     LD    A,CMTXT        ;Get some text
  149.     LD    DE,DATA        ;Where to put it
  150.     PUSH    DE        ;Save for printing
  151.     CALL    COMND        ;Parse it
  152.     JP    KERMT3        ;Jump on error
  153.     POP    HL        ;Get the start
  154.     LD    C,A        ;Make BC the length that is in A
  155.     LD    B,0
  156.     ADD    HL,BC        ;Move to EOS position
  157.     LD    (HL),EOS    ;Put it in place
  158.     CALL    NEWLIN        ;Get a new line
  159.     STROUT    DATA        ;Print the string
  160.     JP    KERMIT        ;Get a new command
  161. ;
  162. ;    CLEAR command.  Services CLEAR INPUT-PORT, and CLEAR SCREEN
  163. ;
  164. CLEARC    LD    A,CMKEY        ;GET A KEYWORD
  165.     LD    DE,CLRTAB    ;FROM THIS TABLE
  166.     CALL    COMND
  167.     JP    KERMT2        ;SAY UNRECOGNIZED COMMAND ON AN ERROR
  168.     LD    (TEMP1),A    ;SAVE THE RETURNED VALUE
  169.     LD    A,CMCFM
  170.     CALL    COMND
  171.     JP    KERMT3
  172.     LD    A,(TEMP1)
  173.     LD    C,A
  174.     IFNZ    CLR010
  175.     CALL    CLRPRT        ;DO "CLEAR INPUT-PORT"
  176.     JP    KERMIT        ;GET A NEW COMMAND
  177. CLR010    CP    3        ;IS IT CLEAR SCREEN?
  178.     JP    NZ,KERMT2    ;SAY UNRECOGNIZED COMMAND IT NOT
  179.     CALL    CMBLNK        ;CLEAR THE SCREEN
  180.     JP    KERMIT        ;GET A NEW COMMAND
  181. ;
  182. ;    TAKE commands from a file.  This is basically a HACK that
  183. ;    initializes some values so that GETSTR reads from the file,
  184. ;    instead of the keyboard, until EOF is found.
  185. ;
  186. TAKE    LD    DE,TFCB        ;WHERE TO PUT THE FILENAME
  187.     LD    A,CMIFI        ;GET A FILE NAME
  188.     CALL    COMND        ;GET USER INPUT
  189.     JP    KERMT3        ;ABORT ON AN ERROR
  190.     OR    A
  191.     JP    Z,KERMT3    ;Abort if no name given
  192.     LD    IY,(FLAGS)    ;GET THE SYSTEM FLAGS
  193.     SET    0,(IY+18)    ;SET UP FOR NO FILE OPEN BIT
  194.     LD    HL,TBUF        ;THIS IS THE DATA BUFFER
  195.     LD    DE,TFCB        ;GET THE FILE FCB
  196.     LD    B,0        ;256 BYTE LRL
  197.     CALL    XOPEN        ;TRY TO OPEN THE FILE
  198.     JR    NZ,TERROR    ;GO REPORT AN ERROR
  199.     LD    A,1
  200.     LD    (TAKFLG),A    ;SET THE FLAG
  201.     JP    KERMIT
  202. TERROR    CALL    XERROR0        ;PRINT THE MESSAGE
  203.     XOR    A        ;RESET THE TAKE FLAG
  204.     LD    (TAKFLG),A
  205.     JP    KERMIT        ;GET A NEW COMMAND
  206. ;
  207. ;    SETCOM command.  We use the TRSDOS SETCOM command here, as it
  208. ;    saves lots of time and trouble.
  209. ;
  210. SETCL    LD    A,CMTXT        ;GET ARBITRARY TEXT
  211.     LD    DE,CLBUF    ;BUFFER TO PUT DATA INTO
  212.     CALL    COMND        ;GET THE INPUT
  213.     JP    KERMT3        ;ABORT ON ERROR
  214.     CALL    NEWLIN        ;NEED A NEW LINE TO PRINT ON
  215.     LD    A,CR        ;Get the EOL character
  216.     LD    (DE),A        ;Put in the terminator
  217.     LD    HL,CLBUF-7    ;Get the 'SETCOM ' prefix
  218.     CALL    XCMNDR        ;Let TRSDOS do it for us
  219.     JP    KERMIT        ;Get a new command, ignoring any errors
  220. ;
  221. ;    LOCAL command.  Use @CMNDR to execute a TRSDOS command
  222. ;
  223. LOCCOM    LD    HL,(CMDPTR)    ;GET THE ADDRESS OF THE START
  224. SYST1    LD    A,(HL)        ;GET A CHARACTER
  225.     INC    HL        ;POINT TO THE NEXT
  226.     IFA    ' ',SYST1    ;Loop if just a blank
  227.     IFA    CR,SYST2    ;Do a LIB command if no text given
  228.     IFANOT    '?',SYST4    ;Go if user not asking for HELP
  229. SYST2    PUSH    HL        ;SAVE THE ADDRESS TO PASS
  230.     POP    IY        ;GET A THE ADDRESS IN AN INDEX
  231.     LD    (IY-1),'L'    ;HL GO INCREMENTED UP THERE
  232.     LD    (IY),'I'    ;SPELLING OUT LIB
  233.     LD    (IY+1),'B'
  234.     LD    (IY+2),CR    ;ADD THE TERMINATOR
  235. SYST4    DEC    HL        ;POINT TO THE ACTUAL ADDRESS
  236.     CALL    NEWLIN    ;NEED A NEW LINE
  237. ;
  238. ;    Remove the comments below to force LOCAL to process only library
  239. ;    commands
  240. ;
  241. ;    LD    IY,(FLAGS)    ;Get the Flags pointer
  242. ;    SET    4,(IY+2)    ;Only library commands are allowed
  243.     CALL    XCMNDR        ;Do a system command
  244. SYST5    JP    KERMIT        ;IGNORE ANY ERRORS
  245. ;
  246. ;    Print UNRECOGNIZED COMMAND message
  247. ;
  248. KERMT2    STROUT    ERMES1        ;Issue the message
  249.     JP    KERMIT
  250. ;
  251. ;    Print NOT CONFIRMED message
  252. ;
  253. KERMT3    STROUT    ERMES3        ;Issue the message
  254.     JP    KERMIT
  255. ;
  256. ;    Exit to TRSDOS
  257. ;
  258. EXIT    LD    A,CMCFM        ;Get a confirmation of the EXIT
  259.     CALL    COMND
  260.     JP    KERMT3
  261. EXIT1    LD    DE,FCB        ;Check the file FCB, and close if needed
  262.     LD    A,(DE)        ;Get the info byte
  263.     BIT    7,A        ;Check the file open BIT
  264.     CALL    NZ,XCLOSE    ;Close it if needed
  265. ;
  266. ;    Check the log files to make sure they are closed
  267. ;
  268.     LD    DE,LFCB        ;Get the file FCB
  269.     LD    A,(LOGFLG)    ;Check if logging active
  270.     OR    A        ;Check the flags
  271.     CALL    NZ,XCLOSE    ;Close the file if open
  272.     LD    DE,DFCB        ;Check debugging
  273.     LD    A,(DEBLOG)    ;Get the flag
  274.     OR    A
  275.     CALL    NZ,XCLOSE    ;Close it if open
  276.     LD    DE,TFCB        ;Get the FCB
  277.     LD    A,(TRANLOG)    ;Get the flag
  278.     OR    A
  279.     CALL    NZ,XCLOSE    ;Close it if open
  280. ;
  281. ;    Now reset the interrupt vector for *CL.
  282. ;
  283.     LD    C,4        ;Interrupts option of the @CTL SVC
  284.     LD    IY,0        ;Reset the INTERRUPT vector of *CL
  285.     LD    DE,(CLDCB)    ;Get the *CL DCB address
  286.     CALL    XCTL        ;Use @CTL to do it
  287.     CALL    CMBLNK        ;Clear the screen
  288. EXIT2    LD    HL,(OLDLOW)    ;Get the old low memory pointer
  289.     LD    B,1        ;Set B to indicate LOW$
  290.     CALL    XHIGH        ;Move the value back
  291. ;
  292. ;    Now fill the *FO, and *FI devices DCB's with zeros.  This
  293. ;    will make the devices no longer available.
  294. ;
  295.     LD    HL,(FINDCB)    ;Get the *FI DCB address
  296.     CALL    ZERO8        ;Fill it with zeroes
  297.     LD    HL,(FOTDCB)    ;Do the same for *FO
  298.     CALL    ZERO8        ;Fill DCB with zeroes
  299.     CALL    STOPTIMER    ;Stop the timer if still running
  300.     LD    SP,(OLDSP)    ;Restore the old STACK pointer
  301.     LD    HL,0        ;Set OK exit
  302.     LD    IY,(FLAGS)    ;If JCL active, then just return
  303.     BIT    5,(IY+18)    ;Check the BIT
  304.     RET    NZ        ;Return if BIT is set
  305.     JP    XEXIT        ;Exit via @EXIT
  306. ;
  307. ;    Zero 8 bytes pointed to by HL
  308. ;
  309. ZERO8    LD    B,8        ;Get the byte count
  310. ZERO8_1    LD    (HL),0        ;Zap one byte
  311.     INC    HL        ;Point to next
  312.     DJNZ    ZERO8_1        ;Loop until done
  313.     RET
  314. ;
  315. ;    CALL ERROR    Prints the DATA area on a new line, and sets
  316. ;            the state to ABORT.
  317. ;    CALL ERROR1    Prints the DATA area on a new line.
  318. ;    CALL ERROR2    Prints the DATA area on the same line
  319. ;    CALL ERROR3    Prints the string pointed to by DE on a new line
  320. ;    CALL ERRORD    Prints a system error message corresponding to
  321. ;            A, providing A is none zero.
  322. ;
  323. ERROR    NSTATE    'A'        ;Set the state to abort
  324. ;
  325. ERROR1    CALL    NEWLIN        ;Get a new line
  326. ;
  327. ERROR2    LD    A,(ARGBLK+1)    ;Get the length of the data
  328.     LD    C,A        ;Put the length into BC
  329.     LD    B,0
  330.     LD    HL,DATA        ;Get the start of the DATA area
  331.     PUSH    HL        ;Save it
  332.     LD    A,EOS        ;Add EOS for printing
  333.     CALL    PUTTRN
  334.     POP    DE        ;Get start back
  335.     JP    PRTSTR        ;Print the string, and return
  336. ;
  337. ERROR3    PUSH    DE        ;Save the message
  338.     CALL    NEWLIN        ;Get a new line
  339.     POP    DE        ;Restore the message
  340.     JP    PRTSTR        ;Print error message
  341. ;
  342. ERRORD    OR    A        ;Display system error message
  343.     RET    Z        ;IFF an error has occured
  344.     JP    XERROR0        ;Do system error
  345. ;
  346. ;    Print the string in DE, followed by a new line
  347. ;
  348. FINMES    CALL    PRTSTR        ;Print the message
  349.     JP    NEWLIN        ;Get a newline and return
  350. ;
  351. ;    The FINISH, BYE, and LOGOUT commands all need a return address
  352. ;    on the stack.  This is because the CHKTRYS routine will use it
  353. ;    to abort the packet operations when MAXTRY retries are reached.
  354. ;
  355. ;    This is the FINISH command.
  356. ;
  357. FINISH    LD    A,CMCFM
  358.     CALL    COMND        ;GET A CONFIRM.
  359.     JP    KERMT3
  360.     CALL    NEWLIN
  361.     CALL    CLRPRT        ;CLEAR ANY STACKED NAKS
  362.     XOR    A        ;DIDN'T GET A CONFIRM.
  363.     LD    (NUMTRY),A    ;INITITIALIZE COUNT.
  364.     LD    A,'1'        ;Set block check to single char
  365.     LD    (CURCHK),A    ;. . .
  366. FINSH1    CALL    CHKTRYS        ;Check the retry threshold
  367.     XOR    A
  368.     LD    (ARGBLK),A    ;MAKE IT PACKET NUMBER ZERO.
  369.     LD    A,1
  370.     LD    (ARGBLK+1),A    ;ONE PIECE OF DATA.
  371.     LD    HL,DATA
  372.     LD    (HL),'F'    ;FINISH RUNNING KERMIT.
  373.     LD    A,'G'        ;GENERIC COMMAND PACKET.
  374.     CALL    SPACK        ;Send the packet
  375.     JP    FINSH1        ;On fail, try again
  376.     CALL    RPACK         ;GET AN ACKNOWLEDGEMENT.
  377.     JP    FINSH1        ;On fail, try again
  378.     CP    'Y'        ;ACK?
  379.     JP    Z,KERMIT    ;YES, WE ARE DONE.
  380.     IFANOT    'E',FINSH2    ;Jump if not error packet
  381.     CALL    ERROR1        ;PRINT THE ERROR MESSAGE.
  382.     JP    KERMIT
  383. FINSH2    CP    'N'        ;Is this a NAK?
  384.     CALL    NZ,CONOUT    ;Output the packet type to term
  385.     JR    FINSH1        ;Resend the packet
  386. ;
  387. ;    This is the LOGOUT command.
  388. ;
  389. LOGOUT    LD    A,CMCFM
  390.     CALL    COMND        ;GET A CONFIRM.
  391.     JP    KERMT3
  392.     CALL    NEWLIN
  393.     CALL    LOGO        ;SEND THE LOGOUT PACKET.
  394.     JP    LOG111        ;GO GET ANOTHER COMMAND
  395.     JP    KERMIT        ;WHETHER WE SUCCEED OR NOT.
  396. LOGO    XOR    A
  397.     LD    (NUMTRY),A    ;INITITIALIZE COUNT.
  398.     CALL    CLRPRT        ;CLEAR ANY STACKED NAKS
  399.     LD    A,'1'        ;Block check type to single
  400.     LD    (CURCHK),A    ;. . .
  401. LOGO1    CALL    CHKTRYS        ;Check retry threshold
  402.     XOR    A
  403.     LD    (ARGBLK),A    ;MAKE IT PACKET NUMBER ZERO.
  404.     LD    A,1
  405.     LD    (ARGBLK+1),A    ;ONE PIECE OF DATA.
  406.     LD    HL,DATA
  407.     LD    (HL),'L'    ;LOGOUT THE REMOTE HOST.
  408.     LD    A,'G'        ;GENERIC COMMAND PACKET.
  409.     CALL    SPACK
  410.     JP    LOGO3
  411.     CALL    RPACK        ;GET AN ACKNOWLEDGEMENT
  412.     JP    LOGO1
  413.     CP    'Y'        ;ACK?
  414.     JP    Z,RSKP        ;YES, WE ARE DONE.
  415.     CP    'E'        ;IS IT AN ERROR PACKET?
  416.     JP    Z,ERROR1    ;Print the error message
  417. LOGO2    CP    'N'
  418.     CALL    NZ,CONOUT
  419.     JR    LOGO1
  420. ;
  421. LOGO3    LD    DE,ERMS19    ;Get the message
  422.     JP    PRTSTR        ;Print it
  423. ;
  424. ;    This is the BYE command
  425. ;
  426. BYE    EQU    $
  427.     LD    A,CMCFM
  428.     CALL    COMND        ;GET A CONFIRM.
  429.     JP    KERMT3
  430.     CALL    NEWLIN
  431.     CALL    LOGO        ;TELL THE MAIN FRAME TO LOGOUT.
  432.     JP    LOG111        ;IF IT FAILS, DON'T EXIT.
  433.     JP    EXIT1        ;EXIT KERMIT.
  434. LOG111    CALL    NEWLIN        ;GET A NEW LINE
  435.     JP    KERMIT
  436. ;
  437. ;    Get the rest of the modules
  438. ;
  439. *GET    M4FILE/ASM    ;Log file code
  440. *GET     M4CMD/ASM    ;Command parser
  441. *GET    M4SET/ASM    ;Set command processing
  442. *GET    M4TERM/ASM    ;Terminal emulation
  443. *GET    M4SHOW/ASM    ;Show command processing
  444. *GET    M4PKT/ASM    ;Additional packet stuff
  445. *GET    M4GET/ASM    ;Receive protocol
  446. *GET    M4SEND/ASM    ;Send protocol
  447. *GET    M4XFER/ASM    ;Protocol common code
  448. *GET    M4ADD/ASM    ;TRSDOS SVC's and other system dependent stuff
  449. *GET    M4RMT/ASM    ;Remote commands
  450. *GET    M4KEY/ASM    ;Set key code
  451. *GET    M4LOG/ASM    ;Input, Output, Pause, Pulse commands
  452. *GET    M4WILD/ASM    ;Wild carding
  453. *GET     M4STR/ASM    ;Strings and storage
  454. TOPMEM    EQU    $+10    ;A little padding
  455.     END    START
  456. ;end of file
  457.