Module Name:    src
Committed By:   tsutsui
Date:           Fri Jul 20 19:31:54 UTC 2012

Modified Files:
        src/sys/arch/luna68k/conf: GENERIC INSTALL
        src/sys/arch/luna68k/dev: lunafb.c omrasops.c
Added Files:
        src/sys/arch/luna68k/dev: omrasopsvar.h
Removed Files:
        src/sys/arch/luna68k/dev: omron_rfont.h

Log Message:
Switch luna68k wscons framebuffer driver to using rasops(9) APIs instead of
deprecated rcons(4).  This allows "options FONT_foo" in kernel config files.
Mostly taken from OpenBSD/luna88k, but unnecessary MI rasops(9) stuff is
omitted since omrasops.c has own raster wsdisplay_emulops functions.
Tested on LUNA with 4bpp fb and LUNA-II with 1bpp fb.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/luna68k/conf/GENERIC
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/luna68k/conf/INSTALL
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/luna68k/dev/lunafb.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/luna68k/dev/omrasops.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/luna68k/dev/omrasopsvar.h
cvs rdiff -u -r1.1 -r0 src/sys/arch/luna68k/dev/omron_rfont.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/luna68k/conf/GENERIC
diff -u src/sys/arch/luna68k/conf/GENERIC:1.98 src/sys/arch/luna68k/conf/GENERIC:1.99
--- src/sys/arch/luna68k/conf/GENERIC:1.98	Sat Mar 10 21:51:53 2012
+++ src/sys/arch/luna68k/conf/GENERIC	Fri Jul 20 19:31:53 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.98 2012/03/10 21:51:53 joerg Exp $
+# $NetBSD: GENERIC,v 1.99 2012/07/20 19:31:53 tsutsui Exp $
 #
 # GENERIC machine description file
 # 
@@ -22,7 +22,7 @@ include		"arch/luna68k/conf/std.luna68k"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.98 $"
+#ident 		"GENERIC-$Revision: 1.99 $"
 
 maxusers	8
 
@@ -137,6 +137,7 @@ options 	NFS_BOOT_DHCP	# superset of BOO
 
 # WS console uses SUN or VT100 terminal emulation
 options 	WSEMUL_VT100
+options 	FONT_OMRON12x20
 
 config		netbsd root on ? type ?
 

Index: src/sys/arch/luna68k/conf/INSTALL
diff -u src/sys/arch/luna68k/conf/INSTALL:1.5 src/sys/arch/luna68k/conf/INSTALL:1.6
--- src/sys/arch/luna68k/conf/INSTALL:1.5	Sat Mar 10 21:51:53 2012
+++ src/sys/arch/luna68k/conf/INSTALL	Fri Jul 20 19:31:53 2012
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL,v 1.5 2012/03/10 21:51:53 joerg Exp $
+# $NetBSD: INSTALL,v 1.6 2012/07/20 19:31:53 tsutsui Exp $
 #
 # config for installation ramdisk kernel
 # 
@@ -123,6 +123,7 @@ options 	NFS_BOOT_DHCP	# superset of BOO
 
 # WS console uses SUN or VT100 terminal emulation
 options 	WSEMUL_VT100
+options 	FONT_OMRON12x20
 
 config		netbsd root on ? type ?
 

Index: src/sys/arch/luna68k/dev/lunafb.c
diff -u src/sys/arch/luna68k/dev/lunafb.c:1.25 src/sys/arch/luna68k/dev/lunafb.c:1.26
--- src/sys/arch/luna68k/dev/lunafb.c:1.25	Wed Jul 27 14:17:54 2011
+++ src/sys/arch/luna68k/dev/lunafb.c	Fri Jul 20 19:31:53 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: lunafb.c,v 1.25 2011/07/27 14:17:54 tsutsui Exp $ */
+/* $NetBSD: lunafb.c,v 1.26 2012/07/20 19:31:53 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.25 2011/07/27 14:17:54 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.26 2012/07/20 19:31:53 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -47,14 +47,15 @@ __KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1
 
 #include <uvm/uvm_extern.h>
 
-#include <dev/rcons/raster.h>
 #include <dev/wscons/wsconsio.h>
-#include <dev/wscons/wscons_raster.h>
 #include <dev/wscons/wsdisplayvar.h>
+#include <dev/rasops/rasops.h>
 
 #include <machine/cpu.h>
 #include <machine/autoconf.h>
 
+#include <arch/luna68k/dev/omrasopsvar.h>
+
 #include "ioconf.h"
 
 struct bt454 {
@@ -88,8 +89,7 @@ struct om_hwdevconfig {
 	int	dc_rowbytes;		/* bytes in a FB scan line */
 	int	dc_cmsize;		/* colormap size */
 	vaddr_t	dc_videobase;		/* base of flat frame buffer */
-	struct raster	dc_raster;	/* raster description */
-	struct rcons	dc_rcons;	/* raster blitter control info */
+	struct rasops_info dc_ri;	/* raster blitter variables */
 };
 
 struct hwcmap {
@@ -112,13 +112,8 @@ static int  omsetcmap(struct omfb_softc 
 static struct om_hwdevconfig omfb_console_dc;
 static void omfb_getdevconfig(paddr_t, struct om_hwdevconfig *);
 
-extern struct wsdisplay_emulops omfb_emulops;
-
 static struct wsscreen_descr omfb_stdscreen = {
-	"std", 0, 0,
-	&omfb_emulops,
-	0, 0,
-	0
+	.name = "std"
 };
 
 static const struct wsscreen_descr *_omfb_scrlist[] = {
@@ -187,7 +182,7 @@ omfbattach(device_t parent, device_t sel
 		sc->nscreens = 1;
 	} else {
 		sc->sc_dc = malloc(sizeof(struct om_hwdevconfig),
-		    M_DEVBUF, M_WAITOK);
+		    M_DEVBUF, M_WAITOK | M_ZERO);
 		omfb_getdevconfig(OMFB_FB_WADDR, sc->sc_dc);
 	}
 	aprint_normal(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
@@ -209,11 +204,12 @@ omfbattach(device_t parent, device_t sel
 omfb_cnattach(void)
 {
 	struct om_hwdevconfig *dc = &omfb_console_dc;
+	struct rasops_info *ri = &dc->dc_ri;
 	long defattr;
 
 	omfb_getdevconfig(OMFB_FB_WADDR, dc);
-	(*omfb_emulops.allocattr)(&dc->dc_rcons, 0, 0, 0, &defattr);
-	wsdisplay_cnattach(&omfb_stdscreen, &dc->dc_rcons, 0, 0, defattr);
+	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
+	wsdisplay_cnattach(&omfb_stdscreen, ri, 0, 0, defattr);
 	omfb_console = 1;
 	return 0;
 }
@@ -350,8 +346,7 @@ static void
 omfb_getdevconfig(paddr_t paddr, struct om_hwdevconfig *dc)
 {
 	int bpp, i;
-	struct raster *rap;
-	struct rcons *rcp;
+	struct rasops_info *ri;
 	union {
 		struct { short h, v; } p;
 		uint32_t u;
@@ -415,7 +410,7 @@ omfb_getdevconfig(paddr_t paddr, struct 
 		}
 	}
 
-	/* adjust h/v orgin on screen */
+	/* adjust h/v origin on screen */
 	rfcnt.p.h = 7;
 	rfcnt.p.v = -27;
 	/* single write of 0x007ffe6 */
@@ -424,28 +419,29 @@ omfb_getdevconfig(paddr_t paddr, struct 
 	/* clear the screen */
 	*(volatile uint32_t *)OMFB_PLANEMASK = 0xff;
 	((volatile uint32_t *)OMFB_ROPFUNC)[5] = ~0;	/* ROP copy */
-	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes/sizeof(uint32_t); i++)
+	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes / sizeof(uint32_t); i++)
 		*((volatile uint32_t *)dc->dc_videobase + i) = 0;
 	*(volatile uint32_t *)OMFB_PLANEMASK = 0x01;
 
 	/* initialize the raster */
-	rap = &dc->dc_raster;
-	rap->width = dc->dc_wid;
-	rap->height = dc->dc_ht;
-	rap->depth = dc->dc_depth;
-	rap->linelongs = dc->dc_rowbytes / sizeof(uint32_t);
-	rap->pixels = (uint32_t *)dc->dc_videobase;
-
-	/* initialize the raster console blitter */
-	rcp = &dc->dc_rcons;
-	rcp->rc_sp = rap;
-	rcp->rc_crow = rcp->rc_ccol = -1;
-	rcp->rc_crowp = &rcp->rc_crow;
-	rcp->rc_ccolp = &rcp->rc_ccol;
-	rcons_init(rcp, 34, 80);
-
-	omfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
-	omfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
+	ri = &dc->dc_ri;
+	ri->ri_width = dc->dc_wid;
+	ri->ri_height = dc->dc_ht;
+	ri->ri_depth = 1;       /* since planes are independently addressed */
+	ri->ri_stride = dc->dc_rowbytes;
+	ri->ri_bits = (void *)dc->dc_videobase;
+	ri->ri_flg = RI_CENTER;
+	if (dc == &omfb_console_dc)
+		ri->ri_flg |= RI_NO_AUTO;
+	ri->ri_hw = dc;
+
+	omrasops_init(ri, 34, 80);
+
+	omfb_stdscreen.nrows = ri->ri_rows;
+	omfb_stdscreen.ncols = ri->ri_cols;
+	omfb_stdscreen.textops = &ri->ri_ops;
+	omfb_stdscreen.fontwidth = ri->ri_font->fontwidth;
+	omfb_stdscreen.fontheight = ri->ri_font->fontheight;
 }
 
 static int
@@ -453,16 +449,15 @@ omfb_alloc_screen(void *v, const struct 
     int *curxp, int *curyp, long *attrp)
 {
 	struct omfb_softc *sc = v;
-	long defattr;
+	struct rasops_info *ri = &sc->sc_dc->dc_ri;
 
 	if (sc->nscreens > 0)
 		return ENOMEM;
 
-	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
+	*cookiep = ri;
 	*curxp = 0;
 	*curyp = 0;
-	(*omfb_emulops.allocattr)(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
-	*attrp = defattr;
+	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, attrp);
 	sc->nscreens++;
 	return 0;
 }

Index: src/sys/arch/luna68k/dev/omrasops.c
diff -u src/sys/arch/luna68k/dev/omrasops.c:1.12 src/sys/arch/luna68k/dev/omrasops.c:1.13
--- src/sys/arch/luna68k/dev/omrasops.c:1.12	Mon Jul 16 11:41:05 2012
+++ src/sys/arch/luna68k/dev/omrasops.c	Fri Jul 20 19:31:53 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: omrasops.c,v 1.12 2012/07/16 11:41:05 tsutsui Exp $ */
+/* $NetBSD: omrasops.c,v 1.13 2012/07/20 19:31:53 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.12 2012/07/16 11:41:05 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.13 2012/07/20 19:31:53 tsutsui Exp $");
 
 /*
  * Designed speficically for 'm68k bitorder';
@@ -42,22 +42,15 @@ __KERNEL_RCSID(0, "$NetBSD: omrasops.c,v
  *	- font glyphs are stored in 32bit padded.
  */
 
-#define USE_OMRONFONT
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
 
-#include <dev/rcons/raster.h>
-#include <dev/wscons/wscons_raster.h>
-#ifndef USE_OMRONFONT
-#include <dev/wscons/wscons_rfont.h>
-#else
-#include <arch/luna68k/dev/omron_rfont.h>
-#endif
+#include <dev/wscons/wsconsio.h>
 #include <dev/wscons/wsdisplayvar.h>
+#include <dev/rasops/rasops.h>
 
-void rcons_init(struct rcons *, int, int);
+#include <arch/luna68k/dev/omrasopsvar.h>
 
 /* wscons emulator operations */
 static void	om_cursor(void *, int, int, int);
@@ -69,17 +62,6 @@ static void	om_erasecols(void *, int, in
 static void	om_eraserows(void *, int, int, long);
 static int	om_allocattr(void *, int, int, int, long *);
 
-struct wsdisplay_emulops omfb_emulops = {
-	om_cursor,
-	om_mapchar,
-	om_putchar,
-	om_copycols,
-	om_erasecols,
-	om_copyrows,
-	om_eraserows,
-	om_allocattr
-};
-
 #define	ALL1BITS	(~0U)
 #define	ALL0BITS	(0U)
 #define	BLITWIDTH	(32)
@@ -95,33 +77,36 @@ struct wsdisplay_emulops omfb_emulops = 
 static void
 om_putchar(void *cookie, int row, int startcol, u_int uc, long attr)
 {
-	struct rcons *rc = cookie;
-	struct raster *rap = rc->rc_sp;
+	struct rasops_info *ri = cookie;
 	uint8_t *p;
 	int scanspan, startx, height, width, align, y;
 	uint32_t lmask, rmask, glyph, inverse;
-	uint32_t *g;
+	int i;
+	uint8_t *fb;
 
-	scanspan = rap->linelongs * 4;
-	y = rc->rc_yorigin + rc->rc_font->height * row;
-	startx = rc->rc_xorigin + rc->rc_font->width * startcol;
-	height = rc->rc_font->height;
-	g = rc->rc_font->chars[uc].r->pixels;
+	scanspan = ri->ri_stride;
+	y = ri->ri_font->fontheight * row;
+	startx = ri->ri_font->fontwidth * startcol;
+	height = ri->ri_font->fontheight;
+	fb = (uint8_t *)ri->ri_font->data +
+	    (uc - ri->ri_font->firstchar) * ri->ri_fontscale;
 	inverse = (attr != 0) ? ALL1BITS : ALL0BITS;
 
-	p = (uint8_t *)rap->pixels + y * scanspan + ((startx / 32) * 4);
+	p = (uint8_t *)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
 	align = startx & ALIGNMASK;
-	width = rc->rc_font->width + align;
+	width = ri->ri_font->fontwidth + align;
 	lmask = ALL1BITS >> align;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	if (width <= BLITWIDTH) {
 		lmask &= rmask;
 		while (height > 0) {
-			glyph = *g;
+			glyph = 0;
+			for (i = ri->ri_font->stride; i != 0; i--)
+				glyph = (glyph << 8) | *fb++;
+			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			glyph = (glyph >> align) ^ inverse;
 			W(p) = (R(p) & ~lmask) | (glyph & lmask);
 			p += scanspan;
-			g += 1;
 			height--;
 		}
 	} else {
@@ -129,7 +114,10 @@ om_putchar(void *cookie, int row, int st
 		uint32_t lhalf, rhalf;
 
 		while (height > 0) {
-			glyph = *g;
+			glyph = 0;
+			for (i = ri->ri_font->stride; i != 0; i--)
+				glyph = (glyph << 8) | *fb++;
+			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			lhalf = (glyph >> align) ^ inverse;
 			W(p) = (R(p) & ~lmask) | (lhalf & lmask);
 			p += BYTESDONE;
@@ -137,7 +125,6 @@ om_putchar(void *cookie, int row, int st
 			W(p) = (rhalf & rmask) | (R(p) & ~rmask);
 
 			p = (q += scanspan);
-			g += 1;
 			height--;
 		}
 	}
@@ -146,20 +133,20 @@ om_putchar(void *cookie, int row, int st
 static void
 om_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
 {
-        struct rcons *rc = cookie;
-        struct raster *rap = rc->rc_sp;
-        uint8_t *p;
-        int scanspan, startx, height, width, align, w, y;
-        uint32_t lmask, rmask, fill;
-
-        scanspan = rap->linelongs * 4;
-        y = rc->rc_yorigin + rc->rc_font->height * row;
-        startx = rc->rc_xorigin + rc->rc_font->width * startcol;
-        height = rc->rc_font->height;
-        w = rc->rc_font->width * ncols;
+	struct rasops_info *ri = cookie;
+	uint8_t *p;
+	int scanspan, startx, height, width, align, w, y;
+	uint32_t lmask, rmask, fill;
+
+	scanspan = ri->ri_stride;;
+	fill = (attr != 0) ? ALL1BITS : ALL0BITS;
+	y = ri->ri_font->fontheight * row;
+	startx = ri->ri_font->fontwidth * startcol;
+	height = ri->ri_font->fontheight;
+	w = ri->ri_font->fontwidth * ncols;
 	fill = (attr != 0) ? ALL1BITS : ALL0BITS;
 
-	p = (uint8_t *)rap->pixels + y * scanspan + ((startx / 32) * 4);
+	p = (uint8_t *)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
 	align = startx & ALIGNMASK;
 	width = w + align;
 	lmask = ALL1BITS >> align;
@@ -195,22 +182,20 @@ om_erasecols(void *cookie, int row, int 
 static void
 om_eraserows(void *cookie, int startrow, int nrows, long attr)
 {
-	struct rcons *rc = cookie;
-	struct raster *rap = rc->rc_sp;
+	struct rasops_info *ri = cookie;
 	uint8_t *p, *q;
 	int scanspan, starty, height, width, w;
 	uint32_t rmask, fill;
 
-	scanspan = rap->linelongs * 4;
-	starty = rc->rc_yorigin + rc->rc_font->height * startrow;
-	height = rc->rc_font->height * nrows;
-	w = rc->rc_font->width * rc->rc_maxcol;
-	fill = (attr == 1) ? ALL1BITS : ALL0BITS;
+	scanspan = ri->ri_stride;
+	starty = ri->ri_font->fontheight * startrow;
+	height = ri->ri_font->fontheight * nrows;
+	w = ri->ri_emuwidth;
+	fill = (attr != 0) ? ALL1BITS : ALL0BITS;
 
-	p = (uint8_t *)rap->pixels + starty * scanspan;
-	p += (rc->rc_xorigin / 32) * 4;
+	p = (uint8_t *)ri->ri_bits + starty * scanspan;
 	width = w;
-        rmask = ALL1BITS << (-width & ALIGNMASK);
+	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
 	while (height > 0) {
 		W(p) = fill;				/* always aligned */
@@ -231,24 +216,22 @@ om_eraserows(void *cookie, int startrow,
 static void
 om_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
 {
-        struct rcons *rc = cookie;
-        struct raster *rap = rc->rc_sp;
-        uint8_t *p, *q;
+	struct rasops_info *ri = cookie;
+	uint8_t *p, *q;
 	int scanspan, offset, srcy, height, width, w;
-        uint32_t rmask;
-        
-	scanspan = rap->linelongs * 4;
-	height = rc->rc_font->height * nrows;
-	offset = (dstrow - srcrow) * scanspan * rc->rc_font->height;
-	srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
+	uint32_t rmask;
+
+	scanspan = ri->ri_stride;
+	height = ri->ri_font->fontheight * nrows;
+	offset = (dstrow - srcrow) * scanspan * ri->ri_font->fontheight;
+	srcy = ri->ri_font->fontheight * srcrow;
 	if (srcrow < dstrow && srcrow + nrows > dstrow) {
 		scanspan = -scanspan;
 		srcy += height;
 	}
 
-	p = (uint8_t *)rap->pixels + srcy * (rap->linelongs * 4);
-	p += (rc->rc_xorigin / 32) * 4;
-	w = rc->rc_font->width * rc->rc_maxcol;
+	p = (uint8_t *)ri->ri_bits + srcy * ri->ri_stride;
+	w = ri->ri_emuwidth;
 	width = w;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
@@ -272,26 +255,25 @@ om_copyrows(void *cookie, int srcrow, in
 static void
 om_copycols(void *cookie, int startrow, int srccol, int dstcol, int ncols)
 {
-	struct rcons *rc = cookie;
-	struct raster *rap = rc->rc_sp;
+	struct rasops_info *ri = cookie;
 	uint8_t *sp, *dp, *basep;
 	int scanspan, height, width, align, shift, w, y, srcx, dstx;
 	uint32_t lmask, rmask;
 
-	scanspan = rap->linelongs * 4;
-	y = rc->rc_yorigin + rc->rc_font->height * startrow;
-	srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
-	dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
-	height = rc->rc_font->height;
-	w = rc->rc_font->width * ncols;
-	basep = (uint8_t *)rap->pixels + y * scanspan;
+	scanspan = ri->ri_stride;
+	y = ri->ri_font->fontheight * startrow;
+	srcx = ri->ri_font->fontwidth * srccol;
+	dstx = ri->ri_font->fontwidth * dstcol;
+	height = ri->ri_font->fontheight;
+	w = ri->ri_font->fontwidth * ncols;
+	basep = (uint8_t *)ri->ri_bits + y * scanspan;
 
 	align = shift = srcx & ALIGNMASK;
 	width = w + align;
 	align = dstx & ALIGNMASK;
 	lmask = ALL1BITS >> align;
 	rmask = ALL1BITS << (-(w + align) & ALIGNMASK);
-	shift = align - shift; 
+	shift = align - shift;
 	sp = basep + (srcx / 32) * 4;
 	dp = basep + (dstx / 32) * 4;
 
@@ -370,11 +352,22 @@ om_copycols(void *cookie, int startrow, 
 static int
 om_mapchar(void *cookie, int c, u_int *cp)
 {
+	struct rasops_info *ri = cookie;
+	struct wsdisplay_font *wf = ri->ri_font;
 
-	if (c < 128) {
-		*cp = c;
-		return 5;
+	if (wf->encoding != WSDISPLAY_FONTENC_ISO) {
+		c = wsfont_map_unichar(wf, c);
+
+		if (c < 0)
+			goto fail;
 	}
+	if (c < wf->firstchar || c >= (wf->firstchar + wf->numchars))
+		goto fail;
+
+	*cp = c;
+	return 5;
+
+ fail:
 	*cp = ' ';
 	return 0;
 }
@@ -385,33 +378,32 @@ om_mapchar(void *cookie, int c, u_int *c
 static void
 om_cursor(void *cookie, int on, int row, int col)
 {
-	struct rcons *rc = cookie;
-	struct raster *rap = rc->rc_sp;
+	struct rasops_info *ri = cookie;
 	uint8_t *p;
 	int scanspan, startx, height, width, align, y;
 	uint32_t lmask, rmask, image;
 
 	if (!on) {
 		/* make sure it's on */
-		if ((rc->rc_bits & RC_CURSOR) == 0)
+		if ((ri->ri_flg & RI_CURSOR) == 0)
 			return;
 
-		row = *rc->rc_crowp;
-		col = *rc->rc_ccolp;
+		row = ri->ri_crow;
+		col = ri->ri_ccol;
 	} else {
 		/* unpaint the old copy. */
-		*rc->rc_crowp = row;
-		*rc->rc_ccolp = col;
+		ri->ri_crow = row;
+		ri->ri_ccol = col;
 	}
 
-	scanspan = rap->linelongs * 4;
-	y = rc->rc_yorigin + rc->rc_font->height * row;
-	startx = rc->rc_xorigin + rc->rc_font->width * col;
-	height = rc->rc_font->height;
+	scanspan = ri->ri_stride;
+	y = ri->ri_font->fontheight * row;
+	startx = ri->ri_font->fontwidth * col;
+	height = ri->ri_font->fontheight;
 
-	p = (uint8_t *)rap->pixels + y * scanspan + ((startx / 32) * 4);
+	p = (uint8_t *)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
 	align = startx & ALIGNMASK;
-	width = rc->rc_font->width + align;
+	width = ri->ri_font->fontwidth + align;
 	lmask = ALL1BITS >> align;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	if (width <= BLITWIDTH) {
@@ -436,7 +428,7 @@ om_cursor(void *cookie, int on, int row,
 			height--;
 		}
 	}
-	rc->rc_bits ^= RC_CURSOR;
+	ri->ri_flg ^= RI_CURSOR;
 }
 
 /*
@@ -447,7 +439,7 @@ om_allocattr(void *id, int fg, int bg, i
 {
 
 	if (flags & (WSATTR_HILIT | WSATTR_BLINK |
-		     WSATTR_UNDERLINE | WSATTR_WSCOLORS))
+	    WSATTR_UNDERLINE | WSATTR_WSCOLORS))
 		return EINVAL;
 	if (flags & WSATTR_REVERSE)
 		*attrp = 1;
@@ -456,42 +448,92 @@ om_allocattr(void *id, int fg, int bg, i
 	return 0;
 }
 
-void
-rcons_init(struct rcons *rc, int mrow, int mcol)
+/*
+ * Init subset of rasops(9) for omrasops.
+ */
+int
+omrasops_init(struct rasops_info *ri, int wantrows, int wantcols)
 {
-	struct raster *rp = rc->rc_sp;
-	int i;
+	int wsfcookie, bpp;
 
-#ifdef USE_OMRONFONT
-	rc->rc_font = &omron20; /* 12x22 monospacing font */
-#else
-	rc->rc_font = &gallant19; /* 12x22 monospacing font */
-#endif
-
-	/* Get distance to top and bottom of font from font origin */
-	rc->rc_font_ascent = -(rc->rc_font->chars)['a'].homey;
-
-	i = rp->height / rc->rc_font->height;
-	rc->rc_maxrow = min(i, mrow);
-
-	i = rp->width / rc->rc_font->width;
-	rc->rc_maxcol = min(i, mcol);
-
-	/* Center emulator screen (but align x origin to 32 bits) */
-	rc->rc_xorigin =
-	    ((rp->width - rc->rc_maxcol * rc->rc_font->width) / 2) & ~ALIGNMASK;
-	rc->rc_yorigin =
-	    (rp->height - rc->rc_maxrow * rc->rc_font->height) / 2;
-#if 0
-	/* Raster width used for row copies */
-	rc->rc_raswidth = rc->rc_maxcol * rc->rc_font->width;
-	if (rc->rc_raswidth & ALIGNMASK) {
-		/* Pad to 32 bits */
-		i = (rc->rc_raswidth + ALIGNMASK) & ~ALIGNMASK;
-		/* Make sure width isn't too wide */
-		if (rc->rc_xorigin + i <= rp->width)
-			rc->rc_raswidth = i;
-	}
-#endif
-	rc->rc_bits = 0;
+	if (wantrows == 0)
+		wantrows = 34;
+	if (wantrows < 10)
+		wantrows = 10;
+	if (wantcols == 0)
+		wantcols = 80;
+	if (wantcols < 20)
+		wantcols = 20;
+
+	/* Use default font */
+	wsfont_init();
+	wsfcookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
+	    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
+	if (wsfcookie < 0)
+		panic("%s: no font available", __func__);
+	if (wsfont_lock(wsfcookie, &ri->ri_font))
+		panic("%s: unable to lock font", __func__);
+	ri->ri_wsfcookie = wsfcookie;
+
+	KASSERT(ri->ri_font->fontwidth > 4 && ri->ri_font->fontwidth <= 32);
+
+	bpp = ri->ri_depth;
+
+	/* Now constrain what they get */
+	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
+	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
+	if (ri->ri_emuwidth > ri->ri_width)
+		ri->ri_emuwidth = ri->ri_width;
+	if (ri->ri_emuheight > ri->ri_height)
+		ri->ri_emuheight = ri->ri_height;
+
+	/* Reduce width until aligned on a 32-bit boundary */
+	while ((ri->ri_emuwidth * bpp & 31) != 0)
+		ri->ri_emuwidth--;
+
+	ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
+	ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
+	ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
+	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
+	ri->ri_ccol = 0;
+	ri->ri_crow = 0;
+	ri->ri_pelbytes = bpp >> 3;
+
+	ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
+	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
+	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
+
+	/* Clear the entire display */
+	if ((ri->ri_flg & RI_CLEAR) != 0)
+		memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
+
+	/* Now centre our window if needs be */
+	ri->ri_origbits = ri->ri_bits;
+
+	if ((ri->ri_flg & RI_CENTER) != 0) {
+		ri->ri_bits += (((ri->ri_width * bpp >> 3) -
+		    ri->ri_emustride) >> 1) & ~3;
+		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
+		    ri->ri_stride;
+		ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
+		   / ri->ri_stride;
+		ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
+		   % ri->ri_stride) * 8 / bpp);
+	} else
+		ri->ri_xorigin = ri->ri_yorigin = 0;
+
+	/* fill our own emulops */
+	ri->ri_ops.cursor    = om_cursor;
+	ri->ri_ops.mapchar   = om_mapchar;
+	ri->ri_ops.putchar   = om_putchar;
+	ri->ri_ops.copycols  = om_copycols;
+	ri->ri_ops.erasecols = om_erasecols;
+	ri->ri_ops.copyrows  = om_copyrows;
+	ri->ri_ops.eraserows = om_eraserows;
+	ri->ri_ops.allocattr = om_allocattr;
+	ri->ri_caps = WSSCREEN_REVERSE;
+
+	ri->ri_flg |= RI_CFGDONE;
+
+	return 0;
 }

Added files:

Index: src/sys/arch/luna68k/dev/omrasopsvar.h
diff -u /dev/null src/sys/arch/luna68k/dev/omrasopsvar.h:1.1
--- /dev/null	Fri Jul 20 19:31:54 2012
+++ src/sys/arch/luna68k/dev/omrasopsvar.h	Fri Jul 20 19:31:53 2012
@@ -0,0 +1,29 @@
+/* $NetBSD: omrasopsvar.h,v 1.1 2012/07/20 19:31:53 tsutsui Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+int omrasops_init(struct rasops_info *, int, int);

Reply via email to