QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2245|回复: 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>
9 c' E0 {9 w, v</P>  B" _  Q( x4 c4 q+ z0 p
<><FONT color=#ff0000>函数名: kbhit </FONT>' S' r+ b  R; h
功 能: 检查当前按下的键 7 H# l+ L0 f' @: j  j" G
用 法: int kbhit(void);
& f: C: O* ^" t. I9 D* Z  ]7 U程序例: </P>3 u7 g: i$ }/ o) q3 Y4 A/ s
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>7 Y( b$ |0 B& i
<><FONT color=#0000ff>int main(void)
9 U, ^! K- {1 O' ^; J{
6 W& Z# B% J& T9 F: x2 g) Scprintf("ress any key to continue:"); 4 W) m/ `. p, \0 A2 ?4 f
while (!kbhit()) /* do nothing */ ; ) g% _9 C( N# {
cprintf("\r\nA key was pressed...\r\n");
  S+ i* }; s$ z& Y7 D! Q& breturn 0;
, b% I, Y: t* M} </FONT>, v5 {/ b  C: z: z$ L3 ^( ?
</P>9 j  I: _- L$ s6 a( N
<><FONT color=#ff0000>函数名: keep </FONT>
1 S: K) _! S: E* E& k功 能: 退出并继续驻留
; F' f  ~- ^6 A  r8 b用 法: void keep(int status, int size);
+ `& a1 P, t; _  t9 s+ e1 P程序例: </P>2 q1 _1 J' h. a4 H: E3 K
<><FONT color=#0000ff>/***NOTE: 2 K; A1 o+ b4 K
This is an interrupt service routine. You 9 h" K; |- p: J2 Z& G
can NOT compile this program with Test
+ ?; S/ J1 f1 V3 qStack Overflow turned on and get an 7 M* F, ~4 F+ D2 S$ e3 q9 K0 U
executable file which will operate ( t; d6 ^" m9 R+ r2 {! p& M
correctly. Due to the nature of this
4 G9 G7 D: D( x, Mfunction the formula used to compute ( p$ C- o: c/ p- G( L
the number of paragraphs may not ) _9 M# n$ j3 g+ K: v& ~
necessarily work in all cases. Use with
; O/ C4 Z0 h+ ]; i( ?6 Z, X; qcare! Terminate Stay Resident (TSR) # X9 e. o: ~, {, k. B- L: E
programs are complex and no other support
, k# j* \! a" [5 L3 gfor them is provided. Refer to the
  c" O! v6 U7 M* m6 P6 UMS-DOS technical documentation 8 l1 U  j! C3 K$ h$ Z/ h
for more information. */ 8 {( V. `. ]9 E- b; }5 ?6 g
#include <DOS.H>
5 B' w" ]" O9 V# K: Z- V/* The clock tick interrupt */
  x$ ^+ B5 B2 z; n#define INTR 0x1C & p/ w3 s9 P8 }9 y+ `2 a# R7 C
/* Screen attribute (blue on grey) */
% x  y( m2 u. i#define ATTR 0x7900 </FONT></P>9 H# f( f* l6 g& d) F$ o
<><FONT color=#0000ff>/* reduce heaplength and stacklength
0 M, |$ G! F; M6 pto make a smaller program in memory */
. B" u4 K5 V  _7 V; e1 H& n& Sextern unsigned _heaplen = 1024; 9 q* q0 e+ Y1 Z. R3 V
extern unsigned _stklen = 512; </FONT></P>* ^" W. r5 O* h5 r, e
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>  z( u$ s4 E  U  U6 f9 V3 S+ Y
<><FONT color=#0000ff>void interrupt handler(void) & d3 i" J4 E# n% F# I2 M# P$ U. N
{ 3 u/ v7 @" g3 b- Y" O
unsigned int (far *screen)[80]; 9 Y: C! r$ g3 ?. N' Z1 {
static int count; </FONT></P>: O  f/ z& f* H" u8 q7 n! T
<><FONT color=#0000ff>/* For a color screen the video memory 0 S7 f1 M' R7 f* G, S# K( }
is at B800:0000. For a monochrome
3 t) y' ?2 q& _$ N, U4 @2 L4 nsystem use B000:000 */ 8 p9 v. w" d: m
screen = MK_FP(0xB800,0); </FONT></P>
# @& d6 ?! G. P! G5 t0 p4 @8 U# o# S<><FONT color=#0000ff>/* increase the counter and keep it $ K$ F( N/ U( j% r+ T
within 0 to 9 */
' H" w  v8 C9 ^' l: \count++; 5 e6 a3 o' b3 q. W
count %= 10; </FONT></P>7 z8 a) I( E! O  q! I
<><FONT color=#0000ff>/* put the number on the screen */
: h" N: |, o# _# f* Nscreen[0][79] = count + '0' + ATTR; </FONT></P>8 K  Q$ U' R! i( G3 Z/ z
<><FONT color=#0000ff>/* call the old interrupt handler */
5 R8 _; }8 i" ?oldhandler(); ( q- E; f* f: n" S1 z1 K3 J
} </FONT></P>
0 o6 z' d! D- H7 k' \" k<><FONT color=#0000ff>int main(void)
) u- X2 N" E7 [{ </FONT></P>0 d5 }% U6 }0 U5 F3 V4 |2 j' g2 O, i
<><FONT color=#0000ff>/* get the address of the current clock / L" A/ L4 I5 j6 `- O4 T
tick interrupt */ 1 B+ Z, S% D( y. i% i! H
oldhandler = getvect(INTR); </FONT></P>
8 K; }' y1 V4 Z+ v/ E% I. m<><FONT color=#0000ff>/* install the new interrupt handler */
' Q3 y. C) _) jsetvect(INTR, handler); </FONT></P>4 P3 F/ u/ o- ]& d  v
<><FONT color=#0000ff>/* _psp is the starting address of the ' A* @; l* s  B/ v; Z
program in memory. The top of the stack
8 C1 S; x/ c& ]) Y  Y3 Y2 M9 _. Kis the end of the program. Using _SS and 9 R4 H, f' p( S$ L; {
_SP together we can get the end of the
* P1 n" Y' g# |6 ?. ]. c: Ustack. You may want to allow a bit of
4 _. Q6 c; h# Rsaftey space to insure that enough room ) T0 W* V( P$ |7 v7 k0 O" Z- d4 X
is being allocated ie:
* j. ]# ]1 G, Z$ {; ^% e" @4 W(_SS + ((_SP + safety space)/16) - _psp) 3 |& X. h6 s2 |" D
*/
* C" u' [& u! x6 Wkeep(0, (_SS + (_SP/16) - _psp));
" f( s- @% Q( s$ hreturn 0;
2 ~: ^# z7 \3 Q* T& B- k* l5 Y) [1 m}
' B& q$ ]/ ~  w) P1 e1 ]# e</FONT></P>
2 G- n$ {* A- l7 w$ ]( f0 X% @/ n+ \7 ^/ K! ^  k
: M$ V* ~. j1 N: D
<><FONT color=#ff0000>函数名: kbhit </FONT>
8 k3 v* f( `! |( b* h2 V% H功 能: 检查当前按下的键
/ O" M. [4 H: Z% v5 |& F5 u用 法: int kbhit(void); : j" f. Y" P0 q3 d0 q  a
程序例: </P># P; `* p( c: Y; G
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 v6 k! r( Q8 @+ h3 `3 h1 W
<><FONT color=#0000ff>int main(void) 2 ^/ t( c; Q& U. q3 ~8 k
{
" \2 D5 `: M4 q) I$ ucprintf("ress any key to continue:"); , h7 k: Q; Z9 o: Q# U* J
while (!kbhit()) /* do nothing */ ; / h# \$ |2 o3 I, r  b! F# R
cprintf("\r\nA key was pressed...\r\n"); - R, B$ D" s; Y9 g1 H
return 0;
6 R5 u' e/ q3 }6 y}
; o0 b. g# ?$ Y; Q. v7 U( l9 I6 n

  P) H# k0 ?# |  j/ V# z</FONT></P>' ?( w3 U; e! C. M" E4 F
<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
, W! I3 ?2 r$ o8 T0 E3 D7 L<FONT color=#000000>功 能: 退出并继续驻留 9 W5 t. ^# k: T+ U
用 法: void keep(int status, int size);
& |$ R4 C9 S3 w程序例: </FONT></FONT></P>2 U; `& Y. }0 T3 `
<><FONT color=#0000ff>/***NOTE:
* P# U, s" D" X! ]This is an interrupt service routine. You 2 u( R: W2 y4 J! `$ L6 [7 }: m
can NOT compile this program with Test
( P( X2 R8 _0 X- {" G6 ^4 @Stack Overflow turned on and get an
. y9 N9 n% f% Uexecutable file which will operate ! Y2 O: b6 x: T0 w
correctly. Due to the nature of this ) h' }& k2 S$ k5 M0 \( G, [' ~' t
function the formula used to compute
6 ~1 `' q3 U' \7 k/ ^8 ithe number of paragraphs may not ( D  ?  T* _3 x9 G7 P
necessarily work in all cases. Use with 6 ~+ t# v: B: W  |( s5 Y) @
care! Terminate Stay Resident (TSR)
% |2 r# s  P2 ]( U; wprograms are complex and no other support : a/ H, y/ G7 B+ T
for them is provided. Refer to the ! t- r' p2 \- Y+ c6 Y6 G
MS-DOS technical documentation
5 [6 O. v( \. @& U1 \. i' Xfor more information. */ : k# d. S9 f! [6 x
#include <DOS.H>  X; U; e. ^/ z$ r
/* The clock tick interrupt */ ' U7 d; [( y: d( p  |
#define INTR 0x1C
. R) ]* X5 v3 Z+ k( O$ p+ B7 s/* Screen attribute (blue on grey) */ * f0 G+ y& i! B' |
#define ATTR 0x7900 </FONT></P>1 d, _0 b, w) r
<><FONT color=#0000ff>/* reduce heaplength and stacklength * Q) R( t/ Z3 ^" C! b! E" ~
to make a smaller program in memory */ 6 T) `9 a9 V) H! C! P' z7 ], n
extern unsigned _heaplen = 1024;
: F2 r% Q4 _- c! c7 Jextern unsigned _stklen = 512; </FONT></P>- m  S* K, p/ K3 j& }& A3 @" ~
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>. A, T) e5 p( g4 W4 E
<><FONT color=#0000ff>void interrupt handler(void)
9 V% _7 l" d4 s" E9 u; [7 }; S/ T{
  u7 w& @/ J& j& T3 q+ aunsigned int (far *screen)[80]; ! s( N4 G1 ^1 R8 J! q1 Q$ V" z  {
static int count; </FONT></P>
3 O% ^/ ~9 {5 ]1 {$ k$ M<><FONT color=#0000ff>/* For a color screen the video memory
  W" F$ G1 M( \* H) j$ V  ?; d4 Cis at B800:0000. For a monochrome " V- A% q* w, C: R
system use B000:000 */
8 [4 h, K( y# ]' ^/ V* g; |screen = MK_FP(0xB800,0); </FONT></P>
" f, \6 E' G- r4 n3 O9 O" t) n<><FONT color=#0000ff>/* increase the counter and keep it - J1 H& G& j7 G: g# k
within 0 to 9 */ # A. I; |0 E4 h9 a
count++;
2 y0 x2 @* O: S4 ~! y+ V$ mcount %= 10; </FONT></P>
& V( B" Z+ O3 n9 s3 e<><FONT color=#0000ff>/* put the number on the screen */
) F/ Q* E: H/ F0 tscreen[0][79] = count + '0' + ATTR; </FONT></P>, n" j7 R6 s% u" X1 h; t* X  t
<P><FONT color=#0000ff>/* call the old interrupt handler */ 2 R! _( U5 k6 P0 n' w3 X* D$ [
oldhandler();
1 ?! K+ @, P4 T} </FONT></P>2 M3 ~) d9 P2 f' t& R* j, Q1 j
<P><FONT color=#0000ff>int main(void) 5 M( ]4 a0 f- r2 q
{ </FONT></P>. R, U$ l/ d, A+ b1 M& A' y
<P><FONT color=#0000ff>/* get the address of the current clock ' Y+ D9 d3 A; g# w8 C" g
tick interrupt */ 9 Q( k! ^/ z, U; G) U
oldhandler = getvect(INTR); </FONT></P>
; h0 o! J, f5 L<P><FONT color=#0000ff>/* install the new interrupt handler */ / g- F( B  O8 n. x; i# R  l
setvect(INTR, handler); </FONT></P>
7 \1 P* F0 I9 e/ n( ^& E: s2 E<P><FONT color=#0000ff>/* _psp is the starting address of the
. c8 x: L8 Z. p! J0 M/ X; tprogram in memory. The top of the stack
, V, i3 x1 ]4 z1 e6 vis the end of the program. Using _SS and ) |0 W. [+ I3 t
_SP together we can get the end of the . ^5 T# T; ~9 V; p
stack. You may want to allow a bit of
: }+ x; }3 j" Z" isaftey space to insure that enough room 1 _; E7 P2 f3 l. l0 M
is being allocated ie: 5 o- u  l0 {, k. a
(_SS + ((_SP + safety space)/16) - _psp)
3 ^7 M" C, l4 ~, @*/ 5 @2 R( |% M# d* l* c5 l
keep(0, (_SS + (_SP/16) - _psp)); ) ]+ C+ _7 I  S
return 0; 9 B5 N& L3 z5 u- c1 F" x/ 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-4-22 01:31 , Processed in 0.591333 second(s), 52 queries .

回顶部