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

  1. ;    m4term/asm
  2. ;
  3. ;    This is the connect command
  4. ;
  5. CONNECT    EQU    $
  6.     LD    A,CMCFM        ;Get a confirmation
  7.     CALL    COMND
  8.     JP    KERMT3        ;Abort if no <ENTER> pressed
  9.     CALL    SCRCON        ;Swap in the proper screen
  10.     LD    A,(MAXCNT)    ;Select the proper buffer size
  11.     LD    (SVMAX),A
  12.     LD    A,80        ;80 characters max are buffered
  13.     LD    (MAXCNT),A
  14.     LD    A,(FTIME)    ;Is this the VERY FIRST connect?
  15.     IFNZ    CON_2
  16.     STROUT    CLRTOP        ;Clear the screen
  17. CON_1    STROUT    INFMS7        ;Display the message
  18.     CALL    ESCPR
  19.     STROUT    INFMS8
  20.     LD    A,1        ;Set the first time done flag
  21.     LD    (FTIME),A
  22. CON_2    LD    A,14
  23.     CALL    CONOUT
  24. ;
  25. ;    While in connect mode, at most, 30 characters may be processed
  26. ;    from the input port, before the keyboard is scaned. We try not
  27. ;    to scan the keyboard too much, as that will kill screen I/O. This
  28. ;    is especially true at higher baud rates, where the user might
  29. ;    not get to type a key because the flow of characters into the
  30. ;    port is continuous.
  31. ;
  32. CHRLUP    LD    A,30        ;Set the maximum character count
  33.     LD    (CHCNT),A    ;Save it
  34.     CALL    PRTCHR        ;Do input characters
  35.     CALL    CONCHR        ;Get a keyboard character
  36.     JP    KERMIT        ;IF we return here, then abort
  37.     JR    CHRLUP        ;Loop on
  38. ;
  39. ;    Look at the input buffer for a character, and return it, or
  40. ;    return no input.
  41. ;
  42. INPORT    PUSH    HL        ;SAVE HL
  43.     LD    HL,(NXTCHR)    ;Get address of next input char
  44.     LD    A,(CURCHR)    ;Get the LSB of the queue start
  45.     IFA    L,INOUT        ;If A=L, then there is no input.
  46.     DI            ;Interrupts off, CRITICAL section
  47.     LD    A,(HL)        ;Get the character back
  48.     LD    (SVCHAR),A    ;Save the input character
  49.     INC    L        ;Delete the character
  50.     LD    (NXTCHR),HL    ;Set the new pointer
  51.     LD    HL,INCNT    ;Decrement the count
  52.     DEC    (HL)
  53.     EI            ;Interrupts back on
  54.     LD    A,(FLOFLG)    ;Is XON/XOFF in effect?
  55.     IFZ    INP11        ;Go if not doing flow control
  56.     PUSH    BC        ;Save BC
  57.     LD    C,(HL)        ;Get a copy of the count
  58.     LD    A,(XFFLG)    ;Check if XOFF sent out
  59.     IFZ    INP10        ;Jump if not
  60.     LD    A,(MAXCNT)    ;It was, so check if time for XON
  61.     SRL    A        ;Use 1/2 of the max as the restart count
  62.     IFALT    C,INP10        ;If A >= count it is not time yet
  63.     PUSH    DE        ;Save DE
  64.     LD    E,XON        ;Get an XON character
  65.     CALL    OUTCHR        ;Out the port it goes
  66.     XOR    A        ;Reset the XOFF sent flag
  67.     LD    (XFFLG),A
  68.     POP    DE        ;Restore E
  69. INP10    POP    BC        ;Restore C
  70. INP11    LD    A,0        ;Get the next character
  71. SVCHAR    EQU    $-1
  72.     CP    A        ;Set Z status for normal return
  73. INOUT1    POP    HL        ;Restore HL
  74.     RET            ;Back to caller
  75. ;
  76. ;    No input exit from INPORT
  77. ;
  78. INOUT    EQU    $
  79.     XOR    A        ;Reset the count
  80.     LD    (INCNT),A    ;Zeroed
  81.     INC    A        ;Set NZ (We know A was zero, now it is 1)
  82.     POP    HL        ;Restore HL
  83.     RET            ;Back to the caller
  84. ;
  85. ;    Input a character, and display it based on the current value
  86. ;    of EMULATION.
  87. ;
  88. PRTCHR    CALL    INPORT        ;Try to get an input character.
  89.     RET    NZ        ;Return if none there
  90.     LD    E,A        ;Get the input character
  91.     CALL    LOGONE        ;Maybe do logging
  92.     LD    A,(PRTFLG)    ;CHECK FOR PRINTER OUTPUT
  93.     OR    A        ;SET THE FLAGS
  94.     CALL    NZ,PRTIT    ;GO PRINT IT
  95.     LD    A,E        ;GET THE CHARACTER AND DISPLAY
  96.     CALL    TRMOUT        ;Send it to the *SO device
  97.     LD    B,0        ;Get the current count
  98. CHCNT    EQU    $-1
  99.     DJNZ    PRTCHR5        ;SKIP RETURN IF NOT LIMIT
  100.     RET            ;RETURN AFTER LIMIT IS UP
  101. PRTCHR5    LD    A,B        ;GET THE NEW COUNT
  102.     LD    (CHCNT),A    ;SAVE IT
  103.     JP    PRTCHR        ;LOOP ON
  104. ;
  105. ; Input a character from the keyboard.
  106. ;
  107. CONCHR    CALL    GETKEY        ;Get a keyboard character without
  108.     JP    NZ,RSKP        ;Return if not one
  109.     LD    E,A        ;Is it CONNECT escape character?
  110.     LD    A,(ESCCHR)
  111.     CP    E
  112.     JP    Z,INTCHR    ;Go process the next key pressed
  113. CONCHR2    IFANOT    128,CONCHR3    ;BREAK?
  114.     CALL    DOBRK        ;Generate real BREAK
  115.     JP    RSKP
  116. CONCHR3    LD    A,E
  117. CONCHR4    PUSH    DE        ;SAVE DE
  118.     CALL    PRTOUT        ;SEND IT TO THE PORT
  119.     POP    DE
  120.     LD    A,(ECOFLG)    ;CHECK FOR LOCAL ECHO
  121.     OR    A
  122.     LD    A,E
  123.     CALL    NZ,TRMOUT    ;Echo out terminal device
  124.     JP    RSKP        ;RETURN TO THE CALLER SAY OK
  125. ;
  126. ;    This is the code to process the escape sequences during the
  127. ;    CONNECT command that do things like return to the KERMIT
  128. ;    prompt, send a break, turn logging on and off, etc...
  129. ;
  130. INTCHR    EQU    $
  131.     CALL    GETKEY        ;Get a character from translator
  132.     JR    NZ,INTCHR    ;Loop until we get one
  133. INCH00    EQU    $
  134.     LD    B,A        ;Put the real character into B
  135.     AND    137O        ;Convert A to upper case
  136.     IFANOT    'C',INCH01    ;Is it connect, if not try other
  137.     CALL    SCRCMD        ;Swap KERMIT screen in
  138.     LD    A,(SVMAX)    ;Restore the old max
  139.     LD    (MAXCNT),A
  140.     RET            ;Return to KERMIT
  141. INCH01    LD    A,B        ;Get the real value
  142.     IFANOT    '?',INTCH1    ;Is it help, if not try next
  143.     LD    A,15        ;Turn the cursor off
  144.     CALL    CONOUT
  145.     LD    B,4        ;Get the cursor position
  146.     CALL    XVDCTL
  147.     PUSH    HL        ;Save it
  148.     LD    HL,2600H    ;Save the screen
  149.     LD    B,6        ;Get screen function
  150.     CALL    XVDCTL        ;Do the move
  151.     LD    HL,0C00H    ;Move to middle
  152.     CALL    TOSCRPOS    ;Move to possition on screen
  153.     LD    A,31        ;Clear to eos
  154.     CALL    CONOUT
  155.     LD    DE,INTHLP    ;Get Help message
  156.     CALL    PRTSTR        ;Print message
  157. INCH11    CALL    GETKEY        ;Get a character
  158.     JR    NZ,INCH11    ;Jump if no key pressed
  159.     POP    HL        ;Reorder the stack
  160.     PUSH    AF
  161.     PUSH    HL
  162.     LD    HL,2600H    ;Get the old screen
  163.     LD    B,5        ;Put it back into view
  164.     CALL    XVDCTL
  165.     POP    HL        ;Restore old cursor position
  166.     CALL    TOSCRPOS    ;Position the cursor
  167.     LD    A,14        ;Turn the cursor back on
  168.     CALL    CONOUT
  169.     POP    AF        ;Get the character typed back
  170.     JR    INCH00        ;Loop back to process character
  171. ;
  172. INTCH1    AND    137O        ;Convert back to uppercase
  173.     IFANOT    'B',INTCH2    ;Is it BREAK, if not try next
  174.     CALL    DOBRK        ;Send BREAK out port
  175.     JP    RSKP        ;Return NO error
  176. INTCH2    LD    A,B        ;Get the real character
  177.     IFANOT    '0',INTCH3    ;Is it NULL, if not try next
  178.     LD    E,0        ;Get a NULL
  179.     CALL    OUTCHR        ;Out the port with it
  180.     JP    RSKP        ;Return no error
  181. INTCH3    LD    E,B        ;Get the real character
  182.     LD    A,(ESCCHR)    ;Get the escape character
  183.     IFA    E,INTCHZ    ;Is it the escape character ?
  184.     LD    A,B        ;Get the real character
  185.     AND    137O        ;Upper case again
  186.     IFANOT    'Q',INTCH4    ;Is it QUIT, if not try next
  187.     LD    A,(LOGFLG)    ;Get the logging flag
  188.     IFANOT    2,INTC3A    ;Is logging active, jump if not
  189.     DEC    A        ;Turn logging off
  190.     LD    (LOGFLG),A    ;Set the value
  191.     JP    RSKP        ;Return no error
  192. INTC3A    LD    A,BELL        ;Get An error sound
  193.     CALL    CONOUT        ;BEEP AT THEM
  194.     JP    RSKP        ;Return no error
  195. INTCH4    IFANOT    'R',INTCH5    ;Resume logging?  Jump if not
  196.     LD    A,(LOGFLG)    ;Check logging status
  197.     IFANOT    1,INTC3A    ;If not 1, can't resume
  198.     INC    A        ;Turn logging on
  199.     LD    (LOGFLG),A    ;Set the value
  200.     JP    RSKP        ;Return no error
  201. INTCH5    LD    A,E        ;Get the character typed
  202.     CALL    PRTOUT        ;Send it out the port
  203.     JP    RSKP        ;Return no error
  204. INTCHZ    CALL    OUTCHR        ;Send it out the port
  205.     LD    A,BELL        ;Get a bell
  206.     CALL    CONOUT        ;Send bell to terminal
  207.     JP    RSKP        ;Return no error
  208. ;
  209. ;    Send character to printer
  210. ;
  211. PRTIT    EQU    $
  212.     LD    A,E        ;Get the character
  213.     PUSH    DE        ;Save E for return
  214.     CALL    XPRT        ;Dos printer routine
  215.     POP    DE        ;Restore E
  216.     RET            ;Return
  217. ;
  218. ;    Generate a real modem break
  219. ;
  220. DOBRK    LD    C,1        ;OPTION 1 OF @CTL
  221.     LD    DE,(CLDCB)    ;Get the *CL DCB
  222.     CALL    XCTL        ;Do @CTL to start Modem break
  223.     DI            ;Make the pause be exact
  224.     LD    BC,39000    ;Pause for 200ms
  225. BRKLOOP    DEC    BC        ;Decrement the count
  226.     LD    A,B
  227.     OR    C
  228.     JR    NZ,BRKLOOP    ;Loop until done
  229.     EI
  230.     LD    E,0        ;Stop break with any character
  231.     JP    OUTCHR        ;Null is good
  232. ;
  233. ;    Output any none null character to the RS232 port
  234. ;
  235. PRTOUT    OR    A        ;Don't send NULLS
  236.     RET    Z
  237.     LD    E,A        ;Get the character
  238.     JP    OUTCHR        ;Output it
  239. ;
  240. ;    Log a character to the log file
  241. ;
  242. LOGONE    PUSH    AF
  243.     PUSH    DE
  244.     LD    E,A
  245.     LD    A,(LOGFLG)
  246.     OR    A
  247.     LD    A,E
  248.     CALL    NZ,LOGIT
  249.     POP    DE
  250.     POP    AF
  251.     RET
  252. ;
  253. ;    Output a character to *DO
  254. ;
  255. CONOUT    PUSH    DE        ;SAVE THE REGS
  256.     PUSH    BC
  257.     PUSH    AF
  258.     IFA    BELL,BEEPON    ;Go if bell
  259.     CALL    XDSP        ;Use the @DSP SVC to display it
  260. CON010    POP    BC        ;Use BC to get A, and not destroy flags
  261.     LD    A,B        ;Get the old A
  262.     POP    BC
  263.     POP    DE
  264.     RET            ;RETURN TO THE CALLER
  265. ;
  266. ;    Output a character to *SO
  267. ;
  268. TRMOUT    PUSH    DE        ;Save the regs
  269.     PUSH    BC
  270.     PUSH    AF
  271.     LD    E,A        ;Make a copy of the character
  272.     LD    A,(EMULFLAG)    ;Get the emulation flag
  273.     IFZ    TRMOUT3        ;Jump if EMULATION set to NONE
  274. ;
  275. ;    Certain control characters are translated on input. In
  276. ;    particular, the following mappings are in effect.
  277. ;
  278. ;    8  -> 24    non destructive backspace
  279. ;    10 -> 26    non destructive linefeed
  280. ;    13 -> 29    True carriage return
  281. ;
  282.     LD    A,E        ;Is this a control character?
  283.     IFAGE    32,TRMOUT3    ;Jump if not a control character
  284.     LD    HL,TRTAB    ;Get the translation table
  285.     LD    B,0        ;Make BC an offset into TRTAB
  286. ;
  287. ;    If the character in the translation table is 0, then it is
  288. ;    ignored. This is handy for blocking out things like cursor
  289. ;    on/off, and inverse video on/off
  290. ;
  291.     LD    C,A        ;Get the character to use as index
  292.     ADD    HL,BC        ;Index to the table
  293.     LD    A,(HL)        ;Get the translated character
  294.     IFZ    TRMOUT5        ;Return if character is to be ignored
  295.     LD    E,A        ;Make a copy for later
  296.     IFANOT    12,TRMOUT1    ;Jump if not a formfeed
  297.     CALL    CMBLNK        ;Clear the screen
  298.     JR    TRMOUT5
  299. TRMOUT1    IFANOT    7,TRMOUT3    ;Jump if not bell
  300.     CALL    CONOUT        ;DUMB uses BUILTIN Bell
  301.     JR    TRMOUT5
  302. TRMOUT3    EQU    $
  303.     LD    A,E        ;Get the character
  304.     LD    DE,(TMODCB)    ;Get the Device DCB for terminal out
  305.     CALL    XPUT        ;@PUT the character to the device
  306. TRMOUT5    POP    BC        ;Use BC to get A, and leave Flags alone
  307.     LD    A,B        ;Get A
  308.     POP    BC        ;Restore BC
  309.     POP    DE        ;And the rest
  310.     RET
  311. ;
  312. ;    Input a character from *SI
  313. ;
  314. TRMIN    PUSH    DE
  315.     PUSH    BC
  316.     LD    DE,(TMIDCB)    ;Get the terminal input DCB
  317.     CALL    XGET        ;@GET a character
  318.     POP    BC        ;Restore the regs
  319.     POP    DE
  320.     RET
  321. ;
  322. ;    Sound a bell
  323. ;
  324. BEEPON    LD    A,(BELFLG)    ;IS THAT OPTION ON?
  325.     IFZ    CON010        ;Jump if bell option off
  326.     PUSH    BC        ;Save counter
  327.     LD    C,50        ;Get the duration
  328. BEEP1    LD    A,1        ;Get the value to send out port
  329.     OUT    (90H),A        ;Toggle port high
  330.     LD    B,130        ;Delay
  331.     DJNZ    $
  332.     DEC    A        ;Set A to zero
  333.     OUT    (90H),A        ;Toggle port low
  334.     LD    B,130        ;Delay
  335.     DJNZ    $
  336.     DEC    C        ;Decrement duration
  337.     JR    NZ,BEEP1    ;Loop if not done
  338.     POP    BC        ;Restore counter
  339.     JR    CON010        ;Join return code
  340. ;
  341. ;    Print string pointed to by DE to *DO, EOS is end of string
  342. ;    NUL characters are thrown out.
  343. ;
  344. PRTSTR    LD    A,(DE)        ;GET A CHARACTER
  345.     CP    EOS        ;IS IT THE END?
  346.     RET    Z        ;RETURN TO CALLER IF SO
  347.     OR    A        ;THROW AWAY THE NULL CHARACTER
  348.     CALL    NZ,CONOUT    ;DISPLAY ANYTHING NON-NULL
  349.     INC    DE        ;POINT TO THE NEXT ONE
  350.     JR    PRTSTR        ;LOOP ON
  351. ;
  352. ;    Get a character from *KI
  353. ;
  354. CONIN    PUSH    DE        ;SAVE DE
  355.     CALL    XKBD        ;LOOK AT THE KEYBOARD WITHOUT WAITING
  356.     POP    DE        ;RESTORE DE
  357.     RET            ;RETURN TO THE CALLER
  358. ;
  359. ;    Output a character to *CL.  The character is in E.
  360. ;
  361. OUTCHR    PUSH    DE        ;SAVE CURRENT DE AND BC
  362.     PUSH    BC
  363.     LD    C,E        ;Put the character where it should be
  364. OUTCH0    LD    A,(XOFREC)    ;CHECK TO SEE IF WE CAN TRANSMIT YET!
  365.     IFZ    OUTCH2
  366. ;
  367. ;    We allow break to force the transmittion of the character that
  368. ;    is being sent.  There are ways that the XON from the host can
  369. ;    be lost.  This allows control to be regained, without rebooting
  370. ;    which would be the only other choice.
  371. ;
  372. OUTCH1    CALL    CONIN        ;Check the break key
  373.     IFANOT    128,OUTCH0    ;Jump if not
  374.     XOR    A        ;Reset the XOF'd flag
  375.     LD    (XOFREC),A
  376. OUTCH2    LD    A,C        ;Get the character to send
  377. OUTCH3    LD    DE,(CLDCB)    ;GET THE DCB OF THE DEVICE TO PUT TO
  378.     CALL    XPUT        ;SEND THE CHARACTER
  379.     JR    NZ,OUTCH3    ;Transmitter may not be ready, loop if
  380. ;                needed until character is transmitted
  381. OUTCH4    POP    BC        ;Restore the regs
  382.     POP    DE
  383.     RET
  384. ;
  385. ;    Character input routine for INPKT.  We can timeout on the
  386. ;    receive by allowing the timer to place a return in the code
  387. ;    below, at the address RECALRM.  Since TRSDOS doesn't allow
  388. ;    us (neatly, without a hack) to transfer control in a task,
  389. ;    to some other code, we use the self modifying code.  This
  390. ;    may be considered dirty, but it does work.  The RET causes
  391. ;    the code to behave as though the user had pressed <ENTER> to
  392. ;    resend the latest packet.
  393. ;
  394. INCHR    XOR    A        ;Get a NOP instruction
  395.     LD    (RECALRM),A    ;Remove any stored RET instruction
  396. INCHR1    CALL    CONIN        ;Check keyboard first to make sure
  397.     IFNZ    INCHR3
  398.     CALL    INPORT        ;Get a character from the buffer
  399.     JP    Z,RSKP        ;Return if we got one
  400. RECALRM    NOP            ;Modified by timeout code to be a RET
  401.     JR    INCHR
  402. INCHR3    IFANOT    CR,INCHR4    ;Check which key was pressed
  403.     LD    A,(TASKSLOT)    ;Get the active task
  404.     OR    A        ;See if task aqctive
  405.     RET    Z        ;Return if not
  406.     LD    C,A        ;Get the task slot into c
  407.     CALL    XRMTSK        ;Stop the task
  408.     RET            ;Return resend status
  409. INCHR4    CHKWKEY    'B'-64        ;Control-B for batch
  410.     CHKWKEY    'F'-64        ;Control-F for file
  411.     CHKWKEY    'A'-64        ;Control-A for status
  412.     CHKWKEY    'E'-64        ;Control-E for send error
  413.     CHKWKEY    'D'-64        ;Debug?
  414.     CHKWKEY    'H'-64        ;Help?
  415.     IFANOT    'C'-64,INCHR1    ;Control-C for abort completely
  416. INCHR5    ADD    A,40H        ;MAKE IT PRINTABLE
  417.     LD    (CZSEEN),A
  418.     RET
  419. ;
  420. ;    Timer task for receiving a packet.  Called every 33.333333333
  421. ;    milliseconds.  We decrement the TIMER counter, and when it
  422. ;    goes to zero, we write a RET into the above code, and kill
  423. ;    the task so that is does not return.
  424. ;
  425. ;    Note that we must NOT leave anything on the stack when @KLTSK
  426. ;    is called or else it will puke.
  427. ;
  428. RECTIMOUT    EQU    $
  429.     PUSH    HL        ;Save the registers used
  430.     PUSH    AF
  431.     LD    HL,(TIMER)    ;Get the counter
  432.     DEC    HL        ;Decrement it
  433.     LD    (TIMER),HL    ;Store the new value
  434.     LD    A,H        ;Check it for zero
  435.     OR    L
  436.     JR    NZ,RECT1
  437.     LD    A,0C9H        ;Get a RET instruction opcode
  438.     LD    (RECALRM),A    ;Write it in
  439.     POP    AF        ;Restore the register
  440.     POP    HL
  441.     JP    XKLTSK        ;Remove this task, NO RETURN.
  442. ;
  443. RECT1    POP    AF        ;Restore the registers
  444.     POP    HL
  445.     RET            ;Return
  446. ;
  447. ;    Move cursor to position on screen
  448. ;
  449. TOSCRPOS    EQU    $
  450.     LD    B,3
  451.     JP    XVDCTL
  452. ;end of file
  453.