QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2241|回复: 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>- ?9 ]! a. _- J6 a$ X. @8 R8 v9 m, ]
</P>
$ j6 v+ V/ S+ O' _2 i<><FONT color=#ff0000>函数名: kbhit </FONT>
, \+ h! h: s: u! s功 能: 检查当前按下的键 4 u9 F6 |+ B" K) v; E! C# y( |7 k% E% J
用 法: int kbhit(void);
! D6 ]1 x, a. j7 W程序例: </P>
5 x" k9 C1 j! Z( T( v5 `7 \. M<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
4 t  E# t6 r& g4 ^/ ?<><FONT color=#0000ff>int main(void) 0 B0 ]- q  M- }* d- r$ H) o
{ . i+ ]$ O7 M, y9 m  j4 C
cprintf("ress any key to continue:");
% @! p% h3 C, D4 z' H  jwhile (!kbhit()) /* do nothing */ ;
. }9 |6 L/ C- C4 l- D# rcprintf("\r\nA key was pressed...\r\n"); ! S5 I' U2 J, W, q
return 0;
% c8 |: i: r' j  M0 b$ m7 ?' K} </FONT>
% D% n+ Z* {/ k) b</P>
& a9 F8 A( q. ^<><FONT color=#ff0000>函数名: keep </FONT>& D% B& E0 Z- J
功 能: 退出并继续驻留 8 s8 c7 i2 p6 g3 A! w/ p* @5 D
用 法: void keep(int status, int size); 9 |2 d# w6 S+ u9 X9 t/ u& ^
程序例: </P>. q1 ~7 a( h% e7 U+ k
<><FONT color=#0000ff>/***NOTE:
* d) x; S0 t) r* H  @+ u7 v% {7 FThis is an interrupt service routine. You + N4 Q0 [' H" T5 W, W3 ^
can NOT compile this program with Test
4 y0 q9 T, V) Q' J9 R3 uStack Overflow turned on and get an
; s6 {& O/ V/ D9 Z# N# S2 eexecutable file which will operate
8 }( M; i. W, N) P* y5 G. Hcorrectly. Due to the nature of this 5 B( M$ X) K6 C
function the formula used to compute
4 L& g6 C% J0 @4 n1 uthe number of paragraphs may not : Y$ S+ I) B8 S9 a
necessarily work in all cases. Use with ; `, B  Q$ j; ?1 L
care! Terminate Stay Resident (TSR)   l% M) ?+ P+ j/ N* J9 }* o) ]* `; u
programs are complex and no other support & Q, C% i7 i" O3 }6 z
for them is provided. Refer to the : `. w8 ]4 i5 f- b- l
MS-DOS technical documentation
% {6 H$ i7 s2 wfor more information. */
, F' g! H7 P; R% G2 R1 O! |#include <DOS.H>$ _3 Z8 g8 T8 a
/* The clock tick interrupt */ : r, l5 P/ I+ {* S( N! Z/ ~- Q* ?$ U
#define INTR 0x1C * F& l' a$ k! Q8 k6 {
/* Screen attribute (blue on grey) */ & u2 Y8 H6 g; i5 d
#define ATTR 0x7900 </FONT></P>
! O6 ~# p/ {: ]6 l<><FONT color=#0000ff>/* reduce heaplength and stacklength
% X1 F: i, V: o% l: r5 Wto make a smaller program in memory */ 3 T7 W3 v9 {$ ?$ n
extern unsigned _heaplen = 1024;
! H4 x* c  F1 e  Qextern unsigned _stklen = 512; </FONT></P>( A' L( Q9 N) J& G0 d+ J: {0 V
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>- J# ^$ L5 y* o, k4 O: S
<><FONT color=#0000ff>void interrupt handler(void) ; W, _: f7 n0 @7 j% d3 D; t# v
{
) m7 J, Y6 Q5 Gunsigned int (far *screen)[80]; # K2 a' L6 w3 R4 x7 \1 ~
static int count; </FONT></P>
- @" \5 y1 P, }# |' R6 H<><FONT color=#0000ff>/* For a color screen the video memory
. @7 x7 k! ?4 m; Q) |is at B800:0000. For a monochrome
7 i# W" z: l2 g( ksystem use B000:000 */ 3 O: t2 y* W- |' _. f) n: ?
screen = MK_FP(0xB800,0); </FONT></P>
& Q+ l  ]( S3 s+ v9 ^1 h<><FONT color=#0000ff>/* increase the counter and keep it & D" }" ~$ P2 d6 l$ i
within 0 to 9 */
% s* x! E0 R: N% ^$ a" pcount++;
% ?- {4 M+ `9 b5 A! hcount %= 10; </FONT></P>
5 g# \* d& [) z3 U7 E2 l<><FONT color=#0000ff>/* put the number on the screen */
  S' ^. f0 ~5 Oscreen[0][79] = count + '0' + ATTR; </FONT></P>
# J2 O$ E# P1 P9 g<><FONT color=#0000ff>/* call the old interrupt handler */ ; {% v5 \* ~+ T
oldhandler(); ' B- V1 E8 n- ?0 J; J# S
} </FONT></P>4 R' s* M! V/ T  K* s& h. z/ @* W2 H
<><FONT color=#0000ff>int main(void) . g. z/ E0 F$ z8 q- D
{ </FONT></P>; F( v, {! `0 L. T1 T, f( I" Y
<><FONT color=#0000ff>/* get the address of the current clock
9 Y( Q+ d/ u6 Q  t4 ]6 itick interrupt */
' B* d# f1 y$ N4 Moldhandler = getvect(INTR); </FONT></P>; m# l: n; c, @4 g
<><FONT color=#0000ff>/* install the new interrupt handler */ ' z7 b0 u. A+ w/ U
setvect(INTR, handler); </FONT></P>$ w. N' o' ~3 i" F
<><FONT color=#0000ff>/* _psp is the starting address of the
. n# {9 R0 ?7 b7 d- n8 aprogram in memory. The top of the stack
3 ?: d& d9 C* i8 m+ e, sis the end of the program. Using _SS and
) ~5 c* q, |: D3 d& D& d6 F_SP together we can get the end of the 4 n/ d/ m' B: Q4 n
stack. You may want to allow a bit of $ y7 `1 h) ~# u) {
saftey space to insure that enough room . m; u$ [( ]" c+ |9 Z% R0 h( j% \; N
is being allocated ie: ( W! [6 ]7 \' n8 k
(_SS + ((_SP + safety space)/16) - _psp)
/ V! _$ a8 T: I" W7 t! }*/
# n0 f3 j. ^; |keep(0, (_SS + (_SP/16) - _psp)); 8 f8 ^; {6 r+ [4 ]$ V& ~9 v
return 0; ! M( q4 ?* l% u; E1 B
}6 a* f6 J2 t0 H3 O& e* a
</FONT></P>
5 l, j( ]! N  k; ^- t+ G- z2 a0 ?; W" t

. Z* {( L3 o6 ]* q- r$ K, C<><FONT color=#ff0000>函数名: kbhit </FONT>' U% l6 C# D: m+ B) @5 A" W! c
功 能: 检查当前按下的键 ' i; A7 Q( e. x4 X% Z, Y4 d
用 法: int kbhit(void);
/ C2 h/ t; u  P3 X  P, E  r程序例: </P>
6 @/ d, }" i, |" T9 c<><FONT color=#0000ff>#include <CONIO.H></FONT></P>- o" U: T3 \  h% `, C  M
<><FONT color=#0000ff>int main(void) & D4 Z6 a0 w* l2 g+ }
{
- G$ D7 R! m9 {  g5 v; {cprintf("ress any key to continue:"); # W1 i' x" m  ^8 h( s8 y9 S9 Z
while (!kbhit()) /* do nothing */ ;
1 R. Y& h$ _  k) R; K2 Q. pcprintf("\r\nA key was pressed...\r\n");
3 S3 D+ x3 z) i8 `return 0; # x: j. G# g. C' V
} + y; h; s3 r0 N/ e# p
6 S* C5 c9 Q( o- U5 \# X$ [3 m
( y: ^  X+ B/ a) L+ B/ ]+ @( m
</FONT></P>
5 S" q2 o- ]! I5 N, E2 s+ Y' E<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>( A" C- c: a. t! G3 `) T" q  e6 J
<FONT color=#000000>功 能: 退出并继续驻留 / h+ W7 X3 q) |  ^9 D" v$ B" e
用 法: void keep(int status, int size); * V6 T: c/ \9 ]  x( B1 e
程序例: </FONT></FONT></P>
  D- |) ]5 n. L! J) D8 f<><FONT color=#0000ff>/***NOTE:
; X2 Y, e2 `+ I# `' T7 P5 ?6 z3 JThis is an interrupt service routine. You   }* E% \0 G1 V3 J. y6 L
can NOT compile this program with Test
2 E' ~5 a: ^/ q" s3 i, [Stack Overflow turned on and get an : s9 y6 Y! t. ?5 o- n# x
executable file which will operate 2 c5 }" j8 W6 P) m& ^
correctly. Due to the nature of this $ M3 }. j  ^7 R$ {1 m
function the formula used to compute
/ X( Q6 C2 s* m% u6 z+ Hthe number of paragraphs may not
( I+ n/ P6 E7 L. z" Mnecessarily work in all cases. Use with
1 ^% \6 w6 [4 ycare! Terminate Stay Resident (TSR) 2 T- u$ [9 z1 b0 P) V
programs are complex and no other support ; L' Y0 [! A5 o8 f
for them is provided. Refer to the 8 u) R0 n+ P2 W# @% r$ l  e
MS-DOS technical documentation $ g$ C7 l  J  `: s8 `% ]3 E
for more information. */
( X* S* l5 h9 b/ X. G#include <DOS.H>: h3 |$ k" c) g" ^5 i" \
/* The clock tick interrupt */ " V# z9 k! m- q# L; O& E$ f
#define INTR 0x1C
! {% b' w6 L9 `, G; o+ s/* Screen attribute (blue on grey) */ 4 @1 k" Z2 E* x4 t; s# A; c
#define ATTR 0x7900 </FONT></P>( M6 {1 I$ q5 K" k
<><FONT color=#0000ff>/* reduce heaplength and stacklength 5 j6 h9 @% ]- N1 u; D$ D: q( t
to make a smaller program in memory */
& B6 w+ U2 g  F. P7 u& T( yextern unsigned _heaplen = 1024; 8 e' Y# c! i' E/ F# f( d" B, V# @2 R
extern unsigned _stklen = 512; </FONT></P>
+ Q) c# _. I4 o. y& b<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>* H+ Q8 ?0 Y  t% q
<><FONT color=#0000ff>void interrupt handler(void)
/ o2 Q' r( ~! T, o0 x0 Z6 l{ 0 @# Y4 k, O( O; A5 V7 Q$ n
unsigned int (far *screen)[80]; 6 o6 c$ |3 H* q, G! E, A& x% q# n
static int count; </FONT></P>$ L* L0 R6 f) W' E0 |0 N+ @
<><FONT color=#0000ff>/* For a color screen the video memory
3 r# J2 k( B5 s: t5 ~% y1 cis at B800:0000. For a monochrome
5 G- u2 D! j% ?7 m0 [8 Z3 Fsystem use B000:000 */
) {) N' [* e, j* oscreen = MK_FP(0xB800,0); </FONT></P>+ ^. T: H$ Q6 F+ x$ d7 Z  H9 w
<><FONT color=#0000ff>/* increase the counter and keep it 1 N8 c2 j+ o8 W- \8 ^
within 0 to 9 */ + p. ]# P% A: K2 z9 O- U9 A
count++;
5 Q5 C+ ]# s+ _( {, i! U# Ycount %= 10; </FONT></P>
' b7 f2 ^& F4 N( u& i5 N& Y2 P, N5 P<><FONT color=#0000ff>/* put the number on the screen */ * k- H) \! P7 ]1 b8 t
screen[0][79] = count + '0' + ATTR; </FONT></P>% p$ X% n& ]' l2 W& M  @
<P><FONT color=#0000ff>/* call the old interrupt handler */ ; J) @& t6 n# T9 `1 @# f9 V1 z
oldhandler(); ' x/ }& L$ c. ^& R- x
} </FONT></P>
  G, k' r5 x, d% }" W<P><FONT color=#0000ff>int main(void) % t  F! f: H" n4 ~
{ </FONT></P>
0 Z5 g+ T5 S. A# |/ M1 T6 H$ U( I<P><FONT color=#0000ff>/* get the address of the current clock
8 Z) a* k$ I5 I; ?: Vtick interrupt */
' s) G2 v2 z$ ?' {; o' goldhandler = getvect(INTR); </FONT></P>
% K" y, c) l7 S% g. S: T( T<P><FONT color=#0000ff>/* install the new interrupt handler */
# ~; C; N: _5 U, Y- C# e9 {. Asetvect(INTR, handler); </FONT></P>0 q" a  f  x: R8 p- S$ {/ Y
<P><FONT color=#0000ff>/* _psp is the starting address of the ! U/ R" M2 m+ Q3 h& m7 g! a) b
program in memory. The top of the stack
3 Z* I* L9 x8 b8 m% P$ Fis the end of the program. Using _SS and
9 ?! X1 [: M! D1 I" z  @_SP together we can get the end of the
3 z6 v1 X( e  e* [' ^% E" V* kstack. You may want to allow a bit of . U7 g! d0 M( ^7 H3 g
saftey space to insure that enough room
5 E' Y- m  y5 n/ D( x/ @/ bis being allocated ie: : A0 L9 s% l* a  H2 Z, o# r* i
(_SS + ((_SP + safety space)/16) - _psp) % |# N2 B; j& x
*/ + u. G5 O! a- ~1 J  _: i9 O' h5 C
keep(0, (_SS + (_SP/16) - _psp));
9 A9 ^4 X1 b* g! @' r3 J$ h5 ureturn 0; ' P+ b; H8 `5 G, G5 U8 C8 w9 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-4-20 17:14 , Processed in 0.470638 second(s), 51 queries .

回顶部