QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2261|回复: 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>2 ^1 v1 S2 q2 `0 ]
</P>
( h% x+ @- W& f6 C1 N<><FONT color=#ff0000>函数名: kbhit </FONT>
& B. y* \; c: x# I0 o功 能: 检查当前按下的键
9 v; \3 a/ U1 }% d用 法: int kbhit(void); % D* X& c) J$ e% e9 e0 Z6 H5 C
程序例: </P>
. X6 K/ A' s* y* M; S<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
- j% g% R0 T' b& V1 h<><FONT color=#0000ff>int main(void) # f! K, O# q0 ]* ~7 D
{ . }% o6 I) e3 U6 W) m0 e- W
cprintf("ress any key to continue:");
) ~- u( J+ W" ]7 j* D1 ]while (!kbhit()) /* do nothing */ ;
$ K6 v. c, b* y+ w1 Gcprintf("\r\nA key was pressed...\r\n");
5 w! y5 W: [3 ~" T1 g8 l  V  Jreturn 0;   x3 f$ y4 Q( i* s
} </FONT>
3 Z( W; W% y' q% S% c& T: W</P>! i9 C- b6 e% u
<><FONT color=#ff0000>函数名: keep </FONT>
4 `, Q" @: \' C, U5 c5 v1 _功 能: 退出并继续驻留 & f' e" ^: z, {7 ^' A
用 法: void keep(int status, int size);
8 l* m' m5 T+ d9 k程序例: </P>1 u! ?0 G( A% a; s/ w
<><FONT color=#0000ff>/***NOTE: / r2 K0 }9 x3 e* R- q* v2 E
This is an interrupt service routine. You ; z3 A) I& F( D; |+ `" ?
can NOT compile this program with Test
- J* }0 }, C( |. rStack Overflow turned on and get an " ]$ y9 d4 ^7 u4 f1 D+ E7 b
executable file which will operate
; J1 }: _4 }0 O. i( B! kcorrectly. Due to the nature of this
! i9 s+ [! C2 f8 y2 o. J/ ^0 _) d" rfunction the formula used to compute
8 o8 y" t2 y7 R6 z. ^6 Othe number of paragraphs may not ( p; |0 P- Z9 p9 n; e9 x) W6 ^
necessarily work in all cases. Use with 6 E* ^( K* k- ^0 m+ G
care! Terminate Stay Resident (TSR) + J  G( y3 I" X8 e- h
programs are complex and no other support
6 C0 M* h  S7 q- w, ufor them is provided. Refer to the 5 ^' ]5 N! Q7 Q# q
MS-DOS technical documentation & U* T6 R, \! r) c8 ]# F8 ]
for more information. */
9 V9 m) @+ g; U9 |) x6 _#include <DOS.H>
+ c( I% B; S; ~! {/* The clock tick interrupt */
" ~* M* R; O# V: v( o& A3 T! ^  O#define INTR 0x1C
  h5 a0 C# Q: P% z9 J/* Screen attribute (blue on grey) */
8 D9 B0 K$ e/ G- t#define ATTR 0x7900 </FONT></P>" a6 p- J7 r$ k
<><FONT color=#0000ff>/* reduce heaplength and stacklength 4 b& `' x" q1 X  r2 s. f
to make a smaller program in memory */
1 U( P2 _0 J9 F  x  ^8 l2 }extern unsigned _heaplen = 1024; * [. Y6 K( I) L0 j
extern unsigned _stklen = 512; </FONT></P>
$ d; u# s9 h2 q<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>, _+ ?' d, v# Y1 g. q
<><FONT color=#0000ff>void interrupt handler(void)
! t. X7 k% y) `) e+ ^2 z{ + B5 m4 o# v* ]" w: E& T, b
unsigned int (far *screen)[80];
2 M$ \' U5 F9 t& ^7 [% ~- a2 Lstatic int count; </FONT></P>
2 y+ y9 l' Z7 V' B. e) O. }<><FONT color=#0000ff>/* For a color screen the video memory $ |; @$ e  q7 U1 D( ]8 {/ B% z
is at B800:0000. For a monochrome ) B( Z( }) m% m$ ~8 A# w
system use B000:000 */ 3 I9 _  w6 F. B9 H
screen = MK_FP(0xB800,0); </FONT></P>
! y6 [4 L4 u- \, w( j<><FONT color=#0000ff>/* increase the counter and keep it 7 X) G' K( ~" d; d7 d& F
within 0 to 9 */ / e7 ?+ M5 A% H2 O" B0 V+ K
count++;
9 Z6 u- q2 ]+ icount %= 10; </FONT></P>
# N( W" l( q6 e+ m4 r<><FONT color=#0000ff>/* put the number on the screen */ 4 ~$ K4 L. H4 f
screen[0][79] = count + '0' + ATTR; </FONT></P>$ N5 y- }' S& C4 m: K
<><FONT color=#0000ff>/* call the old interrupt handler */ ( o' U+ O+ {4 X- G
oldhandler(); , E, `# Y/ C! m6 q" H$ x9 S, u
} </FONT></P>3 d% `% U! f: f9 @
<><FONT color=#0000ff>int main(void)
+ e# M  ]9 l& ^4 _{ </FONT></P>/ x  e1 u/ s; l3 p$ o# n) _. _
<><FONT color=#0000ff>/* get the address of the current clock
' M; Q; D4 f/ S( S, t3 u9 K$ P1 ytick interrupt */ + k9 Z9 X2 q1 t+ }' B& A7 d+ d- b
oldhandler = getvect(INTR); </FONT></P>
# n* f5 }2 }4 u<><FONT color=#0000ff>/* install the new interrupt handler */
$ S. K! M0 y' F$ Osetvect(INTR, handler); </FONT></P># s9 G" r& L4 E& ~% U7 i
<><FONT color=#0000ff>/* _psp is the starting address of the
7 U, J9 R* S* s* }5 G5 Pprogram in memory. The top of the stack
; P/ W$ y6 Z7 u. L9 `, xis the end of the program. Using _SS and
: J8 A  r0 U" Z% C( _5 j* i_SP together we can get the end of the & W' p9 Z5 \& F; o: I
stack. You may want to allow a bit of / }  n. m+ A+ f, {- Z. p& Z+ p0 V
saftey space to insure that enough room 2 l- a" }" c7 }
is being allocated ie: ; a8 l) J2 p$ C+ n. s/ W
(_SS + ((_SP + safety space)/16) - _psp) ' }9 l: L1 R( s/ U+ N' g; q- \7 i8 {
*/ ( }+ n' s3 H8 z- _
keep(0, (_SS + (_SP/16) - _psp)); ' d+ n/ P" D' E0 B& \: w- J) U& M9 v; R
return 0;
  T5 B8 T3 m9 i  I+ u$ [}
6 {5 Q7 n: u9 g& o8 ~' H</FONT></P>
" l/ c; D0 z" o0 u# o/ C+ v+ {6 W9 Z$ L% N0 k4 G1 Y. q4 \4 l; z

. ^( O4 T) K! d! J<><FONT color=#ff0000>函数名: kbhit </FONT>  I6 e2 b. u) j0 V- y
功 能: 检查当前按下的键   l' \# a# N# n$ @
用 法: int kbhit(void);
: T2 ^  `/ N, c程序例: </P>/ H3 M1 B0 H; P
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
# q: f/ r/ X  C- s. D<><FONT color=#0000ff>int main(void) ( c7 @$ F+ q, P) E4 a$ \
{ : e7 q% ^+ P, ^
cprintf("ress any key to continue:"); $ A$ k) n( q9 P, l. a# f
while (!kbhit()) /* do nothing */ ; ( I5 o  f" j5 S* V/ ~+ Y- g2 V
cprintf("\r\nA key was pressed...\r\n");
; Q8 P# z, O) Q! j+ Oreturn 0; ) e- ^$ ?* _9 h/ L, W5 K! v" r  j
}
5 |5 W# r7 H) l; P5 p
9 m+ n, G* W% C$ |1 ], @  N2 I' Z6 D# }" i! F2 ]/ z
</FONT></P>
1 k$ s) G4 J  Z" o7 k0 Z<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
7 w: b& g0 g5 c. f<FONT color=#000000>功 能: 退出并继续驻留
5 ~8 \8 {/ K$ {2 d" i用 法: void keep(int status, int size); - X5 P3 X' @5 ~6 \3 s; r
程序例: </FONT></FONT></P>; B1 D1 D% H# D. ]! ?* o
<><FONT color=#0000ff>/***NOTE: 1 s7 Z1 ?6 q7 L7 H$ B0 M
This is an interrupt service routine. You
% k$ s4 D* a3 scan NOT compile this program with Test * j% x! k/ K1 @: C
Stack Overflow turned on and get an 5 l: x3 g5 U; I' e/ L9 @) H; A' u# Z0 C! i
executable file which will operate & t9 i2 X: ~. G2 X6 a1 w" E
correctly. Due to the nature of this 1 ~& d" o+ N9 m# @3 g3 e/ T8 D
function the formula used to compute 5 M. a: A' [* _6 R( X
the number of paragraphs may not . `+ I& ?% M& n
necessarily work in all cases. Use with
3 T# b2 N- ]. o0 x2 A  g  _0 ]( t$ _care! Terminate Stay Resident (TSR)
  U$ |4 ^- z2 Oprograms are complex and no other support 1 `0 V! ^5 f' N( {
for them is provided. Refer to the
: L) M2 v. {: t7 @% y; `MS-DOS technical documentation
  d. I3 }- h* B' f% B9 [+ O# Bfor more information. */ 7 G+ H  `1 ~* G- P
#include <DOS.H>' Y- l+ E% S2 z
/* The clock tick interrupt */
: \, x- H$ J' o, Q6 j#define INTR 0x1C : {2 j. _0 g9 A7 T) u/ [
/* Screen attribute (blue on grey) */ ( Q1 B. ?& K! {4 Q' r
#define ATTR 0x7900 </FONT></P>9 Q- N% a9 G. P* }. x( d. ~
<><FONT color=#0000ff>/* reduce heaplength and stacklength # }( I$ `: \) a3 n% |( _: g
to make a smaller program in memory */
! D) ]8 ^- U$ R; R, Sextern unsigned _heaplen = 1024; / L* V5 I0 _9 u7 L9 m2 s
extern unsigned _stklen = 512; </FONT></P>
$ _5 H- @8 }; b" I: B<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
( a, h, x) L4 D2 v: m9 m<><FONT color=#0000ff>void interrupt handler(void) 0 Y. f  M! h5 T2 G
{ 3 H/ _- F5 C6 o6 V
unsigned int (far *screen)[80];
4 |4 E; {" k; K+ b0 n9 Rstatic int count; </FONT></P>& ^8 G& b+ n' t) V
<><FONT color=#0000ff>/* For a color screen the video memory / P4 W; ~) |" c
is at B800:0000. For a monochrome 7 w( z! A0 F* T: Y4 F; a/ p& _8 \; t
system use B000:000 */
3 M' i8 J4 _4 o( iscreen = MK_FP(0xB800,0); </FONT></P>- d5 H! r' Y- Z8 c
<><FONT color=#0000ff>/* increase the counter and keep it
; z9 I: m# N/ v5 K& Zwithin 0 to 9 */
; z8 b5 T! F3 j0 D3 Z4 N3 Gcount++; % z! e# O. E9 D( A6 `5 h
count %= 10; </FONT></P>
) ~, F8 T  y1 {<><FONT color=#0000ff>/* put the number on the screen */ ) V2 L+ H6 F  R. O
screen[0][79] = count + '0' + ATTR; </FONT></P>
# B; S  M5 }8 M5 ?<P><FONT color=#0000ff>/* call the old interrupt handler */
6 n: x# U/ p, Coldhandler();   x/ E5 k& V7 m" U! `
} </FONT></P>
9 R+ }8 s# e4 q, Q& x) O3 p<P><FONT color=#0000ff>int main(void) 1 F3 N5 h: l" T+ r3 |
{ </FONT></P>0 k1 L  I0 M0 w7 M9 w
<P><FONT color=#0000ff>/* get the address of the current clock
% ~" ?) ~4 `! |# ctick interrupt */
0 a2 G6 D/ Q2 P& n. ?* H; Voldhandler = getvect(INTR); </FONT></P>0 u. }, Z9 l+ _5 j
<P><FONT color=#0000ff>/* install the new interrupt handler */
" a. {! N7 ?9 x# T6 C! `  K5 asetvect(INTR, handler); </FONT></P># j# r  ~; Y+ ]  ~- R
<P><FONT color=#0000ff>/* _psp is the starting address of the
; O6 F% N- Q3 k$ [' z' `program in memory. The top of the stack
4 Z8 W8 k9 ?2 e" h  Y* Vis the end of the program. Using _SS and : L( K0 _, u% c0 W
_SP together we can get the end of the
' D  K5 S8 }- E1 _stack. You may want to allow a bit of % x# U& \% j5 C2 F' w) |1 ?
saftey space to insure that enough room - L( A% e8 k' Z+ C
is being allocated ie: 8 X7 _5 M! h; O5 e: k5 w- `
(_SS + ((_SP + safety space)/16) - _psp)
; V! k& J* @" `3 R*/ + B! ~  q: J- |
keep(0, (_SS + (_SP/16) - _psp));
2 k0 Z& ~2 G: ]* @return 0;
; q. a& k+ L6 h$ C. |4 U2 n! p! ~}</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-6-14 03:00 , Processed in 0.346015 second(s), 53 queries .

回顶部