QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2238|回复: 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>
4 z) N, W& Y6 V) `</P>: q! B0 v6 l5 R  B3 w0 P
<><FONT color=#ff0000>函数名: kbhit </FONT>% G; i" A" d3 K7 `; z
功 能: 检查当前按下的键
. V. e6 r; f+ j# d: e" s" I  k用 法: int kbhit(void);
4 i; |0 V4 ~9 w1 R7 X程序例: </P>- c' C7 x0 d5 u2 [9 g1 N
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
9 @  ?7 Y! c4 @<><FONT color=#0000ff>int main(void) 1 h! G: m# n2 I4 m/ k
{
" e% G6 @0 [/ wcprintf("ress any key to continue:"); ! {6 R4 X& T0 p/ _5 c
while (!kbhit()) /* do nothing */ ; - R% U/ W& I( M
cprintf("\r\nA key was pressed...\r\n"); - T; o7 i, i' r8 ^# w' U% J6 e( V, i
return 0;
% m% U. M( C1 O: o1 i} </FONT>
( L" D- S" E. ?& }, Q: M- }! |1 h! \</P>
8 c4 H7 ^" R, o0 Y; ]1 ]* ~) q6 E" S; c<><FONT color=#ff0000>函数名: keep </FONT>& ~1 K2 h( m) t( G
功 能: 退出并继续驻留
7 u* X: D7 A4 ]+ X$ r用 法: void keep(int status, int size); ! H' g1 f8 p5 y1 F" o
程序例: </P>9 s! z: N( W8 K0 h
<><FONT color=#0000ff>/***NOTE:
4 V4 ^) v: \& q4 qThis is an interrupt service routine. You ' h8 g+ y: A3 j# M  ?. E
can NOT compile this program with Test   l( y0 F2 D( X/ E) b# U
Stack Overflow turned on and get an
0 L1 W# J3 w. u3 f$ cexecutable file which will operate
" l# f* l8 o+ r1 b7 q5 u# U' Bcorrectly. Due to the nature of this : Y3 k) V1 T! [6 r' t# y2 o
function the formula used to compute
1 p, c2 ?3 A& G! x- R3 s; R4 Fthe number of paragraphs may not
2 @8 x8 [5 w# _7 q1 H+ J- J9 enecessarily work in all cases. Use with % K& _  j* A1 ?/ e$ w) q: R4 U! h
care! Terminate Stay Resident (TSR)
* }7 D5 Z: ]' B2 ]" b& T: Iprograms are complex and no other support   |; S) ~, b! n1 }6 s. T, M6 F
for them is provided. Refer to the " v, k% h3 N4 @8 R2 b* j# p
MS-DOS technical documentation
  J4 s% x3 h+ U  V# J4 X# Bfor more information. */
! L1 m, O0 Y; n- C# u  e#include <DOS.H>* F, c9 s' l8 O* y6 R
/* The clock tick interrupt */ " Q0 j% T( L2 S7 u& R. {8 \( I* u
#define INTR 0x1C 7 m7 K, {& m( }% }
/* Screen attribute (blue on grey) */ - f, C8 Q! Q9 u9 o/ A. h
#define ATTR 0x7900 </FONT></P>
5 i/ \& y2 _; u) ~1 g: d<><FONT color=#0000ff>/* reduce heaplength and stacklength
# \  s6 J. x1 H9 d" T( fto make a smaller program in memory */ 2 p% ^) p# v: }
extern unsigned _heaplen = 1024; ! f# [. S1 d  x6 y# w% ~
extern unsigned _stklen = 512; </FONT></P>
9 B$ S1 ?) i$ i5 ?4 x1 u<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>* D6 m' b' Z* m. d5 X% R
<><FONT color=#0000ff>void interrupt handler(void) * o% a2 \* g& M1 ^
{ 1 }* q# g" G- q% p" s
unsigned int (far *screen)[80]; & G. N) C$ \  m: G+ ^# }  r
static int count; </FONT></P>
1 z6 H9 Y- j3 l' J6 R1 p<><FONT color=#0000ff>/* For a color screen the video memory
6 u1 _: t- ?1 H7 Dis at B800:0000. For a monochrome 9 u2 D: U+ Q' k, Z' S$ u
system use B000:000 */ 5 e+ t, i( z3 P, A4 K6 `
screen = MK_FP(0xB800,0); </FONT></P>) V- \8 j1 k& ^
<><FONT color=#0000ff>/* increase the counter and keep it ; `& `0 u1 c, L2 a3 }7 ~8 R
within 0 to 9 */
9 S: f/ O, x$ N6 D) v- Ecount++;
* ]' X& f, b! ~9 C1 z8 Kcount %= 10; </FONT></P>
" R! l* k7 M7 M. g<><FONT color=#0000ff>/* put the number on the screen */
- r, ~1 m5 Q; R: S( r: j) J% Pscreen[0][79] = count + '0' + ATTR; </FONT></P>
: {- ~4 l- E; u1 z<><FONT color=#0000ff>/* call the old interrupt handler */
( N- j5 h; ?% q" }" j* Aoldhandler();
% m; e( @+ f) p7 ]8 G} </FONT></P>
1 s7 p* G9 h1 X6 T! ~! C<><FONT color=#0000ff>int main(void)
  B3 v0 _" ~1 E, H6 _8 ~3 y  f{ </FONT></P>
6 v: G' ~5 u0 y# {" l, w/ ^<><FONT color=#0000ff>/* get the address of the current clock
0 I& z) E% n( s7 N6 C/ R$ ?$ Htick interrupt */
) ~+ i4 ~: P& e& aoldhandler = getvect(INTR); </FONT></P>5 |8 c/ b( ?' U: Z! U5 P: g0 W
<><FONT color=#0000ff>/* install the new interrupt handler */
+ X( {6 m) V3 S% e9 w6 \setvect(INTR, handler); </FONT></P>" X9 v2 K" j& o9 H
<><FONT color=#0000ff>/* _psp is the starting address of the ' T0 K$ P0 \$ c$ O3 X" V/ ~3 @$ Z
program in memory. The top of the stack ' Q  U/ {- P6 `) s. X
is the end of the program. Using _SS and
" s: ]  ?1 `* b% ^6 C+ N_SP together we can get the end of the
& B  D' Q  \+ c$ ^stack. You may want to allow a bit of & y5 q! d1 q4 l4 C/ p
saftey space to insure that enough room
: P$ q1 U: \. I6 f% T4 Q: z/ ais being allocated ie: , G4 z. L, u9 [
(_SS + ((_SP + safety space)/16) - _psp)
/ l! I: J3 M& n. ^8 B8 _*/
$ r: {; F; E( y) h: P6 o8 E3 mkeep(0, (_SS + (_SP/16) - _psp)); 5 J% r4 Q9 g# f) N
return 0;
8 W" b! ^6 s1 f' V0 t}
* r- Q# z3 V) X+ u* D2 r/ \</FONT></P>2 A4 Q/ b% G8 j1 E# }  ?' G

* f) v- l( {, f9 Y8 b. k% B3 w7 A. \) q
<><FONT color=#ff0000>函数名: kbhit </FONT>
! M/ R/ g( t, m: p功 能: 检查当前按下的键
( q, s& d! D4 f. g" x( ~用 法: int kbhit(void);
9 I: y7 c+ {6 O% t. F3 L8 Z; |程序例: </P>" G* k# [$ U1 {$ h( z5 H: Y) |
<><FONT color=#0000ff>#include <CONIO.H></FONT></P>
1 Z$ V$ t5 a* a# o6 S<><FONT color=#0000ff>int main(void) 5 z( ]0 _& C- R) I4 a( q% t
{ # j. v1 r1 s  \: c
cprintf("ress any key to continue:");
( W: U7 Q3 A6 D( ^- n$ Lwhile (!kbhit()) /* do nothing */ ;
& z8 x8 _; M2 C1 ^& d" Ycprintf("\r\nA key was pressed...\r\n"); ; r2 j: f1 D, F0 ~* A) o
return 0;
9 j$ f) [3 A) a) G}
( o4 A  r: }& J" z3 h7 t4 B7 D* W. M* V4 l1 I/ e
; J' q# ^( D2 \( B4 b6 a
</FONT></P>
3 c/ h4 E2 y% q8 V" q0 A<><FONT color=#ff0000>函数名: keep </FONT><FONT color=#0000ff>
& V, T7 |. P% v* B- _<FONT color=#000000>功 能: 退出并继续驻留
5 O" J( @4 e7 p& B; S7 }用 法: void keep(int status, int size);
3 [: v. i4 m7 s3 a( t6 c程序例: </FONT></FONT></P>6 E/ Y9 d- Y6 Z5 h- ^) j5 L
<><FONT color=#0000ff>/***NOTE:
5 i2 t" Z" J1 O( h* T  H5 i+ r8 wThis is an interrupt service routine. You . a+ s( @! P6 I& w9 |, @
can NOT compile this program with Test ) M# M7 d( h! M" Q
Stack Overflow turned on and get an % X1 _8 A9 [0 X2 p8 ]' E/ A
executable file which will operate 7 Q; d3 Y! C5 _0 R( }- }6 E
correctly. Due to the nature of this
5 q# v, \7 G3 w9 Y* R0 gfunction the formula used to compute - o. b% m; G* ~. X' Q  l0 W9 ?! I
the number of paragraphs may not 5 A9 X" e3 o: s
necessarily work in all cases. Use with 5 r9 t4 h" N0 H" b
care! Terminate Stay Resident (TSR)
1 Q' e5 N3 \5 [% _' a7 oprograms are complex and no other support - i; g! M& t% w
for them is provided. Refer to the 9 M4 e9 x0 b. Y& j- F; ?
MS-DOS technical documentation
7 F) V! M/ F9 E1 s- F. L  Rfor more information. */
9 P5 H  c5 _& ?9 [1 S( Z# G5 o' M#include <DOS.H>
$ X  i. A7 \  T/* The clock tick interrupt */ 8 R8 Z+ \. H2 M; v4 ?3 v3 G* p6 @
#define INTR 0x1C 9 \( g/ ^1 b7 u% b+ M! ?
/* Screen attribute (blue on grey) */
; X2 b6 j. s3 F  O#define ATTR 0x7900 </FONT></P>0 H% k/ F0 k9 K, Y/ y4 b1 |- k
<><FONT color=#0000ff>/* reduce heaplength and stacklength " u# x; R3 R) Q3 x6 u) W2 `7 U
to make a smaller program in memory */ 2 L* D4 v4 m7 M1 I  \
extern unsigned _heaplen = 1024; ' p: D" x$ l- X  T0 ?3 g: [( }3 \- ]3 x  g
extern unsigned _stklen = 512; </FONT></P>
9 W" m' l/ P! Z0 `1 Z<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
8 E$ W* {  g$ b$ j- _<><FONT color=#0000ff>void interrupt handler(void)
; [. @* \2 `& I# E2 P{
0 U: y2 `' `6 r. xunsigned int (far *screen)[80]; 8 r1 x7 X1 k# U9 P
static int count; </FONT></P>
% i; b9 G# a4 z! A2 D) {/ g<><FONT color=#0000ff>/* For a color screen the video memory
& S& D7 r3 m6 t* U% W( fis at B800:0000. For a monochrome
/ R3 |% U& f" E+ N' z/ G4 esystem use B000:000 */ 1 j( V: K$ J3 Y3 h' A( u* U
screen = MK_FP(0xB800,0); </FONT></P>- i% |. X9 P6 y
<><FONT color=#0000ff>/* increase the counter and keep it , G- r- K. v) a( v5 V& Y
within 0 to 9 */ . |5 h" S) h, ^! F6 e
count++;
( U" O% d+ k4 |$ H( @, G, Q, w5 N9 |4 pcount %= 10; </FONT></P>
' q9 }2 k5 {% I+ M) A<><FONT color=#0000ff>/* put the number on the screen */ ' U" i" u( k/ Y
screen[0][79] = count + '0' + ATTR; </FONT></P>
5 }' t* P8 l! g  B" x3 q<P><FONT color=#0000ff>/* call the old interrupt handler */ / M6 p* y  P# l; i% O! Z4 K
oldhandler();
' S  f! N1 O7 _+ o} </FONT></P># i$ H8 K+ F9 [& d# V" c  {
<P><FONT color=#0000ff>int main(void) 5 L& X5 W. p2 |. k" G
{ </FONT></P>3 w6 T$ V# c7 D; C# b7 f4 ]' K/ F
<P><FONT color=#0000ff>/* get the address of the current clock 7 F# W9 X$ j$ H) A* g8 N
tick interrupt */ ; O/ T6 \( ]) h/ Q% p  y+ G% Z+ [
oldhandler = getvect(INTR); </FONT></P>* C- l, F1 }9 s/ x# W7 \/ H
<P><FONT color=#0000ff>/* install the new interrupt handler */
& B: v) W; p, r  I0 _  ~1 Xsetvect(INTR, handler); </FONT></P>2 c1 `: r  B$ H3 R
<P><FONT color=#0000ff>/* _psp is the starting address of the
( I  e- H2 D9 p  Y: Qprogram in memory. The top of the stack
5 x3 s  _  P4 k! q, kis the end of the program. Using _SS and
, z  X* T( l; X* x2 Y* a* U_SP together we can get the end of the
6 n! `4 O/ A' l7 F0 }2 ]  wstack. You may want to allow a bit of ; D  O, p% k- ]0 @* O# ?! @+ z
saftey space to insure that enough room
; c0 ~. U7 @3 ~7 b! wis being allocated ie:
8 @/ `0 K6 p: f5 w+ W) n(_SS + ((_SP + safety space)/16) - _psp) : g3 g/ Y; ^. w1 c
*/
% j$ R7 Y( T: q+ H5 x! M/ _0 Mkeep(0, (_SS + (_SP/16) - _psp));
$ B' z- y1 f! ]5 V9 z# [; d& K# n; ^& Xreturn 0; 3 l" T3 }# O8 r. b1 K5 p
}</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 08:13 , Processed in 0.437934 second(s), 52 queries .

回顶部