summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--log/log-readable.cpp38
-rw-r--r--src/cpu/addressing.c5
-rw-r--r--src/cpu/instructions.c114
-rw-r--r--src/main.c19
4 files changed, 91 insertions, 85 deletions
diff --git a/log/log-readable.cpp b/log/log-readable.cpp
index 82e263d..e110cdc 100644
--- a/log/log-readable.cpp
+++ b/log/log-readable.cpp
@@ -37,24 +37,36 @@ int main()
ifstream Log("log.raw");
ofstream Output("log.new");
- Output << "Time PC Label Instruction Comment\n" << endl;
+ Output << "Time PC acc X Y Flags S Label Instruction Comment\n" << endl;
while(!Log.eof())
{
+ string pc;
string t;
- // Expects time counter, and prints.
- Log >> t;
- Output << t;
- // Expecting a delimiter surrounded with space.
- Log >> t;
- Output << " : ";
- // Expecting program counter
- Log >> t;
- Output << t;
+#define GobbleDelimiter Log >> t; Output << " : "
+ // Time Counter
+ Log >> t; Output << t; GobbleDelimiter;
+ // Program counter
+ Log >> pc; Output << pc; GobbleDelimiter;
+ // acc
+ Log >> t; Output << t; GobbleDelimiter;
+ // X
+ Log >> t; Output << t; GobbleDelimiter;
+ // Y
+ Log >> t; Output << t; GobbleDelimiter;
+ // Flags for( )
+ for (int i = 0; i < 8; i++) {
+ char c;
+ Log >> c;
+ Output << c;
+ }
+ GobbleDelimiter;
+ //Log >> t; Output << t; GobbleDelimiter;
+ // Stack Pointer
+ Log >> t; Output << t;
// If a mapping exists, print out the program counter and line code.
try {
- string s = Convert[t];
- Output << t << " : ";
- Output << s;
+ string s = Convert[pc];
+ Output << " " << s;
}
// Otherwise, don't do anything.
catch (out_of_range) { }
diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c
index 903e5d0..b8f9330 100644
--- a/src/cpu/addressing.c
+++ b/src/cpu/addressing.c
@@ -18,7 +18,7 @@ address fAddressGetAddress(Addressing mode, address x) {
case eAbsolute:
return x;
case eIndirectAbsolute:
- return (address)GetMemory(x) + ((address)GetMemory(x+1) << 8);
+ return (address)GetMemory(x) + (((address)GetMemory(x+1)) << 8);
case eAbsoluteIndexedX:
return x + X;
case eAbsoluteIndexedY:
@@ -32,7 +32,8 @@ address fAddressGetAddress(Addressing mode, address x) {
case eIndexedIndirect:
return (((address)(GetMemory(x+X+1)))<<8) + (address)(GetMemory(x+X));
case eIndirectIndexed:
- return ((address)(GetMemory(x+1))<<8) + (address)(GetMemory(x)) + Y;
+ return ((address)(GetMemory(x+1))<<8) + ((address)(GetMemory(x))) + ((address)Y);
+ //return ((x >> 8) & 0xFF) (x & 0xFF)
}
}
diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c
index abe6365..2b034c4 100644
--- a/src/cpu/instructions.c
+++ b/src/cpu/instructions.c
@@ -65,7 +65,7 @@ void fSBC(Addressing addr){
SetFlagV(buffer, acc);
- SetFlag(flag_C, (buffer > acc) ? 1 : 0);
+ SetFlag(flag_C, (buffer > acc) ? 0 : 1);
acc = buffer;
@@ -190,81 +190,65 @@ void fCPY(Addressing addr){
}
void fBIT(Addressing addr){
- SetFlag(flag_N, ((idata.value & flag_N) != 0) ? 1 : 0);
- SetFlag(flag_V, ((idata.value & flag_V) != 0) ? 1 : 0);
- SetFlag(flag_Z, ((idata.value & acc) == 0) ? 1 : 0);
+ SetFlag(flag_N, ((idata.value & flag_N) != 0));
+ SetFlag(flag_V, ((idata.value & flag_V) != 0));
+ SetFlag(flag_Z, ((idata.value & acc) == 0));
}
// Shift and Rotate Instructions
void fASL(Addressing addr){
- if (addr == eAccumulator) {
- SetFlag(flag_C, (acc & 0x80));
- acc = (idata.value << 1) & 0xFE;
- SetFlagN(acc);
- SetFlagZ(acc);
- }
- else {
- SetFlag(flag_C, (idata.value & 0x80));
- byte m = ((idata.value << 1) & 0xFE);
- SetMemory(idata.add, m);
- SetFlagN(m);
- SetFlagZ(m);
- }
-}
-
-void fLSR(Addressing addr){
- if (addr == eAccumulator) {
- SetFlag(flag_C, (acc & 0x01));
- acc = (idata.value >> 1) & 0x7F;
- SetFlagN(acc);
- SetFlagZ(acc);
- }
- else {
- SetFlag(flag_C, (idata.value & 0x01));
- byte m = ((idata.value >> 1) & 0x7F);
- SetMemory(idata.add, m);
- SetFlagN(m);
- SetFlagZ(m);
- }
+ byte m = (addr == eAccumulator) ? acc : idata.value;
+
+ SetFlag(flag_C, (m & 0b10000000));
+ m = (m << 1) & 0b11111110;
+ SetFlagN(m);
+ SetFlagZ(m);
+
+ (addr == eAccumulator)
+ ? acc = m
+ : SetMemory(idata.add, m);
+}
+
+void fLSR(Addressing addr) {
+ byte m = (addr == eAccumulator) ? acc : idata.value;
+
+ SetFlag(flag_C, (m & 0b00000001));
+ m = (m >> 1) & 0b01111111;
+ SetFlagN(m);
+ SetFlagZ(m);
+
+ (addr == eAccumulator)
+ ? acc = m
+ : SetMemory(idata.add, m);
}
void fROL(Addressing addr){
- if (addr == eAccumulator) {
- SetFlag(flag_C, (idata.value & 0x80));
- acc = (idata.value << 1) & 0xFE;
- acc |= ((getFlag(flag_C) != 0) ? 0x01 : 0x00);
- SetFlagN(acc);
- SetFlagZ(acc);
- }
- else {
- SetFlag(flag_C, (idata.value & 0x80));
- byte m =
- (((idata.value << 1) & 0xFE)
- | ((getFlag(flag_C) != 0) ? 0x01 : 0x00));
- SetMemory(idata.add, m);
- SetFlagN(m);
- SetFlagZ(m);
- }
+ byte m = (addr == eAccumulator) ? acc : idata.value;
+
+ SetFlag(flag_C, (m & 0b10000000));
+ m = (m << 1) & 0b11111110;
+ m |= (getFlag(flag_C)) ? 0b00000001 : 0;
+ SetFlagN(m);
+ SetFlagZ(m);
+
+ (addr == eAccumulator)
+ ? acc = m
+ : SetMemory(idata.add, m);
}
void fROR(Addressing addr){
- if (addr == eAccumulator) {
- SetFlag(flag_C, (idata.value & 0x01));
- acc = (idata.value >> 1) & 0x7F;
- acc |= ((getFlag(flag_C) != 0) ? 0x80 : 0x00);
- SetFlagN(acc);
- SetFlagZ(acc);
- }
- else {
- SetFlag(flag_C, (idata.value & 0x01));
- byte m =
- (((idata.value >> 1) & 0x7F)
- | ((getFlag(flag_C) != 0) ? 0x80 : 0x00));
- SetMemory(idata.add, m);
- SetFlagN(m);
- SetFlagZ(m);
- }
+ byte m = (addr == eAccumulator) ? acc : idata.value;
+
+ SetFlag(flag_C, (m & 0b00000001));
+ m = (m >> 1) & 0b01111111;
+ m |= (getFlag(flag_C)) ? 0b10000000 : 0;
+ SetFlagN(m);
+ SetFlagZ(m);
+
+ (addr == eAccumulator)
+ ? acc = m
+ : SetMemory(idata.add, m);
}
// Transfer Instructions
diff --git a/src/main.c b/src/main.c
index 9e6a5ee..f8b5457 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,12 +2,11 @@
#include "video/interface.h"
#include <ncurses.h>
#include <unistd.h>
-
+#include "cpu/6502.h"
int main() {
-
AppleOn();
DisplayInit();
@@ -16,11 +15,21 @@ int main() {
int Time = 0;
while(1) {
- // Logging
- fprintf(Log, "%04x : %04x\n", Time, PC);
- fflush(Log);
// Computing
CallInstructionTable();
+ // Logging
+ fprintf(Log,
+ "%04x : %04x : %02x : %02x : %02x : %c%c_%c%c%c%c%c : %02x\n",
+ Time, PC-idata.length, acc, X, Y,
+ getFlag(flag_N) ? 'N':'.' ,
+ getFlag(flag_V) ? 'V':'.' ,
+ getFlag(flag_B) ? 'B':'.' ,
+ getFlag(flag_D) ? 'D':'.' ,
+ getFlag(flag_I) ? 'I':'.' ,
+ getFlag(flag_Z) ? 'Z':'.' ,
+ getFlag(flag_C) ? 'C':'.' ,
+ S);
+ fflush(Log);
// Display information
PrintInfo();
// Logging