📄 necbios.doc
字号:
else
printf( "ASCII: yes\tChar: %c \t", ascii );
printf( "Code: %.2X\tScan: %.2X\t Shift: %.4X\n",
ascii, scan, shift );
}
}
------------------------------------------------------------------------------
Include: <bios.h>
Syntax: unsigned _bios_memsize(void);
Returns: Memory block size (unit:1K bytes)
_bios_memsize checks the size of total main memory
Return value
It returns the size of the installed total main memory by 1 K block
unit. The maximum size is 640, which means 640 K bytes.
/* SYSINFO.C illustrates miscellaneous DOS and BIOS status functions
* including:
* _dos_getdrive _dos_setdrive _dos_getdiskfree
* _bios_memsize _bios_equiplist _bios_printer
* (DOS-only)
* See DISK.C for another example of _dos_getdiskfree.
*
* Also illustrated:
* union bitfield struct
*/
#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#define LPT1 0
void main()
{
struct diskfree_t drvinfo;
unsigned drive, drivecount, memory, pstatus;
union { /* Access equipment either as: */
unsigned u; /* unsigned or */
struct { /* bit fields */
unsigned reserved1:1; /* Reserved */
unsigned coprocessor:1; /* Coprocessor? */
unsigned reserved2:1; /* Reserved */
unsigned disks:5; /* Drives */
unsigned mouse:1; /* Mouse */
unsigned comports:3; /* Serial ports */
unsigned gpib:1; /* GP-IB board */
unsigned sound:1; /* Sound board */
unsigned printers:2; /* Number of printers */
} bits;
} equip;
char y[] = "YES", n[] = "NO";
/* Get current drive. */
_dos_getdrive( &drive );
printf( "Current drive:\t\t\t%c:\n", 'A' + drive - 1 );
/* Set drive to current drive in order to get number of drives. */
_dos_setdrive( drive, &drivecount );
_dos_getdiskfree( drive, &drvinfo );
printf( "Disk space free:\t\t%ld\n",
( long )drvinfo.avail_clusters *
drvinfo.sectors_per_cluster *
drvinfo.bytes_per_sector );
/* Get new drive and number of logical drives in system. */
_dos_getdrive( &drive );
printf( "Number of logical drives:\t%d\n", drivecount );
memory = _bios_memsize();
printf( "Memory:\t\t\t\t%dK\n", memory );
equip.u = _bios_equiplist();
printf( "Disk drives:\t\t\t%d\n", equip.bits.disks );
printf( "Coprocessor:\t\t\t%s\n", equip.bits.coprocessor ? y : n );
printf( "Mouse driver:\t\t\t%s\n", equip.bits.mouse ? y : n );
printf( "Serial ports:\t\t\t%d\n", equip.bits.comports );
printf( "GP-IB interface:\t\t%s\n", equip.bits.gpib ? y : n );
printf( "FM-sound:\t\t\t%s\n", equip.bits.sound ? y : n );
printf( "Number of printers:\t\t%d\n", equip.bits.printers );
/* Fail if any error bit is on, or if either operation bit is off. */
pstatus = _bios_printer( _PRN_STATUS, 0 );
if ( pstatus & 0x01 )
pstatus = 0;
else
pstatus = 1;
printf( "Printer available:\t\t%s\n", pstatus ? y : n );
}
------------------------------------------------------------------------------
Include: <bios.h>
Syntax: unsigned _bios_printer(unsigned service,
unsigned char *databyte);
service: _PRN_INIT _PRN_WRITE _PRN_STRING _PRN_STATUS
Returns: It is different depending on <service>.
_bios_printer routine operates things specified by <service>.
One of the following symbol constants is specified in the argument <service>.
_PRN_INIT _PRN_STATUS _PRN_WRITE _PRN_STRING
Return value
It is different depending on <service>. Please refer topics of each symbol constants
Constant: _PRN_INIT _PRN_STATUS _PRN_STRING _PRN_WRITE
Summary: Constants of the argument <service> of _bios_printer
One of the below symbol constants is specified.
Constants The function of _bios_printer
_PRN_INIT It initializes the status area and the controller.
The bit 0 of the return value shows the following contents.
Value Meaning
1 Enable to output data
0 Disable to output data
_PRN_WRITE It putout one byte of data from the area pointed to
by the argument <data>.
The bit 0 of the return value shows the following contents.
Value Meaning
1 Complete to output data / Enable to output data
0 Data is not output.
The bit 0 of the return value shows the following contents.
Value Meaning
1 Time out / The data is not output.
0 Complete to output data
_PRN_STRING It output the data in the area pointed to
by the argument <data> till the first null character.
It returns zero if no errors and the number of characters
which is not output if errors.
_PRN_STATUS It gets the status information of the printer.
The bit 0 of the return value shows the following contents.
Value Meaning
1 Enable to output data
0 Disable to output data
/* SYSINFO.C illustrates miscellaneous DOS and BIOS status functions
* including:
* _dos_getdrive _dos_setdrive _dos_getdiskfree
* _bios_memsize _bios_equiplist _bios_printer
* (DOS-only)
* See DISK.C for another example of _dos_getdiskfree.
*
* Also illustrated:
* union bitfield struct
*/
#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#define LPT1 0
void main()
{
struct diskfree_t drvinfo;
unsigned drive, drivecount, memory, pstatus;
union { /* Access equipment either as: */
unsigned u; /* unsigned or */
struct { /* bit fields */
unsigned reserved1:1; /* Reserved */
unsigned coprocessor:1; /* Coprocessor? */
unsigned reserved2:1; /* Reserved */
unsigned disks:5; /* Drives */
unsigned mouse:1; /* Mouse */
unsigned comports:3; /* Serial ports */
unsigned gpib:1; /* GP-IB board */
unsigned sound:1; /* Sound board */
unsigned printers:2; /* Number of printers */
} bits;
} equip;
char y[] = "YES", n[] = "NO";
/* Get current drive. */
_dos_getdrive( &drive );
printf( "Current drive:\t\t\t%c:\n", 'A' + drive - 1 );
/* Set drive to current drive in order to get number of drives. */
_dos_setdrive( drive, &drivecount );
_dos_getdiskfree( drive, &drvinfo );
printf( "Disk space free:\t\t%ld\n",
( long )drvinfo.avail_clusters *
drvinfo.sectors_per_cluster *
drvinfo.bytes_per_sector );
/* Get new drive and number of logical drives in system. */
_dos_getdrive( &drive );
printf( "Number of logical drives:\t%d\n", drivecount );
memory = _bios_memsize();
printf( "Memory:\t\t\t\t%dK\n", memory );
equip.u = _bios_equiplist();
printf( "Disk drives:\t\t\t%d\n", equip.bits.disks );
printf( "Coprocessor:\t\t\t%s\n", equip.bits.coprocessor ? y : n );
printf( "Mouse driver:\t\t\t%s\n", equip.bits.mouse ? y : n );
printf( "Serial ports:\t\t\t%d\n", equip.bits.comports );
printf( "GP-IB interface:\t\t%s\n", equip.bits.gpib ? y : n );
printf( "FM-sound:\t\t\t%s\n", equip.bits.sound ? y : n );
printf( "Number of printers:\t\t%d\n", equip.bits.printers );
/* Fail if any error bit is on, or if either operation bit is off. */
pstatus = _bios_printer( _PRN_STATUS, 0 );
if ( pstatus & 0x01 )
pstatus = 0;
else
pstatus = 1;
printf( "Printer available:\t\t%s\n", pstatus ? y : n );
}
------------------------------------------------------------------------------
Include: <bios.h>
Syntax: unsigned _bios_serialcom(unsigned service,
unsigned port, struct com_t *serialcom);
service: _COM_COMMAND _COM_GETDTL _COM_INIT _COM_INITX
_COM_RECEIVE _COM_SEND _COM_STATUS
port: _COM_CH1 _COM_CH2 _COM_CH3
Returns: It returns zero if no error, non-zero if error.
It is different in the structure com_t depending on <service>.
_bios_serialcom routine operates serial ports by operations specified
in <service>. The argument <port> shows the operated serial port which
is one of _COM_CH1,_COM_CH2 or _COM_CH3. The information for operation is
specified in <serialcom> of the structure com_t.
One of the following symbol constants is specified in <service>.
_COM_COMMAND _COM_GETDTL _COM_INIT _COM_INITX
_COM_RECEIVE _COM_SEND _COM_STATUS
Return value
It returns zero if no errors, non-zero if errors. The value stored in
the structure com_t is different depending on <service>. Please refer
topics about symbol constants.
Constant: _COM_COMMAND _COM_GETDTL _COM_INIT _COM_INITX
_COM_RECEIVE _COM_SEND _COM_STATUS
Summary: Constants of the argument <service> of _bios_serialcom
One of the below symbol constants is specified.
Constants The function of _bios_serialcom
_COM_COMMAND It outputs the command information.
It uses the field command of the structure com_t only.
_COM_GETDTL It gets the data length of the valid data in the receive buffer.
The received data length is stored in the field size of the structure com_t.
_COM_INIT It initializes the serial port specified in the argument <port>.
It uses all fields of the structure com_t.
When _COM_CH2 or _COM_CH3 is specified in the argument <port>,
the field baud of the structure com_t is ignored.
_COM_INITX It is the same function as _COM_INIT
except it can set X parameter ( flow control ).
_COM_RECEIVE It received data. It stores the received data
in the field buffer+0, the status in buffer+1 if no errors.
_COM_SEND It sends one byte of data in the field buffer
of the structure com_t
_COM_STATUS It gets the status of the controller and the system port.
It stores the information of the controller information
in the field buffer+0 and the system port information
in the field buffer+1 of the structure com_t.
The controller information is the following.
Bit Meaning In the case of 1 In the case of 0
0 Send status Ready Busy
1 Receive status Ready Busy
2 Send buffer Empty Full
3 Parity error Error No error
4 Overrun error Error No error
5 Framing error Error No error
6 Detect break status Detect Not detect
7 Data set ready On Off
The system port information is is the following.
Bit Meaning 1 0
0-4 Not used
5 Received carrier detect Not detect Detect
6 Send Disable Enable
7 Receive No Yes
Structure:
struct com_t
{
unsigned baud; /* Baud rate */
unsigned mode; /* Mode set */
unsigned command; /* Command specified */
unsigned tx_time; /* The period od time out to send */
unsigned rx_time; /* The period od time out to receive */
unsigned size; /* Buffer size to receive */
void _far *buffer; /* Pointer to receive buffer */
};
/* COM.C illustrates serial port access using function:
* _bios_serialcom (DOS-only)
*/
#include <bios.h>
#include <stdio.h>
void main()
{
unsigned status;
status = _bios_serialcom( _COM_STATUS, _COM_CH1, 0 );
/*
* Report status of serial port and test whether there is a
* responding device (such as a modem) for each. If data-set-ready
* and clear-to-send bits are set, a device is responding.
*/
printf( "COM status: %.4X\tActive: %s\n",
status, ( status & 0x0003 ) ? "YES" : "NO" );
}
------------------------------------------------------------------------------
Include: <bios.h>
Syntax: unsigned _bios_timeofday(unsigned service, char *timeval);
service: _TIME_GETCLOCK _TIME_SETCLOCK
Returns: It returns zero if no errors, non-zero if errors
_bios_timeofday routine gets or sets system clocks. _TIME_GETCLOCK or
_TIME_SETCLOCK is specified in the argument <service>.
the area pointed by the argument <timeval> specifies to get or set
the system clock. This area is assigned like the below.
timeval+0 Year (BCD 00-99)
timeval+1 The upper 4 bit is month ( 1-12 hex)
The lower 4 bits is day ( 0-6 hex)
timeval+2 date (BCD 1-31)
timeval+3 hours (BCD 0-23)
timeval+4 minutes (BCD 0-59)
timeval+5 seconds (BCD 0-59)
Return value
It returns zero if no errors, non-zero if errors.
/* SIEVE.C illustrates timing functions including:
* clock difftime _bios_timeofday
*
* In addition to the timing use shown here, these functions can be
* used for delay loops as shown for the clock function
* in BEEP.C.
*/
#include <time.h>
#include <stdio.h>
#include <bios.h>
#define TICKPERSEC 18.2
int mark[ 10000 ];
void main()
{
time_t tstart, tend; /* For difftime */
clock_t cstart, cend; /* For clock */
long bstart, bend; /* For _bios_timeofday */
register int i, loop;
int n, num, step;
/* Start timing. */
printf( "Working...\n" );
time( &tstart ); /* Use time and difftime for timing to seconds */
cstart = clock(); /* Use clock for timing to hundredths of seconds */
#if defined( DOS ) /* Define DOS to use _bios_timeofday */
_bios_timeofday( _TIME_GETCLOCK, &bstart );
#endif
/* Do timed Sieve of Erotosthenes. */
for ( loop = 0; loop < 250; ++loop )
for ( num = 0, n = 3; n < 10000; n += 2 )
if ( !mark[ n ] ) {
step = 2 * n;
for ( i = 3 * n; i < 10000; i += step )
mark[ i ] = -1;
++num;
}
/*
* End timing and print results. Note that _bios_timeofday doesn't
* handle midnight rollover.
*/
time( &tend );
printf( "\ndifftime:\t\t%4.2f seconds to find %d primes 50 times\n",
difftime( tend, tstart ), num );
cend = clock();
printf( "\nclock:\t\t\t%4.2f seconds to find %d primes 50 times\n",
( ( float )cend - cstart ) / CLK_TCK, num );
#if defined( DOS )
_bios_timeofday( _TIME_GETCLOCK, &bend );
printf( "\n_bios_timeofday:\t%4.2f seconds",
( ( float )bend - bstart ) / TICKPERSEC );
printf( " to find %d primes 50 times\n", num );
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -