home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msytip.asm < prev    next >
Assembly Source File  |  2020-01-01  |  43KB  |  980 lines

  1. REVLVL  equ     5               ;Revision level 6-25-85
  2.  
  3. ;=============================================================================
  4. ;
  5. ; MSYTIPRO.ASM This file contains system dependent terminal emulation routines
  6. ;              for the H19 and Tektronix 4010 terminals.
  7. ;
  8. ; NOTE: ESC Z and ANSI mode don't work.
  9. ;
  10. ; Credits:      Dan Smith       Computing Center        (303) 273-3396
  11. ;                               Colorado School of Mines
  12. ;                               Golden, Colorado 80241
  13. ;               Joe Smith, now at TYMSHARE, 39100 Liberty St, Fremont CA 94538
  14. ;
  15. ;
  16. ; The following H19 escape codes are supported:
  17. ;
  18. ; Esc H    Cursor home                      Esc L    Insert line
  19. ; Esc C    Cursor forward                   Esc M    Delete line
  20. ; Esc D    Cursor backward                  Esc N    Delete character
  21. ; Esc B    Cursor down                      Esc O    Exit insert mode
  22. ; Esc A    Cursor up                        Esc @    Enter insert mode
  23. ; Esc I    Reverse index                    Esc p    Enter reverse video mode
  24. ; Esc Y    Direct cursor addressing         Esc q    Exit reverse video mode
  25. ; Esc E    Clear display                    Esc j    Save cursor position
  26. ; Esc J    Erase to end of page             Esc k    Restore cursor position
  27. ; Esc K    Erase to end of line
  28. ; Esc x4   Set block cursor                 Esc Z    Identify as VT52
  29. ; Esc y4   Set underscore cursor
  30. ;
  31. ; The following H19 codes are not supported:
  32. ;
  33. ; Esc n     Cursor position report          Esc <    Enter ANSI mode
  34. ; Esc b     Erase beginning of display      Esc [    Enter hold screen mode
  35. ; Esc l     Erase entire line               Esc \    Exit hold screen mode
  36. ; Esc o     Erase beginning of line         Esc F    Enter graphics mode
  37. ; Esc z     Reset to power up config.       Esc G    Exit graphics mode
  38. ; Esc r ?   Modify baud rate                Esc t    Enter keypad shifted mode
  39. ; Esc x 1-3 Set modes 1 through 3           Esc u    Exit keypad shifted mode
  40. ; Esc x 5-9 Set modes 5 through 9           Esc =    Enter alt keypad mode
  41. ; Esc y 1-3 Reset modes 1 through 3         Esc >    Exit alt keypad mode
  42. ; Esc y 5-9 Reset modes 5 through 9         Esc }    Keyboard disable
  43. ; Esc v     Wrap around at end of line      Esc {    Keyboard enable
  44. ; Esc w     Discard at end of line          Esc ]    Transmit 25th line
  45. ; Esc Z     Identify as H-19                Esc #    transmit page
  46. ;
  47. ;=============================================================================
  48.  
  49.         include mssdef.h
  50.  
  51. datas   segment public 'datas'
  52.         extrn   flags:byte
  53.  
  54. tekflag db      0               ;Flag for ESCape sequences
  55. visible db      0               ;0 to move, 1 to draw a line
  56. tek_hiy dw      0               ;Y coordinate in Tektronix mode
  57. tek_loy db      0
  58. tek_hix dw      0
  59. tek_lox db      0
  60. tek_lsb db      0               ; Low-order 2 bits of X + low Y (4014 mode)
  61.  
  62. arrtab  db      48h,'A'                 ;Up arrow
  63.         db      50h,'B'                 ;Down arrow
  64.         db      4bh,'D'                 ;Left arrow
  65.         db      4dh,'C'                 ;Right arrow
  66. arrtabl equ     ($-arrtab) / 2          ;Number of keys in arrtab
  67.  
  68. spctab  db      27,13,10,08,09,07,29,12
  69. lspctab equ     $-spctab
  70. spcjmp  dw      outesc,outcr,outlf,outbs,outtab,beep,tekini,ffeed
  71.  
  72. esctab  db      'YABCDEHIJKLMNO@pqjkxy'         ;Recognized escape codes
  73.         db      'Z',12,1ah
  74. lesctab equ     $-esctab
  75. escjmp  dw      movcur,curup,curdwn,currt       ;Escape code routines. This
  76.         dw      outbs,clrscr,curhom,revind      ;array must parallel the codes
  77.         dw      clreow,clreol,inslin,dellin     ;listed above.
  78.         dw      delchr,noins,entins,invvid
  79.         dw      nrmvid,savecur,restcur,setm,resetm
  80.         dw      sendid,escff,xhair
  81.  
  82. argadr  dw      0
  83. escchar db      0
  84. videobuf        dw      0de00h
  85. ttstate dw      0
  86. wcoord  db      0
  87. savrow  db      0
  88. insmod  db      0
  89. cursor  dw      0
  90. oldcur  dw      0
  91.  
  92. xmult   dw      9                       ;Scale TEK to TI by 9/13
  93. xdiv    dw      13                      ;so that 0-1023 converts to 0-708
  94. ymult   dw      5                       ;Scale TEK to TI by 5/13
  95. ydiv    dw      13                      ;so that 0-779 converts to 299-0
  96. ybot    dw      299                     ;Bottom of screen is Y=299
  97. oldx    dw      0                       ;Previous scaled coordinates
  98. oldy    dw      0
  99. grseg   dw      0
  100.  
  101. datas   ends
  102.  
  103. code    segment public
  104.         assume  cs:code,ds:datas
  105.  
  106.         extrn   beep:near, prtchr:near, outchr:near
  107.         public  term
  108.  
  109. ;=============================================================================
  110. ; Main entry point for Tektronix 4010 - Heathkit H19 terminal emulation.
  111. ;=============================================================================
  112.         db      'term'
  113. term    proc    near
  114.         mov     argadr,ax               ;Save address of argument block
  115.         call    termini
  116. term10: call    inport                  ;Input from modem
  117.         jnc     term20                  ;No input available; Check keyboard
  118.         call    outtty                  ;Print on terminal
  119. term20: mov     ah,1                    ;See if a character has been typed
  120.         int     4ah                     ;  on keyboard
  121.         jz      term10                  ;Jump if not
  122.         xor     ah,ah                   ;Read char from keyboard buffer
  123.         int     4ah
  124.         cmp     al,escchar              ;See if the Esc character (^])
  125.         jz      term30                  ;Jump if it is
  126.         call    outport                 ;Send character out comm port
  127.         jmp     short term20            ;Make sure KB buffer doesnt overrun
  128. term30: call    termend
  129.         ret
  130. term    endp
  131.  
  132. ;=============================================================================
  133. ; TERMINI  Subroutine to initialize the terminal before starting emulation
  134. ;=============================================================================
  135. termini proc    near
  136.         mov     bx,argadr               ;Save escape char in local storage
  137.         mov     al,[bx].escc
  138.         mov     escchar,al
  139.         mov     grseg,0d000h            ;Assume green on a 3 plane system
  140.         int     4fh                     ;Get system configuration
  141.         test    ax,4000h                ;See if graphics plane 3 exists
  142.         jnz     ti10                    ;Jump if it does
  143.         mov     grseg,0c000h            ;Reset to plane 1 for a 1 plane system
  144. ti10:   mov     ttstate,offset nstate
  145.         mov     insmod,0                ;Turn off insert mode
  146.         mov     ah,13h                  ;Necessary to clear screen in order to
  147.         int     49h                     ;  get CRTC start address in sync with
  148.         mov     word ptr cursor,0       ;    cursor position for direct video
  149.         ret                             ;      buffer access.
  150. termini endp
  151.  
  152. ;=============================================================================
  153. ; TERMEND  Subroutine to clean up after terminal emulation.
  154. ;=============================================================================
  155. termend proc    near
  156. ;*;     mov     ah,13h                  ;Clear text screen
  157. ;*;     int     49h
  158. ;*;     mov     ah,14h                  ;Clear graphics screen
  159. ;*;     int     49h
  160.         ret
  161. termend endp
  162.  
  163. ;=============================================================================
  164. ; Routine to input a character from the modem port. If no character available
  165. ; this returns with the carry flag cleared. (NC)
  166. ;=============================================================================
  167. inport  proc    near                    ;Input from the modem
  168.         call    prtchr
  169.         jmp     short ip10              ;Character available
  170.         nop                             ;Need 3 bytes
  171.         clc                             ;Indicate no character
  172.         ret
  173. ip10:   and     al,7fh                  ;No parity here for terminal emulation
  174.         stc                             ;Indicate character available
  175.         ret
  176. inport  endp
  177.  
  178. ;=============================================================================
  179. ; Subroutine to translate and send the character out the communication port
  180. ;=============================================================================
  181. outport proc    near
  182.         cmp     flags.vtflg,1
  183.         jne     op2                     ;Jump if no Heath-19 emulation
  184.         or      al,al
  185.         jz      op5                     ;Jump if a special key
  186. op2:    mov     ah,al
  187.         jmp     short op30
  188. op5:    mov     cx,arrtabl              ;Number of entries in translation table
  189.         mov     si,offset arrtab        ;Point to start of translation table
  190. op10:   cmp     ah,[si]
  191.         jz      op20                    ;Jump if found key
  192.         add     si,2                    ;Point to next key scan code
  193.         loop    op10
  194.         ret                             ;Scan code not found; don't send it
  195. op20:   mov     ah,27
  196.         call    outchr                  ;Send a leading escape char
  197.         nop                             ;Waste 3 bytes to ignore error
  198.         nop
  199.         nop
  200.         mov     ah,[si+1]               ;Get translated code value
  201. op30:   call    outchr                  ;Output character in AH
  202.         nop                             ;Waste 3 bytes to ignore error
  203.         nop
  204.         nop
  205.         ret
  206. outport endp
  207.  
  208. ;=============================================================================
  209. ; Subroutine to send the character in AL to the screen. If Heath-19 emulation
  210. ; is on, the character will be interpreted according to H-19 and Tektronix 4010
  211. ; escape codes.
  212. ;=============================================================================
  213. outtty  proc    near
  214.         cmp     flags.vtflg,1
  215.         jne     otty10                  ;Jump if no Heath-19 emulation
  216.         mov     dx,cursor               ;These may need cursor...
  217.         cld                             ;Set here so its not required later
  218.         jmp     ttstate                 ;Jump according to current state
  219. otty10: mov     dl,al                   ;Print char in al at cursor position
  220.         mov     ah,2                    ;  using DOS
  221.         int     21h
  222.         ret
  223. outtty  endp
  224.  
  225. ;=============================================================================
  226. ; Subroutine to process the character in AL according to the normal state
  227. ;=============================================================================
  228. nstate  proc    near
  229.         cmp     al,32                   ;Special character?
  230.         jb      conchar                 ;Yes, perform control char operation
  231.         cmp     insmod,0                ;In insert mode?
  232.         je      ns10                    ;No, output normal
  233.         push    ax                      ;Save character
  234.         call    inschr                  ;Insert a blank in line
  235.         pop     ax                      ;Restore character
  236. ns10:   jmp     pchar                   ;Print char in AL
  237. nstate  endp
  238.  
  239. ;=============================================================================
  240. ; Subroutine to handle the ASCII character below 32 in al
  241. ;=============================================================================
  242. conchar proc    near
  243.         mov     di,offset spctab        ;See if character is in table
  244.         mov     cx,lspctab
  245.         repne   scasb
  246.         jz      cc10                    ;Go process if it was
  247.         push    ax                      ;Save char
  248.         mov     al,'^'
  249.         call    pchar                   ;Print caret
  250.         pop     ax
  251.         add     al,'A'-1                ;Make control character printable
  252.         jmp     pchar                   ;Print, then return
  253. cc10:   sub     di,offset spctab+1      ;Get index of char
  254.         shl     di,1                    ;Double for word offset
  255.         jmp     spcjmp[di]              ;And go handle
  256. conchar endp
  257.  
  258. ;=============================================================================
  259. ; special char routines.  cursor is in dx, char in al
  260. ;=============================================================================
  261. outlf   proc    near
  262.         inc     dl                      ;Bump row
  263.         jmp     setcur
  264. outlf   endp
  265.  
  266. outcr   proc    near
  267.         xor     dh,dh                   ;Set col to 0
  268.         jmp     setcur
  269. outcr   endp
  270.  
  271. outbs   proc    near
  272.         or      dh,dh
  273.         jle     setcur                  ;Col 0, can't back up
  274.         dec     dh                      ;Back up col
  275.         jmp     setcur                  ;And use if reasonable
  276. outbs   endp
  277.  
  278. outtab  proc    near
  279.         add     dh,8                    ;Tab is at most 8 columns
  280.         and     dh,not 111b             ;Round down to a multiple of 8
  281.         cmp     dh,80                   ;Out of range?
  282.         jb      outta1                  ;No, go set it
  283.         mov     dh,80-1                 ;Else just move to right margin
  284. outta1: jmp     setcur
  285. outtab  endp
  286.  
  287. outesc  proc    near
  288.         mov     ttstate,offset estate   ;Expect escape sequence.
  289.         ret
  290. outesc  endp
  291.  
  292. ;=============================================================================
  293. ; Escape-char handling routines
  294. ;=============================================================================
  295. estate  proc    near
  296.         mov     ttstate,offset nstate   ;Put state back to normal
  297.         mov     di,offset esctab        ;Escape char tbl
  298.         mov     cx,lesctab              ;Length of tbl
  299.         repne   scasb                   ;Look for it in tbl
  300.         jz      es10                    ;Found, go use it
  301.         push    ax
  302.         mov     al,27                   ;Output Esc character
  303.         call    pchar
  304.         pop     ax                      ;Output unrecognized escape code
  305.         jmp     pchar
  306. es10:   sub     di,offset esctab+1      ;Get offset into tbl
  307.         shl     di,1                    ;Convert to word offset
  308.         jmp     escjmp[di]              ;And go dispatch on it
  309. estate  endp
  310.  
  311. ;=============================================================================
  312. ; Subroutine to print a character at the current cursor position and advance
  313. ; the cursor to the next position.
  314. ;=============================================================================
  315. pchar   proc    near
  316.         push    es                      ;Save ES
  317.         push    ax                      ;Save char to print
  318.         mov     dx,cursor               ;Get row and column
  319.         call    scrloc                  ;Map DX to ES:DI
  320.         pop     ax                      ;Restore char to print
  321.         stosb                           ;Put into video buffer
  322.         pop     es                      ;Restore segment
  323.         inc     dh                      ;Bump col
  324.         jmp     setcur                  ;Position cursor
  325. pchar   endp
  326.  
  327. ;=============================================================================
  328. ; Subroutine to position the cursor. This routine will wrap lines and scroll
  329. ; the screen. The row is in DL, the column is in DH
  330. ;=============================================================================
  331. setcur  proc    near
  332.         cmp     dh,80                   ;See if in range
  333.         jae     sc20
  334.         cmp     dl,24                   ;Lines go from 0 to 23
  335.         jbe     sc10                    ;Not off end, keep going
  336.         push    dx                      ;Save row/col
  337.         xor     dx,dx
  338.         call    dellin                  ;Scroll up one line by deleting top line
  339.         pop     dx
  340.         mov     dl,24                   ;Go to bottom line again...
  341. sc10:   mov     cursor,dx               ;Save cursor pos
  342.         mov     ah,2
  343.         int     49h                     ;Set cursor
  344. sc20:   ret
  345. setcur  endp
  346.  
  347. ;=============================================================================
  348. ; Subroutine to move the cursor up and possibly scroll the screen down
  349. ;=============================================================================
  350. revind  proc    near
  351.         cmp     dl,0
  352.         jle     rev10
  353.         dec     dl                      ;back up a row
  354.         jmp     setcur                  ;and go set cursor
  355. rev10:  xor     dx,dx
  356.         jmp     inslin                  ;Insert a line at top of screen
  357. revind  endp
  358.  
  359. ;=============================================================================
  360. ; Subroutine to move the cursor up
  361. ;=============================================================================
  362. curup   proc    near
  363.         cmp     dl,0                    ;w/in range?
  364.         jle     curu10                  ;no, skip this
  365.         dec     dl                      ;else back up
  366. curu10: jmp     setcur                  ;and go set position
  367. curup   endp
  368.  
  369. ;=============================================================================
  370. ; Subroutine to move the cursor down
  371. ;=============================================================================
  372. curdwn  proc    near
  373.         inc     dl
  374.         jmp     setcur                  ;increment row (setcur can scroll!)
  375. curdwn  endp
  376.  
  377. ;=============================================================================
  378. ; Subroutine to move the cursor 1 position to the right.
  379. ;=============================================================================
  380. currt   proc    near
  381.         inc     dh
  382.         jmp     setcur
  383. currt   endp
  384.  
  385. ;=============================================================================
  386. ; Subroutine to home cursor and clear screen
  387. ;=============================================================================
  388. clrscr  proc    near
  389.         call    curhom                  ;go home cursor
  390.         mov     dx,cursor
  391.         jmp     clreow                  ;then clear to end of window
  392. clrscr  endp
  393.  
  394. ;=============================================================================
  395. ; Subroutine to home the cursor
  396. ;=============================================================================
  397. curhom  proc    near
  398.         xor     dx,dx                   ;move to 0,0
  399.         jmp     setcur
  400. curhom  endp
  401.  
  402. ;=============================================================================
  403. ; Subroutine to clear the screen from the cursor to the end of the window
  404. ;=============================================================================
  405. clreow  proc    near
  406.         push    es
  407.         call    scrloc                  ;Map DX into ES:DI in the video buffer
  408.         mov     cx,80*25                ;Number of chars on screen
  409.         sub     cx,di                   ;Number from the cursor on
  410.         mov     al,' '                  ;Fill with blanks
  411.         rep     stosb                   ;Fill screen
  412.         pop     es
  413.         ret
  414. clreow  endp
  415.  
  416. ;=============================================================================
  417. ; Subroutine to clear the screen from the cursor to the end of the line
  418. ;=============================================================================
  419. clreol  proc    near
  420.         mov     cx,80                   ;Number of cols across screen
  421.         sub     cl,dh                   ;Number from cursor on
  422.         jle     eol10                   ;Jump if past end
  423.         push    es
  424.         call    scrloc                  ;Map DX to ES:DI
  425.         mov     al,' '                  ;Fill end with blanks
  426.         rep     stosb                   ;Blank end of line
  427.         pop     es
  428. eol10:  ret
  429. clreol  endp
  430.  
  431. ;=============================================================================
  432. ; Subroutine to insert a line at the row that the cursor is in.
  433. ;=============================================================================
  434. inslin  proc    near
  435.         xor     dh,dh                   ;Move to start of row
  436.         cmp     dl,24
  437.         jae     clreol                  ;Just clear bottom row
  438.         push    ds
  439.         push    es
  440.         call    scrloc                  ;Map DX to ES:DI
  441.         mov     ds,videobuf             ;Set DS to video buffer
  442.         mov     cx,24*80                ;Number of chars on screen
  443.         sub     cx,di                   ;Number of chars past current row
  444.         push    di                      ;Save current row address
  445.         mov     di,25*80-1              ;Point to last char
  446.         mov     si,24*80-1              ;Point 1 line up
  447.         std                             ;Auto decrement
  448.         rep     movsb                   ;Move lines down
  449.         cld                             ;Auto increment
  450.         mov     cx,80                   ;Number of chars on original line
  451.         pop     di                      ;Restore pointer to start of line
  452.         mov     al,' '                  ;Fill with blanks
  453.         rep     stosb                   ;Blank line
  454.         pop     es
  455.         pop     ds
  456.         ret
  457. inslin  endp
  458.  
  459. ;=============================================================================
  460. ; Subroutine to scroll the screen up over the current line
  461. ;=============================================================================
  462. dellin  proc    near
  463.         xor     dh,dh                   ;Move to start of row
  464.         cmp     dl,24
  465.         jae     clreol                  ;Just clear bottom row
  466.         push    ds
  467.         push    es
  468.         call    scrloc                  ;Map DX to ES:DI
  469.         mov     ds,videobuf             ;Set DS to video buffer
  470.         mov     cx,24*80                ;First char of last row
  471.         sub     cx,di                   ;Number of chars past current row
  472.         mov     si,di
  473.         add     si,80                   ;Source is one line down
  474.         rep     movsb                   ;Move chars up
  475.         mov     cx,80                   ;Number of chars on last line
  476.         mov     al,' '                  ;Fill with blanks
  477.         rep     stosb                   ;Blank line
  478.         pop     es
  479.         pop     ds
  480.         ret
  481. dellin  endp
  482.  
  483. ;=============================================================================
  484. ; Subroutine to delete the current character by scrolling to the left
  485. ;=============================================================================
  486. delchr  proc    near
  487.         push    ds
  488.         push    es
  489.         call    scrloc                  ;Map dx to es:di
  490.         mov     ds,videobuf
  491.         mov     cx,79                   ;Last char on line
  492.         sub     cl,dh
  493.         jz      dch20                   ;Jump if on last char
  494.         mov     si,di
  495.         inc     si                      ;Source is 1 char to right
  496.         rep     movsb                   ;Move chars to left
  497. dch20:  mov     byte ptr [di],' '
  498.         pop     es
  499.         pop     ds
  500.         ret
  501. delchr  endp
  502.  
  503. ;=============================================================================
  504. ; Subroutine to insert a character at the cursor position
  505. ;=============================================================================
  506. inschr  proc    near
  507.         push    ds
  508.         push    es
  509.         mov     cx,79           ;This is last col to move, +1 for length
  510.         sub     cl,dh           ;Compute distance to end
  511.         jle     ichr20          ;Nothing to move...
  512.         mov     dh,78           ;This is address of last col to move
  513.         call    scrloc          ;Compute pos
  514.         mov     ds,videobuf
  515.         mov     si,di
  516.         inc     di              ;Destination is one byte over...
  517.         std                     ;Remember to move us backwards
  518.         rep     movsb           ;Move chars to right
  519.         cld
  520. ichr20: pop     es
  521.         pop     ds
  522.         ret
  523. inschr  endp
  524.  
  525. ;=============================================================================
  526. ; Subroutine to turn off insert mode.
  527. ;=============================================================================
  528. noins   proc    near
  529.         mov     insmod,0                ;Turn off insert mode
  530.         ret
  531. noins   endp
  532.  
  533. ;=============================================================================
  534. ; Subroutine to process ESC Y  (The direct cursor addressing command)
  535. ;=============================================================================
  536. movcur  proc    near
  537.         mov     wcoord,0                ;Want two coordinates...
  538.         mov     ttstate,offset cstate
  539.         ret
  540. movcur  endp
  541.  
  542. ;=============================================================================
  543. ; Subroutine to get a coordinate
  544. ;=============================================================================
  545. cstate  proc    near
  546.         sub     al,32                   ;Coordinates offset by 32
  547.         cmp     wcoord,0                ;See if first coord already received
  548.         jnz     cs10                    ;Jump if it was
  549.         inc     wcoord                  ;Indicate first was received
  550.         mov     savrow,al               ;Save first coordinate  (row)
  551.         ret
  552. cs10:   mov     ttstate,offset nstate   ;Reset state
  553.         mov     dh,al                   ;Put column in DH
  554.         mov     dl,savrow               ;Get saved row
  555.         jmp     setcur                  ;Position cursor
  556. cstate  endp
  557.  
  558. ;=============================================================================
  559. ; Subroutine to enter insert mode.
  560. ;=============================================================================
  561. entins  proc    near
  562.         mov     insmod,0ffh             ;enter insert mode...
  563.         ret                             ;and return
  564. entins  endp
  565.  
  566. ;=============================================================================
  567. ; Subroutine to enter inverse video mode
  568. ;=============================================================================
  569. invvid  proc    near
  570.         ret
  571. invvid  endp
  572.  
  573. ;=============================================================================
  574. ; Subroutine to exit inverse video mode
  575. ;=============================================================================
  576. nrmvid  proc    near
  577.         ret
  578. nrmvid  endp
  579.  
  580. ;=============================================================================
  581. ; Subroutine to handle the set mode command. Sequence = ESC x (1,2,3,4,5...)
  582. ;=============================================================================
  583. setm    proc    near                    ;Here if ESC x entered
  584.         mov     ttstate,offset mstate   ;Wait for value
  585.         ret
  586. mstate: mov     ttstate,offset nstate   ;Put state back to normal
  587.         cmp     al,'4'
  588.         jz      uscurs                  ;Set underscore cursor
  589.         push    ax
  590.         mov     al,27                   ;Output Esc character
  591.         call    pchar
  592.         mov     al,'x'                  ;Output set mode character
  593.         call    pchar
  594.         pop     ax                      ;Output unrecognized mode code
  595.         jmp     pchar
  596. setm    endp
  597.  
  598. ;=============================================================================
  599. ; Subroutine to handle the reset mode command. Sequence = ESC y (1,2,3,4,5...)
  600. ;=============================================================================
  601. resetm  proc    near                    ;Here if ESC y entered
  602.         mov     ttstate,offset rstate   ;Wait for value
  603.         ret
  604. rstate: mov     ttstate,offset nstate   ;Put state back to normal
  605.         cmp     al,'4'
  606.         jz      blcurs                  ;Set block cursor
  607.         push    ax
  608.         mov     al,27                   ;Output Esc character
  609.         call    pchar
  610.         mov     al,'x'                  ;Output set mode character
  611.         call    pchar
  612.         pop     ax                      ;Output unrecognized mode code
  613.         jmp     pchar
  614. resetm  endp
  615.  
  616. ;=============================================================================
  617. ; Subroutine to set the underscore cursor
  618. ;=============================================================================
  619. uscurs  proc    near
  620.         mov     cx,4a0bh
  621.         mov     ah,1
  622.         int     49h
  623.         ret
  624. uscurs  endp
  625.  
  626. ;=============================================================================
  627. ; Subroutine to set a block cursor
  628. ;=============================================================================
  629. blcurs  proc    near
  630.         mov     cx,400bh
  631.         mov     ah,1
  632.         int     49h
  633.         ret
  634. blcurs  endp
  635.  
  636. ;=============================================================================
  637. ; save cursor in DX
  638. ;=============================================================================
  639. savecur proc    near
  640.         mov     oldcur,dx
  641.         ret
  642. savecur endp
  643.  
  644. ;=============================================================================
  645. ; restore cursor onto screen
  646. ;=============================================================================
  647. restcur proc    near
  648.         mov     dx,oldcur
  649.         jmp     setcur
  650. restcur endp
  651.  
  652. ;=============================================================================
  653. ; Computes screen location to es:di, given col and row in dx.
  654. ; Trashes ax,bx
  655. ;=============================================================================
  656. scrloc  proc    near
  657.         mov     al,dl           ;Get row
  658.         xor     ah,ah
  659.         shl     ax,1            ;Row * 2
  660.         mov     bx,ax
  661.         shl     ax,1            ;Row * 4
  662.         shl     ax,1            ;Row * 8
  663.         add     ax,bx           ;Row * 10
  664.         shl     ax,1            ;Row * 20
  665.         shl     ax,1            ;Row * 40
  666.         shl     ax,1            ;Row * 80
  667.         add     al,dh
  668.         adc     ah,0
  669.         mov     di,ax
  670.         mov     es,videobuf
  671.         ret
  672. scrloc  endp
  673.  
  674. ;=============================================================================
  675. ;
  676. ; 12-Dec-84  Joe Smith, CSM Computing Center, Golden CO 80401
  677. ;
  678. ;                  Description of Tektronix commands
  679. ;
  680. ; ESCAPE-CONTROL-E (ENQ) requests a status report
  681. ; ESCAPE-FORMFEED erases the screen.
  682. ; ESCAPE-CONTROL-Z turns on the crosshairs (not on 4006 or 4025)
  683. ; ESCAPE-A-E enables the interactive plotter
  684. ; ESCAPE-A-F turns off the interactive plotter
  685. ; ESCAPE-M-L-2 Selects color 2 for drawing lines on 4113
  686. ; ESCAPE-M-T-: Selects color 10 for drawing text on 4113
  687. ; CONTROL-] (GS) turns on plot mode, the first move will be with beam off.
  688. ; CONTROL-UNDERLINE (US) turns off plot mode.  (CR also works for all but 4025.)
  689. ; CONTROL-X switches HDSGVT from TEKTRONIX mode to NORMAL alpha mode.
  690. ;
  691. ; The plot commands are characters which specify the absolute position to move
  692. ; the beam.  All moves except the one immediately after the GS character
  693. ; (Control-]) are with a visible trace.
  694. ;
  695. ; For 4010-like devices - The positions are from 0 to 1023 for both X and Y,
  696. ; altho only 0 to 780 are visible for Y due to screen geometry.  The screen is
  697. ; 10.23 by 7.80 inches, and coordinates are sent as 1 to 4 characters.
  698. ;
  699. ; For 4014-like devices - The positions are from 0 to 4096, but each movement
  700. ; is a multiple of 4 positions unless the high-resolution LSBXY are sent. This
  701. ; makes it compatible w/the 4010 in that a full sized plot fills the screen.
  702. ;
  703. ; HIX,HIY = High-order 5 bits of position
  704. ; LOX,LOY = Middle-order 5 bits of position
  705. ; LSBXY   = Low-order 2 bits of X + low-order 2 bits of Y (4014 mode)
  706. ;
  707. ; Hi Y    Lo Y    Hi X    LSBXY   Characters sent (Lo-X always sent)
  708. ; ----    ----    ----    -----   ----------------------------------
  709. ; Same    Same    Same    Same                           Lo-X
  710. ; Same    Same    Same    Diff          LSB, Lo-Y,       Lo-X   4014
  711. ; Same    Same    Diff    Same               Lo-Y, Hi-X, Lo-X
  712. ; Same    Same    Diff    Diff          LSB, Lo-Y, Hi-X, Lo-X   4014
  713. ; Same    Diff    Same    Same               Lo-Y,       Lo-X
  714. ; Same    Diff    Same    Diff          LSB, Lo-Y,       Lo-X   4014
  715. ; Same    Diff    Diff    Same               Lo-Y, Hi-X, Lo-X
  716. ; Same    Diff    Diff    Diff          LSB, Lo-Y, Hi-X, Lo-X   4014
  717. ; Diff    Same    Same    Same    Hi-Y,                  Lo-X
  718. ; Diff    Same    Same    Diff    Hi-Y, LSB, Lo-Y,       Lo-X   4014
  719. ; Diff    Same    Diff    Same    Hi-Y,      Lo-Y, Hi-X, Lo-X
  720. ; Diff    Same    Diff    Diff    Hi-Y, LSB, Lo-Y, Hi-X, Lo-X   4014
  721. ; Diff    Diff    Same    Same    Hi-Y,      Lo-Y,       Lo-X
  722. ; Diff    Diff    Same    Diff    Hi-Y, LSB, Lo-Y,       Lo-X   4014
  723. ; Diff    Diff    Diff    Same    Hi-y,      Lo-Y, Hi-X, Lo-X
  724. ; Diff    Diff    Diff    Diff    Hi-y, LSB, Lo-Y, Hi-X, Lo-X   4014
  725. ; Offset for byte:                  40  140   140    40   100
  726. ;
  727. ; Note that LO-Y must be sent if HI-X has changed so the TEKTRONIX knows that
  728. ; the HI-X byte (in the range of 40-77 octal) is HI-X and not HI-Y.  LO-Y must
  729. ; also be sent if LSBXY has changed, so that the 4010 will ignore LSBXY and
  730. ; accept LO-Y.  The LSBXY byte is 140 + MARGIN*20 + LSBY*4 + LSBX.  (MARGIN=0)
  731. ;
  732. ;============================================================================
  733.  
  734. ;============================================================================
  735. ; Subroutine to initialize tektronix emulation. Called when GS char received
  736. ;============================================================================
  737. tekini  proc    near
  738.         mov     visible,0               ;Next move is invisible
  739.         mov     tekflag,1
  740.         mov     ttstate,offset xystate  ;Go to ystate next
  741.         ret
  742. tekini  endp
  743.  
  744. ;============================================================================
  745. ; Subroutine to clear the graphics screen. Called when a Form feed is received
  746. ;============================================================================
  747. ffeed   proc    near
  748.         mov     ah,14h                  ;Clear only graphics (not text)
  749.         int     49h
  750.         ret
  751. ffeed   endp
  752.  
  753. ;============================================================================
  754. ; Subroutine to clear the graphics and the text screen. Called if Esc FF rec.
  755. ;============================================================================
  756. escff   proc    near
  757.         mov     ah,13h                  ;Erase both text and graphics screen
  758.         int     49h
  759.         mov     ah,14h
  760.         int     49h
  761.         mov     ttstate,offset nstate
  762.         ret
  763. escff   endp
  764.  
  765. ;=============================================================================
  766. ; Subroutine to send an identification code back. (Esc Z)
  767. ;=============================================================================
  768. sendid  proc    near
  769.         mov     al,esc
  770.         call    outport
  771.         mov     al,'\'
  772.         call    outport
  773.         mov     al,'K'
  774.         call    outport
  775.         mov     ttstate,offset nstate
  776.         ret
  777. sendid  endp
  778.  
  779. ;=============================================================================
  780. ; Subroutine to turn on the crosshairs. (Esc ^Z)
  781. ;=============================================================================
  782. xhair   proc    near
  783.         mov     ttstate,offset nstate
  784.         ret
  785. xhair   endp
  786.  
  787. ;=============================================================================
  788. ; Subroutine to extract the X,Y coordinates for Tektronix emulation.
  789. ; Expecting HIY because LOX was seen   tekflag = 1
  790. ; Expecting HIX because LOY was seen   tekflag = 0
  791. ; Written by Joe Smith, CSM
  792. ;=============================================================================
  793. xystate proc    near
  794.         cmp     al,29                   ;Process Pen up command
  795.         jz      tekini
  796.         cmp     al,13                   ;Exit graphics mode on CR,LF,US
  797.         je      go2text
  798.         cmp     al,10
  799.         je      go2text
  800.         cmp     al,1fh
  801.         je      go2text
  802.         cmp     al,18h
  803.         je      go2text
  804.         cmp     al,20h                  ;Control char?
  805.         jl      tek20                   ;Ignore it
  806.         cmp     al,40h
  807.         jl      tek30                   ;20-3F are HIX or HIY
  808.         cmp     al,60h                  ;40-5F are LOX (causes beam movement)
  809.         jl      tek50                   ;60-7F are LOY
  810.  
  811. ;Extract low-order 5 bits of Y coordinate, set ESCFLAG=6
  812.  
  813.         mov     ah,tek_loy              ;Copy previous LOY to MSB (in case 4014)
  814.         mov     tek_lsb,ah
  815.         and     al,1Fh                  ;LOY is 5 bits
  816.         mov     tek_loy,al
  817.         cmp     tekflag,0               ;2nd LOY in a row?
  818.         je      tek20                   ;Yes, then LSB is valid
  819.         mov     tek_lsb,0               ;1st one, clear LSB
  820.         mov     tekflag,0               ;LOY seen, expect HIX (instead of HIY)
  821. tek20:  ret
  822.  
  823. ;Extract high-order 5 bits (X or Y, depending on ESCFLAG)
  824.  
  825. tek30:  and     ax,1Fh                  ;Just 5 bits
  826.         mov     cl,5
  827.         shl     ax,cl                   ;Shift over 5 bits
  828.         cmp     tekflag,1               ;Looking for HIY?
  829.         jne     tek40                   ;No, HIX
  830.         mov     tek_hiy,ax              ;Yes, this byte has HIY
  831.         ret                             ;Keep ESCFLAG=4
  832. tek40:  mov     tek_hix,ax              ;This byte has HIX (because ESCFLAG=6)
  833.         mov     tekflag,1               ;Reset to look for HIY next time
  834.         ret
  835.  
  836. ;Extract low-order X, do beam movement
  837.  
  838. tek50:  and     al,1Fh                  ;Just 5 bits
  839.         mov     tek_lox,al
  840.         mov     ax,tek_hix              ;Combine HIX*32
  841.         or      al,tek_lox              ;with LOX
  842.         mov     bx,tek_hiy              ;Same for Y
  843.         or      bl,tek_loy
  844.         mov     cl,visible              ;0=move, 1=draw
  845.         call    tekdraw
  846. go2visi:mov     visible,1               ;Next movement is with a visible trace
  847.         mov     tekflag,1               ;Reset to look for HIY next time
  848.         ret
  849.  
  850. go2text:mov     ttstate,offset nstate
  851.         ret
  852. xystate endp
  853.  
  854. ;=============================================================================
  855. ;
  856. ; Routine to draw a line on the screen, using TEKTRONIX coordinates.
  857. ; X coordinate in AX, 0=left edge of screen, 1023=right edge of screen.
  858. ; Y coordinate in BX, 0=bottom of screen, 779=top of screen.
  859. ; Visiblity flag in CL, 0=move invisible, 1=draw a line.
  860. ;
  861. ; The TI-PRO has (719,299) as the coordinate of the lower-right corner.
  862. ; Calculate endpoint X=(9/13)*(HIX*32+LOX), Y=299-(5/13)*(HIY*32+LOY)
  863. ;
  864. ; The IBM-PC has (639,199) as the coordinate of the lower-right corner.
  865. ; Calculate endpoint X=(12/20)*(HIX*32+LOX), Y=199-(5/20)*(HIY*32+LOY)
  866. ;
  867. ;=============================================================================
  868. tekdraw proc    near
  869.         imul    xmult                   ;Multiply by 9
  870.         idiv    xdiv                    ;Divide by 13
  871.         push    ax                      ;X is now between 0 and 708
  872.         mov     ax,bx
  873.         imul    ymult                   ;Multiply by 5
  874.         idiv    ydiv                    ;Divide by 13
  875.         mov     bx,ybot                 ;Y is now between 0 and 299
  876.         sub     bx,ax                   ;Put new Y in right reg
  877.         pop     ax                      ;Put new X in right reg
  878.         or      cl,cl
  879.         jnz     td10                    ;Jump if line is visible
  880.         mov     oldx,ax                 ;Update last coordinates
  881.         mov     oldy,bx
  882.         ret
  883. td10:   mov     si,oldx                 ;Previous position
  884.         mov     di,oldy
  885.         mov     oldx,ax                 ;Update position
  886.         mov     oldy,bx
  887.         jmp     line                    ;Plot line
  888. tekdraw endp
  889.  
  890. ;=============================================================================
  891. ; LINE  Subroutine to plot line with endpoints in BX,CX and SI,DI. The method
  892. ;       used is an adaptation of octantal dynamic differential analyzer(DDA).
  893. ;       SI,DI = Start X,Y coordinates. AX,BX = End X,Y coordinates.
  894. ;
  895. ;=============================================================================
  896. line    proc    near
  897.         cmp     ax,si                   ;Compare X1 to X2
  898.         jl      plusx                   ;Jump if X1 is to left of X2
  899.         xchg    ax,si                   ;Swap points so point 1 is to left
  900.         xchg    bx,di                   ;  This mirrors quadrants 2,3 to 1,4
  901. plusx:  sub     si,ax                   ;Get delta X into SI
  902.         sub     di,bx                   ;Get delta Y into DI
  903.  
  904. ; Left-hand coordinate in (AX,BX), delta movement in (SI,DI)
  905. ; Map X1,Y1 in AX,BX to  offset into the video buffer in BX and bit pos in AX
  906.  
  907.         shl     bx,1                    ;2*Y
  908.         shl     bx,1                    ;4*Y
  909.         mov     bp,bx                   ;Save 4*Y
  910.         shl     bx,1                    ;8*Y
  911.         shl     bx,1                    ;16*Y
  912.         shl     bx,1                    ;32*Y
  913.         add     bp,bx                   ;DX = 36*Y
  914.         shl     bx,1                    ;64*Y
  915.         shl     bx,1                    ;128*Y
  916.         sub     bx,bp                   ;128Y - 36Y = 92*Y
  917.         mov     cl,al                   ;Low 4 bits of X position
  918.         and     cl,0Fh
  919.         shr     ax,1                    ;Divide by 8 bits per byte
  920.         shr     ax,1
  921.         shr     ax,1
  922.         and     ax,0fffeh               ;Truncate down to word boundary
  923.         add     bx,ax
  924.         mov     ax,8000h                ;Start with set bit on left edge
  925.         shr     ax,cl                   ;Shift it over the correct amount
  926.  
  927. ;AX has bit in position, BX has word address, SI has delta-X, DI has delta-Y
  928.  
  929.         mov     bp,92                   ;Offset from 1 pixel to one below it
  930.         or      di,di                   ;See if delta y is below zero
  931.         jg      line10                  ;Yes, already on quadrant 3
  932.         neg     di                      ;Get absolute value of delta y
  933.         neg     bp                      ;Move toward top of screen
  934. line10: push    ds
  935.         mov     ds,grseg
  936.         cmp     di,si                   ;Compare delta-Y with delta-X
  937.         jg      line30                  ;Greater than +/- 45 degrees
  938.  
  939. ; Here when slope is less than +/- 45 degrees
  940.  
  941. line20: mov     cx,si                   ;Number of pixels to plot = delta x
  942.         inc     cx                      ;  + 1
  943.         mov     dx,si                   ;Initialize line error to -(deltax)/2
  944.         shr     dx,1                    ;
  945.         neg     dx                      ;
  946. line2a: or      [bx],ax                 ;Turn on pixel pointed to by BX and Al
  947.         ror     ax,1                    ;Increment X direction
  948.         jnc     line2b                  ;
  949.         add     bx,2                    ;
  950. line2b: add     dx,di                   ;Add delta y to line error
  951.         jl      line2c                  ;Jump for next pixel if error < 0
  952.         add     bx,bp                   ;Go up (or down) one pixel
  953.         sub     dx,si                   ;Subtract delta x from line error
  954. line2c: loop    line2a                  ;Set next pixel
  955.         pop     ds
  956.         ret
  957.  
  958. ; Here when slope is greater than +/- 45 degrees
  959.  
  960. line30: mov     cx,di                   ;Number of pixels to plot = delta y
  961.         inc     cx                      ;  + 1 (Delta Y was negated above)
  962.         mov     dx,di                   ;Initialize line error to -(deltay)/2
  963.         shr     dx,1                    ;
  964.         neg     dx                      ;
  965. line3a: or      [bx],ax                 ;Turn on pixel pointed to by BX and Al
  966.         add     bx,bp                   ;Move up (or down) 1 pixel
  967.         add     dx,si                   ;Add delta x to line error
  968.         jl      line3c                  ;Jump for next pixel if error < 0
  969.         ror     ax,1                    ;Time to increment X direction
  970.         jnc     line3b                  ;
  971.         add     bx,2                    ;
  972. line3b: sub     dx,di                   ;Subtract delta y from line error
  973. line3c: loop    line3a                  ;Set next pixel
  974.         pop     ds
  975.         ret
  976. line    endp
  977.  
  978. code    ends
  979.         end
  980.