commit 3dcb05e2f4bc5ffc956a473bdb7324762514aa2f
parent 260fe9bf03b2f554a46b5d8f3775c8eb2722b097
Author: Brian Swetland <swetland@frotz.net>
Date: Wed, 11 May 2022 23:25:47 -0700
mandelbrot-fb: use libgfx for drawing
Diffstat:
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/misc/mandelbrot-fb.c b/misc/mandelbrot-fb.c
@@ -7,6 +7,7 @@
#include <hw/debug.h>
#include <hw/platform.h>
#include <hw/litex.h>
+#include <gfx/gfx.h>
#define FB_WIDTH 640
#define FB_HEIGHT 480
@@ -17,14 +18,15 @@ uint16_t colors[12] = {
0x9999, 0xAAAA, 0xBBBB, 0xCCCC,
};
-static inline void plot(unsigned px, unsigned py, unsigned c) {
- ((uint16_t volatile*) FRAMEBUFFER_BASE)[px + py * FB_WIDTH] = c;
-}
-
void start(void) {
xputs("Hello, Mandelbrot!\n");
- memset((void*) FRAMEBUFFER_BASE, 0, 640 * 480 * 2);
+ gfx_surface_t gs;
+ gfx_init_display(&gs);
+
+ memset((void*) gs.pixels, 0, gs.width * gs.height * 2);
+
+ gfx_puts(&gs, 0, gs.height - 17, "Hello, Mandelbrot!");
for (int py = 0; py < FB_HEIGHT; py++) {
int y0 = 1300 - (2600 * py) / FB_HEIGHT;
@@ -35,15 +37,20 @@ void start(void) {
int x2 = x * x / 1000;
int y2 = y * y / 1000;
if ((x2 + y2) > 4000) {
- plot(px, py, colors[(i > 11) ? 11 : i]);
+ gs.fgcolor = colors[(i > 11) ? 11 : i];
+ gfx_plot(&gs, px, py);
goto done;
}
y = 2 * x * y / 1000 + y0;
x = x2 - y2 + x0;
}
- plot(px, py, 0);
+ gs.fgcolor = 0;
+ gfx_plot(&gs, px, py);
done:
;
}
+ gs.fgcolor = 0xFFFF;
}
+
+ gfx_puts(&gs, 0, gs.height - 16, "Hello, Mandelbrot!");
}
diff --git a/project/mandelbrot-fb.app.mk b/project/mandelbrot-fb.app.mk
@@ -3,5 +3,5 @@ MOD_NAME := mandelbrot-fb
MOD_SRC := hw/src/start.S misc/mandelbrot-fb.c
MOD_SRC += hw/src/debug-printf.c hw/src/debug-io.c
MOD_QEMU_FB := 1
-MOD_LIB := c
+MOD_LIB := gfx c
include make/app.mk