[comp.lang.pascal] I/O Port weirdness

bb16@prism.gatech.EDU (Scott Bostater) (10/02/90)

This sort of half belongs in this newsgroup and half in c.s.i.p.hardware, but
I didn't want to take the flak for using Pascal instead of C :-)

I've run into a problem/bug with TP IDE and the use of I/O ports.  I'm trying
to read from an I/O port. Sometimes it works, sometimes it doesn't. 

Program Test;

var
  a: Byte;

Begin
  a := Port[$300];
  Writeln( 'a = ', a);
End.

This simple program has several different outcomes depending on the machine
I run it on and whether I use the IDE or use the command line compiler.  The
program behaves properly when compiled with TPC and executed via TD.

Machine                IDE         Result
--------              ------       ----------------------
IBM XT  (true blue)     Yes        Reboots Computer
IBM XT  (true Blue)     No         a = 175
80386 clone             Yes        a = 255
80386 clone             No         a = 255

During the testing process, I ended up pulling all of the "strange" cards out
of the XT so that now there is only a CGA card, Floppy controller, HD 
controller, and Multifunction I/O board (384K/1s/1p/1g).  

The port I'm trying to read from is $300, which does not exist in either 
machine.  I would expect to get $FF back from reading it (since the data lines
should float high).  

Has anybody else experienced this problem?  Anybody have an idea has to how to
fix it?  I'ld really like to be able to use the IDE because I'm used to it, but
I'd also like to know what's causing the problem.

-- 
Scott Bostater      Georgia Tech Research Institute - Radar Systems Analysis
"My soul finds rest in God alone; my salvation comes from Him"  -Ps 62.1
uucp:     ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!bb16
Internet: bb16@prism.gatech.edu

KRW1@Lehigh (10/03/90)

Use the following inline function instead of the Pascal port array
for reading:

    function inport(x: integer): byte;
      inline($5a/$eb/$00/$ec);

Then instead of p := port[x], use p := inport(x).

The problem is that on fast processors, the input may not be returned
before the result is used.  The inline function includes a short jump
which flushes the prefetch queue on 286's and higher, slowing down
the processor for the next (in) instruction.  -- Kevin

ddavidso@sunc.mqcc.mq.oz.au (Dean Davidson) (10/03/90)

In article <14401@hydra.gatech.EDU> bb16@prism.gatech.EDU (Scott Bostater) writes:
>I've run into a problem/bug with TP IDE and the use of I/O ports.  I'm trying
>to read from an I/O port. Sometimes it works, sometimes it doesn't. 
>
>Program Test;
>
>var
>  a: Byte;
>
>Begin
>  a := Port[$300];
>  Writeln( 'a = ', a);
>End.
>
I've had this sort of problem - in particular using Turbo Asynch in the IDE

I put it down to the fact that there is probably a clash of interupts
or interupts are disabled and not re-enabled or something

It was particularly noticable if you traced right into the routine

I just learned to live with it !


--
Dean Davidson                                 ddavidso@mqccsuna.mqcc.mq.oz.au
User Support                                  Phone 61 2 805 7436
Macquarie University                          Fax   61 2 805 7433
NSW 2109 Australia                            VK2 ZID