[comp.sys.hp] HP9836 BASIC -- HELP !!

ners001@vmsa.technion.ac.il (01/02/89)

*******

Does anybody out there know what the following lines of BASIC mean?
 (this is supposedly written for an HP 9836)

SUB Out_word(@GPIB,INTEGER Xbuf(*),N)
     INTEGER Odata
     FOR I=1 TO N
       Odata=ROTATE(Xbuf(I),8)
       OUTPUT @GPIB USING "#,W";Odata
     NEXT I
     SUBEND

This obviously is sending data to a GPIB device, but what would be the
equivalent in C?  What does the ROTATE function do?   What does the
output look like (binary word transfer or formatted ASCII)?

Thanks for all your help,

Benjamin Cohen
NERS001@VMSA.TECHNION.AC.IL     (bitnet)

scowles@lll-lcc.llnl.gov (Sid Cowles) (01/03/89)

In article <281@vmsa.technion.ac.il> ners001@vmsa.technion.ac.il writes:
>Does anybody out there know what the following lines of BASIC mean?
>
>SUB Out_word(@GPIB,INTEGER Xbuf(*),N)
>     INTEGER Odata
>     FOR I=1 TO N
>       Odata=ROTATE(Xbuf(I),8)
>       OUTPUT @GPIB USING "#,W";Odata
>     NEXT I
>     SUBEND
>
>             ...  What does the ROTATE function do?   What does the
>output look like (binary word transfer or formatted ASCII)?

benjamin,
the rotate function is described as:
"this function returns an integer which equals the value obtained by
shifting the 16-bit binary representation of the argument by the
number of bit positions specified.  the shift is performed with
wrap-around."
i'd guess that the io-path, @gpib, was assigned with format off
since the output statement is using a 2 byte word ("W") format with
no end-of-line sequence.
i hope this helps.
sid
=======================================================================
s cowles                         att:  +1 415 423 0929
lawrence livermore national lab  uucp: {backbone}!lll-lcc!scowles
environmental sciences division  internet:  scowles@lll-lcc.llnl.gov
p. o. box 5507
L-524
livermore, california  94550

steve@hpfcdc.HP.COM (Steve Taylor) (01/04/89)

Benjamin Cohen asks:
}  SUB Out_word(@GPIB,INTEGER Xbuf(*),N)
}       INTEGER Odata
}       FOR I=1 TO N
}         Odata=ROTATE(Xbuf(I),8)
}         OUTPUT @GPIB USING "#,W";Odata
}       NEXT I
}       SUBEND
}  This obviously is sending data to a GPIB device, but what would be the
}  equivalent in C?  What does the ROTATE function do?

It appears the program is sending data to a device which expects low-byte,
high-byte, rather than high-byte, low-byte.  Since ROTATE works on 16-bit
quantities, the value of 8 means swap bytes.

}  What does the
}  output look like (binary word transfer or formatted ASCII)?

As Sid Cowles says:  i'd guess that the io-path, @gpib, was assigned with
}  format off since the output statement is using a 2 byte word ("W") format
}  with no end-of-line sequence.

The "#" says no eol.  The swap above also implies binary data.  To be sure,
look for the statement ASSIGN @Gpib TO ... in the calling portion of the
program.  FORMAT OFF is the default for devices.  If it were formatted ASCII
then the ASSIGN statement would include a FORMAT ON clause.

I'm not familiar with DIL, so perhaps someone who is will give you the C
equivalent.
						Regards, Steve Taylor

holt@hp-sdd.HP.COM (Holt Mebane) (01/04/89)

*** SORRY TO POST, BUT COULD NOT SEND DIRECTLY ***

In article <281@vmsa.technion.ac.il> ners001@vmsa.technion.ac.il writes:
>*******
>
>Does anybody out there know what the following lines of BASIC mean?
> (this is supposedly written for an HP 9836)
>
>SUB Out_word(@GPIB,INTEGER Xbuf(*),N)
>     INTEGER Odata
>     FOR I=1 TO N
>       Odata=ROTATE(Xbuf(I),8)
>       OUTPUT @GPIB USING "#,W";Odata
>     NEXT I
>     SUBEND
>
>This obviously is sending data to a GPIB device, but what would be the
>equivalent in C?  What does the ROTATE function do?   What does the
>output look like (binary word transfer or formatted ASCII)?
>
>Thanks for all your help,
>
>Benjamin Cohen
>NERS001@VMSA.TECHNION.AC.IL     (bitnet)

The ROTATE function does a logical rotate on a 16 bit operand. If the
bit position displacement argument (in this case 8) is positive, it does
a rotate right; negative, left. The output specifier ("#,W") specifies
that the output is word-wide, binary, no carriage-return or linefeed.

So, what this program is doing is swapping bytes in a word and outputting
them to GPIB. Now if GPIB is set up to be the HPIB interface, a logical
question is "What is word-wide since the GPIB is inherently 8 bits wide?"
Well, it will output the data in 2 bytes, MSB first. 
Hope this helps.

                                Holt Mebane
_________________________________________________________________________
UUCP  : {hplabs|hp-pcd|hpfcla|hpda|noscvax|gould|ucsd}!hp-sdd!holt
UUCP  : {cbosgd|allegra|decvax|gatech|sun|tektronix}!hplabs!hp-sdd!holt
ARPA  : hp-sdd!holt@nosc.arpa
CSNET : hp-sdd!holt@hplabs.csnet
USmail: 16399 W. Bernardo Drive, San Diego CA 92127-1899 USA
Phone : (619) 592-4882

fritz@hpfclp.SDE.HP.COM (Gary Fritz) (01/04/89)

I would guess that the @Gpib device is assigned to be format-ON, though
(if I remember correctly, and if @Gpib points to a device and not a file)
it won't make any difference in this case.  The end result of the code is 
that it outputs the 16-bit data in the array with the top and bottom bytes of 
each integer swapped.  (Rotating a 16-bit integer by 8 bits swaps the bytes.)
The output is unformatted, since the "W" specifier in OUTPUT USING says
to output a 16-bit Word without formatting.

It would be roughly equivalent to:

(void) Out_word(Gpib_fd, Xbuf, N)
  int Gpib_fd;				/* File Descriptor of GPID device */
  short Xbuf[];				/* Assumes 16-bit short */
  int N;
{
  int i, ret;
  short Odata;
  for (i=0; i<N; i++) {
    Odata = (Xbuf[i] >> 8 & 0xff) | (Xbuf[i] << 8 & 0xff00);  /* swap bytes */
    ret = write(Gpib_fd, &Odata, 2);
    if (ret < 2)
      { /* handle error */ }
    }
}

The 9836 (and standalone BASIC on all Series 200 & 300 computers) would 
actually output the bytes 2 at a time like this.  It's a single-tasking 
system tuned for I/O performance, and can spit out bytes faster than 
it could if it had to worry about buffering.  Presumably this won't
make any difference to your application, unless your GPIO device depends
on getting its data in small, evenly-spaced chunks.

(If you wanted a more exact duplication of the BASIC code you gave,
you would replace the "write" above with a "printf" [== OUTPUT USING]
that printed only an unformatted 16-bit quantity, and immediately flushed 
its buffers.  I never claimed your BASIC code was efficient.  :-)

Standard disclaimer:  I haven't written any BASIC for about 6 years, and
make no guarantees.  This is not an official statement of HP, etc. etc.

Gary Fritz

steve@hpfcdc.HP.COM (Steve Taylor) (01/05/89)

>> 		FORMAT OFF is the default for devices.  
Oops /.\  Should say,  ON  "   "    "      "     "   .

"W" will keep the data from being converted to an ASCII string, as Gary said.
 Sort of like doing CHR$(x) on both bytes of the word.		SmT