< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>5 w- N& `8 V- H }! t# o9 g- }) c
</P>) k8 c, e1 ~, ]3 c2 v% V5 [
<><FONT color=#ff0000>函数名: kbhit </FONT> 0 l2 h% V% I6 [功 能: 检查当前按下的键 0 p1 H$ t) i8 P" y- |/ ~用 法: int kbhit(void); : P6 e( o" t U3 H
程序例: </P>5 p4 r# B& }, ?7 C) B, l
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>% a1 k) Q( s$ y. Z) H. o c- s
<><FONT color=#0000ff>int main(void) 9 x' C+ y# O4 n: z/ I{ # V6 d$ w5 \* Icprintf("ress any key to continue:"); ) Y/ ?7 H$ F7 t! C! h5 s
while (!kbhit()) /* do nothing */ ; ; G+ K$ a& A6 V$ T, h; I! ], { l
cprintf("\r\nA key was pressed...\r\n"); 9 J% q. A& c ]) ?
return 0; 8 c$ ]- \9 |) v; s# ^8 H, W
} </FONT>: U h' C8 I; [5 F1 b
</P>0 H$ A Z/ X3 O9 K
<><FONT color=#ff0000>函数名: keep </FONT>* r& C3 s+ a/ y6 j
功 能: 退出并继续驻留 ' h8 t* U2 Q7 a: v1 j5 z用 法: void keep(int status, int size); |7 N N# U5 t5 C( w) i程序例: </P> & q0 Z4 g4 }- t8 p<><FONT color=#0000ff>/***NOTE: 1 Z: ]- i& d: g! i- Q& m7 v
This is an interrupt service routine. You ! \' | \4 M; g% M" a' t
can NOT compile this program with Test 0 b2 G7 ]: v9 N& ^+ g
Stack Overflow turned on and get an 0 A) C( t) `3 {2 f* F$ h
executable file which will operate 1 }( Q- `. j9 F; Y2 J1 Ecorrectly. Due to the nature of this 8 q& X! V) F5 o3 l- e) Q
function the formula used to compute & Q( b6 S4 A* D! ]2 H$ N2 Wthe number of paragraphs may not 2 Y1 E; e1 k+ C G5 H8 Vnecessarily work in all cases. Use with ' T9 E2 V6 N5 d
care! Terminate Stay Resident (TSR) 7 S/ a } f" T2 iprograms are complex and no other support $ }$ _ u }0 s2 `8 e0 ~" |
for them is provided. Refer to the 3 E7 c" p8 R( P5 PMS-DOS technical documentation * W$ }" A m8 z9 F' xfor more information. */ + D w' l, p- E: Q4 [6 z8 ~: i
#include <DOS.H> , |8 F3 l6 S9 v( {+ N# t0 Z/* The clock tick interrupt */ 0 o8 ^) _% j# i, T: c1 E
#define INTR 0x1C 0 C, w. W+ m! G; K0 b: U- m5 F
/* Screen attribute (blue on grey) */ 4 r1 ~# }' o* k6 L+ g8 M#define ATTR 0x7900 </FONT></P> + v" A# m) H) Y1 k<><FONT color=#0000ff>/* reduce heaplength and stacklength + d8 m5 Y0 i& Y+ H7 m* uto make a smaller program in memory */ 3 j- {% r1 L6 Y/ }$ Q4 _/ P: c0 p
extern unsigned _heaplen = 1024; ) \+ _/ G# n' W; Iextern unsigned _stklen = 512; </FONT></P> / z+ o3 d. s' U% G<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>3 ^5 p4 B: n: ?/ c
<><FONT color=#0000ff>void interrupt handler(void) o8 I1 M, z7 C6 F0 P* A9 m
{ % h4 l, M& H9 R% P
unsigned int (far *screen)[80]; * G0 L6 g8 H! D s* t; m
static int count; </FONT></P>' V) o' `: W. W
<><FONT color=#0000ff>/* For a color screen the video memory ( l- z* t8 [- H) W. ~2 x/ \
is at B800:0000. For a monochrome ; u0 H/ v& Z+ c/ b. k) g7 C6 i
system use B000:000 */ 1 [3 v7 [* ~1 ]# X+ Qscreen = MK_FP(0xB800,0); </FONT></P>, _8 c# z& v6 S# B2 t# g$ O7 {
<><FONT color=#0000ff>/* increase the counter and keep it . e( l0 j! z2 N2 }0 Q( L# _0 V
within 0 to 9 */ 9 X9 P! m, p5 I& Q. ~count++; # @" ? H" ?* Xcount %= 10; </FONT></P>4 l0 p' H3 `1 |# ^ _
<><FONT color=#0000ff>/* put the number on the screen */ $ v+ w. P1 U2 e( Kscreen[0][79] = count + '0' + ATTR; </FONT></P> # ^! h# Z7 m O! Q9 z9 ?7 \. q' j2 [<><FONT color=#0000ff>/* call the old interrupt handler */ & q! M& p8 N3 B r+ Poldhandler(); # C# M; Q6 Y! p$ p} </FONT></P> % x! a2 _. Y( S2 @7 v7 J& y8 B* o<><FONT color=#0000ff>int main(void) 9 S, h, @9 t- k- u: ^8 u
{ </FONT></P>) D; p) {1 y4 N
<><FONT color=#0000ff>/* get the address of the current clock * A& p# q. e Q8 s0 |* _tick interrupt */ 2 v" Z+ b0 d2 Z0 _- h; Zoldhandler = getvect(INTR); </FONT></P>, Z; {( M. q6 k0 O. i& J9 h! c1 c
<><FONT color=#0000ff>/* install the new interrupt handler */ K) z! C) p% J3 q
setvect(INTR, handler); </FONT></P> 6 i& T v& D: n# G4 @% W3 |2 J2 ]+ S<><FONT color=#0000ff>/* _psp is the starting address of the ) Z; Q( ^1 n( |, E+ x
program in memory. The top of the stack 9 }1 F+ Z7 l" H3 t9 Y
is the end of the program. Using _SS and : R% n0 T+ ?+ X$ \+ _ ?0 U0 @5 O
_SP together we can get the end of the ; E4 ?# H: n" h f' G# U Q
stack. You may want to allow a bit of ; _. j3 {; ]+ i* @; \saftey space to insure that enough room : N" {$ n% U' ^; T/ A( Iis being allocated ie: % u6 d; m6 K& [9 }3 i
(_SS + ((_SP + safety space)/16) - _psp) $ ?+ t* _4 R5 s8 b*/ T+ p$ @& }/ c \6 X0 R
keep(0, (_SS + (_SP/16) - _psp)); & ?: H2 E! X: d9 k" u3 ^- D
return 0; $ y- C& S& Q# o} 7 k M! V6 L- R</FONT></P>$ D7 i: \. h# Z5 T6 P
' G" ~& {, s6 Q% Q( G5 x1 ]
3 q4 n& E0 ?3 ]! A* [; M6 ~0 k
<><FONT color=#ff0000>函数名: kbhit </FONT> - Y s0 \' r' ?3 [& T" T0 c功 能: 检查当前按下的键 - q' \# f M0 S8 }; L6 o
用 法: int kbhit(void); . c8 ?, b: m4 d程序例: </P>7 h- `: m0 `8 K" {+ i# g
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>3 ^6 v8 `7 P7 n- G' S: x3 x3 Z
<><FONT color=#0000ff>int main(void) % c- V, t4 X' S4 M" Q5 j* j. I1 A{ 1 ^" x" I8 h4 l
cprintf("ress any key to continue:"); ; m7 [' _/ u0 h" @* Jwhile (!kbhit()) /* do nothing */ ; 7 k0 V4 h H, W$ o1 K `5 |/ c
cprintf("\r\nA key was pressed...\r\n"); ; q$ ~0 D U. \- S; S
return 0; _7 W" {- f1 d9 R0 l3 ]+ u; a3 E
} ! t* f! p/ p( ~# n% l( G
* G0 k9 {6 A1 ]
% N6 E$ n# x- k+ L, S- y7 q
</FONT></P> 6 p/ c& ]1 ]( V! ~- i4 ], a<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>6 N" l8 e4 S% p3 W* @5 [+ M+ E
<FONT color=#000000>功 能: 退出并继续驻留 * I" @$ K( r. A用 法: void keep(int status, int size); & j) U2 J: l1 m% o0 v# g# b程序例: </FONT></FONT></P>; F% ^1 A$ I0 l% v0 P
<><FONT color=#0000ff>/***NOTE: " r0 a2 I# k9 Q; x
This is an interrupt service routine. You * m) `8 q- ]# O2 C& V* i* F( w
can NOT compile this program with Test / H, {/ l" _! k0 y/ a- { T- j8 hStack Overflow turned on and get an % t+ K2 b7 g, n" B& y( ~# L4 O+ ?
executable file which will operate @% }. }8 U4 R5 @( D/ R
correctly. Due to the nature of this , E# i' x( ]/ K. f2 j% `/ z+ [* R% ^function the formula used to compute ! x V |, a0 }
the number of paragraphs may not - c& ]/ i3 O3 Z1 D
necessarily work in all cases. Use with 1 h# J5 O+ F" l$ t; D" hcare! Terminate Stay Resident (TSR) & x6 n c; q7 _) R! _programs are complex and no other support 0 t* }. q- e5 g3 Z! @" l- yfor them is provided. Refer to the - N$ F1 j4 z; n+ _# {
MS-DOS technical documentation 5 R0 P; e- B mfor more information. */ 8 U0 b* b G4 }#include <DOS.H>+ A0 w6 I3 b A/ c X+ `
/* The clock tick interrupt */ , j: b% j' b3 I7 m( D0 v
#define INTR 0x1C . T1 [, d2 c( m7 {, ^/* Screen attribute (blue on grey) */ 4 B8 O1 R4 J8 q#define ATTR 0x7900 </FONT></P> % z6 H h% X- `- M6 ^<><FONT color=#0000ff>/* reduce heaplength and stacklength 3 H0 X0 X. I$ l: c& P% _
to make a smaller program in memory */ 9 w& C, B7 g2 x- l! B/ C! L$ Z+ j$ E6 h
extern unsigned _heaplen = 1024; ; e# Q: z3 ^- R% H5 y' l
extern unsigned _stklen = 512; </FONT></P> # H8 z4 B# z; u3 L( K<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P> # q# Y" H0 q6 @7 P<><FONT color=#0000ff>void interrupt handler(void) : R: [+ a# @+ C# Y{ , Z p E* m o, @: f+ N+ U" ]unsigned int (far *screen)[80]; 4 B* r( Y7 b: O+ Mstatic int count; </FONT></P> $ [5 U4 M- {( l' Z<><FONT color=#0000ff>/* For a color screen the video memory 8 M6 [6 D8 ^5 f4 s0 P" h. b; q
is at B800:0000. For a monochrome / M, ^' A, A3 X5 \system use B000:000 */ ) Z4 f- Z' L0 H6 l8 @screen = MK_FP(0xB800,0); </FONT></P>6 [1 I! E' U& g2 F/ k
<><FONT color=#0000ff>/* increase the counter and keep it # Y* e: G( l5 V# n5 ?' b1 W
within 0 to 9 */ ' r. I& W3 f% |0 H& `0 acount++; ! ]; O# Z3 H% n- z5 j$ b+ e5 Zcount %= 10; </FONT></P> ' Q: y# Z2 {/ _/ h! B<><FONT color=#0000ff>/* put the number on the screen */ ( h- |* P% F# ^9 n
screen[0][79] = count + '0' + ATTR; </FONT></P> 2 d. c6 r& \: q' }<P><FONT color=#0000ff>/* call the old interrupt handler */ # y$ `# }1 l& s( Y x* X$ T# D8 ]oldhandler(); / F1 P5 K; K- S; p' n1 u! a7 U! ^# O
} </FONT></P>! s s8 w8 P# [ l! E" n
<P><FONT color=#0000ff>int main(void) 5 g: ^) @# ]$ h/ x9 U{ </FONT></P>: W# N; Q; z1 S
<P><FONT color=#0000ff>/* get the address of the current clock ( h0 i! x" g# n% @1 F) a$ z' qtick interrupt */ 5 J7 O T7 b+ b% h+ @, _! t
oldhandler = getvect(INTR); </FONT></P> 8 j, a: B3 c% m7 [) X1 o" |<P><FONT color=#0000ff>/* install the new interrupt handler */ ( q; G6 b, X# x; c; V3 R/ jsetvect(INTR, handler); </FONT></P>* E5 ~4 W: k/ v; ]
<P><FONT color=#0000ff>/* _psp is the starting address of the 5 e. d# b: G- q v" C$ A
program in memory. The top of the stack 3 H1 q; F* D/ i- j
is the end of the program. Using _SS and $ K8 s" ?! O3 a9 O, z8 O_SP together we can get the end of the 2 w3 f6 p- n4 K
stack. You may want to allow a bit of ( i6 @5 y4 t* q- T S: t
saftey space to insure that enough room ) J6 c, w g0 v
is being allocated ie: % w: c7 m4 z8 z# u, V) E3 ]
(_SS + ((_SP + safety space)/16) - _psp) / H1 H! `- }7 t. t$ H
*/ 7 }9 ?; n8 N/ ? B$ p% kkeep(0, (_SS + (_SP/16) - _psp)); * _8 ]: o: l) |5 h
return 0; ( t3 G8 j* ?, P9 g1 o* k8 c: e$ v! t
}</FONT></P>