;       SCCSID = @(#)smgstitl.asm	6.1 90/11/18
;	SCCSID @(#)smgstitl.asm	6.7 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:	SMGSTITL.ASM
;
; Subroutine Name:	DOSSMSGSETTITLE
;
; Descriptive Name:	Set screen group title
;
; Function:	Calls the Shell dynamic link procedure to change
;		the sessions title. If the title is changed
;		successfully and the Shell is the foreground
;		session, notify the Shell to redraw the switch
;		list.
;
; Notes:
;	Dependencies:	None
;
;	Restrictions:	Screen group titles must be contiguous. This
;			subroutine calculates the offset of the title
;			based on the screen group number.
;
;     Change History:
;	@TL7 - 04/05/90 - PTR B712376 - Enable for MMIO
;	@MHW - 09/13/90 - PTR B715818 - Removed MMIO support
;
; Entry Point:
;	Linkage:  EXTRN DOSSMSGSETTITLE:FAR
;			PUSH@	ASCIIZ PgmTitle	  ; Screen Group Title
;			CALL	DOSSMSGSETTITLE
;
; Inputs:
;	ASCIIZ	PgmTitle   Address of new screen group title
;
; Exit Normal:
;	AX	ReturnCode Value = 0, screen group title returned
;
; Exit Errors:
;	AX	ReturnCode error_smg_set_title
;			   error_smg_invalid_session_id
;
;			   DOSGETSHRSEG errors
;
; Effects:	All other registers preserved.
;
; Internal References:
;	   Data:	SGCB_Titlelen - queue title element length
;
;			The following data is in a shared data segment(SDATA)
;
;			sgtitlename    ASCIIZ string '\SHAREMEM\SMG\SGTITLE'
;
;	   Routines:
;
; External References:
;	   Data:	localinfoseg   Selector in global data segment
;				       LIS_CurScrnGrp
;	   Routines:	DOSGETSHRSEG
;			DOSFREESEG
;			DOSSEMCLEAR
;
;**************************************************************************
ifdef I1
;
;   IF (totalscrngrps ne 0) AND
;   IF (Valid sgid)
;      DOSGETSHRSEG (Get seg selector for active sg titles)
;      IF (No_Error)
;	  Calculate offset to sg title
;
;	  IF (Title length e 0)
;	     Bump past title length
;	     Get address of new title
;	     Copy screen group title
;	     DOSSEMCLEAR (Clear title semaphore)
;	  ELSE
;	     RC = Error_SMG_Set_Title
;	  ENDIF
;
;	  DOSFREESEG (Decrement shared segment access count)
;      ENDIF
;   ELSE
;      RC = Error_SMG_Invalid_Session_ID
;   ENDIF
;**************************************************************************
else
.386C
    EXTRN SGTitleName	 : BYTE		; SG shared segment name
    EXTRN LocalSelector	 : WORD		; Local info segment selector
    EXTRN TotalScrnGrps	 : WORD		; Maximum screen groups
    EXTRN STitleRamSem	 : DWORD	; Title change semaphore

    EXTRN DOSGETSHRSEG	 : FAR		; Get shared segment selector
    EXTRN DOSFREESEG	 : FAR		; Free shared segment selector
    EXTRN DOSSEMCLEAR	 : FAR		; Notify Shell of title chg
.xlist
    INCLUDE INFOSEG.INC
    INCLUDE SMRSGCB.INC
    INCLUDE SMRRDATA.INC
    INCLUDE SMGSTITL.INC
.xcref
    INCLUDE ERROR2.INC
    INCLUDE STRUC.INC
.cref
.list

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

    PUBLIC DOSSMSGSETTITLE
DOSSMSGSETTITLE PROC FAR

    Local_Bytes	 EQU  0

    ENTER Local_Bytes,0
    PUSHA				; Save registers
    PUSH DS
    PUSH ES
    PUSH FS
    PUSH GS

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

    MOV	 ES, DS:LocalSelector		; Get local information selector

;   ************************
;   *  Valid screen group  *
;   ************************
    MOV	 DX, DS:TotalScrnGrps		; Maximum screen group
    .IF	 <nonzero DX > AND		; Been initialized?		;CJ10
    .IF	 <ES:LIS_CurScrnGrp b DX>	; Valid screen group

;     *********************************************************
;     *	 Get segment selector for active screen group titles  *
;     *********************************************************
      PUSH AX				; Reserve word on the stack
      MOV  DX, SP
      PUSH DS				; Segment Name (\SHARMEM\SMG\SMGTITLE)
      PUSH OFFSET SGTitleName
      PUSH SS				; Address of word on the stack
      PUSH DX
      CALL DOSGETSHRSEG
      POP  DI				; Shared segment selector

;     *********************************************************************
;     *	 Copy new title to shared title segment if not set by Base Shell  *
;     *********************************************************************
      .IF  < zero AX >							;CJ10
	MOV  AX, ES:LIS_CurScrnGrp	; Get current SG
	MOV  BX, SGCB_Titlelen		; Calculate offset to SG title
	MUL  BL
	MOV  ES, DI
	MOV  DI, AX
	.IF  <<ES:BYTE PTR [DI]> eq 0>	; Title length is 0
	  INC  DI			; Bump past title length
	  PUSH DI			; Save title offset
	  LDS  SI, SS:[BP].SetTlSGTitle ; Addr. of new title
	  CLD
	  MOV  CX, SGCB_Titlelen-2	; Maximum title length

	  .REPEAT			; Copy screen group title
	    LODSB
	  .LEAVE <AL eq 0>
	    STOSB
	  .LOOP

	  SUB  AX, AX			; Successful return code	;CJ10
	  STOSB
	  POP  DI			; Restore title offset

	  PUSH AX			; Save return code
	  PUSH RDATA			; Notify shell of change
	  PUSH OFFSET STitleRamSem
	  CALL DOSSEMCLEAR
	  POP  AX			; Restore return code

	.ELSE
	  MOV  AX, Error_SMG_Set_Title	; Can't change title
	.ENDIF

	PUSH AX				; Save return code
	PUSH ES				; Selector returned by DOSGETSHRSEG
	CALL DOSFREESEG			; Decrement segment access count
	POP  AX				; Restore return code
      .ENDIF
    .ELSE				; Invalid screen group
      MOV  AX, Error_SMG_Invalid_Session_ID
    .ENDIF

    MOV	 AX_Reg, AX			; Place return code on the stack

    POP	 GS				; Restore registers
    POP	 FS
    POP	 ES
    POP	 DS
    POPA

    LEAVE
    RET	 4

DOSSMSGSETTITLE ENDP

CODE ENDS
endif
    END
