Usage of uncommon functions

xiaoxiao2021-03-06  56

It is mentioned herein to use some of the usual functions, and the common functions are used. Recommended Tan Haoqiang's "C Programming" (Tsinghua University Publishing House Publishing) Collection: Jenkin

Function name

[BDoREAD ABSWRITE] [BDOS BDOSPTR] [Bioscom] [Biosequip] [BiosMemory] [Biosprint] [BiOstime] [CPRINTF] [CPUTS PUTS] [cscanfscanf] [disable] [dosexterr] [enable] [GenInterrupt] [Getch ] [GetDisk] [GetVerify] [have GetRr] [Inport] [INT86] [INTDOS] [IOCTL] [KBHIT] [KEEP] [PEEK] [PERRR] [randbrd] [randbwr] [segread] [ SetVect] [SLEEP] [ungetc ungetch] [cgets] [[Back Home]]

1. Function Description: int ABSREAD (int D Drive, int Nsects, int SECTNO, VOID * BUFFER); int ABSWRITE (INT Drive, Int Nsects, In TsectNo, Void * Buffer); Contains File:

Function Explanation: Disk absolute read and write functions. Return to the integer value, Driver is the drive name, 0 represents a disk, 1 represents the B disk. Nsects is the number of sectors. TsectNO is the starting fan code. Butffer is the memory address read.

Usage: When the return value is 0, it means successful, and is -1, indicates an error.

Example:

#include

#include

#include

#include

Int main (void)

{INT I, STRT, CH_OUT, SECTOR;

Char BUF [512];

Printf ("INSERT A DISKETTE INTO Drive A and Press Any Key / N");

GetCh (); sector = 0;

IF (Absread (0, 1, Sector, & Buf)! = 0) / * If you read a drive error * /

{Perror ("Disk Problem"); EXIT (1); / * Exit Program * /}

Printf ("Read OK / N");

STRT = 3;

For (i = 0; i <80; i )

{Ch_out = BUF [STRT I];

Putchar (ch_out); / * Read 80 characters to BUF * /}

Printf ("/ n"); return (0);

2. Function Description: Int BDOS (int DOSFUN, UNSIGNED DOSDX, Unsigned Dosal); Int bdosptr (int dosfun, void * argument, unsigned dosal); Contains file: function explanation: DOS system call. These two The function provides a number of direct access to many system calls. Usage: BDoS function is used for system calls for integer parameters, and can directly access many DOS system resources. The BDoSPTR function is used to call the pointer parameter system call, which is generally used in large data modes .argument For the pointer entrance parameters. Dossal is the Al register value. Sample: / * BDoS function usage * / #include #include / * get current drive as 'A', 'b', ... * / char current_drive (void) {char curdrive; / * get current disk as 0, 1, ... * / curdrive = bdos (0x19, 0, 0); Return ('a' curdrive);} INT main (void) {Printf ("THE CURRENT DRIVE IS% C: / N", current_drive ()); return 0;} / * bdosptr function usage example * / #include #include #include #include #include #include #define buflen 80 int main (void) {charffer [buflen]; int test; printf ("Enter Full Pathname of A Directory / N"); gets (buffer); test = bdosptr (0x3b, buffer, 0); if (test) {Printf ("DOS Error Message:% D / N ", errno); / * see errno.h for error listings * / exit (1);} getcwd (buffer, buflen); Printf (" THE CURRENT DIRECTORY IS:% S / N ", buffer;} 3. Function Description: INT Bioscom (int CMD, CHAR ABYTE, INT) 1, 2, 3.abyte is a certain combination for setting the data bit, stop bit, parity check and baud rate. If the Abyte value is 0xeb (0xE0 | 0x08 | 0x00 | 0x03), the communication port will be set. For 9600 baud rate, odd school inspection, 1 stop bit and 8 data bits. Certificate: #include #include

#define com1 0 #define data_ready 0x100 #define true 1 #define false 0 #define settings (0x80 | 0x02 | 0x00 | 0x00) int main (void) {Int in, out, status, done = false; bioscom (0, Settings , COM1); CPRINTF ("... Bioscom [ESC] to EXIT ... / N"); While (! DONE) {status = bioscom (3, 0, COM1); if (status & data_ready) IF (((STATUS & DATA_READY) IF OUT = Bioscom (2, 0, COM1) & 0x7F)! = 0) PUTCH (OUT); if (kbhit ()) {IF ((in = getCH ()) == '/ x1b') DONE = true; bioscom (1, IN, COM1);}} Return 0;} 4. Function Description: Int BiosDisk (int CMD, int DRIVE, INT NSECTS, VOID * BUFFER); Contains File: Function Explanation: Software Drive I / O Service. Use interrupt 0x13 to transfer disk operation directly to BIOS. Usage: Please include header files before calling. CMD can take 0 to 5 (for IBM PC and its compatible machine) 6 To 20 (only for XT, AT, PS / 2 and its compatible machine), please refer to books. DRIVER is a disk drive .0 represents the first soft drive, 1 represents the second floppy drive, etc.0X80 represents the first hard drive 0x81 represents the second hard drive. Note: This function team disk is operated, it will destroy the content on the disk, be careful when using it. Celebration: #include #include int Main (Voi) d) {int result; char buffer [512]; Printf ("Testing to see if drive a: is ready / n"); Result = BiosDisk (4, 0, 0, 0, 0, 1, buffer); Result & = 0x02; (Printf ("Drive A: Ready / N")): ("Drive A: NOTY / N"); return 0;} 5. Function Description: int Biosequip (void) [Contains file: function explanation: Check the device. Use the BIOS interrupt 0x11. On the IBM PC, the monitoring device is: the number of printers, the printing method (string, parallel), is it connected to the game I / O device Number of COM ports, there is a direct access memory, hard disk, video mode, motherboard RAM size. Usage: Use the header file before use, the return value is a set of a bit domain, and the collection contains the device. Please refer to the specific situation For books. Drafts: #include #include int main (void) {int result;

Char Buffer [512]; Printf ("Testing to See if Drive A: is Ready / N"); Result = BiosDisk (4, 0, 0, 0, 0, 1, Buffer; Result & = 0x02; (Result) (Printf ("Drive A: Ready / N"): ("Drive A: NOTY / N"); Return 0;} 6. Function Description: INT BiosMemory; Contains File: Function: Return the storage block size. Does not include the expansion memory and expand memory. Usage: Use the header file before use. Return to a full value, in K. Sample: #include # INCLUDE int Main (void) {int memory_size; memory_size = biosmemory (); / * returns value Up to 640k * / printf ("RAM SIZE =% DK / N", Memory_Size); Return 0; 7 Function Description: INT BiospRINT (int CMD, INT BYTE, INT) Port is 0 corresponds to LTP1, 1 corresponds to LPT2 or the like. The value of Abort is between 0 and 255. CMD can take 0, 1, 2. Return value is a bit value, used to represent printer status.: #include < STDIO.H> #include #include int main (void) {#define status 2 / * printer status command * / #define portnum 0 / * port number for lpt1 * / int stat STATUS, Abyte = 0; Printf ("Ple ASE TURN OFF YOUR PRINTER. PRESS ANY Key To Continue / N "); getCh (); status = biosprint (status, abyte, portnum); if (status & 0x01) Printf (" Device Time Out./N "); IF (status & 0x08) Printf ("I / O Error./N"); if (status & 0x10) Printf ("SELECTED./N"); if (status & 0x20) Printf ("Out of Paper./N" ); If (status & 0x40) Printf ("Acknowledge./N"); if (Status & 0x80) Printf ("not busy./N"); return 0;} 8. Function Description: Long Biostime (int CMD, Long newtime); Contains files:

Function Explanation: Read or set the BIOS time. Using the BIOS 0x1a interrupt implementation. Usage: CMD is 0, return the current value of the timer; 1, the timer is set to the long type newtime value. Certificate: # Include #include #include #include int main (void) {long bios_time; clrscr (); CPrintf ("The Number of Clock Ticks Since Midnight IS: / r / n "); CPRINTF (" THE NUMBER OF Seconds Since Midnight IS: / R / N "); CPRINTF (" The Number of Minutes Since Midnight IS: / R / N "); CPrintf (" The Number Of Hours Since Midnight IS: / R / N "); CPRINTF (" / R / NPRESS ANY Key To Quit: "); While (! kbhit ()) {BIOS_TIME = Biostime (0, 0L); gotoxy (50, 1 CPRINTF ("% lu", bios_time); gotoxy (50, 2); cprintf ("%. 4f", bios_time / clk_tck); gotoxy (50, 3); CPrintf ("%. 4f", BIOS_TIME / CLK_TCK / 60); gotoxy (50, 4); CPRINTF ("%. 4F", BIOS_TIME / CLK_TCK / 3600);} return 0;} 9. Function name: cprintf header file: function: send format Output to screen usage: int CPRINTF (const char * format [, argument, ...]); can set color. Archventor: #include int main (void) { / * Clear the screen * / clrs (); / * Create a text window * / window (10, 10, 80, 25); / * Output Some text in the window * / cprintf ("Hello WORLD / R / N" ); / * Wait for a key * / getch (); return 0;} 10. Function name: CPUTS header file: function: write characters to screen usage: Void cputs (const char * string) : #Include int main (void) {/ * clear the screen * / clrs (); / * CREATE A TEXT WINDOW * / WINDOW (10, 10, 80, 25); / * OUTPUT Some text in the window * / cputs ("this is for a key * / getch (); return 0;} function name: PUTS header file:

Function: Send a string to the stream Usage: int Puts (char * string); example: #include int main (void) {char string [] = "this is an example ketpring string / n "; PUTS (String); Return 0;} 11. Function Name: cscanf header file: Features: Formatting Input from the console: int Cscanf (char * format [, argument,. ..]);: #include int main (void) {char string [80]; / * clear the screen * / clrscr (); / * prompt the user for infut * / cprintf (" ENTER A STRING WITH NO SPACES: "); / * read the input * / cscanf ("% s ", string); / * Display what was read * / cprintf (" / r / nthe string entered is:% s ", String); Return 0;} function name: scanf header file: Features: Perform formatting input usage: int Scanf (char * format [, argument, ...]); program case: #include #include int main (void) {char label [20]; char name [20]; int entries = 0; int loop, age; double salary; struct entry_struct {char name [20 ]; Int Age; float salary;} entry [20]; / * Input a label as a String of Characters Restr ICTING TO 20 Characters * / Printf ("/ N / N / N / N / N / NPLEASE ENTER A Label for THE CHART:"); Scanf ("% 20s", Label); FFLUSH (stdin); / * Flush the Input Stream in case of bad input * / / * Input Number of Entries as an inTeger * / Printf ("How Many Entries Will there"); scanf ("% d", & entries); fflush (stdin); / * flush the input Stream in case of bad input * / / * input a name restricting input to only letters upper or limited {@ / for (loop = 0; loop

Fflush (stdin); / * Flush the Input Stream in case of bad input * / / / * Input an agent, ("age:"); scanf ("% d", & entry [loop] .age) Fflush (stdin); / * flush the input stream in case of bad input * / / / * Input A Salary as a float * / printf ("Salary:"); scanf ("% f", & entry [loop] .salary ); Fflush (stdin); / * flush the input stream in case of bad input * /} / * input a name, agn and double * / printf ("/ NPLEASE ENTER Your Name, AGE And Salary / N "); Scanf ("% 20S% D% LF ", Name, & Age, & Salary; / * Print Out the data there is invut * / printf (" / n / ntable% s / n ", label ); Printf ("Compiled BY% S AGE% D $% 15.2LF / N", Name, AGE, SALARY); Printf ("------------------ ------------------------------ / n "); for (loop = 0; loop Features: Mask Interrupt Usage: Void Disable (Void); Project: / *** Note: this is an interrupt service routine. You Cannot Compile this Program with test stack overflow Turned On and Get An Executable File That Operates Correctly. * / #include #include #include #define INTR 0X1C / * The Clock Tick Interrupt * / Void Interrupt (* OldHandler) (void); int count = 0; Void Interrupt Handler (void) {/ * disable interrupts during the handling of the interrupt * / disable ();

/ * Increase the global counter * / count ; / * reenable interrupts at the end of the handler * / enable (); / * call the old routine * / oldhandler ();} int main (void) {/ * save the old Interrupt Vector * / OldHandler = getVect (INTR); / * Install the new interrupt handler * / setvect (intel, handler); / * loop unsteil the counter Exceeds 20 * / while (count <20) Printf ("count is% d) / N ", count); / * reset the old interrupt handler * / setVect (INTR, OLDHANDLER); RETURN 0;} 13. Function name: dosexterr header file: Features: Get extended DOS error information Method: INT DOSEXTERR (STRUCT DOSERR * DBLKP); program example: #include #include int main (void) {file * fp; struct doserror info; fp = fopen ("PERROR.DAT "," r "); if (! fp);" unable to open file forread "); dosexterr (& info); Printf (" extended DOS ERROR / INFORMATION: / N); Printf ("Extended Error: / % D / N ", Info.exTerror); Printf (" Class: /% x / n ", info.class); Printf (" Action: /% X / n ", info.ction); Printf (" Error Locus: /% x / n ", info.locus); Return 0;} 14. Function name: enable header file: : open hardware interrupt Usage: void enable (void); procedure example:. / * ** NOTE: This is an interrupt service routine You can NOT compile this program with Test Stack Overflow turned on and get an executable file which will operate correctly . * / #include #include #include / * the clock tick interface * / #define INTR 0x1c void interrupt (* Oldrandler) (void); int count = 0 ;

void interrupt handler (void) {/ * disable interrupts during the handling of the interrupt * / disable (); / * increase the global counter * / count ; / * re enable interrupts at the end of the handler * / enable (); / * Call the old routine * / oldhandler ();} int main (void) {/ * save the old interrupt vector * / oldhandler = getVect (INTR); / * Install the new interface handler * / setVect (Intr, Handler) ; / * loop Until the counter Exceeds 20 * / while (count <20) Printf ("count IS% D / N", count); / * reset the old interrupt handler * / setVect (INTR, OLDHANDLER); RETURN 0; } 15. Function name: GenInterrupt header file: Features: Generate a soft interrupt method: void geninterrupt (int inter_num); program: #include #include / * function prototype * / void writechar (CHAR CH); int Main (void) {clrs (); gotoxy (80, 25); WriteChar ('*'); getCh (); return 0;} / * Outputs a character At The current cursor position using The video bios to avoid the scrolling of the s Creen when Writing to Location (80, 25). * / void Writechar (Char CH) {structure text_info ti; / * grab current text settings * / gettextinfo (& ti); / * interrupt 0x10 sub-function 9 * / _ah = 9 ; / * Character to be output * / _al = ch; _BH = 0; / * video page * / _bl = Ti.attribute; / * video attribute * / _cx = 1; / * repetition factor * / geninterrupt (0x10); / * Output the char * /} 16. Function name: getch header: Features: Nothing back from the console: int GETCH (Void); program example: #include < STDIO.H> #include int main (void) {char ch; printf ("Input a character:"); ch = getche ();

Printf ("/ NYOU INPUT A '% C' / N", CH); RETURN 0;} function name: getche header: Features: Take the character from the console (brought back "usage: INT getChe (void); program example: #include #include int main (void) {char ch; printf ("INPUT A Character:"); ch = getche (); Printf "/ NYOU INPUT A '% C' / N", CH); RETURN 0;} function name: getc header file: Features: Take a character from the stream: int GETC (File * stream) : #Include int main (void) {char ch; printf ("INPUT A Character:"); / * Read a character from the standard input stream * / ch = getc (stdin); printf ("THE Character Input Was: '% C' / N", CH); Return 0;} Function Name: getChar Features: From STDIN Sports Read Character Usage: Int getchar (void); program: #include < Stdio.h> int main (void) {INT C; / * Note That getchar reads from stdin and is line buffered; this means it will not return until you press enter. * / while ((c = getchar ())! = '/ n') Printf ("% c", c); return 0;} 17. Function name: getDisk header file: Features: Take the current disk drive letter: int GETDISK (Void);Delivatives: #include #include int main (void) {int disk; disk = getDisk () 'a'; Printf ("the current drive is:% c / n", Disk; Return 0;} function name: getDTA header file: Features: Take the disk transfer address usage: char far * getdta (void); example: #include #include < Stdio.h> int main (void) {Char Far * DTA; DTA = getdta (); Printf ("The Current Disk Transfer / Address IS:% FP / N", DTA); Return 0;} 18. Function Name: GetVect header: Features: Number of interrupt vector entrance: void interrupt (* getvect (int inter_num)); program case: #include <

Stdio.h> #include void interrupt get_out (); / * interrupt prototype * / void interrupt (* Oldfunc) (); / * interrupt function pointer * / int looping = 1; int main (void) { PUTS ("Press To Terminate); / * Save the Old Interrupt * / OldFunc = GetVect (5); / * Install Interrupt Handler * / SetVect (5, Get_Out); / * Do Nothing * / While (looping); / * restore to Original Interrupt Routine * / setVect (5, OldFunc); PUTS ("Success"); return 0;} void interrupt get_out () {looping = 0; / * Change global variable to get Out of loop * /} 19. Function name: getverify header: Features: Return DOS check flag status: int GETVERIFY (VOID); program: #include #include int main (void) {if (GETVERIFY ()) Printf ("DOS Verify Flag IS ON / N"); Else Printf ("DOS Verify Flag IS Off / N); Return 0;} 20. Function Name: Harderr Header: Features: Create a hardware error handler Usage: Void Harden (int (* fptr) ()); example: / * This Program Will Trap Disk Errors and Prompt The User for action. Try Running it with no disk in drive a: to invoke its functions. * / #include #include #include #define ignore 0 #define retry 1 #define Abort 2 INT BUF [500]; / * Define the error message for trapping disk problems * / static char * err_msg [] = {"Write Protect", "Unknown Unit", "DRIVE NOTY", "Unknown Command", "Data Error CRC) "," Bad Request "," Seek Error "," Unknown Media Type "," Sector Not Found "," Printer Out of Paper "," Write Fault "," Read Fault ","

General Failure, "Reserved", "Reserved", "Invalid Disk change"}; error_win (char * msg) {int RetVal; cputs (msg); / * Prompt for user to press a key to abort, retry, ignore * / While (1) {retval = getch (); if (retval == 'a' || RetVal == 'a') {RETVAL = Abort; Break;} if (Retval == 'R' || RetVal == 'R') {RetVal = Retry; Break;} if (Retval == 'i' || RetVal == 'i') {RETVAL = Ignore; Break;}} Return (RetVal);} / * prgma warn -par Reduces Warnings Which Occur Due to the Non Use of the Parameters Errval, BP and Si To The Handler. * / #pragma Warn -Par Int Handler (Int Errval, Int Ax, Int BP, INT Si) {Static Char MSG [80] Unsigned Di; int Di; int rt erroorn; di = _di; / * if this is not a disk error kil dam / if (ax <0) {/ * report the error * / error_win ("Device Error "); / * and return To The Program Directly Requesting Abort * / HardRetn (Abort);} / * OtherWise It Was a Disk Error * / Drive = AX & 0x00FF; ErrorNO = DI & 0x00FF; / * Report Which Error IT WAS * / SPRINTF (MSG, " Error:% s on drive% C / R / NA) BORT, R) ETRY, I) GNORE: ", ERR_MSG [ErrorNo], 'A' Drive); / * Return to the program via dos interrupt 0x23 with Abort, Retry, or ignore as infut by the user. * / hardresume (Error_WIN (MSG)); Return Abort;} #pragma Warn

PAR INT Main (void) {/ * install outmler on the hardware proBLERRUPT * / HARDERR (Handler); CLRSCR (); Printf ("Make Sure The Is No Disk In Drive A: / N"); Printf ("PRESS any key .... / n "); getCH (); Printf (" Trying to Access Drive A: / N "); Printf (" Fopen Returned% P / N ", FOPEN (" A: Temp.dat ", "w")); RETURN 0;} 21. Function name: Inport header: function: Input from hardware port: int database; program: #include #include int main (void) {int result; int port = 0; / * serial port 0 * / result = inport (port); Printf ("Word Read from Port% D = 0x% x / N ", port, result); Return 0;} 22. Function name: int86 header file: Features: Universal 8086 Soft Interrupt Interface Usage: int INT86 (int INTR_NUM, Union Regs * INREGS, Union Regs * Outregs; program: #include #include #include #define video 0x10 Void MoveToxy (int x, int y) {UNION regs regs; regs.h .ah = 2; / * set cursor post * / regs.h.d = Y; regs.h.dl = x; regs.h.bh = 0; / * video page 0 * / int86 (vi DEO, & Regs, & regs;} int Main (void) {clrs (); MoveToxy (35, 10); Printf ("Hello / N"); return 0;} function name: int86x header file: GM: Universal 8086 Soft Interrupt Interface Usage: INT INT86X (INT INTR_NUM, Union Regs * INSEGS, UNION Regs * Outregs, Struct Sregs * SegRegs); Series: #include #include #include int main (void) {char filename [80]; union regs inregs, outregs; struct Sregs segregs; printf ("Enter filename:"); gets (filename); INREGS.H.AH = 0x43 Inregs.h.al = 0x21; INREGS.X.DX = fp_off (filename); segregs.ds =

FP_SEG (FileName); INT86X (0x21, & INREGS, & OUTREGS, & Segregs); Printf ("File Attribute:% X / N", OUTREGS.X.CX); Return 0;} 23. Function Name: INTDOS header: GM: General DOS interface usage: int INTDOS (Union Regs * INREGS, Union Regs * outregs); program example: #include #include / * deletes file name; returns 0 on success, nonzero on failure * / int delete_file (char Near * filename) {UNION regs regs; int RET; regs.h.ah = 0x41; / * delete file * / regs.x.dx = (unsigned) FILENAME RET = INTDOS (& Regs, & Regs); / * if carry flag is set, there is an error * / return (regs.x.cflag? RET: 0);} int main (void) {int err; err = delete_file "NOTEXIST. $$$"); if (! ERR) Printf ("Able to delete Notexist. $$ / n"); Else Printf ("Not Able To Delete Notexist. $$ / N"); Return 0 (}) Function name: INTDOSX header file: Features: General DOS Interrupt Interface Usage: Int INTDOSX (Union Regs * INREGS, UNION Regs * Outregs, Struct Sregs * Segregs); Series: #include #inclu DELETES FILE Name; RETURNS 0 on success, nonzero on failure * / int delete_file (char far * filename) {UNION Regs regs; struct Sregs Sregs; int RET; regs.h.ah = 0x41; / * delete file * / regs.x.dx = fp_off (filename); SREGS.DS = fp_seg (filename); RET = INTDOSX (& Regs, & Regs, & Sregs); / * if carry flag is set, there is an error * / RETURN (Regs.x.cflag? RET: 0);} int main (void) {int err; err = delete_file ("NOTEXIST. $$$"); if (! ERR) Printf ("Able to delete Notexist. $$$ / n "); Else Printf (" "

NOT ABLE TO Delete Notexist. $$ / n "); Return 0;} 24. Function Name: INTR Header file: Features: Change Soft Interrupt Interface Usage: Void Intr_Num, Struct Regpack * PREG);: #include #include #include #include #define cf 1 / * carry flag * / int main (void) {Char Directory [80]; Struct Regpack REG; Printf ("Enter Directory to change to:"); gets (directory); reg.r_ax = 0x3b << 8; / * shift 3bh INTO AH * / REG.R_DX = fp_off (reg.r_ds = fp_seg (directory); INTR (0x21, & reg); if (REG.R_FLAGS & CF) Printf ("Directory Change Failed / N"); GetCwd (Directory, 80); Printf ("THE Current Directory IS:% S / N ", Directory; Return 0;} 25. Function Name: IOCTL Header: Features: Control I / O Device Usage: IOCTL (Int Handle, Int CMD [, int * argDX, int Argcx]); program example: #include #include #include int main (void) {int stat; / * USE FUNC 8 To DETERMINE IF The Default Drive Is Removable * / Stat = IOCTL (0, 8, 0, 0); if (! stat) Printf ("Drive% C Is Removable./N", getDisk () 'A'); Else Printf ("Drive% C Is Not Removable./N", getDisk () 'A'); Return 0;} 26. Function name: KBHIT header: function: Check the currently pressed key method: int KBHIT (Void); program case: #include int main (void) {CPRINTF ("PRESS any key to payue: "); while (! kbhit ()) / * do nothing * /; cprintf (" / r / na key was press ... / r / n "); return 0;} 27. Function name : keep header file: Features: Exit and continue to reside: void Keep (int status, int size);

Program Example: / *** NOTE:. This is an interrupt service routine You can NOT compile this program with Test Stack Overflow turned on and get an executable file which will operate correctly Due to the nature of this function the formula used to compute. the number of paragraphs may not necessarily work in all cases. Use with care! Terminate Stay Resident (TSR) programs are complex and no other support for them is provided. Refer to the MS-DOS technical documentation for more information. * / #include / * The clock tick interrupt * / #define INTR 0x1C / * Screen attribute (blue on grey) * / #define ATTR 0x7900 / * reduce heaplength and stacklength to make a smaller program in memory * / extern unsigned _heaplen = 1024; extern unsigned _stklen = 512; void interrupt (* oldhandler) (void); void interrupt handler (void) {unsigned int (far * screen) [80]; static int count; / * For a color screen the video memory IS AT B800: 0000. for a monochrome System use b000: 000 * / screen = mk_fp (0xB800, 0); / * Increase the counter and keep it weep 0 to 9 * / count ; count% = 10; / * put the number on the screen * / screen [0 ] [79] = Count '0' Attr; / * Call the old interrupt Handler * / OldHandler ();} int main (void) {/ * get the address of the current clock tick interface * / oldhandler = getVect ( INTR); / * Install the new interrupt handler * / setvect (inter, handler);

/ * _Psp is the starting address of the program in memory. The top of the stack is the end of the program. Using _SS and _SP together we can get the end of the stack. You may want to allow a bit of saftey space to Insure That Enough Room Is Being Allocated IE: (_SS (_SP Safety Space) / 16) - _PSP) * / Keep (0, (_ss (_SP / 16) - _PSP)); Return 0;} 28. Function Name: PEEK header file: Features: Check storage unit usage: int peek (int segment, unsigned offset); program: #include #include #include int main (void) {int value = 0; Printf ("The current status of your keyboard is: / n"); value = peek (0x0040, 0x0017); if (Value & 1) Printf (" Right Shift ON / N "); Else Printf (" Right Shift Off / N "); if (Value & 2) Printf (" Left Shift ON / N "); Else Printf (" Left Shift Off / N "); IF (Value & 4) Printf ("Control Key ON / N"); Else Printf ("Control Key Off / N"); if (Value & 8) Printf ("Alt Key ON / N"); Else Printf ("Alt Key Off / N"); if (Value & 16) Printf ("Scroll Lock ON / N"); Else Printf ("Scroll Lock Off / N"); IF (Value & 32) Printf ("Num Lock ON / N "); Else Printf (" NUM LOCK OFF / N "); if (Value & 64) Printf (" Caps Lock ON / N "); Else Printf (" Caps Lock Off / N "); RETURN 0; } Function name: peekb header file: Features: Check storage unit usage: char peekb (int segment, unsigned offset); program: #include #include # INCLUDE int main (void) {int value = 0; printf ("

The current status of your keyboard is: / n "); value = peekb (0x0040, 0x0017); if (Value & 1) Printf (" Right Shift ON / N "); Else Printf (" Right Shift Off / N ") ; If (Value & 2) Printf ("LEFT SHIFT ON / N"); Else Printf ("LEFT SHIFT OFF / N"); if (Value & 4) Printf ("Control Key ON / N"); Else Printf "Control Key Off / N"); if (Value & 8) Printf ("Alt Key ON / N"); Else Printf ("Alt Key Off / N"); if (Value & 16) Printf ("Scroll Lock On / N "); Else Printf (" scroll lock off / n "); if (Value & 32) Printf (" Num Lock ON / N "); Else Printf (" Num Lock Off / N "); IF (Value & 64) PRINTF ("Caps Lock ON / N"); Else Printf ("Caps Lock Off / N"); Return 0;} 29. Function Name: PERROR header file: function: System error information Method: Void Perror (Char * String); Question: #include int main (void) {file * fp; fp = fopen ("pERROR.DAT", "R"); if (! Fp) "Unable to open file forread"; return 0;} 30. Function Name: randbrd header file: Features: random block Reading: INT RANDBRD (struct fcb * fcbptr, int RECCNT); program: #include #include # Include #include int main (void) {char far * save_dta; char line [80], buffer [256]; struct fcb blk; int i, result; / * Get user input file Name for DTA * / Printf ("Enter Drive and File Name (NO Path - IE A: File.dat) / N"); gets (line); / * put file name in fcb * / if (! PARSFNM (Line, & blk, 1)) {Printf ("

Error In Call To Parsfnm / N "); Exit (1);} Printf (" DRIVE #% D File:% S / N / N ", BLK.FCB_DRIVE, BLK.FCB_NAME); / * Open file with dos FCB Open FILE * / BDOSPTR (0x0f, & blk, 0); / * Save Old DTA, and set new one * / save_dta = getdta (); setdta (buffer); / * set up info for the new dta * / blk.fcb_recsize = 128; BLK.FCB_RandoM = 0L; Result = Randbrd (& BLK, 1); / * Check Results from Randbrd * / if (! Result) Printf ("Read OK / N / N"); Else {Perror ("Error During Read "); Exit (1);} / * read in data from the new dta * / printf (" The first 128 character: / n "); for (i = 0; i <128; i ) PUTCHAR (BUFFER) I]); / * restore previous DTA * / setdta (save_dta); return 0;} 31. Function name: randbwr header file: Features: Random Block Writing: Int RandbWR (Struct FCP * FCBPTR , int Reccnt);: #include #include #include #include int main (void) {char far * save_dta; char line [ 80]; char buffer [256] = "Randbwr Test!"; Struct fcb blk; int result; / * get new file name from user * / printf ("Enter a file name to create (no path - ie. A: file.dat / n"); gets (line); / * Parse the new file name to the dta * / parfnm (line, & blk, 1); Printf ("DRIVE #% D File:% S / N", BLK.FCB_DRIVE, BLK.FCB_NAME); / * Request dos Services to create file * / if (BDoSPTR (0x16, & BLK, 0) == -1) {Perror ("Error Creating File"); EXIT (1);} / * save Old DTA and Set New DTA * / Save_dta = getdta (); setdta (buffer); / * Write new records * / BLK.FCB_RECSIZE =

256; BLK.FCB_Random = 0L; Result = RandbWr (& BLK, 1); if (! Result) Printf ("Write OK / N"); Else {PERROR ("Disk Error"); EXIT (1);} / * Request DOS Services to Close To File * / IF (BDOSPTR (0x10, & BLK, 0) == -1) {Perror ("Error Closing File"); EXIT (1);} / * reset the Old DTA * / SETDTA ( Save_dta); Return 0;} 32. Function Name: segread header: Features: Read Segment Register Value: Void Segread (Struct Sregs * segtbl); Procedure: #include #include int main (void) {struct Sregs Segs; Segread (& Segs); Printf ("Current Segment Register Settings / N / N"); Printf ("CS:% X DS:% X / N" , segs.cs, segs.ds; printf ("ES:% x SS:% x / n", segs.es, segs.ss); Return 0;} 33. Function name: setVect header file: Features: Setting Interrupt Vector Inlet Usage: Void setVect (int INTR_NUM, VOID INTERRUPT (* ISR) ()); program case: / *** Note: this is an interrupt service routine. You can not compile this program WITH TEST Stack Overflow Turned On and Get An Executable File Whi CH WILL OPERATE CORRECTLY. * / #include #include #include #define INTR 0X1C / * The Clock Tick Interrupt * / Void Interrupt (* OldHandler) (VOID); INT count = 0; void interrupt handler (void) {/ * increase the global counter * / count ; / * call the old routine * / oldhandler ();} int main (void) {/ * save the old interrupt vector * / OldHandler = getvect (INTR); / * Install the new interrupt handler * / setvect (inteller); / * loop untric the counter Exceeds 20 * / while (count <20) Printf ("count IS% D / N", COUNT);

/ * reset the old interrupt handler * / setVect (INTR, OLDHANDLER); RETURN 0;} 34. Function name: Sleep header file: Features: Performing a Snexing SepleP (unsigned SECONDS) ); #Include #include int main (void) {INT i; for (i = 1; i <5; i ) {printf ("Sleeping for% D Seconds / n ", i); SLEEP (I);} return 0;} 35. Function name: ungetc header file: Features: Return a character to the input stream: int ungetc (Char C, File * stream);: #include #include int main (void) {int i = 0; char ch; PUTS ("INPUT AN INTEGER FOLLOWED BY A CHAR:"); / * Read Chars Until Non Digit or EOF * / while ((ch = getchar ())! = EOF && Isdigit (CH)) i = 10 * i ch - 48; / * Convert Ascii Into int value * / / * IF Non Digit Char Was Read, Push It Back INTO INPUT Buffer * / if (CH! = EOF) UNGETC (CH, STDIN); Printf ("i =% D, Next Char in buffer =% C / N", I, GetChar ()); Return 0;} function name: ungetch header: Features: Return a character to the keyboard buffer usage: int ungetch (in TC); CHINCLUDE #include #include int main (void) {int i = 0; char ch; PUTS ("INPUT AN INTEGER FOLLOWED BY A Char: "); / * Read Chars Until Non Digit or EOF * / while ((ch = getche ())! = EOF && Isdigit (CH)) i = 10 * i ch - 48; / * Convert Ascii Into Int Value * / / * if Non Digit Char Was Read, Push It Back INTO INPUT Buffer * / IF (CH! = EOF) UNGETCH (CH); Printf ("/ N / Ni =% D, Next Char in buffer =% C / N ", I, getch ()); return 0;} 36. Function Description: Char * cgets (char * STR);

转载请注明原文地址:https://www.9cbs.com/read-114709.html

New Post(0)