--  Em3270PrivDefs:  3270 Emulation Window Private Defs


--  Revised for Star 3.3 by Caro:	 5-Apr-84 15:31:26
--  Revised for Star 3.2fKlamath by Pettit:	30-Nov-83 14:16:45
--  Owner:  Lui

--  Overview:
--  This Def holds information which needs to be shared between various modules of the 3270 Emulator.



DIRECTORY
  AreaDefs USING [Wth],
  CharDefs USING [Char],
  Em3270Defs,
  Environment USING [Byte],
  GateStream USING [DeviceAddress, unspecifiedDeviceAddress],
  IconDefs USING [Icon, Name, File, Reference],
  NSFile USING [Handle, Attributes],
  NSString USING [String],
  RgnDefs USING [Sc, Srt],
  SchemaDefs USING [Lschema, lschemaNil],
  SelectionDefs USING [Seltype],
  Space USING [Interval],
  StandardDefs USING [Bv, Ch, Ct],
  System USING [NetworkAddress],
  VDTDefs USING [CharPos, CRShape, LptCharSeq, LschemaVDT];


Em3270PrivDefs: DEFINITIONS =
  BEGIN OPEN Em3270Defs, StandardDefs;

  --===================
  --  Public Types
  --===================
  -- Define the structure to hold initial default data in for the two3270 traits.
  Trt3270schemadatainit: TYPE = Trt3270schemadata;  -- do this for conformity sake only (could omit)
  Trt3270icondatainit: TYPE = Trt3270icondata;

  OpenData: TYPE = RECORD [  -- a pointer to the icon's name for Em3270osMgr 
    lptHostN: LONG STRING,
    -- modelNum: ModelType,    the 3278 model number,  future enchancement  
    lang: IBMlanguages,      -- the language of this controller as specified in ClearingHouse.
    icon3270: IconDefs.Icon];
   
  -- This is the FileAttributeData for Star3.0xr on:
  FileAttributeData: TYPE = MACHINE DEPENDENT RECORD[  -- describes info stored on icon's file object
    version: CARDINAL,      -- Star Version number 
    lang: IBMlanguages,      -- the language of this controller as specified in ClearingHouse.
    termaddr: GateStream.DeviceAddress,   --  the terminal address previously selected.
    ecsaddr: System.NetworkAddress,
    controllerAddr: CARDINAL,
    numOfTerm: GateStream.DeviceAddress,       -- the number of ports on the controller.
    -- modelNum: ModelType,    the 3278 model number,  future enchancement
     length: CARDINAL,  --  this & the followng fields MUST be last in FileAttributeData (see GetFileData)!
     maxlength: CARDINAL,
     bytes: PACKED ARRAY [0..0) OF Environment.Byte];
    
  EmHandle: TYPE = RECORD [   -- Instance data, exist only while 3270 window is open
    -- Note: Maybe this record should be a monitor because some of these fields can actully be modified in different process, but I believe we are saved becuase before a process updates any of the field, that process should have acquired the Buffer's monitor lock. Since all process must acquired the monitor lock before read or write onto any of the fields in the record, we are saved. Nevertheless one should be aware of the subtleties which exist.
    lang: IBMlanguages,      -- the language of this controller as specified in ClearingHouse.
    -- modelNum: ModelType,    the 3278 model number,  future enchancement
    display: VDTDefs.LschemaVDT ← SchemaDefs.lschemaNil,
    buffer: LptBufferData ← LOOPHOLE[LONG[NIL]],
    commun: LptComData ← LOOPHOLE[LONG[NIL]],
    command: LptCmdData ← LOOPHOLE[LONG[NIL]],
    inputStatus: InputStatus ← systemAvailable,
    status: LptStatusdata ← LOOPHOLE[LONG[NIL]],
    lptToTransFile: BaseOISToEFile ← LOOPHOLE[LONG[NIL]],
    spHandle: Space.Interval,
    prevCursorShape: VDTDefs.CRShape ← underscore,
    lschemaMenu, lschemaTitle: SchemaDefs.Lschema ← SchemaDefs.lschemaNil,
    putMDTStream: MDTStream ← [NIL, 0],   -- data to be send to the host.
    bvNoAID: Bv ← TRUE    -- state of AID, either Set or Reset.
    ];  -- data global to all of 3270 emulator modules

  InputStatus: TYPE = {inputInhibited, insertMode, systemAvailable};
  MDTStream: TYPE = RECORD [lptbuf: LptBufOfChar, blkIx: ComBufIndexCt];  -- info needed by the MDT field enumerators (i.e. AID processors).



  --===================
  -- Em3270BufferDefs Stuff
  --===================
  LptBufferData: TYPE = LONG POINTER TO BufferData; -- ptr to instance data --
  BufferData: TYPE;  -- exported type --
  AccessMode: TYPE = {keyMode, hostMode};
  Visibility:TYPE = MACHINE DEPENDENT
 			 {regularNoSel(0),regularSel(1),intense(2),invisible(3)};
		      -- {dispNoSel & dispSel, intenseDispSel, noDispNoSel} --
  
  PvFieldAndNullsHit: TYPE = PROCEDURE [
    mainBuffer: VDTDefs.LptCharSeq, startPos: VDTDefs.CharPos, fLength: CARDINAL,
     bvHasAttribute: Bv ← TRUE,visibility: Visibility]; -- for make doc. --

  PvFieldHit: TYPE = PROCEDURE [
    mainBuffer: VDTDefs.LptCharSeq, startPos: VDTDefs.CharPos, fLength: CARDINAL,
    clientData: MDTStream, bvIsNewField: Bv, lptToTransFile: BaseOISToEFile] RETURNS [MDTStream];  -- for read modified command --

  --===================
  -- Em3270CharTrans Stuff
  --===================
  BaseOISToEFile: TYPE = LONG BASE POINTER TO Aq3270TransFile;   -- base pointer to a file which contains the OIS to EBCDIC translations
  Aq3270TransFile: TYPE;  -- exported type

  --===================
  -- Em3270Cmd Stuff
  --===================
  -- +++ the following types are used by Em3270BufferPack and Em3270CmdProcessPack, the way how TextIndexType, and MaxRunIndex are declare is very error prone. it should be changed in the future(like OS5). Em3270CmdProcess works okay now, but the element [127] is never used.
   
  LptCmdData: TYPE = LONG POINTER TO CmdData;  -- pointer to command processor's instance data  
  CmdData: TYPE;   -- exported type
  TextIndexType: TYPE = [0..128);  -- a run of Text passed to buffer manager.   
  TextRun: TYPE = ARRAY TextIndexType OF CharDefs.Char;
  EBCDICTextRun: TYPE = ARRAY TextIndexType OF CHARACTER;
  MaxRunIndex: TextIndexType = LAST[TextIndexType];
  LptTextRun: TYPE = LONG POINTER TO TextRun;
  LptETextRun: TYPE = LONG POINTER TO EBCDICTextRun;

  --===================
  -- Em3270Com Stuff
  --===================
  LptComData: TYPE = LONG POINTER TO ComData;  -- pointer to communication's instance data  
  ComData: TYPE;   -- exported type
  ComBufIndexCt: TYPE = [0..508];
  ComBufIndex: TYPE = [0..LAST[ComBufIndexCt]);
  maxComBufCt: ComBufIndexCt = LAST[ComBufIndexCt];
  LptBufOfChar: TYPE = LONG POINTER TO BufOfChar;
  BufOfChar: TYPE = RECORD [  -- host input data buffer.  
    hostData: PACKED ARRAY ComBufIndex OF CHARACTER, nextBuf: LptBufOfChar ← NIL];
  -- pointer to next buffer if current buffer is full

  --===================
  -- Em3270Status Stuff
  --===================
  LptStatusdata: TYPE = LONG POINTER TO Statusdata; -- pointer to status area's instance data;
  Statusdata: TYPE; -- exported type;
  
  --===================
  --  Signals and Errors
  --===================


  --===================
  --  Constants
  --===================
  Star3: CARDINAL = 999;   -- defines a 3270 icon created with Star 3.0xr or newer.
  StarUnknown: CARDINAL = 31;    -- Can't determine which version of star that the icon was created in.
  langDft: IBMlanguages = USenglish;    --  default language to USEnglish.
  wthBorder: AreaDefs.Wth = 4;  -- outside border width of 3270 window
  maxNumPorts: GateStream.DeviceAddress = 8;
  termAddrDflt: GateStream.DeviceAddress = GateStream.unspecifiedDeviceAddress;  -- default Terminal Address
  addrECSDflt: READONLY System.NetworkAddress;  -- default ECS Net Address(exported type)
  szTermAddr: Ct = SIZE[GateStream.DeviceAddress];
  szNetAddr: Ct = SIZE[System.NetworkAddress];
  szCardinal: Ct = SIZE[CARDINAL];
  szMaxCAChars: Ct = 5;  -- MAX[controllerAddr] in display characters
  sztotal: Ct = SIZE[FileAttributeData];
  chNameSeporator: Ch = '#;  -- Clearinghouse seporator between local/domain/region
  chNameRadix: Ch = 'B;  -- Controller Address radix character given to Stream.Create 

  --===================
  --  Public Procedures
  --===================
  -- Any Trait with trait data should provide a PROC which will initialize that data for a new instance.  This data may, of course, be over-written at any time.  Initialize the two 3270's trait datas provided here.
  PvInitTrt3270schemaData: TYPE = PROCEDURE [
    lschema: SchemaDefs.Lschema, ptdatainit: POINTER TO Trt3270schemadatainit];
  InitTrt3270schemaData: PvInitTrt3270schemaData;

  PvInitTrt3270iconData: TYPE = PROCEDURE [
    lschema: SchemaDefs.Lschema, ref: IconDefs.Reference, parent:IconDefs.File, ptdatainit: POINTER TO Trt3270icondatainit];
  InitTrt3270iconData: PvInitTrt3270iconData;

  -- get various Emulator handles or data which are common to all Emulator modules which are stored globally in hyper-space
  GetBufferHandle: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [handle: LptBufferData];
  GetNameOfIcon: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [iconName: IconDefs.Name];
  GetDisplayHandle: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [handle: VDTDefs.LschemaVDT];
  GetSelType: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [SelectionDefs.Seltype];
  GetSrtStatus: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [srt: RgnDefs.Srt];
  GetComHandle: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [handle: LptComData];
  GetCmdHandle: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [handle: LptCmdData];
  GetTransHandle:PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [handle: BaseOISToEFile];
  GetLangType: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [lang: Em3270Defs.IBMlanguages];
  SetLangType: PROCEDURE [lschema: SchemaDefs.Lschema, lang: Em3270Defs.IBMlanguages];
  GetInputStatus: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [status: InputStatus];
  SetInputStatus: PROCEDURE [lschema: SchemaDefs.Lschema, status: InputStatus];
  GetPrevCursorShape:PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [crShape: VDTDefs.CRShape];
  SetPrevCrShape: PROCEDURE [lschema: SchemaDefs.Lschema, crShape: VDTDefs.CRShape];
  GetMDTStream: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [putMDTStream: MDTStream];
  SetMDTStream: PROCEDURE [lschema: SchemaDefs.Lschema, putMDTStream: MDTStream];
  GetAIDStatus: PROCEDURE [lschema: SchemaDefs.Lschema]
    RETURNS [bvNoAID: Bv];
  SetAIDStatus: PROCEDURE [lschema: SchemaDefs.Lschema, bvNoAID: Bv];

  -- Get any data stored on the file object which backs the 3270 icon
  GetFileData: PROCEDURE [file: NSFile.Handle, attributes: NSFile.Attributes, z: UNCOUNTED ZONE]
    RETURNS [
      taddress: GateStream.DeviceAddress, 
      netaddress: System.NetworkAddress,
      controllerAddr: CARDINAL,
      -- termMod: ModelType,
      portOnController: GateStream.DeviceAddress,   -- number of valid ports on controller.
      hostLang: IBMlanguages,  -- Language of controller.  
      ptrs232String: NSString.String];
  -- This routine retrieves from the 3270 icon backing file all the data stored in the Attributes.clientFileWords field and brings it into memory.  Data structurs set up by this routine MUST be freed by calling "ClearFileData".
    
  ClearFileData: PROCEDURE [attributes: NSFile.Attributes];
  -- This routine MUST be used inconjunction with GetFileData to free the storage that GetFileData allocates
  
  
  -- Inline Procedures
  ScVDT: PROCEDURE RETURNS[RgnDefs.Sc] = INLINE
  {RETURN[ [xc:wthBorder,yc:wthBorder] ]};

  END.	-- of Em3270PrivDefs

LOG (date - person - reason)

February 16, 1981 - Kernaghan - Created
February 18, 1982 - Stepak - added 'PvFieldAndNullsHit', 'PvFieldHit', LptBufferData,
   LptCmdData, LptComData, AccessMode.
18-Feb-82 - Lui - added Em3270Com and Em3270Cmd stuff.
February 19, 1982 - Stepak - added inputStatus to emulator instance data, and InputStatus type.
February 22, 1982 - Stepak - added 'bvHasAttribute' param to 'EnumAllFieldsAndNulls'
February 22, 1982 - Kernaghan - Added GetInputStatus and SetInputStatus.
February 23, 1982 - Stepak - Added 'clientData' param to EnumAllFieldsAndNulls
February 25, 1982 - Kernaghan - Added LptBufOfChar and LptCharSeq.
March 3, 1982 - Kernaghan  - Changed rtstatus to srtstatus type RgnDefs.Srt.  Add ScVDT.
March 3, 1982 - Stepak - changed PvFieldAndNullsHit 'clientData' to 'NewDocConvertDefs.Dc'; deleted RETURN param.
March 10, 1982 - Kernaghan - Added lschemaMenu, lschemaTitle to EmHandle.
March 11, 1982 - Kernaghan - Change termAddrDflt to be GateStream.unspecifiedTerminalAddress.  Change PvInitTrt3270iconData input parameters.
March 12, 1982 - Stepak - removed 'NewDocConvertDefs.Dc' from PvFieldAndNullsHit
March 24, 1982 - Kernaghan - Added szCardinal, changed szTermAddr to be
   GateStream.TerminalAddress, and changed sztotal to add 2*szCardinal.
   Add GetFileData, ClearFileData, szMaxCAChars, chNameSeporator, and chNameRadix.
April 1, 1982 - Stepak - added 'Visibility' type, and 'visibility' parameter to
   'pvFieldsAndNullsHit' to fix AR #6324.
12-Apr-82 - Weissman - Change EmHandle.srtstatus to EmHandle.status (long pointer)
18-Jun-82 - Lui - added EBCDICTextRun, and LptETextRun.
   changed TextIndexType: TYPE = [0..1920) to TextIndexType: TYPE = [0..256)   
19-Jul-82 - Lui - changed TextIndexType: TYPE = [0..256) to TextIndexType: TYPE = [0..128).
21-Jul-82 - Lui - Added GetPrevCursorShape and SetPrevCrShape, added prevCursorShape to Emhandle. 
 4-Aug-82 - Lui - merge with Star2.1ar
23-Aug-82 - Lui - Added a Language field to OpenData, FileAttributeData, and EmHandle.
   Added Procedures SetLangType, and GetLangType. Added lang field to return clause of
   procedure GetFileData.
31-Aug-82 - Lui - Added a Language field to PvFieldHit.
 9-Sep-82 - Lui - added Em3270CharTrans Stuff and lptToTransFile to Emhandle.
14-Sep-82 - Lui - removed compilation warning messages
28-Sep-82 - Lui - added GetNameOfIcon
29-Sep-82 - Lui - added GetSelType
12-Oct-82 - Lui - changed FileAttributeData, and GetFileData
 9-Dec-82 - Lui - added spHandle to EmHandle.
25-Jan-83 - Lui - changed MDTStream.blkIx from ComBufIndex to ComBufIndexCt.
14-Feb-83 - Lui - add the constant Star3 and added version to FileAttributeData
18-Apr-83 - Lui - removed READONLY
29-Jun-83 - Lui - Support for Read Modified Command
30-Nov-83 - Pettit - Klamath conversion: GateStream.TerminalAddress -> DeviceAddress;
   spHandle -> Space.Interval (instead of SpDefs.Handle).