; Remove the comment below if using MASM 6.0 or later

;OPTION NOKEYWORD:<EXTERN .IF>

	; 	BEGINNING OF MICROSOFT CODE

.$$RESET_DS = 0
.$$CHECK_STACK = ._NO
.$$USE_286_INSTRUCTION_SET = ._NO;
.$$ALWAYS_SET_NEW_STACK_FRAME = ._NO

.$$SAVE_SI = .$RSI;
.$$SAVE_DI = .$RDI;
.$$SAVE_ES = 0

.$$LATTICE_LONG = ._NO;
.$$FCN_BASE = 8800H 			; .xC_ARGS + .xLABEL
.$$UNDERSCORE = ._LEADING;

.$$DISPLAY_COMPILER_AND_MEMORY_MODEL MACRO
	%OUT
	%OUT COMPILER ***** MICROSOFT C VERSION 3.0/4.0 ******
	IF (.$MEMORY_MODEL EQ ._SMALL_MODEL)
		%OUT MEMORY MODEL       ***** SMALL *****
		ENDIF
	IF (.$MEMORY_MODEL EQ ._MEDIUM_MODEL)
		%OUT MEMORY MODEL  ***** MEDIUM *****
		ENDIF
	IF (.$MEMORY_MODEL EQ ._COMPACT_MODEL)
		%OUT MEMORY MODEL  ***** COMPACT *****
		ENDIF
	IF (.$MEMORY_MODEL EQ ._LARGE_MODEL)
		%OUT MEMORY MODEL  ***** LARGE *****
		ENDIF
	
	ENDM

.$$SET_MEM_MODEL MACRO
			
	IF (.$MEMORY_MODEL EQ ._SMALL_MODEL)
		.$$CODE_SIZE = ._SMALL_CODE;
		.$$DATA_SIZE = ._SMALL_DATA;
		CODE_PTR = ._SMALL_CODE_PTR;
		DATA_PTR = ._SMALL_DATA_PTR;
		.$$DFLT_DATA_ATTR = 0
		.$$DFLT_CODE_ATTR = .$$FCN_BASE
		EXITM
		ENDIF
		
	IF (.$MEMORY_MODEL EQ ._MEDIUM_MODEL)
		.$$CODE_SIZE = ._LARGE_CODE;
		.$$DATA_SIZE = ._SMALL_DATA;
		CODE_PTR = ._LARGE_CODE_PTR;
		DATA_PTR = ._SMALL_DATA_PTR;
		.$$DFLT_DATA_ATTR = 0
		.$$DFLT_CODE_ATTR = .xFAR + .$$FCN_BASE
		EXITM
		ENDIF
	
	IF (.$MEMORY_MODEL EQ ._COMPACT_MODEL)
		.$$CODE_SIZE = ._SMALL_CODE;
		.$$DATA_SIZE = ._LARGE_DATA;
		CODE_PTR = ._SMALL_CODE_PTR;
		DATA_PTR = ._LARGE_DATA_PTR;
		.$$DFLT_DATA_ATTR = .xFAR
		.$$DFLT_CODE_ATTR = .$$FCN_BASE
		EXITM
		ENDIF
	
	IF ((.$MEMORY_MODEL EQ ._LARGE_MODEL) OR (.$MEMORY_MODEL EQ ._HUGE_MODEL))
		.$$CODE_SIZE = ._LARGE_CODE;
		.$$DATA_SIZE = ._LARGE_DATA;
		CODE_PTR = ._LARGE_CODE_PTR;
		DATA_PTR = ._LARGE_DATA_PTR;
		.$$DFLT_DATA_ATTR = .xFAR
		.$$DFLT_CODE_ATTR = .xFAR + .$$FCN_BASE
	     EXITM
	     ENDIF                   
	
	ENDM
	
.$$SET_CHECK_STACK MACRO
		
     IF (.$$CHECK_STACK EQ ._YES)
		EXTERN FCN _chkstk;
		ENDIF
	
	ENDM
	
	
.$$SET_FCN_STACK_FRAME MACRO REG_LIST
	
	.@PUSH_N_BYTES = 0
	IF (.$FAR_DS NE 0)
		.@PUSH_N_BYTES = 2;
		ENDIF
	IF ((.$$CHECK_STACK + .$$ALWAYS_SET_NEW_STACK_FRAME + .$N_FCN_ARG_BYTES + .$N_AUTO_BYTES) GT 0)
		PUSH	BP
		MOV	BP, SP
	     .@PUSH_N_BYTES = .@PUSH_N_BYTES  + 2;
		.$NEW_STACK_FRAME = ._YES
		IF (.$$CHECK_STACK EQ ._YES)
			IF (.$N_AUTO_BYTES EQ 0)
				XOR	AX, AX
			ELSE
				MOV	AX, .$N_AUTO_BYTES
				ENDIF
			CALL __CHKSTK
		ELSE 
			IF (.$N_AUTO_BYTES GT 0) 
				IF (.$N_AUTO_BYTES EQ 2)
					DEC	SP
					DEC	SP
				ELSE
					SUB	SP, .$N_AUTO_BYTES
					ENDIF
				ENDIF
			ENDIF
		ENDIF
	
	.$PUSH_PROLOGUE_REGS <REG_LIST>
	
	IF ((.$N_AUTO_BYTES GT 0) OR (.$PUSH_N_REGS GT 0))
		.$BP_EQUALS_SP = ._NO;
		ENDIF
	
	.$FCN_ARG_BASE = .$FCN_RETURN_PTR_SZ + .@PUSH_N_BYTES
	
	ENDM



DEFINE_DATA_SEG MACRO
	
	START_DATA	MACRO
		_DATA SEGMENT WORD PUBLIC 'DATA'
		ENDM
		
     END_DATA		MACRO
     	_DATA ENDS
     	ENDM
	
	DGROUP    GROUP     _DATA
	ASSUME    DS:DGROUP
	DS_LBL	EQU		DGROUP
	
	ENDM
		
		
DEFINE_CODE_SEG  MACRO   MODULE_NAME
		
	IF (.$$CODE_SIZE EQ ._SMALL_CODE)
		.$$DEFINE_CODE_SEG _TEXT
	ELSE
	     .$$DEFINE_CODE_SEG _EZ_TEXT
	     ENDIF
	ENDM
		

.$$DEFINE_CODE_SEG MACRO MODULE_NAME
	
	CS_LBL 		EQU 		MODULE_NAME
	START_CODE  MACRO
          MODULE_NAME SEGMENT   BYTE PUBLIC 'CODE'
		ENDM
			
	END_CODE	MACRO
		MODULE_NAME ENDS
		ENDM       
	ASSUME    CS:MODULE_NAME
			
	ENDM


