summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2023-11-29 13:32:45 +1100
committeralekseiplusplus <alekseijeaves@protonmail.com>2023-11-29 13:32:45 +1100
commit8d3aaacf14997bbac177ae37ccab4618264cf29c (patch)
tree33cbf86fae08bc1bf97d5d38f1ac2ebebf6e7cd0 /src
parentcbd011fe442dfb520de7b51b61e9c4ef1eacae2f (diff)
work on peripherals and display
Diffstat (limited to 'src')
-rw-r--r--src/Makefile6
-rw-r--r--src/apple.c36
-rw-r--r--src/apple.h7
-rw-r--r--src/cpu/core.h7
-rw-r--r--src/video/interface.h5
-rw-r--r--src/video/ncurses.c49
-rw-r--r--src/video/signetics.c17
7 files changed, 96 insertions, 31 deletions
diff --git a/src/Makefile b/src/Makefile
index 866334d..7ac3085 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,10 +9,10 @@ BUILD_STATIC_LIBRARY = ar -rcs $@ $^
# Executable Targets
default: computer.a video.a
- gcc -o ../build/apple-c -lncurses main.c $^
+ gcc -o ../apple-c -lncurses main.c $^
interpreter: computer.a
- gcc -o ../build/interpreter interpreter.c $^
+ gcc -o ../interpreter interpreter.c $^
@@ -34,4 +34,4 @@ clean:
rm *.a
rm *.o
rm cpu/*.o
- rm video/*.o \ No newline at end of file
+ rm video/*.o
diff --git a/src/apple.c b/src/apple.c
index dae09cc..b9fd6ae 100644
--- a/src/apple.c
+++ b/src/apple.c
@@ -3,19 +3,53 @@
void AppleOn(){
Memory = calloc(MEMORY_SIZE, sizeof(byte));
initInstructionTable();
+
+ // Load ROM
+ FILE *ROM = fopen ("rom.bin", "rb");
+ for (int i = 0; i < 256; i++) {
+ Memory[0xFF00+i] = fgetc(ROM);
+ }
}
void AppleReset(){
acc = 0; X = 0; Y = 0; P = 0; S = 0;
idata.cycles = 0; idata.length = 0; idata.add = 0; idata.value = 0;
+ PC = 0xFF00;
free(Memory);
Memory = calloc(MEMORY_SIZE, sizeof(byte));
}
+byte ToAppleASCII(char x)
+{
+ if (x < 0x20 || x >= 0x60)
+ return -1;
+ if (x >= 0x40)
+ x -= 0x40;
+ return x;
+}
+
+byte ToRegularASCII(char x)
+{
+ if (x < 0x20)
+ x += 0x40;
+ return 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 "accurate" behavior however.
+ case KBD:
+ return 0b10000000 | ToAppleASCII(UserInput());
+ case KBD_CR: case DSP:
+ return 0b10000000;
+ }
+
return Memory[x];
}
void setMemory(address x, byte y){
Memory[x] = y;
-} \ No newline at end of file
+}
diff --git a/src/apple.h b/src/apple.h
index ea1f04e..988a297 100644
--- a/src/apple.h
+++ b/src/apple.h
@@ -2,6 +2,7 @@
#define APPLE_H
#include "cpu/core.h"
+#include <stdio.h>
#include <stdlib.h>
#define MEMORY_SIZE 4096
@@ -21,7 +22,9 @@
#define DSP_CR 0xD013
void AppleOn();
-
void AppleReset();
-#endif \ No newline at end of file
+byte ToAppleAscii(char);
+byte ToRegularAscii(char);
+
+#endif
diff --git a/src/cpu/core.h b/src/cpu/core.h
index b305021..fb6bdf6 100644
--- a/src/cpu/core.h
+++ b/src/cpu/core.h
@@ -49,6 +49,11 @@ struct AddData
}
AddData;
+
+
+// getMemory and setMemory are declared here, but defined in apple.c
+// This is because memory access of particular memory locations is influenced by the Apple I's specific setup, not by the CPU alone.
+
byte getMemory(address x);
void setMemory(address x, byte y);
@@ -57,4 +62,4 @@ extern void *current_instruction;
extern AddData idata;
extern void (*func)(Addressing, address);
-#endif \ No newline at end of file
+#endif
diff --git a/src/video/interface.h b/src/video/interface.h
index 49ac75c..5100032 100644
--- a/src/video/interface.h
+++ b/src/video/interface.h
@@ -1,8 +1,11 @@
// interface.h
// Provides the interface with which all video interactions must occur.
+// Common procedure for taking in user input.
+char UserInput();
+
void TerminalInit();
void TerminalClose();
-void TerminalInput(char n); \ No newline at end of file
+void TerminalInput(char n);
diff --git a/src/video/ncurses.c b/src/video/ncurses.c
index 76bfb26..380c57a 100644
--- a/src/video/ncurses.c
+++ b/src/video/ncurses.c
@@ -10,28 +10,64 @@
int TermX = 0;
int TermY = 0;
+WINDOW *AppleWindow;
+
+
+char UserInput()
+{
+ return getch();
+}
+
+
+
void TerminalInit()
{
initscr();
cbreak();
noecho();
curs_set(0);
+ keypad(stdscr, TRUE);
+
+ AppleWindow = newwin(24, 40, 1, 1);
+
+ // Draw the border.
+ attron(A_REVERSE);
+ move(0, 0);
+ printw(" ");
+ for (int i = 1; i <= 24; i++)
+ {
+ mvaddch(i, 0, ' ');
+ mvaddch(i, 41, ' ');
+ }
+ mvprintw(25, 0, " ~ ");
+ mvprintw(26, 0, " Alekseis Apple I ");
+ mvprintw(27, 0, " ");
+ attroff(A_REVERSE);
+
+
+ mvwaddch(AppleWindow, TermY, TermX, '@' | A_BLINK);
TerminalShiftRegister = (byte*)malloc(960);
TerminalShiftRegisterPosition = TerminalShiftRegister;
TerminalShiftRegisterOffset = 0;
+
+ refresh();
}
+
+
+
void TerminalClose()
{
free(TerminalShiftRegister);
- curs_set(0);
+ curs_set(1);
endwin();
}
+// Takes an an Apple I ASCII character.
void TerminalInput(char n)
{
- mvaddch(TermY,TermX,n);
+ mvwaddch(AppleWindow, TermY,TermX,n);
*TerminalShiftRegisterPosition = n;
TerminalShiftRegisterPosition++;
@@ -64,7 +100,7 @@ void TerminalInput(char n)
if (offset >= (TerminalShiftRegister + 960))
offset -= 960;
- mvaddch(i,j, *(offset));
+ mvwaddch(AppleWindow, i, j, *(offset));
offset++;
}}
@@ -72,8 +108,9 @@ void TerminalInput(char n)
TermX = 0;
// Clear bottom line.
- mvwprintw(stdscr, TermY, TermX, " ");
+ mvwprintw(AppleWindow, TermY, TermX, " ");
}
- mvaddch(TermY, TermX, '@' | A_BLINK);
-} \ No newline at end of file
+ mvwaddch(AppleWindow, TermY, TermX, '@' | A_BLINK);
+ wrefresh(AppleWindow);
+}
diff --git a/src/video/signetics.c b/src/video/signetics.c
index c6dca10..4a996d8 100644
--- a/src/video/signetics.c
+++ b/src/video/signetics.c
@@ -16,20 +16,3 @@ const byte* TerminalShiftRegister;
byte* TerminalShiftRegisterPosition;
int TerminalShiftRegisterOffset;
-
-byte ToAppleASCII(char x)
-{
- if (x < 0x20 || x >= 0x60)
- return -1;
- if (x >= 0x40)
- x -= 0x40;
- return x;
-}
-
-byte ToRegularASCII(char x)
-{
- if (x < 0x20)
- x += 0x40;
- return x;
-}
-