summaryrefslogtreecommitdiff
path: root/instruction.h
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-03-27 17:19:36 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-03-27 17:19:36 +1100
commitcd50e11648971a3fbdc3936839f4a5401e3a9d29 (patch)
tree4bec70a901d854932bd61af79a2d5eea58f56f2a /instruction.h
parent38c238150e9707fed0b9e8602e24bf91a7ffe4e3 (diff)
More instructions, misc system details
Diffstat (limited to 'instruction.h')
-rw-r--r--instruction.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/instruction.h b/instruction.h
index 054e629..a5cc2b9 100644
--- a/instruction.h
+++ b/instruction.h
@@ -60,8 +60,41 @@ void fSBC(Addressing addr, int val){
//Increment and Decrement Instructions
+void fINC(Addressing addr, int val){
+ Memory[x]++;
+ setFlagD(Memory[x]);
+ setFlagZ(Memory[x]);
+}
+
+void fINX(){
+ X++;
+ setFlagD(X);
+ setFlagZ(X);
+}
+
+void fINY(){
+ Y++;
+ setFlagD(Y);
+ setFlagZ(Y);
+}
+
+void fDEC(Addressing addr, int val){
+ Memory[x]--;
+ setFlagD(Memory[x]);
+ setFlagZ(Memory[x]);
+}
+void fDEX(){
+ X--;
+ setFlagD(X);
+ setFlagZ(X);
+}
+void fDEY(){
+ Y--;
+ setFlagD(Y);
+ setFlagZ(Y);
+}
// Logical Instructions
@@ -85,12 +118,94 @@ void fEOR(Addressing addr, int val){
// Jump, Branch, Compare, and Test Bits
+void fJMP(int val){
+ S = val;
+}
+
+void fBCC(signed char val){
+ if (getFlag(flag_C) == 0) S += val;
+}
+
+void fBCS(signed char val){
+ if (getFlag(flag_C) == 1) S += val;
+}
+
+void fBEQ(signed char val){
+ if (getFlag(flag_Z) == 1) S += val;
+}
+
+void fBNE(signed char val){
+ if (getFlag(flag_Z) == 0) S += val;
+}
+
+void fBMI(signed char val){
+ if (getFlag(flag_N) == 1) S += val;
+}
+
+void fBPL(signed char val){
+ if (getFlag(flag_N) == 0) S += val;
+}
+
+void fBVS(signed char val){
+ if (getFlag(flag_V) == 1) S += val;
+}
+
+void fBVC(signed char val){
+ if (getFlag(flag_V) == 0) S += val;
+}
+
+void fCMP(address val){
+ if (acc < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (acc == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (acc > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fCPX(address val){
+ if (X < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (X == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (X > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fCPY(address val){
+ if (Y < Memory[val]){
+ setFlag(flag_N, 1); setFlag(flag_Z, 0); setFlag(flag_C, 0);
+ }if (Y == Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 1); setFlag(flag_C, 0);
+ }if (Y > Memory[val]){
+ setFlag(flag_N, 0); setFlag(flag_Z, 0); setFlag(flag_C, 1);
+ }
+}
+void fBIT(address val){
+ setFlag(flag_N, (Memory[val] & flag_N));
+ setFlag(flag_V, (Memory[val] & flag_V));
+ if (((Memory[val] & flag_N) & (Memory[val] & flag_V)) == 0) {
+ setFlag(flag_Z, 1);
+ } else {
+ setFlag(flag_Z, 0);
+ }
+}
// Shift and Rotate Instructions
+/* ASL - Accumulator Shift Left
+ LSR - Logical Shift Right
+ ROL - ROtate Left
+ ROR - ROtate Right
+
+ Z is set if the result it zero. N is set if bit 7 is 1. It is
+ always reset on LSR. Remember that ASL A is equal to multiplying by
+ two and that LSR is equal to dividing by two.*/
+
+
void fASL(Addressing addr, int val){
setFlag(flag_C, (val & 0x80));
acc = (val << 1);
@@ -98,9 +213,55 @@ void fASL(Addressing addr, int val){
setFlagZ(acc);
}
+/* Use these instructions to move things around in the accumulator or
+ memory. The net effects are (where C is the carry flag):
+
+
+ +-+-+-+-+-+-+-+-+
+ C <- |7|6|5|4|3|2|1|0| <- 0 ASL
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ 0 -> |7|6|5|4|3|2|1|0| -> C LSR
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ C <- |7|6|5|4|3|2|1|0| <- C ROL
+ +-+-+-+-+-+-+-+-+
+
+ +-+-+-+-+-+-+-+-+
+ C -> |7|6|5|4|3|2|1|0| -> C ROR
+ +-+-+-+-+-+-+-+-+
+*/
+
// Transfer Instructions
+void fTAX(){
+ X = acc;
+ setFlagN(X);
+ setFlagZ(X);
+}
+
+void fTAY(){
+ Y = acc;
+ setFlagN(Y);
+ setFlagZ(Y);
+}
+
+void fTXA(){
+ acc = X;
+ setFlagN(acc);
+ setFlagZ(acc);
+}
+
+void fTYA(){
+ acc = Y;
+ setFlagN(acc);
+ setFlagZ(acc);
+}
+
+
// Stack Instructions
// Subroutine Instructions