CPU::Flags
Inherits Enum < Comparable < Value < Object
The flags of the cpu
Constants
The Sign Flag
Sign Flag serves TWO purposes
- To signify the sigN of the last mathematical or bitwise operation. The sign is the bit-7 of the result value. If the last operation was not a signed operation, P.N will still reflect bit-7 of the result, but will NOT be considered as a sign.
- As a result store for a
CPU#bitinstruction: TheCPU#bitinstruction reads the contents of the specified memory address and copies bit-7 of that value to the Sign Flag
The Overflow Flag
P.V serves TWO purposes
- To signify an oVerflow (a sign change) during a mathmatical operation. Caused by an
CPU#adcorCPU#sbcinstruction: If anCPU#adcorCPU#sbcinstruction generates a result that would require more than 8 bits to hold (that is, any number outside the range -128 to 127) then Overflow is SET; else Overflow is CLEARed. This flag may be ignored if the programmer is NOT using signed arithmetic. - As a result store for a
CPU#bitinstruction: TheCPU#bitinstruction reads the contents of the specified memory address and copies bit-6 of that value to P.V
The Break Flag
The Break Flag and the CPU#brk instruction seem to me to be one very badly thought out bodge.
If you do not plan to use the CPU#brk instruction I would just ignore it!
P.B is never actually set in the Flags register!
When a CPU#brk instruction occurs the Flags are PUSHed onto the Stack along with a return address*
It is only this copy of the Flags (the one on the Stack) that has P.B set!
- This return address is actually "Address_of_BRK_instruction+2".
Bearing in mind that the
CPU#brkinstruction is only ONE byte long... This means that if you simply issue anCPU#rti, The byte immediately following theCPU#brkinstruction will be ignored. I have read reasons as to WHY this is the case, but frankly they all stink! ...Just deal with it!
The Decimal Flag
P.D dictates whether Addition (CPU#adc) and Subtraction (CPU#sbc) operate in the classic Binary or the more obscure Binary Coded Decimal (BCD) mode.
The Interrupt (disable) Flag
When P.I is SET, Interrupt ReQuest signals (IRQs) to the IRQ pin (classically pin-4) are IGNORED When P.I is CLEAR, signals to the IRQ pin are acknowledged.
The Zero Flag
P.Z is SET when a zero value is placed in a register P.Z is CLEARed when a non-zero value is placed in a register
The Carry Flag
P.C can be considered to be the 9th bit of an arithmetic operation.
Instance methods
Returns true if this enum value equals Break
Returns true if this enum value equals Carry
Returns true if this enum value equals DecimalMode
Returns true if this enum value equals InterruptDisable
Returns true if this enum value equals Negative
Returns true if this enum value equals Overflow
Returns true if this enum value equals Zero