commit df78d9fed344b55967accac4a73f7485986f4a0d
parent a66eaaa9b45f8661ffb847f60b4da8d9e71c96ad
Author: kocotian <kocotian@kocotian.pl>
Date: Fri, 15 Jan 2021 13:05:17 +0100
[v0.2] flib, new Makefile, AUTHORS and licensing information
Diffstat:
A | AUTHORS | | | 16 | ++++++++++++++++ |
M | CHANGELOG | | | 7 | ++++++- |
M | Makefile | | | 27 | ++++++++++++++++++++++++--- |
A | TODO | | | 3 | +++ |
A | config.mk | | | 17 | +++++++++++++++++ |
M | fwin.c | | | 5 | ++++- |
D | fwin.h | | | 298 | ------------------------------------------------------------------------------- |
A | include/flib.h | | | 55 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | include/font.h | | | 139 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | lib/flib.c | | | 260 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
D | templefont.h | | | 130 | ------------------------------------------------------------------------------- |
11 files changed, 524 insertions(+), 433 deletions(-)
diff --git a/AUTHORS b/AUTHORS
@@ -0,0 +1,16 @@
+fwin - framebuffer window system
+(C) 2021-2021 Kacper Kocot <kocotian@kocotian.pl>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+See LICENSE file for license details
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,7 +1,12 @@
================
-- v0.2 (unrel.):
+- v0.2:
* some basic user input
+* "fwin.h" header is now flib library
+* extended Makefile with config.mk
+* TODO list
+* AUTHORS
+* licensing information
================
- v0.1:
diff --git a/Makefile b/Makefile
@@ -1,4 +1,25 @@
-CC = gcc
+include config.mk
-fwin: fwin.c fwin.h
- ${CC} -std=c99 -Wall -Wextra -o $@ $<
+SRC = fwin.c lib/flib.c
+OBJ = ${SRC:.c=.o}
+
+all: options fwin
+
+options:
+ @echo fwin build options:
+ @echo "CC = ${CC}"
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+
+.c.o:
+ ${CC} -c -o $@ ${CFLAGS} $<
+
+${OBJ}: config.mk
+
+fwin: ${OBJ}
+ ${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+clean:
+ rm -f fwin ${OBJ} *.orig *.rej
+
+.PHONY: all options clean
diff --git a/TODO b/TODO
@@ -0,0 +1,3 @@
+=== TODO ======================================================================
+
+* /tmp/.F<num>.lock - lockfile with info about framebuffer, PID, etc.
diff --git a/config.mk b/config.mk
@@ -0,0 +1,17 @@
+VERSION = 0.1
+
+# paths
+PREFIX = /usr/local
+FWININC = include
+FWINLIB = lib
+
+# includes and libs
+INCS = -I${FWININC}
+LIBS = -L${FWINLIB}
+
+# flags
+CFLAGS = -std=c99 -Wall -pedantic -Os ${INCS}
+LDFLAGS = ${LIBS}
+
+# compiler
+CC = gcc
diff --git a/fwin.c b/fwin.c
@@ -1,10 +1,13 @@
+/* See AUTHORS file for copying details
+ and LICENSE file for license details. */
+
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include "fwin.h"
+#include <flib.h>
#include "getch.h"
int
diff --git a/fwin.h b/fwin.h
@@ -1,298 +0,0 @@
-#define _XOPEN_SOURCE 700
-
-#include <linux/fb.h>
-
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "templefont.h"
-
-#define DEFAULT_FRAMEBUFFER "/dev/fb0"
-
-#define GETA(x) (x >> 24)
-#define GETR(x) ((x >> 16) & 0x000000FF)
-#define GETG(x) ((x >> 8) & 0x000000FF)
-#define GETB(x) (x & 0x000000FF)
-
-#define GETX(x) (x >> 32)
-#define GETY(x) (x & 0x0000FFFF)
-#define XY(x,y) (((int64_t)x << 32) + (int64_t)y)
-
-typedef int64_t ColorARGB;
-typedef int64_t PositionXY;
-
-typedef struct {
- int fbdesc; /* <0 = unopened */
- char *mappoint; /* NULL = unmapped */
- int64_t len; /* length */
- PositionXY res[2]; /* { res, vres } */
-} FbDrawable;
-
-int fbopen(const char *fbname);
-int fbclose(int fbdesc);
-char *fbmap(int fbdesc, int64_t len);
-void fbunmap(char **mappoint, int64_t len);
-
-int fbgetinfo(int fbdesc, struct fb_var_screeninfo *info);
-int fbsetinfo(int fbdesc, struct fb_var_screeninfo *info);
-
-int64_t getres(int fbdesc);
-int64_t getvres(int fbdesc);
-
-void fbfill(FbDrawable *fbdrw, ColorARGB col);
-void fbdrawpixel(FbDrawable *fbdrw, PositionXY xy, ColorARGB col);
-void fbdrawrect(FbDrawable *fbdrw, PositionXY xy, PositionXY wh, char filled, ColorARGB col);
-void fbdrawchar(FbDrawable *fbdrw, PositionXY xy, char ch, ColorARGB fg, ColorARGB bg);
-void fbputs(FbDrawable *fbdrw, PositionXY xy, char *ch, ColorARGB fg, ColorARGB bg);
-
-void drwcpyraw(FbDrawable *dest, FbDrawable *src);
-void drwcpy(FbDrawable *dest, FbDrawable *src);
-void drwcpyat(FbDrawable *dest, FbDrawable *src, PositionXY at);
-
-int
-fbopen(const char *fbname)
-{
- return open(fbname, O_RDWR);
-}
-
-int
-fbclose(int fbdesc)
-{
- return close(fbdesc);
-}
-
-char *
-fbmap(int fbdesc, int64_t len)
-{
- return mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fbdesc, 0);
-}
-
-void
-fbunmap(char **mappoint, int64_t len)
-{
- munmap(*mappoint, len);
-}
-
-/* From <linux/fb.h>:
-struct fb_var_screeninfo {
- __u32 xres; -- visible resolution
- __u32 yres;
- __u32 xres_virtual; -- virtual resolution
- __u32 yres_virtual;
- __u32 xoffset; -- offset from virtual to visible
- __u32 yoffset; -- resolution
-
- __u32 bits_per_pixel; -- guess what
- __u32 grayscale; -- 0 = color, 1 = grayscale,
- -- >1 = FOURCC
- struct fb_bitfield red; -- bitfield in fb mem if true color,
- struct fb_bitfield green; -- else only length is significant
- struct fb_bitfield blue;
- struct fb_bitfield transp; -- transparency
-
- __u32 nonstd; -- != 0 Non standard pixel format
-
- __u32 activate; -- see FB_ACTIVATE_*
-
- __u32 height; -- height of picture in mm
- __u32 width; -- width of picture in mm
-
- __u32 accel_flags; -- (OBSOLETE) see fb_info.flags
-
- -- Timing: All values in pixclocks, except pixclock (of course)
- __u32 pixclock; -- pixel clock in ps (pico seconds)
- __u32 left_margin; -- time from sync to picture
- __u32 right_margin; -- time from picture to sync
- __u32 upper_margin; -- time from sync to picture
- __u32 lower_margin;
- __u32 hsync_len; -- length of horizontal sync
- __u32 vsync_len; -- length of vertical sync
- __u32 sync; -- see FB_SYNC_*
- __u32 vmode; -- see FB_VMODE_*
- __u32 rotate; -- angle we rotate counter clockwise
- __u32 colorspace; -- colorspace for FOURCC-based modes
- __u32 reserved[4]; -- Reserved for future compatibility
-}; */
-
-int
-fbgetinfo(int fbdesc, struct fb_var_screeninfo *info)
-{
- return ioctl(fbdesc, FBIOGET_VSCREENINFO, info);
-}
-
-int
-fbsetinfo(int fbdesc, struct fb_var_screeninfo *info)
-{
- return ioctl(fbdesc, FBIOPUT_VSCREENINFO, info);
-}
-
-int64_t /* first 32 bits are x, second 32 bits are y */
-getres(int fbdesc)
-{
- struct fb_var_screeninfo info;
-
- fbgetinfo(fbdesc, &info);
- return ((int64_t)info.xres << 32) + (int32_t)info.yres;
-}
-
-int64_t /* first 32 bits are x, second 32 bits are y */
-getvres(int fbdesc)
-{
- struct fb_var_screeninfo info;
-
- fbgetinfo(fbdesc, &info);
- return ((int64_t)info.xres_virtual << 32) + (int32_t)info.yres_virtual;
-}
-
-/* ----- actual framebuffer operation functions ----- */
-
-void
-fbfill(FbDrawable *fbdrw, ColorARGB col)
-{
- int64_t leni;
- leni = -1;
- while (++leni < fbdrw->len) {
- switch (leni % 4) {
- case 0: fbdrw->mappoint[leni] = GETB(col); break;
- case 1: fbdrw->mappoint[leni] = GETG(col); break;
- case 2: fbdrw->mappoint[leni] = GETR(col); break;
- case 3: fbdrw->mappoint[leni] = GETA(col); break;
- }
- }
-}
-
-void
-fbdrawpixel(FbDrawable *fbdrw, PositionXY xy, ColorARGB col)
-{
- int64_t vres, coordpoint;
- vres = fbdrw->res[1];
- coordpoint = (((GETX(vres) * GETY(xy)) + (GETX(xy) % GETX(vres))) * 4) - 1;
- fbdrw->mappoint[++coordpoint] = GETB(col);
- fbdrw->mappoint[++coordpoint] = GETG(col);
- fbdrw->mappoint[++coordpoint] = GETR(col);
- fbdrw->mappoint[++coordpoint] = GETA(col);
-}
-
-void
-fbdrawrect(FbDrawable *fbdrw, PositionXY xy, PositionXY wh, char filled, ColorARGB col)
-{
- int64_t vres, coordpoint;
- int32_t witer, hiter;
- vres = fbdrw->res[1];
- hiter = GETY(wh);
- witer = GETX(wh);
- while (--witer > -1) {
- while (--hiter > -1) {
- if (filled || ((hiter == GETY(wh) - 1 || hiter == 0) || (witer == GETX(wh) - 1 || witer == 0))) {
- coordpoint = (((GETX(vres) * (GETY(xy) + hiter)) + ((GETX(xy) + witer) % GETX(vres))) * 4) - 1;
- fbdrw->mappoint[++coordpoint] = GETB(col);
- fbdrw->mappoint[++coordpoint] = GETG(col);
- fbdrw->mappoint[++coordpoint] = GETR(col);
- fbdrw->mappoint[++coordpoint] = GETA(col);
- }
- }
- hiter = GETY(wh);
- }
-}
-
-void
-fbdrawchar(FbDrawable *fbdrw, PositionXY xy, char ch, ColorARGB fg, ColorARGB bg)
-{
- int64_t vres, coordpoint;
- int32_t x, y, lx, ly, iter;
- vres = fbdrw->res[1];
- x = GETX(xy) - 1; y = GETY(xy) - 1;
- lx = GETX(xy) + 8; ly = GETY(xy) + 8;
- iter = 0;
- while (++y < ly) {
- while (++x < lx) {
- coordpoint = (((GETX(vres) * (y)) + ((x) % GETX(vres))) * 4) - 1;
- if ((sys_font_std[(int)ch] >> iter) & 1) {
- fbdrw->mappoint[++coordpoint] = GETB(fg);
- fbdrw->mappoint[++coordpoint] = GETG(fg);
- fbdrw->mappoint[++coordpoint] = GETR(fg);
- fbdrw->mappoint[++coordpoint] = GETA(fg);
- } else {
- fbdrw->mappoint[++coordpoint] = GETB(bg);
- fbdrw->mappoint[++coordpoint] = GETG(bg);
- fbdrw->mappoint[++coordpoint] = GETR(bg);
- fbdrw->mappoint[++coordpoint] = GETA(bg);
- }
- ++iter;
- }
- x = GETX(xy) - 1;
- }
-}
-
-void
-fbputs(FbDrawable *fbdrw, PositionXY xy, char *ch, ColorARGB fg, ColorARGB bg)
-{
- int32_t x, y;
- x = GETX(xy);
- y = GETY(xy);
- while (*ch) {
- fbdrawchar(fbdrw, XY(x, y), *(ch++), fg, bg);
- x += 8;
- }
-}
-
-/* ----- drw manipulation functions ----- */
-
-/* typedef struct {
- int fbdesc; -- <0 = unopened
- char *mappoint; -- NULL = unmapped
- int64_t len; -- length
- PositionXY res[2]; -- { res, vres }
-} FbDrawable; */
-
-void /* for this function, both dest and src
- should have the same resolution and
- src's len must be equal or greater that
- dest's len */
-drwcpyraw(FbDrawable *dest, FbDrawable *src)
-{
- int64_t l = -1;
- while (++l < src->len)
- dest->mappoint[l] = src->mappoint[l];
-}
-
-void
-drwcpy(FbDrawable *dest, FbDrawable *src)
-{
- int64_t ld, ls, xi, yi;
- int32_t xdiff;
- ld = ls = xi = yi = -1;
- xdiff = GETX(dest->res[1]) - GETX(src->res[1]);
- while (++yi < GETY(src->res[1])) {
- while (++xi < (GETX(src->res[1]) * 4)) {
- ++ld; ++ls;
- dest->mappoint[ld] = src->mappoint[ls];
- }
- ld += (xdiff * 4);
- xi = -1;
- }
-}
-
-void
-drwcpyat(FbDrawable *dest, FbDrawable *src, PositionXY at)
-{
- int64_t ld, ls, xi, yi;
- int32_t xdiff;
- ld = ls = -1;
- xi = GETX(at) - 1;
- yi = GETY(at) - 1;
- xdiff = GETX(dest->res[1]) - GETX(src->res[1]);
- ld += (((GETX(dest->res[1]) * GETY(at)) + (GETX(at) % GETX(dest->res[1]))) * 4);
- while (++yi < GETY(src->res[1]) + GETY(at)) {
- while (++xi < (GETX(src->res[1]) * 4) + GETX(at)) {
- ++ld; ++ls;
- dest->mappoint[ld] = src->mappoint[ls];
- }
- ld += (xdiff * 4);
- xi = GETX(at) - 1;
- }
-}
diff --git a/include/flib.h b/include/flib.h
@@ -0,0 +1,55 @@
+/* See AUTHORS file for copying details
+ and LICENSE file for license details. */
+
+#define _XOPEN_SOURCE 700
+
+#include <linux/fb.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#define DEFAULT_FRAMEBUFFER "/dev/fb0"
+
+#define GETA(x) ((x) >> 24)
+#define GETR(x) (((x) >> 16) & 0x000000FF)
+#define GETG(x) (((x) >> 8) & 0x000000FF)
+#define GETB(x) ((x) & 0x000000FF)
+
+#define GETX(x) ((x) >> 32)
+#define GETY(x) ((x) & 0x0000FFFF)
+#define XY(x,y) (((int64_t)(x) << 32) + (int64_t)(y))
+
+typedef int64_t ColorARGB;
+typedef int64_t PositionXY;
+
+typedef struct {
+ int fbdesc; /* <0 = unopened */
+ char *mappoint; /* NULL = unmapped */
+ int64_t len; /* length */
+ PositionXY res[2]; /* { res, vres } */
+} FbDrawable;
+
+int fbopen(const char *fbname);
+int fbclose(int fbdesc);
+char *fbmap(int fbdesc, int64_t len);
+void fbunmap(char **mappoint, int64_t len);
+
+int fbgetinfo(int fbdesc, struct fb_var_screeninfo *info);
+int fbsetinfo(int fbdesc, struct fb_var_screeninfo *info);
+
+int64_t getres(int fbdesc);
+int64_t getvres(int fbdesc);
+
+void fbfill(FbDrawable *fbdrw, ColorARGB col);
+void fbdrawpixel(FbDrawable *fbdrw, PositionXY xy, ColorARGB col);
+void fbdrawrect(FbDrawable *fbdrw, PositionXY xy, PositionXY wh, char filled, ColorARGB col);
+void fbdrawchar(FbDrawable *fbdrw, PositionXY xy, char ch, ColorARGB fg, ColorARGB bg);
+void fbputs(FbDrawable *fbdrw, PositionXY xy, char *ch, ColorARGB fg, ColorARGB bg);
+
+void drwcpyraw(FbDrawable *dest, FbDrawable *src);
+void drwcpy(FbDrawable *dest, FbDrawable *src);
+void drwcpyat(FbDrawable *dest, FbDrawable *src, PositionXY at);
diff --git a/include/font.h b/include/font.h
@@ -0,0 +1,139 @@
+/* Standard font header from TempleOS:
+ https://github.com/cia-foundation/TempleOS/blob/archive/Kernel/FontStd.HC
+
+ (c) 2005-2017 Terry A. Davis */
+
+u_int64_t sys_font_std[256] = {
+ 0x0000000000000000, 0x0000000000000000,
+ /* -------- BOX characters -------- */ /* format: single line, double line */
+ 0x000000FF00000000, 0x000000FF00FF0000, /* horizontal pipes */
+ 0x1818181818181818, 0x6C6C6C6C6C6C6C6C, /* vertical pipes */
+ 0x181818F800000000, 0x6C6C6CEC0CFC0000, /* bottom-right pipes */
+ 0x1818181F00000000, 0x6C6C6C6F607F0000, /* bottom-left pipes */
+ 0x000000F818181818, 0x000000FC0CEC6C6C, /* top-right pipes */
+ 0x0000001F18181818, 0x0000007F606F6C6C, /* top-left pipes */
+ /* ------------- BLANK ------------- */
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0008000000000000,
+ /* -------- ASCII printable -------- */
+ 0x0000000000000000, 0x00180018183C3C18, /* ! */
+ 0x0000000000363636, 0x006C6CFE6CFE6C6C, /* "# */
+ 0x00187ED07C16FC30, 0x0060660C18306606, /* $% */
+ 0x00DC66B61C36361C, 0x0000000000181818, /* &' */
+ 0x0030180C0C0C1830, 0x000C18303030180C, /* () */
+ 0x0000187E3C7E1800, 0x000018187E181800, /* *+ */
+ 0x0C18180000000000, 0x000000007E000000, /* ,- */
+ 0x0018180000000000, 0x0000060C18306000, /* ./ */
+ 0x003C666E7E76663C, 0x007E181818181C18, /* 01 */
+ 0x007E0C183060663C, 0x003C66603860663C, /* 23 */
+ 0x0030307E363C3830, 0x003C6660603E067E, /* 45 */
+ 0x003C66663E060C38, 0x000C0C0C1830607E, /* 67 */
+ 0x003C66663C66663C, 0x001C30607C66663C, /* 89 */
+ 0x0018180018180000, 0x0C18180018180000, /* :; */
+ 0x0030180C060C1830, 0x0000007E007E0000, /* <= */
+ 0x000C18306030180C, 0x001800181830663C, /* >? */
+ 0x003C06765676663C, 0x006666667E66663C, /* @A */
+ 0x003E66663E66663E, 0x003C66060606663C, /* BC */
+ 0x001E36666666361E, 0x007E06063E06067E, /* DE */
+ 0x000606063E06067E, 0x003C66667606663C, /* FG */
+ 0x006666667E666666, 0x007E18181818187E, /* HI */
+ 0x001C36303030307C, 0x0066361E0E1E3666, /* JK */
+ 0x007E060606060606, 0x00C6C6D6D6FEEEC6, /* LM */
+ 0x006666767E6E6666, 0x003C66666666663C, /* NO */
+ 0x000606063E66663E, 0x006C36566666663C, /* PQ */
+ 0x006666363E66663E, 0x003C66603C06663C, /* RS */
+ 0x001818181818187E, 0x003C666666666666, /* TU */
+ 0x00183C6666666666, 0x00C6EEFED6D6C6C6, /* VW */
+ 0x0066663C183C6666, 0x001818183C666666, /* XY */
+ 0x007E060C1830607E, 0x003E06060606063E, /* Z[ */
+ 0x00006030180C0600, 0x007C60606060607C, /* \] */
+ 0x000000000000663C, 0xFFFF000000000000, /* ^_ */
+ 0x000000000030180C, 0x007C667C603C0000, /* `a */
+ 0x003E6666663E0606, 0x003C6606663C0000, /* bc */
+ 0x007C6666667C6060, 0x003C067E663C0000, /* de */
+ 0x000C0C0C3E0C0C38, 0x3C607C66667C0000, /* fg */
+ 0x00666666663E0606, 0x003C1818181C0018, /* hi */
+ 0x0E181818181C0018, 0x0066361E36660606, /* jk */
+ 0x003C18181818181C, 0x00C6D6D6FE6C0000, /* lm */
+ 0x00666666663E0000, 0x003C6666663C0000, /* no */
+ 0x06063E66663E0000, 0xE0607C66667C0000, /* pq */
+ 0x000606066E360000, 0x003E603C067C0000, /* rs */
+ 0x00380C0C0C3E0C0C, 0x007C666666660000, /* tu */
+ 0x00183C6666660000, 0x006CFED6D6C60000, /* vw */
+ 0x00663C183C660000, 0x3C607C6666660000, /* xy */
+ 0x007E0C18307E0000, 0x003018180E181830, /* z{ */
+ 0x0018181818181818, 0x000C18187018180C, /* |} */
+ 0x000000000062D68C, 0xFFFFFFFFFFFFFFFF, /* ~ */
+ /* --- extended ASCII (probably) --- */
+ 0x1E30181E3303331E, 0x007E333333003300,
+ 0x001E033F331E0038, 0x00FC667C603CC37E,
+ 0x007E333E301E0033, 0x007E333E301E0007,
+ 0x007E333E301E0C0C, 0x3C603E03033E0000,
+ 0x003C067E663CC37E, 0x001E033F331E0033,
+ 0x001E033F331E0007, 0x001E0C0C0C0E0033,
+ 0x003C1818181C633E, 0x001E0C0C0C0E0007,
+ 0x00333F33331E0C33, 0x00333F331E000C0C,
+ 0x003F061E063F0038, 0x00FE33FE30FE0000,
+ 0x007333337F33367C, 0x001E33331E00331E,
+ 0x001E33331E003300, 0x001E33331E000700,
+ 0x007E33333300331E, 0x007E333333000700,
+ 0x1F303F3333003300, 0x001C3E63633E1C63,
+ 0x001E333333330033, 0x18187E03037E1818,
+ 0x003F67060F26361C, 0x000C3F0C3F1E3333,
+ 0x70337B332F1B1B0F, 0x0E1B18187E18D870,
+ 0x007E333E301E0038, 0x001E0C0C0C0E001C,
+ 0x001E33331E003800, 0x007E333333003800,
+ 0x003333331F001F00, 0x00333B3F3733003F,
+ 0x00007E007C36363C, 0x00007E003C66663C,
+ 0x001E3303060C000C, 0x000003033F000000,
+ 0x000030303F000000, 0xF81973C67C1B3363,
+ 0xC0F9F3E6CF1B3363, 0x183C3C1818001800,
+ 0x0000CC663366CC00, 0x00003366CC663300,
+ 0x1144114411441144, 0x55AA55AA55AA55AA,
+ 0xEEBBEEBBEEBBEEBB, 0x1818181818181818,
+ 0x1818181F18181818, 0x1818181F181F1818,
+ 0x6C6C6C6F6C6C6C6C, 0x6C6C6C7F00000000,
+ 0x1818181F181F0000, 0x6C6C6C6F606F6C6C,
+ 0x6C6C6C6C6C6C6C6C, 0x6C6C6C6F607F0000,
+ 0x0000007F606F6C6C, 0x0000007F6C6C6C6C,
+ 0x0000001F181F1818, 0x1818181F00000000,
+ 0x000000F818181818, 0x000000FF18181818,
+ 0x181818FF00000000, 0x181818F818181818,
+ 0x000000FF00000000, 0x181818FF18181818,
+ 0x181818F818F81818, 0x6C6C6CEC6C6C6C6C,
+ 0x000000FC0CEC6C6C, 0x6C6C6CEC0CFC0000,
+ 0x000000FF00EF6C6C, 0x6C6C6CEF00FF0000,
+ 0x6C6C6CEC0CEC6C6C, 0x000000FF00FF0000,
+ 0x6C6C6CEF00EF6C6C, 0x000000FF00FF1818,
+ 0x000000FF6C6C6C6C, 0x181818FF00FF0000,
+ 0x6C6C6CFF00000000, 0x000000FC6C6C6C6C,
+ 0x000000F818F81818, 0x181818F818F80000,
+ 0x6C6C6CFC00000000, 0x6C6C6CEF6C6C6C6C,
+ 0x181818FF00FF1818, 0x0000001F18181818,
+ 0x181818F800000000, 0xFFFFFFFFFFFFFFFF,
+ 0xFFFFFFFF00000000, 0x0F0F0F0F0F0F0F0F,
+ 0xF0F0F0F0F0F0F0F0, 0x00000000FFFFFFFF,
+ 0x006E3B133B6E0000, 0x03031F331F331E00,
+ 0x0003030303637F00, 0x0036363636367F00,
+ 0x007F660C180C667F, 0x001E3333337E0000,
+ 0x03063E6666666600, 0x00181818183B6E00,
+ 0x3F0C1E33331E0C3F, 0x001C36637F63361C,
+ 0x007736366363361C, 0x001E33333E180C38,
+ 0x00007EDBDB7E0000, 0x03067EDBDB7E3060,
+ 0x003C06033F03063C, 0x003333333333331E,
+ 0x00003F003F003F00, 0x003F000C0C3F0C0C,
+ 0x003F00060C180C06, 0x003F00180C060C18,
+ 0x1818181818D8D870, 0x0E1B1B1818181818,
+ 0x000C0C003F000C0C, 0x0000394E00394E00,
+ 0x000000001C36361C, 0x0000001818000000,
+ 0x0000001800000000, 0x383C3637303030F0,
+ 0x000000363636361E, 0x0000003E061C301E,
+ 0x00003C3C3C3C0000, 0xFFFFFFFFFFFFFFFF,
+};
diff --git a/lib/flib.c b/lib/flib.c
@@ -0,0 +1,260 @@
+/* See AUTHORS file for copying details
+ and LICENSE file for license details. */
+
+#define _XOPEN_SOURCE 700
+
+#include <linux/fb.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <flib.h>
+#include <font.h>
+
+int
+fbopen(const char *fbname)
+{
+ return open(fbname, O_RDWR);
+}
+
+int
+fbclose(int fbdesc)
+{
+ return close(fbdesc);
+}
+
+char *
+fbmap(int fbdesc, int64_t len)
+{
+ return mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fbdesc, 0);
+}
+
+void
+fbunmap(char **mappoint, int64_t len)
+{
+ munmap(*mappoint, len);
+}
+
+/* From <linux/fb.h>:
+struct fb_var_screeninfo {
+ __u32 xres; -- visible resolution
+ __u32 yres;
+ __u32 xres_virtual; -- virtual resolution
+ __u32 yres_virtual;
+ __u32 xoffset; -- offset from virtual to visible
+ __u32 yoffset; -- resolution
+
+ __u32 bits_per_pixel; -- guess what
+ __u32 grayscale; -- 0 = color, 1 = grayscale,
+ -- >1 = FOURCC
+ struct fb_bitfield red; -- bitfield in fb mem if true color,
+ struct fb_bitfield green; -- else only length is significant
+ struct fb_bitfield blue;
+ struct fb_bitfield transp; -- transparency
+
+ __u32 nonstd; -- != 0 Non standard pixel format
+
+ __u32 activate; -- see FB_ACTIVATE_*
+
+ __u32 height; -- height of picture in mm
+ __u32 width; -- width of picture in mm
+
+ __u32 accel_flags; -- (OBSOLETE) see fb_info.flags
+
+ -- Timing: All values in pixclocks, except pixclock (of course)
+ __u32 pixclock; -- pixel clock in ps (pico seconds)
+ __u32 left_margin; -- time from sync to picture
+ __u32 right_margin; -- time from picture to sync
+ __u32 upper_margin; -- time from sync to picture
+ __u32 lower_margin;
+ __u32 hsync_len; -- length of horizontal sync
+ __u32 vsync_len; -- length of vertical sync
+ __u32 sync; -- see FB_SYNC_*
+ __u32 vmode; -- see FB_VMODE_*
+ __u32 rotate; -- angle we rotate counter clockwise
+ __u32 colorspace; -- colorspace for FOURCC-based modes
+ __u32 reserved[4]; -- Reserved for future compatibility
+}; */
+
+int
+fbgetinfo(int fbdesc, struct fb_var_screeninfo *info)
+{
+ return ioctl(fbdesc, FBIOGET_VSCREENINFO, info);
+}
+
+int
+fbsetinfo(int fbdesc, struct fb_var_screeninfo *info)
+{
+ return ioctl(fbdesc, FBIOPUT_VSCREENINFO, info);
+}
+
+int64_t /* first 32 bits are x, second 32 bits are y */
+getres(int fbdesc)
+{
+ struct fb_var_screeninfo info;
+
+ fbgetinfo(fbdesc, &info);
+ return ((int64_t)info.xres << 32) + (int32_t)info.yres;
+}
+
+int64_t /* first 32 bits are x, second 32 bits are y */
+getvres(int fbdesc)
+{
+ struct fb_var_screeninfo info;
+
+ fbgetinfo(fbdesc, &info);
+ return ((int64_t)info.xres_virtual << 32) + (int32_t)info.yres_virtual;
+}
+
+/* ----- actual framebuffer operation functions ----- */
+
+void
+fbfill(FbDrawable *fbdrw, ColorARGB col)
+{
+ int64_t leni;
+ leni = -1;
+ while (++leni < fbdrw->len) {
+ switch (leni % 4) {
+ case 0: fbdrw->mappoint[leni] = GETB(col); break;
+ case 1: fbdrw->mappoint[leni] = GETG(col); break;
+ case 2: fbdrw->mappoint[leni] = GETR(col); break;
+ case 3: fbdrw->mappoint[leni] = GETA(col); break;
+ }
+ }
+}
+
+void
+fbdrawpixel(FbDrawable *fbdrw, PositionXY xy, ColorARGB col)
+{
+ int64_t vres, coordpoint;
+ vres = fbdrw->res[1];
+ coordpoint = (((GETX(vres) * GETY(xy)) + (GETX(xy) % GETX(vres))) * 4) - 1;
+ fbdrw->mappoint[++coordpoint] = GETB(col);
+ fbdrw->mappoint[++coordpoint] = GETG(col);
+ fbdrw->mappoint[++coordpoint] = GETR(col);
+ fbdrw->mappoint[++coordpoint] = GETA(col);
+}
+
+void
+fbdrawrect(FbDrawable *fbdrw, PositionXY xy, PositionXY wh, char filled, ColorARGB col)
+{
+ int64_t vres, coordpoint;
+ int32_t witer, hiter;
+ vres = fbdrw->res[1];
+ hiter = GETY(wh);
+ witer = GETX(wh);
+ while (--witer > -1) {
+ while (--hiter > -1) {
+ if (filled || ((hiter == GETY(wh) - 1 || hiter == 0) || (witer == GETX(wh) - 1 || witer == 0))) {
+ coordpoint = (((GETX(vres) * (GETY(xy) + hiter)) + ((GETX(xy) + witer) % GETX(vres))) * 4) - 1;
+ fbdrw->mappoint[++coordpoint] = GETB(col);
+ fbdrw->mappoint[++coordpoint] = GETG(col);
+ fbdrw->mappoint[++coordpoint] = GETR(col);
+ fbdrw->mappoint[++coordpoint] = GETA(col);
+ }
+ }
+ hiter = GETY(wh);
+ }
+}
+
+void
+fbdrawchar(FbDrawable *fbdrw, PositionXY xy, char ch, ColorARGB fg, ColorARGB bg)
+{
+ int64_t vres, coordpoint;
+ int32_t x, y, lx, ly, iter;
+ vres = fbdrw->res[1];
+ x = GETX(xy) - 1; y = GETY(xy) - 1;
+ lx = GETX(xy) + 8; ly = GETY(xy) + 8;
+ iter = 0;
+ while (++y < ly) {
+ while (++x < lx) {
+ coordpoint = (((GETX(vres) * (y)) + ((x) % GETX(vres))) * 4) - 1;
+ if ((sys_font_std[(int)ch] >> iter) & 1) {
+ fbdrw->mappoint[++coordpoint] = GETB(fg);
+ fbdrw->mappoint[++coordpoint] = GETG(fg);
+ fbdrw->mappoint[++coordpoint] = GETR(fg);
+ fbdrw->mappoint[++coordpoint] = GETA(fg);
+ } else {
+ fbdrw->mappoint[++coordpoint] = GETB(bg);
+ fbdrw->mappoint[++coordpoint] = GETG(bg);
+ fbdrw->mappoint[++coordpoint] = GETR(bg);
+ fbdrw->mappoint[++coordpoint] = GETA(bg);
+ }
+ ++iter;
+ }
+ x = GETX(xy) - 1;
+ }
+}
+
+void
+fbputs(FbDrawable *fbdrw, PositionXY xy, char *ch, ColorARGB fg, ColorARGB bg)
+{
+ int32_t x, y;
+ x = GETX(xy);
+ y = GETY(xy);
+ while (*ch) {
+ fbdrawchar(fbdrw, XY(x, y), *(ch++), fg, bg);
+ x += 8;
+ }
+}
+
+/* ----- drw manipulation functions ----- */
+
+/* typedef struct {
+ int fbdesc; -- <0 = unopened
+ char *mappoint; -- NULL = unmapped
+ int64_t len; -- length
+ PositionXY res[2]; -- { res, vres }
+} FbDrawable; */
+
+void /* for this function, both dest and src
+ should have the same resolution and
+ src's len must be equal or greater that
+ dest's len */
+drwcpyraw(FbDrawable *dest, FbDrawable *src)
+{
+ int64_t l = -1;
+ while (++l < src->len)
+ dest->mappoint[l] = src->mappoint[l];
+}
+
+void
+drwcpy(FbDrawable *dest, FbDrawable *src)
+{
+ int64_t ld, ls, xi, yi;
+ int32_t xdiff;
+ ld = ls = xi = yi = -1;
+ xdiff = GETX(dest->res[1]) - GETX(src->res[1]);
+ while (++yi < GETY(src->res[1])) {
+ while (++xi < (GETX(src->res[1]) * 4)) {
+ ++ld; ++ls;
+ dest->mappoint[ld] = src->mappoint[ls];
+ }
+ ld += (xdiff * 4);
+ xi = -1;
+ }
+}
+
+void
+drwcpyat(FbDrawable *dest, FbDrawable *src, PositionXY at)
+{
+ int64_t ld, ls, xi, yi;
+ int32_t xdiff;
+ ld = ls = -1;
+ xi = GETX(at) - 1;
+ yi = GETY(at) - 1;
+ xdiff = GETX(dest->res[1]) - GETX(src->res[1]);
+ ld += (((GETX(dest->res[1]) * GETY(at)) + (GETX(at) % GETX(dest->res[1]))) * 4);
+ while (++yi < GETY(src->res[1]) + GETY(at)) {
+ while (++xi < (GETX(src->res[1]) * 4) + GETX(at)) {
+ ++ld; ++ls;
+ dest->mappoint[ld] = src->mappoint[ls];
+ }
+ ld += (xdiff * 4);
+ xi = GETX(at) - 1;
+ }
+}
diff --git a/templefont.h b/templefont.h
@@ -1,130 +0,0 @@
-u_int64_t sys_font_std[256] = {
- 0x0000000000000000,0x0000000000000000,
- 0x000000FF00000000,0x000000FF00FF0000,//horizontal lines
- 0x1818181818181818,0x6C6C6C6C6C6C6C6C,//vertical lines
- 0x181818F800000000,0x6C6C6CEC0CFC0000,//bottom-right
- 0x1818181F00000000,0x6C6C6C6F607F0000,//bottom-left
- 0x000000F818181818,0x000000FC0CEC6C6C,//top-right
- 0x0000001F18181818,0x0000007F606F6C6C,//top-left
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0000000000000000,
- 0x0000000000000000,0x0008000000000000,//
- 0x0000000000000000,0x00180018183C3C18,// !
- 0x0000000000363636,0x006C6CFE6CFE6C6C,//"#
- 0x00187ED07C16FC30,0x0060660C18306606,//$%
- 0x00DC66B61C36361C,0x0000000000181818,//&'
- 0x0030180C0C0C1830,0x000C18303030180C,//()
- 0x0000187E3C7E1800,0x000018187E181800,//*+
- 0x0C18180000000000,0x000000007E000000,//,-
- 0x0018180000000000,0x0000060C18306000,//./
- 0x003C666E7E76663C,0x007E181818181C18,//01
- 0x007E0C183060663C,0x003C66603860663C,//23
- 0x0030307E363C3830,0x003C6660603E067E,//45
- 0x003C66663E060C38,0x000C0C0C1830607E,//67
- 0x003C66663C66663C,0x001C30607C66663C,//89
- 0x0018180018180000,0x0C18180018180000,//:;
- 0x0030180C060C1830,0x0000007E007E0000,//<=
- 0x000C18306030180C,0x001800181830663C,//>?
- 0x003C06765676663C,0x006666667E66663C,//@A
- 0x003E66663E66663E,0x003C66060606663C,//BC
- 0x001E36666666361E,0x007E06063E06067E,//DE
- 0x000606063E06067E,0x003C66667606663C,//FG
- 0x006666667E666666,0x007E18181818187E,//HI
- 0x001C36303030307C,0x0066361E0E1E3666,//JK
- 0x007E060606060606,0x00C6C6D6D6FEEEC6,//LM
- 0x006666767E6E6666,0x003C66666666663C,//NO
- 0x000606063E66663E,0x006C36566666663C,//PQ
- 0x006666363E66663E,0x003C66603C06663C,//RS
- 0x001818181818187E,0x003C666666666666,//TU
- 0x00183C6666666666,0x00C6EEFED6D6C6C6,//VW
- 0x0066663C183C6666,0x001818183C666666,//XY
- 0x007E060C1830607E,0x003E06060606063E,//Z[
- 0x00006030180C0600,0x007C60606060607C,//\]
- 0x000000000000663C,0xFFFF000000000000,//^_
- 0x000000000030180C,0x007C667C603C0000,//`a
- 0x003E6666663E0606,0x003C6606663C0000,//bc
- 0x007C6666667C6060,0x003C067E663C0000,//de
- 0x000C0C0C3E0C0C38,0x3C607C66667C0000,//fg
- 0x00666666663E0606,0x003C1818181C0018,//hi
- 0x0E181818181C0018,0x0066361E36660606,//jk
- 0x003C18181818181C,0x00C6D6D6FE6C0000,//lm
- 0x00666666663E0000,0x003C6666663C0000,//no
- 0x06063E66663E0000,0xE0607C66667C0000,//pq
- 0x000606066E360000,0x003E603C067C0000,//rs
- 0x00380C0C0C3E0C0C,0x007C666666660000,//tu
- 0x00183C6666660000,0x006CFED6D6C60000,//vw
- 0x00663C183C660000,0x3C607C6666660000,//xy
- 0x007E0C18307E0000,0x003018180E181830,//z{
- 0x0018181818181818,0x000C18187018180C,//|}
- 0x000000000062D68C,0xFFFFFFFFFFFFFFFF,//~
- 0x1E30181E3303331E,0x007E333333003300,
- 0x001E033F331E0038,0x00FC667C603CC37E,
- 0x007E333E301E0033,0x007E333E301E0007,
- 0x007E333E301E0C0C,0x3C603E03033E0000,
- 0x003C067E663CC37E,0x001E033F331E0033,
- 0x001E033F331E0007,0x001E0C0C0C0E0033,
- 0x003C1818181C633E,0x001E0C0C0C0E0007,
- 0x00333F33331E0C33,0x00333F331E000C0C,
- 0x003F061E063F0038,0x00FE33FE30FE0000,
- 0x007333337F33367C,0x001E33331E00331E,
- 0x001E33331E003300,0x001E33331E000700,
- 0x007E33333300331E,0x007E333333000700,
- 0x1F303F3333003300,0x001C3E63633E1C63,
- 0x001E333333330033,0x18187E03037E1818,
- 0x003F67060F26361C,0x000C3F0C3F1E3333,
- 0x70337B332F1B1B0F,0x0E1B18187E18D870,
- 0x007E333E301E0038,0x001E0C0C0C0E001C,
- 0x001E33331E003800,0x007E333333003800,
- 0x003333331F001F00,0x00333B3F3733003F,
- 0x00007E007C36363C,0x00007E003C66663C,
- 0x001E3303060C000C,0x000003033F000000,
- 0x000030303F000000,0xF81973C67C1B3363,
- 0xC0F9F3E6CF1B3363,0x183C3C1818001800,
- 0x0000CC663366CC00,0x00003366CC663300,
- 0x1144114411441144,0x55AA55AA55AA55AA,
- 0xEEBBEEBBEEBBEEBB,0x1818181818181818,
- 0x1818181F18181818,0x1818181F181F1818,
- 0x6C6C6C6F6C6C6C6C,0x6C6C6C7F00000000,
- 0x1818181F181F0000,0x6C6C6C6F606F6C6C,
- 0x6C6C6C6C6C6C6C6C,0x6C6C6C6F607F0000,
- 0x0000007F606F6C6C,0x0000007F6C6C6C6C,
- 0x0000001F181F1818,0x1818181F00000000,
- 0x000000F818181818,0x000000FF18181818,
- 0x181818FF00000000,0x181818F818181818,
- 0x000000FF00000000,0x181818FF18181818,
- 0x181818F818F81818,0x6C6C6CEC6C6C6C6C,
- 0x000000FC0CEC6C6C,0x6C6C6CEC0CFC0000,
- 0x000000FF00EF6C6C,0x6C6C6CEF00FF0000,
- 0x6C6C6CEC0CEC6C6C,0x000000FF00FF0000,
- 0x6C6C6CEF00EF6C6C,0x000000FF00FF1818,
- 0x000000FF6C6C6C6C,0x181818FF00FF0000,
- 0x6C6C6CFF00000000,0x000000FC6C6C6C6C,
- 0x000000F818F81818,0x181818F818F80000,
- 0x6C6C6CFC00000000,0x6C6C6CEF6C6C6C6C,
- 0x181818FF00FF1818,0x0000001F18181818,
- 0x181818F800000000,0xFFFFFFFFFFFFFFFF,
- 0xFFFFFFFF00000000,0x0F0F0F0F0F0F0F0F,
- 0xF0F0F0F0F0F0F0F0,0x00000000FFFFFFFF,
- 0x006E3B133B6E0000,0x03031F331F331E00,
- 0x0003030303637F00,0x0036363636367F00,
- 0x007F660C180C667F,0x001E3333337E0000,
- 0x03063E6666666600,0x00181818183B6E00,
- 0x3F0C1E33331E0C3F,0x001C36637F63361C,
- 0x007736366363361C,0x001E33333E180C38,
- 0x00007EDBDB7E0000,0x03067EDBDB7E3060,
- 0x003C06033F03063C,0x003333333333331E,
- 0x00003F003F003F00,0x003F000C0C3F0C0C,
- 0x003F00060C180C06,0x003F00180C060C18,
- 0x1818181818D8D870,0x0E1B1B1818181818,
- 0x000C0C003F000C0C,0x0000394E00394E00,
- 0x000000001C36361C,0x0000001818000000,
- 0x0000001800000000,0x383C3637303030F0,
- 0x000000363636361E,0x0000003E061C301E,
- 0x00003C3C3C3C0000,0xFFFFFFFFFFFFFFFF,
-};