enum

CPU::Flags

Inherits Enum < Comparable < Value < Object

The flags of the cpu

Constants

Negative = 0

The Sign Flag

Sign Flag serves TWO purposes

  1. 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.
  2. As a result store for a CPU#bit instruction: The CPU#bit instruction reads the contents of the specified memory address and copies bit-7 of that value to the Sign Flag
Overflow = 1

The Overflow Flag

P.V serves TWO purposes

  1. To signify an oVerflow (a sign change) during a mathmatical operation. Caused by an CPU#adc or CPU#sbc instruction: If an CPU#adc or CPU#sbc instruction 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.
  2. As a result store for a CPU#bit instruction: The CPU#bit instruction reads the contents of the specified memory address and copies bit-6 of that value to P.V
Break = 2

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#brk instruction is only ONE byte long... This means that if you simply issue an CPU#rti, The byte immediately following the CPU#brk instruction will be ignored. I have read reasons as to WHY this is the case, but frankly they all stink! ...Just deal with it!
DecimalMode = 3

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.

InterruptDisable = 4

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.

Zero = 5

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

Carry = 6

The Carry Flag

P.C can be considered to be the 9th bit of an arithmetic operation.

Instance methods

break?

Returns true if this enum value equals Break

carry?

Returns true if this enum value equals Carry

decimal_mode?

Returns true if this enum value equals DecimalMode

interrupt_disable?

Returns true if this enum value equals InterruptDisable

negative?

Returns true if this enum value equals Negative

overflow?

Returns true if this enum value equals Overflow

zero?

Returns true if this enum value equals Zero