< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>. s `: Z' t( M6 s3 j4 d
</P> / U+ u8 H3 V& Y3 r<><FONT color=#ff0000>函数名: kbhit </FONT> " l, [4 f. U: W& u( N功 能: 检查当前按下的键 3 ?5 h8 o2 T# Z用 法: int kbhit(void); # Y5 g- W! c; a: B) `; Z+ B; F3 j程序例: </P> . \4 w% o; A' e/ a<><FONT color=#0000ff>#include <CONIO.H></FONT></P> 8 x; a, I0 @- E, Z0 O& I# S<><FONT color=#0000ff>int main(void) @1 K% q8 X6 `- A; _$ i{ . L( r: f1 |, P- x, r
cprintf("ress any key to continue:"); # K' x, B B/ d5 y) ]1 [- D6 C5 Twhile (!kbhit()) /* do nothing */ ; J) A1 u8 ]% Y# m. vcprintf("\r\nA key was pressed...\r\n"); 7 C+ o) E* A0 e" N" Creturn 0; 9 E. e/ s \7 D l: {/ M, b
} </FONT>/ w$ u. `& G9 [( H* z
</P>, X! D! O/ Q$ V0 C1 Y
<><FONT color=#ff0000>函数名: keep </FONT>: o. u% h6 H- L) g4 o" ?6 o
功 能: 退出并继续驻留 8 B" w' ~5 Y; d
用 法: void keep(int status, int size); + N6 O( J! C$ s5 a1 r. y/ e: u( r
程序例: </P>4 r" j( S l% F% w8 _
<><FONT color=#0000ff>/***NOTE: $ R) h+ o" k! f8 O
This is an interrupt service routine. You 5 |0 h, R# d$ |6 F! v# fcan NOT compile this program with Test : g6 [- N8 r" j0 JStack Overflow turned on and get an : f( ~' }4 J0 [2 j$ Oexecutable file which will operate , \) B' ^% X: Y: y o
correctly. Due to the nature of this + U0 n: E, M% X7 @, e4 Qfunction the formula used to compute 6 C9 J* H. f9 v4 J' G" k
the number of paragraphs may not ; a/ o% J! G2 p& d1 Y9 Enecessarily work in all cases. Use with # a4 u) p% D" z- Qcare! Terminate Stay Resident (TSR) * x7 L/ |! t7 j& p+ t7 |! Qprograms are complex and no other support ! o. J1 d1 O' T1 o
for them is provided. Refer to the : e- V! x/ Z/ J2 c& E6 zMS-DOS technical documentation * P( F& u1 R% p
for more information. */ - c4 c, u# Y1 T3 p5 H
#include <DOS.H>* J; Y9 _# _* A, ^
/* The clock tick interrupt */ / u% F4 m( m8 A0 l0 O7 {# m# r, K
#define INTR 0x1C 7 x1 T9 q% O! K9 J/ d4 F. x/* Screen attribute (blue on grey) */ + Y* {' I/ O; q4 g#define ATTR 0x7900 </FONT></P> * i$ b; Q3 }1 [0 |# T5 l5 g<><FONT color=#0000ff>/* reduce heaplength and stacklength : V2 h- s! t5 S, }7 |5 J! Z( ito make a smaller program in memory */ 7 k0 V7 l; X. c7 a; c- }
extern unsigned _heaplen = 1024; 3 y5 t. a# w- r Jextern unsigned _stklen = 512; </FONT></P>1 V, {6 f! c. C7 s% X, j- \0 n. ]
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>; C# U O. o/ E4 l
<><FONT color=#0000ff>void interrupt handler(void) : S0 q3 R4 p! K+ N2 ]% x. S
{ 6 M" t3 G | v2 w
unsigned int (far *screen)[80]; 8 z. \4 M8 r- O
static int count; </FONT></P>5 I9 i N# v4 }
<><FONT color=#0000ff>/* For a color screen the video memory 9 `& o/ r0 ^& J% J. N. g8 Vis at B800:0000. For a monochrome 2 n2 _) @; [/ C! v! ~9 ]
system use B000:000 */ % C# q( S& X4 r% B5 e* g$ o
screen = MK_FP(0xB800,0); </FONT></P>- S& n: ] S8 \& X
<><FONT color=#0000ff>/* increase the counter and keep it ) k3 N3 l$ a, e1 I
within 0 to 9 */ 7 R7 N' i. j9 E% n1 @. Acount++; 4 `9 t( }4 ~, {' g( P: qcount %= 10; </FONT></P> , s+ s- o9 z; t! x0 Z<><FONT color=#0000ff>/* put the number on the screen */ 0 H# X; o: ^8 ~/ cscreen[0][79] = count + '0' + ATTR; </FONT></P>, ]+ d; `# o7 m* k, s
<><FONT color=#0000ff>/* call the old interrupt handler */ " [: Q5 X7 L0 T4 B* k3 @1 I# qoldhandler(); 6 g2 E8 k+ i2 A} </FONT></P> & v# |% a& m1 Y- T2 Q9 e<><FONT color=#0000ff>int main(void) # M' C1 i' S3 l' V4 e( M{ </FONT></P> k; R. k! P' W. E+ t* u; _
<><FONT color=#0000ff>/* get the address of the current clock 5 a) I: Z0 Q# z) K0 n- atick interrupt */ & j1 @, {: R3 Z
oldhandler = getvect(INTR); </FONT></P>* t$ N& b2 G/ w
<><FONT color=#0000ff>/* install the new interrupt handler */ 8 c) G$ a9 g9 F8 @: S% [setvect(INTR, handler); </FONT></P> ; e/ c+ B5 R6 l9 b: R, ~) C2 d8 g! K<><FONT color=#0000ff>/* _psp is the starting address of the # T9 z, M- Z, i' \
program in memory. The top of the stack 5 C' Y" x1 j }; lis the end of the program. Using _SS and ! e& j) G! H9 |- V. _! c4 \
_SP together we can get the end of the ! p% p) j- S1 L; K2 s3 ~. q
stack. You may want to allow a bit of 5 x7 R e- i# G+ x. t
saftey space to insure that enough room 9 [" n' n1 U# N. i5 _5 kis being allocated ie: 6 T' G/ ^# \. R( `(_SS + ((_SP + safety space)/16) - _psp) 2 |# V6 z& A1 T3 s*/ 1 [# G3 D D& g) \, T @2 U% J, d0 V$ n
keep(0, (_SS + (_SP/16) - _psp)); 2 T. j2 f' T! \ Freturn 0; # M6 [. i) X# [2 i2 a' S1 v& }
} 2 [8 \5 `3 [. z+ R. l+ S* O1 Y/ ?0 ^* V</FONT></P>6 n( W5 J9 k c
4 _* |7 H! \$ U( Q! L# v. P9 u, x) u2 X
<><FONT color=#ff0000>函数名: kbhit </FONT> $ D2 [ ~/ y6 X2 f功 能: 检查当前按下的键 ; k$ r& x5 N3 p% P/ R; B( w# E6 r用 法: int kbhit(void); 8 H' W/ ]- Q" P4 I程序例: </P>+ Q+ \% c3 r2 r: K! G3 q8 A* O
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> 1 S2 I) ~8 y3 b<><FONT color=#0000ff>int main(void) ( V4 C3 U, `% \! Z6 I3 G
{ ' s# A( \" l( a2 h+ F/ Q g
cprintf("ress any key to continue:"); 9 u7 R4 S/ @. ~2 V5 k
while (!kbhit()) /* do nothing */ ; * W" F2 m8 B7 K
cprintf("\r\nA key was pressed...\r\n"); ! z! O o& l- M1 E- n3 X% u
return 0; 7 |( X4 [ s# a
} - F( L" k7 D! }3 p" ?$ {+ K0 v 2 D+ h0 n& i4 c" `. C- r8 h. D" Q4 N# G, e* W D/ o% \
</FONT></P>! v8 A I; f7 W/ ]
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> " R ^0 b) K; I8 ^. `$ }<FONT color=#000000>功 能: 退出并继续驻留 4 z7 C# _, x0 L1 l用 法: void keep(int status, int size); ( m3 [. H8 t1 j$ r程序例: </FONT></FONT></P> ; W2 O3 q5 V1 s, y<><FONT color=#0000ff>/***NOTE: , N& F" S& {1 d- u+ rThis is an interrupt service routine. You ) t/ F7 o8 a- Ecan NOT compile this program with Test 1 [0 m f7 V: j: z: h! L2 i NStack Overflow turned on and get an ; L& B2 _( X1 N' sexecutable file which will operate $ q# Y0 M3 e% z! a* ]. rcorrectly. Due to the nature of this 9 |5 Y2 l7 L) P7 B) M* a' K
function the formula used to compute - M0 e( Q7 _. d4 d" `the number of paragraphs may not 0 r2 F( X/ t. m. v8 j. a9 z
necessarily work in all cases. Use with 6 U5 i: |) r1 y& u2 h* f6 s& _
care! Terminate Stay Resident (TSR) ; C- u+ m( R! O% m2 ?6 n" [, X/ g
programs are complex and no other support # ~2 c7 j- k9 V6 q( w, v6 R9 gfor them is provided. Refer to the ! ^1 b! L! ?" Z5 Z( V
MS-DOS technical documentation 6 n6 _( I0 [. v% a
for more information. */ 4 W. U$ }' a0 t. D7 P% f- c
#include <DOS.H> 2 N5 x5 k+ I+ s/* The clock tick interrupt */ $ n! w! Z3 n5 y- ~6 z
#define INTR 0x1C O2 m- Z+ p* N, `. u* F
/* Screen attribute (blue on grey) */ + d L, }0 _, U, }4 [8 F#define ATTR 0x7900 </FONT></P> . ]5 s. Y! d% |: A<><FONT color=#0000ff>/* reduce heaplength and stacklength * P/ o/ C. [9 f
to make a smaller program in memory */ , h% `, d2 D- n, T8 W. J
extern unsigned _heaplen = 1024; , o9 V( q* I( L# \1 Hextern unsigned _stklen = 512; </FONT></P> 0 C5 u) U" c0 H) N8 t" M<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> , f [7 h% I- v) u, `& t<><FONT color=#0000ff>void interrupt handler(void) % M% F5 s2 D" g" \6 }: x; p* d& Z& U
{ 1 W P; u1 i, `unsigned int (far *screen)[80]; 5 o3 d: R$ B2 K
static int count; </FONT></P>2 x! f. O) w/ R/ ~4 C9 x
<><FONT color=#0000ff>/* For a color screen the video memory - C3 `9 w0 ?8 w7 V- \- }is at B800:0000. For a monochrome ' w2 l7 K) l" ?! M$ H: w+ |
system use B000:000 */ 8 k& D- O X/ L- S& Iscreen = MK_FP(0xB800,0); </FONT></P> ; \/ p' u/ U% l# r+ y; Q% |7 N<><FONT color=#0000ff>/* increase the counter and keep it 4 ]$ c4 x Z6 O+ ^
within 0 to 9 */ + c/ w; |7 r) H e6 Kcount++; $ L+ L& [+ o0 Zcount %= 10; </FONT></P> 2 m6 m+ l ?0 b$ a8 [<><FONT color=#0000ff>/* put the number on the screen */ : ]# ]/ z1 y% p0 h2 oscreen[0][79] = count + '0' + ATTR; </FONT></P>6 I3 H* i3 Y; m
<P><FONT color=#0000ff>/* call the old interrupt handler */ $ ^" i: E" u( Soldhandler(); s6 H& \2 \; r0 ]8 E; \} </FONT></P>$ H3 v2 b* D& D3 L0 M
<P><FONT color=#0000ff>int main(void) 2 [5 `8 m/ G+ s5 ~6 |{ </FONT></P> w! r" `2 q" V4 Y<P><FONT color=#0000ff>/* get the address of the current clock ( a9 }4 }; r1 B {5 jtick interrupt */ ' @$ \; `8 p# Z
oldhandler = getvect(INTR); </FONT></P> # M% n$ |: \9 K N8 v5 F$ s<P><FONT color=#0000ff>/* install the new interrupt handler */ / I' D: Q a; V/ }. Lsetvect(INTR, handler); </FONT></P>5 m* ^# F6 F& o; l+ U' M
<P><FONT color=#0000ff>/* _psp is the starting address of the % ?* h1 }+ w1 l5 Gprogram in memory. The top of the stack & W3 G4 y) A. b; f5 W
is the end of the program. Using _SS and * @3 u3 _1 R# J5 B; R
_SP together we can get the end of the 5 n# Z5 U$ _( Xstack. You may want to allow a bit of 2 `3 \( c! \5 q1 }; X3 ]+ G
saftey space to insure that enough room 8 F' x8 d! a( f9 S- `: b
is being allocated ie: 6 o* D( [% m4 \. p2 D" o(_SS + ((_SP + safety space)/16) - _psp) ( h; D7 {4 E0 N" J& m; i*/ : H p+ s) \% ^, e: Xkeep(0, (_SS + (_SP/16) - _psp)); 8 ?) A a* b7 M/ ~# k2 R8 e8 breturn 0; ' U6 D9 T& z' m8 |. E/ p, p
}</FONT></P>