< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT> 8 n! D @5 w U0 s* p</P> ! T3 d- ^0 n1 x<><FONT color=#ff0000>函数名: kbhit </FONT> 7 V1 T6 V9 Y1 K功 能: 检查当前按下的键 1 C) U. ]( V" A) A用 法: int kbhit(void); ( p8 p. e) j+ _) a
程序例: </P> / T3 p' l" c1 Y/ ?8 C1 p<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 O0 W8 L8 w N$ G0 h" G
<><FONT color=#0000ff>int main(void) 1 Y$ k& i, ^, ^5 z: u5 s
{ ~* W, f2 k# z" R/ L) \
cprintf("ress any key to continue:"); 2 n$ e% V( y- E: B# x2 P' r- {
while (!kbhit()) /* do nothing */ ; , w" S: \2 G5 [/ n- pcprintf("\r\nA key was pressed...\r\n"); 8 R3 \! w0 W# G
return 0; + `" A0 G0 A# g} </FONT> p2 W4 q" H+ v</P> # L/ h5 c% ^$ v8 R/ H# ]<><FONT color=#ff0000>函数名: keep </FONT>/ g0 c- a. L; V" t* ?* X- _
功 能: 退出并继续驻留 9 G( ^5 Y5 x$ t; ^) w3 L
用 法: void keep(int status, int size); 9 q+ f& c+ K% I, j
程序例: </P>3 p- L" u( i( t& S8 w. q! S
<><FONT color=#0000ff>/***NOTE: 4 x2 g% N5 W& j) ^6 [: g7 |This is an interrupt service routine. You 4 p; O; d8 T1 O+ @0 @
can NOT compile this program with Test * {0 S1 A' x. qStack Overflow turned on and get an ' |) `: u3 i" b4 b& i' r: W
executable file which will operate $ Z8 _) I/ v+ V
correctly. Due to the nature of this * y, p, u! r0 v' d
function the formula used to compute # o( v4 G0 N/ Q( f
the number of paragraphs may not 2 I% g9 E7 j( B3 d. D2 v2 r8 gnecessarily work in all cases. Use with # z: Z$ J8 G+ F" [% Ecare! Terminate Stay Resident (TSR) 0 }- j8 @$ o$ }3 ~* m* J
programs are complex and no other support + a8 a# B4 q" ]# ]3 k4 h+ X3 n& H
for them is provided. Refer to the 7 {6 J0 V# j2 b
MS-DOS technical documentation ! Z2 H: N. |/ e3 ?/ r/ qfor more information. */ 8 Z! |7 U$ I( z) B1 j; C. K1 w#include <DOS.H> S' J7 U3 v9 K& v% e
/* The clock tick interrupt */ 8 r5 Z5 v( P6 g& J8 Z4 @2 N#define INTR 0x1C , Q% a7 n# I, q: D
/* Screen attribute (blue on grey) */ " ~% h$ \! [9 w( [+ }* m# w#define ATTR 0x7900 </FONT></P>" \ @9 e2 Z. N4 V
<><FONT color=#0000ff>/* reduce heaplength and stacklength 9 p/ `9 E* r) P N
to make a smaller program in memory */ . D$ }- i- S6 `# r+ o
extern unsigned _heaplen = 1024; X# h1 n& r. ~3 J3 R. x
extern unsigned _stklen = 512; </FONT></P> " I2 G1 u2 Y' @; r( w<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>$ M+ d4 g9 O/ K
<><FONT color=#0000ff>void interrupt handler(void) % { @- J3 J* H- I9 T& p% h
{ 6 s. L, E9 ^: [1 O) @unsigned int (far *screen)[80]; : o6 u$ U& A5 N1 n5 `
static int count; </FONT></P>3 F! N6 w: `8 H3 F
<><FONT color=#0000ff>/* For a color screen the video memory ! ]6 s- s% X# X
is at B800:0000. For a monochrome % X9 n; ~. \8 N& j: r) p. e% G
system use B000:000 */ 7 k" V& e% P" x; p5 F' D& O
screen = MK_FP(0xB800,0); </FONT></P>, }* q7 w* F& M* y
<><FONT color=#0000ff>/* increase the counter and keep it + b7 x N0 x! F) q5 U% z' o' i
within 0 to 9 */ 9 h% e1 p) f5 N5 Q( V) ecount++; . Z0 C& @: r6 ]$ s
count %= 10; </FONT></P>) b% t- [0 W, v- z, W; w8 X Z
<><FONT color=#0000ff>/* put the number on the screen */ 3 V( D+ F6 `2 o2 z3 Kscreen[0][79] = count + '0' + ATTR; </FONT></P> 2 O6 m2 y" q8 y<><FONT color=#0000ff>/* call the old interrupt handler */ V" S% B2 Q# r* ?# x" Koldhandler(); . x, X) V5 U' U% x% p
} </FONT></P> # F o, y- \3 T<><FONT color=#0000ff>int main(void) r5 ?1 s3 k$ r7 \; v
{ </FONT></P> $ d' I2 |2 A" g6 G9 S* X* q. Y<><FONT color=#0000ff>/* get the address of the current clock 7 Y! N: K6 X& z6 B+ e7 ~8 j
tick interrupt */ . G: f& f& N! U7 j D( A o9 moldhandler = getvect(INTR); </FONT></P> " T9 h* f+ q5 ^9 p8 D) }1 {4 n<><FONT color=#0000ff>/* install the new interrupt handler */ 1 r4 J" x0 z& ^( {+ {1 isetvect(INTR, handler); </FONT></P> 0 p7 ^7 N2 `+ {' d3 u6 M* L<><FONT color=#0000ff>/* _psp is the starting address of the 5 I, B2 @' V( l3 W3 Aprogram in memory. The top of the stack & T/ @$ |* y1 b$ T$ D( Pis the end of the program. Using _SS and 9 }% ]' ^5 o8 H3 s+ f
_SP together we can get the end of the # X8 u. o/ K& c
stack. You may want to allow a bit of 2 r$ W& a# p$ N) S' f' Osaftey space to insure that enough room 4 z a* W( K8 V0 J
is being allocated ie: 4 W" b9 N4 u6 }: q6 T: Y(_SS + ((_SP + safety space)/16) - _psp) : i4 x, `3 O. r. K D. |
*/ N F% _& d% ]* v* w* L2 J( Dkeep(0, (_SS + (_SP/16) - _psp)); # C! b1 ]$ r, ~" y1 ~; @ g
return 0; : k+ w! \% O# B2 ^
} # Y0 [& I+ X' G. O</FONT></P>, }7 }- g# u: |4 C, ]7 t1 C
' Y& i. a# _' T. D+ [
( F& M! N' O! O3 @- ]: _
<><FONT color=#ff0000>函数名: kbhit </FONT> 5 u9 Y" s' y5 q功 能: 检查当前按下的键 : e# |6 b1 {3 K$ [5 Z用 法: int kbhit(void); 1 K6 w& n1 Z1 [: n- @
程序例: </P>! v" c; m" ], N* M3 z q5 u! D
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> % Q+ v9 E# a9 S* n) S7 ^- L<><FONT color=#0000ff>int main(void) ! Q; @& |) S+ k0 U- |7 {# M
{ 7 C! n. C1 s/ d
cprintf("ress any key to continue:"); 2 V! m1 h5 w4 g+ `/ t0 u, @6 wwhile (!kbhit()) /* do nothing */ ; $ C9 g# O; i h; u6 S
cprintf("\r\nA key was pressed...\r\n"); 1 \8 L2 E1 [/ {- u
return 0; 7 g) A5 `" ~1 }& o c} 7 `) D3 Z# }& r$ N4 l$ ?- P& p
0 `' t* q! ?' H ]( M+ F. [! n
i& n0 O) i2 g7 G. f1 q3 j</FONT></P> & l3 N' u& R5 T* @: k& ?; x" P% _$ K<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> 3 m( A) R; i& n* D t<FONT color=#000000>功 能: 退出并继续驻留 6 {$ w& Q, o7 w9 X$ e% y1 e4 c用 法: void keep(int status, int size); - {7 D4 _) d+ K, f: Q, u程序例: </FONT></FONT></P> % X; _/ i) N. v3 B<><FONT color=#0000ff>/***NOTE: . j8 v: T) y$ v' z( d3 EThis is an interrupt service routine. You + Z' d2 C9 a' q- O+ j
can NOT compile this program with Test ; z1 l1 R0 G, n GStack Overflow turned on and get an 7 o1 s/ Y; s! Q+ n4 p n
executable file which will operate # t( B# {2 B: `* G3 }* scorrectly. Due to the nature of this & J B2 t5 U2 u, d% o6 W3 z/ n. I1 afunction the formula used to compute 7 ?) o4 C# c O" m
the number of paragraphs may not 0 {* ]( B2 W; ?8 o2 y
necessarily work in all cases. Use with % y3 Y! S" ~0 s: pcare! Terminate Stay Resident (TSR) 8 O6 b4 c6 j+ A1 H) i6 D( }programs are complex and no other support ; H0 J" J, s7 M- T8 n2 [+ r
for them is provided. Refer to the * T; P6 X& S, H. ]9 {, v1 ]
MS-DOS technical documentation 9 w5 B' p, C6 i& ^$ w$ `0 H8 J# _
for more information. */ # ]) W' T4 |: S: y#include <DOS.H> ) Q1 r4 H7 C( A9 h8 ?$ X/* The clock tick interrupt */ / O6 a5 P( J& ^& a8 A
#define INTR 0x1C ' v7 n$ B$ Q; l7 Q3 @0 [/* Screen attribute (blue on grey) */ - p$ p1 B4 }5 x( c
#define ATTR 0x7900 </FONT></P> 3 w4 w! S, c$ f<><FONT color=#0000ff>/* reduce heaplength and stacklength * ?4 c5 ]7 w: y. V9 P1 x3 W/ ?6 n7 yto make a smaller program in memory */ 1 ^/ d/ w( x& J
extern unsigned _heaplen = 1024; , }% h' q" S. Y( u' x
extern unsigned _stklen = 512; </FONT></P>6 N( J' P! p( c6 W3 e, E/ R* @ \
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> $ O, Q" H% }& L: |4 E2 v<><FONT color=#0000ff>void interrupt handler(void) 2 d2 u! C. k( L1 I4 i, e
{ 5 L/ W' @/ ^/ X; V5 {/ ]: T
unsigned int (far *screen)[80]; j) t5 u; a: J3 ?static int count; </FONT></P> ( i# G1 K8 n! l0 S' h<><FONT color=#0000ff>/* For a color screen the video memory * S# @+ g; j E: R7 Xis at B800:0000. For a monochrome / r4 r$ `1 C2 Y: R$ Z- \ j& G$ x
system use B000:000 */ ' A$ ]8 _1 F: S# B* `9 Q2 R
screen = MK_FP(0xB800,0); </FONT></P> % m# e. C0 w, H+ f$ x, X/ r<><FONT color=#0000ff>/* increase the counter and keep it % W. f1 x- D7 N" l1 }) [
within 0 to 9 */ # V& u% e7 b5 P
count++; 6 y/ O# m' \4 a* D
count %= 10; </FONT></P>) S9 D6 M9 K" U3 p9 C) ~
<><FONT color=#0000ff>/* put the number on the screen */ 7 `+ E8 [. x! X! t/ D* \' F& I
screen[0][79] = count + '0' + ATTR; </FONT></P> + n5 {5 R g; ?& p; \# |: e<P><FONT color=#0000ff>/* call the old interrupt handler */ 7 \+ p7 `) z% n: k( x1 \oldhandler(); 5 l) K4 \# ~+ c3 d% F} </FONT></P>- a1 \( N3 x2 N5 B0 k: ^6 J" m, G
<P><FONT color=#0000ff>int main(void) " h9 q( f7 a5 x# g$ P- j/ j
{ </FONT></P>6 f( S0 h5 _8 o+ h q6 _6 o; I
<P><FONT color=#0000ff>/* get the address of the current clock ) T+ [% R# H6 m' _" C1 K8 P& Ztick interrupt */ 8 I7 j/ V5 f$ j4 |+ Z5 zoldhandler = getvect(INTR); </FONT></P>6 p5 S( K/ U! v! t ]
<P><FONT color=#0000ff>/* install the new interrupt handler */ % q( c9 p4 \+ g. z
setvect(INTR, handler); </FONT></P>: O( e9 k8 X) O- j+ f1 j
<P><FONT color=#0000ff>/* _psp is the starting address of the 0 l! ]. Z/ T7 d/ J4 g2 S! pprogram in memory. The top of the stack 0 A7 |) ?0 H% |
is the end of the program. Using _SS and 3 U1 e+ `3 B! O+ h5 o3 X, l/ u/ l
_SP together we can get the end of the 1 \* `7 e. ^1 Rstack. You may want to allow a bit of # o. b# n: |/ n! M
saftey space to insure that enough room 2 p) z, ^: y( ?' P8 Sis being allocated ie: 5 s) q' h; r+ B* k/ ^) e0 m7 X(_SS + ((_SP + safety space)/16) - _psp) 1 i$ q% n1 M7 ~1 ~4 N) K
*/ , f" P Z1 I, { `keep(0, (_SS + (_SP/16) - _psp)); - X+ f9 u. Z/ j7 treturn 0; ( a0 ?6 `& @# U6 q( d}</FONT></P>