summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--headers/6502.h16
-rw-r--r--headers/addressing.h14
-rw-r--r--headers/apple.h4
-rw-r--r--headers/debug.h1
-rw-r--r--headers/instructions/definitions.h32
5 files changed, 43 insertions, 24 deletions
diff --git a/headers/6502.h b/headers/6502.h
index 0835f36..3a48edc 100644
--- a/headers/6502.h
+++ b/headers/6502.h
@@ -1,8 +1,11 @@
// 6502.h
// Core elements of the 6502 CPU
-typedef unsigned char byte;
-typedef unsigned short address;
+typedef unsigned char\
+ byte;
+typedef unsigned short\
+ address;
+
byte acc, X, Y, P, S = 0x00;
address PC = 0x0000;
byte* Memory; // TO DO. Add expansion capability to memory.
@@ -106,8 +109,15 @@ void setFlagZ(int x){
}*/
+// Memory Manipulation
+//need to add special conditions for D0 and FF
+byte getMemory(address x){
+ return Memory[x];
+}
-
+void setMemory(address x, byte y){
+ Memory[x] = y;
+}
diff --git a/headers/addressing.h b/headers/addressing.h
index af102fd..c5db440 100644
--- a/headers/addressing.h
+++ b/headers/addressing.h
@@ -37,7 +37,7 @@ int fAddressGetLength(Addressing addr){
switch(addr){
case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY:
return 3;
- case eAccumulator:
+ case eAccumulator: case eImplied:
return 1;
default:
return 2;
@@ -93,10 +93,10 @@ AddData fAddress(Addressing addr, short x) {
break;
case eIndexedIndirect:
- ret.add = (((address)Memory[x+X+1])<<8) + (Memory[x+X]);
+ ret.add = ((getMemory(x+X+1))<<8) + (getMemory(x+X));
break;
case eIndirectIndexed:
- ret.add = (((address)Memory[x+1])<<8) + (Memory[x]) + Y;
+ ret.add = ((getMemory(x+1))<<8) + (getMemory(x)) + Y;
break;
}
@@ -117,7 +117,7 @@ AddData fAddress(Addressing addr, short x) {
break;
default:
- ret.value = Memory[ret.add];
+ ret.value = getMemory(ret.add);
}
// LENGTH
@@ -214,11 +214,11 @@ AddData fAddress(Addressing addr, short x) {
|| current_instruction == &fEOR || current_instruction == &fAND || current_instruction == &fORA || current_instruction == &fCMP ){
switch(addr){
case eAbsoluteIndexedX:
- if ((x & 0xFFFC) != ((x + X) & 0xFFFC)) ret.cycles++; break;
+ if ((x & 0xFF00) != ((x + X) & 0xFF00)) ret.cycles++; break;
case eAbsoluteIndexedY:
- if ((x & 0xFFFC) != ((x + Y) & 0xFFFC)) ret.cycles++; break;
+ if ((x & 0xFF00) != ((x + Y) & 0xFF00)) ret.cycles++; break;
case eIndirectIndexed:
- if ((ret.add & 0xFFFC) != (ret.add - Y & 0xFFFC)) ret.cycles++; break;
+ if ((ret.add & 0xFF00) != (ret.add - Y & 0xFF00)) ret.cycles++; break;
}
}
diff --git a/headers/apple.h b/headers/apple.h
index b17124b..55ddaa3 100644
--- a/headers/apple.h
+++ b/headers/apple.h
@@ -10,4 +10,6 @@ void AppleReset(){
idata.cycles = 0; idata.length = 0; idata.add = 0; idata.value = 0;
free(Memory);
Memory = calloc(MEMORY_SIZE, sizeof(byte));
-} \ No newline at end of file
+}
+
+
diff --git a/headers/debug.h b/headers/debug.h
index cb9cc85..06d4733 100644
--- a/headers/debug.h
+++ b/headers/debug.h
@@ -39,5 +39,6 @@ printf("\
\t....Y:\t%x\t...add:\t%x\n\
\tstack:\t%x\t.value:\t%x\n\
\tflags:\t%x\n\
+\n\
", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P);
}
diff --git a/headers/instructions/definitions.h b/headers/instructions/definitions.h
index bdeb54e..937ca10 100644
--- a/headers/instructions/definitions.h
+++ b/headers/instructions/definitions.h
@@ -27,15 +27,15 @@ void fLDY(Addressing addr, address val){ idata = fAddress(addr, val);
}
void fSTA(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[idata.add] = acc;
+ setMemory(idata.add, acc);
}
void fSTX(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[idata.add] = X;
+ setMemory(idata.add, X);
}
void fSTY(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[idata.add] = Y;
+ setMemory(idata.add, Y);
}
// Arithmetic Instructions
@@ -71,7 +71,9 @@ void fSBC(Addressing addr, address val){ idata = fAddress(addr, val);
//Increment and Decrement Instructions
void fINC(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[idata.add]++;
+ byte a = getMemory(idata.add);
+ a++;
+ setMemory(idata.add, a);
setFlagN(Memory[idata.add]);
setFlagZ(Memory[idata.add]);
}
@@ -89,7 +91,9 @@ void fINY(Addressing addr, address val){ idata = fAddress(addr, val);
}
void fDEC(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[idata.add]--;
+ byte a = getMemory(idata.add);
+ a--;
+ setMemory(idata.add, a);
setFlagN(Memory[idata.add]);
setFlagZ(Memory[idata.add]);
}
@@ -195,11 +199,12 @@ void fCPY(Addressing addr, address val){ idata = fAddress(addr, val);
}
}
-//Need to double check the function of this instruction
+//NEED TO DOUBLE CHECK THIS INSTRUCTION
void fBIT(Addressing addr, address val){ idata = fAddress(addr, 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_N, (idata.value & flag_N));
+ setFlag(flag_V, (idata.value & flag_V));
+
+ if (((idata.value & flag_N) & (idata.value & flag_V)) == 0) {
flagSet(flag_Z);
} else {
flagSet(flag_Z);
@@ -275,26 +280,27 @@ void fTXS(Addressing addr, address val){ idata = fAddress(addr, val);
}
void fPHA(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[0x01FF-S] = acc;
+ setMemory(0x01FF-S, acc);
S++;
}
void fPHP(Addressing addr, address val){ idata = fAddress(addr, val);
- Memory[0x01FF-S] = P;
+ setMemory(0x01FF-S, P);
S++;
}
void fPLA(Addressing addr, address val){ idata = fAddress(addr, val);
S--;
- acc = Memory[0x01FF-S];
+ acc = getMemory(0x01FF-S);
}
void fPLP(Addressing addr, address val){ idata = fAddress(addr, val);
S--;
- P = Memory[0x01FF-S];
+ P = getMemory(0x01FF-S);
}
// Subroutine Instructions
+// NEED TO FINISH THESE
void fJSR(Addressing addr, address val){ idata = fAddress(addr, val);
Memory[0x01FF-S] = (idata.add-1);