From 791390dd7ddd79a06eff6766d857d2744c012d75 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 27 Apr 2025 15:40:13 -0400 Subject: 🍎 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/apple.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 user/apple.c (limited to 'user/apple.c') diff --git a/user/apple.c b/user/apple.c new file mode 100644 index 0000000..d0a5cc4 --- /dev/null +++ b/user/apple.c @@ -0,0 +1,56 @@ + +#include +#include +#include + +INCBIN(APPLE, "data/apple.bin"); + +#define APPLE_WIDTH 256 +#define APPLE_HEIGHT 144 +#define APPLE_FPS 12 +#define APPLE_FRAMES 5259 + +#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; + +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 color = + gAPPLEData[offset + ((x / scale) + (y / scale) * APPLE_WIDTH)]; + fb[x + y * width] = (color << 16) | (color << 8) | (color << 0); + } + } + + frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)) % APPLE_FRAMES; +} + +int main(void) +{ + printf("all your apple belong to bad\n"); + + if (drm((void **)&fb, &width, &height, &bpp)) { + printf("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; +} -- cgit v1.2.3-freya From 91fb39db553dea9d07bb124f38c83460abc48d21 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 27 Apr 2025 16:11:54 -0400 Subject: fmt --- kernel/drivers/ata.c | 3 +-- kernel/include/comus/asm.h | 5 ++++- kernel/syscall.c | 6 ++---- user/apple.c | 7 +++++-- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'user/apple.c') diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index 022ec81..6c8de86 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -569,8 +569,7 @@ static enum ide_error ide_device_ata_access(struct ide_device *dev, ide_channel_write(chan, ATA_REG_HDDEVSEL, 0xE0 | (dev->drive_idx << 4) | head); } else { - ide_channel_write(chan, ATA_REG_HDDEVSEL, - 0x40 | (dev->drive_idx << 4)); + ide_channel_write(chan, ATA_REG_HDDEVSEL, 0x40 | (dev->drive_idx << 4)); } // write Parameters diff --git a/kernel/include/comus/asm.h b/kernel/include/comus/asm.h index a6a8a45..4f376b1 100644 --- a/kernel/include/comus/asm.h +++ b/kernel/include/comus/asm.h @@ -36,7 +36,10 @@ static inline uint16_t inw(uint16_t port) static inline void rep_inw(uint16_t port, uint16_t *buffer, size_t count) { - __asm__ volatile("rep insw" : "+D"(buffer), "+c"(count) : "d"(port) : "memory"); + __asm__ volatile("rep insw" + : "+D"(buffer), "+c"(count) + : "d"(port) + : "memory"); } static inline void outw(uint16_t port, uint16_t val) diff --git a/kernel/syscall.c b/kernel/syscall.c index 7a57353..11db5e5 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -13,8 +13,7 @@ #define ARG3(type, name) type name = (type)(current_pcb->regs->rdx) #define ARG4(type, name) type name = (type)(current_pcb->regs->rcx) -__attribute__((noreturn)) -static int sys_exit(void) +__attribute__((noreturn)) static int sys_exit(void) { ARG1(int, status); @@ -57,8 +56,7 @@ static int sys_write(void) return nbytes; } -__attribute__((noreturn)) -static int sys_poweroff(void) +__attribute__((noreturn)) static int sys_poweroff(void) { // TODO: we should probably // kill all user processes diff --git a/user/apple.c b/user/apple.c index d0a5cc4..000718c 100644 --- a/user/apple.c +++ b/user/apple.c @@ -8,7 +8,7 @@ INCBIN(APPLE, "data/apple.bin"); #define APPLE_WIDTH 256 #define APPLE_HEIGHT 144 #define APPLE_FPS 12 -#define APPLE_FRAMES 5259 +#define APPLE_FRAMES 2630 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -33,7 +33,10 @@ static void draw_frame(void) } } - frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)) % APPLE_FRAMES; + frame = ((ticks() - ticks_off) / (1000 / APPLE_FPS)); + + if (frame >= APPLE_FRAMES) + exit(0); } int main(void) -- cgit v1.2.3-freya From 55beb3f2985c9fda15f015320d1b9c723c97fbe0 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 28 Apr 2025 11:07:15 -0400 Subject: add stderr --- user/apple.c | 2 +- user/include/stdio.h | 2 ++ user/lib/fwrite.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'user/apple.c') diff --git a/user/apple.c b/user/apple.c index 000718c..5adafe8 100644 --- a/user/apple.c +++ b/user/apple.c @@ -44,7 +44,7 @@ int main(void) printf("all your apple belong to bad\n"); if (drm((void **)&fb, &width, &height, &bpp)) { - printf("failure!\n"); + fprintf(stderr, "failure!\n"); return 1; } diff --git a/user/include/stdio.h b/user/include/stdio.h index 2e2abf4..fe29c9d 100644 --- a/user/include/stdio.h +++ b/user/include/stdio.h @@ -23,8 +23,10 @@ typedef void FILE; extern FILE *stdin; extern FILE *stdout; +extern FILE *stderr; #define stdin stdin #define stdout stdout +#define stderr stderr /** * Get a char from stdin diff --git a/user/lib/fwrite.c b/user/lib/fwrite.c index aa828e0..515d4ff 100644 --- a/user/lib/fwrite.c +++ b/user/lib/fwrite.c @@ -2,6 +2,7 @@ #include FILE *stdout = (void *)1; +FILE *stderr = (void *)2; int putchar(int c) { -- cgit v1.2.3-freya From dce1a7d3f2f49431888c14940c73b7c204d322d5 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 28 Apr 2025 11:43:24 -0400 Subject: anti aliasing :3 --- user/apple.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'user/apple.c') diff --git a/user/apple.c b/user/apple.c index 5adafe8..a0a7e9a 100644 --- a/user/apple.c +++ b/user/apple.c @@ -21,14 +21,34 @@ 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 color = - gAPPLEData[offset + ((x / scale) + (y / scale) * APPLE_WIDTH)]; + 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); } } -- cgit v1.2.3-freya