QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2237|回复: 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>
0 d' P" ]  d. L" R) h3 F2 U  t</P>
( o) Q- q' k* x8 ?8 F<><FONT color=#ff0000>函数名: kbhit </FONT>2 E! ^0 T: R# H4 x8 ~) N
功 能: 检查当前按下的键 9 |1 \1 \( _- H$ ~
用 法: int kbhit(void);
! e/ H3 K( j- Y程序例: </P>! W6 n! L/ }& B
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
  V8 q6 r9 ]+ @/ q<><FONT color=#0000ff>int main(void) " |, l5 J- B/ |! Q
{ 1 v/ k0 l1 N9 R9 [0 R3 h
cprintf("ress any key to continue:");
% ~! w6 m$ |. J: P4 Pwhile (!kbhit()) /* do nothing */ ; 5 q$ |0 \* n4 c7 ^0 R8 \
cprintf("\r\nA key was pressed...\r\n");
4 w- D4 o+ c* preturn 0;
2 H& w; b% o1 r! D( _( O( q5 a  q} </FONT>
$ D% P6 ~6 f+ o</P>
/ m3 s! }1 A( y<><FONT color=#ff0000>函数名: keep </FONT>8 s# _+ b* k/ y; `# _- `5 x! f
功 能: 退出并继续驻留
" i: c# [# ^, I* k' o用 法: void keep(int status, int size); - E( T5 V$ }" e9 B2 \, o- B- n/ j
程序例: </P>  P6 Q7 ]. d. P: S$ `3 w/ `
<><FONT color=#0000ff>/***NOTE:
& V+ D9 L3 o4 E( P9 W( v, L8 E4 zThis is an interrupt service routine. You
% g* O  |" {1 \& D+ x- ]9 Tcan NOT compile this program with Test
5 l( d7 R7 E- x/ T- ]Stack Overflow turned on and get an * V( h, R6 k0 S. s% ]8 Z
executable file which will operate
" L; L, i8 L  _* @correctly. Due to the nature of this . @: ]; G2 o9 N- k0 \5 C3 f
function the formula used to compute
. O+ p# q# c$ h# V- K& |the number of paragraphs may not
+ p% p! O$ b3 ^6 j% I1 nnecessarily work in all cases. Use with
! ]# d0 m6 K; b6 n9 E0 \  S+ kcare! Terminate Stay Resident (TSR)
5 Q% V+ F. o( W7 _$ [5 Fprograms are complex and no other support 3 M1 m8 g: z8 h# {. s( C* i
for them is provided. Refer to the
( A8 V& e2 u9 A9 G; hMS-DOS technical documentation 3 Q% I; n+ U0 c5 `. c4 `
for more information. */ ; ]$ y0 O5 u- p, r! D' y8 a
#include <DOS.H>
  ?+ p" ~+ q& D7 C; G: H/* The clock tick interrupt */ ( b) q5 ?0 \+ `9 \8 [
#define INTR 0x1C 0 [0 Q' I% M6 [
/* Screen attribute (blue on grey) */ " m* u7 a) B. V
#define ATTR 0x7900 </FONT></P>: ~2 B3 E* w5 z/ ^7 [6 @5 I( p
<><FONT color=#0000ff>/* reduce heaplength and stacklength
: Q$ H. {# g; @- H$ F- G: lto make a smaller program in memory */ 6 V3 a: w2 c1 d! a  @
extern unsigned _heaplen = 1024;
% ]4 C/ d3 x" p. X8 ^; T8 textern unsigned _stklen = 512; </FONT></P>8 u4 v: @" p% L/ ?- D0 E
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
( {: \( f7 C+ H+ |<><FONT color=#0000ff>void interrupt handler(void)
8 h- }3 d0 M# K$ c0 l* U{
1 N3 u5 z8 T7 gunsigned int (far *screen)[80]; ! a8 {7 p3 Q# W+ ?' X6 L
static int count; </FONT></P>
) O+ W* Z9 c. \9 c1 E<><FONT color=#0000ff>/* For a color screen the video memory 8 D% f0 |1 T- c5 Q8 R
is at B800:0000. For a monochrome $ `% D! w: h5 c
system use B000:000 */ ( r3 B5 w& F- `( P. F' E4 W4 F
screen = MK_FP(0xB800,0); </FONT></P>: ]5 y" j. g9 K$ f: C- N8 M8 m* d' i( N
<><FONT color=#0000ff>/* increase the counter and keep it 9 T; T9 i, p- i1 Y, s) J
within 0 to 9 */ 2 ~* r& R* m0 @" _+ }% m
count++; 6 t5 E8 [% f# Z
count %= 10; </FONT></P>
" E7 L; w0 u) S7 R$ D" A5 b0 n<><FONT color=#0000ff>/* put the number on the screen */
( f1 g6 G7 i# v, Q8 L' Mscreen[0][79] = count + '0' + ATTR; </FONT></P>
/ N( ^( @6 i% ?( U/ g" t) v<><FONT color=#0000ff>/* call the old interrupt handler */
7 d1 Y! B2 F% a4 h, aoldhandler();   j" }  n4 X" C1 P
} </FONT></P>
- f1 M8 t4 A# K* ^1 V4 m/ c. s<><FONT color=#0000ff>int main(void)
% r7 V6 T$ A* }7 k: Y1 b, Z% Z{ </FONT></P>) b# S6 F2 R' j7 r7 r3 `# t
<><FONT color=#0000ff>/* get the address of the current clock
0 J+ m% s+ x( c. Htick interrupt */
/ _9 B! T3 I: K1 H* c+ L/ Poldhandler = getvect(INTR); </FONT></P>, e2 b/ Q6 J4 M4 S. m+ t1 _/ n
<><FONT color=#0000ff>/* install the new interrupt handler */ 7 m- c8 n# ~& _6 L9 C6 C
setvect(INTR, handler); </FONT></P>
% d( F: s1 K6 M: A2 I<><FONT color=#0000ff>/* _psp is the starting address of the
" v6 S2 I* {% j2 q$ \, ?/ P6 Fprogram in memory. The top of the stack
; H: L, l& m6 Mis the end of the program. Using _SS and 9 A& Q2 K! t( A6 J, g, p
_SP together we can get the end of the 4 M+ p  z. d2 n
stack. You may want to allow a bit of - z: a/ v6 [4 ?2 n3 `
saftey space to insure that enough room 5 r$ l+ R9 E* L1 G4 @7 h; _
is being allocated ie: 7 W: S" S* m$ K+ O
(_SS + ((_SP + safety space)/16) - _psp) ; i: K$ t* e5 X9 L0 d' b
*/
7 r% J2 z* R- F* t- c' K1 Z5 jkeep(0, (_SS + (_SP/16) - _psp));
4 T% `6 v$ W* m- c. I5 z7 Wreturn 0;
! w* Q! E8 {% F* A}3 t% `9 b# h) {1 T+ g
</FONT></P>
$ \) a% `  q1 n4 N" ~( D' Q5 C' ?" v& M" O
6 f: A5 d; F# s& t- s
<><FONT color=#ff0000>函数名: kbhit </FONT>
5 ~+ k, Z  z. H' Q- A, Z功 能: 检查当前按下的键
& c5 @9 Z" w4 g) K. ?用 法: int kbhit(void);
; u$ E( a5 {1 j  f9 h程序例: </P>
3 V1 {" v4 d# n; v0 _7 G4 j<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
$ W7 g' E  b7 @) e2 D2 g  P2 Z<><FONT color=#0000ff>int main(void)
0 S* U& U# ]9 r# e2 X- z/ y: h{
3 }8 v" G' F: C& `" b8 {: Ecprintf("ress any key to continue:"); 3 h+ m" V8 \% }6 z) m6 d: m4 x
while (!kbhit()) /* do nothing */ ; & W2 r4 A+ u* C* A$ m" K
cprintf("\r\nA key was pressed...\r\n"); 8 i. q* G* G. Y0 h' H" g8 {/ y
return 0;
/ P; Y& |! ]/ q}
( a& o# ~: M& u! C0 L7 n4 O# E' y* u8 P0 U! i

4 A  C+ g# v! J1 Z' \% p' w3 n3 i1 M</FONT></P>
& c0 S0 T) p2 ^<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
4 Q3 y9 L5 x. _<FONT color=#000000>功 能: 退出并继续驻留 $ o! k6 L! q5 j( }
用 法: void keep(int status, int size); ! a, k: [0 ~0 P: q9 v
程序例: </FONT></FONT></P>3 _/ c9 |6 k3 n* E! {0 }
<><FONT color=#0000ff>/***NOTE:
4 E1 j, d8 ?+ Z* f4 o# n, YThis is an interrupt service routine. You
. l6 i3 c' P0 i2 A1 _* ]can NOT compile this program with Test 5 r2 E& d1 h! q# T
Stack Overflow turned on and get an
) s1 L9 [/ a3 C. K$ nexecutable file which will operate
4 f: I5 y2 k% Ycorrectly. Due to the nature of this . s4 Z4 i% L; x; F9 q7 b0 a
function the formula used to compute : D+ y' I6 e/ C6 @# Q7 k
the number of paragraphs may not 0 L3 z1 e0 P; r' W. h
necessarily work in all cases. Use with " ^  K" C; ^' S( p
care! Terminate Stay Resident (TSR)
5 q/ Q1 J( j+ }programs are complex and no other support + M; Q5 s% \6 ]3 ~
for them is provided. Refer to the ' J$ W# V# @) ]9 t; A5 h. u
MS-DOS technical documentation % x! c* ^( h% ]( d2 Y
for more information. */ 3 V  h9 E7 U9 D. U) P1 k
#include <DOS.H>
% f9 K; W, i7 y9 J8 c0 h/* The clock tick interrupt */
3 K/ ]" Y% G% t4 \3 q#define INTR 0x1C $ q0 {' B0 q1 k4 ~, \7 [; N% {0 q
/* Screen attribute (blue on grey) */
& j( K# ~$ k7 J8 R% K7 L/ x#define ATTR 0x7900 </FONT></P>
# p) t  x0 U$ q<><FONT color=#0000ff>/* reduce heaplength and stacklength
- p9 G( n& i, h, p( Mto make a smaller program in memory */ # [8 j% b0 N8 Z/ n" ?
extern unsigned _heaplen = 1024; 3 a$ k4 _  V2 U1 L: a" h
extern unsigned _stklen = 512; </FONT></P>
  [4 z' @* q  c) `( |) C<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>/ F, M9 x& X  T
<><FONT color=#0000ff>void interrupt handler(void)
- }3 I* c8 g' ?{ 9 j* S3 ]/ i4 }) F) l  Y
unsigned int (far *screen)[80];   ~/ N8 B+ t, [
static int count; </FONT></P>
; W) v/ b. x, V1 _' `7 T<><FONT color=#0000ff>/* For a color screen the video memory ) w! d, f7 J' Q* J- j8 u0 ^' u
is at B800:0000. For a monochrome
& k7 Q2 \$ R1 ]3 Z. i' H& f" M; Vsystem use B000:000 */ ) d# r; F/ ]1 e
screen = MK_FP(0xB800,0); </FONT></P>
; h2 k, l9 _) b9 K+ w  B! ^<><FONT color=#0000ff>/* increase the counter and keep it 2 F7 d' b" I4 q3 U
within 0 to 9 */ 3 K9 e2 @* M/ p6 f1 R& x
count++;   z1 t; K. p& A; b
count %= 10; </FONT></P>
' ]' t6 ?8 `/ L  }1 R: N5 Z3 _<><FONT color=#0000ff>/* put the number on the screen */ ! {/ |3 D; H4 s/ p$ P8 N
screen[0][79] = count + '0' + ATTR; </FONT></P>
1 K4 J4 `2 |1 C0 t; E<P><FONT color=#0000ff>/* call the old interrupt handler */ % @1 G) F, k, A# J
oldhandler();
3 u2 P8 i# i8 w( n3 z4 c; A} </FONT></P>
5 a) m- I) ^/ _& M% u. o<P><FONT color=#0000ff>int main(void)
! u  n& ~3 o* x  B6 Z6 d{ </FONT></P>+ n( g; j$ Y6 q" B, H+ K
<P><FONT color=#0000ff>/* get the address of the current clock
/ [( R  x+ T9 [7 @/ C& _tick interrupt */
, V. P9 S$ [7 T9 U2 i) f4 }oldhandler = getvect(INTR); </FONT></P>
4 D* M$ c1 P$ _% w! e* }<P><FONT color=#0000ff>/* install the new interrupt handler */
* F+ @+ i; T3 z2 ksetvect(INTR, handler); </FONT></P>3 _2 X, v& H: _. a$ W
<P><FONT color=#0000ff>/* _psp is the starting address of the
, B1 n$ i6 T: Y  ^/ d% A2 F$ z' tprogram in memory. The top of the stack " {/ u: }: _( F6 _# ]; w+ V
is the end of the program. Using _SS and 7 b9 c8 u: s. d3 {6 Z% u
_SP together we can get the end of the / S" h2 n$ |/ `, g3 w
stack. You may want to allow a bit of
: e9 G/ i/ r9 [. F$ s& T) }2 Q# B$ msaftey space to insure that enough room & Q) J- m" R" }+ ]8 c" q
is being allocated ie: - U4 j0 h) m' M8 {+ d. k5 w6 D
(_SS + ((_SP + safety space)/16) - _psp)
4 q& l9 Y9 Q5 y/ ]" e" E/ h*/ 4 n! h/ b5 R1 G3 G3 Q, W
keep(0, (_SS + (_SP/16) - _psp));
) D3 c' u. }) F8 s7 N6 a( jreturn 0; ! h, F  ^: r1 l# \2 q& N
}</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 06:15 , Processed in 0.313879 second(s), 52 queries .

回顶部