(****************************************************************************)
(*                                                                          *)
(*                           GSX Main Module                                *)
(*                           ===============                                *)
(* This Module contains all managing GSX functions, including the basic     *)
(* variable definitions used in the whole GSX system.                       *)
(*                                                                          *)
(* 21.1.1988          Wolfgang Muees, Hagenring 22, 3300 Braunschweig       *)
(*                                                                          *)
(****************************************************************************)

DEFINITION MODULE GSXMAIN;

FROM SYSTEM IMPORT ADDRESS;

TYPE
  VECTOR     = RECORD	             (* Used to specify a pixel position in arrays. *)
  		 X,Y : CARDINAL
	       END;
CONST
  CRT = 1; PLOTTER = 11; PRINTER = 21;  (* Some predefined workstation identifiers. *)
  replace = 1; transparent = 2;		(* Usable draw modes.    		    *)
  xor     = 3; erase 	   = 4;
  PinLen  =   4;  PoutLen  =   4;       (* Size of default GSX arrays               *)
  CinLen  = 128;  CoutLen  = 128;	(* may be altered by user		    *)

VAR
  PB	     : RECORD			(* Graphic Parameter Block used by GSX.	    *)
		 CTRLADD : ADDRESS;
  		 CINADD  : ADDRESS;
  		 PINADD  : ADDRESS;
  		 COUTADD : ADDRESS;
  		 POUTADD : ADDRESS;
  	       END;
  CB	     : RECORD			(* Control Block used by GSX.		    *)
  		 OPCODE  : CARDINAL;    (* Main function identifier.                *)
  		 PINLEN  : CARDINAL;    (* Number of parameters for all arrays.     *)
  		 POUTLEN : CARDINAL;
  		 CINLEN  : CARDINAL;
  		 COUTLEN : CARDINAL;
  		 ESCID	 : CARDINAL;    (* Second function identifier.              *)
  		 CTRL7   : CARDINAL;    (* Opcode dependent information.            *)
  		 CTRL8	 : CARDINAL;
  		 CTRL9   : CARDINAL;
  		 CTRL10  : CARDINAL;
  	       END;
  OpenParas : ARRAY[1..10] OF CARDINAL; (* default open workstation parameters      *)
  OpenCards : ARRAY[1..45] OF CARDINAL; (* CARDINAL information about workstation   *)
  OpenPtrs  : ARRAY[1..6 ] OF VECTOR;   (* VECTOR information about workstation     *)
  ColorExamined : RECORD		(* Returned information from ExamineColor.  *)
  	            Index, Red, Green, Blue : CARDINAL
		  END;
  PTSIN 	: ARRAY [1..PinLen]  OF VECTOR;			(* input vectors    *)
  PTSOUT	: ARRAY [1..PoutLen] OF VECTOR; 		(* output vectors   *)
  CARDIN	: ARRAY [1..CinLen]  OF CARDINAL;		(* input cardinals  *)
  CARDOUT	: ARRAY [1..CoutLen] OF CARDINAL;		(* output cardinals *)

PROCEDURE ResetAddr;						(* internal use only *)
PROCEDURE ResetPara;						(* internal use only *)
PROCEDURE simple ( Opcode : CARDINAL );				(* internal use only *)
PROCEDURE simplESC ( Opcode : CARDINAL );			(* internal use only *)
PROCEDURE oneCARD ( Opcode, Para : CARDINAL );			(* internal use only *)
PROCEDURE SetText ( Text : ARRAY OF CHAR );			(* internal use only *)
PROCEDURE numPTS ( Opcode, Number : CARDINAL; VAR Points : ARRAY OF VECTOR );

(************************************************************************************)

(*		       G S X M A I N      Definitions				    *)
(*		       ==============================				    *)

PROCEDURE OpenStation ( Identifier : CARDINAL );
 			 (* Opens the passed workstation. MUST be used before accessing
 			    other GSX procedures. *)

PROCEDURE CloseStation;	 (* Counterpart to OpenStation. MUST be called prior to returning
			    to operating system or open another workstation. *)

PROCEDURE ClearStation;  (* Erase screens , insert blank paper. After OpenStation, this
 			    procedure ist not needed. *)

PROCEDURE UpdateStation; (* Causes all pending commands to be executed. Before closing a
			    workstation, this procedure is not needed. Mainly used for
			    printer drivers. *)

PROCEDURE GraphMode;	 (* Explicitly sets graphic mode. Clear screens. After OpenStation,
			    the device is already in graphic mode. *)

PROCEDURE TextMode;      (* Turns to cursor-addressable text mode. This function is also
			    performed by CloseStation. *)

PROCEDURE HardCopy;	 (* Dumps out screen contents on printer. Only meaningfull if the
			    device is a CRT. *)

PROCEDURE SetCursor ( X,Y : CARDINAL );
			 (* Display the graphic cursor ( usualy a cross ) at the specified
			    position. Any old cursor is removed, so you don't need to use
			    the RemoveCursor procedure unless you want to display no cursor
			    at all. Only meaningfull if the device is a CRT. *)

PROCEDURE RemoveCursor;  (* Removes a previously displayed graphic cursor. If no cursor was
			    displayed, nothing happens. *)

PROCEDURE DefineColor ( Index, Red, Green, Blue : CARDINAL );
			 (* Defines color palette for this color index. If the index is not
			    available, nothing happens. *)

PROCEDURE ExamineColor ( Index : CARDINAL; Realized : BOOLEAN );
			 (* Examines color palette for this color index. If Realized = TRUE,
			    color displayed on device is returned, else color defined with
			    DefineColor or OpenStation is returned in ColorExamined. If the
			    index is out of range, then the maximum index is returned ( the
			    same would be used if you try to DRAW with this out-of-range
			    index ). *)

PROCEDURE DrawMode ( Mode : CARDINAL );
			 (* Determines the way pixels are modified. Not all devices can
			    do drawing in all modes ( for example, a PLOTTER can't do
			    xor drawing). Default DrawMode is replace. *)

END GSXMAIN.
