Date : Fri, 23 Jul 2010 07:55:16 +0100
From : mfirth@... (Michael Firth)
Subject: Spitting expletives
On 23/07/2010 05:40, Rick Murray wrote:
> On 22/07/2010 18:54, Tom Walker wrote:
>
>> Carry can be worked out as p.c=(a>=temp),
> How does this work? A borrow occurs (carry clear) if the temp workspace
> value is less than Acc?
> Surely it is if the calculated value is less than zero? Or am I missing
> something?
>
As the SBC operation is effectively A = A - operand, a borrow occurs if
the operand is larger than A.
As C comparisons give a '1' for true and a '0' for false, the code Tom
sent will set C to 1 (borrow doesn't occur) if A is larger than or
equal to the operand, which is the same as "not(operand>A)", which is
the logic that's needed.
>> Did notice you haven't attacked the BCD version, presumably that's
> > for sanity reasons.
>
> Yes... and also because AFAIK the FileStore firmware does not make use
> of BCD, so there didn't seem to be much point including it.
>
>
>> B is always set, except when pushed to the stack on an interrupt.
> Mmmm... I don't think my code does that entirely correctly then.
>
>
> --8<--------
> The B flag
> ----------
> No actual "B" flag exists inside the 6502's processor status register.
> The B flag only exists in the status flag byte pushed to the stack.
> Naturally, when the flags are restored (via PLP or RTI), the B bit is
> discarded.
>
> Depending on the means, the B status flag will be pushed to the stack as
> either 0 or 1.
>
> software instructions BRK& PHP will push the B flag as being 1.
> hardware interrupts IRQ& NMI will push the B flag as being 0.
> --8<--------
>
> BRK sets B, PHP sets B (it does now). IRQ/NMI do not set B, and when the
> status is popped off the stack, B is hardwired to false.
>
I'm not an expert on the B flag, by any means, but this is surely wrong.
If the B flag was always false when popped off the stack, how would you
(simply) be able to tell whether the value that had been pushed to the
stack by the IRQ, BRK or PHP had B set to true or false?
Or is the theory that you pull the value into A and then do a CMP to
find out whether the B position would have been set? That would seem
rather messy to me though - to restore the flags, and check B you
effectively have to do PLA : PHA : PLP : CMP #x, which seems a lot of
instructions.
I'm guessing the idea of the B flag is that when you do a PLP, you can
tell by testing B whether the status flags were pushed by an IRQ/NMI (B
clear), or by software means (B set).
It also seems from the other descriptions that I've seen that B is
effectively an "active low" signal to indicate an IRQ/NMI has happened,
which potentially makes "true" and "false" slightly confusing terms to
use for it.
> The snippet above is from:
>
> http://nesdev.parodius.com/the%20%27B%27%20flag%20&%20BRK%20instruction.txt
>
>
> B is ALWAYS set? I know PHP sets it, so:
> PHP
> PLA
> will see the B flag set... but what about in normal code execution?
> Surely it is considered 'unset' except when flags are pushed to the
> stack in which case it is set except for an actual IRQ?
>
>
> Best wishes,
>
> Rick.
>
Regards
Michael