diff options
-rw-r--r-- | ToDo | 12 | ||||
-rw-r--r-- | headers/6502.h (renamed from headers/applesystem.h) | 20 | ||||
-rw-r--r-- | headers/addressing.h | 2 | ||||
-rw-r--r-- | headers/apple.h | 6 | ||||
-rw-r--r-- | headers/debug.h | 12 | ||||
-rw-r--r-- | headers/include.h | 5 | ||||
-rw-r--r-- | headers/instruction-table.h (renamed from headers/instruction-bin.h) | 25 | ||||
-rw-r--r-- | headers/instructions-init.h (renamed from headers/instruction-init.h) | 27 | ||||
-rw-r--r-- | headers/instructions.h | 23 | ||||
-rwxr-xr-x | inbin | bin | 30760 -> 0 bytes | |||
-rw-r--r-- | interpreter.c | 13 | ||||
-rw-r--r-- | test.c | 20 |
12 files changed, 84 insertions, 81 deletions
@@ -1,12 +1,8 @@ Before the next commit, this should all be completed. -First and foremost, make sure reading is possible. +Go through instruction.h and fix every instruction to work with data structures + + -Create the makefile. -Fix directory structures and header files before it gets even messier. -Delete unnecessary files. -Fix up the instruction dump file. -Expand the names of any acronyms, like IT Figure out simple threading in C to run other programs within the same address space. Perhaps use this to let the emulator run as an engine, which is interfaced by swappable clients, such as the SDL terminal emulator, terminal, and instruction interpreter clients. - Following on from this, functions like a computer hard reset may be useful. -Unstage a.out.
\ No newline at end of file + Following on from this, functions like a computer hard reset may be useful.
\ No newline at end of file diff --git a/headers/applesystem.h b/headers/6502.h index 6b2f818..ea92479 100644 --- a/headers/applesystem.h +++ b/headers/6502.h @@ -1,5 +1,5 @@ -// applesystem.h -// Core elements of the 6502 CPU, and flag manipulation. +// 6502.h +// Core elements of the 6502 CPU typedef unsigned char byte; typedef unsigned short address; @@ -8,19 +8,19 @@ address PC = 0x0000; byte Memory[4096]; // TO DO. Add expansion capability to memory. // FLAGS -const byte flag_N = 0x80; // Negative -const byte flag_V = 0x40; // Overflow -const byte flag_B = 0x10; // BRK command -const byte flag_D = 0x08; // Decimal mode -const byte flag_I = 0x04; // IRQ disable -const byte flag_Z = 0x02; // Zero -const byte flag_C = 0x01; // Carry +#define flag_N 0x80 // Negative +#define flag_V 0x40 // Overflow +#define flag_B 0x10 // BRK command +#define flag_D 0x08 // Decimal mode +#define flag_I 0x04 // IRQ disable +#define flag_Z 0x02 // Zero +#define flag_C 0x01 // Carry byte getFlag(byte flag) { return ((P & flag) == flag) ? 1 : 0; } -void setFlag(byte flag, int x) { //OVERLOAD TO ACCEPT INT AS WELL +void setFlag(byte flag, int x) { if (x == 1){ if ((P & flag) == 0x0) P += flag; }else if (x == 0){ diff --git a/headers/addressing.h b/headers/addressing.h index d9d8e98..58df3f5 100644 --- a/headers/addressing.h +++ b/headers/addressing.h @@ -28,7 +28,7 @@ struct AddData{ typedef struct AddData AddData; -#include"instruction-init.h" +#include"instructions-init.h" //Holds address of current instruction. void* current_instruction; diff --git a/headers/apple.h b/headers/apple.h new file mode 100644 index 0000000..f5cac5c --- /dev/null +++ b/headers/apple.h @@ -0,0 +1,6 @@ +#define MEMORY_SIZE 4096 + +void AppleOn(){ + //Memory = malloc(MEMORY_SIZE); + initInstructionTable(); +}
\ No newline at end of file diff --git a/headers/debug.h b/headers/debug.h index bb6ba40..cb34dac 100644 --- a/headers/debug.h +++ b/headers/debug.h @@ -33,9 +33,11 @@ void dPageDump(short m){ // Dump CPU values void dStatusDump(void){ - printf(" acc:\t%x\n X:\t%x\n Y:\t%x\nstack:\t%x\nflags:\t%x\n", acc, X, Y, S, P); +printf("\ +..acc:\t%x\tcycles:\t%d\n\ +....X:\t%x\tlength:\t%d\n\ +....Y:\t%x\t...add:\t%x\n\ +stack:\t%x\t.value:\t%x\n\ +flags:\t%x\n\ +", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P); } - -void dIdataDump(void){ - printf("cycles:\t%d\nlength:\t%d\n add:\t%x\n value:\t%x\n", idata.cycles, idata.length, idata.add, idata.value); -}
\ No newline at end of file diff --git a/headers/include.h b/headers/include.h index e2578de..c4a2ef8 100644 --- a/headers/include.h +++ b/headers/include.h @@ -2,7 +2,8 @@ #include"stdint.h" #include"stdlib.h" #include"string.h" -#include"applesystem.h" +#include"6502.h" #include"addressing.h" #include"instructions.h" -#include"instruction-bin.h"
\ No newline at end of file +#include"instruction-table.h" +#include"apple.h"
\ No newline at end of file diff --git a/headers/instruction-bin.h b/headers/instruction-table.h index 0127fd7..bb51adb 100644 --- a/headers/instruction-bin.h +++ b/headers/instruction-table.h @@ -1,3 +1,28 @@ +// instruction-table.h +// Defines the instruction table, and the functions to access it. + +void* InstructionTable; +void (*func)(Addressing, address); + +#define InstructionTableSize (256 * (sizeof(uintptr_t) + sizeof(Addressing))) + +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; +} + +Addressing* getInstructionTableAddressing(int i){ + Addressing* r = (InstructionTable + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i)); + return r; +} + +void callInstructionTable(int i, address val){ + uintptr_t a = getInstructionTableFunction(i); + memcpy(&func, a, sizeof(uintptr_t)); + Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i))); + func(*r, val); +} + void setInstructionTable(int i, uintptr_t p, Addressing r){ uintptr_t* p1 = (InstructionTable + (sizeof(uintptr_t)*i)); *p1 = p; diff --git a/headers/instruction-init.h b/headers/instructions-init.h index 68b9cf3..6fddec4 100644 --- a/headers/instruction-init.h +++ b/headers/instructions-init.h @@ -1,32 +1,5 @@ // instruction-init.h // Initializes every instruction function prior to addressing.h so that function addresses are accessible -// also defines the array used to refer to functions - -//InstructionTable -void* InstructionTable; -void (*func)(Addressing, address); - -#define InstructionTableSize (256 * (sizeof(uintptr_t) + sizeof(Addressing))) - -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; -} - -Addressing* getInstructionTableAddressing(int i){ - Addressing* r = (InstructionTable + (sizeof(uintptr_t)*256) + (sizeof(Addressing)*i)); - return r; -} - -void callInstructionTable(int i, address val){ - printf("Table:\t%x\n", InstructionTable); - uintptr_t a = getInstructionTableFunction(i); - printf("A Val:\t%x\n", a); - //printf("Before:\t%x\n", func); func = a; printf("After:\t%x\n", func); - printf("Before:\t%x\n", func); memcpy(&func, a, sizeof(uintptr_t)); printf("After:\t%x\n", func); - Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i))); - func(*r, val); printf("Statement OK"); -} // Load and Store Instructions void fLDA(Addressing, address); diff --git a/headers/instructions.h b/headers/instructions.h index 96f5719..bdcd442 100644 --- a/headers/instructions.h +++ b/headers/instructions.h @@ -1,13 +1,16 @@ -// instruction.h +// instructions.h // Definition of all instruction functions, handling effect of instruction and flags. -// 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 -AddData idata; +/* TO DO + +!!!!!!!! CHECK THAT idata.value IS USED ACROSS ALL FUNCTIONS, NOT VAL !!!!!!!!!!!!!! + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Fix all functions before performing testing + +*/ // Load and Store Instructions @@ -206,15 +209,15 @@ void fBIT(Addressing addr, address val){ idata = fAddress(addr, val); // Shift and Rotate Instructions void fASL(Addressing addr, address val){ idata = fAddress(addr, val); - setFlag(flag_C, (val & 0x80)); - acc = (val << 1); + setFlag(flag_C, (idata.value & 0x80)); + acc = (idata.value << 1); setFlagN(acc); setFlagZ(acc); } void fLSR(Addressing addr, address val){ idata = fAddress(addr, val); - setFlag(flag_C, (val & 0x01)); - acc = (val >> 1); + setFlag(flag_C, (idata.value & 0x01)); + acc = (idata.value >> 1); setFlagN(acc); setFlagZ(acc); } Binary files differdiff --git a/interpreter.c b/interpreter.c index e49c77a..14ef400 100644 --- a/interpreter.c +++ b/interpreter.c @@ -1,20 +1,15 @@ -/* - * interpreter.c WILL BE a tool which can be used to interpret 6502 machine code inline. - * Machine code is expected as hexadecimal of length 2 or 6, depending on the instruction. - * There are a few special characters which print debug information +//interpreter.c is a tool which can interpret 6502 assembly on the go, for the purposes of testing. +/* Special Commands for debug information Q - Quit P - Processor status dump M - Dump a page of memory - */ +*/ #include"headers/include.h" #include"headers/debug.h" int main(){ - char c; - unsigned char a, b; - - initIT(); + AppleOn(); while(1){ c = fgetc(stdin); @@ -1,17 +1,19 @@ +// test.c +// Temporary .c file where arbitrary tests are carried out. + #include"headers/include.h" #include"headers/debug.h" int main(int argc, char *argv[]){ + AppleOn(); initInstructionTable(); - byte* a; - for(int i = 0; i < InstructionTableSize; i++){ - a = InstructionTable + i; - printf("%x\t", *a); - if ((i % 8) == 7) printf("\n"); - } + dStatusDump(); + + fLDA(eImmediate, 0x01); + fSTA(eAbsolute, 0x09); + + dStatusDump(); printf("\n"); - printf("\n"); dStatusDump(); dIdataDump(); printf("%x\n", &fLDA); printf("\n"); - callInstructionTable(0xA9, 0x01); - dStatusDump(); dIdataDump(); printf("\n"); + dPageDump(0x00); }
\ No newline at end of file |