< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>& g9 S% M7 H: a9 V9 f& o5 l
</P> ) H! D7 H7 v$ @( j) q u* P<><FONT color=#ff0000>函数名: kbhit </FONT>9 G" e$ ^/ q" z6 x
功 能: 检查当前按下的键 ) }6 }9 }* n/ S b! D6 k, B用 法: int kbhit(void); 5 Q/ _' X7 f8 Y% O) _
程序例: </P> % H) J ^3 q+ b+ O: b* v1 { m/ k<><FONT color=#0000ff>#include <CONIO.H></FONT></P> 8 G7 e8 n9 b# H* F) D5 C( x<><FONT color=#0000ff>int main(void) . g3 Z; G. [1 x* I{ f6 p( s- V- o% Z5 V* Bcprintf("ress any key to continue:"); 9 ]% s: o" p% G$ z$ [while (!kbhit()) /* do nothing */ ; ; r- i/ Z/ _6 }1 Y
cprintf("\r\nA key was pressed...\r\n"); ! z! b& p, e+ M ?5 ~. E8 oreturn 0; * n1 V3 n% Y& j+ B" Q
} </FONT>- ]6 b6 R3 i& G
</P> ! i9 I& m1 p& r, o j1 A5 A+ b<><FONT color=#ff0000>函数名: keep </FONT> 2 Y/ j) q: c9 Z0 O& o/ q功 能: 退出并继续驻留 1 F9 D- y( K# \' h用 法: void keep(int status, int size); 5 y" w% N0 U1 s/ }, J# E& {程序例: </P>& g ~9 l; v( U, N! K* ~
<><FONT color=#0000ff>/***NOTE: ! }5 V3 f( T; n& L7 jThis is an interrupt service routine. You 1 b5 e D5 {& h: n
can NOT compile this program with Test 9 N+ | r! T7 V4 N' F: {9 N' g
Stack Overflow turned on and get an 0 n) H) T5 }7 E% ~2 }executable file which will operate , Y1 ~' Y0 R: R$ \! g
correctly. Due to the nature of this # i/ n0 `$ |0 U5 cfunction the formula used to compute 8 |/ `4 Q& t; A8 F( M9 g# qthe number of paragraphs may not / j# k1 M& a$ I8 w* i7 f
necessarily work in all cases. Use with : K$ d% b( C) ~- x2 h# N! s, [
care! Terminate Stay Resident (TSR) / `" J, M) A- @/ G( B
programs are complex and no other support I a5 \6 v- @6 U& b n: J* Vfor them is provided. Refer to the ! R: a. q6 [' l! G2 w+ o, |8 Q
MS-DOS technical documentation " u" B0 ]. L' l8 z5 Q* qfor more information. */ 5 ~, G4 N- W9 T/ h) D
#include <DOS.H> " J! _, g6 o3 |# ~/* The clock tick interrupt */ 6 a5 I6 E( _, i; }2 E) a1 U
#define INTR 0x1C & \. |5 f0 B. R/* Screen attribute (blue on grey) */ , X/ ~: P1 _8 g7 Y7 K o7 b
#define ATTR 0x7900 </FONT></P> 6 l q2 j' E+ j" m: u! i<><FONT color=#0000ff>/* reduce heaplength and stacklength " \2 [* N v' z% Z6 e
to make a smaller program in memory */ 5 I( X0 f6 n9 o! w" U+ `+ A
extern unsigned _heaplen = 1024; ) }6 r1 Q! f ~9 C
extern unsigned _stklen = 512; </FONT></P>. ?( V8 E' j; y) f4 s' H6 m
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> {/ G/ g: _+ x) n. g+ O8 S. P$ Q
<><FONT color=#0000ff>void interrupt handler(void) 6 [. l; v0 D' ^0 |4 G( ?2 W
{ " b, Y2 W- j: J1 P. A( E
unsigned int (far *screen)[80]; ! ^7 y! S! o$ g: }static int count; </FONT></P> 7 r7 z. L8 J7 s0 W! {) `. t<><FONT color=#0000ff>/* For a color screen the video memory . I' |3 z( v4 d
is at B800:0000. For a monochrome 4 ?: O2 W5 L) V1 u: s( ?/ h$ Fsystem use B000:000 */ - k) t, n4 v, d- _2 G& r. w6 Bscreen = MK_FP(0xB800,0); </FONT></P>. z0 `2 p* n* d( u
<><FONT color=#0000ff>/* increase the counter and keep it & l, \6 ^: y/ E" x, W' i$ {. J5 n- Bwithin 0 to 9 */ * P; V8 z; g7 ocount++; . F% A( P+ F, Y$ I$ a
count %= 10; </FONT></P>' l2 _8 T- ^& i* j H7 B/ o) N: n
<><FONT color=#0000ff>/* put the number on the screen */ ; x/ w! O) {# j! Y. L# T$ R
screen[0][79] = count + '0' + ATTR; </FONT></P>6 ^& Z# E; c* W) N- E( M P
<><FONT color=#0000ff>/* call the old interrupt handler */ 3 f# h: ^2 T7 R: S5 \8 N3 `' ^
oldhandler(); 2 s4 M* t9 ]+ K8 V
} </FONT></P> 7 @- A, q! L" u. `<><FONT color=#0000ff>int main(void) 8 J0 F$ c2 j; l0 p
{ </FONT></P>( s6 W* y. ~4 m0 @! Y: }
<><FONT color=#0000ff>/* get the address of the current clock 5 [: K& i0 j: o" a" \. P* w
tick interrupt */ + O+ Q D5 d- m$ Q$ c& H1 d8 a
oldhandler = getvect(INTR); </FONT></P>- m! g3 W$ Y' Q2 H) ^
<><FONT color=#0000ff>/* install the new interrupt handler */ 2 E9 E4 ]7 O5 _' Q6 Y [6 ]- y
setvect(INTR, handler); </FONT></P>4 M1 z" z4 d7 R8 u9 E
<><FONT color=#0000ff>/* _psp is the starting address of the 7 k& G& g9 M- ]. r. n. P4 {, `program in memory. The top of the stack - J& [- S# e, u1 F f
is the end of the program. Using _SS and # N+ E% ?- X' \- T
_SP together we can get the end of the % \( Q! r0 x; g, bstack. You may want to allow a bit of " c* x, ]! w9 `) u- xsaftey space to insure that enough room - [( W; s# g K# f
is being allocated ie: ! U2 D9 z) n0 {! p' w; W(_SS + ((_SP + safety space)/16) - _psp) 4 D! G4 y$ q$ t, S1 R( b
*/ 1 e5 J/ n6 R G; c4 S: ?7 b3 Wkeep(0, (_SS + (_SP/16) - _psp)); ) v0 ?% Q# d4 q9 w. f/ R. |return 0; # {- P( W( p( ] @
}) }9 h7 L; s3 a. f: A1 c7 I0 ?! p
</FONT></P> 0 w/ Z6 ]& H/ ]; P 3 _* V7 j) s, L. j; k3 |# g; B8 K; _ , N! @+ r/ {$ y7 } q/ U V. e<><FONT color=#ff0000>函数名: kbhit </FONT>9 m0 r1 S" X3 W: t' h; e2 V: ~% z" I
功 能: 检查当前按下的键 / g2 y$ F! \! F$ W4 {# \- `
用 法: int kbhit(void); 4 N# t# f/ a# \/ f; F5 d9 M程序例: </P> , o# ^7 |, \5 `/ P j: m6 A) U<><FONT color=#0000ff>#include <CONIO.H></FONT></P>" ~- ^9 x' Y9 g
<><FONT color=#0000ff>int main(void) : G, A( P4 [7 `
{ 2 I4 N0 B5 F0 X
cprintf("ress any key to continue:"); 9 g6 n2 \- V, ~5 `4 H5 Bwhile (!kbhit()) /* do nothing */ ; ; C4 J, ]9 w) l( ]
cprintf("\r\nA key was pressed...\r\n"); 3 ] g+ v5 ?# A5 i8 y9 }9 h3 M
return 0; 3 V1 ~6 P/ H/ ]* \; r% T9 E" D
} 0 ?9 c/ \0 D6 f" k6 F& ~* t3 G' R4 c1 n* Y- M
6 \: g# O: V, i</FONT></P> _) s$ {; d6 [<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> " T# F' o+ v) t9 C<FONT color=#000000>功 能: 退出并继续驻留 ; n( b' J5 k$ ?% e! O, }! a
用 法: void keep(int status, int size); # e# q. U) x, G程序例: </FONT></FONT></P>& e. I! ^5 n1 T& N( |
<><FONT color=#0000ff>/***NOTE: 8 \, m' X8 k7 n) q
This is an interrupt service routine. You l; R0 p2 Q2 `$ k" ]7 J
can NOT compile this program with Test 5 [' n- Q$ Z% g; }! I$ t
Stack Overflow turned on and get an & @1 a, X2 S% t+ F" W6 a3 Hexecutable file which will operate " r- y/ b3 w0 ]: X" z
correctly. Due to the nature of this $ T: x9 r( n3 A- A8 ?* m
function the formula used to compute : A# a6 I2 O: O8 R0 D0 w, s* L/ kthe number of paragraphs may not 8 h8 p. y% e" Z! Nnecessarily work in all cases. Use with 1 e* _% h8 ~8 c) f( }/ F; S, d
care! Terminate Stay Resident (TSR) " ~( Q; D8 m% F( mprograms are complex and no other support . u+ N" P+ X. N5 h& {5 P4 z
for them is provided. Refer to the - F. O9 a, Q2 y( d: ?: ]0 I7 S/ NMS-DOS technical documentation 5 k0 \. p( b/ t M
for more information. */ 4 m/ A. a2 i. w5 r6 u
#include <DOS.H> : f8 r9 o% P: v# F& o7 z/* The clock tick interrupt */ 3 u* s2 V' a" o* s ~( o, g
#define INTR 0x1C % h3 x4 ^, L" s) n- T7 A3 p/* Screen attribute (blue on grey) */ 8 m1 j/ } V! }8 o: r f1 W#define ATTR 0x7900 </FONT></P>2 v, d: S" b6 D- U% j$ |
<><FONT color=#0000ff>/* reduce heaplength and stacklength # h5 r5 [4 O. y% U8 o+ Tto make a smaller program in memory */ ; d4 l/ }' ?( i
extern unsigned _heaplen = 1024; 9 D) p' l% l' U* Sextern unsigned _stklen = 512; </FONT></P># ?- O/ S( E1 _& Z# I
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>2 X$ Q) V1 ^' i7 n
<><FONT color=#0000ff>void interrupt handler(void) ! Z, U* P+ e' F0 A{ 7 F, d) F5 _- B- B4 Punsigned int (far *screen)[80]; 1 t7 r3 P7 x; x4 P8 F
static int count; </FONT></P>% ?( H% C& H# i- a: z4 C
<><FONT color=#0000ff>/* For a color screen the video memory . C6 t* D. G" f6 K! [: b8 O+ ~
is at B800:0000. For a monochrome 8 f! U: O& s: u2 s% k6 Z
system use B000:000 */ 9 @* J o! c0 X4 y+ Uscreen = MK_FP(0xB800,0); </FONT></P> # F# S0 \* b9 J5 d! X* a9 {<><FONT color=#0000ff>/* increase the counter and keep it 0 s+ L- W: m5 ~% Y) H9 }
within 0 to 9 */ 6 |8 g4 B, z- Rcount++; / `* R+ k. Z7 pcount %= 10; </FONT></P> 0 Q6 \# L# ~6 A* A4 `<><FONT color=#0000ff>/* put the number on the screen */ ! O4 }4 ~9 _) r1 c! n. e+ b: f# v2 n
screen[0][79] = count + '0' + ATTR; </FONT></P> ! D a- W3 ^1 {! A& a- c* {<P><FONT color=#0000ff>/* call the old interrupt handler */ + F9 Q7 o" L1 f) k! V0 d6 ?* S* ioldhandler(); ( T* k. x/ N: B+ Y f
} </FONT></P>' u. A4 R8 O( S3 u
<P><FONT color=#0000ff>int main(void) $ d2 z0 _+ [4 W9 }$ \{ </FONT></P>" B" d- A" g* n: {( P
<P><FONT color=#0000ff>/* get the address of the current clock ' t0 r+ s' s' Z0 e7 C& S s; a
tick interrupt */ ( y; H. ]1 U! _oldhandler = getvect(INTR); </FONT></P> # E V4 M7 u% ^# x<P><FONT color=#0000ff>/* install the new interrupt handler */ : O5 C, p2 h3 P2 v, k# F# h
setvect(INTR, handler); </FONT></P>. h$ r; e5 N6 g$ W
<P><FONT color=#0000ff>/* _psp is the starting address of the : q: f+ d/ h. r8 `* @program in memory. The top of the stack # G b j$ b# W% M9 B$ ?4 u2 vis the end of the program. Using _SS and . \% [ ^; J: C( c) _- @_SP together we can get the end of the 0 N, D& M6 y- A" u' S; t
stack. You may want to allow a bit of ?( K; q1 p5 z4 t) {, g" Lsaftey space to insure that enough room & r6 K# ^; m$ ^is being allocated ie: 4 w/ _- D$ `; N( E! N(_SS + ((_SP + safety space)/16) - _psp) * x1 m$ I1 }6 _/ N3 u*/ " k! @+ b/ k R* h( ^7 V3 T/ f
keep(0, (_SS + (_SP/16) - _psp)); ; q1 c: S4 n' x, u9 u5 I2 F
return 0; 3 H: J6 Y1 u% L* {# `8 e}</FONT></P>