< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>: z; D9 m: f# E. b: j7 U
</P> ! L$ ~7 }! _% ^<><FONT color=#ff0000>函数名: kbhit </FONT> 7 e: l# Q! u2 x功 能: 检查当前按下的键 4 \5 M/ s( M1 f用 法: int kbhit(void); 8 `! E& L2 I* m5 K( r0 z程序例: </P> 7 z9 e0 S4 Z$ z; R- v! n! m5 G<><FONT color=#0000ff>#include <CONIO.H></FONT></P>$ U3 `# G! z7 h* Y& V
<><FONT color=#0000ff>int main(void) ) N# Z Y& Q. @4 [. Z8 q0 i
{ / J7 |/ Q4 v# ~8 i- P4 O
cprintf("ress any key to continue:"); / ]* }. z2 t. h" ^$ Z4 X" [while (!kbhit()) /* do nothing */ ; 9 X1 S& ~" v8 Z
cprintf("\r\nA key was pressed...\r\n"); 4 d2 N% G( _, B5 \' o3 _
return 0; % Z+ k- C8 l9 S2 l/ j( i6 c} </FONT> % ^" w0 @. ?- \8 z2 y</P>7 P! x) Z6 g8 _5 X, V
<><FONT color=#ff0000>函数名: keep </FONT> 1 F1 \& S) B y! Z9 ^/ p# W功 能: 退出并继续驻留 3 E: T. i n+ x3 O( M
用 法: void keep(int status, int size); 9 r* D. H1 I" h程序例: </P> ! C$ w, r$ R$ G5 ]% t<><FONT color=#0000ff>/***NOTE: & D. J, V; w6 e; U l+ V4 N- W, J
This is an interrupt service routine. You ) ?% L( ~* C$ W J5 ican NOT compile this program with Test 5 P. ?! H; ^! N' AStack Overflow turned on and get an " U+ h2 Y* o1 t0 P% A) j
executable file which will operate 9 a8 T% ~' m% H/ {4 U4 {6 rcorrectly. Due to the nature of this 5 K0 F9 [* X2 j/ m' K8 ^, l3 m
function the formula used to compute 2 l" ^" U# |3 I! i# f# p: \1 u
the number of paragraphs may not . v2 L7 v2 u+ K( inecessarily work in all cases. Use with & b& Y- r; ^' Y+ `$ x6 \
care! Terminate Stay Resident (TSR) . s% @) s/ C1 |: h, R- }4 o( z
programs are complex and no other support 5 ^; }9 y0 F8 k3 r
for them is provided. Refer to the 2 h' f) |& w0 ]
MS-DOS technical documentation 6 ?4 P& h. m7 k' a$ X( Y( ~" O3 Q4 ?
for more information. */ ( F) T0 I" A+ m/ C8 E
#include <DOS.H> + {7 x, n1 I# x( U, m/* The clock tick interrupt */ / X( r3 ~! s9 ~+ _+ [#define INTR 0x1C 4 g/ J7 B4 X$ w# G/ K# z/* Screen attribute (blue on grey) */ 3 O" K9 U7 Q5 t& `- Q) r( [#define ATTR 0x7900 </FONT></P>8 l# q+ L+ l' {- n9 ~+ q
<><FONT color=#0000ff>/* reduce heaplength and stacklength 1 A0 j* @/ p2 Q& S" ^0 eto make a smaller program in memory */ % h# k% Y& A" M
extern unsigned _heaplen = 1024; 0 _8 M$ p0 }0 e- wextern unsigned _stklen = 512; </FONT></P> 7 u& q7 p4 G$ X: a( O<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>+ U+ P; V. }! m5 n% p
<><FONT color=#0000ff>void interrupt handler(void) + n; l+ s3 C( Y5 l5 r) t5 Q{ : C4 g! Q5 s& c/ o1 a1 eunsigned int (far *screen)[80]; ) g( s/ v: d/ ^, s; r
static int count; </FONT></P> ! v# p* g. d- ]; s<><FONT color=#0000ff>/* For a color screen the video memory " e& e% g3 o3 v% s% g7 c
is at B800:0000. For a monochrome , N6 F4 J8 Y8 L3 X* H s* Zsystem use B000:000 */ ) ]4 t8 |- t7 c4 t6 b m
screen = MK_FP(0xB800,0); </FONT></P> 3 U& _, P# v/ f9 X1 Z1 d, {; R<><FONT color=#0000ff>/* increase the counter and keep it - n. x, a8 m5 |7 |4 K
within 0 to 9 */ ) p) _+ b0 \+ w8 t" n8 {count++; 8 k& m# U3 `4 w1 I8 O
count %= 10; </FONT></P> @; _& Z5 \: M/ @) V
<><FONT color=#0000ff>/* put the number on the screen */ ! d, G" B# G* S0 j1 Nscreen[0][79] = count + '0' + ATTR; </FONT></P> ) R/ k( ^# y0 C+ _3 N<><FONT color=#0000ff>/* call the old interrupt handler */ O5 _$ r6 Z) J4 w/ ]4 F2 e
oldhandler(); 8 L" J7 {! \) t) u6 @7 x
} </FONT></P>; y# {! j8 t" e$ {5 F* D# Y
<><FONT color=#0000ff>int main(void) 4 x% F) c% ^0 k; u6 G6 g$ m) K) M{ </FONT></P> + \' I4 j. _( j<><FONT color=#0000ff>/* get the address of the current clock % v& O; f' Y3 M0 T. N7 E
tick interrupt */ % u. B% E$ B Moldhandler = getvect(INTR); </FONT></P> 5 ~/ p5 ]3 |& ^ V9 i% u<><FONT color=#0000ff>/* install the new interrupt handler */ + d( I! M- J( I$ a) s" x
setvect(INTR, handler); </FONT></P> , E/ I; Y3 `+ t; j f<><FONT color=#0000ff>/* _psp is the starting address of the 1 H! ~# a) k4 ^$ ~, ?9 h1 k6 ~# e
program in memory. The top of the stack 2 U0 c1 C$ ]/ t, X# [# eis the end of the program. Using _SS and k/ `, j8 k' ?- D/ q7 D_SP together we can get the end of the 9 ~! g3 m+ [) O( A( O; Estack. You may want to allow a bit of 9 n% {; Y; w% k) M% u8 d
saftey space to insure that enough room * o" L4 S! o# `) ?is being allocated ie: , J9 c, z, \1 A% v
(_SS + ((_SP + safety space)/16) - _psp) 4 ] H; j: E/ B7 N' @
*/ 1 d' w) V1 D B5 S- D6 \0 u1 q8 n
keep(0, (_SS + (_SP/16) - _psp)); 8 i8 `9 s% {; |2 @return 0; ! o( t8 C* V3 q- |% n! [
}# `2 v3 b7 z0 D* a) ?; _
</FONT></P> ' Q$ {; ~& H2 o8 w7 C8 D ) k, \$ D a N . T! |' W* l3 A4 K* k" f<><FONT color=#ff0000>函数名: kbhit </FONT> . I0 s1 X& S. P6 h) e7 u( T( ^功 能: 检查当前按下的键 , Y6 \$ s* ~0 e+ P5 N用 法: int kbhit(void); & h) X H$ S6 v9 d3 a9 x
程序例: </P>, B; u2 C% T M" }0 X; g
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>& Q2 g$ V+ v# b: b5 N; k9 ^" K
<><FONT color=#0000ff>int main(void) 1 G) ~( Q1 C6 B{ ! }, q, [5 W/ e. a
cprintf("ress any key to continue:"); / l" n2 \6 p( ]! }5 M/ ^/ C) X% twhile (!kbhit()) /* do nothing */ ; ' R$ ~* S- D6 V5 s/ s" c
cprintf("\r\nA key was pressed...\r\n"); 7 ^3 l3 r8 N h4 Greturn 0; , o% E, n, I' Q! O} + B/ x3 N- {( |7 m( ^8 ~, j& M+ a$ h" s
% W6 I- ?7 v, s: r3 E- D a</FONT></P>" A& u+ i+ T0 w6 p) g' t- p9 q
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>; ?0 s9 t# p8 y' r5 c
<FONT color=#000000>功 能: 退出并继续驻留 7 J# V8 r4 [4 D9 p$ `/ x C- R# N用 法: void keep(int status, int size); 4 f% q' K3 `' R( H
程序例: </FONT></FONT></P> 0 {1 m9 v. \5 [# M) ?<><FONT color=#0000ff>/***NOTE: " \5 @, O8 Z! u- r( D U2 B' @
This is an interrupt service routine. You 0 z. D' {* f2 A6 `* D
can NOT compile this program with Test ' _2 M* v# J$ i' k4 ]
Stack Overflow turned on and get an % I6 P( h2 V& {! |9 A7 [; p
executable file which will operate ) B5 K% F3 E& W# F+ O4 i
correctly. Due to the nature of this 6 ?3 ^. H& ?9 @ a4 w! X n+ @ hfunction the formula used to compute ' z7 L! w/ s- ?the number of paragraphs may not q3 I/ g4 p. x- b0 B6 j7 _
necessarily work in all cases. Use with 8 H, Y8 Y: q7 s$ s& o/ ^
care! Terminate Stay Resident (TSR) ( j0 y# A9 U! C; u: z) w6 K6 D. B+ t
programs are complex and no other support & I; f. o) D5 Y" O8 P
for them is provided. Refer to the 7 ~9 \" G/ P+ M, Z, qMS-DOS technical documentation ) P, X5 l/ _! u7 e R: ~
for more information. */ ; L2 S, j* K0 ?/ A; w/ S% v3 C# P; d
#include <DOS.H>4 R, X* R" x. n/ [# I
/* The clock tick interrupt */ $ p% {6 d. a/ W; l% T, U" k9 \#define INTR 0x1C w$ T& s: P) d8 Z* K; U' n
/* Screen attribute (blue on grey) */ 0 P8 J* W. R% q- L" w' D
#define ATTR 0x7900 </FONT></P>9 ~6 H/ r+ l) S" i& Q6 c2 C8 n
<><FONT color=#0000ff>/* reduce heaplength and stacklength 8 t% U8 ]$ N h( T0 [: L
to make a smaller program in memory */ ( u9 ~- n4 x% [extern unsigned _heaplen = 1024; 2 q6 e/ A; E9 { Q, b. `# H) g: P
extern unsigned _stklen = 512; </FONT></P>1 X( }, x( O! o4 w$ N/ `
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> : e( L- ]7 p+ ]6 } |# l; \<><FONT color=#0000ff>void interrupt handler(void) , @( k8 T% n0 o9 u" o4 Z
{ ( b+ K. u2 K T0 J$ Ounsigned int (far *screen)[80]; 3 X4 x! F# [6 g3 g i3 d9 Hstatic int count; </FONT></P>; |6 N' {' i5 `$ X8 t
<><FONT color=#0000ff>/* For a color screen the video memory " D, I. w+ {# ^' A+ Zis at B800:0000. For a monochrome / M! H( g5 O$ T3 Rsystem use B000:000 */ ) V9 v) _, \& U4 t$ k* w( p4 f
screen = MK_FP(0xB800,0); </FONT></P> 8 R% E- p0 }6 N<><FONT color=#0000ff>/* increase the counter and keep it + g8 A! H. ~5 X7 a4 {
within 0 to 9 */ & Z! Z- u1 I z2 g4 Hcount++; # \/ k3 B5 ]$ Hcount %= 10; </FONT></P>- z6 Y1 ?+ y7 ?, F6 f* h
<><FONT color=#0000ff>/* put the number on the screen */ ( h0 g/ m5 B9 {3 K3 ?( Rscreen[0][79] = count + '0' + ATTR; </FONT></P> # S2 B6 i* B0 j. q4 n<P><FONT color=#0000ff>/* call the old interrupt handler */ " f0 F, J: c' |2 Y2 V
oldhandler(); # ]* \, B" L' W4 C2 g7 H
} </FONT></P> " z6 |+ V6 Q7 O/ R<P><FONT color=#0000ff>int main(void) * q) V' r9 [/ ]4 C6 E. \
{ </FONT></P>* I/ {1 o+ B- {
<P><FONT color=#0000ff>/* get the address of the current clock : U* O/ e0 [1 q9 p2 I
tick interrupt */ & a4 O) K* T& s& Z
oldhandler = getvect(INTR); </FONT></P>" @# m5 G' R S C5 Z" B; X: U1 b
<P><FONT color=#0000ff>/* install the new interrupt handler */ ) X- ]( Z' P* psetvect(INTR, handler); </FONT></P> ( `$ s9 y: h1 L. a' v8 C+ |, s9 r<P><FONT color=#0000ff>/* _psp is the starting address of the $ I) Z7 b: d* `; S: c& Z! q& l
program in memory. The top of the stack * Z9 M# X4 F7 o; ], J. u, }is the end of the program. Using _SS and & p7 |$ ~' G3 `4 _' V" j3 K
_SP together we can get the end of the % R+ \5 n7 }2 u& k2 Ustack. You may want to allow a bit of 9 [- ?$ _6 l* e% D0 p vsaftey space to insure that enough room / p) D# y6 c, _2 \" f. Kis being allocated ie: 7 B5 o7 d B8 Y8 a& A(_SS + ((_SP + safety space)/16) - _psp) + o) k% D4 j9 _+ x*/ 0 Z# v0 X7 d3 ^' D; z
keep(0, (_SS + (_SP/16) - _psp)); ! T( f+ w1 B: \$ p: @6 ` L8 q$ u8 M
return 0; + W) s, l3 ` f; u/ L3 Z6 O; ^4 j}</FONT></P>