- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>! ]2 v) E7 D$ p8 q7 m
</P>
2 V" \4 |" u. e1 m1 C< ><FONT color=#ff0000>函数名: kbhit </FONT>
0 y/ [6 y: M# n M4 o功 能: 检查当前按下的键
' \' A! K) w. c! I- c. U; N, P用 法: int kbhit(void);
6 E8 U- s) _, I3 e& [/ }程序例: </P>% G2 B5 x% t- F! k- `. b* I: r$ u' n
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
1 w/ @# V$ z9 [. @9 W' Z6 U< ><FONT color=#0000ff>int main(void) ], y2 r& c7 {5 p: D. b
{
# @+ _. {# ~" |( O3 xcprintf(" ress any key to continue:"); / o4 Y8 M# A+ e. ?+ s3 z8 Q+ K% A4 V
while (!kbhit()) /* do nothing */ ; * H2 E( y' {: U! n: c3 n
cprintf("\r\nA key was pressed...\r\n"); / o8 H1 z1 w3 P
return 0; & T6 e8 V2 g. }/ c* V$ q9 a- F
} </FONT>
; j0 L+ \- t& U, p4 {4 i0 `0 @</P>! w6 M* F3 n# j0 p% M' W1 E
< ><FONT color=#ff0000>函数名: keep </FONT>) _! I0 U" o+ W! T1 x2 X( H
功 能: 退出并继续驻留 9 z( H- E4 y! c% c) a+ J2 ~; l
用 法: void keep(int status, int size); ) y1 S3 p( G# u# O0 A1 y
程序例: </P>
% M/ m3 p5 K! n* f; C* O< ><FONT color=#0000ff>/***NOTE: $ k, S# Q% i3 u" f- I7 ~
This is an interrupt service routine. You . K7 g" q) ^, F" T: A
can NOT compile this program with Test 7 [4 v) C% i8 V$ E, H# a3 g
Stack Overflow turned on and get an
* n" S/ V1 T3 \5 vexecutable file which will operate
4 B& m! N F8 qcorrectly. Due to the nature of this 7 j7 r) q4 T# n' O
function the formula used to compute
1 ?) V( w0 s8 T+ n/ A6 mthe number of paragraphs may not 1 \6 M2 M7 a# i: K* T
necessarily work in all cases. Use with
) t, C1 q' S$ P( O. acare! Terminate Stay Resident (TSR)
& h; S0 D( E4 iprograms are complex and no other support
6 N. o! M& V( a: S5 Pfor them is provided. Refer to the
% n/ v% Z; V& R4 PMS-DOS technical documentation ' s: u' f, B( X# Y8 U
for more information. */
: F/ L8 S+ I( X#include <DOS.H>, Q/ U$ s: X8 L$ v) [% }/ t
/* The clock tick interrupt */
5 @6 J2 T$ v6 ]' e3 r#define INTR 0x1C
! o! P+ y1 p4 ?& S; d1 X! p/* Screen attribute (blue on grey) */ 9 m# J/ e: ^4 \+ X( P/ \# ?
#define ATTR 0x7900 </FONT></P>
$ j% C" f! K+ C% u< ><FONT color=#0000ff>/* reduce heaplength and stacklength
) H7 j; r# e1 E8 P5 L S3 Hto make a smaller program in memory */
- x' e# D6 k# X4 _4 mextern unsigned _heaplen = 1024;
; e# c: v0 M# ?extern unsigned _stklen = 512; </FONT></P>. `+ p! A2 A# `8 A
< ><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>& C3 Y7 Y+ T& t$ L+ a' s
< ><FONT color=#0000ff>void interrupt handler(void) % Z; i( ^; [7 e `# Z1 L# A
{
0 \, ?) G! i- E3 S5 M& F) Xunsigned int (far *screen)[80];
: H0 ~ Q% a# m2 qstatic int count; </FONT></P>% h! Q7 s/ S- c0 d9 c% I
< ><FONT color=#0000ff>/* For a color screen the video memory
% ~8 c' j- K2 ais at B800:0000. For a monochrome # R7 `1 P$ M1 j0 S5 {
system use B000:000 */
/ |& Y7 ^, U4 U4 L! gscreen = MK_FP(0xB800,0); </FONT></P>
0 B% [+ q- Q& K3 v/ h5 M< ><FONT color=#0000ff>/* increase the counter and keep it / z; E {% E. z D
within 0 to 9 */ # O/ U2 c3 S3 U ]6 h
count++;
1 _* F, T* d+ B4 r$ Hcount %= 10; </FONT></P>5 \& c0 t6 I) W5 q* z' U5 X
< ><FONT color=#0000ff>/* put the number on the screen */ 1 v0 D* }3 v% G
screen[0][79] = count + '0' + ATTR; </FONT></P>
4 b5 D0 h3 |# v< ><FONT color=#0000ff>/* call the old interrupt handler */ 1 v9 `6 K5 E4 K: x6 G, Q
oldhandler();
8 A1 w% e: b. M% X( R, {} </FONT></P>6 Z, D- b! L' z/ {
< ><FONT color=#0000ff>int main(void)
$ k5 `$ N+ u2 v{ </FONT></P>
1 _$ I; @& M3 [< ><FONT color=#0000ff>/* get the address of the current clock
& q, ?2 {3 w- Y" t7 X: y. \0 N# gtick interrupt */ $ ] }) ?7 g+ N9 B
oldhandler = getvect(INTR); </FONT></P>
0 J/ x' G' y) [3 v( d/ A< ><FONT color=#0000ff>/* install the new interrupt handler */ , u; o, a: |7 _+ x8 k
setvect(INTR, handler); </FONT></P># S& D7 e5 t+ C4 a5 L6 g* T
< ><FONT color=#0000ff>/* _psp is the starting address of the # @, m6 K3 Q% u0 g# L7 f
program in memory. The top of the stack
% a% x- k! r1 m8 E8 y5 R' uis the end of the program. Using _SS and
1 B3 G9 `% r7 ]5 d$ ]+ o_SP together we can get the end of the 3 x% Z0 t3 B) Z4 M& ]2 J7 G
stack. You may want to allow a bit of 9 S" _( C( @/ e
saftey space to insure that enough room 3 J& W( c9 H0 I: T: J6 ]
is being allocated ie:
% x5 S: ]* ^* Q+ c: I(_SS + ((_SP + safety space)/16) - _psp)
1 K( L. H0 Q" s+ n- h0 i*/
, z. X: b* N6 ~" {5 R- |keep(0, (_SS + (_SP/16) - _psp)); [7 @5 u2 H4 ^* Q+ V; z5 Y
return 0;
( |1 @$ u- i2 ]$ g* _, m( {; b}
/ @' J% J! p% d5 R& S# T</FONT></P>
. r3 ^8 _/ t! c
. p& ]0 Q8 i: { T' R: y" ]& j+ _ a5 b/ Q7 L9 x: s
< ><FONT color=#ff0000>函数名: kbhit </FONT>
, `# B2 E) F4 p7 p! O功 能: 检查当前按下的键 / M* x/ F3 H3 O" M" T+ M* N
用 法: int kbhit(void);
- k' G# v1 F6 Y" ^+ r0 s5 c: C程序例: </P>% K" w2 j" I1 T7 ~9 R" X
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>+ p: ?; x. |" f8 L
< ><FONT color=#0000ff>int main(void)
, |; d' O: Q1 c2 D) {{
9 C# u% w4 P$ q' I; z% Dcprintf(" ress any key to continue:"); " ~- f' P6 V! c) t% z9 L
while (!kbhit()) /* do nothing */ ; $ J' v' ?; h% k9 ^9 E
cprintf("\r\nA key was pressed...\r\n");
1 u3 R! H4 Q% m# M1 p- Q' @return 0;
) l9 p. S W' V1 J}
5 H. u" d" `1 t3 i- o% W7 K3 o1 {5 C- W5 D4 i
8 T. Y; Y0 ~9 J# w
</FONT></P>5 p# c: k- E8 R) I" A& `0 T
< ><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
3 t8 R4 k5 N* w: l, A" J# L<FONT color=#000000>功 能: 退出并继续驻留
2 \ L: I, Z) x/ q0 \8 Z y* l- D用 法: void keep(int status, int size);
+ ?$ a8 h8 M. _! Y7 F& j9 Q* B程序例: </FONT></FONT></P>" O O* H! U5 O, F! v( @ d2 k
< ><FONT color=#0000ff>/***NOTE:
4 d2 l/ N. y1 r, [3 Z# TThis is an interrupt service routine. You 0 }( s0 s% d4 q
can NOT compile this program with Test
9 [4 o f/ J; x2 W. }* R! jStack Overflow turned on and get an
w! Q/ T6 C+ |6 n. \executable file which will operate 0 r' \* m8 {9 e
correctly. Due to the nature of this - ~( o+ X2 m% g' i5 W4 O
function the formula used to compute
5 S8 c4 t' b# ithe number of paragraphs may not
, S* ?- Q: a* Snecessarily work in all cases. Use with
6 h6 Q% Q" z3 `care! Terminate Stay Resident (TSR)
4 _# `- M$ u' k- x4 D* {programs are complex and no other support # W7 Z3 c% l9 k1 t: S
for them is provided. Refer to the
* w4 m$ K3 z2 e4 ?; y7 c/ T- WMS-DOS technical documentation
9 A) k/ C8 R2 f6 _8 T& R; T) Afor more information. */
( i: A$ o% y. V* a1 E! x3 j1 k$ C. S#include <DOS.H># Q. R" l% M2 y- z/ ]
/* The clock tick interrupt */ ' H9 I" U& ]6 |
#define INTR 0x1C , L% b, t, `' w! B! o2 [6 H9 w
/* Screen attribute (blue on grey) */ ' c5 p5 b1 p) p4 F B
#define ATTR 0x7900 </FONT></P>
* p7 c! }/ [4 u< ><FONT color=#0000ff>/* reduce heaplength and stacklength
+ T% U J; m( n/ Pto make a smaller program in memory */
# A _. N# F( a+ _+ ?% A% R: t) Vextern unsigned _heaplen = 1024; ( a- u( _) S Q5 v
extern unsigned _stklen = 512; </FONT></P>' y% F/ Z2 r) J7 r* C9 M
< ><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>, d, B' [; s* F; d; G# L
< ><FONT color=#0000ff>void interrupt handler(void)
! E( A1 N1 e" n( k{ - ]# V/ Y; ?* W, u
unsigned int (far *screen)[80]; ) x# E" k' w: [9 U3 u4 s' l# o5 J
static int count; </FONT></P>/ ^5 |: Q5 F: j% K) R7 H) P
< ><FONT color=#0000ff>/* For a color screen the video memory * e8 G8 b# _2 o0 i( E
is at B800:0000. For a monochrome / g* q- O) I$ ?: [* t/ k2 a/ S7 h
system use B000:000 */
9 v7 W" e6 d/ j& S" K; }screen = MK_FP(0xB800,0); </FONT></P>
9 A/ k- D& ~3 d1 p+ h/ f' I< ><FONT color=#0000ff>/* increase the counter and keep it # V: z: e" i/ R* _1 v# f
within 0 to 9 */
' S I8 t: W) Q7 [count++;
# e) }8 @& {' ^count %= 10; </FONT></P>
7 d' c$ v; v/ i< ><FONT color=#0000ff>/* put the number on the screen */ - o5 M5 Q9 H& e4 P% l1 a
screen[0][79] = count + '0' + ATTR; </FONT></P>8 P0 i8 W+ R6 Y
<P><FONT color=#0000ff>/* call the old interrupt handler */
/ A& k; w$ m8 \9 `- joldhandler();
7 b1 _: U; U8 p6 Y: B$ Y} </FONT></P>+ u ]) h6 T* H( W" R
<P><FONT color=#0000ff>int main(void) 8 z# W4 L# W9 b0 }( u0 b8 q, P
{ </FONT></P>. O6 i4 F* z" B j6 k6 e( O
<P><FONT color=#0000ff>/* get the address of the current clock 3 q# q7 \% x7 C1 b+ q* e
tick interrupt */
$ u$ t8 ~1 E5 h# F( Holdhandler = getvect(INTR); </FONT></P>
! Z0 Q" Q: b1 j W, Q1 x<P><FONT color=#0000ff>/* install the new interrupt handler */ ! @; {; F9 [4 S: ^2 p
setvect(INTR, handler); </FONT></P>
7 x- V6 X' s4 t. ~1 B<P><FONT color=#0000ff>/* _psp is the starting address of the
/ a E$ f% W9 n) nprogram in memory. The top of the stack ' K3 x6 T7 g3 t0 k& V
is the end of the program. Using _SS and 1 o) D" e4 g7 Y2 M$ R& O
_SP together we can get the end of the
6 Z. \; g. y1 nstack. You may want to allow a bit of ! S2 b/ E9 n+ q6 ]# b" Z U5 J
saftey space to insure that enough room & c* J: |! f" ]! ?- G, z
is being allocated ie: / e( k0 Y4 `' n! k* g3 g
(_SS + ((_SP + safety space)/16) - _psp)
7 L# r; t g; }8 M*/ 0 \1 N0 _8 G' N5 }4 C
keep(0, (_SS + (_SP/16) - _psp)); ( _/ w$ H; Y$ M- K
return 0;
3 @" D, v4 g0 Q" l3 y}</FONT></P> |
zan
|