;       SCCSID = @(#)smrsmset.asm	6.2 92/02/21
;       SCCSID @(#)smrsmset.asm	6.2 92/02/21
PAGE 60,132                             ;
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;************************************************************************
;
; Source File Name:     SMRSMSET.ASM
;
; Subroutine Name:      DOSSMSETSESSIONTYPE
;
; Descriptive Name:     Set Session Type
;
; Function:     Set the specified session to the given type, if possible.
;               Currently, it is only possible to change full-screen VDMs to
;               windowed, and vice versa.
;
; Notes:
;       Dependencies:   None
;
;       Restrictions:   Only the Shell can call this procedure.
;
;       Change History:
;      @@A2 - 02/15/89 PTR B788085 - Give foreground priority to VDM
;                                    made windowed from fullscreen.
;      @CJ10  05/04/90 PTR B712103 Hot Keying performance too slow.
;      @D1088 07/07/90 DCR 1088 Add support for special needs.
;      @D1180 08/14/90 DCR 1180 Delete SG_Type_Change_Notification.
;
; Entry Point:
;       Linkage:  EXTRN DOSSMSETSESSIONTYPE : FAR
;                       PUSH    WORD   SessionID  ; Session Number
;                       PUSH    WORD   SessType   ; New type
;                       CALL    DOSSMSETSESSIONTYPE
; Inputs:
;       WORD    SessionID  Session Number
;       WORD    SessType   New Session Type
;                          4 = VDM Session
;                          7 = Windowed VDM Session
;
; Exit Normal:
;       AX      ReturnCode Value = 0, change successful
;
; Exit Errors:
;       AX      ReturnCode error_smg_invalid_program_type
;                          error_smg_not_baseshell
;                          error_smg_session_not_found
;
; Effects:      All other registers preserved.
;
; Internal References:
;          Data:        SDATA
;
;          Routines:    GETSMGETSGQUEUE
;
; External References:
;          Routines:    DOSSEMREQUEST
;                       DOSSEMCLEAR
;
;************************************************************************

.386C

    EXTRN DOSSEMCLEAR      : FAR        ; Release semaphore ownership
    EXTRN DOSSEMREQUEST    : FAR        ; Synchronize Shell/App. calls
    EXTRN DOSSMGETSGCB     : FAR
    EXTRN DOSSMBASESHELL   : NEAR       ; Verify Base Shell calling
    EXTRN DOSSETFGND       : FAR
.xlist
    INCLUDE ERROR2.INC                  ; Error code equates
    INCLUDE STRUC.INC
    INCLUDE SMRSGCB.INC
    INCLUDE SMRRDATA.INC
.list

SMSStack STRUC
SMSOldbp DW 0                           ; Callers BP register
SMSOldret DW 2 DUP(?)                   ; Callers return address
SMSType DW 0                            ; Type
SMSSessionID DW 0                       ; Session ID
SMSStack ENDS


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

    PUBLIC DOSSMSETSESSIONTYPE
DOSSMSETSESSIONTYPE PROC FAR

    Local_Bytes EQU 4
    Local_Var1 EQU SS:[BP][-2]          ; Local variable on stack
    Local_Var2 EQU SS:[BP][-4]          ; Local variable on stack

    ENTER Local_Bytes,0

    PUSHA                               ; Save registers
    PUSH DS
    PUSH ES
    PUSH GS                             ; DosSMBaseShell destroys GS    ;CJ10

    MOV  AX, RDATA                      ; Addressability to global data
    MOV  DS, AX

;   *****************************************
;   *  Verify the caller is the Base Shell  *
;   *****************************************
    CALL DOSSMBASESHELL

    .IF  < zero AX >                                                    ;@CJ10
      MOV  BX, SS:[BP].SMSType          ; New type
      MOV  DX, SS:[BP].SMSSessionID     ; Screen group ID

      .IF  < BX e VDM_Type > OR         ; Verify new type is valid
      .IF  < BX e Windowed_VDM_Type >

;       ***********************************
;       *  Get SGCB of Session to change  *
;       ***********************************
        LEA  DI, Local_Var2             ; @ return @ of SGCB
        PUSH SS
        PUSH DI
        PUSH DX                         ; SGID
        PUSH SGID_Lookup                ; Look up SGID not PID
        CALL DOSSMGETSGCB

        .IF  < zero AX >                ; If we found the SGCB          ;@CJ10
          LES  DI, Local_Var2           ; ES:[DI] --> SGCB

;         ********************************************
;         *  Make sure we're changing a VDM session  *
;         ********************************************
          .IF  < ES:[DI].SGCB_Type eq VDM_Type > OR
          .IF  < ES:[DI].SGCB_Type eq Windowed_VDM_Type >
;@D1180;;;;;MOV  AX, ES:[DI].SGCB_ID    ; Get SGID for DosSMNotifyDD call
;@D1180;;;;;MOV  CX, ES:[DI].SGCB_Type  ; save type for DosSMNotifyDD   ;@D1088
            MOV  ES:[DI].SGCB_Type, BX  ; Move in the new Session Type
            MOV  BYTE PTR ES:[DI].SGCB_ID[1], BL ; Change type in SGID too!

            .IF < BL e Windowed_VDM_Type >  ;                            @@A2
;             **************************************                     @@A2
;             * Give this SG foreground priority   *                     @@A2
;             **************************************                     @@A2
              XOR  DH, DH               ; Low byte only                  @@A2
              PUSH 3                    ; Boost SG priority              @@A2
              PUSH DX                   ;                                @@A2
              CALL DOSSETFGND           ;                                @@A2
            .ENDIF                      ;                                @@A2

;           **********************************
;           *  Let Device Drivers know that  *
;           *  this SG has changed types.    *
;           **********************************
;@D1180;;;;;MOV  NotDD_DosDev_Data_Len, Session_2_0_Len     ;data length ;@D1088
;@D1180;;;;;MOV  NotDD_Notification_Type, SG_Type_Change_Notification    ;@D1088
;@D1180;;;;;XOR  AH, AH                 ; Zero out type byte for Old SG  ;@D1088,VR11
;@D1180;;;;;MOV  NotDD_OutSG,AX                                          ;@D1088
;@D1180;;;;;MOV  NotDD_OutType, CX          ; Old SG type                ;@D1088
;@D1180;;;;;MOV  AX, ES:[DI].SGCB_ID        ; New SG                     ;@D1088
;@D1180;;;;;XOR  AH, AH                     ; Zero out type byte         ;@D1088,VR11
;@D1180;;;;;MOV  NotDD_InSG_or_OutType, AX                               ;@D1088
;@D1180;;;;;MOV  AX, ES:[DI].SGCB_Type      ; New SG type                ;@D1088
;@D1180;;;;;MOV  NotDD_InType_or_OutSG, AX                               ;@D1088
;@D1180;;;;;PUSH DS                         ;Address of NotifyDD data    ;@D1088
;@D1180;;;;;PUSH OFFSET NotDD_DosDev_Data_Len                            ;@D1088
;@D1180;;;;;CALL DOSSMNOTIFYDD
            XOR  AX, AX                 ; Set no error return code       ;@D1180

          .ELSE                         ; Trying to change a non VDM session
            MOV  AX, Error_SMG_Invalid_Program_Type
          .ENDIF                        ; Session Type check

        .ENDIF                          ; Error check from DosSMGetSGCB
      .ELSE
        MOV  AX, Error_SMG_Invalid_Program_Type
      .ENDIF
    .ENDIF                              ; Base Shell Calling test

    MOV  AX_Reg[-Local_Bytes], AX       ; Place return code on the stack
    POP  GS                                                             ;CJ10
    POP  ES                             ; Restore registers
    POP  DS
    POPA
    LEAVE

    RET  4
DOSSMSETSESSIONTYPE ENDP


ifdef NEEDED_FOR_DCR_529

;************************************************************************
;
; Source File Name:     SMRSMSET.ASM
;
; Subroutine Name:      DOSSMQUERYSESSIONTYPE
;
; Descriptive Name:     Query Session Type
;
; Function:     Query the specified session's current type.  Note that for
;               VDMs, this may vary from the type selected when the session
;               was started.
;
; Notes:
;       Dependencies:   None
;
;       Restrictions:   Only the Shell can call this procedure.
;
;       Change History:
;
; Entry Point:
;       Linkage:  EXTRN DOSSMQUERYSESSIONTYPE : FAR
;                       PUSH    WORD   SessionID  ; Session Number
;                       PUSH   @WORD   SessType   ; Current type
;                       CALL    DOSSMQUERYSESSIONTYPE
; Inputs:
;       WORD    SessionID  Session Number
;      @WORD    SessType   Far pointer to word, to contain one of:
;                          1 = Full screen session
;                          2 = Windowed VIO session
;                          3 = Presentation Manger specific session
;                          4 = VDM Session
;                          7 = Windowed VDM Session
;
; Exit Normal:
;       AX      ReturnCode Value = 0, change successful
;
; Exit Errors:
;       AX      ReturnCode error_scs_not_session_mgr
;                          error_smg_bad_statusreq
;                          error_smg_not_baseshell
;                          error_smg_session_not_found
;
; Effects:      All other registers preserved.
;
; Internal References:
;          Data:        RDATA
;
;          Routines:    GETSMGETSGQUEUE
;
; External References:
;          Routines:    DOSSEMREQUEST
;                       DOSSEMCLEAR
;
;************************************************************************


SMQStack STRUC
SMQOldbp DW 0                           ; Callers BP register
SMQOldret DW 2 DUP(?)                   ; Callers return address
SMQType DD 0                            ; @Type
SMQSessionID DW 0                       ; Session ID
SMQStack ENDS


    PUBLIC DOSSMQUERYSESSIONTYPE
DOSSMQUERYSESSIONTYPE PROC FAR
    ENTER 0,0

;   PUSHA                               ; Save registers                ;CJ10
    PUSH BX                                                             ;CJ10
    PUSH DI                                                             ;CJ10
    PUSH DS
    PUSH GS                             ; DosSMBaseShell destroys GS    ;CJ10

    MOV  AX, RDATA                      ; Addressability to global data
    MOV  DS, AX

;   *****************************************
;   *  Verify the caller is the Base Shell  *
;   *****************************************
    CALL DOSSMBASESHELL

    .IF  < zero AX >                                                    ;@CJ10
;     ***********************************
;     *  Get SGCB of Session to change  *
;     ***********************************
      LEA  DI, Local_Var2               ; @ return @ of SGCB
      PUSH SS
      PUSH DI
      PUSH SS:[BP].SMQSessionID         ; SGID
      PUSH SGID_Lookup                  ; Look up SGID not PID
      CALL DOSSMGETSGCB

      .IF  < zero AX >                  ; If we found the SGCB          ;@CJ10
        LDS  DI, Local_Var2             ; DS:[DI] --> SGCB
        MOV  BX, DS:[DI].SGCB_Type                                      ;CJ10

        LDS  DI, SS:[BP].SMQType                                        ;CJ10
        MOV  DS:[DI], BX                ; Return current setting        ;CJ10
      .ENDIF                            ; DosSMGetSGCB error test
    .ENDIF                              ; DosBaseShell test

;   MOV  AX_Reg[-Local_Bytes], AX       ; Place return code on the stack;CJ10
    POP  GS                             ; Restore registers             ;CJ10
    POP  DS
    POP  DI                                                             ;CJ10
    POP  BX                                                             ;CJ10
;   POPA                                                                ;CJ10
    LEAVE

    RET  6
DOSSMQUERYSESSIONTYPE ENDP

endif                                   ; NEEDED_FOR_DCR_529


CODE ENDS

    END
