diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-01 00:47:05 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-01 00:47:05 +1100 |
commit | 580a7040ba53367c15ca682d4ea90c31fdcca45f (patch) | |
tree | 58ccb3ddb419884f6f9da790b0173a62eb4dd22f /src | |
parent | 40447eccd6db43d636ccc518ae7792b7b43834b5 (diff) |
large progress approaching functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/apple.c | 14 | ||||
-rw-r--r-- | src/cpu/6502.c | 11 | ||||
-rw-r--r-- | src/cpu/instructions.c | 115 | ||||
-rw-r--r-- | src/cpu/table.c | 1 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/video/ncurses.c | 26 |
6 files changed, 54 insertions, 115 deletions
diff --git a/src/apple.c b/src/apple.c index 8a5e73b..6f48c10 100644 --- a/src/apple.c +++ b/src/apple.c @@ -84,9 +84,14 @@ byte GetMemory(address x){ // 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: + char c = -1; + while(c == -1) + c = UserInput(); + return 0b10000000 | c; + case KBD_CR: return 0b10000000; + case DSP: + return 0b00000000; } if (x >= 0xFF00 && x <= 0xFFFF) { @@ -100,6 +105,11 @@ byte GetMemory(address x){ } void SetMemory(address x, byte y){ + switch(x) + { + case DSP: + + } if (x < MEMORY_SIZE) { Memory[x] = y; } diff --git a/src/cpu/6502.c b/src/cpu/6502.c index 17796cf..ab8248e 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -33,10 +33,11 @@ void flagClear(byte flag){ // Functions which perform reusable routines for finding if a specific flag should be set. void SetFlagN(byte x){ - if ((x & flag_N) == flag_N) + /*if ((x & flag_N) == flag_N) SetFlag(flag_N, 1); else - SetFlag(flag_N, 0); + SetFlag(flag_N, 0);*/ + P = (x & flag_N) | (P & ~flag_N); } //Perform prior to any changes @@ -84,9 +85,11 @@ void SetMemory(address x, byte y){ byte GetStack() { + S--; return GetMemory(0x01FF - S); } -void SetStack(byte z) { - SetMemory(0x01FF - S, z); +void SetStack(byte x) { + SetMemory(0x01FF - S, x); + S++; } diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index 36e2a41..c043ac4 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -18,32 +18,27 @@ AddData idata; void fLDA(Addressing addr, address val){ acc = idata.value; - PC += idata.length; + SetFlagN(acc); } void fLDX(Addressing addr, address val){ X = idata.value; - PC += idata.length; } void fLDY(Addressing addr, address val){ Y = idata.value; - PC += idata.length; } void fSTA(Addressing addr, address val){ SetMemory(idata.add, acc); - PC += idata.length; } void fSTX(Addressing addr, address val){ SetMemory(idata.add, X); - PC += idata.length; } void fSTY(Addressing addr, address val){ SetMemory(idata.add, Y); - PC += idata.length; } // Arithmetic Instructions @@ -60,7 +55,6 @@ void fADC(Addressing addr, address val){ acc += idata.value; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fSBC(Addressing addr, address val){ @@ -75,7 +69,6 @@ void fSBC(Addressing addr, address val){ acc -= idata.value; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } //Increment and Decrement Instructions @@ -86,21 +79,18 @@ void fINC(Addressing addr, address val){ SetMemory(idata.add, a); SetFlagN(Memory[idata.add]); SetFlagZ(Memory[idata.add]); - PC += idata.length; } void fINX(Addressing addr, address val){ X++; SetFlagN(X); SetFlagZ(X); - PC += idata.length; } void fINY(Addressing addr, address val){ Y++; SetFlagN(Y); SetFlagZ(Y); - PC += idata.length; } void fDEC(Addressing addr, address val){ @@ -109,21 +99,18 @@ void fDEC(Addressing addr, address val){ SetMemory(idata.add, a); SetFlagN(Memory[idata.add]); SetFlagZ(Memory[idata.add]); - PC += idata.length; } void fDEX(Addressing addr, address val){ X--; SetFlagN(X); SetFlagZ(X); - PC += idata.length; } void fDEY(Addressing addr, address val){ Y--; SetFlagN(Y); SetFlagZ(Y); - PC += idata.length; } // Logical Instructions @@ -132,21 +119,18 @@ void fAND(Addressing addr, address val){ acc &= idata.value; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fORA(Addressing addr, address val){ acc |= idata.value; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fEOR(Addressing addr, address val){ acc ^= idata.value; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } // Jump, Branch, Compare, and Test Bits @@ -157,59 +141,35 @@ void fJMP(Addressing addr, address val){ void fBCC(Addressing addr, address val){ //FINISH ALL BRANCH INSTRUCTIONS //signed char val down to BVC - if (getFlag(flag_C) == 0) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_C) == 0) PC += (char)val; } void fBCS(Addressing addr, address val){ - if (getFlag(flag_C) == 1) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_C) == 1) PC += (char)val; } void fBEQ(Addressing addr, address val){ - if (getFlag(flag_Z) == 1) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_Z) == 1) PC += (char)val; } void fBNE(Addressing addr, address val){ - if (getFlag(flag_Z) == 0) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_Z) == 0) PC += (char)val; } void fBMI(Addressing addr, address val){ - if (getFlag(flag_N) == 1) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_N) == 1) PC += (char)val; } void fBPL(Addressing addr, address val){ - if (getFlag(flag_N) == 0) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_N) == 0) PC += (char)val; } void fBVS(Addressing addr, address val){ - if (getFlag(flag_V) == 1) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_V) == 1) PC += (char)val; } void fBVC(Addressing addr, address val){ - if (getFlag(flag_V) == 0) - PC += (char)val; - else - PC += idata.length; + if (getFlag(flag_V) == 0) PC += (char)val; } void fCMP(Addressing addr, address val){ @@ -222,7 +182,6 @@ void fCMP(Addressing addr, address val){ else if (acc > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } - PC += idata.length; } void fCPX(Addressing addr, address val){ @@ -235,7 +194,6 @@ void fCPX(Addressing addr, address val){ else if (X > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } - PC += idata.length; } void fCPY(Addressing addr, address val){ @@ -248,20 +206,18 @@ void fCPY(Addressing addr, address val){ else if (Y > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } - PC += idata.length; } //NEED TO DOUBLE CHECK THIS INSTRUCTION void fBIT(Addressing addr, address val){ - SetFlag(flag_N, (idata.value & flag_N)); - SetFlag(flag_V, (idata.value & flag_V)); + SetFlag(flag_N, (idata.value & flag_N)?1:0); + SetFlag(flag_V, (idata.value & flag_V)?1:0); if (((idata.value & flag_N) & (idata.value & flag_V)) == 0) { flagSet(flag_Z); } else { flagSet(flag_Z); } - PC += idata.length; } // Shift and Rotate Instructions @@ -271,7 +227,6 @@ void fASL(Addressing addr, address val){ acc = (idata.value << 1); SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fLSR(Addressing addr, address val){ @@ -279,7 +234,6 @@ void fLSR(Addressing addr, address val){ acc = (idata.value >> 1); SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fROL(Addressing addr, address val){ @@ -288,7 +242,6 @@ void fROL(Addressing addr, address val){ acc |= (getFlag(flag_C) * 0x01); SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fROR(Addressing addr, address val){ @@ -297,7 +250,6 @@ void fROR(Addressing addr, address val){ acc |= (getFlag(flag_C) * 0x80); SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } // Transfer Instructions @@ -306,90 +258,69 @@ void fTAX(Addressing addr, address val){ X = acc; //SetFlagN(X); //SetFlagZ(X); - PC += idata.length; } void fTAY(Addressing addr, address val){ Y = acc; //SetFlagN(Y); //SetFlagZ(Y); - PC += idata.length; } void fTXA(Addressing addr, address val){ acc = X; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } void fTYA(Addressing addr, address val){ acc = Y; SetFlagN(acc); SetFlagZ(acc); - PC += idata.length; } // Stack Instructions void fTSX(Addressing addr, address val){ X = S; - PC += idata.length; } void fTXS(Addressing addr, address val){ S = X; - PC += idata.length; } void fPHA(Addressing addr, address val){ SetStack(acc); - S++; - PC += idata.length; } void fPHP(Addressing addr, address val){ SetStack(P); - S++; - PC += idata.length; } void fPLA(Addressing addr, address val){ - S--; acc = GetStack(); - PC += idata.length; } void fPLP(Addressing addr, address val){ - S--; P = GetStack(); - PC += idata.length; } // Subroutine Instructions // NEED TO FINISH THESE void fJSR(Addressing addr, address val){ - SetStack(((PC-1) & 0xFF00) >> 8); - S++; - SetStack((PC-1) & 0x00FF); - S++; + SetStack((PC+3) >> 8); + SetStack((PC+3) & 0x00FF); PC = idata.add; } void fRTS(Addressing addr, address val){ - S--; - PC = (address)(GetStack() + 1); - S--; + PC = (address)(GetStack()) - 1; PC += ((address)(GetStack())) << 8; } void fRTI(Addressing addr, address val){ - S--; P = GetStack(); //NEED TO FIX - S--; - PC = (address)(GetStack()); - S--; + PC = (address)(GetStack()); PC += (address)(GetStack() << 8); } @@ -397,57 +328,41 @@ void fRTI(Addressing addr, address val){ void fCLC(Addressing addr, address val){ flagClear(flag_C); - PC += idata.length; } void fCLD(Addressing addr, address val){ flagClear(flag_D); - PC += idata.length; } void fCLI(Addressing addr, address val){ flagClear(flag_I); - PC += idata.length; } void fCLV(Addressing addr, address val){ flagClear(flag_V); - PC += idata.length; } void fSEC(Addressing addr, address val){ flagSet(flag_C); - PC += idata.length; } void fSED(Addressing addr, address val){ flagSet(flag_D); - PC += idata.length; } void fSEI(Addressing addr, address val){ flagSet(flag_I); - PC += idata.length; } // NOP/BRK Instructions void fNOP(Addressing addr, address val){ - PC += idata.length; } void fBRK(Addressing addr, address val){ SetStack((((PC+2) & 0xFF00) >> 8)); - S++; SetStack((PC+2) & 0x00FF); - S++; SetStack(P); - S++; PC = (address)(GetMemory(0xFFFE)); PC += ((address)(GetMemory(0xFFFF)) << 8); } - -#ifdef ILLEGAL_INSTRUCTIONS - - -#endif diff --git a/src/cpu/table.c b/src/cpu/table.c index 27ec8f2..ca14c1c 100644 --- a/src/cpu/table.c +++ b/src/cpu/table.c @@ -35,6 +35,7 @@ void CallInstructionTable(int i, address val){ // Perform function func(*r, val); + PC += idata.length; } void SetInstructionTable(int i, uintptr_t p, Addressing r){ @@ -13,7 +13,7 @@ int main() { CallInstructionTable(GetMemory(PC), 0); PrintInfo(); //sleep(3); - getch(); + //getch(); } TerminalClose(); diff --git a/src/video/ncurses.c b/src/video/ncurses.c index c3357c2..e4a7613 100644 --- a/src/video/ncurses.c +++ b/src/video/ncurses.c @@ -18,33 +18,34 @@ WINDOW *AppleWindow; byte UserInput() { int c = getch(); - byte C; + byte r; switch(c) { // Convert special characters case KEY_BACKSPACE: - C = 0xDF; + r = 0xDF; case KEY_ENTER: - C = 0x8D; + r = 0x8D; case KEY_EXIT: //TODO: Figure out if this is Esc or not. - C = 0x9B; + r = 0x9B; // Convert regular characters default: if (c < 0x20 || c >= 0x60) return -1; if (c >= 0x40) - C = c - 0x40; + r = c - 0x40; else - C = c; + r = c; break; } - SetMemory(KBD, C); + SetMemory(KBD, r); + - TerminalInput(c); + TerminalInput(r); return c; @@ -68,6 +69,15 @@ void PrintInfo() getFlag(flag_Z) ? 'Z':'.' , getFlag(flag_C) ? 'C':'.' ); + mvprintw(2, 65, "Stack"); + int count = 3; + for (int i = 0x1ff; i > 0x1cf; i--) { + if (i == (0x1ff-S)) // Indicate the stack pointer! + attron(A_REVERSE); + mvprintw(count, 65, "%x : %x", i, GetMemory(i)); + attroff(A_REVERSE); + count++; + } refresh(); } |