QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2340|回复: 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>+ q' x& v: P+ c/ o
</P>2 s) G! F" U2 g+ O
<><FONT color=#ff0000>函数名: kbhit </FONT>
: W; p$ F* C- ?7 x' X- m功 能: 检查当前按下的键 4 }/ ]5 V2 _$ e, A7 _3 d+ L/ E
用 法: int kbhit(void); ) \% X# {+ w; Q" X" M6 k: @
程序例: </P>8 S- j) w9 w( U/ |) d& T* A& R1 B
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>% ]+ v' P: ~2 d" {# e* D2 B% W
<><FONT color=#0000ff>int main(void) : w% I# Q3 Q% Z! w4 D
{ 6 g. y8 C$ l* M, o) S: o  e
cprintf("ress any key to continue:");
5 l! z% v) J9 W  }while (!kbhit()) /* do nothing */ ;
% y8 G: p, o5 P4 A! b6 h+ _  Dcprintf("\r\nA key was pressed...\r\n"); / R. a. p' ]" Y1 z% b. I  h
return 0;
2 R8 p- N& r7 ^' u2 B+ m. r} </FONT>, u0 ?3 ]1 M9 g1 F
</P>6 n+ [8 e+ l4 c' M% p3 ^7 A3 o& R  ^
<><FONT color=#ff0000>函数名: keep </FONT>
& p- z6 O; }  |) ?$ A功 能: 退出并继续驻留 / V8 ]9 g4 W+ d
用 法: void keep(int status, int size);
0 l* V4 v4 l% J5 I1 v. V程序例: </P>3 ~+ @# H, v! Y- J! f, m
<><FONT color=#0000ff>/***NOTE: % r- x1 p9 r9 {# I
This is an interrupt service routine. You / V7 `- A  D- R+ _7 V
can NOT compile this program with Test
8 G: Z: u$ N6 h$ q" hStack Overflow turned on and get an
8 j' b( Z9 M8 z% \executable file which will operate ( K# }! ~) D6 t4 Y$ m' x
correctly. Due to the nature of this 1 V; O3 N0 F/ J+ d
function the formula used to compute ( s9 z' {0 H( c; F9 q
the number of paragraphs may not
0 q; w* `: {. k  j% h& m4 X& }* Mnecessarily work in all cases. Use with
: ]( j$ K+ f: Q! f- Z6 E& ycare! Terminate Stay Resident (TSR)
! k& A' F6 g9 \programs are complex and no other support & x; i( F7 Q% R. f2 d7 Y
for them is provided. Refer to the
! i% ^) _% a( w6 P( g! MMS-DOS technical documentation ) `- ]- L; f: m8 e
for more information. */ - {1 U& P' M" U6 S- R3 ?
#include <DOS.H>* [# x" q; ]: |) [# O1 a4 J; C2 `7 S
/* The clock tick interrupt */
3 U8 H$ m) `& I" d0 c#define INTR 0x1C
$ B( r: k) v0 o4 E% L8 t0 _/* Screen attribute (blue on grey) */ ( y. H' V* W* ?. V1 ^
#define ATTR 0x7900 </FONT></P>5 T% q2 [8 Y6 G: W# ^
<><FONT color=#0000ff>/* reduce heaplength and stacklength
, N, @  A7 w' @6 }# Fto make a smaller program in memory */
+ R: B1 b, o0 d/ O" F$ D# f/ uextern unsigned _heaplen = 1024;
5 ~$ M8 y) p6 Z3 g! wextern unsigned _stklen = 512; </FONT></P>
6 r( o4 Y8 ]" R* f* R<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
6 Z6 D! C/ G( Z; t- _3 O<><FONT color=#0000ff>void interrupt handler(void)
9 u6 U1 i6 a- E5 Q* L5 j8 b{
8 D9 `0 w/ l) Y# j( L  t: `# c+ ?unsigned int (far *screen)[80]; " o3 L" Z" @9 z& M! u
static int count; </FONT></P>
4 S! o) U' p: H. A' a- u<><FONT color=#0000ff>/* For a color screen the video memory
/ p$ {0 C2 Z7 U2 Y3 mis at B800:0000. For a monochrome
% S* g# {& C0 |, tsystem use B000:000 */ ) h& f& c8 s  F9 I
screen = MK_FP(0xB800,0); </FONT></P>
1 h, p7 ?0 z. B3 G<><FONT color=#0000ff>/* increase the counter and keep it
" ~( C, M( q& p3 M( |& z/ ^within 0 to 9 */ ! }7 S7 m7 {6 z
count++; ( e' t+ B$ p/ H; }3 a
count %= 10; </FONT></P>5 V( g( n) I: d' y
<><FONT color=#0000ff>/* put the number on the screen */
/ R* _5 s+ K7 R( |screen[0][79] = count + '0' + ATTR; </FONT></P>- t* T* L, x0 @+ d
<><FONT color=#0000ff>/* call the old interrupt handler */
% A% p0 H& Q+ r( _* B7 foldhandler(); ! Q6 y2 F! O/ V% }
} </FONT></P>
4 o4 @6 H0 W0 d' F8 @<><FONT color=#0000ff>int main(void)
- E4 }% d3 u" q4 _! X7 ~{ </FONT></P>6 i( Z1 u' i: v" o2 `8 G6 ~2 x
<><FONT color=#0000ff>/* get the address of the current clock
7 k$ q  o# e) d; @) @tick interrupt */ - [9 C, q0 G1 x- k, _3 ~
oldhandler = getvect(INTR); </FONT></P>* M! a0 F- [: m2 H7 C& c4 D/ V
<><FONT color=#0000ff>/* install the new interrupt handler */
2 T9 W: y" B$ ysetvect(INTR, handler); </FONT></P>
" ~7 B, }. |: N, [& C<><FONT color=#0000ff>/* _psp is the starting address of the
( ?' G) V. }+ Q1 ?3 h9 ~4 uprogram in memory. The top of the stack
/ T1 j; h+ a/ L$ Eis the end of the program. Using _SS and - ?1 m$ u8 w$ {3 u6 P6 s! d
_SP together we can get the end of the
& T. l$ Q. E% \; Wstack. You may want to allow a bit of
* H- f) u6 V' R& u4 M0 k7 `% vsaftey space to insure that enough room 8 ?6 M6 f2 e0 M; K2 ?
is being allocated ie: , s! f* F) e/ E, Z/ `, H+ M: T
(_SS + ((_SP + safety space)/16) - _psp) 5 z& v/ F+ V' h4 A
*/ " C: Z' }; k5 o+ K
keep(0, (_SS + (_SP/16) - _psp)); / e6 }/ U5 L4 ]4 J
return 0;
9 L" |0 V% r/ h* e) ]: D) D}
+ o8 [! P+ @% s% @& n</FONT></P>- y' h: H9 }2 o; E4 l4 j( N8 p2 a

1 |* s- W) X' p+ B/ `% e
3 _3 B  d4 ^1 f: S<><FONT color=#ff0000>函数名: kbhit </FONT>  o$ G: h3 k/ G( X! F; a6 j
功 能: 检查当前按下的键 ) N) g9 d% h6 w: \, r3 C) ~- H
用 法: int kbhit(void); 5 E# s: `  P2 H% d3 E9 ?# f, ^
程序例: </P>
8 m: m* Z2 T5 J; E<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
. {1 C7 }; G; }1 m: y2 `<><FONT color=#0000ff>int main(void)
# Q$ J" m: ?' f% r: w{ $ t2 h6 T0 o2 s! v/ R
cprintf("ress any key to continue:");
" \" `1 X6 t$ e' f* Rwhile (!kbhit()) /* do nothing */ ;
$ ?2 l8 u0 q! m8 Ucprintf("\r\nA key was pressed...\r\n");
# t4 n5 g- o3 n" u9 G5 rreturn 0;
! k& d% B1 g1 }7 p) |} 5 G( L- z3 H* [6 G
; c# a2 B. D, {; _7 ]1 Q' @

  {% O& ]/ I) M5 x2 J! m</FONT></P>
* X  Z% w% N- C3 A( m" i7 T, J<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>! X- ?; ?6 E( j4 n2 o- D
<FONT color=#000000>功 能: 退出并继续驻留 $ o+ x0 |5 N2 B/ E
用 法: void keep(int status, int size);
! L: S+ D: a3 W, m0 m程序例: </FONT></FONT></P>1 w# U! Q! k2 @5 u8 N' ?
<><FONT color=#0000ff>/***NOTE:
8 r; V8 ?  }5 f. y" SThis is an interrupt service routine. You , b7 w- e) a1 Z4 G, r
can NOT compile this program with Test 6 m! B3 }* ?1 E5 [9 J& Y2 i* B
Stack Overflow turned on and get an
) Z: g5 ]! {! e+ \! Yexecutable file which will operate
4 o1 }/ H. m& Z' C/ ?correctly. Due to the nature of this
* ~9 N" J2 N) ~function the formula used to compute
. ~! }+ x  m( k! k4 mthe number of paragraphs may not * S% R1 j, E7 J: U+ g
necessarily work in all cases. Use with
9 J+ R$ V! ]  W: d: }care! Terminate Stay Resident (TSR)
: W" p4 E* T2 Gprograms are complex and no other support * U5 b2 W! ]2 O* h% C1 L
for them is provided. Refer to the ' ?! L+ J1 J& K$ P  I
MS-DOS technical documentation
( X' A8 H" C" k- E6 Wfor more information. */
8 b) s5 ]0 }$ }/ Z#include <DOS.H>" e( x8 X# r( g) L6 S
/* The clock tick interrupt */
) ~& D" g$ }& \" i( k  Y7 s#define INTR 0x1C 9 N) f5 x6 p, c5 f9 W
/* Screen attribute (blue on grey) */
* A# G) C, a) M$ p#define ATTR 0x7900 </FONT></P>& P& t& J3 t& T+ H7 V9 }/ G
<><FONT color=#0000ff>/* reduce heaplength and stacklength * N8 b! F2 n  b- f3 p- t3 p$ B
to make a smaller program in memory */ . `, c! B1 g5 J. U9 L% `' b8 I
extern unsigned _heaplen = 1024; 8 F2 [# g9 [2 ]% U; M4 J/ ?" u
extern unsigned _stklen = 512; </FONT></P>
) S/ T* H. s* A6 h+ p6 n' G) E' e  `<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
* M6 y+ d! V9 I2 V& M<><FONT color=#0000ff>void interrupt handler(void) 1 s7 b( ~# y8 h" K, B7 \
{ 5 _9 {: H6 E: L6 o) U2 J
unsigned int (far *screen)[80]; ( e  @: ]' }$ e! s4 R  B  p
static int count; </FONT></P>
0 C) O8 K- Y/ Z  R# D& n<><FONT color=#0000ff>/* For a color screen the video memory 7 T8 L4 a* U1 S: R
is at B800:0000. For a monochrome
3 k! B) K9 \$ u9 _  P5 y2 H9 ysystem use B000:000 */
4 e1 Y1 s, Q$ p1 T! i3 ?screen = MK_FP(0xB800,0); </FONT></P>9 l0 f, F3 v* k( H! _+ R: z4 D
<><FONT color=#0000ff>/* increase the counter and keep it " y8 r; W9 o9 H7 k/ n& P3 d& h. R
within 0 to 9 */ ( t, u5 d! B# Y3 G& L
count++; - }+ e& l+ T' x$ p$ {
count %= 10; </FONT></P>
  s6 C& S- G; e  y2 ~<><FONT color=#0000ff>/* put the number on the screen */ 0 F7 {! }8 W4 D5 L% r; o, }
screen[0][79] = count + '0' + ATTR; </FONT></P>4 R  J7 r4 w+ I7 v( x7 F8 t
<P><FONT color=#0000ff>/* call the old interrupt handler */ % O, Q: ^' L% ?  \# _' ^
oldhandler(); & I0 d$ H8 K$ u- a* U7 n+ k6 ^4 m
} </FONT></P>+ v" }( X! ~* M
<P><FONT color=#0000ff>int main(void)
6 u! g2 V3 C/ J, o! w! ]{ </FONT></P>+ L0 v6 X  e# t3 V
<P><FONT color=#0000ff>/* get the address of the current clock # F- O) @, r% r/ c* C: g
tick interrupt */
8 C9 q2 C, H) Xoldhandler = getvect(INTR); </FONT></P>+ t) ]+ U' t1 \2 n
<P><FONT color=#0000ff>/* install the new interrupt handler */ $ b! _2 q3 z6 K7 P! V) G
setvect(INTR, handler); </FONT></P>
. `+ b: c  K+ {" f. C! {<P><FONT color=#0000ff>/* _psp is the starting address of the ) s: P) }8 s) H- S0 l9 M
program in memory. The top of the stack
; H, E8 n. g  q1 S6 ^" Lis the end of the program. Using _SS and 1 L- k* X2 _$ x# L1 z6 s
_SP together we can get the end of the
6 {4 ^  T$ y" |3 s# e0 \# jstack. You may want to allow a bit of
0 Z7 Y9 m1 j  g% G+ Y) C. \7 qsaftey space to insure that enough room
9 S  K+ n5 N# ~4 Z% ]- nis being allocated ie:
0 D1 s$ x+ K5 B$ A* r; s(_SS + ((_SP + safety space)/16) - _psp)
+ e" h2 u8 W) [( j2 I; F" Z7 _*/
2 C  U  T7 @. i: I7 wkeep(0, (_SS + (_SP/16) - _psp));
2 j$ _' n' r' H. breturn 0;
( _8 {8 [  L4 O}</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-24 10:08 , Processed in 2.160028 second(s), 53 queries .

回顶部