Search code examples
c++iodos

Using inp() on 16Bit Dos 5with Turbo C++ 3.0


First off I'd like to say that I know this is a really outdated question. That,s probably why I can't find any information through google. (or I'm just worse at searching than I'd like to admit! haha.) All the results pretty much tell me that inp() & outp() are useless on modern systems because the kernel handles all input and output rather than the program. I'm running 16 Bit Dos from a 486 machine and I've been able to use outp() with my parallel port perfectly. I like 16 Bit Dos, and I'm not interested in learning a "new and improved" way of doing this on NT era systems and higher (at least not right now).

With that cleared up --

My question is in regards to inp(). I have an old hardcopy manual that says you pass a single variable, the port address, to inp(). In this case I assume that since I use 0x378 as the port for outp(), I'd use it for inp() as well. Since I haven't programmed to accept external input before, I wasn't sure what type of value I'd get from a simple on/off switch so I wrote this quick code to grab all new values-

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>

int main(void){
    clrscr();

    int input;
    int buff = 0;

    restart:

    input = inp(0x378);

        if(input != buff){
        cout<<input;
        buff = input;
        }

    goto restart;

}

I just used 'buff' so that it wouldn't keep spitting '255' out over and over and possibly cover up a different value when power was applied to an input pin. Needless to say, the only value that got printed was '255'.

When I write a program to output data to the "D" pins on the parallel port, I send a hex code to the port that corresponds with the desired output... Right now I am dealing with the "S" pins on the parallel port for input. Should I be getting a hex code back into the program?

Also, I went into the BIOS and made sure that the mode for the parallel port was in/out, not just out. After finding out that I had two modes, my wave of excitement quickly got crushed with the same lousy '255' output.

Any information to point me in the right direction would be helpful.

Thanks!


Solution

  • This looks thorough: http://www.beyondlogic.org/spp/parallel.htm

    Also, make sure you configure the parallel port in the BIOS for Bidirectional mode. Other possibilities are Output Only, EPP and ECP modes, but Bidirectional will work best for what you are trying to do. You'll need bit 5 in 0x37a to control the direction of the port. Also, the base address of the port you are using might not be 0x378...There are locations in memory to get the base addresses of LPT1-LPT4 (The BIOS setup page may tell you as well.)