< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT> ! P0 b/ ]9 A7 Y$ X! p* f</P>& j' l6 p7 E* ?6 N- f' H+ N$ j
<><FONT color=#ff0000>函数名: kbhit </FONT> % s8 A$ }* k7 j6 E) T) S功 能: 检查当前按下的键 ( Y- c8 U3 N; f7 v, X7 a" h( T用 法: int kbhit(void); . l5 A0 Q1 _2 @程序例: </P>( h, l( I; V0 i. O9 @
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> " z) U+ _" A% j. W6 R1 U<><FONT color=#0000ff>int main(void) * O9 ]* J+ x# A. |{ " y0 `& l" A6 E: n. C( H& A1 bcprintf("ress any key to continue:"); , T1 E& T0 ~3 r1 U% Q3 X! fwhile (!kbhit()) /* do nothing */ ; ) @! A; `( N- T; T; O5 N6 {6 qcprintf("\r\nA key was pressed...\r\n"); ' C6 b# K2 [; `
return 0; 0 K/ H0 a$ P2 s8 }7 V; Y
} </FONT> 5 [, C7 E$ S! r! }7 g8 Q</P>% ^" e( K; v4 @: V* @5 T% D6 w
<><FONT color=#ff0000>函数名: keep </FONT>! f J) n% x' F' J" G' F* Q
功 能: 退出并继续驻留 0 A- @6 D; v8 \* V1 A* @' @7 I- S用 法: void keep(int status, int size); * H* n2 C- a/ F. a I5 g
程序例: </P># T8 c% q6 `5 F# T2 e
<><FONT color=#0000ff>/***NOTE: . W6 ]# \; A% p
This is an interrupt service routine. You : ~; O: |" C: W* W6 m
can NOT compile this program with Test 1 u( P' E# d9 F' m, X
Stack Overflow turned on and get an , _# u* M' @* w" r: @executable file which will operate % P1 g' S" D. c! [( Y
correctly. Due to the nature of this + R, w$ {2 Z6 y, ^: ^( @( E3 }5 T
function the formula used to compute : J6 }% U3 M c* }- l, d- tthe number of paragraphs may not + i6 h" Q e9 ?" m' L* J0 ~necessarily work in all cases. Use with ) m% D# R% D0 Z4 Ecare! Terminate Stay Resident (TSR) " L) s ^9 f' C% c6 @5 u
programs are complex and no other support 4 n2 C) Y% w3 i- L. H2 Q
for them is provided. Refer to the 1 h8 p0 }# Q: [3 l' ?
MS-DOS technical documentation % R; N+ h( y6 z+ Q; B0 A
for more information. */ 6 K9 ^( Z" g. o# n9 G7 {
#include <DOS.H>. y0 Q) F& e9 i' t3 ^; a2 d# O' n
/* The clock tick interrupt */ 3 z' h2 ]: i1 M- O$ r" j#define INTR 0x1C 5 D$ k/ k3 D8 b% q/ `2 M/* Screen attribute (blue on grey) */ $ p1 k2 ?6 S3 W+ z% e. i#define ATTR 0x7900 </FONT></P> 5 z+ \& |6 R7 `- C1 ^<><FONT color=#0000ff>/* reduce heaplength and stacklength " y5 y# W( F& h7 W" L& _to make a smaller program in memory */ 2 ~' K1 }+ N3 R% t
extern unsigned _heaplen = 1024; 7 ~( E x& P2 Y, U
extern unsigned _stklen = 512; </FONT></P>7 `3 i% N, }3 t. d+ z* z. N+ T
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> & j: p4 y1 \# }9 m<><FONT color=#0000ff>void interrupt handler(void) 1 {+ V: H7 v: k/ G- j- Y{ : p' T8 r& R; o5 s/ S4 U4 {unsigned int (far *screen)[80]; & X! @. u' u8 P% m$ w5 t# X" Qstatic int count; </FONT></P> " G; O! ]7 ~2 S& \% f* }<><FONT color=#0000ff>/* For a color screen the video memory 8 [( }: u2 g% B; `, B4 o
is at B800:0000. For a monochrome " h0 n8 p2 C& o# isystem use B000:000 */ 1 s) K3 w; t8 pscreen = MK_FP(0xB800,0); </FONT></P> - F# l4 [1 A6 d$ K! e) D0 P+ w' g' Y<><FONT color=#0000ff>/* increase the counter and keep it , n& P8 Z# o/ l# w
within 0 to 9 */ - `- U( r: W$ ~count++; 7 [1 `, g2 G E, e$ r0 ^) }count %= 10; </FONT></P> ) @5 _# H$ X u- ?<><FONT color=#0000ff>/* put the number on the screen */ ; O n, M- L. N, q( j
screen[0][79] = count + '0' + ATTR; </FONT></P>+ e R# e: J) z6 \/ X% r
<><FONT color=#0000ff>/* call the old interrupt handler */ $ N6 P# g* k+ v1 m$ \oldhandler(); - ~/ B) ?4 q5 K4 ]6 h8 p5 }$ Q+ b} </FONT></P>3 j7 Y% o( t& B+ x3 w, I6 m
<><FONT color=#0000ff>int main(void) 2 ?$ Z( f$ ]+ m1 i! v* ^{ </FONT></P>) Q1 F% H8 L9 D, x8 D4 J9 D8 H
<><FONT color=#0000ff>/* get the address of the current clock + D* t7 h4 Z+ N
tick interrupt */ ?4 [& W# r: Y3 j6 ]) f5 J/ d Z4 M3 Roldhandler = getvect(INTR); </FONT></P> 1 I8 ~5 Y' j2 c: T9 o1 S<><FONT color=#0000ff>/* install the new interrupt handler */ 0 `! R2 \) L' e
setvect(INTR, handler); </FONT></P> 7 T) i4 U, y. ~<><FONT color=#0000ff>/* _psp is the starting address of the $ l$ R7 T, A% z" `program in memory. The top of the stack 1 j/ f0 i% _' F2 |( Xis the end of the program. Using _SS and 0 C, [ @+ C1 z! q, t_SP together we can get the end of the # M; i9 X+ C R* z+ U6 Mstack. You may want to allow a bit of 8 `: l# c9 j& e# ]( g+ Y
saftey space to insure that enough room 1 ^3 F7 d2 _( W6 r2 m" H( n* Y
is being allocated ie: / _: h) B& s; z/ _
(_SS + ((_SP + safety space)/16) - _psp) / u0 k" d: R) ^4 l*/ / ?8 t& ?, v. F0 x! J2 V& O
keep(0, (_SS + (_SP/16) - _psp)); ! X% q7 ^$ [0 t4 @5 R1 F& z
return 0; * V3 `2 b9 ]2 A2 K+ X- R} ) j* U8 `8 C( t0 ]6 {$ n</FONT></P> : P5 C P6 O( G, ~3 R' l7 `$ j! |: _) M7 [; U
# o2 m8 o% d6 @" q<><FONT color=#ff0000>函数名: kbhit </FONT>1 `) R* z, `& U
功 能: 检查当前按下的键 + q5 c) q; X( w* P. t& v5 D! D& w用 法: int kbhit(void); , ?6 I% h$ ~) ~程序例: </P>- |6 v; t4 n" r2 M9 J1 L( ~* v
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> 1 H8 b j) h9 J) s6 x- E<><FONT color=#0000ff>int main(void) * @/ ]( P9 O$ i( p7 @+ J
{ - e( [0 n" Q2 C- C5 z
cprintf("ress any key to continue:"); ' `' n5 @5 I( C* H# [0 f W3 W
while (!kbhit()) /* do nothing */ ; 2 L5 J) h3 p. b. ^( A
cprintf("\r\nA key was pressed...\r\n"); 4 I4 k* G& x" m9 D
return 0; : d6 u3 ~4 f1 P
} ) C r1 Z, b3 @0 a( z; S% @* H$ b) P* d3 p$ Q P. D
4 B j8 t: e! O8 {" A4 p$ h: p
</FONT></P> . w% Q U4 l- k9 E<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>0 b1 v0 `6 P! o% M: v* l* }9 ?
<FONT color=#000000>功 能: 退出并继续驻留 3 S. n/ O$ S/ Q
用 法: void keep(int status, int size); * A4 B0 S1 a/ ~- N, z6 q
程序例: </FONT></FONT></P>7 U3 H; ~- U, F
<><FONT color=#0000ff>/***NOTE: , |6 _2 B" u! H; ^! g# l1 p) ^0 }This is an interrupt service routine. You 3 g1 V0 T. g' O, x! n2 x. l
can NOT compile this program with Test $ f6 C7 G' m; e. a7 w( WStack Overflow turned on and get an 1 ^1 p. [7 J/ H3 b
executable file which will operate . J) k/ O. i S! t' |1 a5 Mcorrectly. Due to the nature of this 1 M$ F0 C' ~) e# L. mfunction the formula used to compute 9 ?4 c3 ^) b8 l/ [5 j- Tthe number of paragraphs may not 2 q$ ^. K( x+ B% @3 qnecessarily work in all cases. Use with ( {1 D; U8 _2 q8 W( Ncare! Terminate Stay Resident (TSR) - h( d* e$ Z! R- R* g' X8 C9 G
programs are complex and no other support ; v: ^. \9 @- p j: |+ ^# J4 K5 i
for them is provided. Refer to the 2 Y" t; h" @7 n' N# lMS-DOS technical documentation 5 w4 W( k7 e$ Z2 h0 c9 O
for more information. */ ' s% [9 A6 J2 M6 I2 m: n W2 @
#include <DOS.H>( z+ L3 V* Y8 x, k. P
/* The clock tick interrupt */ 2 ^1 U6 z: n( }, `; Y! k- x2 V
#define INTR 0x1C : B! D$ W! [3 t8 I6 _/* Screen attribute (blue on grey) */ / ^. W' @9 R% r* {. v$ s
#define ATTR 0x7900 </FONT></P> 5 b0 i, C& ^* P# _: \1 D9 z5 ?# H<><FONT color=#0000ff>/* reduce heaplength and stacklength / K' n: s/ ^) r5 E2 w: Y- N! ^
to make a smaller program in memory */ ( G/ p: k0 a7 c- nextern unsigned _heaplen = 1024; ! m( m2 q6 Q5 G0 T" g% ~8 d
extern unsigned _stklen = 512; </FONT></P> 5 }* }' b5 D8 f+ {' t# ]<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>7 P" x* ]- C- ~+ \9 c% F3 S/ c) u
<><FONT color=#0000ff>void interrupt handler(void) $ ~2 y( Y$ P2 m0 V
{ & f. z7 F k6 Z6 ~, ^unsigned int (far *screen)[80]; , s# l! c; T' H' K* K5 k
static int count; </FONT></P>8 o: T8 J0 |0 R
<><FONT color=#0000ff>/* For a color screen the video memory $ K9 J/ r& h/ M# F1 E( u2 @
is at B800:0000. For a monochrome ) E$ ~: i, p3 }! H0 p+ A
system use B000:000 */ & R1 n6 h" ^; ~
screen = MK_FP(0xB800,0); </FONT></P> + a0 C' @6 h3 n4 G<><FONT color=#0000ff>/* increase the counter and keep it $ f( d9 G* j, G0 @% H3 @( ~within 0 to 9 */ $ g! t" t. k( E& a3 p
count++; # C5 @( u$ n- v+ @- }& Z3 Scount %= 10; </FONT></P> 7 w/ B; v* u' }) ]' X<><FONT color=#0000ff>/* put the number on the screen */ 4 Y' _" A! Y* }! tscreen[0][79] = count + '0' + ATTR; </FONT></P>. A Q/ u& R9 i. X% l
<P><FONT color=#0000ff>/* call the old interrupt handler */ : l6 z ?8 B M [1 l& k& f1 F
oldhandler(); 7 S T1 J* w& Z} </FONT></P>, v6 ^' b7 k+ }& d L6 A0 E
<P><FONT color=#0000ff>int main(void) & s+ F; }" r, \& W$ ]8 L
{ </FONT></P>- a8 Q/ a3 m5 T
<P><FONT color=#0000ff>/* get the address of the current clock , \& Q- V/ Z! ptick interrupt */ # o) r4 ~( f$ G9 foldhandler = getvect(INTR); </FONT></P>$ |1 C8 d. e; C# O
<P><FONT color=#0000ff>/* install the new interrupt handler */ 2 |# c1 j# r) p3 _setvect(INTR, handler); </FONT></P> ( m. U. u3 r/ U. T<P><FONT color=#0000ff>/* _psp is the starting address of the 2 F) z, A" @7 {program in memory. The top of the stack , x1 i9 E+ {) F
is the end of the program. Using _SS and " d5 Y; Q$ Z7 a+ G# N4 p7 L# W_SP together we can get the end of the & y, i/ V' n1 l
stack. You may want to allow a bit of 1 m3 ^, P' a4 e% {saftey space to insure that enough room 1 s% G& E: e/ Z/ E2 Qis being allocated ie: 9 i" }% W( F# B3 q3 W/ W/ y
(_SS + ((_SP + safety space)/16) - _psp) ' z- M, m6 r5 I+ ^# b' e
*/ 8 b, ? u! a% j( U( `3 _
keep(0, (_SS + (_SP/16) - _psp)); 3 N0 N+ t# \- A) h/ U
return 0; ; O v3 m; H0 }4 a. c4 _# f x# ]( k}</FONT></P>