home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / OSLIB101.ZIP / SOURCE / YIELD.ASM < prev   
Encoding:
Assembly Source File  |  1998-04-14  |  4.6 KB  |  239 lines

  1. ;; This code is based on code sent to me by the author listed below.
  2. ;;
  3. ;; VADPMI.ASM
  4. ;; ==========
  5. ;;
  6. ;; Copyright (c) 1991-95 Szél Viktor, Szélvész Bt.
  7. ;;
  8. ;; History
  9. ;; =======
  10. ;;
  11. ;; 1.00  (1994-06-10) - Separated from VTOOLASM.ASM 1.15
  12. ;;
  13. ;; Bugs and Anomalies
  14. ;; ==================
  15. ;;
  16. ;; Mi van ha nincs DPMI host, de mégis protected módban fut ?
  17. ;;
  18. ;; ToDo
  19. ;; ====
  20. ;;
  21.  
  22. TRUE  equ 1
  23. FALSE equ 0
  24.  
  25. DGROUP        GROUP    DATA
  26.  
  27. DATA        SEGMENT PUBLIC 'DATA'
  28.  
  29. bChecked    DW    FALSE
  30. bProtected    DW    FALSE
  31.  
  32. DATA        ENDS
  33.  
  34. CODE        SEGMENT 'CODE'
  35.         ASSUME CS:CODE, DS:DGROUP
  36.  
  37. ;;---------------------------------------
  38. ;; GLOBAL  BOOL    PMIsProtected       (VOID);
  39. ;;---------------------------------------
  40.  
  41. .8086
  42.  
  43. PUBLIC        _PMIsProtected
  44.  
  45. _PMIsProtected    PROC    FAR
  46.  
  47.         cmp    bChecked, TRUE        ; Get checked flag
  48.         je    _PMIsProtected_Done
  49.  
  50.         mov    bChecked,TRUE        ; Set checked flag (kockás zászló :-)
  51.  
  52.         push    SP            ; Put SP on stack
  53.         pop    BX            ; Now get it back
  54.         cmp    BX,SP            ; If not ==, 8088/8086
  55.         jne    _PMIsProtected_Done    ; Return FALSE
  56. .286p
  57.         smsw    AX            ; Get status word
  58.         and    AX,1            ; Check for pmode bit
  59.         jz    _PMIsProtected_Done    ; Return FALSE if clear
  60.  
  61.         pushf                ; Mov flag word . . .
  62.         pop    BX            ; . . . to BX
  63.         and    BH,11001111b        ; Set IOPL to zero
  64.         push    BX            ; Move BX . . .
  65.         popf                ; . . . back to flag word
  66.         pushf                ; Now move flags . . .
  67.         pop    BX            ; . . . back to BX
  68.         test    BH,110000b        ; Is IOPL still zero?
  69.  
  70.         mov    bProtected,TRUE     ; ?
  71.         jz    _PMIsProtected_Done    ; If so, return TRUE
  72.  
  73.         push    DS
  74.         push    ES
  75.         push    SI
  76.         push    DI
  77.  
  78.         mov    AX,1686h        ; DPMI -- get CPU mode
  79.         int    2Fh            ; Call DPMI
  80.  
  81.         pop    DI
  82.         pop    SI
  83.         pop    ES
  84.         pop    DS
  85.  
  86.         or    AX,AX
  87.         mov    bProtected,TRUE
  88.         jz    _PMIsProtected_Done
  89.         mov    bProtected,FALSE
  90.  
  91. _PMIsProtected_Done:
  92.         mov    AX,bProtected
  93.         ret
  94.  
  95. _PMIsProtected    ENDP
  96.  
  97. ;;---------------------------------------
  98. ;; GLOBAL  SEL       PMSegToSel           (WORD wSegment);
  99. ;;
  100. ;;    1)  This function always generates a 64K selector.
  101. ;;
  102. ;;    2)  Selectors generated by this function can never be modified or
  103. ;;      freed.
  104. ;;
  105. ;;    3)  Multiple calls to this function with the same segment will
  106. ;;      always return the same selector.
  107. ;;
  108. ;;    This function should be used sparingly.  It is mainly intended
  109. ;;    for use with commonly used real mode memory segments like
  110. ;;    0xB800 or 0x0040.
  111. ;;---------------------------------------
  112.  
  113. .286
  114.  
  115. PUBLIC        _PMSegToSel
  116.  
  117. _PMSegToSel    PROC    FAR
  118.  
  119.         enter    0,0            ; Create stack frame
  120.  
  121.         call    _PMIsProtected        ; See if in protected mode
  122.         cmp    AX,FALSE
  123.         mov    AX,word ptr [BP+6]
  124.         je    _PMSegToSel_Done
  125. .286p
  126.         push    DS
  127.         mov    BX,AX            ; Get segment
  128.         mov    AX,2            ; DPMI -- Seg to Descriptor
  129.         int    31h            ; Call DPMI
  130.         pop    DS
  131.  
  132.         jnc    _PMSegToSel_Done    ; Leave if no error
  133.         xor    AX,AX            ; Return null selector
  134. _PMSegToSel_Done:
  135.         leave                ; Destroy stack frame
  136.         ret
  137.  
  138. _PMSegToSel    ENDP
  139.  
  140. ;   $DOC$
  141. ;   $FUNCNAME$
  142. ;       OL_Yield()
  143. ;   $CATEGORY$
  144. ;       Functions
  145. ;   $ONELINER$
  146. ;       Return a time slice back to the operating system.
  147. ;   $SYNTAX$
  148. ;       OL_Yield()
  149. ;   $ARGUMENTS$
  150. ;       None.
  151. ;   $RETURNS$
  152. ;       Nothing.
  153. ;   $DESCRIPTION$
  154. ;       OL_Yield() can be used to return time slices back to operating
  155. ;       systems such as OS/2 and operating environments such as Windows.
  156. ;       By doing this your application will generate less CPU load and
  157. ;       make your whole machine run just a little smoother.
  158. ;
  159. ;       This function is best used in a wait state in your application
  160. ;       and should be called as many times as possible while it is waiting
  161. ;       for input.
  162. ;
  163. ;       It is safe to call this function even if you are not running your
  164. ;       application under OS/2 or Windows.
  165. ;   $EXAMPLES$
  166. ;       // When you may have done this:
  167. ;
  168. ;       nKey := InKey( 0 )
  169. ;
  170. ;       // It is now better to do this:
  171. ;
  172. ;       While nextkey() == 0
  173. ;          OL_Yield()
  174. ;       End
  175. ;       nKey := InKey()
  176. ;
  177. ;   $SEEALSO$
  178. ;
  179. ;   $END$
  180. ;
  181.  
  182. .286
  183.  
  184. PUBLIC          OL_YIELD
  185.  
  186. OL_YIELD        PROC    FAR
  187. CPUTIME:
  188.         enter    50, 0
  189.  
  190.         call    _PMIsProtected        ; See if in protected mode
  191.         cmp    AX,FALSE
  192.         je    _PMDosIdleCall_Real
  193. .286p
  194.         push    DS
  195.         push    SI
  196.         push    DI
  197.         push    BP
  198.  
  199.         push    SS
  200.         pop    ES
  201.         lea    DI, [BP-50]
  202.         mov    AX, 0
  203.         mov    CX, 50 / 2
  204.         cld
  205.         rep stosw
  206.  
  207.         mov    word ptr [BP-22], 1680h
  208.  
  209.         mov    AX, 0300H
  210.         mov    BL, 2Fh
  211.         mov    BH, 0
  212.         xor    CX, CX
  213.         push    SS
  214.         pop    ES
  215.         lea    DI, [BP-50]
  216.         int    31H
  217.  
  218.         cld
  219.         pop    BP
  220.         pop    DI
  221.         pop    SI
  222.         pop    DS
  223.  
  224.         leave
  225.         retf
  226. .286
  227. _PMDosIdleCall_Real:
  228.         mov    AX, 1680h
  229.         int    2Fh
  230.  
  231.         leave
  232.         retf
  233.  
  234. OL_YIELD        ENDP
  235.  
  236. CODE        ENDS
  237.  
  238.         END
  239.