#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.34 2022/05/29 10:43:19 andvar Exp $");
#ifdef _KERNEL_OPT
#include "opt_rasops.h"
#endif
#include <sys/param.h>
#include <machine/endian.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wsconsio.h>
#define _RASOPS_PRIVATE
#define RASOPS_DEPTH 2
#include <dev/rasops/rasops.h>
#include <dev/rasops/rasops_masks.h>
static void rasops2_copycols(void *, int, int, int, int);
static void rasops2_erasecols(void *, int, int, int, long);
static void rasops2_do_cursor(struct rasops_info *);
static void rasops2_putchar(void *, int, int col, u_int, long);
static void rasops2_putchar_aa(void *, int, int col, u_int, long);
#ifndef RASOPS_SMALL
static void rasops2_putchar8(void *, int, int col, u_int, long);
static void rasops2_putchar12(void *, int, int col, u_int, long);
static void rasops2_putchar16(void *, int, int col, u_int, long);
static void rasops2_makestamp(struct rasops_info *, long);
#endif
#ifndef RASOPS_SMALL
static uint8_t stamp[16];
static long stamp_attr;
static struct rasops_info *stamp_ri;
#define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 4 : (fb))
#define STAMP_MASK 0xf
#define STAMP_READ(o) stamp[o]
#endif
void
rasops2_init(struct rasops_info *ri)
{
if ((ri->ri_font->fontwidth & 3) != 0) {
ri->ri_ops.erasecols = rasops2_erasecols;
ri->ri_ops.copycols = rasops2_copycols;
ri->ri_do_cursor = rasops2_do_cursor;
}
if (FONT_IS_ALPHA(ri->ri_font)) {
ri->ri_ops.putchar = rasops2_putchar_aa;
return;
}
switch (ri->ri_font->fontwidth) {
#ifndef RASOPS_SMALL
case 8:
ri->ri_ops.putchar = rasops2_putchar8;
break;
case 12:
ri->ri_ops.putchar = rasops2_putchar12;
break;
case 16:
ri->ri_ops.putchar = rasops2_putchar16;
break;
#endif
default:
ri->ri_ops.putchar = rasops2_putchar;
return;
}
#ifndef RASOPS_SMALL
stamp_attr = -1;
stamp_ri = NULL;
#endif
}
#ifndef RASOPS_SMALL
static void
rasops2_makestamp(struct rasops_info *ri, long attr)
{
int i;
uint32_t bg, fg;
stamp_attr = attr;
stamp_ri = ri;
bg = ATTR_BG(ri, attr) & 3;
fg = ATTR_FG(ri, attr) & 3;
for (i = 0; i < 16; i++) {
#if BYTE_ORDER == LITTLE_ENDIAN
if ((ri->ri_flg & RI_BSWAP) == 0)
#else
if ((ri->ri_flg & RI_BSWAP) != 0)
#endif
{
stamp[i] = (i & 8 ? fg : bg);
stamp[i] |= (i & 4 ? fg : bg) << 2;
stamp[i] |= (i & 2 ? fg : bg) << 4;
stamp[i] |= (i & 1 ? fg : bg) << 6;
} else {
stamp[i] = (i & 1 ? fg : bg);
stamp[i] |= (i & 2 ? fg : bg) << 2;
stamp[i] |= (i & 4 ? fg : bg) << 4;
stamp[i] |= (i & 8 ? fg : bg) << 6;
}
}
}
#define RASOPS_WIDTH 8
#include <dev/rasops/rasops_putchar_width.h>
#undef RASOPS_WIDTH
#define RASOPS_WIDTH 12
#include <dev/rasops/rasops_putchar_width.h>
#undef RASOPS_WIDTH
#define RASOPS_WIDTH 16
#include <dev/rasops/rasops_putchar_width.h>
#undef RASOPS_WIDTH
#endif
#undef RASOPS_AA
#include <dev/rasops/rasops1-4_putchar.h>
#define RASOPS_AA
#include <dev/rasops/rasops1-4_putchar.h>
#undef RASOPS_AA
#include <dev/rasops/rasops_bitops.h>