Sie sind auf Seite 1von 6

#include

#include
#include
#include
#include

<stdio.h>
<stdlib.h>
<conio.h>
<windows.h>
<time.h>

typedef short _stdcall (*inpfuncPtr)(short portaddr);


typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
void right (int r);
void left (int L);
void wait(int milli);
void brake(int onoff);
short scan(void);
inpfuncPtr inp32;
int main(void)
{
HINSTANCE hLib;
oupfuncPtr oup32;
/* Load the library */
hLib = LoadLibrary("inpout32.dll");
if (hLib == NULL) {
printf("LoadLibrary Failed.\n");
return -1;
}
/* get the address of the Inp32() function */
inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
if (inp32 == NULL) {
printf("GetProcAddress for Inp32 Failed.\n");
return -1;
}
/* get the address of the Out32() function */
oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (oup32 == NULL) {
printf("GetProcAddress for Oup32 Failed.\n");
return -1;
}
// printf("\nProcAddress for Inp32=%d",inp32);
// printf("\nProcAddress for Oup32=%d\n\n\n",oup32);
/***************************************************************/
/* Initialization complete - now access the port(s) */
int x=0;
short in=0;
/*while(1){
in=(inp32)(0x379);
printf("%d\n",in);
system("pause");
}*/
do{
in=0;
in=scan();
while (in==1)
{
x=0;

while ((x<4)&&(in==1)) //////BRAKE AND RIGHT


{
brake(1);right(x);
switch (x)
{
case 0: (oup32)(0x378,0xF8); //1111 1000
break;
case 1:(oup32)(0x378,0xFC); //1111 1100
break;
case 2:(oup32)(0x378,0xFE); //1111 1110
break;
case 3:(oup32)(0x378,0xFF); //1111 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}
}
while (in==2) //////BRAKE AND LEFT
{
x=0;
while ((x<4)&&(in==2))
{
left(x);brake(1);
switch (x)
{
case 0: (oup32)(0x378,0x1F); //0001 1111
break;
case 1:(oup32)(0x378,0x3F); //0011 1111
break;
case 2:(oup32)(0x378,0x7F); //0111 1111
break;
case 3:(oup32)(0x378,0xFF); //1111 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}
}
while (in==3) //////LEFT
{
x=0;
while ((x<4)&&(in==3))
{
left(x);brake(0);
switch (x)
{
case 0: (oup32)(0x378,0x10); //0001 0000
break;
case 1:(oup32)(0x378,0x30); //0011 0000
break;
case 2:(oup32)(0x378,0x70); //0111 0000
break;
case 3:(oup32)(0x378,0xF0); //1111 0000
break;
}

wait(250);
system("cls");
x++; in=scan();
}
}
while (in==6) //////RIGHT
{
x=0;
while ((x<4)&&(in==6))
{
brake(0);right(x);
switch (x)
{
case 0: (oup32)(0x378,0x08); //0000 1000
break;
case 1:(oup32)(0x378,0x0C); //0000 1100
break;
case 2:(oup32)(0x378,0x0E); //0000 1110
break;
case 3:(oup32)(0x378,0x0F); //0000 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}
}
while (in==5)
{
x=0;
while ((x<4)&&(in==5)) //////BRAKE
{
brake(1);brake(1);
(oup32)(0x378,0xFF); //1111 1111
wait(250);
system("cls");
x++; in=scan();
}
}
while (in==4)
{
x=0;
while ((x<4)&&(in==4)) //////HAZARD
{
brake(1);brake(1);
(oup32)(0x378,0xFF);//1111 1111
wait(250);
system("cls");
x++; in=scan();
}
while ((x<8)&&(in==4))
{
brake(0);brake(0);
(oup32)(0x378,0x00);//0000 0000
wait(250);
system("cls");
x++; in=scan();

}
}
while (in==0)
{
x=0;
while ((x<4)) //////HAZARD
{
brake(0);brake(0);
(oup32)(0x378,0x00);//1111 1111
wait(250);
system("cls");
x++; in=scan();
}
}
while (in==42)
{
x=0;
while ((in==42)) //////RANDOM
{
printf("It's on random >:| ");
(oup32)(0x378,(rand()));
wait((rand()%100));
x++; in=scan();
}
}
while (in==9001)
{
x=0;
while ((x<4)&&(in==9001)) //////HAZARD
{
switch (x)
{
case 0: (oup32)(0x378,0x80); //0000 1000
break;
case 1:(oup32)(0x378,0x40); //0000 1100
break;
case 2:(oup32)(0x378,0x20); //0000 1110
break;
case 3:(oup32)(0x378,0x10); //0000 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}
while ((x<8)&&(in==9001))
{
switch (x)
{
case 7: (oup32)(0x378,0x01); //0000 1000
break;
case 6:(oup32)(0x378,0x02); //0000 1100
break;
case 5:(oup32)(0x378,0x04); //0000 1110
break;
case 4:(oup32)(0x378,0x08); //0000 1111
break;
}

wait(250);
system("cls");
x++; in=scan();
}
while ((x<12)&&(in==9001))
{
switch (x)
{
case 8: (oup32)(0x378,0x01); //0000 1000
break;
case 9:(oup32)(0x378,0x02); //0000 1100
break;
case 10:(oup32)(0x378,0x04); //0000 1110
break;
case 11:(oup32)(0x378,0x08); //0000 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}
while ((x<16)&&(in==9001)) //////HAZARD
{
switch (x)
{
case 15: (oup32)(0x378,0x80); //0000 1000
break;
case 14:(oup32)(0x378,0x40); //0000 1100
break;
case 13:(oup32)(0x378,0x20); //0000 1110
break;
case 12:(oup32)(0x378,0x10); //0000 1111
break;
}
wait(250);
system("cls");
x++; in=scan();
}}
}while (1);//Loops the main
}

///////////////////////////////////////////////////////////////////////////////
void right(int r)
{
char light[]="
";
int i;
for (i=0;i<=r;++i)
{light[(i)]='*';}
printf("%s",light);
}
///////////////////////////////////////////////////////////////////////////////
void left(int L)

{
char light[]="
";
int i;
for (i=0;i<=L;++i)
{light[(3-i)]='*';}
printf("%s",light);
}
///////////////////////////////////////////////////////////////////////////////
void wait(int milli)
{
milli=(milli+clock());
while (clock()<milli)
{/*lalalalllallalla*/}
}
///////////////////////////////////////////////////////////////////////////////
void brake(int rl)
{
char on[]="**** ";
char off[]="
";
int b=0;
if (rl==1)
{
printf("%s",on);
}
if (rl==0)
{
printf("%s",off);
}
}
///////////////////////////////////////////////////////////////////////////////
short scan(void)
{
short in=0,out=0;
short mask=0x38;
in=(inp32)(0x379);
//in=in&mask;
//bit 5=brake, 4=right, 3=left
if ((in==56)||(in==32)){out=5;} //00111000 Brake
if (in==24){out=4;} //00011000 Hazard
if (in==8){out=3;} //00001000 Left
if (in==16){out=6;} //00010000 Right
if (in==40){out=2;} //00101000 Brake and Left
if (in==48){out=1;} //00110000 Brake and Right
if (in==0){out=0;} //00000000 Nothing
if (in==64){out=42;} //asdjhaskdajlh
if (in==80){out=9001;} //asdjhaskdajlh
return out;

Das könnte Ihnen auch gefallen