summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addressing.h65
-rw-r--r--assembler.c41
-rw-r--r--instruction.h85
3 files changed, 113 insertions, 78 deletions
diff --git a/addressing.h b/addressing.h
index 3d67b33..1a80466 100644
--- a/addressing.h
+++ b/addressing.h
@@ -3,33 +3,22 @@
enum Addressing {
eImmediate,
+ eAccumulator,
eAbsolute,
- eZeroPage,
- eImplied,
- eIndirectAbsolute,
eAbsoluteIndexedX,
eAbsoluteIndexedY,
+ eZeroPage,
eZeroPageIndexedX,
eZeroPageIndexedY,
eIndexedIndirect,
eIndirectIndexed,
- eRelative,
- eAccumulator
+ eImplied,
+ eIndirectAbsolute,
+ eRelative
};
typedef int Addressing;
-int getLength(Addressing addr){
- switch(addr){
- case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
- return 3;
- case eAccumulator:
- return 1;
- default:
- return 2;
- }
-}
-
/*
* Any addressing method which is single line commented out without definition
* implies that handling should be hard-coded in the switch case of the
@@ -37,26 +26,48 @@ int getLength(Addressing addr){
*/
-int fAddressing(Addressing addr, short x) {
+
+struct AddData{
+ int cycles;
+ int length;
+ byte value;
+};
+
+AddData fAddress(Addressing addr, short x) {
+ AddData ret;
switch(addr){
- case eImmediate: return x;
- case eAccumulator: return acc;
+ case eImmediate: ret.value = x; break;
+ case eAccumulator: ret.value = acc; break;
- case eAbsolute: return Memory[x];
- case eAbsoluteIndexedX: return Memory[(x + X)];
- case eAbsoluteIndexedY: return Memory[(x + Y)];
+ case eAbsolute: ret.value = Memory[x]; break;
+ case eAbsoluteIndexedX: ret.value = Memory[(x + X)]; break;
+ case eAbsoluteIndexedY: ret.value = Memory[(x + Y)]; break;
- case eZeroPage: return Memory[(x & 0x00FF)];
- case eZeroPageIndexedX: return Memory[((x = X) & 0x00FF)];
- case eZeroPageIndexedY: return Memory[((x = Y) & 0x00FF)];
+ case eZeroPage: ret.value = Memory[(x & 0x00FF)]; break;
+ case eZeroPageIndexedX: ret.value = Memory[((x = X) & 0x00FF)]; break;
+ case eZeroPageIndexedY: ret.value = Memory[((x = Y) & 0x00FF)]; break;
- case eIndexedIndirect: return Memory[((x + X) << 8) + ((x + X) + 1)];
- case eIndirectIndexed: return ((Memory[x] + Memory[(x+1 << 8)]) + Y);
+ case eIndexedIndirect: ret.value = Memory[((x + X) << 8) + ((x + X) + 1)]; break;
+ case eIndirectIndexed: ret.value = ((Memory[x] + Memory[(x+1 << 8)]) + Y); break;
//case eImplied: No reference
//case eIndirectAbsolute: Only used in the JMP instruction
//case eRelative: Only used in branch instructions
}
+ switch(addr){
+ case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
+ ret.length = 3; break;
+ case eAccumulator:
+ ret.length = 1; break;
+ default:
+ ret.length = 2; break;
+ }
+
+
+ // FOR TIME, FIND THE PARTICULAR VALUE SET FOR THE FIRST TYPE,
+ // APPLY RELATIVE MOVEMENT
+ // THEN LET THE FUNCTION WHICH CALLED fAddress HANDLE A NON-TYPICAL VALUE.
+
}
diff --git a/assembler.c b/assembler.c
new file mode 100644
index 0000000..5112dc5
--- /dev/null
+++ b/assembler.c
@@ -0,0 +1,41 @@
+#include"stdio.h"
+//syscall library
+
+
+//Will probably need to make a special case which will prevent EOF
+//from being written.
+
+int main(int argc; char* argv[]){
+ int output = 0;
+ switch(argc){
+ case 0: // Arguments are required
+ printf("%s: Input file not given.\n", argv[0]);
+ return -1;
+ case 1: // Input file
+ break;
+ case 2: // Input and Output file
+ output = 1;
+ break;
+ default:
+ printf("%s: Too many arguments.\n", argv[0]);
+ break;
+ }
+
+ //test file existence
+
+
+//call open file
+
+// DRAFTING PROG LOGIC
+char c = 0;
+char in[10];
+while((c != '\n') && (c != '\0')
+c = getchar;
+if(c == '#') c = '\n';
+in[i] = c;
+
+
+}
+
+
+
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){