www.pudn.com > 主板设备检查的 TC 源代码.zip > EQUIP.C
/***************************************************************************/ /* Program : EQUIP.C Creation Date: 06/05/1987 */ /* Author : Richard P. Hendricks Last Modified: 06/11/1987 */ /* Compiler : Turbo C Compiler, Version 1.0 */ /* Function : Study the BIOSEQUIP() Function using two analysis approaches.*/ /* Approach 1: Bit Field Structure */ /* Approach 2: Bit Masking of BIOSEQUIP() Returned Value */ /* */ /* Comments : The Turbo C Documentation appears to be in error on the: */ /* - RS232 Ports - COMM Ports */ /* - Mother Board RAM */ /* Referred to PC Magazine Vol 6 Number 8, April 28, 1987, */ /* A System Board Analyzer, pages 281 - 295 */ /* */ /***************************************************************************/ #include/* Standard I/O functions */ #include /* Needed for BIOSEQUIP() Function */ main() { struct EQUIP /* BIT Field Structure */ { unsigned boot :1; /* bit 0 */ unsigned math :1; /* bit 1 */ unsigned ram1 :1; /* bits 2 */ unsigned ram2 :1; /* bits 3 00 - 64K */ /* 01 - 128K */ /* 3 & 2 10 - 192K */ /* 11 - 256K */ unsigned video1 :1; /* bits 4 */ unsigned video2 :1; /* bits 5 00 - unused */ /* 01 - 40 x 25 BW w/ color cd*/ /* 5 & 4 10 - 80 x 25 BW w/ color cd*/ /* 11 - 80 x 25 BW w/ mono crd*/ unsigned disks1 :1; /* bits 6 */ unsigned disks2 :1; /* bits 7 00 - 1 drive */ /* 01 - 2 drives */ /* 7 & 6 10 - 3 drives */ /* 11 - 4 drives, if bit 0 =1 */ unsigned filler1 :1; /* bit 8 */ unsigned comm1 :1; /* bit 9 */ unsigned comm2 :1; /* bit 10 */ unsigned comm3 :1; /* bit 11 000 - 0 comm ports */ /* 001 - 1 comm port */ /* 11, 10 & 9 010 - 2 comm ports */ /* ^^^^^^ 011 - 3 comm ports */ unsigned game :1; /* bit 12 */ unsigned filler2 :1; /* bit 13 */ unsigned printer1:1; /* bit 14 */ unsigned printer2:1; /* bit 15 00 - 0 printer ports */ /* 01 - 1 printer port */ /* 15 & 14 10 - 2 printer ports */ /* 11 - 3 printer ports */ }; struct EQUIP *equip; unsigned int bios_ret; unsigned int ram; /* Approach 2 Variables */ char *display; char *drives; char *comm_ports; char *printers; bios_ret = biosequip(); /* --- Approach 1: Bit Field Structure --- */ equip = (struct EQUIP *)(&bios_ret); /* Put Returned value into the */ /* Bit Field Structure */ /* --- Report Structure Values --- */ printf("\t\t\t BIOSEQUIP() Function Call\n"); printf("\t\t\tApproach: Bit Field Structure\n\n"); printf("Bits Device Settings\tMeaning\n"); printf(" 0 Boot Disk : %u", equip->boot ); printf("\t\t0 - none, 1 - available\n"); printf(" 1 Math Co-Processor : %u", equip->math ); printf("\t\t0 - none, 1 - installed\n"); printf("3/2 Mother Board RAM : %u %u", equip->ram2, equip->ram1 ); printf("\t\t0 0 - 64K, 0 1 - 128K,\n\t\t\t\t\t1 0 - 192K & 1 1 - 256K\n\n"); printf("5/4 Screen Type : %u %u", equip->video2, equip->video1 ); printf("\t\t0 0 - none, 0 1 - 40 color,\n\t\t\t\t\t1 0 - 80 color & 1 1 - mono\n\n"); printf("7/6 Drives (Bit 0 = 1): %u %u", equip->disks2, equip->disks1 ); printf("\t\t0 0 - 1, 0 1 - 2,\n\t\t\t\t\t1 0 - 3 & 1 1 - 4 drives\n\n"); printf(" 8 Not Used : %u\n", equip->filler1 ); printf("11-9 Comm Ports(10 & 9): %u %u %u", equip->comm3, equip->comm2, equip->comm1 ); printf("\t\t0 0 0 - 0, 0 0 1 - 1,\n\t\t\t\t\t0 1 0 - 2 & 0 1 1 - 3 ports\n\n"); printf(" 12 Game Port : %u", equip->game ); printf("\t\t0 - none, 1 - installed\n"); printf(" 13 Not Used : %u\n", equip->filler2 ); printf("15/14 Printer Ports : %u %u", equip->printer2, equip->printer1 ); printf("\t\t0 0 - 0, 0 1 - 1,\n\t\t\t\t\t1 0 - 2 & 1 1 - 3 ports\n\n"); /* --- Approach 2: Bit Masking of Returned Value --- */ /*-------------------------------------------------------------------------** ** Bit Positions ** ** |---------| |---------| |---------| |---------| ** ** Device\Bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Mask ** ** + + + +-----------+ v ** ** Boot 0 drives 0 0x0000 ** ** drives 1 0x0001 ** ** ** ** Math Chip 0 0 0x0000 ** ** 1 1 0x0002 ** ** ** ** RAM 64k 0 0 0x0000 ** ** 128k 0 1 0x0004 ** ** 196k 1 0 0x0008 ** ** 256k 1 1 0x000C ** ** + + +-----------+ + v ** ** Video None 0 0 0x0000 ** ** 40 Clr 0 1 0x0010 ** ** 80 Clr 1 0 0x0020 ** ** Mono 1 1 0x0030 ** ** ** ** Drives 1 0 0 0x0000 ** ** 2 0 1 0x0040 ** ** 3 1 0 0x0080 ** ** 4 1 1 0x00C0 ** ** + +-----------+ + + v ** ** Not Used - Bit 8 ** ** ** ** COMM Port 0 0 0 0 0x0000 ** ** 1 0 0 1 0x0200 ** ** 2 0 1 0 0x0400 ** ** 3 0 1 1 0x0600 ** ** +-----------+ + + + v ** ** Game Port 0 0 0x0000 ** ** 1 1 0x1000 ** ** ** ** Not Used - Bit 13 ** ** ** ** Printer 0 0 0 0x0000 ** ** 1 0 1 0x4000 ** ** 2 1 0 0x8000 ** ** 3 1 1 0xC000 ** ** + + + + + ** ** Bit position within a group of 4: 3 2 1 0 ** ** Equation for position : 2**3 2**2 2**1 2**0 ** ** Decimal Value : 8 4 2 1 ** ** Conversion Dec to Hex : ** ** ** ** Dec : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ** ** Hex : 0 1 2 3 4 5 6 7 8 9 A B C D E F ** ** ** ** Mask Development Example : bits 3 & 2 are 1's out of a 16 bit ** ** integer. 8 + 4 = 12 --> C, so the ** ** mask will be: 0x000C ** **-------------------------------------------------------------------------*/ /* --- Bit Mask Defines -- */ #define NO_DRIVES 0x0000 #define DRIVES_AVAILABLE 0x0001 #define NO_MATH_CHIP 0x0000 #define MATH_CHIP 0x0002 #define RAM_INTEREST_BITS 0x000C #define MOTHERBOARD_RAM_64K 0x0000 #define MOTHERBOARD_RAM_128K 0x0004 #define MOTHERBOARD_RAM_196K 0x0008 #define MOTHERBOARD_RAM_256K 0x000C #define DISPLAY_INTEREST_BITS 0x0030 #define NO_MONITOR 0x0000 #define COLOR_40 0x0010 #define COLOR_80 0x0020 #define MONOCHROME 0x0030 #define DISK_INTEREST_BITS 0x00C0 #define ONE_DISK_DRIVE 0x0000 #define TWO_DISK_DRIVES 0x0040 #define THREE_DISK_DRIVES 0x0080 #define FOUR_DISK_DRIVES 0x00C0 #define COMM_INTEREST_BITS 0x0600 #define NO_COMM_PORTS 0x0000 #define ONE_COMM_PORT 0x0200 #define TWO_COMM_PORTS 0x0400 #define THREE_COMM_PORTS 0x0600 #define NO_GAME_PORT 0x0000 #define GAME_PORT 0x1000 #define PRINTER_INTEREST_BITS 0xC000 #define NO_PRINTER 0x0000 #define ONE_PRINTER 0x4000 #define TWO_PRINTERS 0x8000 #define THREE_PRINTERS 0xC000 printf("\n"); printf("\t\t\t BIOSEQUIP() Function Call\n"); printf("\t\t\tApproach: Bit Field Masking\n\n"); printf("Bits Device Meaning\n"); printf(" 0 Boot Disk : %s\n", ( bios_ret & DRIVES_AVAILABLE ) ? "Available" : "None" ); printf(" 1 Math Co-Processor : %s\n", ( bios_ret & MATH_CHIP ) ? "Available" : "None" ); ram = -1; if (( bios_ret & RAM_INTEREST_BITS ) == MOTHERBOARD_RAM_256K ) ram = 256; else if (( bios_ret & RAM_INTEREST_BITS ) == MOTHERBOARD_RAM_196K ) ram = 196; else if (( bios_ret & RAM_INTEREST_BITS ) == MOTHERBOARD_RAM_128K ) ram = 128; else if (( bios_ret & RAM_INTEREST_BITS ) == MOTHERBOARD_RAM_64K ) ram = 64; printf("3/2 Mother Board RAM : %dK\n", ram ); display = " "; if (( bios_ret & DISPLAY_INTEREST_BITS ) == MONOCHROME ) display = "Monochrome" ; else if (( bios_ret & DISPLAY_INTEREST_BITS ) == COLOR_80 ) display = "Color with 80 columns"; else if (( bios_ret & DISPLAY_INTEREST_BITS ) == COLOR_40 ) display = "Color with 40 columns"; else if (( bios_ret & DISPLAY_INTEREST_BITS ) == NO_MONITOR ) display = "None"; printf("5/4 Screen Type : %s\n", display ); drives = " "; if (( bios_ret & DISK_INTEREST_BITS ) == FOUR_DISK_DRIVES ) drives = "Four"; else if (( bios_ret & DISK_INTEREST_BITS ) == THREE_DISK_DRIVES ) drives = "Three"; else if (( bios_ret & DISK_INTEREST_BITS ) == TWO_DISK_DRIVES ) drives = "Two"; else if (( bios_ret & DISK_INTEREST_BITS ) == ONE_DISK_DRIVE ) drives = "One"; printf("7/6 Drives (Bit 0 = 1): %s\n", drives ); printf(" 8 Not Used : -\n" ); comm_ports = " "; if (( bios_ret & COMM_INTEREST_BITS ) == THREE_COMM_PORTS ) comm_ports = "Three"; else if (( bios_ret & COMM_INTEREST_BITS ) == TWO_COMM_PORTS ) comm_ports = "Two"; else if (( bios_ret & COMM_INTEREST_BITS ) == ONE_COMM_PORT ) comm_ports = "One"; else if (( bios_ret & COMM_INTEREST_BITS ) == NO_COMM_PORTS ) comm_ports = "None"; printf("11-9 Comm Ports(10 & 9): %s\n", comm_ports ); printf(" 12 Game Port : %s\n", ( bios_ret & GAME_PORT ) ? "Available" : "None" ); printf(" 13 Not Used : -\n" ); printers = " "; if (( bios_ret & PRINTER_INTEREST_BITS ) == THREE_PRINTERS ) printers = "Three"; else if (( bios_ret & PRINTER_INTEREST_BITS ) == TWO_PRINTERS ) printers = "Two"; else if (( bios_ret & PRINTER_INTEREST_BITS ) == ONE_PRINTER ) printers = "One"; else if (( bios_ret & PRINTER_INTEREST_BITS ) == NO_PRINTER ) printers = "None"; printf("15/14 Printer Ports : %s\n", printers ); } /* end-of-file EQUIP.C end-of-file */