mmm....well here it is...the program I've been trying to work for awhile now.......it is supposed to offer chatting over the parallel port with 2 DOS based computers...it's not working though and I don't know........the code is pretty long to post..but I don't know how to make it an attachment..........So just ignore this if you don't have enough free time on your hands...but if anyone does...I would love suggestions as to why it's not working...I'm sure there are plenty of ways to shorten it too, but right now I just want to try to get this version working.
This is how it works (if you haven't heard me rambling about it in previous posts).....there are 2 parts...send.c and receive.c.....The sending computer obviously runs SEND featured bellow:
Code:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <time.h>
char BinaryFull[9];
char send1[5];
char send2[5];
void displayBits( unsigned value );
void splitBits();
void DelaySec(int seconds);
void main()
{
char input[11];
int a=0;
outportb(0x378,0x00);
printf("\n\n\n\t\t Parallel Chat v0.5");
printf("\n\t\t ******************");
printf("\n\n\t\tSend (10 Char Max): ");
scanf("%s",&input);
while (input[a]!='\0')
{
displayBits(input[a]);
splitBits();
DelaySec(1);
outportb(0x378,send1);
DelaySec(2);
outportb(0x378,send2);
a++;
}
}
void displayBits( unsigned value )
{
unsigned c, displayMask = 1 << 7;
int x=0;
for ( c = 1; c <= 8; c++ ) {
BinaryFull[x]=value & displayMask ? '1' : '0';
value <<= 1;
if ( c % 8 == 0 )
putchar( ' ' );
x++;
}
}
void splitBits()
{
int x,y=0;
for (x=0; x < 8; x++)
{
if (x<=3) {
send1[x]=BinaryFull[x];
}
if (x>=4) {
send2[y]=BinaryFull[x];
y++;
}
}
}
void DelaySec(int seconds)
{
time_t cur_time = time((time_t *)NULL);
while(time((time_t *)NULL) < cur_time + (time_t)seconds);
}
Works like this....first it uses outportb to send a string of 0's over to the receiving side to clear out whats there...then it prompts for a string to enter...say you just enter "c"....it first makes the binary of C an array...it splits that array into 2 pieces (because the paralle port only has 5 input pins)....it then proceeds to send the first array of the first 4 binary numbers, then it pauses for a second, and sends the second string of binary numbers...and it's through....
RECEIVING SIDE - The receiving side is supposed to have a constant loop running...it first checks to see whats coming through the port using the inportb() command....If it doesn't equal 0. Then, it runs the function which takes the 4 bits from the in ports and converts it to the receive1 array (the function for converting the bits to an array looks a bit weird....because one of the parallel port pins is inverted, and it also adds 3 000's behind whatever string gets sent..long story..)...anyways....it reads inport again...and does the same thing with the second string...then if both strings have been sent, it puts them together to make the full character, converts the array into a number, then prints the corresponding character.....make sense? here's the receive code:
Code:
#include <stdio.h>
#include <dos.h>
#include <string.h>
int Read_Input();
void restoreBits(int Byte);
void makeChar();
char Binary[9];
char receive1[9], receive2[5];
int Char,y=0,Byte;
void main()
{
while (Char!='e')
{
int a;
Read_Input();
if ((Byte!=0) && (a==1))
{
restoreBits(Byte);
a++;
}
if ((Byte!=0) && (a==0))
{
restoreBits(Byte);
a++;
}
if (a==2)
{
makeChar();
printf("\n\t%c",Char);
a=0;
}
}
}
int Read_Input()
{
Byte=inportb(0x379);
return Byte;
}
void restoreBits(int Byte)
{
int x=0;
unsigned c, displayMask = 1 << 7;
Byte<<=1;
for (c=1; c<=8; c++)
{
Binary[x]=Byte & displayMask ? '1' : '0';
Byte <<= 1;
x++;
if (c % 8 ==0)
{
putchar(' ');
x++;
}
}
if (y==0)
{
for (x=0; x<4; x++)
{
receive1[x]=Binary[x];
}
}
if (y==1)
{
for (x=0; x<4; x++)
{
receive2[x]=Binary[x];
}
}
}
void makeChar()
{
int x;
int Convert[8]={128,64,32,16,8,4,2,1};
strcat(receive1,receive2);
for (x=0; x<8; x++)
{
if (receive1[x]=='1')
{
Char+=Convert[x];
}
y++;
}
}
If this is all non-sense since it's not commented or it just doesn't make sense, just ignore the message.