aboutsummaryrefslogtreecommitdiff
path: root/cpu/flags.go
diff options
context:
space:
mode:
Diffstat (limited to 'cpu/flags.go')
-rw-r--r--cpu/flags.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/cpu/flags.go b/cpu/flags.go
new file mode 100644
index 0000000..b6ede68
--- /dev/null
+++ b/cpu/flags.go
@@ -0,0 +1,29 @@
+package cpu
+
+const (
+ FlagC uint8 = 1 << 0
+ FlagZ uint8 = 1 << 1
+ FlagI uint8 = 1 << 2
+ FlagD uint8 = 1 << 3 // no-op on the NES's 2A03
+ FlagB uint8 = 1 << 4 // only meaningful in the byte pushed by brk/irq
+ FlagU uint8 = 1 << 5
+ FlagV uint8 = 1 << 6
+ FlagN uint8 = 1 << 7
+)
+
+func (c *CPU) setFlag(flag uint8, set bool) {
+ if set {
+ c.Status |= flag
+ } else {
+ c.Status &^= flag
+ }
+}
+
+func (c *CPU) flag(flag uint8) bool {
+ return c.Status&flag != 0
+}
+
+func (c *CPU) setZN(v uint8) {
+ c.setFlag(FlagZ, v == 0)
+ c.setFlag(FlagN, v&0x80 != 0)
+}