;       SCCSID = @(#)sswsgfnd.asm       6.1 90/11/18
;      SCCSID = @(#)sswsgfnd.asm        6.3 90/03/19

; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

;********************** START OF SPECIFICATIONS ***********************/
;                                                                     */
; SUBROUTINE NAME:  SSWSGFND                                          */
;                                                                     */
; DESCRIPTIVE NAME:  Screen Switcher's routine to search the memory   */
;                    mapping table for a particular screen group#.    */
;                                                                     */
; FUNCTION: This is an internally called procedure which looks for    */
;           an occurrence of a sg# which is passed in via the BX      */
;           register. This routine is called by the DosSGSave and     */
;           DosSGRestore routines, as well as the DosScrnLock,        */
;           DosSaveRedrawWait, DosSaveRedrawUndo, DosSaveModeWait,    */
;           DosSaveModeUndo routines. A pointer to the sgcb is        */
;           returned in DI register.                                  */
;                                                                     */
; NOTES:  Executes on Level 3                                         */
;                                                                     */
; ENTRY POINT:  SSCBSetup                                             */
;   LINKAGE:                                                          */
;                                                                     */
; INPUT: DS points to common data segment. BX register must contain   */
;        the sg# being sought.                                        */
;                                                                     */
; EXIT-NORMAL:  DI = pointer to sgcb being sought. AX = no_error (0)  */
;               if a match was found and AX = error_scs_sg_notfound   */
;               if no sg# match was found.                            */
;                                                                     */
; EXIT-ERROR:   None                                                  */
;                                                                     */
; EFFECTS:  AX and DI registers must be assumed to have been changed. */
;                                                                     */
; INTERNAL REFERENCES:                                                */
;   ROUTINES:  None                                                   */
;                                                                     */
; EXTERNAL REFERENCES:                                                */
;   ROUTINES:  None                                                   */
;                                                                     */
;       Change History:                                               */
;                                                                     */
;       @TL6 - 03/01/90 - DCR 704 - Merge SMG/SSW instance data into  */
;                         OS2CHAR                                     */
;       MDLL   01/10/94   BJN Page Tune segments for Merged DLL.      */
;                                                                     */
;*********************** END OF SPECIFICATIONS ************************/

EXTRN memory_pool:byte

.xlist
INCLUDE SSWINC.INC
.list

.386p

CODE_TUNE4    SEGMENT WORD PUBLIC 'CODE' USE16                          ;MDLL

        ASSUME  CS:CODE_TUNE4, DS:NOTHING,SS:NOTHING,ES:NOTHING         ;MDLL

               PUBLIC  SSFINDSG

SSFINDSG       PROC    NEAR                         ; Enter with sought_
                                                    ; for sg# in BX

 push    dx
 push    cx
 push    bx

 mov     di,offset memory_pool                      ; Look at mem table to
 mov     dx,eot                                     ; find available space
 mov     cx,null                                    ; for our sgcb
 sub     ax,ax                                                          ;@TL6

 .WHILE <[di] e dx> OR                              ; If we are at eot or
 .WHILE <[di+3] ne bx> OR                           ; if not sg# or if
 .WHILE <[di+5] ne cx>                              ; #pids not null search
  .IF <[di] e dx>                                   ; Have we reached the
   .IF <[di+2] ne cx>                               ; end-of-table?
    mov     di,[di+2]                               ; If so, and if the
   .ELSE                                            ; ptr_nxt_table is
    mov     ax,null                                 ; valid, follow the
    .LEAVE SHORT                                    ; chain - or leave with
   .ENDIF                                           ; insufficient memory
  .ELSE                                             ; If not eot
   add     di,18                                    ; Go to next full block
  .ENDIF
 .ENDWHILE

 .IF <zero ax>                                      ; A match was found ;@TL6
   mov     di,[di+7]                                ; Store the pointer
 .ELSE                                              ; to the sgcb in DI
   mov     ax,error_scs_sg_notfound
 .ENDIF

 pop     bx
 pop     cx
 pop     dx

 ret

SSFINDSG       ENDP
CODE_TUNE4  ENDS                                                        ;MDLL
               END
