%	*****************************************************************
%	*								*
%	*	This module is a part of the SAO VAX/VMS STOIC SYSTEM	*
%	*								*
%	*	It was created by					*
%	*	Roger Hauck						*
%	*	Smithsonian Institution					*
%	*	Astrophysical Observatory				*
%	*	Cambridge, Massachusetts  02138				*
%	*	(617)495-7151  (FTS 830-7151)				*
%	*								*
%	*	This module may be reproduced				*
%	*	provided that this header is retained.			*
%	*								*
%	*****************************************************************

%  VT100: stuff for controlling the VT100

%  lower-level words

'D<#> :  % value, D<#>, string ptr., count
%	(converts value to a decimal string)
  RADIX @ SWAP DECIMAL  % save radix, switch to decimal
  <#> -ROT RADIX !  % convert number, restore radix
  ;

'ESC : 1B TYO ;

'ESC[ : ESC ASCII [ TYO ;

'SC :  % SAVE CURSOR
  ESC ASCII 7 TYO
  ;

'RC :  % RESTORE CURSOR
  ESC ASCII 8 TYO
  ;

'RI :  % REVERSE INDEX
  ESC ASCII M TYO
  ;

'STBM :  % bottom margin, top margin, STBM
  ESC[  % OUTPUT PREFIX
  D<#> TYPE  % output top line number
  ASCII ; TYO  % separator
  D<#> TYPE  % bottom line #
  ASCII r TYO  % SUFFIX
  ;

'SGR :  % select graphic rendition
  ESC[ #A TYO ASCII m TYO
  ;

'ED :  % erase in display
  ESC[ #A TYO ASCII J TYO
  ;

'SET_MODE :  % value, SET_MODE
  ESC[ ASCII ? TYO #A TYO ASCII h TYO
  ;

'RESET_MODE :  % value, RESET_MODE
  ESC[ ASCII ? TYO #A TYO ASCII l TYO
  ;

'LIGHT_BACKGROUND : 5 SET_MODE ;

'DARK_BACKGROUND : 5 RESET_MODE ;

'WRAP_OFF :  7 RESET_MODE ;

% Low-level VT100 words (continued)

'EL :  % erase in line
  ESC[ #A TYO ASCII K TYO
  ;

'CUP :  % cursor position
  ESC[ D<#> TYPE ASCII ; TYO D<#> TYPE ASCII H TYO
  ;

'DHLT :  % double-height line, top
  ESC '#3 MSG ;

'DHLB :  % double-height line, bottom
  ESC '#4 MSG ;

'DWL :  % double-width line
  ESC '#6 MSG ;

'SWL :  % single-width line
  ESC '#5 MSG ;

'GRAPHICS :
  ESC  ASCII ( TYO  ASCII 0 TYO
  ;

'LCASE :
  ESC  ASCII ( TYO  ASCII B TYO
  ;

'ERASE_THIS_LINE :  2 EL ;
'ERASE_REST_OF_LINE :  0 EL ;
'ERASE_SCREEN :  2 ED ;
'ERASE_REST_OF_SCREEN :  0 ED ;
'BOLD : 1 SGR ;
'UNDERSCORE : 4 SGR ;
'BLINK : 5 SGR ;
'REVERSE : 7 SGR ;
'STEADY : 0 SGR ;

%  Higher-level VT100 words
2 'TBM ARRAY  % top of scrolling region, bottom of scrolling region

'STBM :  % top, bottom, STBM  (sets scrolling region on VT100)
%	keeps track of parameters and does I/O only when necessary
  OVER TBM 4 + @ EQ  % true if bottom has not changed
  OVER TBM     @ EQ AND IF  % have either top or bottom changed?
    2DROP ELSE  % no, do nothing
    DDUP TBM D! STBM THEN  % yes, output to VT100 & record new values
  ; 

'SCROLL :  % m, n, SCROLL
%	causes lines m through n to scroll in the direction from m to n
  DDUP GT_IF  % n>m?
    OVER STBM  % yes, set scrolling region
    1 SWAP CUP RI ELSE  % go to top line, issue reverse index
    DDUP LT_IF  % m>n?
      OVER SWAP STBM  % yes, set scrolling region
      1 SWAP CUP 0A TYO ELSE  % go to bottom line, issue line feed
      DROP 1 SWAP CUP ERASE_REST_OF_LINE THEN  % m=n, delete line
    THEN
  ;

%  Words relating VT100 to Editor

8 'TF VARIABLE

'WINDOW_SIZE :  % WINDOW_SIZE, # of lines in window
  TF @ 2* 1+
  ;

50 'FNSIZE CONSTANT
  FNSIZE 'FILE_NAME SVARIABLE

0 'BUFFER# VARIABLE

'SET_MODE :
  ESC[ ASCII ? TYO TYO ASCII h TYO
  ;

'RESET_MODE :
  ESC[ ASCII ? TYO TYO ASCII l TYO
  ;

'SMOOTH_SCROLL :
  ASCII 4 SET_MODE
  ;

'ANSI_VT100 :  % switch VT100 from VT52 to ANSI
  ESC ASCII < TYO
  ;

'RESET_VT100 :
  ESC ASCII c TYO
  ;

'APPLICATION_KEYPAD :
  ESC ASCII = TYO
  ;

'DMSG :  % double-width, double-height message
  CR DWL DHLT DUP MSG
  CR DWL DHLB MSG
  ;

;F
