diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 2 | ||||
-rw-r--r-- | src/Makefile | 6 | ||||
-rw-r--r-- | src/apple.c | 9 | ||||
-rw-r--r-- | src/apple.h | 9 | ||||
-rw-r--r-- | src/cpu/6502.c | 5 | ||||
-rw-r--r-- | src/cpu/6502.h | 5 | ||||
-rw-r--r-- | src/cpu/addressing.c | 4 | ||||
-rw-r--r-- | src/cpu/addressing.h | 2 | ||||
-rw-r--r-- | src/cpu/core.h | 14 | ||||
-rw-r--r-- | src/cpu/instructions.c | 3 | ||||
-rw-r--r-- | src/cpu/instructions.h | 1 | ||||
-rw-r--r-- | src/cpu/table.c | 5 | ||||
-rw-r--r-- | src/cpu/table.h | 3 | ||||
-rw-r--r-- | src/debug.h | 2 | ||||
-rw-r--r-- | src/interpreter.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 |
16 files changed, 53 insertions, 21 deletions
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 @@ -1,3 +1,5 @@ +#include "apple.h" + int main() { //VideoInit(); |