Skip to content

Instantly share code, notes, and snippets.

@ao-kenji
Created August 10, 2014 03:56
Show Gist options
  • Save ao-kenji/01e6cf6ed723ba094715 to your computer and use it in GitHub Desktop.
Save ao-kenji/01e6cf6ed723ba094715 to your computer and use it in GitHub Desktop.
yaft ( http://uobikiemukot.github.io/yaft/ ) on OpenBSD/luna88k, take 2. 8bpp version.
diff --git a/draw.h b/draw.h
index 9871ba3..9d69618 100644
--- a/draw.h
+++ b/draw.h
@@ -1,6 +1,8 @@
/* See LICENSE for licence details. */
static inline void draw_sixel(struct framebuffer *fb, int line, int col, uint8_t *bitmap)
{
+ /* XXX: Maybe need to re-write on LUNA */
+
int h, w, src_offset, dst_offset;
uint32_t pixel, color = 0;
@@ -16,16 +18,33 @@ static inline void draw_sixel(struct framebuffer *fb, int line, int col, uint8_t
}
}
+/* Based on OpenBSD:src/sys/arch/luna88k/dev/omrasops.c */
+
+#define ALL1BITS (~0U)
+#define BLITWIDTH (32)
+#define ALIGNMASK (0x1f)
+#define BYTESDONE (4)
+#define P0(addr) ((u_int32_t *)(addr))
+#define P1(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x40000))
+#define P2(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x80000))
+#define P3(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0xC0000))
+#define P4(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x100000))
+#define P5(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x140000))
+#define P6(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x180000))
+#define P7(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x1C0000))
+
static inline void draw_line(struct framebuffer *fb, struct terminal *term, int line)
{
- int pos, size, bdf_padding, glyph_width, margin_right;
- int col, w, h;
- uint32_t pixel;
+ int pos, size, col;
struct color_pair_t color_pair;
struct cell_t *cellp;
+ u_int8_t *p;
+ int x, y, width, height, align;
+ u_int32_t lmask, rmask, glyph, glyphbg, fgpat, bgpat;
+ int fg, bg, plane;
+
for (col = term->cols - 1; col >= 0; col--) {
- margin_right = (term->cols - 1 - col) * CELL_WIDTH;
/* target cell */
cellp = &term->cells[col + line * term->cols];
@@ -39,11 +58,16 @@ static inline void draw_line(struct framebuffer *fb, struct terminal *term, int
/* copy current color_pair (maybe changed) */
color_pair = cellp->color_pair;
+#if 0
/* check wide character or not */
glyph_width = (cellp->width == HALF) ? CELL_WIDTH: CELL_WIDTH * 2;
bdf_padding = my_ceil(glyph_width, BITS_PER_BYTE) * BITS_PER_BYTE - glyph_width;
if (cellp->width == WIDE)
bdf_padding += CELL_WIDTH;
+#endif
+ /* check wide character or not */
+ if (cellp->width == NEXT_TO_WIDE)
+ continue;
/* check cursor positon */
if ((term->mode & MODE_CURSOR && line == term->cursor.y)
@@ -54,40 +78,159 @@ static inline void draw_line(struct framebuffer *fb, struct terminal *term, int
color_pair.bg = (!tty.visible && BACKGROUND_DRAW) ? PASSIVE_CURSOR_COLOR: ACTIVE_CURSOR_COLOR;
}
- for (h = 0; h < CELL_HEIGHT; h++) {
- /* if UNDERLINE attribute on, swap bg/fg */
- if ((h == (CELL_HEIGHT - 1)) && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
- color_pair.bg = color_pair.fg;
-
- for (w = 0; w < CELL_WIDTH; w++) {
- pos = (term->width - 1 - margin_right - w) * fb->bytes_per_pixel
- + (line * CELL_HEIGHT + h) * fb->line_length;
-
- /* set color palette */
- if (cellp->glyphp->bitmap[h] & (0x01 << (bdf_padding + w)))
- pixel = term->color_palette[color_pair.fg];
- else if (fb->wall && color_pair.bg == DEFAULT_BG) /* wallpaper */
- memcpy(&pixel, fb->wall + pos, fb->bytes_per_pixel);
- else
- pixel = term->color_palette[color_pair.bg];
-
- /* update copy buffer only */
- memcpy(fb->buf + pos, &pixel, fb->bytes_per_pixel);
+ /* color palette */
+ fg = term->color_palette[color_pair.fg];
+ bg = term->color_palette[color_pair.bg];
+#if 0
+ if (fb->wall && color_pair.bg == DEFAULT_BG) /* wallpaper */
+ memcpy(&pixel, fb->wall + pos, fb->bytes_per_pixel);
+#endif
+
+ x = CELL_WIDTH * col;
+ y = CELL_HEIGHT * line;
+
+ p = (u_int8_t *)fb->buf + y * fb->line_length + ((x / 32) * 4);
+ align = x & ALIGNMASK;
+ width = cellp->glyphp->width * CELL_WIDTH + align;
+ lmask = ALL1BITS >> align;
+ rmask = ALL1BITS << (-width & ALIGNMASK);
+ height = 0;
+
+ if (width <= BLITWIDTH) {
+ lmask &= rmask;
+ while (height < CELL_HEIGHT) {
+ /* if UNDERLINE attribute on, swap bg/fg */
+ if ((height == (CELL_HEIGHT - 1))
+ && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
+ bg = fg;
+ glyph = (uint32_t)cellp->glyphp->bitmap[height];
+ /* shift leftmost */
+ glyph <<= 32 - cellp->glyphp->width * CELL_WIDTH;
+
+ glyph = glyph >> align;
+ glyphbg = glyph ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? glyph : 0;
+ bgpat = (bg & 0x01) ? glyphbg : 0;
+ *P0(p) = (*P0(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x02) ? glyph : 0;
+ bgpat = (bg & 0x02) ? glyphbg : 0;
+ *P1(p) = (*P1(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x04) ? glyph : 0;
+ bgpat = (bg & 0x04) ? glyphbg : 0;
+ *P2(p) = (*P2(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x08) ? glyph : 0;
+ bgpat = (bg & 0x08) ? glyphbg : 0;
+ *P3(p) = (*P3(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x10) ? glyph : 0;
+ bgpat = (bg & 0x10) ? glyphbg : 0;
+ *P4(p) = (*P4(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x20) ? glyph : 0;
+ bgpat = (bg & 0x20) ? glyphbg : 0;
+ *P5(p) = (*P5(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x40) ? glyph : 0;
+ bgpat = (bg & 0x40) ? glyphbg : 0;
+ *P6(p) = (*P6(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x80) ? glyph : 0;
+ bgpat = (bg & 0x80) ? glyphbg : 0;
+ *P7(p) = (*P7(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+
+ p += fb->line_length;
+ height++;
+ }
+ } else {
+ u_int8_t *q = p;
+ u_int32_t lhalf, rhalf;
+ u_int32_t lhalfbg, rhalfbg;
+
+ while (height < CELL_HEIGHT) {
+ /* if UNDERLINE attribute on, swap bg/fg */
+ if ((height == (CELL_HEIGHT - 1))
+ && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
+ bg = fg;
+ glyph = (uint32_t)cellp->glyphp->bitmap[height];
+ /* shift leftmost */
+ glyph <<= 32 - cellp->glyphp->width * CELL_WIDTH;
+
+ lhalf = glyph >> align;
+ lhalfbg = lhalf ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? lhalf : 0;
+ bgpat = (bg & 0x01) ? lhalfbg : 0;
+ *P0(p) = (*P0(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x02) ? lhalf : 0;
+ bgpat = (bg & 0x02) ? lhalfbg : 0;
+ *P1(p) = (*P1(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x04) ? lhalf : 0;
+ bgpat = (bg & 0x04) ? lhalfbg : 0;
+ *P2(p) = (*P2(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x08) ? lhalf : 0;
+ bgpat = (bg & 0x08) ? lhalfbg : 0;
+ *P3(p) = (*P3(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x10) ? lhalf : 0;
+ bgpat = (bg & 0x10) ? lhalfbg : 0;
+ *P4(p) = (*P4(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x20) ? lhalf : 0;
+ bgpat = (bg & 0x20) ? lhalfbg : 0;
+ *P5(p) = (*P5(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x40) ? lhalf : 0;
+ bgpat = (bg & 0x40) ? lhalfbg : 0;
+ *P6(p) = (*P6(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x80) ? lhalf : 0;
+ bgpat = (bg & 0x80) ? lhalfbg : 0;
+ *P7(p) = (*P7(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+
+ p += BYTESDONE;
+
+ rhalf = glyph << (BLITWIDTH - align);
+ rhalfbg = rhalf ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? rhalf : 0;
+ bgpat = (bg & 0x01) ? rhalfbg : 0;
+ *P0(p) = ((fgpat | bgpat) & rmask) | (*P0(p) & ~rmask);
+ fgpat = (fg & 0x02) ? rhalf : 0;
+ bgpat = (bg & 0x02) ? rhalfbg : 0;
+ *P1(p) = ((fgpat | bgpat) & rmask) | (*P1(p) & ~rmask);
+ fgpat = (fg & 0x04) ? rhalf : 0;
+ bgpat = (bg & 0x04) ? rhalfbg : 0;
+ *P2(p) = ((fgpat | bgpat) & rmask) | (*P2(p) & ~rmask);
+ fgpat = (fg & 0x08) ? rhalf : 0;
+ bgpat = (bg & 0x08) ? rhalfbg : 0;
+ *P3(p) = ((fgpat | bgpat) & rmask) | (*P3(p) & ~rmask);
+ fgpat = (fg & 0x10) ? rhalf : 0;
+ bgpat = (bg & 0x10) ? rhalfbg : 0;
+ *P4(p) = ((fgpat | bgpat) & rmask) | (*P4(p) & ~rmask);
+ fgpat = (fg & 0x20) ? rhalf : 0;
+ bgpat = (bg & 0x20) ? rhalfbg : 0;
+ *P5(p) = ((fgpat | bgpat) & rmask) | (*P5(p) & ~rmask);
+ fgpat = (fg & 0x40) ? rhalf : 0;
+ bgpat = (bg & 0x40) ? rhalfbg : 0;
+ *P6(p) = ((fgpat | bgpat) & rmask) | (*P6(p) & ~rmask);
+ fgpat = (fg & 0x80) ? rhalf : 0;
+ bgpat = (bg & 0x80) ? rhalfbg : 0;
+ *P7(p) = ((fgpat | bgpat) & rmask) | (*P7(p) & ~rmask);
+
+ p = (q += fb->line_length);
+ height++;
}
}
}
/* actual display update (bit blit) */
+#if 0
pos = (line * CELL_HEIGHT) * fb->line_length;
size = CELL_HEIGHT * fb->line_length;
memcpy(fb->fp + pos, fb->buf + pos, size);
-
- /* TODO: page flip
- if fb_fix_screeninfo.ypanstep > 0, we can use hardware panning.
- set fb_fix_screeninfo.{yres_virtual,yoffset} and call ioctl(FBIOPAN_DISPLAY)
- but drivers of recent hardware (inteldrmfb, nouveaufb, radeonfb) don't support...
- (we can use this by using libdrm)
- */
+#else
+ size = TERM_WIDTH / 8;
+ for (height = 0; height < CELL_HEIGHT; height++) {
+ for (plane = 0; plane < DEPTH; plane++) {
+ pos = (line * CELL_HEIGHT + height) * fb->line_length
+ + 0x40000 * plane;
+ memcpy(fb->fp + pos, fb->buf + pos, size);
+ }
+ }
+#endif
term->line_dirty[line] = ((term->mode & MODE_CURSOR) && term->cursor.y == line) ? true: false;
}
diff --git a/fb/openbsd.h b/fb/openbsd.h
index 5a11596..276f017 100644
--- a/fb/openbsd.h
+++ b/fb/openbsd.h
@@ -13,11 +13,17 @@ typedef unsigned long u_long;
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsksymdef.h>
-/* some structs for NetBSD */
+/* some structs for OpenBSD */
enum term_size {
+#if 0
TERM_WIDTH = 640,
TERM_HEIGHT = 480,
DEPTH = 8,
+#else
+ TERM_WIDTH = 1280,
+ TERM_HEIGHT = 1024,
+ DEPTH = 8,
+#endif
};
enum fbtype_t {
@@ -45,6 +51,7 @@ struct fbinfo_t {
struct framebuffer {
uint8_t *fp; /* pointer of framebuffer(read only) */
+ uint8_t *fp_orig; /* pointer of framebuffer(original) */
uint8_t *wall; /* buffer for wallpaper */
uint8_t *buf; /* copy of framebuffer */
int fd; /* file descriptor of framebuffer */
@@ -83,7 +90,7 @@ uint8_t *load_wallpaper(struct framebuffer *fb)
return ptr;
}
-/* some functions for NetBSD framebuffer */
+/* some functions for OpenBSD framebuffer */
void cmap_create(struct wsdisplay_cmap **cmap, int size)
{
*cmap = (struct wsdisplay_cmap *) ecalloc(1, sizeof(struct wsdisplay_cmap));
@@ -197,12 +204,19 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
goto fb_init_error;
}
+ /* XXX: Should be check if WSDISPLAYIO_TYPE_LUNA ? */
+
fb->width = TERM_WIDTH;
fb->height = TERM_HEIGHT;
fb->bytes_per_pixel = my_ceil(DEPTH, BITS_PER_BYTE);
+#if 0
fb->line_length = fb->bytes_per_pixel * fb->width;
fb->screen_size = fb->height * fb->line_length;
+#else
+ fb->line_length = 2048 / 8;
+ fb->screen_size = fb->height * fb->line_length * DEPTH;
+#endif
fb->vinfo = bpp_table[DEPTH];
if (DEBUG)
@@ -214,7 +228,7 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
fb->cmap = fb->cmap_org = NULL;
fb->vinfo.fbtype = FBTYPE_RGB;
}
- else if (DEPTH == 8) {
+ else if (DEPTH == 8 || DEPTH == 4 || DEPTH == 1 ) {
cmap_create(&fb->cmap, COLORS);
cmap_create(&fb->cmap_org, finfo.cmsize);
cmap_init(fb);
@@ -226,7 +240,10 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
for (i = 0; i < COLORS; i++) /* init color palette */
color_palette[i] = (fb->bytes_per_pixel == 1) ? (uint32_t) i: color2pixel(&fb->vinfo, color_list[i]);
- fb->fp = (uint8_t *) emmap(0, fb->screen_size, PROT_WRITE | PROT_READ, MAP_SHARED, fb->fd, 0);
+ fb->fp_orig = (uint8_t *) emmap(0, fb->screen_size, PROT_WRITE | PROT_READ, MAP_SHARED, fb->fd, 0);
+
+ fb->fp = fb->fp_orig + 8; /* XXX: LUNA quirk; need 8 byte offset */
+
fb->buf = (uint8_t *) ecalloc(1, fb->screen_size);
//fb->wall = (WALLPAPER && fb->bytes_per_pixel > 1) ? load_wallpaper(fb): NULL;
@@ -251,6 +268,6 @@ void fb_die(struct framebuffer *fb)
}
free(fb->buf);
free(fb->wall);
- emunmap(fb->fp, fb->screen_size);
+ emunmap(fb->fp_orig, fb->screen_size);
eclose(fb->fd);
}
diff --git a/makefile b/makefile
index caf405f..8fc5679 100644
--- a/makefile
+++ b/makefile
@@ -1,7 +1,8 @@
CC ?= gcc
#CC ?= clang
-CFLAGS ?= -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
+#CFLAGS ?= -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
+CFLAGS = -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
LDFLAGS ?=
XCFLAGS ?= -std=c99 -pedantic -Wall -Wextra -I/usr/include/X11/ -O3 -s -pipe
diff --git a/yaft.c b/yaft.c
index 9acbad6..cbeaf9f 100644
--- a/yaft.c
+++ b/yaft.c
@@ -77,11 +77,13 @@ void tty_init(struct termios *save_tm)
vtm.mode = VT_PROCESS;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = SIGUSR1;
+#if 0
if (ioctl(STDIN_FILENO, VT_SETMODE, &vtm))
fatal("ioctl: VT_SETMODE failed (maybe here is not console)");
if (ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS))
fatal("ioctl: KDSETMODE failed (maybe here is not console)");
+#endif
etcgetattr(STDIN_FILENO, save_tm);
set_rawmode(STDIN_FILENO, save_tm);
@@ -102,8 +104,10 @@ void tty_die(struct termios *save_tm)
vtm.mode = VT_AUTO;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = 0;
+#if 0
ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
ioctl(STDIN_FILENO, KDSETMODE, KD_TEXT);
+#endif
tcsetattr(STDIN_FILENO, TCSAFLUSH, save_tm);
fflush(stdout);
diff --git a/draw.h b/draw.h
index 9871ba3..b31bd02 100644
--- a/draw.h
+++ b/draw.h
@@ -1,6 +1,8 @@
/* See LICENSE for licence details. */
static inline void draw_sixel(struct framebuffer *fb, int line, int col, uint8_t *bitmap)
{
+ /* XXX: Maybe need to re-write on LUNA */
+
int h, w, src_offset, dst_offset;
uint32_t pixel, color = 0;
@@ -16,16 +18,33 @@ static inline void draw_sixel(struct framebuffer *fb, int line, int col, uint8_t
}
}
+/* Based on OpenBSD:src/sys/arch/luna88k/dev/omrasops.c */
+
+#define ALL1BITS (~0U)
+#define BLITWIDTH (32)
+#define ALIGNMASK (0x1f)
+#define BYTESDONE (4)
+#define P0(addr) ((u_int32_t *)(addr))
+#define P1(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x40000))
+#define P2(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x80000))
+#define P3(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0xC0000))
+#define P4(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x100000))
+#define P5(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x140000))
+#define P6(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x180000))
+#define P7(addr) ((u_int32_t *)((u_int8_t *)(addr) + 0x1C0000))
+
static inline void draw_line(struct framebuffer *fb, struct terminal *term, int line)
{
- int pos, size, bdf_padding, glyph_width, margin_right;
- int col, w, h;
- uint32_t pixel;
+ int pos, size, col, glyph_width, bdf_shift;
struct color_pair_t color_pair;
struct cell_t *cellp;
+ u_int8_t *p;
+ int x, y, width, height, align;
+ u_int32_t lmask, rmask, glyph, glyphbg, fgpat, bgpat;
+ int fg, bg, plane;
+
for (col = term->cols - 1; col >= 0; col--) {
- margin_right = (term->cols - 1 - col) * CELL_WIDTH;
/* target cell */
cellp = &term->cells[col + line * term->cols];
@@ -39,12 +58,19 @@ static inline void draw_line(struct framebuffer *fb, struct terminal *term, int
/* copy current color_pair (maybe changed) */
color_pair = cellp->color_pair;
+#if 0
/* check wide character or not */
glyph_width = (cellp->width == HALF) ? CELL_WIDTH: CELL_WIDTH * 2;
bdf_padding = my_ceil(glyph_width, BITS_PER_BYTE) * BITS_PER_BYTE - glyph_width;
if (cellp->width == WIDE)
bdf_padding += CELL_WIDTH;
+#endif
+ /* check wide character or not */
+ if (cellp->width == NEXT_TO_WIDE)
+ continue;
+ glyph_width = (cellp->width == HALF) ? CELL_WIDTH: CELL_WIDTH * 2;
+ bdf_shift = 32 - my_ceil(glyph_width, BITS_PER_BYTE) * BITS_PER_BYTE;
/* check cursor positon */
if ((term->mode & MODE_CURSOR && line == term->cursor.y)
&& (col == term->cursor.x
@@ -54,40 +80,159 @@ static inline void draw_line(struct framebuffer *fb, struct terminal *term, int
color_pair.bg = (!tty.visible && BACKGROUND_DRAW) ? PASSIVE_CURSOR_COLOR: ACTIVE_CURSOR_COLOR;
}
- for (h = 0; h < CELL_HEIGHT; h++) {
- /* if UNDERLINE attribute on, swap bg/fg */
- if ((h == (CELL_HEIGHT - 1)) && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
- color_pair.bg = color_pair.fg;
-
- for (w = 0; w < CELL_WIDTH; w++) {
- pos = (term->width - 1 - margin_right - w) * fb->bytes_per_pixel
- + (line * CELL_HEIGHT + h) * fb->line_length;
-
- /* set color palette */
- if (cellp->glyphp->bitmap[h] & (0x01 << (bdf_padding + w)))
- pixel = term->color_palette[color_pair.fg];
- else if (fb->wall && color_pair.bg == DEFAULT_BG) /* wallpaper */
- memcpy(&pixel, fb->wall + pos, fb->bytes_per_pixel);
- else
- pixel = term->color_palette[color_pair.bg];
-
- /* update copy buffer only */
- memcpy(fb->buf + pos, &pixel, fb->bytes_per_pixel);
+ /* color palette */
+ fg = term->color_palette[color_pair.fg];
+ bg = term->color_palette[color_pair.bg];
+#if 0
+ if (fb->wall && color_pair.bg == DEFAULT_BG) /* wallpaper */
+ memcpy(&pixel, fb->wall + pos, fb->bytes_per_pixel);
+#endif
+
+ x = CELL_WIDTH * col;
+ y = CELL_HEIGHT * line;
+
+ p = (u_int8_t *)fb->buf + y * fb->line_length + ((x / 32) * 4);
+ align = x & ALIGNMASK;
+ width = cellp->glyphp->width * CELL_WIDTH + align;
+ lmask = ALL1BITS >> align;
+ rmask = ALL1BITS << (-width & ALIGNMASK);
+ height = 0;
+
+ if (width <= BLITWIDTH) {
+ lmask &= rmask;
+ while (height < CELL_HEIGHT) {
+ /* if UNDERLINE attribute on, swap bg/fg */
+ if ((height == (CELL_HEIGHT - 1))
+ && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
+ bg = fg;
+ glyph = (uint32_t)cellp->glyphp->bitmap[height];
+ /* shift leftmost */
+ glyph <<= bdf_shift;
+
+ glyph = glyph >> align;
+ glyphbg = glyph ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? glyph : 0;
+ bgpat = (bg & 0x01) ? glyphbg : 0;
+ *P0(p) = (*P0(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x02) ? glyph : 0;
+ bgpat = (bg & 0x02) ? glyphbg : 0;
+ *P1(p) = (*P1(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x04) ? glyph : 0;
+ bgpat = (bg & 0x04) ? glyphbg : 0;
+ *P2(p) = (*P2(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x08) ? glyph : 0;
+ bgpat = (bg & 0x08) ? glyphbg : 0;
+ *P3(p) = (*P3(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x10) ? glyph : 0;
+ bgpat = (bg & 0x10) ? glyphbg : 0;
+ *P4(p) = (*P4(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x20) ? glyph : 0;
+ bgpat = (bg & 0x20) ? glyphbg : 0;
+ *P5(p) = (*P5(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x40) ? glyph : 0;
+ bgpat = (bg & 0x40) ? glyphbg : 0;
+ *P6(p) = (*P6(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x80) ? glyph : 0;
+ bgpat = (bg & 0x80) ? glyphbg : 0;
+ *P7(p) = (*P7(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+
+ p += fb->line_length;
+ height++;
+ }
+ } else {
+ u_int8_t *q = p;
+ u_int32_t lhalf, rhalf;
+ u_int32_t lhalfbg, rhalfbg;
+
+ while (height < CELL_HEIGHT) {
+ /* if UNDERLINE attribute on, swap bg/fg */
+ if ((height == (CELL_HEIGHT - 1))
+ && (cellp->attribute & attr_mask[ATTR_UNDERLINE]))
+ bg = fg;
+ glyph = (uint32_t)cellp->glyphp->bitmap[height];
+ /* shift leftmost */
+ glyph <<= bdf_shift;
+
+ lhalf = glyph >> align;
+ lhalfbg = lhalf ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? lhalf : 0;
+ bgpat = (bg & 0x01) ? lhalfbg : 0;
+ *P0(p) = (*P0(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x02) ? lhalf : 0;
+ bgpat = (bg & 0x02) ? lhalfbg : 0;
+ *P1(p) = (*P1(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x04) ? lhalf : 0;
+ bgpat = (bg & 0x04) ? lhalfbg : 0;
+ *P2(p) = (*P2(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x08) ? lhalf : 0;
+ bgpat = (bg & 0x08) ? lhalfbg : 0;
+ *P3(p) = (*P3(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x10) ? lhalf : 0;
+ bgpat = (bg & 0x10) ? lhalfbg : 0;
+ *P4(p) = (*P4(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x20) ? lhalf : 0;
+ bgpat = (bg & 0x20) ? lhalfbg : 0;
+ *P5(p) = (*P5(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x40) ? lhalf : 0;
+ bgpat = (bg & 0x40) ? lhalfbg : 0;
+ *P6(p) = (*P6(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+ fgpat = (fg & 0x80) ? lhalf : 0;
+ bgpat = (bg & 0x80) ? lhalfbg : 0;
+ *P7(p) = (*P7(p) & ~lmask) | ((fgpat | bgpat) & lmask);
+
+ p += BYTESDONE;
+
+ rhalf = glyph << (BLITWIDTH - align);
+ rhalfbg = rhalf ^ ALL1BITS;
+
+ fgpat = (fg & 0x01) ? rhalf : 0;
+ bgpat = (bg & 0x01) ? rhalfbg : 0;
+ *P0(p) = ((fgpat | bgpat) & rmask) | (*P0(p) & ~rmask);
+ fgpat = (fg & 0x02) ? rhalf : 0;
+ bgpat = (bg & 0x02) ? rhalfbg : 0;
+ *P1(p) = ((fgpat | bgpat) & rmask) | (*P1(p) & ~rmask);
+ fgpat = (fg & 0x04) ? rhalf : 0;
+ bgpat = (bg & 0x04) ? rhalfbg : 0;
+ *P2(p) = ((fgpat | bgpat) & rmask) | (*P2(p) & ~rmask);
+ fgpat = (fg & 0x08) ? rhalf : 0;
+ bgpat = (bg & 0x08) ? rhalfbg : 0;
+ *P3(p) = ((fgpat | bgpat) & rmask) | (*P3(p) & ~rmask);
+ fgpat = (fg & 0x10) ? rhalf : 0;
+ bgpat = (bg & 0x10) ? rhalfbg : 0;
+ *P4(p) = ((fgpat | bgpat) & rmask) | (*P4(p) & ~rmask);
+ fgpat = (fg & 0x20) ? rhalf : 0;
+ bgpat = (bg & 0x20) ? rhalfbg : 0;
+ *P5(p) = ((fgpat | bgpat) & rmask) | (*P5(p) & ~rmask);
+ fgpat = (fg & 0x40) ? rhalf : 0;
+ bgpat = (bg & 0x40) ? rhalfbg : 0;
+ *P6(p) = ((fgpat | bgpat) & rmask) | (*P6(p) & ~rmask);
+ fgpat = (fg & 0x80) ? rhalf : 0;
+ bgpat = (bg & 0x80) ? rhalfbg : 0;
+ *P7(p) = ((fgpat | bgpat) & rmask) | (*P7(p) & ~rmask);
+
+ p = (q += fb->line_length);
+ height++;
}
}
}
/* actual display update (bit blit) */
+#if 0
pos = (line * CELL_HEIGHT) * fb->line_length;
size = CELL_HEIGHT * fb->line_length;
memcpy(fb->fp + pos, fb->buf + pos, size);
-
- /* TODO: page flip
- if fb_fix_screeninfo.ypanstep > 0, we can use hardware panning.
- set fb_fix_screeninfo.{yres_virtual,yoffset} and call ioctl(FBIOPAN_DISPLAY)
- but drivers of recent hardware (inteldrmfb, nouveaufb, radeonfb) don't support...
- (we can use this by using libdrm)
- */
+#else
+ size = TERM_WIDTH / 8;
+ for (height = 0; height < CELL_HEIGHT; height++) {
+ for (plane = 0; plane < DEPTH; plane++) {
+ pos = (line * CELL_HEIGHT + height) * fb->line_length
+ + 0x40000 * plane;
+ memcpy(fb->fp + pos, fb->buf + pos, size);
+ }
+ }
+#endif
term->line_dirty[line] = ((term->mode & MODE_CURSOR) && term->cursor.y == line) ? true: false;
}
diff --git a/fb/openbsd.h b/fb/openbsd.h
index 5a11596..276f017 100644
--- a/fb/openbsd.h
+++ b/fb/openbsd.h
@@ -13,11 +13,17 @@ typedef unsigned long u_long;
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsksymdef.h>
-/* some structs for NetBSD */
+/* some structs for OpenBSD */
enum term_size {
+#if 0
TERM_WIDTH = 640,
TERM_HEIGHT = 480,
DEPTH = 8,
+#else
+ TERM_WIDTH = 1280,
+ TERM_HEIGHT = 1024,
+ DEPTH = 8,
+#endif
};
enum fbtype_t {
@@ -45,6 +51,7 @@ struct fbinfo_t {
struct framebuffer {
uint8_t *fp; /* pointer of framebuffer(read only) */
+ uint8_t *fp_orig; /* pointer of framebuffer(original) */
uint8_t *wall; /* buffer for wallpaper */
uint8_t *buf; /* copy of framebuffer */
int fd; /* file descriptor of framebuffer */
@@ -83,7 +90,7 @@ uint8_t *load_wallpaper(struct framebuffer *fb)
return ptr;
}
-/* some functions for NetBSD framebuffer */
+/* some functions for OpenBSD framebuffer */
void cmap_create(struct wsdisplay_cmap **cmap, int size)
{
*cmap = (struct wsdisplay_cmap *) ecalloc(1, sizeof(struct wsdisplay_cmap));
@@ -197,12 +204,19 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
goto fb_init_error;
}
+ /* XXX: Should be check if WSDISPLAYIO_TYPE_LUNA ? */
+
fb->width = TERM_WIDTH;
fb->height = TERM_HEIGHT;
fb->bytes_per_pixel = my_ceil(DEPTH, BITS_PER_BYTE);
+#if 0
fb->line_length = fb->bytes_per_pixel * fb->width;
fb->screen_size = fb->height * fb->line_length;
+#else
+ fb->line_length = 2048 / 8;
+ fb->screen_size = fb->height * fb->line_length * DEPTH;
+#endif
fb->vinfo = bpp_table[DEPTH];
if (DEBUG)
@@ -214,7 +228,7 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
fb->cmap = fb->cmap_org = NULL;
fb->vinfo.fbtype = FBTYPE_RGB;
}
- else if (DEPTH == 8) {
+ else if (DEPTH == 8 || DEPTH == 4 || DEPTH == 1 ) {
cmap_create(&fb->cmap, COLORS);
cmap_create(&fb->cmap_org, finfo.cmsize);
cmap_init(fb);
@@ -226,7 +240,10 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
for (i = 0; i < COLORS; i++) /* init color palette */
color_palette[i] = (fb->bytes_per_pixel == 1) ? (uint32_t) i: color2pixel(&fb->vinfo, color_list[i]);
- fb->fp = (uint8_t *) emmap(0, fb->screen_size, PROT_WRITE | PROT_READ, MAP_SHARED, fb->fd, 0);
+ fb->fp_orig = (uint8_t *) emmap(0, fb->screen_size, PROT_WRITE | PROT_READ, MAP_SHARED, fb->fd, 0);
+
+ fb->fp = fb->fp_orig + 8; /* XXX: LUNA quirk; need 8 byte offset */
+
fb->buf = (uint8_t *) ecalloc(1, fb->screen_size);
//fb->wall = (WALLPAPER && fb->bytes_per_pixel > 1) ? load_wallpaper(fb): NULL;
@@ -251,6 +268,6 @@ void fb_die(struct framebuffer *fb)
}
free(fb->buf);
free(fb->wall);
- emunmap(fb->fp, fb->screen_size);
+ emunmap(fb->fp_orig, fb->screen_size);
eclose(fb->fd);
}
diff --git a/makefile b/makefile
index caf405f..8fc5679 100644
--- a/makefile
+++ b/makefile
@@ -1,7 +1,8 @@
CC ?= gcc
#CC ?= clang
-CFLAGS ?= -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
+#CFLAGS ?= -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
+CFLAGS = -std=c99 -pedantic -Wall -Wextra -O3 -s -pipe
LDFLAGS ?=
XCFLAGS ?= -std=c99 -pedantic -Wall -Wextra -I/usr/include/X11/ -O3 -s -pipe
diff --git a/yaft.c b/yaft.c
index 9acbad6..cbeaf9f 100644
--- a/yaft.c
+++ b/yaft.c
@@ -77,11 +77,13 @@ void tty_init(struct termios *save_tm)
vtm.mode = VT_PROCESS;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = SIGUSR1;
+#if 0
if (ioctl(STDIN_FILENO, VT_SETMODE, &vtm))
fatal("ioctl: VT_SETMODE failed (maybe here is not console)");
if (ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS))
fatal("ioctl: KDSETMODE failed (maybe here is not console)");
+#endif
etcgetattr(STDIN_FILENO, save_tm);
set_rawmode(STDIN_FILENO, save_tm);
@@ -102,8 +104,10 @@ void tty_die(struct termios *save_tm)
vtm.mode = VT_AUTO;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = 0;
+#if 0
ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
ioctl(STDIN_FILENO, KDSETMODE, KD_TEXT);
+#endif
tcsetattr(STDIN_FILENO, TCSAFLUSH, save_tm);
fflush(stdout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment