QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2263|回复: 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>
: o# k0 I1 r. z8 ?  c# P. o% b! W</P>+ \' c0 {7 q0 U. H% @' A! |
<><FONT color=#ff0000>函数名: kbhit </FONT>5 l- z$ t9 B5 w+ T0 s
功 能: 检查当前按下的键
- u8 J' q% i1 @/ T. a5 L用 法: int kbhit(void); ) [5 p3 E& s: V* u
程序例: </P>' o1 A5 x& z6 W+ `+ r
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>$ f" i; m8 C9 J
<><FONT color=#0000ff>int main(void)
( V  L  Y8 O5 i5 `9 q{
3 ^/ h. ]/ C  [$ d% H) o4 jcprintf("ress any key to continue:");
4 F1 X5 s5 f! m  swhile (!kbhit()) /* do nothing */ ;
9 P! s. v1 j- Y; q1 c/ ccprintf("\r\nA key was pressed...\r\n");
" X! V% l6 _* K/ Q* Nreturn 0;
2 _6 T. }0 K: T& i9 y} </FONT>
8 @( O1 T" E$ G8 K( d* o</P>' \$ [1 k" b. @1 ?  j
<><FONT color=#ff0000>函数名: keep </FONT>
0 U- r! A# C3 ^! }* t功 能: 退出并继续驻留 - u% Q! I" d2 L$ _3 _3 w
用 法: void keep(int status, int size); * t9 O) A. H! k* L0 q+ ]
程序例: </P>$ `' L& ^. _* [& {8 y, J( |
<><FONT color=#0000ff>/***NOTE: 5 G& D4 y7 x, T0 Y9 |# s( t# j
This is an interrupt service routine. You 1 g8 U% z& z+ T  Z/ B* Y. f
can NOT compile this program with Test ! `4 j# ]7 h/ C
Stack Overflow turned on and get an & l5 _$ K6 J" _9 N! v+ S8 N! @5 b
executable file which will operate 9 v4 K" R; x; `* D, K) S
correctly. Due to the nature of this * n+ l$ Q* o* Q1 I
function the formula used to compute 2 p* f5 ?: d$ h
the number of paragraphs may not
/ E) I; v5 n* p* X! {necessarily work in all cases. Use with . m5 @5 ^7 ~. Y. V
care! Terminate Stay Resident (TSR) & o  S& t" K2 o( O' r' F; T  y
programs are complex and no other support
1 `- c5 O9 S4 Q$ ^for them is provided. Refer to the
8 _! j9 O! ?1 v  \MS-DOS technical documentation
+ ~, T" q- [( nfor more information. */ 8 y2 B# j0 Q7 ~# K
#include <DOS.H>
5 m- c6 _! N7 y( ^2 ?8 o/* The clock tick interrupt */ % l) t1 M8 J6 K! }
#define INTR 0x1C
/ ?6 |8 s) E' Z+ O/* Screen attribute (blue on grey) */
- r  {0 s* Q+ Q, W9 a; G#define ATTR 0x7900 </FONT></P>' l! R& |; y8 r6 y  @8 o- o( A
<><FONT color=#0000ff>/* reduce heaplength and stacklength ; X; y2 w* Q6 e8 K6 T
to make a smaller program in memory */
% a! v7 J$ s$ @+ V( y$ t* {0 ^0 c  {extern unsigned _heaplen = 1024;
( L# }8 t% l2 r# `- k1 P: B1 lextern unsigned _stklen = 512; </FONT></P>2 f4 v$ y3 _/ k$ B, [
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>! ]3 X: x0 k# S) ]. z2 l) u
<><FONT color=#0000ff>void interrupt handler(void) 2 G/ @( H2 H5 m. a3 _8 Z% S/ d7 `
{
; @( r4 C* O- o+ e% P$ o; C9 r% Cunsigned int (far *screen)[80]; ; F% m$ V# w; Y3 S. Q. q1 [
static int count; </FONT></P>
' ?$ R9 ]0 g1 p<><FONT color=#0000ff>/* For a color screen the video memory : c4 V+ K. {8 Z0 _* S2 c
is at B800:0000. For a monochrome % M( Y' }+ J! C2 I$ V
system use B000:000 */ 6 \' l% z% O1 D& ?/ a. K5 f
screen = MK_FP(0xB800,0); </FONT></P>
) n1 w# l! g! p3 ]' K5 K4 i<><FONT color=#0000ff>/* increase the counter and keep it
; X6 w# U# ]$ Y+ @" A  [$ Ewithin 0 to 9 */ ' ^: N; d' O. F
count++; 4 O2 X$ g: j4 U% z+ @, m$ S! V' S2 i
count %= 10; </FONT></P>
( Q" ]2 x* U! v9 [" k<><FONT color=#0000ff>/* put the number on the screen */ " `" ?; N% x$ h  c. n
screen[0][79] = count + '0' + ATTR; </FONT></P>+ {% h" V" F- H, A9 p/ ?
<><FONT color=#0000ff>/* call the old interrupt handler */
3 {. n( y( L% D  Z9 E6 doldhandler(); $ c  O$ f& Q+ ]
} </FONT></P>
8 a! h3 P! x  ~$ a( M1 @: G" m<><FONT color=#0000ff>int main(void) 2 T- E9 o) K) J' v, }4 e
{ </FONT></P>
& r6 N+ B- [7 M/ ^* S3 {  a<><FONT color=#0000ff>/* get the address of the current clock
$ V# Y8 o3 }* P4 W, {1 \tick interrupt */
; U! n, }! Y  U: [oldhandler = getvect(INTR); </FONT></P>
+ O5 J3 M0 ]- R<><FONT color=#0000ff>/* install the new interrupt handler */
, u3 j# O/ Q' }, s5 Wsetvect(INTR, handler); </FONT></P>
0 c9 j4 `  ~5 ~& @+ o! H! L$ ?/ {<><FONT color=#0000ff>/* _psp is the starting address of the
& V3 h; {' a* Lprogram in memory. The top of the stack
: q* H; T/ C( X; P/ D. z: Tis the end of the program. Using _SS and
5 ^0 s9 M  t  `% l4 g0 H_SP together we can get the end of the
! N) o. c* q/ Q9 G) o" istack. You may want to allow a bit of
0 d0 K; g3 e, d$ E* H$ N+ R3 h8 |saftey space to insure that enough room
* Q$ d8 s5 Y$ }" P8 Mis being allocated ie:
2 d5 M! G( v1 d6 N7 r(_SS + ((_SP + safety space)/16) - _psp)
/ `9 [& m5 G! R! Z) ?3 |) Y& W+ y*/
. Z, n( d3 g3 Dkeep(0, (_SS + (_SP/16) - _psp)); / E; o( p% W. l" [) z
return 0;
$ p+ a  v7 h6 |! Y3 T, S4 ]" x}0 q& N) R1 n  q! S4 W' n
</FONT></P>% ]1 }! {) q! g; H) V2 c7 F' Y
; h2 R  e- @( @, p9 E" M
* \2 E+ z5 b1 q0 q0 c! A8 M
<><FONT color=#ff0000>函数名: kbhit </FONT>
  T4 h- d9 V0 i& E* I功 能: 检查当前按下的键
3 c/ i6 W' q& f+ h用 法: int kbhit(void); $ ~% W& E% k, J4 e& `
程序例: </P>  k* c' L5 U$ o& g) _1 C
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>) g* C9 S5 {( s. `
<><FONT color=#0000ff>int main(void)
, b2 J7 q6 q3 R$ D9 }" i$ N# [{ 8 O# ]8 q3 Y" y) a; c) m
cprintf("ress any key to continue:");
, e/ b+ L+ j/ J1 W* [% R( C& q8 uwhile (!kbhit()) /* do nothing */ ; : |! X4 |  l; o4 P
cprintf("\r\nA key was pressed...\r\n");
9 t) k8 |# X/ z) @4 Ireturn 0;
2 n  I" y2 R3 _4 @$ H9 X$ C} ! t4 g- N' |6 Q1 F9 f

" M1 ?& i6 a0 O$ |! B# z
8 ~  P% k/ p% s- T$ J</FONT></P>
- d& r- b( R4 J% t4 e<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>  Z# m7 h( \, A8 |
<FONT color=#000000>功 能: 退出并继续驻留 0 g7 G1 S* {+ s. }% Y# x* f- {
用 法: void keep(int status, int size); 6 {  Q7 }( ^6 L% `) }- P  b
程序例: </FONT></FONT></P>% B4 o7 F3 \* H. l
<><FONT color=#0000ff>/***NOTE: $ d0 R- K" i0 j
This is an interrupt service routine. You
" w! [9 i5 ^  {& p+ {( V. ican NOT compile this program with Test
. q. t; T& `, w) \' p" Z0 z) iStack Overflow turned on and get an
) _  _" h6 s, ^8 d9 Sexecutable file which will operate ) ~% g$ {) J2 h7 x2 `5 C" h# k
correctly. Due to the nature of this ' D3 s3 c/ V6 J0 a
function the formula used to compute ( s+ Q9 V2 H0 A( K5 @
the number of paragraphs may not 0 \* v9 E8 e7 ^/ P3 a9 W3 L
necessarily work in all cases. Use with & [1 V5 M" Q1 d. K" [) o$ W
care! Terminate Stay Resident (TSR) ( v( Y$ B- \( x
programs are complex and no other support
2 |4 ~; W4 b1 [8 G: ffor them is provided. Refer to the 1 l0 p# G: G7 f  x
MS-DOS technical documentation $ K' j2 J7 d3 a2 n! [
for more information. */ % z- r, t+ J# k# ?# D- N3 o$ g. q" G
#include <DOS.H>
. v5 q' m) G8 E0 w: B' O1 b/* The clock tick interrupt */
( c5 ?) X. Z) u#define INTR 0x1C
& t9 Z0 a; w5 f1 _/* Screen attribute (blue on grey) */ + f# u; n% z- L. c0 u3 s. S6 u; Q
#define ATTR 0x7900 </FONT></P>
% T9 T$ V9 \" H8 d" _: W1 r9 P" Z! P<><FONT color=#0000ff>/* reduce heaplength and stacklength ) D0 @, u% o. r8 d3 [
to make a smaller program in memory */
1 g$ \9 M8 l  |/ A) F4 rextern unsigned _heaplen = 1024; / m# U+ m1 {, Z4 X2 p- X
extern unsigned _stklen = 512; </FONT></P>
0 L, X- v0 h5 m# i) d+ d. ~<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>% P0 @' i, N  h
<><FONT color=#0000ff>void interrupt handler(void)
: d6 s" o, z+ V4 M, q# a/ D0 U{
% b" D8 S+ y  }! s4 Cunsigned int (far *screen)[80];
, S7 g& o  F/ m: g4 E& Kstatic int count; </FONT></P>- U' I/ G/ c7 G% i4 E
<><FONT color=#0000ff>/* For a color screen the video memory + |* v  D, k! b: G
is at B800:0000. For a monochrome 8 O7 S/ S) n; j
system use B000:000 */ % O! |9 a* p* Z7 i
screen = MK_FP(0xB800,0); </FONT></P>4 f' w+ q9 M( N' u5 I
<><FONT color=#0000ff>/* increase the counter and keep it
# r: Y) n) d- L) s0 u  P  Mwithin 0 to 9 */
9 ^5 y% {: l* Q% R/ ~5 R3 Scount++;
7 K, W: P+ N. c/ v8 _count %= 10; </FONT></P># L. @* e' a9 }
<><FONT color=#0000ff>/* put the number on the screen */
) P. i* h6 b; Y+ Rscreen[0][79] = count + '0' + ATTR; </FONT></P>
" {  K. q+ s$ F<P><FONT color=#0000ff>/* call the old interrupt handler */ - s" Y0 S% L! b: b) E% z7 H; k3 Y
oldhandler();
: S- l# f. o* {7 y! b/ E} </FONT></P>0 b  o% |- K* @
<P><FONT color=#0000ff>int main(void) ' T9 a: c" K( V
{ </FONT></P>
8 N+ H5 |, ?5 V; P, l) `; D<P><FONT color=#0000ff>/* get the address of the current clock
- E3 u3 B' j: x( _3 F3 Otick interrupt */ * a( b& B& Q" v) `! i
oldhandler = getvect(INTR); </FONT></P>
/ J6 Y: m$ h7 A) N6 _0 [: X<P><FONT color=#0000ff>/* install the new interrupt handler */
5 u. |6 h; q) W3 rsetvect(INTR, handler); </FONT></P>0 ]- J4 P0 Q0 f# j. P$ A# Q
<P><FONT color=#0000ff>/* _psp is the starting address of the + K' D8 M+ L! X6 @! \! x
program in memory. The top of the stack
0 k& F3 n2 P4 e& x4 _4 [- Sis the end of the program. Using _SS and 8 U; l# N  X* `! Z, P1 P5 c5 b7 o
_SP together we can get the end of the " X2 f2 d  \" W* E/ }
stack. You may want to allow a bit of
3 w& ^3 x% q# d( S* r0 gsaftey space to insure that enough room
  t; H$ b; r/ sis being allocated ie:
! @+ c. x* E: q7 e1 [& [(_SS + ((_SP + safety space)/16) - _psp) ) l8 _% ?% ?/ K9 G
*/
$ ~: X, O7 [% L, _/ z! a+ wkeep(0, (_SS + (_SP/16) - _psp)); # n" E$ J* d" W) H  u5 \
return 0;
5 ^9 I% C2 }6 |2 d}</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 07:09 , Processed in 0.408142 second(s), 51 queries .

回顶部