home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / slicer / slicer.asm next >
Assembly Source File  |  1993-03-11  |  6KB  |  179 lines

  1.  
  2. ; Public Domain - credits to Matthew Staben, Staben Technologies
  3. ;                                            811 West 14th Avenue
  4. ;                                            Spokane, WA  99204
  5. ;                                            March 10, 1993
  6. ;
  7. ;                 YOU MAY DO ANYTHING YOU WANT WITH THIS CODE.
  8.  
  9. .Model Small
  10. .Code
  11.  
  12. ismtask         DB      0                       ; zero if none
  13. timeslice       DB      0                       ; timeslicing release
  14. old_1ch_vector  dd      0
  15. timer        DW    0
  16.  
  17. new_1ch_vector  proc    far
  18.         
  19.  
  20.                 sti                             ; renable 8088 irq, the
  21.                                                 ; 8088 (80x86) will disable
  22.                                                 ; when called.  The 8259
  23.                                                 ; will not allow anything
  24.                                                 ; to interrupt until
  25.                                                 ; this routine is done
  26.                 push ax
  27.                 push bx
  28.                 push cx
  29.                 push dx
  30.                 push si
  31.                 push di
  32.                 push bp
  33.                 push ds
  34.                 push es
  35.  
  36.                 ;note call to old vecter is an intersegment far call
  37.         
  38.                 pushf                           ; push flags to simulate int
  39.                 call cs:old_1ch_vector          ; chain old routine
  40.         
  41.                 mov al,20h                      ; send eoi to 8259
  42.                 mov dx,20h
  43.                 out dx,al
  44.  
  45.                 ; check for multitasking
  46.                 cmp     [cs:ismtask], 00h
  47.                 je      no_release
  48.                 ;
  49.                 ; hmm, now release a timeslice if the count is hi enuf!!
  50.                 ;
  51.                 inc     [cs:timeslice]
  52.                 cmp     [cs:timeslice], 003h    ; 3 = 3/18.2 (1/6)
  53.                 jb      no_release              ; adjust as necessary
  54.        release:
  55.                 cmp     [cs:ismtask], 02h
  56.                 je      release_desqview
  57.                 mov     ax, 01680h        ; OS/2/ Windows timslice release call
  58.                 int     02Fh
  59.                 mov     [cs:timeslice], 00h
  60.                 jmp     no_release
  61.        release_desqview:
  62.                 mov     ax, 0101Ah           ; Switch to DV's stack.
  63.                 int     015h
  64.                 mov     ax, 01000h           ; Give up time-slice.
  65.                 int     015h
  66.                 mov     ax, 01025h           ; Restore local stack.
  67.                 int     015h
  68.        no_release:
  69.                 
  70. bye_bye:
  71.                 
  72.  
  73.                 pop es
  74.                 pop ds
  75.                 pop bp
  76.                 pop di
  77.                 pop si
  78.                 pop dx
  79.                 pop cx
  80.                 pop bx
  81.                 pop ax
  82.                 iret
  83.                 endp
  84.  
  85.  
  86.  
  87. ;----------------------------------------------------------------------------
  88. _1ch_install    proc
  89.  
  90.                 cli                             ; disable interrupts
  91.                                                 ; while diddling vectors
  92.  
  93.                 ; get old vector and save it
  94.                 mov ah, 35h                     ; get vector
  95.                 mov al, 1ch                     ; of int 1ch
  96.                 int 21h
  97.                 mov  word ptr old_1ch_vector, bx
  98.                 mov  word ptr old_1ch_vector + 2, es
  99.  
  100.                 push ds                         ; save ds, int 25h uses it
  101.  
  102.                 ; get address of new vector and install it
  103.                 mov dx, cs
  104.                 mov ds, dx
  105.                 mov dx,  offset new_1ch_vector
  106.                 mov ah, 25h                     ; set vector
  107.                 mov al, 1ch                     ; of 1ch
  108.                 int 21h
  109.  
  110.                 pop ds
  111.                 sti                             ; reenable interrupts
  112.                 ret
  113.                 endp
  114.  
  115. ;----------------------------------------------------------------------------
  116. main            proc
  117.                 call _1ch_install
  118.                 mov    [timer], 0h
  119.  
  120.                 ;
  121.                 ; first, we check for various multitasking systems
  122.                 ; DESQVIEW
  123.                 ; OS/2
  124.                 ; WINDOWS
  125.                 ;
  126.                  
  127.                 mov     [cs:ismtask], 00h       ; set to none
  128.                 
  129.                 ; check for DESQVIEW
  130.                 
  131.                 mov     cx, 'DE'
  132.                 mov     dx, 'SQ'
  133.                 mov     ax, 02B01h       ; DOS set date function.
  134.                 int     021h
  135.                 cmp     al, 0FFh         ; Did DOS report the invalid date?
  136.                 jnz     @@desqview       ; If not, we've got Desqview.
  137.  
  138.                 ; check for OS/2
  139.                 
  140.                 mov     ah, 030h         ; DOS get version fn.
  141.                 int     021h
  142.  
  143.                 cmp     al, 014h         ; 20 decimal.
  144.                 jb      @@no_OS2
  145.                 mov     [cs:ismtask], 01h
  146.  
  147.             @@no_OS2:
  148.             
  149.                 ; check for Windows
  150.                 
  151.                 mov     ax, 01600h
  152.                 int     02Fh
  153.                 cmp     al, 00h
  154.                 jz      begin_init
  155.                 cmp     al, 080h
  156.                 jz      begin_init
  157.                 cmp     al, 01h           ; Windows/386 2.x; not supported.
  158.                 jz      begin_init
  159.                 cmp     al, 0FFh          ; Windows/386 2.x; not supported.
  160.                 cmp     al, 03h           ; At least Win 3.0?
  161.                 jb      begin_init
  162.                 mov     [cs:ismtask], 01h
  163.                 jmp     begin_init
  164.         @@desqview:
  165.                 mov     [cs:ismtask], 02h
  166.         begin_init:                
  167.                 ; terminate and stay resident
  168.                 mov dx, ((offset pgm_length + 15) / 16) + 20
  169.                 mov ah, 31h
  170.                 mov al, 00h
  171.                 int 21h
  172.                 endp
  173.  
  174. pgm_length      equ $ - main                    ; remove un-needed code
  175.  
  176.                 end  main                       ; specify start location
  177.  
  178.  
  179.