Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!lsuc!jimomura From: jimomura@lsuc.UUCP Newsgroups: comp.sys.m6809 Subject: gs_rdy.c Message-ID: <2110@lsuc.UUCP> Date: Tue, 27-Oct-87 23:25:29 EST Article-I.D.: lsuc.2110 Posted: Tue Oct 27 23:25:29 1987 Date-Received: Thu, 29-Oct-87 06:13:17 EST Reply-To: jimomura@lsuc.UUCP (Jim Omura) Distribution: na Organization: Law Society of Upper Canada, Toronto Lines: 70 Summary: replacement for getstat(1,path) If you've been working with the Color Computer version of Microware C and have tried to write a program reading irregular amounts of data through an SCF device, you've probably run into this problem. The original compiler spec in the manuals says that getstat(1,path) returns -1 for no data and 0 for data waiting. This is true. However, it also says that read(path,buffer,nnn) will return the number of bytes actually read -- which seems to imply that it will return having read fewer bytes than those specified by nnn. This doesn't work. It'll sit there waiting for all the bytes to arrive. Now, the assembly language I$GetStt call returns the actual numbers waiting to be read, which if you use it, means you can specify what you need to receive from read(), but no way is provided in the standard libraries. So, I've written a short program which can be used in place of getstat(1,path). It's patterned after _gs_rdy() which comes in the 68K Microware compiler, so using it should also enhance portability. Having read all this preamble, you'll be disappointed when you see how short the program is, but, that's life. ;-) /* gs_rdy.c * 1987/10/26 * Public Domain */ /* By Jim Omura, Byte Information Exchange 'jimomura' * 2A King George's Drive * Toronto, Ontario * M6M 2G9 */ /* _gs_rdy() * * Usage: * * int _gs_rdy(path) * * int path; * * Returns the number of bytes waiting to be read. * * To be used in place of "getstat(1,path)" in order * to work with read(). */ int _gs_rdy(path) int path; { int waiting; #asm leas -2,s stack points at "waiting" lda 7,s load "path" -- actually ldd 6 and shift left 8. ldb #1 os9 $8d I$GetStt bcs errhand lda #0 clear upper byte to make sense. std 0,s bra cleanexit errhand ldd #-1 std 0,s cleanexit leas 2,s Restore stack pointer. #endasm return(waiting); } -- Jim Omura, 2A King George's Drive, Toronto, (416) 652-3880 ihnp4!utzoo!lsuc!jimomura Byte Information eXchange: jimomura