sandyx 2 years ago
parent c583153df9
commit 2222e7db41

@ -0,0 +1,20 @@
//cpu.c
#include <inttypes.h>
//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

@ -0,0 +1,91 @@
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <raylib.h>
#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;
}
Loading…
Cancel
Save