📄 demo1_bp.cpp
字号:
/*******************************************************
* *
* Program : DEMO1_BP Language : Borland C++ *
* *
* Modified : 20 nov 2003 *
* *
* Copyright (c) 1988,2003, ORITECH V 5.1 *
* All rights reserved. *
* *
*******************************************************
* *
* DEMO1_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 <math.h>
#include <time.h>
#include "etlib.h"
PMultiTask task[7];
int gd,gm,ge;
BOOL stop;
void randcolor(void)
{
word mycolor;
do
{
mycolor = random(15);
} while (mycolor <= 8);
setcolor(mycolor);
}
double mysin(double a, double k, double x)
{
return (a*sin(k*x));
}
void task1(pvoid, pvoid) // sinus drawing
{
int x0,y0,dx,dy;
int i,c;
double a,k,y,yi;
int wx,wy;
int slowdisp;
wx = 200;
wy = 50;
pausemode(MTG);
setviewport(150,45,350,100,True);
setcolor(WHITE);
rectangle(0,0,200,50);
do
{
slowdisp = random(200);
c = 0;
while (c<2)
{
c++;
switch (c)
{
case 1:
randcolor();
break;
case 2:
setcolor(BLACK);
break;
}
x0 = 1;
y0 = 0;
a = (-wy / 2);// +6;
k = 0.2;
y = mysin(a,k,0);
moveto(0+x0,0+y0+(int)y+(wy / 2));
i = 0;
while ((i<wx-4) && (wx > 6))
{
i++;
dx = 1;
yi = mysin(a,k,i);
dy = (int)(yi - y);
lineto(getx()+dx,gety()+dy);
y = yi;
pause();
if (!slowdisp) taskdelay(1);
}
}
} while (!stop);
}
void task2(pvoid, pvoid) // star drawing
{
int i,c,x,y;
int slowdisp;
pausemode(MTG);
setviewport(20,20,639,350,False);
do
{
slowdisp = random(200);
c = 0;
while (c<2)
{
c++;
switch (c)
{
case 1:
setcolor(BLACK);
break;
case 2:
randcolor();
break;
}
i = 0;
do
{
moveto(50,50);
y = 5*i;
x = 50+y;
lineto(x,y);
moveto(50,50);
lineto(x,100-y);
moveto(50,50);
x = 50-y;
lineto(x,y);
moveto(50,50);
lineto(x,100-y);
i++;
pause();
if (!slowdisp) taskdelay(1);
} while (x != 0);
}
} while (!stop);
}
void task3(pvoid, pvoid) // square drawing
{
int i,c,x1,y1,x2,y2;
int slowdisp;
pausemode(MTG);
setviewport(500,135,639,300,False);
do
{
slowdisp = random(200);
c = 0;
while (c<2)
{
c++;
switch (c)
{
case 1:
setcolor(BLACK);
break;
case 2:
randcolor();
break;
}
x1 = 40;
y1 = 40;
x2 = 60;
y2 = 60;
i = 0;
while (i<10)
{
i++;
rectangle(x1,y1,x2,y2);
x1 = x1-5;
y1 = y1-5;
x2 = x2+5;
y2 = y2+5;
pause();
if (!slowdisp) taskdelay(1);
}
}
} while (!stop);
}
void task4(pvoid, pvoid) // disk access
{
FILE *f = NULL;
char s1[128],s2[128],s3[128],s4[128];
int n;
char cs[2];
int sl1,sl2,sl3,sl4,slmax;
int _cx = 8;
int _cy = 15;
cs[1] = 0;
pausemode(MTG);
setviewport(0,40,639,340,False);
f = fopen("readme.txt","r");
if (f==NULL)
{
outtextxy(1*_cx,20*_cy,"File readme.txt not found.**=======================**");
return;
}
do
{
while ((!feof(f)) && (!stop))
{
fgets(s1,80,f);
fgets(s2,80,f);
fgets(s3,80,f);
fgets(s4,80,f);
sl1 = strlen(s1)-1;
sl2 = strlen(s2)-1;
sl3 = strlen(s3)-1;
sl4 = strlen(s4)-1;
slmax = __max(sl1,sl2);
slmax = __max(slmax,sl3);
slmax = __max(slmax,sl4);
setcolor(Yellow);
for (n=0; n <= slmax; n++)
{
cs[0] = s1[n];
if (n<sl1) outtextxy((n+1)*_cx,(19*_cy),cs);
cs[0] = s2[n];
if (n<sl2) outtextxy((n+1)*_cx,(19+1)*_cy,cs);
cs[0] = s3[n];
if (n<sl3) outtextxy((n+1)*_cx,(19+2)*_cy,cs);
cs[0] = s4[n];
if (n<sl4) outtextxy((n+1)*_cx,(19+3)*_cy,cs);
if (!stop && (s1[n]>32 || s2[n]>32 || s3[n]>32 || s4[n]>32) ) taskdelay(1);
}
setcolor(LightRed);
for (n=slmax-1; n>=0; n--)
{
cs[0] = s1[n];
if (n<sl1) outtextxy((n+1)*_cx,19*_cy,cs);
cs[0] = s2[n];
if (n<sl2) outtextxy((n+1)*_cx,(19+1)*_cy,cs);
cs[0] = s3[n];
if (n<sl3) outtextxy((n+1)*_cx,(19+2)*_cy,cs);
cs[0] = s4[n];
if (n<sl4) outtextxy((n+1)*_cx,(19+3)*_cy,cs);
if (!stop && (s1[n]>32 || s2[n]>32 || s3[n]>32 || s4[n]>32) ) taskdelay(1);
}
setcolor(BLACK);
for (n=0; n <= slmax; n++)
{
cs[0] = s1[n];
if (n<sl1) outtextxy((n+1)*_cx,19*_cy,cs);
cs[0] = s2[n];
if (n<sl2) outtextxy((n+1)*_cx,(19+1)*_cy,cs);
cs[0] = s3[n];
if (n<sl3) outtextxy((n+1)*_cx,(19+2)*_cy,cs);
cs[0] = s4[n];
if (n<sl4) outtextxy((n+1)*_cx,(19+3)*_cy,cs);
if (!stop && (s1[n]>32 || s2[n]>32 || s3[n]>32 || s4[n]>32) ) taskdelay(1);
}
}
rewind(f);
} while (!stop);
fclose(f);
}
void task5(pvoid, pvoid) // serial COM1,COM2
{
char s[256];
char c;
byte g;
word com;
char cs[2];
int err;
cs[1] = 0;
pausemode(MTG);
g = 0;
outp(COM1+RCM_8250,0x0F);
if (inp(COM1+RCM_8250) == 0x0F)
{
g = 4;
com = COM1;
}
else
{
outp(COM2+RCM_8250,0x0F);
if (inp(COM2+RCM_8250) == 0x0F)
{
g = 3;
com = COM2;
}
}
setviewport(410,45,639,340,False);
setcolor(WHITE);
rectangle(0,0,200,55);
if (g==0) strcpy(s,"NO SERIAL PORT");
else if (g==3) strcpy(s,"SERIAL PORT COM2");
else if (g==4) strcpy(s,"SERIAL PORT COM1");
outtextxy(56,8,s);
if (g==0) return;
OpenSerial(g,1,256,256,com,err);
resetserial(g,1,1200,7,1,MT_EVENPARITY,smode_dtr+smode_rts,err);
setviewport(410+2,45+1,410+200-2,45+55-2,True);
clearviewport();
moveto(0,10);
do
{
do
{
c = getserial(g,1,pause,1,err);
} while (!(stop || err == 0));
cs[0] = c;
if (c>=' ') outtext(cs);
if (c=='\r') moveto(0,gety());
if (getx() > 190)
{
moveto(0,gety()+10);
}
if (gety() > 40)
{
clearviewport();
moveto(0,10);
}
} while(!stop);
disposeserial();
}
void task6(pvoid, pvoid) // edit
{
BOOL keyfunc;
char keychar;
byte quitmode;
char quitchar;
int n;
char s[256];
char ts[6][65];
BOOL fin, qbol, qeol;
TSetOfChar mask,maskquitfunc,maskquit;
pausemode(MTG);
setviewport(0,0,600,300,False);
setcolor(Yellow);
settextstyle(SANS_SERIF_FONT,0,0);
setusercharsize(100,100,100,100);
outtextxy(200,2,"EasyTask");
outtextxy(130,240,"Example for C++");
settextstyle(0,0,0);
for (n=1; n<=5; n++)
{
strcpy(ts[n],""); //** init ts="";
}
strcpy(ts[2],"Multitasking Kernel for C++");
strcpy(ts[4],"***************************");
outtextxy(110,150,ts[1]);
outtextxy(110,165,ts[2]);
outtextxy(110,180,ts[3]);
outtextxy(110,195,ts[4]);
outtextxy(110,210,ts[5]);
outtextxy(110,125,"Edit your text: ESC for exit");
rectangle(100,135,400,235);
n = 1;
qbol = FALSE;
qeol = FALSE;
fin = FALSE;
do
{
moveto(110,150+((n-1)*15));
strcpy(s,ts[n]);
setclear(mask);
seton(mask,8);
setrangeon(mask,' ','z');
setclear(maskquitfunc);
setclear(maskquit);
seton(maskquit,13);
seton(maskquit,27);
inquire(s,32,FALSE,mask,maskquitfunc,maskquit,
qbol,qeol,&quitmode,&quitchar);
strcpy(ts[n],s);
switch (quitmode)
{
case IQBOL:
n--;
if (n==1) qbol = FALSE;
qeol = TRUE;
break;
case IQEOL:
n++;
if (n==5) qeol = FALSE;
qbol = TRUE;
break;
case IQQUIT:
switch (quitchar)
{
case 13:
if (n<5)
{
n++;
qbol = TRUE;
if (n==5) qeol = FALSE;
}
break;
case 27:
fin = TRUE;
break;
}
}
} while (!fin);
setcolor(LightRed);
settextstyle(SANS_SERIF_FONT,0,0);
setusercharsize(100,100,100,100);
outtextxy(110,280,"End of edit, ESC for exit");
settextstyle(0,0,0);
areadkeymask(&keyfunc,&keychar,FALSE,maskquit,maskquitfunc);
stop = TRUE;
}
void main(void)
{
ETKer_Init();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
ge = graphresult();
if (ge < 0)
{
cprintf("Graphic Error:%s\n\r",grapherrormsg(ge));
cprintf("Graphic device not recognize\n\r");
exit(1);
}
if (gd==CGA) setgraphmode(CGAHI);
if (gd==MCGA) setgraphmode(MCGAMED);
if (gd==EGA) setgraphmode(EGAHI);
if (gd==EGA64) setgraphmode(EGA64LO);
//
stop = FALSE;
task[1] = newtask(task1,8000,1,MT_CHILD,NULL,0,NULL); // sinus
task[2] = newtask(task2,8000,1,MT_CHILD,NULL,0,NULL); // star
task[3] = newtask(task3,8000,1,MT_CHILD,NULL,0,NULL); // square
task[4] = newtask(task4,8000,1,MT_CHILD,NULL,0,NULL); // disk
task[5] = newtask(task5,8000,1,MT_CHILD,NULL,0,NULL); // serial
task[6] = newtask(task6,8000,1,MT_CHILD,NULL,0,NULL); // edit
waitnotask();
closegraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -