;       SCCSID = @(#)dbcs.inc	6.1 90/11/17
;      SCCSID = @(#)dbcs.inc	13.8 89/11/27

;	IBM/Microsoft Confidential
;
;	Copyright (c) IBM Corporation 1987, 1989
;	Copyright (c) Microsoft Corporation 1987, 1989
;
;	All Rights Reserved

; NOTE: this file should be INCLUDEd AFTER tkptda.inc !!!
;
;*  Generate externs if	necessary

IF2
IFNDEF CharType
	ReferGlobal	CharType
ENDIF
IFNDEF CharTypeHIGH2
	HIGH2CODE   SEGMENT
	EXTRN		CharTypeHIGH2:BYTE
	HIGH2CODE   ENDS
ENDIF
ENDIF

	EXTRNFAR	TestDBCSLOW

ifndef	 TKOPTDA
	ReferTask	CP_Flgs,BYTE,ifundef
endif

BREAK <DBCS testing macros - test for DBCS activity and lead bytes>      
;*** 	TestDBCS
;***	TestDBCSProcess
;***	TestDBCSLeadByte
;
;	TestDBCSProcess - Determine if the current process is DBCS-active.
;			(fCP_DBCS flag of CP_Flgs clear = DBCS-active.)
;
;		ENTRY: <none>
;		
;		EXIT : Zero set   (ZR) - process is DBCS-active
;		       Zero clear (NZ) - process is not DBCS-active
;
;		USES : <none>
;
;
;	TestDBCSLeadByte- Determine if a character is a valid DBCS lead
;			byte, when it is known BEFOREHAND that a process
;			is DBCS-active.  Will generate inline code if used
;			in High2Code or a call to TestDBCSLOW otherwise.
;			(fDBCS bit in CharType array clear = DBCS lead byte.)
;
;	TestDBCS        - same as TestDBCSLeadByte, but with a preceeding check
;			to see whether the current process is DBCS-active.
;			Use when you need to check a character but do not know
;			whether the process is DBCS-active.  The <nz_target>
;			is provided to skip around the character check should
;			the process turn out to be DBCS-inactive.
;
;	--info for both TestDBCS and TestDBCSLeadByte--
;
;		ENTRY: (AL) = byte from character string
;
;		EXIT : Zero set   (ZR) - char is lead byte of DBCS char
;		       Zero clear (NZ) - char is not lead byte of DBCS char
;
;		USES : all but low 8 bits of ax or eax (as appropriate
;			to invokation).
;


TestDBCSProcess		MACRO
IFNDEF TKOPTDA
	IF (?cstype EQ ?CS_32bit)		; account for ASSUMEs
	test	byte ptr ss:[CP_Flgs],fCP_DBCS
	ELSE
	test	byte ptr TASKAREA:[CP_Flgs],fCP_DBCS
	ENDIF
ELSE
	test	byte ptr ss:[TKOPTDA.CP_Flgs],fCP_DBCS
ENDIF
ENDM


TestDBCSLeadByte	MACRO
IF (?cstype EQ ?CS_32bit)
	and	eax,0ffh
	test	byte ptr FLAT:[eax].CharType,fDBCS
ELSE
	IF  (?farcode EQ SN_DosHigh2Code)
		MOV	AH,0			; (AX) = index into CharType
		XCHG	AX,BX			; (BX) = index into CharType
		TEST	BYTE PTR CS:CharTypeHIGH2[BX],fDBCS
		XCHG	BX,AX			; Restore (AX),(BX) contents
	ELSE
		?GenCall TestDBCSLOW, SN_DosCode
	ENDIF
ENDIF
ENDM

TestDBCS    MACRO  nz_target
local	a
    TestDBCSProcess		; DBCS active for this process?
    IFB <nz_target>
	jnz	a			; no, fall through with NZ
    ELSE
	jnz	nz_target		; no, branch to given target
    ENDIF
    TestDBCSLeadByte
a:
ENDM
