diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | ToDo | 11 | ||||
-rw-r--r-- | assembler.c | 40 | ||||
-rw-r--r-- | headers/6502.h | 2 | ||||
-rw-r--r-- | headers/addressing.h | 16 | ||||
-rw-r--r-- | headers/apple.h | 7 | ||||
-rw-r--r-- | headers/debug.h | 4 | ||||
-rw-r--r-- | interpreter.c | 104 | ||||
-rw-r--r-- | test.c | 19 |
9 files changed, 82 insertions, 132 deletions
@@ -8,12 +8,9 @@ My emulator has a handful of specific milestones to achieve that will demonstrat 2. Run a system monitor program correctly. 3. Successfully run a BASIC program in Wozniak's BASIC interpreter. -Restrictions of my emulator include: - -1. No plans to support illegal instructions as of yet. +There are no plans as of yet to support illegal instructions. Planned core features for the emulator include: - -1. A terminal emulator with the original Apple I font. -2. A program to read binary files straight to memory. -3. An extremely simple assembler so the user may write programs to read into the emulator.
\ No newline at end of file +1. A mode to run an SDL terminal emulator with the original Apple I font. +2. A mode to run within the users terminal. +3. A program to read binary files straight to memory.
\ No newline at end of file @@ -2,7 +2,14 @@ Before the next commit, this should all be completed. Go through instruction.h and fix every instruction to work with data structures - +Link pthreads library, and segregate work into multiple threads. 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.
\ No newline at end of file + + + + Tests to run +LDA/SBC +JMP +CMP,CPX,CPY +stack instructions
\ No newline at end of file diff --git a/assembler.c b/assembler.c deleted file mode 100644 index 1797d9b..0000000 --- a/assembler.c +++ /dev/null @@ -1,40 +0,0 @@ -// assembler.c -// A minimalistic assembler for creating binary files. - -#include"stdio.h" - -int main(int argc; char* argv[]){ - int output = 0; - switch(argc){ - case 0: // Arguments are required - printf("%s: Input file not given.\n", argv[0]); - return -1; - case 1: // Input file - break; - case 2: // Input and Output file - output = 1; - break; - default: - printf("%s: Too many arguments.\n", argv[0]); - break; - } - - //test file existence - - -//call open file - -// DRAFTING PROG LOGIC -/* -char c = 0; -char in[10]; -while((c != '\n') && (c != EOF) -c = getchar; -if(c == '#') c = '\n'; -in[i] = c; -*/ - -} - - - diff --git a/headers/6502.h b/headers/6502.h index ea92479..0835f36 100644 --- a/headers/6502.h +++ b/headers/6502.h @@ -5,7 +5,7 @@ typedef unsigned char byte; typedef unsigned short address; byte acc, X, Y, P, S = 0x00; address PC = 0x0000; -byte Memory[4096]; // TO DO. Add expansion capability to memory. +byte* Memory; // TO DO. Add expansion capability to memory. // FLAGS #define flag_N 0x80 // Negative diff --git a/headers/addressing.h b/headers/addressing.h index 58df3f5..d1b8371 100644 --- a/headers/addressing.h +++ b/headers/addressing.h @@ -33,7 +33,7 @@ typedef struct AddData AddData; //Holds address of current instruction. void* current_instruction; -Addressing fAddressGetLength(Addressing addr){ +int fAddressGetLength(Addressing addr){ switch(addr){ case eAbsolute: case eAbsoluteIndexedX: case eAbsoluteIndexedY: return 3; @@ -44,6 +44,20 @@ Addressing fAddressGetLength(Addressing addr){ } } +int fAddressGetLengthPrempt(int i){ //Check the functions to make sure that there isnt some incorrect values being given for length. + switch(i){ + case 0x6D: case 0x7D: case 0x79: case 0x2D: case 0x3D: case 0x39: case 0x0E: case 0x1E: case 0x2C: case 0xCD: case 0xD0: case 0xD9: case 0xEC: + case 0xCC: case 0xCE: case 0xDE: case 0x4D: case 0x5D: case 0x59: case 0xEE: case 0xFE: case 0x4C: case 0x20: case 0xAD: case 0xBD: case 0xB9: + case 0xAE: case 0xBE: case 0xAC: case 0xBC: case 0x4E: case 0x5E: case 0x0D: case 0x1D: case 0x19: case 0x2E: case 0x3E: case 0x6E: case 0x7E: + case 0xED: case 0xFD: case 0xF9: case 0x8D: case 0x9D: case 0x99: case 0x8E: case 0x8C: + return 3; + case 0x0A: case 0x2A: case 0x4A: case 0x6A: + return 1; + default: + return 2; + } +} + AddData fAddress(Addressing addr, short x) { AddData ret; diff --git a/headers/apple.h b/headers/apple.h index f5cac5c..cfcc879 100644 --- a/headers/apple.h +++ b/headers/apple.h @@ -1,6 +1,11 @@ #define MEMORY_SIZE 4096 void AppleOn(){ - //Memory = malloc(MEMORY_SIZE); + Memory = calloc(MEMORY_SIZE, sizeof(byte)); initInstructionTable(); +} + +void AppleReset(){ //Firt few Zp addresses have gibberish, need to fix + 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 cb34dac..4b36710 100644 --- a/headers/debug.h +++ b/headers/debug.h @@ -1,7 +1,7 @@ // debug.h // Various functions useful for use during development. -// Converts a single character to hexadecimal +// Converts a single character to hexadecimal int dCharToNum(char c){ // 0x0 - 0x9 if (c != 0x20 && (c >= 0x30 && c <= 0x39)){ @@ -19,7 +19,7 @@ int dCharToNum(char c){ } } -// Dump a particular page in memory. +// Dump page m from memory to stdout. void dPageDump(short m){ m <<= 8; for(int i = 0; i < 256; i+=16){ diff --git a/interpreter.c b/interpreter.c index 14ef400..fece473 100644 --- a/interpreter.c +++ b/interpreter.c @@ -1,61 +1,47 @@ -//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" +// test.c +// Temporary .c file where arbitrary tests are carried out. + +#include"headers/include.h" //LOOK INTO PTHREADS #include"headers/debug.h" -int main(){ - AppleOn(); - - while(1){ - c = fgetc(stdin); - - // Exit condition - if ( (c == 'Q') || (c == 'q') || (c == EOF) ) break; - - if (dCharToNum(c) == -1){ - // Debug print conditions - switch(c){ - // Print debug information - case 'P': case 'p': - dStatusDump(); - break; - // Dump memory page - case 'M': case 'm': - byte m; - m += dCharToNum(fgetc(stdin)) << 4; - m += dCharToNum(fgetc(stdin)); - dPageDump(m); - break; - case ' ': case '\n': - break; - } - }else{ // RUN INSTRUCTION - // Pass in Instruction - byte inst = dCharToNum(c) << 4; - inst += dCharToNum(fgetc(stdin)); - // Pass in Value - address pass = 0x0000; - int range = fAddressGetLength(getITAddressing(inst)); - printf("range = %d\n", range); //DEBUG - range = ((2*range)-2); - c = fgetc(stdin); - for(int i = 0; i < range; i++){ - if ((c == ' ') || (c == '\n')){ - i--; - }else{ - pass <<= 4; - pass += c; - } - c = fgetc(stdin); - } - current_instruction = getITFunction(inst); - callIT(current_instruction, pass); - } - } - return 0; -}
\ No newline at end of file +int main(int argc, char *argv[]){ + AppleOn(); + + + byte c; + + // Interpreter loop + while(1){ + do { + c = getc(stdin); + } while (c == '\n' || c == ' '); + + if (c == 'P' || c == 'p'){ + dStatusDump(); + continue; + } + + if (c == 'M' || c == 'm'){ + c = dCharToNum(getc(stdin)) << 4; + c += dCharToNum(getc(stdin)); + dPageDump(c); + continue; + } + + // From here on it is expected input will be mostly correct + c = dCharToNum(c) << 4; + c += dCharToNum(getc(stdin)); + address x = 0x0000; + char z; + for(int i = ((fAddressGetLengthPrempt(c) * 2) - 2); i > 0; i--) { + z = getc(stdin); + if (z != '\n'){ + x += dCharToNum(z) << ((4 * (i - 1))); + }else{ + i++; + } + } + callInstructionTable(c, x); + } + +} @@ -1,19 +0,0 @@ -// 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(); - - dStatusDump(); - - fLDA(eImmediate, 0x01); - fSTA(eAbsolute, 0x09); - - dStatusDump(); printf("\n"); - - dPageDump(0x00); -}
\ No newline at end of file |