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

Subject: Re: [stella] BRK instruction: Request for clarification!
From: "Eckhard Stolberg" <Eckhard_Stolberg@xxxxxx>
Date: Tue, 26 Jul 2005 09:55:29 -0400
>> 1) When a BRK instruction is executed, is the existing
>> status register altered?
> Yes: the B flag is set.

Actually the B flag should always be set, except when a hardware
interrupt occurs. I think in this case a BRK instruction will
be executed but with the B flag cleared during execution so
that it gets pushed to the stack in this state.

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.

The BRK instruction sets the I flag after pushing the status byte
to the stack though, as you mentioned below.

>> 2) Where and how should the BRK flag be cleared? Or is this
>> done automatically?
> In your interrupt handler. As you said, you have to clear it by masking
> the bit manually.

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.

>> 3) What happens to the IRQ flag during execution of the BRK?
>> is it ever changed? (It should normally be inactive when a
>> BRK occurs, but since it is ignored by BRK it could be in
>> any state.)
> According to the Stella code above (and according to "cpu.asm" in the
> z26 source), the I flag gets set *after* the PC and status are pushed,
> so an RTI restores its original state. I didn't know/remember that until
> I looked at the code just now (it's been a long time since I used a 6502
> system that actually has interrupts: on the 2600, I just SEI at startup
> and ignore the I flag thereafter).
> I doubt both Stella and z26 are wrong though, not when they're doing
> exactly the same thing.

This behaviour is described in many 6502 manuals, including the
tutorial on that you pointed to. So I suppose both
emulators are handling it correctly. ;-)

Ciao, Eckhard Stolberg

Archives (includes files) at
Unsub & more at

Current Thread