Re: [stella] BRK instruction: Request for clarification!

Subject: Re: [stella] BRK instruction: Request for clarification!
From: "C. Bond" <cbond@xxxxxxxxxxxxx>
Date: Tue, 26 Jul 2005 22:58:31 -0400
-----Original Message-----
From: Eckhard Stolberg <Eckhard_Stolberg@xxxxxx>
Sent: Jul 26, 2005 1:53 PM
To: stella@xxxxxxxxxxxxxxxxxx
Subject: Re: [stella] BRK instruction: Request for clarification!

>> The B flag is wired directly to the interrupt input pin on the
>> 6502. In the 6507 this pin is internally set high, so on the VCS
>> the B flag should always be set.
> ...
>> None of the instructions in the 6502 affects the B flag.
>> It's hardwired to the interrupt input pin, so you can't change
>> the bit yourself.
> You sure about that?
> If you're right, someone needs to fix this tutorial:
> It claims that:
>    The B (Break) flag, bit 4 of the P (Processor status) register, is a
>    frequent source of confusion on the 6502. The sole purpose of this flag
>    is to distinguish a BRK from a IRQ.
> ...which is what I always thought it was for, too... but I'm none too
> confident that I know what I'm talking about, since I haven't actually
> used any of this interrupt-related stuff in 15+ years.

It is used to distinguish a BRK from an IRQ. But as the
tutorial says, the only way to find out what caused the
interrupt to happen is by testing bit 4 of the status
byte that was pushed to the stack by the BRK/IRQ. Pushing
the status byte to the stack yourself won't work reliably.

The reason for that is the fact that the only time the
B bit is low in the status register is while the IRQ line
on the 6502 is pulled low to trigger an external interrupt.
Since the B flag is connected directly to the IRQ pin on the
6502, it will be low in the status value that the IRQ pushes to
the stack.

At least that's the theory I think is most plausible. I guess
it would be possible that the tutorial is correct and the
BRK/IRQ mask out the B flag before pushing it to the stack.
But to me it seems easier to just connect it directly to the
IRQ pin on the 6502.

I guess to find out for sure someone would need to connect
the IRQ line on a 6502 to ground and check what value a PHP
would push to the stack.

Ciao, Eckhard Stolberg



If your analysis is correct, what is the point of setting the 'B' flag *before* pushing the
status register on the stack in an emulator? On a VCS system, it probably should be set
high during power up and just left there... No?



Archives (includes files) at
Unsub & more at

Archives (includes files) at
Unsub & more at

Current Thread