From 2222e7db41f909b308a0e2d3d290ef433929bd3e Mon Sep 17 00:00:00 2001 From: sandyx Date: Sun, 16 Jun 2024 09:25:19 -0500 Subject: [PATCH] cpu --- src/cpu.c | 20 ++++++++++++ src/main.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/cpu.c create mode 100644 src/main.c diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..775b167 --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,20 @@ +//cpu.c +#include + +//the idea of this being its own file is that you can +//swap in and out different cpus + +/* + general purpose registers start with "r" + kinda like powerpc +*/ + +typedef struct _cpu { + uint8_t r0, r1, r2, r3, r4, r5; + uint8_t sp, bp; + uint8_t flags; +} cpu; + +//public + +//private diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..470cf86 --- /dev/null +++ b/src/main.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#define overload _Generic + +#define WIDTH 640 +#define HEIGHT 480 +#define VMEM WIDTH * HEIGHT + +Color video_memory[VMEM] = {}; +Image charset[26]; + +void draw_frame() { + for (int i = 0; i < WIDTH; i++) { + for (int j = 0; j < HEIGHT; j++) { + DrawPixel(i, j, video_memory[i + (j * WIDTH)]); + } + } +} + +void red_line(Color *vmem) { + static int i = 0; + for (; i < 70; i++) { + video_memory[i] = RED; + } +} + +void write_image(Color *vmem, Image image, uint32_t x, uint32_t y) { + for (int i = 0; i < 16; i++) { + int image_size = image.width * sizeof(uint32_t); //16 pixels, 4 bytes per pixel + memcpy(vmem + (i * WIDTH) + (y * WIDTH * 16) + (x * 16), &image.data[i * image_size], image_size); + } +} + +void load_charset() { + char filenames[][26] = { + "resources/A.png", + "resources/B.png", + "resources/C.png", + "resources/D.png", + "resources/E.png", + "resources/F.png", + "resources/G.png", + "resources/H.png", + "resources/I.png", + "resources/J.png", + "resources/K.png", + "resources/L.png", + "resources/M.png", + "resources/N.png", + "resources/O.png", + "resources/P.png", + "resources/Q.png", + "resources/R.png", + "resources/S.png", + "resources/T.png", + "resources/U.png", + "resources/V.png", + "resources/W.png", + "resources/X.png", + "resources/Y.png", + "resources/Z.png" + }; + + for (int i = 0; i < 26; i++) { + charset[i] = LoadImage(filenames[i]); + } +} + +int main(void) { + InitWindow(WIDTH, HEIGHT, "Computer :3"); + SetTargetFPS(60); + + load_charset(); + + int i = 0; + + while (!WindowShouldClose()) { + BeginDrawing(); + ClearBackground(BLUE); + + draw_frame(); + write_image(&video_memory, charset[i++ % 26], 0, 0); + + EndDrawing(); + } + + return 0; +} \ No newline at end of file