[comp.sys.atari.8bit] Bit wise operations.

hutch@pluto.sybase.com (Reginald Hutcherson) (04/06/91)

	Folks,

	Anyone know how to preform bit wise operations on the Atari.
	I have an Atari 800xl, and have developed a simple player
	missle graphics game. The problem is that I have two players
	that fire missles, but when I move the missles up/down in
	memory I zap one of the players missle bit map because they
	share memory bytes. What I would like to do is mask out the
	bits that apply to a specific player. Also, all this is being
	done in basic, any ideas? Another question, in Atari basic
	how are HEX numbers represented?

	Thanks in advance.

-- hutch

Tom_Klok@mindlink.UUCP (Tom Klok) (04/07/91)

> hutch@pluto.sybase.com writes:
>         Anyone know how to preform bit wise operations on the Atari.
>         I have an Atari 800xl, and have developed a simple player
>         missle graphics game. The problem is that I have two players
>         that fire missles, but when I move the missles up/down in
>         memory I zap one of the players missle bit map because they
>         share memory bytes. What I would like to do is mask out the
>         bits that apply to a specific player. Also, all this is being
>         done in basic, any ideas?

Well, first off, cartridge BASIC is poorly suited for writing PM graphics and
games.  The lack of bitwise operations, no interrupt handling, no fast memory
moves, slowness in general... it all conspires to make it just about
impossible.  You should take a look at alternative languages.  If not straight
assembly, perhaps mixing assembly routines with your BASIC.  OSS's BASIC A+,
BASIC XE or Turbo BASIC all have some support for this sort of thing.  Action!
would be even better.

But if you're a masochist, bitwise operations can be simulated.  The following
code chunk isn't optimum, being off the top of my head... but it should give
you the general idea.

Consider a missile stripe starting at the addr MISS, containing all four
missiles.  The addr MISS+Y contains the data for that Y pos.

7 6 5 4 3 2 1 0
 m3  m2  m1  m0

To convert from byte to missile data bit pairs, try this:

BYTE = PEEK(MISS+Y)
M3 = INT(BYTE / 64)
BYTE = BYTE - M3 * 64
M2 = INT(BYTE / 16)
BYTE = BYTE - M2 * 16
M1 = INT(BYTE / 4)
M0 = BYTE - M1 * 4

To put the pairs back together:

BYTE = M0 + 4*M1 + 16*M2 + 64*M3
POKE MISS+Y, BYTE

> Another question, in Atari basic how are HEX numbers represented?


Decimal is all you get.  Actually, cartridge basic knows nothing but floating
point, but you can ignore that.  If you want to work with HEX, you'll have to
supply your own conversions.  Hex numbers can be kept around in strings, but
it's easier to let the computer use what it's happy with and save the HEX for
input/output with the human.

Hex conversions are much like the missile example above.  Here's a bit of code
I use a lot, again from memory (so it might need some debugging :)

DIM H$(16):H$="0123456789ABCDEF"
HEX = your number to display
GOSUB hex_print

hex_print:
K=4096
FOR Q=0 TO 3
    H = INT(HEX/K)
    HEX = HEX - H * K
    K = K / 16
    ? H$(H+1,H+1);
NEXT Q
RETURN

To print 2-digit values (bytes) instead of 4 digits (words), change the loop to
2 iterations and K = 16.

>         Thanks in advance.
> 
> -- hutch


Tom
a344@mindlink.UUCP      "What, me hurry?" - Alfred E. Von Neumann

Ordania-DM@cup.portal.com (Charles K Hughes) (04/07/91)

Hutch writes:
>
>	Folks,
>
>	Anyone know how to preform bit wise operations on the Atari.
>	I have an Atari 800xl, and have developed a simple player
>	missle graphics game. The problem is that I have two players
>	that fire missles, but when I move the missles up/down in
>	memory I zap one of the players missle bit map because they
>	share memory bytes. What I would like to do is mask out the
>	bits that apply to a specific player. Also, all this is being
>	done in basic, any ideas? Another question, in Atari basic
>	how are HEX numbers represented?

  Hex numbers do not exist in standard Atari BASIC.
  To do bit manipulations you'll need to either do them in machine language,
or split each byte into its bits in Basic.

>
>	Thanks in advance.
>
>-- hutch

Charles_K_Hughes@cup.portal.com