;       SCCSID = @(#)bksgetcp.asm	6.1 90/11/16
;       SCCSID = @(#)bksgetcp.asm	6.5 90/02/14
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
        PAGE    60,132
        TITLE   BKSGETCP.ASM - Get Current Codepage

;******************************************************************************
;*******   C H A N G E       H I S T O R Y   **********************************
;
;       86/12/01  TPL   Return ERROR_KBD_PARAMETER when reserved DWord are
;                       not zeroes.
;       87/01/13  TPL   Get In-use codepage IOCTL trashes the first word
;                       of the DBCS ranges.  Use local storage (Shift_State)
;                       to hold the codepage ID instead of (CP_ID).
;@T52   90/01/15  TPL   DCR 704 work
;******************************************************************************

        .286p                           ; 286 Protect Mode instructions

        .xlist
        INCLUDE error2.inc              ; Extended error code file
        INCLUDE struc.inc               ; Structured Macros
        INCLUDE bksxxx.inc              ; Equates and structure template file
        INCLUDE bksextrn.inc            ; External data declaration file
        .list

CSEG    SEGMENT BYTE PUBLIC 'CODE'
CSEG    ENDS

IDSEG   SEGMENT BYTE PUBLIC 'DATA'      ; Per process instance data segment
IDSEG   ENDS
;
;       System services routine name(s)
;
        EXTRN   DOSDEVIOCTL:FAR         ; Get in use codepage ID

;$$#I000
        EXTRN   WINCONSOLEGETCP:DWORD   ;CDB2
        GDSEG   SEGMENT BYTE PUBLIC 'FAR_DATA'                          ;@T52
        GDSEG   ENDS
;$$#END

        PUBLIC  GetCodepage

CSEG    SEGMENT BYTE PUBLIC 'CODE'
        ASSUME  CS:CSEG,DS:NOTHING,ES:NOTHING
        PAGE

;********************START OF SPECIFICATIONS****************************
;
; SUBROUTINE NAME:      GetCodepage
;
; DESCRIPTIVE NAME:     Get Current Keyboard Codepage
;
; FUNCTION:     Return, to the caller, the current active code page.
;
; ENTRY POINT:          GetCodePage
;
;    LINKAGE:           Near Call
;
; INPUT PARAMETERS
;    SYMBOLIC NAME:     KBD_Handle
;
;    DESCRIPTION:       Keyboard Handle
;
;    TYPE:              Word (on stack)
;
;    USAGE:             Keyboard device handle
;
;    SYMBOLIC NAME:     CodePageAdr
;
;    DESCRIPTION:       Address of Translation Table ID
;
;    TYPE:              Selector-Offset (on stack) pointing to
;                       a word
;
;    USAGE:             Translation table index
;
; EXIT-NORMAL:          AX  =   0
;
; EXIT-ERROR:           AX  =   None
;
; INTERNAL REFERENCES:  IDSEG - Per process instance data segment
;          ROUTINES:    none
;
; EXTERNAL REFERENCES:  none
;          ROUTINES:    DOSDEVIOCTL - Get in use codepage ID
;
;******************END OF SPECIFICATIONS********************************
;
;
;GetCodepage PROC  NEAR
;
; CALLFAR DOSDEVIOCTL                   ; Get in use codepage ID
;.IF <No Error>
;| SS:[bp].CodePageID = DS:XlateCP      ; Return codepage ID to caller
;.ENDIF
; ret
;
;GetCodepage ENDP
        PAGE



GetCodepage PROC NEAR                   ; @@ Version 1.1 code - BEGIN
        ASSUME  DS:IDSEG
;
;************************************************************************
;*  On entry:  DS = IDSEG   AX = 0                                      *
;*             ES = GDSEG   DX = KBD_SG                                 *
;************************************************************************
;
;
;       int     3
;
        mov     ax,[bp].GetCP_ReservedH ; Get reserved Hi-word
        or      ax,[bp].GetCP_ReservedL
       .IF Z                            ; Valid reserved DWord?
         .IF <dx be LastBaseSG>         ;@@DTF
         test   Flag,CUSTOM_ON          ; Custom codepage in effect?
        .IF NZ
;@@DTF - Begin
;$$#R001
;
;         mov   bx,Previous_CP          ; Return previous codepage ID
;$$#REND
;        .IF <dx A LastBaseSG>          ; Winthorn screen group?
;             push    es:hConsole
;             push    [bp].KBD_Handle
;             push    ds
;             push    offset Shield_Scratch
;             Call    WINCONSOLEGETCP
;             mov     bx,Shield_Scratch
;        .ELSE
              mov     bx,Previous_CP  ; Return previous codepage ID
;        .ENDIF
;@@DTF - End
;$$#END
;$$#I002
;

;$$#END
;
        .ELSE
          push  ax                      ; Setup:  Address of dummy DATA
          push  ax                      ;           Parmlist
          push  ds                      ;         Address of INPUT Parmlist
          push  OFFSET Shift_State      ;           (codepage ID)
          push  78H                     ;         Category code
          push  KEYBOARD                ;         Function code
          push  Dev_Handle              ;         Device Handle
          call  DOSDEVIOCTL             ; Get in-use codepage ID
          mov   bx,Shift_State          ; Get codepage ID
        .ENDIF
;@@DTF - Begin
;      .ELSE
;        mov    ax,ERROR_KBD_PARAMETER
;      .ENDIF
       .ELSE
         push    hConsole               ;@@DTF1
         push    [bp].KBD_Handle
         push    ds
         push    offset Shield_Scratch
         Call    ES:WINCONSOLEGETCP    ;CDB2
         mov     bx,Shield_Scratch
       .ENDIF
       .ELSE
         mov    ax,ERROR_KBD_PARAMETER
       .ENDIF
;@@DTF - End
        or      ax,ax                   ;
       .IF Z                            ; No error encountered?
         les    di,[bp].CodePageAdr     ;
         mov    WORD PTR es:[di],bx     ; Return codepage ID to caller
       .ENDIF
        ret

GetCodepage ENDP                        ; @@ Version 1.1 code - END

CSEG    ENDS
        END
