Скачиваний:
35
Добавлен:
15.09.2014
Размер:
2.64 Кб
Скачать
#include <dos.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <time.h>
#include <conio.h>

#define TIMEINT 8
#define count 100
#define step 6

void interrupt (*oldtime)();
void interrupt  newtime();
void printdot(int dot, int i);

static int y[count];
static int max;
static int pos;
static int val;
static int f;
union REGS rr;
struct SREGS sr;
void *readvect(int in);
void writevect(int in, void *h);

void main()
{
  unsigned oldtic=65535u;
  unsigned newtic=32768u;
  int video;
  int rez;
  int errorcode;
  double x;

  textbackground(0);
  clrscr();

  video = 3; /* EGA, 16 */
  rez = 1;  /* 640*350 */

  initgraph(&video,&rez,"");

  errorcode = graphresult();
  if (errorcode != grOk)
  {
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
		exit(1);
  }


  gotoxy(33,12);
  printf("Are you ready?");
  getch();
  textcolor(0);
  clrscr();


  outportb(0x43,0x36);
  outportb(0x40,newtic&0x00ff);
  outportb(0x40,newtic>>8);

  f = -1;
  max = 0;
  pos = 0;


  (void*)oldtime=readvect(TIMEINT);
  writevect(TIMEINT,newtime);

  randomize();
  while(!kbhit())
  {
		f = 1;
		x++;
		val = (int)(50*(fabs(sin(x/10)) + random(20)/100) + 150);
  }

  writevect(TIMEINT,oldtime);

  outportb(0x43,0x36);
  outportb(0x40,oldtic&0x00ff);
  outportb(0x40,oldtic>>8);

  getch();
  closegraph();
}

void interrupt newtime()
{
  (*oldtime)();
  if(f == 1)
  {
		  if(pos >= count)
		  {
				max = 1;
				pos = 0;
				y[pos++] = val;
		  }
		  else
		  {
				y[pos++] = val;
		  }
		  if(max == 1)
		  {
				clrscr();
				int dot = 0;
				for(int i = pos; i < count; i ++)
				{
					printdot(dot++, i);
				}
				for(i = 0; i < pos; i ++)
				{
					printdot(dot++, i);
				}
		  }
		  else
		  {
				if(pos > 1)
				{
					printdot(pos, pos-1);
				}
				else
				{
					setcolor(4);
					circle(22+pos*step,330-y[pos-1]*1,2);
				}

		  }
	}
}

void printdot(int dot, int i)
{
	setcolor(4);
	circle(22+dot*step,330-y[i]*1,2);
	setcolor(5);
	if(i != 0 && dot != 0)
	{
			line(22+(dot-1)*step,330-y[i-1]*1,22+dot*step,330-y[i]*1);
	}
	if(i == 0 && dot != 0)
	{
			line(22+(dot-1)*step,330-y[count-1]*1,22+dot*step,330-y[i]*1);
	}
}


void *readvect(int in)
{
  rr.h.ah=0x35; rr.h.al=in;
  intdosx(&rr,&rr,&sr);
  return(MK_FP(sr.es,rr.x.bx));
}


void writevect(int in, void *h)
{
  rr.h.ah=0x25;
  rr.h.al=in;
  sr.ds=FP_SEG(h);
  rr.x.dx=FP_OFF(h);
  intdosx(&rr,&rr,&sr);
}