diff options
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/apple.c | 25 | ||||
-rw-r--r-- | src/apple.h | 4 | ||||
-rw-r--r-- | src/cpu/6502.c | 3 | ||||
-rw-r--r-- | src/debug.h | 4 |
5 files changed, 23 insertions, 17 deletions
diff --git a/src/Makefile b/src/Makefile index 7ac3085..8762231 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,8 +11,8 @@ BUILD_STATIC_LIBRARY = ar -rcs $@ $^ default: computer.a video.a gcc -o ../apple-c -lncurses main.c $^ -interpreter: computer.a - gcc -o ../interpreter interpreter.c $^ +interpreter: computer.a video.a + gcc -o ../interpreter -lncurses interpreter.c $^ diff --git a/src/apple.c b/src/apple.c index ec7769a..52ef358 100644 --- a/src/apple.c +++ b/src/apple.c @@ -1,17 +1,21 @@ #include"apple.h" -void AppleOn(){ +byte* ROM; + +void AppleOn() { Memory = calloc(MEMORY_SIZE, sizeof(byte)); + ROM = calloc(256, sizeof(byte)); InitInstructionTable(); // Load ROM. - FILE *ROM = fopen ("rom.bin", "rb"); - if (ROM == NULL) { + FILE *ROM_File = fopen ("rom.bin", "rb"); + if (ROM_File == NULL) { printf("\n\rROM does not exist.\n"); abort(); } for (int i = 0; i < 256; i++) { - Memory[0xFF00+i] = fgetc(ROM); + ROM[i] = fgetc(ROM_File); + printf("%x", ROM[i]); } } @@ -43,18 +47,21 @@ byte ToAscii(char x) byte GetMemory(address x){ switch(x) { - // I opted to make the kbd return successfully at all times for the sake of simplicity. - // This is not technically "accurate" behavior however. + // The keyboard does not act precisely as the real hardware, because there is no need to wait for the keyboard. + // So KBD_CR and DSP always return a high high-order bit, and when the keyboard data is requested it will wait for UserInput() to finish. case KBD: return 0b10000000 | UserInput(); case KBD_CR: case DSP: return 0b10000000; - default: - return Memory[x]; } + if (x >= 0xFF00 && x <= 0xFFFF) { + return ROM[0x00FF & x]; + } } void SetMemory(address x, byte y){ - Memory[x] = y; + if (x < MEMORY_SIZE) { + Memory[x] = y; + } } diff --git a/src/apple.h b/src/apple.h index 5f38265..3a5bb97 100644 --- a/src/apple.h +++ b/src/apple.h @@ -23,5 +23,5 @@ void AppleOn(); void AppleReset(); -byte ToAppleAscii(char); -byte ToAscii(char);
\ No newline at end of file +//byte ToAppleAscii(char); +//byte ToAscii(char); diff --git a/src/cpu/6502.c b/src/cpu/6502.c index a1d3a38..17796cf 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -6,7 +6,6 @@ byte acc, X, Y, P, S = 0x00; address PC = 0x0000; byte* Memory; -byte* ROM; byte getFlag(byte flag) { return ((P & flag) == flag) ? 1 : 0; @@ -90,4 +89,4 @@ byte GetStack() { void SetStack(byte z) { SetMemory(0x01FF - S, z); -}
\ No newline at end of file +} diff --git a/src/debug.h b/src/debug.h index 0035e0f..59e3c47 100644 --- a/src/debug.h +++ b/src/debug.h @@ -35,10 +35,10 @@ void dPageDump(short m){ printf("\t"); for(int j = 0; j < 16; j+=1){ if ((j+1) % 4 == 0){ - printf("%02x ", Memory[(m+(i+j))]); + printf("%02x ", GetMemory((m+(i+j)))); } else { - printf("%02x ", Memory[(m+(i+j))]); + printf("%02x ", GetMemory((m+(i+j)))); } } printf("\n"); |