Re: [stella] Newbie: Efficiency in Code, Joystick Routine asExample

Subject: Re: [stella] Newbie: Efficiency in Code, Joystick Routine asExample
From: Bill Heineman <burger@xxxxxxxxxxxxxxxxx>
Date: Sun, 14 Jul 2002 15:43:30 -0700
on 7/14/02 3:36 PM, Andrew Davie at adavie@xxxxxxxxxxx wrote:

>> Not necessary, everything looks fine! :-)
> The statement that "has to compare a whole byte for each possibility, while
> the second routine compares 1 bit. That's 8 times more efficient (I think).
> "  is in error.  Comparing a byte against comparing a bit is not 8 times
> less efficient.  In fact, it really depends how you do things, and what you
> want to do.  Sometimes comparing a bit is less efficient.  Depends which
> bit, and if you can modify A, for example.  Or if the byte is in memory or a
> register.
> For example, if I wanted to check to see if bit 4 was set in A, without
> destroying A...... how do I do that?
> I can't... directly.  There's no BIT #  instruction.  So I have to save the
> value somewhere, bit it, and restore it
> sta temp        ; save A
> lda #16        ; the bit we want to check
> bit temp        ; check the bit
> lda temp        ; restore

To test is very simple

Var16 .Byte 16 ;Single byte in ROM, a 16 is here

 LDA value      ;Get value, optional since it may already be loaded in A
 BIT Var16      ;AND with #16, store result of AND in the zero flag
 BNE BitIsSet   ;BNE if true, BEQ if AND is false



Archives (includes files) at
Unsub & more at

Current Thread