[comp.sys.apple2] Bitwise operaters in Applesoft

bchurch@oucsace.cs.OHIOU.EDU (Bob Church) (08/20/90)

All of this talk about using the serial port from Applesoft got
me curious (again). I've never had any luck with PR#2 or IN#2 from
within an Applesoft program so I decided to try using peeks and pokes
to go about it in a more direct way. The snag is in reading the status
register. I have to check the status of bits 3 and 4 regularly and cannot
figure out a way to do in in Applesoft. Any hints or clues? I normally
use Assembler, ML or C but decided to try it for old times sake.


********************************************************************
*                                                                  *
*   bob church  bchurch@oucsace.cs.ohiou.edu                       *
*                                                                  *
*  If economics isn't an "exact" science why do computers crash    *
*  so much more often than the stock market?                       *
*                                          bc                      *
********************************************************************

toddpw@tybalt.caltech.edu (Todd P. Whitesel) (08/22/90)

bchurch@oucsace.cs.OHIOU.EDU (Bob Church) writes:

>All of this talk about using the serial port from Applesoft got
>me curious (again). I've never had any luck with PR#2 or IN#2 from
>within an Applesoft program so I decided to try using peeks and pokes
>to go about it in a more direct way. The snag is in reading the status
>register. I have to check the status of bits 3 and 4 regularly and cannot
>figure out a way to do in in Applesoft. Any hints or clues? I normally
>use Assembler, ML or C but decided to try it for old times sake.

Bit-flicking in Applesloth is not something you want to do realtime (S L O W)
but you can get the value of bit n (0..7) in the variable byte from:

 ( INT(byte/2^n)/2 = INT(INT(byte/2^n)/2) )

what this does is int divide out the bits below the one you want, and then
test to see if the result is even or odd (which depends on the bit you want).

note that you can improve on this generic routine quite a bit.

A far better method would be to poke a tiny machine language subroutine that
tests the bits you want or splits them up into seperate bytes so you can use

CALL serial_status : IF PEEK(rx_full) THEN character received

but I still feel that Apple sloth is too slow for the actual character routines
-- far better to use ML to provide an interrupt driven, buffered interface that
uses either ampersand routines or I/O hooks.

Todd Whitesel
toddpw @ tybalt.caltech.edu