< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT> " x# K1 O! P4 Y5 k</P> & i; n% q0 T# I) r: c2 Q<><FONT color=#ff0000>函数名: kbhit </FONT> % q+ J4 D0 U/ E; G4 G$ Y. `功 能: 检查当前按下的键 " R7 D/ c2 G* C) K
用 法: int kbhit(void); & x) H+ }- f1 B: t' I$ ~程序例: </P>. T1 C& s* J. F1 F7 S
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 B, ?2 n9 H @- C( m/ X
<><FONT color=#0000ff>int main(void) : g+ V/ H( d3 Q{ + P5 y; n: ^6 i5 A7 y+ _1 Fcprintf("ress any key to continue:"); 3 T& v3 }) T+ Q3 e
while (!kbhit()) /* do nothing */ ; , F6 w) g; E/ p# ^2 E& r- H. \cprintf("\r\nA key was pressed...\r\n"); $ o. L' J4 X z( q B- Jreturn 0; " w7 l3 y/ E9 g) E- I# k} </FONT> B9 {4 P# T- D! f
</P> ( n4 C% d, {! u% ?( o; ^3 m<><FONT color=#ff0000>函数名: keep </FONT> * W" S% Y. x. l" ?# n功 能: 退出并继续驻留 # W0 E& ] u7 \5 c$ O' ?用 法: void keep(int status, int size); / m8 ]9 r1 A8 _( G
程序例: </P>& R; c; F# U0 v+ _# c
<><FONT color=#0000ff>/***NOTE: ; i3 C8 A1 r( B Z( v4 P7 y
This is an interrupt service routine. You # ^6 h8 [5 Z: p3 Y1 u( d1 zcan NOT compile this program with Test % k3 q# @ I5 m
Stack Overflow turned on and get an & Y5 a$ R% n: ?) k: r' Y
executable file which will operate % j, M9 @0 ]! _8 h- y2 Scorrectly. Due to the nature of this . x8 D1 U& G/ R/ e z: g! {, tfunction the formula used to compute $ X5 n& S% ^4 C& w9 ~ g$ z% k7 d9 N/ ]the number of paragraphs may not , M1 Y' i" }8 { @+ c
necessarily work in all cases. Use with . a' j1 A+ _# ]; c: Tcare! Terminate Stay Resident (TSR) , }2 G' M1 \9 S" W# d$ v' k
programs are complex and no other support N/ x. o( I U `" c
for them is provided. Refer to the 4 O. g; k6 V. ]5 |
MS-DOS technical documentation + r: l+ q; e7 M4 j0 ofor more information. */ 7 H. U* h6 w, A% X. V4 z3 U
#include <DOS.H> 4 P- T: N6 K( Y/ n/* The clock tick interrupt */ - m+ Q' d0 [8 S+ G7 f- c#define INTR 0x1C # Z/ g7 A6 C/ w* G1 ~/* Screen attribute (blue on grey) */ + u- t1 W& h8 j
#define ATTR 0x7900 </FONT></P> N' k+ _. e8 S" m3 Q0 q% M
<><FONT color=#0000ff>/* reduce heaplength and stacklength , e V5 _6 R9 T* k+ r3 vto make a smaller program in memory */ # v5 U9 z# s1 r F# C- a
extern unsigned _heaplen = 1024; $ u n8 @8 L. m$ L9 ]5 A% \2 G
extern unsigned _stklen = 512; </FONT></P> & f v; c& K3 M; A2 J+ }' @ |8 `<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> 1 O4 h" P7 Q, W" T8 w<><FONT color=#0000ff>void interrupt handler(void) ! _8 Z, r, W, c: _. C) C0 K{ 7 \) i" O1 N6 b$ s" \! ~
unsigned int (far *screen)[80]; 4 v; j r6 v! k! k
static int count; </FONT></P>' A q1 A( k/ y; |2 v: x7 s
<><FONT color=#0000ff>/* For a color screen the video memory % `& C/ ]. r/ X, R* Q0 k: d' P# Z. Zis at B800:0000. For a monochrome $ w, L/ G% O7 L: @8 H2 b& ^
system use B000:000 */ * B0 C9 k4 p4 l" ^: o! ~( g) } dscreen = MK_FP(0xB800,0); </FONT></P>5 @% Y q O q) m) @) K7 D4 z
<><FONT color=#0000ff>/* increase the counter and keep it 9 g$ F) `) c/ m; b
within 0 to 9 */ 3 a* I, Y/ F4 L7 L6 j& t" G, |& Wcount++; 7 a! n$ i! Z9 U; k' K1 u2 d6 [
count %= 10; </FONT></P> & [7 M# ~& N) l+ q# c. m1 W9 p<><FONT color=#0000ff>/* put the number on the screen */ / f. I% Z, T! L5 Z9 h$ x% W" O6 ]% W
screen[0][79] = count + '0' + ATTR; </FONT></P> & v2 X* i5 T5 @3 X3 q<><FONT color=#0000ff>/* call the old interrupt handler */ _, ^* W# z( b6 Goldhandler(); , o. d) \- n& s/ L0 i$ s c% p; E
} </FONT></P> ! k7 f) T% k1 J<><FONT color=#0000ff>int main(void) 6 D9 p" d- f& j. T8 V9 ~ P{ </FONT></P>/ o1 A- @) X; ] ]9 v( p
<><FONT color=#0000ff>/* get the address of the current clock - r% S) K, q `" y3 b6 O4 N4 rtick interrupt */ ! U: z2 `! s3 e: f( U: s Xoldhandler = getvect(INTR); </FONT></P>5 t8 q+ y! x* ^+ a, Y! T4 G! ~) p
<><FONT color=#0000ff>/* install the new interrupt handler */ 2 q2 h9 G0 B9 V/ O
setvect(INTR, handler); </FONT></P>; l6 K+ A/ S' e0 f7 O: L/ m8 ]) {) b
<><FONT color=#0000ff>/* _psp is the starting address of the B: k1 [4 P. Z8 w# @program in memory. The top of the stack * F' F4 l; \, _. X
is the end of the program. Using _SS and # ?0 c4 D# |; Q_SP together we can get the end of the 0 G- W+ X! e3 tstack. You may want to allow a bit of ; f; {4 U9 x9 x9 r7 nsaftey space to insure that enough room 6 q& b u- y9 C; dis being allocated ie: % d& `/ Y6 L& {' [6 \(_SS + ((_SP + safety space)/16) - _psp) 4 y5 o: ^$ T- w }*/ ( m$ ^1 L8 u. s' y7 r6 M( [
keep(0, (_SS + (_SP/16) - _psp)); ; @) K$ n( I9 Q/ greturn 0; & x5 J+ e7 w& s) L7 _& U/ _}) C$ U) I7 t& O% s6 K
</FONT></P>. X- _; S. H2 n2 \ N
9 u5 t9 H! [. R# \2 }4 A
$ V4 ^; l6 H8 s
<><FONT color=#ff0000>函数名: kbhit </FONT> - W% ]# J* }$ M5 X- a* V6 f" _功 能: 检查当前按下的键 p2 f8 c6 B) E8 X5 I用 法: int kbhit(void); . m# t2 S. b$ J+ V( R* A6 m! N程序例: </P>' a- L4 ^3 B* O% x% O/ h
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>; d) Q' k0 y7 t! V* E
<><FONT color=#0000ff>int main(void) . u; u/ T8 W8 D' n1 W$ n- p{ " J% W- r0 b2 P: x c; C5 Ucprintf("ress any key to continue:"); + I, j0 E' |* N* N, Qwhile (!kbhit()) /* do nothing */ ; 0 r: L: `4 l. J6 L% _
cprintf("\r\nA key was pressed...\r\n"); ) {) J* ^0 ? Q" m# I9 \
return 0; ) [5 D9 q( f+ h0 V7 F* ^4 D; |
} . m6 i# T: v- n {8 K
/ t. c/ i1 z4 s& I; x% n% w- V P7 r0 n" Q8 n
</FONT></P>/ s6 A0 r* T i0 Q( j0 s
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> & z4 z3 f, T; m h: y/ I<FONT color=#000000>功 能: 退出并继续驻留 0 m7 |9 v. b8 u用 法: void keep(int status, int size); + Y0 [- \3 i8 l) L2 U$ t程序例: </FONT></FONT></P> 5 V) k/ v0 K3 ~. Q6 R0 h* T2 P1 O7 a<><FONT color=#0000ff>/***NOTE: 1 I2 |' [7 r& @$ A' K1 K! e \This is an interrupt service routine. You " ?& f8 f# @ v7 ^" z
can NOT compile this program with Test ' [1 h0 g. _# ?& F5 EStack Overflow turned on and get an & X0 u: i5 R- t, @/ A; qexecutable file which will operate 9 I6 ?/ |" H! |) L/ N4 ^% m
correctly. Due to the nature of this 8 U6 j3 [% q5 D) k
function the formula used to compute % }6 O, b: ~" b( m! ^& t8 m% E
the number of paragraphs may not 4 T w" J5 p( `, b Onecessarily work in all cases. Use with ; s* S' f: Y- o( M4 Jcare! Terminate Stay Resident (TSR) 4 [( |+ P' _8 |/ P7 M
programs are complex and no other support & M u5 Y0 ]% d* c2 |
for them is provided. Refer to the 7 x" S2 G+ S& KMS-DOS technical documentation 0 }0 o9 W5 m; J+ zfor more information. */ 2 s7 ]: e3 y" D
#include <DOS.H> - Q2 P H6 ~; J; o: M4 t2 j$ R! L/* The clock tick interrupt */ / ^. b4 }4 j) I* f* ?#define INTR 0x1C , p( i0 `' T$ }% B: b/* Screen attribute (blue on grey) */ 1 n* b& H; l' A) e! c$ O
#define ATTR 0x7900 </FONT></P>; P0 [; ~6 P/ p4 x2 E8 C
<><FONT color=#0000ff>/* reduce heaplength and stacklength 1 o9 b4 t* W" C% p
to make a smaller program in memory */ 6 d; B X' {, I5 v; E. [extern unsigned _heaplen = 1024; ' P0 [' k* l: o7 V. t" iextern unsigned _stklen = 512; </FONT></P>4 \% Q- Y# d' {# r7 y- |7 p4 S: o/ N
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>6 @+ F0 N' \7 \" s6 g
<><FONT color=#0000ff>void interrupt handler(void) e6 g: o L/ V/ D' ~2 [{ : a% {2 S3 B& f; i' h' a0 Nunsigned int (far *screen)[80]; ! e) r' Z8 H# A2 ?# i3 f8 z G/ tstatic int count; </FONT></P>. f. Z( B8 ]) i/ j+ O
<><FONT color=#0000ff>/* For a color screen the video memory " D7 y8 @) _ s; c, Xis at B800:0000. For a monochrome & b3 j: v& i/ G( n3 W4 Q1 G, v
system use B000:000 */ ; P4 h+ [* l2 `# \( y0 ~
screen = MK_FP(0xB800,0); </FONT></P> 1 R D l9 ], Y* z* ~) d4 R* y4 H<><FONT color=#0000ff>/* increase the counter and keep it . [+ ^% q8 _ x x, ] X2 G
within 0 to 9 */ - X. f. @+ Q: u5 t) d) \3 dcount++; / K! ^. G" _' a: O) G3 i
count %= 10; </FONT></P>. O I( T! ?0 ^5 f; \
<><FONT color=#0000ff>/* put the number on the screen */ % E8 i# B& @' p, S, V4 R0 i" rscreen[0][79] = count + '0' + ATTR; </FONT></P># m9 s) D% Z% V1 G
<P><FONT color=#0000ff>/* call the old interrupt handler */ # ] w9 ]1 |6 G4 L2 S+ t" u* D
oldhandler(); 8 j$ Z6 M; N3 Z
} </FONT></P>: P9 {! ]0 v) r0 ]& t0 F
<P><FONT color=#0000ff>int main(void) + ]5 O# |, E: K6 Q5 K7 N
{ </FONT></P>: j2 n, c+ c0 B+ I" J
<P><FONT color=#0000ff>/* get the address of the current clock + e7 y7 h; ?% I! ftick interrupt */ / D4 {; ]2 d. j# x' ]& Uoldhandler = getvect(INTR); </FONT></P> & u p5 x8 I/ z! R3 k; l) F<P><FONT color=#0000ff>/* install the new interrupt handler */ ' \3 x9 C0 s& Y# |; esetvect(INTR, handler); </FONT></P># A- S/ u& O b0 ? q: P
<P><FONT color=#0000ff>/* _psp is the starting address of the ' ~$ k) z8 w- p1 kprogram in memory. The top of the stack # W3 g1 N2 p/ c6 e0 `2 z8 Pis the end of the program. Using _SS and 3 {0 t' g, x# t% u* E' O- t_SP together we can get the end of the ! }% h" u3 b F7 `1 ?. J& Pstack. You may want to allow a bit of 4 v9 y" j& \# c& J
saftey space to insure that enough room 1 h0 i5 U2 `% ^- }
is being allocated ie: 2 `/ A! q# G7 c$ y4 f/ c; \
(_SS + ((_SP + safety space)/16) - _psp) # d& o( x2 K# g( U4 |5 G/ R- Y
*/ : E! Q' {: O# i
keep(0, (_SS + (_SP/16) - _psp)); $ z: g# E- n* O
return 0; 5 x7 ~( x0 ?6 m# D+ j}</FONT></P>