< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>- K; j; B( ^9 u6 n" g1 N
</P> r5 p9 l8 @$ E- D, E' N
<><FONT color=#ff0000>函数名: kbhit </FONT>3 z% |/ m" o+ y5 R; Z g' a' Y) W( A
功 能: 检查当前按下的键 6 p$ |# w1 f) K+ w用 法: int kbhit(void); # [2 x6 o! n& K) z3 [程序例: </P> 4 S7 U4 V# B) U$ U<><FONT color=#0000ff>#include <CONIO.H></FONT></P>+ u5 @1 O' \# W+ Q) |* g
<><FONT color=#0000ff>int main(void) 1 y b! [6 l5 z1 q- \' Q{ , U/ L5 @' x( |& }+ c! `) a
cprintf("ress any key to continue:"); ~2 M- b. A+ {, c2 D$ ^- J9 Ywhile (!kbhit()) /* do nothing */ ; s0 C8 i) y0 s8 I- Ycprintf("\r\nA key was pressed...\r\n"); - b$ A) O: f& g z, c
return 0; $ w, _1 h( B0 _2 O: W
} </FONT> 4 B* t/ X3 B+ K! d7 O</P> # z, M# N' b$ C& A<><FONT color=#ff0000>函数名: keep </FONT>, ~. O) ?6 W3 h8 Z
功 能: 退出并继续驻留 4 m* \8 d- J0 Q
用 法: void keep(int status, int size); . C4 i N0 g( R% ^9 M
程序例: </P>, P# f1 C) b" A' t6 s# i f
<><FONT color=#0000ff>/***NOTE: 7 u0 I0 j& @- s L r
This is an interrupt service routine. You & L+ I( }, Q8 f1 wcan NOT compile this program with Test : f/ E5 ~7 w5 }. dStack Overflow turned on and get an 2 s" Z6 g* t l8 S1 r* v0 \executable file which will operate # V. E: ]7 u% ^; F/ n8 ncorrectly. Due to the nature of this " z' e& p6 L6 ~! N
function the formula used to compute 4 Y. f9 H1 \/ O4 i; D
the number of paragraphs may not : y i% X: `# e- lnecessarily work in all cases. Use with 1 U r3 k; u2 A/ O+ Y
care! Terminate Stay Resident (TSR) 9 B, l0 N& p% ^+ N1 O, Kprograms are complex and no other support , x' m; ^3 _2 u1 l; W
for them is provided. Refer to the " T; w! D# ~$ Z, Y2 CMS-DOS technical documentation % w# N$ v' k( z8 O
for more information. */ 5 r; Q- U: S/ V6 B# I% |
#include <DOS.H> / a/ ~# H( K2 T+ Z3 o, r/ a/* The clock tick interrupt */ . j6 n# D9 |& h
#define INTR 0x1C 0 U+ t+ a6 f* t R8 A$ |; D
/* Screen attribute (blue on grey) */ 4 F5 M; D% h* e; b#define ATTR 0x7900 </FONT></P> : g' _3 Z4 g% k; H- t0 a& Z, D<><FONT color=#0000ff>/* reduce heaplength and stacklength 9 M. t* D3 q% y. I: c2 S7 a+ eto make a smaller program in memory */ # g* D W& s( ~! \6 yextern unsigned _heaplen = 1024; a7 X& @( v* _6 x4 A
extern unsigned _stklen = 512; </FONT></P>: U" n1 v4 [8 G# b1 j# F
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> * U2 H8 T9 z+ G% y, D F. H* E- Y E<><FONT color=#0000ff>void interrupt handler(void) 3 Y" Y6 j+ P$ S1 A
{ " Z& s0 p" Q5 M3 z. a4 punsigned int (far *screen)[80]; / N; {/ p) Z; O
static int count; </FONT></P> 1 X# W5 n$ B# p1 i! U<><FONT color=#0000ff>/* For a color screen the video memory " Q. B- q; N' i$ mis at B800:0000. For a monochrome ' a; w; I( ? q# T4 lsystem use B000:000 */ ; v5 h6 f% ?5 u0 |9 a
screen = MK_FP(0xB800,0); </FONT></P> - `- }# p5 i( G4 @8 O<><FONT color=#0000ff>/* increase the counter and keep it ) y+ p0 q J0 {. g1 e9 r- S
within 0 to 9 */ 8 L- U8 P, e; p$ c- Z
count++; 3 h" d( u) g3 }, a# h) ^) P$ n7 o5 x
count %= 10; </FONT></P> : Y/ Z i. V! t3 p$ D8 P<><FONT color=#0000ff>/* put the number on the screen */ - Z4 ~! z0 B s# h# [) s% L- P7 }% q- hscreen[0][79] = count + '0' + ATTR; </FONT></P> $ ~* `8 Z3 B$ z" F8 _( z3 p<><FONT color=#0000ff>/* call the old interrupt handler */ 6 _, k$ r/ w0 J- \, M4 \* Y4 U$ P$ Aoldhandler(); ) O r: B# k. w; V- G
} </FONT></P>' ~3 y/ \& u& i
<><FONT color=#0000ff>int main(void) / M. c# y' s1 g& [7 H6 `% _# a{ </FONT></P>0 x9 g( j! d. g
<><FONT color=#0000ff>/* get the address of the current clock 1 r) v% _% x- [2 O L1 o& I, m
tick interrupt */ - B, ]0 O2 p3 \( h9 ^
oldhandler = getvect(INTR); </FONT></P> 0 s, e/ u" w2 F3 ]) a" G<><FONT color=#0000ff>/* install the new interrupt handler */ : H8 D* @* g+ S
setvect(INTR, handler); </FONT></P>( a& y y1 ?+ X9 q9 d1 C4 Z
<><FONT color=#0000ff>/* _psp is the starting address of the & {# F) J0 {# A
program in memory. The top of the stack 9 m+ E% T5 Z2 R; ois the end of the program. Using _SS and 7 t) h/ ]4 V( @( h( B$ f) E
_SP together we can get the end of the - R5 [) Q, |/ X% x
stack. You may want to allow a bit of : y" @. B. h, V6 Z% e; Qsaftey space to insure that enough room 6 K* f: x: Z' l. c1 \( u$ O+ G
is being allocated ie: , v. I- _" _& b/ t! X(_SS + ((_SP + safety space)/16) - _psp) # {8 _$ \& |/ j
*/ 7 e0 B- z& s5 T7 Y+ s4 ~' O/ Fkeep(0, (_SS + (_SP/16) - _psp)); , E- V, o1 Q* b" l j
return 0; 5 t( J4 ` a% u8 ~) P' N- D}; }5 w: R, G1 ]( E3 F
</FONT></P> # U+ a) [1 y+ [5 D" y+ Y# R 4 O3 H, Z- c0 D, Y' @9 m8 N& B& S# C
<><FONT color=#ff0000>函数名: kbhit </FONT>$ t% @' |& D: B. `4 L' Z% v- q2 ?
功 能: 检查当前按下的键 , b2 C- ?$ g3 x6 y3 s8 t) B, \, H9 U* P
用 法: int kbhit(void); + o! `6 \5 m$ c3 K( T/ C0 n
程序例: </P> 6 b$ }9 S7 Q5 p<><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 ?$ z0 ?" U/ D* E4 L
<><FONT color=#0000ff>int main(void) , J3 n* z6 _1 ^, e" q% E
{ . t. U% Y- {$ r( o" jcprintf("ress any key to continue:"); 8 ]1 |1 S! k' c8 o! ^$ a# a
while (!kbhit()) /* do nothing */ ; 9 _2 W5 e( N8 d2 ~cprintf("\r\nA key was pressed...\r\n"); 5 h. v/ @6 R: x# p
return 0; + L% A& g( E' o; S4 t8 i% l. p% U* r} + i9 A6 p! k; A
2 \) b0 u" h$ m, c 0 ^# \( M: g5 U$ H5 Z0 x4 D</FONT></P> ( R5 ?% G* K/ L<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> 3 B! E+ A: L- R7 T0 R8 @- w* a<FONT color=#000000>功 能: 退出并继续驻留 ) r4 `" a7 q5 F# |) c
用 法: void keep(int status, int size); 0 H! h7 E/ d: s2 h程序例: </FONT></FONT></P> ! R+ w. l3 \# b4 c7 Z. V% e9 E( `<><FONT color=#0000ff>/***NOTE: 6 B- M* B8 m r
This is an interrupt service routine. You # Y$ N$ ] P0 t/ M* T0 T# a# @( u
can NOT compile this program with Test " m% P8 I, N V: k: o. m7 IStack Overflow turned on and get an 5 ?/ e- N1 s J7 Aexecutable file which will operate " Q& f4 I+ J& c3 T5 U% Z! ncorrectly. Due to the nature of this 3 y ~, V+ Y6 |3 sfunction the formula used to compute 5 V% ]+ Y" d* h9 [2 Z# C
the number of paragraphs may not 2 I8 X; p$ V5 ]0 ]$ f, h `2 Q/ p' Nnecessarily work in all cases. Use with ' W% e2 R) S d. w1 Z8 @! g0 s# rcare! Terminate Stay Resident (TSR) , V; T. W+ d4 [
programs are complex and no other support + G# s& W V0 [7 f- ^9 V3 Rfor them is provided. Refer to the . [& \3 N* f9 z. Y* nMS-DOS technical documentation % r; o$ w2 ]- [$ |6 p' zfor more information. */ ; Q% ]+ y( J0 s8 d
#include <DOS.H> - v( M j6 S! r2 }% X/* The clock tick interrupt */ / ~! X0 T8 \( k W0 |5 j+ [. S
#define INTR 0x1C 1 e& U! W/ z6 C8 q( r X' M) W: L/* Screen attribute (blue on grey) */ # v. J$ D. i7 f Y# z; }#define ATTR 0x7900 </FONT></P>7 W* j9 l9 B% t) G; D
<><FONT color=#0000ff>/* reduce heaplength and stacklength |) V: s! B, V( x! {
to make a smaller program in memory */ / Q }8 L$ \( l! `: qextern unsigned _heaplen = 1024; ! W7 k7 {8 A$ ?5 ^" Z+ S$ I
extern unsigned _stklen = 512; </FONT></P> ) I* I( J$ W5 U0 E( V) ^% g<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> / U) s+ X1 j9 t/ G. k. V<><FONT color=#0000ff>void interrupt handler(void) # ~! \/ K; D, \6 Y
{ ! M8 m2 C( Q! a% D8 t" q1 `; O
unsigned int (far *screen)[80]; 7 H! I, ~$ B+ T0 o: e+ c* P: |
static int count; </FONT></P> - l2 m `# h7 {8 r6 \; }<><FONT color=#0000ff>/* For a color screen the video memory - F! Y, c/ W# d# ^: \4 k
is at B800:0000. For a monochrome 0 K8 A+ y4 U- k
system use B000:000 */ / L2 w. Q" {0 v/ t* N3 E
screen = MK_FP(0xB800,0); </FONT></P>/ j. H( Z- b% G: Q( `7 f& L
<><FONT color=#0000ff>/* increase the counter and keep it ) C/ [3 ~1 V5 c2 r8 Hwithin 0 to 9 */ / U) k9 w1 X9 V. n
count++; k. O) y( z N6 K' |* C
count %= 10; </FONT></P> 2 c4 W7 _8 A$ B1 R N<><FONT color=#0000ff>/* put the number on the screen */ 2 @& X: n3 z- i9 w8 x% u
screen[0][79] = count + '0' + ATTR; </FONT></P> ( Z) W* `! O, X) h, h<P><FONT color=#0000ff>/* call the old interrupt handler */ ; M1 c0 \ w: ~1 T9 Holdhandler(); - Y# n W6 x+ A [% p0 L
} </FONT></P># O1 S9 W4 S3 n8 e/ P% S4 c
<P><FONT color=#0000ff>int main(void) 2 v2 ?2 Y! K* g4 {
{ </FONT></P> , v. k m; Q' [" K" C/ j<P><FONT color=#0000ff>/* get the address of the current clock 5 U: d8 J; g5 b5 k: n. m
tick interrupt */ : j4 I! g1 \$ e) [" g) Z5 doldhandler = getvect(INTR); </FONT></P>& O2 }: o+ D u& Y$ \
<P><FONT color=#0000ff>/* install the new interrupt handler */ ' j0 K# |- P- e! i1 Gsetvect(INTR, handler); </FONT></P>; w, K8 Z: L' c' v
<P><FONT color=#0000ff>/* _psp is the starting address of the 2 k( i) b& ]% d9 @, N
program in memory. The top of the stack 3 C) Z# f+ ]. b* G. {, u9 H* R
is the end of the program. Using _SS and 3 r( E( E+ a5 G9 L" m1 x_SP together we can get the end of the 2 M! A8 |7 O$ Z
stack. You may want to allow a bit of # ~5 E1 m3 h/ O5 ]' l
saftey space to insure that enough room % M( a7 ~& J2 \$ P3 g9 R9 ]; wis being allocated ie: - ~8 V# N( k0 i, ?% G6 _
(_SS + ((_SP + safety space)/16) - _psp) 8 Z/ O; @) G" B C* G
*/ & O# h; r, ?4 K+ ]2 B Wkeep(0, (_SS + (_SP/16) - _psp)); ! ~) [( {- O. S& l( D8 U- D) Jreturn 0; 8 y1 E, l1 l0 h& K8 D% C. G}</FONT></P>