home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / DICT / DFKC / ZWH / CHCS / CHTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  11.9 KB  |  631 lines

  1. /*
  2.  * xtest.c
  3.  *
  4.  */
  5.  
  6. #pragma    inline
  7. #include   <stdio.h>
  8.  
  9. #define    Bool            unsigned char
  10. #define    True            1
  11. #define    False           0
  12.  
  13. #define    I8088           0x01
  14. #define    NECV20          0x02
  15. #define    I8086           0x03
  16. #define    NECV30          0x04
  17. #define    I80186          0x05
  18. #define    I80286          0x06
  19. #define    I80386SX        0x07
  20. #define    I80386DX        0x08
  21. #define    I80486SX        0x09
  22. #define    I80486DX        0x0a
  23.  
  24. #define    VGA             0x01      // Standard
  25. #define    TVGA            0x02      // Trident
  26. #define    PVGA            0x03      // Paradise
  27. #define    AVGA            0x04      // ATI
  28. #define    GVGA            0x05      // Geona
  29. #define    HVGA            0x06      // Chips
  30. #define    EVGA            0x07      // Tseng
  31.  
  32.    int     CPUtype, VGAtype, VRamSize,
  33.        BaseMem, FreeXMS, FreeEMS, FreeEXT;
  34.    Bool    FloppyA, FloppyB, Hard1, Hard2;
  35.    Bool    DosVerMajor, DosVerMinor;
  36.    int     CRTCindex;
  37.    char    CPUmsg[12][16] = {
  38.           "No",
  39.           "8088",
  40.           "NEC V20",
  41.           "8086",
  42.           "NEC V30",
  43.           "80186",
  44.           "80286",
  45.           "80386SX",
  46.           "80386DX",
  47.           "80486SX",
  48.           "80486"
  49.    };
  50.    char    VGAmsg[8][20] = {
  51.           "No VGA Card",
  52.           "Standard VGA",
  53.           "Trident Super VGA",
  54.           "Paradise Super VGA",
  55.           "ATI Super VGA",
  56.           "Geona Super VGA",
  57.           "Chips Super VGA",
  58.           "Tseng Super VGA"
  59.    };
  60.    char    FloppyMsg[5][6] = {
  61.           "No", "360K", "1.2M", "720K", "1.44M"
  62.    };
  63.  
  64.  
  65. Bool TestDOS()
  66. {
  67.    asm {
  68.        mov  ax, 3306h
  69.        int  21h
  70.        jc   dos5_
  71.        mov  ax, bx
  72.        jmp  dosOk
  73.    }
  74.    dos5_:
  75.    asm {
  76.        mov  ah, 30h
  77.        int  21h
  78.    }
  79.    dosOk:
  80.    asm {
  81.        mov  DosVerMajor, al
  82.        mov  DosVerMinor, ah
  83.    }
  84.    printf("DOS version     : %d.%02d\n", DosVerMajor, DosVerMinor);
  85.    if (DosVerMajor < 3 || DosVerMajor == 4) return False;
  86.    if (DosVerMajor == 3 && DosVerMinor < 1) return False;
  87.    return True;
  88. }
  89.  
  90. Bool TestCPU()
  91. {
  92.    Bool    Is86Series;
  93.  
  94.    asm {
  95.        push sp
  96.        pop  ax
  97.        cmp  ax, sp
  98.        jne  realModeCPU
  99.        pushf
  100.        pop  ax
  101.        or   ax, 4000h
  102.        push ax
  103.        popf
  104.        pushf
  105.        pop  ax
  106.        test ax, 4000h
  107.        jz   Is_80286
  108.        .386
  109.        pushfd
  110.        pushfd
  111.        pop  eax
  112.        xor  eax, 40000h
  113.        push eax
  114.        popfd
  115.        pushfd
  116.        pop  eax
  117.        popfd
  118.        test eax, 40000h
  119.        jz   Is_80386
  120.        jmp  Is_80486
  121.    }
  122.    Is_80186:
  123.    asm {
  124.       mov  CPUtype, I80186
  125.       jmp  prCPUtype
  126.    }
  127.    Is_80286:
  128.    asm {
  129.       mov  CPUtype, I80286
  130.       jmp  prCPUtype
  131.    }
  132.  
  133.    Is_80386:
  134.    asm {
  135.        .386p
  136.        mov  eax, cr0
  137.        mov  ebx, eax
  138.        xor  eax, 10h
  139.        mov  cr0, eax
  140.        mov  eax, cr0
  141.        mov  cr0, ebx
  142.        cmp  eax, ebx
  143.        jz   Is_80386SX
  144.        jmp  Is_80386DX
  145.        .8086
  146.    }
  147.    Is_80386SX:
  148.    asm {
  149.       mov   word ptr CPUtype, I80386SX
  150.       jmp   prCPUtype
  151.    }
  152.    Is_80386DX:
  153.    asm {
  154.       mov   word ptr CPUtype, I80386DX
  155.       jmp   prCPUtype
  156.    }
  157.    Is_80486:
  158.    asm {
  159.        mov  word ptr CPUtype, I80486DX
  160.        jmp  prCPUtype
  161.    }
  162.  
  163.    realModeCPU:
  164.    asm {
  165.        mov  cx, 21h
  166.        mov  al, 0ffh
  167.        shl  al, cl
  168.        jz   Not_80186
  169.        jmp  Is_80186
  170.    }
  171.    Not_80186:
  172.    asm {
  173.        lea  di, chk86
  174.        push di
  175.        mov  cx, 7
  176.        std
  177.        cli
  178.        mov  ax, 40h
  179.        push cx
  180.        rep  stosb
  181.        pop  cx
  182.        pop  di
  183.        mov  ax, 90h
  184.        rep  stosb
  185.        nop
  186.        nop
  187.        nop
  188.        nop
  189.        nop
  190.        nop
  191.        chk86 label byte
  192.        nop
  193.        cmp  ax, 94h
  194.        ja   Is86
  195.        mov  byte ptr Is86Series, 0
  196.        jmp  ContChk8x
  197.    }
  198.    Is86:
  199.    asm mov  byte ptr Is86Series, 1
  200.    ContChk8x:
  201.    asm {
  202.        sti
  203.        mov  cx, 0ffffh
  204.        push si
  205.        rep  lods byte ptr es:[si]
  206.        pop  si
  207.        or   cx, cx
  208.        jnz  Is_808x
  209.        jmp  Is_NecVx0
  210.    }
  211.    Is_808x:
  212.    if (Is86Series) CPUtype = I8086;
  213.    else            CPUtype = I8088;
  214.    goto prCPUtype;
  215.  
  216.    Is_NecVx0:
  217.    if (Is86Series) CPUtype = NECV30;
  218.    else            CPUtype = NECV20;
  219.  
  220.    prCPUtype:
  221.    printf("CPU type        : %s\n", CPUmsg[CPUtype]);
  222.    return True;
  223. }
  224.  
  225. Bool isVGA()
  226. {
  227.    asm {
  228.        mov  ax, 1a00h
  229.        int  10h
  230.        cmp  al, 1ah
  231.        je   cont0
  232.    }
  233.    return False;
  234.    cont0:
  235.    VGAtype = VGA;
  236.    asm {
  237.        push es
  238.        mov  ax, 40h
  239.        mov  es, ax
  240.        mov  dx, es:[63h]
  241.        mov  CRTCindex, dx
  242.        mov  al, es:[87h]
  243.        mov  cl, 5
  244.        shr  al, cl
  245.        and  al, 3
  246.        xor  ah, ah
  247.        mov  VRamSize, ax
  248.        pop  es
  249.  
  250.        cmp  dx, 3d4h
  251.        jne  Mono
  252.        jmp  Color
  253.    }
  254.    Mono:    return False;
  255.    Color:   return True;
  256. }
  257.  
  258. Bool isTridentSVGA()
  259. /*
  260.    OUT: (Hex)
  261.       00 --- not Trident
  262.       5B --- 800 x 600 Graphics mode code
  263. */
  264. {
  265. /*
  266.    asm {
  267.        mov  dx, 3c4h
  268.        mov  al, 0eh
  269.        out  dx, al
  270.        inc  dx
  271.        in   al, dx
  272.        mov  cl, al      // Save it
  273.        mov  al, 0
  274.        out  dx, al      // Write bit 1=0 all other bits 0
  275.        in   al, dx      // Read back
  276.        and  al, 0fh
  277.        mov  ch, al
  278.        mov  al, cl      // Restore old value
  279.        out  dx, al
  280.        cmp  ch, 02h
  281.        jne  isNot
  282.        jmp  isTrue
  283.    }
  284. */
  285.    asm {
  286.        mov  ax, 1200h
  287.        mov  bl, 11h
  288.        int  10h
  289.        cmp  al, 12h
  290.        jne  isNot
  291.        jmp  isTrue
  292.    }
  293.    isNot:   return 0;
  294.    isTrue:
  295.    asm {
  296.        mov  dx, 3c4h
  297.        mov  al, 1fh
  298.        out  dx, al
  299.        inc  dx
  300.        in   al, dx
  301.        and  al, 3
  302.        xor  ah, ah
  303.        mov  VRamSize, ax
  304.    }
  305.    VGAtype = TVGA;
  306.    return 0x5b;
  307. }
  308.  
  309. Bool isParadiseSVGA()
  310. /*
  311.    OUT: (Hex)
  312.       00 --- not Paradise
  313.       58 --- 800 x 600 Graphics mode code
  314. */
  315. {
  316.    static char sign[4] = "VGA=";
  317.  
  318.    asm {
  319.        mov  ax, 0c000h
  320.        mov  es, ax
  321.        mov  di, 007dh
  322.        mov  cx, 0004h
  323.        lea  si, sign
  324.        cld
  325.        repz cmpsb
  326.        jnz  isNot
  327.        jmp  isTrue
  328.    }
  329.    isNot:   return 0;
  330.    isTrue:
  331.    VGAtype = PVGA;
  332.    asm {
  333.        mov  dx, 3ceh
  334.        mov  al, 0bh
  335.        out  dx, al
  336.        inc  dx
  337.        in   al, dx
  338.        mov  cl, 6
  339.        shr  al, cl
  340.        cmp  al, 0
  341.        je   skipdec
  342.        cmp  al, 3
  343.        je   skipdec
  344.        dec  al
  345.    }
  346.    skipdec:
  347.    asm {
  348.        xor  ah, ah
  349.        mov  VRamSize, ax
  350.    }
  351.    return 0x58;
  352. }
  353.  
  354. Bool isATI_SVGA()
  355. /*
  356.    OUT: (Hex)
  357.       00 --- not Paradise
  358.       53/54 --- 800 x 600 Graphics mode code
  359. */
  360. {
  361.    static char sign[9] = "761295520";
  362.  
  363.    asm {
  364.        mov  ax, 0c000h
  365.        mov  es, ax
  366.        mov  di, 0031h   // c000:0031 --- ATI signature
  367.        mov  cx, 0009h
  368.        lea  si, sign
  369.        cld
  370.        repz cmpsb
  371.        jnz  isNot
  372.        jmp  isTrue
  373.    }
  374.    isNot:   return 0;
  375.    isTrue:  VGAtype = AVGA;  return 0x53;
  376. }
  377.  
  378. Bool isGenoaSVGA()
  379. /*
  380.    OUT: (Hex)
  381.       00 --- not Genoa
  382.       6A/79 --- 800 x 600 Graphics mode code
  383. */
  384. {
  385.    static char sign[4] = { 0x77, 0x11, 0x66, 0x99 };
  386.  
  387.    asm {
  388.        mov  ax, 0c000h
  389.        mov  es, ax
  390.        mov  di, 0037h   // c000:0037 -- Genoa signature
  391.        lea  si, sign
  392.        mov  al, [si]
  393.        cmp  al, es:[di]
  394.        jne  isNot
  395.        mov  al, [si+2]
  396.        cmp  al, es:[di+2]
  397.        jne  isNot
  398.        mov  al, [si+3]
  399.        cmp  al, es:[di+3]
  400.        jne  isNot
  401.        jmp  isTrue
  402.    }
  403.    isNot:   return 0;
  404.    isTrue:  VGAtype = GVGA;
  405.    return 0x6a;
  406. }
  407.  
  408. Bool isTsengSVGA()
  409. /*
  410.    OUT: (Hex)
  411.       00 --- not Tseng
  412.       30 --- 800 x 600 Graphics mode code
  413. */
  414. {
  415.    asm {
  416.        mov  dx, 3dah
  417.        in   al, dx
  418.        mov  dx, 3c0h
  419.        mov  al, 16h
  420.        out  dx, al
  421.        inc  dx
  422.        in   al, dx
  423.        mov  cl, al      // save it
  424.  
  425.        mov  dx, 3dah
  426.        in   al, dx
  427.        mov  dx, 3c0h
  428.        mov  al, 16h
  429.        out  dx, al
  430.        mov  al, cl
  431.        xor  al, 10h
  432.        mov  ch, al      // save it
  433.        out  dx, al
  434.  
  435.        mov  dx, 3dah
  436.        in   al, dx
  437.        mov  dx, 3c0h
  438.        mov  al, 16h
  439.        out  dx, al
  440.        inc  dx
  441.        in   al, dx
  442.        mov  ah, al      // save it
  443.  
  444.        mov  dx, 3dah
  445.        in   al, dx
  446.        mov  dx, 3c0h
  447.        mov  al, 16h
  448.        out  dx, al
  449.        mov  al, cl
  450.        out  dx, al
  451.  
  452.        cmp  ch, ah
  453.        jne  isNot
  454.        jmp  isTrue
  455.    }
  456.    isTrue:  VGAtype = EVGA;  return 0x30;
  457.    isNot:   return 0;
  458. }
  459.  
  460. /*
  461. Bool isChipsSVGA()
  462. //
  463.    OUT: (Hex)
  464.       00 --- not Chips
  465.        --- 800 x 600 Graphics mode code
  466. //
  467. {
  468.    asm {
  469.        mov  dx, 46e8h
  470.        mov  al, 1eh
  471.        out  dx, al
  472.        mov  dx, 104h
  473.        in   al, dx
  474. */
  475.  
  476. void TestVGA()
  477. {
  478.    if (! isVGA()) {
  479.       printf("xtest: Display Card not Supported !\n");
  480.       exit(0xff);
  481.    }
  482.    VRamSize ++;  VRamSize *= 64;
  483.    if (! isTridentSVGA())
  484.      if (! isParadiseSVGA())
  485.     if (! isGenoaSVGA()) isATI_SVGA();
  486.    if (VRamSize < 64) { VRamSize ++;  VRamSize *= 256; }
  487.    printf("Video Card Type : %s\n", VGAmsg[VGAtype]);
  488. }
  489.  
  490. void TestXMS()
  491. {
  492.    asm {
  493.        mov  ax, 4300h
  494.        int  2fh
  495.        cmp  al, 80h
  496.        jne  retn
  497.        push es
  498.        mov  ax, 4310h
  499.        int  2fh
  500.        mov  word ptr cs:XMSentry, bx
  501.        mov  word ptr cs:XMSentry+2, es
  502.        pop  es
  503.        mov  ah, 08h
  504.        call dword ptr cs:XMSentry
  505.        cmp  bl, 0
  506.        jne  retn
  507.        mov  FreeXMS, ax
  508.    }
  509.    if (FreeXMS) printf("Free XMS Memory : %d KB\n", FreeXMS);
  510.    retn:    return;
  511.    asm {
  512.        XMSentry  dd     ?
  513.    }
  514. }
  515.  
  516. void TestEMS()
  517. {
  518.    static char   EMMdevName[9] = "EMMXXXX0";
  519.  
  520.    asm {
  521.        push es
  522.        mov  ax, 3567h
  523.        int  21h
  524.        mov  di, 000ah
  525.        mov  si, offset EMMdevName
  526.        mov  cx, 8
  527.        cld
  528.        repz cmpsb
  529.        pop  es
  530.        jz   eCont0
  531.    }
  532.    retn:    return;
  533.    eCont0:
  534.    asm {
  535.        mov  ah, 42h
  536.        int  67h
  537.        or   ah, ah
  538.        jnz  retn
  539.        mov  cl, 4
  540.        shl  bx, cl
  541.        mov  FreeEMS, bx
  542.    }
  543.    if (FreeEMS) printf("Free EMS Memory : %d KB\n", FreeEMS);
  544. }
  545.  
  546. void TestEXT()
  547. {
  548.    asm {
  549.        mov  ah, 88h
  550.        int  15h
  551.        mov  FreeEXT, ax
  552.    }
  553.    if (FreeEXT) printf("Free EXT Memory : %d KB\n", FreeEXT);
  554. }
  555.  
  556. void TestFloppy()
  557. {
  558.    asm {
  559.        mov  al, 10h
  560.        out  70h, al
  561.        in   al, 71h
  562.        mov  ah, al
  563.        and  al, 0fh
  564.        mov  cl, 4
  565.        shr  ah, cl
  566.        mov  byte ptr FloppyA, ah
  567.        mov  byte ptr FloppyB, al
  568.    }
  569. /*   
  570.    if (FloppyA != 0)
  571.       printf("Floppy Drive A  : %s\n", FloppyMsg[FloppyA]);
  572.    if (FloppyB != 0)
  573.       printf("Floppy Drive B  : %s\n", FloppyMsg[FloppyB]);
  574. */
  575. }
  576.  
  577. void TestHardDriver()
  578. {
  579.    asm {
  580.        mov  al, 12h
  581.        out  70h, al
  582.        in   al, 71h
  583.        mov  ah, al
  584.        mov  cl, 4
  585.        shr  al, cl
  586.        cmp  al, 0fh
  587.        jne  skip0
  588.        mov  al, 19h
  589.        out  70h, al
  590.        in   al, 71h
  591.    }
  592.    skip0:
  593.    asm {
  594.        xchg ah, al
  595.        and  al, 0fh
  596.        cmp  al, 0fh
  597.        jne  skip1
  598.        mov  al, 1ah
  599.        out  70h, al
  600.        in   al, 71h
  601.    }
  602.    skip1:
  603.    asm {
  604.        mov  byte ptr Hard1, ah
  605.        mov  byte ptr Hard2, al
  606.    }
  607. /*
  608.    if (Hard1) printf("Hard Drive 1    : %d\n", Hard1);
  609.    if (Hard2) printf("Hard Drive 2    : %d\n", Hard2);
  610. */
  611. }
  612.  
  613. void main()
  614. {
  615.    if (! TestDOS()) {
  616.       printf("xtest: DOS Version not Supported !\n");
  617.       exit(0xff);
  618.    }
  619.    if (! TestCPU()) {
  620.       printf("xtest: CPU Type not Supported !\n");
  621.       exit(0xff);
  622.    }
  623.    TestVGA();
  624.    TestXMS();  TestEMS();  TestEXT();
  625.    TestFloppy();  TestHardDriver();
  626.    if (FreeXMS > 256) exit(0);       // Use XMS Memory
  627.    if (FreeEMS > 256) exit(1);       // Use EMS Memory
  628.    if (FreeEXT > 256) exit(2);       // Use EXT Memory
  629.    exit(3);                          // Use Cache
  630. }
  631.