aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-08-29 12:25:49 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-08-29 12:26:01 +0100
commitfac35c2ba1dbc9fbf4e4d2e499bb23586cc19c41 (patch)
tree86c5f73e35155902f8e78c3d43101a3eb4afa944
parent9a75f5b9f691117df12cdf1893e17dcbe09fddeb (diff)
downloaduboxlib-dos-fac35c2ba1dbc9fbf4e4d2e499bb23586cc19c41.tar.gz
uboxlib-dos-fac35c2ba1dbc9fbf4e4d2e499bb23586cc19c41.zip
Add basic bitmap font rendering
-rw-r--r--include/ubox.h1
-rw-r--r--include/ubox_text.h7
-rw-r--r--src/text.c21
3 files changed, 29 insertions, 0 deletions
diff --git a/include/ubox.h b/include/ubox.h
index cbf8d98..25d44eb 100644
--- a/include/ubox.h
+++ b/include/ubox.h
@@ -9,6 +9,7 @@
#include "ubox_joy.h"
#include "ubox_control.h"
#include "ubox_sound.h"
+#include "ubox_text.h"
#include "ubox_assets.h"
#endif /* _UBOX_H */
diff --git a/include/ubox_text.h b/include/ubox_text.h
new file mode 100644
index 0000000..49fef56
--- /dev/null
+++ b/include/ubox_text.h
@@ -0,0 +1,7 @@
+#ifndef _UBOX_TEXT_H
+#define _UBOX_TEXT_H
+
+void ubox_set_font(const uint8_t *pixdata);
+void ubox_put_text(uint16_t x, uint16_t y, const char *text, uint8_t color);
+
+#endif /* _TEXT_H */
diff --git a/src/text.c b/src/text.c
new file mode 100644
index 0000000..6cec4ad
--- /dev/null
+++ b/src/text.c
@@ -0,0 +1,21 @@
+#include <stdint.h>
+
+#include "ubox_vga.h"
+
+static const uint8_t *font;
+
+void ubox_set_font(const uint8_t *pixdata)
+{
+ font = pixdata;
+}
+
+void ubox_put_text(uint16_t x, uint16_t y, const char *text, uint8_t color)
+{
+ ubox_rect dst = { x, y, 8, 8};
+
+ while (*text)
+ {
+ ubox_blit_c(font + ((*text++ - ' ') << 6), &dst, color);
+ dst.x += 8;
+ }
+}