#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>


void memwerte(void);
void stdisk(void);
void lfdisk(void);
void stdisk(void);
void clrmem(void);
void maske(void);
void ausgabe(void);
void defcolor(void);
void mausfunc(void);
void show(void);
void eingabe(void);
void start(void);

//**************** Voreinstellungen ************************


//-------------- Allgemeine Variablen (Global) -------------

	unsigned int x=0;		//allg. Zhler
	unsigned int a=0;		//Variable fr Tastatureingabe
	unsigned int text;     	//text$(30)           'Zeilen zu Beginn der laser.dat
	unsigned int tastea= 0; //Tastatureingabe getch()
	unsigned int tasteb= 0;
	unsigned mauszaehler= 801;	//Warten, bis zur nchsten Maus - Abfrage
	int maust=0, mausx=0, mausy=0;     	//Mausdaten
	unsigned int mausaltx=0, mausalty=0, mausaltt=0;
	int i=0;

	static unsigned int memta[44];	//memta(50)          'Memory 01 - 41, ma - mc,
	static unsigned int memtb[44];	//memtb(50)          'time
	static unsigned int memtc[44];	//memtc(50)
	static unsigned int mempa[44];	//mempa(50)          'pause
	static unsigned int mempb[44];	//mempb(50)
	static unsigned int mempc[44];	//mempc(50)
	static unsigned int memra[44];	//memra(50)           'Motor a Richtung
	static unsigned int memc[44];	//memc(50)            'MemColor m01 - m42
	static unsigned int memx=0;	//x-position Speicherfeld
	static unsigned int memy=0;	//y-position Speicherfeld
	static unsigned int mem=0;	//Platzhalter fr fscanf
	unsigned int mtaste=0, mx=0, my=0;

	unsigned int port= 0x378;	//port = 888              'Printerport #1


	unsigned int ma= 0;	//ma = 0                  'Motor a
	unsigned int mb= 0;	//mb = 0                  'Motor b
	unsigned int mc= 0;	//mc = 0

	unsigned int xa= 0;	//xa = 0                  'Index impuls a
	unsigned int xb= 0;	//xb = 0                  'Index impuls b
	unsigned int xc= 0;	//xc = 0

	unsigned int ya= 0;	//ya = 0                  'Index pause a
	unsigned int yb= 0;	//yb = 0                  'Index pause b
	unsigned int yc= 0;	//yc = 0

	signed int ta= 0;	//ta = 0                  'Time a
	signed int tb= 0;	//tb = 0                  'Time b
	signed int tc= 0;	//tc = 0                  'Time c

	signed int pa= 0;	//pa = 0                  'Pause a
	signed int pb= 0;	//pb = 0                  'Pause b
	signed int pc= 0;	//pc = 0                  'Pause c

	unsigned int ra=2;		//r = 1                   'Richtung

	const char *richtung[3]={"", "rechts", "links "};  //r$(1) = "rechts"        'Anzeige rechts

				//r$(2) = "links "        'Anzeige links

	unsigned int ende= 1;	//ende = 1                'Programmausstieg bei 0

	unsigned int ca= 0;	//ca = 0                  'index hochzhlen
	unsigned int cb= 0;	//cb = 0
	unsigned int cc= 0;	//cc = 0

	unsigned int da= 0;	//da = 0                  'pause hochzhlen
	unsigned int db= 0;	//db = 0
	unsigned int dc= 0;	//dc = 0

	unsigned int m= 0;



	//port = 888;

       //text = 0;     	//text$(30)           'Zeilen zu Beginn der laser.dat

       //	memta= 0;	//memta(50)          'Memory 01 - 41, ma - mc,
      //	memtb= 0;	//memtb(50)          'time
      //	memtc= 0;	//memtc(50)
      //	mempa= 0;	//mempa(50)          'pause
      //	mempb= 0;	//mempb(50)
      //	mempc= 0;	//mempc(50)
      //	memra= 0;	//memra(50)           'Motor a Richtung
      //	memc= 0;	//memc(50)            'MemColor m01 - m42

      //	port= 0;	//port = 888              'Printerport #1


      //	ma= 0;	//ma = 0                  'Motor a
      //	mb= 0;	//mb = 0                  'Motor b
      //	mc= 0;	//mc = 0

      //	xa= 0;	//xa = 0                  'Index impuls a
      //	xb= 0;	//xb = 0                  'Index impuls b
      //	xc= 0;	//xc = 0

      //	ya= 0;	//ya = 0                  'Index pause a
      //	yb= 0;	//yb = 0                  'Index pause b
      //	yc= 0;	//yc = 0

      //	ta= 0;	//ta = 0                  'Time a
      //	tb= 0;	//tb = 0                  'Time b
      //	tc= 0;	//tc = 0                  'Time c

      //	pa= 0;	//pa = 0                  'Pause a
      //	pb= 0;	//pb = 0                  'Pause b
      //	pc= 0;	//pc = 0                  'Pause c

      //	r= 0;  	//r = 1                   'Richtung
		//r$(1) = "rechts"        'Anzeige rechts
		//r$(2) = "links "        'Anzeige links

      //	ende= 1;	//ende = 1                'Programmausstieg bei 0

      //	ca= 0;	//ca = 0                  'index hochzhlen
      //	cb= 0;	//cb = 0
      //	cc= 0;	//cc = 0

      //	da= 0;	//da = 0                  'pause hochzhlen
      //	db= 0;	//db = 0
      //	dc= 0;	//dc = 0



void clrmem(void)
{

for (x=1; x<=42; x++)
	{
		memta[x]=0;
		mempa[x]=0;
		memra[x]=0;

		memtb[x]=0;
		mempb[x]=0;

		memtc[x]=0;
		mempc[x]=0;

		memra[x]=0;

		memc[x]=1;
	}

gotoxy(55, 13); cprintf("   cleared...    ");
memwerte();

}


//++++++++++++++++++++++++++ Bildschirmmaske +++++++++++++++++++++++++++

//Programmteile vorwegladen  aus aktuellem Verzeichnis
// #inlude "maske.cpp"
void maske(void)
{

clrscr();
 textbackground(0);
 textcolor(3);
 cprintf("ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออหอออออออออออออออป");
 cprintf("บ                                                              บ               บ");
 cprintf("ฬอออออออออออหออออออออออออออออออออออออออหอออออออออออหอออออออออออสอออออออออออออออน");
 cprintf("บ           บ    Status:               บ           บ    Status:                บ");
 cprintf("ฬอออออออออออผ                          ฬอออออออออออผ                           บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ Index Impuls:     Index Pause:       บ  Index Impuls:     Index Pause:       บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ Max Pause          Max Impuls        บ  Max Pause          Max Impuls        บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ Richtung:                            บ                                       บ");
 cprintf("ฬอออออออออออหออออออออออออออออออออออออออฮออออออหออออออหอออออออออออออออออหอออออออน");
 cprintf("บ           บ    Status                บ Load บ Save บ                 บ Clear บ");
 cprintf("ฬอออออออออออผ                          ฬออออออสออออออสอออออออออออออออออสอออออออน");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ Index Impuls:     Index Pause:       บ                                       บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ Max Pause          Max Impuls        บ                                       บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("บ                                      บ                                       บ");
 cprintf("ฬออออออออออออออออออออออหอออออออออออออออสอออออออหอออออออออออออออออออออออออออออออน");
 cprintf("บ Maus: X:   Y:   T:   บ Beenden mit Leertaste บ                               บ");
 cprintf("ศออออออออออออออออออออออสอออออออออออออออออออออออสอออออออออออออออออออออออออออออออผ");

 gotoxy(25, 2); cprintf("Thorstens Lasershow");


textcolor(3);
	  gotoxy(4, 4); cprintf("Motor 1");
	  gotoxy(43, 4); cprintf("Motor 2");
	  gotoxy(3, 13); cprintf("Zerhacker");

textcolor(4);
	  gotoxy(20, 9); cprintf("R");
	  gotoxy(38, 9); cprintf("R");
	  gotoxy(60, 9); cprintf("R");
	  gotoxy(78, 9); cprintf("R");
	  gotoxy(20, 18); cprintf("R");
	  gotoxy(38, 18); cprintf("R");
	  gotoxy(66, 2); cprintf("Reset  ti  tp");

textcolor(14);
	  gotoxy( 14, 9); cprintf("<   >");
	  gotoxy( 32, 9); cprintf("<   >");
	  gotoxy( 54, 9); cprintf("<   >");
	  gotoxy( 72, 9); cprintf("<   >");
	  gotoxy( 14, 18); cprintf("<   >");
	  gotoxy( 32, 18); cprintf("<   >");

textcolor(12);
	  gotoxy( 50, 22); cprintf("Daten=  M1:   M2:   Z:   G:");

textcolor(7);

//....................... Ende Bildschirmmaske ..................
}//********************************************************************
//************************* Unterprogramme ***************************
//********************************************************************

//************************** Programmrotienen ************************

void stdisk(void)
{
	FILE *datei_pointer=fopen("laser.dat","w");
	if (datei_pointer == 0) { printf("error opening file..."); }

	for (x=1; x<=42; x++)
	{
		fprintf(datei_pointer, "%u ", memta[x]);
		fprintf(datei_pointer, "%u ", mempa[x]);
		fprintf(datei_pointer, "%u ", memra[x]);

		fprintf(datei_pointer, "%u ", memtb[x]);
		fprintf(datei_pointer, "%u ", mempb[x]);

		fprintf(datei_pointer, "%u ", memtc[x]);
		fprintf(datei_pointer, "%u ", mempc[x]);

		fprintf(datei_pointer, "%u\n ", memc[x]);
	}

	gotoxy(55, 13); cprintf("     saved...    ");
	fclose(datei_pointer);

}


void lfdisk(void)
{

  FILE *werte;

  werte=fopen("laser.dat", "r+");
  for(i=1; i<=42; i++)
    {
      fscanf(werte, "%d", &memta[i]);
      fscanf(werte, "%d", &mempa[i]);
      fscanf(werte, "%d", &memra[i]);

      fscanf(werte, "%d", &memtb[i]);
      fscanf(werte, "%d", &mempb[i]);

      fscanf(werte, "%d", &memtc[i]);
      fscanf(werte, "%d", &mempc[i]);

      fscanf(werte, "%d", &memc[i]);
   }

   fclose(werte);
   gotoxy(55, 13); cprintf("    loaded...    ");
   memwerte();
}




//+++++++++++++++++++ Ausgabe der Werte +++++++++++++++++++++++++
//--- Die Zahlen sind der Index fr z$ (gegen die res. Stelle ---
//--- des Minuszeichens                                       ---

void ausgabe(void)
{




	gotoxy(13, 11); cprintf("%s",richtung[ra]);   //r$(r)

	gotoxy(15, 9); cprintf("%3i",ta);   //z$(ta)
	gotoxy(33, 9); cprintf("%3i",pa);   //z$(pa)

	gotoxy(55, 9); cprintf("%3i",tb);   //z$(tb)
	gotoxy(73, 9); cprintf("%3i",pb);   //z$(pb)

	gotoxy(15, 18); cprintf("%3i",tc);  //z$(tc)
	gotoxy(33, 18); cprintf("%3i",pc);  //z$(pc)

// ausg = 0                'Werte ausgeben ende

// RETURN

//.................... Ende Ausgabe der Werte .................

}
//++++++++++++++++++++ Ausgabe des Speichers +++++++++++++++++

void memwerte(void)
{

gotoxy(44, 15); textcolor(memc[1]); cprintf("M01");
gotoxy(44, 16); textcolor(memc[2]); cprintf("M02");
gotoxy(44, 17); textcolor(memc[3]); cprintf("M03");
gotoxy(44, 18); textcolor(memc[4]); cprintf("M04");
gotoxy(44, 19); textcolor(memc[5]); cprintf("M05");
gotoxy(44, 20); textcolor(memc[6]); cprintf("M06");

gotoxy(49, 15); textcolor(memc[7]); cprintf("M07");
gotoxy(49, 16); textcolor(memc[8]); cprintf("M08");
gotoxy(49, 17); textcolor(memc[9]); cprintf("M09");
gotoxy(49, 18); textcolor(memc[10]); cprintf("M10");
gotoxy(49, 19); textcolor(memc[11]); cprintf("M11");
gotoxy(49, 20); textcolor(memc[12]); cprintf("M12");

gotoxy(54, 15); textcolor(memc[13]); cprintf("M13");
gotoxy(54, 16); textcolor(memc[14]); cprintf("M14");
gotoxy(54, 17); textcolor(memc[15]); cprintf("M15");
gotoxy(54, 18); textcolor(memc[16]); cprintf("M16");
gotoxy(54, 19); textcolor(memc[17]); cprintf("M17");
gotoxy(54, 20); textcolor(memc[18]); cprintf("M18");

gotoxy(59, 15); textcolor(memc[19]); cprintf("M19");
gotoxy(59, 16); textcolor(memc[20]); cprintf("M20");
gotoxy(59, 17); textcolor(memc[21]); cprintf("M21");
gotoxy(59, 18); textcolor(memc[22]); cprintf("M22");
gotoxy(59, 19); textcolor(memc[23]); cprintf("M23");
gotoxy(59, 20); textcolor(memc[24]); cprintf("M24");

gotoxy(64, 15); textcolor(memc[25]); cprintf("M25");
gotoxy(64, 16); textcolor(memc[26]); cprintf("M26");
gotoxy(64, 17); textcolor(memc[27]); cprintf("M27");
gotoxy(64, 18); textcolor(memc[28]); cprintf("M28");
gotoxy(64, 19); textcolor(memc[29]); cprintf("M29");
gotoxy(64, 20); textcolor(memc[30]); cprintf("M30");

gotoxy(69, 15); textcolor(memc[31]); cprintf("M31");
gotoxy(69, 16); textcolor(memc[32]); cprintf("M32");
gotoxy(69, 17); textcolor(memc[33]); cprintf("M33");
gotoxy(69, 18); textcolor(memc[34]); cprintf("M34");
gotoxy(69, 19); textcolor(memc[35]); cprintf("M35");
gotoxy(69, 20); textcolor(memc[36]); cprintf("M36");

gotoxy(74, 15); textcolor(memc[37]); cprintf("M37");
gotoxy(74, 16); textcolor(memc[38]); cprintf("M38");
gotoxy(74, 17); textcolor(memc[39]); cprintf("M39");
gotoxy(74, 18); textcolor(memc[40]); cprintf("M40");
gotoxy(74, 19); textcolor(memc[41]); cprintf("M41");
gotoxy(74, 20); textcolor(memc[42]); cprintf("M42");

textcolor(7);

//.................... Ende Ausgabe des Speichers .............
}

//---------------------- ClearColor -------------------------
//-------- Farbe fr leere Mem - Felder = blau (1) ----------

void defcolor(void)
{

	//FOR x = 1 TO 50
	//        memc(x) = 1             'Farbe der Speicherzelle = blau
	//NEXT x

	for (x=0; x<=43; x++)
	{
	  memc[x] = 1;
	}

	  //memc[5] = 2;  // 2 = grn

//################# Ende Voreinstellungen ####################

}
//Maus - Functions

// maus_rst --> Maus Reset
// maus_an  --> Mauszeiger sichtbar machen
// maus_aus --> Mauszeiger ausschalten
// maus_pos --> Mausposition ausgeben (taste, x, y)


void maus_rst(void)
{
	asm {
		mov ax, 0
		int 0x33
	}
}


void maus_an(void) {

	asm {
		mov ax, 1
		int 0x33
	}
}

void maus_aus(void)
{
	asm {
		mov ax, 2
		int 0x33
	}
}

void maus_pos(int *mtaste,int *mx,int *my)
{
	int rt, rx, ry;
	asm {
		mov ax, 3
		int 0x33
		mov rt, bx
		mov rx, cx
		mov ry, dx
	}
	*mtaste = rt;
	*mx = rx / 8;
	*my = ry / 8;

}


//+++++++++++++++++++++ Animation in der Titelzeile ++++++++++++++++++




void show(void)
{



	static unsigned char tdb[] = {"Thorstens Lasershow"};

//	DIM tdb$(20)
//	DATA "T","h","o","r","s","t","e","n","s"," "
//	DATA "L","a","s","e","r","s","h","o","w"

//	FOR x = 1 TO 19
//		READ tdb$(x)
//	NEXT x

//RETURN




 static unsigned char tdbindex = 0;
 unsigned char color;

 //sh = 0

 //c = c + 1: IF c = 16 THEN c = 1
 color = random(17);





	//LOCATE 2, 24 + tdb: COLOR C: PRINT tdb$(tdb)
	gotoxy(25 + tdbindex, 2);
	textcolor (color);
	cprintf("%c", tdb[tdbindex]);

	//tdb = tdb + 1: IF tdb = 20 THEN tdb = 1
	if (tdbindex++ > 18) tdbindex = 0;
	//tdbindex ++, (erst wird die Klammer ausgefhrt, dann die
	//if - Abfrage



 textcolor(7);	//COLOR 7

}

//................. Ende Animation in der Titelzeile ................

//###################################################################
//################# Auswertung Tastatur und Maus ####################
//###################################################################

void eingabe(void)

{

//#################### Abfrage der Tasten ###########################

if (kbhit())
{

tastea = getch();

if (tastea == 32 || tastea == 27)
	ende = 0;		//Programmende mit Leertaste oder ESC

if (tastea == 0)                //prfen, ob 2-Byte-Taste gedrckt
	tasteb = getch();


if (tastea == 'r')			//Richtung Motor 1
 {
	if (ra == 1) ra = 2;
	else ra = 1;
 }


//Motor 1 Sinus
//Feineinstellung
	if ((tastea == 0) && (tasteb == 72) && (ta <= 998)) ta ++;
	if ((tastea == 0) && (tasteb == 80) && (ta >= 1)) ta --;

	if ((tastea == 0) && (tasteb == 77) && (pa <= 998)) pa ++;
	if ((tastea == 0) && (tasteb == 75) && (pa >= 1)) pa --;

	if ((tastea == 0) && (tasteb == 63)) 	//Motor 1 aus
	{
		ta = 0;
		pa = 0;
	}


//Motor 2 Sinus
//Feineinstellung
	if (tastea == 56 && tb <= 998) tb ++;
	if (tastea == 50 && tb >= 1) tb --;

	if (tastea == 54 && pb <= 998) pb ++;
	if (tastea == 52 && pb >= 1) pb --;

	if ((tastea == 0) && (tasteb == 64))
	{
		tb = 0;
		pb = 0;
	}



//Motor 3 Blanking
//Feineinstellung
	if ((tastea == 0) && (tasteb == 71) && (tc <= 998)) tc ++;
	if ((tastea == 0) && (tasteb == 79) && (tc >= 1)) tc --;

	if ((tastea == 0) && (tasteb == 81) && (pc <= 998)) pc ++;
	if ((tastea == 0) && (tasteb == 83) && (pc >= 1)) pc --;

	if ((tastea == 0) && (tasteb == 65)) 	//Motor 1 aus
	{
		tc = 0;
		pc = 0;
	}


}

//##################### Abfrage der Maus ###########################
if (maust != 0)
{

	mauszaehler = 0;

	//Programmende
	if (mausy == 21)
	{
		if ((mausx >= 24) && (mausx <= 46))
		{
			ende = 0;
		}
	}
	//programmende


	//Motor 1 Richtung

	if (mausy == 10)
	{
		if ((mausx >= 1) && (mausx <= 18))
		{
			if (ra == 1) ra = 2;
			else ra = 1;
		}
	}



	//Motor 1 Sinus

		if (mausy == 8)
		{
			if (mausx == 17)
			{
				if ((maust == 1) && (ta < 999)) ta ++;
				if ((maust == 2) && (ta < 990)) ta += 10;
				if ((maust == 3) && (ta < 900)) ta += 100;
			}

			if (mausx == 13)
			{
				if ((maust == 1) && (ta > 0)) ta --;
				if ((maust == 2) && (ta > 10)) ta -= 10;
				if ((maust == 3) && (ta > 100)) ta -= 100;
			}

			if ((mausx == 19) && (maust == 1))
			{
				ta = 0;
			}

			if (mausx == 35)
			{
				if ((maust == 1) && (pa < 999)) pa ++;
				if ((maust == 2) && (pa < 990)) pa += 10;
				if ((maust == 3) && (pa < 900)) pa += 100;
			}

			if (mausx == 31)
			{
				if ((maust == 1) && (pa > 0)) pa  --;
				if ((maust == 2) && (pa > 10)) pa -= 10;
				if ((maust == 3) && (pa > 100)) pa -= 100;
			}

			if ((mausx == 37) && (maust == 1))
			{
				pa = 0;
			}


		//Motor 2 Sinus

			if (mausx == 57)
			{
				if ((maust == 1) && (tb < 999)) tb ++;
				if ((maust == 2) && (tb < 990)) tb += 10;
				if ((maust == 3) && (tb < 900)) tb += 100;
			}

			if (mausx == 53)
			{
				if ((maust == 1) && (tb > 0)) tb --;
				if ((maust == 2) && (tb > 10)) tb -= 10;
				if ((maust == 3) && (tb > 100)) tb -= 100;
			}

			if ((mausx == 59) && (maust == 1))
			{
				if (mausy == 8) { tb = 0; }
			}

			if (mausx == 75)
			{
				if ((maust == 1) && (pb < 999)) pb ++;
				if ((maust == 2) && (pb < 990)) pb += 10;
				if ((maust == 3) && (pb < 900)) pb += 100;
			}

			if (mausx == 71)
			{
				if ((maust == 1) && (pb > 0)) pb  --;
				if ((maust == 2) && (pb > 10)) pb -= 10;
				if ((maust == 3) && (pb > 100)) pb -= 100;
			}

			if ((mausx == 77) && (maust == 1))
			{
				pb = 0;
			}

		} //if (mausy == 8) ende

		if (mausy == 17)
		{
			if (mausx == 17)
			{
				if ((maust == 1) && (tc < 999)) tc ++;
				if ((maust == 2) && (tc < 990)) tc += 10;
				if ((maust == 3) && (tc < 900)) tc += 100;
			}

			if (mausx == 13)
			{
				if ((maust == 1) && (tc > 0)) tc --;
				if ((maust == 2) && (tc > 10)) tc -= 10;
				if ((maust == 3) && (tc > 100)) tc -= 100;
			}

			if ((mausx == 19) && (maust == 1))
			{
				tc = 0;
			}

			if (mausx == 35)
			{
				if ((maust == 1) && (pc < 999)) pc ++;
				if ((maust == 2) && (pc < 990)) pc += 10;
				if ((maust == 3) && (pc < 900)) pc += 100;
			}

			if (mausx == 31)
			{
				if ((maust == 1) && (pc > 0)) pc  --;
				if ((maust == 2) && (pc > 10)) pc -= 10;
				if ((maust == 3) && (pc > 100)) pc -= 100;
			}

			if ((mausx == 37) && (maust == 1)) //?
			{
				pc = 0;
			}
		 } //if (mausy == 17) ende

// ----------  Reset der einzelnen Motoren ---------
//Mauskoordinaten:
//1/3 bis 11/3  	Koordinaten Motor 1
//40/3 bis 50/3         Koordinaten Motor 2
//1/12 bis 11/12	Koordinaten Motor 3

//Motor A Sinus Reset
if ((mausy == 3) && (maust == 1))
	{
	if ((mausx >= 1) && (mausx <= 11))
		{
		ta = 0;
		pa = 0;
		}

//Motor B Sinus Reset
	if ((mausx >= 40) && (mausx <= 50))
		{
		tb = 0;
		pb = 0;
		}
	}

//Motor C Blanking Reset
if ((mausy == 12) && (maust == 1))
	{
		if ((mausx >= 1) && (mausx <= 11))
		{
		tc = 0;
		pc = 0;
		}
	}

	//############## Speicherfeld ####################

	//Berechnung der Matrix

	if ((mausx >= 42) && (mausx <= 46)) { memx = 1 + 0; }
	if ((mausx >= 47) && (mausx <= 51)) { memx = 1 + 6; }
	if ((mausx >= 52) && (mausx <= 56)) { memx = 1 + 12; }
	if ((mausx >= 57) && (mausx <= 61)) { memx = 1 + 18; }
	if ((mausx >= 64) && (mausx <= 66)) { memx = 1 + 24; }
	if ((mausx >= 67) && (mausx <= 71)) { memx = 1 + 30; }
	if ((mausx >= 72) && (mausx <= 76)) { memx = 1 + 36; }

	if ((mausx >= 42) && (mausx <= 76))
	{
		if ((mausy >= 14) && (mausy <= 19))
		{
			memy = mausy - 14;
			gotoxy(2, 2); cprintf("%3i", memx + memy);

	//-------------- Werte lesen ---------------------

			if (maust == 1)
			{
				ta = memta[memx + memy]; pa = mempa[memx + memy];
				tb = memtb[memx + memy]; pb = mempb[memx + memy];
				tc = memtc[memx + memy]; pc = mempc[memx + memy];
				ra = memra[memx + memy];
			}

	//------------- Werte speichern ---------------------

			if (maust == 2)
			{
				memta[memx + memy] = ta; mempa[memx + memy] = pa;
				memtb[memx + memy] = tb; mempb[memx + memy] = pb;
				memtc[memx + memy] = tc; mempc[memx + memy] = pc;
				memra[memx + memy] = ra;
				memc[memx + memy] = 2;  gotoxy(2, 5); cprintf("%2i", memc[memx + memy]);
			}





		} //if ((mausy >= 14) && (mausy <= 19)) ende
	memwerte();
	} //if ((mausx >= 42) && (mausx <= 76)) ende


	if ((mausy == 12) && (maust == 1))
	{
		if ((mausx >= 40) && (mausx <= 45)) { lfdisk(); }
		if ((mausx >= 47) && (mausx <= 52)) { stdisk(); }
		if ((mausx >= 72) && (mausx <= 78)) { clrmem(); }
	}





} //if (maust != 0) ende

ausgabe();

}





//********************************************************************
//********** Beginn des Hauptprogramms- und Abbruchschleife **********
//********************************************************************

void start()
{


while (ende != 0)
{


 //WHILE ende <> 0

 //------------------Abfrage Wert Tastatur Maus------------------------

		//a$ = INKEY$
  maus_pos(&maust, &mausx, &mausy);   //Daten von maus_pos holen

			//mausx = GetMaus(3)
			//mausy = GetMaus(4)
			//maust = GetMaus(0)

 //IF a$ <> "" THEN GOSUB eingabe
 if (kbhit()) eingabe();
 //IF maust <> 0 THEN GOSUB eingabe
 if ((maust != 0) && (mauszaehler >= 998)) eingabe();
 if (mauszaehler < 1000) mauszaehler ++;

 gotoxy(1, 24); cprintf("%4i", mauszaehler);
 //----------------- Motor Bit setzen ? -------------------
 //     IF xa >= ta THEN ma = r: xa = 0: ca = 0: da = 1
	if(xa >= ta) { ma = ra; xa = 0; ca = 0; da = 1; }
 //	IF xb >= tb THEN mb = 4: xb = 0: cb = 0: db = 1
	if(xb >= tb) { mb = 4; xb = 0; cb = 0; db = 1; }
 //	IF xc >= tc THEN mc = 8: xc = 0: cc = 0: dc = 1
	if(xc >= tc) { mc = 8; xc = 0; cc = 0; dc = 1; }
 //
 //'----------------- Motor Bit lschen? -------------------
 //	IF ya >= pa THEN ma = 0: ya = 0: ca = 1: da = 0
	if(ya >= pa) { ma = 0; ya = 0; ca = 1; da = 0; }
 //	IF yb >= pb THEN mb = 0: yb = 0: cb = 1: db = 0
	if(yb >= pb) { mb = 0; yb = 0; cb = 1; db = 0; }
 //	IF yc >= pc THEN mc = 0: yc = 0: cc = 1: dc = 0
	if(yc >= pc) { mc = 0; yc = 0; cc = 1; dc = 0; }



 //'************************* Index *****************************

 //'---------------------- Index Impuls ++ ----------------------

 //	IF ca = 1 THEN xa = xa + 1
	if(ca == 1) { xa ++; }
 //	IF cb = 1 THEN xb = xb + 1
	if(cb == 1) { xb ++; }
 //	IF cc = 1 THEN xc = xc + 1
	if (cc == 1) { xc ++; }


 //'---------------------- Index Pause ++ -----------------------

 //	IF da = 1 THEN ya = ya + 1
	if(da == 1) { ya ++; }
 //	IF db = 1 THEN yb = yb + 1
	if(db == 1) { yb ++; }
 //	IF dc = 1 THEN yc = yc + 1
	if(dc == 1) { yc ++; }

 //'------------------- Ausgabe Index ----------------------------

 //LOCATE 7, 16: PRINT xa          'Index Impuls Motor a
   gotoxy(16, 7); cprintf(" %3i", xa);
 //LOCATE 7, 33: PRINT ya          'Index Pause  Motor a
   gotoxy(33, 7); cprintf(" %3i", ya);

 //LOCATE 7, 56: PRINT xb          'Index Impuls Motor b
   gotoxy(56, 7); cprintf(" %3i", xb);
 //LOCATE 7, 73: PRINT yb          'Index Pause  Motor b
   gotoxy(73, 7); cprintf(" %3i", yb);

 //LOCATE 16, 16: PRINT xc         'Index Impuls Motor c
   gotoxy(16, 16); cprintf(" %3i", xc);
 //LOCATE 16, 33: PRINT yc         'Index Pause  Motor c
   gotoxy(33, 16); cprintf(" %3i", yc);


 //'-------------Ausgabe der Daten auf den Port--------------------

 //OUT port, ma + mb + mc
 outp(port, ma + mb + mc);

 //'-------------------Anzeigen der Daten--------------------------

 //LOCATE 22, 76: PRINT ma + mb + mc
   gotoxy(77, 22); cprintf("%2i", ma + mb + mc);

 //LOCATE 22, 60: PRINT ma
   gotoxy(61, 22); cprintf("%2i", ma);
 //LOCATE 22, 66: PRINT mb
   gotoxy(67, 22); cprintf("%2i", mb);
 //LOCATE 22, 71: PRINT mc
   gotoxy(72, 22); cprintf("%2i", mc);

 //'-------------------------- Show----------------------------------

 //REM GOSUB show



 //------------- Anzeigen der Maus - Position ----------------------


 if (mausx != mausaltx)
 {
	gotoxy(11, 22); cprintf("%2i", mausx); //LOCATE 22, 11: PRINT mausx
	mausaltx = mausx;
 }

 if (mausy != mausalty)
 {
	gotoxy(16, 22); cprintf("%2i", mausy); //LOCATE 22, 16: PRINT mausy
	mausalty = mausy;
 }

 if (maust != mausaltt)
 {
	gotoxy(21, 22); cprintf("%2i", maust); //LOCATE 22, 21: PRINT maust
	mausaltt = maust;
 }


 show();     //Animation in der Titelzeile aufrufen
 //mausaltx = mausx;
 //mausalty = mausy;
 //mausaltt = maust;

//WEND
//RETURN

//'##################### Ende des Hauptprogramms ######################

 }
}
//09.08.00 Neo, The Dosbreaker

// #include "lfdisk.cpp"
// #include "stdisk.cpp"
// #include "clrmem.cpp"
// #include "maske.cpp"
// #include "ausgabe.cpp"
// #include "memwerte.cpp"
// #include "defcolor.cpp"
// #include "mausfunc.cpp"
// #include "show.cpp"
// #include "eingabe.cpp"
// #include "start.cpp"


void main(void)
{

 clrscr();
 printf("Initialising...   Please wait!");
 sleep(1);
 clrscr();

 asm {
  mov ah, 1
  mov ch, 20
  mov cl, 0
  int 0x10
 }

 clrscr();
 clrmem();
 defcolor();
 maske();
 ausgabe();
 memwerte();
 maus_rst();
 maus_an();
 start();

 //getch(); //warten auf Tastendruck ;-)
}
