/*
* Copyright (c) 2005, Miodrag Vallat.
* 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 AUTHOR ``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 AUTHOR 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.
*
*/
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*/
/*
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
*
* @(#)grf_tc.c 8.4 (Berkeley) 1/12/94
*/
/*
* Graphics routines for TOPCAT, CATSEYE and KATHMANDU frame buffers
*/
if (fbr->id == GRFHWID) {
switch (fbr->fbid) {
case GID_TOPCAT:
case GID_LRCATSEYE:
case GID_HRCCATSEYE:
case GID_HRMCATSEYE:
#if 0
case GID_XXXCATSEYE:
#endif
return 1;
}
}
if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER) {
switch (da->da_secid) {
case DIO_DEVICE_SECID_TOPCAT:
case DIO_DEVICE_SECID_LRCATSEYE:
case DIO_DEVICE_SECID_HRCCATSEYE:
case DIO_DEVICE_SECID_HRMCATSEYE:
#if 0
case DIO_DEVICE_SECID_XXXCATSEYE:
#endif
return 1;
}
}
/*
* Initialize hardware and display routines.
*/
int
topcat_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
{
volatile struct tcboxfb *tc = (struct tcboxfb *)fbr;
struct rasops_info *ri = &fb->ri;
int rc;
u_int i;
bool sparse = false;
if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
return rc;
/*
* If we could not get a valid number of planes, determine it
* by writing to the first frame buffer display location,
* then reading it back.
*/
if (fb->planes == 0) {
volatile uint8_t *fbp;
uint8_t save;
/*
* Some displays, such as the HP332 and HP340 internal video
* and HP98542/98543 appear to return a display width of 1024
* instead of 512. It looks these boards have actually have
* enough 64KB (1bpp) or 256KB (4bpp) VRAM and RAMDAC capabilities
* to display 1024x400 pixels.
*
* However HP's official "Service Information Manual" for
* "HP 900 Series 300 Computers Models 330/350" says:
* "The medium-resolution board uses eight memory chips per plane.
* This is enough to display 512 doubled pixels by 400 scan lines."
*
* This "512 doubled pixels" implies that the native HP-UX treated
* these 1024x400 framebuffers as pseudo 512x400 ones because
* ancient 1980s CRTs (such as 35741) didn't display such higher
* resolution. Furthermore, even modern LCDs can only handle
* upto 720 pixels in the "400 line" as VGA compatible mode.
*
* As mentioned above, we treat these 1024x400 1 bit or 4 bit
* framebuffers as "2 bytes per pixel" ones, so we have to handle
* 512 pixels per line with 1024 bytes per line.
*/
if (fb->planes <= 4 && fb->dwidth == 1024 && fb->dheight == 400) {
fb->dwidth = 512;
sparse = true;
}
fb->bmv = topcat_windowmove;
topcat_restore(fb);
diofb_fbsetup(fb);
if (!sparse) {
/* save original rasops putchar op */
fb->wsputchar = ri->ri_ops.putchar;
ri->ri_ops.putchar = topcat_putchar8;
} else {
ri->ri_ops.putchar = topcat_putchar1_4;
/* copycols and erasecols ops require byte size of fontwidth */
fb->wsd.fontwidth *= 2;
/* copyrows and eraserows ops require byte size per line */
ri->ri_emuwidth *= 2;
}
for (i = 0; i <= fb->planemask; i++)
topcat_setcolor(fb, i);
/*
* Catseye looks a lot like a topcat, but not completely.
* So, we set some bits to make it work.
*/
if (tc->regs.fbid != GID_TOPCAT) {
while ((tc->catseye_status & 1))
;
tc->catseye_status = 0x0;
tc->vb_select = 0x0;
tc->tcntrl = 0x0;
tc->acntrl = 0x0;
tc->pncntrl = 0x0;
tc->rug_cmdstat = 0x90;
}
/*
* Enable reading/writing of all the planes.
*/
tc->fben = fb->planemask;
tc->wen = fb->planemask;
tc->ren = fb->planemask;
tc->prr = RR_COPY;
/* Wait windowmove ops complete before drawing a glyph */
tc_waitbusy(tc, diofb->planemask);
/* Call the original rasops putchar */
(*diofb->wsputchar)(cookie, row, col, uc, attr);
}
/*
* Put a single character on 1 bpp (98542) or 4 bpp (98543) variants
* with 1024x400 VRAM to treat them as a pseudo 512x400 bitmap.
*/
static void
topcat_putchar1_4(void *cookie, int row, int col, u_int uc, long attr)
{
int width, height, cnt, fs;
uint32_t fb;
uint8_t *fr, clr[2];
uint8_t *dp, *rp;
struct rasops_info *ri;
struct diofb *diofb;
volatile struct tcboxfb *tc;