aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpk33 <pk33@pk33.space>2024-11-03 22:26:28 +0100
committerpk33 <pk33@pk33.space>2024-11-03 22:26:28 +0100
commit0ffb4f8463e3e06e8d88b7be22f5cb7adb702361 (patch)
tree05e626d6ce4e0d8e544a40f8a14965cf4fdd5780
parent6c69ea8da9d306e4e6d21d0feee5213fea15f49e (diff)
downloadengine33-0ffb4f8463e3e06e8d88b7be22f5cb7adb702361.tar.gz
fonts, text and basic ui for on-screen log
-rw-r--r--README.html5
-rw-r--r--include/options.h6
-rw-r--r--include/strings33.h42
-rw-r--r--include/ui33.h9
-rw-r--r--makefile2
-rw-r--r--src/display.c9
-rw-r--r--src/font33.c116
-rw-r--r--src/logger.c21
-rw-r--r--src/main.c9
-rw-r--r--src/strings33.c78
-rw-r--r--src/ui33.c44
11 files changed, 320 insertions, 21 deletions
diff --git a/README.html b/README.html
index 48773d1..cdb5234 100644
--- a/README.html
+++ b/README.html
@@ -14,14 +14,13 @@
<p>You need a monitor connected to an on-board connector.<br>
Edit options.h.<br>
Run ./bin/engine33 on a TTY.<br>
-Can you see the green pixel on your screen? Well done.</p>
<br><br>
<h3>TODO</h3>
<hr>
<ol>
-<li>Fonts*</li>
-<li></li>
+<li>labeled and coloured on-screen messages</li>
+<li>*draw some graphics</li>
</ol>
<br><br>
diff --git a/include/options.h b/include/options.h
index 2ce1726..418a296 100644
--- a/include/options.h
+++ b/include/options.h
@@ -4,9 +4,9 @@
#define LOG_PATH "/dev/tty3"
-#define DRM_DEVICE "/dev/dri/card1"
-#define DRM_MODE "1366x768"
-#define DRM_RATE 60
+#define DRM_DEVICE "/dev/dri/card0"
+#define DRM_MODE "1024x768"
+#define DRM_RATE 75
#endif /* __OPTIONS_H */
diff --git a/include/strings33.h b/include/strings33.h
new file mode 100644
index 0000000..c987690
--- /dev/null
+++ b/include/strings33.h
@@ -0,0 +1,42 @@
+#ifndef __STRINGS_H__
+#define __STRINGS_H__
+
+#include "types.h"
+#include "display.h"
+#include "system.h"
+
+
+#define E33_MAX_GLYPH_PLOTS 256
+#define E33_MAX_FONT_GLYPHS 256
+
+#define E33_FONT_DEFAULT 0
+#define E33_FONT_BIG 1
+
+#define quprint( s, x, y, str ) e33_uprint( s, E33_FONT_DEFAULT, WHITE, x, y, str );
+#define quprintf( s, x, y, frm, ... ) e33_uprintf( s, E33_FONT_DEFAULT, WHITE, x, y, frm, ##__VA_ARGS__ );
+#define suprint( f, c, x, y, str ) e33_uprint( &__display.surface, f, c, x, y, str );
+#define suprintf( f, c, x, y, frm, ... ) e33_uprintf( &__display.surface, f, c, x, y, frm, ##__VA_ARGS__ );
+#define qsuprint( str, x, y ) e33_uprint( &__display.surface, E33_FONT_DEFAULT, WHITE, x, y, str );
+#define qsuprintf( x, y, frm, ... ) e33_uprintf( &__display.surface, E33_FONT_DEFAULT, WHITE, x, y, frm, ##__VA_ARGS__ )
+
+
+typedef struct {
+ Size num_plots;
+ Size width;
+ u16 plots[ E33_MAX_GLYPH_PLOTS ];
+} FontGlyph33;
+
+typedef struct {
+ Size xShift, yAnd;
+ Size height;
+ Size num_glyphs;
+ Size maxGlyphWidth;
+ FontGlyph33 glyphs[ E33_MAX_FONT_GLYPHS ];
+} Font33;
+
+
+void e33_uprint( Surface *surf, Size font, u32 col, Size x, Size y, String str );
+void e33_uprintf( Surface *surf, Size font, u32 col, Size x, Size y, String fmt, ... );
+
+
+#endif /* __STRING_H__ */
diff --git a/include/ui33.h b/include/ui33.h
new file mode 100644
index 0000000..7aa489c
--- /dev/null
+++ b/include/ui33.h
@@ -0,0 +1,9 @@
+#ifndef __UI_H__
+#define __UI_H__
+
+
+void ui_add_message( String fmt, ... );
+void ui_draw_messages( void );
+
+
+#endif /** UI **/
diff --git a/makefile b/makefile
index d3255f2..36d7c36 100644
--- a/makefile
+++ b/makefile
@@ -1,7 +1,7 @@
CC = clang
PROJECT = engine33
-OBJS = main.o system.o logger.o clock.o display.o
+OBJS = main.o system.o logger.o font33.o strings33.o ui33.o clock.o display.o
PDIR = ./bin
.PATH: ./src
diff --git a/src/display.c b/src/display.c
index 806b78e..bad4d69 100644
--- a/src/display.c
+++ b/src/display.c
@@ -156,6 +156,7 @@ void display_flip( void )
__display.crtc.fb_id = __display.fb.id[i];
if( e33_ioctl( __display.devfd, (int)DRM_IOCTL_MODE_SETCRTC, &__display.crtc ) == -1 ) {
+ logw( "Failed to set CRTC for page flip prep. Skipping" );
return;
}
@@ -164,9 +165,7 @@ void display_flip( void )
flip.user_data = ((__u64)(&__display.crtc.crtc_id));
flip.flags = DRM_MODE_PAGE_FLIP_EVENT;
- if( e33_ioctl( __display.devfd, (int)DRM_IOCTL_MODE_PAGE_FLIP, &flip ) == -1 ) {
- return;
- }
+ e33_ioctl( __display.devfd, (int)DRM_IOCTL_MODE_PAGE_FLIP, &flip );
/* TODO remove later */
memset( __display.surface.data, 0, (uSize)__display.fb.size );
@@ -314,7 +313,7 @@ static Size _get_drm_connector( void )
if( connector->connection == 1 &&
connector->count_modes > 0 &&
- connector->count_encoders > 0
+ connector->count_encoders > 0
) {
connector->modes_ptr = (__u64)drmData.connModes;
connector->props_ptr = (__u64)drmData.connProps;
@@ -324,7 +323,7 @@ static Size _get_drm_connector( void )
if( e33_ioctl( __display.devfd, (int)DRM_IOCTL_MODE_GETCONNECTOR, connector) == -1 ) {
continue;
}
-
+
for( j = 0; j < connector->count_modes; ++j )
{
struct drm_mode_modeinfo *mode = &drmData.connModes[j];
diff --git a/src/font33.c b/src/font33.c
new file mode 100644
index 0000000..43e2145
--- /dev/null
+++ b/src/font33.c
@@ -0,0 +1,116 @@
+#include "strings33.h"
+
+
+Font33 bigFont = {
+ 8, 0x00FF, 24, 2, 24,
+ {
+ { 5, 24, {0x0000,0x1700,0x0017,0x1717,0x0B0B} },
+ { 5, 24, {0x0B00,0x000B,0x170B,0x0B17,0x0B0B} },
+ }
+};
+
+/* plots, width */
+
+/* h, ngly, mwid */
+Font33 defFont = {
+ 4, 0x0F, 16, 96, 13,
+ {
+ /* */{ 0, 3, {0} },
+ /* ! */{ 9, 3, {0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1B,0x1C} },
+ /* " */{ 8, 5, {0x11,0x31,0x12,0x32,0x13,0x33,0x14,0x34} },
+ /* # */{ 38, 12, {0x62,0xA2,0x63,0xA3,0x54,0x94,0x15,0x25,0x35,0x45,0x55,0x65,0x75,0x85,0x95,0xA5,0xB5,0x46,0x86,0x47,0x87,0x18,0x28,0x38,0x48,0x58,0x68,0x78,0x88,0x98,0xA8,0xB8,0x39,0x79,0x2A,0x6A,0x2B,0x6B} },
+ /* $ */{ 26, 8, {0x41,0x32,0x42,0x52,0x23,0x43,0x63,0x14,0x44,0x25,0x45,0x36,0x46,0x47,0x58,0x48,0x68,0x49,0x69,0x1A,0x4A,0x5A,0x2B,0x3B,0x4B,0x4C} },
+ /* % */{ 28, 10, {0x22,0x32,0x13,0x43,0x93,0x14,0x44,0x84,0x15,0x45,0x75,0x26,0x36,0x66,0x57,0x77,0x87,0x48,0x68,0x98,0x39,0x69,0x99,0x2A,0x6A,0x9A,0x7B,0x8B} },
+ /* & */{ 28, 11, {0x32,0x42,0x52,0x23,0x63,0x24,0x64,0x35,0x65,0x36,0x46,0x56,0x27,0x67,0x97,0x18,0x78,0x88,0x19,0x79,0x89,0x2A,0x6A,0x9A,0x3B,0x4B,0x5B,0xAB} },
+ /* ' */{ 5, 3, {0x01,0x11,0x12,0x13,0x04} },
+ /* ( */{ 11, 4, {0x32,0x23,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x2B,0x3C} },
+ /* ) */{ 11, 4, {0x02,0x13,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x1B,0x0C} },
+ /* * */{ 14, 8, {0x42,0x43,0x14,0x24,0x34,0x44,0x54,0x64,0x74,0x45,0x36,0x56,0x27,0x67} },
+ /* + */{ 13, 6, {0x34,0x35,0x36,0x07,0x17,0x27,0x37,0x47,0x57,0x67,0x38,0x39,0x3A} },
+ /* , */{ 5, 4, {0x19,0x29,0x2A,0x2B,0x1C} },
+ /* - */{ 4, 6, {0x17,0x27,0x37,0x47} },
+ /* . */{ 1, 3, {0x1B} },
+ /* / */{ 12, 6, {0x40,0x41,0x42,0x33,0x34,0x35,0x26,0x27,0x28,0x19,0x1A,0x1B} },
+ /* 0 */{ 26, 8, {0x32,0x42,0x23,0x53,0x14,0x54,0x64,0x15,0x45,0x65,0x16,0x46,0x66,0x17,0x37,0x67,0x18,0x38,0x68,0x19,0x29,0x69,0x2A,0x5A,0x3B,0x4B} },
+ /* 1 */{ 16, 6, {0x32,0x23,0x33,0x14,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x1B,0x2B,0x3B,0x4B,0x5B} },
+ /* 2 */{ 18, 8, {0x22,0x32,0x42,0x13,0x53,0x64,0x65,0x56,0x47,0x38,0x29,0x1A,0x1B,0x2B,0x3B,0x4B,0x5B,0x6B} },
+ /* 3 */{ 18, 7, {0x22,0x32,0x42,0x13,0x53,0x54,0x55,0x26,0x36,0x46,0x57,0x58,0x59,0x1A,0x5A,0x2B,0x3B,0x4B} },
+ /* 4 */{ 18, 7, {0x12,0x13,0x14,0x15,0x16,0x46,0x17,0x47,0x18,0x48,0x19,0x29,0x39,0x49,0x59,0x69,0x4A,0x4B} },
+ /* 5 */{ 19, 7, {0x12,0x22,0x32,0x42,0x52,0x13,0x14,0x15,0x25,0x35,0x46,0x57,0x58,0x59,0x1A,0x5A,0x2B,0x3B,0x4B} },
+ /* 6 */{ 20, 8, {0x32,0x42,0x23,0x53,0x14,0x15,0x16,0x36,0x46,0x17,0x27,0x57,0x18,0x68,0x19,0x69,0x2A,0x5A,0x3B,0x4B} },
+ /* 7 */{ 14, 6, {0x12,0x22,0x32,0x42,0x52,0x53,0x44,0x45,0x36,0x37,0x28,0x29,0x1A,0x1B} },
+ /* 8 */{ 20, 8, {0x32,0x42,0x23,0x53,0x14,0x64,0x25,0x55,0x36,0x46,0x27,0x57,0x18,0x68,0x19,0x69,0x2A,0x5A,0x3B,0x4B} },
+ /* 9 */{ 20, 8, {0x22,0x32,0x42,0x52,0x13,0x63,0x14,0x64,0x15,0x65,0x26,0x66,0x37,0x47,0x57,0x67,0x68,0x69,0x6A,0x6B} },
+ /* : */{ 2, 3, {0x16,0x1B} },
+ /* ; */{ 6, 3, {0x27,0x29,0x2A,0x2B,0x1C,0x1D} },
+ /* < */{ 11, 6, {0x53,0x24,0x34,0x44,0x15,0x06,0x17,0x28,0x38,0x48,0x59} },
+ /* = */{ 12, 8, {0x16,0x26,0x36,0x46,0x56,0x66,0x19,0x29,0x39,0x49,0x59,0x69} },
+ /* > */{ 11, 6, {0x03,0x14,0x24,0x34,0x45,0x56,0x47,0x18,0x28,0x38,0x09} },
+ /* ? */{ 16, 8, {0x20,0x30,0x40,0x50,0x11,0x61,0x02,0x62,0x63,0x64,0x55,0x46,0x37,0x38,0x39,0x3B} },
+ /* @ */{ 44, 13, {0x42,0x52,0x62,0x72,0x82,0x92,0x33,0xA3,0x24,0x54,0x64,0x74,0xB4,0x15,0x45,0x85,0xB5,0x16,0x36,0x86,0xB6,0x17,0x37,0x87,0xB7,0x18,0x38,0x78,0x98,0xB8,0x19,0x49,0x59,0x69,0xA9,0x2A,0x3B,0x4B,0x5B,0x6B,0x7B,0x8B,0x9B,0xAB} },
+ /* A */{ 24, 8, {0x32,0x42,0x23,0x53,0x14,0x64,0x15,0x65,0x16,0x26,0x36,0x46,0x56,0x66,0x17,0x67,0x18,0x68,0x19,0x69,0x1A,0x6A,0x1B,0x6B} },
+ /* B */{ 26, 7, {0x12,0x22,0x32,0x42,0x13,0x53,0x14,0x54,0x15,0x55,0x16,0x26,0x36,0x46,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x2B,0x3B,0x4B} },
+ /* C */{ 14, 7, {0x32,0x42,0x25,0x53,0x14,0x15,0x16,0x17,0x18,0x19,0x2A,0x5A,0x3B,0x4B} },
+ /* D */{ 23, 7, {0x12,0x22,0x32,0x13,0x43,0x14,0x54,0x15,0x55,0x16,0x56,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x2B,0x3B,0x4B} },
+ /* E */{ 20, 6, {0x12,0x22,0x32,0x42,0x52,0x13,0x14,0x15,0x16,0x26,0x36,0x17,0x18,0x19,0x1A,0x1B,0x2B,0x3B,0x4B,0x5B} },
+ /* F */{ 16, 6, {0x12,0x22,0x32,0x42,0x52,0x13,0x14,0x15,0x16,0x26,0x36,0x17,0x18,0x19,0x1A,0x1B} },
+ /* G */{ 21, 8, {0x32,0x42,0x52,0x23,0x63,0x14,0x15,0x16,0x46,0x56,0x17,0x67,0x18,0x68,0x19,0x69,0x2A,0x6A,0x3B,0x4B,0x5B} },
+ /* H */{ 23, 7, {0x12,0x52,0x13,0x53,0x14,0x54,0x15,0x55,0x16,0x26,0x36,0x46,0x56,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x5B} },
+ /* I */{ 14, 3, {0x02,0x12,0x22,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x0B,0x1B,0x2B} },
+ /* J */{ 18, 7, {0x12,0x22,0x32,0x42,0x52,0x62,0x43,0x44,0x45,0x46,0x47,0x48,0x19,0x49,0x1A,0x4A,0x2B,0x3B} },
+ /* K */{ 19, 7, {0x12,0x52,0x13,0x43,0x14,0x34,0x15,0x25,0x16,0x17,0x27,0x18,0x38,0x19,0x49,0x1A,0x5A,0x1B,0x6B} },
+ /* L */{ 14, 6, {0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x2B,0x3B,0x4B,0x5B} },
+ /* M */{ 25, 9, {0x12,0x72,0x13,0x73,0x14,0x24,0x64,0x74,0x15,0x35,0x55,0x75,0x16,0x46,0x76,0x17,0x77,0x18,0x78,0x19,0x79,0x1A,0x7A,0x1B,0x7B} },
+ /* N */{ 28, 8, {0x12,0x62,0x13,0x23,0x63,0x14,0x34,0x64,0x15,0x35,0x65,0x16,0x46,0x66,0x17,0x47,0x67,0x18,0x48,0x68,0x19,0x59,0x69,0x1A,0x5A,0x6A,0x1B,0x6B} },
+ /* O */{ 20, 8, {0x32,0x42,0x23,0x53,0x14,0x64,0x15,0x65,0x16,0x66,0x17,0x67,0x18,0x68,0x19,0x69,0x2A,0x5A,0x3B,0x4B} },
+ /* P */{ 18, 7, {0x12,0x22,0x32,0x13,0x43,0x14,0x54,0x15,0x55,0x16,0x46,0x17,0x27,0x37,0x18,0x19,0x1A,0x1B} },
+ /* Q */{ 23, 8, {0x32,0x42,0x23,0x53,0x14,0x64,0x15,0x65,0x16,0x66,0x17,0x67,0x18,0x38,0x68,0x19,0x49,0x69,0x2A,0x5A,0x3B,0x4B,0x6B} },
+ /* R */{ 23, 7, {0x12,0x22,0x32,0x42,0x13,0x53,0x14,0x54,0x15,0x55,0x16,0x46,0x17,0x27,0x37,0x18,0x38,0x19,0x49,0x1A,0x5A,0x1B,0x5B} },
+ /* S */{ 14, 7, {0x32,0x42,0x23,0x53,0x14,0x25,0x36,0x47,0x58,0x59,0x1A,0x4A,0x2B,0x3B} },
+ /* T */{ 14, 5, {0x02,0x12,0x22,0x32,0x42,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B} },
+ /* U */{ 22, 8, {0x12,0x62,0x13,0x63,0x14,0x64,0x15,0x65,0x16,0x66,0x17,0x67,0x18,0x68,0x19,0x69,0x2A,0x5A,0x6A,0x3B,0x4B,0x6B} },
+ /* V */{ 18, 7, {0x12,0x52,0x13,0x53,0x14,0x54,0x15,0x55,0x16,0x56,0x27,0x47,0x28,0x48,0x29,0x49,0x3A,0x3B} },
+ /* W */{ 26, 9, {0x12,0x72,0x13,0x73,0x14,0x74,0x15,0x75,0x16,0x46,0x76,0x17,0x47,0x77,0x18,0x48,0x78,0x19,0x49,0x79,0x2A,0x4A,0x6A,0x3B,0x4B,0x5B} },
+ /* X */{ 19, 7, {0x12,0x52,0x13,0x53,0x24,0x44,0x25,0x45,0x36,0x27,0x47,0x28,0x48,0x19,0x59,0x1A,0x5A,0x1B,0x5B} },
+ /* Y */{ 14, 7, {0x12,0x52,0x13,0x53,0x14,0x54,0x25,0x45,0x36,0x37,0x38,0x39,0x3A,0x3B} },
+ /* Z */{ 18, 9, {0x12,0x22,0x32,0x42,0x52,0x53,0x44,0x45,0x36,0x27,0x28,0x19,0x1A,0x1B,0x2B,0x3B,0x4B,0x5B} },
+ /* [ */{ 17, 5, {0x22,0x32,0x42,0x52,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x3C,0x4C,0x5C} },
+ /* \ */{ 12, 6, {0x10,0x11,0x12,0x23,0x24,0x25,0x36,0x37,0x38,0x49,0x4A,0x4B} },
+ /* ] */{ 17, 5, {0x02,0x12,0x22,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x0C,0x1C,0x2C,0x3C} },
+ /* ^ */{ 10, 8, {0x32,0x42,0x23,0x53,0x24,0x54,0x25,0x55,0x16,0x66} },
+ /* _ */{ 7, 9, {0x1B,0x2B,0x3B,0x4B,0x5B,0x6B,0x7B} },
+ /* ` */{ 5, 4, {0x10,0x20,0x11,0x12,0x23} },
+ /* a */{ 17, 7, {0x26,0x36,0x46,0x17,0x57,0x28,0x38,0x48,0x58,0x19,0x59,0x1A,0x5A,0x2B,0x3B,0x4B,0x5B} },
+ /* b */{ 19, 7, {0x12,0x13,0x14,0x15,0x16,0x26,0x36,0x17,0x47,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x2B,0x3B,0x4B} },
+ /* c */{ 10, 6, {0x26,0x36,0x46,0x17,0x18,0x19,0x1A,0x2B,0x3B,0x4B} },
+ /* d */{ 19, 7, {0x52,0x53,0x54,0x55,0x36,0x46,0x56,0x27,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x2B,0x3B,0x4B,0x5B} },
+ /* e */{ 16, 7, {0x26,0x36,0x46,0x17,0x57,0x18,0x58,0x19,0x29,0x39,0x49,0x1A,0x2B,0x3B,0x4B,0x5B} },
+ /* f */{ 15, 6, {0x34,0x44,0x25,0x55,0x26,0x27,0x18,0x28,0x38,0x29,0x2A,0x2B,0x2C,0x2D,0x1E} },
+ /* g */{ 22, 7, {0x26,0x36,0x46,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x2B,0x3B,0x4B,0x5B,0x5C,0x5D,0x1E,0x5E,0x2F,0x3F,0x4F} },
+ /* h */{ 18, 7, {0x12,0x13,0x14,0x15,0x16,0x36,0x46,0x17,0x27,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x5B} },
+ /* i */{ 6, 3, {0x15,0x17,0x18,0x19,0x1A,0x1B} },
+ /* j */{ 13, 6, {0x45,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x1D,0x4D,0x1E,0x4E,0x2F,0x3F} },
+ /* k */{ 16, 6, {0x12,0x13,0x14,0x15,0x16,0x46,0x17,0x37,0x18,0x28,0x19,0x39,0x1A,0x4A,0x1B,0x5B} },
+ /* l */{ 10, 3, {0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B} },
+ /* m */{ 19, 9, {0x26,0x36,0x56,0x66,0x17,0x47,0x77,0x18,0x48,0x78,0x19,0x49,0x79,0x1A,0x4A,0x7A,0x1B,0x4B,0x7B} },
+ /* n */{ 14, 7, {0x16,0x36,0x46,0x17,0x27,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x5B} },
+ /* o */{ 14, 7, {0x26,0x36,0x46,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x2B,0x3B,0x4B} },
+ /* p */{ 19, 7, {0x26,0x36,0x46,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x1B,0x2B,0x3B,0x4B,0x1C,0x1D,0x1E,0x1F} },
+ /* q */{ 17, 7, {0x36,0x46,0x27,0x57,0x18,0x58,0x19,0x59,0x2A,0x5A,0x3B,0x4B,0x5B,0x5C,0x5D,0x5E,0x6F} },
+ /* r */{ 8, 5, {0x16,0x36,0x17,0x27,0x18,0x19,0x1A,0x1B} },
+ /* s */{ 14, 7, {0x26,0x36,0x46,0x56,0x66,0x17,0x28,0x38,0x48,0x59,0x5A,0x1B,0x2B,0x3B,0x4B} },
+ /* t */{ 12, 5, {0x13,0x14,0x15,0x16,0x26,0x36,0x17,0x18,0x19,0x1A,0x2B,0x3B} },
+ /* u */{ 13, 7, {0x16,0x56,0x17,0x57,0x18,0x58,0x19,0x59,0x1A,0x5A,0x2B,0x3B,0x4B} },
+ /* v */{ 10, 7, {0x16,0x56,0x17,0x57,0x28,0x48,0x29,0x49,0x3A,0x3B} },
+ /* w */{ 16, 7, {0x16,0x56,0x17,0x57,0x18,0x38,0x58,0x19,0x39,0x59,0x1A,0x3A,0x5A,0x2B,0x3B,0x4B} },
+ /* x */{ 11, 7, {0x16,0x56,0x27,0x47,0x38,0x29,0x49,0x2A,0x4A,0x1B,0x5B} },
+ /* y */{ 19, 7, {0x16,0x56,0x17,0x57,0x18,0x58,0x19,0x59,0x2A,0x3A,0x4A,0x5A,0x5B,0x5C,0x5D,0x1E,0x4E,0x2F,0x3F} },
+ /* z */{ 14, 7, {0x16,0x26,0x36,0x46,0x56,0x47,0x38,0x29,0x1A,0x1B,0x2B,0x3B,0x4B,0x5B} },
+ /* { */{ 13, 5, {0x32,0x42,0x23,0x24,0x25,0x16,0x07,0x18,0x29,0x2A,0x2B,0x3C,0x4C} },
+ /* | */{ 12, 3, {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B} },
+ /* } */{ 13, 5, {0x02,0x12,0x23,0x24,0x25,0x36,0x47,0x38,0x29,0x2A,0x2B,0x0C,0x1C} },
+ /* ~ */{ 9, 11, {0x17,0x26,0x35,0x45,0x55,0x66,0x77,0x87,0x96} },
+ /* :) */{ 0, 0, {0} }
+ }
+};
+
diff --git a/src/logger.c b/src/logger.c
index 860311b..d6bf3f9 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -10,16 +10,17 @@
#include "logger.h"
#include "options.h"
+#include "ui33.h"
Logger __logger;
static char *colours[5] = {
- "[\x1b[36mDebug\x1b[37m]",
- "[\x1b[32mInfo\x1b[37m]",
- "[\x1b[35mWarn\x1b[37m]",
- "[\x1b[33mError\x1b[37m]",
- "[\x1b[31mFatal\x1b[37m]",
+ "[\x1b[36mD\x1b[37m]",
+ "[\x1b[32mI\x1b[37m]",
+ "[\x1b[35mW\x1b[37m]",
+ "[\x1b[33mE\x1b[37m]",
+ "[\x1b[31mFl\x1b[37m]",
};
Size logger_init( void )
@@ -43,6 +44,7 @@ Size logger_init( void )
__logger.func = 0;
+ ui_add_message( "Welcome to Engine33" );
dprintf( __logger.fd, "\033[3J\033[1;1HWelcome to Engine33!\r\n\r\n" );
return E33_EXIT_SUCCESS;
@@ -66,7 +68,12 @@ void logger( Size level, const char *fmt, ... )
time(&currentTime);
m_time = localtime(&currentTime);
- dprintf( __logger.fd, "Engine33 [%02d:%02d:%02d] -", m_time->tm_hour, m_time->tm_min, m_time->tm_sec );
+
+ ui_add_message( fmt, args ); /* XXX */
+
+
+ dprintf( __logger.fd, "Engine33 [%02d:%02d:%02d] -",
+ m_time->tm_hour, m_time->tm_min, m_time->tm_sec );
dprintf( __logger.fd, " %s ", colours[level] );
vdprintf(__logger.fd, fmt, args);
@@ -75,7 +82,7 @@ void logger( Size level, const char *fmt, ... )
dprintf( __logger.fd, ". Reason: %s", strerror(errno) );
errno = 0;
}
-
+
dprintf( __logger.fd, ".\r\n" );
va_end(args);
diff --git a/src/main.c b/src/main.c
index 1b9b2d3..f950eff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,8 @@
#include "logger.h"
#include "system.h"
#include "signal.h"
+#include "strings33.h"
+#include "ui33.h"
static void _term_sighandler( int sig );
@@ -33,9 +35,13 @@ int main(int argc, char *argv[])
{
display_vtswitcher_poll(1);
+
if( __display.active )
{
- __display.surface.data[10] = GREEN;
+ qsuprintf( 5, 5, "fps: %d", FPS-1 );
+
+ ui_draw_messages();
+
display_flip();
}
@@ -45,7 +51,6 @@ int main(int argc, char *argv[])
if(time >= 1000000)
{
- logi("FPS: %d", FPS);
FPS = fps;
time = 0;
fps = 0;
diff --git a/src/strings33.c b/src/strings33.c
new file mode 100644
index 0000000..0bb7ea0
--- /dev/null
+++ b/src/strings33.c
@@ -0,0 +1,78 @@
+#include "stdarg.h"
+#include "stdio.h"
+#include "string.h"
+
+#include "strings33.h"
+#include "types.h"
+
+
+extern Font33 defFont;
+extern Font33 bigFont;
+
+static Font33 *fonts[2] = {
+ &defFont, &bigFont
+};
+
+
+
+void e33_uprintf( Surface *surf, Size f, u32 col, Size x, Size y, const char *fmt, ... )
+{
+ static char tmp[512];
+
+ va_list args;
+ va_start(args, fmt);
+
+ vsprintf(tmp, fmt, args);
+ e33_uprint( surf, f, col, x, y, tmp );
+
+ va_end(args);
+}
+
+
+void e33_uprint( Surface *surf, Size f, u32 col, Size x, Size y, const char *str )
+{
+ Size i, j, ofs;
+ Font33 *font = fonts[f];
+ Size sWidth = surf->w;
+ Size sHeight = surf->h;
+ FontGlyph33 *glyphs = font->glyphs;
+ Size fbw = surf->w;
+ Size fbh = surf->h;
+ u32 *out;
+ uSize slen = strlen(str);
+
+ Size strWid = 0;
+ for( i = 0; i < slen; ++i ) {
+ strWid += glyphs[ str[i] - 0x20 ].width;
+ }
+
+ if( (x + strWid) >= sWidth ) {
+ x -= (strWid - (sWidth - x));
+ }
+ if( (y + font->height) >= sHeight ) {
+ y -= (font->height - (sHeight - y));
+ }
+
+ if(x < 0) { x = 0; }
+ if(y < 0) { y = 0; }
+ out = surf->data + (x + (y * surf->w));
+
+ for( i = 0, ofs = 0; i < slen; ++i )
+ {
+ FontGlyph33 *glyph = &glyphs[ str[i] - 0x20 ];
+ Size numPlots = glyph->num_plots;
+ Size gWidth = glyph->width;
+ u16 *plots = glyph->plots;
+
+ for( j = 0; j < numPlots; ++j )
+ {
+ Size plot = plots[j];
+ Size offset = (((plot & font->yAnd) * fbw) + (plot >> font->xShift)) + ofs;
+
+ memcpy( out + offset, &col, sizeof(u32) );
+ }
+
+ ofs += gWidth;
+ }
+}
+
diff --git a/src/ui33.c b/src/ui33.c
new file mode 100644
index 0000000..4139a5e
--- /dev/null
+++ b/src/ui33.c
@@ -0,0 +1,44 @@
+#include "string.h"
+#include "stdarg.h"
+#include "stdio.h"
+
+#include "types.h"
+#include "strings33.h"
+#include "logger.h"
+
+
+#define MB_MAX 6
+
+
+static char messageBox[MB_MAX][256] = { 0, };
+static Size A = 0;
+static Size P = 0;
+
+
+void ui_add_message( String fmt, ... )
+{
+ va_list args;
+ va_start(args, fmt);
+
+ vsnprintf( messageBox[P++], 256, fmt, args );
+ if( P == MB_MAX ) P = 0;
+ if( P == A ) ++A;
+ if( A == MB_MAX ) A = 0;
+
+ va_end(args);
+}
+
+void ui_draw_messages( void )
+{
+ Size start = __display.surface.h - 5 - 8;
+ Size i = P-1;
+
+ qsuprintf( 300, 40, "A(%d), P(%d)", A, P );
+
+ do {
+ if( i < 0 ) i = MB_MAX-1;
+ qsuprint( messageBox[i], 5, start );
+ start -= 18;
+ } while( (i--) != A );
+}
+