From f844536c0a3a4ba397f586897482dcb0f7550f5b Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Mon, 8 May 2023 19:29:52 +1000 Subject: started graphical application, plus other stuff --- src/cpu/6502.h | 9 ++++++-- src/debug.h | 4 ++-- src/include.h | 7 +++++- src/main.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/signetics.h | 2 ++ 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/main.c create mode 100644 src/signetics.h (limited to 'src') diff --git a/src/cpu/6502.h b/src/cpu/6502.h index 8ceba29..66526fd 100644 --- a/src/cpu/6502.h +++ b/src/cpu/6502.h @@ -1,14 +1,15 @@ // 6502.h // Core elements of the 6502 CPU -typedef unsigned char\ +typedef unsigned char byte; -typedef unsigned short\ +typedef unsigned short address; byte acc, X, Y, P, S = 0x00; address PC = 0x0000; byte* Memory; +byte* ROM; // FLAGS #define flag_N 0x80 // Negative @@ -98,6 +99,10 @@ void setMemory(address x, byte y); + + + + #include"addressing.h" #include"instructions/definitions.h" #include"instructions/table.h" \ No newline at end of file diff --git a/src/debug.h b/src/debug.h index 06d4733..850b2d0 100644 --- a/src/debug.h +++ b/src/debug.h @@ -38,7 +38,7 @@ printf("\ \t....X:\t%x\tlength:\t%d\n\ \t....Y:\t%x\t...add:\t%x\n\ \tstack:\t%x\t.value:\t%x\n\ -\tflags:\t%x\n\ +\tflags:\t%x\t....PC:\t%x\n\ \n\ -", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P); +", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P, PC); } diff --git a/src/include.h b/src/include.h index 815bbf7..f266ca6 100644 --- a/src/include.h +++ b/src/include.h @@ -3,4 +3,9 @@ #include"stdlib.h" #include"string.h" #include"cpu/6502.h" -#include"apple.h" \ No newline at end of file +#include"apple.h" + +#ifdef GRAPHICAL +#include"SDL2/SDL.h" +#include"signetics.h" +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..dd7f306 --- /dev/null +++ b/src/main.c @@ -0,0 +1,68 @@ +#include"include.h" + + +#define SCALE 2 + +#define CHR_WIDTH 5 +#define CHR_HEIGHT 8 + +#define WIDTH_SPACE 1 + +#define MIN_WIDTH (40 * CHR_WIDTH) +#define MIN_HEIGHT (24 * CHR_HEIGHT) + +int main(){ + // INITIALIZATION + SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); + SDL_Window* window = SDL_CreateWindow( + "Apple C", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 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_FreeSurface(font_surface); + + SDL_Rect character = { + .x = 0, + .y = 0, + .w = CHR_WIDTH, + .h = CHR_HEIGHT + }; + + SDL_Rect draw_character = { + .x = 0, + .y = 0, + .w = CHR_WIDTH * SCALE, + .h = CHR_HEIGHT * SCALE + }; + + SDL_SetRenderDrawColor (render, 0, 0, 0, 255); + SDL_RenderClear (render); + + for(int i = 0; i < 500; i++){ + + SDL_RenderCopy (render, font_texture, &character, &draw_character); + SDL_RenderPresent (render); + + + character.x = (i % 0x10) * CHR_WIDTH; + draw_character.x += draw_character.w; + if(i % 2 == 1) draw_character.y += draw_character.h; + if(draw_character.x > MIN_WIDTH*SCALE) draw_character.x -= MIN_WIDTH*SCALE; + if(draw_character.y > MIN_HEIGHT*SCALE) draw_character.y -= MIN_HEIGHT*SCALE; + SDL_Delay(40); + } + + + + // Just delay before it dies + //SDL_Delay(5000); + + SDL_Quit(); + return 0; +} \ No newline at end of file diff --git a/src/signetics.h b/src/signetics.h new file mode 100644 index 0000000..228aa85 --- /dev/null +++ b/src/signetics.h @@ -0,0 +1,2 @@ +// signetics.h +// The Apple I came with its own terminal on-board, with a Signetics 2513 character ROM. -- cgit v1.2.3