Home | History | Annotate | Line # | Download | only in hpc
hpcfb.c revision 1.1.4.3
      1  1.1.4.3  bouyer /*	$NetBSD: hpcfb.c,v 1.1.4.3 2001/03/27 15:31:51 bouyer Exp $	*/
      2  1.1.4.2  bouyer 
      3  1.1.4.2  bouyer /*-
      4  1.1.4.2  bouyer  * Copyright (c) 1999
      5  1.1.4.2  bouyer  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  1.1.4.2  bouyer  * Copyright (c) 2000,2001
      7  1.1.4.2  bouyer  *         SATO Kazumi. All rights reserved.
      8  1.1.4.2  bouyer  *
      9  1.1.4.2  bouyer  * Redistribution and use in source and binary forms, with or without
     10  1.1.4.2  bouyer  * modification, are permitted provided that the following conditions
     11  1.1.4.2  bouyer  * are met:
     12  1.1.4.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     13  1.1.4.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     14  1.1.4.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.4.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.4.2  bouyer  *    documentation and/or other materials provided with the distribution.
     17  1.1.4.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     18  1.1.4.2  bouyer  *    must display the following acknowledgement:
     19  1.1.4.2  bouyer  *	This product includes software developed by the PocketBSD project
     20  1.1.4.2  bouyer  *	and its contributors.
     21  1.1.4.2  bouyer  * 4. Neither the name of the project nor the names of its contributors
     22  1.1.4.2  bouyer  *    may be used to endorse or promote products derived from this software
     23  1.1.4.2  bouyer  *    without specific prior written permission.
     24  1.1.4.2  bouyer  *
     25  1.1.4.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1.4.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1.4.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1.4.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1.4.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1.4.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1.4.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1.4.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1.4.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1.4.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1.4.2  bouyer  * SUCH DAMAGE.
     36  1.1.4.2  bouyer  *
     37  1.1.4.2  bouyer  */
     38  1.1.4.2  bouyer 
     39  1.1.4.2  bouyer /*
     40  1.1.4.2  bouyer  * jump scroll, scroll thread, multiscreen, virtual text vram
     41  1.1.4.2  bouyer  * and hpcfb_emulops functions
     42  1.1.4.2  bouyer  * written by SATO Kazumi.
     43  1.1.4.2  bouyer  */
     44  1.1.4.2  bouyer 
     45  1.1.4.2  bouyer #define FBDEBUG
     46  1.1.4.2  bouyer static const char _copyright[] __attribute__ ((unused)) =
     47  1.1.4.2  bouyer     "Copyright (c) 1999 Shin Takemura.  All rights reserved.";
     48  1.1.4.2  bouyer static const char _rcsid[] __attribute__ ((unused)) =
     49  1.1.4.3  bouyer     "$Id: hpcfb.c,v 1.1.4.3 2001/03/27 15:31:51 bouyer Exp $";
     50  1.1.4.2  bouyer 
     51  1.1.4.2  bouyer #include <sys/param.h>
     52  1.1.4.2  bouyer #include <sys/systm.h>
     53  1.1.4.2  bouyer #include <sys/kernel.h>
     54  1.1.4.2  bouyer #include <sys/signalvar.h>
     55  1.1.4.2  bouyer #include <sys/map.h>
     56  1.1.4.2  bouyer #include <sys/proc.h>
     57  1.1.4.2  bouyer #include <sys/kthread.h>
     58  1.1.4.2  bouyer #include <sys/lock.h>
     59  1.1.4.2  bouyer #include <sys/user.h>
     60  1.1.4.2  bouyer #include <sys/device.h>
     61  1.1.4.2  bouyer #include <sys/conf.h>
     62  1.1.4.2  bouyer #include <sys/malloc.h>
     63  1.1.4.2  bouyer #include <sys/buf.h>
     64  1.1.4.2  bouyer #include <sys/ioctl.h>
     65  1.1.4.2  bouyer 
     66  1.1.4.2  bouyer #include <uvm/uvm_extern.h>
     67  1.1.4.2  bouyer 
     68  1.1.4.2  bouyer #include <machine/bus.h>
     69  1.1.4.2  bouyer #include <machine/autoconf.h>
     70  1.1.4.2  bouyer 
     71  1.1.4.2  bouyer #include <dev/wscons/wsconsio.h>
     72  1.1.4.2  bouyer #include <dev/wscons/wsdisplayvar.h>
     73  1.1.4.2  bouyer #include <dev/wscons/wscons_callbacks.h>
     74  1.1.4.2  bouyer 
     75  1.1.4.2  bouyer #include <dev/wsfont/wsfont.h>
     76  1.1.4.2  bouyer #include <dev/rasops/rasops.h>
     77  1.1.4.2  bouyer 
     78  1.1.4.2  bouyer #include <dev/hpc/hpcfbvar.h>
     79  1.1.4.2  bouyer #include <dev/hpc/hpcfbio.h>
     80  1.1.4.2  bouyer 
     81  1.1.4.2  bouyer #include "bivideo.h"
     82  1.1.4.2  bouyer #if NBIVIDEO > 0
     83  1.1.4.2  bouyer #include <dev/hpc/bivideovar.h>
     84  1.1.4.2  bouyer #endif
     85  1.1.4.2  bouyer 
     86  1.1.4.2  bouyer #ifdef FBDEBUG
     87  1.1.4.2  bouyer int	hpcfb_debug = 0;
     88  1.1.4.2  bouyer #define	DPRINTF(arg) if (hpcfb_debug) printf arg;
     89  1.1.4.2  bouyer #else
     90  1.1.4.2  bouyer #define	DPRINTF(arg)
     91  1.1.4.2  bouyer #endif
     92  1.1.4.2  bouyer 
     93  1.1.4.2  bouyer #ifndef HPCFB_MAX_COLUMN
     94  1.1.4.2  bouyer #define HPCFB_MAX_COLUMN 130
     95  1.1.4.2  bouyer #endif /* HPCFB_MAX_COLUMN */
     96  1.1.4.2  bouyer #ifndef HPCFB_MAX_ROW
     97  1.1.4.2  bouyer #define HPCFB_MAX_ROW 80
     98  1.1.4.2  bouyer #endif /* HPCFB_MAX_ROW */
     99  1.1.4.2  bouyer 
    100  1.1.4.2  bouyer /*
    101  1.1.4.2  bouyer  * currently experimental
    102  1.1.4.2  bouyer #define HPCFB_JUMP
    103  1.1.4.2  bouyer */
    104  1.1.4.2  bouyer 
    105  1.1.4.2  bouyer struct hpcfb_vchar {
    106  1.1.4.2  bouyer 	u_int c;
    107  1.1.4.2  bouyer 	long attr;
    108  1.1.4.2  bouyer };
    109  1.1.4.2  bouyer 
    110  1.1.4.2  bouyer struct hpcfb_tvrow {
    111  1.1.4.2  bouyer 	int maxcol;
    112  1.1.4.2  bouyer 	int spacecol;
    113  1.1.4.2  bouyer 	struct hpcfb_vchar col[HPCFB_MAX_COLUMN];
    114  1.1.4.2  bouyer };
    115  1.1.4.2  bouyer 
    116  1.1.4.2  bouyer struct hpcfb_devconfig {
    117  1.1.4.2  bouyer 	struct rasops_info	dc_rinfo;	/* rasops infomation */
    118  1.1.4.2  bouyer 
    119  1.1.4.2  bouyer 	int		dc_blanked;	/* currently had video disabled */
    120  1.1.4.2  bouyer 	struct hpcfb_softc *dc_sc;
    121  1.1.4.2  bouyer 	int dc_rows;
    122  1.1.4.2  bouyer 	int dc_cols;
    123  1.1.4.2  bouyer 	struct hpcfb_tvrow *dc_tvram;
    124  1.1.4.2  bouyer 	int dc_curx;
    125  1.1.4.2  bouyer 	int dc_cury;
    126  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    127  1.1.4.2  bouyer 	int dc_min_row;
    128  1.1.4.2  bouyer 	int dc_max_row;
    129  1.1.4.2  bouyer 	int dc_scroll;
    130  1.1.4.2  bouyer 	struct callout dc_scroll_ch;
    131  1.1.4.2  bouyer 	int dc_scroll_src;
    132  1.1.4.2  bouyer 	int dc_scroll_dst;
    133  1.1.4.2  bouyer 	int dc_scroll_num;
    134  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    135  1.1.4.2  bouyer 	volatile int dc_state;
    136  1.1.4.2  bouyer #define HPCFB_DC_CURRENT		0x80000000
    137  1.1.4.2  bouyer #define HPCFB_DC_DRAWING		0x01	/* drawing raster ops */
    138  1.1.4.2  bouyer #define HPCFB_DC_TDRAWING		0x02	/* drawing tvram */
    139  1.1.4.2  bouyer #define HPCFB_DC_SCROLLPENDING		0x04	/* scroll is pending */
    140  1.1.4.2  bouyer #define HPCFB_DC_UPDATE			0x08	/* tvram update */
    141  1.1.4.2  bouyer #define HPCFB_DC_SCRDELAY		0x10	/* scroll time but delay it */
    142  1.1.4.2  bouyer #define HPCFB_DC_SCRTHREAD		0x20	/* in scroll thread or callout */
    143  1.1.4.2  bouyer #define HPCFB_DC_UPDATEALL		0x40	/* need to redraw all */
    144  1.1.4.2  bouyer #define HPCFB_DC_ABORT			0x80	/* abort redrawing */
    145  1.1.4.2  bouyer 	int dc_scrno;
    146  1.1.4.2  bouyer 	int	dc_memsize;
    147  1.1.4.2  bouyer 	u_char *dc_fbaddr;
    148  1.1.4.2  bouyer };
    149  1.1.4.2  bouyer 
    150  1.1.4.2  bouyer #define HPCFB_MAX_SCREEN 5
    151  1.1.4.2  bouyer #define HPCFB_MAX_JUMP 5
    152  1.1.4.2  bouyer 
    153  1.1.4.2  bouyer struct hpcfb_softc {
    154  1.1.4.2  bouyer 	struct	device sc_dev;
    155  1.1.4.2  bouyer 	struct	hpcfb_devconfig *sc_dc;	/* device configuration */
    156  1.1.4.2  bouyer 	struct	hpcfb_devconfig *screens[HPCFB_MAX_SCREEN];
    157  1.1.4.2  bouyer 	const struct hpcfb_accessops	*sc_accessops;
    158  1.1.4.2  bouyer 	void *sc_accessctx;
    159  1.1.4.2  bouyer 	int nscreens;
    160  1.1.4.2  bouyer 	void *sc_powerhook;	/* power management hook */
    161  1.1.4.2  bouyer 	struct device *sc_wsdisplay;
    162  1.1.4.2  bouyer 	int sc_screen_resumed;
    163  1.1.4.2  bouyer 	int sc_polling;
    164  1.1.4.2  bouyer 	int sc_mapping;
    165  1.1.4.2  bouyer 	struct proc *sc_thread;
    166  1.1.4.2  bouyer 	struct lock sc_lock;
    167  1.1.4.2  bouyer 	void *sc_wantedscreen;
    168  1.1.4.2  bouyer 	void (*sc_switchcb) __P((void *, int, int));
    169  1.1.4.2  bouyer 	void *sc_switchcbarg;
    170  1.1.4.2  bouyer 	struct callout sc_switch_callout;
    171  1.1.4.2  bouyer };
    172  1.1.4.2  bouyer 
    173  1.1.4.2  bouyer /*
    174  1.1.4.2  bouyer  *  function prototypes
    175  1.1.4.2  bouyer  */
    176  1.1.4.2  bouyer int	hpcfbmatch __P((struct device *, struct cfdata *, void *));
    177  1.1.4.2  bouyer void	hpcfbattach __P((struct device *, struct device *, void *));
    178  1.1.4.2  bouyer int	hpcfbprint __P((void *aux, const char *pnp));
    179  1.1.4.2  bouyer 
    180  1.1.4.2  bouyer int	hpcfb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    181  1.1.4.2  bouyer paddr_t	hpcfb_mmap __P((void *, off_t, int));
    182  1.1.4.2  bouyer 
    183  1.1.4.2  bouyer void	hpcfb_refresh_screen __P((struct hpcfb_softc *sc));
    184  1.1.4.2  bouyer void	hpcfb_doswitch __P((struct hpcfb_softc *sc));
    185  1.1.4.2  bouyer 
    186  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    187  1.1.4.2  bouyer static void	hpcfb_create_thread __P((void *));
    188  1.1.4.2  bouyer static void	hpcfb_thread __P((void *));
    189  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    190  1.1.4.2  bouyer 
    191  1.1.4.2  bouyer static int	hpcfb_init __P((struct hpcfb_fbconf *fbconf,
    192  1.1.4.2  bouyer 				struct hpcfb_devconfig *dc));
    193  1.1.4.2  bouyer static int	hpcfb_alloc_screen __P((void *, const struct wsscreen_descr *,
    194  1.1.4.2  bouyer 				     void **, int *, int *, long *));
    195  1.1.4.2  bouyer static void	hpcfb_free_screen __P((void *, void *));
    196  1.1.4.2  bouyer static int	hpcfb_show_screen __P((void *, void *, int,
    197  1.1.4.2  bouyer 				    void (*) (void *, int, int), void *));
    198  1.1.4.2  bouyer static void     hpcfb_pollc __P((void *, int));
    199  1.1.4.2  bouyer static void	hpcfb_power __P((int, void *));
    200  1.1.4.2  bouyer static void	hpcfb_cmap_reorder __P((struct hpcfb_fbconf *,
    201  1.1.4.2  bouyer 					struct hpcfb_devconfig *));
    202  1.1.4.2  bouyer 
    203  1.1.4.2  bouyer static int	pow __P((int, int));
    204  1.1.4.2  bouyer 
    205  1.1.4.2  bouyer void    hpcfb_cursor __P((void *c, int on, int row, int col));
    206  1.1.4.2  bouyer int     hpcfb_mapchar __P((void *, int, unsigned int *));
    207  1.1.4.2  bouyer void    hpcfb_putchar __P((void *c, int row, int col, u_int uc, long attr));
    208  1.1.4.2  bouyer void    hpcfb_copycols __P((void *c, int row, int srccol,
    209  1.1.4.2  bouyer 			int dstcol, int ncols));
    210  1.1.4.2  bouyer void    hpcfb_erasecols __P((void *c, int row, int startcol,
    211  1.1.4.2  bouyer 			int ncols, long attr));
    212  1.1.4.2  bouyer void    hpcfb_redraw __P((void *c, int row, int nrows, int all));
    213  1.1.4.2  bouyer void    hpcfb_copyrows __P((void *c, int srcrow, int dstrow, int nrows));
    214  1.1.4.2  bouyer void    hpcfb_eraserows __P((void *c, int row, int nrows, long attr));
    215  1.1.4.2  bouyer int     hpcfb_alloc_attr __P((void *c, int fg, int bg, int flags, long *attr));
    216  1.1.4.2  bouyer void    hpcfb_cursor_raw __P((void *c, int on, int row, int col));
    217  1.1.4.2  bouyer 
    218  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    219  1.1.4.2  bouyer void	hpcfb_update __P((void *));
    220  1.1.4.2  bouyer void	hpcfb_do_scroll __P((void *));
    221  1.1.4.2  bouyer void	hpcfb_check_update __P((void *));
    222  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    223  1.1.4.2  bouyer 
    224  1.1.4.2  bouyer struct wsdisplay_emulops hpcfb_emulops = {
    225  1.1.4.2  bouyer 	hpcfb_cursor,
    226  1.1.4.2  bouyer 	hpcfb_mapchar,
    227  1.1.4.2  bouyer 	hpcfb_putchar,
    228  1.1.4.2  bouyer 	hpcfb_copycols,
    229  1.1.4.2  bouyer 	hpcfb_erasecols,
    230  1.1.4.2  bouyer 	hpcfb_copyrows,
    231  1.1.4.2  bouyer 	hpcfb_eraserows,
    232  1.1.4.2  bouyer 	hpcfb_alloc_attr
    233  1.1.4.2  bouyer };
    234  1.1.4.2  bouyer 
    235  1.1.4.2  bouyer /*
    236  1.1.4.2  bouyer  *  static variables
    237  1.1.4.2  bouyer  */
    238  1.1.4.2  bouyer struct cfattach hpcfb_ca = {
    239  1.1.4.2  bouyer 	sizeof(struct hpcfb_softc), hpcfbmatch, hpcfbattach,
    240  1.1.4.2  bouyer };
    241  1.1.4.2  bouyer 
    242  1.1.4.2  bouyer struct wsscreen_descr hpcfb_stdscreen = {
    243  1.1.4.2  bouyer 	"std",
    244  1.1.4.2  bouyer 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    245  1.1.4.2  bouyer 	&hpcfb_emulops,	/* XXX */
    246  1.1.4.2  bouyer 	0, 0,
    247  1.1.4.2  bouyer 	WSSCREEN_REVERSE
    248  1.1.4.2  bouyer };
    249  1.1.4.2  bouyer 
    250  1.1.4.2  bouyer const struct wsscreen_descr *_hpcfb_scrlist[] = {
    251  1.1.4.2  bouyer 	&hpcfb_stdscreen,
    252  1.1.4.2  bouyer 	/* XXX other formats, graphics screen? */
    253  1.1.4.2  bouyer };
    254  1.1.4.2  bouyer 
    255  1.1.4.2  bouyer struct wsscreen_list hpcfb_screenlist = {
    256  1.1.4.2  bouyer 	sizeof(_hpcfb_scrlist) / sizeof(struct wsscreen_descr *),
    257  1.1.4.2  bouyer 	_hpcfb_scrlist
    258  1.1.4.2  bouyer };
    259  1.1.4.2  bouyer 
    260  1.1.4.2  bouyer struct wsdisplay_accessops hpcfb_accessops = {
    261  1.1.4.2  bouyer 	hpcfb_ioctl,
    262  1.1.4.2  bouyer 	hpcfb_mmap,
    263  1.1.4.2  bouyer 	hpcfb_alloc_screen,
    264  1.1.4.2  bouyer 	hpcfb_free_screen,
    265  1.1.4.2  bouyer 	hpcfb_show_screen,
    266  1.1.4.2  bouyer 	0 /* load_font */,
    267  1.1.4.2  bouyer 	hpcfb_pollc
    268  1.1.4.2  bouyer };
    269  1.1.4.2  bouyer 
    270  1.1.4.2  bouyer void    hpcfb_tv_putchar __P((struct hpcfb_devconfig *, int, int, u_int, long));
    271  1.1.4.2  bouyer void    hpcfb_tv_copycols __P((struct hpcfb_devconfig *, int, int, int, int));
    272  1.1.4.2  bouyer void    hpcfb_tv_erasecols __P((struct hpcfb_devconfig *, int, int, int, long));
    273  1.1.4.2  bouyer void    hpcfb_tv_copyrows __P((struct hpcfb_devconfig *, int, int, int));
    274  1.1.4.2  bouyer void    hpcfb_tv_eraserows __P((struct hpcfb_devconfig *, int, int, long));
    275  1.1.4.2  bouyer 
    276  1.1.4.2  bouyer struct wsdisplay_emulops rasops_emul;
    277  1.1.4.2  bouyer 
    278  1.1.4.2  bouyer static int hpcfbconsole;
    279  1.1.4.2  bouyer struct hpcfb_devconfig hpcfb_console_dc;
    280  1.1.4.2  bouyer struct wsscreen_descr hpcfb_console_wsscreen;
    281  1.1.4.2  bouyer struct hpcfb_tvrow hpcfb_console_tvram[HPCFB_MAX_ROW];
    282  1.1.4.2  bouyer 
    283  1.1.4.2  bouyer /*
    284  1.1.4.2  bouyer  *  function bodies
    285  1.1.4.2  bouyer  */
    286  1.1.4.2  bouyer static int
    287  1.1.4.2  bouyer pow(int x, int n)
    288  1.1.4.2  bouyer {
    289  1.1.4.2  bouyer 	int res = 1;
    290  1.1.4.2  bouyer 	while (0 < n--) {
    291  1.1.4.2  bouyer 		res *= x;
    292  1.1.4.2  bouyer 	}
    293  1.1.4.2  bouyer 	return (res);
    294  1.1.4.2  bouyer }
    295  1.1.4.2  bouyer 
    296  1.1.4.2  bouyer int
    297  1.1.4.2  bouyer hpcfbmatch(parent, match, aux)
    298  1.1.4.2  bouyer 	struct device *parent;
    299  1.1.4.2  bouyer 	struct cfdata *match;
    300  1.1.4.2  bouyer 	void *aux;
    301  1.1.4.2  bouyer {
    302  1.1.4.2  bouyer 	return (1);
    303  1.1.4.2  bouyer }
    304  1.1.4.2  bouyer 
    305  1.1.4.2  bouyer void
    306  1.1.4.2  bouyer hpcfbattach(parent, self, aux)
    307  1.1.4.2  bouyer 	struct device *parent, *self;
    308  1.1.4.2  bouyer 	void *aux;
    309  1.1.4.2  bouyer {
    310  1.1.4.2  bouyer 	struct hpcfb_softc *sc = (struct hpcfb_softc *)self;
    311  1.1.4.2  bouyer 	struct hpcfb_attach_args *ha = aux;
    312  1.1.4.2  bouyer 	struct wsemuldisplaydev_attach_args wa;
    313  1.1.4.2  bouyer 
    314  1.1.4.2  bouyer 	sc->sc_accessops = ha->ha_accessops;
    315  1.1.4.2  bouyer 	sc->sc_accessctx = ha->ha_accessctx;
    316  1.1.4.2  bouyer 
    317  1.1.4.2  bouyer 	if (hpcfbconsole) {
    318  1.1.4.2  bouyer 		sc->screens[0] =
    319  1.1.4.2  bouyer 		sc->sc_dc = &hpcfb_console_dc;
    320  1.1.4.2  bouyer 		sc->nscreens = 1;
    321  1.1.4.2  bouyer 		hpcfb_console_dc.dc_sc = sc;
    322  1.1.4.2  bouyer 	} else {
    323  1.1.4.2  bouyer 		sc->screens[0] =
    324  1.1.4.2  bouyer 		sc->sc_dc = (struct hpcfb_devconfig *)
    325  1.1.4.2  bouyer 		    malloc(sizeof(struct hpcfb_devconfig), M_DEVBUF, M_WAITOK);
    326  1.1.4.3  bouyer 		sc->nscreens = 0; /* XXXX */
    327  1.1.4.2  bouyer 		bzero(sc->sc_dc, sizeof(struct hpcfb_devconfig));
    328  1.1.4.2  bouyer 		if (hpcfb_init(&ha->ha_fbconflist[0], sc->sc_dc) != 0) {
    329  1.1.4.2  bouyer 			return;
    330  1.1.4.2  bouyer 		}
    331  1.1.4.2  bouyer 		sc->sc_dc->dc_tvram = hpcfb_console_tvram;
    332  1.1.4.2  bouyer 		bzero(hpcfb_console_tvram, sizeof(hpcfb_console_tvram));
    333  1.1.4.2  bouyer 		sc->sc_dc->dc_sc = sc;
    334  1.1.4.2  bouyer 	}
    335  1.1.4.2  bouyer 	sc->sc_polling = 0; /* XXX */
    336  1.1.4.2  bouyer 	sc->sc_mapping = 0; /* XXX */
    337  1.1.4.2  bouyer 	callout_init(&sc->sc_switch_callout);
    338  1.1.4.2  bouyer 	hpcfb_stdscreen.nrows = sc->sc_dc->dc_rows;
    339  1.1.4.2  bouyer         hpcfb_stdscreen.ncols = sc->sc_dc->dc_cols;
    340  1.1.4.2  bouyer 	hpcfb_stdscreen.capabilities = sc->sc_dc->dc_rinfo.ri_caps;
    341  1.1.4.3  bouyer 	printf(": hpcrasops %dx%d pixels, %d colors, %dx%d chars: multi",
    342  1.1.4.2  bouyer 	       sc->sc_dc->dc_rinfo.ri_width,
    343  1.1.4.2  bouyer 	       sc->sc_dc->dc_rinfo.ri_height,
    344  1.1.4.2  bouyer 	       pow(2, sc->sc_dc->dc_rinfo.ri_depth),
    345  1.1.4.2  bouyer 	       sc->sc_dc->dc_rinfo.ri_cols,
    346  1.1.4.2  bouyer 	       sc->sc_dc->dc_rinfo.ri_rows);
    347  1.1.4.2  bouyer 	printf("\n");
    348  1.1.4.2  bouyer 
    349  1.1.4.2  bouyer 	/* Set video chip dependent CLUT if any. */
    350  1.1.4.2  bouyer 	if (hpcfbconsole && sc->sc_accessops->setclut) {
    351  1.1.4.2  bouyer 		sc->sc_accessops->setclut(sc->sc_accessctx,
    352  1.1.4.2  bouyer 					  &hpcfb_console_dc.dc_rinfo);
    353  1.1.4.2  bouyer 	}
    354  1.1.4.2  bouyer 
    355  1.1.4.2  bouyer 	/* set font for hardware accel */
    356  1.1.4.2  bouyer 	if (sc->sc_accessops->font) {
    357  1.1.4.2  bouyer 		sc->sc_accessops->font(sc->sc_accessctx,
    358  1.1.4.2  bouyer 					sc->sc_dc->dc_rinfo.ri_font);
    359  1.1.4.2  bouyer 	}
    360  1.1.4.2  bouyer 
    361  1.1.4.2  bouyer 	/* Add a power hook to power management */
    362  1.1.4.2  bouyer 	sc->sc_powerhook = powerhook_establish(hpcfb_power, sc);
    363  1.1.4.2  bouyer 	if (sc->sc_powerhook == NULL)
    364  1.1.4.2  bouyer 		printf("%s: WARNING: unable to establish power hook\n",
    365  1.1.4.2  bouyer 			sc->sc_dev.dv_xname);
    366  1.1.4.2  bouyer 
    367  1.1.4.2  bouyer 	wa.console = hpcfbconsole;
    368  1.1.4.2  bouyer 	wa.scrdata = &hpcfb_screenlist;
    369  1.1.4.2  bouyer 	wa.accessops = &hpcfb_accessops;
    370  1.1.4.2  bouyer 	wa.accesscookie = sc;
    371  1.1.4.2  bouyer 
    372  1.1.4.2  bouyer 	sc->sc_wsdisplay = config_found(self, &wa, wsemuldisplaydevprint);
    373  1.1.4.2  bouyer 
    374  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    375  1.1.4.2  bouyer 	/*
    376  1.1.4.2  bouyer 	 * Create a kernel thread to scroll,
    377  1.1.4.2  bouyer 	 */
    378  1.1.4.2  bouyer 	kthread_create(hpcfb_create_thread, sc);
    379  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    380  1.1.4.2  bouyer }
    381  1.1.4.2  bouyer 
    382  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    383  1.1.4.2  bouyer void
    384  1.1.4.2  bouyer hpcfb_create_thread(arg)
    385  1.1.4.2  bouyer 	void *arg;
    386  1.1.4.2  bouyer {
    387  1.1.4.2  bouyer 	struct hpcfb_softc *sc = arg;
    388  1.1.4.2  bouyer 
    389  1.1.4.2  bouyer 	if (kthread_create1(hpcfb_thread, sc, &sc->sc_thread,
    390  1.1.4.2  bouyer 			    "%s", sc->sc_dev.dv_xname) == 0)
    391  1.1.4.2  bouyer 		return;
    392  1.1.4.2  bouyer 
    393  1.1.4.2  bouyer 	/*
    394  1.1.4.2  bouyer 	 * We were unable to create the HPCFB thread; bail out.
    395  1.1.4.2  bouyer 	 */
    396  1.1.4.2  bouyer 	sc->sc_thread = 0;
    397  1.1.4.2  bouyer 	printf("%s: unable to create thread, kernel hpcfb scroll support disabled\n",
    398  1.1.4.2  bouyer 	       sc->sc_dev.dv_xname);
    399  1.1.4.2  bouyer }
    400  1.1.4.2  bouyer 
    401  1.1.4.2  bouyer void
    402  1.1.4.2  bouyer hpcfb_thread(arg)
    403  1.1.4.2  bouyer 	void *arg;
    404  1.1.4.2  bouyer {
    405  1.1.4.2  bouyer 	struct hpcfb_softc *sc = arg;
    406  1.1.4.2  bouyer 
    407  1.1.4.2  bouyer 	/*
    408  1.1.4.2  bouyer 	 * Loop forever, doing a periodic check for update events.
    409  1.1.4.2  bouyer 	 */
    410  1.1.4.2  bouyer 	for (;;) {
    411  1.1.4.2  bouyer 		/* HPCFB_LOCK(sc); */
    412  1.1.4.2  bouyer 		sc->sc_dc->dc_state |= HPCFB_DC_SCRTHREAD;
    413  1.1.4.2  bouyer 		if (!sc->sc_mapping) /* draw only EMUL mode */
    414  1.1.4.2  bouyer 			hpcfb_update(sc->sc_dc);
    415  1.1.4.2  bouyer 		sc->sc_dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
    416  1.1.4.2  bouyer 		/* APM_UNLOCK(sc); */
    417  1.1.4.2  bouyer 		(void) tsleep(sc, PWAIT, "hpcfb",  (8 * hz) / 7 / 10);
    418  1.1.4.2  bouyer 	}
    419  1.1.4.2  bouyer }
    420  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    421  1.1.4.2  bouyer 
    422  1.1.4.2  bouyer /* Print function (for parent devices). */
    423  1.1.4.2  bouyer int
    424  1.1.4.2  bouyer hpcfbprint(aux, pnp)
    425  1.1.4.2  bouyer 	void *aux;
    426  1.1.4.2  bouyer 	const char *pnp;
    427  1.1.4.2  bouyer {
    428  1.1.4.2  bouyer 	if (pnp)
    429  1.1.4.2  bouyer 		printf("hpcfb at %s", pnp);
    430  1.1.4.2  bouyer 
    431  1.1.4.2  bouyer 	return (UNCONF);
    432  1.1.4.2  bouyer }
    433  1.1.4.2  bouyer 
    434  1.1.4.2  bouyer int
    435  1.1.4.2  bouyer hpcfb_cnattach(fbconf)
    436  1.1.4.2  bouyer 	struct hpcfb_fbconf *fbconf;
    437  1.1.4.2  bouyer {
    438  1.1.4.2  bouyer 	struct hpcfb_fbconf __fbconf __attribute__((__unused__));
    439  1.1.4.2  bouyer 	long defattr;
    440  1.1.4.2  bouyer 
    441  1.1.4.2  bouyer #if NBIVIDEO > 0
    442  1.1.4.2  bouyer 	if (fbconf == 0) {
    443  1.1.4.2  bouyer 		memset(&__fbconf, 0, sizeof(struct hpcfb_fbconf));
    444  1.1.4.2  bouyer 		if (bivideo_getcnfb(&__fbconf) != 0)
    445  1.1.4.2  bouyer 			return (ENXIO);
    446  1.1.4.2  bouyer 		fbconf = &__fbconf;
    447  1.1.4.2  bouyer 	}
    448  1.1.4.2  bouyer #endif /* NBIVIDEO > 0 */
    449  1.1.4.2  bouyer 	bzero(&hpcfb_console_dc, sizeof(struct hpcfb_devconfig));
    450  1.1.4.2  bouyer 	if (hpcfb_init(fbconf, &hpcfb_console_dc) != 0)
    451  1.1.4.2  bouyer 		return (ENXIO);
    452  1.1.4.2  bouyer 
    453  1.1.4.2  bouyer 	hpcfb_console_dc.dc_tvram = hpcfb_console_tvram;
    454  1.1.4.2  bouyer 	bzero(hpcfb_console_tvram, sizeof(hpcfb_console_tvram));
    455  1.1.4.2  bouyer 
    456  1.1.4.2  bouyer 	hpcfb_console_wsscreen = hpcfb_stdscreen;
    457  1.1.4.2  bouyer 	hpcfb_console_wsscreen.nrows = hpcfb_console_dc.dc_rows;
    458  1.1.4.2  bouyer 	hpcfb_console_wsscreen.ncols = hpcfb_console_dc.dc_cols;
    459  1.1.4.2  bouyer 	hpcfb_console_wsscreen.capabilities = hpcfb_console_dc.dc_rinfo.ri_caps;
    460  1.1.4.2  bouyer 	hpcfb_alloc_attr(&hpcfb_console_dc, 7, 0, 0, &defattr);
    461  1.1.4.2  bouyer 	wsdisplay_cnattach(&hpcfb_console_wsscreen, &hpcfb_console_dc,
    462  1.1.4.2  bouyer 			   0, 0, defattr);
    463  1.1.4.2  bouyer 	hpcfbconsole = 1;
    464  1.1.4.2  bouyer 
    465  1.1.4.2  bouyer 	return (0);
    466  1.1.4.2  bouyer }
    467  1.1.4.2  bouyer 
    468  1.1.4.2  bouyer int
    469  1.1.4.2  bouyer hpcfb_init(fbconf, dc)
    470  1.1.4.2  bouyer 	struct hpcfb_fbconf *fbconf;
    471  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
    472  1.1.4.2  bouyer {
    473  1.1.4.2  bouyer 	struct rasops_info *ri;
    474  1.1.4.2  bouyer 	vaddr_t fbaddr;
    475  1.1.4.2  bouyer 
    476  1.1.4.2  bouyer 	fbaddr = (vaddr_t)fbconf->hf_baseaddr;
    477  1.1.4.2  bouyer 	dc->dc_fbaddr = (u_char *)fbaddr;
    478  1.1.4.2  bouyer 
    479  1.1.4.2  bouyer 	/* init rasops */
    480  1.1.4.2  bouyer 	ri = &dc->dc_rinfo;
    481  1.1.4.2  bouyer 	bzero(ri, sizeof(struct rasops_info));
    482  1.1.4.2  bouyer 	ri->ri_depth = fbconf->hf_pixel_width;
    483  1.1.4.2  bouyer 	ri->ri_bits = (caddr_t)fbaddr;
    484  1.1.4.2  bouyer 	ri->ri_width = fbconf->hf_width;
    485  1.1.4.2  bouyer 	ri->ri_height = fbconf->hf_height;
    486  1.1.4.2  bouyer 	ri->ri_stride = fbconf->hf_bytes_per_line;
    487  1.1.4.2  bouyer #if 0
    488  1.1.4.2  bouyer 	ri->ri_flg = RI_FORCEMONO | RI_CURSOR;
    489  1.1.4.2  bouyer #else
    490  1.1.4.2  bouyer 	ri->ri_flg = RI_CURSOR;
    491  1.1.4.2  bouyer #endif
    492  1.1.4.2  bouyer 	if (rasops_init(ri, HPCFB_MAX_ROW, HPCFB_MAX_COLUMN)) {
    493  1.1.4.2  bouyer 		panic("%s(%d): rasops_init() failed!", __FILE__, __LINE__);
    494  1.1.4.2  bouyer 	}
    495  1.1.4.2  bouyer 
    496  1.1.4.2  bouyer 	/* over write color map of rasops */
    497  1.1.4.2  bouyer 	hpcfb_cmap_reorder (fbconf, dc);
    498  1.1.4.2  bouyer 
    499  1.1.4.2  bouyer 	dc->dc_curx = -1;
    500  1.1.4.2  bouyer 	dc->dc_cury = -1;
    501  1.1.4.2  bouyer 	dc->dc_rows = dc->dc_rinfo.ri_rows;
    502  1.1.4.2  bouyer 	dc->dc_cols = dc->dc_rinfo.ri_cols;
    503  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_CURRENT;
    504  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    505  1.1.4.2  bouyer 	dc->dc_max_row = 0;
    506  1.1.4.2  bouyer 	dc->dc_min_row = dc->dc_rows;
    507  1.1.4.2  bouyer 	dc->dc_scroll = 0;
    508  1.1.4.2  bouyer 	callout_init(&dc->dc_scroll_ch);
    509  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    510  1.1.4.2  bouyer 	dc->dc_memsize = ri->ri_stride * ri->ri_height;
    511  1.1.4.2  bouyer 	dc->dc_scrno = 0;
    512  1.1.4.2  bouyer 	/* hook rasops in hpcfb_ops */
    513  1.1.4.2  bouyer 	rasops_emul = ri->ri_ops; /* struct copy */
    514  1.1.4.2  bouyer 	ri->ri_ops = hpcfb_emulops; /* struct copy */
    515  1.1.4.2  bouyer 
    516  1.1.4.2  bouyer 	return (0);
    517  1.1.4.2  bouyer }
    518  1.1.4.2  bouyer 
    519  1.1.4.2  bouyer static void
    520  1.1.4.2  bouyer hpcfb_cmap_reorder(fbconf, dc)
    521  1.1.4.2  bouyer 	struct hpcfb_fbconf *fbconf;
    522  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
    523  1.1.4.2  bouyer {
    524  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
    525  1.1.4.2  bouyer 	int reverse = fbconf->hf_access_flags & HPCFB_ACCESS_REVERSE;
    526  1.1.4.2  bouyer 	int *cmap = ri->ri_devcmap;
    527  1.1.4.2  bouyer 	vaddr_t fbaddr = (vaddr_t)fbconf->hf_baseaddr;
    528  1.1.4.2  bouyer 	int i, j, bg, fg, tmp;
    529  1.1.4.2  bouyer 
    530  1.1.4.2  bouyer 	/*
    531  1.1.4.2  bouyer 	 * Set forground and background so that the screen
    532  1.1.4.2  bouyer 	 * looks black on white.
    533  1.1.4.2  bouyer 	 * Normally, black = 00 and white = ff.
    534  1.1.4.2  bouyer 	 * HPCFB_ACCESS_REVERSE means black = ff and white = 00.
    535  1.1.4.2  bouyer 	 */
    536  1.1.4.2  bouyer 	switch (fbconf->hf_pixel_width) {
    537  1.1.4.2  bouyer 	case 1:
    538  1.1.4.2  bouyer 		/* FALLTHROUGH */
    539  1.1.4.2  bouyer 	case 2:
    540  1.1.4.2  bouyer 		/* FALLTHROUGH */
    541  1.1.4.2  bouyer 	case 4:
    542  1.1.4.2  bouyer 		if (reverse) {
    543  1.1.4.2  bouyer 			bg = 0;
    544  1.1.4.2  bouyer 			fg = ~0;
    545  1.1.4.2  bouyer 		} else {
    546  1.1.4.2  bouyer 			bg = ~0;
    547  1.1.4.2  bouyer 			fg = 0;
    548  1.1.4.2  bouyer 		}
    549  1.1.4.2  bouyer 		/* for gray-scale LCD, hi-contrast color map */
    550  1.1.4.2  bouyer 		cmap[0] = bg;
    551  1.1.4.2  bouyer 		for (i = 1; i < 16; i++)
    552  1.1.4.2  bouyer 			cmap[i] = fg;
    553  1.1.4.2  bouyer 		break;
    554  1.1.4.2  bouyer 	case 8:
    555  1.1.4.2  bouyer 		/* FALLTHROUGH */
    556  1.1.4.2  bouyer 	case 16:
    557  1.1.4.2  bouyer 		if (reverse) {
    558  1.1.4.2  bouyer 			for (i = 0, j = 15; i < 8; i++, j--) {
    559  1.1.4.2  bouyer 				tmp = cmap[i];
    560  1.1.4.2  bouyer 				cmap[i] = cmap[j];
    561  1.1.4.2  bouyer 				cmap[j] = tmp;
    562  1.1.4.2  bouyer 			}
    563  1.1.4.2  bouyer 		}
    564  1.1.4.2  bouyer 		break;
    565  1.1.4.2  bouyer 	}
    566  1.1.4.2  bouyer 
    567  1.1.4.2  bouyer 	/* clear the screen */
    568  1.1.4.2  bouyer 	bg = cmap[0];
    569  1.1.4.2  bouyer 	for (i = 0;
    570  1.1.4.2  bouyer 	     i < fbconf->hf_height * fbconf->hf_bytes_per_line;
    571  1.1.4.2  bouyer 	     i += sizeof(u_int32_t)) {
    572  1.1.4.2  bouyer 		*(u_int32_t *)(fbaddr + i) = bg;
    573  1.1.4.2  bouyer 	}
    574  1.1.4.2  bouyer }
    575  1.1.4.2  bouyer 
    576  1.1.4.2  bouyer int
    577  1.1.4.2  bouyer hpcfb_ioctl(v, cmd, data, flag, p)
    578  1.1.4.2  bouyer 	void *v;
    579  1.1.4.2  bouyer 	u_long cmd;
    580  1.1.4.2  bouyer 	caddr_t data;
    581  1.1.4.2  bouyer 	int flag;
    582  1.1.4.2  bouyer 	struct proc *p;
    583  1.1.4.2  bouyer {
    584  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    585  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = sc->sc_dc;
    586  1.1.4.2  bouyer 	struct wsdisplay_fbinfo *wdf;
    587  1.1.4.2  bouyer 
    588  1.1.4.2  bouyer 	switch (cmd) {
    589  1.1.4.2  bouyer 	case WSKBDIO_BELL:
    590  1.1.4.2  bouyer 		return (0);
    591  1.1.4.2  bouyer 		break;
    592  1.1.4.2  bouyer 
    593  1.1.4.2  bouyer 	case WSDISPLAYIO_GTYPE:
    594  1.1.4.2  bouyer 		*(u_int *)data = WSDISPLAY_TYPE_HPCFB;
    595  1.1.4.2  bouyer 		return 0;
    596  1.1.4.2  bouyer 
    597  1.1.4.2  bouyer 	case WSDISPLAYIO_GINFO:
    598  1.1.4.2  bouyer 		wdf = (void *)data;
    599  1.1.4.2  bouyer 		wdf->height = dc->dc_rinfo.ri_height;
    600  1.1.4.2  bouyer 		wdf->width = dc->dc_rinfo.ri_width;
    601  1.1.4.2  bouyer 		wdf->depth = dc->dc_rinfo.ri_depth;
    602  1.1.4.2  bouyer 		wdf->cmsize = 256;	/* XXXX */
    603  1.1.4.2  bouyer 		return 0;
    604  1.1.4.2  bouyer 
    605  1.1.4.2  bouyer 	case WSDISPLAYIO_SMODE:
    606  1.1.4.2  bouyer 		if (*(int *)data == WSDISPLAYIO_MODE_EMUL){
    607  1.1.4.2  bouyer 			if (sc->sc_mapping){
    608  1.1.4.2  bouyer 				sc->sc_mapping = 0;
    609  1.1.4.2  bouyer 				if (dc->dc_state&HPCFB_DC_DRAWING)
    610  1.1.4.2  bouyer 					dc->dc_state &= ~HPCFB_DC_ABORT;
    611  1.1.4.2  bouyer #ifdef HPCFB_FORCE_REDRAW
    612  1.1.4.2  bouyer 				hpcfb_refresh_screen(sc);
    613  1.1.4.2  bouyer #else
    614  1.1.4.2  bouyer 				dc->dc_state |= HPCFB_DC_UPDATEALL;
    615  1.1.4.2  bouyer #endif
    616  1.1.4.2  bouyer 			}
    617  1.1.4.2  bouyer 		} else {
    618  1.1.4.2  bouyer 			if (!sc->sc_mapping) {
    619  1.1.4.2  bouyer 				sc->sc_mapping = 1;
    620  1.1.4.2  bouyer 				dc->dc_state |= HPCFB_DC_ABORT;
    621  1.1.4.2  bouyer 			}
    622  1.1.4.2  bouyer 			sc->sc_mapping = 1;
    623  1.1.4.2  bouyer 		}
    624  1.1.4.2  bouyer 		if (sc && sc->sc_accessops->iodone)
    625  1.1.4.2  bouyer 			(*sc->sc_accessops->iodone)(sc->sc_accessctx);
    626  1.1.4.2  bouyer 		return 0;
    627  1.1.4.2  bouyer 
    628  1.1.4.2  bouyer 	case WSDISPLAYIO_GETCMAP:
    629  1.1.4.2  bouyer 	case WSDISPLAYIO_PUTCMAP:
    630  1.1.4.2  bouyer 	case WSDISPLAYIO_GETPARAM:
    631  1.1.4.2  bouyer 	case WSDISPLAYIO_SETPARAM:
    632  1.1.4.2  bouyer 	case HPCFBIO_GCONF:
    633  1.1.4.2  bouyer 	case HPCFBIO_SCONF:
    634  1.1.4.2  bouyer 	case HPCFBIO_GDSPCONF:
    635  1.1.4.2  bouyer 	case HPCFBIO_SDSPCONF:
    636  1.1.4.2  bouyer 	case HPCFBIO_GOP:
    637  1.1.4.2  bouyer 	case HPCFBIO_SOP:
    638  1.1.4.2  bouyer 		return (*sc->sc_accessops->ioctl)(sc->sc_accessctx,
    639  1.1.4.2  bouyer 						  cmd, data, flag, p);
    640  1.1.4.2  bouyer 
    641  1.1.4.2  bouyer 	default:
    642  1.1.4.2  bouyer 		if (IOCGROUP(cmd) != 't')
    643  1.1.4.2  bouyer 			DPRINTF(("%s(%d): hpcfb_ioctl(%lx, %lx) grp=%c num=%ld\n",
    644  1.1.4.2  bouyer 			 __FILE__, __LINE__,
    645  1.1.4.2  bouyer 			 cmd, (u_long)data, (char)IOCGROUP(cmd), cmd&0xff));
    646  1.1.4.2  bouyer 		break;
    647  1.1.4.2  bouyer 	}
    648  1.1.4.2  bouyer 
    649  1.1.4.2  bouyer 	return (ENOTTY); /* Inappropriate ioctl for device */
    650  1.1.4.2  bouyer }
    651  1.1.4.2  bouyer 
    652  1.1.4.2  bouyer paddr_t
    653  1.1.4.2  bouyer hpcfb_mmap(v, offset, prot)
    654  1.1.4.2  bouyer 	void *v;
    655  1.1.4.2  bouyer 	off_t offset;
    656  1.1.4.2  bouyer 	int prot;
    657  1.1.4.2  bouyer {
    658  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    659  1.1.4.2  bouyer 
    660  1.1.4.2  bouyer 	return (*sc->sc_accessops->mmap)(sc->sc_accessctx, offset, prot);
    661  1.1.4.2  bouyer }
    662  1.1.4.2  bouyer 
    663  1.1.4.2  bouyer static void
    664  1.1.4.2  bouyer hpcfb_power(why, arg)
    665  1.1.4.2  bouyer 	int why;
    666  1.1.4.2  bouyer 	void *arg;
    667  1.1.4.2  bouyer {
    668  1.1.4.2  bouyer 	struct hpcfb_softc *sc = arg;
    669  1.1.4.2  bouyer 
    670  1.1.4.2  bouyer 	switch (why) {
    671  1.1.4.2  bouyer 	case PWR_STANDBY:
    672  1.1.4.2  bouyer 		break;
    673  1.1.4.2  bouyer 	case PWR_SOFTSUSPEND:
    674  1.1.4.2  bouyer 		/* XXX, casting to 'struct wsdisplay_softc *' means
    675  1.1.4.2  bouyer 		   that you should not call the method here... */
    676  1.1.4.2  bouyer 		sc->sc_screen_resumed = wsdisplay_getactivescreen(
    677  1.1.4.2  bouyer 			(struct wsdisplay_softc *)sc->sc_wsdisplay);
    678  1.1.4.2  bouyer 		if (wsdisplay_switch(sc->sc_wsdisplay,
    679  1.1.4.2  bouyer 		    WSDISPLAY_NULLSCREEN,
    680  1.1.4.2  bouyer 		    1 /* waitok */) == 0) {
    681  1.1.4.2  bouyer 			wsscreen_switchwait(
    682  1.1.4.2  bouyer 				(struct wsdisplay_softc *)sc->sc_wsdisplay,
    683  1.1.4.2  bouyer 				WSDISPLAY_NULLSCREEN);
    684  1.1.4.2  bouyer 		} else {
    685  1.1.4.2  bouyer 			sc->sc_screen_resumed = WSDISPLAY_NULLSCREEN;
    686  1.1.4.2  bouyer 		}
    687  1.1.4.2  bouyer 		break;
    688  1.1.4.2  bouyer 	case PWR_SOFTRESUME:
    689  1.1.4.2  bouyer 		if (sc->sc_screen_resumed != WSDISPLAY_NULLSCREEN)
    690  1.1.4.2  bouyer 			wsdisplay_switch(sc->sc_wsdisplay,
    691  1.1.4.2  bouyer 			    sc->sc_screen_resumed,
    692  1.1.4.2  bouyer 			    1 /* waitok */);
    693  1.1.4.2  bouyer 		break;
    694  1.1.4.2  bouyer 	}
    695  1.1.4.2  bouyer }
    696  1.1.4.2  bouyer 
    697  1.1.4.2  bouyer void
    698  1.1.4.2  bouyer hpcfb_refresh_screen(sc)
    699  1.1.4.2  bouyer 	struct hpcfb_softc *sc;
    700  1.1.4.2  bouyer {
    701  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = sc->sc_dc;
    702  1.1.4.2  bouyer 	int x, y;
    703  1.1.4.2  bouyer 
    704  1.1.4.2  bouyer 	if (dc == NULL)
    705  1.1.4.2  bouyer 		return;
    706  1.1.4.2  bouyer 
    707  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    708  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
    709  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
    710  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_UPDATE;
    711  1.1.4.2  bouyer 		callout_stop(&dc->dc_scroll_ch);
    712  1.1.4.2  bouyer 	}
    713  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    714  1.1.4.2  bouyer 	/*
    715  1.1.4.2  bouyer 	 * refresh screen
    716  1.1.4.2  bouyer 	 */
    717  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_UPDATEALL;
    718  1.1.4.2  bouyer 	x = dc->dc_curx;
    719  1.1.4.2  bouyer 	y = dc->dc_cury;
    720  1.1.4.2  bouyer 	if (0 <= x && 0 <= y)
    721  1.1.4.2  bouyer 		hpcfb_cursor_raw(dc, 0,  y, x); /* disable cursor */
    722  1.1.4.2  bouyer 	/* redraw all text */
    723  1.1.4.2  bouyer 	hpcfb_redraw(dc, 0, dc->dc_rows, 1);
    724  1.1.4.2  bouyer 	if (0 <= x && 0 <= y)
    725  1.1.4.2  bouyer 		hpcfb_cursor_raw(dc, 1,  y, x); /* enable cursor */
    726  1.1.4.2  bouyer }
    727  1.1.4.2  bouyer 
    728  1.1.4.2  bouyer static int
    729  1.1.4.2  bouyer hpcfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    730  1.1.4.2  bouyer 	void *v;
    731  1.1.4.2  bouyer 	const struct wsscreen_descr *type;
    732  1.1.4.2  bouyer 	void **cookiep;
    733  1.1.4.2  bouyer 	int *curxp, *curyp;
    734  1.1.4.2  bouyer 	long *attrp;
    735  1.1.4.2  bouyer {
    736  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    737  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
    738  1.1.4.2  bouyer 
    739  1.1.4.2  bouyer 	DPRINTF(("%s(%d): hpcfb_alloc_screen()\n", __FILE__, __LINE__));
    740  1.1.4.2  bouyer 
    741  1.1.4.2  bouyer 	if (!hpcfbconsole && sc->nscreens > 0)	/* XXXXX */
    742  1.1.4.2  bouyer 		return ENOMEM;
    743  1.1.4.2  bouyer 
    744  1.1.4.2  bouyer 	if (sc->nscreens > HPCFB_MAX_SCREEN)
    745  1.1.4.2  bouyer 		return (ENOMEM);
    746  1.1.4.2  bouyer 
    747  1.1.4.2  bouyer 	if (sc->screens[sc->nscreens] == NULL){
    748  1.1.4.2  bouyer 		sc->screens[sc->nscreens] =
    749  1.1.4.2  bouyer 			malloc(sizeof(struct hpcfb_devconfig), M_DEVBUF, M_WAITOK);
    750  1.1.4.2  bouyer 		if (sc->screens[sc->nscreens] == NULL)
    751  1.1.4.2  bouyer 			return ENOMEM;
    752  1.1.4.2  bouyer 		bzero(sc->screens[sc->nscreens], sizeof(struct hpcfb_devconfig));
    753  1.1.4.2  bouyer 	}
    754  1.1.4.2  bouyer 	dc = sc->screens[sc->nscreens];
    755  1.1.4.2  bouyer 	dc->dc_sc = sc;
    756  1.1.4.2  bouyer 
    757  1.1.4.2  bouyer 	/* copy master raster info */
    758  1.1.4.2  bouyer 	dc->dc_rinfo = sc->sc_dc->dc_rinfo;
    759  1.1.4.2  bouyer 	if (sc->sc_accessops->font) {
    760  1.1.4.2  bouyer 		sc->sc_accessops->font(sc->sc_accessctx,
    761  1.1.4.2  bouyer 					sc->sc_dc->dc_rinfo.ri_font);
    762  1.1.4.2  bouyer 	}
    763  1.1.4.2  bouyer 
    764  1.1.4.2  bouyer 	dc->dc_fbaddr = dc->dc_rinfo.ri_bits;
    765  1.1.4.2  bouyer 	dc->dc_rows = dc->dc_rinfo.ri_rows;
    766  1.1.4.2  bouyer 	dc->dc_cols = dc->dc_rinfo.ri_cols;
    767  1.1.4.2  bouyer 	dc->dc_memsize = dc->dc_rinfo.ri_stride * dc->dc_rinfo.ri_height;
    768  1.1.4.2  bouyer 
    769  1.1.4.2  bouyer 	dc->dc_scrno = sc->nscreens;
    770  1.1.4.2  bouyer 	dc->dc_curx = -1;
    771  1.1.4.2  bouyer 	dc->dc_cury = -1;
    772  1.1.4.2  bouyer 	if (dc->dc_tvram == NULL){
    773  1.1.4.2  bouyer 		dc->dc_tvram =
    774  1.1.4.2  bouyer 			malloc(sizeof(struct hpcfb_tvrow)*dc->dc_rows,
    775  1.1.4.2  bouyer 				M_DEVBUF, M_WAITOK);
    776  1.1.4.2  bouyer 		if (dc->dc_tvram == NULL){
    777  1.1.4.2  bouyer 			free(sc->screens[sc->nscreens], M_DEVBUF);
    778  1.1.4.2  bouyer 			sc->screens[sc->nscreens] = NULL;
    779  1.1.4.2  bouyer 			return ENOMEM;
    780  1.1.4.2  bouyer 		}
    781  1.1.4.2  bouyer 		bzero(dc->dc_tvram,
    782  1.1.4.2  bouyer 				sizeof(struct hpcfb_tvrow)*dc->dc_rows);
    783  1.1.4.2  bouyer 	}
    784  1.1.4.2  bouyer 
    785  1.1.4.2  bouyer 	*curxp = 0;
    786  1.1.4.2  bouyer 	*curyp = 0;
    787  1.1.4.2  bouyer 	sc->nscreens++;
    788  1.1.4.2  bouyer 	*cookiep = dc;
    789  1.1.4.2  bouyer 	hpcfb_alloc_attr(*cookiep, 7, 0, 0, attrp);
    790  1.1.4.2  bouyer 	return (0);
    791  1.1.4.2  bouyer }
    792  1.1.4.2  bouyer 
    793  1.1.4.2  bouyer static void
    794  1.1.4.2  bouyer hpcfb_free_screen(v, cookie)
    795  1.1.4.2  bouyer 	void *v;
    796  1.1.4.2  bouyer 	void *cookie;
    797  1.1.4.2  bouyer {
    798  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    799  1.1.4.2  bouyer 
    800  1.1.4.2  bouyer 	if (sc->nscreens == 1 && sc->sc_dc == &hpcfb_console_dc)
    801  1.1.4.2  bouyer 		panic("hpcfb_free_screen: console");
    802  1.1.4.2  bouyer 	sc->nscreens--;
    803  1.1.4.2  bouyer }
    804  1.1.4.2  bouyer 
    805  1.1.4.2  bouyer static int
    806  1.1.4.2  bouyer hpcfb_show_screen(v, cookie, waitok, cb, cbarg)
    807  1.1.4.2  bouyer 	void *v;
    808  1.1.4.2  bouyer 	void *cookie;
    809  1.1.4.2  bouyer 	int waitok;
    810  1.1.4.2  bouyer 	void (*cb) __P((void *, int, int));
    811  1.1.4.2  bouyer 	void *cbarg;
    812  1.1.4.2  bouyer {
    813  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    814  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
    815  1.1.4.2  bouyer 	struct hpcfb_devconfig *odc;
    816  1.1.4.2  bouyer 
    817  1.1.4.2  bouyer 	DPRINTF(("%s(%d): hpcfb_show_screen()\n", __FILE__, __LINE__));
    818  1.1.4.2  bouyer 
    819  1.1.4.2  bouyer 	odc = sc->sc_dc;
    820  1.1.4.2  bouyer 
    821  1.1.4.2  bouyer 	if (dc == NULL || odc == dc) {
    822  1.1.4.2  bouyer 		hpcfb_refresh_screen(sc);
    823  1.1.4.2  bouyer 		return 0;
    824  1.1.4.2  bouyer 	}
    825  1.1.4.2  bouyer 
    826  1.1.4.2  bouyer 	sc->sc_wantedscreen = cookie;
    827  1.1.4.2  bouyer 	sc->sc_switchcb = cb;
    828  1.1.4.2  bouyer 	sc->sc_switchcbarg = cbarg;
    829  1.1.4.2  bouyer 	if (cb) {
    830  1.1.4.2  bouyer 		callout_reset(&sc->sc_switch_callout, 0,
    831  1.1.4.2  bouyer 			(void(*)(void *))hpcfb_doswitch, sc);
    832  1.1.4.2  bouyer 		return EAGAIN;
    833  1.1.4.2  bouyer 	}
    834  1.1.4.2  bouyer 
    835  1.1.4.2  bouyer 	hpcfb_doswitch(sc);
    836  1.1.4.2  bouyer 	return 0;
    837  1.1.4.2  bouyer }
    838  1.1.4.2  bouyer 
    839  1.1.4.2  bouyer void
    840  1.1.4.2  bouyer hpcfb_doswitch(sc)
    841  1.1.4.2  bouyer 	struct hpcfb_softc *sc;
    842  1.1.4.2  bouyer {
    843  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
    844  1.1.4.2  bouyer 	struct hpcfb_devconfig *odc;
    845  1.1.4.2  bouyer 
    846  1.1.4.2  bouyer 	odc = sc->sc_dc;
    847  1.1.4.2  bouyer 	dc = sc->sc_wantedscreen;
    848  1.1.4.2  bouyer 
    849  1.1.4.2  bouyer 	if (!dc) {
    850  1.1.4.2  bouyer 		(*sc->sc_switchcb)(sc->sc_switchcbarg, EIO, 0);
    851  1.1.4.2  bouyer 		return;
    852  1.1.4.2  bouyer 	}
    853  1.1.4.2  bouyer 
    854  1.1.4.2  bouyer 	if (odc == dc)
    855  1.1.4.2  bouyer 		return;
    856  1.1.4.2  bouyer 
    857  1.1.4.2  bouyer 	if (odc) {
    858  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    859  1.1.4.2  bouyer 		odc->dc_state |= HPCFB_DC_ABORT;
    860  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    861  1.1.4.2  bouyer 
    862  1.1.4.2  bouyer 		if (odc->dc_curx >= 0 && odc->dc_cury >= 0)
    863  1.1.4.2  bouyer 			hpcfb_cursor_raw(odc, 0,  odc->dc_cury, odc->dc_curx);
    864  1.1.4.2  bouyer 			 /* disable cursor */
    865  1.1.4.2  bouyer 		/* disable old screen */
    866  1.1.4.2  bouyer 		odc->dc_state &= ~HPCFB_DC_CURRENT;
    867  1.1.4.2  bouyer 		odc->dc_rinfo.ri_bits = NULL;
    868  1.1.4.2  bouyer 	}
    869  1.1.4.2  bouyer 	/* switch screen to new one */
    870  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_CURRENT;
    871  1.1.4.2  bouyer 	dc->dc_rinfo.ri_bits = dc->dc_fbaddr;
    872  1.1.4.2  bouyer 	sc->sc_dc = dc;
    873  1.1.4.2  bouyer 
    874  1.1.4.2  bouyer 	/* redraw screen image */
    875  1.1.4.2  bouyer 	hpcfb_refresh_screen(sc);
    876  1.1.4.2  bouyer 
    877  1.1.4.2  bouyer 	sc->sc_wantedscreen = NULL;
    878  1.1.4.2  bouyer 	if (sc->sc_switchcb)
    879  1.1.4.2  bouyer 		(*sc->sc_switchcb)(sc->sc_switchcbarg, 0, 0);
    880  1.1.4.2  bouyer 
    881  1.1.4.2  bouyer 	return;
    882  1.1.4.2  bouyer }
    883  1.1.4.2  bouyer 
    884  1.1.4.2  bouyer static void
    885  1.1.4.2  bouyer hpcfb_pollc(v, on)
    886  1.1.4.2  bouyer 	void *v;
    887  1.1.4.2  bouyer 	int on;
    888  1.1.4.2  bouyer {
    889  1.1.4.2  bouyer 	struct hpcfb_softc *sc = v;
    890  1.1.4.2  bouyer 
    891  1.1.4.2  bouyer 	if (sc == NULL)
    892  1.1.4.2  bouyer 		return;
    893  1.1.4.2  bouyer 	sc->sc_polling = on;
    894  1.1.4.2  bouyer 	if (sc->sc_accessops->iodone)
    895  1.1.4.2  bouyer 		(*sc->sc_accessops->iodone)(sc->sc_accessctx);
    896  1.1.4.2  bouyer 	if (on) {
    897  1.1.4.2  bouyer 		hpcfb_refresh_screen(sc);
    898  1.1.4.2  bouyer 		if (sc->sc_accessops->iodone)
    899  1.1.4.2  bouyer 			(*sc->sc_accessops->iodone)(sc->sc_accessctx);
    900  1.1.4.2  bouyer 	}
    901  1.1.4.2  bouyer 
    902  1.1.4.2  bouyer 	return;
    903  1.1.4.2  bouyer }
    904  1.1.4.2  bouyer 
    905  1.1.4.2  bouyer /*
    906  1.1.4.2  bouyer  * cursor
    907  1.1.4.2  bouyer  */
    908  1.1.4.2  bouyer void
    909  1.1.4.2  bouyer hpcfb_cursor(cookie, on, row, col)
    910  1.1.4.2  bouyer 	void *cookie;
    911  1.1.4.2  bouyer 	int on, row, col;
    912  1.1.4.2  bouyer {
    913  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
    914  1.1.4.2  bouyer 
    915  1.1.4.2  bouyer 	if (on) {
    916  1.1.4.2  bouyer 		dc->dc_curx = col;
    917  1.1.4.2  bouyer 		dc->dc_cury = row;
    918  1.1.4.2  bouyer 	} else {
    919  1.1.4.2  bouyer 		dc->dc_curx = -1;
    920  1.1.4.2  bouyer 		dc->dc_cury = -1;
    921  1.1.4.2  bouyer 	}
    922  1.1.4.2  bouyer 
    923  1.1.4.2  bouyer 	hpcfb_cursor_raw(cookie, on, row, col);
    924  1.1.4.2  bouyer }
    925  1.1.4.2  bouyer 
    926  1.1.4.2  bouyer void
    927  1.1.4.2  bouyer hpcfb_cursor_raw(cookie, on, row, col)
    928  1.1.4.2  bouyer 	void *cookie;
    929  1.1.4.2  bouyer 	int on, row, col;
    930  1.1.4.2  bouyer {
    931  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
    932  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
    933  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
    934  1.1.4.2  bouyer 	int curwidth, curheight;
    935  1.1.4.2  bouyer 	int xoff, yoff;
    936  1.1.4.2  bouyer 
    937  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    938  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
    939  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
    940  1.1.4.2  bouyer 		return;
    941  1.1.4.2  bouyer 	}
    942  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
    943  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
    944  1.1.4.2  bouyer 		return;
    945  1.1.4.2  bouyer 
    946  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
    947  1.1.4.2  bouyer 		return;
    948  1.1.4.2  bouyer 
    949  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
    950  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->cursor) {
    951  1.1.4.2  bouyer 		xoff = col * ri->ri_font->fontwidth;
    952  1.1.4.2  bouyer 		yoff = row * ri->ri_font->fontheight;
    953  1.1.4.2  bouyer 		curheight = ri->ri_font->fontheight;
    954  1.1.4.2  bouyer 		curwidth = ri->ri_font->fontwidth;
    955  1.1.4.2  bouyer 		(*sc->sc_accessops->cursor)(sc->sc_accessctx,
    956  1.1.4.2  bouyer 				on, xoff, yoff, curwidth, curheight);
    957  1.1.4.2  bouyer 	} else
    958  1.1.4.2  bouyer 		rasops_emul.cursor(ri, on, row, col);
    959  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
    960  1.1.4.2  bouyer }
    961  1.1.4.2  bouyer 
    962  1.1.4.2  bouyer /*
    963  1.1.4.2  bouyer  * mapchar
    964  1.1.4.2  bouyer  */
    965  1.1.4.2  bouyer int
    966  1.1.4.2  bouyer hpcfb_mapchar(cookie, c, cp)
    967  1.1.4.2  bouyer 	void *cookie;
    968  1.1.4.2  bouyer 	int c;
    969  1.1.4.2  bouyer 	unsigned int *cp;
    970  1.1.4.2  bouyer {
    971  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
    972  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
    973  1.1.4.2  bouyer 
    974  1.1.4.2  bouyer 	return rasops_emul.mapchar(ri, c, cp);
    975  1.1.4.2  bouyer }
    976  1.1.4.2  bouyer 
    977  1.1.4.2  bouyer /*
    978  1.1.4.2  bouyer  * putchar
    979  1.1.4.2  bouyer  */
    980  1.1.4.2  bouyer void
    981  1.1.4.2  bouyer hpcfb_tv_putchar(dc, row, col, uc, attr)
    982  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
    983  1.1.4.2  bouyer 	int row, col;
    984  1.1.4.2  bouyer 	u_int uc;
    985  1.1.4.2  bouyer 	long attr;
    986  1.1.4.2  bouyer {
    987  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
    988  1.1.4.2  bouyer 	struct hpcfb_vchar *vc = &vscn[row].col[col];
    989  1.1.4.2  bouyer 	struct hpcfb_vchar *vcb;
    990  1.1.4.2  bouyer 
    991  1.1.4.2  bouyer 	if (vscn == 0)
    992  1.1.4.2  bouyer 		return;
    993  1.1.4.2  bouyer 
    994  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
    995  1.1.4.2  bouyer #ifdef HPCFB_JUMP
    996  1.1.4.2  bouyer 	if (row < dc->dc_min_row)
    997  1.1.4.2  bouyer 		dc->dc_min_row = row;
    998  1.1.4.2  bouyer 	if (row > dc->dc_max_row)
    999  1.1.4.2  bouyer 		dc->dc_max_row = row;
   1000  1.1.4.2  bouyer 
   1001  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1002  1.1.4.2  bouyer 	if (vscn[row].maxcol +1 == col)
   1003  1.1.4.2  bouyer 		vscn[row].maxcol = col;
   1004  1.1.4.2  bouyer 	else if (vscn[row].maxcol < col) {
   1005  1.1.4.2  bouyer 		vcb =  &vscn[row].col[vscn[row].maxcol+1];
   1006  1.1.4.2  bouyer 		bzero(vcb, sizeof(struct hpcfb_vchar)*(col-vscn[row].maxcol-1));
   1007  1.1.4.2  bouyer 		vscn[row].maxcol = col;
   1008  1.1.4.2  bouyer 	}
   1009  1.1.4.2  bouyer 	vc->c = uc;
   1010  1.1.4.2  bouyer 	vc->attr = attr;
   1011  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1012  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1013  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1014  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1015  1.1.4.2  bouyer }
   1016  1.1.4.2  bouyer 
   1017  1.1.4.2  bouyer void
   1018  1.1.4.2  bouyer hpcfb_putchar(cookie, row, col, uc, attr)
   1019  1.1.4.2  bouyer 	void *cookie;
   1020  1.1.4.2  bouyer 	int row, col;
   1021  1.1.4.2  bouyer 	u_int uc;
   1022  1.1.4.2  bouyer 	long attr;
   1023  1.1.4.2  bouyer {
   1024  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1025  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
   1026  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1027  1.1.4.2  bouyer 	int xoff;
   1028  1.1.4.2  bouyer 	int yoff;
   1029  1.1.4.2  bouyer 	int fclr, uclr;
   1030  1.1.4.2  bouyer 	struct wsdisplay_font *font;
   1031  1.1.4.2  bouyer 
   1032  1.1.4.2  bouyer 	hpcfb_tv_putchar(dc, row, col, uc, attr);
   1033  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1034  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
   1035  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
   1036  1.1.4.2  bouyer 		return;
   1037  1.1.4.2  bouyer 	}
   1038  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1039  1.1.4.2  bouyer 
   1040  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1041  1.1.4.2  bouyer 		return;
   1042  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1043  1.1.4.2  bouyer 		return;
   1044  1.1.4.2  bouyer 
   1045  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
   1046  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->putchar
   1047  1.1.4.2  bouyer 	       && (dc->dc_state&HPCFB_DC_CURRENT)) {
   1048  1.1.4.2  bouyer 		font = ri->ri_font;
   1049  1.1.4.2  bouyer 		yoff = row * ri->ri_font->fontheight;
   1050  1.1.4.2  bouyer 		xoff =  col * ri->ri_font->fontwidth;
   1051  1.1.4.2  bouyer 		fclr = ri->ri_devcmap[((u_int)attr >> 24) & 15];
   1052  1.1.4.2  bouyer 		uclr = ri->ri_devcmap[((u_int)attr >> 16) & 15];
   1053  1.1.4.2  bouyer 
   1054  1.1.4.2  bouyer 		(*sc->sc_accessops->putchar)(sc->sc_accessctx,
   1055  1.1.4.2  bouyer 				xoff, yoff, font, fclr, uclr, uc, attr);
   1056  1.1.4.2  bouyer 	} else
   1057  1.1.4.2  bouyer 		rasops_emul.putchar(ri, row, col, uc, attr);
   1058  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
   1059  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1060  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1061  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1062  1.1.4.2  bouyer }
   1063  1.1.4.2  bouyer 
   1064  1.1.4.2  bouyer /*
   1065  1.1.4.2  bouyer  * copycols
   1066  1.1.4.2  bouyer  */
   1067  1.1.4.2  bouyer void
   1068  1.1.4.2  bouyer hpcfb_tv_copycols(dc, row, srccol, dstcol, ncols)
   1069  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
   1070  1.1.4.2  bouyer 	int row, srccol, dstcol, ncols;
   1071  1.1.4.2  bouyer {
   1072  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
   1073  1.1.4.2  bouyer 	struct hpcfb_vchar *svc = &vscn[row].col[srccol];
   1074  1.1.4.2  bouyer 	struct hpcfb_vchar *dvc = &vscn[row].col[dstcol];
   1075  1.1.4.2  bouyer 
   1076  1.1.4.2  bouyer 	if (vscn == 0)
   1077  1.1.4.2  bouyer 		return;
   1078  1.1.4.2  bouyer 
   1079  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
   1080  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1081  1.1.4.2  bouyer 	if (row < dc->dc_min_row)
   1082  1.1.4.2  bouyer 		dc->dc_min_row = row;
   1083  1.1.4.2  bouyer 	if (row > dc->dc_max_row)
   1084  1.1.4.2  bouyer 		dc->dc_max_row = row;
   1085  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1086  1.1.4.2  bouyer 
   1087  1.1.4.2  bouyer 	bcopy(svc, dvc, ncols*sizeof(struct hpcfb_vchar));
   1088  1.1.4.2  bouyer 	if (vscn[row].maxcol < srccol+ncols-1)
   1089  1.1.4.2  bouyer 		vscn[row].maxcol = srccol+ncols-1;
   1090  1.1.4.2  bouyer 	if (vscn[row].maxcol < dstcol+ncols-1)
   1091  1.1.4.2  bouyer 		vscn[row].maxcol = dstcol+ncols-1;
   1092  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1093  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1094  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1095  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1096  1.1.4.2  bouyer }
   1097  1.1.4.2  bouyer 
   1098  1.1.4.2  bouyer void
   1099  1.1.4.2  bouyer hpcfb_copycols(cookie, row, srccol, dstcol, ncols)
   1100  1.1.4.2  bouyer 	void *cookie;
   1101  1.1.4.2  bouyer 	int row, srccol, dstcol, ncols;
   1102  1.1.4.2  bouyer {
   1103  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1104  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
   1105  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1106  1.1.4.2  bouyer 	int srcxoff,dstxoff;
   1107  1.1.4.2  bouyer 	int srcyoff,dstyoff;
   1108  1.1.4.2  bouyer 	int height, width;
   1109  1.1.4.2  bouyer 
   1110  1.1.4.2  bouyer 	hpcfb_tv_copycols(dc, row, srccol, dstcol, ncols);
   1111  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1112  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
   1113  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
   1114  1.1.4.2  bouyer 		return;
   1115  1.1.4.2  bouyer 	}
   1116  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1117  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1118  1.1.4.2  bouyer 		return;
   1119  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1120  1.1.4.2  bouyer 		return;
   1121  1.1.4.2  bouyer 
   1122  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
   1123  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->bitblit
   1124  1.1.4.2  bouyer 	       && (dc->dc_state&HPCFB_DC_CURRENT)) {
   1125  1.1.4.2  bouyer 		srcxoff = srccol * ri->ri_font->fontwidth;
   1126  1.1.4.2  bouyer 		srcyoff = row * ri->ri_font->fontheight;
   1127  1.1.4.2  bouyer 		dstxoff = dstcol * ri->ri_font->fontwidth;
   1128  1.1.4.2  bouyer 		dstyoff = row * ri->ri_font->fontheight;
   1129  1.1.4.2  bouyer 		width = ncols * ri->ri_font->fontwidth;
   1130  1.1.4.2  bouyer 		height = ri->ri_font->fontheight;
   1131  1.1.4.2  bouyer 		(*sc->sc_accessops->bitblit)(sc->sc_accessctx,
   1132  1.1.4.2  bouyer 			srcxoff, srcyoff, dstxoff, dstyoff, height, width);
   1133  1.1.4.2  bouyer 	} else
   1134  1.1.4.2  bouyer 		rasops_emul.copycols(ri, row, srccol, dstcol, ncols);
   1135  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
   1136  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1137  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1138  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1139  1.1.4.2  bouyer }
   1140  1.1.4.2  bouyer 
   1141  1.1.4.2  bouyer 
   1142  1.1.4.2  bouyer /*
   1143  1.1.4.2  bouyer  * erasecols
   1144  1.1.4.2  bouyer  */
   1145  1.1.4.2  bouyer void
   1146  1.1.4.2  bouyer hpcfb_tv_erasecols(dc, row, startcol, ncols, attr)
   1147  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
   1148  1.1.4.2  bouyer 	int row, startcol, ncols;
   1149  1.1.4.2  bouyer 	long attr;
   1150  1.1.4.2  bouyer {
   1151  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
   1152  1.1.4.2  bouyer 
   1153  1.1.4.2  bouyer 	if (vscn == 0)
   1154  1.1.4.2  bouyer 		return;
   1155  1.1.4.2  bouyer 
   1156  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
   1157  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1158  1.1.4.2  bouyer 	if (row < dc->dc_min_row)
   1159  1.1.4.2  bouyer 		dc->dc_min_row = row;
   1160  1.1.4.2  bouyer 	if (row > dc->dc_max_row)
   1161  1.1.4.2  bouyer 		dc->dc_max_row = row;
   1162  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1163  1.1.4.2  bouyer 
   1164  1.1.4.2  bouyer 	vscn[row].maxcol = startcol-1;
   1165  1.1.4.2  bouyer 	if (vscn[row].spacecol < startcol+ncols-1)
   1166  1.1.4.2  bouyer 		vscn[row].spacecol = startcol+ncols-1;
   1167  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1168  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1169  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1170  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1171  1.1.4.2  bouyer }
   1172  1.1.4.2  bouyer 
   1173  1.1.4.2  bouyer void
   1174  1.1.4.2  bouyer hpcfb_erasecols(cookie, row, startcol, ncols, attr)
   1175  1.1.4.2  bouyer 	void *cookie;
   1176  1.1.4.2  bouyer 	int row, startcol, ncols;
   1177  1.1.4.2  bouyer 	long attr;
   1178  1.1.4.2  bouyer {
   1179  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1180  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
   1181  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1182  1.1.4.2  bouyer 	int xoff, yoff;
   1183  1.1.4.2  bouyer 	int width, height;
   1184  1.1.4.2  bouyer 
   1185  1.1.4.2  bouyer 	hpcfb_tv_erasecols(dc, row, startcol, ncols, attr);
   1186  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1187  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
   1188  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
   1189  1.1.4.2  bouyer 		return;
   1190  1.1.4.2  bouyer 	}
   1191  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1192  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1193  1.1.4.2  bouyer 		return;
   1194  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1195  1.1.4.2  bouyer 		return;
   1196  1.1.4.2  bouyer 
   1197  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
   1198  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->erase
   1199  1.1.4.2  bouyer 	       && (dc->dc_state&HPCFB_DC_CURRENT)) {
   1200  1.1.4.2  bouyer 		xoff = startcol * ri->ri_font->fontwidth;
   1201  1.1.4.2  bouyer 		yoff = row * ri->ri_font->fontheight;
   1202  1.1.4.2  bouyer 		width = ncols * ri->ri_font->fontwidth;
   1203  1.1.4.2  bouyer 		height = ri->ri_font->fontheight;
   1204  1.1.4.2  bouyer 		(*sc->sc_accessops->erase)(sc->sc_accessctx,
   1205  1.1.4.2  bouyer 			xoff, yoff, height, width, attr);
   1206  1.1.4.2  bouyer 	} else
   1207  1.1.4.2  bouyer 		rasops_emul.erasecols(ri, row, startcol, ncols, attr);
   1208  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
   1209  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1210  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1211  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1212  1.1.4.2  bouyer }
   1213  1.1.4.2  bouyer 
   1214  1.1.4.2  bouyer /*
   1215  1.1.4.2  bouyer  * Copy rows.
   1216  1.1.4.2  bouyer  */
   1217  1.1.4.2  bouyer void
   1218  1.1.4.2  bouyer hpcfb_tv_copyrows(dc, src, dst, num)
   1219  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
   1220  1.1.4.2  bouyer 	int src, dst, num;
   1221  1.1.4.2  bouyer {
   1222  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
   1223  1.1.4.2  bouyer 	struct hpcfb_tvrow *svc = &vscn[src];
   1224  1.1.4.2  bouyer 	struct hpcfb_tvrow *dvc = &vscn[dst];
   1225  1.1.4.2  bouyer 	int i;
   1226  1.1.4.2  bouyer 	int d;
   1227  1.1.4.2  bouyer 
   1228  1.1.4.2  bouyer 	if (vscn == 0)
   1229  1.1.4.2  bouyer 		return;
   1230  1.1.4.2  bouyer 
   1231  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
   1232  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1233  1.1.4.2  bouyer 	if (dst < dc->dc_min_row)
   1234  1.1.4.2  bouyer 		dc->dc_min_row = dst;
   1235  1.1.4.2  bouyer 	if (dst + num > dc->dc_max_row)
   1236  1.1.4.2  bouyer 		dc->dc_max_row = dst + num -1;
   1237  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1238  1.1.4.2  bouyer 
   1239  1.1.4.2  bouyer 	if (svc > dvc)
   1240  1.1.4.2  bouyer 		d = 1;
   1241  1.1.4.2  bouyer 	else if (svc < dvc) {
   1242  1.1.4.2  bouyer 		svc += num-1;
   1243  1.1.4.2  bouyer 		dvc += num-1;
   1244  1.1.4.2  bouyer 		d = -1;
   1245  1.1.4.2  bouyer 	} else  {
   1246  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1247  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1248  1.1.4.2  bouyer 		hpcfb_check_update(dc);
   1249  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1250  1.1.4.2  bouyer 		return;
   1251  1.1.4.2  bouyer 	}
   1252  1.1.4.2  bouyer 
   1253  1.1.4.2  bouyer 	for (i = 0; i < num; i++) {
   1254  1.1.4.2  bouyer 		bcopy(&svc->col[0], &dvc->col[0], sizeof(struct hpcfb_vchar)*(svc->maxcol+1));
   1255  1.1.4.2  bouyer 		if (svc->maxcol < dvc->maxcol && dvc->spacecol < dvc->maxcol)
   1256  1.1.4.2  bouyer 			dvc->spacecol = dvc->maxcol;
   1257  1.1.4.2  bouyer 		dvc->maxcol = svc->maxcol;
   1258  1.1.4.2  bouyer 		svc+=d;
   1259  1.1.4.2  bouyer 		dvc+=d;
   1260  1.1.4.2  bouyer 	}
   1261  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1262  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1263  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1264  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1265  1.1.4.2  bouyer }
   1266  1.1.4.2  bouyer 
   1267  1.1.4.2  bouyer void
   1268  1.1.4.2  bouyer hpcfb_redraw(cookie, row, num, all)
   1269  1.1.4.2  bouyer 	void *cookie;
   1270  1.1.4.2  bouyer 	int row, num;
   1271  1.1.4.2  bouyer 	int all;
   1272  1.1.4.2  bouyer {
   1273  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1274  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1275  1.1.4.2  bouyer 	int cols;
   1276  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
   1277  1.1.4.2  bouyer 	struct hpcfb_vchar *svc;
   1278  1.1.4.2  bouyer 	int i, j;
   1279  1.1.4.2  bouyer 
   1280  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1281  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
   1282  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
   1283  1.1.4.2  bouyer 		return;
   1284  1.1.4.2  bouyer 	}
   1285  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1286  1.1.4.2  bouyer 	if (dc->dc_sc != NULL
   1287  1.1.4.2  bouyer 	    && !dc->dc_sc->sc_polling
   1288  1.1.4.2  bouyer 	    && dc->dc_sc->sc_mapping)
   1289  1.1.4.2  bouyer 		return;
   1290  1.1.4.2  bouyer 
   1291  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_ABORT;
   1292  1.1.4.2  bouyer 
   1293  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1294  1.1.4.2  bouyer 		return;
   1295  1.1.4.2  bouyer 	if (vscn == 0)
   1296  1.1.4.2  bouyer 		return;
   1297  1.1.4.2  bouyer 
   1298  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1299  1.1.4.2  bouyer 		return;
   1300  1.1.4.2  bouyer 
   1301  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
   1302  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
   1303  1.1.4.2  bouyer 	for (i = 0; i < num; i++) {
   1304  1.1.4.2  bouyer 		if (dc->dc_state&HPCFB_DC_ABORT)
   1305  1.1.4.2  bouyer 			break;
   1306  1.1.4.2  bouyer 		cols = vscn[row+i].maxcol;
   1307  1.1.4.2  bouyer 		for (j = 0; j <= cols; j++) {
   1308  1.1.4.2  bouyer 			if (dc->dc_state&HPCFB_DC_ABORT)
   1309  1.1.4.2  bouyer 				continue;
   1310  1.1.4.2  bouyer 			svc = &vscn[row+i].col[j];
   1311  1.1.4.2  bouyer 			rasops_emul.putchar(ri, row + i, j, svc->c, svc->attr);
   1312  1.1.4.2  bouyer 		}
   1313  1.1.4.2  bouyer 		if (all)
   1314  1.1.4.2  bouyer 			cols = dc->dc_cols-1;
   1315  1.1.4.2  bouyer 		else
   1316  1.1.4.2  bouyer 			cols = vscn[row+i].spacecol;
   1317  1.1.4.2  bouyer 		for (; j <= cols; j++) {
   1318  1.1.4.2  bouyer 			if (dc->dc_state&HPCFB_DC_ABORT)
   1319  1.1.4.2  bouyer 				continue;
   1320  1.1.4.2  bouyer 			rasops_emul.putchar(ri, row + i, j, ' ', 0);
   1321  1.1.4.2  bouyer 		}
   1322  1.1.4.2  bouyer 		vscn[row+i].spacecol = 0;
   1323  1.1.4.2  bouyer 	}
   1324  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_ABORT)
   1325  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_ABORT;
   1326  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
   1327  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1328  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1329  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1330  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1331  1.1.4.2  bouyer }
   1332  1.1.4.2  bouyer 
   1333  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1334  1.1.4.2  bouyer void
   1335  1.1.4.2  bouyer hpcfb_update(v)
   1336  1.1.4.2  bouyer 	void *v;
   1337  1.1.4.2  bouyer {
   1338  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
   1339  1.1.4.2  bouyer 
   1340  1.1.4.2  bouyer 	/* callout_stop(&dc->dc_scroll_ch); */
   1341  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
   1342  1.1.4.2  bouyer 	if (dc->dc_curx > 0 && dc->dc_cury > 0)
   1343  1.1.4.2  bouyer 		hpcfb_cursor_raw(dc, 0,  dc->dc_cury, dc->dc_curx);
   1344  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_UPDATEALL)) {
   1345  1.1.4.2  bouyer 		hpcfb_redraw(dc, 0, dc->dc_rows, 1);
   1346  1.1.4.2  bouyer 		dc->dc_state &= ~(HPCFB_DC_UPDATE|HPCFB_DC_UPDATEALL);
   1347  1.1.4.2  bouyer 	} else if ((dc->dc_state&HPCFB_DC_UPDATE)) {
   1348  1.1.4.2  bouyer 		hpcfb_redraw(dc, dc->dc_min_row,
   1349  1.1.4.2  bouyer 				dc->dc_max_row - dc->dc_min_row, 0);
   1350  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_UPDATE;
   1351  1.1.4.2  bouyer 	} else {
   1352  1.1.4.2  bouyer 		hpcfb_redraw(dc, dc->dc_scroll_dst, dc->dc_scroll_num, 0);
   1353  1.1.4.2  bouyer 	}
   1354  1.1.4.2  bouyer 	if (dc->dc_curx > 0 && dc->dc_cury > 0)
   1355  1.1.4.2  bouyer 		hpcfb_cursor_raw(dc, 1,  dc->dc_cury, dc->dc_curx);
   1356  1.1.4.2  bouyer }
   1357  1.1.4.2  bouyer 
   1358  1.1.4.2  bouyer void
   1359  1.1.4.2  bouyer hpcfb_do_scroll(v)
   1360  1.1.4.2  bouyer 	void *v;
   1361  1.1.4.2  bouyer {
   1362  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
   1363  1.1.4.2  bouyer 
   1364  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_SCRTHREAD;
   1365  1.1.4.2  bouyer 	if (dc->dc_state&(HPCFB_DC_DRAWING|HPCFB_DC_TDRAWING))
   1366  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_SCRDELAY;
   1367  1.1.4.2  bouyer 	else if (dc->dc_sc != NULL && dc->dc_sc->sc_thread)
   1368  1.1.4.2  bouyer 		wakeup(dc->dc_sc);
   1369  1.1.4.2  bouyer 	else if (dc->dc_sc != NULL && !dc->dc_sc->sc_mapping) {
   1370  1.1.4.2  bouyer 		/* draw only EMUL mode */
   1371  1.1.4.2  bouyer 		hpcfb_update(v);
   1372  1.1.4.2  bouyer 	}
   1373  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
   1374  1.1.4.2  bouyer }
   1375  1.1.4.2  bouyer 
   1376  1.1.4.2  bouyer void
   1377  1.1.4.2  bouyer hpcfb_check_update(v)
   1378  1.1.4.2  bouyer 	void *v;
   1379  1.1.4.2  bouyer {
   1380  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
   1381  1.1.4.2  bouyer 
   1382  1.1.4.2  bouyer 	if (dc->dc_sc != NULL
   1383  1.1.4.2  bouyer 		&& dc->dc_sc->sc_polling
   1384  1.1.4.2  bouyer 		&& (dc->dc_state&HPCFB_DC_SCROLLPENDING)){
   1385  1.1.4.2  bouyer 		callout_stop(&dc->dc_scroll_ch);
   1386  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_SCRDELAY;
   1387  1.1.4.2  bouyer 		hpcfb_update(v);
   1388  1.1.4.2  bouyer 	}
   1389  1.1.4.2  bouyer 	else if (dc->dc_state&HPCFB_DC_SCRDELAY){
   1390  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_SCRDELAY;
   1391  1.1.4.2  bouyer 		hpcfb_update(v);
   1392  1.1.4.2  bouyer 	} else if (dc->dc_state&HPCFB_DC_UPDATEALL){
   1393  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_UPDATEALL;
   1394  1.1.4.2  bouyer 		hpcfb_update(v);
   1395  1.1.4.2  bouyer 	}
   1396  1.1.4.2  bouyer }
   1397  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1398  1.1.4.2  bouyer 
   1399  1.1.4.2  bouyer void
   1400  1.1.4.2  bouyer hpcfb_copyrows(cookie, src, dst, num)
   1401  1.1.4.2  bouyer 	void *cookie;
   1402  1.1.4.2  bouyer 	int src, dst, num;
   1403  1.1.4.2  bouyer {
   1404  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1405  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1406  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
   1407  1.1.4.2  bouyer 	int srcyoff, dstyoff;
   1408  1.1.4.2  bouyer 	int width, height;
   1409  1.1.4.2  bouyer 
   1410  1.1.4.2  bouyer 	hpcfb_tv_copyrows(cookie, src, dst, num);
   1411  1.1.4.2  bouyer 
   1412  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1413  1.1.4.2  bouyer 		return;
   1414  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1415  1.1.4.2  bouyer 		return;
   1416  1.1.4.2  bouyer 
   1417  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->bitblit
   1418  1.1.4.2  bouyer 	       && (dc->dc_state&HPCFB_DC_CURRENT)) {
   1419  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_DRAWING;
   1420  1.1.4.2  bouyer 		srcyoff = src * ri->ri_font->fontheight;
   1421  1.1.4.2  bouyer 		dstyoff = dst * ri->ri_font->fontheight;
   1422  1.1.4.2  bouyer 		width = dc->dc_cols * ri->ri_font->fontwidth;
   1423  1.1.4.2  bouyer 		height = num * ri->ri_font->fontheight;
   1424  1.1.4.2  bouyer 		(*sc->sc_accessops->bitblit)(sc->sc_accessctx,
   1425  1.1.4.2  bouyer 			0, srcyoff, 0, dstyoff, height, width);
   1426  1.1.4.2  bouyer 		dc->dc_state &= ~HPCFB_DC_DRAWING;
   1427  1.1.4.2  bouyer 	}
   1428  1.1.4.2  bouyer 	else {
   1429  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1430  1.1.4.2  bouyer 		if (sc && sc->sc_polling) {
   1431  1.1.4.2  bouyer 			hpcfb_check_update(dc);
   1432  1.1.4.2  bouyer 		} else if ((dc->dc_state&HPCFB_DC_SCROLLPENDING) == 0) {
   1433  1.1.4.2  bouyer 			dc->dc_state |= HPCFB_DC_SCROLLPENDING;
   1434  1.1.4.2  bouyer 			dc->dc_scroll = 1;
   1435  1.1.4.2  bouyer 			dc->dc_scroll_src = src;
   1436  1.1.4.2  bouyer 			dc->dc_scroll_dst = dst;
   1437  1.1.4.2  bouyer 			dc->dc_scroll_num = num;
   1438  1.1.4.2  bouyer 			callout_reset(&dc->dc_scroll_ch, hz/100, &hpcfb_do_scroll, dc);
   1439  1.1.4.2  bouyer 			return;
   1440  1.1.4.2  bouyer 		} else if (dc->dc_scroll++ < dc->dc_rows/HPCFB_MAX_JUMP) {
   1441  1.1.4.2  bouyer 			dc->dc_state |= HPCFB_DC_UPDATE;
   1442  1.1.4.2  bouyer 			return;
   1443  1.1.4.2  bouyer 		} else {
   1444  1.1.4.2  bouyer 			dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
   1445  1.1.4.2  bouyer 			callout_stop(&dc->dc_scroll_ch);
   1446  1.1.4.2  bouyer 		}
   1447  1.1.4.2  bouyer 		if (dc->dc_state&HPCFB_DC_UPDATE) {
   1448  1.1.4.2  bouyer 			dc->dc_state &= ~HPCFB_DC_UPDATE;
   1449  1.1.4.2  bouyer 			hpcfb_redraw(cookie, dc->dc_min_row,
   1450  1.1.4.2  bouyer 					dc->dc_max_row - dc->dc_min_row, 0);
   1451  1.1.4.2  bouyer 			dc->dc_max_row = 0;
   1452  1.1.4.2  bouyer 			dc->dc_min_row = dc->dc_rows;
   1453  1.1.4.2  bouyer 			if (dc->dc_curx > 0 && dc->dc_cury > 0)
   1454  1.1.4.2  bouyer 				hpcfb_cursor(dc, 1,  dc->dc_cury, dc->dc_curx);
   1455  1.1.4.2  bouyer 			return;
   1456  1.1.4.2  bouyer 		}
   1457  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1458  1.1.4.2  bouyer 		hpcfb_redraw(cookie, dst, num, 0);
   1459  1.1.4.2  bouyer 	}
   1460  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1461  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1462  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1463  1.1.4.2  bouyer }
   1464  1.1.4.2  bouyer 
   1465  1.1.4.2  bouyer /*
   1466  1.1.4.2  bouyer  * eraserows
   1467  1.1.4.2  bouyer  */
   1468  1.1.4.2  bouyer void
   1469  1.1.4.2  bouyer hpcfb_tv_eraserows(dc, row, nrow, attr)
   1470  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc;
   1471  1.1.4.2  bouyer 	int row, nrow;
   1472  1.1.4.2  bouyer 	long attr;
   1473  1.1.4.2  bouyer {
   1474  1.1.4.2  bouyer 	struct hpcfb_tvrow *vscn = dc->dc_tvram;
   1475  1.1.4.2  bouyer 	int cols;
   1476  1.1.4.2  bouyer 	int i;
   1477  1.1.4.2  bouyer 
   1478  1.1.4.2  bouyer 	if (vscn == 0)
   1479  1.1.4.2  bouyer 		return;
   1480  1.1.4.2  bouyer 
   1481  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_TDRAWING;
   1482  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_TDRAWING;
   1483  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1484  1.1.4.2  bouyer 	if (row < dc->dc_min_row)
   1485  1.1.4.2  bouyer 		dc->dc_min_row = row;
   1486  1.1.4.2  bouyer 	if (row + nrow > dc->dc_max_row)
   1487  1.1.4.2  bouyer 		dc->dc_max_row = row + nrow;
   1488  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1489  1.1.4.2  bouyer 
   1490  1.1.4.2  bouyer 	for (i = 0; i < nrow; i++) {
   1491  1.1.4.2  bouyer 		cols = vscn[row+i].maxcol;
   1492  1.1.4.2  bouyer 		if (vscn[row+i].spacecol < cols)
   1493  1.1.4.2  bouyer 			vscn[row+i].spacecol = cols;
   1494  1.1.4.2  bouyer 		vscn[row+i].maxcol = -1;
   1495  1.1.4.2  bouyer 	}
   1496  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1497  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1498  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1499  1.1.4.2  bouyer }
   1500  1.1.4.2  bouyer 
   1501  1.1.4.2  bouyer void
   1502  1.1.4.2  bouyer hpcfb_eraserows(cookie, row, nrow, attr)
   1503  1.1.4.2  bouyer 	void *cookie;
   1504  1.1.4.2  bouyer 	int row, nrow;
   1505  1.1.4.2  bouyer 	long attr;
   1506  1.1.4.2  bouyer {
   1507  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1508  1.1.4.2  bouyer 	struct hpcfb_softc *sc = dc->dc_sc;
   1509  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1510  1.1.4.2  bouyer 	int yoff;
   1511  1.1.4.2  bouyer 	int width;
   1512  1.1.4.2  bouyer 	int height;
   1513  1.1.4.2  bouyer 
   1514  1.1.4.2  bouyer 	hpcfb_tv_eraserows(dc, row, nrow, attr);
   1515  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1516  1.1.4.2  bouyer 	if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
   1517  1.1.4.2  bouyer 		dc->dc_state |= HPCFB_DC_UPDATE;
   1518  1.1.4.2  bouyer 		return;
   1519  1.1.4.2  bouyer 	}
   1520  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1521  1.1.4.2  bouyer 	if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
   1522  1.1.4.2  bouyer 		return;
   1523  1.1.4.2  bouyer 	if (ri->ri_bits == NULL)
   1524  1.1.4.2  bouyer 		return;
   1525  1.1.4.2  bouyer 
   1526  1.1.4.2  bouyer 	dc->dc_state |= HPCFB_DC_DRAWING;
   1527  1.1.4.2  bouyer 	if (sc && sc->sc_accessops->erase
   1528  1.1.4.2  bouyer 	       && (dc->dc_state&HPCFB_DC_CURRENT)) {
   1529  1.1.4.2  bouyer 		yoff = row * ri->ri_font->fontheight;
   1530  1.1.4.2  bouyer 		width = dc->dc_cols * ri->ri_font->fontwidth;
   1531  1.1.4.2  bouyer 		height = nrow * ri->ri_font->fontheight;
   1532  1.1.4.2  bouyer 		(*sc->sc_accessops->erase)(sc->sc_accessctx,
   1533  1.1.4.2  bouyer 			0, yoff, height, width, attr);
   1534  1.1.4.2  bouyer 	} else
   1535  1.1.4.2  bouyer 		rasops_emul.eraserows(ri, row, nrow, attr);
   1536  1.1.4.2  bouyer 	dc->dc_state &= ~HPCFB_DC_DRAWING;
   1537  1.1.4.2  bouyer #ifdef HPCFB_JUMP
   1538  1.1.4.2  bouyer 	hpcfb_check_update(dc);
   1539  1.1.4.2  bouyer #endif /* HPCFB_JUMP */
   1540  1.1.4.2  bouyer }
   1541  1.1.4.2  bouyer 
   1542  1.1.4.2  bouyer /*
   1543  1.1.4.2  bouyer  * alloc_attr
   1544  1.1.4.2  bouyer  */
   1545  1.1.4.2  bouyer int
   1546  1.1.4.2  bouyer hpcfb_alloc_attr(cookie, fg, bg, flags, attrp)
   1547  1.1.4.2  bouyer 	void *cookie;
   1548  1.1.4.2  bouyer 	int fg, bg, flags;
   1549  1.1.4.2  bouyer 	long *attrp;
   1550  1.1.4.2  bouyer {
   1551  1.1.4.2  bouyer 	struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
   1552  1.1.4.2  bouyer 	struct rasops_info *ri = &dc->dc_rinfo;
   1553  1.1.4.2  bouyer 
   1554  1.1.4.2  bouyer 	return rasops_emul.alloc_attr(ri, fg, bg, flags, attrp);
   1555  1.1.4.2  bouyer }
   1556