QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2337|回复: 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>& e' Y' V. P  ~( I6 j- ~
</P>
& L$ a$ j% i8 Q7 `4 T- U& y<><FONT color=#ff0000>函数名: kbhit </FONT>* Y/ Q. N$ R% i( ~7 I
功 能: 检查当前按下的键
, k3 Q& F0 C1 i9 O: x用 法: int kbhit(void);
# Z2 K. y* z/ m  r& o6 W/ b' Z程序例: </P>
. G. X3 Q0 F9 u6 k7 Q9 m. i<><FONT color=#0000ff>#include <CONIO.H></FONT></P>. ?4 g2 Z* q3 A# d. f# M% i0 B
<><FONT color=#0000ff>int main(void)
: Z& z+ E8 j3 K$ o2 K$ h. E{
/ B1 J0 c/ C& n: Hcprintf("ress any key to continue:"); : y5 l& i: y3 x& U
while (!kbhit()) /* do nothing */ ;
  T  c, |; k. i: p) y- W! Ecprintf("\r\nA key was pressed...\r\n"); $ p$ M1 Z. \+ o
return 0; 0 [$ N/ U) A4 g% L0 @' h8 I
} </FONT>, }& e' a* U! d* q+ z. w8 q4 f
</P>1 b3 c* F, y2 v! T
<><FONT color=#ff0000>函数名: keep </FONT>5 T, T2 [9 M+ ~5 y( n& r
功 能: 退出并继续驻留
8 q& F) V) S+ q用 法: void keep(int status, int size);
0 i9 J7 p2 q8 |' Q4 c程序例: </P>
4 r: Q6 r; w3 O1 J<><FONT color=#0000ff>/***NOTE:
$ h4 E+ Y: \* w! L% rThis is an interrupt service routine. You
+ i6 }9 G, O8 ~$ L5 N9 Ncan NOT compile this program with Test
5 j  d7 C% E) Z, A( [; ?* [9 n9 ]Stack Overflow turned on and get an
) n  Z% u: {0 h* d1 H& mexecutable file which will operate 0 O  S! _" s; [( K1 F
correctly. Due to the nature of this ! s$ }" n: B7 s$ ^6 }6 h; I
function the formula used to compute 5 J. o) k' A0 H- L" n. v% [
the number of paragraphs may not
: {1 V7 t5 k5 {necessarily work in all cases. Use with
3 [. A& A) Z3 H: N- k$ k8 i& Ocare! Terminate Stay Resident (TSR) * C/ C0 i0 Q, f! C" W1 k# ]) |4 [
programs are complex and no other support 0 U# M% E" m, A' M# Z# L( k; e
for them is provided. Refer to the + e7 H& q1 d, l* p, ?. ~" i
MS-DOS technical documentation ; Y+ v3 b. N1 h! H" c
for more information. */
# i* \" M; e) D" j#include <DOS.H>0 J; a' [  ?3 S- O+ U! S5 k
/* The clock tick interrupt */ * A; F: U1 O: ?' J( F3 z
#define INTR 0x1C 0 F- j3 s+ f6 z- P3 |
/* Screen attribute (blue on grey) */
1 B9 m  D0 w) B#define ATTR 0x7900 </FONT></P>
. U9 h5 E( B9 C, S0 ?* o( ]2 `, T<><FONT color=#0000ff>/* reduce heaplength and stacklength
# ?+ [: ^6 q, F8 R6 A, M' Cto make a smaller program in memory */
) \: k: a1 R5 r; T4 p$ Oextern unsigned _heaplen = 1024; 5 N" j% U7 [% q' Z$ V) j
extern unsigned _stklen = 512; </FONT></P>  g7 n) X& S5 Y" _1 S" ]) Q
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>5 B% F! S8 q4 N6 M8 i
<><FONT color=#0000ff>void interrupt handler(void)
8 o; P0 P1 p) k: f+ }{
' T8 m% `4 j  t& M- v1 L% E5 Wunsigned int (far *screen)[80];
; |0 E" u% T. e% y# ]static int count; </FONT></P>
1 o' k% w) ^% _. o+ N( d2 c: j<><FONT color=#0000ff>/* For a color screen the video memory 7 |- l" F( \: c9 @  `
is at B800:0000. For a monochrome
7 _/ s8 A" F, e# {3 Csystem use B000:000 */
; Y/ W4 M  ?4 lscreen = MK_FP(0xB800,0); </FONT></P>
7 M' p* M8 `5 s. h" m<><FONT color=#0000ff>/* increase the counter and keep it & K1 j! B" h9 w) x+ d$ |
within 0 to 9 */
4 O% b, k( e) c0 T$ }+ {2 a, wcount++;
. b( y" k4 M* [5 ?% ^count %= 10; </FONT></P>
- j) `3 L& T% l# }! M% l) \! f' y<><FONT color=#0000ff>/* put the number on the screen */
8 w; e: _- [1 Q1 lscreen[0][79] = count + '0' + ATTR; </FONT></P>( i/ \% i* |7 G5 ]2 g* O% _
<><FONT color=#0000ff>/* call the old interrupt handler */ ) J, L* C4 k0 u' a; g. A4 C& D/ O
oldhandler();   y+ A- _  s- u, n1 r/ j/ d
} </FONT></P>
2 [% ^: {' n" T<><FONT color=#0000ff>int main(void) ! Z% K' N3 M9 ^' t7 V
{ </FONT></P>/ h7 F. i2 ~7 J
<><FONT color=#0000ff>/* get the address of the current clock 2 ]0 l1 p3 R- S1 r
tick interrupt */
) y9 y! j* H2 P) U. r: |" foldhandler = getvect(INTR); </FONT></P>* m+ x3 X/ e  c$ [' w* Y, R
<><FONT color=#0000ff>/* install the new interrupt handler */ & e1 F. D- C5 J4 u9 y
setvect(INTR, handler); </FONT></P>
  M0 O$ ^6 Q  G1 [<><FONT color=#0000ff>/* _psp is the starting address of the 2 t  a, K& G3 ?, Z$ N$ J3 G# {! }
program in memory. The top of the stack - k: l  d' v7 n! U0 P) ~3 N* I& Y
is the end of the program. Using _SS and & q0 ~) o# c6 ]! K$ ^
_SP together we can get the end of the
4 t5 ?" D) I4 c4 J" v8 L! Astack. You may want to allow a bit of
7 U7 r& G4 U8 M* F- ]saftey space to insure that enough room ) N9 n0 @& j& A) H, j
is being allocated ie: % b3 W5 X# G! c
(_SS + ((_SP + safety space)/16) - _psp)
9 t, N  Z1 O) H9 c4 i*/
8 x2 m0 u5 a  s9 a" S) Lkeep(0, (_SS + (_SP/16) - _psp)); ; J7 K9 }5 F' c9 t
return 0;
. K4 E; Y% M* a}; \# T) q* d! e
</FONT></P>
! W# ?6 W+ m3 X8 i$ |4 D# I' N* `3 n8 n2 _; o% B5 k# V
# `" v$ ~& d3 D; U2 }  q) e
<><FONT color=#ff0000>函数名: kbhit </FONT>) T/ `3 ~0 y- V+ ]' v6 v4 K
功 能: 检查当前按下的键 * \1 ^! r# x* W- H3 z1 I& Y0 D" k% j
用 法: int kbhit(void); ( a# B) Z: v6 f  j( U
程序例: </P>: g& y& W8 J3 n9 U9 C/ X
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
" p/ ]" M. t/ `$ x+ u8 B' ~* N<><FONT color=#0000ff>int main(void)
' T1 m( P1 k) ^$ P9 k! w7 C{
" q  ~1 u' Q0 W# O1 qcprintf("ress any key to continue:");
9 Y* o& q1 f; c. v/ o6 wwhile (!kbhit()) /* do nothing */ ; : \" x# L' }5 X
cprintf("\r\nA key was pressed...\r\n"); 3 ^; }- r! u1 Q; N- F# ~
return 0;
" L( v* ^; N: |+ S6 `7 o}
" U  F+ k* L9 N7 c# `4 T; ~2 m% E" Y. q3 K7 t: l8 z' J6 q

% c$ [. `/ e9 F% G, E2 F/ i( @</FONT></P>
( N2 h6 d+ E4 \<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>+ y% b% ?3 f- p8 B% K" h0 ^; r8 K
<FONT color=#000000>功 能: 退出并继续驻留
: o: m0 y5 v0 E3 l用 法: void keep(int status, int size);
/ {0 n8 f3 n% h/ \5 N% @4 @( z8 {程序例: </FONT></FONT></P>* x* U- ]2 A( o+ j, l% U2 s5 h( C
<><FONT color=#0000ff>/***NOTE: + ^* j5 r2 C+ x: E
This is an interrupt service routine. You
: z1 S: {8 s6 vcan NOT compile this program with Test
7 {/ z# {, x8 z; f5 {( H3 r) Z0 iStack Overflow turned on and get an
# R/ T8 j( K- M: Wexecutable file which will operate 0 L2 X1 R+ H8 P/ R3 i
correctly. Due to the nature of this
+ l" _. X/ u( H. I  T6 \* }1 `" _function the formula used to compute
0 a9 W  N. u7 xthe number of paragraphs may not 7 R# `. N" W+ R2 A% A  j
necessarily work in all cases. Use with ! z  K- A- B9 p, Z( }: R" }
care! Terminate Stay Resident (TSR) & w0 W0 N0 Z8 Y$ D' |
programs are complex and no other support
4 r7 z9 ]$ r- _) ]7 cfor them is provided. Refer to the ) p3 ~* F/ }3 H* H0 u" @% C
MS-DOS technical documentation
+ k4 f& @( z% _, L- sfor more information. */ 3 {1 w, a: h# w1 r7 n5 {4 m' W
#include <DOS.H>! r: u6 {+ z1 }
/* The clock tick interrupt */
* E$ p) h: |' t+ N/ p: U#define INTR 0x1C - E9 M% ]5 Q5 u1 o  a
/* Screen attribute (blue on grey) */
: B/ L1 X/ q# Q0 ~#define ATTR 0x7900 </FONT></P>
6 I. a7 o* H. R& D" D! c) ^* ^<><FONT color=#0000ff>/* reduce heaplength and stacklength 3 ]% K8 ?! Y# l1 m( K5 y
to make a smaller program in memory */ ) ~  @& N1 m* @1 D* X7 Z
extern unsigned _heaplen = 1024; % g7 F  w  I- ]# u: Y# u
extern unsigned _stklen = 512; </FONT></P>- g8 m  j2 [0 a4 l3 A) b- K
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>3 M% c" t" B, x
<><FONT color=#0000ff>void interrupt handler(void)
+ x7 Z" {3 |; N& y) B{
3 P. E9 j5 m7 _4 l) s# M4 eunsigned int (far *screen)[80]; # _* D2 D/ ?6 U$ K. u' O* i
static int count; </FONT></P>
! @9 c+ u, b6 ?; x7 w' t- O- X<><FONT color=#0000ff>/* For a color screen the video memory 6 C7 `- `7 j+ q' _6 A
is at B800:0000. For a monochrome
5 Y/ K. z+ Q' e( o3 D. jsystem use B000:000 */ : s* Q- k3 G: g6 d
screen = MK_FP(0xB800,0); </FONT></P>9 S7 o# U/ B5 J0 d2 ~6 t/ `
<><FONT color=#0000ff>/* increase the counter and keep it
3 h6 Z; J+ d; U0 Xwithin 0 to 9 */ , q; J# \. o! M  j: G" q# i
count++;
: G2 ~7 o9 m& S" z4 g  Rcount %= 10; </FONT></P>
4 a. K, `' v* _8 d/ c* ~<><FONT color=#0000ff>/* put the number on the screen */
- H# X; q. w) uscreen[0][79] = count + '0' + ATTR; </FONT></P>
# {6 J- X" `+ b* ?<P><FONT color=#0000ff>/* call the old interrupt handler */
. y1 j6 m1 {4 V8 m! w3 }" ^# W2 Roldhandler();
" D0 l% t& U% T} </FONT></P>4 }) f3 ~0 P' c7 T( g- q. X' f$ ~
<P><FONT color=#0000ff>int main(void) 4 j) \# m1 ^  F( m- G  w
{ </FONT></P>
& `$ |6 g, w8 ~, p<P><FONT color=#0000ff>/* get the address of the current clock
4 U, j% u- s( H9 a, E7 ptick interrupt */ 4 r2 |! }  A& L% N3 T
oldhandler = getvect(INTR); </FONT></P>9 i6 c- i8 D6 q5 n
<P><FONT color=#0000ff>/* install the new interrupt handler */ 0 j0 D' {+ W0 D. Q
setvect(INTR, handler); </FONT></P>
0 p) n" S1 f. h" r0 f<P><FONT color=#0000ff>/* _psp is the starting address of the 6 v" n9 w' ?- @5 a6 D" V* \- H
program in memory. The top of the stack * v* x0 ^: h6 i+ Z) a0 ~
is the end of the program. Using _SS and 8 [. ?; m  S. s) S5 l% b) x$ ~/ i
_SP together we can get the end of the
% {# M0 s4 Z( t. V, m% D4 fstack. You may want to allow a bit of 0 V" Q! E- h& k" z6 l8 U
saftey space to insure that enough room - G/ ^4 }" U; h
is being allocated ie:   f3 x6 u: [5 D
(_SS + ((_SP + safety space)/16) - _psp) ( |% W+ U- `- _
*/ ; E0 O; b' Z4 _& s+ f
keep(0, (_SS + (_SP/16) - _psp)); 1 n9 a# @, x7 \0 h( X- B
return 0;
9 Y8 y7 E( g& X}</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-23 09:16 , Processed in 0.716446 second(s), 52 queries .

回顶部