PAGE 66,132
TITLE RBBS-PC DESQview Interface Copyright 1986 by Jon Martin     
;--------------------------------------------------------------------;
;ROUTINE: RBBSDV              AUTHOR:  Jon Martin                    ;
;                                      4396 N. Prairie Willow Ct.    ;
;                                      Concord, California 94521     ;
;                                                                    ;
;DATE:  June 20, 1986         VERSION: 1.0                           ;       
;                                                                    ;
;FUNCTION: This routine supports calls from the IBM (MICROSOFT)      ;
;          BASIC Version 2.0 or Microsoft Quick BASIC Version 1.0    ;
;          compilers to the DESQview User Interface.  The call is:   ;
;                                                                    ;
;            CALL RBBSDV (AX%,BX%)                                   ;
;                                                                    ;
;          where AX% and BX% are 16-bit binary data items (i.e.      ;
;          integer variables) and should be set for the desired      ;
;          function as described herein.                             ;
;                                                                    ;
;          The value for AX, is defined as follows:                  ;
;                                                                    ;
;             AX% = 1     (Begin critical)  LOCK FILES               ;
;             AX% = 2     (End critical)    UNLOCK FILES             ;
;                                                                    ;
;             BX% = 0     (RBBSDV will return 0 if DESQview is not   ;
;                         active and will return version number if   ;
;                         DESQview is active)                        ;
;--------------------------------------------------------------------;
RBBS_DESQ SEGMENT BYTE PUBLIC 'CODESG'
          ASSUME CS:RBBS_DESQ
          PUBLIC RBBSDV
IN_DV	  DB     0
TST_DV    DB     0
DV_VERS   DW     0
; API_CALL is a local routine that goes on stack, does whatever call is
; passed it in BX, and then goes off stack
API_CALL PROC
	PUSH	AX
	MOV	AX,101AH
	INT	15H			; OSTACK
	MOV	AX,BX
	INT	15H			; Parameter
	MOV	AX,1025H
	INT	15H			; USTACK
	POP	AX
	RET
API_CALL ENDP
GET_VERSION PROC
	  PUSH	BX
	  PUSH	CX
	  PUSH	DX
	  MOV	AX,2B01H		; DV get version request
	  MOV	CX,'DE'
	  MOV	DX,'SQ'
	  INT	21H
	  CMP	AL,0FFH			; Are we in DV?
	  JE	NO_DV			; Jump if not
	  MOV	AX,BX			; We are; put the version number in AX
          MOV   DV_VERS,AX              ; Save Version ID
	  MOV	CS:IN_DV,1		; Set the local IN_DV flag
	  JMP	SHORT DVGV_EXIT
NO_DV:	  SUB	AX,AX			; Clear AX
	  MOV	CS:IN_DV,AL		; And the local flag
DVGV_EXIT:
	  POP	DX
	  POP	CX
	  POP	BX
	  RET
GET_VERSION ENDP
; Begins a critical region.  This is a section of code which DV will not
; slice out of.  It MUST be ended with a DV_END_CRITICAL call.
DV_BEGIN_CRITICAL PROC FAR
	PUSH	BX
	MOV	BX,101BH		; BEGINC
	CALL	API_CALL
	POP	BX
DVBC_END:
	RET
DV_BEGIN_CRITICAL ENDP

; Ends a critical region.
DV_END_CRITICAL PROC FAR
	PUSH	BX
	MOV	BX,101CH		; ENDC
	CALL	API_CALL
	POP	BX
DVEC_END:
	RET
DV_END_CRITICAL ENDP
RBBSDV    PROC   FAR           ;LONG CALL
          PUSH   BP            ;SAVE CALLERS BASE POINTER REGISTER -- BP 
          MOV    BP,SP         ;SETUP TO ADDRESS OFF OF BASE POINTER REGISTER
          CMP    CS:TST_DV,1   ;HAVE WE TESTED FOR DESQview?
          JE     IS_IT         ;BYPASS TEST
          MOV    CS:TST_DV,1   ;TEST WAS DONE ONCE
          CALL   GET_VERSION   ;LET'S FIND OUT
IS_IT:    CMP    CS:IN_DV,0    ;IS DESQview RUNNING?
          JE     EXIT          ;NO IT IS NOT
          MOV    DI,[BP]+8     ;GET ADDRESS OF AX% PARAMETER
          MOV    AX,[DI]       ;PUT VALUE IN AX REGISTER
          CMP    AX,1          ;TEST FOR START CRITICAL
          JNE    TST_END       ;NO IT IS NOT
          CALL   DV_BEGIN_CRITICAL
          JMP    SET_RTN  
TST_END:  CMP    AX,2          ;TEST FOR END CRITICAL
          JNE    EXIT          ;MUST BE AN ERROR
          CALL   DV_END_CRITICAL
SET_RTN:  MOV    DI,[BP]+6     ;GET ADDRESS OF BX% PARAMETER
          MOV    AX,CS:DV_VERS    ;GET STORED VERSION
          MOV    [DI],AX       ;PUT DESQview VERSION IN A% PARAMETER
EXIT:     POP    BP            ;RESTORE CALLERS BASE POINTER REGISTER-- BP
          RET    4             ;RETURN AND REMOVE THE 2 PARAMETERS FROM STACK
RBBSDV    ENDP
RBBS_DESQ ENDS
          END
