summaryrefslogtreecommitdiff
path: root/addressing.h
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-03-23 16:43:07 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-03-23 16:43:07 +1100
commitdae1ec0de59f31b533c225a74019ac77a59c92a1 (patch)
treec331c6620373678ad8fc3452d2d44b1c1a21c05a /addressing.h
first commit I think
Diffstat (limited to 'addressing.h')
-rw-r--r--addressing.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/addressing.h b/addressing.h
new file mode 100644
index 0000000..ccde083
--- /dev/null
+++ b/addressing.h
@@ -0,0 +1,51 @@
+#define FALSE 0
+#define TRUE 1
+
+enum Addressing {
+ eImmediate,
+ eAbsolute,
+ eZeroPage,
+ eImplied,
+ eIndirectAbsolute,
+ eAbsoluteIndexedX,
+ eAbsoluteIndexedY,
+ eZeroPageIndexedX,
+ eZeroPageIndexedY,
+ eIndexedIndirect,
+ eIndirectIndexed,
+ eRelative,
+ eAccumulator
+};
+
+typedef int Addressing;
+
+ /*
+ * Any addressing method which is single line commented out without definition
+ * implies that handling should be hard-coded in the switch case of the
+ * instruction from which it came.
+ */
+
+
+int fAddressing(Addressing addr, short x) {
+ switch(addr){
+ case eImmediate: return x;
+ case eAccumulator: return acc;
+
+ case eAbsolute: return Memory[x];
+ case eAbsoluteIndexedX: return Memory[(x + X)];
+ case eAbsoluteIndexedY: return Memory[(x + Y)];
+
+ case eZeroPage: return Memory[(x & 0x00FF)];
+ case eZeroPageIndexedX: return Memory[((x = X) & 0x00FF)];
+ case eZeroPageIndexedY: return Memory[((x = Y) & 0x00FF)];
+
+ case eIndexedIndirect: return Memory[((x + X) << 8) + ((x + X) + 1)];
+ case eIndirectIndexed: return ((Memory[x] + Memory[(x+1 << 8)]) + Y);
+
+ //case eImplied: No reference
+ //case eIndirectAbsolute: Only used in the JMP instruction
+ //case eRelative: Only used in branch instructions
+ }
+
+}
+