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

  1. ;+ This is MSGP98.ASM
  2. ;
  3. ;  Tektronix 4014 emulator for NEC-PC9801
  4. ;  Author: Hirofumi Fujii (KEK On-line group)
  5. ;
  6. ; Last edited 17-Apr-1991
  7. ; 17-Apr-1991   Joe (and Rikitake) pointed out that tek_gtxt: should be
  8. ;               'tek_gtxt proc near'.
  9. ; 09-Mar-1991   Joe pointed out that CAN is reserved word for MASM 5.
  10. ;               CAN -> CL_CAN
  11. ;               SUB -> CL_SUB
  12. ; 01-Sep-1990    Start TEK4105 coding
  13. ; 09-Aug-1990    Add protection for coordinates in TEK40_DEV_COOD.
  14. ; 24-Jul-1990    for MS-Kermit v3.02
  15. ; 10-Jul-1990    ESC[1;30m gives white line for gnuplot v2.0
  16. ; 25-Jun-1990    Support for ESC [ XX ; YY ; .. ; ZZ m
  17. ; 30-May-1989   Fixed bug in background color.
  18. ;               Reset command resets color to default (color in command mode).
  19. ; 21-Apr-1989   Cooked logging is added
  20. ; 13-Feb-1989    Fill 0FFh of all RAM of the GGDC when tek4014_save is called.
  21.  
  22. GGDC_STS_PORT    equ    0A0h
  23. GGDC_CMD_PORT    equ    0A2h
  24. GGDC_PRM_PORT    equ    0A0h
  25.  
  26. GGDC_BLUE_PLANE        equ    04000h
  27. GGDC_RED_PLANE        equ    08000h
  28. GGDC_GREEN_PLANE    equ    0C000h
  29.  
  30. GGDC_GIN_PLANE        equ    04000h
  31. GGDC_GCUR_PLANE        equ    04000h
  32.  
  33. CPU_BLUE_PLANE    equ    0A800h
  34. CPU_RED_PLANE    equ    0B000h
  35. CPU_GREEN_PLANE    equ    0B800h
  36.  
  37. TEK_X_MAX    equ    4095
  38. TEK_Y_MAX    equ    3071
  39. TEK_DX        equ    56
  40. TEK_DY        equ    112
  41.  
  42. TEK41_NO_ACT    equ    0
  43. TEK41_XY_TYPE    equ    1
  44. TEK41_INT_TYPE    equ    2
  45. TEK41_STR_TYPE    equ    3
  46. TEK41_IAR_TYPE    equ    4
  47.  
  48. TEK41_ARGBUF_SIZE    equ    512
  49. TEK41_FABUF_SIZE    equ    1024
  50.  
  51. BELL        equ    007h
  52. BS        equ    008h
  53. HT        equ    009h
  54. LF        equ    00Ah
  55. VT        equ    00Bh
  56. FF        equ    00Ch
  57. CR        equ    00Dh
  58. CL_CAN        equ    018h
  59. CL_SUB        equ    01Ah
  60. ESCAPE        equ    01Bh
  61. FS        equ    01Ch
  62. GS        equ    01Dh
  63. RS        equ    01Eh
  64. US        equ    01Fh
  65.  
  66. HIY        equ    020h
  67. EXT        equ    060h
  68. LOY        equ    060h
  69. HIX        equ    020h
  70. LOX        equ    040h
  71.  
  72. X_OFS        equ    64
  73. Y_OFS        equ    8
  74.  
  75. IN_REPEAT    equ    1
  76. SIXEL_YMAX    equ    378        ; 24 x 16 - 6
  77. SIXEL_XMAX    equ    639
  78.  
  79.     include    msxp98.h
  80.  
  81.     public    tek4014,tek4014_ini,tek4014_reset
  82.     public    tek4014_save, tek4014_restore, tek4014_modlin
  83.     public    tek4014_color
  84.     public    tekstat
  85.     public    gdisp_on, gdisp_off, set_gcolor
  86.     public    sixel, sixel_in, sixel_clear
  87.     public    sixel_rollup, sixel_rolldown
  88.     public    set_gpalette
  89.  
  90. data     segment    public 'data'
  91.  
  92.     extrn    vt100_flags:byte, vt100_lflag:byte, vt100_gflag:byte
  93.     extrn    vtgrph_flg:byte
  94.     extrn    display_mode:byte
  95.     extrn    gnrm_color:byte, gbck_color:byte    ; in MSYP98.ASM
  96.     extrn    def_color:byte, scn_color:byte
  97.  
  98. gdisp_mode    db    0        ; digital(0)/analogue(1) display
  99. gplane_nums    db    3        ; number of graphic planes (3 or 4)
  100. gplane_actv    dw    15        ; active plane mask
  101. gplane_segm    dw    0A800h        ; CPU segment address of G-VRAM
  102.         dw    0B000h
  103.         dw    0B800h
  104.         dw    0E000h
  105. ;
  106. pc98_mouse_type    db    1
  107. pc98_mouse_init    db    0
  108. pc98_mouse_char    db    0,'1','2','3'
  109. ;
  110. tek_dialog_area    db    0
  111. tek_dialog_vsbl    db    0
  112. ;
  113. ; Color mode
  114. ; <int1> 0: no change       <int2>  0: no change    <int3> 0:nochange
  115. ;        1: RGB [0-100]             1: opake               1:color
  116. ;        2: CMY [0-100]             2: sub                 2:monochrome
  117. ;        3: HLS                     3: add
  118. ;        4: RGB [0-255]
  119. ;
  120. tek_cmode_1    db    3
  121. tek_cmode_2    db    1
  122. tek_cmode_3    db    1
  123.         db    0        ; for alignment
  124. ;
  125. ; Window and Viewport (Ordering is important.)
  126. ;
  127. tek_wnx1    dw    0
  128. tek_wnx2    dw    4095
  129. tek_wny1    dw    0
  130. tek_wny2    dw    3071
  131. ;
  132. tek_vpx1    dw    0
  133. tek_vpx2    dw    4095
  134. tek_vpy1    dw    0
  135. tek_vpy2    dw    3071
  136. ;
  137. ; Transformation Matrix from Window to Viewport.
  138. ; 16-bit fixed decimal point number.
  139. ;
  140. tek_w2v_mat    dw    8 dup (?)
  141. ;
  142. ; Window/Viewport for GIN (Viewport must be first)
  143. ;
  144. gin_vpx1    dw    0
  145. gin_vpx2    dw    479
  146. gin_vpy1    dw    0
  147. gin_vpy2    dw    359
  148. ;
  149. gin_wnx1    dw    0
  150. gin_wnx2    dw    4095
  151. gin_wny1    dw    0
  152. gin_wny2    dw    3071
  153. ;
  154. ; Viewport to Window transformation matrix
  155. ;
  156. gin_v2w_mat    dw    8 dup (?)
  157. ;
  158. ;
  159. ; Character vectors
  160. ;
  161. tek_gtxt_ang    dw    0
  162. tek_gtxt_w    dw    39
  163. tek_gtxt_h    dw    52
  164. tek_gtxt_s    dw    13
  165. tek_gtxt_dr    db    2, 0        ; graph text dir for GDC
  166. tek_gtxt_ux    dw    52
  167. tek_gtxt_uy    dw    0
  168. tek_gtxt_vx    dw    0
  169. tek_gtxt_vy    dw    52
  170. ;
  171. sixel_replace    db    1, 0
  172. sixel_state    db    0
  173. sixel_char    db    0
  174. sixel_on    db    0
  175. sixel_off    db    0
  176. sixel_x        dw    0
  177. sixel_y        dw    0
  178. repeat_count    dw    0
  179. sixel_byte    dw    0
  180. sixel_segm    dw    0
  181. ;
  182. vt_buf        db    8 dup (?)
  183. vt_dialog_clr    db    7,ESCAPE,"[2J",ESCAPE,"[H"
  184. ;
  185. tek_zero    dw    0        ; Zero for clearing mode line
  186. tek_cur_x    dw    0        ; TEK current position x
  187. tek_cur_y    dw    0        ; TEK current position y
  188. tek_req_x    dw    0        ; TEK requested position x
  189. tek_req_y    dw    0        ; TEK requested position y
  190. ;
  191. tek_lncol    dw    1        ; TEK line color
  192. tek_txcol    dw    1        ; TEK text color
  193. tek_facol    dw    1        ; TEK fill area color
  194. ;
  195. loc_x        dw    0        ; locator position in DC
  196. loc_y        dw    0
  197. loc_mov        dw    0
  198. ;
  199. tek_npnt    dw    0
  200. ;
  201. line_type    dw    0
  202. line_type_table    dw    0FFFFh
  203.         dw    08888h
  204.         dw    0E4E4h
  205.         dw    0F0F0h
  206.         dw    0FF00h
  207.         dw    0927Ch
  208.         dw    0FF18h
  209.         dw    0CCCCh
  210. ;
  211. marker_type    dw    0
  212. ;
  213. tek41_cmd    dw    0
  214. tek41_func    dw    0
  215. tek41_nget    dw    0
  216. tek41_narg    dw    0
  217. tek41_nreq    db    0        ; next requested data type
  218. tek41_nact    db    0        ; next action
  219. tek41_argt    db    8 dup (0)
  220. tek41_ival    dw    0
  221. ;
  222. tek_P_prv    db    0,0
  223. tek_P_num    dw    0
  224. tek_P_pnt    dw    0
  225. tek_P_buf    dw    32 dup (0)
  226. ;
  227. tek_vseq    db    0
  228. tek_cur_HIY    db    0
  229. tek_cur_EXT    db    0
  230. tek_cur_LOY    db    0
  231. tek_cur_HIX    db    0
  232. tek_cur_LOX    db    0
  233. ;
  234. tek_mod        db    0        ; 0=Alpha,1=Vector,2=Plot,3=Increment
  235. tek_esc        db    0        ; 1=TEK in esc-seq, 2= in CSI-seq
  236. tek_byp        db    0        ; 1=Bypass mode
  237. tek_cur        db    0        ; 0=Alpha cursor off, 1=on
  238. tek_pen        db    0        ; 0=Pen Up, 1=Pen down
  239. tek_hgt        db    0        ; 0=Normal, 1=HighLight
  240. ;
  241. tek_inpanel    db    0
  242. tek_panel_bnd    db    0
  243. tek_famod    db    0
  244. tek_fapat    db    0
  245. ;
  246. tek_col0    db    0,1,2,3,4,5,6,7    ; default color index table
  247. ;
  248. ; Default Tek mode color table (R,G,B)  [0-255]
  249. ;
  250. tek_col_def    db    000h,000h,000h    ;  0:black
  251.         db    0ffh,0ffh,0ffh    ;  1:white
  252.         db    0ffh,000h,000h    ;  2:red
  253.         db    000h,0ffh,000h    ;  3:green
  254.         db    000h,000h,0ffh    ;  4:blue
  255.         db    000h,0ffh,0ffh    ;  5:cyan
  256.         db    0ffh,000h,0ffh    ;  6:magenta
  257.         db    0ffh,0ffh,000h    ;  7:yellow
  258.         db    0ffh,0afh,000h    ;  8:orange
  259.         db    0afh,0ffh,000h    ;  9:yellow-green
  260.         db    000h,0ffh,0afh    ; 10:green-cyan
  261.         db    000h,0afh,0ffh    ; 11:blue-cyan
  262.         db    0afh,000h,0ffh    ; 12:blue-magenta
  263.         db    0ffh,000h,0afh    ; 13:red-magenta
  264.         db    07fh,07fh,07fh    ; 14:dark-gray
  265.         db    0afh,0afh,0afh    ; 15:light-gray
  266. ;
  267. ; Tek mode color table (R,G,B)  [0-255]
  268. ;
  269. tek_col        db    000h,000h,000h    ;  0:black
  270.         db    0ffh,0ffh,0ffh    ;  1:white
  271.         db    0ffh,000h,000h    ;  2:red
  272.         db    000h,0ffh,000h    ;  3:green
  273.         db    000h,000h,0ffh    ;  4:blue
  274.         db    000h,0ffh,0ffh    ;  5:cyan
  275.         db    0ffh,000h,0ffh    ;  6:magenta
  276.         db    0ffh,0ffh,000h    ;  7:yellow
  277.         db    0ffh,0afh,000h    ;  8:orange
  278.         db    0afh,0ffh,000h    ;  9:yellow-green
  279.         db    000h,0ffh,0afh    ; 10:green-cyan
  280.         db    000h,0afh,0ffh    ; 11:blue-cyan
  281.         db    0afh,000h,0ffh    ; 12:blue-magenta
  282.         db    0ffh,000h,0afh    ; 13:red-magenta
  283.         db    07fh,07fh,07fh    ; 14:dark-gray
  284.         db    0afh,0afh,0afh    ; 15:light-gray
  285. ;
  286. ; Sixel mode color table (R,G,B)  [0-255]
  287. ; Note that only plane #3 is used for sixel.
  288. ;
  289. sixel_col0    db    000h,000h,000h    ;  0:black
  290.         db    000h,000h,000h    ;  1
  291.         db    000h,000h,000h    ;  2
  292.         db    000h,000h,000h    ;  3
  293.         db    0ffh,0ffh,0ffh    ;  4
  294.         db    0ffh,0ffh,0ffh    ;  5
  295.         db    0ffh,0ffh,0ffh    ;  6
  296.         db    0ffh,0ffh,0ffh    ;  7
  297.         db    000h,000h,000h    ;  8
  298.         db    000h,000h,000h    ;  9
  299.         db    000h,000h,000h    ; 10
  300.         db    000h,000h,000h    ; 11
  301.         db    0ffh,0ffh,0ffh    ; 12
  302.         db    0ffh,0ffh,0ffh    ; 13
  303.         db    0ffh,0ffh,0ffh    ; 14
  304.         db    0ffh,0ffh,0ffh    ; 15
  305. ;
  306. sixel_col    db    000h,000h,000h    ;  0:black
  307.         db    000h,000h,000h    ;  1
  308.         db    000h,000h,000h    ;  2
  309.         db    000h,000h,000h    ;  3
  310.         db    0ffh,0ffh,0ffh    ;  4
  311.         db    0ffh,0ffh,0ffh    ;  5
  312.         db    0ffh,0ffh,0ffh    ;  6
  313.         db    0ffh,0ffh,0ffh    ;  7
  314.         db    000h,000h,000h    ;  8
  315.         db    000h,000h,000h    ;  9
  316.         db    000h,000h,000h    ; 10
  317.         db    000h,000h,000h    ; 11
  318.         db    0ffh,0ffh,0ffh    ; 12
  319.         db    0ffh,0ffh,0ffh    ; 13
  320.         db    0ffh,0ffh,0ffh    ; 14
  321.         db    0ffh,0ffh,0ffh    ; 15
  322. ;
  323. tek41_col    db    0,7,2,4,1,5,3,6
  324.         db    7,7,2,4,1,5,3,6
  325. ;
  326. disp_bank    db    0
  327. actv_bank    db    0
  328. ;
  329. tek41_larg    dw    0
  330. tek41_argbuf    db    TEK41_ARGBUF_SIZE dup (?)
  331.         dw    0                ; for guard
  332. tek41_lstr    dw    0        ; string length
  333. tek41_nchr    dw    0        ; number of char gotten
  334. tek41_liar    dw    0        ; INT array size
  335. tek41_niar    dw    0        ; number of INT gotten
  336. tek41_faadr    dw    0
  337. tek41_numbnd    dw    0
  338. tek41_nfa    dw    0
  339. tek41_lfa    dw    0
  340. tek41_fabuf    db    TEK41_FABUF_SIZE dup (?)
  341. ;
  342. scan_n        dw    0                ; number of lines
  343. scan_x        dw    0
  344. scan_y        dw    0
  345. scan_ofs    dw    0        ; offset address in the graphic plane
  346. scan_xstr    dw    0
  347. scan_xlen    dw    0
  348. scan_xmin    dw    0
  349. scan_xmax    dw    0
  350. scan_ymin    dw    0
  351. scan_ymax    dw    0
  352. ;
  353. scan_buf    db    80 dup (?)
  354. scan_fil    db    0, 0
  355. ;
  356. pc98_x1        dw    0
  357. pc98_y1        dw    0
  358. pc98_x2        dw    0
  359. pc98_y2        dw    0
  360. ;
  361. HLS_n1        dw    0
  362. HLS_n2        dw    0
  363. ;
  364. ggdc_buff    db    80 dup (?)
  365. loc_x_buff    db    32 dup (?)
  366. loc_y_buff    db    32 dup (?)
  367. alp_cur_buff    db    48 dup (?)
  368. ;
  369. alp_cur_font    db    000h,000h,000h,000h,000h,07eh,07eh,000h
  370. ;
  371. GDC_plane_address    db    040h, 080h, 0C0h, 000h
  372. col_indx_tab_N    db    0, 2, 4, 6, 1, 3, 5, 7    ; color index for Normal
  373. col_indx_tab_H    db    7, 2, 4, 6, 1, 3, 5, 7    ; color index for HighLight
  374. ;
  375. ext_gin        db    023h,000h,0FFh,000h
  376. ent_gin        db    021h,000h            ; complement
  377.         db    078h,008h
  378.         db    0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh
  379.         db    0FFh,000h
  380. gin_ans        db    006h,020h,020h,020h,020h,020h,00Dh,004h
  381. ;
  382. ggdc_solid    db    078h,008h
  383.         db    0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh,0FFh
  384.         db    0FFh,000h
  385. ggdc_on        db    00Dh,000h,0FFh,000h
  386. ggdc_off    db    00Ch,000h,0FFh,000h
  387. ;
  388. ggdc_set    db    04Bh,001h,000h            ; CSFORM
  389.         db    070h,004h,000h,000h,000h,019h    ; SCROLL
  390.         db    023h,000h            ; WRITE MODE SET
  391.         db    0FFh                ; terminator
  392. ;
  393. bit_on    db    080h, 040h, 020h, 010h, 008h, 004h, 002h, 001h
  394. bit_off    db    07Fh, 0BFh, 0DFh, 0EFh, 0F7h, 0FBh, 0FDh, 0FEh
  395. ;------------------------------------------------------------------------------
  396. ; 8 x 8 marker font
  397. ;
  398. ; offset
  399. ;
  400. mark_dx        dw    -4
  401. mark_dy        dw    4
  402. ;
  403. gmark88    db    000h,000h,000h,008h,000h,000h,000h,000h    ; dot
  404.     db    000h,000h,008h,01ch,008h,000h,000h,000h ; small plus
  405.     db    008h,008h,008h,07fh,008h,008h,008h,000h ; large plus
  406.     db    041h,022h,014h,07fh,014h,022h,041h,000h    ; star
  407.     db    01ch,022h,041h,041h,041h,022h,01ch,000h    ; circle
  408.     db    041h,022h,014h,008h,014h,022h,041h,000h    ; cross
  409.     db    07fh,041h,041h,041h,041h,041h,07fh,000h    ; square
  410.     db    008h,014h,022h,041h,022h,014h,008h,000h    ; 
  411.     db    07fh,041h,049h,05dh,049h,041h,07fh,000h    ; square-dot
  412.     db    008h,014h,02ah,05dh,02ah,014h,008h,000h    ;
  413.     db    07fh,063h,055h,049h,055h,063h,07fh,000h    ; square-cross
  414. ;------------------------------------------------------------------------------
  415. ; text font table (8 x 8)
  416. ;
  417. gfont88    db      000h,000h,000h,000h,000h,000h,000h,000h    ; space
  418.     db    008h,008h,008h,008h,000h,000h,008h,000h    ; !
  419.     db    022h,022h,022h,000h,000h,000h,000h,000h    ; "
  420.     db    024h,024h,07eh,024h,07eh,024h,024h,000h    ; #
  421.     db      008h,07eh,009h,03eh,048h,03fh,008h,000h    ; $
  422.         db      043h,021h,010h,008h,004h,042h,061h,000h    ; %
  423.         db      006h,009h,009h,006h,049h,031h,04eh,000h    ; &
  424.         db      018h,010h,008h,000h,000h,000h,000h,000h    ; '
  425.         db      010h,008h,004h,004h,004h,008h,010h,000h    ; (
  426.         db      004h,008h,010h,010h,010h,008h,004h,000h    ; )
  427.         db      000h,022h,014h,07fh,014h,022h,000h,000h ; *
  428.         db      000h,008h,008h,07fh,008h,008h,000h,000h    ; +
  429.         db      000h,000h,000h,000h,00ch,008h,004h,000h    ; ,
  430.         db      000h,000h,000h,03eh,000h,000h,000h,000h    ; -
  431.         db      000h,000h,000h,000h,000h,00ch,00ch,000h    ; .
  432.         db      040h,020h,010h,008h,004h,002h,001h,000h    ; /
  433.         db      03ch,062h,052h,05ah,046h,046h,03ch,000h    ; 0
  434.         db      008h,00ch,008h,008h,008h,008h,01ch,000h    ; 1
  435.         db      01ch,022h,020h,018h,004h,002h,03eh,000h    ; 2
  436.         db      03eh,020h,010h,018h,020h,022h,01ch,000h    ; 3
  437.         db      010h,018h,014h,012h,03fh,010h,010h,000h    ; 4
  438.         db      03eh,002h,01eh,022h,020h,022h,01ch,000h    ; 5
  439.         db      018h,004h,002h,01eh,022h,022h,01ch,000h    ; 6
  440.         db      03eh,020h,010h,008h,004h,004h,004h,000h    ; 7
  441.         db      03ch,042h,042h,03ch,042h,042h,03ch,000h    ; 8
  442.         db      01ch,022h,022h,03ch,020h,010h,008h,000h    ; 9
  443.         db      000h,00ch,00ch,000h,00ch,00ch,000h,000h    ; :
  444.         db      000h,00ch,00ch,000h,00ch,008h,004h,000h    ; ;
  445.         db      020h,010h,008h,004h,008h,010h,020h,000h    ; <
  446.         db      000h,000h,07eh,000h,07eh,000h,000h,000h    ; =
  447.         db      002h,004h,008h,010h,008h,004h,002h,000h    ; >
  448.         db      03ch,042h,030h,008h,008h,000h,008h,000h    ; ?
  449.         db      03ch,042h,071h,049h,039h,002h,03ch,000h    ; @
  450.         db      01ch,022h,022h,03eh,022h,022h,022h,000h    ; A
  451.         db      01fh,022h,022h,01eh,022h,022h,01fh,000h    ; B
  452.         db      01ch,022h,002h,002h,002h,022h,01ch,000h    ; C
  453.         db      01fh,022h,022h,022h,022h,022h,01fh,000h    ; D
  454.         db      03eh,002h,002h,01eh,002h,002h,03eh,000h    ; E
  455.         db      03eh,002h,002h,01eh,002h,002h,002h,000h    ; F
  456.         db      01ch,022h,002h,002h,072h,022h,01ch,000h    ; G
  457.         db      022h,022h,022h,03eh,022h,022h,022h,000h    ; H
  458.         db      01ch,008h,008h,008h,008h,008h,01ch,000h    ; I
  459.         db      070h,020h,020h,020h,022h,022h,01ch,000h    ; J
  460.         db      042h,022h,012h,00eh,012h,022h,042h,000h    ; K
  461.         db      002h,002h,002h,002h,002h,002h,03eh,000h    ; L
  462.         db      041h,063h,055h,049h,041h,041h,041h,000h    ; M
  463.         db      042h,046h,04ah,052h,062h,042h,042h,000h    ; N
  464.         db      01ch,022h,022h,022h,022h,022h,01ch,000h    ; O
  465.         db      01eh,022h,022h,01eh,002h,002h,002h,000h    ; P
  466.         db      03ch,042h,042h,042h,052h,022h,05ch,000h    ; Q
  467.         db      01eh,022h,022h,01eh,012h,022h,042h,000h    ; R
  468.         db      01ch,022h,002h,01ch,020h,022h,01ch,000h    ; S
  469.         db      03eh,008h,008h,008h,008h,008h,008h,000h    ; T
  470.         db      022h,022h,022h,022h,022h,022h,01ch,000h    ; U
  471.         db      041h,041h,022h,022h,014h,014h,008h,000h    ; V
  472.         db      041h,041h,041h,041h,049h,055h,022h,000h    ; W
  473.         db      041h,022h,014h,008h,014h,022h,041h,000h    ; X
  474.         db      041h,022h,014h,008h,008h,008h,008h,000h    ; Y
  475.         db      03eh,020h,010h,008h,004h,002h,03eh,000h    ; Z
  476.         db      038h,008h,008h,008h,008h,008h,038h,000h    ; [
  477.         db      001h,002h,004h,008h,010h,020h,040h,000h    ; backslash
  478.         db      00eh,008h,008h,008h,008h,008h,00eh,000h    ; ]
  479.         db      008h,014h,022h,000h,000h,000h,000h,000h    ; ^
  480.         db      000h,000h,000h,000h,000h,000h,07fh,000h    ; _
  481.     db    018h,008h,000h,000h,000h,000h,000h,000h    ; left quote
  482.     db    000h,000h,01ch,020h,03ch,022h,07ch,000h    ; a
  483.     db    002h,002h,01ah,026h,022h,022h,01eh,000h    ; b
  484.     db    000h,000h,01ch,022h,002h,002h,03ch,000h    ; c
  485.         db    020h,020h,02ch,032h,022h,022h,03ch,000h    ; d
  486.     db    000h,000h,01ch,022h,01eh,002h,03ch,000h    ; e
  487.     db    038h,044h,004h,01eh,004h,004h,004h,000h    ; f
  488.     db    000h,000h,01ch,022h,022h,03ch,022h,01ch    ; g
  489.     db    002h,002h,01ah,026h,022h,022h,022h,000h    ; h
  490.     db    008h,000h,008h,008h,008h,008h,010h,000h    ; i
  491.     db    020h,000h,020h,020h,020h,020h,022h,01ch    ; j
  492.     db    002h,002h,022h,012h,01ah,026h,042h,000h    ; k
  493.     db    008h,008h,008h,008h,008h,008h,010h,000h    ; l
  494.     db    000h,000h,037h,049h,049h,049h,041h,000h    ; m
  495.     db    000h,000h,03ah,046h,042h,042h,042h,000h    ; n
  496.     db    000h,000h,01ch,022h,022h,022h,01ch,000h    ; o
  497.     db    000h,000h,01eh,022h,022h,01eh,002h,002h    ; p
  498.     db    000h,000h,01ch,022h,022h,03ch,020h,060h    ; q
  499.     db    000h,000h,03ah,046h,002h,002h,002h,000h    ; r
  500.     db    000h,000h,03ch,002h,01ch,020h,01eh,000h    ; s
  501.     db    008h,008h,03eh,008h,008h,008h,030h,000h    ; t
  502.     db    000h,000h,022h,022h,022h,022h,05ch,000h    ; u
  503.     db    000h,000h,022h,022h,022h,014h,008h,000h    ; v
  504.     db    000h,000h,041h,041h,049h,049h,036h,000h    ; w
  505.     db    000h,000h,022h,014h,008h,014h,022h,000h    ; x
  506.     db    000h,000h,022h,022h,022h,03ch,022h,01ch    ; y
  507.     db    000h,000h,03eh,010h,008h,004h,03eh,000h    ; z
  508.     db    030h,008h,010h,00eh,010h,008h,030h,000h    ; {
  509.     db    008h,008h,008h,000h,008h,008h,008h,000h    ; |
  510.     db    006h,008h,004h,038h,004h,008h,006h,000h    ; }
  511.     db    000h,040h,03ch,002h,000h,000h,000h,000h    ; ~
  512.     db    012h,049h,024h,012h,049h,024h,012h,049h    ; del
  513. ;---------------------------------------------------------------------------
  514. func41    dw    'LE'
  515.     dw    tek41_exec_LE
  516.     db    0,0,0,0,0,0
  517. ;
  518.     dw    'LP'
  519.     dw    tek41_exec_LP
  520.     db    2,TEK41_XY_TYPE,TEK41_INT_TYPE,0,0,0
  521. ;
  522.     dw    'LV'
  523.     dw    tek41_exec_LV
  524.     db    1,TEK41_INT_TYPE,0,0,0,0
  525. ;
  526.     dw    'LZ'
  527.     dw    tek41_exec_LZ
  528.     db    0,0,0,0,0,0
  529. ;
  530.     dw    'KA'
  531.     dw    tek41_exec_KA
  532.     db    1,TEK41_INT_TYPE,0,0,0,0
  533. ;
  534.     dw    'LG'            ; draw
  535.     dw    tek41_exec_LG
  536.     db    1,TEK41_XY_TYPE,0,0,0,0
  537. ;
  538.     dw    'LF'            ; move
  539.     dw    tek41_exec_LF
  540.     db    1,TEK41_XY_TYPE,0,0,0,0
  541. ;
  542.     dw    'LH'            ; marker
  543.     dw    tek41_exec_LH
  544.     db    1,TEK41_XY_TYPE,0,0,0,0
  545. ;
  546.     dw    'LT'            ; graphic text
  547.     dw    tek41_exec_LT
  548.     db    1,TEK41_STR_TYPE,0,0,0,0
  549. ;
  550.     dw    'MC'            ; set graphtext size
  551.     dw    tek41_exec_MC
  552.     db    3,TEK41_INT_TYPE,TEK41_INT_TYPE,TEK41_INT_TYPE,0,0
  553. ;
  554.     dw    'ML'            ; set line color index
  555.     dw    tek41_exec_ML
  556.     db    1,TEK41_INT_TYPE,0,0,0,0
  557. ;
  558.     dw    'MM'            ; set marker type
  559.     dw    tek41_exec_MM
  560.     db    1,TEK41_INT_TYPE,0,0,0,0
  561. ;
  562.     dw    'MP'            ; set fill pattern
  563.     dw    tek41_exec_MP
  564.     db    1,TEK41_INT_TYPE,0,0,0,0
  565. ;
  566.     dw    'MR'            ; set graphtext rotation
  567.     dw    tek41_exec_MR
  568.     db    2,TEK41_INT_TYPE,TEK41_INT_TYPE,0,0,0
  569. ;
  570.     dw    'MT'            ; set text color index
  571.     dw    tek41_exec_MT
  572.     db    1,TEK41_INT_TYPE,0,0,0,0
  573. ;
  574.     dw    'MV'            ; set line style
  575.     dw    tek41_exec_MV
  576.     db    1,TEK41_INT_TYPE,0,0,0,0
  577. ;
  578.     dw    'NM'            ; set prompt mode
  579.     dw    tek41_exec_none
  580.     db    1,TEK41_INT_TYPE,0,0,0,0
  581. ;
  582.     dw    'RW'            ; set window
  583.     dw    tek41_exec_RW
  584.     db    2,TEK41_XY_TYPE,TEK41_XY_TYPE,0,0,0
  585. ;
  586.     dw    'TG'            ; set surface color map
  587.     dw    tek41_exec_TG
  588.     db    2,TEK41_INT_TYPE,TEK41_IAR_TYPE,0,0,0
  589. ;
  590.     dw    'TM'            ; set color mode
  591.     dw    tek41_exec_TM
  592.     db    3,TEK41_INT_TYPE,TEK41_INT_TYPE,TEK41_INT_TYPE,0,0
  593. ;
  594.     dw    '%!'            ; set command
  595.     dw    tek41_exec_SETCOM
  596.     db    1,TEK41_INT_TYPE,0,0,0,0
  597. ;
  598.     dw    0
  599.     dw    tek41_exec_unknown
  600.     db    0,0,0,0,0,0
  601. ;----------------------------------------------
  602. tek_stat_msg    db    CR,LF,"  Tek status: "
  603. tek_pmode_msg    db    "        "
  604.         db    "  color mode: "
  605. tek_cmode_msg    db    "3 1 1 "
  606.         db    "  mouse: "
  607. tek_mouse_msg    db    "      "
  608.         db    CR,LF,"  Tek Last Unknown command: "
  609. tek_unkwn_msg    dw    '  '
  610.         db    "  Tek Last Ignored command: "
  611. tek_ignor_msg    dw    '  '
  612. tek_test1_msg    db    ' '
  613. tek_test2_msg    db    ' '
  614. tek_test3_msg    db    ' '
  615. tek_test4_msg    db    ' '
  616.         db    '$'
  617. ;----------------------------------------------
  618. data    ends
  619.  
  620. code    segment    public 'code'
  621.  
  622.     extrn    vt100_modlin:near
  623.     extrn    outcapt:near
  624.     extrn    set_cur_color:near
  625.     extrn    set_cursor:near        ; in MSZP98
  626.     extrn    text_scrn:near        ; in MSZP98
  627.     extrn    pc98_bell:near
  628.  
  629.     assume    cs:code,ds:data,es:nothing
  630.  
  631. TEK41_W2V    PROC    NEAR
  632. ;
  633. ; Input  (ax,bx) -- coordinate in window
  634. ;          [si]  -- transformation matrix
  635. ; Output (ax,bx) -- coordinate in viewport
  636. ;
  637. ; format of the transformation matrix
  638. ;   xv = (xw - wx0)*mx + vx0
  639. ;   yv = (yw - wy0)*my + vy0
  640. ;
  641. ;   [si   ]  mx_l
  642. ;   [si+ 2]  mx_h
  643. ;   [si+ 4]  wx0
  644. ;   [si+ 6]  vx0
  645. ;   [si+ 8]  my_l
  646. ;   [si+10]  my_h
  647. ;   [si+12]  wy0
  648. ;   [si+14]  vy0
  649. ;
  650.     push    cx
  651.     push    dx
  652.     push    si
  653.     push    di
  654. ;
  655.     mov    di,bx            ; save y
  656. ;
  657.     sub    ax,[si+ 4]
  658.     push    ax            ; save (x-wx0)
  659.     xor    cx,cx
  660.     cmp    ax,0
  661.     jge    tek41_w2v_1
  662.     mov    cl,1
  663.     neg    ax
  664. tek41_w2v_1:
  665.     mul    WORD PTR [si]        ; low word
  666.     mov    bx,dx
  667.     pop    ax
  668.     mul    WORD PTR [si+ 2]    ; high word
  669.     add    bx,ax
  670.     jcxz    tek41_w2v_2
  671.     neg    bx
  672. tek41_w2v_2:
  673.     add    bx,[si+ 6]
  674. ;
  675.     mov    ax,di            ; get y
  676.     mov    di,bx            ; save result x
  677.     sub    ax,[si+12]
  678.     push    ax            ; save (y-wy0)
  679.     xor    cx,cx
  680.     cmp    ax,0
  681.     jge    tek41_w2v_3
  682.     mov    cl,1
  683.     neg    ax
  684. tek41_w2v_3:
  685.     mul    WORD PTR [si+ 8]    ; low word
  686.     mov    bx,dx
  687.     pop    ax
  688.     mul    WORD PTR [si+10]    ; high word
  689.     add    bx,ax
  690.     jcxz    tek41_w2v_4
  691.     neg    bx
  692. tek41_w2v_4:
  693.     add    bx,[si+14]
  694.     mov    ax,di
  695. ;
  696.     pop    di
  697.     pop    si
  698.     pop    dx
  699.     pop    cx
  700. ;
  701.     ret
  702. TEK41_W2V    ENDP
  703. ;-----------------------------------------------------------------------
  704. ; TEK4010/4014 terminal emulator
  705. ;-----------------------------------------------------------------------
  706. TEK40_DEV_COOD    PROC    NEAR
  707. ;
  708. ;  Transform TEK4014 coordinates to PC9801 device coordinates
  709. ;    Inputs:
  710. ;      AX: TEK4014 X coordinate ( to be replaced by device x )
  711. ;      BX: TEK4014 Y coordinate ( to be replaced by device y )
  712. ;    Outputs:
  713. ;      AX: Device X coordinate
  714. ;      BX: Device Y coordinate
  715. ;
  716.     push    si
  717.     mov    si,offset tek_w2v_mat
  718.     call    tek41_w2v
  719.     pop    si
  720. ;
  721.     push    cx
  722.     cmp    bx,399
  723.     jle    tek40_dev_cood_1
  724.     mov    bx,399
  725. tek40_dev_cood_1:
  726.     mov    cx,399
  727.     sub    cx,bx
  728.     xchg    bx,cx
  729.     cmp    ax,639
  730.     jle    tek40_dev_cood_2
  731.     mov    ax,639
  732. tek40_dev_cood_2:
  733.     pop    cx
  734.     ret
  735. ;
  736. TEK40_DEV_COOD    ENDP
  737. ;
  738. ;
  739. TEK40_GIN    PROC    NEAR
  740. ;
  741. ;  Request locator
  742. ;
  743. ;  If we are using mouse, set the position
  744. ;
  745.     mov    pc98_mouse_type,0
  746.     test    vtgrph_flg,MOUSE_BIT        ; mouse on ?
  747.     jz    tek40_gin_00            ; no.
  748. tek40_gin_m01:
  749.     mov    ax,0                ; init mouse
  750.     mov    bx,0
  751.     int    33h
  752.     cmp    ax,-1                ; mouse available ?
  753.     jne    tek40_gin_00
  754.     cmp    bx,2                ; MS-mouse ?
  755.     jne    tek40_gin_m02            ; ne=no.
  756.     mov    pc98_mouse_type,2
  757.     jmp    tek40_gin_m03
  758. tek40_gin_m02:
  759.     mov    pc98_mouse_type,1
  760. tek40_gin_m03:
  761.     mov    cx,loc_x
  762.     mov    dx,loc_y
  763.     mov    ax,4                ; locate mouse
  764.     int    33h
  765. tek40_gin_00:
  766.     mov    si,offset ent_gin        ; write mode is complement
  767.     call    send_to_GGDC
  768.     mov    loc_mov,3
  769. ;
  770. ;    Draw X axis
  771. ;
  772. tek40_gin_01:
  773.     test    loc_mov,1
  774.     jz    tek40_gin_02
  775.     mov    di,offset loc_x_buff
  776.     mov    ax,gin_vpx1
  777.     mov    bx,loc_y
  778.     mov    cx,GGDC_GIN_PLANE        ; locator graphic plane
  779.     call    gcsrw
  780.     mov    ax,gin_vpx2
  781.     sub    ax,gin_vpx1
  782.     mov    bx,0
  783.     call    gline
  784.     mov    byte ptr [di],0FFh
  785.     mov    si,offset loc_x_buff
  786.     call    send_to_GGDC
  787. ;
  788. ;    Draw Y axis
  789. ;
  790. tek40_gin_02:
  791.     test    loc_mov,2
  792.     jz    tek40_gin_10
  793.     mov    di,offset loc_y_buff
  794.     mov    ax,loc_x
  795.     mov    bx,399
  796.     sub    bx,gin_vpy2
  797.     mov    cx,GGDC_GIN_PLANE
  798.     call    gcsrw
  799.     mov    ax,0
  800.     mov    bx,gin_vpy2
  801.     sub    bx,gin_vpy1
  802.     call    gline
  803.     mov    byte ptr [di],0FFh
  804.     mov    si,offset loc_y_buff
  805.     call    send_to_GGDC
  806. ;
  807. tek40_gin_10:
  808.     cmp    pc98_mouse_type,0        ; using mouse ?
  809.     jne    tek40_gin_m10            ; ne=yes.
  810.     jmp    tek40_gin_11
  811. tek40_gin_m10:
  812.     mov    ax,3
  813.     int    33h
  814.     cmp    pc98_mouse_type,1        ; NEC type ?
  815.     jne    tek40_gin_m12            ; ne=no.
  816.     and    ax,01h
  817.     and    bx,02h
  818.     or    bx,ax                ; MS-mouse method
  819. tek40_gin_m12:
  820.     and    bx,03h
  821.     cmp    bx,0
  822.     jne    tek40_gin_m14
  823.     cmp    cx,loc_x
  824.     jne    tek40_gin_m14
  825.     cmp    dx,loc_y
  826.     jne    tek40_gin_m14
  827.     mov    ah,01h                ; sense keyboard buffer
  828.     int    BIOS
  829.     cmp    bh,0
  830.     je    tek40_gin_m10
  831.     mov    ah,00h                ; read keyboard buffer
  832.     int    BIOS
  833.     jmp    tek40_gin_ex
  834. tek40_gin_m14:
  835.     mov    loc_x,cx
  836.     mov    loc_y,dx
  837.     cmp    bx,0
  838.     je    tek40_gin_m16
  839.     mov    ax,bx
  840.     mov    bx,offset pc98_mouse_char
  841.     add    bx,ax
  842.     mov    al,[bx]
  843.     jmp    tek40_gin_ex
  844. ;
  845. tek40_gin_m16:
  846.     mov    si,offset loc_x_buff
  847.     call    send_to_GGDC
  848.     mov    si,offset loc_y_buff
  849.     call    send_to_GGDC
  850.     mov    loc_mov,3
  851.     jmp    tek40_gin_01
  852. ;
  853. ;    If we are using mouse, read mouse.
  854. ;    Otherwise, scan Keyboard
  855. ;
  856. tek40_gin_11:
  857.     mov    dx,1
  858.     mov    ah,1            ; sense keyborad buffer
  859.     int    18h            ; BIOS call
  860.     cmp    bh,0
  861.     je    tek40_gin_11
  862. ;
  863.     mov    ah,2            ; sense shift keys
  864.     int    18h
  865.     test    al,1            ; SHIFT key pressed ?
  866.     jz    tek40_gin_12
  867.     mov    dx,4
  868. tek40_gin_12:
  869.     test    al,16            ; CTRL key pressed ?
  870.     jz    tek40_gin_13
  871.     mov    dx,8
  872. tek40_gin_13:
  873. ;
  874.     mov    ah,0            ; read keyboard buffer
  875.     int    18h
  876. ;
  877.     mov    loc_mov,0
  878. ;
  879.     cmp    ax,03A00h        ; UP
  880.     je    tek40_gin_up
  881.     cmp    ax,03D00h
  882.     je    tek40_gin_down
  883.     cmp    ax,03B00h
  884.     je    tek40_gin_left
  885.     cmp    ax,03C00h
  886.     je    tek40_gin_right
  887. ;
  888. ;    Alpha-Numeric key.
  889. ;
  890.     jmp    tek40_gin_ex
  891. ;
  892. tek40_gin_up:
  893.     sub    loc_y,dx
  894.     cmp    loc_y,9-Y_OFS
  895.     jge    tek40_gin_y
  896.     mov    loc_y,9-Y_OFS
  897.     jmp    tek40_gin_y
  898. tek40_gin_down:
  899.     add    loc_y,dx
  900.     cmp    loc_y,399-Y_OFS
  901.     jle    tek40_gin_y
  902.     mov    loc_y,399-Y_OFS
  903. tek40_gin_y:
  904. ;    erase X axis
  905.     mov    si,offset loc_x_buff
  906.     or    loc_mov,1
  907.     jmp    tek40_gin_xy
  908. ;
  909. tek40_gin_left:
  910.     sub    loc_x,dx
  911.     cmp    loc_x,X_OFS
  912.     jge    tek40_gin_x
  913.     mov    loc_x,X_OFS
  914.     jmp    tek40_gin_x
  915. tek40_gin_right:
  916.     add    loc_x,dx
  917.     cmp    loc_x,511+X_OFS
  918.     jle    tek40_gin_x
  919.     mov    loc_x,511+X_OFS
  920. tek40_gin_x:
  921.     mov    si,offset loc_y_buff
  922.     or    loc_mov,2
  923. tek40_gin_xy:
  924.     call    send_to_GGDC
  925.     jmp    tek40_gin_01
  926. ;
  927. tek40_gin_ex:
  928. ;
  929. ;    set-up answerback
  930. ;
  931.     mov    si,offset gin_ans
  932.     mov    [si+1],al        ; Keyboard character
  933. ;
  934.     mov    si,offset gin_v2w_mat
  935.     mov    ax,loc_x
  936.     mov    bx,399
  937.     sub    bx,loc_y
  938.     call    tek41_w2v
  939.     shr    ax,1
  940.     shr    ax,1            ; convert to 10-bit address
  941.     shr    bx,1
  942.     shr    bx,1            ; convert to 10-bit address
  943. ;
  944.     mov    si,offset gin_ans
  945.     push    bx            ; save Y
  946. ;
  947.     mov    bx,ax
  948.     mov    cx,5            ; set shift count
  949.     shr    ax,cl            ; get HiX
  950.     and    ax,01Fh            ; mask higher bits
  951.     or    al,020h            ; convert to character
  952.     mov    [si+2],al        ; set HiX
  953.     and    bx,01Fh            ; get LoX
  954.     or    bl,020h            ; convert to character
  955.     mov    [si+3],bl        ; set LoX
  956. ;
  957.     pop    bx            ; restore Y
  958. ;
  959.     mov    ax,bx
  960.     mov    cx,5            ; set shift count
  961.     shr    ax,cl            ; get HiY
  962.     and    ax,01Fh            ; mask higher bits
  963.     or    al,020h            ; convert to character
  964.     mov    [si+4],al        ; set HiY
  965.     and    bx,01Fh            ; get LoY
  966.     or    bl,020h            ; convert to character
  967.     mov    [si+5],bl        ; set LoY
  968. ;
  969. ;    Erase cross hair cursor
  970. ;
  971.     mov    si,offset loc_x_buff
  972.     call    send_to_GGDC
  973.     mov    si,offset loc_y_buff
  974.     call    send_to_GGDC
  975. ;
  976. ;    Reset write mode
  977. ;
  978.     mov    si,offset ext_gin
  979.     call    send_to_GGDC
  980. ;
  981.     mov    tek_byp,1        ; set bypass mode
  982.     mov    si,offset gin_ans
  983.     xor    cx,cx
  984.     mov    cl,[si]
  985.     inc    si
  986.     ret
  987. TEK40_GIN    ENDP
  988.  
  989. TEK40_CURON    PROC    NEAR
  990.     push    ax
  991.     push    bx
  992.     push    cx
  993.     push    si
  994.     push    di
  995. ;
  996.     mov    si,offset alp_cur_font
  997.     mov    di,offset alp_cur_buff
  998.     mov    byte ptr [di],078h    ; TEXTW
  999.     mov    byte ptr [di+1],8    ; number of parameters
  1000.     add    di,2
  1001.     cld
  1002.     mov    cx,8
  1003.     push    es
  1004.     push    ds
  1005.     pop    es
  1006.     rep    movsb
  1007.     pop    es
  1008.     mov    ax,tek_cur_x
  1009.     mov    bx,tek_cur_y
  1010.     call    tek40_dev_cood
  1011.     mov    cx,GGDC_GCUR_PLANE    ; cursor graphic plane
  1012.     call    gcsrw
  1013.     mov    byte ptr [di],21h    ; write in COMPLEMENT mode
  1014.     mov    byte ptr [di+1],0
  1015.     add    di,2
  1016.     mov    byte ptr [di],04Ch    ; VEXTW
  1017.     mov    byte ptr [di+1],3    ; number of parameters
  1018.     mov    byte ptr [di+2],012h    ; normal text dir=2
  1019.     mov    byte ptr [di+3],07h
  1020.     mov    byte ptr [di+4],0
  1021.     mov    byte ptr [di+5],068h    ; TEXTE
  1022.     mov    byte ptr [di+6],0
  1023.     mov    byte ptr [di+7],0FFh    ; terminator
  1024.     mov    si,offset alp_cur_buff
  1025.     call    send_to_GGDC
  1026.     mov    tek_cur,1
  1027. ;
  1028.     pop    di
  1029.     pop    si
  1030.     pop    cx
  1031.     pop    bx
  1032.     pop    ax
  1033.     ret
  1034. TEK40_CURON    ENDP
  1035.  
  1036. TEK40_CUROFF    PROC    NEAR
  1037.     cmp    tek_cur,0
  1038.     je    tek40_curoff_ex
  1039.     push    si
  1040.     mov    si,offset alp_cur_buff
  1041.     call    send_to_GGDC
  1042.     pop    si
  1043.     mov    tek_cur,0
  1044. tek40_curoff_ex:
  1045.     ret
  1046. TEK40_CUROFF    ENDP
  1047.  
  1048. TEK4014_INI    PROC    NEAR
  1049.     call    tek4014_reset
  1050.     mov    si,offset ggdc_off
  1051.     call    send_to_GGDC
  1052.     ret
  1053. TEK4014_INI    ENDP
  1054.  
  1055. TEK4014_COLOR    PROC    NEAR
  1056. ;
  1057. ;  Set color index table
  1058. ;  [si]   foreground color
  1059. ;  [si+1] background color
  1060. ;
  1061.     push    ax
  1062.     push    di
  1063. ;
  1064.     push    si
  1065.     mov    al,[si+1]        ; background color
  1066.     xor    ah,ah
  1067.     mov    si,offset gnrm_color
  1068.     add    si,ax
  1069.     add    si,ax
  1070.     add    si,ax
  1071.     mov    di,offset tek_col    ; index 0 is background color
  1072.     mov    al,[si]
  1073.     mov    [di],al
  1074.     mov    al,[si+1]
  1075.     mov    [di+1],al
  1076.     mov    al,[si+2]
  1077.     mov    [di+2],al
  1078. ;
  1079.     push    cx
  1080.     mov    cx,4
  1081.     mov    di,offset sixel_col
  1082. tek4014_color_sxb:
  1083.     mov    al,[si]
  1084.     mov    [di],al            ; R
  1085.     mov    [di+24],al        ; R
  1086.     mov    al,[si+1]
  1087.     mov    [di+1],al        ; G
  1088.     mov    [di+25],al        ; G
  1089.     mov    al,[si+2]
  1090.     mov    [di+2],al        ; B
  1091.     mov    [di+26],al        ; B
  1092.     add    di,3
  1093.     loop    tek4014_color_sxb
  1094.     pop    cx
  1095. ;
  1096.     pop    si
  1097. ;
  1098.     push    si
  1099.     mov    al,[si]            ; foreground color
  1100.     xor    ah,ah
  1101.     mov    si,offset gnrm_color
  1102.     add    si,ax
  1103.     add    si,ax
  1104.     add    si,ax
  1105.     mov    di,offset tek_col
  1106.     add    di,3            ; index 1 is foreground color
  1107.     mov    al,[si]
  1108.     mov    [di],al
  1109.     mov    al,[si+1]
  1110.     mov    [di+1],al
  1111.     mov    al,[si+2]
  1112.     mov    [di+2],al
  1113. ;
  1114.     push    cx
  1115.     mov    cx,4
  1116.     mov    di,offset sixel_col
  1117.     add    di,12            ; start from index 4
  1118. tek4014_color_sxf:
  1119.     mov    al,[si]
  1120.     mov    [di],al            ; R
  1121.     mov    [di+24],al        ; R
  1122.     mov    al,[si+1]
  1123.     mov    [di+1],al        ; G
  1124.     mov    [di+25],al        ; G
  1125.     mov    al,[si+2]
  1126.     mov    [di+2],al        ; B
  1127.     mov    [di+26],al        ; B
  1128.     add    di,3
  1129.     loop    tek4014_color_sxf
  1130.     pop    cx
  1131. ;
  1132.     pop    si
  1133. ;@@    mov    [di+7],al
  1134. ;@@    mov    al,[si+1]
  1135. ;@@    mov    [di],al
  1136. ;@@    mov    di,offset sixel_col
  1137. ;@@    mov    al,[si]
  1138. ;@@    mov    [di+4],al
  1139. ;@@    mov    [di+5],al
  1140. ;@@    mov    [di+6],al
  1141. ;@@    mov    [di+7],al
  1142. ;@@    mov    al,[si+1]
  1143. ;@@    mov    [di],al
  1144. ;@@    mov    [di+1],al
  1145. ;@@    mov    [di+2],al
  1146. ;@@    mov    [di+3],al
  1147.     pop    di
  1148.     pop    ax
  1149.     ret
  1150. TEK4014_COLOR    ENDP
  1151.  
  1152. tek40_color    proc    near
  1153. ;
  1154. ; set color
  1155. ; input ax
  1156. ;
  1157.     push    ax            ; save register
  1158.     cmp    ax,0            ; normal intensity [0] ?
  1159.     jne    tek40_color_1        ; ne=no
  1160.     mov    tek_hgt,0        ; set normal intensity
  1161.     jmp    tek40_color_ex
  1162. tek40_color_1:
  1163.     cmp    ax,1            ; high intensity [1] ?
  1164.     jne    tek40_color_2        ; ne=no
  1165.     mov    tek_hgt,1        ; set high intensity
  1166.     jmp    tek40_color_ex
  1167. tek40_color_2:
  1168.     cmp    ax,30            ; forground color [30-37] ?
  1169.     jl    tek40_color_bk
  1170.     cmp    ax,37
  1171.     jg    tek40_color_bk
  1172.     sub    ax,30            ; OK, convert to color index
  1173.     push    bx
  1174.     mov    bx,offset col_indx_tab_N
  1175.     add    bx,ax
  1176.     cmp    tek_hgt,0        ; HighLight ?
  1177.     je    tek40_color_fg1        ; e=no
  1178.     add    bx,8
  1179. tek40_color_fg1:
  1180.     mov    al,[bx]
  1181.     pop    bx
  1182.     mov    tek_lncol,ax
  1183.     mov    tek_txcol,ax
  1184.     mov    tek_facol,ax
  1185.     jmp    tek40_color_ex
  1186. tek40_color_bk:
  1187.     cmp    ax,40            ; background color [40-47] ?
  1188.     jl    tek40_color_ex
  1189.     cmp    ax,47            ; bug fixed [30-May-1989]. Was 37.
  1190.     jg    tek40_color_ex
  1191.     sub    ax,40
  1192.     push    si
  1193.     mov    si,offset col_indx_tab_N
  1194.     add    si,ax
  1195.     mov    al,[si]
  1196.     mov    si,offset scn_color
  1197.     mov    [si+1],al
  1198.     call    tek4014_color
  1199.     mov    si,offset tek_col
  1200.     call    set_gpalette
  1201.     pop    si
  1202. tek40_color_ex:
  1203.     pop    ax            ; restore ax
  1204.     ret
  1205. tek40_color    endp
  1206.  
  1207. TEK4014_RESET    PROC    NEAR
  1208. ;
  1209. ;  Hardware initialization
  1210. ;
  1211. tek4014_reset_lp01:
  1212.     in    al,GGDC_STS_PORT
  1213.     xor    al,024h
  1214.     test    al,024h            ; VSYNC & GDC Empty ?
  1215.     jne    tek4014_reset_lp01
  1216. ;
  1217.     mov    al,disp_bank
  1218.     out    0A4h,al            ; set display bank
  1219.     mov    al,actv_bank
  1220.     out    0A6h,al            ; set active bank
  1221.     mov    al,02h            ; color mode
  1222.     out    068h,al            ; set mode F/F
  1223.     mov    al,08h            ; 400 line mode
  1224.     out    068h,al            ; set mode F/F
  1225.     mov    si,offset ggdc_set    ; CSFORM & SCROLL
  1226.     call    send_to_GGDC
  1227. ;
  1228.     cmp    display_mode,0
  1229.     je    tek4014_reset_02
  1230.     mov    gdisp_mode,1
  1231.     mov    gplane_nums,4
  1232.     jmp    tek4014_reset_03
  1233. tek4014_reset_02:
  1234.     mov    gdisp_mode,0
  1235.     mov    gplane_nums,3
  1236. tek4014_reset_03:
  1237.     mov    al,gdisp_mode        ; display mode
  1238.     out    6ah,al
  1239. ;
  1240.     call    gcls
  1241. ;
  1242. ;  Software reset
  1243. ;
  1244. ; Set color mode
  1245. ;
  1246.     mov    tek_cmode_1,3
  1247.     mov    tek_cmode_2,1
  1248.     mov    tek_cmode_3,1
  1249. ;
  1250.     push    si
  1251.     mov    si,offset def_color
  1252.     call    set_cur_color
  1253.     call    tek4014_color
  1254.     pop    si
  1255. ;
  1256. ; Set Windows
  1257. ;
  1258.     mov    tek_wnx1,0
  1259.     mov    tek_wnx2,TEK_X_MAX
  1260.     mov    tek_wny1,0
  1261.     mov    tek_wny2,TEK_Y_MAX
  1262. ;
  1263.     mov    gin_wnx1,0
  1264.     mov    gin_wnx2,TEK_X_MAX
  1265.     mov    gin_wny1,0
  1266.     mov    gin_wny2,TEK_Y_MAX
  1267. ;
  1268. ; Set Viewports
  1269. ;
  1270.     mov    tek_vpx1,X_OFS
  1271.     mov    tek_vpx2,(X_OFS+479)
  1272.     mov    tek_vpy1,Y_OFS
  1273.     mov    tek_vpy2,(Y_OFS+359)
  1274. ;
  1275.     mov    gin_vpx1,X_OFS
  1276.     mov    gin_vpx2,(X_OFS+479)
  1277.     mov    gin_vpy1,Y_OFS
  1278.     mov    gin_vpy2,(Y_OFS+359)
  1279. ;
  1280. ; Set Transformation Matricies
  1281. ;
  1282.     push    si
  1283.     push    di
  1284.     mov    si,offset tek_wnx1
  1285.     mov    di,offset tek_w2v_mat
  1286.     call    set_tek41_mat
  1287.     mov    si,offset gin_vpx1        ; viewport to window for GIN
  1288.     mov    di,offset gin_v2w_mat
  1289.     call    set_tek41_mat
  1290.     pop    di
  1291.     pop    si
  1292. ;
  1293. ; Set text parameters
  1294. ;
  1295.     mov    tek_gtxt_ang,0
  1296.     mov    tek_gtxt_w,39
  1297.     mov    tek_gtxt_h,52
  1298.     mov    tek_gtxt_s,13
  1299.     mov    tek_gtxt_dr,2
  1300.     mov    tek_gtxt_ux,52        ; w+s
  1301.     mov    tek_gtxt_uy,0
  1302.     mov    tek_gtxt_vx,0
  1303.     mov    tek_gtxt_vy,52        ; h
  1304. ;
  1305. ; Set current position
  1306. ;
  1307.     mov    tek_cur_x,0
  1308.     mov    tek_cur_y,TEK_Y_MAX
  1309.     mov    ax,TEK_DY
  1310.     sub    tek_cur_y,ax
  1311.     mov    line_type,0
  1312.     mov    marker_type,0
  1313.     mov    tek_byp,0
  1314.     mov    tek_lncol,1        ; line color is white
  1315.     mov    tek_txcol,1        ; text color is white
  1316.     mov    tek_facol,1        ; fill area color is white
  1317.     mov    tek_hgt,0        ; Normal Intensity
  1318.     mov    tek_esc,0
  1319.     mov    tek_inpanel,0
  1320.     mov    tek41_cmd,0
  1321. ;
  1322. ;    Set locator position at the center of the screen
  1323. ;
  1324.     push    bx
  1325.     mov    ax,(TEK_X_MAX+1)
  1326.     shr    ax,1
  1327.     mov    bx,(TEK_Y_MAX+1)
  1328.     shr    bx,1
  1329.     call    tek40_dev_cood
  1330.     mov    loc_x,ax
  1331.     mov    loc_y,bx
  1332.     pop    bx
  1333. ;
  1334. ;    Set color index table
  1335. ;
  1336.     push    cx
  1337.     push    di
  1338.     push    si
  1339.     push    es
  1340. ;
  1341.     push    ds
  1342.     pop    es
  1343.     mov    si,offset tek_col_def    ; source
  1344.     mov    di,offset tek_col    ; destination
  1345.     mov    cx,48            ; 16 colors x 3
  1346.     cld
  1347.     rep    movsb
  1348.     mov    si,offset tek_col
  1349.     call    set_gpalette
  1350. ;
  1351. ;    Set dialog area
  1352. ;
  1353.     mov    tek_dialog_area,0
  1354.     mov    tek_dialog_vsbl,0
  1355. ;
  1356.     pop    es
  1357.     pop    si
  1358.     pop    di
  1359.     pop    cx
  1360. ;
  1361.     call    tek40_curon
  1362. ;
  1363.     ret
  1364. TEK4014_RESET    ENDP
  1365.  
  1366. TEK4014_SAVE    PROC    NEAR
  1367. ;
  1368. ;@@    mov    si,offset tek_col0
  1369.     call    set_gpalette
  1370. ;
  1371.     mov    si,offset ggdc_solid
  1372.     call    send_to_GGDC
  1373.     mov    si,offset ggdc_off
  1374.     call    send_to_GGDC
  1375. ;
  1376. ; Clear mode line
  1377. ;
  1378.     push    dx
  1379.     mov    dx,offset tek_zero
  1380.     call    vt100_modlin
  1381.     pop    dx
  1382. ;
  1383.     push    ax
  1384.     xor    ax,ax        ; restore cursor attributes
  1385.     call    set_cursor
  1386.     mov    ax,1
  1387.     call    text_scrn    ; text screen ON
  1388.     pop    ax
  1389. ;
  1390.     ret
  1391. TEK4014_SAVE    ENDP
  1392.  
  1393.  
  1394. TEK4014_RESTORE    PROC    NEAR
  1395. ;@@    push    ax
  1396. ;@@    mov    ax,1        ; disable text cursor
  1397. ;@@    call    set_cursor
  1398. ;@@    pop    ax
  1399. ;
  1400.     push    ax
  1401.     mov    al,display_mode
  1402.     cmp    al,gdisp_mode
  1403.     je    tek4014_restore_1
  1404.     mov    gdisp_mode,0
  1405.     mov    gplane_nums,3
  1406.     cmp    al,0
  1407.     je    tek4014_restore_2
  1408.     mov    gdisp_mode,1
  1409.     mov    gplane_nums,4
  1410. tek4014_restore_2:
  1411.     mov    al,gdisp_mode
  1412.     out    6ah,al
  1413. tek4014_restore_1:
  1414.     pop    ax
  1415. ;
  1416.     call    gdisp_on
  1417. ;
  1418.     mov    si,offset tek_col
  1419.     call    set_gpalette
  1420.     ret
  1421. TEK4014_RESTORE    ENDP
  1422.  
  1423.  
  1424. TEK4014_MODLIN    PROC    NEAR
  1425.     call    vt100_modlin
  1426.     ret
  1427. TEK4014_MODLIN    ENDP
  1428.  
  1429. ; Tek4014/Tek4105 emulator by H.Fujii (KEK)
  1430. ;
  1431. ; Carry Set if parameters need to be passed to VT100.
  1432. ; In this case, CX contains number of characters and [SI] contains the
  1433. ; string.
  1434. ;
  1435. TEK4014    PROC    NEAR
  1436.     cmp    vt100_lflag,(LOGCOOK_BIT+LOGENAB_BIT)
  1437.     jne    tek4014_01        ; ne = no.
  1438.     call    outcapt            ; log it
  1439. tek4014_01:
  1440.     call    tek40_curoff
  1441.     cmp    tek_byp,0        ; bypass mode ?
  1442.     je    tek40_00        ; e = No.
  1443.     mov    bl,al            ; Bypass mode
  1444.     and    bl,07Fh            ; Mask 8th bit
  1445.     cmp    bl,020h            ; control character ?
  1446.     jge    tek40_ex        ; ge = No.
  1447.     mov    tek_byp,0        ; Off the bypass mode
  1448. tek40_00:
  1449.     cmp    tek_esc,0        ; in ESC sequence ?
  1450.     je    tek40_01        ; e = No.
  1451.     jmp    tek40_esc
  1452. tek40_01:
  1453.     cmp    tek_mod,0        ; Alpha mode ?
  1454.     jne    tek40_02
  1455.     jmp    tek40_alp
  1456. tek40_02:
  1457.     cmp    tek_mod,1        ; Vector mode ?
  1458.     jne    tek40_03
  1459.     jmp    tek40_vct
  1460. tek40_03:
  1461.     cmp    tek_mod,2        ; Point plot mode ?
  1462.     jne    tek40_04
  1463.     jmp    tek40_vct
  1464. tek40_04:
  1465.     cmp    tek_mod,3
  1466.     jne    tek40_05
  1467.     jmp    tek40_inc
  1468. tek40_05:
  1469.     call    pc98_bell        ; Program error !!!
  1470. tek40_ex:
  1471.     cmp    tek_esc,0        ; in ESC seq ?
  1472.     jne    tek40_ex1        ; ne=yes.
  1473.     cmp    tek_dialog_area,0    ; Disable dialog ?
  1474.     jne    tek40_ex1        ; ne=no, dialog is VT screen
  1475.     cmp    tek_mod,0        ; in alpha mode ?
  1476.     jne    tek40_ex1        ; ne=no
  1477.     call    tek40_curon
  1478. tek40_ex1:
  1479.     mov    ah,0
  1480.     mov    cx,0
  1481.     clc                ; normal return
  1482.     ret
  1483. ;-----------------------------------------------------------------------
  1484. ; ESC sequence
  1485. ;-----------------------------------------------------------------------
  1486. tek40_esc:
  1487.     cmp    tek_esc,1        ; just entered ?
  1488.     je    tek40_esc1        ; e=yes.
  1489.     cmp    tek_esc,2        ; in CSI mode ?
  1490.     jne    tek40_esc_n2        ; ne=no.
  1491.     jmp    tek40_esc2
  1492. tek40_esc_n2:
  1493.     cmp    tek_esc,3        ; in 20C ?
  1494.     jne    tek40_esc_n3
  1495.     jmp    tek40_esc3
  1496. tek40_esc_n3:
  1497.     jmp    tek40_esc4
  1498. ;
  1499. tek40_esc1:
  1500.     cmp    al,020h            ; C0 character ?
  1501.     jb    tek40_esc_C0        ; b=yes.
  1502.     jmp    tek40_esc_GL
  1503. ;
  1504. tek40_esc_C0:
  1505. tek40_esc_0C:
  1506.     cmp    al,FF            ; FF ?
  1507.     jne    tek40_esc_n0C        ; ne=no.
  1508.     test    vtgrph_flg,GCLRWAIT_BIT
  1509.     jz    tek40_esc_0C_2
  1510.     push    ax
  1511.     push    bx
  1512.     call    pc98_bell
  1513. tek40_esc_0C_1:
  1514.     mov    ax,0100h
  1515.     int    BIOS
  1516.     cmp    bh,0
  1517.     je    tek40_esc_0C_1
  1518.     mov    ax,0
  1519.     int    BIOS
  1520.     pop    bx
  1521.     pop    ax
  1522. tek40_esc_0C_2:
  1523.     call    gcls            ; ESC FF clears screen
  1524.     mov    tek_esc,0        ; ESC seq done
  1525.     mov    tek_mod,0        ; enter alpha mode
  1526.     mov    tek_cur_x,0
  1527.     mov    tek_cur_y,TEK_Y_MAX
  1528.     sub    tek_cur_y,TEK_DY
  1529.     jmp    tek40_ex
  1530. tek40_esc_n0C:
  1531. ;
  1532.     cmp    al,CL_SUB        ; SUB (1A) ?
  1533.     jne    tek40_esc_n1A        ; ne=no.
  1534.     call    tek40_gin
  1535.     mov    tek_esc,0
  1536.     mov    tek_mod,0
  1537.     mov    ah,0
  1538.     clc
  1539.     ret                ; EIXT with gin answerback
  1540. tek40_esc_n1A:
  1541.     mov    tek_esc,0        ; any other C0 characters are
  1542.     jmp    tek40_C0        ; treated as a single C0 character
  1543. ;
  1544. tek40_esc_GL:
  1545.     cmp    al,'['
  1546.     je    tek40_esc_5B
  1547.     ja    tek40_esc_5C
  1548.     mov    tek_esc,3        ; in TEK4105 command mode
  1549.     xor    ah,ah
  1550.     mov    tek41_cmd,ax
  1551.     jmp    tek40_ex
  1552. tek40_esc_5B:
  1553.     mov    tek_esc,2        ; in CSI mode
  1554.     mov    bx,offset tek_P_buf
  1555.     mov    tek_P_pnt,bx
  1556.     mov    word ptr [bx],0
  1557.     mov    tek_P_num,0
  1558.     mov    tek_P_prv,0
  1559.     jmp    tek40_ex
  1560. tek40_esc_5C:
  1561.     jmp    tek40_esc_ex
  1562. ;
  1563. ; ANSI CSI sequence
  1564. ;
  1565. tek40_esc2:
  1566.     cmp    al,'0'
  1567.     jl    tek40_esc2_01
  1568.     cmp    al,'9'
  1569.     jg    tek40_esc2_01
  1570.     xor    ah,ah
  1571.     sub    al,'0'
  1572.     mov    bx,tek_P_pnt
  1573.     mov    cx,[bx]
  1574.     shl    cx,1
  1575.     shl    cx,1
  1576.     add    cx,[bx]
  1577.     shl    cx,1
  1578.     add    ax,cx
  1579.     mov    [bx],ax
  1580.     jmp    tek40_ex
  1581. tek40_esc2_01:
  1582.     cmp    al,'?'
  1583.     jne    tek40_esc2_02
  1584.     mov    tek_P_prv,al
  1585.     jmp    tek40_ex
  1586. tek40_esc2_02:
  1587.     cmp    al,';'
  1588.     jne    tek40_esc2_03
  1589.     add    tek_P_pnt,2
  1590.     mov    bx,tek_P_pnt
  1591.     mov    word ptr [bx],0
  1592.     inc    tek_P_num
  1593.     jmp    tek40_ex
  1594. tek40_esc2_03:
  1595.     cmp    al,'h'
  1596.     jne    tek40_esc2_04
  1597.     jmp    tek40_esc_ex
  1598. tek40_esc2_04:
  1599.     cmp    al,'l'
  1600.     jne    tek40_esc2_05
  1601.     jmp    tek40_vtchg
  1602. tek40_esc2_05:
  1603.     cmp    al,'m'
  1604.     jne    tek40_esc2_06
  1605.     push    ax
  1606.     push    cx
  1607.     push    si
  1608.     mov    si,offset tek_P_buf
  1609.     mov    cx,tek_P_num        ; number of parameters
  1610.     inc    cx
  1611. tek40_esc2_05a:
  1612.     mov    ax,[si]            ; get color code
  1613.     call    tek40_color
  1614.     add    si,2
  1615.     loop    tek40_esc2_05a        ; loop over all parameters
  1616.     pop    si
  1617.     pop    cx
  1618.     pop    ax
  1619.     jmp    tek40_esc_ex
  1620. tek40_esc2_06:
  1621.     jmp    tek40_esc_ex
  1622. ;
  1623. tek40_esc3:
  1624. ;
  1625. ; 20C mode
  1626. ;
  1627.     cmp    al,020h            ; C0 character ?
  1628.     jae    tek40_esc3_01        ; ae = no.
  1629.     jmp    tek40_C0
  1630. tek40_esc3_01:
  1631.     mov    bx,tek41_cmd
  1632.     mov    bh,al
  1633.     xchg    bh,bl
  1634.     mov    tek41_cmd,bx        ; stored it.
  1635.     mov    tek_esc,4        ; enter Tek41 command mode
  1636.     mov    tek41_narg,0
  1637.     mov    tek41_nget,0
  1638.     mov    tek41_larg,0
  1639. ;
  1640. ; analyze command and set number of arguments and argument types
  1641. ;
  1642.     mov    ax,bx
  1643.     mov    bx,offset func41
  1644. tek41_ana_03:
  1645.     mov    cx,[bx]
  1646.     cmp    ax,cx
  1647.     je    tek41_ana_01
  1648.     cmp    cx,0
  1649.     jne    tek41_ana_05
  1650.     add    bx,2
  1651.     mov    cx,[bx]
  1652.     mov    tek41_func,cx
  1653.     xchg    ah,al            ; change to character order
  1654.     mov    tek_unkwn_msg,ax
  1655.     xchg    ah,al
  1656.     jmp    tek40_ex
  1657. tek41_ana_05:
  1658.     add    bx,10
  1659.     jmp    tek41_ana_03
  1660. tek41_ana_01:
  1661.     add    bx,2
  1662.     mov    cx,[bx]
  1663.     mov    tek41_func,cx
  1664.     add    bx,2
  1665.     mov    cl,[bx]
  1666.     inc    bx
  1667.     xor    ch,ch
  1668.     mov    tek41_narg,cx
  1669.     cmp    cx,0
  1670.     je    tek41_ana_02
  1671.     push    si
  1672.     mov    si,offset tek41_argt
  1673. tek41_ana_04:
  1674.     mov    al,[bx]
  1675.     mov    [si],al
  1676.     inc    bx
  1677.     inc    si
  1678.     loop    tek41_ana_04
  1679.     pop    si
  1680. tek41_ana_02:
  1681.     jmp    tek41_next
  1682. ;
  1683. tek40_esc4:
  1684.     cmp    al,20h            ; C0 character ?
  1685.     jae    tek40_esc4_02        ; ae=no.
  1686.     cmp    al,ESCAPE        ; one of ESC,FS,GS,RS,US ?
  1687.     jl    tek40_esc4_01        ; l=no.
  1688.     mov    tek_esc,0        ; terminate the command
  1689.     jmp    tek40_C0        ; and treat as C0
  1690. tek40_esc4_01:
  1691.     jmp    tek40_ex        ; ignore any other C0 character.
  1692. tek40_esc4_02:
  1693.     cmp    tek41_nreq,TEK41_XY_TYPE
  1694.     jne    tek40_esc4_03
  1695.     jmp    tek41_xy
  1696. tek40_esc4_03:
  1697.     cmp    tek41_nreq,TEK41_INT_TYPE
  1698.     jne    tek40_esc4_04
  1699.     jmp    tek41_int
  1700. tek40_esc4_04:
  1701.     cmp    tek41_nreq,TEK41_STR_TYPE
  1702.     jne    tek40_esc4_05
  1703.     jmp    tek41_str
  1704. tek40_esc4_05:
  1705.     cmp    tek41_nreq,TEK41_IAR_TYPE
  1706.     jne    tek40_esc4_06
  1707.     jmp    tek41_int
  1708. tek40_esc4_06:
  1709.     jmp    tek40_ex            ; Unknown command, ignore.
  1710. ;
  1711. tek40_esc_ex:
  1712.     mov    tek_esc,0
  1713.     jmp    tek40_ex
  1714.  
  1715. ; receive and convert Tek41 type xy-coordinate
  1716. ; note that xy-coordinate system is the same as Tek401x.
  1717. ;
  1718. tek41_xy:
  1719.     jmp    tek40_vct    ; goto Tek40 type vector format analyzer
  1720. tek41_xy1:
  1721.     mov    cx,tek41_larg    ; check the room for storage
  1722.     add    cx,4
  1723.     cmp    cx,TEK41_ARGBUF_SIZE
  1724.     jae    tek41_xy2    ; ae = room is full
  1725.     mov    bx,offset tek41_argbuf
  1726.     add    bx,tek41_larg
  1727.     mov    ax,tek_req_x
  1728.     mov    [bx],ax        ; store it in buffer
  1729.     mov    ax,tek_req_y
  1730.     mov    [bx+2],ax
  1731.     add    tek41_larg,4    ; update buffer length
  1732. tek41_xy2:
  1733.     inc    tek41_nget    ; icrement number of argument we get
  1734.     jmp    tek41_next
  1735. ;
  1736. ; receive and convert Tek41 type integer
  1737. ;    7 6 5 4 3 2 1 0             7 6 5 4 3 2 1 0
  1738. ;   +-+-+-+-+-+-+-+-+           +-+-+-+-+-+-+-+-+
  1739. ;   |P|1|   value   |     ...   |P|0|1|S| value |   where S=1 if int >= 0
  1740. ;   +-+-+-+-+-+-+-+-+           +-+-+-+-+-+-+-+-+
  1741. ;
  1742. tek41_int:
  1743.     mov    ah,al        ; copy to AH
  1744.     mov    bx,tek41_ival    ; get previous value
  1745.     test    al,040h        ; Hi byte ?
  1746.     jz    tek41_int1    ; z=no
  1747.     mov    cx,6        ; shift count
  1748.     shl    bx,cl        ; shift-left previous value by 6 bits
  1749.     and    ah,03Fh
  1750.     or    bl,ah
  1751.     mov    tek41_ival,bx    ; store it
  1752.     jmp    tek40_ex    ; and continue
  1753. tek41_int1:
  1754.     mov    cx,4
  1755.     shl    bx,cl
  1756.     and    ah,00Fh
  1757.     or    bl,ah
  1758.     test    al,010h        ; check sign bit
  1759.     jnz    tek41_int2    ; nz=positive
  1760.     neg    bx        ; negative integer
  1761. tek41_int2:
  1762.     mov    ax,bx
  1763.     mov    tek41_ival,ax    ; store it
  1764.     mov    cx,tek41_larg    ; check the room for storage
  1765.     add    cx,2
  1766.     cmp    cx,TEK41_ARGBUF_SIZE
  1767.     jae    tek41_int3    ; ae = room is full
  1768.     mov    bx,offset tek41_argbuf
  1769.     add    bx,tek41_larg
  1770.     mov    [bx],ax        ; store it in buffer
  1771.     add    tek41_larg,2    ; update buffer length
  1772. tek41_int3:
  1773.     cmp    tek41_nact,TEK41_INT_TYPE    ; processing single INT ?
  1774.     jne    tek41_int4    ; ne=no.
  1775.     inc    tek41_nget    ; increment number of arg. we get
  1776.     jmp    tek41_next    ; setup for next argument
  1777. tek41_int4:
  1778.     cmp    tek41_nact,TEK41_STR_TYPE    ; processing string ?
  1779.     jne    tek41_int5    ; ne=no.
  1780.     mov    tek41_lstr,ax    ; set character length
  1781.     mov    tek41_nchr,0    ; clear the filled size
  1782.     mov    tek41_nreq,TEK41_STR_TYPE    ; next data is character
  1783.     jmp    tek40_ex    ; and continue
  1784. tek41_int5:
  1785.     cmp    tek41_nact,TEK41_IAR_TYPE    ; processing INT array ?
  1786.     jne    tek41_int8
  1787.     cmp    tek41_nreq,TEK41_INT_TYPE    ; beginning of array ?
  1788.     jne    tek41_int6
  1789.     mov    tek41_liar,ax    ; set array length
  1790.     mov    tek41_niar,0    ; clear the filled size
  1791.     mov    tek41_ival,0    ; clear the buffer
  1792.     mov    tek41_nreq,TEK41_IAR_TYPE    ; next data is INT array elem.
  1793.     jmp    tek40_ex    ; and continue
  1794. tek41_int6:
  1795.     inc    tek41_niar
  1796.     mov    cx,tek41_niar
  1797.     cmp    cx,tek41_liar
  1798.     jge    tek41_int7
  1799.     mov    tek41_ival,0    ; clear the buffer
  1800.     jmp    tek40_ex
  1801. tek41_int7:
  1802.     inc    tek41_nget
  1803.     jmp    tek41_next
  1804. tek41_int8:
  1805.     jmp    tek40_ex    ; PROGRAM ERROR !!!
  1806. ;
  1807. tek41_str:
  1808.     mov    cx,tek41_larg    ; check the room
  1809.     inc    cx
  1810.     cmp    cx,TEK41_ARGBUF_SIZE
  1811.     jae    tek41_str1    ; ae = room is full
  1812.     mov    bx,offset tek41_argbuf
  1813.     add    bx,tek41_larg
  1814.     mov    [bx],al
  1815.     inc    tek41_larg    ; update buffer length
  1816. tek41_str1:
  1817.     inc    tek41_nchr
  1818.     mov    cx,tek41_nchr
  1819.     cmp    cx,tek41_lstr
  1820.     jge    tek41_str2
  1821.     jmp    tek40_ex
  1822. tek41_str2:
  1823.     inc    tek41_nget
  1824.     jmp    tek41_next
  1825. ;
  1826. ; setup next argument for Tek41xx
  1827. ;
  1828. tek41_next:
  1829.     mov    cx,tek41_nget    ; number of arg. we have
  1830.     cmp    cx,tek41_narg    ; enough ?
  1831.     jl    tek41_next1    ; l=no, not.
  1832.     mov    tek41_nreq,TEK41_NO_ACT    ; yes, we have enough, no more.
  1833.     jmp    tek41_exec    ; execute the command.
  1834. tek41_next1:
  1835.     mov    bx,offset tek41_argt
  1836.     add    bx,cx
  1837.     mov    al,[bx]        ; argument type
  1838.     mov    tek41_nact,al    ; set next action
  1839.     cmp    al,TEK41_XY_TYPE
  1840.     jne    tek41_next2
  1841.     mov    tek41_nreq,TEK41_XY_TYPE    ; next data type is XY-type
  1842.     mov    tek_vseq,0    ; initialize vector format seq.
  1843.     jmp    tek40_ex
  1844. tek41_next2:
  1845.     cmp    al,TEK41_INT_TYPE
  1846.     jne    tek41_next3
  1847.     mov    tek41_nreq,TEK41_INT_TYPE    ; next data type is INT
  1848.     mov    tek41_ival,0
  1849.     jmp    tek40_ex
  1850. tek41_next3:
  1851.     cmp    al,TEK41_STR_TYPE
  1852.     jne    tek41_next4
  1853.     mov    tek41_nreq,TEK41_INT_TYPE    ; next data type is INT
  1854.     mov    tek41_ival,0
  1855.     mov    tek41_lstr,0
  1856.     mov    tek41_nchr,0
  1857.     jmp    tek40_ex
  1858. tek41_next4:
  1859.     cmp    al,TEK41_IAR_TYPE
  1860.     jne    tek41_next5
  1861.     mov    tek41_nreq,TEK41_INT_TYPE    ; next data type is INT
  1862.     mov    tek41_ival,0
  1863.     mov    tek41_liar,0
  1864.     mov    tek41_niar,0
  1865.     jmp    tek40_ex
  1866. tek41_next5:
  1867.     jmp    tek40_ex            ; PROGRAM ERROR !!!
  1868. ;
  1869. ; execute the Tek41 command
  1870. ;
  1871. tek41_exec:
  1872.     mov    bx,tek41_func
  1873.     jmp    bx
  1874. ;
  1875. tek41_exec_MC:
  1876.     mov    bx,offset tek41_argbuf
  1877.     mov    ax,[bx]            ; text width
  1878.     mov    tek_gtxt_w,ax
  1879.     mov    ax,[bx+2]        ; text height
  1880.     mov    tek_gtxt_h,ax
  1881.     mov    ax,[bx+4]        ; text spacing
  1882.     mov    tek_gtxt_s,ax
  1883.     call    set_gtxt_vect
  1884.     jmp    tek41_exec_done
  1885. ;
  1886. tek41_exec_ML:
  1887.     mov    ax,tek41_ival
  1888. ;@@    call    tek41_getcol    ; convert to tek41 color index
  1889.     mov    tek_lncol,ax
  1890.     jmp    tek41_exec_done
  1891. ;
  1892. tek41_exec_MT:
  1893.     mov    ax,tek41_ival
  1894. ;@@    call    tek41_getcol    ; convert to tek41 color index
  1895.     mov    tek_txcol,ax
  1896.     jmp    tek41_exec_done
  1897. ;
  1898. tek41_exec_MM:
  1899.     mov    ax,tek41_ival
  1900.     mov    marker_type,ax
  1901.     jmp    tek41_exec_done
  1902. ;
  1903. tek41_exec_MP:
  1904.     mov    ax,tek41_ival
  1905.     cmp    ax,0
  1906.     jg    tek41_exec_MP2
  1907.     je    tek41_exec_MP1
  1908.     neg    ax
  1909. ;@@    call    tek41_getcol    ; convert to tek41 color index
  1910. tek41_exec_MP1:
  1911.     mov    tek_facol,ax
  1912.     mov    tek_famod,0
  1913. tek41_exec_MP2:
  1914.     jmp    tek41_exec_done
  1915. ;
  1916. tek41_exec_MV:
  1917.     mov    ax,tek41_ival
  1918.     and    ax,07h
  1919.     mov    line_type,ax
  1920.     jmp    tek41_exec_done
  1921. ;
  1922. tek41_exec_MR:
  1923.     mov    bx,offset tek41_argbuf
  1924.     mov    ax,[bx]            ; rotation angle
  1925.     mov    cx,[bx+2]
  1926.     cmp    cx,0
  1927.     je    tek41_exec_MR_1
  1928.     jg    tek41_exec_MR_2
  1929.     neg    cx
  1930.     sar    ax,cl
  1931.     jmp    tek41_exec_MR_1
  1932. tek41_exec_MR_2:
  1933.     sal    ax,cl
  1934. tek41_exec_MR_1:
  1935.     cmp    ax,0
  1936.     jge    tek41_exec_MR_3
  1937.     add    ax,360
  1938.     jmp    tek41_exec_MR_1
  1939. tek41_exec_MR_3:
  1940.     cmp    ax,360
  1941.     jl    tek41_exec_MR_4
  1942.     sub    ax,360
  1943.     jmp    tek41_exec_MR_3
  1944. tek41_exec_MR_4:
  1945.     mov    tek_gtxt_ang,ax
  1946.     call    set_gtxt_vect
  1947.     jmp    tek41_exec_done
  1948. ;
  1949. tek41_exec_KA:
  1950.     mov    ax,tek41_ival
  1951.     mov    tek_dialog_area,al
  1952.     jmp    tek41_exec_done
  1953. ;
  1954. tek41_exec_LV:
  1955.     mov    ax,tek41_ival
  1956.     mov    tek_dialog_vsbl,al
  1957.     call    text_scrn
  1958.     jmp    tek41_exec_done
  1959. ;
  1960. tek41_exec_LZ:
  1961.     mov    si,offset vt_dialog_clr
  1962.     xor    cx,cx
  1963.     xor    ax,ax
  1964.     mov    cl,[si]
  1965.     inc    si
  1966.     stc
  1967.     ret
  1968. ;
  1969. tek41_exec_SETCOM:
  1970.     cmp    tek41_ival,0
  1971.     je    tek41_exec_nSETCOM
  1972.     mov    ah,1        ; change the mode to VT
  1973.     mov    al,0
  1974.     xor    cx,cx
  1975.     mov    tek41_cmd,0
  1976.     mov    tek_esc,0
  1977.     ret
  1978. tek41_exec_nSETCOM:
  1979. tek41_exec_unknown:
  1980.     mov    tek41_cmd,0    ; unknown command
  1981.     jmp    tek40_ex
  1982. ;
  1983. tek41_exec_none:
  1984.     mov    ax,tek41_cmd
  1985.     xchg    ah,al
  1986.     mov    tek_ignor_msg,ax
  1987.     jmp    tek41_exec_done
  1988. ;
  1989. tek41_exec_LG:
  1990.     cmp    tek_inpanel,0
  1991.     je    tek41_exec_LG1
  1992.     jmp    tek40_vct_fa
  1993. tek41_exec_LG1:
  1994.     mov    ax,line_type
  1995.     call    tek_ltyp
  1996.     mov    ax,tek_cur_x
  1997.     mov    bx,tek_cur_y
  1998.     call    tek40_dev_cood
  1999.     mov    pc98_x1,ax
  2000.     mov    pc98_y1,bx
  2001.     mov    ax,tek_req_x
  2002.     mov    bx,tek_req_y
  2003.     call    tek40_dev_cood
  2004.     call    tek_draw
  2005.     jmp    tek41_exec_LF1
  2006. tek41_exec_LH:
  2007.     cmp    tek_inpanel,0
  2008.     je    tek41_exec_LH1
  2009.     jmp    tek40_vct_fa
  2010. tek41_exec_LH1:
  2011.     mov    ax,tek_req_x
  2012.     mov    bx,tek_req_y
  2013.     call    tek40_dev_cood
  2014.     call    tek_mark
  2015.     jmp    tek41_exec_LF1
  2016. tek41_exec_LF:
  2017.     cmp    tek_inpanel,0
  2018.     je    tek41_exec_LF1
  2019.     jmp    tek40_vct_fa
  2020. tek41_exec_LF1:
  2021.     mov    ax,tek_req_x
  2022.     mov    tek_cur_x,ax
  2023.     mov    ax,tek_req_y
  2024.     mov    tek_cur_y,ax
  2025.     jmp    tek41_exec_done
  2026. ;
  2027. tek41_exec_LT:
  2028.     cmp    tek_inpanel,0
  2029.     je    tek41_exec_LT1
  2030.     jmp    tek40_ex
  2031. tek41_exec_LT1:
  2032.     mov    cx,tek41_nchr        ; get number of characters
  2033.     mov    si,offset tek41_argbuf
  2034.     add    si,2            ; 1st 2-bytes contains num of char
  2035.     call    tek_gtxt        ; draw graphic text
  2036.     jmp    tek41_exec_done
  2037. ;
  2038. ; Begin Panel Boundary
  2039. ;
  2040. tek41_exec_LP:
  2041.     mov    si,offset tek41_fabuf
  2042.     cmp    tek_inpanel,0        ; already in panel mode ?
  2043.     jne    tek41_exec_LP_c1    ; ne=Yes. Close the previous polygon
  2044.     jmp    tek41_exec_LP_1
  2045. tek41_exec_LP_c1:
  2046.     mov    ax,tek41_lfa
  2047.     add    si,ax
  2048.     mov    bx,tek41_faadr        ; get the address of the 1st point
  2049.     mov    ax,[bx+2]        ; get 1st X
  2050.     mov    [si],ax            ; add it to the last point
  2051.     mov    ax,[bx+4]        ; get 1st Y
  2052.     mov    [si+2],ax        ; add it to the last point
  2053.     add    tek41_lfa,4        ; update buffer length
  2054. ;
  2055.     cmp    tek_panel_bnd,0        ; draw boundary ?
  2056.     je    tek41_exec_LP_c2    ; e=no.
  2057.     mov    ax,[si]            ; get the 1st X
  2058.     mov    bx,[si+2]        ; get the 1st Y
  2059.     xchg    ax,pc98_x2
  2060.     xchg    bx,pc98_y2
  2061.     mov    pc98_x1,ax
  2062.     mov    pc98_y1,bx
  2063.     mov    ax,pc98_x2
  2064.     mov    bx,pc98_y2
  2065.     push    si            ; save buffer address
  2066.     call    tek_draw
  2067.     pop    si
  2068. tek41_exec_LP_c2:
  2069.     add    si,4            ; update buffer address
  2070.     jmp    tek41_exec_LP_2
  2071. tek41_exec_LP_1:
  2072.     mov    scan_xmin,639
  2073.     mov    scan_xmax,0
  2074.     mov    scan_ymin,399
  2075.     mov    scan_ymax,0
  2076.     mov    tek41_lfa,0
  2077. tek41_exec_LP_2:
  2078.     mov    tek41_faadr,si
  2079.     mov    ax,1            ; 1st point
  2080.     mov    [si],ax
  2081.     mov    ax,tek_req_x
  2082.     mov    bx,tek_req_y
  2083.     mov    tek_cur_x,ax
  2084.     mov    tek_cur_y,bx
  2085.     call    tek40_dev_cood
  2086.     mov    [si+2],ax
  2087.     mov    [si+4],bx
  2088.     mov    pc98_x2,ax
  2089.     mov    pc98_y2,bx
  2090.     cmp    ax,scan_xmin
  2091.     jge    tek41_exec_LP_3
  2092.     mov    scan_xmin,ax
  2093. tek41_exec_LP_3:
  2094.     cmp    ax,scan_xmax
  2095.     jle    tek41_exec_LP_4
  2096.     mov    scan_xmax,ax
  2097. tek41_exec_LP_4:
  2098.     cmp    bx,scan_ymin
  2099.     jge    tek41_exec_LP_5
  2100.     mov    scan_ymin,bx
  2101. tek41_exec_LP_5:
  2102.     cmp    bx,scan_ymax
  2103.     jle    tek41_exec_LP_6
  2104.     mov    scan_ymax,bx
  2105. tek41_exec_LP_6:
  2106.     add    tek41_lfa,6
  2107.     mov    tek_inpanel,1
  2108.     mov    ax,tek41_ival
  2109.     mov    tek_panel_bnd,al        ; set panel boundary mode
  2110.     test    al,1
  2111.     jz    tek41_exec_LP_ex
  2112.     mov    ax,line_type
  2113.     call    tek_ltyp
  2114. tek41_exec_LP_ex:
  2115.     jmp    tek41_exec_done
  2116. ;
  2117. tek41_exec_LE:
  2118.     mov    tek_inpanel,0
  2119. ;
  2120.     mov    si,offset tek41_fabuf
  2121.     mov    ax,tek41_lfa
  2122.     add    si,ax
  2123.     mov    bx,tek41_faadr
  2124.     mov    ax,[bx+2]        ; get 1st X
  2125.     mov    [si],ax            ; add it to the last point
  2126.     mov    ax,[bx+4]        ; get 1st Y
  2127.     mov    [si+2],ax        ; add it to the last point
  2128.     xor    ax,ax            ; terminator
  2129.     mov    [si+4],ax        ; set terminator
  2130.     add    tek41_lfa,6        ; update buffer length
  2131. ;
  2132.     cmp    tek_panel_bnd,0
  2133.     je    tek41_exec_LE6
  2134.     mov    ax,[si]
  2135.     mov    bx,[si+2]
  2136.     xchg    ax,pc98_x2
  2137.     xchg    bx,pc98_y2
  2138.     mov    pc98_x1,ax
  2139.     mov    pc98_y1,bx
  2140.     mov    ax,pc98_x2
  2141.     mov    bx,pc98_y2
  2142.     call    tek_draw
  2143. ;
  2144. tek41_exec_LE6:
  2145.     mov    si,offset tek41_fabuf
  2146.     call    tek_fill
  2147. tek41_exec_LE_ex:
  2148.     jmp    tek41_exec_done
  2149. ;
  2150. tek41_exec_RW:
  2151.     push    ax
  2152.     push    bx
  2153. ;
  2154. ; Check the variables
  2155. ;
  2156.     mov    si,offset tek41_argbuf
  2157.     mov    ax,[si]            ; x1
  2158.     mov    bx,[si+4]        ; x2
  2159.     cmp    ax,bx
  2160.     jl    tek41_exec_RW1
  2161.     jmp    tek41_exec_RW_ERR
  2162. tek41_exec_RW1:
  2163.     mov    ax,[si+2]        ; y1
  2164.     mov    bx,[si+6]        ; y2
  2165.     cmp    ax,bx
  2166.     jl    tek41_exec_RW2
  2167.     jmp    tek41_exec_RW_ERR
  2168. tek41_exec_RW2:
  2169. ;
  2170. ; Check OK. Do it.
  2171. ;
  2172.     mov    ax,[si]
  2173.     mov    tek_wnx1,ax
  2174.     mov    ax,[si+2]
  2175.     mov    tek_wny1,ax
  2176.     mov    ax,[si+4]
  2177.     mov    tek_wnx2,ax
  2178.     mov    ax,[si+6]
  2179.     mov    tek_wny2,ax
  2180. ;
  2181.     push    si
  2182.     push    di
  2183.     mov    si,offset tek_wnx1
  2184.     mov    di,offset tek_w2v_mat
  2185.     call    set_tek41_mat        ; set the transformation matrix
  2186.     pop    di
  2187.     pop    si
  2188.     jmp    tek41_exec_RW_ex
  2189. ;
  2190. tek41_exec_RW_ERR:
  2191. tek41_exec_RW_ex:
  2192.     pop    bx
  2193.     pop    ax
  2194.     jmp    tek41_exec_done
  2195. ;
  2196. tek41_exec_TM:
  2197.     push    bx
  2198.     mov    bx,offset tek41_argbuf
  2199.     mov    ax,[bx]
  2200.     cmp    ax,0
  2201.     je    tek41_exec_TM1
  2202.     mov    tek_cmode_1,al
  2203. tek41_exec_TM1:
  2204.     add    bx,2
  2205.     mov    ax,[bx]
  2206.     cmp    ax,0
  2207.     je    tek41_exec_TM2
  2208.     mov    tek_cmode_2,al
  2209. tek41_exec_TM2:
  2210.     add    bx,2
  2211.     mov    ax,[bx]
  2212.     cmp    ax,0
  2213.     je    tek41_exec_TM3
  2214.     mov    tek_cmode_3,al
  2215. tek41_exec_TM3:
  2216.     pop    bx
  2217.     jmp    tek41_exec_done
  2218. ;
  2219. tek41_exec_TG:
  2220.     push    si
  2221.     mov    si,offset tek41_argbuf
  2222.     mov    ax,[si]            ; ignore surface number
  2223. tek41_exec_TG1:
  2224.     mov    ax,[si+2]        ; array size
  2225.     cmp    ax,4            ; must be multiple of 4
  2226.     jge    tek41_exec_TG2
  2227.     jmp    tek41_exec_TG_ex
  2228. tek41_exec_TG2:
  2229.     shr    ax,1
  2230.     shr    ax,1            ; number of colors
  2231.     mov    cx,ax
  2232.     add    si,4
  2233. tek41_exec_TG_L1:
  2234.     cmp    cx,0
  2235.     jg    tek41_exec_TG_L2
  2236.     jmp    tek41_exec_TG_do
  2237. tek41_exec_TG_L2:
  2238.     mov    ax,[si]            ; get index
  2239.     cmp    ax,0
  2240.     jge    tek41_exec_TG3
  2241.     jmp    tek41_exec_TG_nx
  2242. tek41_exec_TG3:
  2243.     cmp    ax,15
  2244.     jle    tek41_exec_TG4
  2245.     jmp    tek41_exec_TG_nx
  2246. tek41_exec_TG4:
  2247.     cmp    tek_cmode_1,1        ; RGB [0-100] mode ?
  2248.     jne    tek41_exec_TG5
  2249.     jmp    tek41_exec_TG_RGB1
  2250. tek41_exec_TG5:
  2251.     cmp    tek_cmode_1,2        ; CMY [0-100] mode ?
  2252.     jne    tek41_exec_TG6
  2253.     jmp    tek41_exec_TG_CMY
  2254. tek41_exec_TG6:
  2255.     cmp    tek_cmode_1,3        ; HLS mode ?
  2256.     jne    tek41_exec_TG7
  2257.     jmp    tek41_exec_TG_HLS
  2258. tek41_exec_TG7:
  2259.     cmp    tek_cmode_1,4        ; RGB [0-255] mode ?
  2260.     jne    tek41_exec_TG8
  2261.     jmp    tek41_exec_TG_RGB2
  2262. tek41_exec_TG8:
  2263.     jmp    tek41_exec_TG_ex    ; other cases are not supported yet.
  2264. tek41_exec_TG_HLS:
  2265.     push    si
  2266.     add    si,2
  2267.     call    HLS_to_RGB
  2268.     pop    si
  2269.     jmp    tek41_exec_TG_RGB1
  2270. tek41_exec_TG_CMY:
  2271.     push    bx
  2272.     mov    ax,100
  2273.     mov    bx,[si+2]
  2274.     sub    ax,bx
  2275.     mov    [si+2],ax
  2276.     mov    ax,100
  2277.     mov    bx,[si+4]
  2278.     sub    ax,bx
  2279.     mov    [si+4],ax
  2280.     mov    ax,100
  2281.     mov    bx,[si+6]
  2282.     sub    ax,bx
  2283.     mov    [si+6],ax
  2284.     pop    bx
  2285. tek41_exec_TG_RGB1:
  2286.     push    bx
  2287.     push    dx
  2288.     mov    bx,655
  2289.     mov    ax,[si+2]        ; get R
  2290.     mul    bx
  2291.     mov    al,ah
  2292.     xor    ah,ah
  2293.     mov    [si+2],ax
  2294.     mov    ax,[si+4]        ; G
  2295.     mul    bx
  2296.     mov    al,ah
  2297.     xor    ah,ah
  2298.     mov    [si+4],ax
  2299.     mov    ax,[si+6]        ; B
  2300.     mul    bx
  2301.     mov    al,ah
  2302.     xor    ah,ah
  2303.     mov    [si+6],ax
  2304.     pop    dx
  2305.     pop    bx
  2306. tek41_exec_TG_RGB2:
  2307.     push    bx
  2308.     mov    bx,offset tek_col
  2309.     mov    ax,[si]            ; get index
  2310.     add    bx,ax
  2311.     add    bx,ax
  2312.     add    bx,ax
  2313.     mov    ax,[si+2]
  2314.     mov    [bx],al
  2315.     mov    ax,[si+4]
  2316.     mov    [bx+1],al
  2317.     mov    ax,[si+6]
  2318.     mov    [bx+2],al
  2319.     pop    bx
  2320. tek41_exec_TG_nx:
  2321.     dec    cx
  2322.     add    si,8            ; 4 integers are processed.
  2323.     jmp    tek41_exec_TG_L1
  2324. tek41_exec_TG_do:
  2325.     mov    si,offset tek_col
  2326.     call    set_gpalette
  2327. tek41_exec_TG_ex:
  2328.     pop    si
  2329. ;
  2330. tek41_exec_done:
  2331.     mov    tek41_cmd,0
  2332.     mov    tek_esc,0
  2333.     jmp    tek40_ex
  2334. ;
  2335. tek40_vtchg:
  2336.     cmp    tek_P_prv,'?'
  2337.     jne    tek40_vtchg_ex
  2338.     cmp    tek_P_buf,38
  2339.     jne    tek40_vtchg_ex
  2340.     mov    ah,1
  2341.     mov    al,0
  2342.     mov    cx,0
  2343.     clc
  2344.     ret
  2345. tek40_vtchg_ex:
  2346.     jmp    tek40_esc_ex
  2347.  
  2348. ;  Alpha mode: If printable character, then put the character at
  2349. ;  current position.
  2350. ;---------
  2351. tek40_alp:
  2352. ;---------
  2353.     and    al,07Fh
  2354.     cmp    al,' '        ; C0 character ?
  2355.     jae    tek40_alp_01    ; ae=no.
  2356.     jmp    tek40_C0
  2357. tek40_alp_01:
  2358.     cmp    tek_dialog_area,0    ; dialog on graphic screen ?
  2359.     je    tek40_alp_02    ; e = yes.
  2360.     mov    si,offset vt_buf
  2361.     mov    [si],al
  2362.     mov    cx,1
  2363.     stc            ; set carry to pass the char. to VT
  2364.     ret
  2365. tek40_alp_02:
  2366.     sub    al,' '
  2367.     xor    ah,ah
  2368.     shl    ax,1
  2369.     shl    ax,1
  2370.     shl    ax,1
  2371.     mov    si,offset gfont88
  2372.     add    si,ax
  2373.     mov    di,offset ggdc_buff
  2374.     mov    byte ptr [di],078h    ; TEXTW
  2375.     mov    byte ptr [di+1],8    ; number of parameters
  2376.     add    di,2
  2377.     cld
  2378.     mov    cx,8
  2379.     push    es
  2380.     push    ds
  2381.     pop    es
  2382.     rep    movsb
  2383.     pop    es
  2384. ;    add    di,8
  2385.     mov    ax,tek_cur_x
  2386.     mov    bx,tek_cur_y
  2387.     call    tek40_dev_cood
  2388.     push    di
  2389. ;@@    mov    cx,GGDC_GREEN_PLANE    ; cursor graphic plane
  2390.     xor    cx,cx
  2391.     call    gcsrw
  2392.     mov    byte ptr [di],20h
  2393.     mov    byte ptr [di+1],0
  2394.     add    di,2
  2395.     mov    byte ptr [di],04Ch    ; VEXTW
  2396.     mov    byte ptr [di+1],3    ; number of parameters
  2397.     mov    byte ptr [di+2],012h    ; normal text dir=2
  2398.     mov    byte ptr [di+3],07h
  2399.     mov    byte ptr [di+4],0
  2400.     mov    byte ptr [di+5],068h    ; TEXTE
  2401.     mov    byte ptr [di+6],0
  2402.     mov    byte ptr [di+7],0FFh    ; terminator
  2403.     mov    si,offset ggdc_buff
  2404. ;@@    call    send_to_GGDC
  2405.     mov    ax,tek_txcol        ; set text color
  2406.     pop    di
  2407.     call    GGDC_color
  2408.     mov    ax,TEK_DX
  2409.     add    tek_cur_x,ax
  2410.     jmp    tek40_ex
  2411. ;--------
  2412. tek40_C0:
  2413. ;--------
  2414.     cmp    al,ESCAPE        ; need to handle in this module?
  2415.     jl    tek40_C01        ; l=no. May go to vt
  2416.     jmp    tek40_C02
  2417. tek40_C01:
  2418.     cmp    tek_dialog_area,0    ; dialog on graphics ?
  2419.     je    tek40_C01_1        ; e=yes.
  2420.     mov    tek_esc,0
  2421.     mov    tek_mod,0
  2422.     mov    si,offset vt_buf
  2423.     mov    [si],al
  2424.     mov    cx,1
  2425.     stc                ; set carry to pass AL to VT
  2426.     ret
  2427. tek40_C01_1:
  2428.     mov    tek_esc,0
  2429.     mov    tek_mod,0
  2430.     cmp    al,BELL
  2431.     jne    tek40_n07
  2432.     call    pc98_bell
  2433.     jmp    tek40_ex
  2434. tek40_n07:
  2435.     cmp    al,BS
  2436.     jne    tek40_n08
  2437.     sub    tek_cur_x,TEK_DX
  2438.     cmp    tek_cur_x,0
  2439.     jge    tek40_08_01
  2440.     mov    tek_cur_x,0
  2441. tek40_08_01:
  2442.     mov    tek_esc,0
  2443.     jmp    tek40_ex
  2444. tek40_n08:
  2445. ;
  2446.     cmp    al,HT
  2447.     jne    tek40_n09
  2448.     add    tek_cur_x,TEK_DX
  2449.     cmp    tek_cur_x,TEK_X_MAX
  2450.     jle    tek40_09_01
  2451.     mov    tek_cur_x,TEK_X_MAX
  2452. tek40_09_01:
  2453.     mov    tek_esc,0
  2454.     jmp    tek40_ex
  2455. tek40_n09:
  2456. ;
  2457.     cmp    al,LF
  2458.     jne    tek40_n0A
  2459.     sub    tek_cur_y,TEK_DY
  2460.     cmp    tek_cur_y,0
  2461.     jge    tek40_0A_01
  2462.     mov    tek_cur_y,TEK_Y_MAX
  2463.     sub    tek_cur_y,TEK_DY
  2464. tek40_0A_01:
  2465.     mov    tek_esc,0            ; ESC seq done
  2466.     jmp    tek40_ex
  2467. tek40_n0A:
  2468. ;
  2469.     cmp    al,VT
  2470.     jne    tek40_n0B
  2471.     jmp    tek40_ex
  2472. tek40_n0B:
  2473.     cmp    al,CR
  2474.     jne    tek40_n0D
  2475.     mov    tek_cur_x,0
  2476.     mov    tek_mod,0            ; enter alpha mode
  2477.     mov    tek_esc,0            ; ESC seq done
  2478.     jmp    tek40_ex
  2479. tek40_n0D:
  2480. ;
  2481.     cmp    al,CL_CAN
  2482.     jne    tek40_n18
  2483.     mov    tek_mod,0
  2484.     mov    tek_esc,0
  2485. ;
  2486. ; Leave tektronix mode if tek4010 enabled
  2487. ;
  2488.     test    vt100_flags,AUTOTEK_BIT
  2489.     jz    tek40_18_01
  2490.     mov    ah,1            ; pass no character
  2491.     mov    al,0
  2492.     mov    cx,0
  2493.     clc
  2494.     ret
  2495. tek40_18_01:
  2496.     jmp    tek40_ex
  2497. tek40_n18:
  2498. ;
  2499. ; ESC, FS, GS, RS, US must be analyzed in TeK module
  2500. ;
  2501. tek40_C02:
  2502.     cmp    al,ESCAPE
  2503.     jne    tek40_n1B
  2504.     mov    tek_esc,1            ; initiate ESC sequence
  2505.     jmp    tek40_ex
  2506. tek40_n1B:
  2507. ;
  2508.     cmp    al,FS
  2509.     jne    tek40_n1C
  2510.     mov    tek_mod,2            ; enter point plot mode
  2511.     mov    tek_vseq,0            ; reset xy order sequence
  2512.     mov    di,offset ggdc_buff
  2513.     mov    byte ptr [di],078h        ; TEXTW command
  2514.     mov    byte ptr [di+1],2        ; number of parameters
  2515.     mov    word ptr [di+2],0FFFFh        ; set line type to solid
  2516.     mov    byte ptr [di+4],0FFh        ; terminator
  2517.     mov    si,offset ggdc_buff
  2518.     call    send_to_GGDC
  2519.     mov    tek_esc,0            ; ESC seq done
  2520.     jmp    tek40_ex
  2521. tek40_n1C:
  2522. ;
  2523.     cmp    al,GS
  2524.     jne    tek40_n1D
  2525.     mov    tek_mod,1            ; enter graph mode
  2526.     mov    tek_npnt,0            ; reset number of points
  2527.     mov    tek_vseq,0
  2528.     mov    ax,line_type
  2529.     call    tek_ltyp
  2530.     mov    tek_esc,0            ; ESC seq done
  2531.     jmp    tek40_ex
  2532. tek40_n1D:
  2533. ;
  2534.     cmp    al,RS
  2535.     jne    tek40_n1E
  2536.     mov    tek_mod,3            ; enter incremental plot mode
  2537.     mov    tek_pen,0            ; reset pen state
  2538.     mov    di,offset ggdc_buff
  2539.     mov    byte ptr [di],078h        ; TEXTW command
  2540.     mov    byte ptr [di+1],2        ; number of parameters
  2541.     mov    word ptr [di+2],0FFFFh        ; set line type to solid
  2542.     mov    byte ptr [di+4],0FFh        ; terminator
  2543.     mov    si,offset ggdc_buff
  2544.     call    send_to_GGDC
  2545.     mov    tek_esc,0            ; ESC seq done
  2546.     jmp    tek40_ex
  2547. tek40_n1E:
  2548. ;
  2549.     cmp    al,US
  2550.     jne    tek40_n1F
  2551.     mov    tek_mod,0            ; enter alpha mode
  2552.     mov    line_type,0
  2553.     mov    tek_esc,0            ; ESC seq done
  2554.     jmp    tek40_ex
  2555. tek40_n1F:
  2556.     mov    tek_esc,0        ; Unknonw C0 character
  2557.     jmp    tek40_ex
  2558.  
  2559. ;---------
  2560. tek40_vct:
  2561. ;---------
  2562.     and    al,07Fh            ; Mask 8th bit
  2563.     cmp    al,' '            ; Control character ?
  2564.     jae    tek40_vct_01        ; ae = No.
  2565.     cmp    al,ESCAPE
  2566.     jae    tek40_vct_C0
  2567.     cmp    al,CR
  2568.     jne    tek40_vct_n0D
  2569.     cmp    tek_dialog_area,0    ; disable dialog ?
  2570.     je    tek40_vct_C0        ; e=yes.
  2571. tek40_vct_n0D:
  2572.     jmp    tek40_ex        ; any other C0 characters are ignored.
  2573. tek40_vct_C0:
  2574.     jmp    tek40_C0        ; Yes. control character.
  2575. tek40_vct_01:
  2576.     mov    ah,al
  2577.     and    ah,060h
  2578.     and    al,01Fh
  2579. ;
  2580.     cmp    tek_vseq,0
  2581.     jne    tek40_vct_02
  2582. tek40_vct_HIY:
  2583.     cmp    ah,HIY            ; HIY data ?
  2584.     jne    tek40_vct_EXT
  2585.     mov    tek_cur_HIY,al        ; Yes. Fill HIY
  2586.     mov    tek_vseq,1        ; Next is EXT
  2587.     jmp    tek40_vct_end
  2588. tek40_vct_02:
  2589.     cmp    tek_vseq,1        ; EXT order?
  2590.     jne    tek40_vct_03
  2591. tek40_vct_EXT:
  2592.     cmp    ah,EXT            ; EXT data ?
  2593.     jne    tek40_vct_LOY
  2594.     mov    tek_cur_LOY,al        ; Yes. Temporary store to LOY
  2595.     mov    tek_vseq,2        ; Next is LOY
  2596.     jmp    tek40_vct_end
  2597. tek40_vct_03:
  2598.     cmp    tek_vseq,2        ; LOY order ?
  2599.     jne    tek40_vct_04
  2600. tek40_vct_LOY:
  2601.     cmp    ah,LOY            ; LOY data ?
  2602.     jne    tek40_vct_HIX
  2603.     mov    ah,tek_cur_LOY        ; Yes. LOY/EXT appears twice.
  2604.     mov    tek_cur_EXT,ah        ; Previous is EXT and current is LOY
  2605.     mov    tek_cur_LOY,al
  2606.     mov    tek_vseq,3        ; Next is HIX
  2607.     jmp    tek40_vct_end
  2608. tek40_vct_04:
  2609.     cmp    tek_vseq,3        ; HIX order ?
  2610.     jne    tek40_vct_05
  2611. tek40_vct_HIX:
  2612.     cmp    ah,HIX            ; HIX data ?
  2613.     jne    tek40_vct_LOX        ; No. Test LOX data
  2614.     mov    tek_cur_HIX,al        ; Yes. Set HIX
  2615.     mov    tek_vseq,4        ; Next is LOX
  2616.     jmp    tek40_vct_end
  2617. tek40_vct_05:
  2618.     cmp    tek_vseq,4        ; LOX order ?
  2619.     jne    tek40_vct_ERR
  2620. tek40_vct_LOX:
  2621.     cmp    ah,LOX            ; LOX data ?
  2622.     jne    tek40_vct_ERR        ; No. This is error
  2623.     mov    tek_cur_LOX,al        ; Yes. Set LOX
  2624.     mov    tek_vseq,0        ; GS seq done
  2625.     jmp    tek40_get_xy
  2626. tek40_vct_ERR:
  2627.     call    pc98_bell
  2628.     mov    tek_vseq,0
  2629.     mov    tek_npnt,0
  2630.     cmp    tek_esc,4        ; in Tek41 command ?
  2631.     jne    tek40_vct_ERR1        ; ne = no.
  2632.     mov    tek_req_x,0
  2633.     mov    tek_req_y,0
  2634.     jmp    tek41_xy1
  2635. tek40_vct_ERR1:
  2636.     jmp    tek40_vct_end
  2637. ;
  2638. ;  Convert TEK xy representation to the binary (x,y)
  2639. ;
  2640. tek40_get_xy:
  2641.     mov    al,tek_cur_HIY        ; get HIY
  2642.     xor    ah,ah            ; clear higher byte
  2643.     mov    cl,5            ; number of shifts
  2644.     shl    ax,cl            ; HIY done
  2645.     or    al,tek_cur_LOY        ; add LOY
  2646.     shl    ax,1
  2647.     shl    ax,1
  2648.     mov    bl,tek_cur_EXT        ; get EXT
  2649.     shr    bl,1
  2650.     shr    bl,1
  2651.     and    bl,3            ; Lower 2 bits have meaning
  2652.     or    al,bl            ; all done.
  2653.     mov    tek_req_y,ax        ; set requested y
  2654. ;
  2655.     mov    al,tek_cur_HIX        ; get HIX
  2656.     xor    ah,ah            ; clear higher byte
  2657.     mov    cl,5            ; number of shifts
  2658.     shl    ax,cl            ; HIX is set
  2659.     or    al,tek_cur_LOX        ; add LOX
  2660.     shl    ax,1
  2661.     shl    ax,1
  2662.     mov    bl,tek_cur_EXT        ; get EXT
  2663.     and    bl,3            ; Only lower 2 bits have meaning
  2664.     or    al,bl            ; all done.
  2665.     mov    tek_req_x,ax        ; set requested x
  2666. ;
  2667.     cmp    tek_esc,4        ; in TeK41 command ?
  2668.     jne    tek40_get_xy1        ; ne = no.
  2669.     jmp    tek41_xy1
  2670. tek40_get_xy1:
  2671.     cmp    tek_inpanel,0        ; in Panel mode ?
  2672.     je    tek40_get_xy2        ; e = no.
  2673.     jmp    tek40_vct_fa
  2674. tek40_get_xy2:
  2675. ;
  2676.     cmp    tek_mod,1
  2677.     je    tek40_vec_ln
  2678.     jmp    tek40_vct_pt
  2679. tek40_vec_ln:
  2680.     cmp    tek_npnt,0
  2681.     jne    tek40_vct_ln01
  2682.     mov    tek_npnt,1
  2683.     jmp    tek40_vct_do1
  2684. ;
  2685. tek40_vct_ln01:
  2686. ;
  2687. ;    Not the first point. Draw line.
  2688. ;
  2689.     mov    ax,tek_cur_x
  2690.     mov    bx,tek_cur_y
  2691.     call    tek40_dev_cood
  2692.     mov    pc98_x1,ax
  2693.     mov    pc98_y1,bx
  2694.     mov    ax,tek_req_x
  2695.     mov    bx,tek_req_y
  2696.     call    tek40_dev_cood
  2697.     mov    pc98_x2,ax
  2698.     mov    pc98_y2,bx
  2699.     call    tek_draw
  2700.     jmp    tek40_vct_do1
  2701. ;
  2702. ; Point plot mode
  2703. ;
  2704. tek40_vct_pt:
  2705.     mov    ax,tek_req_x
  2706.     mov    bx,tek_req_y
  2707.     call    tek40_dev_cood
  2708.     call    tek_mark
  2709. ;
  2710. tek40_vct_do:
  2711.     mov    di,si
  2712. ;@@    call    send_to_GGDC
  2713.     call    GGDC_color
  2714. tek40_vct_do1:
  2715.     mov    ax,tek_req_x
  2716.     mov    tek_cur_x,ax
  2717.     mov    ax,tek_req_y
  2718.     mov    tek_cur_y,ax
  2719.     jmp    tek40_vct_end
  2720. ;
  2721. tek40_vct_fa:
  2722.     mov    ax,tek_req_x
  2723.     mov    bx,tek_req_y
  2724.     call    tek40_dev_cood
  2725.     mov    cx,tek41_lfa
  2726.     add    cx,10            ; requested length
  2727.     cmp    cx,TEK41_FABUF_SIZE    ; have enough room ?
  2728.     jbe    tek40_vct_fa1        ; be=yes
  2729.     jmp    tek40_vct_fa2
  2730. tek40_vct_fa1:
  2731.     push    si
  2732.     mov    si,offset tek41_fabuf
  2733.     add    si,tek41_lfa
  2734.     mov    [si],ax
  2735.     mov    [si+2],bx
  2736.     add    tek41_lfa,4
  2737.     mov    si,tek41_faadr
  2738.     mov    cx,[si]
  2739.     inc    cx
  2740.     mov    [si],cx            ; increment number of points
  2741.     pop    si
  2742.     cmp    ax,scan_xmin
  2743.     jge    tek40_vct_fa1_1
  2744.     mov    scan_xmin,ax
  2745. tek40_vct_fa1_1:
  2746.     cmp    ax,scan_xmax
  2747.     jle    tek40_vct_fa1_2
  2748.     mov    scan_xmax,ax
  2749. tek40_vct_fa1_2:
  2750.     cmp    bx,scan_ymin
  2751.     jge    tek40_vct_fa1_3
  2752.     mov    scan_ymin,bx
  2753. tek40_vct_fa1_3:
  2754.     cmp    bx,scan_ymax
  2755.     jle    tek40_vct_fa1_4
  2756.     mov    scan_ymax,bx
  2757. tek40_vct_fa1_4:
  2758. tek40_vct_fa2:
  2759.     cmp    tek_panel_bnd,0
  2760.     je    tek40_vct_end
  2761.     xchg    ax,pc98_x2
  2762.     xchg    bx,pc98_y2
  2763.     mov    pc98_x1,ax
  2764.     mov    pc98_y1,bx
  2765.     mov    ax,pc98_x2
  2766.     mov    bx,pc98_y2
  2767.     call    tek_draw
  2768. tek40_vct_end:
  2769.     jmp    tek40_ex
  2770. ;
  2771. ; Incremental Plot
  2772. ;
  2773. tek40_inc:
  2774.     and    al,07Fh            ; mask 8th bit
  2775.     cmp    al,'A'            ; move to right?
  2776.     jne    tek40_inc_NA        ; ne = no
  2777.     inc    tek_cur_x
  2778.     jmp    tek40_inc_do
  2779. tek40_inc_NA:
  2780.     cmp    al,'B'            ; move to left?
  2781.     jne    tek40_inc_NB        ; ne = no.
  2782.     dec    tek_cur_x
  2783.     jmp    tek40_inc_do
  2784. tek40_inc_NB:
  2785.     cmp    al,'D'            ; move to up?
  2786.     jne    tek40_inc_ND        ; ne = no.
  2787.     inc    tek_cur_y
  2788.     jmp    tek40_inc_do
  2789. tek40_inc_ND:
  2790.     cmp    al,'H'            ; move to down?
  2791.     jne    tek40_inc_NH        ; ne = no.
  2792.     dec    tek_cur_y
  2793.     jmp    tek40_inc_do
  2794. tek40_inc_NH:
  2795.     cmp    al,'E'            ; move to right up
  2796.     jne    tek40_inc_NE
  2797.     inc    tek_cur_x
  2798.     inc    tek_cur_y
  2799.     jmp    tek40_inc_do
  2800. tek40_inc_NE:
  2801.     cmp    al,'J'
  2802.     jne    tek40_inc_NJ
  2803.     dec    tek_cur_x
  2804.     dec    tek_cur_y
  2805.     jmp    tek40_inc_do
  2806. tek40_inc_NJ:
  2807.     cmp    al,'F'
  2808.     jne    tek40_inc_NF
  2809.     dec    tek_cur_x
  2810.     inc    tek_cur_y
  2811.     jmp    tek40_inc_do
  2812. tek40_inc_NF:
  2813.     cmp    al,'I'
  2814.     jne    tek40_inc_NI
  2815.     inc    tek_cur_x
  2816.     dec    tek_cur_y
  2817.     jmp    tek40_inc_do
  2818. tek40_inc_NI:
  2819.     cmp    al,' '
  2820.     jne    tek40_inc_NS
  2821.     mov    tek_pen,0
  2822.     jmp    tek40_ex
  2823. tek40_inc_NS:
  2824.     cmp    al,'P'
  2825.     jne    tek40_inc_NP
  2826.     mov    tek_pen,1
  2827.     jmp    tek40_ex
  2828. tek40_inc_NP:
  2829.     mov    tek_mod,0        ; Enter alpha mode
  2830.     jmp    tek40_00
  2831. tek40_inc_do:
  2832.     cmp    tek_pen,0
  2833.     jne    tek40_inc_do1
  2834.     jmp    tek40_ex
  2835. tek40_inc_do1:
  2836.     mov    di,offset ggdc_buff
  2837.     mov    ax,tek_cur_x
  2838.     mov    bx,tek_cur_y
  2839.     call    tek40_dev_cood
  2840. ;@@    mov    cx,GGDC_GREEN_PLANE
  2841.     xor    cx,cx
  2842.     call    gcsrw
  2843.     mov    byte ptr [di],20h
  2844.     mov    byte ptr [di+1],0
  2845.     add    di,2
  2846. ;
  2847.     mov     byte ptr [di],4ch        ; VECTW command
  2848.     mov    byte ptr [di+1],9        ; number of parameters
  2849. ;
  2850.     mov    byte ptr [di+2],0        ; dir
  2851.     mov    word ptr [di+3],0        ; abs(d_x)
  2852.     mov    word ptr [di+5],0        ; 2*abs(d_y)-abs(d_x)
  2853.     mov    word ptr [di+7],0        ; 2*abs(d_y)-2*abs(d_x)
  2854.     mov    word ptr [di+9],0        ; 2*abs(d_y)
  2855. ;
  2856.     mov    byte ptr [di+11],6ch        ; VECTE command
  2857.     mov    byte ptr [di+12],0        ; with no parameters
  2858.     add    di,13                ; update address
  2859. ;
  2860.     mov    byte ptr [di],0FFh        ; set terminator
  2861.     mov    si,offset ggdc_buff
  2862.     mov    ax,tek_lncol            ; set line color
  2863. ;
  2864.     mov    di,si
  2865. ;@@    call    send_to_GGDC
  2866.     call    GGDC_color
  2867.     jmp    tek40_ex
  2868. ;
  2869. TEK4014    ENDP
  2870. ;
  2871. tek_ltyp    proc    near
  2872. ;
  2873. ; Set line type in AX
  2874. ;
  2875.     shl    ax,1
  2876.     mov    si,offset line_type_table
  2877.     add    si,ax
  2878.     mov    ax,[si]
  2879.     mov    di,offset ggdc_buff
  2880.     mov    byte ptr [di],078h    ; TEXTW command
  2881.     mov    byte ptr [di+1],2    ; number of parameters
  2882.     mov    word ptr [di+2],ax    ; line type
  2883.     mov    byte ptr [di+4],0FFh    ; terminator
  2884.     mov    si,offset ggdc_buff
  2885.     call    send_to_GGDC
  2886.     ret
  2887. tek_ltyp    endp
  2888. ;
  2889. tek_draw    proc    near
  2890. ;
  2891. ; Draw line between from (pc98_x1,pc98_y1) to (ax,bx)
  2892. ;
  2893.     push    ax
  2894.     push    bx
  2895.     mov    di,offset ggdc_buff
  2896.     mov    ax,pc98_x1
  2897.     mov    bx,pc98_y1
  2898.     xor    cx,cx
  2899.     call    gcsrw
  2900.     mov    byte ptr [di],20h
  2901.     mov    byte ptr [di+1],0
  2902.     add    di,2
  2903.     pop    bx
  2904.     pop    ax
  2905.     sub    ax,pc98_x1
  2906.     sub    bx,pc98_y1
  2907.     call    gline
  2908.     mov    byte ptr [di],0FFh
  2909.     mov    si,offset ggdc_buff
  2910.     mov    ax,tek_lncol
  2911.     mov    di,si
  2912.     call    GGDC_color
  2913.     ret
  2914. tek_draw    endp
  2915. ;
  2916. tek_mark    proc    near
  2917. ;
  2918. ;  Put marker at (ax,bx) given in device coordinate
  2919. ;
  2920.     cmp    marker_type,0        ; marker type 0 ?
  2921.     je    tek_mark_0        ; e=yes
  2922.     jmp    tek_mark_n0
  2923. tek_mark_0:
  2924.     xor    cx,cx
  2925.     call    gcsrw
  2926.     mov    byte ptr [di],20h
  2927.     mov    byte ptr [di+1],0
  2928.     add    di,2
  2929. ;
  2930.     mov     byte ptr [di],4ch        ; VECTW command
  2931.     mov    byte ptr [di+1],9        ; number of parameters
  2932. ;
  2933.     mov    byte ptr [di+2],0        ; dir
  2934.     mov    word ptr [di+3],0        ; abs(d_x)
  2935.     mov    word ptr [di+5],0        ; 2*abs(d_y)-abs(d_x)
  2936.     mov    word ptr [di+7],0        ; 2*abs(d_y)-2*abs(d_x)
  2937.     mov    word ptr [di+9],0        ; 2*abs(d_y)
  2938. ;
  2939.     mov    byte ptr [di+11],6ch        ; VECTE command
  2940.     mov    byte ptr [di+12],0        ; with no parameters
  2941.     add    di,13                ; update address
  2942. ;
  2943.     mov    byte ptr [di],0FFh        ; set terminator
  2944.     mov    si,offset ggdc_buff
  2945.     mov    ax,tek_lncol            ; set line color
  2946.     mov    di,si
  2947.     jmp    tek_mark_do
  2948. tek_mark_n0:
  2949.     push    ax
  2950.     push    bx
  2951.     mov    ax,marker_type
  2952.     xor    ah,ah
  2953.     shl    ax,1
  2954.     shl    ax,1
  2955.     shl    ax,1
  2956.     mov    si,offset gmark88
  2957.     add    si,ax
  2958.     mov    di,offset ggdc_buff
  2959.     mov    byte ptr [di],078h    ; TEXTW
  2960.     mov    byte ptr [di+1],8    ; number of parameters
  2961.     add    di,2
  2962.     cld
  2963.     mov    cx,8
  2964.     push    es
  2965.     push    ds
  2966.     pop    es
  2967.     rep    movsb
  2968.     pop    es
  2969. ;@@    add    di,8
  2970.     mov    byte ptr [di],0ffh    ; set terminator
  2971.     mov    si,offset ggdc_buff
  2972.     call    send_to_GGDC
  2973.     pop    bx
  2974.     pop    ax            ; remember x position
  2975.     add    ax,mark_dx
  2976.     add    bx,mark_dy
  2977.     mov    di,offset ggdc_buff
  2978.     xor    cx,cx
  2979.     call    gcsrw
  2980.     mov    byte ptr [di],20h
  2981.     mov    byte ptr [di+1],0
  2982.     add    di,2
  2983.     mov    byte ptr [di],04Ch    ; VECTW
  2984.     mov    byte ptr [di+1],3    ; number of parameters
  2985.     mov    byte ptr [di+2],012h    ; normal text dir=2
  2986.     mov    byte ptr [di+3],07h
  2987.     mov    byte ptr [di+4],0
  2988.     mov    byte ptr [di+5],068h    ; TEXTE
  2989.     mov    byte ptr [di+6],0
  2990.     mov    byte ptr [di+7],0FFh    ; terminator
  2991.     mov    di,offset ggdc_buff
  2992.     mov    si,di
  2993.     mov    ax,tek_lncol        ; set marker color
  2994. tek_mark_do:
  2995.     call    GGDC_color
  2996.     ret
  2997. tek_mark    endp
  2998. ;
  2999. tek_gtxt    proc    near
  3000. ;
  3001. ; Write Graphic Text
  3002. ;    cx    number of characters
  3003. ;    [si]    strings
  3004. ;
  3005. tek_gtxt1:
  3006.     cmp    cx,0
  3007.     jg    tek_gtxt2
  3008.     jmp    tek_gtxt_ex
  3009. tek_gtxt2:
  3010.     push    cx
  3011.     push    si
  3012. ;
  3013.     mov    al,[si]
  3014.     and    al,07Fh
  3015.     cmp    al,' '
  3016.     jae    tek_gtxt3
  3017.     mov    al,' '
  3018. tek_gtxt3:
  3019.     sub    al,' '
  3020.     xor    ah,ah
  3021.     shl    ax,1
  3022.     shl    ax,1
  3023.     shl    ax,1
  3024.     mov    si,offset gfont88
  3025.     add    si,ax
  3026.     mov    di,offset ggdc_buff
  3027.     mov    byte ptr [di],078h    ; TEXTW
  3028.     mov    byte ptr [di+1],8    ; number of parameters
  3029.     add    di,2
  3030.     cld
  3031.     mov    cx,8
  3032.     push    es
  3033.     push    ds
  3034.     pop    es
  3035.     rep    movsb
  3036.     pop    es
  3037. ;    add    di,8
  3038.     mov    byte ptr [di],0FFh    ; set terminator
  3039.     mov    si,offset ggdc_buff
  3040.     call    send_to_GGDC
  3041. ;
  3042.     mov    ax,tek_cur_x
  3043.     mov    bx,tek_cur_y
  3044.     call    tek40_dev_cood
  3045.     mov    di,offset ggdc_buff
  3046. ;@@    mov    cx,GGDC_GREEN_PLANE    ; cursor graphic plane
  3047.     xor    cx,cx
  3048.     call    gcsrw
  3049.     mov    byte ptr [di],20h
  3050.     mov    byte ptr [di+1],0
  3051.     add    di,2
  3052.     mov    byte ptr [di],04Ch    ; VEXTW
  3053.     mov    byte ptr [di+1],3    ; number of parameters
  3054.     mov    al,010h            ; normal text
  3055.     or    al,tek_gtxt_dr        ; set text dir
  3056.     mov    byte ptr [di+2],al
  3057.     mov    byte ptr [di+3],07h
  3058.     mov    byte ptr [di+4],0
  3059.     mov    byte ptr [di+5],068h    ; TEXTE
  3060.     mov    byte ptr [di+6],0
  3061.     mov    byte ptr [di+7],0FFh    ; terminator
  3062.     mov    si,offset ggdc_buff
  3063.     mov    di,si
  3064. ;@@    call    send_to_GGDC
  3065.     mov    ax,tek_lncol        ; set text color
  3066.     call    GGDC_color
  3067.     mov    ax,tek_gtxt_ux
  3068.     add    tek_cur_x,ax
  3069.     mov    ax,tek_gtxt_uy
  3070.     add    tek_cur_y,ax
  3071. ;
  3072.     pop    si
  3073.     pop    cx
  3074.     inc    si
  3075.     dec    cx
  3076.     jmp    tek_gtxt1
  3077. tek_gtxt_ex:
  3078.     ret
  3079. tek_gtxt    endp
  3080. ;
  3081. ; Routines for Fill Area
  3082. ;
  3083. scan_clr    proc    near
  3084. ;
  3085. ; Purpose: Clear the scan buffer, scan_buf.
  3086. ; Input:   none
  3087. ; Output:  none
  3088. ;
  3089.     push    ax
  3090.     push    cx
  3091.     push    di
  3092.     push    es
  3093. ;
  3094.     cld
  3095.     mov    cx,40            ; size of the scan buffer in words
  3096.     mov    di,offset scan_buf
  3097.     push    ds
  3098.     pop    es            ; es = ds
  3099.     xor    ax,ax            ; data
  3100.     rep    stosw            ; string clear
  3101. ;
  3102.     pop    es
  3103.     pop    di
  3104.     pop    cx
  3105.     pop    ax
  3106.     ret
  3107. scan_clr    endp
  3108. ;
  3109. scan_cross    proc    near
  3110. ;
  3111. ; Purpose:  calculate the cross point of the line and scan_y
  3112. ; Input:    san_y, [si], scan_xmin, scan_xmax, bit_on
  3113. ; Output:   scan_buf
  3114. ; WorkArea: pc98_x1, pc98_y1, pc98_x2, pc98_y2
  3115. ;
  3116.     push    ax
  3117.     push    bx
  3118.     push    dx
  3119. ;
  3120.     mov    ax,[si+2]        ; y1
  3121.     mov    bx,[si+6]        ; y2
  3122.     cmp    bx,ax            ; y2 > y1 ?
  3123.     jg    scan_cross_1        ; g=yes
  3124.     mov    pc98_y1,bx
  3125.     mov    pc98_y2,ax
  3126.     mov    ax,[si+4]
  3127.     mov    bx,[si]
  3128.     jmp    scan_cross_2
  3129. scan_cross_1:
  3130.     mov    pc98_y1,ax
  3131.     mov    pc98_y2,bx
  3132.     mov    ax,[si]
  3133.     mov    bx,[si+4]
  3134. scan_cross_2:
  3135.     mov    pc98_x1,ax
  3136.     mov    pc98_x2,bx
  3137.     mov    ax,scan_y
  3138.     cmp    ax,pc98_y1        ; scan_y >= y1
  3139.     jge    scan_cross_3        ; ge=yes
  3140.     jmp    scan_cross_ex
  3141. scan_cross_3:
  3142.     cmp    ax,pc98_y2        ; scan_y < y2
  3143.     jl    scan_cross_4        ; l=yes
  3144.     jmp    scan_cross_ex
  3145. scan_cross_4:
  3146.     sub    ax,pc98_y1        ; ax = scan_y - y1
  3147.     mov    bx,pc98_x2
  3148.     sub    bx,pc98_x1        ; bx = x2 - x1
  3149.     imul    bx            ; dx:ax =(scan_y - y1)*(x2-x1)
  3150.     mov    bx,pc98_y2
  3151.     sub    bx,pc98_y1        ; bx = y2 - y1
  3152.     idiv    bx            ; dx:ax =(scan_y-y1)*(x2-x1)/(y2-y1)
  3153.     add    ax,pc98_x1
  3154.     cmp    ax,scan_xmin        ; scan_x < xmin ?
  3155.     jge    scan_cross_5        ; ge = no
  3156.     mov    ax,scan_xmin
  3157. scan_cross_5:
  3158.     cmp    ax,scan_xmax        ; scan_x > xmax ?
  3159.     jle    scan_cross_6        ; le = no
  3160.     mov    ax,scan_xmax
  3161. scan_cross_6:
  3162.     push    ax
  3163.     and    ax,07h
  3164.     mov    bx,offset bit_on
  3165.     add    bx,ax
  3166.     mov    dl,[bx]
  3167.     pop    ax
  3168.     mov    bx,offset scan_buf
  3169.     shr    ax,1
  3170.     shr    ax,1
  3171.     shr    ax,1
  3172.     add    bx,ax
  3173.     xor    [bx],dl
  3174. scan_cross_ex:
  3175.     pop    dx
  3176.     pop    bx
  3177.     pop    ax
  3178.     ret
  3179. scan_cross    endp
  3180. ;
  3181. scan_fill    proc    near
  3182. ;
  3183. ; fill the scan line
  3184. ;
  3185.     push    ax
  3186.     push    bx
  3187.     push    cx
  3188.     push    dx
  3189.     push    si
  3190. ;
  3191.     mov    si,offset scan_buf
  3192.     add    si,scan_xstr
  3193.     mov    dx,0ff00h        ; dh:fill, dl:no-fill
  3194.     mov    cx,scan_xlen
  3195. scan_fill_1:
  3196.     mov    al,[si]
  3197.     cmp    al,0
  3198.     jne    scan_fill_2
  3199.     mov    [si],dl
  3200.     jmp    scan_fill_5
  3201. scan_fill_2:
  3202.     push    cx
  3203.     mov    cx,8
  3204.     mov    bx,offset bit_on
  3205. scan_fill_3:
  3206.     mov    ah,[bx]
  3207.     and    ah,al
  3208.     cmp    ah,0
  3209.     je    scan_fill_4
  3210.     xchg    dh,dl
  3211. scan_fill_4:
  3212.     mov    ah,[bx]
  3213.     and    ah,dl
  3214.     or    [si],ah
  3215.     inc    bx
  3216.     loop    scan_fill_3
  3217.     pop    cx
  3218. scan_fill_5:
  3219.     inc    si
  3220.     loop    scan_fill_1
  3221.     pop    si
  3222.     pop    dx
  3223.     pop    cx
  3224.     pop    bx
  3225.     pop    ax
  3226.     ret
  3227. scan_fill    endp
  3228. ;
  3229. scan_put    proc    near
  3230. ;
  3231. ; Put the scan line to the graphic screen
  3232. ;
  3233.     push    es
  3234.     cld
  3235.     mov    dx,1
  3236.     xor    ch,ch
  3237.     mov    cl,gplane_nums
  3238.     mov    bx,offset gplane_segm
  3239. scan_put1:
  3240.     push    bx
  3241.     push    cx
  3242.     mov    ax,[bx]
  3243.     mov    es,ax
  3244.     mov    di,scan_ofs
  3245.     mov    si,offset scan_buf
  3246.     add    si,scan_xstr
  3247.     mov    cx,scan_xlen
  3248.     test    tek_facol,dx
  3249.     jz    scan_put3
  3250. scan_put2:
  3251.     lodsb
  3252.     or    es:[di],al
  3253.     inc    di
  3254.     loop    scan_put2
  3255.     jmp    scan_put4
  3256. scan_put3:
  3257.     lodsb
  3258.     xor    al,0ffh
  3259.     and    es:[di],al
  3260.     inc    di
  3261.     loop    scan_put3
  3262. scan_put4:
  3263.     pop    cx
  3264.     pop    bx
  3265.     add    bx,2
  3266.     shl    dx,1
  3267.     loop    scan_put1
  3268. scan_put_ex:
  3269.     pop    es
  3270.     ret
  3271. scan_put    endp
  3272. ;
  3273. tek_fill    proc    near
  3274. ;
  3275. ; Fill area
  3276. ;
  3277.     mov    ax,scan_ymin
  3278.     mov    scan_y,ax
  3279.     shl    ax,1
  3280.     shl    ax,1
  3281.     add    ax,scan_y        ; ax=scan_y*5
  3282.     mov    cx,4
  3283.     shl    ax,cl            ; ax=scan_y*80
  3284.     mov    scan_ofs,ax
  3285.     mov    ax,scan_xmin
  3286.     mov    cx,3
  3287.     shr    ax,cl
  3288.     mov    scan_xstr,ax        ; start byte address in x
  3289.     add    scan_ofs,ax
  3290.     mov    ax,scan_xmax
  3291.     mov    cx,3
  3292.     shr    ax,cl
  3293.     sub    ax,scan_xstr
  3294.     inc    ax
  3295.     mov    scan_xlen,ax
  3296. ;
  3297.     cmp    gdisp_mode,0
  3298.     je    tek_fill_1
  3299.     jmp    tek_fill_GC1
  3300. tek_fill_1:
  3301.     mov    ax,scan_y
  3302.     cmp    ax,scan_ymax
  3303.     jle    tek_fill_2
  3304.     jmp    tek_fill_ex
  3305. tek_fill_2:
  3306.     call    scan_clr            ; clear the scan buffer
  3307.     mov    si,offset tek41_fabuf        ; position of the line
  3308. ;
  3309. tek_fill_3:
  3310.     mov    cx,[si]                ; get number of points
  3311.     jcxz    tek_fill_5
  3312.     add    si,2
  3313. tek_fill_4:
  3314.     call    scan_cross
  3315.     add    si,4
  3316.     loop    tek_fill_4
  3317.     add    si,4
  3318.     jmp    tek_fill_3
  3319. tek_fill_5:
  3320.     call    scan_fill
  3321.     call    scan_put
  3322.     inc    scan_y
  3323.     add    scan_ofs,80
  3324.     jmp    tek_fill_1
  3325. ;
  3326. tek_fill_GC1:
  3327.     cld
  3328.     mov    al,0C0h        ; GRCG on, RMW mode, all planes are active
  3329.     out    7Ch,al
  3330.     mov    cx,4
  3331.     mov    dx,1
  3332. tek_fill_GC2:
  3333.     test    tek_facol,dx
  3334.     jz    tek_fill_GC3
  3335.     mov    al,0FFh
  3336.     jmp    tek_fill_GC4
  3337. tek_fill_GC3:
  3338.     mov    al,0
  3339. tek_fill_GC4:
  3340.     out    7Eh,al        ; write tile reg.
  3341.     shl    dx,1
  3342.     loop    tek_fill_GC2
  3343. ;
  3344.     push    es
  3345. tek_fill_GC5:
  3346.     mov    ax,scan_y
  3347.     cmp    ax,scan_ymax
  3348.     jg    tek_fill_GC7
  3349.     call    scan_clr            ; clear the scan buffer
  3350.     mov    si,offset tek41_fabuf        ; position of the line
  3351. tek_fill_GC8:
  3352.     mov    cx,[si]                ; number of lines
  3353.     jcxz    tek_fill_GC9
  3354.     add    si,2
  3355. tek_fill_GC6:
  3356.     call    scan_cross
  3357.     add    si,4
  3358.     loop    tek_fill_GC6
  3359.     add    si,4
  3360.     jmp    tek_fill_GC8
  3361. tek_fill_GC9:
  3362.     call    scan_fill
  3363.     mov    di,scan_ofs
  3364.     mov    ax,gplane_segm
  3365.     mov    es,ax
  3366.     mov    si,offset scan_buf
  3367.     add    si,scan_xstr
  3368.     mov    cx,scan_xlen
  3369.     rep    movsb
  3370.     inc    scan_y
  3371.     add    scan_ofs,80
  3372.     jmp    tek_fill_GC5
  3373. tek_fill_GC7:
  3374.     mov    al,040h                ; GRCG off
  3375.     out    7Ch,al
  3376.     pop    es
  3377. ;
  3378. tek_fill_ex:
  3379.     ret
  3380. tek_fill    endp
  3381. ;
  3382. tek41_getcol    proc    near
  3383. ;
  3384. ; convert tek41 color index to normal index
  3385. ;
  3386.     push    bx
  3387.     and    ax,0fh
  3388.     mov    bx,offset tek41_col
  3389.     add    bx,ax
  3390.     mov    ax,[bx]
  3391.     pop    bx
  3392.     ret
  3393. tek41_getcol    endp
  3394. ;
  3395. set_gcolor    proc    near
  3396. ;
  3397. ; set graphic color
  3398. ;
  3399.     push    ax
  3400.     push    si
  3401.     mov    al,vt100_gflag
  3402.     and    al,07Fh            ; mask text screen ctrl bit
  3403.     cmp    al,0
  3404.     jne    set_gcolor_n0
  3405.     mov    si,offset gnrm_color
  3406.     jmp    set_gcolor_do
  3407. set_gcolor_n0:
  3408.     cmp    al,1
  3409.     jne    set_gcolor_n1
  3410.     mov    si,offset gbck_color
  3411.     jmp    set_gcolor_do
  3412. set_gcolor_n1:
  3413.     cmp    al,2
  3414.     jne    set_gcolor_n2
  3415.     mov    si,offset sixel_col
  3416.     jmp    set_gcolor_do
  3417. set_gcolor_n2:
  3418.     cmp    al,3
  3419.     jne    set_gcolor_n3
  3420.     mov    si,offset sixel_col
  3421.     jmp    set_gcolor_do
  3422. set_gcolor_n3:
  3423.     cmp    al,4
  3424.     jne    set_gcolor_n4
  3425.     mov    si,offset tek_col
  3426.     jmp    set_gcolor_do
  3427. set_gcolor_n4:
  3428.     cmp    al,5
  3429.     jne    set_gcolor_n5
  3430.     mov    si,offset tek_col
  3431.     jmp    set_gcolor_do
  3432. set_gcolor_n5:
  3433.     jmp    set_gcolor_ex
  3434. set_gcolor_do:
  3435.     call    set_gpalette
  3436.     call    gdisp_on
  3437.     mov    al,1
  3438.     test    vt100_gflag,80h
  3439.     jz    set_gcolor_do1
  3440.     mov    al,tek_dialog_vsbl
  3441. set_gcolor_do1:
  3442.     call    text_scrn
  3443. set_gcolor_ex:
  3444.     pop    si
  3445.     pop    ax
  3446.     ret
  3447. set_gcolor    endp
  3448. ;
  3449. sixel_clear    proc    near
  3450.     call    gcls
  3451.     ret
  3452. sixel_clear    endp
  3453.  
  3454. sixel_in    proc    near
  3455.     call    gcls
  3456.     mov    si,offset sixel_col
  3457.     call    set_gpalette
  3458.     call    gdisp_on
  3459.     mov    sixel_x,0
  3460.     mov    sixel_y,0
  3461.     mov    sixel_state,0
  3462.     mov    repeat_count,0
  3463.     ret
  3464. sixel_in    endp
  3465. ;
  3466. sixel    proc    near
  3467.     cmp    sixel_state,IN_REPEAT
  3468.     jne    sixel_1
  3469.     cmp    al,'0'
  3470.     jb    sixel_1
  3471.     cmp    al,'9'
  3472.     ja    sixel_1
  3473.     xor    ah,ah
  3474.     sub    al,'0'
  3475.     push    ax
  3476.     mov    ax,repeat_count
  3477.     add    repeat_count,ax
  3478.     mov    cx,3
  3479.     shl    ax,cl
  3480.     add    repeat_count,ax            ; repeat_count *= 10
  3481.     pop    ax
  3482.     add    repeat_count,ax
  3483.     jmp    sixel_ex
  3484. sixel_1:
  3485.     cmp    al,07Eh
  3486.     ja    sixel_2
  3487.     cmp    al,03Fh
  3488.     jb    sixel_2                ; b=no. special char.
  3489.     mov    sixel_state,0
  3490.     xor    ah,ah
  3491.     sub    al,03Fh
  3492.     call    sixel_put
  3493.     mov    sixel_state,0            ; clear the sixel state
  3494.     mov    repeat_count,0            ; clear the repeat counter
  3495.     jmp    sixel_ex
  3496. sixel_2:
  3497.     cmp    al,'!'                ; repeat count prefix ?
  3498.     jne    sixel_3                ; ne = no.
  3499.     mov    sixel_state,IN_REPEAT        ; yes, set repeat count flag
  3500.     mov    repeat_count,0            ;   and clear the counter
  3501.     jmp    sixel_ex
  3502. sixel_3:
  3503.     cmp    al,'$'                ; Graphic CR ?
  3504.     jne    sixel_4                ; ne = no.
  3505.     mov    sixel_x,0            ; yes, go to left margin
  3506.     mov    sixel_state,0            ; clear the sixel state
  3507.     mov    repeat_count,0            ; and clear the counter
  3508.     jmp    sixel_ex
  3509. sixel_4:
  3510.     cmp    al,'-'                ; Graphic NL ?
  3511.     jne    sixel_5                ; ne = no.
  3512.     mov    sixel_x,0            ; yes, go to left margin
  3513.     xor    cx,cx                ; and move Y by repeat count
  3514. sixel_4_1:
  3515.     add    sixel_y,6
  3516.     inc    cx
  3517.     cmp    cx,repeat_count
  3518.     jl    sixel_4_1
  3519.     mov    sixel_state,0
  3520.     mov    repeat_count,0
  3521.     jmp    sixel_ex
  3522. sixel_5:
  3523.     cmp    al,020h                ; character ?
  3524.     jb    sixel_ex            ; b=no. it's control char.
  3525.     cmp    al,07Fh                ; DEL/C1/GR ?
  3526.     jae    sixel_ex            ; e=yes. ignore it.
  3527.     mov    sixel_state,0
  3528.     mov    repeat_count,0
  3529. sixel_ex:
  3530.     ret
  3531. sixel    endp
  3532. ;
  3533. ; put sixel character in AL to the graphic screen
  3534. ;
  3535. sixel_put    proc    near
  3536.     push    si
  3537.     push    es
  3538.     mov    sixel_char,al        ; save the sixel character
  3539.     cmp    sixel_y,SIXEL_YMAX
  3540.     jle    sixel_put_1
  3541.     mov    ax,sixel_y
  3542.     sub    ax,SIXEL_YMAX
  3543.     mov    cx,ax
  3544.     call    sixel_scroll
  3545.     mov    sixel_y,SIXEL_YMAX
  3546. sixel_put_1:
  3547.     cmp    sixel_x,SIXEL_XMAX
  3548.     jle    sixel_put_2
  3549.     jmp    sixel_put_6
  3550. sixel_put_2:
  3551.     mov    sixel_segm,CPU_GREEN_PLANE
  3552.     mov    ax,sixel_y
  3553.     add    sixel_segm,ax
  3554.     shl    ax,1
  3555.     shl    ax,1
  3556.     add    sixel_segm,ax        ; sixel_segm = sixel_y*5 + segm_0
  3557.     mov    ax,sixel_x
  3558.     shr    ax,1
  3559.     shr    ax,1
  3560.     shr    ax,1
  3561.     mov    sixel_byte,ax        ; sixel_byte = sixel_x / 8
  3562.     mov    ax,sixel_x
  3563.     and    ax,07h            ; ax = sixel_x % 8
  3564.     cmp    ax,0            ; byte boundary ?
  3565.     jne    sixel_put_2_1        ; ne = no, not.
  3566.     cmp    repeat_count,8        ; repeat_count >= 8 ?
  3567.     jl    sixel_put_2_1        ; l = no, not.
  3568.     jmp    sixel_put_byte1
  3569. sixel_put_2_1:
  3570.     mov    bx,offset bit_on
  3571.     add    bx,ax
  3572.     mov    cl,[bx]
  3573.     mov    sixel_on,cl        ; bit mask to ON the graphic bit
  3574.     mov    bx,offset bit_off
  3575.     add    bx,ax
  3576.     mov    cl,[bx]
  3577.     mov    sixel_off,cl        ; bit mask to OFF the graphic bit
  3578.     mov    ax,sixel_segm
  3579.     mov    es,ax
  3580.     mov    cx,6            ; repeat count
  3581.     cld
  3582.     mov    si,sixel_byte
  3583.     mov    al,sixel_char
  3584.     mov    dl,1
  3585. sixel_put_3:
  3586.     test    al,dl
  3587.     jz    sixel_put_4
  3588.     mov    bh,sixel_on
  3589.     or    es:[si],bh
  3590.     jmp    sixel_put_5
  3591. sixel_put_4:
  3592.     cmp    sixel_replace,1        ; replace mode?
  3593.     jne    sixel_put_5        ; ne=no.
  3594.     mov    bh,sixel_off
  3595.     and    es:[si],bh
  3596. sixel_put_5:
  3597.     shl    dl,1
  3598.     add    si,80
  3599.     loop    sixel_put_3
  3600. sixel_put_6:
  3601.     add    sixel_x,1
  3602.     dec    repeat_count
  3603.     jmp    sixel_put_7
  3604. ;
  3605. sixel_put_byte1:
  3606.     mov    ax,sixel_segm
  3607.     mov    es,ax
  3608.     mov    cx,6            ; repeat count
  3609.     cld
  3610.     mov    si,sixel_byte
  3611.     mov    al,sixel_char
  3612.     mov    dl,1
  3613. sixel_put_byte3:
  3614.     test    al,dl
  3615.     jz    sixel_put_byte4
  3616.     mov    bh,0ffh
  3617.     mov    es:[si],bh
  3618.     jmp    sixel_put_byte5
  3619. sixel_put_byte4:
  3620.     cmp    sixel_replace,1        ; replace mode?
  3621.     jne    sixel_put_byte5        ; ne=no.
  3622.     mov    bh,0
  3623.     mov    es:[si],bh
  3624. sixel_put_byte5:
  3625.     shl    dl,1
  3626.     add    si,80
  3627.     loop    sixel_put_byte3
  3628. sixel_put_byte6:
  3629.     add    sixel_x,8
  3630.     sub    repeat_count,8
  3631. ;
  3632. sixel_put_7:
  3633.     cmp    repeat_count,0
  3634.     jle    sixel_put_8
  3635.     jmp    sixel_put_1
  3636. sixel_put_8:
  3637.     mov    repeat_count,0
  3638.     pop    es
  3639.     pop    si
  3640.     ret
  3641. sixel_put    endp
  3642. ;
  3643. sixel_scroll    proc    near
  3644. ;
  3645. ; scroll up  CX lines
  3646. ;
  3647.     push    bx
  3648.     push    si
  3649.     push    di
  3650.     push    es
  3651.     push    ds
  3652. ;
  3653.     cld
  3654. ;
  3655.     mov    si,0            ; offset of the top of the buffer
  3656.     mov    di,0            ; for both dest. and source.
  3657.     mov    ax,cx
  3658.     add    ax,cx
  3659.     shl    ax,1
  3660.     add    ax,cx            ; ax = n * 5, number of para.
  3661.     mov    bx,ax            ; save it for later use
  3662.     mov    ax,(CPU_BLUE_PLANE+1)    ; top of the buffer
  3663.     mov    es,ax            ; dest. segm.
  3664.     add    ax,bx
  3665.     mov    ds,ax            ; source segm.
  3666.     mov    cx,32760        ; number of words of the buffer
  3667.     rep    movsw            ; move words
  3668.     mov    si,0            ; clear offsets
  3669.     mov    di,0            ;  for both dest. and source
  3670.     mov    ax,CPU_GREEN_PLANE
  3671.     mov    ds,ax            ; source segm.
  3672.     sub    ax,bx
  3673.     mov    es,ax            ; dest. segm.
  3674.     mov    cx,16000        ; scroll with status line
  3675.     mov    ax,bx            ; ax = n * 5
  3676.     shl    ax,1
  3677.     shl    ax,1
  3678.     shl    ax,1            ; ax = n * 40
  3679.     sub    cx,ax
  3680.     rep    movsw
  3681. ;
  3682.     pop    ds
  3683.     pop    es
  3684.     pop    di
  3685.     pop    si
  3686.     pop    bx
  3687.     ret
  3688. sixel_scroll    endp
  3689.  
  3690. sixel_rollup    proc    near
  3691.     push    bx
  3692.     push    si
  3693.     push    di
  3694.     push    es
  3695.     push    ds
  3696. ;
  3697.     mov    ax,cx
  3698.     shl    ax,1
  3699.     shl    ax,1
  3700.     add    ax,cx            ; ax = n * 5
  3701.     mov    bx,ax            ; bx = ax = n * 5
  3702.     shl    ax,1
  3703.     shl    ax,1
  3704.     shl    ax,1            ; ax = n * 40
  3705. ;
  3706. ; copy top n-lines to the save buffer
  3707. ;
  3708.     cld
  3709.     mov    si,0
  3710.     mov    di,0
  3711.     push    ax
  3712.     mov    ax,(CPU_BLUE_PLANE+1)    ; top segment
  3713.     mov    ds,ax
  3714.     mov    ax,(CPU_GREEN_PLANE+2000)    ; save-buffer segment
  3715.     mov    es,ax
  3716.     pop    ax            ; ax = n * 40
  3717.     mov    cx,ax
  3718.     rep    movsw
  3719. ;
  3720. ; roll-up n-lines
  3721. ;
  3722.     mov    si,0
  3723.     mov    di,0
  3724.     push    ax
  3725.     mov    ax,(CPU_BLUE_PLANE+1)
  3726.     mov    es,ax            ; destination
  3727.     add    ax,bx
  3728.     mov    ds,ax            ; source
  3729.     mov    cx,32760
  3730.     rep    movsw
  3731. ;
  3732.     mov    si,0
  3733.     mov    di,0
  3734.     mov    ax,CPU_GREEN_PLANE
  3735.     mov    es,ax
  3736.     add    ax,bx
  3737.     mov    ds,ax
  3738.     mov    cx,15360
  3739.     pop    ax
  3740.     sub    cx,ax
  3741.     rep    movsw
  3742. ;
  3743. ;  Copy saved n-lines to the bottom
  3744. ;
  3745.     mov    si,0
  3746.     mov    di,0
  3747.     push    ax
  3748.     mov    ax,(CPU_GREEN_PLANE+1920)
  3749.     sub    ax,bx
  3750.     mov    es,ax            ; destination
  3751.     mov    ax,(CPU_GREEN_PLANE+2000)
  3752.     mov    ds,ax            ; source
  3753.     pop    ax
  3754.     mov    cx,ax
  3755.     rep    movsw
  3756. ;
  3757.     pop    ds
  3758.     pop    es
  3759.     pop    di
  3760.     pop    si
  3761.     pop    bx
  3762.     ret
  3763. sixel_rollup    endp
  3764.  
  3765. sixel_rolldown    proc    near
  3766.     push    bx
  3767.     push    si
  3768.     push    di
  3769.     push    es
  3770.     push    ds
  3771. ;
  3772.     mov    ax,cx
  3773.     shl    ax,1
  3774.     shl    ax,1
  3775.     add    ax,cx        ; ax = n * 5
  3776.     mov    bx,ax        ; bx = n * 5, save it for later use
  3777.     shl    ax,1
  3778.     shl    ax,1
  3779.     shl    ax,1        ; ax = n * 40
  3780. ;
  3781. ;  Copy bottom n-lines to the save buffer
  3782. ;
  3783.     cld
  3784.     mov    si,0
  3785.     mov    di,0
  3786.     push    ax
  3787.     mov    ax,(CPU_GREEN_PLANE+1920)    ; 1920 = (24x16)lines x 5 segm.
  3788.     sub    ax,bx
  3789.     mov    ds,ax        ; source segm.
  3790.     mov    ax,(CPU_GREEN_PLANE+2000)    ; save segm.
  3791.     mov    es,ax        ; destination
  3792.     pop    ax        ; ax = n * 40
  3793.     mov    cx,ax
  3794.     rep    movsw        ; store n-lines to save segm.
  3795. ;
  3796. ;  Rolldown n-lines
  3797. ;
  3798.     std
  3799.     mov    si,30718    ; bottom offset address (word boundary)
  3800.     mov    di,30718
  3801.     push    ax
  3802.     mov    ax,CPU_GREEN_PLANE
  3803.     mov    es,ax        ; destination
  3804.     sub    ax,bx
  3805.     mov    ds,ax        ; source
  3806.     mov    cx,15360    ; cx = 24 x 16 x 40 words
  3807.     rep    movsw        ; reverse move in Green segm.
  3808. ;
  3809.     mov    si,0FFEEh    ; bottom offset address (word boundary)
  3810.     mov    di,0FFEEh
  3811.     mov    ax,(CPU_BLUE_PLANE+1)
  3812.     mov    es,ax
  3813.     sub    ax,bx
  3814.     mov    ds,ax
  3815.     mov    cx,32760    ; number of words in the buffer
  3816.     pop    ax        ; ax = n * 40
  3817.     sub    cx,ax
  3818.     rep    movsw
  3819. ;
  3820.     cld
  3821.     mov    si,0
  3822.     mov    di,0
  3823.     push    ax
  3824.     mov    ax,(CPU_GREEN_PLANE+2000)
  3825.     mov    ds,ax
  3826.     mov    ax,(CPU_BLUE_PLANE+1)
  3827.     mov    es,ax
  3828.     pop    ax        ; ax = n * 40
  3829.     mov    cx,ax
  3830.     rep    movsw
  3831. ;
  3832.     pop    ds
  3833.     pop    es
  3834.     pop    di
  3835.     pop    si
  3836.     pop    bx
  3837.     ret
  3838. sixel_rolldown    endp
  3839. ;------------------------------------------------------------------------------
  3840. tekstat        proc    near
  3841.     push    ax
  3842.     mov    si,offset tek_cmode_msg
  3843.     mov    al,tek_cmode_1
  3844.     add    al,'0'
  3845.     mov    [si],al
  3846.     mov    al,tek_cmode_2
  3847.     add    al,'0'
  3848.     mov    [si+2],al
  3849.     mov    al,tek_cmode_3
  3850.     add    al,'0'
  3851.     mov    [si+4],al
  3852. ;
  3853.     mov    si,offset tek_mouse_msg
  3854.     test    vtgrph_flg,MOUSE_BIT
  3855.     jz    tekstat_m01
  3856.     mov    al,'o'
  3857.     mov    [si],al
  3858.     mov    al,'n'
  3859.     mov    [si+1],al
  3860.     mov    al,' '
  3861.     mov    [si+2],al
  3862.     jmp    tekstat_m02
  3863. tekstat_m01:
  3864.     mov    al,'o'
  3865.     mov    [si],al
  3866.     mov    al,'f'
  3867.     mov    [si+1],al
  3868.     mov    [si+2],al
  3869. tekstat_m02:
  3870.     mov    al,' '
  3871.     mov    [si+3],al
  3872.     mov    al,pc98_mouse_type
  3873.     add    al,'0'
  3874.     mov    [si+4],al
  3875. ;
  3876.     mov    si,offset tek_pmode_msg
  3877.     mov    al,tek_mod
  3878.     add    al,'0'
  3879.     mov    [si],al
  3880.     mov    al,tek_esc
  3881.     add    al,'0'
  3882.     mov    [si+1],al
  3883.     mov    si,offset tek_stat_msg
  3884.     pop    ax
  3885.     ret
  3886. tekstat        endp
  3887. ;----------------------------------------------------------------------------
  3888. set_tek41_mat    proc    near
  3889. ;
  3890. ; set the transformation matrix.
  3891. ; parameter consistency must be checked before call.
  3892. ; Input  [si] window xmin,xmax,ymin,ymax; viewport xmin,xmax,ymin,ymax
  3893. ; Output [di] transformation matrix
  3894. ;
  3895.     push    ax
  3896.     push    bx
  3897.     push    dx
  3898. ;
  3899.     mov    ax,[si+10]    ; viewport xmax
  3900.     sub    ax,[si+ 8]    ; viewport (xmax-xmin)
  3901.     inc    ax
  3902.     xor    dx,dx
  3903.     mov    bx,[si+ 2]    ; window xmax
  3904.     sub    bx,[si   ]    ; window (xmax-xmin)
  3905.     inc    bx
  3906.     div    bx
  3907.     mov    [di+ 2],ax
  3908.     xor    ax,ax
  3909.     div    bx
  3910.     mov    [di   ],ax
  3911. ;
  3912.     mov    ax,[si+14]    ; viewport ymax
  3913.     sub    ax,[si+12]    ; viewport (ymax-ymin)
  3914.     inc    ax
  3915.     xor    dx,dx
  3916.     mov    bx,[si+ 6]    ; window ymax
  3917.     sub    bx,[si+ 4]    ; window (ymax-ymin)
  3918.     inc    bx
  3919.     div    bx
  3920.     mov    [di+10],ax
  3921.     xor    ax,ax
  3922.     div    bx
  3923.     mov    [di+ 8],ax
  3924. ;
  3925.     mov    ax,[si   ]    ; get window xmin
  3926.     mov    [di+ 4],ax
  3927.     mov    ax,[si+ 4]    ; get window ymin
  3928.     mov    [di+12],ax
  3929.     mov    ax,[si+ 8]    ; get viewport xmin
  3930.     mov    [di+ 6],ax
  3931.     mov    ax,[si+12]    ; get viewport ymin
  3932.     mov    [di+14],ax
  3933. ;
  3934.     pop    dx
  3935.     pop    bx
  3936.     pop    ax
  3937.     ret
  3938. set_tek41_mat    endp
  3939. ;------------------------------------------------------------------------------
  3940. send_to_GGDC    proc    near
  3941. ;
  3942. ;  send commands and parameters
  3943. ;  to graphic GDC
  3944. ;    inputs    DS:[SI]    address of the list
  3945. ;
  3946.     push    ax
  3947.     push    cx
  3948.     push    si
  3949.     cld
  3950. send_to_GGDC_loop1:
  3951.     lodsb
  3952.     cmp    al,0ffh
  3953.     je    send_to_GGDC_exit
  3954.     push    ax
  3955. send_to_GGDC_loop2:
  3956.     in    al,GGDC_STS_PORT
  3957.     test    al,2
  3958.     jne    send_to_GGDC_loop2
  3959.     pop    ax
  3960.     out    GGDC_CMD_PORT,al
  3961.     lodsb
  3962.     mov    cl,al
  3963.     mov    ch,0
  3964.     cmp    cx,0
  3965.     je    send_to_GGDC_loop1
  3966. send_to_GGDC_loop3:
  3967.     lodsb
  3968.     push    ax
  3969. send_to_GGDC_loop4:
  3970.     in    al,GGDC_STS_PORT
  3971.     test    al,2
  3972.     jne    send_to_GGDC_loop4
  3973.     pop    ax
  3974.     out    GGDC_PRM_PORT,al
  3975.     loop    send_to_GGDC_loop3
  3976.     jmp    send_to_GGDC_loop1
  3977. send_to_GGDC_exit:
  3978.     pop    si
  3979.     pop    cx
  3980.     pop    ax
  3981.     ret
  3982. send_to_GGDC    endp
  3983. ;------------------------------------------------------------------------------
  3984. GGDC_color    proc    near
  3985. ;
  3986. ;  send DS:[SI] to graphic GDC with
  3987. ;  color index.
  3988. ;
  3989. ;  inputs
  3990. ;    ax:  color index
  3991. ;    si:  buffer address (used by send_to_GGDC)
  3992. ;    di:  CSR pointer
  3993. ;
  3994.     push    bx
  3995.     push    cx
  3996.     push    dx
  3997.     push    di
  3998. ;
  3999.     mov    bx,[di+3]
  4000.     push    bx
  4001.     mov    bx,[di+5]
  4002.     push    bx
  4003. ;
  4004.     xor    ch,ch
  4005.     mov    cl,gplane_nums
  4006.     mov    bx,offset GDC_plane_address
  4007.     mov    dx,1
  4008. GGDC_color_1:
  4009.     and    byte ptr [di+3],3Fh        ; mask plane address
  4010.     push    ax
  4011.     mov    al,[bx]
  4012.     or    byte ptr [di+3],al        ; add plane address
  4013.     pop    ax
  4014.     inc    bx
  4015.     test    dx,gplane_actv
  4016.     jz    GGDC_color_4            ; skip if non-active plane
  4017.     test    dx,ax                ; test color bit
  4018.     jz    GGDC_color_2
  4019.     mov    byte ptr [di+5],23h         ; write mode = SET
  4020.     jmp    GGDC_color_3
  4021. GGDC_color_2:
  4022.     mov    byte ptr [di+5],22h        ; write mode = CLEAR
  4023. GGDC_color_3:
  4024.     call    send_to_GGDC
  4025. GGDC_color_4:
  4026.     shl    dx,1
  4027.     loop    GGDC_color_1
  4028. ;
  4029.     pop    bx
  4030.     mov    [di+5],bx
  4031.     pop    bx
  4032.     mov    [di+3],bx
  4033. ;
  4034.     pop    di
  4035.     pop    dx
  4036.     pop    cx 
  4037.     pop    bx
  4038.     ret
  4039. GGDC_color    endp
  4040.  
  4041. ;-----------------------------------------------------------------------
  4042. ; Get digitized color index in AL from (r,g,b)
  4043. ; si: (r,g,b) table
  4044. ;
  4045. get_dig_color    proc    near
  4046.     push    cx
  4047.     mov    ch,ah        ; save AH
  4048.     mov    ah,[si]        ; get red
  4049.     mov    cl,6
  4050.     shr    ah,cl
  4051.     and    ah,02h
  4052.     mov    al,ah
  4053.     mov    ah,[si+1]    ; get green
  4054.     mov    cl,5
  4055.     shr    ah,cl
  4056.     and    ah,04h
  4057.     or    al,ah
  4058.     mov    ah,[si+2]    ; get blue
  4059.     mov    cl,7
  4060.     shr    ah,cl
  4061.     and    ah,01h
  4062.     or    al,ah
  4063.     mov    ah,ch        ; restore AH
  4064.     pop    cx
  4065.     ret
  4066. get_dig_color    endp
  4067.  
  4068. HLS_value    proc    near
  4069. ;
  4070. ; input         HLS_n1    n1  [0-100]
  4071. ;               HLS_n2    n2  [0-100]
  4072. ;               AX : hue
  4073. ; output        AX : value
  4074. ;
  4075.     push    bx
  4076.     push    dx
  4077. ;
  4078. HLS_value_1:
  4079.     cmp    ax,360
  4080.     jle    HLS_value_2
  4081.     sub    ax,360
  4082.     jmp    HLS_value_1
  4083. HLS_value_2:
  4084.     cmp    ax,0
  4085.     jge    HLS_value_3
  4086.     add    ax,360
  4087.     jmp    HLS_value_2
  4088. HLS_value_3:
  4089.     cmp    ax,60
  4090.     jl    HLS_value_4
  4091.     cmp    ax,180
  4092.     jl    HLS_value_5
  4093.     cmp    ax,240
  4094.     jl    HLS_value_6
  4095.     mov    ax,HLS_n1
  4096.     jmp    HLS_value_ex
  4097. HLS_value_5:
  4098.     mov    ax,HLS_n2
  4099.     jmp    HLS_value_ex
  4100. HLS_value_6:
  4101.     mov    bx,ax
  4102.     mov    ax,240
  4103.     sub    ax,bx
  4104. HLS_value_4:
  4105.     mov    bx,ax
  4106.     mov    ax,HLS_n2
  4107.     sub    ax,HLS_n1
  4108.     imul    bx
  4109.     mov    bx,60
  4110.     idiv    bx
  4111.     add    ax,HLS_n1
  4112. HLS_value_ex:
  4113.     pop    dx
  4114.     pop    bx
  4115.     ret
  4116. HLS_value    endp
  4117.  
  4118. HLS_to_RGB    proc    near
  4119. ;
  4120. ;  input [si]    Hue [0-360]
  4121. ;        [si+2]    Lightness [0-100]
  4122. ;        [si+4] Satulation [0-100]
  4123. ;
  4124.     push    ax
  4125.     push    bx
  4126.     push    dx
  4127. ;
  4128.     mov    ax,[si+4]        ; get s
  4129.     cmp    ax,0            ; if( s==0 ) then monochrome
  4130.     jne    HLS_to_RGB_1        ; ne=no
  4131.     jmp    HLS_to_RGB_nomo
  4132. HLS_to_RGB_1:
  4133.     mov    bx,[si+2]        ; get l
  4134.     mul    bx            ; dx:ax=l*s  (dx should be 0)
  4135.     mov    bx,100
  4136.     div    bx            ; ax=(l*s)/100
  4137.     cmp    WORD PTR [si+2],50    ; if( l>50 ) then case_2
  4138.     jg    HLS_to_RGB_2
  4139.     mov    bx,[si+2]        ; bx=l
  4140.     jmp    HLS_to_RGB_3
  4141. HLS_to_RGB_2:
  4142.     mov    bx,[si+4]        ; bx=s
  4143.     sub    bx,ax            ; bx=s-l*s/100
  4144.     mov    ax,[si+2]        ; ax=l
  4145. HLS_to_RGB_3:
  4146.     add    ax,bx            ; ax=ax+bx
  4147.     mov    HLS_n2,ax
  4148.     mov    bx,[si+2]        ; bx=l
  4149.     shl    bx,1            ; bx=2*l
  4150.     sub    bx,ax            ; bx=2*l-ax
  4151.     mov    HLS_n1,bx
  4152.     mov    ax,[si]            ; ax=hue
  4153.     push    ax
  4154.     call    HLS_value
  4155.     mov    [si],ax
  4156.     pop    ax
  4157.     push    ax
  4158.     mov    bx,120
  4159.     sub    ax,bx            ; ax=hue-120
  4160.     call    HLS_value
  4161.     mov    [si+2],ax
  4162.     pop    ax
  4163.     mov    bx,120
  4164.     add    ax,bx            ; ax=hue+120
  4165.     call    HLS_value
  4166.     mov    [si+4],ax
  4167.     jmp    HLS_to_RGB_ex
  4168. HLS_to_RGB_nomo:
  4169.     mov    ax,[si+2]
  4170.     mov    [si],ax
  4171.     mov    [si+4],ax
  4172. HLS_to_RGB_ex:
  4173.     pop    dx
  4174.     pop    bx
  4175.     pop    ax
  4176.     ret
  4177. HLS_to_RGB    endp
  4178. ;-----------------------------------------------------------------------
  4179. ; Set graphic color palette
  4180. ; si: points the color index table (8 colors)
  4181. ;
  4182. set_gpalette    proc    near
  4183.     push    ax
  4184.     push    bx
  4185.     push    cx
  4186. ;
  4187.     cmp    gdisp_mode,0    ; digital display ?
  4188.     jne    set_gpalette_A    ; ne=no.
  4189.     jmp    set_gpalette_D
  4190. ;--------------
  4191. set_gpalette_A:
  4192. ;--------------
  4193.     push    si
  4194.     mov    cx,16
  4195.     mov    bx,0
  4196. set_gpalette_A1:
  4197.     push    cx
  4198.     mov    al,bl
  4199.     out    0A8h,al            ; set color index
  4200.     lodsb
  4201.     mov    cx,4
  4202.     shr    al,cl
  4203.     and    al,0Fh
  4204.     out    0ACh,al            ; set red
  4205.     lodsb
  4206.     mov    cx,4
  4207.     shr    al,cl
  4208.     and    al,0Fh
  4209.     out    0AAh,al            ; set green
  4210.     lodsb
  4211.     mov    cx,4
  4212.     shr    al,cl
  4213.     and    al,0Fh
  4214.     out    0AEh,al            ; set blue
  4215.     pop    cx
  4216.     inc    bx
  4217.     loop    set_gpalette_A1
  4218. ;
  4219.     pop    si
  4220.     jmp    set_gpalette_ex
  4221. ;
  4222. ;--------------
  4223. set_gpalette_D:
  4224. ;--------------
  4225.     push    si
  4226.     add    si,9            ; index #3
  4227.     call    get_dig_color
  4228.     mov    ah,al
  4229.     mov    cl,4
  4230.     shl    ah,cl
  4231.     pop    si
  4232.     push    si
  4233.     add    si,21            ; index #7
  4234.     call    get_dig_color
  4235.     or    al,ah
  4236.     out    0A8h,al            ; set palette #3 and #7
  4237.     pop    si
  4238. ;
  4239.     push    si
  4240.     add    si,3            ; index #1
  4241.     call    get_dig_color
  4242.     mov    ah,al
  4243.     mov    cl,4
  4244.     shl    ah,cl
  4245.     pop    si
  4246.     push    si
  4247.     add    si,15            ; index #5
  4248.     call    get_dig_color
  4249.     or    al,ah
  4250.     out    0AAh,al            ; set palette #1 and #5
  4251.     pop    si
  4252. ;
  4253.     push    si
  4254.     add    si,6            ; index #2
  4255.     call    get_dig_color
  4256.     mov    ah,al
  4257.     mov    cl,4
  4258.     shl    ah,cl
  4259.     pop    si
  4260.     push    si
  4261.     add    si,18            ; index #6
  4262.     call    get_dig_color
  4263.     or    al,ah
  4264.     out    0ACh,al            ; set palette #2 and #6
  4265.     pop    si
  4266. ;
  4267.     push    si
  4268.     call    get_dig_color
  4269.     mov    ah,al
  4270.     mov    cl,4
  4271.     shl    ah,cl
  4272.     pop    si
  4273.     push    si
  4274.     add    si,12
  4275.     call    get_dig_color
  4276.     or    al,ah
  4277.     out    0AEh,al            ; set palette #0 and #4
  4278.     pop    si
  4279. ;
  4280. set_gpalette_ex:
  4281.     pop    cx
  4282.     pop    bx
  4283.     pop    ax
  4284.     ret
  4285. set_gpalette    endp
  4286.  
  4287. set_gtxt_vect    proc    near
  4288.     push    ax
  4289.     push    bx
  4290.     push    cx
  4291.     mov    bx,tek_gtxt_w
  4292.     add    bx,tek_gtxt_s
  4293.     mov    cx,tek_gtxt_h
  4294.     mov    ax,tek_gtxt_ang
  4295.     cmp    ax,45
  4296.     jge    set_gtxt_vect_n1
  4297.     jmp    set_gtxt_vect_1
  4298. set_gtxt_vect_n1:
  4299.     cmp    ax,135
  4300.     jge    set_gtxt_vect_n2
  4301.     jmp    set_gtxt_vect_2
  4302. set_gtxt_vect_n2:
  4303.     cmp    ax,225
  4304.     jge    set_gtxt_vect_n3
  4305.     jmp    set_gtxt_vect_3
  4306. set_gtxt_vect_n3:
  4307.     cmp    ax,315
  4308.     jge    set_gtxt_vect_1
  4309.     jmp    set_gtxt_vect_4
  4310. set_gtxt_vect_1:
  4311.     mov    tek_gtxt_dr,2
  4312.     mov    tek_gtxt_ux,bx
  4313.     mov    tek_gtxt_uy,0
  4314.     mov    tek_gtxt_vx,0
  4315.     mov    tek_gtxt_vy,cx
  4316.     jmp    set_gtxt_vect_5
  4317. set_gtxt_vect_2:
  4318.     neg    cx
  4319.     mov    tek_gtxt_dr,4
  4320.     mov    tek_gtxt_ux,0
  4321.     mov    tek_gtxt_uy,bx
  4322.     mov    tek_gtxt_vx,cx
  4323.     mov    tek_gtxt_vy,0
  4324.     jmp    set_gtxt_vect_5
  4325. set_gtxt_vect_3:
  4326.     neg    bx
  4327.     neg    cx
  4328.     mov    tek_gtxt_dr,6
  4329.     mov    tek_gtxt_ux,bx
  4330.     mov    tek_gtxt_uy,0
  4331.     mov    tek_gtxt_vx,0
  4332.     mov    tek_gtxt_vy,cx
  4333.     jmp    set_gtxt_vect_5
  4334. set_gtxt_vect_4:
  4335.     neg    bx
  4336.     mov    tek_gtxt_dr,0
  4337.     mov    tek_gtxt_ux,0
  4338.     mov    tek_gtxt_uy,bx
  4339.     mov    tek_gtxt_vx,cx
  4340.     mov    tek_gtxt_vy,0
  4341. set_gtxt_vect_5:
  4342.     pop    cx
  4343.     pop    bx
  4344.     pop    ax
  4345.     ret
  4346. set_gtxt_vect    endp
  4347. ;------------------------------------------------------------------------------
  4348. gcsrw    proc    near
  4349. ;
  4350. ; fill CSRW parameters in the buffer [di]
  4351. ;   Inputs
  4352. ;     ax: x position
  4353. ;     bx: y position
  4354. ;     cx: plane offset / 256
  4355. ;     di: buffer address ( to be broken )
  4356. ;   Outputs
  4357. ;     di: next buffer address
  4358. ;
  4359.     push    ax
  4360.     push    bx
  4361.     push    cx
  4362.     mov    byte ptr [di],49h        ; fill CSRW command
  4363.     mov    byte ptr [di+1],3        ; number of parameters
  4364.     push    ax                ; save x value
  4365.     push    cx                ; save plane number
  4366.     mov    cl,4                ; shift counts
  4367.     shr    ax,cl                ; ax = x / 16
  4368.     mov     cx,bx                ; save y value
  4369.     shl    bx,1                ; bx = y * 2
  4370.     shl    bx,1                ; bx = bx * 2 = y * 4
  4371.     add    bx,cx                ; bx = bx + y = y * 5
  4372.     mov    cl,3                ; shift counts
  4373.     shl    bx,cl                ; bx = bx * 8 = y * 40
  4374.     add    ax,bx                ; ax = x / 16 + y * 40
  4375.     mov    byte ptr [di+2],al        ; set EAD_L
  4376.     mov    al,ah                ; discard EAD_L
  4377.     xor    ah,ah                ; clear higher byte
  4378.     pop    bx                ; recall plane offset
  4379.     mov    bl,bh                ; mov to lower byte
  4380.     xor    bh,bh                ; clear higher byte
  4381.     add    ax,bx                ; add plane offset
  4382.     mov    byte ptr [di+3],al        ; set EAD_M
  4383.     mov    al,ah                ; discard EAD_M
  4384.     xor    ah,ah                ; clear higher byte
  4385.     pop    bx                ; recall x
  4386.     and    bx,000fh            ; lower 4 bits of x (dAD)
  4387.     mov    cl,4                ; shift counts
  4388.     shl    bx,cl                ; shift 4 bits
  4389.      add    ax,bx                ; add to EAD_H
  4390.     mov    byte ptr [di+4],al        ; set dAD+EAD_H
  4391.     add    di,5                ; set next pointer
  4392.     pop    cx
  4393.     pop    bx
  4394.     pop    ax
  4395.     ret
  4396. gcsrw    endp
  4397. ;------------------------------------------------------------------------------
  4398. gline    proc    near
  4399. ;
  4400. ;  Draw line from current position to the displacement (AX,BX)
  4401. ;  Inputs:
  4402. ;    ax: delta_x
  4403. ;    bx: delta_y
  4404. ;    di: buffer address
  4405. ;  Outputs:
  4406. ;    di: next buffer address
  4407. ;
  4408.     push    ax
  4409.     push    bx
  4410.     push    cx
  4411.     mov     byte ptr [di],4ch        ; VECTW command
  4412.     mov    byte ptr [di+1],9        ; number of parameters
  4413. ;
  4414. ;   determine direction (cx)
  4415. ;
  4416.     mov    cx,8                ; Line function with dir=0
  4417.     cmp    ax,0                ; if delta_x = 0 then
  4418.     je    gln0                ;   goto gln0
  4419.     jl    gln1                ; else if delta_x < 0 goto gln1
  4420.     jmp    gln2                ; else goto gln2
  4421. gln0:
  4422.     cmp    bx,0                ;
  4423.     jge    gln2                ; if delta_y >= 0 goto gln2
  4424. gln1:
  4425.     neg    ax                ; delta_x = -delta_x
  4426.     neg    bx                ; delta_y = -delta_y
  4427.     add    cx,4                ; dir >= 4
  4428. gln2:
  4429.     cmp    bx,0                ;
  4430.     jg    gln3                ; if delta_y > 0 goto gln3
  4431.     neg    bx                ; delta_y = -delta_y
  4432.     xchg    ax,bx                ;
  4433.     add    cx,2                ; dir >= 2 or 6
  4434. gln3:
  4435.     cmp    ax,bx                ;
  4436.     jl    gln4                ; if delta_x < delta_y goto gln4 
  4437.     inc    cx                ; dir = 1, 3, 5, or 7
  4438.     jmp    gln5
  4439. gln4:
  4440.     xchg    ax,bx
  4441. gln5:
  4442. ;
  4443. ;     end of direction determination.
  4444. ;     ax: abs(d_x)
  4445. ;     bx: abs(d_y)
  4446. ;     cx: line_code + dir
  4447. ;
  4448.     mov    byte ptr [di+2],cl        ; P1 ready
  4449.     mov    word ptr [di+3],ax        ; abs(d_x)
  4450.     mov    cx,bx                ; cx = abs(d_y)
  4451.     add    cx,bx                ; cx = 2*abs(d_y)
  4452.     push    cx                ; save 2*abs(d_y) for later use
  4453.     sub    cx,ax                ; cx = 2*abs(d_y)-abs(d_x)
  4454.     mov    word ptr [di+5],cx        ; send it
  4455.     sub    cx,ax                ; cx = 2*abs(d_y)-2*abs(d_x)
  4456.     mov    word ptr [di+7],cx        ; send it
  4457.     pop    cx                ; recall 2*abs(d_y)
  4458.     mov    word ptr [di+9],cx        ; send it
  4459. ;
  4460.     mov    byte ptr [di+11],6ch        ; VECTE command
  4461.     mov    byte ptr [di+12],0        ; with no parameters
  4462.     add    di,13                ; update address
  4463.     pop    cx
  4464.     pop    bx
  4465.     pop    ax
  4466.     ret
  4467. gline    endp
  4468. ;-----------------------------------
  4469. gdisp_on    proc    near
  4470.     push    ax
  4471.     push    si
  4472.     mov    al,gdisp_mode
  4473.     out    6ah,al
  4474.     mov    si,offset ggdc_on
  4475.     call    send_to_GGDC
  4476.     pop    si
  4477.     pop    ax
  4478.     ret
  4479. gdisp_on    endp
  4480. ;-----------------------------------
  4481. gdisp_off    proc    near
  4482.     push    si
  4483.     mov    si,offset ggdc_off
  4484.     call    send_to_GGDC
  4485.     pop    si
  4486.     ret
  4487. gdisp_off    endp
  4488. ;-----------------------------------
  4489. gcls    proc    near
  4490.     push    ax
  4491.     push    bx
  4492.     push    cx
  4493.     push    di
  4494.     push    si
  4495.     push    es
  4496. ;
  4497.     mov    si,offset ggdc_off        ; off the graphic GDC
  4498.     call    send_to_GGDC
  4499. ;
  4500.     cld                    ; normal direction
  4501.     xor    ch,ch
  4502.     mov    cl,gplane_nums
  4503.     mov    bx,offset gplane_segm    ; GDC segment address
  4504. gcls_1:
  4505.     mov    ax,[bx]                ; get segment
  4506.     mov    es,ax                ; and set it to ES
  4507.     xor    ax,ax                ; store 0
  4508.     mov    di,ax                ; offset address is 0
  4509.     push    cx                ; save counter
  4510.     mov    cx,16000            ; number of words of G-VRAM
  4511.     rep    stosw                ; store it
  4512.     pop    cx                ; remember number of planes
  4513.     add    bx,2                ; next segment address
  4514.     loop    gcls_1
  4515. ;
  4516.     mov    si,offset ggdc_on        ; on the graphic GDC
  4517.     call    send_to_GGDC
  4518. ;
  4519.     pop    es
  4520.     pop    si
  4521.     pop    di
  4522.     pop    cx
  4523.     pop    bx
  4524.     pop    ax
  4525.     ret
  4526. gcls    endp
  4527.  
  4528. code    ends
  4529.     end
  4530.