home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msyp98.asm < prev    next >
Assembly Source File  |  2020-01-01  |  89KB  |  4,539 lines

  1. ;+ This is MSYP98.ASM   VT100 emulation for NEC-PC9801          by.H.Fujii
  2. ;
  3. ; Update History
  4. ; 17-Apr-1991 vt_ourarg in vt100_modlin1 for modeline is changed.
  5. ;             prn_out is replaced by pntchr.
  6. ;             [these are done by Joe Doupnik]
  7. ; 01-Sep-1990 DCS is interpreted. Bugs for C0 characters in ESC/CSI seq.
  8. ;             have been fixed.
  9. ;             Saved CX in vt100_modlin.
  10. ; 29-Jul-1990 DCS is separated and ignored.
  11. ; 27-Jul-1990 For MS-Kermit v3.02
  12. ; 25-Jun-1990 Fixed bug of ESC FF (forgot to clear ESC flag).
  13. ; 04-Aug-1989 Fixed wrong ESC M (reverse index) and ESC E (next line).
  14. ; 30-May-1989 ESC [ 0 m resets colors to default (color in command mode).
  15. ; 21-Apr-1989 Backquote modification for display is moved to disp_char.
  16. ; 19-Apr-1989 Put CR/LF for CSI*;1H in the cooked-log file.
  17. ; 16-Apr-1989 Installed Cooked log
  18. ; 17-Jan-1989 Bug in VT100_color. Highlight color set was wrong.
  19. ; 03-Dec-1988 Bug report from Mikami-san at NTT software lab. for
  20. ;             ESC[;r.  The routine for 'set scroll region' is fixed.
  21. ; 06-Nov-1988 Bug found in VT100_SAVE.  In some situation, VT100 screen
  22. ;             is not restored correctly.
  23. ; 10-Sep-1988 Autoprint feateres are installed
  24. ; 14-Aug-1988 Roll-Up/Down features with simple circular movement.
  25. ;
  26. ; ESC sequence
  27. ; - General rule -
  28. ;   1) 2-byte sequence
  29. ;      a) ESC Fs terminated by 6/0 - 7/14 (standard sequence)
  30. ;      b) ESC Fp terminated by 3/0 - 3/15 (private sequence)
  31. ;      c) ESC Fe terminated by 4/0 - 5/15 (C1 control character)
  32. ;   2) multibyte sequnce
  33. ;      a) ESC I...I Fp terminated by 3/0 - 3/15 (private sequence)
  34. ;      b) ESC I...I Ft terminated by 4/0 - 7/14 (standard sequence)
  35. ;      where I is 2/0 - 2/15
  36. ;
  37. ; Cotrol sequence
  38. ;   1) CSI P...P I...I Ft terminated by 4/0 - 6/15 (standard sequence)
  39. ;   2) CSI P...P I...I Fp terminated by 7/0 - 7/14 (private sequence)
  40. ;      where CSI is 9/11 or ESC 5/11 (one of ESC Fe sequnce)
  41. ;            P is 3/0 - 3/15,
  42. ;                 3/11 is separator
  43. ;                 3/15 is private parameter introducer
  44. ;            I is 2/0 - 2/15
  45. ;
  46. ; CRT display character
  47. ;
  48. ;   Character plane
  49. ;              F E D C B A 9 8   7 6 5 4 3 2 1 0
  50. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  51. ;             |      0        | |    ANK code   |         ANK
  52. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  53. ;
  54. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  55. ;             |0|   JIS 2nd   | |JIS 1st - '20'X|     Kanji Left half
  56. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  57. ;             |1|   JIS 2nd   | |JIS 1st - '20'X|     Kanji Right half
  58. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  59. ;
  60. ;
  61. ;   Attribute plane
  62. ;              F E D C B A 9 8   7 6 5 4 3 2 1 0
  63. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  64. ;             |      N/A      | |G|R|B| | | | | |
  65. ;             +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
  66. ;                                ^ ^ ^ ^ ^ ^ ^ ^
  67. ;                                | | | | | | | |
  68. ;                                | | | | | | | secret (0)
  69. ;                                | | | | | | blink (1)
  70. ;                                | | | | | reverse (1)
  71. ;                                | | | | underline (1)
  72. ;                                | | | vertical line/graph pattern
  73. ;                                color
  74. ;
  75. ;
  76. ; The following Japanese Industrial Standards specify the Kana-Kanji treatment
  77. ; for information interchange.
  78. ;
  79. ;   JIS C 6226:
  80. ;     Code of the Japanese Graphic Character Set
  81. ;     for Information Intercahnge
  82. ;
  83. ;   JIS C 6228:
  84. ;     Code Extension Techniques for Use with the Code
  85. ;     for Information Interchange .
  86. ;
  87. ; In these standards, each byte of the multi-byte code is in the range
  88. ; 2/1 - 7/14. Each character is specified by an index of the current character
  89. ; table. In 7-bit environment, every index is the character code itself (or the
  90. ; first byte of the multi-byte character code). In 8-bit environment, there are
  91. ; two sets of current character table, called GL and GR.  A GL-character is
  92. ; specified by the character code itself, and a GR-character is specified by
  93. ; the character code with 8-th bits on.
  94. ; As intermediate character sets, four sets of characters can be used at onece.
  95. ; These sets are called G0, G1, G2 and G3.  To invoke these sets to the current
  96. ; character set(s),
  97. ;
  98. ; in 7-bit environment,
  99. ;
  100. ;   0/F       Shift In                Invoke G0 character set
  101. ;   0/E       Shift Out               Invoke G1 character set
  102. ;   ESC 6/E   Locking Shift 2         Invoke G2 character set
  103. ;   ESC 6/F   Locking Shift 3         Invoke G3 character set
  104. ;
  105. ;   ESC 4/E   Single Shift 2          Invoke G2 character
  106. ;   ESC 4/F   Single Shift 3          Invoke G3 character
  107. ;
  108. ; in 8-bit environment,
  109. ;
  110. ;   0/F       Locking Shift 0         Invoke G0 character set to GL
  111. ;   0/E       Locking Shift 1         Invoke G1 character set to GL
  112. ;   ESC 7/E   Locking Shift 1 Right   Invoke G1 character set to GR
  113. ;   ESC 6/E   Locking Shift 2         Invoke G2 character set to GL
  114. ;   ESC 7/D   Locking Shift 2 Right   Invoke G2 character set to GR
  115. ;   ESC 6/F   Locking Shift 3         Invoke G3 character set to GL
  116. ;   ESC 7/C   Locking Shift 3 Right   Invoke G3 character set to GR
  117. ;
  118. ;   8/E       Single Shift 2          Invoke G2 character
  119. ;   8/F       Single Shift 3          Invoke G3 character.
  120. ;
  121. ; To designate the single-byte character set, (JIS C 6228: 5.3.7)
  122. ;   ESC 2/8 F      and ESC 2/12 F              to G0 character set
  123. ;   ESC 2/9 F      and ESC 2/13 F              to G1 character set
  124. ;   ESC 2/10 F     and ESC 2/14 F              to G2 character set
  125. ;   ESC 2/11 F     and ESC 2/15 F              to G3 character set
  126. ;
  127. ;   where F is a final character in the range 3/0 - 7/14 which specifies the
  128. ;   character set. For example,
  129. ;
  130. ;       F        Character Set
  131. ;      ----      -------------
  132. ;      4/1       UK
  133. ;      4/2       US (ASCII)
  134. ;      4/9       JIS Katakana
  135. ;      4/10      JIS Roman
  136. ;      4/11      Germany
  137. ;      5/2       France
  138. ;      5/4       Chinese Roman
  139. ;      5/9       Italy
  140. ;      5/10      Spain
  141. ;      5/11      Greek
  142. ; .
  143. ;
  144. ; To designate the multi-byte character set, (JIS C 6226: 5.3.8)
  145. ;   ESC 2/4 F      and ESC 2/4 2/12 F          to G0 character set
  146. ;   ESC 2/4 2/9 F  and ESC 2/4 2/13 F          to G1 character set
  147. ;   ESC 2/4 2/10 F and ESC 2/4 2/14 F          to G2 character set
  148. ;   ESC 2/4 2/11 F and ESC 2/4 2/15 F          to G3 character set
  149. ;
  150. ;   where F is a final character in the range 3/0 - 7/14 which specifies the
  151. ;   character set. For example,
  152. ;
  153. ;       F        Character Set
  154. ;      ---       -------------
  155. ;      4/0       JIS C 6226 - 1978
  156. ;      4/1       Chinese Kanji
  157. ;      4/2       JIS C 6226 - 1983
  158. ;  .
  159. ;
  160. ; Corresponding Internatial Standard is ISO 2022.
  161. ;
  162.     include    mssdef.h
  163.     include    msxp98.h
  164. ;
  165. NUL    equ    0
  166. CSI    equ    9Bh
  167. ;
  168. ROLLMEM_MIN    equ    40        ; minimum & maximum number of
  169. ROLLMEM_MAX    equ    4000        ; paragraphs for roll-back buffer
  170. ;
  171.  
  172. CHR_REV        equ    04h
  173. CRT_TXT_SEG    equ    0A000h
  174.  
  175. PRIVP_FLG    equ    08000h
  176.  
  177. in_ESC_MODE    equ    1
  178. in_CSI_MODE    equ    2
  179. in_DCS_MODE    equ    3
  180.  
  181. VT52_DCA_L    equ    64
  182. VT52_DCA_C    equ    65
  183.  
  184. IN_SIXEL    equ    66
  185.  
  186.     public    vt100,vt100_ini,vt100_save,vt100_restore,vt100_reset
  187.     public    vt100_modlin, vt100_dump, vt100_color
  188.     public    vt100_rupn, vt100_rdnn, vt100_prnl, vt100_prns
  189.     public    set_modlin
  190.     public    prn_chk
  191.  
  192.     public    char_SS, char_GL, char_GR
  193.     public    gnrm_color, gbck_color
  194.  
  195. data     segment    public 'data'
  196.  
  197.     extrn    flags:byte, trans:byte
  198.     extrn    cpu_clock:byte, vtgrph_flg:byte, vttest_flg:byte
  199.     extrn    curkey_mode:byte, keypad_mode:byte
  200.     extrn    display_mode:byte
  201.     extrn    keyin_dos:byte
  202.     extrn    kanji_rcode:byte, kanji_scode:byte
  203.     extrn    vt100_cursr:byte
  204.     extrn    vt100_flags:byte, vt100_pflag:byte
  205.     extrn    vt100_lflag:byte, vt100_gflag:byte
  206.     extrn    vt_ourarg:byte
  207.     extrn    def_color:byte, scn_color:byte
  208.  
  209. vt_saveseg    dw    ?        ; segment address to save screen
  210. vt_rollseg    dw    ?        ; segment address to roll-up screen
  211. vt_rollmxs    dw    ?        ; maximum segment address allocated
  212. vt_rollmxl    dw    ?
  213. vt_rollcur    dw    ?        ; current segment address
  214. vt_rollcln    dw    0        ; current line number of the buffer
  215. vt_rollfil    dw    1
  216. vt_rollnum    dw    0
  217.  
  218. vt_init        db    0
  219. vt_wrap        db    0        ; wrap request flag
  220. vt_graph    db    0
  221. vt_chrset    db    0
  222. vt_chratr    db    0        ; current character attributes
  223. vt_blkatr    db    0        ; blank area attributes
  224. vt_nrmatr    db    0E1h        ; normal character attributes
  225. vt_hglatr    db    0C0h        ; highlight character attribute
  226. vt_modatr    db    0C5h        ; mode line character attributes
  227.  
  228. vt_in_stat    db    0        ; in status line flag
  229. vt_stat_type    db    1        ; status line type
  230. stat_col    db    0        ; column in status line
  231. stat_row    db    24        ; row of the status line (from 0)
  232.  
  233. sixel_disp_on    db    0, 0
  234.  
  235. save_flags    db    ?
  236. save_graph    db    ?
  237. save_chrset    db    ?
  238. save_chratr    db    ?
  239. save_blkatr    db    ?
  240.  
  241. vt_knjmode    db    0        ; Kanji mode if 1
  242. vt_kanji1    db    0        ; Kanji 1st byte
  243. vt_kanji2    db    0
  244.  
  245. ; The fllowing parameters are used for ESC/CSI/DCS sequence.
  246. ;   seq_stage:  0  normal character stage
  247. ;               1  in ESC seq.
  248. ;               2  in ESC intermediate stage
  249. ;               3  in CSI (parameter) stage.
  250. ;               4  in CSI intermediate stage
  251. ;               5  in DCS (parameter) stage.
  252. ;               6  in DCS intermediate stage
  253. ;
  254. spec_mode    db    0
  255. spec_stage    db    0
  256. I_pnt        dw    0
  257. I_buf        db    128 dup (?)
  258. P_pnt        dw    0
  259. P_buf        dw    128 dup (?)
  260.  
  261. priv_pflg    dw    0
  262. priv_char    db    0
  263.  
  264. char_SS        dw    0        ; GL for single shift
  265. char_GL        dw    ?
  266. char_GR        dw    ?
  267.  
  268. char_save_SS    dw    ?
  269. char_save_GL    dw    ?
  270. char_save_GR    dw    ?
  271.  
  272. char_G0        db    CSET_JISROMAN
  273. char_G1        db    CSET_DECGRAPH
  274. char_G2        db    CSET_JISKATAKANA
  275. char_G3        db    CSET_JISC6226
  276.  
  277. char_save_G0    db    ?
  278. char_save_G1    db    ?
  279. char_save_G2    db    ?
  280. char_save_G3    db    ?
  281.  
  282. ; Normal PC98 color table
  283. ;
  284. gnrm_color    db    000h,000h,000h        ;  0:black
  285.         db    000h,000h,0ffh        ;  1:blue
  286.         db    0ffh,000h,000h        ;  2:red
  287.         db    0ffh,000h,0ffh        ;  3:magenta
  288.         db    000h,0ffh,000h        ;  4:green
  289.         db    000h,0ffh,0ffh        ;  5:cyan
  290.         db    0ffh,0ffh,000h        ;  6:yellow
  291.         db    0ffh,0ffh,0ffh        ;  7:white
  292.         db    0afh,0afh,0afh        ;  8:light-gray
  293.         db    000h,000h,0afh        ;  9:dark-blue
  294.         db    0afh,000h,000h        ; 10:dark-red
  295.         db    0afh,000h,0afh        ; 11:dark-magenta
  296.         db    000h,0afh,000h        ; 12:dark-green
  297.         db    000h,0afh,0afh        ; 13:dark-cyan
  298.         db    0afh,0afh,000h        ; 14:dark-yellow
  299.         db    07fh,07fh,07fh        ; 15:dark-gray
  300. ;
  301. gbck_color    db    000h,000h,000h        ;  0:
  302.         db    000h,000h,000h        ;  1:
  303.         db    000h,000h,000h        ;  2:
  304.         db    000h,000h,000h        ;  3:
  305.         db    000h,000h,000h        ;  4:
  306.         db    000h,000h,000h        ;  5:
  307.         db    000h,000h,000h        ;  6:
  308.         db    000h,000h,000h        ;  7:
  309.         db    000h,000h,000h        ;  8:
  310.         db    000h,000h,000h        ;  9:
  311.         db    000h,000h,000h        ; 10:
  312.         db    000h,000h,000h        ; 11:
  313.         db    000h,000h,000h        ; 12:
  314.         db    000h,000h,000h        ; 13:
  315.         db    000h,000h,000h        ; 14:
  316.         db    000h,000h,000h        ; 15:
  317.  
  318. vt_gset        db    0EAh,087h,009h,00Ch,00Dh,00Ah,0DFh,08Fh
  319.         db    015h,00Bh,09Bh,099h,098h,09Ah,08Fh,094h
  320.         db    094h,095h,081h,080h,093h,092h,090h,091h
  321.         db    096h,01Dh,01Ch,01Eh,01Fh,0F1h,0A5h,020h
  322.  
  323.         even
  324. C0_func_tab    dw    vt_disp_none        ; 00H NUL
  325.         dw    vt_disp_none        ; 01H SOH
  326.         dw    vt_disp_none        ; 02H STX
  327.         dw    vt_disp_none        ; 03H ETX
  328.         dw    vt_disp_none        ; 04H EOT
  329.         dw    vt_disp_none        ; 05H ENQ
  330.         dw    vt_disp_none        ; 06H ACK
  331.         dw    vt_disp_BEL        ; 07H BEL
  332.         dw    vt_disp_BS        ; 08H BS
  333.         dw    vt_disp_HT        ; 09H HT
  334.         dw    vt_disp_LF        ; 0AH LF
  335.         dw    vt_disp_LF        ; 0BH VT
  336.         dw    vt_disp_LF        ; 0CH FF
  337.         dw    vt_disp_CR        ; 0DH CR
  338.         dw    vt_disp_SO        ; 0EH SO
  339.         dw    vt_disp_SI        ; 0FH SI
  340. ;
  341.         dw    vt_disp_none        ; 10H DLE
  342.         dw    vt_disp_none        ; 11H DC1 (XON)
  343.         dw    vt_disp_none        ; 12H DC2
  344.         dw    vt_disp_none        ; 13H DC3 (XOFF)
  345.         dw    vt_disp_none        ; 14H DC4
  346.         dw    vt_disp_none        ; 15H NAK
  347.         dw    vt_disp_none        ; 16H SYN
  348.         dw    vt_disp_none        ; 17H ETB
  349.         dw    vt_disp_CAN        ; 18H CAN
  350.         dw    vt_disp_none        ; 19H EM
  351.         dw    vt_disp_SUB        ; 1AH SUB
  352.         dw    vt_disp_ESC        ; 1BH ESC
  353.         dw    vt_disp_none        ; 1CH FS
  354.         dw    vt_disp_GS        ; 1DH GS
  355.         dw    vt_disp_none        ; 1EH RS
  356.         dw    vt_disp_none        ; 1FH US
  357. ;
  358.         even
  359. vram_line    dw    0000h        ; 0-line
  360.         dw    00a0h        ; 1
  361.         dw    0140h        ; 2
  362.         dw    01e0h        ; 3
  363.         dw    0280h        ; 4
  364.         dw    0320h        ; 5
  365.         dw    03c0h        ; 6
  366.         dw    0460h        ; 7
  367.         dw    0500h        ; 8
  368.         dw    05a0h        ; 9
  369.         dw    0640h        ;10
  370.         dw    06e0h        ;11
  371.         dw    0780h        ;12
  372.         dw    0820h        ;13
  373.         dw    08c0h        ;14
  374.         dw    0960h        ;15
  375.         dw    0a00h        ;16
  376.         dw    0aa0h        ;17
  377.         dw    0b40h        ;18
  378.         dw    0be0h        ;19
  379.         dw    0c80h        ;20
  380.         dw    0d20h        ;21
  381.         dw    0dc0h        ;22
  382. vram_botm_line    dw    0e60h        ;23
  383. vram_last_line    dw    0f00h        ;24
  384. ;
  385. I_am_vt52    db    3
  386.         db    ESCAPE,"/Z"
  387. I_am_vt102    db    5
  388.         db    ESCAPE,"[?6c"
  389. I_am_vt220    db    16
  390.         db    ESCAPE,"[?62;1;2;6;7;8c"
  391. I_am_fine    db    4
  392.         db    ESCAPE,"[0n"
  393. My_cursor_is    db    ESCAPE,"["
  394.         db    10 dup (?)
  395. cur_col        db    0
  396. cur_row        db    0
  397. cur_save_col    db    0
  398. cur_save_row    db    0
  399.  
  400. text_col    db    0
  401. text_row    db    0
  402. text_top    db    0
  403. text_bottom    db    0
  404.  
  405. color_index_table    db    0, 2, 4, 6, 1, 3, 5, 7
  406. ;
  407. vt_phys_top    db    0
  408. vt_phys_bottom    db    23
  409.  
  410. vt_top        db    0
  411. vt_bottom    db    23
  412.  
  413. tabstops    db    80 dup (?)    ; tab stop table
  414.         db    1,1        ; guard
  415.  
  416. nam_none    db    '          '
  417. nam_vt52    db    'VT52      '
  418. nam_vt100    db    'VT102 '
  419. LED_buff    db    '....'
  420. nam_tek        db    'TEK4010/14'
  421. nam_prn        db    ' PRN'
  422. nam_nprn    db    '    '
  423.  
  424. dump_pntr    dw    ?
  425. dump_buffer    db    256    dup (?)
  426. dump_mode    db    0
  427.  
  428. watch_pnd    dw    0
  429. watch_buf    db    12 dup (?)
  430. watch_lvl    db    0
  431. watch_mod    db    0
  432.  
  433. ;
  434. ; Kermit mode line buffer
  435. ;
  436. mode_len    db    0
  437. mode_ker    db    'Esc-chr: '
  438. mode_esc    db    '^]'
  439.         db    '  help: '
  440. mode_hlp    db    '^]'
  441.         db    '?  port:'
  442. mode_prt    db    '1'
  443.         db    ' speed:'
  444. mode_spd    db    '     '
  445.         db    ' parity:'
  446. mode_pty    db    'none'
  447.         db    ' echo:'
  448. mode_ech    db    'rem'
  449.         db    ' '
  450. mode_trm    db    '          '
  451. mode_prn    db    '    '
  452. MODE_LINE_LENG    = $ - mode_len
  453.  
  454. unkbaud        db    ' Unk '    ; must be 5 characters
  455. baudname    db    ' 45.5'
  456.         db    '  50 '
  457.         db    '  75 '
  458.         db    ' 110 '
  459.         db    '134.5'
  460.         db    ' 150 '
  461.         db    ' 300 '
  462.         db    ' 600 '
  463.         db    ' 1200'
  464.         db    ' 1800'
  465.         db    ' 2000'
  466.         db    ' 2400'
  467.         db    ' 4800'
  468.         db    ' 9600'
  469.         db    '19200'
  470.         db    '38400'
  471.         db    '57.6K'
  472.         db    '115 K'
  473. BAUDNSIZ    equ    18
  474.  
  475. parityname    db    'even'        ; must be 4 characters
  476.         db    'mark'
  477.         db    'none'
  478.         db    'odd '
  479.         db    'spc '
  480.  
  481. lclename    db    'loc'
  482. remename    db    'rem'
  483.  
  484. data    ends
  485.  
  486. code    segment    public    'code'
  487.     assume    cs:code,ds:data,es:nothing
  488.  
  489.     extrn    sbrk:near        ; memory allocation routine in mssker
  490.     extrn    s2jis:near, jis2s:near    ; in MSZP98
  491.     extrn    set_cursor:near        ; in MSZP98
  492.     extrn    set_gpalette:near    ; in MSGP98
  493.     extrn    gdisp_on:near, gdisp_off:near    ; in MSGP98
  494.     extrn    tek4014_color:near    ; in MSGP98
  495.     extrn    set_gcolor:near        ; in MSGP98
  496.     extrn    pntchr:near
  497.     extrn    outcapt:near        ; in MSXP98
  498.     extrn    set_cur_color:near    ; in MSXP98
  499.     extrn    sixel_in:near        ; in MSGP98
  500.     extrn    sixel_clear:near    ; in MSGP98
  501.     extrn    sixel:near        ; in MSGP98
  502. ;
  503. ; VT100 terminal emulator
  504. ;
  505. ;
  506. ;-----------------------------------------------------------
  507. ;
  508. ; Initilization routine
  509. ; This is called from lclini, local initialization routine.
  510.  
  511. VT100_INI    PROC    NEAR
  512.     cmp    vt_init,0
  513.     je    vt100_ini_1
  514.     jmp    vt100_ini_ex
  515. vt100_ini_1:
  516.     mov    vt_init,1
  517. ;
  518. ; Allocate memory to save screen
  519. ;
  520.     mov    ax,2000h    ; display + attributes
  521.     call    sbrk
  522.     mov    vt_saveseg,ax
  523. ;
  524. ; Check the memory size
  525. ;
  526.     mov    bx,0FFFFh    ; allocate full integer (must fail)
  527.     mov    ah,ALLOC    ; memory allocation
  528.     int    DOS        ; system call. BX has number of free para.
  529.     mov    ax,bx
  530.     cmp    ax,2000        ; keep 32K for COMMAND.COM (in parag. size)
  531.     ja    vt100_ini_r1
  532.     mov    ax,ROLLMEM_MIN
  533.     jmp    vt100_ini_r2
  534. vt100_ini_r1:
  535.     sub    ax,2000
  536.     cmp    ax,ROLLMEM_MAX
  537.     jbe    vt100_ini_r2
  538.     mov    ax,ROLLMEM_MAX
  539. vt100_ini_r2:
  540.     xor    dx,dx
  541.     mov    cx,20        ; number of parag. per line
  542.     div    cx
  543.     mov    vt_rollmxl,ax
  544.     mov    cx,20        ; number of parag. per line
  545.     mul    cx
  546.     push    ax        ; save number of parag.
  547.     mov    bx,ax
  548.     mov    ah,ALLOC    ; allocate memory
  549.     int    DOS
  550.     mov    vt_rollseg,ax
  551.     mov    vt_rollcur,ax
  552.     mov    vt_rollcln,0
  553.     mov    vt_rollfil,1
  554.     pop    bx
  555.     add    ax,bx
  556.     mov    vt_rollmxs,ax
  557. ;
  558. vt100_ini_ex:
  559.     call    vt100_soft_res    ; reset software parameters
  560.     ret
  561. VT100_INI    ENDP
  562.  
  563. VT100_RESET    PROC    NEAR
  564.     call    vt100_soft_res
  565.     call    vt100_restore
  566.     call    vt100_modlin
  567.     ret
  568. VT100_RESET    ENDP
  569.  
  570. VT100_SOFT_RES    PROC    NEAR
  571. ;
  572. ; Software reset terminal (* means not supported yet)
  573. ;  * Text cursor      On
  574. ;    Insert/Replace   Replace
  575. ;    Origin Mode      Absolute
  576. ;    Autowrap         Off
  577. ;  * Keyboard Action  Unlocked
  578. ;    Keypad Mode      Numeric
  579. ;    Cursor Key Mode  Normal
  580. ;    Top Margin       1
  581. ;    Bottom Margin    24
  582. ;    Character Sets   default
  583. ;    Video Character  Normal
  584. ;
  585.     push    ax
  586.     push    bx
  587. ;
  588.     mov    sixel_disp_on,0        ; no sixel display
  589.     mov    vt100_gflag,1
  590.     push    si
  591.     mov    si,offset def_color    ; set color to default
  592.     call    set_cur_color
  593.     call    vt100_color
  594.     pop    si
  595. ;
  596.     mov    vt_in_stat,0        ; main screen
  597.     mov    vt_stat_type,1
  598. ;
  599.     mov    ax,'..'            ; LED-clear
  600.     mov    bx,offset LED_buff
  601.     mov    [bx],ax
  602.     mov    [bx+2],ax
  603. ;
  604.     and    vt100_flags,(not INSERT_BIT)
  605.     and    vt100_flags,(not ORIGIN_BIT)
  606.     and    vt100_flags,(not AUTOWRAP_BIT)
  607.     mov    vt100_pflag,0        ; flags for printer control
  608.     mov    vt100_cursr,0        ; cursor style
  609.     mov    curkey_mode,0
  610.     mov    keypad_mode,0
  611.     mov    cur_col,0
  612.     mov    cur_row,0
  613.     mov    cur_save_col,0
  614.     mov    cur_save_row,0
  615.     mov    al,vt_nrmatr
  616.     mov    vt_chratr,al
  617.     mov    vt_blkatr,al
  618.     mov    al,vt_phys_top
  619.     mov    vt_top,al
  620.     mov    al,vt_phys_bottom
  621.     mov    vt_bottom,al
  622.     mov    priv_pflg,0
  623. ;
  624.     mov    char_G0,CSET_JISROMAN
  625.     mov    char_G1,CSET_DECGRAPH
  626.     mov    char_G2,CSET_JISKATAKANA
  627.     mov    char_G3,CSET_JISC6226
  628. ;
  629.     mov    vt_graph,0
  630.     mov    char_SS,0
  631.     mov    char_GL,offset char_G0
  632.     mov    char_GR,offset char_G3
  633. ;
  634. ; Erase save area
  635. ;
  636.     push    es
  637.     push    di
  638.     cld
  639.     mov    ax,vt_saveseg
  640.     mov    es,ax
  641.     mov    di,0        ; offset address
  642.     mov    cx,0800h
  643.     mov    ax,0020h
  644.     rep    stosw
  645.     mov    al,vt_blkatr
  646.     xor    ah,ah
  647.     mov    cx,0800h
  648.     rep    stosw
  649. ;
  650.     pop    di
  651.     pop    es
  652. ;
  653. ; Initialize TAB table
  654. ;
  655.     push    cx
  656.     push    dx
  657. ;
  658.     mov    bx,offset tabstops
  659.     mov    cx,80
  660.     xor    ax,ax
  661. vt_ini_t1:
  662.     mov    dl,0
  663.     test    ax,7
  664.     jnz    vt_ini_t2
  665.     mov    dl,1
  666. vt_ini_t2:
  667.     push    bx
  668.     add    bx,ax
  669.     mov    byte ptr [bx],dl
  670.     pop    bx
  671.     inc    ax
  672.     loop    vt_ini_t1
  673. ;
  674.     pop    dx
  675.     pop    cx
  676. ;
  677.     call    set_modlin        ; set Kermit modeline buffer
  678.     call    save_cursor
  679.     pop    bx
  680.     pop    ax
  681.     ret
  682. VT100_SOFT_RES    ENDP
  683.  
  684. ;
  685. ; save VT100 screen
  686. ;
  687. VT100_SAVE    PROC    NEAR
  688.     push    ax
  689.     push    cx
  690.     push    dx
  691.     push    ds
  692.     push    es
  693. ;
  694.     cld
  695. ;
  696.     mov    ah,0Dh            ; stop display
  697.     int    BIOS
  698. ;
  699.     mov    ax,vt_saveseg
  700.     mov    es,ax            ; destination segment address
  701.     mov    di,0
  702.     mov    si,vram_line        ; set source address [06-Nov-88]
  703.     push    si            ; save it for later use [06-Nov-88]
  704.     mov    ax,CRT_TXT_SEG
  705.     mov    ds,ax
  706.     mov    cx,0800h
  707.     rep    movsw
  708.     pop    si            ; remember source address [06-Nov-88]
  709.     add    si,2000h        ; attribute area
  710.     mov    cx,0800h
  711.     rep    movsw
  712. ;
  713.     pop    es
  714.     pop    ds
  715. ;
  716. ; clear mode line
  717. ;
  718.     mov    al,vt_blkatr
  719.     call    vt_stat_clr
  720. ;
  721.     mov    ah,0Ch            ; start dispay
  722.     int    BIOS
  723. ;
  724.     mov    ax,0
  725.     call    set_cursor        ; restore cursor attributes
  726. ;
  727.     mov    si,offset gnrm_color
  728.     call    set_gpalette
  729.     call    gdisp_off
  730. ;
  731.     pop    dx
  732.     pop    cx
  733.     pop    ax
  734. ;
  735.     ret
  736. VT100_SAVE    ENDP
  737.  
  738. ;
  739. ; restore VT100 screen
  740. ;
  741. VT100_RESTORE    PROC    NEAR
  742.     push    ax
  743.     push    bx
  744.     push    cx
  745.     push    dx
  746.     push    ds
  747.     push    es
  748. ;
  749.     cld
  750. ;
  751.     mov    ah,0Dh            ; stop display
  752.     int    BIOS
  753. ;
  754.     mov    ax,CRT_TXT_SEG
  755.     mov    es,ax            ; destination sagment address
  756.     mov    di,vram_line
  757.     push    di
  758.     mov    ax,vt_saveseg
  759.     mov    ds,ax
  760.     mov    si,0
  761.     mov    cx,0800h
  762.     rep    movsw
  763.     pop    di
  764.     add    di,2000h        ; attribute area
  765.     mov    cx,0800h
  766.     rep    movsw
  767. ;
  768.     mov    ah,0Ch            ; start dispay
  769.     int    BIOS
  770. ;
  771.     pop    es
  772.     pop    ds
  773. ;
  774.     xor    ax,ax
  775.     mov    al,vt100_cursr
  776.     call    set_cursor        ; set cursor attributes
  777. ;
  778.     call    locate_cur
  779. ;
  780.     call    set_gcolor
  781.     call    gdisp_on
  782. ;
  783.     pop    dx
  784.     pop    cx
  785.     pop    bx
  786.     pop    ax
  787. ;
  788.     ret
  789. VT100_RESTORE    ENDP
  790.  
  791. set_termnam    proc    near
  792.     push    ax
  793.     push    cx
  794.     push    si
  795.     push    di
  796.     push    es
  797. ;
  798.     mov    ax,ds
  799.     mov    es,ax
  800. ;  terminal type
  801.     mov    cx,10            ; length of terminal name
  802.     mov    si,offset nam_vt52
  803.     cmp    flags.vtflg,ttvt52
  804.     je    set_termnam1
  805.     mov    si,offset nam_vt100
  806.     cmp    flags.vtflg,ttvt100
  807.     je    set_termnam1
  808.     mov    si,offset nam_tek
  809.     cmp    flags.vtflg,tttek
  810.     je    set_termnam1
  811.     mov    si,offset nam_none
  812. set_termnam1:
  813.     mov    di,offset mode_trm
  814.     rep    movsb
  815. ;
  816.     pop    es
  817.     pop    di
  818.     pop    si
  819.     pop    cx
  820.     pop    ax
  821.     ret
  822. set_termnam    endp
  823. ;
  824. set_prnstat    proc
  825.     push    ax
  826.     push    cx
  827.     push    si
  828.     push    di
  829.     push    es
  830. ;
  831.     mov    ax,ds
  832.     mov    es,ax
  833. ;
  834. ;  printer status
  835. ;
  836.     mov    cx,4
  837.     mov    si,offset nam_nprn
  838.     test    vt100_pflag,(AUTOPRINT_BIT+PRINTCTRL_BIT)
  839.     jz    set_prnstat1
  840.     mov    si,offset nam_prn
  841. set_prnstat1:
  842.     mov    di,offset mode_prn
  843.     rep    movsb
  844.     pop    es
  845.     pop    di
  846.     pop    si
  847.     pop    cx
  848.     pop    ax
  849.     ret
  850. set_prnstat    endp
  851. ;
  852. SET_MODLIN    PROC    NEAR
  853. ; set the mode line buffer
  854. ;
  855.     push    es
  856.     mov    ax,ds
  857.     mov    es,ax
  858. ;
  859.     mov    al,' '
  860.     mov    ah,trans.escchr
  861.     cmp    ah,020h
  862.     jge    set_modlin1
  863.     mov    al,'^'
  864.     or    ah,040h
  865. set_modlin1:
  866.     mov    word ptr mode_esc,ax
  867.     mov    word ptr mode_hlp,ax
  868. ;
  869.     mov    al,vt_ourarg.baudb
  870.     mov    si,offset unkbaud    ; Assume unknown baud.
  871.     mov    cx,5            ; length of baud space
  872.     cmp    al,BAUDNSIZ        ; too big?
  873.     jnb    set_modlin2        ; yes, use default
  874.     mul    cl
  875.     xor    ah,ah
  876.     add    ax,offset baudname
  877.     mov    si,ax
  878. set_modlin2:
  879.     mov    di,offset mode_spd
  880.     rep    movsb
  881. ;
  882.     mov    al,vt_ourarg.prt
  883.     cmp    al,'A'
  884.     jae    set_modlin3
  885.     add    al,'0'            ; convert to character
  886. set_modlin3:
  887.     mov    mode_prt,al
  888. ;
  889.     mov    al,vt_ourarg.parity
  890.     xor    ah,ah
  891.     mov    cx,4
  892.     imul    cl
  893.     add    ax,offset parityname
  894.     mov    si,ax
  895.     mov    di,offset mode_pty
  896.     rep    movsb
  897. ;
  898.     mov    si,offset lclename
  899.     test    vt_ourarg.flgs,lclecho
  900.     jnz    set_modlin4
  901.     mov    si,offset remename
  902. set_modlin4:
  903.     mov    cx,3
  904.     mov    di,offset mode_ech
  905.     rep    movsb
  906. ;
  907.     call    set_termnam
  908.     call    set_prnstat
  909. ;
  910.     mov    mode_len,MODE_LINE_LENG
  911. ;
  912.     pop    es
  913.     ret
  914. SET_MODLIN    ENDP
  915. ;
  916. vt_stat_clr    proc    near
  917. ;
  918. ; clear status line with attribute in AL.
  919. ;
  920.     push    bx
  921.     push    es
  922.     push    di
  923.     push    si
  924. ;
  925.     mov    bx,ax
  926.     cld
  927.     mov    ax,CRT_TXT_SEG
  928.     mov    es,ax
  929.     mov    di,vram_last_line
  930.     mov    cx,80
  931.     xor    ah,ah
  932.     mov    al,' '
  933.     rep    stosw
  934.     mov    di,vram_last_line
  935.     add    di,02000h
  936.     mov    al,bl
  937.     mov    cx,80
  938.     rep    stosw
  939. ;
  940.     mov    ax,bx
  941.     pop    si
  942.     pop    di
  943.     pop    es
  944.     pop    bx
  945.     ret
  946. vt_stat_clr    endp
  947. ;
  948. VT100_MODLIN    PROC    NEAR
  949. ;
  950. ; Mode line display control
  951. ;
  952. ; Inputs:
  953. ;    dx    offset address of the mode line buffer;
  954. ;        The 1st byte of the mode line buffer must contain the
  955. ;        the number of characters in the buffer. If it is zero,
  956. ;        the mode line is cleared.
  957. ;
  958.     push    ax
  959.     push    cx
  960.     cmp    vt_stat_type,0        ; clear status buffer ?
  961.     jne    vt100_modlin1        ; ne=no.
  962.     mov    al,vt_blkatr        ; attribute
  963.     call    vt_stat_clr        ; clear the status line
  964.     jmp    vt100_modlin_ex        ; and return
  965. ;
  966. vt100_modlin1:
  967.     cmp    vt_stat_type,1        ; Kermit mode line control ?
  968.     jne    vt100_modlin2        ; ne=no.
  969.     test    vt_ourarg.flgs,modoff    ; mode line off ?
  970.     jz    vt100_modlin1_1        ; z=no.
  971.     mov    al,vt_blkatr
  972.     call    vt_stat_clr
  973.     jmp    vt100_modlin_ex
  974. ;
  975. ;  display kermit mode line
  976. ;
  977. vt100_modlin1_1:
  978.     mov    al,vt_modatr
  979.     call    vt_stat_clr
  980. ;
  981.     push    es
  982.     push    di
  983.     push    si
  984. ;
  985.     cld
  986.     xor    ch,ch
  987.     mov    cl,mode_len
  988.     mov    si,offset mode_ker
  989.     mov    ax,CRT_TXT_SEG
  990.     mov    es,ax
  991.     mov    di,vram_last_line
  992.     xor    ah,ah
  993. vt100_modlin1_2:
  994.     mov    al,[si]
  995.     mov    es:[di],ax
  996.     inc    si
  997.     add    di,2
  998.     loop    vt100_modlin1_2
  999. ;
  1000.     pop    si
  1001.     pop    di
  1002.     pop    es
  1003.     jmp    vt100_modlin_ex
  1004. ;
  1005. vt100_modlin2:
  1006. ;@@    mov    al,vt_modatr
  1007. ;@@    call    vt_stat_clr
  1008. ;
  1009. vt100_modlin_ex:
  1010.     call    locate_cur
  1011. ;
  1012.     pop    cx
  1013.     pop    ax
  1014.     ret
  1015. VT100_MODLIN    ENDP
  1016.  
  1017. VT100_COLOR    PROC    NEAR
  1018. ;
  1019. ; Change color to the value specified in [si].
  1020. ;    [si]    color index for foreground
  1021. ;    [si+1]    color index for background
  1022. ;    [si+2]    color index for highlight
  1023. ;    [si+3]    color index for modeline
  1024. ;
  1025.     push    ax
  1026.     push    cx
  1027. ;
  1028.     mov    al,[si]
  1029.     and    vt_nrmatr,1Fh        ; mask color attributes
  1030.     and    vt_chratr,1Fh
  1031.     and    vt_blkatr,1Fh
  1032.     mov    cl,5
  1033.     shl    al,cl
  1034.     or    vt_nrmatr,al
  1035.     or    vt_chratr,al
  1036.     or    vt_blkatr,al
  1037. ;
  1038.     push    di
  1039.     push    si
  1040.     mov    al,[si+1]
  1041.     xor    ah,ah
  1042.     mov    si,offset gnrm_color
  1043.     add    si,ax
  1044.     add    si,ax
  1045.     add    si,ax
  1046.     mov    di,offset gbck_color
  1047.     mov    cx,16
  1048. vt100_color1:
  1049.     mov    al,[si]
  1050.     mov    [di],al
  1051.     inc    di
  1052.     mov    al,[si+1]
  1053.     mov    [di],al
  1054.     inc    di
  1055.     mov    al,[si+2]
  1056.     mov    [di],al
  1057.     inc    di
  1058.     loop    vt100_color1
  1059.     pop    si
  1060.     pop    di
  1061. ;
  1062.     mov    al,[si+2]
  1063.     and    vt_hglatr,1Fh        ; mask color attributes
  1064.     mov    cl,5
  1065.     shl    al,cl
  1066.     or    vt_hglatr,al
  1067. ;
  1068.     mov    al,[si+3]
  1069.     and    vt_modatr,1Fh        ; mask color attributes
  1070.     mov    cl,5
  1071.     shl    al,cl
  1072.     or    vt_modatr,al
  1073. ;
  1074.     pop    cx
  1075.     pop    ax
  1076.     ret
  1077. VT100_COLOR    ENDP
  1078.  
  1079. mrsave        proc    near
  1080. ;
  1081. ; save n lines (given by CL) in roll-up buffer (circular).
  1082. ;
  1083.     push    ax
  1084.     push    cx
  1085.     push    si
  1086.     push    di
  1087.     push    ds
  1088.     push    es
  1089. ;
  1090.     xor    ch,ch        ; clear high byte of CX
  1091.     mov    si,vram_line
  1092. mrsave1:
  1093.     cmp    cx,0
  1094.     jle    mrsave3
  1095.     push    cx
  1096.     push    ds
  1097.     mov    ax,vt_rollcur    ; current roll-buffer segment
  1098.     mov    es,ax        ; destination segment address
  1099.     mov    di,0        ; destination offset address
  1100.     mov    ax,CRT_TXT_SEG
  1101.     mov    ds,ax        ; source segment address
  1102.     push    si        ; save the source offset address
  1103.     mov    cx,80        ; words per line
  1104.     rep    movsw        ; save the text area
  1105.     pop    si
  1106.     add    si,2000h    ; offset address of the attribute area
  1107.     mov    cx,80
  1108.     rep    movsw        ; save the attribute area
  1109.     sub    si,2000h    ; return to text area
  1110.     pop    ds
  1111.     pop    cx
  1112.     dec    cx
  1113.     inc    vt_rollcln    ; update lines
  1114.     add    vt_rollcur,20    ; update segment address. 20 parag. per line
  1115.     mov    ax,vt_rollfil
  1116.     cmp    ax,vt_rollmxl
  1117.     jge    mrsave2
  1118.     inc    vt_rollfil
  1119. mrsave2:
  1120.     mov    ax,vt_rollcln
  1121.     cmp    ax,vt_rollmxl    ; exceed maximum lines ?
  1122.     jl    mrsave1
  1123.     mov    ax,vt_rollseg
  1124.     mov    vt_rollcur,ax
  1125.     mov    vt_rollcln,0
  1126.     jmp    mrsave1
  1127. mrsave3:
  1128.     pop    es
  1129.     pop    ds
  1130.     pop    di
  1131.     pop    si
  1132.     pop    cx
  1133.     pop    ax
  1134.     ret
  1135. mrsave        endp
  1136.  
  1137. prn_chk    proc    near
  1138. ;
  1139. ; Check the printer port
  1140. ; carry on  -- printer not ready
  1141. ;
  1142.     push    ax
  1143.     mov    ah,ioctl
  1144.     mov    al,7            ; get output status of printer
  1145.     push    bx
  1146.     mov    bx,4            ; file handle for system printer
  1147.     int    dos
  1148.     pop    bx
  1149.      jc    prn_chk1        ; c = printer not ready
  1150.      cmp    al,0ffh            ; Ready status?
  1151.     je    prn_chk2        ; e = Ready
  1152. prn_chk1:
  1153.     call    vt_bell
  1154.     stc
  1155. prn_chk2:
  1156.     pop    ax
  1157.     ret
  1158. prn_chk    endp
  1159.  
  1160.  
  1161. VT100_RUPN    proc    near
  1162. ;
  1163. ; roll-up n lines (n is given in cx)
  1164. ; cx will be broken when return.
  1165. ; 1) copy the last line of the screen to the current save area
  1166. ; 2) decrement the save area pointer
  1167. ; 3) scroll down the screen by one line
  1168. ; 4) copy the current save area to the top of screen
  1169. ; 5) increment the number of moved lines
  1170. ;
  1171.     push    ax
  1172.     push    dx
  1173.     push    si
  1174.     push    di
  1175.     push    es
  1176. ;
  1177. vt100_rupn_1:
  1178.     cmp    cx,0
  1179.     jg    vt100_rupn_2
  1180.     jmp    vt100_rupn_ex
  1181. vt100_rupn_2:
  1182.     mov    ax,vt_rollnum
  1183.     inc    ax
  1184.     cmp    ax,vt_rollfil
  1185.     jl    vt100_rupn_3
  1186.     jmp    vt100_rupn_ex
  1187. ;
  1188. vt100_rupn_3:
  1189.     push    cx            ; save counter
  1190.     mov    ax,vt_rollcur
  1191.     mov    es,ax
  1192.     mov    di,0
  1193. ;
  1194.     push    ds
  1195. ;
  1196.     mov    ax,CRT_TXT_SEG
  1197.     mov    si,vram_botm_line
  1198.     push    si
  1199.     mov    cx,80
  1200.     mov    ds,ax
  1201.     cld
  1202.     rep    movsw
  1203.     pop    si
  1204.     add    si,2000h        ; attribute area
  1205.     mov    cx,80
  1206.     rep    movsw            ; save attributes
  1207. ;
  1208.     pop    ds
  1209. ;
  1210.     mov    cx,20            ; one line (display + attributes)
  1211.     cmp    vt_rollcln,0
  1212.     jg    vt100_rupn_4
  1213.     mov    ax,vt_rollmxl
  1214.     mov    vt_rollcln,ax
  1215.     mov    ax,vt_rollmxs
  1216.     mov    vt_rollcur,ax
  1217. vt100_rupn_4:
  1218.     dec    vt_rollcln
  1219.     mov    ax,vt_rollcln
  1220.     sub    vt_rollcur,cx
  1221. ;
  1222.     mov    cx,vram_botm_line
  1223.     sub    cx,vram_line
  1224.     mov    di,vram_last_line
  1225.     dec    di
  1226.     mov    si,vram_botm_line
  1227.     dec    si
  1228.     std
  1229.     mov    ax,CRT_TXT_SEG
  1230. ;
  1231.     push    ds
  1232. ;
  1233.     push    cx
  1234.     push    di
  1235.     push    si
  1236.     mov    ds,ax
  1237.     mov    es,ax
  1238.     std
  1239.     rep    movsb
  1240.     pop    si
  1241.     pop    di
  1242.     pop    cx
  1243.     add    si,2000h
  1244.     add    di,2000h
  1245.     rep    movsb
  1246. ;
  1247.     pop    ds
  1248.     cld
  1249. ;
  1250.     mov    di,vram_line
  1251.     mov    si,0
  1252.     mov    ax,CRT_TXT_SEG
  1253.     mov    es,ax
  1254.     mov    ax,vt_rollcur
  1255. ;
  1256.     push    ds
  1257. ;
  1258.     mov    ds,ax
  1259.     mov    cx,80
  1260.     push    di
  1261.     rep    movsw
  1262.     pop    di
  1263.     add    di,2000h
  1264.     mov    cx,80
  1265.     rep    movsw
  1266. ;
  1267.     pop    ds
  1268. ;
  1269.     inc    vt_rollnum
  1270.     pop    cx            ; restore line counter
  1271.     dec    cx
  1272.     jmp    vt100_rupn_1
  1273. ;
  1274. vt100_rupn_ex:
  1275.     pop    es
  1276.     pop    di
  1277.     pop    si
  1278.     pop    dx
  1279.     pop    ax
  1280.     ret
  1281. VT100_RUPN    endp
  1282.  
  1283. VT100_RDNN    proc    near
  1284. ;
  1285. ; roll-down n lines (n is given in CX).
  1286. ; CX will be broken when return.
  1287. ; 1) copy the top of the screen to the current save area
  1288. ; 2) increment the save area pointer
  1289. ; 3) screen scroll up one line
  1290. ; 4) copy the current save area to the bottom of the screen
  1291. ; 5) decrement the number of moved lines
  1292. ;
  1293.     push    ax
  1294.     push    dx
  1295.     push    si
  1296.     push    di
  1297.     push    es
  1298. ;
  1299. vt100_rdnn_1:
  1300.     cmp    cx,0
  1301.     jg    vt100_rdnn_2
  1302.     jmp    vt100_rdnn_ex
  1303. vt100_rdnn_2:
  1304.     mov    ax,vt_rollnum
  1305.     cmp    ax,0
  1306.     jg    vt100_rdnn_3
  1307.     jmp    vt100_rdnn_ex
  1308. ;
  1309. vt100_rdnn_3:
  1310.     push    cx            ; save line counter
  1311.     mov    ax,vt_rollcur
  1312.     mov    es,ax
  1313.     mov    di,0
  1314. ;
  1315.     push    ds
  1316. ;
  1317.     mov    ax,CRT_TXT_SEG
  1318.     mov    si,vram_line
  1319.     push    si
  1320.     mov    cx,80
  1321.     mov    ds,ax
  1322.     cld
  1323.     rep    movsw
  1324.     pop    si
  1325.     add    si,2000h        ; attribute area
  1326.     mov    cx,80
  1327.     rep    movsw            ; save attributes
  1328. ;
  1329.     pop    ds
  1330. ;  increment save-area pointer
  1331.     mov    cx,20            ; one line (display + attributes)
  1332.     inc    vt_rollcln
  1333.     add    vt_rollcur,cx
  1334.     mov    ax,vt_rollcln
  1335.     cmp    ax,vt_rollmxl
  1336.     jl    vt100_rdnn_4
  1337.     mov    vt_rollcln,0
  1338.     mov    ax,vt_rollseg
  1339.     mov    vt_rollcur,ax
  1340. vt100_rdnn_4:
  1341. ;
  1342.     mov    cx,vram_botm_line
  1343.     sub    cx,vram_line
  1344.     mov    di,vram_line
  1345.     mov    si,di
  1346.     add    si,160
  1347.     mov    ax,CRT_TXT_SEG
  1348. ;
  1349.     push    ds
  1350. ;
  1351.     push    cx
  1352.     push    di
  1353.     push    si
  1354.     mov    ds,ax
  1355.     mov    es,ax
  1356.     rep    movsb
  1357.     pop    si
  1358.     pop    di
  1359.     pop    cx
  1360.     add    si,2000h
  1361.     add    di,2000h
  1362.     rep    movsb
  1363. ;
  1364.     pop    ds
  1365. ;
  1366.     mov    di,vram_botm_line
  1367.     mov    si,0
  1368.     mov    ax,CRT_TXT_SEG
  1369.     mov    es,ax
  1370.     mov    ax,vt_rollcur
  1371. ;
  1372.     push    ds
  1373. ;
  1374.     mov    ds,ax
  1375.     mov    cx,80
  1376.     push    di
  1377.     rep    movsw
  1378.     pop    di
  1379.     add    di,2000h
  1380.     mov    cx,80
  1381.     rep    movsw
  1382. ;
  1383.     pop    ds
  1384. ;
  1385.     dec    vt_rollnum
  1386.     pop    cx            ; restore line counter
  1387.     dec    cx
  1388.     jmp    vt100_rdnn_1
  1389. ;
  1390. vt100_rdnn_ex:
  1391.     pop    es
  1392.     pop    di
  1393.     pop    si
  1394.     pop    dx
  1395.     pop    ax
  1396.     ret
  1397. VT100_RDNN    endp
  1398.  
  1399. scrn_mode    proc    near
  1400. ;
  1401. ; set screen mode to normal(AL=0)/reverse(AL=1)
  1402. ; [NOTE]
  1403. ;    registers AX and BX are broken when return
  1404. ;
  1405.     push    cx
  1406.     push    di
  1407.     push    es
  1408. ;
  1409.     mov    bx,ax
  1410.     mov    ax,CRT_TXT_SEG
  1411.     mov    es,ax
  1412.     mov    di,vram_line
  1413.     add    di,2000h
  1414.     mov    cx,1920            ; 1920 = 80 x 24
  1415.     cmp    bl,0
  1416.     je    scrn_mode0
  1417. scrn_mode1:
  1418. ;  light background dark text.
  1419.     test    vt_nrmatr,CHR_REV
  1420.     jz    scrn_mode1L
  1421.     jmp    scrn_mode3
  1422. scrn_mode1L:
  1423.     xor    BYTE PTR es:[di],CHR_REV
  1424.     add    di,2
  1425.     loop    scrn_mode1L
  1426.     or    vt_nrmatr,CHR_REV
  1427.     or    vt_chratr,CHR_REV
  1428.     or    vt_blkatr,CHR_REV
  1429.     jmp    scrn_mode3
  1430. scrn_mode0:
  1431. ;  dark background light text.
  1432.     test    vt_nrmatr,CHR_REV
  1433.     jnz    scrn_mode0L
  1434.     jmp    scrn_mode3
  1435. scrn_mode0L:
  1436.     xor    BYTE PTR es:[di],CHR_REV
  1437.     add    di,2
  1438.     loop    scrn_mode0L
  1439.     and    vt_nrmatr,NOT CHR_REV
  1440.     and    vt_chratr,NOT CHR_REV
  1441.     and    vt_blkatr,NOT CHR_REV
  1442. scrn_mode3:
  1443.     pop    es
  1444.     pop    di
  1445.     pop    cx
  1446.     ret
  1447. scrn_mode    endp
  1448.  
  1449.  
  1450. locate_cur    proc    near
  1451. ;
  1452. ; locate cursor at (cur_row,cur_col)
  1453. ;
  1454. ; [NOTE]
  1455. ;    Registers ax, bx and dx are to be broken when return.
  1456. ;
  1457.  
  1458.     mov    dh,cur_row
  1459.     mov    dl,cur_col
  1460.     call    move_cur
  1461.     mov    vt_wrap,0        ; new position clears wrap req. flag
  1462.     ret
  1463. locate_cur    endp
  1464. ;
  1465. move_cur    proc    near
  1466. ;
  1467. ;  Move cursor at (dh:row,dl:col)
  1468. ;  Registers ax, bx and dx are broken when return.
  1469. ;
  1470.     call    vram_ofs        ; get VRAM address in BX
  1471.     shr    bx,1
  1472.     cli
  1473. move_cur1:
  1474.     in    al,60h
  1475.     test    al,04h            ; test GDC status
  1476.     jz    move_cur1        ; z=not ready
  1477.     mov    al,49h
  1478.     out    62h,al
  1479.     mov    al,bl
  1480.     out    60h,al
  1481.     mov    al,bh
  1482.     out    60h,al
  1483.     sti
  1484.     ret
  1485. move_cur    endp
  1486. ;
  1487. disp_char    proc    near
  1488. ;
  1489. ; Display character in AX on the screen.
  1490. ; Cursor moves to the next character position.
  1491. ; AX:will be broken when return.
  1492. ;
  1493.     cmp    ax,00060h        ; backquote special treatment
  1494.     jne    disp_char_mod1
  1495.     mov    ax,06009h        ; for backquote
  1496.     jmp    disp_char_modx
  1497. disp_char_mod1:
  1498. ;@@    cmp    ax,0005Ch        ; backslash
  1499. ;@@    jne    disp_char_mod2
  1500. ;@@    mov    ax,000EFh
  1501. disp_char_mod2:
  1502. disp_char_modx:
  1503. ;
  1504.     push    es            ; save segment reg.
  1505.     mov    dx,CRT_TXT_SEG        ; set vram segment address
  1506.     mov    es,dx
  1507.     cmp    vt_wrap,0        ; wrap requested ?
  1508.     je    disp_char_nowrap    ; e = no.
  1509. ;
  1510.     mov    cur_col,0        ; return to left margin
  1511.     mov    bl,cur_row
  1512.     cmp    bl,vt_bottom        ; exceed bottom margin ?
  1513.     jl    disp_char_wrap1        ; l = No.
  1514.     je    disp_char_wrap2
  1515.     inc    cur_row
  1516.     mov    bl,cur_row
  1517.     cmp    bl,vt_phys_bottom
  1518.     jle    disp_char_nowrap
  1519.     mov    bl,vt_phys_bottom
  1520.     mov    cur_row,bl
  1521.     jmp    disp_char_nowrap
  1522. disp_char_wrap1:
  1523.     inc    cur_row
  1524.     jmp    disp_char_nowrap
  1525. disp_char_wrap2:
  1526.     push    ax
  1527.     mov    al,vt_top
  1528.     mov    ah,vt_bottom
  1529.     mov    cx,1
  1530.     call    scroll_up
  1531.     pop    ax
  1532. disp_char_nowrap:
  1533.     mov    dh,cur_row        ; get current cursor position
  1534.     mov    dl,cur_col
  1535.     call    vram_ofs        ; get vram offset address in bx
  1536.     mov    di,bx            ; set destination
  1537.     test    vt100_flags,INSERT_BIT    ; insert mode ?
  1538.     jz    disp_char_noins        ; z = no
  1539.     cmp    cur_col,79        ; at left margin ?
  1540.     jge    disp_char_noins        ; ge = Yes. No characters shifted
  1541.     mov    cx,79
  1542.     sub    cl,cur_col        ; get num. of chars. to be shifted
  1543.     mov    dh,cur_row
  1544.     mov    dl,79
  1545.     call    vram_ofs        ; get destination offset address
  1546.     mov    di,bx            ; set destination reg
  1547.     mov    si,bx
  1548.     sub    si,2            ; source offset address
  1549.     push    ds            ; save data-seg. reg.
  1550.     mov    dx,CRT_TXT_SEG
  1551.     mov    ds,dx
  1552.     std                ; inverse direction
  1553.     rep    movsw            ; shift the characters
  1554.     cld                ; reset direction flag
  1555.     pop    ds            ; restore data-seg. reg.
  1556. disp_char_noins:
  1557.     mov    es:[di],ax        ; put the character
  1558.     xor    ah,ah            ; clear higher bit
  1559.     mov    al,vt_chratr        ; load attribute
  1560.     add    di,02000h        ; attribute offset address
  1561.     stosw                ; put attribute and increment address
  1562.     pop    es            ; restore segment
  1563.     inc    cur_col            ; update cursor position
  1564.     mov    al,cur_col
  1565.     cmp    al,79            ; exceed right margin ?
  1566.     jbe    disp_char_loc        ; be = No.
  1567.     mov    cur_col,79        ; stay at right margin
  1568.     test    vt100_flags,AUTOWRAP_BIT    ; Autowrap enable ?
  1569.     jz    disp_char_ex        ; z = No. NoWrap
  1570.     mov    vt_wrap,1        ; wrap request
  1571.     jmp    disp_char_ex        ; all done.
  1572. disp_char_loc:
  1573.     call    locate_cur
  1574. disp_char_ex:
  1575.     ret
  1576. disp_char    endp
  1577.  
  1578. save_cursor    proc    near
  1579. ; saves
  1580. ; 1) cursor position
  1581.     mov    al,cur_row
  1582.     mov    cur_save_row,al
  1583.     mov    al,cur_col
  1584.     mov    cur_save_col,al
  1585. ; 2) graphic rendition
  1586.     mov    al,vt_graph
  1587.     mov    save_graph,al
  1588.     mov    al,vt_chrset
  1589.     mov    save_chrset,al
  1590.     mov    al,vt_chratr
  1591.     mov    save_chratr,al
  1592.     mov    al,vt_blkatr
  1593.     mov    save_blkatr,al
  1594. ;
  1595.     mov    ax,char_SS
  1596.     mov    char_save_SS,ax
  1597.     mov    ax,char_GL
  1598.     mov    char_save_GL,ax
  1599.     mov    ax,char_GR
  1600.     mov    char_save_GR,ax
  1601. ;
  1602.     mov    al,char_G0
  1603.     mov    char_save_G0,al
  1604.     mov    al,char_G1
  1605.     mov    char_save_G1,al
  1606.     mov    al,char_G2
  1607.     mov    char_save_G2,al
  1608.     mov    al,char_G3
  1609.     mov    char_save_G3,al
  1610. ; 3) state of wrap flag
  1611. ; 4) state of origin mode
  1612.     mov    al,vt100_flags
  1613.     mov    save_flags,al
  1614. ; 5) state of selective erase
  1615.     ret
  1616. save_cursor    endp
  1617.  
  1618. restore_cursor    proc    near
  1619. ; 1) state of selective erase
  1620. ; 2) state of origin mode
  1621.     and    vt100_flags,(not ORIGIN_BIT)
  1622.     mov    al,save_flags
  1623.     and    al,ORIGIN_BIT
  1624.     or    vt100_flags,al
  1625. ; 3) state of wrap flag
  1626.     and    vt100_flags,(not AUTOWRAP_BIT)
  1627.     mov    al,save_flags
  1628.     and    al,AUTOWRAP_BIT
  1629.     or    vt100_flags,al
  1630. ; 4) graphic rendition
  1631.     mov    al,save_graph
  1632.     mov    vt_graph,al
  1633.     mov    al,save_chrset
  1634.     mov    vt_chrset,al
  1635.     mov    al,save_chratr
  1636.     mov    vt_chratr,al
  1637.     mov    al,save_blkatr
  1638.     mov    vt_blkatr,al
  1639. ;
  1640.     mov    ax,char_save_SS
  1641.     mov    char_SS,ax
  1642.     mov    ax,char_save_GL
  1643.     mov    char_GL,ax
  1644.     mov    ax,char_save_GR
  1645.     mov    char_GR,ax
  1646. ;
  1647.     mov    al,char_save_G0
  1648.     mov    char_G0,al
  1649.     mov    al,char_save_G1
  1650.     mov    char_G1,al
  1651.     mov    al,char_save_G2
  1652.     mov    char_G2,al
  1653.     mov    al,char_save_G3
  1654.     mov    char_G3,al
  1655. ; 5) cursor position
  1656.     mov    al,cur_save_row
  1657.     mov    cur_row,al
  1658.     mov    al,cur_save_col
  1659.     mov    cur_col,al
  1660.     call    locate_cur
  1661.     ret
  1662. restore_cursor    endp
  1663.  
  1664. vt_dump    proc    near
  1665. ;
  1666. ; copy the one line image from es:[si] to dump buffer.
  1667. ; input
  1668. ;   ES:SI
  1669. ; outputs
  1670. ;   CX        contains number of characters.
  1671. ;   ES:SI    will be updated (points to the next line).
  1672. ;
  1673.     push    ax
  1674.     push    di
  1675. ;
  1676.     mov    dump_mode,0
  1677.     mov    di,offset dump_buffer
  1678.     mov    dump_pntr,di
  1679.     mov    cx,80
  1680. ;
  1681. vt_dump1:
  1682.     mov    ax,es:[si]
  1683.     cmp    ah,0            ; 1 byte code ?
  1684.     je    vt_dump3        ; e = yes.
  1685.     cmp    al,09h            ; ANK ?
  1686.     jne    vt_dump11        ; ne = no.
  1687.     mov    al,ah
  1688.     mov    ah,0
  1689.     jmp    vt_dump3
  1690. vt_dump11:
  1691.     cmp    dump_mode,0
  1692.     je    vt_dump12
  1693.     mov    byte ptr [di],ESCAPE
  1694.     mov    word ptr [di+1],'0)'
  1695.     add    di,3
  1696.     mov    dump_pntr,di
  1697.     mov    dump_mode,0
  1698. vt_dump12:
  1699.     add    ax,20h            ; convert to jis
  1700.     and    ax,7F7Fh        ; mask 8th bit
  1701.     call    jis2s            ; convert to shift jis
  1702.     mov    [di],al
  1703.     mov    [di+1],ah
  1704.     add    di,2
  1705.     add    si,4
  1706.     dec    cx
  1707.     mov    dump_pntr,di
  1708.     jmp    vt_dump2
  1709. vt_dump3:
  1710. ; check graphic code. It is overrap over the shift-JIS kanji code.
  1711. ; In that case, we should put the ESC seq to change the character set.
  1712.     cmp    al,80h
  1713.     jbe    vt_dump6
  1714.     cmp    al,0FCh
  1715.     ja    vt_dump6
  1716.     cmp    al,09Fh
  1717.     jbe    vt_dump5
  1718.     cmp    al,0E0h
  1719.     jb    vt_dump6
  1720. vt_dump5:
  1721.     cmp    dump_mode,0
  1722.     jne    vt_dump4
  1723.     mov    byte ptr [di],ESCAPE
  1724.     mov    word ptr [di+1],'3)'
  1725.     add    di,3
  1726.     mov    dump_pntr,di
  1727.     mov    dump_mode,1
  1728.     jmp    vt_dump4
  1729. vt_dump6:
  1730.     cmp    dump_mode,0
  1731.     je    vt_dump4
  1732.     mov    byte ptr [di],ESCAPE
  1733.     mov    word ptr [di+1],'0)'
  1734.     add    di,3
  1735.     mov    dump_pntr,di
  1736.     mov    dump_mode,0
  1737. vt_dump4:
  1738.     mov    [di],al            ; remove Kanji flag etc in ah.
  1739.     inc    di
  1740.     add    si,2
  1741.     cmp    al,' '            ; Is it blank ?
  1742.     je    vt_dump2        ; e = yes.
  1743.     mov    dump_pntr,di
  1744. vt_dump2:
  1745.     dec    cx
  1746.     jcxz    vt_dump7
  1747.     jmp    vt_dump1
  1748. ;
  1749. vt_dump7:
  1750.     mov    di,dump_pntr
  1751.     cmp    dump_mode,0
  1752.     je    vt_dump8
  1753.     mov    byte ptr [di],ESCAPE
  1754.     mov    word ptr [di+1],'0)'
  1755.     add    di,3
  1756. vt_dump8:
  1757.     mov    ax,0A0Dh        ; add CR/LF
  1758.     mov    [di],ax
  1759.     add    di,2
  1760.     mov    cx,di
  1761.     sub    cx,offset dump_buffer
  1762. ;
  1763.     pop    di
  1764.     pop    ax
  1765.     ret
  1766. vt_dump    endp
  1767.  
  1768.  
  1769. vt_prn    proc    near
  1770. ;
  1771. ; copy the one line image from es:[si] to dump buffer as a printer
  1772. ; image.
  1773. ;
  1774. ; input
  1775. ;   ES:SI
  1776. ; outputs
  1777. ;   CX        contains number of characters.
  1778. ;   ES:SI    will be updated (points to the next line).
  1779. ;
  1780.     push    ax
  1781.     push    di
  1782. ;
  1783.     mov    dump_mode,0
  1784.     mov    di,offset dump_buffer
  1785.     mov    dump_pntr,di
  1786.     mov    cx,80
  1787. ;
  1788. vt_prn1:
  1789.     mov    ax,es:[si]
  1790.     cmp    ah,0            ; 1 byte code ?
  1791.     je    vt_prn3            ; e = yes.
  1792. vt_prn11:
  1793.     cmp    dump_mode,0        ; in 2 byte mode ?
  1794.     jne    vt_prn12        ; ne = yes.
  1795.     mov    byte ptr [di],ESCAPE
  1796.     mov    byte ptr [di+1],'K'    ; Kanji mode.
  1797.     add    di,2
  1798.     mov    dump_pntr,di
  1799.     mov    dump_mode,1
  1800. vt_prn12:
  1801.     add    ax,20h            ; convert to jis
  1802.     and    ax,7F7Fh        ; mask 8th bit
  1803.     mov    [di],al
  1804.     mov    [di+1],ah
  1805.     add    di,2
  1806.     add    si,4
  1807.     dec    cx
  1808.     mov    dump_pntr,di
  1809.     jmp    vt_prn2
  1810. vt_prn3:
  1811.     cmp    dump_mode,0        ; in 1 byte mode ?
  1812.     je    vt_prn4            ; e = yes.
  1813.     mov    byte ptr [di],ESCAPE
  1814.     mov    byte ptr [di+1],'H'    ; High density pica mode.
  1815.     add    di,2
  1816.     mov    dump_pntr,di
  1817.     mov    dump_mode,0
  1818. vt_prn4:
  1819.     mov    [di],al            ; remove Kanji flag etc in ah.
  1820.     inc    di
  1821.     add    si,2
  1822.     cmp    al,' '            ; Is it blank ?
  1823.     je    vt_prn2            ; e = yes.
  1824.     mov    dump_pntr,di
  1825. vt_prn2:
  1826.     dec    cx
  1827.     jcxz    vt_prn7
  1828.     jmp    vt_prn1
  1829. ;
  1830. vt_prn7:
  1831.     mov    di,dump_pntr
  1832.     cmp    dump_mode,0
  1833.     je    vt_prn8
  1834.     mov    byte ptr [di],ESCAPE
  1835.     mov    byte ptr [di+1],'H'
  1836.     add    di,2
  1837. vt_prn8:
  1838.     mov    ax,0A0Dh        ; add CR/LF
  1839.     mov    [di],ax
  1840.     add    di,2
  1841.     mov    cx,di
  1842.     sub    cx,offset dump_buffer
  1843. ;
  1844.     pop    di
  1845.     pop    ax
  1846.     ret
  1847. vt_prn    endp
  1848.  
  1849. vt_bell    proc    near
  1850.     push    ax
  1851.     push    cx
  1852. ;
  1853.     mov    al,06h
  1854.     out    37h,al
  1855.     mov    cx,0D000h
  1856. vt_bell1:
  1857.     loop    vt_bell1
  1858.     mov    al,07h
  1859.     out    37h,al
  1860. ;
  1861.     pop    cx
  1862.     pop    ax
  1863. vt_bell    endp
  1864.  
  1865. ;---------------------------
  1866. VT100_DUMP    PROC    NEAR
  1867. ;---------------------------
  1868. ; Dump screen. This procedure dump the VT100 screen on the disk using
  1869. ; MS-DOS function 40H (int 21H).
  1870. ;
  1871. ; Inputs
  1872. ;   BX    file handle
  1873. ;
  1874. ; Outputs
  1875. ;   None
  1876. ;
  1877.     push    cx
  1878.     push    dx
  1879.     push    es
  1880.     push    si
  1881.     push    di
  1882.  
  1883.     mov    ax,CRT_TXT_SEG
  1884.     mov    es,ax
  1885.     mov    si,vram_line
  1886.     mov    cx,24
  1887. vt100_dump0:
  1888.     push    cx
  1889.     call    vt_dump
  1890.     mov    ah,WRITE2        ; write function
  1891.     mov    dx,offset dump_buffer
  1892.     int    DOS
  1893. ;
  1894.     pop    cx
  1895.     loop    vt100_dump0
  1896. ;
  1897.     pop    di
  1898.     pop    si
  1899.     pop    es
  1900.     pop    dx
  1901.     pop    cx
  1902.     ret
  1903. VT100_DUMP    ENDP
  1904.  
  1905. ;------------------------------------------------------------------------------
  1906. VT100_PRNC    PROC    NEAR
  1907. ;
  1908. ;  Printer control (Transparent printing).
  1909. ;  - Watches the control seunce CSI 4 i (turns off printer controller mode).
  1910. ;    If this sequence is found, control returns to normal terminal mode.
  1911. ;  - Until CSI 4 i sequnce is found, all the received characters are sent to
  1912. ;    the printer without displaying them on the screen except NUL, XON, XOFF,
  1913. ;    CSI 5 i and CSI 4 i.
  1914. ;
  1915.     mov    di,offset watch_buf    ; get buffer pointer
  1916.     add    di,watch_pnd        ; adjust pointer
  1917.     mov    [di],al            ; save the character
  1918.     inc    watch_pnd        ; increment the pointer
  1919. ;
  1920.     cmp    watch_lvl,0        ; normal sequnce ?
  1921.     jne    vt100_prnc_n0        ; ne = no.
  1922.     jmp    vt100_prnc_L0
  1923. vt100_prnc_n0:
  1924.     cmp    watch_lvl,1        ; next ESC ?
  1925.     jne    vt100_prnc_n1        ; ne = no.
  1926.     jmp    vt100_prnc_L1
  1927. vt100_prnc_n1:
  1928.     cmp    watch_lvl,2        ; after CSI ?
  1929.     jne    vt100_prnc_n2        ; ne = no.
  1930.     jmp    vt100_prnc_L2
  1931. vt100_prnc_n2:
  1932.     cmp    watch_lvl,3        ; final character ?
  1933.     jne    vt100_prnc_n3        ; ne = no.
  1934.     jmp    vt100_prnc_L3
  1935. vt100_prnc_n3:                ; *** if come here, PROGRAM ERROR ***
  1936.     mov    watch_lvl,0
  1937.     mov    watch_pnd,0
  1938.     jmp    vt100_prnc_OUT
  1939. ;
  1940. vt100_prnc_L0:
  1941.     mov    watch_lvl,1        ; assume ESC
  1942.     cmp    al,ESCAPE        ; ESC ?
  1943.     je    vt100_prnc_L0_1        ; e = yes.
  1944.     mov    watch_lvl,2        ; assume CSI
  1945.     cmp    al,CSI            ; CSI ?
  1946.     je    vt100_prnc_L0_1        ; e = yes.
  1947.     jmp    vt100_prnc_OUT
  1948. ;
  1949. vt100_prnc_L0_1:
  1950.     mov    di,offset watch_buf
  1951.     mov    watch_pnd,0
  1952.     mov    [di],al
  1953.     inc    watch_pnd
  1954.     jmp    vt100_prnc_ex
  1955. ;
  1956. vt100_prnc_L1:
  1957.     cmp    al,'['
  1958.     je    vt100_prnc_L1_1
  1959.     jmp    vt100_prnc_OUT
  1960. vt100_prnc_L1_1:
  1961.     mov    watch_lvl,2
  1962.     jmp    vt100_prnc_ex
  1963. ;
  1964. vt100_prnc_L2:
  1965.     mov    watch_mod,al
  1966.     cmp    al,'5'
  1967.     je    vt100_prnc_L2_1
  1968.     cmp    al,'4'
  1969.     je    vt100_prnc_L2_1
  1970.     jmp    vt100_prnc_OUT
  1971. vt100_prnc_L2_1:
  1972.     mov    watch_lvl,3
  1973.     jmp    vt100_prnc_ex
  1974. ;
  1975. vt100_prnc_L3:
  1976.     cmp    al,'i'
  1977.     jne    vt100_prnc_OUT
  1978.     mov    watch_pnd,0        ; clear pending buffer
  1979.     cmp    watch_mod,'4'        ; off the printer control ?
  1980.     jne    vt100_prnc_L3_1        ; ne = no.
  1981.     and    vt100_pflag,(not PRINTCTRL_BIT)
  1982. vt100_prnc_L3_1:
  1983.     jmp    vt100_prnc_ex
  1984. ;
  1985. vt100_prnc_OUT:
  1986.     mov    di,offset watch_buf
  1987.     mov    cx,watch_pnd
  1988. vt100_prnc_OUT1:
  1989.     mov    ah,LSTOUT
  1990.     mov    dl,[di]
  1991.     int    DOS
  1992.     jc    vt100_prnc_OUT2
  1993.     inc    di
  1994.     loop    vt100_prnc_OUT1
  1995.     mov    watch_pnd,0
  1996.     jmp    vt100_prnc_ex
  1997. ;
  1998. vt100_prnc_OUT2:
  1999.     call    vt_bell
  2000.     and    vt100_pflag,(not (AUTOPRINT_BIT+PRINTCTRL_BIT))
  2001.     mov    watch_pnd,0
  2002. ;
  2003. vt100_prnc_ex:
  2004.     xor    ah,ah
  2005.     xor    cx,cx
  2006.     ret
  2007. VT100_PRNC    ENDP
  2008.  
  2009. ;------------------------------------------------------------------------------
  2010. VT100_PRNL    PROC    NEAR
  2011. ;
  2012. ;  Print the current line on the printer
  2013. ;
  2014.     push    dx
  2015. ;
  2016.     push    bx
  2017.     mov    dh,cur_row
  2018.     mov    dl,0
  2019.     call    vram_ofs
  2020.     mov    si,bx
  2021.     pop    bx
  2022. ;
  2023.     push    es
  2024.     mov    ax,CRT_TXT_SEG
  2025.     mov    es,ax
  2026.     call    vt_prn
  2027.     pop    es
  2028. ;
  2029.     mov    di,offset dump_buffer
  2030. vt100_prnl1:
  2031.     mov    al,[di]
  2032.     call    pntchr
  2033.     jc    vt100_prnl2
  2034.     inc    di
  2035.     loop    vt100_prnl1
  2036.     jmp    vt100_prnl3
  2037. ;
  2038. vt100_prnl2:
  2039.     call    vt_bell
  2040.     and    vt100_pflag,(not (AUTOPRINT_BIT+PRINTCTRL_BIT))
  2041. ;
  2042. vt100_prnl3:
  2043. ;
  2044.     pop    dx
  2045.     ret
  2046. VT100_PRNL    ENDP
  2047.  
  2048. ;------------------------------------------------------------------------------
  2049. VT100_PRNS    PROC    NEAR
  2050. ;
  2051. ;  Print the current screen on the printer.
  2052. ;  Similar to dump.
  2053. ;
  2054.     push    cx
  2055.     push    dx
  2056.     push    es
  2057.     push    si
  2058.     push    di
  2059. ;
  2060.     test    vt100_pflag,AUTOPRINT_BIT    ; printer off?
  2061.     jnz    vt100_prns1        ; nz = no not. it is on.
  2062.     call    prn_chk            ; check the printer port
  2063.     jnc    vt100_prns1        ; nc = ready.
  2064.     jmp    vt100_prns5
  2065. ;
  2066. vt100_prns1:
  2067.     mov    ax,CRT_TXT_SEG
  2068.     mov    es,ax
  2069.     mov    si,vram_line
  2070.     mov    cx,24
  2071.     test    vt100_pflag,PRINTEXT_BIT    ; full screen printing?
  2072.     jnz    vt100_prns2        ; nz = yes.
  2073.     mov    al,vt_top        ; determine start address
  2074.     xor    ah,ah
  2075.     mov    cx,ax
  2076.     shl    ax,1
  2077.     mov    si,offset vram_line
  2078.     add    si,ax
  2079.     mov    si,[si]
  2080.     mov    al,vt_bottom
  2081.     xor    ah,ah
  2082.     xchg    ax,cx
  2083.     sub    cx,ax
  2084.     inc    cx
  2085. vt100_prns2:
  2086.     push    cx
  2087.     call    vt_prn
  2088.     mov    di,offset dump_buffer
  2089. ;
  2090. vt100_prns3:
  2091.     mov    al,[di]
  2092.     call    pntchr
  2093.     jc    vt100_prns4
  2094.     inc    di
  2095.     loop    vt100_prns3
  2096. ;
  2097.     pop    cx
  2098.     loop    vt100_prns2
  2099. ;
  2100.     test    vt100_pflag,PRINTFF_BIT    ; must print FF ?
  2101.     jz    vt100_prns5    ; z = no.
  2102.     mov    al,FF
  2103.     call    pntchr
  2104.     jc    vt100_prns4
  2105.     jmp    vt100_prns5
  2106. ;
  2107. vt100_prns4:
  2108.     call    vt_bell
  2109.     and    vt100_pflag,(not (AUTOPRINT_BIT+PRINTCTRL_BIT))
  2110. ;
  2111. vt100_prns5:
  2112.     pop    di
  2113.     pop    si
  2114.     pop    es
  2115.     pop    dx
  2116.     pop    cx
  2117.     ret
  2118. VT100_PRNS    ENDP
  2119.  
  2120. ;------------------------------------------------------------------------------
  2121. VT100        PROC    NEAR
  2122. ;
  2123. ;  The main program for VT100 emulator
  2124. ;  Inputs:
  2125. ;       AL  character code
  2126. ;  Outputs:
  2127. ;       AH  results
  2128. ;           0:Normal, in this case,
  2129. ;       CX  number of characters to be sent to communication port
  2130. ;    DS:SI  character string to be sent
  2131. ;
  2132. ;       AH  non zero means 'change to the tek4010 emulation mode'
  2133. ;           1:only change the mode. do not pass any character.
  2134. ;           2:change the mode and send the character in AL.
  2135. ;           3:change the mode and send the characters in DH and DL.
  2136. ;       DX  character pair to be sent to tek4010 emulator if AH=3.
  2137. ;    
  2138. ;------------------------------------------------------------------------------
  2139. ;
  2140. ; Character display routine in VT-100 mode
  2141. ;
  2142. vt_disp:
  2143.     mov    vt_rollnum,0
  2144. ;
  2145.     cmp    spec_mode,0        ; in special mode ?
  2146.     je    vt_disp_NRM        ; e = No. go to normal process.
  2147.     cmp    spec_mode,IN_ESC_MODE    ; in ESC sequence ?
  2148.     jne    vt_disp_01        ; ne = No. check other sequnce.
  2149.     jmp    vt_disp_inESC        ; go to ESC sequence procedure.
  2150. vt_disp_01:
  2151.     cmp    spec_mode,IN_CSI_MODE    ; in CSI sequence ?
  2152.     jne    vt_disp_02        ; ne = No. check other sequnce.
  2153.     jmp    vt_disp_inCSI        ; go to CSI sequence procedure.
  2154. vt_disp_02:
  2155.     cmp    spec_mode,IN_DCS_MODE    ; in DCS sequence ?
  2156.     jne    vt_disp_03        ; ne = No.
  2157.     jmp    vt_disp_inDCS        ; go to DCS sequence procedure.
  2158. vt_disp_03:
  2159.     mov    spec_mode,0        ; May be my program error. treate as
  2160.                     ; normal character.
  2161. ;
  2162. vt_disp_NRM:
  2163.     cmp    al,080h            ; C0/GL character ?
  2164.     jae    vt_disp_C1GR        ; ae = No.
  2165. ;
  2166. ; C0/D0 character
  2167. ;
  2168.     cmp    al,020h            ; C0 code ?
  2169.     jae    vt_disp_GL        ; ae = No. This is GL code.
  2170.     jmp    vt_disp_C0        ; do C0 control.
  2171. vt_disp_GL:
  2172.     cmp    al,07Fh            ; DEL code ?
  2173.     je    vt_disp_ex        ; e = Yes. Ignore this character.
  2174.     cmp    char_SS,0        ; single shift in progress ?
  2175.     je    vt_disp_GL2        ; e = No.
  2176.     mov    bx,char_SS        ; single shift
  2177.     jmp    disp_out        ; display character
  2178. vt_disp_GL2:
  2179.     mov    bx,char_GL        ; GL character
  2180.     jmp    disp_out        ; display character
  2181. vt_disp_ex:
  2182.     mov    ah,0            ; continue vt emulation
  2183.     mov    cx,0
  2184.     ret
  2185. ;
  2186. ; C1/GR character
  2187. ;
  2188. vt_disp_C1GR:
  2189.     cmp    al,0A0h            ; C1 code ?
  2190.     jae    vt_disp_GR        ; ae = No. This is GR code
  2191.     jmp    vt_disp_C1        ; do C1 control
  2192. vt_disp_GR:
  2193.     cmp    al,0FFh            ; 8 bit DEL code ?
  2194.     je    vt_disp_ex        ; e = Yes. Ignore this character
  2195.     and    al,07Fh
  2196.     cmp    char_SS,0        ; Single shift in progress ?
  2197.     je    vt_disp_GR2        ; e = No.
  2198.     mov    bx,char_SS        ; set single shift
  2199.     jmp    disp_out
  2200. vt_disp_GR2:
  2201.     mov    bx,char_GR        ; GR character
  2202. ;-----------------------------------
  2203. ; Display the character code.
  2204. ; Inputs:
  2205. ;   AL: Character code
  2206. ;   BX: Address of the character set
  2207. ;-----------------------------------
  2208. disp_out:
  2209.     cmp    vt_knjmode,0        ; multi-byte code in progress ?
  2210.     jne    disp_Kanji        ; ne = Yes.
  2211.     jmp    disp_out0        ; 1st byte character code.
  2212. ;
  2213. disp_Kanji:
  2214.     mov    vt_kanji2,al        ; save Kanji 2nd byte
  2215. ;
  2216. ;       test logging
  2217. ;
  2218.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT) ; log enabled and cooked
  2219.     jne    disp_Kanji_1            ; ne = No.
  2220.     mov    ah,vt_kanji2
  2221.     mov    al,vt_kanji1
  2222.     call    jis2s            ; convert to shift JIS
  2223.     call    outcapt                 ; log 1st byte
  2224.     xchg    ah,al
  2225.     call    outcapt            ; log 2nd byte
  2226. disp_Kanji_1:
  2227. ;
  2228. ;       Display Kanji
  2229. ;
  2230.     mov    ah,vt_kanji2        ; restore Kanji 2nd byte
  2231.     mov    al,vt_kanji1        ; restore Kanji 1st byte
  2232.     sub    ax,020h
  2233.     push    ax
  2234.     call    disp_char
  2235.     pop    ax
  2236.     or    ax,8000h
  2237.     call    disp_char
  2238.     mov    vt_knjmode,0
  2239.     mov    char_SS,0        ; reset single shift
  2240.     jmp    vt_disp_ex
  2241. ;
  2242. disp_out0:
  2243.     mov    ah,[bx]            ; Get character set number
  2244.     mov    vt_graph,ah
  2245.     xor    ah,ah
  2246.     cmp    vt_graph,CSET_JISROMAN    ; JIS roman character set ?
  2247.     jne    disp_out1
  2248.     jmp    disp_outit
  2249. disp_out1:
  2250.     cmp    vt_graph,CSET_DECGRAPH    ; DEC special graphics character set ?
  2251.     jne    disp_out2
  2252.     jmp    disp_DECGRAPH
  2253. disp_out2:
  2254.     cmp    vt_graph,CSET_JISC6226    ; JIS 2-byte Kanji code ?
  2255.     jne    disp_out3
  2256.     jmp    disp_JISC6226
  2257. disp_out3:
  2258.     cmp    vt_graph,CSET_JISKATAKANA
  2259.     jne    disp_out4
  2260.     jmp    disp_JISKATAKANA
  2261. disp_out4:
  2262.     jmp    disp_outit
  2263. ;---------------------------------------
  2264. disp_DECGRAPH:
  2265.     cmp    ax,060h
  2266.     jge    disp_DECGRAPH1
  2267.     jmp    disp_outit
  2268. disp_DECGRAPH1:
  2269.     sub    ax,060h
  2270.     mov    bx,offset vt_gset
  2271.     add    bx,ax
  2272.     mov    al,[bx]
  2273.     jmp    disp_outit
  2274. disp_JISC6226:
  2275.     mov    vt_kanji1,al
  2276.     mov    vt_knjmode,1
  2277.     jmp    vt_disp_ex
  2278. disp_JISKATAKANA:
  2279.     or    al,080h
  2280. disp_outit:
  2281.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  2282.     jne    disp_outit_1
  2283.     call    outcapt
  2284. disp_outit_1:
  2285.     call    disp_char
  2286.     mov    char_SS,0        ; reset single shift
  2287.     jmp    vt_disp_ex
  2288. ;
  2289. ;-------------------------------------------------
  2290. ; C0 control characters
  2291. ; Note that only CAN and SUB clear ESC, CSI stage.
  2292. ;-------------------------------------------------
  2293. vt_disp_C0:
  2294.     push    ax
  2295.     mov    bx,offset C0_func_tab    ; jump table address
  2296.     xor    ah,ah
  2297.     shl    ax,1
  2298.     add    bx,ax
  2299.     pop    ax
  2300.     jmp    [bx]
  2301. ;
  2302. ; No action
  2303. ;
  2304. vt_disp_none:
  2305.     jmp    vt_disp_ex
  2306. ;
  2307. ; BEL
  2308. ;
  2309. vt_disp_BEL:
  2310.     mov    al,06h
  2311.     out    37h,al
  2312.     mov    cx,0D000h
  2313. bell_loop:
  2314.     loop    bell_loop
  2315.     mov    al,07h
  2316.     out    37h,al
  2317.     jmp    vt_disp_ex
  2318. ;
  2319. ; BS
  2320. ;
  2321. vt_disp_BS:
  2322.     mov    vt_knjmode,0        ; clear multi-byte flag
  2323.     cmp    cur_col,0
  2324.     jg    vt_disp_BS_1
  2325.     jmp    vt_disp_ex
  2326. vt_disp_BS_1:
  2327.     dec    cur_col
  2328.     call    locate_cur
  2329.     jmp    vt_disp_ex
  2330. ;
  2331. ; HT
  2332. ;
  2333. vt_disp_HT:
  2334.     mov    vt_knjmode,0        ; clear multi-byte flag
  2335.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  2336.     jne    vt_disp_HT0
  2337.     call    outcapt
  2338. vt_disp_HT0:
  2339.     push    bx            ; save BX register
  2340.     mov    bx,offset tabstops    ; set address of tabstops
  2341.     mov    al,cur_col        ; get current cursor position
  2342.     xor    ah,ah            ; clear higher byte
  2343.     add    bx,ax            ; tab table pointer
  2344. vt_disp_HT1:
  2345.     cmp    al,79            ; right margin ?
  2346.     jge    vt_disp_HT2        ; ge = Yes. do not move any more
  2347.     inc    al            ; move position
  2348.     inc    bx            ; update table pointer
  2349.     cmp    byte ptr [bx],0        ; TAB stop position ?
  2350.     je    vt_disp_HT1        ; e = No. increment pointer and cont.
  2351. ;
  2352. vt_disp_HT2:
  2353.     pop    bx
  2354.     mov    cur_col,al        ; save the new cursor position
  2355.     call    locate_cur        ; and move the cursor
  2356.     jmp    vt_disp_ex
  2357. ;
  2358. ; LF
  2359. ;
  2360. vt_disp_LF:
  2361.     mov    vt_knjmode,0        ; clear multi-byte flag
  2362.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  2363.     jne    vt_disp_LF0
  2364.     call    outcapt
  2365. vt_disp_LF0:
  2366.     test    vt100_pflag,AUTOPRINT_BIT    ; auto-print requested ?
  2367.     jz    vt_disp_LF5    ; z = no.
  2368.     call    vt100_prnl    ; print the current line
  2369. vt_disp_LF5:
  2370.     mov    bl,vt_bottom    ; get bottom margin
  2371.     cmp    cur_row,bl
  2372.     jl    vt_disp_LF2    ; above boundary
  2373.     je    vt_disp_LF1    ; on the boundary
  2374.     inc    cur_row
  2375.     mov    bl,vt_phys_bottom
  2376.     cmp    cur_row,bl    ; screen boundary
  2377.     jle    vt_disp_LF3
  2378.     mov    cur_row,bl
  2379.     jmp    vt_disp_LF3
  2380. vt_disp_LF1:
  2381.     mov    cur_row,bl
  2382.     mov    al,vt_top
  2383.     mov    ah,vt_bottom
  2384.     mov    cx,1
  2385.     call    scroll_up
  2386.     jmp    vt_disp_LF3
  2387. vt_disp_LF2:
  2388.     inc    cur_row
  2389. vt_disp_LF3:
  2390.     test    vt100_flags,NEWLINE_BIT    ; newline enabled ?
  2391.     jz    vt_disp_LF4    ; z = no.
  2392.     mov    cur_col,0
  2393. vt_disp_LF4:
  2394.     call    locate_cur
  2395.     jmp    vt_disp_ex
  2396. ;
  2397. ; CR
  2398. ;
  2399. vt_disp_CR:
  2400.     mov    vt_knjmode,0        ; clear multi-byte flag
  2401.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  2402.     jne    vt_disp_CR0
  2403.     call    outcapt
  2404. vt_disp_CR0:
  2405.     mov    cur_col,0
  2406.     call    locate_cur
  2407.     jmp    vt_disp_ex
  2408. ;
  2409. ; SO
  2410. ;
  2411. vt_disp_SO:
  2412.     mov    vt_knjmode,0        ; clear multi-byte flag
  2413.     mov    char_GL,offset char_G1
  2414.     jmp    vt_disp_ex
  2415. ;
  2416. ; SI
  2417. ;
  2418. vt_disp_SI:
  2419.     mov    vt_knjmode,0        ; clear multi-byte flag
  2420.     mov    char_GL,offset char_G0
  2421.     jmp    vt_disp_ex
  2422. ;
  2423. ; CAN
  2424. ;
  2425. vt_disp_CAN:
  2426.     mov    vt_knjmode,0        ; clear multi-byte flag
  2427.     mov    spec_mode,0        ; clear ESC/CSI seq.
  2428.     jmp    vt_disp_ex
  2429. ;
  2430. ; SUB
  2431. ;
  2432. vt_disp_SUB:
  2433.     mov    vt_knjmode,0        ; clear multi-byte flag
  2434.     mov    spec_mode,0        ; clear ESC/CSI seq.
  2435.     mov    ax,001Ah
  2436.     jmp    disp_outit        ; and display it.
  2437. ;
  2438. vt_disp_ESC:
  2439.     mov    vt_knjmode,0        ; clear multi-byte flag
  2440.     mov    spec_mode,in_ESC_MODE    ; enter in ESC mode
  2441.     mov    spec_stage,0        ; show that just entered
  2442.     mov    I_pnt,0
  2443.     mov    bx,offset I_buf
  2444.     mov    word ptr [bx],0
  2445.     jmp    vt_disp_ex
  2446. ;
  2447. ; GS  Enter tektronix mode if tek4010 enabled
  2448. ;
  2449. vt_disp_GS:
  2450.     test    vt100_flags,AUTOTEK_BIT
  2451.     jnz    vt_disp_GS_01
  2452.     jmp    vt_disp_ex
  2453. vt_disp_GS_01:
  2454.     mov    vt_knjmode,0        ; clear multi-byte flag
  2455.     mov    spec_mode,0
  2456.     mov    ah,2            ; pass character in AL
  2457.     mov    cx,0
  2458.     ret
  2459. ;
  2460. ;----------------------
  2461. ; C1 control characters
  2462. ;----------------------
  2463. vt_disp_C1:
  2464.     mov    vt_knjmode,0        ; clear multi-byte flag
  2465.     cmp    al,084h            ; IND
  2466.     jne    vt_disp_C1_n84
  2467.     jmp    vt_C1_IND
  2468. vt_disp_C1_n84:
  2469.     cmp    al,085h            ; NEL
  2470.     jne    vt_disp_C1_n85
  2471.     jmp    vt_C1_NEL
  2472. vt_disp_C1_n85:
  2473.     cmp    al,088h            ; HTS
  2474.     jne    vt_disp_C1_n88
  2475.     jmp    vt_C1_HTS
  2476. vt_disp_C1_n88:
  2477.     cmp    al,08Dh            ; RI
  2478.     jne    vt_disp_C1_n8D
  2479.     jmp    vt_C1_RI
  2480. vt_disp_C1_n8D:
  2481.     cmp    al,08Eh            ; SS2
  2482.     jne    vt_disp_C1_n8E
  2483.     jmp    vt_C1_SS2
  2484. vt_disp_C1_n8E:
  2485.     cmp    al,08Fh            ; SS3
  2486.     jne    vt_disp_C1_n8F
  2487.     jmp    vt_C1_SS3
  2488. vt_disp_C1_n8F:
  2489.     cmp    al,090h            ; DCS
  2490.     jne    vt_disp_C1_n90
  2491.     jmp    vt_C1_DCS
  2492. vt_disp_C1_n90:
  2493.     cmp    al,09Bh            ; CSI
  2494.     jne    vt_disp_C1_n9B
  2495.     jmp    vt_C1_CSI
  2496. vt_disp_C1_n9B:
  2497.     cmp    al,09Ch            ; ST
  2498.     jne    vt_disp_C1_n9C
  2499.     jmp    vt_C1_ST
  2500. vt_disp_C1_n9C:
  2501.     jmp    vt_disp_ex
  2502. ;--------------------------------------------
  2503. vt_disp_vt52ESC:
  2504.     cmp    al,'A'
  2505.     jb    vt_disp_vt52ESC_nD
  2506.     cmp    al,'D'
  2507.     ja    vt_disp_vt52ESC_nD
  2508.     mov    WORD PTR P_buf,1
  2509.     jmp    vt_CSI_ABCD
  2510. vt_disp_vt52ESC_nD:
  2511.     cmp    al,'H'
  2512.     jne    vt_disp_vt52ESC_nH
  2513.     mov    cur_col,0
  2514.     mov    cur_row,0
  2515.     call    locate_cur
  2516.     jmp    vt_esc_done
  2517. vt_disp_vt52ESC_nH:
  2518.     cmp    al,'I'
  2519.     jne    vt_disp_vt52ESC_nI
  2520.     jmp    vt_C1_RI
  2521. vt_disp_vt52ESC_nI:
  2522.     cmp    al,'J'
  2523.     jne    vt_disp_vt52ESC_nJ
  2524.     mov    WORD PTR P_buf,0
  2525.     jmp    vt_CSI_J
  2526. vt_disp_vt52ESC_nJ:
  2527.     cmp    al,'K'
  2528.     jne    vt_disp_vt52ESC_nK
  2529.     mov    WORD PTR P_buf,0
  2530.     jmp    vt_CSI_K
  2531. vt_disp_vt52ESC_nK:
  2532.     cmp    al,'Y'
  2533.     jne    vt_disp_vt52ESC_nY
  2534.     mov    spec_stage,VT52_DCA_L
  2535. vt_disp_vt52ESC_nY:
  2536.     cmp    al,'F'            ; enter graphics mode ?
  2537.     jne    vt_disp_vt52ESC_nF
  2538.     jmp    vt_esc_done
  2539. vt_disp_vt52ESC_nF:
  2540.     cmp    al,'G'            ; leave graphics mode ?
  2541.     jne    vt_disp_vt52ESC_nG
  2542.     jmp    vt_esc_done
  2543. vt_disp_vt52ESC_nG:
  2544.     cmp    al,'W'            ; enter printer control mode ?
  2545.     jne    vt_disp_vt52ESC_nW
  2546.     jmp    vt_esc_done
  2547. vt_disp_vt52ESC_nW:
  2548.     cmp    al,'X'            ; leave printer control mode ?
  2549.     jne    vt_disp_vt52ESC_nX
  2550.     jmp    vt_esc_done
  2551. vt_disp_vt52ESC_nX:
  2552.     cmp    al,'V'            ; print cursor line ?
  2553.     jne    vt_disp_vt52ESC_nV
  2554.     jmp    vt_esc_done
  2555. vt_disp_vt52ESC_nV:
  2556. ;
  2557. ; Non VT52 sequence is interpreted as VT100 sequence.
  2558. ;
  2559.     add    al,040h        ; convert to C1
  2560.     jmp    vt_disp_c1
  2561. ;
  2562. vt_disp_vt52ESC_YL:
  2563.     xor    ah,ah
  2564.     sub    ax,32
  2565.     mov    P_buf,ax
  2566.     mov    spec_stage,VT52_DCA_C
  2567.     jmp    vt_disp_ex
  2568. ;
  2569. vt_disp_vt52ESC_YC:
  2570.     push    ax
  2571.     xor    ah,ah
  2572.     sub    ax,32
  2573.     mov    cur_col,al
  2574.     mov    ax,P_buf
  2575.     mov    cur_row,al
  2576.     call    locate_cur
  2577.     pop    ax
  2578.     jmp    vt_esc_done
  2579. ;------------------------------------------------------------------------------
  2580. ; ESC sequence analysis
  2581. ; Note that VT100 allows many C0 characters in ESC-seq.
  2582.  
  2583. vt_disp_inESC:
  2584.     cmp    al,07Eh            ; check the allowed range
  2585.     ja    vt_disp_inESCe        ; error.
  2586.     cmp    al,020h            ; normal GL character ?
  2587.     jae    vt_disp_inESC1        ; ae = yes.
  2588. ; C0 control character
  2589.     cmp    spec_stage,0        ; 1st character in ESC seq.?
  2590.     je    vt_disp_inESC0        ; e = Yes. Need check ESC FF.
  2591.     jmp    vt_disp_C0
  2592. vt_disp_inESC0:
  2593.     cmp    al,0Ch            ; FF ?
  2594.     je    vt_disp_ESC_FF        ; e = Yes. Need special treatment.
  2595.     jmp    vt_disp_C0
  2596. ;
  2597. ; ESC FF:Enter tektronix mode if tek4010 enabled
  2598. ;
  2599. vt_disp_ESC_FF:
  2600.     test    vt100_flags,AUTOTEK_BIT    ; AutoTek enabled ?
  2601.     jnz    vt_disp_ESC_FF_do    ; nz = Yes.
  2602.     jmp    vt_disp_C0
  2603. vt_disp_ESC_FF_do:
  2604.     mov    spec_mode,0        ; ESC sequnce done. [25-Jun-1990]
  2605.     mov    ah,3            ; pass character in DX
  2606.     mov    dh,ESCAPE
  2607.     mov    dl,al
  2608.     mov    cx,0
  2609.     ret
  2610. ;--------------
  2611. vt_disp_inESC1:
  2612.     cmp    spec_stage,0        ; 1st character in ESC seq.?
  2613.     jne    vt_disp_inESC2        ; ne = no, check the sequnce type
  2614.     jmp    vt_esc_1
  2615. vt_disp_inESC2:
  2616.     cmp    spec_stage,1        ; ESC with I sequence ?
  2617.     jne    vt_disp_inESC3
  2618.     jmp    vt_esc_2
  2619. vt_disp_inESC3:
  2620.     cmp    flags.vtflg,ttvt52
  2621.     jne    vt_disp_inESCe
  2622. ;
  2623.     cmp    spec_stage,VT52_DCA_L
  2624.     jne    vt_disp_inESC4
  2625.     jmp    vt_disp_VT52ESC_YL
  2626. vt_disp_inESC4:
  2627.     cmp    spec_stage,VT52_DCA_C
  2628.     jne    vt_disp_inESCe
  2629.     jmp    vt_disp_VT52ESC_YC
  2630. vt_disp_inESCe:
  2631.     mov    spec_mode,0        ; Sequence error. Clear flags and
  2632.     jmp    vt_disp_NRM        ; treat as normal case.
  2633. ;--------------------------------
  2634. ; 1st byte just after the ESC
  2635. ; AL is in 2/0 - 7/E
  2636. vt_esc_1:
  2637.     cmp    al,02Fh
  2638.     ja    vt_esc_10        ; char is in 3/0 - 7/14, i.e., single
  2639.     mov    spec_stage,1        ; set mutibyte flag
  2640.     jmp    vt_esc_I        ; and goto I-seq.
  2641. vt_esc_10:
  2642.     cmp    al,05Fh
  2643.     ja    vt_esc_do_s        ; char is in 6/0 - 7/14, i.e., single
  2644.     cmp    al,040h
  2645.     jb    vt_esc_do_s        ; char is in 3/0 - 3/15, i.e., single
  2646. ;  now AL is in 4/0 - 5/15, i.e., C1 except for a few cases
  2647.     cmp    al,'Z'            ; DECDA ?
  2648.     jne    vt_esc_11
  2649.     jmp    vt_CSI_DA
  2650. vt_esc_11:
  2651.     cmp    flags.vtflg,ttvt52    ; vt52 mode ?
  2652.     jne    vt_esc_12        ; ne = no.
  2653.     jmp    vt_disp_vt52ESC
  2654. vt_esc_12:
  2655.     add    al,040h            ; convert to C1
  2656.     jmp    vt_disp_c1        ; display the C1 character
  2657. ;--------------------------------
  2658. ; in multi-byte ESC seq.
  2659. ; AL is 2/0 - 7/E
  2660. vt_esc_2:
  2661.     cmp    al,02Fh
  2662.     jbe    vt_esc_I        ; char is in 2/0 - 2/15, i.e., I
  2663.     jmp    vt_esc_do_m        ; char is in 3/0 - 7/14, i.e., final
  2664. vt_esc_I:
  2665.     mov    bx,offset I_buf
  2666.     add    bx,I_pnt
  2667.     mov    byte ptr [bx],al
  2668.     inc    I_pnt
  2669.     jmp    vt_disp_ex
  2670. ;
  2671. vt_esc_done:
  2672. vt_CSI_done:
  2673.     mov    spec_mode,0
  2674.     jmp    vt_disp_ex
  2675. ;
  2676. ; Found the final character of the ESC sequence
  2677. ;
  2678. ; Single-byte ESC seq.
  2679. ; 3/0 - 3/15  private seq.
  2680. ; 6/0 - 7/14  standard seq.
  2681. vt_esc_do_s:
  2682.     cmp    al,6Eh
  2683.     jne    vt_esc_do_n6E
  2684.     mov    char_GL,offset char_G2
  2685.     jmp    vt_esc_done
  2686. vt_esc_do_n6E:
  2687.     cmp    al,6Fh
  2688.     jne    vt_esc_do_n6F
  2689.     mov    char_GL,offset char_G3
  2690.     jmp    vt_esc_done
  2691. vt_esc_do_n6F:
  2692.     cmp    al,7Ch
  2693.     jne    vt_esc_do_n7C
  2694.     mov    char_GR,offset char_G3
  2695.     jmp    vt_esc_done
  2696. vt_esc_do_n7C:
  2697.     cmp    al,7Dh
  2698.     jne    vt_esc_do_n7D
  2699.     mov    char_GR,offset char_G2
  2700.     jmp    vt_esc_done
  2701. vt_esc_do_n7D:
  2702.     cmp    al,7Eh
  2703.     jne    vt_esc_do_n7E
  2704.     mov    char_GR,offset char_G1
  2705.     jmp    vt_esc_done
  2706. vt_esc_do_n7E:
  2707.     cmp    al,63h            ; ESC c
  2708.     jne    vt_esc_do_n63
  2709.     call    vt100_reset
  2710.     jmp    vt_esc_done
  2711. vt_esc_do_n63:
  2712.     cmp    al,3Dh            ; ESC =
  2713.     jne    vt_esc_do_n3D
  2714.     mov    keypad_mode,1
  2715.     jmp    vt_esc_done
  2716. vt_esc_do_n3D:
  2717.     cmp    al,3Eh            ; ESC >
  2718.     jne    vt_esc_do_n3E
  2719.     mov    keypad_mode,0
  2720.     jmp    vt_esc_done
  2721. vt_esc_do_n3E:
  2722.     cmp    al,37h            ; ESC 7
  2723.     jne    vt_esc_do_n37
  2724.     call    save_cursor
  2725.     jmp    vt_esc_done
  2726. vt_esc_do_n37:
  2727.     cmp    al,38h            ; ESC 8
  2728.     jne    vt_esc_do_n38
  2729.     call    restore_cursor
  2730.     jmp    vt_esc_done
  2731. vt_esc_do_n38:
  2732.     cmp    al,3Ch            ; ESC < VT52 -> ANSI mode ?
  2733.     jne    vt_esc_do_n3C
  2734.     mov    flags.vtflg,ttvt100
  2735.     call    set_termnam
  2736.     call    vt100_modlin
  2737.     jmp    vt_esc_done
  2738. vt_esc_do_n3C:
  2739.     jmp    vt_esc_done
  2740. ;
  2741. ; Multi-byte ESC seq.
  2742. ; 3/0 - 3/15  Private seq.
  2743. ; 4/0 - 7/14  Standard seq.
  2744. vt_esc_do_m:
  2745. vt_esc_do32:
  2746.     mov    bx,offset I_buf
  2747.     mov    ah,byte ptr [bx]
  2748.     cmp    ah,24h            ; multibyte designation code ?
  2749.     jne    vt_esc_do34
  2750.     jmp    vt_desig_m
  2751. vt_esc_do34:
  2752.     cmp    ah,28h            ; singlebyte desig. code (2/8-2/15)?
  2753.     jb    vt_esc_do36        ; b = no.
  2754.     cmp    ah,2Fh            ;
  2755.     ja    vt_esc_do36        ; a = no.
  2756.     jmp    vt_desig_s
  2757. vt_esc_do36:
  2758.     cmp    al,'0'            ; Possible Select Tek mode ?
  2759.     jne    vt_esc_do37        ; ne = no
  2760.     cmp    I_pnt,2
  2761.     jne    vt_esc_do37
  2762.     cmp    ah,'%'            ; Tek4105 Select code 1st byte ?
  2763.     jne    vt_esc_do37        ; ne = no
  2764.     inc    bx            ; next int. char.
  2765.     mov    ah,byte ptr [bx]
  2766.     cmp    ah,'!'            ; Tek4105 Select code 2nd byte ?
  2767.     jne    vt_esc_do37
  2768.     mov    vt100_gflag,5        ; Tek41xx screen color
  2769.     mov    ah,1            ; enter Tek mode
  2770.     mov    cx,0
  2771.     mov    spec_mode,0        ; clear ESC/CSI seq.
  2772.     ret
  2773. vt_esc_do37:
  2774.     jmp    vt_esc_done        ; unknown
  2775. ;-------------------------------------
  2776. ; designate single byte character set
  2777. ;
  2778. vt_desig_s:
  2779.     and    ah,3
  2780.     mov    bx,offset char_G0
  2781.     add    bl,ah
  2782.     mov    ah,CSET_JISROMAN
  2783.     cmp    al,49h
  2784.     jne    vt_desig_s1
  2785.     mov    ah,CSET_JISKATAKANA
  2786.     jmp    vt_desig_s2
  2787. vt_desig_s1:
  2788.     cmp    al,30h
  2789.     jne    vt_desig_s2
  2790.     mov    ah,CSET_DECGRAPH
  2791. vt_desig_s2:
  2792.     mov    byte ptr [bx],ah
  2793.     jmp    vt_esc_done
  2794. ;
  2795. ; designate multi-byte character set.
  2796. ;
  2797. vt_desig_m:
  2798.     mov    ah,0
  2799.     cmp    I_pnt,1
  2800.     jbe    vt_desig_m1
  2801.     add    bx,1
  2802.     mov    ah,byte ptr [bx]
  2803.     and    ah,3
  2804. vt_desig_m1:
  2805.     mov    bx,offset char_G0
  2806.     add    bl,ah
  2807.     mov    ah,CSET_JISC6226
  2808.     mov    byte ptr [bx],ah
  2809.     jmp    vt_esc_done
  2810. ;----------------------------------------------------
  2811. ; Control seuence analysis
  2812. ; Note that VT100 allows C0 characters in CSI seq.
  2813. vt_disp_inCSI:
  2814.     cmp    al,07Eh            ; check the range
  2815.     ja    vt_disp_inCSIe        ; error.
  2816.     cmp    al,020h            ; C0 character ?
  2817.     jae    vt_disp_inCSI1        ; ae = no. It is GL.
  2818.     jmp    vt_disp_C0
  2819. vt_disp_inCSI1:
  2820.     cmp    spec_stage,0        ; 1st character in CSI ?
  2821.     jne    vt_disp_inCSI2        ; ne = No.
  2822.     jmp    vt_CSI_1        ; CSI with Parameters
  2823. vt_disp_inCSI2:
  2824.     cmp    spec_stage,1        ; in intermediates ?
  2825.     jne    vt_disp_inCSI3
  2826.     jmp    vt_CSI_2        ; CSI with Intermediates
  2827. vt_disp_inCSI3:
  2828. vt_disp_inCSIe:
  2829.     mov    spec_mode,0        ; clear flags and treat as normal
  2830.     jmp    vt_disp_NRM
  2831. ;
  2832. vt_disp_inCSIx:
  2833.     mov    spec_mode,0
  2834.     jmp    vt_disp_ex
  2835. ;-----------------------------------------------------
  2836. ; DCS analysis
  2837. ;-----------------------------------------------------
  2838. vt_disp_inDCS:
  2839.     cmp    al,07Fh            ; check the range
  2840.     jae    vt_disp_inDCSe        ; sequence error.
  2841.     cmp    al,08h
  2842.     jb    vt_disp_inDCSe
  2843.     cmp    al,0Dh
  2844.     jbe    vt_disp_inDCS1
  2845.     cmp    al,020h
  2846.     jb    vt_disp_inDCSe
  2847. vt_disp_inDCS1:
  2848.     cmp    spec_stage,IN_SIXEL
  2849.     jne    vt_disp_inDCS2
  2850.     call    sixel
  2851.     jmp    vt_disp_ex
  2852. vt_disp_inDCS2:
  2853.     jmp    vt_DCS_1
  2854. vt_disp_inDCSe:
  2855.     mov    spec_mode,0        ; sequence error.
  2856.     jmp    vt_disp_NRM
  2857. ;--------------------------
  2858. vt_DCS_do:
  2859.     cmp    al,'q'            ; sixel ?
  2860.     jne    vt_DCS_do_nq
  2861.     mov    spec_stage,IN_SIXEL
  2862.     call    sixel_in
  2863.     mov    vt100_gflag,2
  2864.     mov    sixel_disp_on,1
  2865. vt_DCS_do_nq:
  2866.     jmp    vt_disp_ex
  2867. ;----------------------------------------------------------
  2868. ; CSI & DCS sequence analysys
  2869. ;----------------------------------------------------------
  2870. vt_DCS_1:
  2871. vt_CSI_1:
  2872.     cmp    al,030h            ; Parameter (3/0-3/15) ?
  2873.     jb    vt_CSI_2
  2874.     cmp    al,03Fh
  2875.     jbe    vt_CSI_Para
  2876.     mov    spec_stage,1
  2877. vt_CSI_2:
  2878.     cmp    al,020h            ; Intermediate (2/0-2/15) ?
  2879.     jb    vt_CSI_3
  2880.     cmp    al,02Fh
  2881.     jbe    vt_CSI_Intr
  2882.     cmp    al,040h            ; Terminator (4/0-7/14) ?
  2883.     jb    vt_CSI_3
  2884.     cmp    spec_mode,IN_CSI_MODE
  2885.     jne    vt_CSI_2_1
  2886.     jmp    vt_CSI_do
  2887. vt_CSI_2_1:
  2888.     jmp    vt_DCS_do
  2889. vt_CSI_3:
  2890.     jmp    vt_CSI_done
  2891. ;
  2892. ; Parameter (3/0-3/15)
  2893. ;
  2894. vt_CSI_Para:
  2895.     cmp    al,03ah
  2896.     jae    vt_CSI_Para1
  2897.     mov    bx,offset P_buf
  2898.     add    bx,P_pnt
  2899.     mov    cx,[bx]            ; cx = previous value
  2900.     and    cx,7FFFh        ; mask private parameter flag
  2901.     mov    dx,cx
  2902.     shl    dx,1
  2903.     shl    dx,1
  2904.     add    dx,cx            ; dx = cx*5
  2905.     shl    dx,1            ; dx = (previous value)*10
  2906.     xor    ah,ah
  2907.     sub    ax,030h
  2908.     add    ax,dx            ; ax is (previous value)*10 + new
  2909.     or    ax,priv_pflg        ; set private parameter flag
  2910.     mov    [bx],ax            ; save it
  2911.     jmp    vt_disp_ex
  2912. vt_CSI_Para1:
  2913.     cmp    al,'?'            ; Private parameter ? (3/15)
  2914.     jne    vt_CSI_Para11
  2915.     mov    priv_pflg,PRIVP_FLG
  2916.     jmp    vt_disp_ex
  2917. vt_CSI_Para11:
  2918.     add    P_pnt,2            ; separator
  2919.     mov    bx,offset P_buf
  2920.     add    bx,P_pnt
  2921.     mov    word ptr [bx],0        ; clear for next parameter
  2922.     jmp    vt_disp_ex
  2923. ;
  2924. ; Intermediate (2/0-2/15)
  2925. ;
  2926. vt_CSI_Intr:
  2927.     mov    bx,offset I_buf
  2928.     add    bx,I_pnt
  2929.     mov    byte ptr [bx],al
  2930.     inc    I_pnt
  2931.     jmp    vt_disp_ex
  2932.  
  2933. ;------------------------
  2934. ; Do the control sequence
  2935. ;------------------------
  2936. vt_CSI_do:
  2937.     cmp    al,'K'
  2938.     jne    vt_CSI_do_10
  2939.     jmp    vt_CSI_K
  2940. vt_CSI_do_10:
  2941.     cmp    al,'J'
  2942.     jne    vt_CSI_do_20
  2943.     jmp    vt_CSI_J
  2944. vt_CSI_do_20:
  2945.     cmp    al,'H'
  2946.     jne    vt_CSI_do_25
  2947.     jmp    vt_CSI_H
  2948. vt_CSI_do_25:
  2949.     cmp    al,'f'
  2950.     jne    vt_CSI_do_30
  2951.     jmp    vt_CSI_H
  2952. vt_CSI_do_30:
  2953.     cmp    al,'A'
  2954.     jb    vt_CSI_do_40
  2955.     cmp    al,'D'
  2956.     ja    vt_CSI_do_40
  2957.     jmp    vt_CSI_ABCD
  2958. vt_CSI_do_40:
  2959.     cmp    al,'r'
  2960.     jne    vt_CSI_do_50
  2961.     jmp    vt_CSI_SCR
  2962. vt_CSI_do_50:
  2963.     cmp    al,'L'
  2964.     jne    vt_CSI_do_60
  2965.     jmp    vt_CSI_L
  2966. vt_CSI_do_60:
  2967.     cmp    al,'M'
  2968.     jne    vt_CSI_do_70
  2969.     jmp    vt_CSI_M
  2970. vt_CSI_do_70:
  2971.     cmp    al,'m'
  2972.     jne    vt_CSI_do_80
  2973.     jmp    vt_CSI_CATR
  2974. vt_CSI_do_80:
  2975.     cmp    al,'c'
  2976.     jne    vt_CSI_do_90
  2977.     jmp    vt_CSI_DA
  2978. vt_CSI_do_90:
  2979.     cmp    al,'h'
  2980.     jne    vt_CSI_do_100
  2981.     jmp    vt_CSI_SET_M
  2982. vt_CSI_do_100:
  2983.     cmp    al,'l'
  2984.     jne    vt_CSI_do_110
  2985.     jmp    vt_CSI_RESET_M
  2986. vt_CSI_do_110:
  2987.     cmp    al,'n'
  2988.     jne    vt_CSI_do_120
  2989.     jmp    vt_CSI_DSR
  2990. vt_CSI_do_120:
  2991.     cmp    al,'q'
  2992.     jne    vt_CSI_do_130
  2993.     jmp    vt_CSI_LED
  2994. vt_CSI_do_130:
  2995.     cmp    al,'P'
  2996.     jne    vt_CSI_do_140
  2997.     jmp    vt_CSI_DCH
  2998. vt_CSI_do_140:
  2999.     cmp    al,'@'
  3000.     jne    vt_CSI_do_150
  3001.     jmp    vt_CSI_ICH
  3002. vt_CSI_do_150:
  3003.     cmp    al,'X'
  3004.     jne    vt_CSI_do_160
  3005.     jmp    vt_CSI_ECH
  3006. vt_CSI_do_160:
  3007.     cmp    al,'g'
  3008.     jne    vt_CSI_do_170
  3009.     jmp    vt_CSI_TBC
  3010. vt_CSI_do_170:
  3011.     cmp    al,'i'
  3012.     jne    vt_CSI_do_180
  3013.     jmp    vt_CSI_PRN
  3014. vt_CSI_do_180:
  3015.     cmp    al,'}'
  3016.     jne    vt_CSI_do_190
  3017.     jmp    vt_CSI_DECSASD
  3018. vt_CSI_do_190:
  3019.     cmp    al,'~'
  3020.     jne    vt_CSI_do_200
  3021.     jmp    vt_CSI_DECSSDT
  3022. vt_CSI_do_200:
  3023. vt_CSI_do_ex:
  3024.     jmp    vt_CSI_done
  3025. ;
  3026. vt_CSI_DA:
  3027. ; Device attributes
  3028.     mov    si,offset I_am_vt52
  3029.     cmp    flags.vtflg,ttvt52
  3030.     je    vt_CSI_DA_1
  3031.     mov    si,offset I_am_vt102
  3032. vt_CSI_DA_1:
  3033.     xor    cx,cx
  3034.     mov    cl,[si]
  3035.     inc    si
  3036.     mov    spec_mode,0            ; done the sequence
  3037.     mov    ah,0
  3038.     ret
  3039. ;
  3040. vt_CSI_DSR:
  3041. ;
  3042. ; Device status report
  3043. ;     Host to VT             VT returns
  3044. ;      CSI 5 n                CSI 0 n      no mulfunction
  3045. ;                             CSI 3 n      mulfunction
  3046. ;
  3047. ;      CSI 6 n                CSI Pr;Pc R  cursor position is Pr(row)
  3048. ;                                          Pc (column)
  3049. ;
  3050.     mov    spec_mode,0        ; done the sequence
  3051.     mov    si,offset P_buf        ; get param. buff address
  3052.     mov    bx,[si]            ; get parameter value
  3053.     cmp    bx,5
  3054.     je    vt_CSI_DSR5
  3055.     cmp    bx,6
  3056.     je    vt_CSI_DSR6
  3057.     jmp    vt_CSI_do_ex
  3058. ;
  3059. vt_CSI_DSR5:
  3060.     mov    si,offset I_am_fine
  3061.     xor    cx,cx
  3062.     mov    cl,[si]
  3063.     inc    si
  3064.     mov    ah,0
  3065.     ret
  3066. vt_CSI_DSR6:
  3067.     mov    si,offset My_cursor_is
  3068.     add    si,2
  3069.     mov    cx,2
  3070. ;
  3071.     xor    ax,ax
  3072.     mov    al,cur_row
  3073.     inc    ax
  3074.     cmp    ax,100
  3075.     jb    vt_CSI_DSR61
  3076.     mov    bx,100
  3077.     div    bl
  3078.     or    al,30h
  3079.     mov    byte ptr [si],al
  3080.     inc    si
  3081.     inc    cx
  3082.     mov    al,ah
  3083.     xor    ah,ah
  3084.     jmp    vt_CSI_DSR62
  3085. vt_CSI_DSR61:
  3086.     cmp    ax,10
  3087.     jb    vt_CSI_DSR63
  3088. vt_CSI_DSR62:
  3089.     mov    bx,10
  3090.     div    bl
  3091.     or    al,30h
  3092.     mov    byte ptr [si],al
  3093.     inc    si
  3094.     inc    cx
  3095.     mov    al,ah
  3096.     xor    ah,ah
  3097. vt_CSI_DSR63:
  3098.     or    al,30h
  3099.     mov    byte ptr [si],al
  3100.     inc    si
  3101.     inc    cx
  3102. ;
  3103.     mov    byte ptr [si],';'
  3104.     inc    si
  3105.     inc    cx
  3106. ;
  3107.     xor    ax,ax
  3108.     mov    al,cur_col
  3109.     inc    ax
  3110.     cmp    ax,100
  3111.     jb    vt_CSI_DSR64
  3112.     mov    bx,100
  3113.     div    bl
  3114.     or    al,30h
  3115.     mov    byte ptr [si],al
  3116.     inc    si
  3117.     inc    cx
  3118.     mov    al,ah
  3119.     xor    ah,ah
  3120.     jmp    vt_CSI_DSR65
  3121. vt_CSI_DSR64:
  3122.     cmp    ax,10
  3123.     jb    vt_CSI_DSR66
  3124. vt_CSI_DSR65:
  3125.     mov    bx,10
  3126.     div    bl
  3127.     or    al,30h
  3128.     mov    byte ptr [si],al
  3129.     inc    si
  3130.     inc    cx
  3131.     mov    al,ah
  3132.     xor    ah,ah
  3133. vt_CSI_DSR66:
  3134.     or    al,30h
  3135.     mov    byte ptr [si],al
  3136.     inc    si
  3137.     inc    cx
  3138. ;
  3139.     mov    byte ptr [si],'R'
  3140.     inc    si
  3141.     inc    cx
  3142. ;
  3143.     mov    si,offset My_cursor_is
  3144.     mov    ah,0
  3145.     ret
  3146. ;
  3147. ; Character attributes
  3148. ;    0  All off
  3149. ;    1  Bold (Highlight)
  3150. ;    4  Underscored
  3151. ;    5  Blinking
  3152. ;    7  Reverse
  3153. ;   22  Normal intensity
  3154. ;   24  Not underlined
  3155. ;   25  Not blinking
  3156. ;   27  Positive image
  3157. ; 30-37 Foreground color = 30 + colors (colors: 1=red, 2=green, 4=blue)
  3158. ;
  3159. vt_CSI_CATR:
  3160.     push    cx
  3161.     push    si
  3162.  
  3163.     mov    si,offset P_buf
  3164.     mov    cx,P_pnt
  3165.     shr    cx,1
  3166.     inc    cx
  3167. vt_CSI_CATR1:
  3168.     mov    bx,[si]
  3169.     cmp    bx,0
  3170.     jne    vt_CSI_CATR2
  3171.     push    si
  3172.     mov    si,offset def_color    ; reset to default color
  3173.     call    set_cur_color
  3174.     call    vt100_color
  3175.     pop    si
  3176.     call    set_gcolor
  3177.     mov    al,vt_nrmatr
  3178.     mov    vt_chratr,al
  3179.     jmp    vt_CSI_CATRX
  3180. vt_CSI_CATR2:
  3181.     cmp    bx,1
  3182.     jne    vt_CSI_CATR3
  3183.     mov    al,vt_chratr            ; Bold
  3184.     and    al,01Fh
  3185.     or    al,vt_hglatr
  3186.     mov    vt_chratr,al
  3187.     jmp    vt_CSI_CATRX
  3188. vt_CSI_CATR3:
  3189.     cmp    bx,4
  3190.     jne    vt_CSI_CATR5
  3191.     or    vt_chratr,8            ; Underscored
  3192.     jmp    vt_CSI_CATRX
  3193. vt_CSI_CATR5:
  3194.     cmp    bx,5
  3195.     jne    vt_CSI_CATR7
  3196.     or    vt_chratr,2            ; Blinking
  3197.     jmp    vt_CSI_CATRX
  3198. vt_CSI_CATR7:
  3199.     cmp    bx,7
  3200.     jne    vt_CSI_CATR22
  3201.     test    vt_nrmatr,CHR_REV
  3202.     jz    vt_CSI_CATR7_1
  3203.     and    vt_chratr,(not CHR_REV)
  3204.     jmp    vt_CSI_CATRX
  3205. vt_CSI_CATR7_1:
  3206.     or    vt_chratr,CHR_REV
  3207.     jmp    vt_CSI_CATRX
  3208. vt_CSI_CATR22:
  3209.     cmp    bx,22
  3210.     jne    vt_CSI_CATR24
  3211.     jmp    vt_CSI_CATRX
  3212. vt_CSI_CATR24:
  3213.     cmp    bx,24
  3214.     jne    vt_CSI_CATR25
  3215.     and    vt_chratr,0F7h            ; not Underscored
  3216.     jmp    vt_CSI_CATRX
  3217. vt_CSI_CATR25:
  3218.     cmp    bx,25
  3219.     jne    vt_CSI_CATR27
  3220.     and    vt_chratr,0FDh            ; not blinking
  3221.     jmp    vt_CSI_CATRX
  3222. vt_CSI_CATR27:
  3223.     cmp    bx,27
  3224.     jne    vt_CSI_CATR30
  3225.     test    vt_nrmatr,CHR_REV
  3226.     jz    vt_CSI_CATR27_1
  3227.     or    vt_chratr,CHR_REV
  3228.     jmp    vt_CSI_CATRX
  3229. vt_CSI_CATR27_1:
  3230.     and    vt_chratr,(not CHR_REV)        ; positive image
  3231.     jmp    vt_CSI_CATRX
  3232. vt_CSI_CATR30:
  3233.     cmp    bx,30
  3234.     jb    vt_CSI_CATR40
  3235.     cmp    bx,37
  3236.     ja    vt_CSI_CATR40
  3237.     mov    ax,bx
  3238.     sub    ax,30
  3239.     mov    bx,offset color_index_table
  3240.     add    bx,ax
  3241.     mov    al,[bx]
  3242.     push    si
  3243.     mov    si,offset scn_color
  3244.     mov    [si],al
  3245.     call    vt100_color            ; set color
  3246.     pop    si
  3247.     jmp    vt_CSI_CATRX
  3248. vt_CSI_CATR40:
  3249.     cmp    bx,40
  3250.     jb    vt_CSI_CATRX
  3251.     cmp    bx,47
  3252.     ja    vt_CSI_CATRX
  3253.     mov    ax,bx
  3254.     sub    ax,40
  3255.     mov    bx,offset color_index_table
  3256.     add    bx,ax
  3257.     mov    al,[bx]
  3258.     push    si
  3259.     mov    si,offset scn_color
  3260.     mov    [si+1],al
  3261.     call    vt100_color
  3262.     pop    si
  3263.     call    set_gcolor
  3264. ;
  3265. vt_CSI_CATRX:
  3266.     add    si,2
  3267.     dec    cx
  3268.     jcxz    vt_CSI_CATRXX
  3269.     jmp    vt_CSI_CATR1
  3270. vt_CSI_CATRXX:
  3271.     pop    si
  3272.     pop    cx
  3273.     jmp    vt_CSI_do_ex
  3274.  
  3275. ; LED control
  3276. vt_CSI_LED:
  3277.     push    cx
  3278.     push    si
  3279.  
  3280.     mov    si,offset P_buf
  3281.     mov    cx,P_pnt
  3282.     shr    cx,1
  3283.     inc    cx
  3284. vt_CSI_LED1:
  3285.     mov    bx,[si]
  3286.     cmp    bx,0
  3287.     jb    vt_CSI_LEDX
  3288.     jne    vt_CSI_LED2
  3289.     mov    ax,'..'
  3290.     mov    bx,offset LED_buff
  3291.     mov    [bx],ax
  3292.     mov    [bx+2],ax
  3293.     jmp    vt_CSI_LED3
  3294. vt_CSI_LED2:
  3295.     cmp    bx,4
  3296.     ja    vt_CSI_LEDX
  3297.     mov    ax,bx
  3298.     dec    bx
  3299.     add    bx,offset LED_buff
  3300.     add    al,'0'
  3301.     mov    [bx],al
  3302. vt_CSI_LED3:
  3303. vt_CSI_LEDX:
  3304.     add    si,2
  3305.     loop    vt_CSI_LED1
  3306.     call    set_termnam
  3307.     call    vt100_modlin
  3308.     pop    si
  3309.     pop    cx
  3310.     jmp    vt_CSI_do_ex
  3311.  
  3312. ;
  3313. ; Set mode
  3314. ;   2  Keyboard locked
  3315. ;   4  Insert mode
  3316. ;  12  Send-Receive off
  3317. ;  20  LF is newline
  3318. ;  ?1  Cursor Key is application
  3319. ;  ?3  132 column
  3320. ;  ?4  Smooth scroll
  3321. ;  ?5  Reverse screen
  3322. ;  ?6  Origin mode relative
  3323. ;  ?7  Auto Wrap on
  3324. ;  ?8  Auto repeate on
  3325. ; ?18  Print form feed on
  3326. ; ?19  Print extent is full screen
  3327. ; ?25  Text cursor enable on
  3328. ; ?38  Tektronix graphic mode
  3329. ;
  3330. vt_CSI_SET_M:
  3331.     push    cx
  3332.     push    si
  3333.  
  3334.     mov    si,offset P_buf
  3335.     mov    cx,P_pnt
  3336.     shr    cx,1
  3337.     inc    cx
  3338. vt_CSI_SET_M0:
  3339.     mov    bx,[si]
  3340. vt_CSI_SET_M4:
  3341.     cmp    bx,4            ; 4 = Insert mode ?
  3342.     jne    vt_CSI_SET_M5        ; ne = no
  3343.     or    vt100_flags,INSERT_BIT
  3344.     jmp    vt_CSI_SET_MX
  3345. vt_CSI_SET_M5:
  3346. vt_CSI_SET_M20:
  3347.     cmp    bx,20            ; 20 = Newline mode ?
  3348.     jne    vt_CSI_SET_M21        ; ne = no
  3349.     or    vt100_flags,NEWLINE_BIT
  3350.     jmp    vt_CSI_SET_MX
  3351. vt_CSI_SET_M21:
  3352. ;
  3353. ; Private sequence
  3354. ;
  3355. vt_CSI_SET_MP1:
  3356.     cmp    bx,1+PRIVP_FLG        ; ?1 = Cursor key application ?
  3357.     jne    vt_CSI_SET_MP2        ; ne = no
  3358.     mov    curkey_mode,1
  3359.     jmp    vt_CSI_SET_MX
  3360. vt_CSI_SET_MP2:
  3361. vt_CSI_SET_MP3:
  3362.     cmp    bx,3+PRIVP_FLG        ; ?3 = 132 Column ?
  3363.     jne    vt_CSI_SET_MP4
  3364.     jmp    vt_CSI_SET_MX
  3365. vt_CSI_SET_MP4:
  3366. vt_CSI_SET_MP5:
  3367.     cmp    bx,5+PRIVP_FLG        ; ?5 = reverse screen ?
  3368.     jne    vt_CSI_SET_MP6
  3369.     mov    ax,1
  3370.     call    scrn_mode
  3371.     jmp    vt_CSI_SET_MX
  3372. vt_CSI_SET_MP6:
  3373.     cmp    bx,6+PRIVP_FLG        ; ?6 = Origin relative mode ?
  3374.     jne    vt_CSI_SET_MP7
  3375.     or    vt100_flags,ORIGIN_BIT
  3376.     mov    al,vt_top
  3377.     mov    cur_row,al
  3378.     mov    cur_col,0
  3379.     call    locate_cur
  3380.     jmp    vt_CSI_SET_MX
  3381. vt_CSI_SET_MP7:
  3382.     cmp    bx,7+PRIVP_FLG        ; ?7 = AutoWrap ?
  3383.     jne    vt_CSI_SET_MP8
  3384.     or    vt100_flags,AUTOWRAP_BIT
  3385.     jmp    vt_CSI_SET_MX
  3386. vt_CSI_SET_MP8:
  3387.     cmp    bx,18+PRIVP_FLG        ; ?18 = Print form feed
  3388.     jne    vt_CSI_SET_MP19
  3389.     or    vt100_pflag,PRINTFF_BIT
  3390.     jmp    vt_CSI_SET_MX
  3391. vt_CSI_SET_MP19:
  3392.     cmp    bx,19+PRIVP_FLG        ; ?19 = Print Extent
  3393.     jne    vt_CSI_SET_MP20
  3394.     or    vt100_pflag,PRINTEXT_BIT
  3395.     jmp    vt_CSI_SET_MX
  3396. vt_CSI_SET_MP20:
  3397. vt_CSI_SET_MP38:
  3398.     cmp    bx,38+PRIVP_FLG        ; ?38 = Tektronix mode
  3399.     jne    vt_CSI_SET_MP39
  3400.     pop    si
  3401.     pop    cx
  3402.     mov    spec_mode,0        ; done the sequence.
  3403.     mov    vt100_gflag,4        ; Tek40xx color
  3404.     mov    ah,1            ; do not pass the character
  3405.     mov    al,0
  3406.     mov    cx,0
  3407.     ret
  3408. vt_CSI_SET_MP39:
  3409. vt_CSI_SET_MX:
  3410.     add    si,2
  3411.     dec    cx
  3412.     jcxz    vt_CSI_SET_MX0
  3413.     jmp    vt_CSI_SET_M0
  3414. vt_CSI_SET_MX0:
  3415.     pop    si
  3416.     pop    cx
  3417.     jmp    vt_CSI_do_ex
  3418. ;
  3419. ; Reset mode
  3420. ;   2  Keyboard Unlocked
  3421. ;   4  Replace mode
  3422. ;  12  Send-Receive on
  3423. ;  20  LF is line feed
  3424. ;  ?1  Normal cursor key
  3425. ;  ?2  Enter VT52 mode
  3426. ;  ?3  80 column
  3427. ;  ?4  Jump scroll
  3428. ;  ?5  Normal screen
  3429. ;  ?6  Orgin mode is absolute
  3430. ;  ?7  Auto wrap off
  3431. ;  ?8  Auto repeat off
  3432. ; ?18  Print form feed off
  3433. ; ?19  Print extent is scroll region
  3434. ; ?25  Text cursor enable off
  3435. ;
  3436. vt_CSI_RESET_M:
  3437.     push    cx
  3438.     push    si
  3439.  
  3440.     mov    si,offset P_buf
  3441.     mov    cx,P_pnt
  3442.     shr    cx,1
  3443.     inc    cx
  3444. vt_CSI_RESET_M0:
  3445.     mov    bx,[si]
  3446. vt_CSI_RESET_M4:
  3447.     cmp    bx,4            ; 4 = Replace mode ?
  3448.     jne    vt_CSI_RESET_M5        ; ne = no.
  3449.     and    vt100_flags,(not INSERT_BIT)
  3450.     jmp    vt_CSI_RESET_MX
  3451. vt_CSI_RESET_M5:
  3452. vt_CSI_RESET_M20:
  3453.     cmp    bx,20            ; 20 = Linefeed mode ?
  3454.     jne    vt_CSI_RESET_M21    ; ne = no.
  3455.     and    vt100_flags,(not NEWLINE_BIT)
  3456.     jmp    vt_CSI_RESET_MX
  3457. vt_CSI_RESET_M21:
  3458. ;
  3459. ; Private sequence
  3460. ;
  3461. vt_CSI_RESET_MP1:
  3462.     cmp    bx,1+PRIVP_FLG        ; ?1 = Normal cursor key ?
  3463.     jne    vt_CSI_RESET_MP2
  3464.     mov    curkey_mode,0
  3465.     jmp    vt_CSI_RESET_MX
  3466. vt_CSI_RESET_MP2:
  3467.     cmp    bx,2+PRIVP_FLG        ; ?2 = Enter VT52 mode ?
  3468.     jne    vt_CSI_RESET_MP3
  3469.     mov    flags.vtflg,ttvt52
  3470.     call    set_termnam        ; set terminal name
  3471.     call    vt100_modlin        ; re-display mode line
  3472.     jmp    vt_CSI_RESET_MX
  3473. vt_CSI_RESET_MP3:
  3474. vt_CSI_RESET_MP5:
  3475.     cmp    bx,5+PRIVP_FLG        ; ?5 = normal screen ?
  3476.     jne    vt_CSI_RESET_MP6
  3477.     mov    ax,0
  3478.     call    scrn_mode
  3479.     jmp    vt_CSI_RESET_MX
  3480. vt_CSI_RESET_MP6:
  3481.     cmp    bx,6+PRIVP_FLG        ; ?6 = Origin absolute mode ?
  3482.     jne    vt_CSI_RESET_MP7
  3483.     and    vt100_flags,(not ORIGIN_BIT)
  3484.     mov    cur_row,0
  3485.     mov    cur_col,0
  3486.     call    locate_cur
  3487.     jmp    vt_CSI_RESET_MX
  3488. vt_CSI_RESET_MP7:
  3489.     cmp    bx,7+PRIVP_FLG
  3490.     jne    vt_CSI_RESET_MP8
  3491.     and    vt100_flags,(not AUTOWRAP_BIT)
  3492.     jmp    vt_CSI_RESET_MX
  3493. vt_CSI_RESET_MP8:
  3494.     cmp    bx,18+PRIVP_FLG
  3495.     jne    vt_CSI_RESET_MP19
  3496.     and    vt100_pflag,(not PRINTFF_BIT)
  3497.     jmp    vt_CSI_RESET_MX
  3498. vt_CSI_RESET_MP19:
  3499.     cmp    bx,19+PRIVP_FLG
  3500.     jne    vt_CSI_RESET_MP20
  3501.     and    vt100_pflag,(not PRINTEXT_BIT)
  3502.     jmp    vt_CSI_RESET_MX
  3503. vt_CSI_RESET_MP20:
  3504. vt_CSI_RESET_MX:
  3505.     add    si,2
  3506.     dec    cx
  3507.     jcxz    vt_CSI_RESET_MX0
  3508.     jmp    vt_CSI_RESET_M0
  3509. vt_CSI_RESET_MX0:
  3510.     pop    si
  3511.     pop    cx
  3512.     jmp    vt_CSI_do_ex
  3513. ;
  3514. vt_CSI_ABCD:
  3515.     mov    bx,offset P_buf
  3516.     mov    bx,[bx]
  3517.     cmp    bx,1
  3518.     jae    vt_CSI_ABCD1
  3519.     mov    bx,1
  3520. vt_CSI_ABCD1:
  3521.     cmp    al,'B'
  3522.     je    vt_CSI_CUD
  3523.     cmp    al,'C'
  3524.     je    vt_CSI_CUR
  3525.     cmp    al,'D'
  3526.     je    vt_CSI_CUL
  3527. vt_CSI_CUU:
  3528.     xor    ah,ah
  3529.     mov    al,cur_row
  3530.     sub    ax,bx
  3531.     xor    bh,bh
  3532.     mov    bl,vt_top
  3533.     cmp    ax,bx
  3534.     jge    vt_CSI_CUU1
  3535.     mov    ax,bx
  3536. vt_CSI_CUU1:
  3537.     mov    cur_row,al
  3538.     jmp    vt_CSI_ABCD_ex
  3539. vt_CSI_CUD:
  3540.     xor    ah,ah
  3541.     mov    al,cur_row
  3542.     add    ax,bx
  3543.     cmp    al,vt_bottom
  3544.     jle    vt_CSI_CUD1
  3545.     mov    al,vt_bottom
  3546. vt_CSI_CUD1:
  3547.     mov    cur_row,al
  3548.     jmp    vt_CSI_ABCD_ex
  3549. vt_CSI_CUR:
  3550.     xor    ah,ah
  3551.     mov    al,cur_col
  3552.     add    ax,bx
  3553.     cmp    ax,79
  3554.     jle    vt_CSI_CUR1
  3555.     mov    ax,79
  3556. vt_CSI_CUR1:
  3557.     mov    cur_col,al
  3558.     jmp    vt_CSI_ABCD_ex
  3559. vt_CSI_CUL:
  3560.     xor    ah,ah
  3561.     mov    al,cur_col
  3562.     sub    ax,bx
  3563.     cmp    ax,0
  3564.     jge    vt_CSI_CUL1
  3565.     mov    ax,0
  3566. vt_CSI_CUL1:
  3567.     mov    cur_col,al
  3568. vt_CSI_ABCD_ex:
  3569.     call    locate_cur
  3570.     jmp    vt_CSI_do_ex
  3571. ;
  3572. vt_CSI_K:
  3573.     mov    bx,offset P_buf
  3574.     mov    ax,[bx]
  3575.     cmp    ax,0
  3576.     jne    vt_CSI_K1
  3577.     mov    dh,cur_row
  3578.     mov    dl,cur_col
  3579.     call    vram_ofs
  3580.     mov    ax,bx
  3581.     mov    dh,cur_row
  3582.     mov    dl,79
  3583.     jmp    vt_CSI_KX
  3584. vt_CSI_K1:
  3585.     cmp    ax,1
  3586.     jne    vt_CSI_K2
  3587.     mov    dh,cur_row
  3588.     mov    dl,0
  3589.     call    vram_ofs
  3590.     mov    ax,bx
  3591.     mov    dh,cur_row
  3592.     mov    dl,cur_col
  3593.     jmp    vt_CSI_KX
  3594. vt_CSI_K2:
  3595.     cmp    ax,2
  3596.     jne    vt_CSI_K3
  3597.     mov    dh,cur_row
  3598.     mov    dl,0
  3599.     call    vram_ofs
  3600.     mov    ax,bx
  3601.     mov    dh,cur_row
  3602.     mov    dl,79
  3603.     jmp    vt_CSI_KX
  3604. vt_CSI_K3:
  3605.     jmp    vt_CSI_do_ex
  3606. vt_CSI_KX:
  3607.     call    vram_ofs
  3608.     call    vt_erase
  3609.     jmp    vt_CSI_do_ex
  3610. ;
  3611. vt_CSI_L:
  3612.     mov    al,cur_row
  3613.     cmp    al,vt_top
  3614.     jge    vt_CSI_L01
  3615.     jmp    vt_CSI_do_ex
  3616. vt_CSI_L01:
  3617.     cmp    al,vt_bottom
  3618.     jle    vt_CSI_L02
  3619.     jmp    vt_CSI_do_ex
  3620. vt_CSI_L02:
  3621.     mov    bx,offset P_buf
  3622.     mov    cx,[bx]
  3623.     cmp    cx,0
  3624.     jg    vt_CSI_L1
  3625.     mov    cx,1
  3626. vt_CSI_L1:
  3627.     mov    ah,vt_bottom
  3628.     call    scroll_down
  3629.     mov    cur_col,0
  3630.     call    locate_cur
  3631.     jmp    vt_CSI_do_ex
  3632.  
  3633. vt_CSI_M:
  3634.     mov    al,cur_row
  3635.     cmp    al,vt_top
  3636.     jge    vt_CSI_M01
  3637.     jmp    vt_CSI_do_ex
  3638. vt_CSI_M01:
  3639.     cmp    al,vt_bottom
  3640.     jle    vt_CSI_M02
  3641.     jmp    vt_CSI_do_ex
  3642. vt_CSI_M02:
  3643.     mov    bx,offset P_buf
  3644.     mov    cx,[bx]
  3645.     cmp    cx,0
  3646.     jg    vt_CSI_M1
  3647.     mov    cx,1
  3648. vt_CSI_M1:
  3649.     mov    ah,vt_bottom
  3650.     call    scroll_up
  3651.     mov    cur_col,0
  3652.     call    locate_cur
  3653.     jmp    vt_CSI_do_ex
  3654.  
  3655. vt_CSI_J:
  3656.     mov    bx,offset P_buf
  3657.     mov    ax,[bx]
  3658.     cmp    ax,0
  3659.     jg    vt_CSI_J1
  3660.     mov    dh,cur_row
  3661.     mov    dl,cur_col
  3662.     call    vram_ofs
  3663.     mov    ax,bx
  3664.     mov    dh,vt_phys_bottom
  3665.     mov    dl,79
  3666.     call    vram_ofs
  3667.     jmp    vt_CSI_JX
  3668. vt_CSI_J1:
  3669.     cmp    ax,1
  3670.     jg    vt_CSI_J2
  3671.     mov    dh,0
  3672.     mov    dl,0
  3673.     call    vram_ofs
  3674.     mov    ax,bx
  3675.     mov    dh,cur_row
  3676.     mov    dl,cur_col
  3677.     call    vram_ofs
  3678.     jmp    vt_CSI_JX
  3679. vt_CSI_J2:
  3680.     cmp    sixel_disp_on,1
  3681.     jne    vt_CSI_J2_1
  3682.     call    sixel_clear
  3683.     mov    vt100_gflag,1
  3684.     mov    sixel_disp_on,0
  3685. vt_CSI_J2_1:
  3686.     mov    dh,0
  3687.     mov    dl,0
  3688.     call    vram_ofs
  3689.     mov    ax,bx
  3690.     mov    dh,vt_phys_bottom
  3691.     mov    dl,79
  3692.     call    vram_ofs
  3693. vt_CSI_JX:
  3694.     call    vt_erase
  3695.     jmp    vt_CSI_do_ex
  3696. ;
  3697. ; Cursor Position CUP    CSI Pl ; Pc H
  3698. ;
  3699. vt_CSI_H:
  3700.     mov    bx,offset P_buf
  3701.     mov    ax,[bx]
  3702.     cmp    ax,1
  3703.     jae    vt_CSI_H1
  3704.     mov    ax,1
  3705. vt_CSI_H1:
  3706.     test    vt100_flags,ORIGIN_BIT    ; relative mode ?
  3707.     jz    vt_CSI_H2        ; z = no.
  3708.     add    al,vt_top        ; convert to absolute
  3709.     cmp    al,vt_bottom
  3710.     jbe    vt_CSI_H3
  3711.     mov    al,vt_bottom
  3712.     jmp    vt_CSI_H31
  3713. vt_CSI_H2:
  3714.     cmp    ax,24
  3715.     jbe    vt_CSI_H3
  3716.     mov    ax,24
  3717. vt_CSI_H3:
  3718.     dec    ax
  3719. vt_CSI_H31:
  3720.     mov    cur_row,al
  3721.     xor    ax,ax
  3722.     cmp    P_pnt,2
  3723.     jb    vt_CSI_H6
  3724.     mov    ax,[bx+2]
  3725.     cmp    ax,1
  3726.     jae    vt_CSI_H4
  3727.     mov    ax,1
  3728. vt_CSI_H4:
  3729.     cmp    ax,80
  3730.     jbe    vt_CSI_H5
  3731.     mov    ax,80
  3732. vt_CSI_H5:
  3733.     dec    ax
  3734. vt_CSI_H6:
  3735.     mov    cur_col,al
  3736. ;
  3737. ;    put the CR/LF for the cooked log.
  3738. ;
  3739.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  3740.     jne    vt_CSI_H61
  3741. ;@@    cmp    al,0
  3742. ;@@    jne    vt_CSI_H61
  3743.     mov    al,0Dh        ; put CR
  3744.     call    outcapt
  3745.     mov    al,0Ah        ; put LF
  3746.     call    outcapt
  3747. vt_CSI_H61:
  3748. ;
  3749.     call    locate_cur
  3750.     jmp    vt_CSI_do_ex
  3751.  
  3752. ;
  3753. ; Chracter editing functions
  3754. ;   CSI Pn @     ICH           Inserts Pn blank characters
  3755. ;   CSI Pn P     DCH           Deletes Pn characters
  3756. ;   CSI Pn X     ECH           Erases Pn characters
  3757. ; In each function, action starts from current cursor position
  3758. ; and the cursor does not move.
  3759. ;
  3760.  
  3761. ; Insert characters (ICH) -- CSI Pn @
  3762.  
  3763. vt_CSI_ICH:
  3764. vt_CSI_ICH1:
  3765.     mov    bx,offset P_buf        ; get the address of the parameter
  3766.     mov    cx,[bx]            ; get the parameter value
  3767.     cmp    cx,0
  3768.     jg    vt_CSI_ICH2
  3769.     mov    cx,1            ; use default
  3770. vt_CSI_ICH2:
  3771.     std                ; backward direction
  3772.     mov    dl,79            ; set destination (row,col)
  3773.     mov    dh,cur_row
  3774.     call    vram_ofs
  3775.     mov    di,bx            ; set destination address
  3776.     xor    ax,ax
  3777.     mov    al,cur_col
  3778.     mov    bx,ax            ; save column position
  3779.     add    ax,cx            ; ax = cur_col + Pn
  3780.     cmp    ax,79            ; inside the right margin ?
  3781.     jle    vt_CSI_ICH3        ; le = Yes.
  3782.     mov    cx,80
  3783.     sub    cx,bx            ; cx = 80 - cur_col
  3784.     jmp    vt_CSI_ICH4
  3785. vt_CSI_ICH3:
  3786.     push    cx            ; save Pn
  3787.     mov    dx,79
  3788.     sub    dx,cx            ; dx = 79 - Pn
  3789.     mov    dh,cur_row
  3790.     call    vram_ofs        ; get VRAM offset address
  3791.     mov    si,bx            ; set source address
  3792.     mov    cx,80
  3793.     sub    cx,ax            ; cx = 80 - cur_col - Pn
  3794.     mov    ax,CRT_TXT_SEG
  3795.     push    es            ; save segment registers
  3796.     push    ds
  3797.     mov    es,ax            ; set segment registers
  3798.     mov    ds,ax
  3799.     push    si
  3800.     push    di
  3801.     push    cx
  3802.     rep    movsw            ; move the characters
  3803.     pop    cx
  3804.     pop    di
  3805.     pop    si
  3806.     add    di,2000h        ; attribute area
  3807.     add    si,2000h
  3808.     rep    movsw            ; move the attributes
  3809.     sub    di,2000h
  3810.     pop    ds
  3811.     pop    es
  3812.     pop    cx            ; restore Pn
  3813. vt_CSI_ICH4:
  3814.     push    es
  3815.     push    cx
  3816.     push    di
  3817.     mov    ax,CRT_TXT_SEG
  3818.     mov    es,ax
  3819.     mov    ax,20h            ; set blank code
  3820.     rep    stosw
  3821.     pop    di
  3822.     pop    cx
  3823.     add    di,2000h        ; attribute area
  3824.     mov    al,vt_nrmatr        ; set normal attributes
  3825.     rep    stosw
  3826.     pop    es
  3827.     cld                ; reset direction flag
  3828.     jmp    vt_CSI_do_ex
  3829.  
  3830.  
  3831. ; Delete characters (DCH) -- CSI Pn P
  3832.  
  3833. vt_CSI_DCH:
  3834. vt_CSI_DCH1:
  3835.     mov    bx,offset P_buf        ; get the address of the parameter
  3836.     mov    cx,[bx]            ; get the parameter value
  3837.     cmp    cx,0
  3838.     jg    vt_CSI_DCH2
  3839.     mov    cx,1            ; use default
  3840. vt_CSI_DCH2:
  3841.     cld
  3842.     xor    ax,ax
  3843.     mov    al,cur_col
  3844.     mov    dh,cur_row
  3845.     mov    dl,cur_col
  3846.     call    vram_ofs        ; get the destination address
  3847.     mov    di,bx            ; set the destination address
  3848.     mov    bx,ax            ; save column position
  3849.     add    ax,cx            ; ax = cur_col + Pn
  3850.     cmp    ax,79            ; inside the right margin ?
  3851.     jle    vt_CSI_DCH3        ; le = Yes.
  3852.     mov    cx,80
  3853.     sub    cx,bx            ; cx = 80 - cur_col
  3854.     jmp    vt_CSI_DCH4
  3855. vt_CSI_DCH3:
  3856.     push    cx
  3857.     mov    cx,80
  3858.     sub    cx,ax            ; cx = 80 - cur_col - Pn
  3859.     mov    dh,cur_row        ; set curosr pointer
  3860.     mov    dl,al
  3861.     call    vram_ofs        ; get VRAM offset address
  3862.     mov    si,bx            ; set the source address
  3863.     mov    ax,CRT_TXT_SEG
  3864.     push    es            ; save segment registers
  3865.     push    ds
  3866.     mov    es,ax            ; set segment registers
  3867.     mov    ds,ax
  3868.     push    si
  3869.     push    di
  3870.     push    cx
  3871.     rep    movsw            ; move the characters
  3872.     pop    cx
  3873.     pop    di
  3874.     pop    si
  3875.     add    di,2000h
  3876.     add    si,2000h
  3877.     rep    movsw            ; move the attributes
  3878.     sub    di,2000h
  3879.     pop    ds
  3880.     pop    es
  3881.     pop    cx
  3882. vt_CSI_DCH4:
  3883.     push    es
  3884.     push    cx
  3885.     push    di
  3886.     mov    ax,CRT_TXT_SEG
  3887.     mov    es,ax
  3888.     mov    ax,20h            ; set blank code
  3889.     rep    stosw
  3890.     pop    di
  3891.     pop    cx
  3892.     add    di,2000h
  3893.     mov    al,vt_blkatr        ; set blank attributes
  3894.     rep    stosw
  3895.     pop    es
  3896.     jmp    vt_CSI_do_ex
  3897.  
  3898.  
  3899. ; Erase characters (ECH) -- CSI Pn X
  3900.  
  3901. vt_CSI_ECH:
  3902. vt_CSI_ECH1:
  3903.     mov    bx,offset P_buf        ; get the address of the parameter
  3904.     mov    cx,[bx]            ; get the parameter value
  3905.     cmp    cx,0
  3906.     jg    vt_CSI_ECH2
  3907.     mov    cx,1            ; use default
  3908. vt_CSI_ECH2:
  3909.     cld
  3910.     xor    ax,ax
  3911.     mov    al,cur_col
  3912.     mov    dh,cur_row
  3913.     mov    dl,cur_col
  3914.     call    vram_ofs        ; get the destination address
  3915.     mov    di,bx            ; set the destination address
  3916.     mov    bx,ax            ; save column position
  3917.     add    ax,cx            ; ax = cur_col + Pn
  3918.     cmp    ax,79            ; inside the right margin ?
  3919.     jle    vt_CSI_ECH3        ; le = Yes.
  3920.     mov    cx,80
  3921.     sub    cx,bx            ; cx = 80 - cur_col
  3922. vt_CSI_ECH3:
  3923.     push    es
  3924.     push    cx
  3925.     push    di
  3926.     mov    ax,CRT_TXT_SEG
  3927.     mov    es,ax
  3928.     mov    ax,20h            ; set blank code
  3929.     rep    stosw
  3930.     pop    di
  3931.     pop    cx
  3932.     add    di,2000h
  3933.     mov    al,vt_nrmatr        ; set normal attributes
  3934.     rep    stosw
  3935.     pop    es
  3936.     jmp    vt_CSI_do_ex
  3937.  
  3938. ;  Tabulation Clear (TBC)
  3939. ;    CSI g
  3940. ;    CSI 0 g    Clears a horizontal tab stop at cursor position
  3941. ;    CSI 3 g    Clears all horizontal tab stops
  3942.  
  3943. vt_CSI_TBC:
  3944.     mov    bx,offset P_buf
  3945.     mov    ax,[bx]            ; get the parameter value
  3946.     cmp    ax,0            ; zero ?
  3947.     je    vt_CSI_TBC0        ; e = yes.
  3948.     cmp    ax,3            ; 3 ?
  3949.     je    vt_CSI_TBC3        ; e = yes.
  3950.     jmp    vt_CSI_do_ex        ; not supported
  3951. ;
  3952. vt_CSI_TBC0:
  3953.     xor    ax,ax
  3954.     mov    al,cur_col        ; get current cursor position
  3955.     mov    bx,offset tabstops
  3956.     add    bx,ax
  3957.     mov    byte ptr [bx],0        ; clear the tab
  3958.     jmp    vt_CSI_do_ex
  3959. ;
  3960. vt_CSI_TBC3:
  3961.     push    es
  3962.     push    di
  3963.     mov    ax,ds
  3964.     mov    es,ax            ; set destination segment
  3965.     mov    di,offset tabstops    ; set destination offset
  3966.     mov    cx,80            ; number of bytes
  3967.     mov    ax,0            ; data = 0
  3968.     cld
  3969.     rep    stosb            ; store it
  3970.     pop    di
  3971.     pop    es
  3972.     jmp    vt_CSI_do_ex
  3973.  
  3974. ;  Printer control
  3975. ;    * not implemented yet
  3976. ;    CSI i    Prints the screen (full/scroll region) display.
  3977. ;    CSI 0 i    Same as above.
  3978. ;  * CSI 4 i    Turns off printer controller mode.
  3979. ;  * CSI 5 i    Turns on printer controller mode (transparent printing).
  3980. ;    CSI ? 1 i    Prints the display line containing the cursor.
  3981. ;    CSI ? 4 i    Turns off auto print mode.
  3982. ;    CSI ? 5 i    Turns on auto print mode.
  3983. ;
  3984.  
  3985. vt_CSI_PRN:
  3986.     mov    bx,offset P_buf
  3987.     mov    ax,[bx]            ; get the parameter value
  3988.     cmp    ax,0            ; 0
  3989.     je    vt_CSI_PRN_S0        ; e = yes.
  3990.     cmp    ax,1+PRIVP_FLG        ; ?1
  3991.     je    vt_CSI_PRN_P1        ; e = yes.
  3992.     cmp    ax,4+PRIVP_FLG        ; ?4
  3993.     je    vt_CSI_PRN_P4        ; e = yes.
  3994.     cmp    ax,5+PRIVP_FLG        ; ?5 ?
  3995.     je    vt_CSI_PRN_P5        ; e = yes.
  3996.     jmp    vt_CSI_do_ex        ; not supported
  3997. ;
  3998. vt_CSI_PRN_S0:
  3999.     call    vt100_prns
  4000.     jmp    vt_CSI_do_ex
  4001. ;
  4002. vt_CSI_PRN_P1:
  4003.     test    vt100_pflag,AUTOPRINT_BIT    ; printer off?
  4004.     jnz    vt_CSI_PRN_P1_1        ; nz = no not. it is on.
  4005.     call    prn_chk            ; check the printer port
  4006.     jc    vt_CSI_PRN_P1_2        ; c = not ready.
  4007. vt_CSI_PRN_P1_1:
  4008.     call    vt100_prnl
  4009. vt_CSI_PRN_P1_2:
  4010.     jmp    vt_CSI_do_ex
  4011. ;
  4012. vt_CSI_PRN_P4:
  4013.     and    vt100_pflag,(not AUTOPRINT_BIT)    ; turns off the printer
  4014.     call    set_prnstat        ; show printer status
  4015.     call    vt100_modlin        ; re-display mode line
  4016.     jmp    vt_CSI_do_ex
  4017. ;
  4018. vt_CSI_PRN_P5:
  4019.     test    vt100_pflag,AUTOPRINT_BIT    ; printer off?
  4020.     jnz    vt_CSI_PRN_P5_1        ; nz = no not. do nothing.
  4021.     call    prn_chk            ; check the printer port
  4022.     jc    vt_CSI_PRN_P5_1        ; c = not ready.
  4023.     or    vt100_pflag,AUTOPRINT_BIT    ; turns on auto print
  4024.     call    set_prnstat            ; show printer status
  4025.     call    vt100_modlin        ; re-display mode line
  4026. vt_CSI_PRN_P5_1:
  4027.     jmp    vt_CSI_do_ex
  4028.  
  4029. ;  Set scroll region.
  4030. ;  It is NOT clear that this command affects the cursor position
  4031. ;  or not.  In my experence, cursor moves to the left-top corner of the
  4032. ;  entire screen (i.e., same as <ESC>[1;1H ).
  4033. ;  - The above statement was wrong. In ORIGIN mode, the cursor goes to
  4034. ;    left-top corner of the scroll region. Thanx for VTTEST. [01-Oct-88].
  4035. ;  - Bugs for funny scroll region are fixed. Thanx for VTTEST. [01-Oct-88].
  4036. ;  - Bug for ESC[;r is fixed. [03-Dec-88].
  4037.  
  4038. vt_CSI_SCR:
  4039.     mov    bx,offset P_buf
  4040.     cmp    P_pnt,2            ; have good number of parameters ?
  4041.     je    vt_CSI_SCR1        ; e = yes.
  4042.     ja    vt_CSI_SCR7        ; a = too many. Ignore. [03-Dec-88].
  4043.     mov    ax,[bx]
  4044.     mov    bx,24            ; set to default
  4045.     jmp    vt_CSI_SCR2
  4046. vt_CSI_SCR1:
  4047.     mov    ax,[bx]
  4048.     mov    bx,[bx+2]
  4049. vt_CSI_SCR2:
  4050.     cmp    ax,1
  4051.     jae    vt_CSI_SCR3
  4052.     mov    ax,1
  4053. vt_CSI_SCR3:
  4054.     cmp    bx,0            ; Pb = 0? [03-Dec-88]
  4055.     ja    vt_CSI_SCR31        ; a = no. [03-Dec-88]
  4056.     mov    bx,24            ; set to default. [03-Dec-88].
  4057.     jmp    vt_CSI_SCR4        ; [03-Dec-88].
  4058. vt_CSI_SCR31:                ; [03-Dec-88].
  4059.     cmp    bx,24
  4060.     jbe    vt_CSI_SCR4
  4061.     mov    bx,24
  4062. vt_CSI_SCR4:
  4063.     cmp    ax,bx            ; Pt < Pb ?
  4064.     jae    vt_CSI_SCR7        ; ae = no. Do nothing.
  4065. vt_CSI_SCR5:
  4066.     dec    ax
  4067.     dec    bx
  4068.     mov    vt_top,al
  4069.     mov    vt_bottom,bl
  4070.     test    vt100_flags,ORIGIN_BIT    ; origin relative mode ?
  4071.     jnz    vt_CSI_SCR6        ; nz = Yes. Use vt_top.
  4072.     mov    ax,0
  4073. vt_CSI_SCR6:
  4074.     mov    cur_row,al
  4075.     mov    cur_col,0
  4076.     call    locate_cur
  4077. vt_CSI_SCR7:
  4078.     jmp    vt_CSI_do_ex
  4079. ;
  4080. vt_CSI_DECSASD:
  4081.     cmp    I_pnt,1            ; requires 1 intermediate char.
  4082.     je    vt_CSI_DECSASD_1    ; e=yes, we have.
  4083.     jmp    vt_CSI_do_ex
  4084. vt_CSI_DECSASD_1:
  4085.     cmp    I_buf,'$'        ; required character ?
  4086.     je    vt_CSI_DECSASD_2    ; e=yes, we have.
  4087.     jmp    vt_CSI_do_ex
  4088. vt_CSI_DECSASD_2:
  4089.     mov    ax,P_buf        ; P_buf always has at least 0.
  4090.     cmp    ax,0
  4091.     je    vt_CSI_DECSASD_3
  4092.     jmp    vt_CSI_DECSASD_5
  4093. ;
  4094. vt_CSI_DECSASD_3:
  4095.     cmp    vt_in_stat,0        ; already in main screen ?
  4096.     jne    vt_CSI_DECSASD_4
  4097.     jmp    vt_CSI_do_ex
  4098. vt_CSI_DECSASD_4:
  4099.     mov    vt_in_stat,0
  4100.     mov    al,cur_row
  4101.     mov    stat_row,al
  4102.     mov    al,cur_col
  4103.     mov    stat_col,al
  4104.     mov    al,text_row
  4105.     mov    cur_row,al
  4106.     mov    al,text_col
  4107.     mov    cur_col,al
  4108.     mov    al,text_top
  4109.     mov    vt_top,al
  4110.     mov    al,text_bottom
  4111.     mov    vt_bottom,al
  4112.     call    locate_cur
  4113.     jmp    vt_CSI_do_ex
  4114. ;
  4115. vt_CSI_DECSASD_5:
  4116.     cmp    vt_in_stat,1        ; already in status line ?
  4117.     jne    vt_CSI_DECSASD_6
  4118.     jmp    vt_CSI_do_ex
  4119. vt_CSI_DECSASD_6:
  4120.     cmp    vt_stat_type,2        ; host writable status line ?
  4121.     je    vt_CSI_DECSASD_7    ; e=yes.
  4122.     jmp    vt_CSI_do_ex
  4123. vt_CSI_DECSASD_7:
  4124.     mov    vt_in_stat,1
  4125.     mov    al,cur_row
  4126.     mov    text_row,al
  4127.     mov    al,cur_col
  4128.     mov    text_col,al
  4129.     mov    al,vt_top
  4130.     mov    text_top,al
  4131.     mov    al,vt_bottom
  4132.     mov    text_bottom,al
  4133. ;
  4134.     mov    al,stat_col
  4135.     mov    cur_col,al
  4136.     mov    al,stat_row
  4137.     mov    cur_row,al
  4138.     mov    vt_top,al
  4139.     mov    vt_bottom,al
  4140.     call    locate_cur
  4141.     jmp    vt_CSI_do_ex
  4142. ;
  4143. vt_CSI_DECSSDT:
  4144.     cmp    I_pnt,1            ; requires 1 intermediate char.
  4145.     je    vt_CSI_DECSSDT_1    ; e=yes, we have.
  4146.     jmp    vt_CSI_do_ex
  4147. vt_CSI_DECSSDT_1:
  4148.     cmp    I_buf,'$'        ; required character ?
  4149.     je    vt_CSI_DECSSDT_2    ; e=yes, we have.
  4150.     jmp    vt_CSI_do_ex
  4151. vt_CSI_DECSSDT_2:
  4152.     mov    ax,P_buf        ; P_buf always has at least 1 param.
  4153.     cmp    ax,2            ; allowed parameter?
  4154.     jbe    vt_CSI_DECSSDT_3    ; be=yes.
  4155.     jmp    vt_CSI_do_ex
  4156. vt_CSI_DECSSDT_3:
  4157.     cmp    al,vt_stat_type        ; same type?
  4158.     jne    vt_CSI_DECSSDT_4    ; ne=no.
  4159.     jmp    vt_CSI_do_ex
  4160. vt_CSI_DECSSDT_4:
  4161.     cmp    ax,2            ; host writable ?
  4162.     jne    vt_CSI_DECSSDT_5    ; ne=no.
  4163.     push    ax
  4164.     mov    al,vt_blkatr
  4165.     call    vt_stat_clr        ; clear status line
  4166.     pop    ax
  4167.     mov    stat_col,0        ; cursor move to left margin
  4168. vt_CSI_DECSSDT_5:
  4169.     mov    vt_stat_type,al
  4170.     call    vt100_modlin
  4171.     jmp    vt_CSI_do_ex
  4172. ;
  4173. ; Erase from VRAM address AX to BX
  4174. ;
  4175. vt_erase:
  4176.     cld
  4177.     push    es
  4178.     mov    cx,bx
  4179.     sub    cx,ax
  4180.     shr    cx,1
  4181.     inc    cx
  4182.     mov    di,ax
  4183.     push    cx
  4184.     push    di
  4185.     mov    ax,CRT_TXT_SEG
  4186.     mov    es,ax
  4187.     mov    ax,0020h
  4188.     rep    stosw
  4189.     pop    di
  4190.     add    di,2000h
  4191.     pop    cx
  4192.     xor    ah,ah
  4193.     mov    al,vt_blkatr
  4194.     rep    stosw
  4195.     pop    es
  4196.     ret
  4197.  
  4198. ;-------------
  4199. ; Scroll-down
  4200. ;-------------
  4201. ; scroll down n-lines in the region [Pt,Pb].  The cursor does not move.
  4202. ;
  4203. ; Input paramters:
  4204. ;    al: top row position Pt
  4205. ;    ah: bottom row position Pb
  4206. ;    cl: number of lines n (must be > 0)
  4207. ; Registers:
  4208. ;    ax, bx, cx, dx, si, di are broken
  4209.  
  4210. scroll_down:
  4211.     mov    bl,ah
  4212.     sub    bl,al
  4213.     cmp    cl,bl            ; n <= bottom - top ?
  4214.     jle    scroll_down_2        ; yes, text remains.
  4215.     jmp    scroll_down_3        ; no text remains.
  4216. scroll_down_2:
  4217.     mov    dh,ah
  4218.     sub    dh,cl
  4219.     mov    dl,79
  4220.     call    vram_ofs
  4221.     mov    si,bx            ; si is VRAM(bottom-n,79)
  4222.     mov    dh,al
  4223.     xor    dl,dl
  4224.     call    vram_ofs
  4225.     mov    cx,si
  4226.     sub    cx,bx
  4227.     shr    cx,1            ; byte counts -> word counts
  4228.     inc    cx            ; number of words to be moved
  4229.     mov    dh,ah
  4230.     mov    dl,79
  4231.     call    vram_ofs
  4232.     mov    di,bx            ; di is VRAM(bottom,79)
  4233.     push    es
  4234.     push    ds
  4235.     mov    ax,CRT_TXT_SEG
  4236.     mov    bl,vt_blkatr        ; save attribute before ds cahnge
  4237.     mov    es,ax
  4238.     mov    ds,ax
  4239.     push    cx            ; save word count
  4240.     push    di            ; save destination address
  4241.     push    si            ; save source address
  4242.     std
  4243.     rep    movsw            ; move the text codes
  4244.     mov    cx,di
  4245.     sub    cx,si
  4246.     shr    cx,1
  4247.     mov    ax,0020h        ; fill blank
  4248.     rep    stosw
  4249. ;
  4250.     pop    si
  4251.     pop    di
  4252.     pop    cx            ; cx, si, di are restored
  4253.     add    di,2000h        ; attribute block
  4254.     add    si,2000h
  4255.     rep    movsw            ; move the attributes
  4256.     mov    cx,di
  4257.     sub    cx,si
  4258.     shr    cx,1
  4259.     mov    al,bl            ; fill attributes
  4260.     xor    ah,ah
  4261.     rep    stosw
  4262. ;
  4263.     cld
  4264.     pop    ds
  4265.     pop    es
  4266.     jmp    scroll_down_ex
  4267. scroll_down_3:
  4268.     mov    dh,al
  4269.     xor    dl,dl
  4270.     call    vram_ofs
  4271.     mov    cx,bx
  4272.     mov    dh,ah
  4273.     mov    dl,79
  4274.     call    vram_ofs
  4275.     mov    ax,cx
  4276.     call    vt_erase
  4277. scroll_down_ex:
  4278.     ret
  4279. ;
  4280. ;-----------
  4281. ; Scroll-up
  4282. ;-----------
  4283. ; scroll up n-lines in the region [Pt,Pb].  The cursor does not move.
  4284. ;
  4285. ; Input paramters:
  4286. ;    al: top row position Pt
  4287. ;    ah: bottom row position Pb (ah must be > al)
  4288. ;    cl: number of lines n (must be > 0)
  4289. ; Registers:
  4290. ;    ax, bx, cx, dx, si, di are broken
  4291.  
  4292. scroll_up:
  4293.     cmp    al,0
  4294.     jne    scroll_up_1
  4295.     call    mrsave            ; save into roll buffer
  4296. scroll_up_1:
  4297.     mov    bl,ah
  4298.     sub    bl,al
  4299.     cmp    cl,bl            ; n <= bottom - top ?
  4300.     jle    scroll_up_2        ; yes, text remains.
  4301.     jmp    scroll_up_3        ; no text remains.
  4302. scroll_up_2:
  4303.     mov    dh,al
  4304.     add    dh,cl
  4305.     xor    dl,dl
  4306.     call    vram_ofs
  4307.     mov    si,bx            ; si is VRAM(top+n,0)
  4308.     mov    dh,ah
  4309.     xor    dl,79
  4310.     call    vram_ofs
  4311.     mov    cx,bx
  4312.     sub    cx,si
  4313.     shr    cx,1            ; byte counts -> word counts
  4314.     inc    cx            ; number of words to be moved
  4315.     mov    dh,al
  4316.     xor    dl,dl
  4317.     call    vram_ofs
  4318.     mov    di,bx            ; di is VRAM(top,0)
  4319.     push    es
  4320.     push    ds
  4321.     mov    ax,CRT_TXT_SEG
  4322.     mov    bl,vt_blkatr        ; save attribute before ds cahnge
  4323.     mov    es,ax
  4324.     mov    ds,ax
  4325.     push    cx            ; save word count
  4326.     push    di            ; save destination address
  4327.     push    si            ; save source address
  4328.     cld
  4329.     rep    movsw            ; move the text codes
  4330.     mov    cx,si
  4331.     sub    cx,di
  4332.     shr    cx,1
  4333.     mov    ax,0020h        ; fill blank
  4334.     rep    stosw
  4335. ;
  4336.     pop    si
  4337.     pop    di
  4338.     pop    cx            ; cx, si, di are restored
  4339.     add    di,2000h        ; attribute block
  4340.     add    si,2000h
  4341.     rep    movsw            ; move the attributes
  4342.     mov    cx,si
  4343.     sub    cx,di
  4344.     shr    cx,1
  4345.     mov    al,bl            ; fill attributes
  4346.     xor    ah,ah
  4347.     rep    stosw
  4348. ;
  4349.     cld
  4350.     pop    ds
  4351.     pop    es
  4352.     jmp    scroll_up_ex
  4353. scroll_up_3:
  4354.     mov    dh,al
  4355.     xor    dl,dl
  4356.     call    vram_ofs
  4357.     mov    cx,bx
  4358.     mov    dh,ah
  4359.     mov    dl,79
  4360.     call    vram_ofs
  4361.     mov    ax,cx
  4362.     call    vt_erase
  4363. scroll_up_ex:
  4364.     ret
  4365.  
  4366. ;
  4367. ; Calculate VRAM offset address from (col,row)
  4368. ; Inputs:
  4369. ;   dh: row (0-vt_phys_bottom)
  4370. ;   dl: col (0-79)
  4371. ; Output:
  4372. ;   bx: VRAM offset address
  4373. ;
  4374. ; dx is broken when return
  4375.  
  4376. vram_ofs:
  4377.     xor    bx,bx
  4378.     mov    bl,dh
  4379.     shl    bx,1
  4380.     add    bx,offset vram_line
  4381.     mov    bx,[bx]
  4382.     xor    dh,dh
  4383.     shl    dl,1
  4384.     add    bx,dx
  4385.     ret
  4386.  
  4387. ; C1 8-bit control character
  4388.  
  4389. ;-----------------------------
  4390. ; Single shift 2 (8/14); ESC N
  4391. ;-----------------------------
  4392. ; Temporarily invokes G2 character set into GL for the next graphic
  4393. ; character.
  4394.  
  4395. vt_c1_SS2:
  4396.     mov    char_SS,offset char_G2
  4397.     jmp    vt_esc_done
  4398.  
  4399. ;-----------------------------
  4400. ; Single shift 3 (8/15); ESC O
  4401. ;-----------------------------
  4402. ; Temporarily invokes G3 character set into GL for the next graphic
  4403. ; character.
  4404.  
  4405. vt_c1_SS3:
  4406.     mov    char_SS,offset char_G3
  4407.     jmp    vt_esc_done
  4408.  
  4409. ;----------------------
  4410. ; Index ( 8/4 ); ESC D
  4411. ;----------------------
  4412. ; Moves the cursor down one line in the same column.  If the cursor
  4413. ; is at the bottom margin, the screen perform a scroll-up.
  4414.  
  4415. vt_c1_IND:
  4416.     mov    ah,cur_row
  4417.     cmp    ah,vt_bottom
  4418.     jl    vt_c1_IND_1
  4419.     je    vt_c1_IND_2
  4420.     jmp    vt_esc_done
  4421. vt_c1_IND_1:
  4422.     inc    ah
  4423.     mov    cur_row,ah
  4424.     call    locate_cur
  4425.     jmp    vt_esc_done
  4426. vt_c1_IND_2:
  4427.     mov    al,vt_top
  4428.     mov    cx,1
  4429.     call    scroll_up
  4430.     jmp    vt_esc_done
  4431.  
  4432. ;-------------------------------
  4433. ; Reverse index ( 8/13 ); ESC M
  4434. ;-------------------------------
  4435. ; Moves the cursor up one line in the same column.  If the cursor is
  4436. ; at the top margin, the screen performs a scroll-down.
  4437.  
  4438. vt_c1_RI:
  4439.     mov    al,cur_row
  4440.     cmp    al,vt_top
  4441.     jg    vt_c1_RI_1
  4442.     je    vt_c1_RI_2        ; [04-Aug-1989]
  4443.     cmp    al,0            ; [04-Aug-1989]
  4444.     jg    vt_c1_RI_1        ; [04-Aug-1989]
  4445.     jmp    vt_esc_done        ; [04-Aug-1989]
  4446. vt_c1_RI_1:
  4447.     dec    al
  4448.     jmp    vt_c1_RI_3
  4449. vt_c1_RI_2:
  4450.     mov    al,vt_top
  4451.     mov    ah,vt_bottom
  4452.     mov    cx,1
  4453.     call    scroll_down
  4454.     mov    al,vt_top
  4455. vt_c1_RI_3:
  4456.     mov    cur_row,al
  4457.     call    locate_cur
  4458.     jmp    vt_esc_done
  4459.  
  4460. ;--------------------------
  4461. ; Next line ( 8/5 ); ESC E
  4462. ;--------------------------
  4463. ; Moves the cursor to the first position on the next line.
  4464. ; If the cursor is at the bottom margin, the screen performs a
  4465. ; scroll-up.
  4466.  
  4467. vt_c1_NEL:
  4468.     mov    ah,cur_row
  4469.     cmp    ah,vt_bottom
  4470.     jl    vt_c1_NEL_1
  4471.     je    vt_c1_NEL_2
  4472.     cmp    ah,vt_phys_bottom    ; [04-Aug-1989]
  4473.     jl    vt_c1_NEL_1        ; [04-Aug-1989]
  4474.     jmp    vt_esc_done
  4475. vt_c1_NEL_1:
  4476.     inc    ah
  4477.     mov    cur_row,ah
  4478.     mov    cur_col,0
  4479.     call    locate_cur
  4480.     jmp    vt_esc_done
  4481. vt_c1_NEL_2:
  4482.     mov    al,vt_top
  4483.     mov    cx,1
  4484.     call    scroll_up
  4485.     mov    cur_col,0
  4486.     call    locate_cur
  4487.     jmp    vt_esc_done
  4488.  
  4489. ;----------------------------------
  4490. ; Horizontal tab set (8/08); ESC H
  4491. ;----------------------------------
  4492. vt_c1_HTS:
  4493.     xor    ax,ax
  4494.     mov    al,cur_col
  4495.     mov    bx,offset tabstops
  4496.     add    bx,ax            ; tab pointer
  4497.     mov    byte ptr [bx],1
  4498.     jmp    vt_esc_done
  4499. ;
  4500. ;-------------------------------------------
  4501. ; Device Control String (9/0); ESC P
  4502. ;-------------------------------------------
  4503. vt_c1_DCS:
  4504.     mov    spec_mode,in_DCS_MODE
  4505.     mov    P_pnt,0
  4506.     mov    bx,offset P_buf
  4507.     mov    word ptr [bx],0
  4508.     mov    I_pnt,0
  4509.     mov    bx,offset I_buf
  4510.     mov    byte ptr [bx],0
  4511.     mov    priv_pflg,0
  4512.     jmp    vt_disp_ex
  4513. ;
  4514. ;-------------------------------------------
  4515. ; Control Sequence Introducer (9/11); ESC [
  4516. ;-------------------------------------------
  4517. vt_c1_CSI:
  4518.     mov    spec_mode,in_CSI_MODE
  4519.     mov    P_pnt,0
  4520.     mov    bx,offset P_buf
  4521.     mov    word ptr [bx],0
  4522.     mov    I_pnt,0
  4523.     mov    bx,offset I_buf
  4524.     mov    byte ptr [bx],0
  4525.     mov    priv_pflg,0
  4526.     jmp    vt_disp_ex
  4527. ;
  4528. ;-------------------------------------------
  4529. ; String Terminator (9/12); ESC \
  4530. ;-------------------------------------------
  4531. vt_c1_ST:
  4532.     mov    spec_mode,0
  4533.     jmp    vt_disp_ex
  4534. ;
  4535. VT100    ENDP
  4536.  
  4537. code    ends
  4538.     end
  4539.