home *** CD-ROM | disk | FTP | other *** search
- ;; This code is based on code sent to me by the author listed below.
- ;;
- ;; VADPMI.ASM
- ;; ==========
- ;;
- ;; Copyright (c) 1991-95 Szél Viktor, Szélvész Bt.
- ;;
- ;; History
- ;; =======
- ;;
- ;; 1.00 (1994-06-10) - Separated from VTOOLASM.ASM 1.15
- ;;
- ;; Bugs and Anomalies
- ;; ==================
- ;;
- ;; Mi van ha nincs DPMI host, de mégis protected módban fut ?
- ;;
- ;; ToDo
- ;; ====
- ;;
-
- TRUE equ 1
- FALSE equ 0
-
- DGROUP GROUP DATA
-
- DATA SEGMENT PUBLIC 'DATA'
-
- bChecked DW FALSE
- bProtected DW FALSE
-
- DATA ENDS
-
- CODE SEGMENT 'CODE'
- ASSUME CS:CODE, DS:DGROUP
-
- ;;---------------------------------------
- ;; GLOBAL BOOL PMIsProtected (VOID);
- ;;---------------------------------------
-
- .8086
-
- PUBLIC _PMIsProtected
-
- _PMIsProtected PROC FAR
-
- cmp bChecked, TRUE ; Get checked flag
- je _PMIsProtected_Done
-
- mov bChecked,TRUE ; Set checked flag (kockás zászló :-)
-
- push SP ; Put SP on stack
- pop BX ; Now get it back
- cmp BX,SP ; If not ==, 8088/8086
- jne _PMIsProtected_Done ; Return FALSE
- .286p
- smsw AX ; Get status word
- and AX,1 ; Check for pmode bit
- jz _PMIsProtected_Done ; Return FALSE if clear
-
- pushf ; Mov flag word . . .
- pop BX ; . . . to BX
- and BH,11001111b ; Set IOPL to zero
- push BX ; Move BX . . .
- popf ; . . . back to flag word
- pushf ; Now move flags . . .
- pop BX ; . . . back to BX
- test BH,110000b ; Is IOPL still zero?
-
- mov bProtected,TRUE ; ?
- jz _PMIsProtected_Done ; If so, return TRUE
-
- push DS
- push ES
- push SI
- push DI
-
- mov AX,1686h ; DPMI -- get CPU mode
- int 2Fh ; Call DPMI
-
- pop DI
- pop SI
- pop ES
- pop DS
-
- or AX,AX
- mov bProtected,TRUE
- jz _PMIsProtected_Done
- mov bProtected,FALSE
-
- _PMIsProtected_Done:
- mov AX,bProtected
- ret
-
- _PMIsProtected ENDP
-
- ;;---------------------------------------
- ;; GLOBAL SEL PMSegToSel (WORD wSegment);
- ;;
- ;; 1) This function always generates a 64K selector.
- ;;
- ;; 2) Selectors generated by this function can never be modified or
- ;; freed.
- ;;
- ;; 3) Multiple calls to this function with the same segment will
- ;; always return the same selector.
- ;;
- ;; This function should be used sparingly. It is mainly intended
- ;; for use with commonly used real mode memory segments like
- ;; 0xB800 or 0x0040.
- ;;---------------------------------------
-
- .286
-
- PUBLIC _PMSegToSel
-
- _PMSegToSel PROC FAR
-
- enter 0,0 ; Create stack frame
-
- call _PMIsProtected ; See if in protected mode
- cmp AX,FALSE
- mov AX,word ptr [BP+6]
- je _PMSegToSel_Done
- .286p
- push DS
- mov BX,AX ; Get segment
- mov AX,2 ; DPMI -- Seg to Descriptor
- int 31h ; Call DPMI
- pop DS
-
- jnc _PMSegToSel_Done ; Leave if no error
- xor AX,AX ; Return null selector
- _PMSegToSel_Done:
- leave ; Destroy stack frame
- ret
-
- _PMSegToSel ENDP
-
- ; $DOC$
- ; $FUNCNAME$
- ; OL_Yield()
- ; $CATEGORY$
- ; Functions
- ; $ONELINER$
- ; Return a time slice back to the operating system.
- ; $SYNTAX$
- ; OL_Yield()
- ; $ARGUMENTS$
- ; None.
- ; $RETURNS$
- ; Nothing.
- ; $DESCRIPTION$
- ; OL_Yield() can be used to return time slices back to operating
- ; systems such as OS/2 and operating environments such as Windows.
- ; By doing this your application will generate less CPU load and
- ; make your whole machine run just a little smoother.
- ;
- ; This function is best used in a wait state in your application
- ; and should be called as many times as possible while it is waiting
- ; for input.
- ;
- ; It is safe to call this function even if you are not running your
- ; application under OS/2 or Windows.
- ; $EXAMPLES$
- ; // When you may have done this:
- ;
- ; nKey := InKey( 0 )
- ;
- ; // It is now better to do this:
- ;
- ; While nextkey() == 0
- ; OL_Yield()
- ; End
- ; nKey := InKey()
- ;
- ; $SEEALSO$
- ;
- ; $END$
- ;
-
- .286
-
- PUBLIC OL_YIELD
-
- OL_YIELD PROC FAR
- CPUTIME:
- enter 50, 0
-
- call _PMIsProtected ; See if in protected mode
- cmp AX,FALSE
- je _PMDosIdleCall_Real
- .286p
- push DS
- push SI
- push DI
- push BP
-
- push SS
- pop ES
- lea DI, [BP-50]
- mov AX, 0
- mov CX, 50 / 2
- cld
- rep stosw
-
- mov word ptr [BP-22], 1680h
-
- mov AX, 0300H
- mov BL, 2Fh
- mov BH, 0
- xor CX, CX
- push SS
- pop ES
- lea DI, [BP-50]
- int 31H
-
- cld
- pop BP
- pop DI
- pop SI
- pop DS
-
- leave
- retf
- .286
- _PMDosIdleCall_Real:
- mov AX, 1680h
- int 2Fh
-
- leave
- retf
-
- OL_YIELD ENDP
-
- CODE ENDS
-
- END
-