📄 timer_bp.cpp
字号:
/*******************************************************
* *
* Program : TIMER_BP Language : Borland C++ *
* *
* Modified : 20 nov 2003 *
* *
* Copyright (c) 1988,2003, ORITECH V 5.1 *
* All rights reserved. *
* *
*******************************************************
* *
* TIMER_BP.CPP Demo EasyTask DPMI16 *
* *
*******************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <conio.h>
#include <string.h>
#include <float.h>
#include <time.h>
#include "etlib.h"
typedef struct
{
long cnt1;
long cnt2;
long cnt3;
int position_x;
} TParmsCnt;
typedef TParmsCnt *PParmsCnt;
typedef struct
{
long cnt1;
long cnt2;
long cnt3;
int position_x;
int position_y;
} TParms3;
typedef TParms3 *PParms3;
PMultiTask taskclockptr, taskcountptr;
PMultiTask taskcnt1ptr, taskcnt2ptr, taskcnt3ptr, taskdskptr;
PParmsCnt parmscnt, parmscnt2;
TParms3 myparms3;
long _wfar cnttimer; // *** __far for irq mode address ***
BOOL diskend;
#pragma check_stack_off // *** begin hardware timer function
void thetimer()
{
float n,n2;
cnttimer++; // *** global variable declared __far ***
n = 17.5;
n2 = 200.23;
n = n2 / n * (float)1.54;
}
#pragma check_stack_on // *** end hardware timer function
void taskclock(pvoid, pvoid) // task 1
{
char tbuffer[9];
char sb[128];
pausemode(MTT); // save context
window(1,1,80,25);
textbackground(White);
textcolor(LightBlue);
sethardtimer(500,thetimer);
do
{
gotoxy(60,1);
sprintf(sb,"%s; %li",_strtime( tbuffer ),cnttimer);
cprintf(sb);
taskdelay(1000);
} while (TRUE);
}
void taskcount(pvoid, pvoid) // task 2
{
long x;
char sb[128];
pausemode(MTT); // save context
textbackground(BLACK);
textcolor(LightCyan);
window(10,15,20,20);
x = 0;
do
{
x++;
if ((x%9 == 0) && (x%4 == 0))
{
sprintf(sb,"x=%li\n\r",x);
cprintf(sb);
}
pause();
} while (!kbhit());
killalltasks();
}
void taskcnt(TParmsCnt VAR parms, pvoid)
{
long n;
char s[128];
pausemode(MTT);
textbackground(Green);
textcolor(Yellow);
window(parms.position_x,5,parms.position_x+22,10);
clrscr();
parms.cnt1 = 0; // init local variables
parms.cnt2 = 0;
parms.cnt3 = 0;
for (n=1L; n<=1000000L; n++)
{
parms.cnt1 += 1;
parms.cnt2 += 2;
parms.cnt3 += 3;
if (((parms.cnt1 % 5) == 0) && ((parms.cnt1 % 7) == 0))
{
sprintf(s,"%li:%li:%li\n\r",parms.cnt1,parms.cnt2,parms.cnt3);
cprintf(s);
}
pause();
}
}
void taskcnt3(TParms3 VAR parms, pvoid)
{
long n;
char s[128];
pausemode(MTT);
textbackground(White);
textcolor(BLACK);
window(parms.position_x,parms.position_y,parms.position_x+22,parms.position_y+5);
clrscr();
parms.cnt1 = 0; // init local variables
parms.cnt2 = 0;
parms.cnt3 = 0;
for (n=1L; n<=1000000L; n++)
{
parms.cnt1 += 1;
parms.cnt2 += 2;
parms.cnt3 += 3;
if (((parms.cnt1 % 5) == 0) && ((parms.cnt1 % 7) == 0))
{
sprintf(s,"%li:%li:%li\n\r",parms.cnt1,parms.cnt2,parms.cnt3);
cprintf(s);
}
pause();
}
}
void taskdsk(pvoid, pvoid)
{
FILE *f;
word n1,n2;
char s[128];
char sb[128];
diskend = 0;
pausemode(MTT);
textbackground(WHITE);
textcolor(LightBlue);
window(22,15,47,20);
clrscr();
for (n1 = 1; n1 <= 500; n1++)
{
f = fopen("TESTTMR.TXT","w");
for (n2 = 1; n2 <= 1000; n2++)
{
fprintf(f,"Text file %i line %i\r\n",n1,n2);
pause();
}
fclose(f);
if (diskend) return;
//
f = fopen("TESTTMR.TXT","r");
for (n2 = 1; n2 <= 1000; n2++)
{
fgets(s,80,f);
sprintf(sb,"%s\r",s);
cprintf(sb);
pause();
}
fclose(f);
if (diskend) return;
}
}
void main(void)
{
etker_init();
textbackground(BLACK);
textcolor(WHITE);
clrscr();
_setcursortype(_NOCURSOR);
taskclockptr = newtask(taskclock,8000,1,MT_CHILD,NULL,0,NULL);
taskcountptr = newtask(taskcount,8000,1,MT_CHILD,NULL,0,NULL);
taskcnt1ptr = newtask((PTaskFunc)taskcnt,8000,1,MT_CHILD,NULL,sizeof(TParmsCnt),NULL);
taskcnt2ptr = newtask((PTaskFunc)taskcnt,8000,3,MT_CHILD,NULL,sizeof(TParmsCnt),NULL);
myparms3.position_x = 50;
myparms3.position_y = 15;
taskcnt3ptr = newtask((PTaskFunc)taskcnt3,8000,2,MT_CHILD,&myparms3,0,NULL);
parmscnt2 = (PParmsCnt)taskcnt1ptr->taskparam;
parmscnt2->position_x = 10;
parmscnt2 = (PParmsCnt)taskcnt2ptr->taskparam;
parmscnt2->position_x = 50;
taskdskptr = newtask(taskdsk,8000,1,MT_CHILD,NULL,0,NULL);
waitnotask();
_setcursortype(_NORMALCURSOR);
cprintf("Program End\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -