1/* $NetBSD: rasops2.c,v 1.34 2022/05/29 10:43:19 andvar Exp $ */ 2 3/*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.34 2022/05/29 10:43:19 andvar Exp $"); 34 35#ifdef _KERNEL_OPT 36#include "opt_rasops.h" 37#endif 38 39#include <sys/param.h> 40 41#include <machine/endian.h> 42 43#include <dev/wscons/wsdisplayvar.h> 44#include <dev/wscons/wsconsio.h> 45 46#define _RASOPS_PRIVATE 47#define RASOPS_DEPTH 2 48#include <dev/rasops/rasops.h> 49#include <dev/rasops/rasops_masks.h> 50 51static void rasops2_copycols(void *, int, int, int, int); 52static void rasops2_erasecols(void *, int, int, int, long); 53static void rasops2_do_cursor(struct rasops_info *); 54static void rasops2_putchar(void *, int, int col, u_int, long); 55static void rasops2_putchar_aa(void *, int, int col, u_int, long); 56#ifndef RASOPS_SMALL 57static void rasops2_putchar8(void *, int, int col, u_int, long); 58static void rasops2_putchar12(void *, int, int col, u_int, long); 59static void rasops2_putchar16(void *, int, int col, u_int, long); 60static void rasops2_makestamp(struct rasops_info *, long); 61#endif 62 63#ifndef RASOPS_SMALL 64/* stamp for optimized character blitting */ 65static uint8_t stamp[16]; 66static long stamp_attr; 67static struct rasops_info *stamp_ri; 68 69/* 70 * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK 71 * destination = STAMP_READ(offset) 72 */ 73#define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 4 : (fb)) 74#define STAMP_MASK 0xf 75#define STAMP_READ(o) stamp[o] 76#endif 77 78/* 79 * Initialize rasops_info struct for this colordepth. 80 */ 81void 82rasops2_init(struct rasops_info *ri) 83{ 84 85 if ((ri->ri_font->fontwidth & 3) != 0) { 86 ri->ri_ops.erasecols = rasops2_erasecols; 87 ri->ri_ops.copycols = rasops2_copycols; 88 ri->ri_do_cursor = rasops2_do_cursor; 89 } 90 91 if (FONT_IS_ALPHA(ri->ri_font)) { 92 ri->ri_ops.putchar = rasops2_putchar_aa; 93 return; 94 } 95 96 switch (ri->ri_font->fontwidth) { 97#ifndef RASOPS_SMALL 98 case 8: 99 ri->ri_ops.putchar = rasops2_putchar8; 100 break; 101 case 12: 102 ri->ri_ops.putchar = rasops2_putchar12; 103 break; 104 case 16: 105 ri->ri_ops.putchar = rasops2_putchar16; 106 break; 107#endif 108 default: 109 ri->ri_ops.putchar = rasops2_putchar; 110 return; 111 } 112 113#ifndef RASOPS_SMALL 114 stamp_attr = -1; 115 stamp_ri = NULL; 116#endif 117} 118 119#ifndef RASOPS_SMALL 120/* 121 * Recompute the blitting stamp. 122 */ 123static void 124rasops2_makestamp(struct rasops_info *ri, long attr) 125{ 126 int i; 127 uint32_t bg, fg; 128 129 stamp_attr = attr; 130 stamp_ri = ri; 131 132 bg = ATTR_BG(ri, attr) & 3; 133 fg = ATTR_FG(ri, attr) & 3; 134 135 for (i = 0; i < 16; i++) { 136#if BYTE_ORDER == LITTLE_ENDIAN 137 if ((ri->ri_flg & RI_BSWAP) == 0) 138#else 139 if ((ri->ri_flg & RI_BSWAP) != 0) 140#endif 141 { 142 /* little endian */ 143 stamp[i] = (i & 8 ? fg : bg); 144 stamp[i] |= (i & 4 ? fg : bg) << 2; 145 stamp[i] |= (i & 2 ? fg : bg) << 4; 146 stamp[i] |= (i & 1 ? fg : bg) << 6; 147 } else { 148 /* big endian */ 149 stamp[i] = (i & 1 ? fg : bg); 150 stamp[i] |= (i & 2 ? fg : bg) << 2; 151 stamp[i] |= (i & 4 ? fg : bg) << 4; 152 stamp[i] |= (i & 8 ? fg : bg) << 6; 153 } 154 } 155} 156 157/* 158 * Width-optimized putchar functions 159 */ 160#define RASOPS_WIDTH 8 161#include <dev/rasops/rasops_putchar_width.h> 162#undef RASOPS_WIDTH 163 164#define RASOPS_WIDTH 12 165#include <dev/rasops/rasops_putchar_width.h> 166#undef RASOPS_WIDTH 167 168#define RASOPS_WIDTH 16 169#include <dev/rasops/rasops_putchar_width.h> 170#undef RASOPS_WIDTH 171 172#endif /* !RASOPS_SMALL */ 173 174/* rasops2_putchar */ 175#undef RASOPS_AA 176#include <dev/rasops/rasops1-4_putchar.h> 177 178/* rasops2_putchar_aa */ 179#define RASOPS_AA 180#include <dev/rasops/rasops1-4_putchar.h> 181#undef RASOPS_AA 182 183/* 184 * Grab routines common to depths where (bpp < 8) 185 */ 186#include <dev/rasops/rasops_bitops.h> 187