diff options
author | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
---|---|---|
committer | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
commit | ae2cdd83ba4a0cae161db0b29031d5591005fa34 (patch) | |
tree | 82fbdfcbb1fe4e3b5e232db195c8c331d69489fd /user/apple.c | |
parent | Started writing fat.c (diff) | |
parent | fs header changes (diff) | |
download | comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.gz comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.bz2 comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.zip |
Merge branch 'main' of https://github.com/kenshineto/kern into fat32
Merging main into here
Diffstat (limited to 'user/apple.c')
-rw-r--r-- | user/apple.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/user/apple.c b/user/apple.c new file mode 100644 index 0000000..a0a7e9a --- /dev/null +++ b/user/apple.c @@ -0,0 +1,79 @@ + +#include <incbin.h> +#include <stdio.h> +#include <unistd.h> + +INCBIN(APPLE, "data/apple.bin"); + +#define APPLE_WIDTH 256 +#define APPLE_HEIGHT 144 +#define APPLE_FPS 12 +#define APPLE_FRAMES 2630 + +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +// returned from drm +static uint32_t *fb; +static int width, height, bpp, scale; + +// meta +static size_t frame = 0; +static size_t frame_size; +static size_t ticks_off; + +#define PIXEL(x, y) \ + gAPPLEData[offset + \ + (((x + APPLE_WIDTH % APPLE_WIDTH) / scale) + \ + ((y + APPLE_HEIGHT % APPLE_HEIGHT) / scale) * APPLE_WIDTH)] + +static void draw_frame(void) +{ + size_t offset = frame_size * frame; + + for (int y = 0; y < APPLE_HEIGHT * scale; y++) { + for (int x = 0; x < APPLE_WIDTH * scale; x++) { + uint8_t colors[9]; + colors[0] = PIXEL(x, y); + colors[1] = PIXEL(x - 1, y); + colors[2] = PIXEL(x + 1, y); + colors[3] = PIXEL(x, y - 1); + colors[4] = PIXEL(x - 1, y - 1); + colors[5] = PIXEL(x + 1, y - 1); + colors[6] = PIXEL(x, y + 1); + colors[7] = PIXEL(x - 1, y + 1); + colors[8] = PIXEL(x + 1, y + 1); + + // anti aliasing + uint8_t color = (colors[0] + colors[0] + colors[0] + colors[0] + + colors[1] + colors[2] + colors[3] + colors[4] + + colors[5] + colors[6] + colors[7] + colors[8]) / + 12; + + fb[x + y * width] = (color << 16) | (color << 8) | (color << 0); + } + } + + frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)); + + if (frame >= APPLE_FRAMES) + exit(0); +} + +int main(void) +{ + printf("all your apple belong to bad\n"); + + if (drm((void **)&fb, &width, &height, &bpp)) { + fprintf(stderr, "failure!\n"); + return 1; + } + + ticks_off = ticks(); + frame_size = APPLE_WIDTH * APPLE_HEIGHT; + scale = MIN(width / APPLE_WIDTH, height / APPLE_HEIGHT); + + while (1) + draw_frame(); + + return 0; +} |