summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-11-30 14:36:15 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-11-30 14:36:15 +1100
commitd0f5e175f713a52d76d102780e0b899f3984c416 (patch)
treecfb4b030b186bf3dd4a155a78a9b232e4d971139 /src
parent401a2171b1fa2bcc077934191cc609208368152e (diff)
overall progress
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/apple.c9
-rw-r--r--src/cpu/core.h4
-rw-r--r--src/cpu/table.c10
-rw-r--r--src/interpreter.c2
-rw-r--r--src/main.c5
-rw-r--r--src/video/interface.h3
-rw-r--r--src/video/ncurses.c63
8 files changed, 72 insertions, 26 deletions
diff --git a/src/Makefile b/src/Makefile
index 8762231..d12972c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,7 +9,7 @@ BUILD_STATIC_LIBRARY = ar -rcs $@ $^
# Executable Targets
default: computer.a video.a
- gcc -o ../apple-c -lncurses main.c $^
+ gcc -g -o ../apple-c -lncurses main.c $^
interpreter: computer.a video.a
gcc -o ../interpreter -lncurses interpreter.c $^
diff --git a/src/apple.c b/src/apple.c
index 201239a..fbb85f7 100644
--- a/src/apple.c
+++ b/src/apple.c
@@ -1,6 +1,6 @@
#include"apple.h"
-const byte ROM = {
+const byte ROM[256] = {
0xd8, 0x58, 0xa0, 0x7f, 0x8c, 0x12, 0xd0, 0xa9,
0xa7, 0x8d, 0x11, 0xd0, 0x8d, 0x13, 0xd0, 0xc9,
0xdf, 0xf0, 0x13, 0xc9, 0x9b, 0xf0, 0x03, 0xc8,
@@ -37,7 +37,7 @@ const byte ROM = {
void AppleOn() {
Memory = calloc(MEMORY_SIZE, sizeof(byte));
- ROM = calloc(256, sizeof(byte));
+ //ROM = calloc(256, sizeof(byte));
InitInstructionTable();
// Load ROM (alternative)
@@ -92,6 +92,11 @@ byte GetMemory(address x){
if (x >= 0xFF00 && x <= 0xFFFF) {
return ROM[0x00FF & x];
}
+
+ if (x < MEMORY_SIZE)
+ return Memory[x];
+
+ return -1;
}
void SetMemory(address x, byte y){
diff --git a/src/cpu/core.h b/src/cpu/core.h
index 850f04b..5a73818 100644
--- a/src/cpu/core.h
+++ b/src/cpu/core.h
@@ -15,7 +15,7 @@ extern byte P;
extern byte S;
extern address PC;
extern byte* Memory;
-extern byte* ROM;
+extern const byte ROM[];
enum Addressing
@@ -58,4 +58,4 @@ void SetMemory(address x, byte y);
extern void *current_instruction;
extern AddData idata;
-extern void (*func)(Addressing, address); \ No newline at end of file
+extern void (*func)(Addressing, address);
diff --git a/src/cpu/table.c b/src/cpu/table.c
index 7ec0891..0af04f9 100644
--- a/src/cpu/table.c
+++ b/src/cpu/table.c
@@ -18,10 +18,20 @@ Addressing* GetInstructionTableAddressing(int i){
}
void CallInstructionTable(int i, address val){
+ val = 0; // TODO: Let the initial value of val be redundant for now so as to not break anything, but fix later
+ // Setup to call the correct function.
uintptr_t a = GetInstructionTableFunction(i);
memcpy(&func, a, sizeof(uintptr_t));
+ // Find the correct addressing mode.
Addressing* r = (InstructionTable + ((sizeof(uintptr_t)*256) + (sizeof(Addressing) * i)));
+ // Set idata
idata = fAddress(*r, val);
+ // Set val
+ if (idata.length > 0)
+ val += GetMemory(PC+1);
+ if (idata.length > 1)
+ val += GetMemory(PC+2) << 8;
+ // Perform function
func(*r, val);
}
diff --git a/src/interpreter.c b/src/interpreter.c
index d243e67..6dc7178 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -53,7 +53,7 @@ int main(int argc, char *argv[]){
x <<= 8;
x += dCharToNum(c) << 4;
x += dCharToNum(getc(stdin));
- printf("@%04x:%02x\n", x, Memory[x]);
+ printf("@%04x:%02x\n", x, GetMemory(x));
}
else{
printf("Page %02x", x);
diff --git a/src/main.c b/src/main.c
index ef09933..24ca710 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,7 @@
#include "apple.h"
#include "video/interface.h"
#include <ncurses.h>
+#include <unistd.h>
int main() {
@@ -9,7 +10,9 @@ int main() {
AppleOn();
while(1) {
- TerminalInput( UserInput() );
+ CallInstructionTable(GetMemory(PC), 0);
+ PrintInfo();
+ sleep(1);
}
TerminalClose();
diff --git a/src/video/interface.h b/src/video/interface.h
index 048aa25..2443b62 100644
--- a/src/video/interface.h
+++ b/src/video/interface.h
@@ -9,6 +9,9 @@
// Common procedure for taking in user input.
byte UserInput();
+// Common way to print processor information.
+void PrintInfo();
+
// Initialization procedure for the terminal
void TerminalInit();
diff --git a/src/video/ncurses.c b/src/video/ncurses.c
index d584088..2827ff7 100644
--- a/src/video/ncurses.c
+++ b/src/video/ncurses.c
@@ -6,6 +6,7 @@
#include"interface.h"
#include"signetics.c"
#include"../apple.h"
+#include"../cpu/6502.h"
int TermX = 0;
@@ -17,29 +18,65 @@ WINDOW *AppleWindow;
byte UserInput()
{
int c = getch();
+ byte C;
switch(c)
{
// Convert special characters
case KEY_BACKSPACE:
- return 0xDF;
+ C = 0xDF;
case KEY_ENTER:
- return 0x8D;
+ C = 0x8D;
case KEY_EXIT: //TODO: Figure out if this is Esc or not.
- return 0x9B;
+ C = 0x9B;
// Convert regular characters
default:
if (c < 0x20 || c >= 0x60)
return -1;
+
if (c >= 0x40)
- c -= 0x40;
+ C = c - 0x40;
+ else
+ C = c;
+
break;
}
+ SetMemory(KBD, C);
+
+ TerminalInput(c);
+
+
return c;
}
+#define FlagVisual(x, c) (getFlag(x)) ? c : '.'
+
+void PrintInfo()
+{
+ move(2, 43);
+ printf("acc : %x", acc);
+ move(3, 43);
+ printf(" X : %x", X );
+ move(4, 43);
+ printf(" Y : %x", Y );
+ move(5, 43);
+ printf(" PC : %x", PC);
+ move(6, 43);
+ printf("Flags : %c%c_%c%c%c%c%c",
+ getFlag(flag_N) ? 'N':'.' ,
+ getFlag(flag_V) ? 'V':'.' ,
+ getFlag(flag_B) ? 'B':'.' ,
+ getFlag(flag_D) ? 'D':'.' ,
+ getFlag(flag_I) ? 'I':'.' ,
+ getFlag(flag_Z) ? 'Z':'.' ,
+ getFlag(flag_C) ? 'C':'.'
+ );
+ refresh();
+}
+
+
void TerminalInit()
{
@@ -90,22 +127,10 @@ void TerminalClose()
void TerminalInput(byte n)
-{
- // Handle special characters and conversion.
- switch (n)
- {
- case 0xDF: // Backslash
- case 0x8D: // Enter
- case 0x9B: // Escape
- return;
- default:
- // Convert to ASCII
- if (n < 0x20) n += 0x40;
- }
-
+{
// Place character
mvwaddch(AppleWindow, TermY, TermX, ' ');
- mvwaddch(AppleWindow, TermY, TermX, n);
+ mvwaddch(AppleWindow, TermY, TermX, CharacterROM[n]);
// Add character to register
*TerminalShiftRegisterPosition = n;
@@ -138,7 +163,7 @@ void TerminalInput(byte n)
for (int j = 0; j < 40; j++) {
if (offset >= (TerminalShiftRegister + 960))
offset -= TerminalShiftRegister;
- mvwaddch(AppleWindow, i, j, (*offset < 0x20) ? *offset + 0x40 : *offset );
+ mvwaddch(AppleWindow, i, j, CharacterROM[*offset] );
offset++;
}}