summaryrefslogtreecommitdiff
path: root/piboot.c
diff options
context:
space:
mode:
Diffstat (limited to 'piboot.c')
-rw-r--r--piboot.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/piboot.c b/piboot.c
new file mode 100644
index 0000000..0aa6326
--- /dev/null
+++ b/piboot.c
@@ -0,0 +1,58 @@
+/*
+ piboot
+ Copyright 2025 metamuffin <metamuffin.org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ char *fbpath = "/dev/fb0";
+ if (argc >= 2)
+ fbpath = argv[1];
+ int fd = open(fbpath, O_CLOEXEC | O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "cannot open fb0: %s\n", strerror(errno));
+ return 1;
+ }
+
+ int w = 1920, h = 1080;
+ int sidepad = (w - h) / 2;
+ uint8_t *frame = malloc(w * h * 4);
+ memset(frame, 0, w * h * 4);
+
+ for (int y = 0; y < h; y++)
+ for (int x = 0; x < w; x++) {
+ if (x < sidepad || x >= h + sidepad)
+ continue;
+ int base = (x + y * w) * 4;
+ int u = (x - sidepad) * 256 / h, v = y * 256 / h;
+ frame[base + 0] = v;
+ frame[base + 1] = u;
+ frame[base + 2] = 255 - v;
+ }
+
+ int res = write(fd, frame, w * h * 4);
+ if (res < 0) {
+ fprintf(stderr, "cannot write to fb0: %s\n", strerror(errno));
+ return 1;
+ }
+
+ return 0;
+}