Turbo C Printer Port Bug/Error 
Author Message
 Turbo C Printer Port Bug/Error

Turbo C Printer Port Bug/Error
this program can not run on new PC, Why ????
it can run on 486 PC & My P-133 , But Can not run on My Friend P166
   & My school New PC P-100).
My Program Code:

#include <dos.h>
#include <stdio.h>
#include <bios.h>
union REGS in_regs, out_regs;

main()
{
   unsigned char result;

   while ( !kbhit() )
     {
       result = inportb(0x379);
       printf(" 0x%X\n",result);
     }

Quote:
}



Thu, 06 Jan 2000 03:00:00 GMT  
 Turbo C Printer Port Bug/Error

Quote:

> Turbo C Printer Port Bug/Error
> this program can not run on new PC, Why ????
> it can run on 486 PC & My P-133 , But Can not run on My Friend P166
>    & My school New PC P-100).
> My Program Code:

> #include <dos.h>
> #include <stdio.h>
> #include <bios.h>
> union REGS in_regs, out_regs;

> main()
> {
>    unsigned char result;

>    while ( !kbhit() )
>      {
>        result = inportb(0x379);
>        printf(" 0x%X\n",result);
>      }
> }

You're assuming that the io_port addresses of LPT1 are 0x378-0x37A. It's
not always the case, the io base-address of LPT1 can often be changed by
bios settings.

The real io base-address of LPT1 is stored at 0x0040:0x0008.
The real io base-address of LPT2 is stored at 0x0040:0x000A.
The real io base-address of LPT3 is stored at 0x0040:0x000C.

You can retrieve it with this magic formula:

unsigned short lpt1IoBase = *(unsigned short far *)0x408;

Then, change your code:

result = inportb(lpt1IoBase + 1);

Xavier

PS: It's not an ANSI C related question... Please, look at the right
newsgroup in the future.



Thu, 06 Jan 2000 03:00:00 GMT  
 Turbo C Printer Port Bug/Error



Quote:
>Turbo C Printer Port Bug/Error
>this program can not run on new PC, Why ????
>it can run on 486 PC & My P-133 , But Can not run on My Friend P166
>   & My school New PC P-100).
>My Program Code:

>#include <dos.h>
>#include <stdio.h>
>#include <bios.h>
>union REGS in_regs, out_regs;

>main()
>{
>   unsigned char result;

>   while ( !kbhit() )
>     {
>       result = inportb(0x379);
>       printf(" 0x%X\n",result);
>     }
>}

Hmm.. inportb() - haven't used that for a while.
The last time I messed with ports was to write a diagnostic utility for
a Zappa motherboard, which could read the state of DIP switches.

Are you running it under Windows 95?
Also, note that writing direct to ports flushes portability down the
loo. Ports are not always the same, even under the same OS. YMMV.

Also, change that 0x379 to 0x378 - the address of LPT1 is 0x378 - you
might have a forgiving computer that works with 379, but try 378.
--
Revised anti-spam in use : remove X to reply -
'Xnetbook' becomes 'netbook'

Anti-spam thermonuclear warheads cheap at only $300!



Sat, 08 Jan 2000 03:00:00 GMT  
 Turbo C Printer Port Bug/Error

Quote:

> Hmm.. inportb() - haven't used that for a while.
> The last time I messed with ports was to write a diagnostic utility for
> a Zappa motherboard, which could read the state of DIP switches.

[SNIP]

Quote:
> Also, change that 0x379 to 0x378 - the address of LPT1 is 0x378 - you
> might have a forgiving computer that works with 379, but try 378.

Hi James MacDonald,

I can't shake the opinion that you are confusing comp.lang.c with
comp.os.msdos.programmer. All that stuff about "dos.h" and using
ports and interrupts is *not* part of the standard C language.
It's all just some language extensions to one (or maybe two)
isolated special C compilers

Why do you want to let comp.os.msdos.programmer suffer isolation and
loneliness ? You rob them of their purpose in life :-)
(which is answering questions about MS-DOS).

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Sun, 09 Jan 2000 03:00:00 GMT  
 Turbo C Printer Port Bug/Error


scribbled :

Quote:

>> Hmm.. inportb() - haven't used that for a while.
>> The last time I messed with ports was to write a diagnostic utility for
>> a Zappa motherboard, which could read the state of DIP switches.

>[SNIP]

>> Also, change that 0x379 to 0x378 - the address of LPT1 is 0x378 - you
>> might have a forgiving computer that works with 379, but try 378.

>Hi James MacDonald,

>I can't shake the opinion that you are confusing comp.lang.c with
>comp.os.msdos.programmer. All that stuff about "dos.h" and using
>ports and interrupts is *not* part of the standard C language.
>It's all just some language extensions to one (or maybe two)
>isolated special C compilers

>Why do you want to let comp.os.msdos.programmer suffer isolation and
>loneliness ? You rob them of their purpose in life :-)
>(which is answering questions about MS-DOS).

But if we all stuck to the standard, we'd be incredibly boring :)
Anyway, I do most of my programming using DJGPP, so I deal with the DOS
stuff on a daily basis. It's kind of natural. Anyway, if they posted
here, I suppose it would be best to answer here too.

Next time I'll probably answer the question, crosspost the answer, and
mail the author to tell them off :)
--
Revised anti-spam in use : remove X to reply -
'Xnetbook' becomes 'netbook'

Anti-spam thermonuclear warheads cheap at only $300!



Mon, 10 Jan 2000 03:00:00 GMT  
 Turbo C Printer Port Bug/Error

Quote:

> But if we all stuck to the standard, we'd be incredibly boring :)

No, not really. c.l.c is the place for discussing standard C and it's
not very boring.

Quote:
> Anyway, I do most of my programming using DJGPP, so I deal with the DOS
> stuff on a daily basis. It's kind of natural. Anyway, if they posted
> here, I suppose it would be best to answer here too.

That's an opinion being held by many, but it poses the serious problem
of flooding c.l.c with unrelated questions (and answers). The number
of postings per day is already on a high level, but imagine most of
the Unix and MS-DOS postings coming here as well. This would drain
the Unix and MS-DOS newsgroups and render c.l.c almost useless.

Quote:
> Next time I'll probably answer the question, crosspost the answer, and
> mail the author to tell them off :)

You might point the questioner at comp.os.msdos.programmer and answer
the question there.

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Tue, 11 Jan 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Printer Port , Timing of printer port, Urgent ,LaserShow

2. Bugs in Turbo C's Patch for their First Bugs

3. bug in CS Form?

4. Newbie: separate big .cs file into small .cs files

5. HELP: Turbo C to Turbo C for Windows Lin k Error

6. Compiler error CS 1595 - Help

7. Using printer with turbo C?

8. Printer control with Turbo-C

9. printer port acces code ..

10. Trouble accessing printer port

11. Printer Port I/O

12. Switching printer ports

 

 
Powered by phpBB® Forum Software