Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

port programming

Status
Not open for further replies.

bahati

Programmer
Joined
Feb 14, 2005
Messages
1
Location
KE
HI,
i have written the code below. I need help on how to modify the program so that it takes its input (reads) from a file and then the data read from the port is returned to another new file specified by a user. This program has been written to send data to and read from an encrypting circuitry ( stream cipher).

SOFTWARE DESIGN.

/* *******************************************************/
/*This program is intended to WRITE and READ data to and from the SPP port */

/*Author: Mr.Kebungo Dominic. */

/*Date: 8-12 Feb. 2005.
/*Reference: . */

/******************************************************************/
#include <stdio.h> /* required so as to access the filesystem*/
#include <dos.h>
#include <time.h>
#define DATA 0x378 /*Data Register base address*/
#define STATUS DATA+1 /* Status Register address*/
#define CONTROL DATA+2 /*Control Register address*/

main()
{
char s;
char c;
c='A';


outport(CONTROL,inportb(CONTROL)&0xF0|0x04); /*initialise the
CONTROL port for data input*/

outportb(DATA, c); /*write c to the DATA register*/
delay(4);/*allow for propagation delay time*/

s=(inportb(STATUS)&0xF0); /* read MSnibble*/

s=s|(inportb(CONTROL)&0x0F);/*Read LSnibble*/

s=s^0x84; /*toggle bit 2 and 7 */
/*pins 11 and 14 are hardware inverted*/

printf("character: %c becomes: %c\n", c,s);

return (0);

}
 
Well first of all, write a function to do the work
Code:
char encrypt ( char c ) {
    char s;
    outport(CONTROL,inportb(CONTROL)&0xF0|0x04);
    /* initialise the CONTROL port for data input*/
    outportb(DATA, c);   /*write c to the DATA register*/
    delay(4);/*allow for  propagation delay time*/

    s=(inportb(STATUS)&0xF0);  /* read MSnibble*/
    s=s|(inportb(CONTROL)&0x0F);/*Read LSnibble*/
    s=s^0x84; /*toggle bit 2 and 7 */
                 /*pins 11 and 14 are hardware inverted*/
    return s;
}

Then your main would be
Code:
int main() {
    char c = 'A';
    char s = encrypt(c);
    printf("character: %c becomes: %c\n", c,s);
    return 0;
}

Now all you need do is
- open and close files (fopen, fclose)
- read and write characters (fgetc, fputc)

Oh, and that delay(4) will really hurt your performance when you're reading large files.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top