home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / XLIB_TP5.ZIP / UNITS / X_DETECT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-16  |  10KB  |  293 lines

  1. unit X_detect;
  2. (*                                                                       *)
  3. (* ****** XLIB - Mode X graphics library                **************** *)
  4. (*                                                                       *)
  5. (* X_Dectect                                                             *)
  6. (*                                                                       *)
  7. (* Hardware detection module                                             *)
  8. (*                                                                       *)
  9. (* x_graphics,x_mousedriver       Written By Themie Gouthas              *)
  10. (* x_processor,x_coprocessor      Written By Martin Althaus (DOS 2'91)   *)
  11. (* Converted in TP                By Christian Harms                     *)
  12. (*                                                                       *)
  13. (* Gouthas : egg@dstos3.dsto.gov.au or teg@bart.dsto.gov.au              *)
  14. (* Harms   : harms@minnie.informatik.uni-stuttgart.de                    *)
  15. (*                                                                       *)
  16. (* Attention: x_coprocessor are irrespective of x_processor , because    *)
  17. (*            the following combinations are possible:                   *)
  18. (*                                                                       *)
  19. (*            8087   :  8086,8088,80186,80188                            *)
  20. (*            80287  :  80286,80386DX,80386SX                            *)
  21. (*            80387  :  80386,80486SX,(80486DX intern)                   *)
  22.  
  23.  
  24. interface
  25.  
  26. const pz8086    = 0    ;           (* Processor    *)
  27.       pz8088    = 1    ;
  28.       pzV20     = 2    ;
  29.       pzV30     = 3    ;
  30.       pz80186   = 4    ;
  31.       pz80188   = 5    ;
  32.       pz80286   = 6    ;
  33.       pz80386   = 7    ;
  34.       pz80486   = 8    ;
  35.  
  36.       cp_no     = 0    ;           (* Co-Processor *)
  37.       cp8087    = 1    ;
  38.       cp80287   = 2    ;
  39.       cp80387   = 3    ; (* He is in all 486DX ! *)
  40.  
  41.       NONE      = 0    ;           (* Video-Card   *)
  42.       MDA       = 1    ;
  43.       CGA       = 2    ;
  44.       EGAMono   = 3    ;
  45.       EGAColor  = 4    ;
  46.       VGAMono   = 5    ;
  47.       VGAColor  = 6    ;
  48.       MCGAMono  = 7    ;
  49.       MCGAColor = 8    ;
  50.  
  51.       BUS_MOUSE    = 1 ;           (* Mouse Driver *)
  52.       SERIAL_MOUSE = 2 ;
  53.       INPORT_MOUSE = 3 ;
  54.       PS2_MOUSE    = 4 ;
  55.       HP_MOUSE     = 5 ;
  56.  
  57.  
  58. var   MouseButtonCount,MouseVersion : Word;
  59.       MouseType,MouseIRQ            : Byte;
  60.  
  61. function x_graphics_card : Word;
  62. function x_mousedriver   : Boolean;
  63. function x_processor     : Word;
  64. function x_coprocessor   : Word;
  65.  
  66. (* Strings for constants of pzXXX,cpXXX and Video-Modes. *)
  67. const pzNames  : Array[0..8] of String[11] =
  68.         ('Intel 8086' ,'Intel 8088','NEC V20','NEC V30','Intel 80186','Intel 80188','Intel 80286','Intel 80386','Intel 80486');
  69.       (* Example : WriteLn('CPU :',pzNames[GetCPU]);        *)
  70.       cpNames  : Array[0..3] of String[11] =
  71.         ('none','Intel 8087','Intel 80287','Intel 80387');
  72.       VideoNames : Array[0..8] of String[10] =
  73.         ('NONE','MDA','CGA','EGA Mono','EGA Color','VGA Mono','VGA Color','MCGA Mono','MCGA Color');
  74.  
  75.  
  76. implementation
  77.  
  78. uses My_Asm;
  79.  
  80. const  PS2_CARDS : Array[0..12] of Byte = (0,1,2,2,4,3,2,5,6,2,8,7,8);
  81.  
  82. function x_graphics_card:Word;       assembler;
  83. asm
  84.     mov  ax,$1A00           (* Try calling VGA Identity Adapter function *)
  85.     int  10h
  86.     cmp  al,1Ah             (* Do we have PS/2 video bios ?             *)
  87.     jne  @@not_PS2          (* No!                                      *)
  88.  
  89.     cmp  bl,0Ch             (* bl > 0Ch => CGA hardware                 *)
  90.     jg   @@is_CGA           (* Jump if we have CGA                      *)
  91.     xor  bh,bh
  92.     xor  ah,ah
  93.     mov  al,ds:[offset PS2_CARDS+bx](* Load ax from PS/2 hardware table *)
  94.     jmp  @@done             (* return ax                                *)
  95. @@is_CGA:
  96.     mov  ax,CGA             (* Have detected CGA, return id             *)
  97.     jmp  @@done
  98. @@not_PS2:                      (* OK We don't have PS/2 Video bios         *)
  99.     mov  ah,12h             (* Set alternate function service           *)
  100.     mov  bx,10h             (* Set to return EGA information            *)
  101.     int  10h                (* call video service                       *)
  102.     cmp  bx,10h             (* Is EGA there ?                           *)
  103.     je   @@simple_adapter   (* Nop!                                     *)
  104.     mov  ah,12h             (* Since we have EGA bios, get details      *)
  105.     mov  bl,10h
  106.     int  10h
  107.     or   bh,bh              (* Do we have colour EGA ?                  *)
  108.     jz   @@ega_color        (* Yes                                      *)
  109.     mov  ax,EGAMono         (* Otherwise we have Mono EGA               *)
  110.     jmp  @@done
  111. @@ega_color:
  112.     mov  ax,EGAColor        (* Have detected EGA Color, return id       *)
  113.     jmp  @@done
  114. @@simple_adapter:
  115.     int  11h                (* Lets try equipment determination service *)
  116.     and  al,30h
  117.         mov  cl,4
  118.     shr  al,cl
  119.     xor  ah,ah
  120.     or   al,al              (* Do we have any graphics card at all ?    *)
  121.     jz   @@done             (* No ? This is a stupid machine!           *)
  122.     cmp  al,3               (* Do We have a Mono adapter                *)
  123.     jne  @@is_CGA           (* No                                       *)
  124.     mov  ax,MDA             (* Have detected MDA, return id             *)
  125. @@done:
  126. end;
  127.  
  128.  
  129. (*  Returns True, if mouse driver found, false otherwise.                   *)
  130. function x_mousedriver:Boolean;     assembler;
  131. asm
  132.            mov  ax,$3533       (* Get int 33 interrupt vector           *)
  133.            int  21h            (* Call dos                              *)
  134.            mov  cx,false       (* Clear "found" flag                    *)
  135.            mov  ax,es          (* Is the vector null (ES==0 && BX==0) ? *)
  136.            or   bx,ax
  137.            jz   @@NoMouseDriver(* Yes! No mouse driver installed - Jump *)
  138.  
  139.           (* Just make absolutely sure the vector points to the mouse   *)
  140.           (* driver (just in case)                                      *)
  141.  
  142.            xor  ax,ax          (* FUNC 0: Mouse Initialization          *)
  143.            int   33h
  144.            or    ax,ax         (* Do we have an installed mouse driver ?*)
  145.            jz    @@NoMouseDriver (* No ? *)
  146.            mov   MouseButtonCount,bx
  147.  
  148.            mov   ax,24h
  149.            int   33h
  150.            mov   MouseVersion,bx
  151.            mov   MouseType,ch
  152.            mov   MouseIRQ,cl
  153.  
  154.            mov  cx,true        (* Yes! set flag                         *)
  155.  
  156. @@NoMouseDriver:
  157.            mov  ax,cx          (* Return "found" flag                   *)
  158. end;
  159.  
  160. function x_processor:Word; assembler;
  161. label queue486; (* forward declaration necessary for TP *)
  162. asm
  163.     pushf
  164.     xor   bx,bx
  165.     push  bx
  166.     popf
  167.     pushf
  168.     pop   bx              (* get flags      *)
  169.     and   bx,$f000        (* higher 4 bits  *)
  170.     cmp   bx,$f000        (* all equal ?    *)
  171.     je   @No286_386
  172.     mov   dx,pz80386
  173.     mov   bx,$7000        (* set bits 12-14 *)
  174.     push  bx
  175.     popf
  176.     pushf
  177.     pop   bx              (* get flags      *)
  178.     and   bx,$7000        (* all bit = 0?   *)
  179.     jne  @it_is486
  180.     mov   dx,pz80286
  181.     jmp  @ende
  182. @it_is486:
  183.     xor   si,si
  184.     mov   byte ptr [cs:offset queue486+11],$46  (* $46 means <inc si> *)
  185. queue486:
  186.     db    $90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90,$90
  187.     cmp   si,0
  188.     jne  @ende
  189.     mov   dx,pz80486
  190.     jmp  @ende
  191. @No286_386:
  192.     mov   dx,pz80188
  193.     mov   al,$ff
  194.     mov   cl,$21
  195.     shr   al,cl
  196.     jne  @TestDatabus     (* difference between 80186 and 80188 *)
  197.     mov   dx,pzv20
  198.     sti
  199.     mov   si,0
  200.     mov   cx,$ffff
  201.     db    $F3,$26,$AC     (* => rep lods byte ptr es:[si]  , but TP-asm *)
  202.                           (* would not compile this expression :-(      *)
  203.     cmp   cx,0
  204.     je   @TestDatabus
  205.     mov   dx,pz8086       (* It's an 8086 or 8088               *)
  206. @TestDatabus:
  207.     push  cs
  208.     pop   es
  209.     xor   bx,bx
  210.     std
  211.     mov   al,$90
  212.     mov   cx,3
  213.  
  214.       pop   di
  215.       push  di
  216.       add   di,9
  217.  
  218.     cli
  219.     rep   stosb
  220.     cld
  221.     nop
  222.     nop
  223.     nop
  224.     inc   bx
  225.     nop
  226.     sti
  227.     cmp   bx,0
  228.     je   @ende
  229.     cmp   dx,pz8086
  230.     je   @it_is8088
  231.     cmp   dx,pzV20
  232.     je   @it_isV20
  233.     cmp   dx,pz80186
  234.     jne  @ende
  235.     mov   dx,pz80188
  236.     jmp  @ende
  237. @it_is8088:
  238.     mov   dx,pz8088
  239.     jmp  @ende
  240. @it_isV20:
  241.     mov   dx,pzV20
  242.     jmp  @ende
  243. @ende:
  244.     popf
  245.     mov ax,dx
  246. end;
  247.  
  248. (* Attention : TP make some changes on asm-code with coprozessor.          *)
  249. (* Therefor some asm-commands are as dw xx, so can't TP change coproz.- *)
  250. (* code. Tasm/Masm-friends can use the original-code in the comments.      *)
  251. function x_coprocessor:Word; assembler;
  252. label n1,n2;    (* forward declaration necessary for TP *)
  253. var cputest:Word;
  254. asm;
  255.       mov    dx,cp_no
  256.       mov    byte ptr [cs:offset n1],$90 (* If no Coproz., wait can make trouble. *)
  257.       mov    byte ptr [cs:offset n2],$90
  258. n1:   wait       (* ! <wait> would automaticly insert by Tasm/Masm ! -> If  *)
  259.                  (* you want to use this code in really asm-code, you should*)
  260.                  (* remove all wait-commands in this source-code.           *)
  261.                  (* ASM-Freaks: <;> is here not the begin of a comment !    *)
  262.       fninit
  263.       mov    byte ptr [offset cputest+1],0
  264. n2:   wait
  265.       fnstcw word ptr [offset cputest]
  266.       mov    ah,byte ptr [offset cputest+1]
  267.       cmp    ah,3
  268.       jne   @cpende
  269.       mov    dx,8087
  270.       and    cputest,$ff7f
  271.  wait;dw _fldcw,Offset Cputest (* fldcw word ptr [offset cputest] *)
  272.  wait;fndisi
  273.  wait;fnstcw word ptr [offset cputest]
  274.       test   cputest,$80
  275.       jne   @cpende
  276.       mov    dx,cp80287
  277.  wait;fninit
  278.  wait;dw _fld1                 (*  fld1             *)
  279.  wait;dw _fldz                 (*  fldz             *)
  280.  wait;dw _fdivp                (*  fdivp st(1),st   *)
  281.  wait;dw _fld                  (*  fld   st(0)      *)
  282.  wait;dw _fchs                 (*  fchs             *)
  283.  wait;dw _fcompp               (*  fcompp           *)
  284.  wait;fnstcw word ptr [offset cputest]
  285.       mov    ax,cputest
  286.  wait;sahf
  287.       je    @cpende
  288.       mov    dx,cp80387
  289. @cpende:
  290.       mov    ax,dx
  291. end;
  292.  
  293. end.