home *** CD-ROM | disk | FTP | other *** search
- /*
- * xtest.c
- *
- */
-
- #pragma inline
- #include <stdio.h>
-
- #define Bool unsigned char
- #define True 1
- #define False 0
-
- #define I8088 0x01
- #define NECV20 0x02
- #define I8086 0x03
- #define NECV30 0x04
- #define I80186 0x05
- #define I80286 0x06
- #define I80386SX 0x07
- #define I80386DX 0x08
- #define I80486SX 0x09
- #define I80486DX 0x0a
-
- #define VGA 0x01 // Standard
- #define TVGA 0x02 // Trident
- #define PVGA 0x03 // Paradise
- #define AVGA 0x04 // ATI
- #define GVGA 0x05 // Geona
- #define HVGA 0x06 // Chips
- #define EVGA 0x07 // Tseng
-
- int CPUtype, VGAtype, VRamSize,
- BaseMem, FreeXMS, FreeEMS, FreeEXT;
- Bool FloppyA, FloppyB, Hard1, Hard2;
- Bool DosVerMajor, DosVerMinor;
- int CRTCindex;
- char CPUmsg[12][16] = {
- "No",
- "8088",
- "NEC V20",
- "8086",
- "NEC V30",
- "80186",
- "80286",
- "80386SX",
- "80386DX",
- "80486SX",
- "80486"
- };
- char VGAmsg[8][20] = {
- "No VGA Card",
- "Standard VGA",
- "Trident Super VGA",
- "Paradise Super VGA",
- "ATI Super VGA",
- "Geona Super VGA",
- "Chips Super VGA",
- "Tseng Super VGA"
- };
- char FloppyMsg[5][6] = {
- "No", "360K", "1.2M", "720K", "1.44M"
- };
-
-
- Bool TestDOS()
- {
- asm {
- mov ax, 3306h
- int 21h
- jc dos5_
- mov ax, bx
- jmp dosOk
- }
- dos5_:
- asm {
- mov ah, 30h
- int 21h
- }
- dosOk:
- asm {
- mov DosVerMajor, al
- mov DosVerMinor, ah
- }
- printf("DOS version : %d.%02d\n", DosVerMajor, DosVerMinor);
- if (DosVerMajor < 3 || DosVerMajor == 4) return False;
- if (DosVerMajor == 3 && DosVerMinor < 1) return False;
- return True;
- }
-
- Bool TestCPU()
- {
- Bool Is86Series;
-
- asm {
- push sp
- pop ax
- cmp ax, sp
- jne realModeCPU
- pushf
- pop ax
- or ax, 4000h
- push ax
- popf
- pushf
- pop ax
- test ax, 4000h
- jz Is_80286
- .386
- pushfd
- pushfd
- pop eax
- xor eax, 40000h
- push eax
- popfd
- pushfd
- pop eax
- popfd
- test eax, 40000h
- jz Is_80386
- jmp Is_80486
- }
- Is_80186:
- asm {
- mov CPUtype, I80186
- jmp prCPUtype
- }
- Is_80286:
- asm {
- mov CPUtype, I80286
- jmp prCPUtype
- }
-
- Is_80386:
- asm {
- .386p
- mov eax, cr0
- mov ebx, eax
- xor eax, 10h
- mov cr0, eax
- mov eax, cr0
- mov cr0, ebx
- cmp eax, ebx
- jz Is_80386SX
- jmp Is_80386DX
- .8086
- }
- Is_80386SX:
- asm {
- mov word ptr CPUtype, I80386SX
- jmp prCPUtype
- }
- Is_80386DX:
- asm {
- mov word ptr CPUtype, I80386DX
- jmp prCPUtype
- }
- Is_80486:
- asm {
- mov word ptr CPUtype, I80486DX
- jmp prCPUtype
- }
-
- realModeCPU:
- asm {
- mov cx, 21h
- mov al, 0ffh
- shl al, cl
- jz Not_80186
- jmp Is_80186
- }
- Not_80186:
- asm {
- lea di, chk86
- push di
- mov cx, 7
- std
- cli
- mov ax, 40h
- push cx
- rep stosb
- pop cx
- pop di
- mov ax, 90h
- rep stosb
- nop
- nop
- nop
- nop
- nop
- nop
- chk86 label byte
- nop
- cmp ax, 94h
- ja Is86
- mov byte ptr Is86Series, 0
- jmp ContChk8x
- }
- Is86:
- asm mov byte ptr Is86Series, 1
- ContChk8x:
- asm {
- sti
- mov cx, 0ffffh
- push si
- rep lods byte ptr es:[si]
- pop si
- or cx, cx
- jnz Is_808x
- jmp Is_NecVx0
- }
- Is_808x:
- if (Is86Series) CPUtype = I8086;
- else CPUtype = I8088;
- goto prCPUtype;
-
- Is_NecVx0:
- if (Is86Series) CPUtype = NECV30;
- else CPUtype = NECV20;
-
- prCPUtype:
- printf("CPU type : %s\n", CPUmsg[CPUtype]);
- return True;
- }
-
- Bool isVGA()
- {
- asm {
- mov ax, 1a00h
- int 10h
- cmp al, 1ah
- je cont0
- }
- return False;
- cont0:
- VGAtype = VGA;
- asm {
- push es
- mov ax, 40h
- mov es, ax
- mov dx, es:[63h]
- mov CRTCindex, dx
- mov al, es:[87h]
- mov cl, 5
- shr al, cl
- and al, 3
- xor ah, ah
- mov VRamSize, ax
- pop es
-
- cmp dx, 3d4h
- jne Mono
- jmp Color
- }
- Mono: return False;
- Color: return True;
- }
-
- Bool isTridentSVGA()
- /*
- OUT: (Hex)
- 00 --- not Trident
- 5B --- 800 x 600 Graphics mode code
- */
- {
- /*
- asm {
- mov dx, 3c4h
- mov al, 0eh
- out dx, al
- inc dx
- in al, dx
- mov cl, al // Save it
- mov al, 0
- out dx, al // Write bit 1=0 all other bits 0
- in al, dx // Read back
- and al, 0fh
- mov ch, al
- mov al, cl // Restore old value
- out dx, al
- cmp ch, 02h
- jne isNot
- jmp isTrue
- }
- */
- asm {
- mov ax, 1200h
- mov bl, 11h
- int 10h
- cmp al, 12h
- jne isNot
- jmp isTrue
- }
- isNot: return 0;
- isTrue:
- asm {
- mov dx, 3c4h
- mov al, 1fh
- out dx, al
- inc dx
- in al, dx
- and al, 3
- xor ah, ah
- mov VRamSize, ax
- }
- VGAtype = TVGA;
- return 0x5b;
- }
-
- Bool isParadiseSVGA()
- /*
- OUT: (Hex)
- 00 --- not Paradise
- 58 --- 800 x 600 Graphics mode code
- */
- {
- static char sign[4] = "VGA=";
-
- asm {
- mov ax, 0c000h
- mov es, ax
- mov di, 007dh
- mov cx, 0004h
- lea si, sign
- cld
- repz cmpsb
- jnz isNot
- jmp isTrue
- }
- isNot: return 0;
- isTrue:
- VGAtype = PVGA;
- asm {
- mov dx, 3ceh
- mov al, 0bh
- out dx, al
- inc dx
- in al, dx
- mov cl, 6
- shr al, cl
- cmp al, 0
- je skipdec
- cmp al, 3
- je skipdec
- dec al
- }
- skipdec:
- asm {
- xor ah, ah
- mov VRamSize, ax
- }
- return 0x58;
- }
-
- Bool isATI_SVGA()
- /*
- OUT: (Hex)
- 00 --- not Paradise
- 53/54 --- 800 x 600 Graphics mode code
- */
- {
- static char sign[9] = "761295520";
-
- asm {
- mov ax, 0c000h
- mov es, ax
- mov di, 0031h // c000:0031 --- ATI signature
- mov cx, 0009h
- lea si, sign
- cld
- repz cmpsb
- jnz isNot
- jmp isTrue
- }
- isNot: return 0;
- isTrue: VGAtype = AVGA; return 0x53;
- }
-
- Bool isGenoaSVGA()
- /*
- OUT: (Hex)
- 00 --- not Genoa
- 6A/79 --- 800 x 600 Graphics mode code
- */
- {
- static char sign[4] = { 0x77, 0x11, 0x66, 0x99 };
-
- asm {
- mov ax, 0c000h
- mov es, ax
- mov di, 0037h // c000:0037 -- Genoa signature
- lea si, sign
- mov al, [si]
- cmp al, es:[di]
- jne isNot
- mov al, [si+2]
- cmp al, es:[di+2]
- jne isNot
- mov al, [si+3]
- cmp al, es:[di+3]
- jne isNot
- jmp isTrue
- }
- isNot: return 0;
- isTrue: VGAtype = GVGA;
- return 0x6a;
- }
-
- Bool isTsengSVGA()
- /*
- OUT: (Hex)
- 00 --- not Tseng
- 30 --- 800 x 600 Graphics mode code
- */
- {
- asm {
- mov dx, 3dah
- in al, dx
- mov dx, 3c0h
- mov al, 16h
- out dx, al
- inc dx
- in al, dx
- mov cl, al // save it
-
- mov dx, 3dah
- in al, dx
- mov dx, 3c0h
- mov al, 16h
- out dx, al
- mov al, cl
- xor al, 10h
- mov ch, al // save it
- out dx, al
-
- mov dx, 3dah
- in al, dx
- mov dx, 3c0h
- mov al, 16h
- out dx, al
- inc dx
- in al, dx
- mov ah, al // save it
-
- mov dx, 3dah
- in al, dx
- mov dx, 3c0h
- mov al, 16h
- out dx, al
- mov al, cl
- out dx, al
-
- cmp ch, ah
- jne isNot
- jmp isTrue
- }
- isTrue: VGAtype = EVGA; return 0x30;
- isNot: return 0;
- }
-
- /*
- Bool isChipsSVGA()
- //
- OUT: (Hex)
- 00 --- not Chips
- --- 800 x 600 Graphics mode code
- //
- {
- asm {
- mov dx, 46e8h
- mov al, 1eh
- out dx, al
- mov dx, 104h
- in al, dx
- */
-
- void TestVGA()
- {
- if (! isVGA()) {
- printf("xtest: Display Card not Supported !\n");
- exit(0xff);
- }
- VRamSize ++; VRamSize *= 64;
- if (! isTridentSVGA())
- if (! isParadiseSVGA())
- if (! isGenoaSVGA()) isATI_SVGA();
- if (VRamSize < 64) { VRamSize ++; VRamSize *= 256; }
- printf("Video Card Type : %s\n", VGAmsg[VGAtype]);
- }
-
- void TestXMS()
- {
- asm {
- mov ax, 4300h
- int 2fh
- cmp al, 80h
- jne retn
- push es
- mov ax, 4310h
- int 2fh
- mov word ptr cs:XMSentry, bx
- mov word ptr cs:XMSentry+2, es
- pop es
- mov ah, 08h
- call dword ptr cs:XMSentry
- cmp bl, 0
- jne retn
- mov FreeXMS, ax
- }
- if (FreeXMS) printf("Free XMS Memory : %d KB\n", FreeXMS);
- retn: return;
- asm {
- XMSentry dd ?
- }
- }
-
- void TestEMS()
- {
- static char EMMdevName[9] = "EMMXXXX0";
-
- asm {
- push es
- mov ax, 3567h
- int 21h
- mov di, 000ah
- mov si, offset EMMdevName
- mov cx, 8
- cld
- repz cmpsb
- pop es
- jz eCont0
- }
- retn: return;
- eCont0:
- asm {
- mov ah, 42h
- int 67h
- or ah, ah
- jnz retn
- mov cl, 4
- shl bx, cl
- mov FreeEMS, bx
- }
- if (FreeEMS) printf("Free EMS Memory : %d KB\n", FreeEMS);
- }
-
- void TestEXT()
- {
- asm {
- mov ah, 88h
- int 15h
- mov FreeEXT, ax
- }
- if (FreeEXT) printf("Free EXT Memory : %d KB\n", FreeEXT);
- }
-
- void TestFloppy()
- {
- asm {
- mov al, 10h
- out 70h, al
- in al, 71h
- mov ah, al
- and al, 0fh
- mov cl, 4
- shr ah, cl
- mov byte ptr FloppyA, ah
- mov byte ptr FloppyB, al
- }
- /*
- if (FloppyA != 0)
- printf("Floppy Drive A : %s\n", FloppyMsg[FloppyA]);
- if (FloppyB != 0)
- printf("Floppy Drive B : %s\n", FloppyMsg[FloppyB]);
- */
- }
-
- void TestHardDriver()
- {
- asm {
- mov al, 12h
- out 70h, al
- in al, 71h
- mov ah, al
- mov cl, 4
- shr al, cl
- cmp al, 0fh
- jne skip0
- mov al, 19h
- out 70h, al
- in al, 71h
- }
- skip0:
- asm {
- xchg ah, al
- and al, 0fh
- cmp al, 0fh
- jne skip1
- mov al, 1ah
- out 70h, al
- in al, 71h
- }
- skip1:
- asm {
- mov byte ptr Hard1, ah
- mov byte ptr Hard2, al
- }
- /*
- if (Hard1) printf("Hard Drive 1 : %d\n", Hard1);
- if (Hard2) printf("Hard Drive 2 : %d\n", Hard2);
- */
- }
-
- void main()
- {
- if (! TestDOS()) {
- printf("xtest: DOS Version not Supported !\n");
- exit(0xff);
- }
- if (! TestCPU()) {
- printf("xtest: CPU Type not Supported !\n");
- exit(0xff);
- }
- TestVGA();
- TestXMS(); TestEMS(); TestEXT();
- TestFloppy(); TestHardDriver();
- if (FreeXMS > 256) exit(0); // Use XMS Memory
- if (FreeEMS > 256) exit(1); // Use EMS Memory
- if (FreeEXT > 256) exit(2); // Use EXT Memory
- exit(3); // Use Cache
- }
-