home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  5.5 KB  |  277 lines

  1. // SYSTEM.H
  2. // (C) Anubis Software Noviembre 1994
  3. // Con la especial colaboración de todo el ShareWare del mundo
  4. // De todo corazón (Gracias)
  5. // NOTA:(!!!  MUY IMPORTANTE  !!!) esta librería debe compilarse con
  6. // el procesador 386 como mínimo. Sino dará un bonito error
  7. #ifndef SYSTEM.H
  8. #define SYSTEM.H
  9.  
  10. #include <conio.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #pragma inline
  15.  
  16. unsigned int test_cpu(void)
  17. {
  18.    unsigned char i,ii,iii,iiii;
  19.    unsigned int total;
  20.    asm cli
  21.  
  22.    asm mov al,34h
  23.    asm out 43h,al
  24.  
  25.    asm xor al,al
  26.    asm out 40h,al
  27.    asm out 40h,al
  28.  
  29.    asm sti
  30.  
  31.    asm mov cx,1000h
  32. here:
  33.    asm dec cx
  34.    asm jnz here
  35.  
  36.    asm cli
  37.  
  38.    asm mov al,4h
  39.    asm out 43h,al
  40.  
  41.    asm in al,40h
  42.    asm mov dl,al
  43.    asm in al,40h
  44.    asm mov dh,al
  45.  
  46.    asm sti
  47.  
  48.    asm neg dx
  49.  
  50.    asm mov cl,dh
  51.    asm and cl,11110000b
  52.    asm shr cl,4
  53.    asm mov iiii,cl
  54.  
  55.    asm mov cl,dh
  56.    asm and cl,00001111b
  57.    asm mov iii,cl
  58.  
  59.    asm mov cl,dl
  60.    asm and cl,11110000b
  61.    asm shr cl,4
  62.    asm mov ii,cl
  63.  
  64.    asm mov cl,dl
  65.    asm and cl,00001111b
  66.    asm mov i,cl
  67.  
  68.    total=i |(ii<<4)|(iii<<8)|(iiii<<12);
  69.    return(total);
  70. }// end test cpu
  71.  
  72. // Esta rutina (adaptada por mí, devuelve un valor entre 0 y 8
  73. // correspondiendo los siguientes tipos:
  74. // 0 -> 8088
  75. // 1 -> 8086
  76. // 2 -> NEC V20
  77. // 3 -> NEC V30
  78. // 4 -> 80188
  79. // 5 -> 80186
  80. // 6 -> 80286
  81. // 7 -> 80386
  82. // 8 -> 80486
  83. unsigned int procesador(void)
  84. {
  85.    unsigned int cpu;
  86.  
  87.    asm pushf
  88.    asm push ds
  89.    asm push es
  90.    asm push cx
  91.    asm push dx
  92.    asm push di
  93.    asm push si
  94.    asm mov ax,cs
  95.    asm mov ds,ax
  96.    asm mov es,ax
  97.    asm mov dl,6
  98.    asm pushf
  99.    asm pop ax
  100.    asm and ax,0FFFh
  101.    asm push ax
  102.    asm popf
  103.    asm pushf
  104.    asm pop ax
  105.    asm and ax,0F000h
  106.    asm cmp ax,0f000h
  107.    asm je ni286ni_super
  108.    asm pushf
  109.    asm pop ax
  110.    asm or ax,7000h
  111.    asm push ax
  112.    asm popf
  113.    asm pushf
  114.    asm pop ax
  115.    asm and ax,7000h
  116.    asm jz cpu_hallada
  117.    asm inc dl
  118.    asm push dx
  119.    asm cli
  120.    asm mov edx,esp
  121.    asm and esp,0FFFFh
  122.    asm and esp,0FFFCh
  123.    asm pushfd
  124.    asm pop eax
  125.    asm mov ecx,eax
  126.    asm xor eax,40000h
  127.    asm push eax
  128.    asm popfd
  129.    asm pushfd
  130.    asm pop eax
  131.    asm xor eax,ecx
  132.    asm shr eax,12h
  133.    asm and eax,1
  134.    asm push ecx
  135.    asm popfd
  136.    asm mov esp,edx
  137.    asm sti
  138.    asm pop dx
  139.    asm cmp ax,0
  140.    asm je cpu_hallada
  141.    asm inc dl
  142.    asm jmp cpu_hallada
  143. ni286ni_super:
  144.    asm mov dl,4
  145.    asm mov ax,0FFFFh
  146.    asm mov cl,33
  147.    asm shl ax,cl
  148.    asm jnz tipo_bus_proc
  149.    asm mov dl,2
  150.    asm mov cx,0FFFFh
  151.    asm sti
  152.    asm repz lodsb
  153.    asm jcxz tipo_bus_proc
  154.    asm xor dl,dl
  155. tipo_bus_proc:
  156. cpu_hallada:
  157.    asm mov al,dl
  158.    asm xor ah,ah
  159.    asm pop si
  160.    asm pop di
  161.    asm pop dx
  162.    asm pop cx
  163.    asm pop es
  164.    asm pop ds
  165.    asm popf
  166.    asm mov cpu,ax
  167.    return(cpu);
  168. }// end procesador
  169.  
  170.  
  171.  
  172. // Esta función debe devolver si la tarjeta instalad es una TRIDENT
  173. // Se basa en el archivo TRIDENT.TXT de las PCGPE.
  174. // Pero desgraciadamente no funciona asi como esperaba
  175. // y se cuelga.
  176. unsigned char trident(void)
  177. {
  178.    unsigned char valor,valor1,valor2;
  179.  
  180.    asm mov dx,3C4h     // Cogemos el valor del 3C4h
  181.    asm in  al,dx
  182.    asm mov valor,al
  183.  
  184. //   asm mov dx,3C5h     // Cogemos el valor del 3C5h
  185. //   asm in ax,dx
  186. //   asm mov valor1,ax
  187.  
  188.    asm mov al,0Eh      // Ponemos 0Eh en 3C4h
  189.    asm mov dx,3C4h
  190.    asm out dx,al
  191.  
  192. //   asm mov ax,00h     // Ponemos 00h en 3C5h
  193. //   asm mov dx,3C5h
  194. //   asm out dx,ax
  195.  
  196.    asm mov dx,3C5h      //Cogemos el valor de 3C5h
  197.    asm in  al,dx
  198.    asm mov valor2,al
  199.  
  200. //   asm mov ax,valor1   // Restablecemos el valor de 3C5h
  201. //   asm mov dx,3C5h
  202. //   asm out dx,ax
  203.  
  204.    asm mov al,valor     // Restablecemos el valor de 3C4h
  205.    asm mov dx,3C4h
  206.    asm out dx,al
  207.  
  208.    return(valor2>=1);
  209. }// end trident
  210.  
  211. // Esta función, determina que chip de la trident está instalado
  212. // si el valor devuelto es >=3 es el chip 8900
  213. // si no es el chip 8800
  214. unsigned int trident_chip(void)
  215. {
  216.    unsigned char valor,valor1,valor2;
  217.  
  218.    asm mov dx,3C4h     // Cogemos el valor del 3C4h
  219.    asm in  al,dx
  220.    asm mov valor,al
  221.  
  222.    asm mov dx,3C5h     // Cogemos el valor del 3C5h
  223.    asm in al,dx
  224.    asm mov valor1,al
  225.  
  226.    asm mov dx,3C4h     // Ponemos 0B$ en 3C4h
  227.    asm mov al,0Bh
  228.    asm out dx,al
  229.  
  230.    asm mov dx,3C5h     // Ponemos 00h en 3C5h
  231.    asm mov al,00h
  232.    asm out dx,al
  233.  
  234.    asm mov dx,3C5h     // Cogemos el valor que nos interesa
  235.    asm in  al,dx
  236.    asm mov valor2,al
  237.  
  238.    asm mov al,valor1   // Restablecemos el valor de 3C5h
  239.    asm mov dx,3C5h
  240.    asm out dx,al
  241.  
  242.    asm mov al,valor     // Restablecemos el valor de 3C4h
  243.    asm mov dx,3C4h
  244.    asm out dx,al
  245.    if(valor2>=3) return(8900);
  246.    else return(8800);
  247. }// end trident_chip
  248.  
  249.  
  250.  
  251. int main(void)
  252. {
  253.    int a;
  254.    char cadena[10];
  255.    a=procesador();
  256.    switch (a) {
  257.       case 0:{strcpy(cadena,"8088");break;}
  258.       case 1:{strcpy(cadena,"8086");break;}
  259.       case 2:{strcpy(cadena,"NEC V20");break;}
  260.       case 3:{strcpy(cadena,"NEC V30");break;}
  261.       case 4:{strcpy(cadena,"80188");break;}
  262.       case 5:{strcpy(cadena,"80186");break;}
  263.       case 6:{strcpy(cadena,"80286");break;}
  264.       case 7:{strcpy(cadena,"80386");break;}
  265.       case 8:{strcpy(cadena,"80486");}
  266.    }// end switch
  267.    printf("\nProcesador: %s",cadena);
  268.    a=test_cpu();
  269.    printf("\nSpeed Test: %X %d",a,a);
  270.    a=trident();
  271.    printf("\nTarjeta TRIDENT : %d",a);
  272.    a=trident_chip();
  273.    printf("\nChip de la tarjeta TRIDENT : %d",a);
  274.    return(0);
  275. }// end main
  276.  
  277. #endif