[comp.sys.atari.8bit] reading bytes in Action!

SULLIVAN@suny-bing.CSNET (05/05/87)

John Sangster writes:

>I have just started writing in ACTION!, so pardon the dumb questions, but can
>anyone tell me if there is a way to read a block of bytes from a device in
>ACTION! without taking them one at a time?
>
>Specifically, GetD(channel) returns one byte, InputBD(channel) also returns
>one byte, and (I assume) InputMD(channel, buffer, maxchars) inputs groups
>of characters all right, but terminates input on an EOL character.  Or does
>it?  What I want to do is to read in a specified number of characters, except
>if End Of File occurs during the attempt, I want to know how many characters
>were actually read before that happened.  This can be done easily in assembly
>language -- it is precisely what CIO will do -- but I wonder if there is a way
>to do it in ACTION, other than doing a CIO call in a "code block" or
>subroutine call.

The following routine is a real kluge, but it does what you want.  I don't
think that this a dumb question.  xio was obviously intended to copy the 
BASIC command of the same name.  This is quite unfortunate,  since the 
result is to give the programmer access to only a part of the cio facility.
It would have made much more sense to give the programmer full access to the
cio functions.  (As I am sure you've figured out, it is quite easy to write a 
procedure which does this.  The record facility comes in handy in setting 
up the cio block.)  I wasn't at all sure that this would work until I tried it.

proc get_bytes(byte channel,
               byte length,
               byte array buffer)
buffer(0) = length
xio(channel,0,7,0,0,buffer)
return

xio takes the length byte from the string and stores it in the byte count/
buffer length location in the cio block.  In the above, the buffer 
must be a array of size length + 1, and length must be < 256.  This is
because Action! is expecting an ordinary Action! string.  I don't think it is
possible to make this work with longer buffers.  If you set the buffer length
entry in the cio block, xio will reset it with a high byte of 0.  Also, I think
that the only way to find out how many characters were actually read is to read
the buffer length/byte count field directly from the cio block after the call
to xio.  Still, this might be useful if you know that the size of the file is a
multiple of some number.  Otherwise, it's probably worthwhile to do it from 
scratch, calling cio.  I hope that this is helpful.

Fred Sullivan
Dept. Math. Sci.
SUNY @ Binghamton
sullivan @ suny-bing.csnet

I used to have a Televideo 950 on my desk.  I almost think that I'd rather
look at the Omniview character set.  Anyway, the extra space on my desk is
well worth 4 by 8 characters.  (Even if braces are a little funny.)  

Append your favorite disclaimer here!