c	Examples of the use of the MicroWay programs:
c		enab_ex, dsab_ex, inf_ctl, round and precis,
c	which provide an easy method for the Fortran or C
c	programmer to set up and to alter the state of the NDP.
c	Exceptions can be enabled (unmasked) and disabled (masked)
c	in groups or individually, the infinity mode may be set
c	(on 80287 only), and the rounding and /or precision control
c	modes may be set to any possible value.

	integer stndpcw, ldndpcw
	integer type, cw_arg, save_cw

c	Function declarations:
c		enab_ex		- enable (unmask) exceptions.
c		dsab_ex		- disable (mask) exceptions.
c		round		- rounding control.
c		inf_ctl		- 80287 infinity control.
c		precis		- precision control.

	integer enab_ex, dsab_ex
	integer round, inf_ctl, precis

c	Argument definitions:
c	    Exceptions:
c		IM	- invalid operation.
c		DM	- denormalized operand (80x87 only).
c		ZM	- zero divide.
c		OM	- overflow.
c		UM	- underflow.
c		PM	- precision.
c		UOM	- undefined opcode (Weitek only).
c		DCM	- data chain (Weitek only).
c	    80287 infinity control:
c		AFFINE	- affine closure.
c		PROJ	- projective closure.
c	    Rounding control:
c		EVEN	- round to nearest or even.
c		DOWN	- round toward - infinity.
c		UP	- round toward + infinity.
c		CHOP	- round toward zero.
c		IRND	- round integers like reals (Weitek only).
c		IZ	- round integers toward 0 (Weitek only).
c	    Precision control:
c		SINGLE	- single precision (24 bits) (80x87 only).
c		DOUBLE	- double precision (53 bits) (80x87 only).
c		EXTEND	- extended precision (64 bits) (80x87 only).

	integer IM, DM, ZM, OM, UM, PM, UOM, DCM
	integer AFFINE, PROJ
	integer EVEN, DOWN, UP, CHOP, IRND, IZ
	integer SINGLE, DOUBLE, EXTEND

	parameter (IM = 1, DM = 2, ZM = 4, OM = 8, UM = 16, PM = 32)
	parameter (UOM = 64, DCM = 128)
	parameter (AFFINE = 1, PROJ = 0)
	parameter (EVEN = 0, DOWN = 1, UP = 2, CHOP = 3, IRND = 4, IZ = 5)
	parameter (SINGLE = 0, DOUBLE = 2, EXTEND = 3)


c	Initialize the NDP.

	call init_ndp

c	Save the control word as the base line value.

	save_cw = stndpcw()
	write(*,1) save_cw
1	format(/' Control word = ',8z,'.'/)

c	Enable various exceptions.

	cw_arg = enab_ex(IM)
	type = stndpcw()
	write(*,1) type

	cw_arg = enab_ex(DM)
	type = stndpcw()
	write(*,1) type

	cw_arg = enab_ex(ZM)
	type = stndpcw()
	write(*,1) type

	cw_arg = enab_ex(OM)
	type = stndpcw()
	write(*,1) type

	cw_arg = enab_ex(UM)
	type = stndpcw()
	write(*,1) type

	cw_arg = enab_ex(PM)
	type = stndpcw()
	write(*,1) type

c	Disable them.

	cw_arg = dsab_ex(IM)
	type = stndpcw()
	write(*,1) type

	cw_arg = dsab_ex(DM)
	type = stndpcw()
	write(*,1) type

	cw_arg = dsab_ex(ZM)
	type = stndpcw()
	write(*,1) type

	cw_arg = dsab_ex(OM)
	type = stndpcw()
	write(*,1) type

	cw_arg = dsab_ex(UM)
	type = stndpcw()
	write(*,1) type

	cw_arg = dsab_ex(PM)
	type = stndpcw()
	write(*,1) type

c	Set the infinity control.

	cw_arg = inf_ctl(AFFINE)
	type = stndpcw()
	write(*,1) type

c	Set various rounding control modes.

	cw_arg = round(EVEN)
	type = stndpcw()
	write(*,1) type
	
	cw_arg = round(DOWN)
	type = stndpcw()
	write(*,1) type
	
	cw_arg = round(UP)
	type = stndpcw()
	write(*,1) type
	
	cw_arg = round(CHOP)
	type = stndpcw()
	write(*,1) type

c	Set various precision control modes.
	
	cw_arg = precis(SINGLE)
	type = stndpcw()
	write(*,1) type
	
	cw_arg = precis(DOUBLE)
	type = stndpcw()
	write(*,1) type
	
	cw_arg = precis(EXTEND)
	type = stndpcw()
	write(*,1) type

c	Restore the base line control word state.

	type = ldndpcw(save_cw)
	type = stndpcw()
	write(*,1) type

	end
