summaryrefslogtreecommitdiff
path: root/instruction.h
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-04-05 22:23:17 +1000
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-04-05 22:23:17 +1000
commit98c242def30ae70f327323d65485b41bdbd151b4 (patch)
tree4128d42992b197b99d48f471b8bf6d55bc1a7593 /instruction.h
parent92e5aaf275785bfb6e7ec3d98df910af9bf9b65f (diff)
reworking instructions, added assembler.c
Diffstat (limited to 'instruction.h')
-rw-r--r--instruction.h85
1 files changed, 34 insertions, 51 deletions
diff --git a/instruction.h b/instruction.h
index b296e0c..2c4c3a2 100644
--- a/instruction.h
+++ b/instruction.h
@@ -1,68 +1,44 @@
-//void fXXX(ADDRESSING addr, int val)
-
-// Considering making instruction functions return an int of
-// how many cycles passed
-
-struct instruction_data {
- int length = 0;
- int cycles = 0;
-};
-
-int getLength(Addressing addr){
- switch(addr){
- case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
- return 3;
- case eAccumulator:
- return 1;
- default:
- return 2;
- }
-}
+
+// array/map of pointers which all point
+// to the functions which the index corresponds to.
+// use that like a sort of map
+AddData idata; //Instruction Data
+
// Load and Store Instructions
+// the load and store instructions are currently
+// used to express how data structures will work eventually.
-instruction_data fLDA(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- acc = fAddressing(addr, val);
- return d;
+void fLDA(Addressing addr, address val){ idata = fAddress(addr, val);
+ acc = idata.val;
}
-instruction_data fLDX(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- X = fAddressing(addr, val);
- return d;
+void fLDX(Addressing addr, address val){ idata = fAddress(addr, val);
+ X = idata.value;
}
-instruction_data fLDY(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- Y = fAddressing(addr, val);
- return d;
+void fLDY(Addressing addr, address val){ idata = fAddress(addr, val);
+ Y = idata.value;
}
-instruction_data fSTA(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- Memory[(fAddressing(addr, val))] = acc;
- return d;
+void fSTA(Addressing addr, address val){ idata = fAddress(addr, val);
+ Memory[idata.value] = acc;
}
-instruction_data fSTX(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- Memory[(fAddressing(addr, val))] = X;
- return d;
+void fSTX(Addressing addr, address val){ idata = fAddress(addr, val);
+ Memory[idata.value] = X;
}
-instruction_data fSTY(Addressing addr, address val){
- instruction_data d; d.length = getLength(addr);
- Memory[(fAddressing(addr, val))] = Y;
- return d;
+void fSTY(Addressing addr, address val){ idata = fAddress(addr, val);
+ Memory[idata.value] = Y;
}
// Arithmetic Instructions
instruction_data fADC(Addressing addr, address val){
instruction_data d; d.length = getLength(addr);
- int buffer = acc + fAddressing(addr, val);
+ int buffer = acc + fAddress(addr, val);
setFlagV(buffer, acc);
if (buffer > 255){
@@ -71,13 +47,13 @@ instruction_data fADC(Addressing addr, address val){
flagClear(flag_C);
}
- acc += fAddressing(addr, val);
+ acc += fAddress(addr, val);
setFlagN(acc);
setFlagZ(acc);
}
instruction_data fSBC(Addressing addr, address val){
- int buffer = acc - fAddressing(addr, val);
+ int buffer = acc - fAddress(addr, val);
setFlagV(buffer, acc);
if (buffer < 0){
@@ -85,7 +61,7 @@ instruction_data fSBC(Addressing addr, address val){
}else{
flagClear(flag_C);
}
- acc -= fAddressing(addr, val);
+ acc -= fAddress(addr, val);
setFlagN(acc);
setFlagZ(acc);
}
@@ -131,19 +107,19 @@ instruction_data fDEY(){
// Logical Instructions
instruction_data fAND(Addressing addr, address val){
- acc = acc & fAddressing(addr, val);
+ acc = acc & fAddress(addr, val);
setFlagN();
setFlagZ(acc);
}
instruction_data fORA(Addressing addr, address val){
- acc = acc | fAddressing(addr, val);
+ acc = acc | fAddress(addr, val);
setFlagN();
setFlagZ(acc);
}
instruction_data fEOR(Addressing addr, address val){
- acc = acc ^ fAddressing(addr, val);
+ acc = acc ^ fAddress(addr, val);
setFlagN(acc);
setFlagZ(acc);
}
@@ -364,6 +340,13 @@ instruction_data fBRK(){
+
+
+
+
+
+
+
/*
void runInstruction(int code, int val){
switch(code){