scgdcrndr.c revision 56337
1/*- 2 * Copyright (c) 1999 FreeBSD(98) Porting Team. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer as 10 * the first lines of this file unmodified. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/pc98/cbus/scgdcrndr.c 56337 2000-01-20 15:16:49Z kato $ 27 */ 28 29#include "sc.h" 30#include "gdc.h" 31#include "opt_syscons.h" 32#include "opt_gdc.h" 33 34#if NSC > 0 && NGDC > 0 35 36#include <sys/param.h> 37#include <sys/kernel.h> 38 39#include <machine/console.h> 40 41#include <dev/fb/fbreg.h> 42#include <dev/syscons/syscons.h> 43 44#ifndef SC_RENDER_DEBUG 45#define SC_RENDER_DEBUG 0 46#endif 47 48static vr_clear_t gdc_txtclear; 49static vr_draw_border_t gdc_txtborder; 50static vr_draw_t gdc_txtdraw; 51static vr_set_cursor_t gdc_txtcursor_shape; 52static vr_draw_cursor_t gdc_txtcursor; 53#ifndef SC_NO_CUTPASTE 54static vr_draw_mouse_t gdc_txtmouse; 55#else 56#define gdc_txtmouse (vr_draw_mouse_t *)gdc_nop 57#endif 58 59#ifndef SC_NO_MODE_CHANGE 60static vr_draw_border_t gdc_grborder; 61#endif 62 63static void gdc_nop(scr_stat *scp, ...); 64 65static struct linker_set gdc_set; 66 67static sc_rndr_sw_t txtrndrsw = { 68 gdc_txtclear, 69 gdc_txtborder, 70 gdc_txtdraw, 71 gdc_txtcursor_shape, 72 gdc_txtcursor, 73 (vr_blink_cursor_t *)gdc_nop, 74 (vr_set_mouse_t *)gdc_nop, 75 gdc_txtmouse, 76}; 77RENDERER(gdc, 0, txtrndrsw, gdc_set); 78 79#ifndef SC_NO_MODE_CHANGE 80static sc_rndr_sw_t grrndrsw = { 81 (vr_clear_t *)gdc_nop, 82 gdc_grborder, 83 (vr_draw_t *)gdc_nop, 84 (vr_set_cursor_t *)gdc_nop, 85 (vr_draw_cursor_t *)gdc_nop, 86 (vr_blink_cursor_t *)gdc_nop, 87 (vr_set_mouse_t *)gdc_nop, 88 (vr_draw_mouse_t *)gdc_nop, 89}; 90RENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set); 91#endif /* SC_NO_MODE_CHANGE */ 92 93RENDERER_MODULE(gdc, gdc_set); 94 95static void 96gdc_nop(scr_stat *scp, ...) 97{ 98} 99 100/* text mode renderer */ 101 102static void 103gdc_txtclear(scr_stat *scp, int c, int attr) 104{ 105 sc_vtb_clear(&scp->scr, c, attr); 106} 107 108static void 109gdc_txtborder(scr_stat *scp, int color) 110{ 111 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); 112} 113 114static void 115gdc_txtdraw(scr_stat *scp, int from, int count, int flip) 116{ 117 vm_offset_t p; 118 int c; 119 int a; 120 121 if (from + count > scp->xsize*scp->ysize) 122 count = scp->xsize*scp->ysize - from; 123 124 if (flip) { 125 p = sc_vtb_pointer(&scp->scr, from); 126 for (; count-- > 0; ++from) { 127 c = sc_vtb_getc(&scp->vtb, from); 128 a = sc_vtb_geta(&scp->vtb, from) ^ 0x4; 129 sc_vtb_putchar(&scp->scr, p, c, a); 130 } 131 } else { 132 sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count); 133 } 134} 135 136static void 137gdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink) 138{ 139 if (base < 0 || base >= scp->font_size) 140 return; 141 /* the caller may set height <= 0 in order to disable the cursor */ 142 (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp, 143 base, height, 144 scp->font_size, blink); 145} 146 147static void 148gdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip) 149{ 150 if (on) { 151 scp->status |= VR_CURSOR_ON; 152 (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp, 153 at%scp->xsize, at/scp->xsize); 154 } else { 155 if (scp->status & VR_CURSOR_ON) 156 (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp, 157 -1, -1); 158 scp->status &= ~VR_CURSOR_ON; 159 } 160} 161 162#ifndef SC_NO_CUTPASTE 163 164static void 165draw_txtmouse(scr_stat *scp, int x, int y) 166{ 167 int at; 168 169 at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff; 170 sc_vtb_putc(&scp->scr, at, 171 sc_vtb_getc(&scp->scr, at), 172 sc_vtb_geta(&scp->scr, at) ^ 0x4); 173} 174 175static void 176remove_txtmouse(scr_stat *scp, int x, int y) 177{ 178} 179 180static void 181gdc_txtmouse(scr_stat *scp, int x, int y, int on) 182{ 183 if (on) 184 draw_txtmouse(scp, x, y); 185 else 186 remove_txtmouse(scp, x, y); 187} 188 189#endif /* SC_NO_CUTPASTE */ 190 191#ifndef SC_NO_MODE_CHANGE 192 193/* graphics mode renderer */ 194 195static void 196gdc_grborder(scr_stat *scp, int color) 197{ 198 (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); 199} 200 201#endif /* SC_NO_MODE_CHANGE */ 202 203#endif /* NSC > 0 && NGDC > 0 */ 204