Добавил:
Mymnan
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Сборка Часть1 / avmis_labs / лабы / 3. таймер / TIMER
.CPP
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <time.h>
#include <conio.h>
#include <math.h>
#define TIMEINT 8
#define N 100
void interrupt (*oldtime)(...);
void interrupt newtime(...);
static int resmas[N];
static int ny;
static int yc;
static int counter;
int main()
{
unsigned oldtic = 65535;
unsigned newtic = 16412;
int g_driver, g_mode;
int errorcode;
int x;
clrscr();
printf("Please wait");
outportb(0x43,0x36);
outportb(0x40,(char)newtic);
outportb(0x40,(char)(newtic>>8));
ny = -1;
counter = 4;
oldtime=getvect(TIMEINT);
setvect(TIMEINT,newtime);
randomize();
int tmp1, tmp2;
for (x=0,ny=0; ny<N; x++)
{
yc=(int)(0.5*(x%100)+100*sin(x/5)*random(2)+150);
}
setvect(TIMEINT,oldtime);
outportb(0x43,0x36);
outportb(0x40,(char)oldtic);
outportb(0x40,(char)(oldtic>>8));
g_driver = 3; /* EGA, 16 colors */
g_mode = 1; /* Rezhim 640*350 */
initgraph(&g_driver, &g_mode, "");
errorcode = graphresult();
if(errorcode != grOk)
{
printf("\nGraphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(9);
rectangle(15,40,624,330);
setcolor(11);
for(ny=0; ny<N; ny++)
{
circle(22+ny*6, 330-resmas[ny]*1,2);
line(22+ny*6, 330, 22+ny*6, 333-resmas[ny]*1);
}
setcolor(12);
settextstyle(0, 0, 1);
outtextxy(260, 340, "Press any key to continue ...");
getch();
closegraph();
return 0;
}
void interrupt newtime(...)
{
counter--;
if(counter<=0)
{
(*oldtime)();
counter = 4;
}
else outportb(0x20,0x20);
if(ny>=0 && ny<N) resmas[ny++]=yc;
}