home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / MTASK211 / IDEAL.ASM < prev    next >
Assembly Source File  |  1991-05-11  |  14KB  |  352 lines

  1. ; *****************************************************************************
  2. ;
  3. ;           MTASK.ASM ... General-purpose multitasker interface code
  4. ;                        Release 2.01  (March 30, 1991)
  5. ;
  6. ;                       Copyright (C) 1991, David Begley
  7. ;
  8. ;                           Authors: David Begley
  9. ;                                    Anthony Rumble
  10. ;
  11. ; *****************************************************************************
  12.  
  13. ;                *********************************************
  14. ;                      Turbo Assembler 2.01 - IDEAL Mode
  15. ;                Conditionally assembles for Pascal, C and C++
  16. ;                *********************************************
  17.  
  18. ; NOTES:
  19. ;
  20. ;   To assemble for C/C++, define the symbol "CEE".  This will create all the
  21. ;   necessary code for linking into Turbo C/C++.  If CEE is not defined,
  22. ;   Turbo Pascal is assumed.
  23. ;
  24. ;   If CEE is defined, a second symbol, "MEMORY" must be defined, as per the
  25. ;   required memory model:
  26. ;
  27. ;          - tiny
  28. ;          - small
  29. ;          - medium
  30. ;          - compact
  31. ;          - large
  32. ;          - huge
  33. ;
  34. ;   Case is insensitive.  If MEMORY is not defined, the small memory model is
  35. ;   assumed.
  36.  
  37. ; Values returned by DetectMultitasker correspond to:
  38. ;   0  no known multitasker found, DOS Idle interrupt assumed
  39. ;   1  generic TopView detected
  40. ;   2  generic TAME=controlled detected
  41. ;   3  DESQview
  42. ;   4  MultiDOS II
  43. ;   5  MultiDOS III
  44. ;   6  DoubleDOS
  45. ;   7  Windows 2.xx or lower
  46. ;   8  Windows 3.xx
  47. ;   9  OS/2's DOS Compatability Box
  48. ;; 10  ConcurrentDOS
  49. ;  11  PC-MOS/386
  50. ;  12  MultiLink
  51. ;
  52. ; Planned multitasker support:
  53. ;   VM/386
  54. ;   VMiX
  55. ;   CSwitch
  56. ;
  57. ; Possible enhancements:
  58. ;   C++ inline macros?
  59. ;   Turbo Pascal 6.0 inline assembly version?
  60. ;   Assembly compatible routine (perhaps try the C/C++ one?)
  61. ;   Virtual screen detection
  62. ;   Processor specific operations (ie., 286, 386 and 486 commands)
  63. ;   Fix the MultiDOS III detection code with the new API calls
  64. ;   Fix the ConcurrentDOS detection problem
  65.  
  66. ; Pascal definitions:
  67. ;   function DetectMultitasker : byte;
  68. ;   procedure TaskSwitch;
  69.  
  70. ; C/C++ definitions:
  71. ;   unsigned char DetectMultitasker();
  72. ;   void TaskSwitch();
  73.  
  74.  
  75.                    IDEAL                  ; TASM's "IDEAL" assembly mode
  76.                    INCLUDE "SM86TI.INC"   ; Use SM86 macro package
  77.  
  78.                    %TITLE "MTASK OFFICIAL RELEASE 2.01"
  79.                    %SUBTTL "Using Joe Moldovan's SM86 v1.10"
  80.  
  81.                    _sm86 LIST             ; Begin SM86 code
  82.  
  83.  
  84.                    IFDEF CEE
  85.                      DOSSEG               ; Use DOS segment ordering
  86.                      IFNDEF MEMORY
  87.                        MODEL small        ; Small memory model is default
  88.                      ELSE
  89.                        MODEL MEMORY       ; Use memory model programmer wants
  90.                      ENDIF
  91.                      PUBLIC C DetectMultitasker, C TaskSwitch
  92.                    ELSE
  93.                      MODEL TPascal        ; Use Turbo Pascal memory model
  94.                      PUBLIC Pascal DetectMultitasker, Pascal TaskSwitch
  95.                    ENDIF
  96.  
  97.  
  98.                    MACRO Begin            ; Standard entry code
  99.                      push bp
  100.                      mov bp, sp
  101.                    ENDM
  102.  
  103.                    MACRO Bend             ; Standard exit code
  104.                          mov sp, bp
  105.                          pop bp
  106.                          IFDEF CEE
  107.                            ret
  108.                          ELSE
  109.                            retf
  110.                          ENDIF
  111.                    ENDM
  112.  
  113.  
  114. ; Recognition codes
  115. None               =  0                ; No known multitasker
  116. TopView            =  1                ; generic TopView compatible detected
  117. TAME               =  2                ; generic TAME-controlled detected
  118. DESQview           =  3                ; DESQview
  119. MultiDOS2          =  4                ; MultiDOS II
  120. MultiDOS3          =  5                ; MultiDOS III
  121. DoubleDOS          =  6                ; DoubleDOS
  122. Windows2           =  7                ; Windows 2.xx or lower
  123. Windows3           =  8                ; Windows 3.xx
  124. OS2                =  9                ; OS/2's DOS Compatability Box
  125. ;ConDOS             = 10                ; ConcurrentDOS
  126. PCMOS              = 11                ; PC-MOS/386
  127. MultiLink          = 12                ; MultiLink
  128.  
  129.  
  130.                    CODESEG
  131.  
  132. WhichOne           DB 0                ; Which multitasker was found
  133. Detected           DB 0                ; Flag: set if DetectMultitasker has run
  134.  
  135.  
  136. ;; ******************** DetectMultitasker
  137. ;;
  138. ;; This attempts to detect which (if any) multitasker is currently active or is
  139. ;; loaded into the machine on which the host application is running on.
  140. ;;
  141. ;; As well, as returning the type of multitasker found, a record is kept
  142. ;; internally so as to automate the task-switching process.  This means that
  143. ;; if the application has no need of knowing what multitasker it is under, it
  144. ;; doesn't need to call DetectMultitasker, AT ALL!!  The first call to
  145. ;; TaskSwitch will automatically call DetectMultitasking for you.
  146. ;;
  147. ;; ********************
  148.  
  149.                    IFDEF CEE
  150.                      PROC DetectMultitasker NEAR
  151.                    ELSE
  152.                      PROC DetectMultitasker FAR
  153.                    ENDIF
  154.  
  155.                    Begin
  156.  
  157.                    mov ax, 2B01h                 ; --- Look for DESQview
  158.                    mov cx, 4445h                 ;  |
  159.                    mov dx, 5351h                 ;  |
  160.                    int 21h                       ;  |
  161.                    _if al NE 0FFh                ;  |
  162.                      mov al, DESQview            ;  +- FOUND
  163.                      jmp ExitDetect              ;  |
  164.                    _end                          ;  +- Not detected
  165.  
  166.                    mov ax, 4680h                 ; --- Look for Windows 3.xx
  167.                    int 2Fh                       ;  |
  168.                    _if ax E 0                    ;  |
  169.                      mov al, Windows3            ;  +- FOUND
  170.                      jmp ExitDetect              ;  |
  171.                    _end                          ;  +- Not detected
  172.  
  173.                    mov ax, 1600h                 ; --- Look for Windows 2.xx
  174.                    int 2Fh                       ;  |
  175.                    _if al NE 0 and al NE 80h     ;  |
  176.                      mov al, Windows2            ;  +- FOUND
  177.                      jmp short ExitDetect        ;  |
  178.                    _end                          ;  +- Not detected
  179.  
  180.                    mov ah, 30h                   ; --- Look for OS/2
  181.                    int 21                        ;  |
  182.                    _if al E 0Ah                  ;  |
  183.                      mov al, OS2                 ;  +- FOUND
  184.                      jmp short ExitDetect        ;  |
  185.                    _end                          ;  +- Not detected
  186.  
  187. ;                   mov ah, 30h                   ; --- Look for PC-MOS
  188. ;                   int 21                        ;  |
  189. ;                   push ax                       ;  |
  190. ;                   mov ax, 3000h                 ;  |
  191. ;                   mov bx, ax                    ;  |
  192. ;                   mov cx, ax                    ;  |
  193. ;                   mov dx, ax                    ;  |
  194. ;                   int 21h                       ;  |
  195. ;                   pop bx                        ;  |
  196. ;                   _if ax NE bx                  ;  |
  197. ;                     mov al, PCMOS               ;  +- FOUND
  198. ;                     jmp short ExitDetect        ;  |
  199. ;                   _end                          ;  +- Not detected
  200.  
  201. ;                  mov ax, 4451h                 ; --- Look for Concurrent DOS
  202. ;                  int 21                        ;  |
  203. ;                  _if CARRY                     ;  |
  204. ;                    mov al, ConDOS              ;  +- FOUND
  205. ;                    jmp short ExitDetect        ;  |
  206. ;                  _end                          ;  +- Not detected
  207.  
  208. ;                  mov ah, 0FFh                  ; --- Look for MultiDOS III
  209. ;                  int 14h                       ;  |
  210. ;                  _if ax E 564Dh or ax E 4D44h  ;  |
  211. ;                    mov al, MultiDOS3           ;  +- FOUND
  212. ;                    jmp short ExitDetect        ;  |
  213. ;                  _end                          ;  +- Not detected
  214.  
  215.                    mov ah, 35h                   ; --- Look for MultiDOS II
  216.                    mov al, 9Dh                   ;  |
  217.                    int 21h                       ;  |
  218.                    _if bx NE 0                   ;  |
  219.                      mov al, MultiDOS2           ;  +- FOUND
  220.                      jmp short ExitDetect        ;  |
  221.                    _end                          ;  +- Not detected
  222.  
  223.                    mov ah, 0E4h                  ; --- Look for DoubleDOS
  224.                    int 21h                       ;  |
  225.                    _if al E 01h or al E 02h      ;  |
  226.                      mov al, DoubleDOS           ;  +- FOUND
  227.                      jmp short ExitDetect        ;  |
  228.                    _end                          ;  +- Not detected
  229.  
  230.                    sub ax, ax                    ; --- Look for MultiLink
  231.                    mov ds, ax                    ;  |
  232.                    mov ax, [ds:01FEh]            ;  |
  233.                    _if ax NE 0                   ;  |
  234.                      mov al, MultiLink           ;  +- FOUND
  235.                      jmp short ExitDetect        ;  |
  236.                    _end                          ;  +- Not detected
  237.  
  238.                    mov ax, 1022h                 ; --- Look for TopView etc.
  239.                    xor bx, bx                    ;  |
  240.                    int 15h                       ;  |
  241.                    _if bx NE 0                   ;  |
  242.                      mov al, TopView             ;  +- FOUND
  243.                      jmp short ExitDetect        ;  |
  244.                    _end                          ;  +- Not detected
  245.  
  246.                    mov ax, 2B01h                 ; --- Look for TAME
  247.                    mov cx, 5441h                 ;  |
  248.                    mov dx, 4D45h                 ;  |
  249.                    int 21h                       ;  |
  250.                    _if al E 02h                  ;  |
  251.                      mov al, TAME                ;  +- FOUND
  252.                      jmp short ExitDetect        ;  |
  253.                    _end                          ;  +- Not detected
  254.  
  255.                    xor al, al                    ; Multitasker not found
  256.  
  257. ExitDetect:        mov [WhichOne], al            ; Record the multitasker found
  258.                    mov dl, 01h                   ; Detection has been run
  259.                    mov [Detected], dl            ; Record this in a flag
  260.  
  261.                    Bend
  262.  
  263.                    ENDP DetectMultitasker
  264.  
  265.  
  266. ;; ******************** TaskSwitch
  267. ;;
  268. ;; This executes appropriate task-switching (or time-slicing) code, depending
  269. ;; on which multitasker is currently active.  If DetectMultitasking hasn't
  270. ;; been called to determine the mutitasker type, then it is automatically
  271. ;; called by TaskSwitch so as to set some internal variables and flags.  This
  272. ;; automates and speeds the task-switching process, both for the programmer
  273. ;; and for the application at run-time.
  274. ;;
  275. ;; ********************
  276.  
  277.                    IFDEF CEE
  278.                      PROC TaskSwitch NEAR
  279.                    ELSE
  280.                      PROC TaskSwitch FAR
  281.                    ENDIF
  282.  
  283.                    Begin
  284.  
  285.                    mov al, [Detected]            ; Has detection been run?
  286.                    _if al E 0
  287.                      call DetectMultitasker      ; If not, call it
  288.                    _end
  289.  
  290.                    mov al, [Detected]            ; Based on the m'tasker found
  291.                    _switch al
  292.  
  293.                      _case TopView - DESQview    ; TopView (and compats.) and
  294.                        mov ax, 1000h             ; DESQview
  295.                        int 15h
  296.                        _if al E DESQview         ; Additional DESQview only
  297.                          mov ax, 101Ah
  298.                          int 15h
  299.                          mov ax, 1025h
  300.                          int 15h
  301.                        _end
  302.                      _break
  303.  
  304.                      _case Windows2 - OS2        ; Win2, Win3 and OS/2
  305.                        mov ax, 1680h
  306.                        int 2fh
  307.                      _break
  308.  
  309.                      _case PCMOS                 ; PC-MOS/386
  310.                        mov ax, 0703h
  311.                        mov bx, 3                 ; Give up three ticks
  312.                        xor cx, cx                ; Clear wait on IRQ mask
  313.                        mov dx, cx                ; Clear ports to wait on
  314.                        int 38h
  315.                      _break
  316.  
  317.                      _case MultiDOS2             ; MultiDOS II
  318.                        int  9Eh
  319.                      _break
  320.  
  321.                      _case MultiDOS3             ; MultiDOS III
  322.                        mov ax, 1100h             ; Give back 18 timer ticks
  323.                        mov cx, 0012h
  324.                        int 41h
  325.                      _break
  326.  
  327.                      _case DoubleDOS             ; DoubleDOS
  328.                        mov ax, 0EE06h            ; Give back 6 x 55ms
  329.                        int 21h
  330.                        int 0F4h                  ; Well, BinkleyTerm has it!
  331.                      _break
  332.  
  333.                      _case MultiLink             ; MultiLink
  334.                        mov ah, 02h
  335.                        xor al, al
  336.                        int 7Fh
  337.                      _break
  338.  
  339.                 _end
  340.  
  341.                 int 28h                          ; Generate Int 0x28 for TSRs
  342.  
  343.                 Bend
  344.  
  345.                 ENDP TaskSwitch
  346.  
  347.                 ENDS
  348.  
  349.                 _endsm86                         ; Completion of SM86 code
  350.  
  351.                 END
  352.