QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2260|回复: 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>
1 G. y0 F$ U# p5 O</P>! Z$ x  S2 w3 |  D1 b/ L
<><FONT color=#ff0000>函数名: kbhit </FONT>+ f4 h% j+ B- U, `2 d8 y7 ~- k* S
功 能: 检查当前按下的键 3 ~9 E4 T; Q; J+ k, x; P: H9 G
用 法: int kbhit(void); $ E" E8 J% m- \, ]: u' u
程序例: </P>
: w" n! {) v- Q: k2 g9 U' L<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
' o) L  O6 `* _# G/ U" l, ?<><FONT color=#0000ff>int main(void) 7 k2 i* k* ^9 ^) z+ U
{ : J" g( S2 Q! R. g& d
cprintf("ress any key to continue:");   y' c8 ~: W+ R) |0 D4 \9 s
while (!kbhit()) /* do nothing */ ; ( i. v9 w2 A( ~. z
cprintf("\r\nA key was pressed...\r\n"); . \% I8 C# H7 _
return 0;
' t% E( Y# d8 P} </FONT>" |" ]( {' @3 q6 X: G" J/ }7 i
</P>8 a4 N' O2 \0 t  {  {
<><FONT color=#ff0000>函数名: keep </FONT>
( e0 h8 g1 Q% u7 S功 能: 退出并继续驻留
# V3 b4 i9 c: I0 w0 a6 B$ b, n用 法: void keep(int status, int size); ' t2 [* ]7 P; ~1 f
程序例: </P>: k& }- s, V" b7 x" J; X
<><FONT color=#0000ff>/***NOTE:
4 H, z- l% T& C# vThis is an interrupt service routine. You 7 F3 O% ~8 X3 m* X% ~0 i$ s
can NOT compile this program with Test . |" g0 D4 D% n1 V
Stack Overflow turned on and get an
9 U/ E5 x; c4 M" _+ k" P3 X" Kexecutable file which will operate
0 t5 @6 P5 v# z$ j: Dcorrectly. Due to the nature of this * R% N0 _: V; g
function the formula used to compute 1 s1 |/ \. \( M, N8 ^5 u
the number of paragraphs may not
! Q6 n) c$ J( o2 X4 @necessarily work in all cases. Use with - V, V- M+ t3 A% [, g
care! Terminate Stay Resident (TSR)
, S6 d/ ^$ M0 A* D+ R# V4 pprograms are complex and no other support 9 y# T; n% A: m# V0 X
for them is provided. Refer to the
, W! S0 j! s) f1 v. LMS-DOS technical documentation
2 r/ \: b/ a1 Zfor more information. */
* D2 l+ U; O5 X9 ~  ^#include <DOS.H>
' R# U( l. ^7 }$ l/ Q; Z+ L/* The clock tick interrupt */ : _* C  [  L" _# u- m
#define INTR 0x1C " _% s" _: t+ Y
/* Screen attribute (blue on grey) */ ) x4 B, ~7 z5 ~+ I1 c+ w
#define ATTR 0x7900 </FONT></P>7 K, _7 p3 F$ ]; ?
<><FONT color=#0000ff>/* reduce heaplength and stacklength 7 L# [3 x4 c1 _& q- Z# E
to make a smaller program in memory */
! I$ t% G' x& [' ~2 U5 j1 |1 rextern unsigned _heaplen = 1024; ; j6 O) m, w1 }
extern unsigned _stklen = 512; </FONT></P>4 d0 ?! S* t9 M2 ~6 y2 ?+ w5 z
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
. t$ u' R0 m2 D2 t. `% z5 i' r) H<><FONT color=#0000ff>void interrupt handler(void)
  \/ W3 t3 J5 O: C{
2 D+ x- T% c& a( z7 |% Dunsigned int (far *screen)[80]; ) R6 ?' P. y5 q4 I9 k" p
static int count; </FONT></P>! J. V9 w+ v4 T/ J( r4 d3 y, J) {
<><FONT color=#0000ff>/* For a color screen the video memory
" R' i. U) e/ D4 z- L/ Eis at B800:0000. For a monochrome * b" F7 y" n: s/ L. E" Z$ K5 j
system use B000:000 */ * k2 Y# H8 |. K2 d7 B: X7 ~# C. Z
screen = MK_FP(0xB800,0); </FONT></P>
3 A8 H! d: l+ a/ z8 O: }5 _7 `<><FONT color=#0000ff>/* increase the counter and keep it - v- a$ j. L: @; Z
within 0 to 9 */ " i9 o0 ], @6 \: ~1 C3 K4 X
count++;
; e: G! V5 u. {4 dcount %= 10; </FONT></P>4 e  R  U% ]% ?
<><FONT color=#0000ff>/* put the number on the screen */ ! m6 k" w$ x7 y+ |5 ]+ W1 \" m+ v( z
screen[0][79] = count + '0' + ATTR; </FONT></P>% R  K0 ^, ~0 J- m& `# r7 W" }- E
<><FONT color=#0000ff>/* call the old interrupt handler */ $ b  ^5 n$ F+ L3 v; q: ^
oldhandler();
5 m0 S8 @4 E  f  B4 U, n. E9 i4 [6 H/ x} </FONT></P>( P7 \* Q2 c9 K& m
<><FONT color=#0000ff>int main(void)
  D% w3 F7 j5 h$ R7 A! a  {{ </FONT></P>2 I9 j  e! p. W; L. L5 E6 }. z/ J
<><FONT color=#0000ff>/* get the address of the current clock
: F) Q3 t9 P. ktick interrupt */
; @" c# Q! k$ |) e3 Aoldhandler = getvect(INTR); </FONT></P>- u; N: C1 d& v' d- x7 H
<><FONT color=#0000ff>/* install the new interrupt handler */ - |5 ^) _, x, d+ J$ E
setvect(INTR, handler); </FONT></P>
. l& `: d+ q; k<><FONT color=#0000ff>/* _psp is the starting address of the 9 ^- O, D8 M7 m9 U6 n2 O2 m
program in memory. The top of the stack
( A5 v  a: j+ p! qis the end of the program. Using _SS and ( Y: _& |5 d! [; k4 _" c# Z' l- e
_SP together we can get the end of the
0 R! T, v3 E5 g) B2 s9 Y* j/ Ustack. You may want to allow a bit of ; f% O# l" h' u1 J* @
saftey space to insure that enough room / Q- p" J7 Z- J, W: o) i
is being allocated ie: ; i- z- B4 b6 x/ k1 h6 s: p
(_SS + ((_SP + safety space)/16) - _psp)
# E! J) f) G* C3 L*/ ( K* Q* k% c5 a4 B1 \0 Y: n8 v5 R
keep(0, (_SS + (_SP/16) - _psp));
& m1 j0 N7 t7 O0 Vreturn 0; 6 X+ r5 `: Z- i1 s9 K, s
}
! b6 y  w' Q3 b</FONT></P>+ I, ?4 o5 J, [* F, x. K
; R/ q& E) }; J

1 c* s( G/ [+ i: o) P+ A7 i<><FONT color=#ff0000>函数名: kbhit </FONT># @7 {& J0 x" I
功 能: 检查当前按下的键
  n! |( E; E- X2 _7 \用 法: int kbhit(void);
; }' p* D5 }  l  q8 K% e程序例: </P>, e( ~: X. T& d
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
' E7 X8 d" ?+ F* }$ H<><FONT color=#0000ff>int main(void)
$ _* N* ?7 X6 s) y5 ~: v- Q{ / [) y* G3 f) N4 |, W
cprintf("ress any key to continue:");
. n) ]2 J& U+ R4 ewhile (!kbhit()) /* do nothing */ ; . ]# ]' P3 _' z, \1 f9 }, j
cprintf("\r\nA key was pressed...\r\n"); * d7 E" L# d; V& q2 c
return 0; 4 u  q0 a( {& G
}
- o1 ]+ H, O; z( E& k/ \" K: g% B5 K$ _6 {8 {' o

# Q* \: q" M9 V5 ?  k1 v. I</FONT></P>8 C$ T. @! y; U! `: U# r
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>- c8 {% e( }% k# ?) y
<FONT color=#000000>功 能: 退出并继续驻留
: f1 Q, _( k  V) e- e用 法: void keep(int status, int size);
- M+ I# v2 n% I' u; ?3 m1 ]程序例: </FONT></FONT></P>2 _& `% i; V0 Y" L
<><FONT color=#0000ff>/***NOTE: 7 J& b: k5 b* e2 _
This is an interrupt service routine. You
6 a7 t7 L2 ~6 _' V$ w9 u: hcan NOT compile this program with Test 2 `* u9 e) x$ g; Y6 f' k5 {$ ^
Stack Overflow turned on and get an
! s; J, [4 p4 d8 K+ l* uexecutable file which will operate " i7 U- q2 j1 O% J! ?& g) _: V6 J* ~
correctly. Due to the nature of this
  z; ~$ S! U& W4 Y# Y2 b) Cfunction the formula used to compute
: c5 j, ~  u( c! Nthe number of paragraphs may not
/ {/ z/ W+ q/ A. Q4 K: D" O1 ~necessarily work in all cases. Use with 1 j; @5 h) r9 h, D# a4 @6 t
care! Terminate Stay Resident (TSR) * K0 |! n6 N. Q2 i
programs are complex and no other support : x0 b" r( d& E% Z2 k) _
for them is provided. Refer to the
$ C/ y( q+ g6 T+ q2 I& cMS-DOS technical documentation % Y" d5 U. z4 m
for more information. */
$ e/ p. H8 z2 i3 W% g#include <DOS.H>
4 j5 B5 V7 b; s0 o$ R/* The clock tick interrupt */ ) M* e9 J/ ?3 G9 A; Y1 |; q
#define INTR 0x1C
) U8 a) ]. P  o# G/* Screen attribute (blue on grey) */ + P6 j) I( O+ I- S; K
#define ATTR 0x7900 </FONT></P>
* @- E3 U/ Q( P# x4 v+ o<><FONT color=#0000ff>/* reduce heaplength and stacklength   @$ K( ~6 T, w  a) G
to make a smaller program in memory */ 5 w5 m2 x; l4 k  t0 \8 @7 L" Q
extern unsigned _heaplen = 1024;
3 t6 g9 X/ l& H% Oextern unsigned _stklen = 512; </FONT></P>
! I( ^  H! p! O) @<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
- z7 q% K, t) J. O7 p<><FONT color=#0000ff>void interrupt handler(void)
/ O0 e, _2 X" K% A" `{
5 O' r, o6 R& k' l) L2 V% Punsigned int (far *screen)[80];
# G& y/ I2 L% W* h2 Ostatic int count; </FONT></P>
0 m, W; ]! c% S0 P" U. u<><FONT color=#0000ff>/* For a color screen the video memory ( s2 G! V! i- l* B
is at B800:0000. For a monochrome
. D( W/ j: |, n! |7 e2 Gsystem use B000:000 */
4 P  q' E7 i, e1 V- L1 K* o# Rscreen = MK_FP(0xB800,0); </FONT></P>/ d& e0 C4 [6 S  p+ P- T5 L
<><FONT color=#0000ff>/* increase the counter and keep it
# R2 k& u) {/ ]8 ~, r3 O) qwithin 0 to 9 */ ) Z" z7 D" j. h! a
count++; 4 _8 W* l" ]! y% K
count %= 10; </FONT></P>
) ?2 I- t0 g9 S$ T2 B) K<><FONT color=#0000ff>/* put the number on the screen */ / T# f/ N  f+ p  P* U: {, ]6 |1 v
screen[0][79] = count + '0' + ATTR; </FONT></P>) x$ s5 n5 m1 M/ l7 ?2 w
<P><FONT color=#0000ff>/* call the old interrupt handler */ & E1 \% S( K7 w  A% x; f3 h: K* ]
oldhandler();
6 u# e6 [9 E$ p} </FONT></P>2 g5 V! O( B% S
<P><FONT color=#0000ff>int main(void) 8 @' ^" ?/ P1 ]$ x' |4 f2 w2 b
{ </FONT></P>
( K8 j) C  D2 U: G: U/ E<P><FONT color=#0000ff>/* get the address of the current clock ! b- P0 g# v; u) n
tick interrupt */
( @1 A# q* @7 h. r2 @7 Foldhandler = getvect(INTR); </FONT></P>
( F7 g% y- ~! ~5 y! h<P><FONT color=#0000ff>/* install the new interrupt handler */   h6 Q( _4 }2 e' a6 y) K
setvect(INTR, handler); </FONT></P>6 O  g/ f+ |. k9 X% k
<P><FONT color=#0000ff>/* _psp is the starting address of the
7 R6 F# g$ B) T, U5 Aprogram in memory. The top of the stack
+ G* m5 |0 @( L) H9 K& fis the end of the program. Using _SS and
! a, f( T; v7 I9 s9 Q+ E_SP together we can get the end of the
  h: }- b! \9 |6 ostack. You may want to allow a bit of ( o/ x1 R* ~! P* N
saftey space to insure that enough room   L  E5 Y9 N( j$ V* d. w4 p
is being allocated ie: 8 X2 F/ T( H0 n; C% Z
(_SS + ((_SP + safety space)/16) - _psp) . l* V) Y) r& l5 `
*/
  F0 l! a0 E7 W4 t0 I8 M( L# Kkeep(0, (_SS + (_SP/16) - _psp));
4 I; U7 S' K0 `! k/ yreturn 0;
: u$ a5 E7 A" N" O  W}</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 01:15 , Processed in 0.479565 second(s), 51 queries .

回顶部