;       SCCSID = @(#)smgpopup.asm	6.1 90/11/18
;	SCCSID @(#)smgpopup.asm	6.8 90/09/12
PAGE 60,132    ;
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************

;***************************************************************************
;
; Source File Name:	SMGPOPUP.ASM
;
; Subroutine Name:	DOSSMSGDOPOPUP
;
; Descriptive Name:	Session Manager Do Popup Switch
;
; Function:	Signal the Session Manager via a shared RAM semaphore
;		that an application do popup switch is pending.
;
; Notes:
;	Dependencies:	None
;
;	Restrictions:	None
;
;     Change History:
;	@TL7 - 04/05/90 - PTR B712376 - Enable for MMIO
;	@MHW - 09/13/90 - PTR B715818 - In-line Performance (MMIO) hooks
;
; Entry Point:
;	Linkage:  EXTRN DOSSMSGDOPOPUP:FAR
;			PUSH	WORD   Proc_Type  ; Process Type
;			PUSH	WORD   Poptype	  ; Normal or Transparent
;			PUSH	WORD   PID	  ; Process ID
;			PUSH	WORD   SGID	  ; Screen Group Number
;			CALL	DOSSMSGDOPOPUP
;
; Inputs:
;	WORD	Proc_Type  Process Type of requesting popup (from LDT)
;	WORD	Poptype	   Value = 0, Normal popup w/screen clear
;			   Value = 1, Transparent popup,
;				      no screen clear
;	WORD	PID	   Process ID requesting popup
;	WORD	SGID	   Screen group number requesting popup
;
; Exit Normal:
;	AX	ReturnCode Value = 0, successful screen group
;				      switch
;
; Exit Errors:
;	AX	ReturnCode error_smg_session_not_found
;
;			   POPUPSWITCH errors
;
; Effects:	All other registers preserved.
;
; Internal References:
;	   Data:	The following data is in a shared data segment(SDATA)
;				popupsgid
;				popupflags
;	   Routines:	POPUPSWITCH
;
; External References:
;	   Routines:
;
;***************************************************************************
ifdef I1
;
;   IF (Not hard error popup) OR
;   IF (dopoprtype e detached)
;      Initialize popup data
;      IF (Transparent popup request)
;	  Set popup flag
;      ENDIF
;      Setup offset to popup semaphores
;
;   ELSE
;      Setup offset to hard error popup semaphores
;   ENDIF
;
;   POPUPSWITCH (Process popup request)
;
;***************************************************************************
else

.386C
   EXTRN HdePopRetCode	 : WORD		; Hard error popup retcode
   EXTRN PopUpPID	 : WORD		; Popup process ID
   EXTRN PopUpSGID	 : WORD		; Popup screen group ID
   EXTRN PopUpPrType	 : WORD		; Popup process type
   EXTRN PopUpFlags	 : WORD		; Do or end popup request
   EXTRN PopUpReturnCode : WORD		; Popup return code from SMgr
   EXTRN HdeOldFgnd	 : WORD		; Old fgnd SG prior to popup
   EXTRN HdePopFlags	 : BYTE		; Do or end popup request
   EXTRN HdeSMGRamSem	 : DWORD	; Hard error popup sem.(SMG)
   EXTRN HdeVioRamSem	 : DWORD	; Hard error popup sem.(VIO)
   EXTRN LocalSelector	 : WORD		; Local infoseg selector
   EXTRN PopSMGRamSem	 : DWORD	; Popup RAM semaphore for SMGR
   EXTRN PopVioRamSem	 : DWORD	; Popup RAM semaphore for VIO

   EXTRN DOSSEMCLEAR	 : FAR		; Release semaphore ownership
   EXTRN DOSSEMSET	 : FAR		; Unconditionally set semaphore
   EXTRN DOSSEMWAIT	 : FAR		; Wait clear semaphore

.xlist
   INCLUDE SMGPOPUP.INC
   INCLUDE SMRRDATA.INC
   INCLUDE INFOSEG.INC
    INCLUDE SMMMPHA.INC			; Performance hook macros	;MHW
   INCLUDE ERROR.INC			; ERROR_INTERRUPT
.xcref
   INCLUDE STRUC.INC
.cref
.list

CODE SEGMENT WORD PUBLIC 'CODE' USE16
   ASSUME CS:CODE,DS:NOTHING,SS:NOTHING,ES:NOTHING

   PUBLIC DOSSMSGDOPOPUP
   PUBLIC DOSSMSGDOPOPUP_POSTDT
DOSSMSGDOPOPUP PROC FAR

   Local_Bytes	EQU  0

   ENTER Local_Bytes,0
   PUSH AX				; Save registers
   PUSH DS
   PUSH SI
   PUSH DI
   MOV	AX, RDATA			; Addressability to global data
   MOV	DS, AX

   MMPHPreDOSSMSGDoPopup		; Performance Hook (8009h)	;MHW

;  ***********************************************************************
;  *  Initialize data required by Session Manager for a do popup switch	 *
;  ***********************************************************************
   MOV	AX, SS:[BP].DoPopSGID		; Screen group requesting popup
   .IF	<AX ne 0> OR			; If not hard error popup
   .IF	<SS:[BP].DoPopRType eq LIS_PT_DETACHED>

     MOV  DS:PopUpSGID, AX
     MOV  AX, SS:[BP].DoPopPID		; popup process ID
     MOV  DS:PopUpPID, AX
     MOV  DS:PopUpFlags, 0		; Do popup request

     MOV  AX, SS:[BP].DoPopRType	; Process Type xxxxxxxxx
     MOV  DS:PopUpPrType, AX

     .IF  <SS:[BP].DoPopType ne 0>	; Transparent popup req.
       OR   DS:PopUpFlags, 8000H
     .ENDIF
     MOV  SI, OFFSET PopSMGRamSem
     MOV  DI, OFFSET PopVioRamSem

   .ELSE
     MOV  DS:HdePopFlags, 0		; Do popup request
     MOV  SI, OFFSET HdeSMGRamSem
     MOV  DI, OFFSET HdeVioRamSem
   .ENDIF

   CALL POPUPSWITCH			; Process application popup request

   MOV	AX_Reg[-Local_Bytes], AX	; Place return code on the stack

   MMPHPostDOSSMSGDoPopup		; Performance Hook (8089h)	;MHW

   POP	DI				; Restore registers
   POP	SI
   POP	DS
   POP	AX

   LEAVE
   DOSSMSGDOPOPUP_POSTDT LABEL FAR
   RET	DoPopUpLen

DOSSMSGDOPOPUP ENDP
endif					; I1 package check

PAGE
;***************************************************************************
;
; Source File Name:	SMGPOPUP.ASM
;
; Subroutine Name:	DOSSMSGENDPOPUP
;
; Descriptive Name:	Session Manager End Popup Switch
;
; Function:	Signal the Session Manager via a shared RAM semaphore
;		that an application end popup switch is pending.
;
; Notes:
;	Dependencies:	None
;
;	Restrictions:	None
;
;	Change History:
;
; Entry Point:
;	Linkage:  EXTRN DOSSMSGENDPOPUP:FAR
;			PUSH	WORD   SGID	  ; Screen Group Number
;			CALL	DOSSMSGENDPOPUP
;
; Inputs:
;	WORD	SGID	   Screen group number terminating popup
;
; Exit Normal:
;	AX	ReturnCode Value = 0, successful screen group switch
;
; Exit Errors:
;	AX	ReturnCode POPUPSWITCH errors
;
; Effects:	All other registers preserved.
;
; Internal References:
;	   Data:	The following data is in a shared data segment(SDATA)
;				popupflags
;	   Routines:	POPUPSWITCH
;
; External References:
;	   Routines:
;
;***************************************************************************
ifdef I1
;
;		IF (Not hard error popup) OR
;		IF (Hard error popup)	  AND
;		IF (dopoprtype e detached)
;		   Setup offset to popup semaphores
;		ELSE
;		   Setup offset to hard error popup semaphores
;		ENDIF
;		POPUPSWITCH(Process end popup)
;
;***************************************************************************
else

   PUBLIC DOSSMSGENDPOPUP
   PUBLIC DOSSMSGENDPOPUP_POSTDT
DOSSMSGENDPOPUP PROC FAR

   Local_Bytes	EQU  0

   ENTER Local_Bytes,0

   PUSH AX				; Save registers
   PUSH DS
   PUSH SI
   PUSH DI
   MOV	AX, RDATA			; Addressability to global data
   MOV	DS, AX

   MMPHPreDOSSMSGEndPopup		; Performance Hook (800Ah)	;MHW

;  *************************************************************************
;  *  Initialize data required by Session Manager for an end popup switch  *
;  *************************************************************************
   .IF	<SS:[BP].DoPopSGID ne 0> OR
   .IF	<SS:[BP].DoPopSGID e 0>	 AND	; Detached may be in sg 0
   PUSH DS				;
   MOV	DS,DS:LocalSelector		;
   CMP	DS:[LIS_CurScrnGrp],3		; Detached doing end popup?
   POP	DS				;

   .IF	<z>				;
     OR	  DS:PopUpFlags, 1		; End popup request
     MOV  SI, OFFSET PopSMGRamSem
     MOV  DI, OFFSET PopVioRamSem
   .ELSE
     MOV  DS:HdePopFlags, 1		; End popup request
     MOV  SI, OFFSET HdeSMGRamSem
     MOV  DI, OFFSET HdeVioRamSem
   .ENDIF

   CALL POPUPSWITCH			; Process application end popup

   MOV	AX_Reg[-Local_Bytes], AX	; Place return code on the stack

   MMPHPostDOSSMSGEndPopup		; Performance Hook (808Ah)	;MHW

   POP	DI				; Restore registers
   POP	SI
   POP	DS
   POP	AX

   LEAVE

   DOSSMSGENDPOPUP_POSTDT LABEL FAR
   RET	2

DOSSMSGENDPOPUP ENDP
endif					; I1 package check

PAGE
;***************************************************************************
;
; Source File Name:	SMGPOPUP.ASM
;
; Subroutine Name:	POPUPSWITCH
;
; Descriptive Name:	Session Manager Popup Switch
;
; Function:	Signal the Session Manager via a shared RAM
;		semaphore that an application do/end popup
;		switch is pending.
;
; Notes:
;	Dependencies:	None
;
;	Restrictions:	None
;
;	Change History:
;
; Entry Point:
;	Linkage:  EXTRN POPUPSWITCH:NEAR
;			CALL	POPUPSWITCH
;
; Inputs:
;	None
;
; Exit Normal:
;	DS:DI	Sel:Off	   Addr. of semaphore to request popup
;	DS:SI	Sel:Off	   Addr. of semaphore indicating popup
;			   complete
;	AX	ReturnCode Value = 0, successful screen group
;				      switch
;
; Exit Errors:
;	AX	ReturnCode popupreturncode
;
; Effects:	All other registers preserved.
;
; Entry Points:
;
;***************************************************************************
ifdef I1
;
;		DOSSEMSET(Set popup complete semaphore)
;		DOSSEMCLEAR(Release popup request semaphore)
;		REPEAT
;		   DOSSEMWAIT(Wait on popup completion semaphore)
;		UNTIL(AX ne error_interrupt)
;		IF (popup request)
;		   AX = popupreturncode
;		ELSE
;		   AX = hdepopretcode
;		ENDIF
;
;***************************************************************************
else

POPUPSWITCH PROC NEAR

   ENTER 0,0
;  *******************************************************************
;  *  Wait for the Session Manager to signal the switch is complete  *
;  *******************************************************************
   PUSH DS				; Pre-set popup RAM semaphore for SMGR
   PUSH SI
   CALL DOSSEMSET

;  *************************************************
;  *  Clear the shared RAM popup switch semaphore  *
;  *************************************************
   PUSH DS				; Shared popup RAM semaphore for VIO
   PUSH DI
   CALL DOSSEMCLEAR

;  *******************************************************************
;  *  Wait for the Session Manager to signal the switch is complete  *
;  *******************************************************************
   .REPEAT				; Make sure sem is cleared
     PUSH DS				; Shared popup RAM semaphore for SMGR
     PUSH SI
     PUSH -1				; No timeout
     PUSH -1
     CALL DOSSEMWAIT
   .UNTIL < AX ne Error_Interrupt >	; In case int. woke us up

   .IF	<SI eq <OFFSET PopSMGRamSem>>
     MOV  AX, DS:PopUpReturnCode	; Return code from SMgr
   .ELSE
     MOV  AX, DS:HdePopRetCode		; Return code from SMgr
   .ENDIF

   LEAVE
   RET					; Return to caller

POPUPSWITCH ENDP

CODE ENDS
endif
   END
