Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Can someone please help me port this C code?

    This is a C code written for windows to help identify the address of a parallel port:
    /*This piece of code determines if the PC has any parallel adapter*/
    /*If yes, it finds out and prints the addresses of the DATA, CONTROL */
    /*and the STATUS ports*/
    #include <stdio.h>
    #include <dos.h>
    int dport, cport, sport, select, offset;
    clrscr(); /*clear screen*/
    printf("\tProgram to detect the parallel printer adapter.\n");
    printf("Enter 1, 2 or 3 to detect LPT1, LPT2 or LPT3 respectively.\n\n");
    /*wait for a keystroke*/
    /*loop indefinitely if the key pressed is not '1', '2' or '3'*/
    while ( (select != '1') && (select != '2') && (select != '3') )
    printf("Invalid number. Enter 1, 2 or 3\n");
    if(select =='1') offset = 0x08;
    if (select =='2') offset = 0x0a;
    if (select =='3') offset = 0x0c;
    /*now look into BIOS area to determine the address of the particular*/
    /*parallel adapter*/
    dport=peek(0x40, offset);
    /*If the address is zero, means that particular parallel adapter*/
    /*is not present. No point in continuing. Abort the code here*/
    if (dport == 0)
    printf("Sorry, On this machine LPT%d does not exist\n", select-'0');
    /*else print the port addresses of the DATA, STATUS and CONTROL ports*/
    printf("\nLPT%d detected!\n", select -'0');
    printf("DATA port is %x\n", dport);
    printf("STATUS port is %x\n", dport+1);
    printf("CONTROL port is %x\n", dport+2);
    I am well aware than this wont work on linux becuase we use things such as ioperm() to get port access and inb() and outb() to read and write data.

    Can someone translate this code to linux C? I am also unaware as to why those offset values where chosen.


  2. #2


    Please read the HOWTO about IOPerm (chapter 2):

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts