From 2ded6baaab3946e461a7cf0b39618b31e5806c89 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Tue, 28 Nov 2023 02:51:33 +1100 Subject: days end --- src/Makefile | 24 ++++++++++-------------- src/apple.c | 9 --------- src/apple.h | 6 +----- src/main.c | 8 +++++++- src/signetics.h | 34 ---------------------------------- src/video/interface.h | 8 +++++--- src/video/ncurses.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/video/sdl.c | 39 +++++++++++++++++++-------------------- src/video/signetics.c | 32 ++++++++++++++++++++++++++++++++ 9 files changed, 114 insertions(+), 87 deletions(-) delete mode 100644 src/signetics.h create mode 100644 src/video/signetics.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 710df5a..866334d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,37 +1,33 @@ SDL = -L/usr/lib -lSDL2 -MAIN_COMPONENTS = cpu.a video.a apple.a +OBJECTS_CPU = cpu/6502.o cpu/addressing.o cpu/instructions.o cpu/table.o + +BUILD_STATIC_LIBRARY = ar -rcs $@ $^ -TARGET_CPU = cpu/6502.o cpu/addressing.o cpu/instructions.o cpu/table.o -TARGET_VIDEO = video/ncurses.o # Executable Targets -default: cpu.a apple.a - gcc -o ../build/apple-c main.c $^ +default: computer.a video.a + gcc -o ../build/apple-c -lncurses main.c $^ -interpreter: cpu.a apple.a +interpreter: computer.a gcc -o ../build/interpreter interpreter.c $^ # Internal Libraries -cpu.a: $(TARGET_CPU) - ar cr $@ $^ - -video.a: $(TARGET_VIDEO) - ar cr $@ $^ +computer.a: $(OBJECTS_CPU) apple.o + $(BUILD_STATIC_LIBRARY) -apple.a: apple.o $(TARGET_CPU) $(TARGET_VIDEO) - ar -rcs $@ $^ +video.a: video/ncurses.o + $(BUILD_STATIC_LIBRARY) *.o: *.c gcc -c $^ - # Clean clean: diff --git a/src/apple.c b/src/apple.c index 3e3b928..dae09cc 100644 --- a/src/apple.c +++ b/src/apple.c @@ -1,14 +1,5 @@ #include"apple.h" -extern byte acc; -extern byte X; -extern byte Y; -extern byte P; -extern byte S; -extern address PC; -extern byte* Memory; -extern byte* ROM; - void AppleOn(){ Memory = calloc(MEMORY_SIZE, sizeof(byte)); initInstructionTable(); diff --git a/src/apple.h b/src/apple.h index a1d527d..64542de 100644 --- a/src/apple.h +++ b/src/apple.h @@ -1,11 +1,7 @@ #ifndef APPLE_H #define APPLE_H -#include"cpu/6502.h" -#include"cpu/addressing.h" -#include"cpu/core.h" -#include"cpu/instructions.h" -#include"cpu/table.h" +#include "cpu/core.h" #define MEMORY_SIZE 4096 diff --git a/src/main.c b/src/main.c index f640bc1..5e7bfa2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,10 +1,16 @@ #include "apple.h" +#include "video/interface.h" int main() { - //VideoInit(); + TerminalInit(); AppleOn(); + TerminalPrompt(); + getch(); + + TerminalClose(); + return 0; } \ No newline at end of file diff --git a/src/signetics.h b/src/signetics.h deleted file mode 100644 index 45f9a3a..0000000 --- a/src/signetics.h +++ /dev/null @@ -1,34 +0,0 @@ -// signetics.h -// The Apple I came with its own terminal on-board, with a Signetics 2513 character ROM. -#include"cpu/core.h" -#include"stdlib.h" - -const byte CharacterROM[0x40] = { - '@' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , - 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , '[' , '\\', ']' , '^' , '_' , - ' ' , '!' , '"' , '#' , '$' , '%' , '&' , '\'', '(' , ')' , '*' , '+' , ',' , '-' , '.' , '/' , - '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ':' , ';' , '<' , '=' , '>' , '?' -}; - -byte* TerminalShiftRegister; - -int TerminalShiftRegisterOffset = 0; - -void InitSignetics(){ - TerminalShiftRegister = (byte*)malloc(1024); //maybe 960 -} - -byte ToAppleASCII(char x){ - if (x < 32 || x > 95) - return -1; - if (x >= 64) - x -= 64; - return x; -} - -byte ToRegularASCII(char x){ - if (x < 32) - x += 64; - return x; -} - diff --git a/src/video/interface.h b/src/video/interface.h index 0167037..db9bd54 100644 --- a/src/video/interface.h +++ b/src/video/interface.h @@ -1,8 +1,10 @@ // interface.h // Provides the interface with which all video interactions must occur. -void VideoInit(); +void TerminalInit(); -void VideoClose(); +void TerminalClose(); -void DisplayCharacter(char In); \ No newline at end of file +void TerminalInput(char n); + +void TerminalPrompt(); \ No newline at end of file diff --git a/src/video/ncurses.c b/src/video/ncurses.c index a9221e1..05653e2 100644 --- a/src/video/ncurses.c +++ b/src/video/ncurses.c @@ -2,4 +2,43 @@ // Implements interface.h // Provides an in-terminal interface to the emulator. -#include"interface.h" \ No newline at end of file +#include"interface.h" +#include"signetics.c" +#include + + +int TermX = 0; +int TermY = 0; + +void TerminalInit() +{ + initscr(); + cbreak(); + noecho(); + + TerminalShiftRegister = (byte*)malloc(960); + TerminalShiftRegisterOffset = 0; +} + +void TerminalClose() +{ + free(TerminalShiftRegister); + endwin(); +} + +void TerminalInput() +{ + if (TermX >= 40) { + TermX = 0; + TermY++; + } + + if (TermY >= 24) { + + } +} + +void TerminalPrompt() +{ + addch('@' | A_BLINK); +} \ No newline at end of file diff --git a/src/video/sdl.c b/src/video/sdl.c index 811b0d3..7161a08 100644 --- a/src/video/sdl.c +++ b/src/video/sdl.c @@ -5,34 +5,35 @@ #include"interface.h" #include -#define SCALE 2 +#define SCALE 2 -#define CHR_WIDTH 5 -#define CHR_HEIGHT 8 +#define CHR_WIDTH 5 +#define CHR_HEIGHT 8 #define WIDTH_SPACE 1 * SCALE -#define MIN_WIDTH (40 * CHR_WIDTH) + 39*WIDTH_SPACE -#define MIN_HEIGHT (24 * CHR_HEIGHT) +#define MIN_WIDTH (40 * CHR_WIDTH) + 39*WIDTH_SPACE +#define MIN_HEIGHT (24 * CHR_HEIGHT) -int VideoInit(){ +int TerminalInit(){ // INITIALIZATION SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); - SDL_Window* window = SDL_CreateWindow( + + SDL_Window* window = SDL_CreateWindow( "Apple C", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - MIN_WIDTH * SCALE, - MIN_HEIGHT * SCALE, + MIN_WIDTH * SCALE, + MIN_HEIGHT * SCALE, SDL_WINDOW_SHOWN ); - SDL_Renderer* render = SDL_CreateRenderer(window, -1, 0); - SDL_Surface* font_surface = SDL_LoadBMP("font.bmp"); - SDL_Texture* font_texture = SDL_CreateTextureFromSurface(render, font_surface); + SDL_Renderer* render = SDL_CreateRenderer(window, -1, 0); + SDL_Surface* font_surface = SDL_LoadBMP("font.bmp"); + SDL_Texture* font_texture = SDL_CreateTextureFromSurface(render, font_surface); SDL_FreeSurface(font_surface); - SDL_Rect character = { + SDL_Rect character = { .x = 0, .y = 0, .w = CHR_WIDTH, @@ -46,15 +47,13 @@ int VideoInit(){ .h = CHR_HEIGHT * SCALE }; - SDL_SetRenderDrawColor (render, 0, 0, 0, 255); - SDL_RenderClear (render); - SDL_RenderCopy (render, font_texture, &character, &draw_character); - SDL_RenderPresent (render); + SDL_SetRenderDrawColor (render, 0, 0, 0, 255); + SDL_RenderClear (render); + SDL_RenderCopy (render, font_texture, &character, &draw_character); + SDL_RenderPresent (render); } -void VideoClose() { - - +void TerminalClose() { SDL_Quit(); } \ No newline at end of file diff --git a/src/video/signetics.c b/src/video/signetics.c new file mode 100644 index 0000000..944ac4d --- /dev/null +++ b/src/video/signetics.c @@ -0,0 +1,32 @@ +// signetics.h +// The Apple I came with its own terminal on-board, with a Signetics 2513 character ROM, and multiple shift registers acting as video memory. +#include"cpu/core.h" +#include"stdlib.h" + +const byte CharacterROM[0x40] = { + '@' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , + 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , '[' , '\\', ']' , '^' , '_' , + ' ' , '!' , '"' , '#' , '$' , '%' , '&' , '\'', '(' , ')' , '*' , '+' , ',' , '-' , '.' , '/' , + '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ':' , ';' , '<' , '=' , '>' , '?' +}; + +byte* TerminalShiftRegister; + +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; +} + -- cgit v1.2.3