;       SCCSID = @(#)sswinit.asm	6.1 90/11/18

;      SCCSID = @(#)sswinit.asm	1.6 90/03/19
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************

; ****************************************************************************
; *	Change History: 						     *
; *									     *
; *	@TL6 - 03/01/90 - DCR 704 - Merge SMG/SSW instance data into	     *
; *			  OS2CHAR					     *
; *									     *
; ****************************************************************************
			 page 60,132

EXTRN DOSFSRAMSEMCLEAR:FAR
.xlist
.xcref
INCLUDE SSWSTRUC.INC
INCLUDE SSWEXTR1.INC
INCLUDE SSWEXTR3.INC
INCLUDE STRUC.INC
INCLUDE SSWEQUAT.INC
INCLUDE INFOSEG.INC
INCLUDE ERROR.INC
INCLUDE ERROR2.INC

PUBLIC memmapptr, noexclusive, locktime, allocation_cnt, locktimepid
PUBLIC scrngroup, sgnumber, sgpointeroff, shsegsize, ssmgr_pid
PUBLIC shared_name, sgcb_str_len,kbd_parm_table
PUBLIC kbd_name, memmapsize,pidcb_str_len, memory_pool, timedouterror
PUBLIC kbd_filehandle, kbd_actiontaken, kbd_filesize
PUBLIC kbd_fileattr, kbd_openflag, kbd_openmode
PUBLIC semsuffix
PUBLIC mempoolsize, memtableptr, lockneededname, pidcb_str
PUBLIC pidpointeroff, memtbl_str, memtbl_str_len
PUBLIC sgcb_str,scrngrpsize
PUBLIC blockid,ddnotify,ddnotifysize
PUBLIC segsize,subfunction, actionpacket, procid
PUBLIC responsepacket, scrnaction, modeaction
PUBLIC lockfrozen, screenlocksgid					;@TL6
PUBLIC locktimerowner, locktimersem
PUBLIC struc_length, blank, priority					;@TL6
PUBLIC saveundosem, saveundoflag					;@TL6
PUBLIC localsg, globalsg
PUBLIC savelocksem, savelockflag, savelockowner
.cref
.list

.386p

;------------------------------------------------------------------------

RDATA	       SEGMENT WORD PUBLIC 'DATA' USE16 ; Static memory area    ;@TL6

allocation_cnt DW      0
blank	       DB      20H,07H
blockid        DW      0
globalsg       DW      0			    ; Hold selector ###1
localsg        DW      0			    ; Hold selector ###1
locktime       DW      30000			    ; 30 seconds
locktimepid    DW      0
memmapptr      DW      0			    ; offset of mem table
noexclusive    DW      1			    ; No exclusive owner
lockfrozen     DW      0			    ; =1 if pid frozen
locktimerowner DW      0			    ; Owner of locktimer
pidpointeroff  DW      0			    ; Next pidcb to initial
priority       DW      0			    ; For dosgetprty call
saveundoflag   DW      0			    ; Sem has been set
screenlocksgid DW      0			    ; SG of savelockowner
scrngroup      DW      0			    ; Parameter passed in
semflags       DW      0			    ; Tests semaphores
sgpointeroff   DW      0			    ; Next sgcb to initial
shsegsize      DW      0
ssmgr_pid      DW      0			    ; For session mgr pid#
timedouterror  DW      0
modeaction     DW      0			    ; Restore mode
scrnaction     DW      0			    ; Save/restore screen

;***************************************************************************
; The following parameters are for the DOSOPEN call issued to get a handle
; when invoking DOSDEVIOCTL to call the KBD driver.
;***************************************************************************

kbd_name       LABEL   BYTE
kbd_filename   DB      'KBD     ',0                 ; Name of KBD dev drv
kbd_filehandle DW      0			    ; New file's handle
kbd_actiontaken DW	0			    ; Only open exist file
kbd_filesize   DW      0
kbd_fileattr   DW      0004H			    ; system file attribute
kbd_openflag   DW      0001H			    ; Fail if not there
kbd_openmode   DW      0042H			    ; shared/ro/ret errs

;***************************************************************************

struc_length	DW	3			    ; process dies
;type		 DB	 0

;***************************************************************************

shared_name    LABEL   BYTE
sharedmem_name DB      '\SHAREMEM\SCRSWT.DAT',0     ; Name  of shared data

lockneededname	    DB	'\SEM\LKNED'
semsuffix	    DB	'000'
		    DB	'.SEM',0
saveundosem	    DD	0
locktimersem	    DD	0
locktimeflag	    DB	0
;
savelocksem    LABEL   BYTE
	       DW      14	; length of FSRAMSEM structure
savelockowner  DW      0	; process ID of owner
thrdID	       DW      0	; thread ID of owner
use_count      DW      0	; ref count
savelockflag   DB      0	; debug flag (user defined)
	       DB      0
savelockRAMsem DD      0	; RAM semaphore
;***************************************************************************
; The following is storage for the Action Packet required by the
; DosSystemService call,
;***************************************************************************


actionpacket   DW      1
subfunction    DW      ?			    ; 0 = freeze, 1 = thaw
procid	       DW      ?			    ; pid to be froz/thawed

responsepacket DW      10 dup(0)

;***************************************************************************
; The following section allocates a block of memory for a structure. This
; should be removed at a later date when the final sizes are stable.
;***************************************************************************

;MEMMAP 	MEMTABLE <>			     ; layout of memory avail
;memmapsize	DW	$ - memmap
memmapsize	DW	148
;SCRNGROUP0	SGCB	<0>			     ; Layout of sgcb
;scrngrpsize	DW	$ - scrngroup0
scrngrpsize	DW	92

KBD_PARM_TABLE LABEL   BYTE
DDNOTIFY       DEVICEDRV <>			    ; Parameters for KBD
ddnotifysize   DW      $ - ddnotify

;PIDCB0 	PIDCB	<>
;pidcbsize	DW	$ - pidcb0
;***************************************************************************

MEMTBL_STR     LABEL   BYTE
	       DB      16 dup (0,0,1,2 dup(-1),4 dup(0))
	       DW      2 dup (-1)		    ; Eot and ptr to next
memtbl_str_len DW      $ - memtbl_str		    ; memtable
memtableptr    DW      memory_pool					;@TL6


PIDCB_STR      LABEL   BYTE
	       DW      19 dup(0)		    ; Initialization string
	       DD      -1			    ; eotmarker and ptr to
						    ; continuation pidtable
pidcb_str_len  DW      $ - pidcb_str

SGCB_STR       LABEL   BYTE
sgnumber       DW      0			    ; Used to initialize
	       DW      -1			    ; the screen group
	       DW      4 dup(0) 		    ; control block
	       DW      -1
	       DW      3 dup (0)
	       DW      -1
	       DW      2 dup (0)
	       DW      -1
	       DB      15 dup(0)
	       DW      -1
	       DB      47 dup(0)
sgcb_str_len   DW      $ - sgcb_str


;***************************************************************************
; Here begins the area of memory allocated to the memory mapping table and
; the area for screen group control blocks and pid control blocks.
;***************************************************************************

memory_pool    DB      148 dup('M')                  ; For mem table and
	       DB      8 * 92 dup ('M')              ; 8 sgcbs
mempoolsize    DW      $ - memory_pool

segsize        DW      $ + 2			    ; Initial memory	;@TL6
						    ; requirement
RDATA	       ENDS

;------------------------------------------------------------------------
;*********************** START OF SPECIFICATIONS ***********************/
;								       */
;  SOURCE FILE NAME: SSWINIT					       */
;								       */
;  SUBROUTINE NAME:  DOSSSINIT					       */
;								       */
;  DESCRIPTIVE NAME:  Screen Switcher initialization call	       */
;								       */
;  FUNCTION:  Issued by Session Manager to allow Screen Switcher to    */
;	      allocate shared memory, initialize variables, tables.    */
;								       */
;  NOTES:  Executes on Level 3					       */
;								       */
;  ENTRY POINT:  DosSSInit					       */
;    LINKAGE:							       */
;								       */
;  INPUT:							       */
;								       */
;  EXIT-NORMAL:  AX = 0 					       */
;								       */
;  EXIT-ERROR:	 AX = 1 for invalid function call (call issued by      */
;		       other than Session Manager)		       */
;								       */
;  EFFECTS:  Contents of AX destroyed by return code		       */
;								       */
;  INTERNAL REFERENCES: 					       */
;    ROUTINES:	SSCBSetup, SSCBAllocate, SSSemSetup		       */
;								       */
;  EXTERNAL REFERENCES: 					       */
;    ROUTINES:	None						       */
;								       */
;************************ END OF SPECIFICATIONS ************************/

; Get current pid number
; IF <pid is not session mgr>
;  AX = error_scs_not_session_ngr
; ELSE
;  Set up memory table
;  Allocate storage for screen groups 0 - 3
;  Set up system-wide semaphore used to help synchronize Screen Switcher
;  Set up system-wide semaphore used to time screen locks
;  Set up system-wide semaphore used to block undo calls
;  AX = no_error
; ENDIF

CODE	SEGMENT WORD PUBLIC 'CODE' USE16                                ;@TL6

	ASSUME	CS:CODE, DS:RDATA, SS:NOTHING, ES:NOTHING		;@TL6

	       PUBLIC  DOSSSINIT

DOSSSINIT      PROC    FAR

 push	 bx
;push	 cx								;@TL6
 push	 es
 push	 ds

 mov	 ax,RDATA				    ; We can access our ;@TL6
 mov	 ds,ax					    ; static data area	;@TL6

 push	 ds					    ;
 push	 offset globalsg			    ; global infoseg @	;@TL6
 push	 ds					    ;			;@TL6
 push	 offset localsg 			    ; local infoseg @	;@TL6
 call	 DOSGETINFOSEG				    ; Get screen group#
 .IF <zero ax> near							;@TL6
  mov	  es,localsg				    ;			;@TL6
  mov	  bx,es:lis_curprocid			    ; Get current pid#
  .IF <ssmgr_pid e ax>				    ; 1st caller?	;@TL6
   mov	   ssmgr_pid,bx 			    ; Save current pid

;************************************************************************
;*	       Set up SSCBs for process/thread data storage		*
;*		   clear all variables, flags				*
;************************************************************************

;  lea	   ax,memory_pool			    ; Points to first	;@TL6
						    ; memory mapping table loc
;  mov	   memtableptr,ax			    ; Keep as growing ptr
   call    SSMEMTABLESU 			    ; Sets up memory

;************************************************************************
;	  Now we allocate storage for screen groups 0,1,2, & 3
;	  (Note: this code was added on 1/9/87)
;************************************************************************
    push si					    ; Save/restore regs ;@TL6
    push di					    ; destroyed by	;@TL6
   .FOR bx = 0 to 3				    ; SSGETSGCB
    call SSGETSGCB
    .LEAVE <nonzero ax> 						;@TL6
   .NEXT bx
    pop  di					    ; In case Session	;@TL6
    pop  si					    ; Manager changes	;@TL6
;************************************************************************
;  We set up the system-wide semaphore which will time screen locks
;************************************************************************
;   push    ds								;@TL6
;   push    offset locktimersem 					;@TL6
;   call    DOSSEMCLEAR 						;@TL6
;   .IF <zero ax>							;@TL6
;************************************************************************
;  We set up the system-wide semaphore which will block undo calls
;************************************************************************
;    push    ds 							;@TL6
;    push    offset saveundosem 					;@TL6
;    call    DOSSEMCLEAR						;@TL6
;   .ENDIF								;@TL6
  .ELSEIF <bx ne ssmgr_pid>			; Is caller SESMGR?	;@TL6
   mov	   ax,error_scs_not_session_mgr
  .ENDIF
 .ENDIF
 pop	 ds
 pop	 es
;pop	 cx								;@TL6
 pop	 bx

 Ret						    ; Return error code
DOSSSINIT      ENDP				    ; in AX
CODE	ENDS								;@TL6
 END
