Добавил:
Mymnan
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Сборка Часть1 / avmis_labs / неразобрано / 501 / Лаб_Таймер / !TAYMER_Gilevsky / BBB
.C#include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define TIMEINT 8
#define NN 100
void writeGraphic(int color, int del);
int getFunc(int x);
// Old handler timer interruptions
void interrupt (*oldtime)();
// New handler timer interruptions
void interrupt newtime();
static int y[NN];
static int gMass[NN];
static int gMassIdx;
static int yIdx;
static int yCur;
static int oTCCount; // Counter of oldtime call
static int grCount = 0;
int main()
{
unsigned oldtic=65535u; // Old divide koefficient
unsigned newtic=21645u; // New divide koefficient
int x; // sin & cos argument
int graphDriver; // Graphics driver
int graphMode; // Graphics mode
int errorcode;
srand(time(NULL));
fflush(stdin);
clrscr();
/* Conclusion results */
graphDriver=3; /* EGA, 16 colors */
graphMode=1; /* 640*350 mode */
initgraph(&graphDriver,&graphMode,"");
/* checking the result to initialization */
errorcode = graphresult();
if (errorcode != grOk) /* Error of the graphic mode */
{
puts("Graphics error: %s\n");
puts(grapherrormsg(errorcode));
puts("Press any key to halt:");
getch();
exit(1);
}
// Channel 0 programming
outportb(0x43,0x36); /* Control byte */
outportb(0x40,newtic&0x00ff); /* Young counter byte */
outportb(0x40,newtic>>8); /* Old counter byte */
yIdx=-1; /* AtD does not begin */
oTCCount=15;
// Connection to vector
oldtime = _dos_getvect(TIMEINT);
_dos_setvect(TIMEINT,newtime);
// Starting "unceasing process"
randomize();
for (x = yIdx = 0; yIdx < NN; x += 1){
yCur = getFunc(x);
if (yIdx >= NN){
for (yIdx = 1; yIdx < NN; yIdx++){
y[yIdx - 1] = y[yIdx];
}
if (kbhit()){
break;
}
for (gMassIdx = 0; gMassIdx < NN; gMassIdx ++){
gMass[gMassIdx] = y[gMassIdx];
}
writeGraphic(5,1500);
writeGraphic(0,0);
grCount++;
if (grCount >= 10){
grCount = 0;
cleardevice();
clearviewport();
}
yIdx = NN - 1;
}
}
// Recover vector
_dos_setvect(TIMEINT,oldtime);
// Recover channel 0
outportb(0x43,0x36); /* Young counter byte */
outportb(0x40,oldtic&0x00ff); /* Young counter byte */
outportb(0x40,oldtic>>8); /* Old counter byte */
getch();
return 0;
}
void writeGraphic(int color, int del)
{
setcolor(3);
settextstyle(TRIPLEX_FONT,0,4);
outtextxy(15,15,"Results of Arithmetic Numeric Convertion:");
setcolor(3);
rectangle(15,40,624,330);
setcolor(color);
for(gMassIdx=0; gMassIdx < NN - 1; gMassIdx++)
{
line(22+gMassIdx*6,330,22+gMassIdx*6,330-gMass[gMassIdx]*1);
}
delay(del);
}
int getFunc(int x){
return (50*(cos(x/10)+random( 3 )*cos(x/5))+150);
}
/* New timer interruption handler */
void interrupt newtime()
{
if (--oTCCount<0) {
/* Call oldtime - to the 2nd time */
(*oldtime)();
oTCCount=7;
}
else /* reset controller */
outportb(0x20,0x20);
if ((yIdx>=0) /* If AtD begins, */
&&(yIdx<NN)) /* and NN do not collect, */
y[yIdx++]=yCur; /* remember new evidence */
}