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

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


	 page 60,132

;********************** START OF SPECIFICATIONS ***********************/
;								      */
; SUBROUTINE NAME:  SSWSEMSU					      */
;								      */
; DESCRIPTIVE NAME:  Screen Switcher's system semaphore setup         */
;		     procedure. 				      */
;								      */
; FUNCTION: This is an internally called procedure which sets up      */
;	    the system semaphores needed for timing screen lock and   */
;	    save/restore function.				      */
;								      */
; NOTES:  Executes on Level 3					      */
;								      */
; ENTRY POINT:	SSSemSetup					      */
;   LINKAGE:							      */
;								      */
; INPUT: DS must point to the common data segment. Sgpointeroff       */
;	 points to the sgcb which is being created. BX contains       */
;	 the sg# for which we are created the semaphores.	      */
;								      */
; EXIT-NORMAL:	None						      */
;								      */
; EXIT-ERROR:	AX = error_no_semaphores_available		      */
;								      */
; EFFECTS:  System semaphores are created for the sg# passed in.      */
;								      */
; INTERNAL REFERENCES:						      */
;   ROUTINES:  None						      */
;								      */
; EXTERNAL REFERENCES:						      */
;   ROUTINES:  DosCreateSem					      */
;								      */
;	Change History: 					      */
;								      */
;	@TL6 - 03/01/90 - DCR 704 - Merge SMG/SSW instance data into  */
;			  OS2CHAR				      */
;								      */
;*********************** END OF SPECIFICATIONS ************************/

EXTRN noexclusive:word, semsuffix:byte, sgpointeroff:word
EXTRN lockneededname:byte

.xlist
INCLUDE STRUC.INC
INCLUDE SSWEQUAT.INC
INCLUDE SSWSTRUC.INC
INCLUDE SSWEXTR1.INC
INCLUDE ERROR.INC
INCLUDE ERROR2.INC
.list

.386P

CODE	SEGMENT WORD PUBLIC 'CODE' USE16                                ;@TL6

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

	 PUBLIC  SSSEMSETUP

SSSEMSETUP     PROC    NEAR		; We enter here with
					; common memory
					; accessible in DS
	 push	 di
	 push	 dx
	 push	 cx
	 push	 bx

;***************************************************************************
;  We first set  the 3-digit suffix in the ASCIIZ title of the system
;  semaphores to the sg# passed in.
;***************************************************************************

	 xchg	 ax,bx			; Get sg# in ax
	 mov	 bx,offset semsuffix	; Point to first suffix

	 mov	 word ptr [bx], '00'    ; each position
	 mov	 si,10			; Divide by 10
	 add	 bx,2
	 mov	 byte ptr [bx], '0'     ; each position

	 .WHILE <nonzero ax>		; Begin binary to		;@TL6
	    sub     dx,dx		; ASCII conversion
	    div     si
	    add     dx,'0'
	    mov     [bx],dl
	    dec     bx
	 .ENDWHILE


	 mov	 di,sgpointeroff	; DI points to sgcb
	 mov	 bx,word ptr semsuffix
	 mov	 word ptr[di].suffix,bx
	 mov	 dl,semsuffix+2
	 mov	 [di+2].suffix,dl
	 add	 di,offset lockneededsem
	 mov	 si,offset lockneededname

	 mov	 [si+10],bx
	 mov	 [si+12],dl
	 push	 noexclusive
	 push	 ds			; store sem handle
	 push	 di
	 push	 ds			; semaphore
	 push	 si

	 call	 DosCreateSem
	 .IF <zero ax>							;@TL6
	    mov     di,sgpointeroff
	    add     di,offset savemodesem
	    push    ds
	    push    di
	    call    DOSSEMCLEAR
	    .IF <zero ax>						;@TL6
	       mov     di,sgpointeroff
	       add     di,offset savemodethreadsem
	       push    ds
	       push    di
	       call    DOSSEMCLEAR
	       .IF <zero ax>						;@TL6
		  mov	  di,sgpointeroff
		  add	  di,offset saveredrawsem
		  push	  ds
		  push	  di
		  call	  DOSSEMCLEAR
		  .IF <zero ax> 					;@TL6
		     mov     di,sgpointeroff
		     add     di,offset saveresthreadsem
		     push    ds
		     push    di
		     call    DOSSEMCLEAR
		  .ENDIF
	       .ENDIF
	    .ENDIF
	 .ELSE					   ;			   @@@T
	    mov     ax,ERROR_VIO_INTERNAL_RESOURCE ; Return meaningful err @@@T
	 .ENDIF

	 pop  bx
	 pop  cx
	 pop  dx
	 pop  di

	 ret
SSSEMSETUP     ENDP

CODE	ENDS								;@TL6
	 END

