home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / MTASK211 / MTASK.ASM < prev    next >
Assembly Source File  |  1991-05-11  |  14KB  |  355 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.1 -- MASM 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. ; NOTE: Ive had to back out the PCMOS code cause it dosent seem to work
  75. ;       properly yet..
  76. ;       Anthony..
  77.  
  78.  
  79.                    INCLUDE SM86.INC       ; Use SM86 macro package
  80.  
  81.                    TITLE "MTASK OFFICIAL RELEASE 2.01"
  82.                    SUBTTL "Using Joe Moldovan's SM86 v1.10"
  83.  
  84.                    .sm86 LIST             ; Begin SM86 code
  85.  
  86.  
  87.                    IFDEF CEE
  88.                      DOSSEG               ; Use DOS segment ordering
  89.                      IFNDEF MEMORY
  90.                        MODEL small        ; Small memory model is default
  91.                      ELSE
  92.                        MODEL MEMORY       ; Use memory model programmer wants
  93.                      ENDIF
  94.                      PUBLIC C DetectMultitasker, C TaskSwitch
  95.                    ELSE
  96.                      MODEL TPascal        ; Use Turbo Pascal memory model
  97.                      PUBLIC Pascal DetectMultitasker, Pascal TaskSwitch
  98.                    ENDIF
  99.  
  100.  
  101. Begin              MACRO                  ; Standard entry code
  102.                      push bp
  103.                      mov bp, sp
  104.                    ENDM
  105.  
  106. Bend               MACRO                  ; Standard exit code
  107.                          mov sp, bp
  108.                          pop bp
  109.                          IFDEF CEE
  110.                            ret
  111.                          ELSE
  112.                            retf
  113.                          ENDIF
  114.                    ENDM
  115.  
  116.  
  117. ; Recognition codes
  118. None               =  0                ; No known multitasker
  119. TopView            =  1                ; generic TopView compatible detected
  120. TAME               =  2                ; generic TAME-controlled detected
  121. DESQview           =  3                ; DESQview
  122. MultiDOS2          =  4                ; MultiDOS II
  123. MultiDOS3          =  5                ; MultiDOS III
  124. DoubleDOS          =  6                ; DoubleDOS
  125. Windows2           =  7                ; Windows 2.xx or lower
  126. Windows3           =  8                ; Windows 3.xx
  127. OS2                =  9                ; OS/2's DOS Compatability Box
  128. ;ConDOS             = 10                ; ConcurrentDOS
  129. PCMOS              = 11                ; PC-MOS/386
  130. MultiLink          = 12                ; MultiLink
  131.  
  132.  
  133.                    CODESEG
  134.  
  135. WhichOne           DB 0                ; Which multitasker was found
  136. Detected           DB 0                ; Flag: set if DetectMultitasker has run
  137.  
  138.  
  139. ;; ******************** DetectMultitasker
  140. ;;
  141. ;; This attempts to detect which (if any) multitasker is currently active or is
  142. ;; loaded into the machine on which the host application is running on.
  143. ;;
  144. ;; As well, as returning the type of multitasker found, a record is kept
  145. ;; internally so as to automate the task-switching process.  This means that
  146. ;; if the application has no need of knowing what multitasker it is under, it
  147. ;; doesn't need to call DetectMultitasker, AT ALL!!  The first call to
  148. ;; TaskSwitch will automatically call DetectMultitasking for you.
  149. ;;
  150. ;; ********************
  151.  
  152.                    IFDEF CEE
  153.                      DetectMultitasker PROC NEAR
  154.                    ELSE
  155.                      DetectMultitasker PROC FAR
  156.                    ENDIF
  157.  
  158.                    Begin
  159.  
  160.                    mov ax, 2B01h                 ; --- Look for DESQview
  161.                    mov cx, 4445h                 ;  |
  162.                    mov dx, 5351h                 ;  |
  163.                    int 21h                       ;  |
  164.                    .if al NE 0FFh                ;  |
  165.                      mov al, DESQview            ;  +- FOUND
  166.                      jmp ExitDetect              ;  |
  167.                    .end                          ;  +- Not detected
  168.  
  169.                    mov ax, 4680h                 ; --- Look for Windows 3.xx
  170.                    int 2Fh                       ;  |
  171.                    .if ax E 0                    ;  |
  172.                      mov al, Windows3            ;  +- FOUND
  173.                      jmp ExitDetect              ;  |
  174.                    .end                          ;  +- Not detected
  175.  
  176.                    mov ax, 1600h                 ; --- Look for Windows 2.xx
  177.                    int 2Fh                       ;  |
  178.                    .if al NE 0 and al NE 80h     ;  |
  179.                      mov al, Windows2            ;  +- FOUND
  180.                      jmp short ExitDetect        ;  |
  181.                    .end                          ;  +- Not detected
  182.  
  183.                    mov ah, 30h                   ; --- Look for OS/2
  184.                    int 21                        ;  |
  185.                    .if al E 0Ah                  ;  |
  186.                      mov al, OS2                 ;  +- FOUND
  187.                      jmp short ExitDetect        ;  |
  188.                    .end                          ;  +- Not detected
  189.  
  190. ;                   mov ah, 30h                   ; --- Look for PC-MOS
  191. ;                   int 21                        ;  |
  192. ;                   push ax                       ;  |
  193. ;                   mov ax, 3000h                 ;  |
  194. ;                   mov bx, ax                    ;  |
  195. ;                   mov cx, ax                    ;  |
  196. ;                   mov dx, ax                    ;  |
  197. ;                   int 21h                       ;  |
  198. ;                   pop bx                        ;  |
  199. ;                   .if ax E bx                   ;  |
  200. ;                     mov al, PCMOS               ;  +- FOUND
  201. ;                     jmp short ExitDetect        ;  |
  202. ;                   .end                          ;  +- Not detected
  203.  
  204. ;                  mov ax, 4451h                 ; --- Look for Concurrent DOS
  205. ;                  int 21                        ;  |
  206. ;                  .if CARRY                     ;  |
  207. ;                    mov al, ConDOS              ;  +- FOUND
  208. ;                    jmp short ExitDetect        ;  |
  209. ;                  .end                          ;  +- Not detected
  210.  
  211. ;                  mov ah, 0FFh                  ; --- Look for MultiDOS III
  212. ;                  int 14h                       ;  |
  213. ;                  .if ax E 564Dh or ax E 4D44h  ;  |
  214. ;                    mov al, MultiDOS3           ;  +- FOUND
  215. ;                    jmp short ExitDetect        ;  |
  216. ;                  .end                          ;  +- Not detected
  217.  
  218.                    mov ah, 35h                   ; --- Look for MultiDOS II
  219.                    mov al, 9Dh                   ;  |
  220.                    int 21h                       ;  |
  221.                    .if bx NE 0                   ;  |
  222.                      mov al, MultiDOS2           ;  +- FOUND
  223.                      jmp short ExitDetect        ;  |
  224.                    .end                          ;  +- Not detected
  225.  
  226.                    mov ah, 0E4h                  ; --- Look for DoubleDOS
  227.                    int 21h                       ;  |
  228.                    .if al E 01h or al E 02h      ;  |
  229.                      mov al, DoubleDOS           ;  +- FOUND
  230.                      jmp short ExitDetect        ;  |
  231.                    .end                          ;  +- Not detected
  232.  
  233.                    sub ax, ax                    ; --- Look for MultiLink
  234.                    mov ds, ax                    ;  |
  235.                    mov ax, [ds:01FEh]            ;  |
  236.                    .if ax NE 0                   ;  |
  237.                      mov al, MultiLink           ;  +- FOUND
  238.                      jmp short ExitDetect        ;  |
  239.                    .end                          ;  +- Not detected
  240.  
  241.                    mov ax, 1022h                 ; --- Look for TopView etc.
  242.                    xor bx, bx                    ;  |
  243.                    int 15h                       ;  |
  244.                    .if bx NE 0                   ;  |
  245.                      mov al, TopView             ;  +- FOUND
  246.                      jmp short ExitDetect        ;  |
  247.                    .end                          ;  +- Not detected
  248.  
  249.                    mov ax, 2B01h                 ; --- Look for TAME
  250.                    mov cx, 5441h                 ;  |
  251.                    mov dx, 4D45h                 ;  |
  252.                    int 21h                       ;  |
  253.                    .if al E 02h                  ;  |
  254.                      mov al, TAME                ;  +- FOUND
  255.                      jmp short ExitDetect        ;  |
  256.                    .end                          ;  +- Not detected
  257.  
  258.                    xor al, al                    ; Multitasker not found
  259.  
  260. ExitDetect:        mov [WhichOne], al            ; Record the multitasker found
  261.                    mov dl, 01h                   ; Detection has been run
  262.                    mov [Detected], dl            ; Record this in a flag
  263.  
  264.                    Bend
  265.  
  266. DetectMultitasker  ENDP
  267.  
  268.  
  269. ;; ******************** TaskSwitch
  270. ;;
  271. ;; This executes appropriate task-switching (or time-slicing) code, depending
  272. ;; on which multitasker is currently active.  If DetectMultitasking hasn't
  273. ;; been called to determine the mutitasker type, then it is automatically
  274. ;; called by TaskSwitch so as to set some internal variables and flags.  This
  275. ;; automates and speeds the task-switching process, both for the programmer
  276. ;; and for the application at run-time.
  277. ;;
  278. ;; ********************
  279.  
  280.                    IFDEF CEE
  281.                      TaskSwitch PROC NEAR
  282.                    ELSE
  283.                      TaskSwitch PROC FAR
  284.                    ENDIF
  285.  
  286.                    Begin
  287.  
  288.                    mov al, [Detected]            ; Has detection been run?
  289.                    .if al E 0
  290.                      call DetectMultitasker      ; If not, call it
  291.                    .end
  292.  
  293.                    mov al, [Detected]            ; Based on the m'tasker found
  294.                    .switch al
  295.  
  296.                      .case TopView - DESQview    ; TopView (and compats.) and
  297.                        mov ax, 1000h             ; DESQview
  298.                        int 15h
  299.                        .if al E DESQview         ; Additional DESQview only
  300.                          mov ax, 101Ah
  301.                          int 15h
  302.                          mov ax, 1025h
  303.                          int 15h
  304.                        .end
  305.                      .break
  306.  
  307.                      .case Windows2 - OS2        ; Win2, Win3 and OS/2
  308.                        mov ax, 1680h
  309.                        int 2fh
  310.                      .break
  311.  
  312.                      .case PCMOS                 ; PC-MOS/386
  313.                        mov ax, 0703h
  314.                        mov bx, 3                 ; Give up three ticks
  315.                        xor cx, cx                ; Clear wait on IRQ mask
  316.                        mov dx, cx                ; Clear ports to wait on
  317.                        int 38h
  318.                      .break
  319.  
  320.                      .case MultiDOS2             ; MultiDOS II
  321.                        int  9Eh
  322.                      .break
  323.  
  324.                      .case MultiDOS3             ; MultiDOS III
  325.                        mov ax, 1100h             ; Give back 18 timer ticks
  326.                        mov cx, 0012h
  327.                        int 41h
  328.                      .break
  329.  
  330.                      .case DoubleDOS             ; DoubleDOS
  331.                        mov ax, 0EE06h            ; Give back 6 x 55ms
  332.                        int 21h
  333.                        int 0F4h                  ; Well, BinkleyTerm has it!
  334.                      .break
  335.  
  336.                      .case MultiLink             ; MultiLink
  337.                        mov ah, 02h
  338.                        xor al, al
  339.                        int 7Fh
  340.                      .break
  341.  
  342.                 .end
  343.  
  344.                 int 28h                          ; Generate Int 0x28 for TSRs
  345.  
  346.                 Bend
  347.  
  348. TaskSwitch      ENDP
  349.  
  350.                 ENDS
  351.  
  352.                 .endsm86                         ; Completion of SM86 code
  353.  
  354.                 END
  355.