Re: [stella] Help Interpreting Code

Subject: Re: [stella] Help Interpreting Code
From: Jeff Johnston <jeffryj@xxxxxxxxxxxxx>
Date: Sat, 13 Jul 2002 19:45:59 -0700 (MST)

On Sat, 13 Jul 2002, Roagie wrote:
> I tell ya, this newbie FAQ is gonna be good! :)
> If anyone else can think of some common 6502/general assembly/TIA/etc
> "gotchas" that newbies always seem to be asking about, please send them my
> way so I may include them in the FAQ.

One thing that screwed me up for a long time is the unusual handling of
the carry flag in the 6502 (all this applies for the 6507) too, of

The Carry flag of the 6502 is backwards after subtractions.  A carry
occurs when you subtract a small number from a large number, or add two
numbers that go over 255 (an overflow happens too, but that's different).
Anyways, after a subtraction, if you want to find out if there was a
carry, test for the OPPOSITE of what you thought should happen.  For

LDA #7
SEC	; another annoyance of the 6502, SEC to subtract, CLC to add
SBC #5

Okay, so the answer is obviously going to be 2 in A, but the carry flag
will be SET, not clear, even though it's a positive answer in our
subtraction.  Also, because when you are doing a compare it's really a
subtraction behind the scenes, your carry flag results will be backwards
just like subtract's are.  Example:

LDA strange
CMP #5
BCC weird

So, if "strange" is 4 you'd have, say 4-5=-1.. which you'd think makes a
carry because the subtraction goes "negative" to 255.. and to test for it
you'd think you would think of BCS.  But, since the carry results for
subtractions are backwards in 6502 land, BCC is the one you'd need to jump
if "strange" is less than 5.  If you wanted to test for greater than or
equal to 5, you'd use BCS.  So, to get to the point for the above example,
for values less than 5 the above code jumps to "weird" otherwise it
returns from the subroutine.

Hope this helps.  Please correct me if it is inaccurate.


> Here's another quick question while I'm at it. Is there an adavantage to
> using hex, for example, when defining player graphics? It seems to be much
> easier to use the binary notation. i.e. $20 = %00100000
> You can design your sprite right in the code in this manner! There has to be
> a downside, what is it?
> Thanks all!
> ----------------------------------------------------------------------------------------------
> Archives (includes files) at
> Unsub & more at

Archives (includes files) at
Unsub & more at

Current Thread