home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 300 / 257 / msxtek.asm < prev    next >
Assembly Source File  |  1984-12-07  |  7KB  |  188 lines

  1. PAGE    60,132  ; 60 lines, 132 columns
  2. TITLE   MSTEKTRM - TEKTRONIX 4010 terminal emulation module
  3. ; 29-Nov-84     Joe Smith, CSM Computing Center, Golden CO 80401 (303)273-3448
  4.  
  5.         public  TERMEMU                     ; Terminal emulation routine
  6.         extrn   INMODEM:near,OUTMODEM:near  ; Read and write to the modem port
  7.         extrn   INKEYB:near,OUTSCRN:near    ; Read and write to the console
  8.         extrn   CLS:near,TEKDRAW:near       ; Erase and draw routines
  9.         extrn   CROSHAIR:near               ; Trigger the cross-hairs
  10.         extrn   IDSEQ:word                  ; Pointer to string for ESC-Z
  11.         extrn   CTLTAB:word                 ; Pointer to control table
  12.  
  13. NUL     equ     00h             ; ^@
  14. BEL     equ     07h             ; ^G Bell
  15. BS      equ     08h             ; ^H Backspace
  16. HT      equ     09h             ; ^I Horizontal TAB
  17. LF      equ     0Ah             ; ^J Linefeed
  18. VT      equ     0Bh             ; ^K Vertical tab
  19. FF      equ     0Ch             ; ^L formfeed to clear the screen
  20. CR      equ     0Dh             ; ^M Carriage Return
  21. CAN     equ     18h             ; ^X to return to ANSI mode
  22. EM      equ     19h             ; ^Y not used
  23. SUB     equ     1Ah             ; ESC-^Z triggers crosshairs
  24. ESC     equ     1Bh             ; ESC-^Z and ESC-FF does special things
  25. FS      equ     1Ch             ; ^\ not used
  26. GS      equ     1Dh             ; ^] goes to graphics (1st move invisible)
  27. RS      equ     1Eh             ; ^^ for point plot mode
  28. US      equ     1Fh             ; ^_ returns tor returns to text mode
  29. DEL     equ     7Fh             ; DELETE or RUBOUT
  30.  
  31. datas   segment public 'datas'
  32.  
  33. escflag db      0               ; Flag for ESCape sequences
  34. visible db      0               ; 0 to move, 1 to draw a line
  35. tek_hiy dw      0               ; Y coordinate in Tektronix mode
  36. tek_loy db      0
  37. tek_hix dw      0
  38. tek_lox db      0
  39. tek_lsb db      0               ; Low-order 2 bits of X + low Y (4014 mode)
  40.  
  41. datas   ends
  42.  
  43. code    segment public
  44.         assume  cs:code,ds:datas
  45.  
  46.  
  47. SENDID  PROC NEAR               ; Pretend VT100 with graphics option only
  48.         mov bx,IDSEQ            ; Get addr of string
  49. sndid1: mov al,DS:[bx]          ; Get char from sequence
  50.         cmp al,0                ; End of sequence?
  51.         jz sndid0               ; Yes, return
  52.         call OUTMODEM           ; Send it out the port
  53.         inc bx
  54.         jmp sndid1
  55. sndid0: ret
  56. SENDID  ENDP
  57.  
  58.  
  59. ;Terminal emulation - check for ESC-Z and for TEKTRONIX graphics commands
  60.  
  61. TERMEMU PROC NEAR               ; Send 7-bit character to the screen
  62.         and al,7Fh              ;  mask off parity for terminal
  63.         cmp al,NUL              ; NULL character?
  64.         je terme9               ; Yes, skip it
  65.         cmp al,GS               ; Group Separator (^]) ?
  66.         je go2graf              ; Yes, set graphics mode, pen up
  67.         cmp al,ESC              ; Escape?
  68.         je go2esc               ; Yes, remember that
  69.         mov bl,escflag          ; Get the state flag
  70.         xor bh,bh
  71.         jmp CS:tekjump[bx]      ; Go to routine
  72.  
  73. tekjump label   word
  74.         dw      TEKTXT          ; 0 = Normal text mode
  75.         dw      TEKESC          ; 2 = ESCape seen (forces text mode)
  76.         dw      TEKHIY          ; 4 = Graphics, get HI-Y
  77.         dw      TEKHIX          ; 6 = Graphics, get HI-X
  78.  
  79. go2graf:mov visible,0           ; Next move is invisible
  80.         mov escflag,4           ; Go to TEKGHIY next
  81. terme9: ret
  82.  
  83. go2esc: mov escflag,2           ; ESCape in text mode, goto TEKESC next
  84.         ret
  85.  
  86. ;ESCFLAG=0 - Normal text mode
  87.  
  88. TEKTXT: cmp al,DEL              ; RUBOUT?
  89.         je tektxt1              ; Yes, skip it in text mode
  90.         cmp al,FF               ; Formfeed?
  91.         je tektxt2              ; Yes, clear graphics
  92.         call OUTSCRN            ; No, output character to the screen
  93. tektxt1:ret
  94.  
  95. tektxt2:mov al,1                ; Clear only graphics (not text)
  96.         call CLS
  97.         ret
  98.  
  99. ;ESCFLAG=2 - Previous character was an ESCape
  100.  
  101. TEKESC: cmp al,'Z'              ; ESC-Z?
  102.         jne tekesc1
  103.         call SENDID             ; Send terminal identification
  104.         jmp go2text
  105.  
  106. tekesc1:cmp al,FF               ; ESC-FF?
  107.         jne tekesc2
  108.         mov al,0                ; CLS 0 to erase both text and graphics
  109.         call cls                ; Clear screen
  110.         jmp go2text             ; Return to text mode after ESC-FF
  111.  
  112. tekesc2:cmp al,SUB              ; ESC-^Z ?
  113.         jne tekesc3
  114.         call CROSHAIR           ; Activate the cross-hairs
  115.         jmp go2text
  116.  
  117. tekesc3:push ax                 ; Pass ESCape sequence to DOS
  118.         mov al,esc
  119.         call OUTSCRN
  120.         pop ax                  ; Character after the ESCape
  121.         call OUTSCRN
  122. go2text:mov escflag,0           ; Go to TEKTXT next time
  123.         ret
  124.  
  125. ;ESCFLAG=4 - Expecting HIY because LOX was seen
  126. ;ESCFLAG=6 - Expecting HIX because LOY was seen
  127. TEKHIY:
  128. TEKHIX: cmp al,CR               ; Exit graphics mode on CR,LF,US
  129.         je go2text
  130.         cmp al,LF
  131.         je go2text
  132.         cmp al,US
  133.         je go2text
  134.         cmp al,CAN
  135.         je go2text
  136.         cmp al,20h              ; Control char?
  137.         jl tekgh1               ; Ignore it
  138.         cmp al,40h
  139.         jl tekgh2               ; 20-3F are HIX or HIY
  140.         cmp al,60h              ; 40-5F are LOX (causes beam movement)
  141.         jl tekgh4               ; 60-7F are LOY
  142.  
  143. ;Extract low-order 5 bits of Y coordinate, set ESCFLAG=6
  144.  
  145.         mov ah,tek_loy          ; Copy previous LOY to MSB (in case 4014)
  146.         mov tek_lsb,ah
  147.         and al,1Fh              ; LOY is 5 bits
  148.         mov tek_loy,al
  149.         cmp escflag,6           ; 2nd LOY in a row?
  150.         je tekgh1               ; Yes, then LSB is valid
  151.         mov tek_lsb,0           ; 1st one, clear LSB
  152.         mov escflag,6           ; LOY seen, expect HIX (instead of HIY)
  153. tekgh1: ret
  154.  
  155. ;Extract high-order 5 bits (X or Y, depending on ESCFLAG)
  156.  
  157. tekgh2: and ax,1Fh              ; Just 5 bits
  158.         mov cl,5
  159.         shl ax,cl               ; Shift over 5 bits
  160.         cmp escflag,4           ; Looking for HIY?
  161.         jne tekgh3              ; No, HIX
  162.         mov tek_hiy,ax          ; Yes, this byte has HIY
  163.         ret                     ; Keep ESCFLAG=4
  164.  
  165. tekgh3: mov tek_hix,ax          ; This byte has HIX (because ESCFLAG=6)
  166.         mov escflag,4           ; Reset to look for HIY next time
  167.         ret
  168.  
  169. ;Extract low-order X, do beam movement
  170.  
  171. tekgh4: and al,1Fh              ; Just 5 bits
  172.         mov tek_lox,al
  173.  
  174.         mov ax,tek_hix          ; Combine HIX*32
  175.         or  al,tek_lox          ;  with LOX
  176.         mov bx,tek_hiy          ; Same for Y
  177.         or  bl,tek_loy
  178.         mov cl,visible          ; 0=move, 1=draw
  179.         call TEKDRAW
  180.  
  181. go2visi:mov visible,1           ; Next movement is with a visible trace
  182.         mov escflag,4           ; Reset to look for HIY next time
  183.         ret
  184. TERMEMU ENDP
  185.  
  186. code    ends
  187.         end