- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>
' |/ w( z! V; Z2 u- U< align=left><FONT color=#ff0000>函数名: imagesize</FONT> " t+ f m5 U/ t6 j3 y2 b
功 能: 返回保存位图像所需的字节数
C' m- r @2 l用 法: unsigned far imagesize(int left, int top, int right, int bottom); , V1 t T# Y- S: v4 K3 L+ ?; w
程序例: </P>
; g) I- X$ Y: V9 ^9 {+ A3 {< ><FONT color=#0000ff>#include <GRAPHICS.H>
z- m u s2 N1 \7 i#include <STDLIB.H>
8 M' D! x- p! d# O! i: C0 [#include <STDIO.H>
9 w: ?7 P) ]/ a3 W#include <CONIO.H></FONT></P>$ m: s* k& U4 q9 H5 Z
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>7 l, b3 ]6 y1 v" O
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>5 o; |+ X" Y3 `( v. J5 f1 V
< ><FONT color=#0000ff>int main(void) 2 g! G1 z/ r1 G1 L/ s
{ " D& Z$ Z8 K9 b6 L: N
/* request autodetection */
$ k5 B* I2 H" P' \" ]& A* R# w8 K) ~int gdriver = DETECT, gmode, errorcode;
* _$ L; k0 t( N, yvoid *arrow; - r: w! f( J" P8 a3 Y
int x, y, maxx;
' U) @) t# j5 B8 i0 Aunsigned int size; </FONT></P>+ A, G I8 G- S* I4 s. |/ p: Y
< ><FONT color=#0000ff>/* initialize graphics and local variables */ ( B5 x3 T# {' i
initgraph(&gdriver, &gmode, ""); </FONT></P>
8 D1 G, {8 l2 A" {< ><FONT color=#0000ff>/* read result of initialization */
8 |& t7 B* r& Kerrorcode = graphresult();
# D D) a) u1 A$ } yif (errorcode != grOk) /* an error occurred */ , c ~1 {/ T' _4 v% H& G9 `8 V
{
0 A+ _% u' z$ v/ Rprintf("Graphics error: %s\n", grapherrormsg(errorcode));
$ [% n; R9 H) B- m- p1 `9 o4 pprintf(" ress any key to halt:"); 3 Q% p. N; ~+ B/ M) e7 k6 d/ b4 g
getch(); ! v, C! z2 t- ^1 c5 }- s
exit(1); /* terminate with an error code */
' q* G# y1 h! u5 Y} </FONT></P>
/ q/ s: p1 V3 ]* p, O< ><FONT color=#0000ff>maxx = getmaxx();
+ o+ |& F% ~) \1 Y; l" \$ q+ t# qx = 0; % `8 I4 Q% D: j ~2 j& d
y = getmaxy() / 2; </FONT></P>9 i( b+ o3 ~# e: V) @* z% M
< ><FONT color=#0000ff>/* draw the image to be grabbed */ # i3 t {# }* w* |5 J" w" K
draw_arrow(x, y); </FONT></P>
$ n$ o/ e8 n4 r1 d- t) ^< ><FONT color=#0000ff>/* calculate the size of the image */
j2 Q+ J' s: @* bsize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>; s! Y3 k# z; [; R4 {
< ><FONT color=#0000ff>/* allocate memory to hold the image */ / |$ P" V7 C; B% X) X" N' @2 N
arrow = malloc(size); </FONT></P>0 L |( r$ q' K+ t* e6 ]
< ><FONT color=#0000ff>/* grab the image */ / ~6 j+ p( d2 H
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>* l! G$ Q. j) s+ E6 a) A
< ><FONT color=#0000ff>/* repeat until a key is pressed */
! ^. y' k1 N8 }0 L# awhile (!kbhit()) 1 L& U( q9 m7 u0 S/ T' F, w
{ 9 t9 P0 d* U) T/ H$ J- R
/* erase old image */
9 L2 w$ {; o. T. a1 ~& P" |$ S, `putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
" x7 m4 T) ?% U. M6 B+ d< ><FONT color=#0000ff>x += ARROW_SIZE;
5 A/ b% Q+ H/ w4 C4 qif (x >= maxx)
3 Y; Z9 Z, f# w) r% P" l, [6 [0 Cx = 0; </FONT></P>" f; N; `. Y" u9 Q* Y1 o
< ><FONT color=#0000ff>/* plot new image */
5 h$ G, h0 W x& m& ~0 Zputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); % x4 s% a$ q \8 R+ @6 J" a2 k/ M. f$ |
} </FONT></P>* w* w# H8 Z/ y8 ^0 n
< ><FONT color=#0000ff>/* clean up */
( J- p( O: u+ Q/ v( d( E5 Cfree(arrow); % o! i% ]( @& X, H0 w$ I2 V& m
closegraph();
: X4 ^) m1 a/ g9 g4 l9 ireturn 0; - y0 _% l$ z Q" I" l
} </FONT></P>2 p( ^- h: z- r; g* d
< ><FONT color=#0000ff>void draw_arrow(int x, int y) 2 ^( f7 D9 }5 C* J5 ~5 X1 M+ s
{
( L: P; ]) S2 H+ l) M/* draw an arrow on the screen */ 7 I$ F7 x3 j9 l' m
moveto(x, y); [$ s5 y3 c5 T; }! n# S u8 X3 e
linerel(4*ARROW_SIZE, 0);
9 |' f7 v, Q0 `5 ^4 h0 x' ?linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); 0 l) T0 j- [7 R# F3 t' i& W
linerel(0, 2*ARROW_SIZE);
8 y% J8 Q _$ xlinerel(2*ARROW_SIZE, -1*ARROW_SIZE);
1 z0 \; b: X0 k0 u" C4 S# T0 E}
/ C' v3 C/ s* r, h9 q+ Q8 g. n m8 G; X# T9 {# R. [
% W/ t9 w: f: F4 V- w</FONT></P>( z4 I5 n9 k0 A, s
< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
6 [% B2 I& X8 D% S% Z/ ~/ |2 k _<FONT color=#000000>功 能: 初始化图形系统 & t G; s4 n. L5 \8 @
用 法: void far initgraph(int far *graphdriver, int far *graphmode,
# s r" n% {! P' Q, n! j1 fchar far *pathtodriver);
; C1 p1 h% z E J% I程序例: </FONT></FONT></P>$ B" {7 ^# g) e* ]7 {. E
< ><FONT color=#0000ff>#include <GRAPHICS.H>
) p7 Y3 U8 h% K$ z2 t8 M#include <STDLIB.H>* B% m) K, B6 Z" i
#include <STDIO.H>( K8 r* V# z* B- o8 A2 n
#include <CONIO.H></FONT></P>
, A+ }0 _$ G; u< ><FONT color=#0000ff>int main(void) " t" `& S; y b3 D% B
{ % w) p. P. [* C. l
/* request auto detection */ ; [ K1 {6 e) c. L/ S5 _
int gdriver = DETECT, gmode, errorcode; </FONT></P>
0 \$ G" N, o/ N- K$ V1 \ ^< ><FONT color=#0000ff>/* initialize graphics mode */ ' U @. M3 f7 |' R
initgraph(&gdriver, &gmode, ""); </FONT></P>
& @* O; y3 ]: z< ><FONT color=#0000ff>/* read result of initialization */ $ L; B3 C1 l+ b) _
errorcode = graphresult(); </FONT></P>
# W7 v: {8 _4 o, t< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ : B' [$ a1 e- N8 P
{
, C9 T9 t' _! J: Oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
3 G b4 ~! V1 C) @printf(" ress any key to halt:");
6 o% @( ]( A e; r2 W; t2 F! h- |, Lgetch(); p2 U8 r! W4 g. p8 o+ \+ ^$ j1 T
exit(1); /* return with error code */
* g4 H0 o: p: E! S( ~0 F. q$ G} </FONT></P>1 g$ S) c3 A$ q- n7 ?* N
< ><FONT color=#0000ff>/* draw a line */ 6 @' e q R: }. L
line(0, 0, getmaxx(), getmaxy()); </FONT></P>/ n7 l( R/ ~9 j4 a7 ?) L
< ><FONT color=#0000ff>/* clean up */
; }1 |) ]2 o9 [& bgetch();
' v- C* }# k# V! w4 Y: J9 j. tclosegraph(); , M# @5 w5 {; N/ T) B
return 0; 0 r4 O1 S; v- Y' g% t1 c, r
} </FONT>
0 H3 @; _- R- O* j
9 \, X& D1 z: Q9 h* D; |; _</P> ]6 v/ y3 W% y: x5 Y
< ><FONT color=#ff0000>函数名: inport </FONT>4 O5 x9 V6 S4 P/ k- C
功 能: 从硬件端口中输入
. [" x" v/ y4 k! [9 s用 法: int inp(int protid); ; [7 P# [6 ^9 K5 X; {: ^
程序例: </P>- G+ f# N/ }: P2 @
< ><FONT color=#0000ff>#include <STDIO.H>! C8 q( c$ N/ U& y! U
#include <DOS.H></FONT></P>
' S8 N, q4 M; y+ j<P><FONT color=#0000ff>int main(void)
0 o6 p: D+ \; F{
^, s5 b! E, \1 P4 `5 bint result;
6 a5 e `( H6 X3 {2 iint port = 0; /* serial port 0 */ </FONT></P>! ^( b3 ^% _( h2 y% k5 T
<P><FONT color=#0000ff>result = inport(port);
# V* z: _3 \, G* k3 B/ t& D0 eprintf("Word read from port %d = 0x%X\n", port, result); & S0 N( z6 z' D$ k1 m/ q/ }( H
return 0;
/ D4 y9 r8 C( @' W$ \} 4 h! M# {) W' U; l; I8 k7 B& }
( `8 U8 i3 J4 _0 b/ J& T9 x</FONT></P>
( N1 U% b; T) @8 ]! @% m<P><FONT color=#ff0000>函数名: insline </FONT>
# ~5 I5 [% @/ G/ r/ ]功 能: 在文本窗口中插入一个空行
8 y5 o. B8 P6 b0 l4 c: K" n% x用 法: void insline(void);
8 `7 O( ?5 k( Y. S% S* @程序例: </P>
$ G, z$ P- I) {. g. ]. s6 I<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
' Q; C2 T/ e S5 p! M2 d' z% h<P><FONT color=#0000ff>int main(void)
- V5 T/ n; @- ^8 N{
( }2 ?# S* U7 Q) }9 H( Uclrscr();
; r m4 ?+ A) W9 ~; K6 kcprintf("INSLINE inserts an empty line in the text window\r\n");
8 d2 K# f) w+ l1 m/ u( Z, mcprintf("at the cursor position using the current text\r\n"); : z2 o# ^8 c8 ~6 R
cprintf("background color. All lines below the empty one\r\n"); 9 f, F7 M+ }- p6 U( E0 ~
cprintf("move down one line and the bottom line scrolls\r\n"); 3 r$ v3 M# y4 {
cprintf("off the bottom of the window.\r\n"); $ u/ i# {5 O, y; j3 i0 d
cprintf("\r\nPress any key to continue:");
/ V% \2 Q: ^) M) }gotoxy(1, 3); 6 Z/ v% G$ x5 y% l
getch();
( X! w; L0 C5 p( o/ Y. iinsline();
, K+ Z" M$ s" l' F& O7 ~getch(); # h( B a$ q7 O8 }: F! `* {
return 0;
# r( z' [/ d9 p} 6 U8 K$ x# T# T- Z
</FONT>) F+ B1 r. r2 F y6 g
+ T) i q. K4 f
</P>
1 y8 M, A, i1 B! m<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
+ Z+ A, k7 t! o5 Q: h( X功 能: 安装设备驱动程序到BGI设备驱动程序表中 * X2 W9 S4 b, c8 g
用 法: int far installuserdriver(char far *name, int (*detect)(void));
# L% Q% Y) Q) a( K, O6 q程序例: </P>/ k; ?8 a7 s, s: A
<P><FONT color=#0000ff>#include <GRAPHICS.H>5 r/ ?/ |" M5 p& I9 c+ T3 d. c- K8 }
#include <STDLIB.H>
" l2 i2 @4 y5 k#include <STDIO.H>
% \0 Y7 ]8 k5 R+ i6 o2 u: C#include <CONIO.H></FONT></P>/ v- ?( J9 s* g Q
<P><FONT color=#0000ff>/* function prototypes */ 3 B: O% U+ h( {
int huge detectEGA(void); * F( {" f. C2 \! ?* ~( [$ l$ E
void checkerrors(void); </FONT></P>
: @& q Q* L0 k<P><FONT color=#0000ff>int main(void) # I1 y8 B; q+ k+ D
{
& [, W3 M( [* @1 gint gdriver, gmode; </FONT></P>
! C* a6 V2 Y/ F0 r. r7 v) O<P><FONT color=#0000ff>/* install a user written device driver */ 6 f R$ m7 C# Y; i2 ]
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
; b) B+ _, S* `% `8 ]: \3 B<P><FONT color=#0000ff>/* must force use of detection routine */
1 \ K& l$ G! j& ggdriver = DETECT; </FONT></P>
1 r0 F4 ?1 ]5 b8 K7 A2 y$ E2 A<P><FONT color=#0000ff>/* check for any installation errors */
\7 q2 @" N$ D5 [- [( M. ~checkerrors(); </FONT></P>( p5 k! _+ F% Q) J! f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 V4 `9 A. C! I! Dinitgraph(&gdriver, &gmode, ""); </FONT></P>/ |1 N& y4 y3 d! B
<P><FONT color=#0000ff>/* check for any initialization errors */ - J+ i- g4 X& {# f+ [# p
checkerrors(); </FONT></P>
* g- O8 s# s! q: H; o; d<P><FONT color=#0000ff>/* draw a line */ ' K$ R2 g {0 ?4 B- J
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
& W! k A9 n4 w0 [# M9 g<P><FONT color=#0000ff>/* clean up */
+ B; L" G3 \! ]; b1 ?$ Vgetch(); q2 {9 Q, t! {: D* e5 `
closegraph(); 9 g. M8 |' Q$ m0 E
return 0;
: F: a; }/ e' R }" F9 u! L} </FONT></P>) j m) g! \. @, C& b
<P><FONT color=#0000ff>/* detects EGA or VGA cards */ 2 c% T( I( _# ]( w8 y' A, T! O$ i
int huge detectEGA(void)
$ @* k+ i0 z0 ]. N g! Z8 L{
% {9 j6 I! r3 g; o8 t3 g7 Eint driver, mode, sugmode = 0; </FONT></P>% F% A* e/ _9 s* h1 }2 ?
<P><FONT color=#0000ff>detectgraph(&driver, &mode);
/ `+ \! {6 v0 bif ((driver == EGA) || (driver == VGA)) - H, n" Z) k$ p5 D1 }4 ]! `# L
/* return suggested video mode number */
+ f' ` C& A+ z7 Greturn sugmode; : C+ m& E* a) y3 f
else
' u: W( ~, w* h, }8 V& A7 i/* return an error code */ " q3 V y; f9 M% f8 F- T& d: E
return grError; ) a7 s% P' k* \9 y7 H2 `( d9 F# m
} </FONT></P>
" J# W6 T( [, m4 f<P><FONT color=#0000ff>/* check for and report any graphics errors */ 0 f' t7 U$ a: f' }+ e: F
void checkerrors(void) + @# n/ B, ?( K" l; X
{ 9 D J" \$ s) V8 d
int errorcode; </FONT></P>
" b6 u+ c# \4 h1 @<P><FONT color=#0000ff>/* read result of last graphics operation */ ' _7 e/ v9 Y( ~6 x( m* L1 B, l# m4 K
errorcode = graphresult();
; {" _8 ?$ R: w, l; cif (errorcode != grOk)
& W2 Z1 v% U6 N: P* B# [! A{
6 H- e5 v- |8 Z" R% X8 t0 J! j) H( [3 Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, B' p1 j/ X9 C2 C$ iprintf("Press any key to halt:"); ; q. A7 h* Z. D4 P: P. i' P
getch(); # a4 n# j* H+ n
exit(1); ; D5 g: ]3 z$ @$ N# n
}
' A; y$ f5 N3 G# Y- y# _7 T- X- d} </FONT></P>
" t# c v/ @; F<P><FONT color=#ff0000>函数名: installuserfont </FONT>4 I* H. k2 b1 ?5 N, [6 f
功 能: 安装未嵌入BGI系统的字体文件(CHR)
* g# g, v! I! n' l- ^用 法: int far installuserfont(char far *name); 3 }* ^9 L, y9 g, ]- v& f6 ]# P
程序例: </P>
Y/ @9 Z% D9 G: N<P><FONT color=#0000ff>#include <GRAPHICS.H>
V( Z) Q+ u7 v, e2 p#include <STDLIB.H>: I" x0 z8 v O1 K3 o
#include <STDIO.H>
8 ?2 J3 [1 M" Z$ c9 S; H( F6 l#include <CONIO.H></FONT></P>
8 D5 L( |# _. N<P><FONT color=#0000ff>/* function prototype */ * X& a% Y9 g3 G- Y7 N! y* \+ L2 ?
void checkerrors(void); </FONT></P>
, p" h9 W E9 p8 E/ {<P><FONT color=#0000ff>int main(void) i6 G. O8 e% }9 h4 m3 @( t* B
{
, K, m3 s( A( n- ^* L+ |/* request auto detection */
) Y' b8 D( ^1 v0 ~4 w/ Y/ xint gdriver = DETECT, gmode; 2 }# q2 v, u% C; y+ z: R- [7 q$ w
int userfont; ) W7 C, e' Z+ T7 R& V
int midx, midy; </FONT></P>
5 n( b' M2 _5 ^, P7 }9 L: P' l<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ T8 a& X# t; N) kinitgraph(&gdriver, &gmode, ""); </FONT></P>
" X' ]3 p- |# r9 v1 u% B<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 B/ D0 ~$ R" ]5 c! h5 T
midy = getmaxy() / 2; </FONT></P>
* U1 X5 J! b9 w! N8 ]* ]0 [* w<P><FONT color=#0000ff>/* check for any initialization errors */ , i' R# t+ K1 u2 v- {
checkerrors(); </FONT></P>2 W4 X* R) O; u3 v4 j" A) R
<P><FONT color=#0000ff>/* install a user defined font file */ ! U8 m: Q0 |; z; t& w0 V
userfont = installuserfont("USER.CHR"); </FONT></P>
/ h3 W, _% S9 o, s<P><FONT color=#0000ff>/* check for any installation errors */ 2 Y1 {/ Q: T% s- A2 {
checkerrors(); </FONT></P>
g3 C; |/ o K s! D6 Z/ ]' V& E<P><FONT color=#0000ff>/* select the user font */ 4 o ]+ }6 S1 p1 s, T3 A
settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>5 D3 @0 V2 v6 f( C: f
<P><FONT color=#0000ff>/* output some text */ 1 e3 }/ t8 O: D' Q
outtextxy(midx, midy, "Testing!"); </FONT></P>
& S4 ~% M0 A* y& \6 a8 x4 Q<P><FONT color=#0000ff>/* clean up */ . e, m! P- S' ~, t. h$ _
getch();
3 T9 ?0 F# |! fclosegraph();
6 \ M3 B+ V* dreturn 0; % }7 y! ~( Y6 |+ }
} </FONT></P>
5 k* z: |* o! B7 H3 Q: q3 c/ ^<P><FONT color=#0000ff>/* check for and report any graphics errors */
9 f$ R: P8 w. d- Dvoid checkerrors(void) " f: W4 o8 f0 ` d! s$ l6 N! J" Z
{
! g! G0 D4 o3 n6 `int errorcode; </FONT></P>3 r& o& ]7 j% n
<P><FONT color=#0000ff>/* read result of last graphics operation */ # J7 i& }4 w# Y. p
errorcode = graphresult(); 6 J" b9 l& ?) X7 `& r
if (errorcode != grOk) 0 } h* ^6 f# T( i% y# K
{
( B- I8 ^4 @3 p$ f9 Cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " h8 Y, I+ X" G1 r
printf("Press any key to halt:"); + H5 X) _' g" Y/ ]
getch(); + X/ s) ^# N4 \) C% z
exit(1); z" \' q6 B: }5 R
}
w* k: R" Z6 L1 O# t} </FONT>
P; J4 ]. `6 m* X4 x. l" i2 |; X
6 u9 D) M: ~! Y, t2 i0 I
, B1 s9 H9 I) i" @" s D</P>! I6 ]8 g/ G( ^
<P><FONT color=#ff0000>函数名: int86 </FONT>& x+ m H, A8 w
功 能: 通用8086软中断接口
/ E( P9 D& u0 O) C6 _* [' C2 p5 c用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); ' L( B1 O2 }# R6 _
程序例: </P>" k+ `& q3 d* G- j
<P><FONT color=#0000ff>#include <STDIO.H>. E d% [2 N% y4 u9 Z
#include <CONIO.H>3 h4 u0 {4 |1 x; J0 z3 p/ u
#include <DOS.H></FONT></P>
1 k; ?! b7 m7 w& V* g4 H2 r<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
, P. p. \' ]5 E9 M1 Z& A3 m<P><FONT color=#0000ff>void movetoxy(int x, int y) ! d5 ^' M* ~" L2 ~, q6 o+ G
{
4 v! @3 ^+ g" K; B% d3 e8 ounion REGS regs; </FONT></P>
0 [ I0 k' ~" N! D<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
$ h; x9 N' G V* f: I2 g! u& @regs.h.dh = y; 6 c9 o2 z6 |# I7 S
regs.h.dl = x; 4 q3 D8 g/ }" y- O+ S
regs.h.bh = 0; /* video page 0 */
0 j' \3 b/ ?5 o6 C K! Yint86(VIDEO, ®s, ®s);
& m" p. @) q) w) B! W0 t( D: \} </FONT></P>
% u% w. T& F6 f4 N9 Z5 K$ W% l<P><FONT color=#0000ff>int main(void) 2 ^2 a$ l E# u# u" {
{
K: U/ V/ H0 Tclrscr();
( m6 g. A% N% L9 I! ^7 W% kmovetoxy(35, 10);
7 _0 F, v# W$ e6 Rprintf("Hello\n");
7 h) p% v8 @8 Zreturn 0; ; `( [" `6 N. A6 \, }$ ^
} </FONT>7 x+ \4 ^; N$ D; K' ~7 i
$ F# j# V# L8 B9 e2 J
</P>
$ z. o9 f6 ?% b0 n! O<P><FONT color=#ff0000>函数名: int86x </FONT>; M: C+ t9 B* q) T3 Y4 c
功 能: 通用8086软中断接口 4 M+ E- \) p9 O' ?$ x" @; Q. J
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, : W; f+ ]9 s: \, t
struct SREGS *segregs); ; r, [3 A. L$ M" B% y
程序例: </P>5 s& l* s3 x/ I7 e
<P><FONT color=#0000ff>#include <DOS.H># C2 T: b8 {. _" T7 a$ d
#include <PROCESS.H>
( P- k# b# V, L) F#include <STDIO.H></FONT></P>
v% y3 u, w* F# `: d" T9 h<P><FONT color=#0000ff>int main(void)
- h7 P2 K9 j1 |+ }! D/ ~) k5 u{ P8 M2 C! [4 _5 Q) U+ x
char filename[80];
* l T v( K$ \: l$ @- ?4 |7 Hunion REGS inregs, outregs; ) @# S; Z# ^$ u
struct SREGS segregs; </FONT></P>
, W* J& `" J% f+ a2 z( Q! ^& ^5 c: H<P><FONT color=#0000ff>printf("Enter filename: "); n5 k# e" J* Y- I
gets(filename);
; r7 O- S' r& e2 f/ f4 ?$ Y6 o% Rinregs.h.ah = 0x43; / s6 D1 k# ?, [( y, {
inregs.h.al = 0x21; 9 f8 c4 f1 p6 A: X
inregs.x.dx = FP_OFF(filename);
, T% h" Y3 p, F* }; B& jsegregs.ds = FP_SEG(filename); 0 L9 G; w1 o1 |& C
int86x(0x21, &inregs, &outregs, &segregs); - O1 F+ S6 o+ s5 Q9 M. T* m
printf("File attribute: %X\n", outregs.x.cx);
/ H4 ]5 I& t# n5 e: ~. i: rreturn 0; " e- D' k# n0 z" s
} , D3 u4 ]& o& m$ ]( h
- K4 {% H. X) [+ W8 l6 k
</FONT>
8 X3 N$ \3 r4 F9 O</P>
' e3 _- H4 T/ g. T2 t2 |<P><FONT color=#ff0000>函数名: intdos </FONT>0 K4 Z! N5 ]9 t0 Q* h: d% l
功 能: 通用DOS接口 & W: F% S0 ?$ l4 S1 d
用 法: int intdos(union REGS *inregs, union REGS *outregs); ! |' M* v+ Z6 S; j: f* s
程序例: </P>, ~& P4 R" b2 N
<P><FONT color=#0000ff>#include <STDIO.H>
8 r9 A) L: ^1 F#include <DOS.H></FONT></P>
! j7 K' i h9 L8 T<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
7 U" ]( F" J- ~* \2 K7 J! }& k' ] Dint delete_file(char near *filename) & f1 s0 e- F# r
{ + N4 k4 X7 N. n4 r
union REGS regs;
) H7 `- f, D0 _. c7 D8 K# Dint ret;
r$ @& o8 M w2 p8 V- u9 Y3 U7 a1 jregs.h.ah = 0x41; /* delete file */ ) I0 ^/ }1 u( m7 l+ E T: H) e
regs.x.dx = (unsigned) filename;
% ?& |5 G8 {- e/ Z3 S3 f5 \- Bret = intdos(®s, ®s); </FONT></P>% T% m& y' G% W5 T* p2 L" n
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ 7 l& z' }' J' e2 _( Y
return(regs.x.cflag ? ret : 0);
5 d5 N X$ s% v4 G9 e} </FONT></P>9 A7 p. U/ v& b) m
<P><FONT color=#0000ff>int main(void)
0 r1 H7 d, P0 o& O6 H6 \( ^{
$ {' j Q+ P; G" k+ l$ d" Gint err;
3 q2 o3 @" Y: x& F1 Y. o$ Qerr = delete_file("NOTEXIST.$$$"); 9 { \) G4 J) A. r* S& X* B" I
if (!err)
- V; D$ G. y" Q: B" Jprintf("Able to delete NOTEXIST.$$$\n");
: k. H& G3 b* Y$ k* pelse
8 B; B' }4 `. c+ U8 y% aprintf("Not Able to delete NOTEXIST.$$$\n"); 1 H7 H0 V( e, n
return 0;
" W2 D) P' L. @+ b* \* J& l} * d7 P5 Q* g% @$ C' N- S
& M, N/ P: r6 z9 F! U8 K
</FONT>3 j3 m& c+ R! b! H0 r
</P>
7 ^3 d: W; k4 p# W<P><FONT color=#ff0000>函数名: intdosx </FONT>
1 C) }( Z( s+ g0 y; T+ b功 能: 通用DOS中断接口 , q% |/ s- d4 p! ^
用 法: int intdosx(union REGS *inregs, union REGS *outregs, 2 _7 X0 r) j8 Q$ W
struct SREGS *segregs); 2 _' y) H4 o- M! a5 r) ^
程序例: </P>' K' p0 T( ~- j* A: a* {
<P><FONT color=#0000ff>#include <STDIO.H>
. P$ S6 v. ^/ m5 h#include <DOS.H></FONT></P>
6 _4 O$ l2 N" T5 q( F9 M' b/ m<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ " u9 r: P) v/ U/ D7 ]5 D `
int delete_file(char far *filename) % f0 i" o8 F3 Q! J
{ / j0 N3 s3 Z# c. h1 D8 e% V
union REGS regs; struct SREGS sregs;
5 L$ \, S7 d1 ~ j4 j \int ret;
6 X4 `+ ]/ M# I. H% hregs.h.ah = 0x41; /* delete file */ 4 u4 l' o7 S1 u. Y
regs.x.dx = FP_OFF(filename); : I$ l+ t# l4 @1 H. L
sregs.ds = FP_SEG(filename); $ e* t% k" ^2 V. h. o' i
ret = intdosx(®s, ®s, &sregs); </FONT></P>
* I/ L! N" c o7 x! T- n<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
7 c' p* q+ j6 k0 _( B' [& ?7 ireturn(regs.x.cflag ? ret : 0);
1 n1 P/ I; n( H, y0 U( `& C. v} </FONT></P>
' E( K, {0 V2 z I3 w/ ], X( n7 {<P><FONT color=#0000ff>int main(void) L+ z: ^4 ]. Q3 a* v7 q. v
{ 3 F( r" l* R) ]$ a. }- O
int err; 7 C( {0 t: \. |2 ?6 w
err = delete_file("NOTEXIST.$$$");
! w3 U- ]' A/ }' a& s9 d4 Kif (!err)
. Y' Z5 p/ D+ s" ?3 yprintf("Able to delete NOTEXIST.$$$\n"); / M0 z) `! t/ I
else - W. r5 z* r- j: b: @
printf("Not Able to delete NOTEXIST.$$$\n");
3 D M: B: I: R1 Z4 L) [% q2 qreturn 0;
8 N6 U0 h3 m* M# e) b4 l" K} 6 ?; p0 s% o1 ]' c& ~: X3 e8 f
</FONT>
8 S& k: @, p; y- m</P>
3 o# |4 m6 L$ K2 Z<P><FONT color=#ff0000>函数名: intr </FONT>9 E4 N4 s4 a: c/ H% I$ B
功 能: 改变软中断接口 " w7 V3 A! r% `, K
用 法: void intr(int intr_num, struct REGPACK *preg);
' c" n7 L+ X+ {% k1 E1 o程序例: </P>) n \& G) i! _, x7 B; ^3 d( r, R
<P><FONT color=#0000ff>#include <STDIO.H>
# d( ^5 Z* C/ R8 I7 X. Z' b#include <STRING.H>
- E3 C3 j0 j+ m9 E# d2 B6 d4 ^4 o#include <DIR.H>
2 x2 ]: ~. ^9 M* Q/ n4 f#include <DOS.H></FONT></P>! L. F; J# F! O- x/ v$ P) O0 P
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>3 z- z" T8 E8 O& l4 { J
<P><FONT color=#0000ff>int main(void)
1 c, g$ v. r5 |{ & B+ F Z3 n2 O* `/ Q+ z
char directory[80]; 4 ~" G( [2 g% ~) u
struct REGPACK reg; </FONT></P>
, r) p, E" d) H<P><FONT color=#0000ff>printf("Enter directory to change t "); $ L4 B4 J& x( I
gets(directory); 0 v. r; o$ l6 G# E) V
reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */ ! v: K- d) K1 @ P
reg.r_dx = FP_OFF(directory);
2 h# C& x g9 Q2 ^5 C. g8 Nreg.r_ds = FP_SEG(directory); ; v3 X3 d/ Q/ A
intr(0x21, ®);
2 j& A% `! l C+ Wif (reg.r_flags & CF)
0 S" T$ S, P8 D5 Q6 o7 nprintf("Directory change failed\n"); 1 z, d) n/ Q) n' {6 t5 l
getcwd(directory, 80); " ]' Y- i9 b' {) L
printf("The current directory is: %s\n", directory); * j' w& }( z _4 H7 N& K
return 0; 7 j9 h* F* g) k, l
} " A- K* e8 l% n: i5 q o6 a
</FONT>1 t' P! D c4 G8 s& B+ R; f3 T
</P>
1 Z6 v% ], m6 f d, V0 O<P><FONT color=#ff0000>函数名: ioctl </FONT>
. n8 T+ ]8 ~) X( _, h) H功 能: 控制I/O设备
0 p$ q# a+ I1 c& P用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
5 n N7 T9 Z7 @# D( b$ Q程序例: </P>
0 t- X4 p! J9 B9 T<P><FONT color=#0000ff>#include <STDIO.H>) L! ?/ p' D; r
#include <DIR.H> t- k z9 w) R8 C* b) f
#include <IO.H></FONT></P>/ T; c; m) {# t9 [: m
<P><FONT color=#0000ff>int main(void) % l+ V3 p6 l2 _4 x8 R, p
{ * {! {/ c% _. h0 T7 `; L3 w
int stat; </FONT></P>, _. E" ]" O ` ~/ R
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ 0 b" N( s- \3 O7 }5 c/ L
stat = ioctl(0, 8, 0, 0);
, m9 [- s9 @+ Q$ m8 N; q. ?if (!stat)
& U! g S. Q6 N6 w% d9 z( y8 Vprintf("Drive %c is removable.\n", getdisk() + 'A'); ' S& \: b2 ?9 U7 n4 A" l
else
4 {; q& J ~% k% r* l) uprintf("Drive %c is not removable.\n", getdisk() + 'A'); 8 I& Q+ u% ~2 {3 @
return 0;
1 Y3 i% o) g5 k}
- q+ F! o V& [+ U* Z: }
- _4 f$ y0 n& o; t. \6 A2 R</FONT>7 M. R; i9 H' z# n/ T
</P>
0 d2 x( s2 d9 `+ B<P><FONT color=#ff0000>函数名: isatty </FONT>1 L; v/ Y* A( I* p: o! `% d' L
功 能: 检查设备类型
* M: \, z! U5 l m. M/ e; d+ j) K7 w用 法: int isatty(int handle); 4 c/ r! N, b6 J, _
程序例: </P>
- P( h5 ]0 l6 C; U) `' l<P><FONT color=#0000ff>#include <STDIO.H>4 }' |, S; c6 a$ U; s4 X
#include <IO.H></FONT></P>
; H+ {& H- j- u9 ]4 l( A<P><FONT color=#0000ff>int main(void)
3 U, |4 A# g) i7 m/ a5 d/ c{ * n; L8 g" F' B1 Q( W
int handle; </FONT></P>, ]% O c/ C. J; J8 X3 E5 E% A# s& K
<P><FONT color=#0000ff>handle = fileno(stdprn);
5 k0 a r& h. Z. X" U- \if (isatty(handle)) ; S1 t* }& e/ Q' e( I
printf("Handle %d is a device type\n", handle);
- n, @, N" `: }- e0 delse
9 r" ~7 I0 h5 c1 ?5 j' t* qprintf("Handle %d isn't a device type\n", handle);
+ a) z V# _- P0 Ireturn 0;
+ j) _- w7 Q) j3 M}
- X9 r" G) I9 s- M( J; R, ?9 I0 C {# ?% e
</FONT>" ^0 p: I) ~, j( s- c
</P>" `6 j3 m; y e& k" C) P' N
<P><FONT color=#ff0000>函数名: itoa </FONT>* H1 q) X0 L8 U7 h. {, T! e8 \
功 能: 把一整数转换为字符串 4 A4 i5 v- L2 k( U
用 法: char *itoa(int value, char *string, int radix); 9 L+ D- x; M% ]
程序例: </P>
, i5 @! c7 x" e# C: J) O3 I<P><FONT color=#0000ff>#include <STDLIB.H>
0 I @( w+ J2 G' D0 Z#include <STDIO.H></FONT></P>
4 Y! j0 \8 z. o( q% s<P><FONT color=#0000ff>int main(void)
* s- Y5 Z$ t- d; t4 _$ U$ U{
( S3 H4 c8 N$ s% k% I' |3 aint number = 12345; . U! q: H5 v7 w7 C# H
char string[25]; </FONT></P>
$ e7 \# ?4 s1 L% t. M% I$ Z ^<P><FONT color=#0000ff>itoa(number, string, 10);
/ P9 Y. H/ t7 r6 _% `printf("integer = %d string = %s\n", number, string);
3 a+ M+ M. Z# {9 E; P+ Ereturn 0; 5 k) V& P6 x. B) v. z
} </FONT><FONT color=#0000ff>% N) @! r/ ?' c2 d4 h8 u
</FONT></P> |
zan
|