QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2343|回复: 0
打印 上一主题 下一主题

函数大全(k开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:58 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(k开头)</FONT></B></FONT>
7 ]+ V' I6 ?, R9 s* ~: [' W; i+ V' |</P>2 q/ p( _  C4 X2 o
<><FONT color=#ff0000>函数名: kbhit </FONT>) l" G+ O! C* b3 h8 Z3 S" o$ I
功 能: 检查当前按下的键 ; D" {2 z  t& d
用 法: int kbhit(void); / ?+ X0 a- U1 M, }% [4 V) E
程序例: </P>
7 Z* Z& P+ U( P* p: N7 P<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 Z5 W2 ]" W6 n5 |1 A5 v' i7 z
<><FONT color=#0000ff>int main(void)
6 g: R2 Y! o9 {7 }6 S' D# I* y- O0 {{
% k- B- t' l, ?0 n2 w, x1 K$ L6 Ecprintf("ress any key to continue:");
  h& I! g  d8 M! u9 Ywhile (!kbhit()) /* do nothing */ ;
& `! h% M' o: S( Q3 z- ucprintf("\r\nA key was pressed...\r\n");
. k" X$ V- \0 j3 Nreturn 0;   [( c' k" p8 U1 N3 D
} </FONT>* d5 F* ?. v  P( K. `- A
</P>
. I* C( |( p" |/ r; k# n6 q<><FONT color=#ff0000>函数名: keep </FONT>
; G2 Y0 e& [5 ]( m功 能: 退出并继续驻留
: q2 O* \' V; }/ I/ h用 法: void keep(int status, int size); 8 V! X8 r; ?. l
程序例: </P>4 l) S/ P, C6 u0 Z
<><FONT color=#0000ff>/***NOTE:
6 K1 ?3 y9 Z7 B$ M* J9 [* sThis is an interrupt service routine. You ' y5 r* K( t9 R% w, z* X: g+ j
can NOT compile this program with Test
& k! P. ]" F% `9 NStack Overflow turned on and get an ! u) ]) ~7 K/ v6 \6 ]6 c' d9 W
executable file which will operate
$ ?2 v7 h: q; o3 b; P5 @! ?* O5 jcorrectly. Due to the nature of this
# g' p3 D3 w$ [1 a1 J* M% kfunction the formula used to compute $ P, ?4 `3 O: t
the number of paragraphs may not
4 e2 ?# P3 \5 l9 G! ]/ Cnecessarily work in all cases. Use with
& k/ q# ?! J- F, b, i  Qcare! Terminate Stay Resident (TSR)
3 Y3 J) D7 z& v. U1 Yprograms are complex and no other support 5 i/ A" r( l0 u" Y/ t9 z. e$ M/ D
for them is provided. Refer to the $ e$ M, Y- j7 t$ f/ l# C5 h. C5 {
MS-DOS technical documentation
2 S/ l6 V0 w& O' qfor more information. */ + v; y. H. Q# o5 G' q( Y
#include <DOS.H>
6 ?: F- ~' E3 {! Q) y/* The clock tick interrupt */
$ ^7 w' h! D( j& x( c2 K#define INTR 0x1C 1 R/ g  i! @  t) y
/* Screen attribute (blue on grey) */
6 x6 h5 A8 ?1 f% p+ {- o#define ATTR 0x7900 </FONT></P>: ^3 k- L1 s. _- O' l
<><FONT color=#0000ff>/* reduce heaplength and stacklength
8 r( v7 }  L- q- R5 s5 qto make a smaller program in memory */
. U" O9 V( u4 o9 K* |extern unsigned _heaplen = 1024;
4 P7 f! U8 P, {* A4 Gextern unsigned _stklen = 512; </FONT></P>
; x$ `6 s; r, G+ |2 p2 t/ H( t<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>! ]6 G6 s9 t. u" U# E8 A+ K
<><FONT color=#0000ff>void interrupt handler(void) ; k5 O6 x# M& M1 D$ m" L7 v4 X* j/ @
{ 0 b3 @5 q+ X/ @$ d3 f9 `
unsigned int (far *screen)[80]; ' g: ]0 ^3 Q$ I" c. Y
static int count; </FONT></P>
3 e% p7 d9 o7 n% C: k<><FONT color=#0000ff>/* For a color screen the video memory
$ S; R* i0 y5 r" A3 o4 T, l3 Yis at B800:0000. For a monochrome
4 m7 x* `8 n: e% Q  R  asystem use B000:000 */ 8 ^8 h. f/ a' Q! |+ {) H) V7 b: r
screen = MK_FP(0xB800,0); </FONT></P>2 X' f4 m. W- `/ W
<><FONT color=#0000ff>/* increase the counter and keep it
1 i5 Y' f8 I2 V& Owithin 0 to 9 */
% Z4 @" k( P5 l2 w, V* Mcount++;
* B) I1 ?: b: M( K& n: t' B3 d# b1 lcount %= 10; </FONT></P>
6 Z- \3 f- V8 y$ E<><FONT color=#0000ff>/* put the number on the screen */ " @, {' ^# r5 D+ l4 [
screen[0][79] = count + '0' + ATTR; </FONT></P>6 _) Y' F# z; I0 S' r( I  F; w
<><FONT color=#0000ff>/* call the old interrupt handler */
/ @3 ~7 w% s. K, |oldhandler(); ; B3 ]( T) L8 X' l4 |
} </FONT></P>' l" a; f8 ^: _' `- ^( N
<><FONT color=#0000ff>int main(void)
0 C( U: V9 U& t3 O{ </FONT></P>
- D; @7 ^* B* p0 o4 o9 H<><FONT color=#0000ff>/* get the address of the current clock
6 G9 v" }4 P& dtick interrupt */   `8 ?, B  t8 P0 M2 [# P
oldhandler = getvect(INTR); </FONT></P>
4 Q+ z  F2 K4 l2 G8 i# F9 U4 `<><FONT color=#0000ff>/* install the new interrupt handler */ ! z0 }1 n2 c2 ]) A
setvect(INTR, handler); </FONT></P>; i2 E6 L# [$ b
<><FONT color=#0000ff>/* _psp is the starting address of the 2 w1 O" Z- e2 R# N8 k
program in memory. The top of the stack ; L; h2 n1 O. j% D
is the end of the program. Using _SS and 0 T! H) ]. J0 z8 }
_SP together we can get the end of the 4 {9 M9 y- g1 W$ |
stack. You may want to allow a bit of
5 R* b# Q; I6 O: Q' {+ vsaftey space to insure that enough room
% ^8 y$ `0 P, n. t, z) iis being allocated ie: + |3 r# L/ r4 ?' m$ [& q
(_SS + ((_SP + safety space)/16) - _psp)
) d' p, k+ z4 k  m2 k# r' E) o5 Q*/ ( J: h0 _- V" Y; K# j
keep(0, (_SS + (_SP/16) - _psp)); 6 [! j7 \% o' z: k% @
return 0; ; j& s  W5 c( M; t( K1 B& z
}
; j) C; _( W. i5 E! h- H</FONT></P>1 j- s) A9 c! `7 |1 i9 g

  g! b! ~4 g( A0 g8 x9 [9 m! H1 H% f) ?- I
<><FONT color=#ff0000>函数名: kbhit </FONT>
* |) h3 X% E! J1 J5 _功 能: 检查当前按下的键 + m/ X! k' B  j
用 法: int kbhit(void); # _# T) h* k8 f# T5 j8 ~. h) F' u
程序例: </P>1 b9 V: N# g/ F) `6 R
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>* V& u$ Y% Y- _! A
<><FONT color=#0000ff>int main(void) 1 a( n$ Z' w7 g4 y7 O6 R
{ ' I8 ~  [& Q# n1 n) b% T
cprintf("ress any key to continue:");
; c. E, V) f" q1 B+ i" _- Y; Bwhile (!kbhit()) /* do nothing */ ; ' T$ y: B, v. S2 F
cprintf("\r\nA key was pressed...\r\n"); 4 W+ S: f- f2 `0 g
return 0; 1 V' ^6 \/ g# ^* m/ J6 K7 h+ }
}
* f) K. o$ p+ i& y% J, I0 ~; [1 a
# V: g+ F9 z8 @7 N7 P+ X  H0 A  \# e4 e( i1 T
</FONT></P>, `( O, u- {+ ^, Q
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>! R6 |" U' _+ h8 {6 W- g3 V
<FONT color=#000000>功 能: 退出并继续驻留
% w) s" u' v: y9 O. I用 法: void keep(int status, int size); & a- Z0 U$ J) E1 W1 ~) k1 H8 n
程序例: </FONT></FONT></P>
+ x+ B! _+ t, {. w<><FONT color=#0000ff>/***NOTE:
  `3 T9 C: D2 g! R2 s, HThis is an interrupt service routine. You
  h  Y& ?' m: W4 j! `9 k# \can NOT compile this program with Test
" a0 b7 L+ v  {$ e+ K* J, `3 MStack Overflow turned on and get an
; P, O9 U% e$ k4 N) {executable file which will operate * B' O! Y" I7 z) {: p' C  O  D
correctly. Due to the nature of this
. I+ d# M5 L- I5 F% r* Rfunction the formula used to compute 1 t% P2 E; ^5 ^9 ]0 t: G  a' N
the number of paragraphs may not
8 \  p! J/ P7 ?! i  Mnecessarily work in all cases. Use with
2 X# t* N- Z3 B3 h' y$ O  }. xcare! Terminate Stay Resident (TSR)
, u& c" h& d  y( s' A: J" p) X3 [programs are complex and no other support ; Q. w7 R! p2 f; |" q" _) F2 V
for them is provided. Refer to the   |7 G! q6 x9 p0 C8 ~, R: f
MS-DOS technical documentation 8 }! O- g0 p" a+ u4 D
for more information. */
: n5 s7 x; q; _9 s: j; ^#include <DOS.H>. N$ [* _" S3 U+ ?6 ?
/* The clock tick interrupt */
- I- u; }4 u% ~0 |9 S  Z* o' V#define INTR 0x1C - c% U2 J9 g6 ~* D
/* Screen attribute (blue on grey) */
6 m* d0 |, s; B; H: s#define ATTR 0x7900 </FONT></P>/ i+ S- x$ ^7 l4 |
<><FONT color=#0000ff>/* reduce heaplength and stacklength
6 i% o, y$ m8 F: o$ _to make a smaller program in memory */ 2 ^6 ?% P' ]% p( _# j% u) [; f
extern unsigned _heaplen = 1024; % r: a1 l7 T& e3 [1 K. K
extern unsigned _stklen = 512; </FONT></P>
- j3 T( N- H+ ]' Z' t<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
$ x; Z. `- E8 \<><FONT color=#0000ff>void interrupt handler(void) ' F6 ~( R6 q& x5 \9 b
{ 2 Q9 r! O. x& h2 v3 \
unsigned int (far *screen)[80];
- E# a% d4 U7 }static int count; </FONT></P>8 F8 T5 t: e) t
<><FONT color=#0000ff>/* For a color screen the video memory 4 c# K/ u2 y- ]! i
is at B800:0000. For a monochrome " i5 O( X( [0 f1 d
system use B000:000 */
7 D% W5 B% ]% }screen = MK_FP(0xB800,0); </FONT></P>  T) `' ?# x0 \- C3 D& n& `$ T
<><FONT color=#0000ff>/* increase the counter and keep it
0 W% M) Q8 p- E) I, }within 0 to 9 */
/ g1 k7 m8 U3 q% J/ G3 s5 b5 s- ?count++;
0 |& P  f# v5 \( Q; Vcount %= 10; </FONT></P>1 p3 ?" O' l, i% @
<><FONT color=#0000ff>/* put the number on the screen */
' l# J: }! N& H+ Q1 w$ zscreen[0][79] = count + '0' + ATTR; </FONT></P>6 z7 t7 ~6 r' m) Z
<P><FONT color=#0000ff>/* call the old interrupt handler */ 7 R) i% p3 K8 a9 ?" o$ L" J5 r$ ^
oldhandler();
$ q3 ?; v2 }; I5 ?% Z} </FONT></P>2 I, z/ E9 ^% }: U' t. B$ b
<P><FONT color=#0000ff>int main(void)
2 n. I$ U4 n# {0 ?{ </FONT></P>
% |' n; m( M! b5 w; Y2 }<P><FONT color=#0000ff>/* get the address of the current clock ) u+ l+ `0 C) o9 ]+ \8 T
tick interrupt */
6 t  v3 S& r8 Poldhandler = getvect(INTR); </FONT></P>
. I( M6 j* w0 H, }5 l. }' v<P><FONT color=#0000ff>/* install the new interrupt handler */
3 s4 d" }# W: U6 @setvect(INTR, handler); </FONT></P>$ n/ `- K' w) \* k4 N
<P><FONT color=#0000ff>/* _psp is the starting address of the   c. C5 H4 b+ b  j) K& X0 l' s
program in memory. The top of the stack
7 n! @/ b1 |1 C$ [; t* n" b: [# Q0 z+ xis the end of the program. Using _SS and + }6 r( b" ^0 _5 z, i$ s  Z
_SP together we can get the end of the ' {" H: S' }" g( \5 O  Y
stack. You may want to allow a bit of
. {, c6 `' g/ G5 ^saftey space to insure that enough room
- o4 _2 [; l4 Q& h* `; I2 mis being allocated ie:
! v$ c+ \% h2 L8 W' o(_SS + ((_SP + safety space)/16) - _psp)
; M8 C& n" C) m6 v8 a+ i( k; L*/
  D$ l4 _# [1 S5 s0 o2 Kkeep(0, (_SS + (_SP/16) - _psp)); + C6 V* q% R3 n- g" A' Z# D0 f1 w7 y
return 0; 6 ^' X1 r8 k& k+ W
}</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-10-25 09:19 , Processed in 0.529323 second(s), 51 queries .

回顶部