summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore10
-rw-r--r--src/.gitignore2
-rw-r--r--src/Makefile6
-rw-r--r--src/apple.c9
-rw-r--r--src/apple.h9
-rw-r--r--src/cpu/6502.c5
-rw-r--r--src/cpu/6502.h5
-rw-r--r--src/cpu/addressing.c4
-rw-r--r--src/cpu/addressing.h2
-rw-r--r--src/cpu/core.h14
-rw-r--r--src/cpu/instructions.c3
-rw-r--r--src/cpu/instructions.h1
-rw-r--r--src/cpu/table.c5
-rw-r--r--src/cpu/table.h3
-rw-r--r--src/debug.h2
-rw-r--r--src/interpreter.c2
-rw-r--r--src/main.c2
-rw-r--r--test/01-LDA1
18 files changed, 56 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index dfdcf93..b4fcfc8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,2 @@
-main
-instructions.bin
-instruction-dump
-.vscode/settings.json
-a
-interpreter
-build/*
-.gitignore
+build/apple-c
+build/interpreter \ No newline at end of file
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..22e64fa
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
+*.a
+*.o \ No newline at end of file
diff --git a/src/Makefile b/src/Makefile
index fcb1c3a..710df5a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,7 +8,7 @@ TARGET_VIDEO = video/ncurses.o
# Executable Targets
-default: $(MAIN_COMPONENTS)
+default: cpu.a apple.a
gcc -o ../build/apple-c main.c $^
interpreter: cpu.a apple.a
@@ -24,8 +24,8 @@ cpu.a: $(TARGET_CPU)
video.a: $(TARGET_VIDEO)
ar cr $@ $^
-apple.a:
- ar cr $@ $^
+apple.a: apple.o $(TARGET_CPU) $(TARGET_VIDEO)
+ ar -rcs $@ $^
*.o: *.c
gcc -c $^
diff --git a/src/apple.c b/src/apple.c
index 9886d2c..3e3b928 100644
--- a/src/apple.c
+++ b/src/apple.c
@@ -1,5 +1,13 @@
#include"apple.h"
+extern byte acc;
+extern byte X;
+extern byte Y;
+extern byte P;
+extern byte S;
+extern address PC;
+extern byte* Memory;
+extern byte* ROM;
void AppleOn(){
Memory = calloc(MEMORY_SIZE, sizeof(byte));
@@ -13,7 +21,6 @@ void AppleReset(){
Memory = calloc(MEMORY_SIZE, sizeof(byte));
}
-
byte getMemory(address x){
return Memory[x];
}
diff --git a/src/apple.h b/src/apple.h
index 2fe3fcb..a1d527d 100644
--- a/src/apple.h
+++ b/src/apple.h
@@ -1,12 +1,11 @@
#ifndef APPLE_H
#define APPLE_H
-
-#include"cpu/6502.c"
-#include"cpu/addressing.c"
+#include"cpu/6502.h"
+#include"cpu/addressing.h"
#include"cpu/core.h"
-#include"cpu/instructions.c"
-#include"cpu/table.c"
+#include"cpu/instructions.h"
+#include"cpu/table.h"
#define MEMORY_SIZE 4096
diff --git a/src/cpu/6502.c b/src/cpu/6502.c
index 672ead3..a5c47f5 100644
--- a/src/cpu/6502.c
+++ b/src/cpu/6502.c
@@ -3,6 +3,11 @@
#include"6502.h"
+byte acc, X, Y, P, S = 0x00;
+address PC = 0x0000;
+byte* Memory;
+byte* ROM;
+
byte getFlag(byte flag) {
return ((P & flag) == flag) ? 1 : 0;
}
diff --git a/src/cpu/6502.h b/src/cpu/6502.h
index 093fc3c..14d65f3 100644
--- a/src/cpu/6502.h
+++ b/src/cpu/6502.h
@@ -7,11 +7,6 @@
#include"stdio.h"
#include"core.h"
-byte acc, X, Y, P, S = 0x00;
-address PC = 0x0000;
-byte* Memory;
-byte* ROM;
-
// FLAGS
#define flag_N 0x80 // Negative
#define flag_V 0x40 // Overflow
diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c
index 3fd640a..df632cf 100644
--- a/src/cpu/addressing.c
+++ b/src/cpu/addressing.c
@@ -4,6 +4,10 @@
#include"addressing.h"
+
+//Holds address of current instruction.
+void* current_instruction;
+
address fAddressGetAddress(Addressing mode, short x) {
switch(mode){
case eImplied:
diff --git a/src/cpu/addressing.h b/src/cpu/addressing.h
index 2c9c63a..5fea2fb 100644
--- a/src/cpu/addressing.h
+++ b/src/cpu/addressing.h
@@ -8,8 +8,6 @@
#include"6502.h"
#include"instructions.h"
-//Holds address of current instruction.
-void* current_instruction;
#define getInstructionLength(c) fAddressGetLength(*getInstructionTableAddressing(c))
diff --git a/src/cpu/core.h b/src/cpu/core.h
index 26a6bc5..b305021 100644
--- a/src/cpu/core.h
+++ b/src/cpu/core.h
@@ -9,6 +9,16 @@ typedef
unsigned short
address;
+extern byte acc;
+extern byte X;
+extern byte Y;
+extern byte P;
+extern byte S;
+extern address PC;
+extern byte* Memory;
+extern byte* ROM;
+
+
enum Addressing
{
eImmediate,
@@ -43,4 +53,8 @@ byte getMemory(address x);
void setMemory(address x, byte y);
+extern void *current_instruction;
+extern AddData idata;
+extern void (*func)(Addressing, address);
+
#endif \ No newline at end of file
diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c
index 6e80602..a4c96d6 100644
--- a/src/cpu/instructions.c
+++ b/src/cpu/instructions.c
@@ -11,6 +11,9 @@ Fix all functions before performing testing
*/
+
+AddData idata;
+
// Load and Store Instructions
void fLDA(Addressing addr, address val){
diff --git a/src/cpu/instructions.h b/src/cpu/instructions.h
index 6e8c1bf..33ba11d 100644
--- a/src/cpu/instructions.h
+++ b/src/cpu/instructions.h
@@ -6,7 +6,6 @@
#include"6502.h"
//#include"addressing.h"
-AddData idata;
// Load and Store Instructions
void fLDA(Addressing, address);
diff --git a/src/cpu/table.c b/src/cpu/table.c
index fb419d2..cdbe995 100644
--- a/src/cpu/table.c
+++ b/src/cpu/table.c
@@ -2,6 +2,11 @@
#include"table.h"
+
+void* InstructionTable;
+
+void (*func)(Addressing, address);
+
uintptr_t* getInstructionTableFunction(int i){ //Segmentation fault is occurring here, likely in next one too
uintptr_t* r = (InstructionTable + (sizeof(uintptr_t)*i));
return r;
diff --git a/src/cpu/table.h b/src/cpu/table.h
index e54776d..c8ecb00 100644
--- a/src/cpu/table.h
+++ b/src/cpu/table.h
@@ -8,9 +8,6 @@
#include"string.h"
#include"addressing.h"
-void* InstructionTable;
-
-void (*func)(Addressing, address);
#define InstructionTableSize (256 * (sizeof(uintptr_t) + sizeof(Addressing)))
diff --git a/src/debug.h b/src/debug.h
index 9a365db..0035e0f 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -8,6 +8,8 @@
#include"cpu/instructions.h"
#include"cpu/table.h"
+
+
// Converts a single character to hexadecimal
int dCharToNum(char c){
// 0x0 - 0x9
diff --git a/src/interpreter.c b/src/interpreter.c
index 4005998..200347e 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -2,7 +2,7 @@
// Useful for carrying out tests of the CPU instructions.
// Refer to interpreter.md for the manual
-#include"apple.c"
+#include"apple.h"
#include"debug.h"
//Write a custom getc function here which ignores spaces
diff --git a/src/main.c b/src/main.c
index 746d290..f640bc1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,5 @@
+#include "apple.h"
+
int main() {
//VideoInit();
diff --git a/test/01-LDA b/test/01-LDA
index 7b0f0d1..3c55624 100644
--- a/test/01-LDA
+++ b/test/01-LDA
@@ -30,4 +30,5 @@ b107 8518 #LDA In. Y store in 0019
#Print 00 Page
m00
+m02
q