Skip to content

Instantly share code, notes, and snippets.

@ao-kenji
Created August 31, 2014 11:41
Show Gist options
  • Save ao-kenji/85fb643192df02516465 to your computer and use it in GitHub Desktop.
Save ao-kenji/85fb643192df02516465 to your computer and use it in GitHub Desktop.
yaft ( http://uobikiemukot.github.io/yaft/ ) on OpenBSD/sparc64 (with creator(4) frame buffer).
diff --git a/fb/openbsd.h b/fb/openbsd.h
index 05903c6..6938097 100644
--- a/fb/openbsd.h
+++ b/fb/openbsd.h
@@ -14,6 +14,7 @@ typedef unsigned long u_long;
#include <dev/wscons/wsksymdef.h>
/* some structs for OpenBSD */
+/* XXX: actually not used in OpenBSD/sparc64 */
enum term_size {
TERM_WIDTH = 640,
TERM_HEIGHT = 480,
@@ -52,6 +53,7 @@ struct framebuffer {
long screen_size; /* screen data size (byte) */
int line_length; /* line length (byte) */
int bytes_per_pixel; /* BYTES per pixel */
+ int mode_org; /* original framebuffer mode */
struct wsdisplay_cmap /* cmap for legacy framebuffer (8bpp pseudocolor) */
*cmap, *cmap_org;
struct fbinfo_t vinfo;
@@ -67,9 +69,15 @@ const struct fbinfo_t bpp_table[] = {
[BPP24] = {.red = {.offset = 16, .length = 8},
.green = {.offset = 8, .length = 8},
.blue = {.offset = 0, .length = 8}},
+#if 0
[BPP32] = {.red = {.offset = 16, .length = 8},
.green = {.offset = 8, .length = 8},
.blue = {.offset = 0, .length = 8}},
+#else /* Sun frame buffer uses BGR layout */
+ [BPP32] = {.red = {.offset = 0, .length = 8},
+ .green = {.offset = 8, .length = 8},
+ .blue = {.offset = 16, .length = 8}},
+#endif
};
/* common functions */
@@ -169,7 +177,7 @@ static inline uint32_t color2pixel(struct fbinfo_t *vinfo, uint32_t color)
void fb_init(struct framebuffer *fb, uint32_t *color_palette)
{
- int i, orig_mode, mode;
+ int i, mode;
char *path, *env;
struct wsdisplay_fbinfo finfo;
struct wsdisplay_gfx_mode gfx_mode;
@@ -179,14 +187,16 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
else
fb->fd = eopen(fb_path, O_RDWR);
- ioctl(fb->fd, WSDISPLAYIO_GMODE, &orig_mode);
+ ioctl(fb->fd, WSDISPLAYIO_GMODE, &(fb->mode_org));
gfx_mode.width = TERM_WIDTH;
gfx_mode.height = TERM_HEIGHT;
gfx_mode.depth = DEPTH;
+#if 0 /* OpenBSD/sparc64 does not support this ioctl. */
if(ioctl(fb->fd, WSDISPLAYIO_SETGFXMODE, &gfx_mode))
fatal("ioctl: WSDISPLAYIO_SETGFXMODE failed");
+#endif
mode = WSDISPLAYIO_MODE_DUMBFB;
if (ioctl(fb->fd, WSDISPLAYIO_SMODE, &mode))
@@ -197,24 +207,48 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
goto fb_init_error;
}
+#if 0
fb->width = TERM_WIDTH;
fb->height = TERM_HEIGHT;
fb->bytes_per_pixel = my_ceil(DEPTH, BITS_PER_BYTE);
+#else
+ fb->width = finfo.width;
+ fb->height = finfo.height;
+ fb->bytes_per_pixel = my_ceil(finfo.depth, BITS_PER_BYTE);
+#endif
+#if 0
fb->line_length = fb->bytes_per_pixel * fb->width;
fb->screen_size = fb->height * fb->line_length;
fb->vinfo = bpp_table[DEPTH];
+#else
+ if (ioctl(fb->fd, WSDISPLAYIO_LINEBYTES, &(fb->line_length))) {
+ fatal("ioctl: WSDISPLAYIO_LINEBYTES failed");
+ goto fb_init_error;
+ }
+ fb->screen_size = fb->height * fb->line_length;
+ fb->vinfo = bpp_table[finfo.depth];
+#endif
if (DEBUG)
fprintf(stderr, "cmsize:%d depth:%d width:%d height:%d line_length:%d\n",
finfo.cmsize, DEPTH, TERM_WIDTH, TERM_HEIGHT, fb->line_length);
+#if 0
if (DEPTH == 15 || DEPTH == 16
|| DEPTH == 24 || DEPTH == 32) {
+#else
+ if (finfo.depth == 15 || finfo.depth == 16
+ || finfo.depth == 24 || finfo.depth == 32) {
+#endif
fb->cmap = fb->cmap_org = NULL;
fb->vinfo.fbtype = FBTYPE_RGB;
}
+#if 0
else if (DEPTH == 8) {
+#else
+ else if (finfo.depth == 8) {
+#endif
cmap_create(&fb->cmap, COLORS);
cmap_create(&fb->cmap_org, finfo.cmsize);
cmap_init(fb);
@@ -233,12 +267,26 @@ void fb_init(struct framebuffer *fb, uint32_t *color_palette)
if (((env = getenv("YAFT")) != NULL) && (strstr(env, "wall") != NULL))
fb->wall = load_wallpaper(fb);
else
+#if 0
+ fb->wall = NULL;
+#else
+ {
fb->wall = NULL;
+ /*
+ * Clear whole screen when we do not use the wallpaper.
+ * Because if (fb->height % CELL_HEIGHT != 0), we do not touch
+ * that surplus (most downside) area from now.
+ * So it is better to erase the previous garbage image.
+ * XXX: Is '0' appropriate value?
+ */
+ memset(fb->fp, 0, fb->screen_size);
+ }
+#endif
return;
fb_init_error:
- ioctl(fb->fd, WSDISPLAYIO_SMODE, &orig_mode);
+ ioctl(fb->fd, WSDISPLAYIO_SMODE, &(fb->mode_org));
exit(EXIT_FAILURE);
}
@@ -252,5 +300,7 @@ void fb_die(struct framebuffer *fb)
free(fb->buf);
free(fb->wall);
emunmap(fb->fp, fb->screen_size);
+ if (ioctl(fb->fd, WSDISPLAYIO_SMODE, &(fb->mode_org)))
+ fatal("ioctl: WSDISPLAYIO_SMODE failed");
eclose(fb->fd);
}
diff --git a/yaft.c b/yaft.c
index 6068da2..dcf6559 100644
--- a/yaft.c
+++ b/yaft.c
@@ -75,11 +75,13 @@ void tty_init(struct termios *save_tm)
vtm.mode = VT_PROCESS;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = SIGUSR1;
+#if 0 /* OpenBSD/sparc64 does not support these ioctl's */
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);
@@ -100,8 +102,10 @@ void tty_die(struct termios *save_tm)
vtm.mode = VT_AUTO;
vtm.waitv = 0;
vtm.relsig = vtm.acqsig = vtm.frsig = 0;
+#if 0 /* OpenBSD/sparc64 does not support these ioctl's */
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