Date : Sat, 01 Mar 2008 16:36:51 +0000
From : jgh@... (Jonathan Graham Harston)
Subject: BBC FPGA and B flags
Mark McDougall wrote:
> According to the MAME documentation, the (NMOS) 6502 *always* has the B flag
> set in the P register. According to the code itself, it is set on reset, and
> *never* set to 0 there-after. As is commonly accepted, in response to an
> IRQ/NMI, the processor pushes P onto the stack with the B flag set to zero -
> P.B is otherwise unaffected. Likewise in the MAME 6502 core, PLP and RTI
> instructions both (also) set P.B. FWIW BRK pushes P with B flag set.
An implementation where:
RESET sets 'B' (actually, irrelavant)
IRQ/NMI clears 'B' before pushing P
BRK sets 'B' before pushing P, then sets 'I'
should work satisfactorily. To follow the hardware correctly, the
implementation should do:
BRK sets 'B' before pushing P, and then clears 'B' and sets 'I'.
No other instruction or action should modify the 'B' flag,
though as long as the three above actions do as above, it will
(should?) not matter that P is implemented as a full 8-bit value.
Having an 8-bit P register has the useful side effect that an
program can tell if it's running on hardware or an emulator with:
LDA #0:PHA:PLP:PHP:PLA:AND #16:BEQ emulator:BNE hardware
In an implementation that doesn't have IRQ/NMI implmented, a
useful modification is to make PLP always set the 'B' bit.
--
J.G.Harston - jgh@... - mdfs.net/User/JGH
A Review of Sheffield City Council's Members' Allowances Scheme
See http://mdfs.net/payreform