QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2244|回复: 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>
  t/ `1 r7 f3 _, f; _</P>: J; {9 f6 S1 ~6 _  \. e$ Q
<><FONT color=#ff0000>函数名: kbhit </FONT>
- D$ v3 q# \  x2 A功 能: 检查当前按下的键
4 d6 [+ [( |9 m8 T$ g4 G用 法: int kbhit(void);
+ D% @; _9 D! v- {6 n0 Z程序例: </P>
, M6 o% ?4 |# i1 x( p5 L0 t. {<><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 E% {' F, W! R- r9 n- s
<><FONT color=#0000ff>int main(void) ' A; p+ N0 j% m- T
{ 5 T/ g: }$ B4 H1 P* v: g! l  `
cprintf("ress any key to continue:");
! j4 p6 z: a+ t4 Fwhile (!kbhit()) /* do nothing */ ; & j2 _0 O& P2 N% d
cprintf("\r\nA key was pressed...\r\n"); , K* W: f# O" x$ }
return 0; $ {3 f- P+ N5 \6 B( h6 z' E
} </FONT>
$ o3 q7 e* e7 Z( W' d/ ?</P>3 E2 i0 o, U7 {' `9 V2 H9 W
<><FONT color=#ff0000>函数名: keep </FONT>: e; i0 B2 [0 J  ]* Y
功 能: 退出并继续驻留 2 M' q' a) D$ j# S7 X; R( a, D: }
用 法: void keep(int status, int size);
' k4 i6 l# T4 [; g. j程序例: </P>& e6 Q2 g( i6 w4 k
<><FONT color=#0000ff>/***NOTE: 2 `& }2 c  O1 I8 v9 Z6 F. k
This is an interrupt service routine. You
7 Q# L5 t9 z6 C, R7 ccan NOT compile this program with Test ) v! m2 p" W" f
Stack Overflow turned on and get an 5 ]% K9 ^/ m3 C* {" D- _
executable file which will operate 9 k, _5 R: ?$ h, L, \1 G
correctly. Due to the nature of this 5 b* K' e2 O1 m8 u. g" _# T
function the formula used to compute
, R0 Y' q( I4 u- c: N/ x& g3 t: Athe number of paragraphs may not 0 _/ x) Z" E7 u. `) u. f
necessarily work in all cases. Use with
5 m0 \, `- ], L7 G3 S1 R4 C3 bcare! Terminate Stay Resident (TSR) & L# }7 ?% j  B8 L6 N. [
programs are complex and no other support * f$ y3 s  p7 h; n- K; D3 N1 [
for them is provided. Refer to the
8 \) d. q" _0 X2 ?MS-DOS technical documentation
# a3 ~1 B" Q0 D9 e- Nfor more information. */
, [; v7 S' b; j" C# C#include <DOS.H>
2 f; z7 b* @, Q2 P, r: N/* The clock tick interrupt */
: t: i0 w/ g# ]: ^& b1 q2 {#define INTR 0x1C
1 g0 \/ z+ O2 J, w7 W6 l/* Screen attribute (blue on grey) */ / [! m4 Y; L- ]( u
#define ATTR 0x7900 </FONT></P>* X1 i+ ~( X% o
<><FONT color=#0000ff>/* reduce heaplength and stacklength 4 P" e: d# i. t: s' \5 S- a2 K
to make a smaller program in memory */ : e) l* u1 b3 {: n* \0 x
extern unsigned _heaplen = 1024; 9 T9 ]- b0 p+ t( U: e
extern unsigned _stklen = 512; </FONT></P>
6 h0 H( u( i5 H- \( U<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
+ }2 B# p4 t+ ~<><FONT color=#0000ff>void interrupt handler(void)
( E7 Q' R7 r5 j/ n{
3 P9 m  w& [5 p) m$ ^9 X3 b5 \4 Vunsigned int (far *screen)[80]; * b1 q! K5 D9 D( w/ Y& [
static int count; </FONT></P>
& \$ d, T7 D& N<><FONT color=#0000ff>/* For a color screen the video memory 3 D9 c# X' m& ^  {  \5 f
is at B800:0000. For a monochrome 4 I& p( t. l- M8 q
system use B000:000 */
# [# m4 n' j1 d* M* d$ iscreen = MK_FP(0xB800,0); </FONT></P>
4 K. P, Z+ _5 n. b<><FONT color=#0000ff>/* increase the counter and keep it
. k! ^: K2 g) L% i+ ~: F$ S' Kwithin 0 to 9 */
* C+ i: v7 I6 v; Rcount++; : b: Z; }+ M' `3 s: n( z7 Z, U
count %= 10; </FONT></P>
! B5 N6 A- K1 R- z3 ]- m<><FONT color=#0000ff>/* put the number on the screen */ $ [$ v# N$ C; E6 q
screen[0][79] = count + '0' + ATTR; </FONT></P>
# }7 l  S" D" q<><FONT color=#0000ff>/* call the old interrupt handler */
3 C* k- C* a" X5 y2 p/ ?oldhandler();
7 t% b/ M" U: M  \5 @} </FONT></P>" T* w  b1 `, @+ A  N( \
<><FONT color=#0000ff>int main(void) , B1 I1 {5 t4 i" ~6 H
{ </FONT></P>
9 Q5 t/ d- T& f  p% P<><FONT color=#0000ff>/* get the address of the current clock 3 y" o+ _( h: G  ]5 g+ T) v
tick interrupt */ # Q  ?9 {$ d7 k5 _: H/ \: z
oldhandler = getvect(INTR); </FONT></P>( B2 L% R$ n( Q( @+ A. z4 {0 ^7 H
<><FONT color=#0000ff>/* install the new interrupt handler */
" [& |5 ~3 f- ~setvect(INTR, handler); </FONT></P>2 @. S0 \  W" H8 U3 `2 L5 A7 X- n
<><FONT color=#0000ff>/* _psp is the starting address of the
3 [, S) z5 n! ]( gprogram in memory. The top of the stack
6 V8 {/ Y6 D! Y" q3 o$ fis the end of the program. Using _SS and 3 I$ x% n- o+ }5 i5 A; w9 z! f, i+ O
_SP together we can get the end of the ) ?' L! o/ m/ R6 I) }! P
stack. You may want to allow a bit of
6 e" L& S8 s$ usaftey space to insure that enough room 3 I5 r2 o/ {4 ~/ [+ j0 u
is being allocated ie: + o  q2 k- R0 O7 n
(_SS + ((_SP + safety space)/16) - _psp)
+ N+ o* t5 i/ I; W6 O; Y0 s0 H*/ : G$ O( |; |* e
keep(0, (_SS + (_SP/16) - _psp));
; k) @( N' e7 d2 I9 Y6 ireturn 0; ; t: ~& P. @5 C, f
}
$ W: }) j. ~7 d6 [</FONT></P>3 b0 z9 ~, q3 j7 @+ |- `/ A) Z8 K
- G  D8 B5 Y/ d4 q+ |6 P9 o" J
8 o3 S. E6 P& R* U
<><FONT color=#ff0000>函数名: kbhit </FONT>
% l. D& r4 J! W- \% H6 M8 y功 能: 检查当前按下的键 3 v( _- y. }4 w! {& l1 k4 N7 ~( k! x
用 法: int kbhit(void); , y5 k" _5 j7 V7 h' G6 z+ V8 R$ R% A
程序例: </P>. \- ]1 J! ~% g
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
  R7 b6 L7 H  ]* c6 M/ o<><FONT color=#0000ff>int main(void) 1 Z- G. T7 b6 C7 m5 ~. B7 Y
{ . g% }+ r4 t& v5 ]2 @
cprintf("ress any key to continue:");
( X7 _& D9 U& k4 W2 I4 R# Vwhile (!kbhit()) /* do nothing */ ;
% N$ b# X; K" j7 p0 n- m/ n' Rcprintf("\r\nA key was pressed...\r\n"); 5 f  N4 u% m; q# z7 Y) D7 W
return 0;
+ w6 L$ U) ]8 M9 Z} : p% h6 o/ B5 J: g8 n
# X& W! b( b8 @4 B' r) P% F5 [
+ l0 D5 |- U% D4 D; f, C, ]
</FONT></P>
+ F  Z: b3 O2 o4 e8 F<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>/ s7 x1 n9 R! d) f
<FONT color=#000000>功 能: 退出并继续驻留
. F) S7 T. ~9 c: q6 H" \3 H( o9 j用 法: void keep(int status, int size); - z0 `3 O4 P" F) b* q9 r
程序例: </FONT></FONT></P>: H% F8 p- u( t! Z9 o, z
<><FONT color=#0000ff>/***NOTE: 0 n% D0 |3 d) e
This is an interrupt service routine. You
, H" A3 ~& B8 M; {2 }; ^can NOT compile this program with Test
. ~0 Z5 T: V; F8 P8 nStack Overflow turned on and get an
/ R8 X8 I; T9 \8 l! g3 ]4 Uexecutable file which will operate
. D4 m0 }0 ?' @8 f$ |correctly. Due to the nature of this
1 \7 B* ~5 J' R( j0 rfunction the formula used to compute
* B. q7 p) ?6 V$ c& gthe number of paragraphs may not
2 W3 l! y/ F( q1 }0 a$ Nnecessarily work in all cases. Use with
6 P; ]3 b4 B- m0 X2 Fcare! Terminate Stay Resident (TSR)
$ d. |7 d/ A$ M6 J) [) o2 Lprograms are complex and no other support
5 I( A( \. h/ E# ]1 L1 g# r3 Kfor them is provided. Refer to the
0 Q' y  l  p) P+ L9 YMS-DOS technical documentation
$ m( }  g, n( k( Nfor more information. */ , W3 j( l  }7 F: U& v5 ?. ~! u
#include <DOS.H>
( E# a* |( \- `0 d3 [/* The clock tick interrupt */
( ^8 T6 q7 _4 D. s: w#define INTR 0x1C 4 [" S' b. h3 z0 F2 I+ |/ E
/* Screen attribute (blue on grey) */
1 S; Y- |' h# a7 r#define ATTR 0x7900 </FONT></P>
5 |* j. m5 e5 O2 q, E; y<><FONT color=#0000ff>/* reduce heaplength and stacklength
. G7 N. |8 D( l5 H8 mto make a smaller program in memory */
& F/ v! p) K( P" B" U& nextern unsigned _heaplen = 1024; $ I* F* [: @/ m7 y! G% E
extern unsigned _stklen = 512; </FONT></P>" j: ^8 W# E" J$ V( o
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
# ?6 a/ }+ O8 t9 x2 M" {<><FONT color=#0000ff>void interrupt handler(void) ( K( v# L( V4 G
{ ( L  _: [) B( d" J& e  E( g
unsigned int (far *screen)[80];
/ X9 ?0 P2 x) V) u. A6 @static int count; </FONT></P>! [- K) u' _5 ~
<><FONT color=#0000ff>/* For a color screen the video memory % X7 E2 G8 D4 t" U
is at B800:0000. For a monochrome - w4 A0 {  l6 i; o3 d# d& D
system use B000:000 */ / v* N! v; n" r; g
screen = MK_FP(0xB800,0); </FONT></P>
: N, L7 [' l) R5 j) u<><FONT color=#0000ff>/* increase the counter and keep it
$ q$ z) u2 E- i" b8 e8 A# r) Kwithin 0 to 9 */ ( ]7 Z6 W% S/ x2 Q7 p  c7 r
count++;
; g2 n: S8 C3 s) S# f/ d) wcount %= 10; </FONT></P>
7 _# S: i+ A6 w; l<><FONT color=#0000ff>/* put the number on the screen */
) P1 W) Q* {) {3 p* _& a8 S* Vscreen[0][79] = count + '0' + ATTR; </FONT></P>
  s) O$ f& ~3 f; L# G1 a8 g% R<P><FONT color=#0000ff>/* call the old interrupt handler */ 2 D- {) y8 _  p% e8 O" B& T& K
oldhandler();
& v# `6 u6 D! P1 P( q} </FONT></P>
( s( d8 ]! {9 v& @$ z<P><FONT color=#0000ff>int main(void) ) {: d: k! P/ U$ a7 n% d
{ </FONT></P>! a0 F& n& D6 @8 ^7 l
<P><FONT color=#0000ff>/* get the address of the current clock
: X3 W) t0 u, @. G. f6 stick interrupt */
8 B( I  d$ E) }4 n/ c) [/ loldhandler = getvect(INTR); </FONT></P>/ }- E5 D+ L. a- ~1 j9 b5 {* I4 f
<P><FONT color=#0000ff>/* install the new interrupt handler */ 5 X8 b1 D+ r7 C* O2 l& ]9 k
setvect(INTR, handler); </FONT></P>
4 L$ v0 e9 U  D! D9 V' p  C<P><FONT color=#0000ff>/* _psp is the starting address of the
3 a) j% H$ m+ G5 D! y0 hprogram in memory. The top of the stack
2 |  R; X5 F: S8 [5 t9 lis the end of the program. Using _SS and
6 }3 k% h. o! {$ H* {$ o_SP together we can get the end of the
4 A% Q, F0 @. o  N' Astack. You may want to allow a bit of 2 A$ g3 i' v, N+ @- \7 n8 W
saftey space to insure that enough room : w" n- U% h" f; W
is being allocated ie: : [  T& o4 c6 A/ k# f
(_SS + ((_SP + safety space)/16) - _psp)
1 V- d$ g: ~% A5 q. @# |*/
5 p- b, \$ `6 w6 B$ Rkeep(0, (_SS + (_SP/16) - _psp)); ! T+ l3 m" W, G) R" @( O
return 0; , G( F" n5 A4 l8 W: d$ Z. ~5 g
}</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 21:58 , Processed in 0.425729 second(s), 53 queries .

回顶部