;       SCCSID = @(#)d_setcp.asm	6.1 91/02/15
;	SCCSID = @(#)d_setcp.asm	1.4 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;
;	04-May-87 (robertc): Install hooks for DOSErrorClass Support.
;	All int 21h errors are passed through api_get_extended to get the
;	extended errorcode and to provide the class, action, and locus for
;	the dynamic error FIFO queue.
;
; @@	8-May-87 (Tarng): Check reserved dword are zeros.
;
;/*************** START OF SPECIFICATIONS ******************************/
;/*								       */
;/* SUBROUTINE NAME: DosSetCP					       */
;/*								       */
;/* SOURCE FILE NAME: D_SETCP.ASM				       */
;/*								       */
;/* DESCRIPTIVE NAME: Dos Set Code Page				       */
;/*								       */
;/* FUNCTION:  Set the code page				       */
;/*								       */
;/* NOTES:  @@ DosSetCP is a new routine to the 1.10 Family API	       */
;/*	    Library.						       */
;/*								       */
;/* ENTRY POINT:						       */
;/*	    LINKAGE:  EXTRN DosSetCP:FAR			       */
;/*								       */
;/* INPUT:	      PUSH	WORD	CodePage  ;Code Page identifier*/
;/*		      PUSH	WORD	Reserved  ;Reserved, set to 0  */
;/*		      call  DosSetCP				       */
;/*								       */
;/*								       */
;/* EXIT-NORMAL:  AX = 0					       */
;/*								       */
;/* EXIT-ERROR:	 AX = Error Code				       */
;/*								       */
;/*    ReturnCode Value = 1, Error_invalid_function		       */
;/*			  ?, Error_invalid_code_page		       */
;/*								       */
;/* EFFECTS:  BP and ES registers are saved.			       */
;/*								       */
;/* PSUEDO CODE:						       */
;/*								       */
;/*	save registers						       */
;/*								       */
;/*	get DOS version						       */
;/*								       */
;/*	If version < 3.30					       */
;/*	    then AX=invalid DOS version and goto DosSetCPExit	       */
;/*								       */
;/*	use BP as pointer to stack parameters			       */
;/*								       */
;/*	load registers for int 21 call				       */
;/*	  bx=codepage						       */
;/*								       */
;/*	execute int 21 with function 6602H			       */
;/*								       */
;/*	if carry flag set					       */
;/*	    then AX=Error code and goto DosGetCPExit		       */
;/*								       */
;/*	AX=0							       */
;/*								       */
;/*DosSetCPExit:						       */
;/*								       */
;/*	restore registers					       */
;/*								       */
;/*	return clearing stack frame				       */
;/*								       */
;/*								       */
;/* INTERNAL REFERENCES:					       */
;/*    ROUTINES:						       */
;/*								       */
;/* EXTERNAL REFERENCES:					       */
;/*    ROUTINES:    INT 21H FUNCTION 6602H    SET CODE PAGE	       */
;/*		    INT 21H FUNCTION 3000H    GET DOS VERSION	       */
;/*								       */
;/*************** END OF SPECIFICATIONS ********************************/
;
;
; LIBRARIES
;
.XLIST
include error2.inc
include error.inc

	EXTRN	api_get_extended:far	;@@ added support for DOSErrorClass
	EXTRN	__api_begin:near	;@@
	EXTRN	__api_end:near		;@@
	EXTRN	_api_getvrsn:near	;@@
.LIST
;
; PUBLIC SYMBOLS
;
	PUBLIC	DosSetCP

	PAGE

_TEXT	segment byte public 'CODE'
	assume	CS:_TEXT,DS:NOTHING
;
; stack frame:
; +0	bp
; +2	ip
; +4	cs
; +6	reserved
; +8	codepage
;
str	struc
old_bp		dw	?
return		dd	?
reserved	dw	?
codepage	dw	?
str	ends
;
DosSetCP	PROC	FAR

	call	__api_begin	; init bp and save bp,ds,bx,cx,dx,si,di,es
				; required to save: bp,es,ds,di,si
;
; Check DOS version to make sure PC DOS 3.30 or higher
;
		call	_api_getvrsn		; AH <- major, AL <- minor
		cmp	ax,031Eh		; if version >= 3.30
		jae	valid_version		; if yes then valid version
		jmp	short DOS_version_error ; else return invalid function
;
valid_version:
; check validity of reserved words
	mov	ax,ERROR_INVALID_PARAMETER	;@@
	mov	bx, [bp].Reserved		;@@ reserved words not zeros
	or	bx,bx				;@@
	jnz	DosSetCPexit			;@@ then return error

;
; Now set up set global code page interrupt
;
		mov	bx,[bp].codepage	; Put code page in bx
		mov	ax,6602H		; Set global code page
		int	21h
		jc	DosSetCPErr		; Exit if error
		xor	ax,ax			; No errors returned
		jmp	short DosSetCPexit
Dos_version_error:
		mov	ax,error_invalid_function ; Return invalid function

	jmp	short DosSetCPexit	;@@ Added support for DOSErrorClass
DosSetCPerr:				;@@ added support for DOSErrorClass
	call	api_get_extended	;@@ added support for DOSErrorClass

DosSetCPexit:
	call	__api_end	; check sigs & restore es,di,si,dx,cx,bx,ds,bp
		ret	size str - 6		; Clear stack frame
DosSetCP	ENDP
_TEXT	ends
		END
