þ a‹R þ d þ w ÿÿÿÿÿÿÿÿÿÿþ m^9     þ hý	 oP     þ nSystem-wide$TITLE (GPiB Set Status Module) DATE (4/10/84)
$DEBUG

NAME  GPiB_SStat_Module

;***************************************************
;*
;* GPiB.SetStat.ASM
;*
;* KMW
;* April 10, 1984
;*
;* GRiD Corporation, Proprietor
;*
;* Revision Date:
;*
;*  1) April 10, 1984
;*  2) April 26, 1984
;*  3) August 03, 1984
;*  4) September 07, 1984
;*  5) October 26, 1984
;*  6) October 26, 1984
;*  7) February 5, 1985
;*  8) April 30, 1985
;*  9) November 27, 1985
;* 10) June 6, 1986 rv
;* 11) June 26, 1986 rv
;* 12) July 7, 1986 rv
;*
;* Reason for Revision:
;*
;*  1) Original Version
;*  2) Code Reduction to fit into PROM.  Delete new
;*     functions.  The file, gpib.big.setstat.asm~text~
;*     will have the new functions
;*  3) Remove Send_Addr for code squeeze.
;*  4) When doing a selective device clear, check for 
;*     secondary addressing on the device.
;*  5) Add two new SetStatus commands, SetREN and
;*     ResetREN.
;*  6) Change the micro-command routine so that it re-
;*     flects the new strategy of the specification.
;*  7) In Selective Device Clear, use the routine 
;*     'Send_Byte_Out' to send the SDC byte.  Second-
;*     ary addressing checks for BO int before return-
;*     ing, thus sending SDC out will timeout.
;*  8) Add the 'adjust variables' SetStatus command so
;*     that the variables used in the driver can be
;*     accessed by an external program (this is to allow
;*     special applications to be written and executed).
;*  9) Use Read9914Reg and Write9914Reg instead of going 
;*     to the hardware.
;* 10) Use OK_To_Send instead of Send_Byte_Out in the
;*     Old_SDClear routine to put the SDClear on the bus,
;*     so we don't overrun the 9914's data out register
;*     if the receiver is slow to accept the prior byte.
;* 11) Changed all references to offsets in data segments
;*     to be relative to the dgroup base.
;* 12) Changed the loading of DS register from 'DATA'
;*     to pushing and then popping DS.
;*
;*
;* Module Description
;*
;* This module will decode the Set Status mode and
;* call the module for that mode.  The modes imple-
;* mented with the Set Status command are:
;*
;*  1. Selective Device Clear
;*  2. Micro-Commands
;*  3. Service Request Enable
;*  4. Set REN
;*  5. Reset REN
;*  6. Access Variables
;*  7. Enable_SRQ
;*  8. Disable_SRQ
;*  9. GPiB_Command
;* 10. Enable_ParallelPoll
;* 11. Disable_ParallelPoll
;* 12. Enable_Talker/Listener
;* 13. Set_SRQ
;* 14. Set_ParallelPoll
;* 15. Pass_Control
;*
;* The first three Set Status Commands are a duplication
;* of the commands used in the first gpib driver.  This
;* allows for compatibility with any software written 
;* prior to the release of this code.
;*
;***************************************************
$EJ
;***************************************************
;*
;* EQUATES
;*
;***************************************************
$INCLUDE (gpib.inc~text~)
$INCLUDE (gpib.9914.inc~text~)
$EJ
CGROUP  GROUP  CODE
DGROUP  GROUP  DATA

;***************************************************
;*
;* PUBLIC Declarations
;*
;***************************************************

PUBLIC	GPiB_SetStatus
;??????????????? added 9/9/86 rv ??????????????????
;PUBLIC POff_GPiB
;??????????????????????????????????????????????????


;***************************************************
;*
;* EXTERNAL Declarations
;*
;***************************************************

EXTRN  OK_to_Send : NEAR
EXTRN  Sec_Addr : NEAR
EXTRN  Send_Byte_Out : NEAR
EXTRN  Read9914Reg : NEAR  ;added 11/27/85 dmg
EXTRN  Write9914Reg : NEAR  ;added 11/27/85 dmg
;??????????????? added 9/9/86 rv ??????????????????
;EXTRN	Power_On_GPiB : NEAR
;EXTRN	Power_Off_GPiB : NEAR
;??????????????????????????????????????????????????

$EJ
$INCLUDE (gpib.mem.inc~text~)
$EJ
;***************************************************
;*
;* Start of Code
;*
;***************************************************

CODE  SEGMENT BYTE  PUBLIC  'CODE'

ASSUME  CS:CGROUP, DS:DGROUP



;***************************************************
;*****************  Old_SDClear  *******************
;***************************************************

; Convert this old command into the compatible new
; command and call the routine.


Old_SDClear	PROC	NEAR

	mov	AL, params.address
	or	AL, MLAddr
	mov	AH, TRUE
	call	OK_To_Send
	or	AX, AX		; any error
	jnz	SDC_Done	; yes

	call	Sec_Addr	; check if secaddr enabled
	or 	AX, AX
	jnz	SDC_Done	; error found

	mov	AL, SDClear	; send out selective

;***************** changed 6/6/86 rv for wps
	mov	AH, true
	call	OK_To_Send
;	call	Send_Byte_Out
;***************** end 6/6/86 rv

	mov	AL, UNLstn	; send out UNListen
	mov	AH, TRUE
	call	OK_to_Send

SDC_Done:
	ret			; return

Old_SDClear	ENDP
$EJ
;***************************************************
;***************  Old_MicroCmnds  ******************
;***************************************************

; this routine allows the high level software to command
; the TI 9914 directly.  The following parameters are
; defined:
;
;   params.addrSEC = GPiBregister to interface (offset
;                   address). If the MSBit is set, the
;                   command is to write.  Else, read.
;   params.ENDchar = GPiBdata for register


Old_MicroCmnds	PROC	NEAR


;****** removed 11/27/85
;	mov	AX, GPiBioSEG	; setup address segment
;	mov	ES, AX		; for 9914
;	xor	AX, AX
;******
;****** changed 11/27/85
	mov	AL, params.addrSEC ; Data to write
	mov	AH, params.ENDchar ; setup offset to reg
;	mov	DI, AX
	test	AH, 80H		; write command?
	jnz	Write_Cmnd

	call	Read9914Reg	; read reg
	mov	params.ENDchar, AL
	jmp	End_uCmnd

Write_Cmnd:
	and	AH, 000fH	; get rid of bit in lower
				; byte
;	mov	DI, AX
	call	Write9914Reg	; write reg
;****** end of change

End_uCmnd:
	ret			; done with this one


Old_MicroCmnds	ENDP
$EJ
;***************************************************
;*******************  Old_EnbSRQ  ******************
;***************************************************

; this command originally set a device in the polling
; table for when SRQ's occurred.  Now it will take 
; the appropriate parameters and put them in their
; new parameter locations.  Enable_SRQ is then called
; to actually put the device in the table.


Old_EnbSRQ	PROC	NEAR

	xor	AX, AX
	mov	BX, Offset DGroup:Semafor_Tbl  ; get table
	mov	AL, params.address	; get device addr
	add	AX, AX			; double it
	mov	SI, AX
	mov	AX, Word Ptr params.ENDchar
				; get the word following
                                ; params.GPiBmode.  It is
				; the semaphore for this
				; device.
	mov	[BX][SI], AX	; put semaphore in table
	ret			; return to calling rou-
				; tine

Old_EnbSRQ	ENDP
$EJ
;***************************************************
;*****************  New_REN_Set  *******************
;***************************************************

; this routine is a new setstatus command allowing
; the user to set the REN true.  This is required for
; interfacing to many HP instruments


New_REN_Set	PROC	NEAR

;****** removed 11/27/85
;	mov	AX, GPiBioSEG
;	mov	ES, AX
;******

;****** changed 11/27/85
	mov	AH, Auxlry_Mode_ID
	mov	AL, sre_ON
	call	Write9914Reg
	ret

New_REN_Set	ENDP



;***************************************************
;*****************  New_REN_Reset  *****************
;***************************************************

; this routine is a new setstatus command allowing
; the user to set the REN line false.


New_REN_Reset	PROC	NEAR

;****** removed 11/27/85
;	mov	AX, GPiBioSEG
;	mov	ES, AX
;******

;****** changed 11/27/85
	mov	AH, Auxlry_Mode_ID
	mov	AL, sre_off
	call	Write9914Reg
	ret

New_REN_Reset	ENDP
$EJ
;***************************************************
;****************  Access_Variables  ***************
;***************************************************

; This routine is a new setstatus command which allows
; the user to access the variables used in the driver.
; It is assumed that the following parameters will be
; set so that the proper action is taken by the routine.
;
;   Overflow.GPiBcmnd(low nibble) = X0H = Entry_Semfor
;   Overflow.GPiBcmnd(low nibble) = X1H = Data_Semfor
;   Overflow.GPiBcmnd(low nibble) = X2H = GPiB_Flags
;   Overflow.GPiBcmnd(low nibble) = X3H = Controller
;   Overflow.GPiBcmnd(low nibble) = X4H = dmaINTrcvd
;   Overflow.GPiBcmnd(low nibble) = X5H = serviceSRQ
;   Overflow.GPiBcmnd(low nibble) = X6H = SaveMask0
;   Overflow.GPiBcmnd(low nibble) = X7H = SaveMask1
;   Overflow.GPiBcmnd(low nibble) = X8H = TlkLsn_TO
;   Overflow.GPiBcmnd(low nibble) = X9H = Semafor_Tbl
;
;   Overflow.GPiBcmnd(high nibble) = 0XH = Write Byte
;   Overflow.GPiBcmnd(high nibble) = 1XH = Write Word
;   Overflow.GPiBcmnd(high nibble) = 2XH = Read Byte
;   Overflow.GPiBcmnd(high nibble) = 3XH = Read Word

; If the command is to read or write 'Semafor_Tbl', the
; first byte in the buffer for Overflow.GPiBadds will
; contain the offset into the Table.

; The variable is returned in the parameter, 
; Overflow.ExtraInfo.  The value to be written to the
; parameter is stored in Overflow.ExtraInfo.


Access_Variables	PROC	NEAR
;***** changed 7/7/86 rv
 	push	DS
	lds	SI, BlockPtr
	les	BX, DS:[SI].pOverflow
	pop	DS
;	mov	AX, DATA
;	mov	DS, AX
;***** end 7/7/86 change

	mov	AL, ES:[BX].GPiBcmnd ; read or write it?
	mov	CL, AL		; save it
	and	CL, 0f0H	; mask out param type
	and	AL, 0fH		; mask out rd/wt type
	xor	AH, AH
	add	AX, AX		; double it


	push	BX
	mov	BX, Offset Parameter_Tbl
	add	BX, AX		; offset into table
	mov	SI, CS:[BX]	; get parameter address
	pop	BX

	cmp	AX, 2*9H	; trying to rd/wt table?
	jne	Other_Vars	; no

	mov	AL, ES:[BX].GPiBadds ; get offset into it
	xor	AH, AH
	add	AX, AX		; double it
	add	SI, AX		; add in offset

Other_Vars:	
	mov	AX, ES:[BX].ExtraInfo ; get value to write
	cmp	CL, 00H		; write the byte?
	jne	Chk_WrtWord	; no

	mov	Byte Ptr DS:[SI], AL ; yes, write byte
	jmp	End_Access

Chk_WrtWord:
	cmp	CL, 010H	; write the word?
	jne	Chk_RdByte	; no, go and read it

	mov	Word Ptr DS:[SI], AX ; yes, write word
	jmp	End_Access

Chk_RdByte:
	cmp	CL, 020H	; read a byte param
	jne	Chk_RdWord	; no, read a word

	mov	AL, Byte Ptr DS:[SI] ; read a byte
	jmp	Store_Param

Chk_RdWord:
	mov	AX, Word Ptr DS:[SI] ; write a byte

Store_Param:
	mov	ES:[BX].ExtraInfo, AX

End_Access: 
	ret


	Parameter_Tbl	dw	Offset DGroup:Entry_Semfor
		dw	Offset DGroup:Data_Semfor
		dw	Offset DGroup:GPiB_Flags
		dw	Offset DGroup:Controller
		dw	Offset DGroup:dmaINTrcvd
		dw	Offset DGroup:serviceSRQ
		dw	Offset DGroup:SaveMask0
		dw	Offset DGroup:SaveMask1
		dw	Offset DGroup:TlkLsn_TO
		dw	Offset DGroup:Semafor_Tbl

Access_Variables	ENDP


;???????????????? added 9/9/86 rv ?????????????????
;$EJ
;;**************************************************
;;******************  POn_GPiB  ********************
;;**************************************************
;POn_GPiB PROC NEAR
;	test	gpib_flags, power_on
;	jnz	POnRet
;	call	Power_On_GPiB
;	or	gpib_flags, power_on
;POnRet:	ret
;POn_GPiB ENDP
;
;
;;**************************************************
;;******************  POff_GPiB  *******************
;;**************************************************
;POff_GPiB PROC NEAR
;	test	gpib_flags, power_on
;	jz	POffRet
;	mov	bx, OFFSET dgroup:Semafor_Tbl
;	mov	si, 0
;	mov	cx, 31
;POffLoop:
;	mov	ax, [bx][si]
;	or	ax, ax
;	jnz	POffRet
;	inc	si
;	inc	si
;	loop	POffLoop
;	call	Power_Off_GPiB
;	and	GPiB_Flags, NOT power_on
;POffRet:ret
;POff_GPiB ENDP
;
;;**************************************************
;;***************  POff_GPiB_NoChek  ***************
;;**************************************************
;POff_GPiB_NoChek PROC NEAR
;	test	gpib_flags, power_on
;	jz	POffNoChekRet
;	call	Power_Off_GPiB
;	and	GPiB_Flags, NOT power_on
;POffNoChekRet:
;	ret
;POff_GPiB_NoChek ENDP
;
;;???????????????????? end 9/9/86 add ??????????????
$EJ
;**************************************************
;***************  GPiB_SetStatus  *****************
;**************************************************

GPiB_SetStatus	PROC	NEAR

;****** removed 11/27/85 dmg
;	mov	AX, GPiBioSEG	; setup for accessing
;	mov	ES, AX		; GPiB chip
;******
	mov	AL, params.GPiBmode ; get set stat mode
	xor	AH, AH
	add	AX, AX		; double that number
	mov	BX, Offset SetStat_Tbl
	add	BX, AX		; offset into table
	mov	SI, CS:[BX]	; get routine address
	call	SI		; call the routine
	ret


SetStat_Tbl	dw	Offset Old_SDClear
		dw	Offset Old_MicroCmnds
		dw	Offset Old_enbSRQ
		dw	Offset New_REN_Set
		dw	Offset New_REN_Reset
		dw	Offset Access_Variables
;??????????????? added 9/9/86 rv ??????????????????
;		dw	Offset POn_GPiB
;		dw	Offset POff_GPiB
;		dw	Offset POff_GPiB_NoChek
;??????????????????????????????????????????????????

GPiB_SetStatus	ENDP

CODE	ENDS
	END
