< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>8 e7 Y# ^* i0 u; [) Z, O: B: k
</P> 0 t9 H# c' J4 H<><FONT color=#ff0000>函数名: kbhit </FONT>- ]& W6 ^. T( e7 e7 C
功 能: 检查当前按下的键 # u6 I! ^7 g; J% J
用 法: int kbhit(void); ; d& v" z" |0 t1 b. I* ]# D/ t
程序例: </P>: E) @7 @8 n8 o
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> + L8 k6 S+ k8 k; f* t7 Y<><FONT color=#0000ff>int main(void) 7 M; _) ~0 ?3 {
{ " f. a: U4 b# l2 Q' J4 M) Q) ^cprintf("ress any key to continue:"); 7 ]& u. B w; D& m6 p2 i) \- J7 b
while (!kbhit()) /* do nothing */ ; 3 s/ x. J: k$ b; t) Z/ i! p0 a
cprintf("\r\nA key was pressed...\r\n"); ' |: _; h' l w- E& r' C
return 0; 1 O" m2 d2 l1 m* u1 B- c. j, g} </FONT>1 l: w. p+ K& z# t3 L
</P>! [. e, j! X* N/ x
<><FONT color=#ff0000>函数名: keep </FONT> ! V. R5 [9 t4 J7 B1 }功 能: 退出并继续驻留 $ m$ H+ q- `9 G- P
用 法: void keep(int status, int size); U) p7 { u3 M, K4 h5 j程序例: </P> $ C/ _( u& @4 Y8 e6 v$ ?3 d* ]<><FONT color=#0000ff>/***NOTE: 8 ^0 |) h" w$ {) aThis is an interrupt service routine. You ) ]) S: X& a2 t, ]) x1 ~* v4 b- `; X
can NOT compile this program with Test ~6 v% O4 h, d9 B3 s3 FStack Overflow turned on and get an 5 [: R& g" ^: d1 R
executable file which will operate 2 Z" H9 k6 i6 V# F/ W" t- Q" c5 k# a* scorrectly. Due to the nature of this 9 F5 [) v, x( A% D9 E& r$ Lfunction the formula used to compute 7 d; A) `' J9 t w% z
the number of paragraphs may not + w. q+ ?* Q( p0 B: Jnecessarily work in all cases. Use with % v6 \3 |3 R, U' \- pcare! Terminate Stay Resident (TSR) # u# E/ L* y- D0 pprograms are complex and no other support 9 @; e- h0 d; A- ]; F, t* Ofor them is provided. Refer to the $ y- L& B; v# K' B4 bMS-DOS technical documentation 3 h: |3 z9 w9 l7 [( n; f [, nfor more information. */ ( o `3 J) d6 }6 r#include <DOS.H>( y$ k. @8 y9 d6 r
/* The clock tick interrupt */ 4 e; P0 T& W, l0 j
#define INTR 0x1C * |" A- H f( }4 e i( h* L% l- r/ N
/* Screen attribute (blue on grey) */ ' v: x9 a. [7 d* G4 N5 h#define ATTR 0x7900 </FONT></P>2 H1 x* P/ N) g, v* ^ V* u
<><FONT color=#0000ff>/* reduce heaplength and stacklength 4 x# \7 I' n; n9 `- P' W5 z$ `
to make a smaller program in memory */ 7 [4 U* R# w/ e$ I
extern unsigned _heaplen = 1024; 5 c! ?: O- b* Lextern unsigned _stklen = 512; </FONT></P>, y7 ^9 K; H* s' s0 ]# z
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>+ j# B" ?; l& n8 O+ W& v# K
<><FONT color=#0000ff>void interrupt handler(void) ' d% y+ C& {5 b4 x
{ 7 R! u- R5 z- I, ?: X6 p% x
unsigned int (far *screen)[80]; ) I; ?) u3 z% Z8 Q* M+ k% `
static int count; </FONT></P> + E% J' I9 X1 u: c5 V/ z<><FONT color=#0000ff>/* For a color screen the video memory . I. S% I! c N8 `* ^( l+ ^
is at B800:0000. For a monochrome 1 G1 T' @& k' p
system use B000:000 */ : }+ w* g1 p F5 {/ Qscreen = MK_FP(0xB800,0); </FONT></P>+ V" s: v5 r+ i: Q' W0 l% E$ _
<><FONT color=#0000ff>/* increase the counter and keep it 6 O$ B: p4 i, U" K% I2 Rwithin 0 to 9 */ % U0 ^8 R) l# U7 ]+ C; l' ccount++; c$ G5 O( q9 q3 v
count %= 10; </FONT></P>, \4 i" `9 c* T
<><FONT color=#0000ff>/* put the number on the screen */ $ d6 Z, N3 N/ X; y+ v# i- Q" Oscreen[0][79] = count + '0' + ATTR; </FONT></P> 2 B* ]' D2 T3 b# C+ W3 K( j& X<><FONT color=#0000ff>/* call the old interrupt handler */ ; e1 s' f& X4 O# w, k# O, d
oldhandler(); 4 F7 b& F3 w- c* q: K: K} </FONT></P>1 e+ L; O0 c' X. h9 k: K+ k
<><FONT color=#0000ff>int main(void) S N/ `& {, D7 U8 i+ |{ </FONT></P> $ E. g9 E A7 L) v& E/ C<><FONT color=#0000ff>/* get the address of the current clock . d- N' a4 |& K: W8 vtick interrupt */ ; S/ k7 D9 ]* V' ^6 v3 B* g) |
oldhandler = getvect(INTR); </FONT></P> % T; j- |: L+ I' O( K! {. i<><FONT color=#0000ff>/* install the new interrupt handler */ 5 Z I' q6 Z9 z4 k5 Zsetvect(INTR, handler); </FONT></P> s% f& G B: M: \ [<><FONT color=#0000ff>/* _psp is the starting address of the 0 m: T* Z4 j- s, R- y4 j0 j: ~% Mprogram in memory. The top of the stack ; |; P% M# q5 s6 h' ?is the end of the program. Using _SS and 1 i7 P! B8 p. p3 s; P' W' u_SP together we can get the end of the 7 V, p- W: }* l+ S
stack. You may want to allow a bit of / D% E4 v8 |7 C- r
saftey space to insure that enough room ' W: j1 \5 G* D7 t
is being allocated ie: 9 `8 |( }) C$ Z! L! Y
(_SS + ((_SP + safety space)/16) - _psp) & t0 P n+ w. R/ \, F8 d c" Z
*/ 4 f& d6 U( H% s/ ]; t- E4 `4 Ckeep(0, (_SS + (_SP/16) - _psp)); . Q1 u1 K9 i. k& l; B
return 0; : k" q% Z+ C0 }" ?} " u* {* J" u; m% `</FONT></P> $ B2 n0 _+ c4 N' D) @! F$ r) }: l5 z 9 _8 \, @7 C$ T7 p$ u; z8 {4 E c) k- A' C
<><FONT color=#ff0000>函数名: kbhit </FONT> # P0 v8 _2 }+ y4 Z" f4 [. t, q功 能: 检查当前按下的键 & q& w7 v/ G' o1 C用 法: int kbhit(void); 0 ^- I* S+ ^+ B0 V程序例: </P>' @/ X. T" ]$ y) O
<><FONT color=#0000ff>#include <CONIO.H></FONT></P> + F' [7 Y4 I1 Q q* m2 ^<><FONT color=#0000ff>int main(void) 0 L4 E5 p( y8 E- h{ + U- r% ~6 p1 ]cprintf("ress any key to continue:"); 7 i" \% s9 n# @# L' X5 b" o3 Ywhile (!kbhit()) /* do nothing */ ; , ]& X: Y; W: x+ N2 d. j* O
cprintf("\r\nA key was pressed...\r\n"); / n8 |$ p i. \0 B N$ E% k5 ?
return 0; / ?- M, N7 g( s- i3 u7 g} 3 T6 q B* C' N/ M
; Y+ Q7 i- I8 R7 E5 b3 Z+ v 1 a3 o, v* X! u3 w$ a% P. g6 L# ~</FONT></P> . \. d& H* V' R- v5 ~0 D' e z" C<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff> B" v- p+ k$ U: S" n( q' z
<FONT color=#000000>功 能: 退出并继续驻留 0 z. f0 z: i8 }3 G
用 法: void keep(int status, int size); ( l! J! O2 s7 D$ v* T! |
程序例: </FONT></FONT></P> / C0 b3 Q+ B! v, L, z7 V8 ]& W1 {<><FONT color=#0000ff>/***NOTE: : |$ P' Q# i3 u" ^* \5 I5 B6 T) U
This is an interrupt service routine. You $ E! I. v$ ^' O% o9 a1 g1 Wcan NOT compile this program with Test % j8 x% L- e9 Y* b6 ~Stack Overflow turned on and get an 0 o. M' G0 ]; [2 f% E7 Y; N% Nexecutable file which will operate l2 U9 ]. F. P& m/ T9 zcorrectly. Due to the nature of this , [6 C! R/ L" L; N( G; mfunction the formula used to compute 6 O7 D- T m& _. `the number of paragraphs may not 8 W3 }: y5 {& `7 M+ [4 N* O; fnecessarily work in all cases. Use with # C5 W' w5 O- o- g2 N
care! Terminate Stay Resident (TSR) 3 T$ Q9 _0 b6 x
programs are complex and no other support , T( u' p# ?) z& ^ d
for them is provided. Refer to the / v5 b; c) N( O$ Y' qMS-DOS technical documentation & L9 G8 F1 t" u5 {- ?+ @1 b
for more information. */ + f3 J% Z6 a) s0 N; Z; n#include <DOS.H> 0 h6 O( E! n4 J# o. Z0 p* B. a- I/* The clock tick interrupt */ + U1 Z$ }5 e- X
#define INTR 0x1C * F% B" D F* E0 k0 S/* Screen attribute (blue on grey) */ 5 n! |0 z! |% H0 u. F" C+ }5 }
#define ATTR 0x7900 </FONT></P>+ s7 N7 w4 R6 x/ l( E0 M% B" W8 u
<><FONT color=#0000ff>/* reduce heaplength and stacklength & Q5 p: W3 i1 g2 |to make a smaller program in memory */ ) T4 Z! V6 @: ~& w
extern unsigned _heaplen = 1024; # y, E( y# e0 x, Z6 t4 z. Textern unsigned _stklen = 512; </FONT></P>. n5 x X4 @& O0 G' I
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>6 d% }* R7 Y) q- d9 n
<><FONT color=#0000ff>void interrupt handler(void) + ^& g1 v6 S: q3 f$ ^2 K# Z6 l* A/ h{ : R$ G% {2 z/ a+ @1 c1 P. Y
unsigned int (far *screen)[80]; # } D( Z! [. n0 M& p# j: tstatic int count; </FONT></P>% o8 p6 N; `$ N) b- r; w8 x7 n
<><FONT color=#0000ff>/* For a color screen the video memory / i1 u! I( _" q9 t: [1 p
is at B800:0000. For a monochrome $ Z0 Q1 H% s; usystem use B000:000 */ - `7 s E R7 C# v
screen = MK_FP(0xB800,0); </FONT></P>1 f& M; w- I8 L: [6 j
<><FONT color=#0000ff>/* increase the counter and keep it ! t( s% w3 l* q+ `( g9 \
within 0 to 9 */ 4 H# ]0 }8 P! G, \, V5 y2 Qcount++; " s% s, ?7 S7 N( f! A
count %= 10; </FONT></P> 7 Q6 V9 T( u1 Q0 j [* V6 k% U<><FONT color=#0000ff>/* put the number on the screen */ $ ?" E q, O3 K5 e. x/ |" q, cscreen[0][79] = count + '0' + ATTR; </FONT></P>7 b7 {1 A9 j+ z" L' a' j
<P><FONT color=#0000ff>/* call the old interrupt handler */ . K. R d6 s8 O. Z9 J+ Poldhandler(); . |2 N8 e4 }7 t
} </FONT></P> 8 N3 x$ d& J H6 A; j1 d* _<P><FONT color=#0000ff>int main(void) 9 E5 R9 e6 \4 w+ C0 R, e2 j
{ </FONT></P>3 ]5 S7 H% n( \8 c" Y, Z! N. A
<P><FONT color=#0000ff>/* get the address of the current clock # V/ I- S) `$ ^& G- E# D5 @- F# gtick interrupt */ 4 f) e0 K4 o+ O& E1 K9 [: Z, Z
oldhandler = getvect(INTR); </FONT></P>1 k9 h- O3 _" R
<P><FONT color=#0000ff>/* install the new interrupt handler */ / B) X5 \% y/ S( g' k J$ P- T
setvect(INTR, handler); </FONT></P>5 X/ E" S. F( g: c0 O
<P><FONT color=#0000ff>/* _psp is the starting address of the # T% m) J: ?1 Sprogram in memory. The top of the stack & s7 |3 p3 P8 s! j9 w/ \+ s" U9 G+ Dis the end of the program. Using _SS and . M5 x8 c& r: {+ m/ E
_SP together we can get the end of the " T4 _: n% m! J) _" `0 v+ z7 o7 _
stack. You may want to allow a bit of 6 d3 [3 h1 \, ]0 f' R
saftey space to insure that enough room % g# f; o; c: j" M
is being allocated ie: + V* s8 K+ o& J/ i% d6 F3 C, p
(_SS + ((_SP + safety space)/16) - _psp) 2 g% L4 j% h. [8 Z
*/ 7 z, g1 {4 f7 q# g! K# G& K
keep(0, (_SS + (_SP/16) - _psp)); ! Z: D8 _: ~5 l5 O
return 0; ) z( k- z1 q# V2 h3 f5 [* p
}</FONT></P>