QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2242|回复: 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>0 G) S  f4 j9 |' x& z
</P># }, ~: F' r) {: j# h5 i: _
<><FONT color=#ff0000>函数名: kbhit </FONT>4 d7 U0 ^9 ~. k! ?
功 能: 检查当前按下的键 ' A$ x. m% x0 ]. t8 I) o5 f% Y; T
用 法: int kbhit(void);
  y/ w3 I" c7 p; q1 f& [! V/ t/ f程序例: </P>) `$ U% [9 d6 j1 ^
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>8 F: K: u2 z& C! |" ]7 n& H
<><FONT color=#0000ff>int main(void)
' D5 I6 b1 O8 N{
+ b7 h  g( X, ^# z2 j2 zcprintf("ress any key to continue:"); . T' \; w, b0 q
while (!kbhit()) /* do nothing */ ; ' z: k1 \" ?& M" D" h6 T: s
cprintf("\r\nA key was pressed...\r\n");
1 Y5 h4 ?- ]+ ^# i: ~return 0; 3 n# _: A, x7 M) A" p: Q) f3 c
} </FONT>6 l7 M" \* g$ Q( y3 d
</P>
- O" e9 ]/ s- h<><FONT color=#ff0000>函数名: keep </FONT>! l6 ]' Q' g8 ?  h& G2 V  Y$ e
功 能: 退出并继续驻留
! T! L& T( A- o4 C. ]6 Y6 X用 法: void keep(int status, int size); : S( m  n% Z+ B& e5 G; L
程序例: </P>0 C! m# B) p( z- ^
<><FONT color=#0000ff>/***NOTE:
. T+ g/ X+ Z' c: P  o5 V. t1 nThis is an interrupt service routine. You
2 u$ {& S* j. ^6 }can NOT compile this program with Test
: j6 ?4 p! a7 K4 w! E' EStack Overflow turned on and get an
# _5 M6 |0 g; j8 I5 }1 ~executable file which will operate 1 s+ Q3 z# j4 p& f. P: W; S- C
correctly. Due to the nature of this
. T6 k% _2 i% Q2 L! Y3 f# gfunction the formula used to compute
, \0 m( {* t% T6 S8 c; |" Vthe number of paragraphs may not
, V& o# @$ O1 p0 p/ ?4 Lnecessarily work in all cases. Use with 5 v, z" C$ v" y  G
care! Terminate Stay Resident (TSR)
, i- J" Z1 T: f) O# I- Wprograms are complex and no other support
, p5 S" g+ I" V2 R8 [4 Afor them is provided. Refer to the " j0 l& W4 M) g
MS-DOS technical documentation
) E, m& p3 l( A8 v4 \for more information. */ ! U+ b2 K# U8 x) R; y
#include <DOS.H>
: s$ K" g. v2 d/ f. ^. A  M/* The clock tick interrupt */
8 B5 e  B. s: T/ _#define INTR 0x1C
& U9 Y+ M- l! I/* Screen attribute (blue on grey) */
9 I4 T5 r: H/ j" i  e0 u- S7 G#define ATTR 0x7900 </FONT></P>
2 ]$ A. N+ m, A8 Z: q" N* P<><FONT color=#0000ff>/* reduce heaplength and stacklength
/ X+ }  @) Z$ v6 w; _% Fto make a smaller program in memory */
$ ^/ W( Y5 }" _; Dextern unsigned _heaplen = 1024;
6 j% J' {, B& h8 ~8 H/ M1 W' ^extern unsigned _stklen = 512; </FONT></P>5 Y8 G% b, _, j& G/ a
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
0 o  H) i( @3 _1 ^<><FONT color=#0000ff>void interrupt handler(void)
  d& L- J9 u" s* K- ~# c, P/ K{ ! O. Q5 m4 L' G& I3 K$ p; R9 |8 W
unsigned int (far *screen)[80];
- U2 \$ e$ J' P; i) x, fstatic int count; </FONT></P>$ W! q4 r  `. F  O: y5 F* k! V
<><FONT color=#0000ff>/* For a color screen the video memory " Z. Z5 N1 \+ }* A
is at B800:0000. For a monochrome
- M( F( @+ D0 I% x' _, a7 \* B. Msystem use B000:000 */
1 ^9 @* t5 e4 B% e6 u& iscreen = MK_FP(0xB800,0); </FONT></P>
2 |1 V% h/ ^% a' O<><FONT color=#0000ff>/* increase the counter and keep it
! P9 d% x. z. E' Ewithin 0 to 9 */
+ o) w$ F, }* x5 T) v$ Pcount++; 1 q/ c1 f  D' k" J4 t
count %= 10; </FONT></P>: }$ R$ D: r# |3 X
<><FONT color=#0000ff>/* put the number on the screen */
% [* k+ T1 L! A) I# l& r% dscreen[0][79] = count + '0' + ATTR; </FONT></P>+ Q4 F8 U/ e# P; `5 S
<><FONT color=#0000ff>/* call the old interrupt handler */
1 n3 Y2 Z0 u) F* @9 Woldhandler(); & P( y' q3 X: ?' D2 z
} </FONT></P>
3 T) U. u" V) u3 F<><FONT color=#0000ff>int main(void)
" H( l# _/ s, z- U% F( |{ </FONT></P>. V. P" ]1 j, t
<><FONT color=#0000ff>/* get the address of the current clock 9 j2 |; p5 E/ s; |0 i& x' i
tick interrupt */ . z: q% G: ]( ^( H# J
oldhandler = getvect(INTR); </FONT></P>
6 n7 J( c" |9 G# V2 ^<><FONT color=#0000ff>/* install the new interrupt handler */ ( ^5 M- n5 I/ a6 x7 j
setvect(INTR, handler); </FONT></P>+ Z) ?* c$ D" Y4 {( d
<><FONT color=#0000ff>/* _psp is the starting address of the
2 h+ v) t6 r' m2 y3 x0 y6 Bprogram in memory. The top of the stack
0 s4 {7 l# z& h$ Ais the end of the program. Using _SS and
. n, ?; T: K7 t; F# R& S0 `_SP together we can get the end of the
& A4 L1 h7 y# Q8 z3 q3 B# astack. You may want to allow a bit of
: H! e3 L, u3 p1 r3 y" L  {saftey space to insure that enough room
3 N5 i* @0 Y) p, |- sis being allocated ie: 9 R: U& I% b4 C% E1 a
(_SS + ((_SP + safety space)/16) - _psp) $ I$ m& j/ L7 ]5 O
*/ & F# z$ c8 U0 q$ I0 n: X
keep(0, (_SS + (_SP/16) - _psp));
$ ~, R6 q0 y. w) t7 @return 0;
* t3 _! \% K3 G! ?5 s}
6 L; X1 {9 I5 p9 P1 X4 T! E5 F: O( ^3 J</FONT></P>
; o( D* _) K% N" x# y2 m- M5 m/ C0 Q! W5 o3 R3 @4 \0 K6 i0 B6 m
' f- _' H& _+ Z. F9 y* K
<><FONT color=#ff0000>函数名: kbhit </FONT>
0 q7 @6 p7 v0 h" J" O功 能: 检查当前按下的键
8 ^) z! F: s& {+ B/ p& v# `$ w用 法: int kbhit(void);
$ {- P) h0 [  J. K程序例: </P>: y! |( l6 F1 B, m) Y' G: x- ]
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
4 ?' t- N8 C6 I4 v$ j; y<><FONT color=#0000ff>int main(void)
+ d+ K' N/ F. o+ i; X{
7 {6 {" i+ t+ q/ ?+ p6 t2 g6 m6 ^+ mcprintf("ress any key to continue:"); 9 @2 _; ~- j$ c
while (!kbhit()) /* do nothing */ ;
  Q' [8 v& ]5 l* h- \) r# pcprintf("\r\nA key was pressed...\r\n");
. c# `9 n& C8 {1 j7 M$ y& Y, Wreturn 0;
- ?5 |# L# |: N$ S+ H. I: s} * s+ R9 C1 T+ t* l- ^  V
3 h; y  i) X0 q1 n' v  V

1 z9 [* z8 D: q2 |</FONT></P>" w9 H9 q" Y3 n
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
$ A  I! U3 h6 i* C% E" ]4 U8 E4 U<FONT color=#000000>功 能: 退出并继续驻留 ( [; F7 v2 n, J
用 法: void keep(int status, int size); 3 H7 b2 _1 q! ~8 h# m" H  o/ Q9 Q
程序例: </FONT></FONT></P>
" `; {9 |- Q$ P6 P9 Q<><FONT color=#0000ff>/***NOTE:   p& G) N; r( [- C( C7 ?1 a
This is an interrupt service routine. You
2 x8 J" C3 N! ~$ G+ c9 [9 Z, G5 jcan NOT compile this program with Test ) J( H  u( V6 Z+ A  i9 U
Stack Overflow turned on and get an
" Y9 c! k. X! a; L; C" Xexecutable file which will operate
' F, o: k3 I" n  |- icorrectly. Due to the nature of this / r' |- G$ g; d. T, v
function the formula used to compute
0 u6 g+ H0 U5 g2 f1 z- D% W7 othe number of paragraphs may not ! H8 |8 F3 Z. i* |
necessarily work in all cases. Use with
1 p) ^+ G+ c5 l5 rcare! Terminate Stay Resident (TSR) % n2 [9 q# g5 ~- c& h0 {
programs are complex and no other support
4 C$ s) o* O$ @for them is provided. Refer to the
1 s4 Q5 J) x# o; X0 W- Z+ a) _MS-DOS technical documentation
( F; \+ [1 Y# x# t" w4 Sfor more information. */
- y2 s: E: Q- P#include <DOS.H>7 c1 R: y: i, x9 l
/* The clock tick interrupt */ . S% W1 K* B4 ~0 W- }" U- o
#define INTR 0x1C
" t; H' y7 x# g4 T. i) p/* Screen attribute (blue on grey) */ ; `# ~$ R% p" Z6 Z
#define ATTR 0x7900 </FONT></P>) y7 ~3 G4 x( t! ?6 L
<><FONT color=#0000ff>/* reduce heaplength and stacklength / f3 m2 H1 K$ [( o+ E' u% _6 o
to make a smaller program in memory */
* d3 A' v9 z; Q: R' W# H/ W% _extern unsigned _heaplen = 1024;
% j6 |+ G, V% S4 |4 aextern unsigned _stklen = 512; </FONT></P>
, {/ D5 L9 `7 O# {' U# t1 x) s/ O" q<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
; \+ e+ }% c$ g4 u( |  @) p<><FONT color=#0000ff>void interrupt handler(void)
" c8 z' L6 d/ j) D) P; f, |$ w! {3 }{
: F6 U% B; \3 ~6 a0 z" Z+ Iunsigned int (far *screen)[80];
) Z+ b! I: L# k, Ustatic int count; </FONT></P>
& Z- X& [8 q' L& ?1 |<><FONT color=#0000ff>/* For a color screen the video memory 8 b/ n/ E* r/ y; l
is at B800:0000. For a monochrome 0 T$ Q5 r2 r$ q" L& B
system use B000:000 */ 6 P9 C* z9 X# `( v& V
screen = MK_FP(0xB800,0); </FONT></P>
9 `8 q- Y/ w) u) ^* {  E/ t/ c<><FONT color=#0000ff>/* increase the counter and keep it
7 @. D/ w, K7 m5 T/ A8 Vwithin 0 to 9 */
$ F7 v& q' H7 U8 _6 r- g3 ucount++; $ v  D- }, m3 C, h+ |8 D7 i
count %= 10; </FONT></P>  {, }# d1 Q  G
<><FONT color=#0000ff>/* put the number on the screen */
( X  q, }; t# e, L( Y' V% p- kscreen[0][79] = count + '0' + ATTR; </FONT></P>5 |& ]* c6 M! r) y' k  H
<P><FONT color=#0000ff>/* call the old interrupt handler */ ; E! H' v5 R4 X+ F
oldhandler();
; n- P) L! @5 h: N} </FONT></P>3 W& g! C$ I2 E* v& u6 E" b( M8 e
<P><FONT color=#0000ff>int main(void) 9 h% B# g( f4 h- l  x, f
{ </FONT></P>
" d0 E: |) d4 W3 r<P><FONT color=#0000ff>/* get the address of the current clock 0 P: z4 ]4 R* [% {0 p* A
tick interrupt */ 5 |! ?& X( _9 Z. g
oldhandler = getvect(INTR); </FONT></P>4 S* F' I. Q7 h$ a9 ?+ O- f
<P><FONT color=#0000ff>/* install the new interrupt handler */
9 {" y8 w2 f, i, U: H) Isetvect(INTR, handler); </FONT></P>4 `% e. i: ~/ r- s; Y. Q& `5 N1 v9 c
<P><FONT color=#0000ff>/* _psp is the starting address of the 9 b- X9 {' I; S6 c
program in memory. The top of the stack 7 p) c. g. I3 A& R6 W. t
is the end of the program. Using _SS and
( @3 ]; |- s& |  Z0 f% Y_SP together we can get the end of the 8 e. q. C, j6 i( Y) p: S
stack. You may want to allow a bit of 9 P. w6 y5 w7 F" x/ a
saftey space to insure that enough room
% @+ b' |$ e% j4 `is being allocated ie: 7 ^* ?! a2 t( |  T+ G& s1 e
(_SS + ((_SP + safety space)/16) - _psp) ) K4 H  y' b9 o/ b* Q
*/ ! w' l7 I  R$ B2 }  w7 e0 h# S
keep(0, (_SS + (_SP/16) - _psp));
% \' j& ^+ z  S  K# G0 Oreturn 0;
$ A1 f7 X8 ]- z" b; u}</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-4-21 04:56 , Processed in 0.577062 second(s), 52 queries .

回顶部