--- xfree86-1-3.3.6.orig/debian/TODO
+++ xfree86-1-3.3.6/debian/TODO
@@ -0,0 +1,39 @@
+BenC is going to revisit the Xsun mouse opening/ioctl/gpm-conflict
+problem									DONE, LOGGED
+just add /dev/gpmdata to the existing devfs mouse patch
+
+64918: xlib6g: More Chinese-related fixes to XLC_LOCALE			DONE, LOGGED
+Anthony's yet-again-updated zh_* locale stuff
+
+64957: ATI Rage Pro LT LCD flicker fix					DONE, LOGGED
+
+update all references to Tom Dickey's homepage and email; he moved	DONE, LOGGED
+
+updated version of Tom's xterm FAQ					DONE, LOGGED
+
+updated splash raster files with new logo				DONE, LOGGED
+
+Chris Evans's 4 Xlib security exploits					DONE, LOGGED
+
+xterm DoS attack; get Thomas Dickey's patch				DONE, LOGGED
+
+64943: system X resources are not loaded anymore			DONE, LOGGED
+50198: /etc/X11/Xresources/ not checked completely for funky files
+careful not to re-open 64750: Xsession xrdb fails if colorized ls
+
+65045: Xsession creates empty files in /tmp				DONE, LOGGED
+
+due to tempfile, xfree86-common needs Depends: debianutils (>= 1.6)	DONE, LOGGED
+
+public fixes #4 and #5 from upstream (both are Trio3D fixes)		DONE, LOGGED
+
+63625: get i810 module source/information onto XSF web page		DONE (no log needed)
+
+64952: xserver-mach64: sparc /dev/fb not created			DONE, LOGGED
+
+check Xsession manpage for difference since we changed it		DONE, LOGGED
+
+*************
+
+64967: xdm: conflicts with Optional packages gdm and wdm		DOWNGRADED per release manager
+64925: xfs dies on alpha						EXAMINE
--- xfree86-1-3.3.6.orig/debian/setperms
+++ xfree86-1-3.3.6/debian/setperms
@@ -0,0 +1,214 @@
+#!/bin/sh
+
+set -e
+
+for file in create-arch-rstartd \
+            create-arch-twm \
+            create-arch-xbase-clients \
+            create-arch-xdm \
+            create-arch-xext \
+            create-arch-xf86setup \
+            create-arch-xfs \
+            create-arch-xlib6g \
+            create-arch-xlib6g-dev \
+            create-arch-xlib6g-static \
+            create-arch-xmh \
+            create-arch-xnest \
+            create-arch-xproxy \
+            create-arch-xprt \
+            create-arch-xserver-common \
+            create-arch-xservers \
+            create-arch-xsm \
+            create-arch-xterm \
+            create-arch-xvfb \
+            create-compat-xlib6 \
+            create-compat-xlib6-altdev \
+            create-indep-rstart \
+            create-indep-xbase \
+            create-indep-xfree86-common \
+            create-server \
+            sys-build.mk \
+            timebuild; do
+#            create-compat-xlib6-static \
+  chmod 755 debian/$file
+done
+
+for file in archmap \
+            fix.source.patch \
+            getglibcversion \
+            patch.apply \
+            patch.unapply \
+            source.patch \
+            source.unpack \
+            unfix.source.patch \
+            vars* \
+            xtemp \
+            xtree \
+            xtree-libc5; do
+  chmod 755 debian/scripts/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/rstart/$file
+done
+
+for file in postinst \
+            preinst \
+            prerm; do
+  chmod 755 debian/rstartd/$file
+done
+
+for file in menu-method \
+            postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/twm/$file
+done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm \
+            update-fonts-alias \
+            update-fonts-scale \
+            xinitrc; do
+  chmod 755 debian/xbase-clients/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xbase/$file
+done
+
+for file in Xreset \
+            Xreset_0 \
+            Xsetup \
+            Xsetup_0 \
+            Xstartup \
+            Xstartup_0 \
+            init \
+            postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xdm/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xext/$file
+done
+
+for file in postinst \
+            postrm \
+            prerm; do
+  chmod 755 debian/xf86setup/$file
+done
+
+for file in Xsession \
+            postinst \
+            postrm \
+            preinst \
+            prerm \
+            xsession-example; do
+  chmod 755 debian/xfree86-common/$file
+done
+
+for file in init \
+            postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xfs/$file
+done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xlib6/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xlib6-altdev/$file
+done
+
+# for file in postinst \
+#             prerm; do
+#   chmod 755 debian/xlib6-static/$file
+# done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xlib6g/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xlib6g-dev/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xlib6g-static/$file
+done
+
+for file in postinst \
+            postrm \
+            prerm; do
+  chmod 755 debian/xmh/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xnest/$file
+done
+
+for file in postinst \
+            preinst \
+            prerm; do
+  chmod 755 debian/xproxy/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xprt/$file
+done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xserver/$file
+done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm \
+            xserver-configure; do
+  chmod 755 debian/xserver-common/$file
+done
+
+for file in postinst \
+            preinst \
+            prerm; do
+  chmod 755 debian/xsm/$file
+done
+
+for file in postinst \
+            postrm \
+            preinst \
+            prerm; do
+  chmod 755 debian/xterm/$file
+done
+
+for file in postinst \
+            prerm; do
+  chmod 755 debian/xvfb/$file
+done
--- xfree86-1-3.3.6.orig/debian/sys-build.mk
+++ xfree86-1-3.3.6/debian/sys-build.mk
@@ -0,0 +1,65 @@
+#!/usr/bin/make -f
+# Debian rules file for XFree86
+# Originally by Stephen Early <sde1000@debian.org>
+# Modified by Mark W. Eichin <eichin@kitten.gen.ma.us>
+# Modified by Branden Robinson <branden@debian.org>
+# Complete overhaul by Adam Heath <doogie@debian.org>
+
+patchapply: debian/stampdir/patchapply
+debian/stampdir/patchapply: debian/stampdir/source.build
+	debian/scripts/patch.apply
+	touch $@
+	rm -f debian/stampdir/patchunapply
+
+patchunapply: debian/stampdir/patchunapply
+debian/stampdir/patchunapply: debian/stampdir/source.build
+	debian/scripts/patch.unapply
+	touch $@
+	rm -f debian/stampdir/patchapply
+
+.export: SOURCE_TREE
+
+#
+# The rules that really do the work all start with debian/stampdir/
+# This little trick allows us to use stamp files to keep us from
+# having to rerun long targets over and over.  It also puts
+# all stamp files in one place, for easy cleaning.
+#
+# If a stampdir rule depends on something else, be sure it is
+# another stampdir rule.  Depending on base rule won't work.
+#
+
+source.build: debian/stampdir/source.build
+debian/stampdir/source.build: debian/stampdir/source.unpack debian/stampdir/source.patch
+	touch $@
+
+source.clean: unfix.source.patch
+	rm -rf $(SOURCE_DIR) debian/stampdir/upstream/ debian/stampdir/patches
+	rm -f $(patsubst %,debian/stampdir/%,source.build source.make source.unpack fix.source.patch)
+
+source.make: debian/stampdir/source.make
+debian/stampdir/source.make: debian/stampdir/source.build debian/stampdir/patchapply
+	touch $@
+
+source.unpack: debian/stampdir/source.unpack
+debian/stampdir/source.unpack:
+	debian/scripts/source.unpack
+	touch $@
+
+source.patch: debian/stampdir/source.patch
+debian/stampdir/source.patch: debian/stampdir/source.unpack debian/stampdir/fix.source.patch
+	debian/scripts/source.patch
+	touch $@
+
+fix.source.patch: debian/stampdir/fix.source.patch
+debian/stampdir/fix.source.patch:
+	debian/scripts/fix.source.patch
+	touch $@
+
+unfix.source.patch: debian/stampdir/unfix.source.patch
+debian/stampdir/unfix.source.patch:
+	debian/scripts/unfix.source.patch
+	touch $@
+
+DIR_TARGETS+=debian/stampdir
+# STAMPDIR_TARGETS+=source.make source.unpack source.patch fix.source.patch unfix.source.patch patchunapply patchunapply
--- xfree86-1-3.3.6.orig/debian/xterm/preinst
+++ xfree86-1-3.3.6/debian/xterm/preinst
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Debian xterm package pre-installation script
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting installation of xterm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+clobberdir () {
+  if [ -d /usr/doc/xterm ]; then
+    rm -r /usr/doc/xterm
+  fi;
+}
+
+case "$1" in
+  install)
+    clobberdir
+    exit 0 ;;
+  upgrade) ;;
+  abort-upgrade) exit 0 ;;
+esac
+
+if [ "$2" ]; then
+  if dpkg --compare-versions $2 gt 3.3.5-1; then
+    if dpkg --compare-versions $2 le 3.3.6-2; then
+      clobberdir
+    fi
+  fi
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xterm/xterm.faq.html
+++ xfree86-1-3.3.6/debian/xterm/xterm.faq.html
@@ -0,0 +1,1377 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<!--
+  $Id: xterm.faq.html,v 1.42 2000/05/29 16:01:43 tom Exp $
+  -->
+<HTML>
+<HEAD>
+<TITLE>XTERM - Frequently Asked Questions (FAQ)</TITLE>
+<LINK REV=MADE HREF="mailto:dickey@herndon4.his.com">
+</HEAD>
+<BODY>
+<HR>
+Copyright 1997,1998 by Thomas E. Dickey
+<HR>
+<H1>Contents</H1>
+<UL>
+<LI><A HREF="#what_is_it">What is XTERM?</A>
+<LI><A HREF="#who_did_it">Who wrote XTERM?</A>
+<LI><A HREF="#what_platforms">What platforms does it run on?</A>
+<LI><A HREF="#latest_version">What is the latest version?</A>
+<LI><A HREF="#other_versions">What versions are available?</A>
+<LI><A HREF="#how_do_i">How do I...</A>
+<LI><A HREF="#frequent_problems">Frequent problems</A>
+<LI><A HREF="#known_bugs">Known bugs</A>
+<LI><A HREF="#building_it">How do I build xterm?</A>
+<LI><A HREF="#report_bugs">How do I report bugs?</A>
+<LI><A HREF="#future_work">Ongoing/future work</A>
+</UL>
+
+<HR>
+<H1><A NAME="what_is_it">What is XTERM?</A></H1>
+From the manual page:
+<blockquote>
+The xterm program is a terminal emulator for the X Window System.  It provides
+DEC VT102 and Tektronix 4014 compatible terminals for programs that can't use
+the window system directly.  If the underlying operating system supports
+terminal resizing capabilities (for example, the SIGWINCH signal in systems
+derived from 4.3bsd), xterm will use the facilities to notify programs running
+in the window whenever it is resized.
+</blockquote>
+
+<H1><A NAME="who_did_it">Who wrote XTERM?</A></H1>
+
+A lot of people, cited at the bottom of the manual page wrote
+the original xterm program, maintained by the X Consortium
+(now part of the Open Group).
+There is no changelog, and it is not clear who did what.
+Email from Jim Gettys provides some background:
+<blockquote>
+Cast of thousands...
+<p>
+To give a bit of history, xterm predates X!
+<p>
+It was originally written as a stand-alone terminal emulator for the
+VS100 by Mark Vandevoorde, as my coop student the summer that
+X started.
+<p>
+Part way through the summer, it became clear that X was more useful
+than trying to do a stand alone program, so I had him retarget it to X.
+Part of why xterm's internals are so horrifying is that it was originally
+intended that a single process be able to drive multiple VS100 displays.
+Don't hold this against Mark; it isn't his fault.
+<p>
+I then did a lot of hacking on it, and merged several improved versions
+from others back in.
+<p>
+Notable improvements include the proper ANSI parser, that Bob McNamara
+did.
+<p>
+The Tek 4010 support came from a guy at Smithsonian Astrophysical Observatory
+whose name slips my mind at the moment.
+<p>
+Ported to X11 by Loretta Guarino.
+<p>
+Then hacked on at the X Consortium by uncounted people.
+</blockquote>
+Email from Doug Mink provides more background:
+<blockquote>
+I was checking out the newly revised AltaVista search 
+engine to see what was on the net about xterm, and I 
+found your pages.  I can add to the FAQ in that I was the 
+"guy at the Smithsonian Astrophysical Observatory" Jim 
+Gettys refers to.  I am listed at the end of the man page 
+under authors.  What happened was that I was hired by SAO 
+(after leaving the research staff at MIT) in October 1985 
+to write analysis software for the Spacelab 2 Infrared 
+Telescope which was to fly on the Space Shuttle in 1985 
+less than six months after I was hired.  I came with a tar 
+tape full of software I had written for Unix and Tektronix 
+terminals, but I was presented with a VS100 terminal which 
+had an early version (X6 or so) of xterm, with no graphics 
+capabilities.  SAO is at Harvard, across Cambridge from MIT, 
+where Jim Gettys was detailed from DEC to the X project, 
+and Jim had connections with SAO, having worked here after 
+college (MIT, where we had both worked at the observatory 
+at various times); he was still sharing an apartment with 
+an SAO colleague of mine, too. Anyway, everyone decided 
+that since I knew Tektronix commands pretty well, and our 
+group desparately needed the graphics capabilities, it 
+would be a good use of my time to implement a Tektronix 
+terminal emulator under X.  So I set to work learning 
+more C--I had only written a couple of wrappers to C I/O 
+routines so I could use them with my Fortran software--and 
+wrote a Tektronix emulator.  The only X documentation at 
+the time was the code itself.  While I was at it, I wrote 
+an improved Tektronix emulator for our Imagen laser printer 
+which used the full resolution of that 300 dpi printer instead 
+of the effective 100 dpi (i.e. jaggy) emultator distributed 
+with the printer.  The original xterm Tek emulator shared a 
+window with the VT100 emulator, much like on the VT240 terminals 
+which I had been using at MIT before I came to Harvard.  With 
+a VAX 750 running several VS100's, window creation was sloowww, 
+so sharing a window was the quickest way to do things, and all 
+of my software was written for that mode of operation, anyway. 
+While I wrote the emulator so that my software would work on 
+it, it was tested by the X group against a BBN graphics package, 
+the name of which slips my mind right now. 
+<p> 
+Anyway, 15 years later, I am still using xterm and some of the 
+same mapping software I wrote the emulator for.  And I am still 
+at the Smithsonian Astrophysical Observatory. 
+</blockquote>
+<P>
+This FAQ is oriented toward the version of xterm distributed with XFree86 3.3,
+which is based on the X11R6.3 xterm, with the addition of ANSI color and
+VT220 controls.
+
+<H1><A NAME="what_platforms">What platforms does it run on?</A></H1>
+<STRONG>Xterm</STRONG> runs in all of the implementations of X Windows.
+I've built and run these since I started working on xterm:
+
+<UL>
+<LI>AIX 3.2.5 (cc)
+<LI>Digital Unix 3.2, 4.0 (cc)
+<LI>FreeBSD 2.2.6 (gcc 2.8)
+<LI>HP-UX 9.05 (gcc 2.7.2)
+<LI>IRIX 5.2, 6.2 (cc, gcc 2.7.2, gcc 2.8)
+<LI>Linux 2.0.0, 2.0.29 (gcc 2.7.2)
+<LI>Solaris 2.4, 2.5, 2.5.1, 2.6 (cc, gcc 2.7.2)
+<LI>SunOS 4.1.1, 4.1.3 (gcc 2.7.2)
+</UL>
+<P>
+Most of these configurations have X11R5 libraries.  Only minor changes
+are needed to make xterm work on those systems.  However, with X11R6
+you can obtain better locale support, as well as new features such as the
+active icon.
+
+<H1><A NAME="latest_version">What is the latest version?</A></H1>
+The most recent (and well supported) version of xterm is the XFree86 version.
+I have a copy at
+<P>
+Ftp: <A HREF="ftp://dickey.his.com/xterm/xterm.tar.gz">ftp://dickey.his.com/xterm/xterm.tar.gz</A>
+
+<H1><A NAME="other_versions">What versions are available?</A></H1>
+There are several other versions of xterm, as well as similar programs.
+These include
+<UL>
+<LI><A HREF="#bug_ansi_xterm">ansi_xterm</A>
+<LI><A HREF="#bug_color_xterm">color_xterm</A>
+<LI><A HREF="#bug_dtterm">dtterm</A>
+<LI><A HREF="#bug_emu">emu</A> (from X Consortium)
+<LI><A HREF="#bug_nxterm">nxterm</A>
+<LI><A HREF="#bug_kterm">kterm</A>
+<LI><A HREF="#bug_rxvt">rxvt</A>
+<LI><A HREF="#bug_xiterm">xiterm</A>
+<LI><A HREF="#bug_xterm">xterm</A> (from X Consortium)
+</UL>
+(I am aware of a few others, such as
+<STRONG>xcterm</STRONG> and
+<STRONG>mterm</STRONG>, but have not seen
+a working version of these).
+<p>
+There are actually two versions of XFree86 xterm.  Starting with my
+<a href="xterm.log.html#xterm_88">patch 88</a>,
+there are the stable (beta) and unstable (alpha) versions, which currently
+are XFree86 3.3.6 and XFree86 4.0, respectively.
+I have been making only critical changes to the stable version since
+patch 88;
+ongoing development (including all non-critical fixes)
+is focused on the "unstable".
+<p>
+XFree86 4.0 should have incorporated my
+<a href="xterm.log.html#xterm_131">patch 131</a>,
+but it was overlooked at the last moment.
+Unfortunately, the patch 130 version which was released
+renders colors incorrectly on most platforms, in particular FreeBSD.
+Ironically, the change in
+<a href="xterm.log.html#xterm_129">patch 129</a>
+which introduced this bug
+was designed to work around a bug which I have seen only running with FreeBSD.
+To compound the irony,
+there is some resistance at this time
+(2000/4/5) by that organization to incorporating the fix
+because it might be confused with the 4.0 release version.
+
+<H1><A NAME="how_do_i">How do I ...</A></H1>
+Not really problems, but frequently asked questions (the point of this,
+after all):
+<UL>
+<LI><A HREF="#how2_fsize">How do I change the font size?</A>
+<LI><A HREF="#how2_print">How do I print the screen?</A>
+<LI><A HREF="#how2_fkeys">How do I set up function keys?</A>
+<LI><A HREF="#how2_title">How do I set the title?</A>
+</UL>
+
+<H2><A NAME="how2_fsize">How do I change the font size?</A></H2>
+This is in the manpage, in <em>MENUS</em>.
+<p>
+X Consortium xterm provides popup menus, by pressing the control key
+together with the mouse button.
+Control right mouse button pops up the <em>VT FONTS</em> menu,
+from which you can select fonts that are specified in xterm's resources.
+Usually these are in increasing order of size.
+<p>
+XFree86 xterm provides the menu, plus a feature adapted from rxvt: pressing
+the shifted keypad plus or minus keys steps through the font menu selections,
+in order of their size.
+
+<H2><A NAME="how2_print">How do I print the screen?</A></H2>
+That depends on why you want to print it.
+<p>
+If you want a trace of an interactive session, you should use the
+<em>script</em> program.  It records every character sent to the
+screen, recording them in a file <code>typescript</code>.
+There are two drawbacks to this approach:
+<ul>
+<li>Every character is recorded.
+Even cursor movement, if you run an editor.
+<li>You must start a new shell to capture the <code>typescript</code> file.
+</ul>
+Well, what about logging?
+Some versions of xterm support logging to a file.
+In fact XFree86 xterm does.  Logging was dropped from X Consortium xterm
+during X11R5 due to security concerns.  Those were addressed, but logging
+was not reinstated
+(in fact there is a related <a href="#bug_xterm">bug</a> in xterm).
+Some people prefer this, because it is convenient:
+you can start and stop logging a popup menu entry.
+However
+<ul>
+<li>Every character is recorded.
+Even cursor movement, if you run an editor.
+<li>Line drawing characters are translated to control characters,
+i.e., codes 0-31
+(this may be fixed sometime,
+it is a problem inherited from X Consortium xterm).
+</ul>
+Both <em>script</em> and logging are useful for recording, but they
+require interpretation to make sense of the trace.  You probably
+would not send that trace to a printer (not twice, anyway).
+<p>
+If you want to print the contents of the screen, XFree86 xterm
+implements, as part of the VT100 emulation, an "attached" printer.
+<ul>
+<li>The printer is really a pipe command, to which xterm writes.
+<li>You can print the current line, page, or continuously with
+the corresponding control sequences.  That takes an application
+program which knows how to print the screen.
+<li>If you do not have an application, xterm has a popup menu
+entry to print the window.
+</ul>
+There are limitations and tradeoffs using the "attached" printer,
+because it is an emulation:
+<ul>
+<li>The emulation is based on detailed documentation for a VT320.
+This states that control sequences are sent in each line to
+reset bold, underlining and other printable attributes, and
+to set them as needed.
+Your printer probably does not understand this sort of input.
+Use the xterm resource <code>printAttributes</code> to get
+more easily printed output.
+<li>The printer may hang.
+Not really, but it seems that way.
+If you use the "attached" printer from an application designed
+for the VT100 terminal, it is written with the assumption that
+the printer is a dedicated piece of hardware,
+printing onto a continuous form.
+Use the <code>printerAutoClose</code> resource to change
+xterm's behavior to close the printer pipe whenever the terminal
+is told to switch the printer offline.
+</ul>
+If you use the popup menu to print the screen, this will close the
+printer pipe unless it was already opened by the application running in xterm.
+
+<H2><A NAME="how2_fkeys">How do I set up function keys?</A></H2>
+With XFree86 xterm, this is relatively simple.  So I'll answer that first.
+<P>
+With X Consortium xterm, you have partial support for DEC VTxxx function keys.
+Function keys F1 to F12 correspond to DEC's F1 to F12 (sort of).
+Actually, DEC's VT220 terminals do not have codes for F1 through F5.
+They are reserved for local functions.
+And the VT220 (and up) terminals have 20 function keys.
+So you cannot do anything with the F13 through F20 (i.e., DO, HELP and SELECT).
+Finally, though xterm is reputed to be VT100-compatible, it has no support
+for the VT100 keypad (PF1 to PF4, and the "," key).
+<P>
+XFree86 xterm changes the X Consortium codes for F1 to F4 to match the
+VT100 PF1 to PF4, except when the emulation level is VT220 and up.
+In this case, it generates the same F1 to F4 codes as X Consortium xterm.
+Moreover, it adds a new resource <STRONG>sunKeyboard</STRONG>, which
+tells the program whether it has only 12 function keys (i.e., a Sun or PC
+keyboard).
+If so (this is selectable from the popup menu), you can use the control key
+with F1 to F12 to get F13 to F24, and use the "+" key on the keypad as an
+alias for "," (comma).
+<P>
+The emulation level for XFree86 xterm is set via the resource
+<STRONG>decTerminalID</STRONG>, e.g., to 220 for a VT220.
+Once set, applications can set the emulation level up or down within that
+limit.  DEC's terminals are configured in much the same way by a setup
+option.
+<P>
+That is the simple way, using a couple of new resources.
+The traditional way to get function keys involves translations.
+I have seen a few postings on the newsgroups that do this.
+Here is one from Bruce Momjian &lt;root@candle.pha.pa.us&gt;
+for a VT220:
+<PRE>
+<code>
+	xterm $XTERMFLAGS +rw +sb +ls $@ -tm 'erase ^? intr ^c' \
+		-name vt220 -title vt220 -tn xterm-220 "$@" &amp;
+</code>
+</PRE>
+<P>
+with the corresponding resources:
+<PRE>
+<code>
+	XTerm*VT100.Translations: #override \n\
+		&lt;Key&gt;Home: string(0x1b) string("[3~") \n \
+		&lt;Key&gt;End: string(0x1b) string("[4~") \n
+	vt220*VT100.Translations: #override \n\
+	~Shift	&lt;Key&gt;F1: string(0x1b) string("OP") \n \
+	~Shift	&lt;Key&gt;F2: string(0x1b) string("OQ") \n \
+	~Shift	&lt;Key&gt;F3: string(0x1b) string("OR") \n \
+	~Shift	&lt;Key&gt;F4: string(0x1b) string("OS") \n \
+	~Shift	&lt;Key&gt;F5: string(0x1b) string("[16~") \n \
+	~Shift	&lt;Key&gt;F6: string(0x1b) string("[17~") \n \
+	~Shift	&lt;Key&gt;F7: string(0x1b) string("[18~") \n \
+	~Shift	&lt;Key&gt;F8: string(0x1b) string("[19~") \n \
+	~Shift	&lt;Key&gt;F9: string(0x1b) string("[20~") \n \
+	~Shift	&lt;Key&gt;F10: string(0x1b) string("[21~") \n \
+	~Shift	&lt;Key&gt;F11: string(0x1b) string("[28~") \n \
+	~Shift	&lt;Key&gt;F12: string(0x1b) string("[29~") \n \
+	Shift	&lt;Key&gt;F1: string(0x1b) string("[23~") \n \
+	Shift	&lt;Key&gt;F2: string(0x1b) string("[24~") \n \
+	Shift	&lt;Key&gt;F3: string(0x1b) string("[25~") \n \
+	Shift 	&lt;Key&gt;F4: string(0x1b) string("[26~") \n \
+	Shift	&lt;Key&gt;F5: string(0x1b) string("[K~") \n \
+	Shift	&lt;Key&gt;F6: string(0x1b) string("[31~") \n \
+	Shift	&lt;Key&gt;F7: string(0x1b) string("[31~") \n \
+	Shift	&lt;Key&gt;F8: string(0x1b) string("[32~") \n \
+	Shift	&lt;Key&gt;F9: string(0x1b) string("[33~") \n \
+	Shift	&lt;Key&gt;F10: string(0x1b) string("[34~") \n \
+	Shift	&lt;Key&gt;F11: string(0x1b) string("[28~") \n \
+	Shift	&lt;Key&gt;F12: string(0x1b) string("[29~") \n \
+		&lt;Key&gt;Print: string(0x1b) string("[32~") \n\
+		&lt;Key&gt;Cancel: string(0x1b) string("[33~") \n\
+		&lt;Key&gt;Pause: string(0x1b) string("[34~") \n\
+		&lt;Key&gt;Insert: string(0x1b) string("[2~") \n\
+		&lt;Key&gt;Delete: string(0x1b) string("[3~") \n\
+		&lt;Key&gt;Home: string(0x1b) string("[1~") \n\
+		&lt;Key&gt;End: string(0x1b) string("[4~") \n\
+		&lt;Key&gt;Prior: string(0x1b) string("[5~") \n\
+		&lt;Key&gt;Next: string(0x1b) string("[6~") \n\
+		&lt;Key&gt;BackSpace: string(0x7f) \n\
+		&lt;Key&gt;Num_Lock: string(0x1b) string("OP") \n\
+		&lt;Key&gt;KP_Divide: string(0x1b) string("Ol") \n\
+		&lt;Key&gt;KP_Multiply: string(0x1b) string("Om") \n\
+		&lt;Key&gt;KP_Subtract: string(0x1b) string("OS") \n\
+		&lt;Key&gt;KP_Add: string(0x1b) string("OM") \n\
+		&lt;Key&gt;KP_Enter: string(0x1b) string("OM") \n\
+		&lt;Key&gt;KP_Decimal: string(0x1b) string("On") \n\
+		&lt;Key&gt;KP_0: string(0x1b) string("Op") \n\
+		&lt;Key&gt;KP_1: string(0x1b) string("Oq") \n\
+		&lt;Key&gt;KP_2: string(0x1b) string("Or") \n\
+		&lt;Key&gt;KP_3: string(0x1b) string("Os") \n\
+		&lt;Key&gt;KP_4: string(0x1b) string("Ot") \n\
+		&lt;Key&gt;KP_5: string(0x1b) string("Ou") \n\
+		&lt;Key&gt;KP_6: string(0x1b) string("Ov") \n\
+		&lt;Key&gt;KP_7: string(0x1b) string("Ow") \n\
+		&lt;Key&gt;KP_8: string(0x1b) string("Ox") \n\
+		&lt;Key&gt;KP_9: string(0x1b) string("Oy") \n
+
+	!	&lt;Key&gt;Up: string(0x1b) string("[A") \n\
+	!	&lt;Key&gt;Down: string(0x1b) string("[B") \n\
+	!	&lt;Key&gt;Right: string(0x1b) string("[C") \n\
+	!	&lt;Key&gt;Left: string(0x1b) string("[D") \n\
+
+	*visualBell:	true
+	*saveLines:    1000
+	*cursesemul:	true
+	*scrollKey: true
+	*scrollBar: true
+</code>
+</PRE>
+Note that real VT220 terminals use shifted function keys to mean something
+different: the user-programmable keys (i.e., DECUDK).  XFree86 xterm
+supports this, but the translations do not (they're using shift to select
+F13 to F20).
+<P>
+Here's another one, from
+Robert Ess &lt;ress@spd.dsccc.com&gt;:
+<PRE>
+<code>
+	#!/bin/sh
+
+	# 		vax
+	# 09-17-96	Bob Ess      - initial creation
+	# 09-26-96	Shig Katada  - Additional keybindings
+	#
+	# 		Script file to incorporate keybindings and command line
+	#		options for connecting to a VAX node
+
+	# Usage statement
+	Usage(){
+		echo
+		echo " Usage  : vax -options"
+		echo
+		echo " Options: -80   for 80 column terminal"
+		echo "          -132  for 132 column terminal"
+		echo "          -fg colorname"
+		echo "          -bg colorname"
+		echo "          -fn fontname"
+		echo "          -fb bold fontname"
+		echo "          -host [altair] [devel] [leonis] [castor]"
+		echo ""
+		echo " Example: \"vax -80 -fg white -bg black -fn 9x15 -fb 9x15b -host castor\""
+		echo "          Starts a VAX session with an 80 column terminal"
+		echo "          with a black background, white foreground, a normal"
+		echo "          font of 9x15 and a bold font of 9x15b, and connects"
+		echo "          to the node 'castor'"
+		echo
+		echo "          If you need additional help, please call Workstation"
+		echo "          Services at x92396."
+		echo
+		exit 1
+	}
+
+
+	# Default to a black foreground with a white background.
+	# Use the 9x15 and 9x15bold fonts. Connect to castor by default.
+	#
+	FG=black
+	BG=white
+	HOST=castor
+	FONT=9x15
+	BFONT=9x15bold
+	COLS=80
+
+
+	# Parse the command line arguments
+	#
+	while [ $# != 0 ];
+	do
+		case $1 in
+			-80)	COLS=80
+				FONT=spc12x24c
+				BFONT=spc12x24b
+				shift
+				;;
+			-132)	COLS=132
+				FONT=9x15
+				BFONT=9x15b
+				shift
+				;;
+			-fg)	shift
+				FG=$1
+				shift;;
+			-bg)	shift
+				BG=$1
+				shift;;
+			-fn)	shift
+				FONT=$1
+				shift;;
+			-fb)	shift
+				BFONT=$1
+				shift;;
+			-host)	shift
+				HOST=$1
+				shift;;
+			-help)	Usage;;
+			*)	Usage;;
+		esac
+	done
+
+
+	xterm  -title "VAX" -sb -sl 1200 -geo ${COLS}x24 -fg ${FG} -bg ${BG} \
+		-cr red -fn ${FONT} -fb ${BFONT} -xrm \
+		"XTerm*vt100.translations:     #override \n\
+		&lt;Key&gt;Insert:            string(\001) \n\
+		Shift &lt;Key&gt;Up:          scroll-back(1,lines) \n\
+		Shift &lt;Key&gt;Down:        scroll-forw(1,lines) \n\
+		Shift &lt;Key&gt;Right:       string(0x1b) string("f") \n\
+		Shift &lt;Key&gt;Left:        string(0x1b) string("b") \n\
+		Shift &lt;Key&gt;Delete:      string(0x1b) string(0x08) \n\
+		Shift &lt;Key&gt;Tab:         string(0x1b) string("*") \n\
+		&lt;Key&gt;0x1000FF0D:        scroll-back(1,page) \n\
+		&lt;Key&gt;0x1000FF0E:        scroll-forw(1,page) \n\
+		&lt;Key&gt;0x1000FF09:        string(\010) \n\
+		&lt;Key&gt;0x1000FF0A:        string(\005) \n\
+		&lt;Key&gt;BackSpace:         string(0xff) \n\
+		&lt;Key&gt;Select:            select-start() \n\
+		&lt;Key&gt;0x1000FF02:        select-end(PRIMARY,CUT_BUFFER0) \n\
+		Meta &lt;Key&gt;0x1000FF02:   select-end(CLIPBOARD) \n\
+		&lt;Key&gt;0x1000FF04:        insert-selection(PRIMARY,CUT_BUFFER0) \n\
+		Meta &lt;Key&gt;0x1000FF04:   insert-selection(CLIPBOARD) \n\
+		&lt;Key&gt;F1:                string(0x1b) string("OP") \n\
+		&lt;Key&gt;F2:                string(0x1b) string("OQ") \n\
+		&lt;Key&gt;F3:                string(0x1b) string("OR") \n\
+		&lt;Key&gt;F4:                string(0x1b) string("OS") \n\
+		&lt;Key&gt;F5:                string(0x1b) string("OA") \n\
+		&lt;Key&gt;F11:               string(0x1b) string("[23~") \n\
+		&lt;Key&gt;F12:               string(0x1b) string("[24~") \n\
+		&lt;Key&gt;KP_0:              string(0x1b) string("Op") \n\
+		&lt;Key&gt;KP_1:              string(0x1b) string("Oq") \n\
+		&lt;Key&gt;KP_2:              string(0x1b) string("Or") \n\
+		&lt;Key&gt;KP_3:              string(0x1b) string("Os") \n\
+		&lt;Key&gt;KP_4:              string(0x1b) string("Ot") \n\
+		&lt;Key&gt;KP_5:              string(0x1b) string("Ou") \n\
+		&lt;Key&gt;KP_Divide:         string(0x1b) string("OP") \n\
+		&lt;Key&gt;KP_Multiply:       string(0x1b) string("[29~") \n\
+		&lt;Key&gt;KP_Enter:          string(0x1b) string("OM") \n\
+		&lt;Key&gt;KP_Subtract:       string(0x1b) string("Om") \n\
+		&lt;Key&gt;KP_Add:            string(0x1b) string("Ol") \n\
+		&lt;Key&gt;KP_Decimal:        string(0x1b) string("On") \n\
+		&lt;Btn1Down&gt;:             select-start() \n\
+		&lt;Btn1Motion&gt;:           select-extend() \n\
+		&lt;Btn1Up&gt;:               select-end(PRIMARY,CUT_BUFFER0) \n\
+		Button1&lt;Btn2Down&gt;:      select-end(CLIPBOARD) \n\
+		Button1&lt;Btn2Up&gt;:        ignore()" \
+		-e telnet $HOST &amp;
+</code>
+</PRE>
+
+<H2><A NAME="how2_title">How do I set the title?</A></H2>
+The control sequences are documented in ctlseqs.ms; a copy is contained
+in the <A HREF="#latest_version">xterm.tar.gz</A> file.
+<P>
+The usual context for this question is setting the title according to
+the current working directory.
+People post answers to this periodically on the newsgroups.
+Here is one that I have seen,
+from Roy Wright &lt;nobody@roystoy.dseg.ti.com&gt;.
+In your /etc/profile after:
+<PRE>
+<code>
+	if [ "$SHELL" = "/bin/pdksh" -o "$SHELL" = "/bin/ksh" ]; then
+		PS1="! $ "
+	elif [ "$SHELL" = "/bin/zsh" ]; then
+		PS1="%m:%~%# "
+	elif [ "$SHELL" = "/bin/ash" ]; then
+		PS1="$ "
+	else
+		PS1='\u@\h:\w\$ '
+	fi
+</code>
+</PRE>
+<P>
+add:
+<PRE>
+<code>
+	if [ "$TERM" = "xterm" ]; then
+		PS1="\033]2;\u@\h:\w\007bash$ "
+	fi
+</code>
+</PRE>
+<P>
+The terminator "\007" is a problem area.  Xterm historically uses this
+character, though it is non-ANSI.  The "correct" character should be
+a "\233" string terminator, or "\033\\", which is the 7-bit equivalent.
+XFree86 xterm recognizes either (the "\007" or string terminator);
+waiting for the first of these.
+<P>
+You may have resource or environment problems that prevent you from
+setting the title at all.  Newer xterms (starting somewhere in X11R5)
+use the $LANG variable.  If your locale is incorrectly installed, you
+will be unable to set the xterm's title.
+As noted by Mikhail Teterin &lt;mi@rtfm.ziplink.net&gt;:
+Make sure that the locale (LANG and/or LOCALE environment variable)
+is known to X Window System.
+Check ${X11ROOT}/lib/X11/locale.* for it.
+If it is not listed in either one of the files, find
+the nearest match and add an alias to it.
+Restart X if you have made changes.
+<P>
+On a related note, some people want to know how to read the title
+from an xterm.
+This works for XFree86 xterm and dtterm, but not for other variations:
+<PRE>
+<code>
+	#!/bin/ksh
+	# Echo the current X term title bar to standard output.
+	# Written by Icarus Sparry &lt;icarus@bath.ac.uk&gt; 11 Apr 1997
+	#
+	exec &lt;/dev/tty
+	old=$(stty -g)
+	stty raw -echo min 0  time ${1-10}
+	print "\033[21t\c" &gt; /dev/tty
+	IFS='' read -r a
+	stty $old
+	b=${a#???}
+	print -R "${b%??}"
+</code>
+</PRE>
+But it is possible to avoid escape sequences altogether (from
+Hemant Shah &lt;shah@typhoon.xnet.com&gt;):
+<PRE>
+<code>
+	$ xprop -id $WINDOWID | grep WM_NAME
+	WM_NAME(STRING) = "this is my title"
+	current_title=$(xprop -id $WINDOWID | grep WM_NAME | cut -d= -f2)
+</code>
+</PRE>
+Here's another source of information:
+<a href="http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/">Xterm-Title HowTo</a>
+
+<H1><A NAME="frequent_problems">Frequent problems</A></H1>
+<UL>
+<LI><A HREF="#no_altchar">My terminal doesn't show box characters</A>
+<LI><A HREF="#no_color">My terminal doesn't recognize color</A>
+<LI><A HREF="#xterm_terminfo">What $TERM should I use?</A>
+<LI><A HREF="#no_ncurses">I need libncurses.so.3.0</A>
+<LI><A HREF="#no_termcap">I need /etc/termcap</A>
+<LI><A HREF="#no_ptys">Xterm does not run (no available pty's)</A>
+<LI><A HREF="#setup_resize">Why is my screen size not set?</A>
+<LI><A HREF="#xterm_pageup">Why can't I use the pageup/pagedown keys?</A>
+<LI><A HREF="#xterm_paste">Why can't I cut/paste in xterm?</A>
+<LI><A HREF="#xterm_hilite">Reverse video is not reset</A>
+<LI><A HREF="#xterm_resize">Resizing under FVWM does weird things</A>
+<LI><A HREF="#xterm_tite">Why doesn't the screen clear when running vi?</A>
+<LI><A HREF="#xterm_vite">Why is the cursor misplaced after running vi?</A>
+<LI><A HREF="#xterm_erase">Why doesn't my delete key work?</A>
+<LI><A HREF="#xterm_erased">Why did my delete key stop working?</A>
+<LI><A HREF="#xterm_keypad">Why doesn't my keypad work?</A>
+<LI><A HREF="#xterm_8bits">Why can't I input 8-bit characters?</A>
+<LI><A HREF="#tiny_menus">Why are the menus tiny?</A>
+<LI><A HREF="#warning_msg">What is this warning message?</A>
+</UL>
+
+<H2><A NAME="no_altchar">My terminal doesn't show box characters</A></H2>
+Xterm displays the 7-bit ASCII and VT100 graphic characters (including
+box corners) using specially arranged fixed-pitch fonts.  The first
+32 glyph positions (which would correspond to nonprinting control
+characters) are used to hold the VT100 graphic characters.  Some
+fonts that otherwise look fine (such as courier) do not have glyphs
+defined for these positions.  So they display as blanks.
+Use <em>xfd</em> to display the font.
+<p>
+You may also have a problem with the terminfo description.
+As distributed, the X11R6 terminfo for xterm does not have the
+<em>acsc</em> string defined, so most implementations of curses
+do not try to use the alternate character set.
+<p>
+Finally, some people confuse the VT100 graphic characters with the VT220
+support for DEC technical character set.
+These are distinct (7-bit) character sets.
+Xterm currently does not support this.
+
+<H2><A NAME="no_color">My terminal doesn't recognize color</A></H2>
+First, ensure that you have set up xterm to render color.
+The XFree86 xterm renders color only if you have set resources
+to do this; the default behavior is monochrome to maintain compatibility
+with older applications.
+The manual page describes these resources.
+I set them in my <A HREF="#my_xdefaults">.Xdefaults</A> file.
+<P>
+Check the terminal description, to see if it is installed properly,
+e.g., for
+<A HREF="../ncurses/ncurses.faq.html#no_color">ncurses</A>, which uses terminfo.
+<P>
+Finally, some applications (that do not interface properly with terminfo
+or termcap) may need the environment variable
+<a href="../ncurses/ncurses.faq.html#no_colorterm">$COLORTERM</a> to be set.
+
+<H2><A NAME="setup_resize">Why is my screen size not set?</A></H2>
+Well, it may be set, but not correctly. You may notice these symptoms:
+<ul>
+<li>When editing with vi, you cannot see the beginning of the file, or
+<li>Running
+<pre>
+<code>
+	stty -a
+</code>
+</pre>
+shows the rows and/or columns values as 0, or some other value (such as 65)
+which has nothing to do with the actual window size.
+</ul>
+Xterm knows how big the screen is (of course), and tries to tell your
+applications (e.g., by invoking ioctl's and sending SIGWINCH).  But sometimes
+it cannot:
+<ul>
+<li>Xterm itself may have been built incorrectly
+(the #ifdef's that make the logic work are inactive).
+<li>You may be running xterm via a remote connection which refuses to pass
+that information.  This can happen even on "modern" networks where the connection
+crosses domain boundaries.
+<li>You may be running su'd to another account.
+SIGWINCH is just another signal; signals do not propagate for security reasons.
+</ul>
+Most full-screen applications such as vi are designed to use the ioctl
+calls that return the screen size.  When they fail, the applications
+use the size defined in the terminal's terminfo or termcap description.
+<p>
+You may be able to use the <em>resize</em> program to issue the ioctl's
+that will notify your application of the actual screen size. This does not
+always work for the reasons just mentioned.
+Newer versions of stty let you specify the screen size, though it will not
+be updated if you resize the xterm window:
+<pre>
+<code>
+	stty rows 24 columns 80
+</code>
+</pre>
+Most full-screen applications also
+check if the $LINES and $COLUMNS variables are set, using those values to
+override the terminal description:
+<pre>
+<code>
+	setenv LINES 24
+	setenv COLUMNS 80
+</code>
+</pre>
+Why 65 lines?  The standard xterm terminfo description specifies 65 lines,
+perhaps because someone liked it that way.  Real VT100's are 24 lines.
+I once used (and wrote applications for) a Bitgraph terminal, which
+emulated Vt100, but displayed 65 lines.
+
+<H2><A NAME="xterm_pageup">Why can't I use the pageup/pagedown keys?</A></H2>
+Some vendors, e.g,. Sun, have added key translations which make the
+pageup and pagedown keys talk to the xterm's scrollbar instead of your
+application.
+You can override this by specifying your own translations in your resource
+file.
+Use the translations in
+<pre>
+<code>
+	/usr/lib/X11/app-defaults/XTerm
+</code>
+</pre>
+as a guide.
+For example,
+<pre>
+<code>
+	XTerm.VT100.Translations:       #override \
+		~Shift&lt;Key&gt;Home:  string(\033[1~)\n\
+		~Shift&lt;Key&gt;End:   string(\033[4~)\n\
+		~Shift&lt;Key&gt;Prior: string(\033[5~)\n\
+		~Shift&lt;Key&gt;Next:  string(\033[6~)\n\
+		Shift&lt;Key&gt;Prior:  scroll-back(100,page) \n\
+		Shift&lt;Key&gt;Next:   scroll-forw(100,page) \n\
+		Shift&lt;Key&gt;Home:   scroll-back(100,page) \n\
+		Shift&lt;Key&gt;End:    scroll-forw(100,page) \n
+</code>
+</pre>
+makes the home/end and pageup/pagedown keys usable by your editor,
+while leaving their shifted equivalents available for the scrollbar.
+
+<H2><A NAME="xterm_paste">Why can't I cut/paste in xterm</A></H2>
+When an application sets xterm to any of its mouse tracking modes, it reserves
+the unshifted mouse button clicks for the application's use.
+Unless you have modified the treatment of the shifted mouse button events
+(e.g., with your window manager), you can always do cut/paste by pressing
+the shift key while clicking with the mouse.
+
+<H2><A NAME="no_ncurses">I need libncurses.so.3.0</A></H2>
+During initialization, xterm checks to see if the value of $TERM is
+legal, i.e., is defined via the termcap interface.
+Some people have linked xterm against ncurses, which provides a similar
+interface, since they do not want to package termcap on their system.
+<P>
+The libncurses.so.3.0 corresponds to ncurses 1.9.8a; while there have
+been interface changes to ncurses past this point (the current version of
+<A HREF="../ncurses/ncurses.faq.html#latest_version">ncurses</A>),
+the termcap interface should still be compatible.
+So (for xterm) it doesn't matter much which version of ncurses you have
+installed.  However, other applications may not work properly.
+Some people have advised just linking libncurses.so.2.0 to libncurses.so.3.0,
+but that won't work well at all (one person simply linked libncurses.so.3.0
+to the libtermcap.so, which may work...).
+A better solution would be to install the later version of ncurses,
+with a link (if you must) from the newer version to the older library.
+<P>
+Since there is little agreement on the set of shared libraries that
+are assumed to be present on the user's system, XFree86 distributes
+xterm statically linked against termcap because that is simplest,
+and because you lose functionality (the $TERMCAP variable) when linked
+against terminfo libraries such as ncurses.
+
+<H2><A NAME="no_termcap">I need /etc/termcap</A></H2>
+If you have a termcap version of xterm on a system with no termcap libraries,
+you may also be missing /etc/termcap.
+<P>
+A workaround is to copy /usr/X11R6/lib/X11/etc/xterm.termcap to
+/etc/termcap.
+<P>
+This is fixed another way starting with XFree86 3.3.1.
+If xterm cannot find the terminal description, it will accept that,
+though it will print a warning.  If xterm does not find the termcap
+entry, it will not set the $TERMCAP variable.
+
+<H2><A NAME="no_ptys">Xterm does not run (no available pty's)</A></H2>
+For older systems (most computers in fact)
+you must either make xterm run setuid to root, or make the pty's
+world-writable.
+<p>
+Perhaps your system does not have enough pty's, or (a recent problem
+reported with newer Linux kernels, especially RedHat 6.0) the major device
+numbers of the pty's may have changed during a kernel upgrade.
+
+<H2><A NAME="xterm_hilite">Reverse video is not reset</A></H2>
+When running <em>less</em> or other programs that do highlighting,
+you see the highlighting not turned off properly.
+<P>
+This may be due to incompatible terminal descriptions for xterm.
+With XFree86 3.2, I modified the terminal description for XFree86
+xterm to use the VT220 (aka ISO 6429) controls that allow an application
+to turn off highlighting (or bold, underline) without modifying the
+other attributes.  The X Consortium xterm does not recognize these
+controls.
+<P>
+If, for example, you are running an older xterm and rlogin to a system
+where the newer xterm has been installed, you will have this problem,
+because both programs default to $TERM set to xterm.
+The solution for mixed systems is to install the newer terminal description as
+as a different name (e.g., <code>xterm-color</code>)
+and set the <STRONG>termName</STRONG>
+resource accordingly in the app-defaults file for the system which has the
+newer xterm.
+<p>
+However - see <a href="#xterm_terminfo">below</a>.
+
+<H2><A NAME="xterm_terminfo">What $TERM should I use?</A></H2>
+<p>
+The <code>xterm-color</code> value for $TERM
+is a bad choice for XFree86 xterm because it is
+commonly used for a terminfo entry which happens to not support <code>bce</code>.
+Use the <code>xterm-xfree86</code> entry which is distributed with
+XFree86 xterm (or the similar one distributed with ncurses).
+<p>
+The term "<code>bce</code>" stands for "back color erase".  Terminals such as XFree86 xterm
+and rxvt implement back color erase, others such as dtterm do not.
+When an application clears the screen, a terminal that implements back
+color erase will retain the last-set background color.  A terminal
+that does not implement back color erase will reset the background color
+to the default or initial colors.  Applications that paint most of the
+screen in a single color are more efficient on terminals that support
+back color erase.
+<p>
+Curses libraries that support color know about <code>bce</code> and do the
+right thing - provided that you tell them what the terminal does.
+That is the whole point of setting $TERM.
+The "xterm-color" description distributed with ncurses does not list
+<code>bce</code>, because it was applied originally to a terminal type
+which does
+not implement back color erase.
+It will "work" for XFree86 xterm,
+though less efficient.  Some other applications such as the slang library
+have hardcoded support for terminals that implement back color erase.
+Given the "xterm-color" description, those will be efficient - and
+fortuitously work.  However, slang (through version 1.4.0) does not
+work properly for the terminals that xterm-color was designed for.
+See this <a href="../lynx/lynx-ncurses.html">page</a> for an example
+of (n)curses and slang running on dtterm.
+
+<H2><A NAME="xterm_resize">FVWM does weird things when I try to resize xterm</A></H2>
+I have an old (3.1.2G) bug report for xterm which may be related to the
+second (3.9s) problem:
+<ul>
+<li>Steven Lang &lt;tiger@ecis.com&gt; reports a problem with extra resize
+events for xterm.
+<P>
+When I change font size often I will get the double-refresh, and when that
+happens the text program gets 2 resize events..  Running a quick test, I
+got this: Going to a bigger font, it got a 53x20 resize, then a 80x24
+resize.  Going to a smaller font, it got a 120x27 resize, then a 80x24
+resize.
+<P>
+Earlier I made a mention of changing font size in rxvt (And xterm does it
+to) causing 2 resize events.  Well I just happened to do it in fvwm
+(Instead of fvwm 95) and found it seems to be a 'feature' of fvwm95, not
+XFree86 as I'd initially assumed.
+<li>Stephen Marley &lt;stephen@memex.com&gt; reports a problem with the active
+icon (from X11R6.3 xterm):
+<p>
+Using the XFree86 xterm-53 with the active icon feature on, I get
+some problems resizing where the xterm window shrinks as small
+as possible and won't stay at whatever size you set it thereafter.
+<p>
+Comment out the PixmapPath and IconPath from your .fvwmrc file to
+disable the fvwm icons and restart the WM.
+Start an xterm.
+Iconify xterm and maximize it again.
+Use resize button or corners to resize the xterm.
+<p>
+The xterm now shrinks to a tiny size and attempts to resize it
+result in it shrinking again.
+<p>
+I've tried this with fvwm 1.23 and fvwm 2.0.46 with the same results.
+Olvm, olvwm and twm all behave correctly so it may be a fvwm problem.
+</ul>
+I have not observed the first, but have reproduced the second.
+
+<H2><A NAME="xterm_tite">Why doesn't the screen clear when running vi?</A></H2>
+Under SunOS 4.x, the termcap description for xterm embeds in the
+<STRONG>ti</STRONG> and <STRONG>te</STRONG> capabilities a command to switch to
+xterm's alternate screen (e.g., while running <STRONG>vi</STRONG>), and return
+to the normal screen on exit.
+This has the effect of clearing the screen.
+Under Solaris 2.x, the terminfo description does not use the alternate
+screen (it is a matter of preference after all), so that the text from
+vi remains on the screen after exit.
+There are corresponding terminfo symbols for
+<STRONG>ti</STRONG> and <STRONG>te</STRONG>:
+<STRONG>enter_ca_mode</STRONG> and <STRONG>exit_ca_mode</STRONG>, respectively.
+<P>
+This is configurable.
+<p>
+For example (from Bjorn Helgaas &lt;helgaas@dhc.net&gt;)
+this procedure adds these capabilities to the "xterm"
+terminfo definition on HP-UX 10.20:
+<pre>
+<code>
+	cp /usr/lib/terminfo/x/xterm /usr/lib/terminfo/x/xterm.orig
+	untic xterm &gt; /tmp/xterm.src
+	echo " smcup=\E7\E[?47h, rmcup=\E[2J\E[?47l\E8," &gt;&gt; /tmp/xterm.src
+	tic /tmp/xterm.src
+</code>
+</pre>
+However, xterms that are linked with termcap are more flexible in this area
+than those linked with terminfo libraries.
+The xterm program supports a resource <STRONG>titeInhibit</STRONG> which
+manipulates the $TERMCAP variable to accomplish this.  It sets the $TERMCAP
+variable for the client with the <EM>ti</EM> and <EM>te</EM> capabilities
+suppressed.
+Systems that use terminfo cannot do this.  If you are running terminfo
+with the alternate screen controls in the terminal description, then
+you can suppress the switching to the alternate screen by the
+<STRONG>titeInhibit</STRONG>, but not the associated cursor save/restore
+and clear-screen operations.
+<P>
+XFree86 3.9s xterm implements a different set of controls which addresses
+this (in addition to the older set of controls, for compatibility).  The
+new set of controls implements the entire <EM>ti</EM> sequence (save cursor,
+switch to alternate screen, clear screen) and <EM>te</EM> (switch to normal
+screen, restore cursor) as two control sequences that can be disabled by
+<STRONG>titeInhibit</STRONG>.
+
+<H2><A NAME="xterm_vite">Why is the cursor misplaced after running vi?</A></H2>
+Vi and other full-screen applications use the termcap ti/te (terminfo
+smcup/rmcup) strings to initiate and end cursor addressing mode.
+As mentioned in the discussion of <A HREF="#xterm_tite">titeInhibit</A>,
+full-screen applications can expect the initialization string to save
+the cursor, and the end-string to restore it.
+<P>
+A few applications (reportedly IRIX 5.x and 6.x <STRONG>vi</STRONG>
+incorrectly move the cursor before initializing cursor-addressing.
+This will cause the end-string to restore the cursor to its position
+when it was saved by the initialization string (typically at the
+upper left corner of the screen).
+
+<H2><A NAME="xterm_erase">Why doesn't my delete key work?</A></H2>
+This seems to be a problem with the older XFree86 release (3.1.2).
+I have picked up pieces of the story (xterm and the keyboard work as
+designed under XFree86 3.2 and up).
+<P>
+You are probably talking about the <STRONG>backarrow</STRONG> key
+(on my keyboard, at the upper right of the QWERTY block),
+or the key labeled <STRONG>delete</STRONG>.  Since xterm is emulating
+a VT100/VT220, the backarrow key should generate a 127 (often displayed as
+<STRONG>^?</STRONG>).  You would use a control/H to obtain a backspace
+on a real VT220.
+<P>
+Tastes differ on Unix, people expect the backarrow key to generate a backspace
+(or not).  As I understand it, at one point, XFree86 picked up the sense of the
+erase character during initialization, so that xterm would in effect use the
+same erase character as the console.  The current scheme (X11R6) uses keyboard
+mapping tables that are independent of the environment.
+<P>
+XFree86 xterm provides a resource toggle <em>backarrowKey</em> (from VT320)
+that changes this key between the two styles (backspace or delete).
+<p>
+With XFree86 xterm patch number 95, you may have an xterm which can
+automatically initialize the backarrow key to backspace or delete
+depending on the pseudo terminal's sense, or based on the termcap
+setting of <em>kbs</em> (backspace key).
+This feature is controlled by the resource setting <em>ptyInitialErase</em>.
+
+<H2><A NAME="xterm_erased">Why did my delete key stop working?</A></H2>
+Well, something changed.
+You have to determine what did.
+<p>
+One unexpected scenario came out of hiding when I was implementing the
+<em>ptyInitialErase</em> resource.  When xterm is (by default) built
+to support this, it sets the pty's erase character to match the
+termcap entry.  Xterm also sets the $TERMCAP environment variable to match. 
+So everything is consistent, and everything defined.
+The stty erase character is either backspace (^H) or delete (^?).
+<p>
+However, the <em>screen</em> program prefers to make the termcap
+delete (kD) an &lt;escape&gt;[3~, which corresponds to the VT220
+<kbd>remove</kbd> key.
+If $TERMCAP is set when starting <em>screen</em>, it will translate stty's
+erase character into the &lt;escape&gt;[3~, making most curses and
+termcap applications work.
+But stty still has the original erase character.
+So low-level applications which check stty will not work.
+<p>
+Unset $TERMCAP in xterms in which you expect to run screen.
+That works.
+
+<H2><A NAME="xterm_keypad">Why doesn't my keypad work?</A></H2>
+A few people have commented that the keypad does not work properly.
+Aside from bugs (I have fixed a few), the most common problem seems
+to be misconception.
+<p>
+Here's a picture of the VT100 numeric keypad:
+<pre>
+	+-----+-----+-----+-----+
+	| PF1 | PF2 | PF3 | PF4 |
+	+-----+-----+-----+-----+
+	|  7  |  8  |  9  |  -  |
+	+-----+-----+-----+-----+
+	|  4  |  5  |  6  |  ,  |
+	+-----+-----+-----+-----+
+	|  1  |  2  |  3  |     |
+	+-----+-----+-----+ ENT +
+	|     0     |  .  |     |
+	+-----+-----+-----+-----+
+</pre>
+and the similar Sun and PC keypads:
+<pre>
+	+-----+-----+-----+-----+
+	| NUM |  /  |  *  |  -  |
+	+-----+-----+-----+-----+
+	|  7  |  8  |  9  |     |
+	+-----+-----+-----+  +  +
+	|  4  |  5  |  6  |     |
+	+-----+-----+-----+-----+
+	|  1  |  2  |  3  |     |
+	+-----+-----+-----+ ENT +
+	|     0     |  .  |     |
+	+-----+-----+-----+-----+
+</pre>
+Working in X Windows, the NUM (NumLock) key has better uses than an alias
+for PF1 (and is sometimes reserved).  I use the F1 through F4 on the keyboard
+to implement PF1 through PF4, alias the keypad "+" to "," and use the existing
+"-" key.
+<p>
+I test the keyboard (for VT52/VT100/VT220) using
+<A HREF="../vttest/vttest.html">vttest</A>.
+If you find (or think that you have found) a problem with the keyboard
+handling of xterm, please test it with vttest first.
+
+<H2><A NAME="xterm_8bits">Why can't I input 8-bit characters</A></H2>
+You must have the <STRONG>eightBitInput</STRONG> resource set to do this.
+
+<H2><A NAME="my_xdefaults">My .Xdefaults for XTERM</A></H2>
+<PRE><code>
+	XTerm*internalBorder:  10
+	XTerm*highlightSelection:  true
+	XTerm*VT100*colorBDMode:  on
+	XTerm*VT100*colorBD:  blue
+	XTerm*VT100*colorULMode:  on
+	XTerm*VT100*colorUL:  magenta
+	XTerm.VT100.eightBitInput:  true
+	XTerm.VT100.eightBitOutput:  true
+	XTerm*scrollBar:  true
+	XTerm.VT100.titeInhibit:  true
+
+	XTerm.VT100*colorMode:  on
+	XTerm.VT100*dynamicColors:  on
+
+	! Uncomment this to use color for underline attribute
+	XTerm.VT100*colorULMode:  on
+	XTerm.VT100*underLine:  off
+
+	! Uncomment this to use color for the bold attribute
+	XTerm.VT100*colorBDMode: on
+
+	XTerm.VT100*color0: black
+	XTerm.VT100*color1: red3
+	XTerm.VT100*color2: green3
+	XTerm.VT100*color3: yellow3
+	XTerm.VT100*color4: blue3
+	XTerm.VT100*color5: magenta3
+	XTerm.VT100*color6: cyan3
+	XTerm.VT100*color7: gray90
+	XTerm.VT100*color8: gray30
+	XTerm.VT100*color9: red
+	XTerm.VT100*color10: green
+	XTerm.VT100*color11: yellow
+	XTerm.VT100*color12: blue
+	XTerm.VT100*color13: magenta
+	XTerm.VT100*color14: cyan
+	XTerm.VT100*color15: white
+	XTerm.VT100*colorUL: yellow
+	XTerm.VT100*colorBD: white
+
+	XTerm.VT100*cursorColor: lime green
+</code>
+</PRE>
+XFree86 xterm comes with two copies of the resource file,
+one with color only (<code>XTerm-col.ad</code>,
+which is installed as <code>XTerm-color</code>),
+and the regular one (<code>XTerm.ad</code>,
+installed as <code>XTerm</code>).
+To use the <code>XTerm-color </code>file in conjunction
+with a separate <code>XTerm</code> app-defaults
+file which does not contain color,
+add the following line to your <code>.Xdefaults</code> file:
+<PRE>
+<code>
+	*customization: -color
+</code>
+</PRE>
+<H2><A NAME="tiny_menus">Why are the menus tiny</A></H2>
+Everything seems to work, except that the
+xterm menus (VT options, fonts, etc.) do not display
+properly; the menus pop up, but only with a tiny display
+area in which none of the options are visible (and only
+part of the menu title is visible).
+<P>
+You have specified the geometry for xterm too high in the hierarchy, and that
+24x80 (or whatever the -geometry parameter happens to be) is applying to the
+menus in pixels.
+This resource makes the geometry apply to the menus as well as the VT100 widget:
+<PRE>
+<code>
+	XTerm*geometry: 80x24
+</code>
+</PRE>
+while this applies only to the VT100 widget
+(which is probably what you intended):
+<PRE>
+<code>
+	XTerm.VT100*geometry: 80x24
+</code>
+</PRE>
+
+<H2><A NAME="warning_msg">What is this warning message?</A></H2>
+<DL>
+<DT>xterm: Error 11, errno 22: permission denied
+<DD>Actually, any message like this denotes a failure which requires
+studying the xterm source to determine the exact problem.
+<p>
+You have either found a bug in xterm, or there is something wrong
+with your computer's configuration, e.g., not enough pty's,
+incorrect permissions, etc.
+<p>
+The first number is an internal code (defined in error.h in xterm's source),
+and the second is the system error number (defined in /usr/include/sys/errno.h). 
+The system error number is easier to lookup, but the internal error code
+tells you where to look in the source.
+<DT>input method doesn't support my preedit type
+<DD>Ignore this if you do not know what <em>input method</em> is.
+Input methods are used to enter composite characters (e.g., umlauts,
+other types of punctuated characters, East Asian characters, etc).
+Your computer's libraries support this, but are missing configuration
+tables, and xterm is warning you.
+</DL>
+
+<H2><A NAME="known_bugs">Known Bugs in XTERM</A></H2><P>
+These are the known bugs (or limitations) in the XFree86 xterm.
+They are also present in the other versions based on the X Consortium
+sources (color_xterm, ansi_xterm, kterm).
+<P>
+Note that of the emulators that support color, most do not support
+<STRONG>bce</STRONG> (back color erase).
+The bce capability is also called the
+"new color model", though it has been implemented in the IBM PC for
+quite a while.
+<UL>
+<LI>cut/paste does not select tabs; instead spaces are selected.
+This is because the selection works from the array of displayed
+characters, on which tab/space conversion has already been performed.
+<LI>does not implement the autorepeat feature of VTxxx terminals.
+</UL>
+
+<H3><A NAME="bug_xterm">X11R6.3 XTERM</A></H3>
+The X Consortium version of xterm (and versions based on it) has
+additional bugs not in XFree86 xterm:
+<UL>
+<LI>the program must be run with fixed (nonproportional) fonts.
+<LI>the home and end keys do not generate usable escape sequences, due to
+an indexing error.
+<LI>the Main Options menu is improperly constructed, due to incorrect
+indices after removing the logging toggle.
+This makes the list of signals off by one.
+<LI>very large screens (e.g., by using nil2 for a font) cause core dumps
+because the program uses a fixed array (200 lines) for adjusting pointers.
+<LI>certain types of key translations cause a core dump because the program
+does not check the event class before attempting to use events.
+</UL>
+(These bugs are also present in the X11R5 version).
+
+<H3><A NAME="bug_color_xterm">COLOR_XTERM</A>
+<A HREF="ftp://www.x.org/contrib/applications/color_xterm-beta1.tar.gz">download</A></H3>
+This is based on the X Consortium X11R5 source, with the same bugs.
+<UL>
+<LI>implements non-bce color model
+<LI>moving the cursor is reported to leave trails of incorrect color
+<LI>clearing the screen resets colors (arguably this is a limitation).
+</UL>
+Not exactly a bug, but it does not build on Linux with X11R6.3
+
+<H3><A NAME="bug_ansi_xterm">ANSI_XTERM</A>
+<A HREF="ftp://www.x.org/contrib/applications/xterm-R6-sb_right-ansi-3d.tar.gz">download</A></H3>
+This is based on the X Consortium source, with the same bugs.
+<UL>
+<LI>implements non-bce color model
+<LI>fails
+<A HREF="../vttest/vttest.html">vttest</A>
+by not rendering reverse-video screen
+</UL>
+
+<H3><A NAME="bug_dtterm">DTTERM</A></H3>
+This is distributed with CDE.
+It implements more of the DEC VT220 than the X Consortium xterm,
+and also adds controls to manipulate the window and icon.
+<UL>
+<LI>implements non-bce color model
+<LI>fails
+<A HREF="../vttest/vttest.html">vttest</A>
+by clearing its background to solid white rather
+than preserving its sense in response to ED.
+<LI>under some circumstances, scrolling margins are not recognized.
+For instance, running
+<A HREF="../vile/vile.html">vile</A>
+which uses scrolling margins, we see text overwriting the status line.
+</UL>
+
+<H3><A NAME="bug_emu">EMU 1.3</A>
+<A HREF="ftp://www.x.org/contrib/applications/emu-1.31.tar.gz">download</A></H3>
+This is not based on the X Consortium source.
+The authors state that it implements VT220 emulation.
+It is in need of maintenance, since it builds with some problems to produce
+an executable that (on Linux and SunOS) does not handle the carriage return
+and newline translations properly.
+So I am unable to run
+<A HREF="../vttest/vttest.html">vttest</A>
+on this emulator.
+
+<H3><A NAME="bug_kterm">KTERM</A>
+<A HREF="ftp://www.x.org/contrib/applications/kterm-6.2.0.tar.gz">download</A></H3>
+This is based on the X Consortium source, with the same bugs
+(though the list of original authors has been removed; the modifications
+that comprise kterm is relatively small).
+<UL>
+<LI>implements non-bce color model
+<LI>implements status line, but uses non-DEC escape sequences for this.
+</UL>
+
+<H3><A NAME="bug_nxterm">NXTERM</A></H3>
+Distributed with Redhat Linux 5.2,
+it is a repackaging of <A HREF="#bug_ansi_xterm">xterm-sb_right-ansi</A>, to use the
+Xaw3d widget set.  This is based on the X Consortium X11R6 source, with the
+same bugs.
+<UL>
+<LI>implements non-bce color model
+<LI>does not implement SGR 39 and SGR 49, all attributes are reset when changing colors.
+<LI>popup menus do not appear to work.
+</UL>
+Starting with Redhat 6.0, <em>nxterm</em> is the XFree86 3.3.6 xterm.
+Unfortunately Redhat neglected to update their termcap for nxterm to match
+the program.
+
+<H3><A NAME="bug_rxvt">RXVT</A>
+<A HREF="http://www.rxvt.org/">link</A></H3>
+This applies to versions of <EM>rxvt</EM> through 2.21:
+<UL>
+<LI>clearing the screen resets colors
+<LI>does not have a delete key
+<LI>the implementation of <STRONG>ech</STRONG> (erase characters) does not
+follow DEC VT220 (also ISO 6429), causing applications using this function to
+misbehave.
+</UL>
+A new version
+(upgraded to an beta as of 2.6.PRE3, however, since it no longer dumps core in
+<A HREF="../vttest/vttest.html">vttest</A>)
+is reported to fix the <STRONG>ech</STRONG> bug.
+However, it is less VT100-compatible than the earlier versions such as 2.21b
+because it does not render reverse video (<STRONG>DECSCNM</STRONG>) properly.
+All versions do not update the screen frequently enough, making animation
+ineffective.
+See <A HREF="../vttest/vttest.html">vttest</A>, tests 1 and 2.
+
+<H3><A NAME="bug_xiterm">XITERM</A>
+<A HREF="ftp://sunsite.unc.edu/pub/Linux/X11/terms/">link</A></H3>
+This appears to be rxvt 2.20,
+lightly reformatted,
+with a few ifdef's changed.
+
+<H2><A NAME="building_it">How do I build XTERM?</A></H2>
+Building a copy of xterm is simple, provided that you have a development
+configuration for X Windows:
+<UL>
+<LI>Header files and libraries.
+If you do not have the header files (usually under /usr/include/X11) for
+your system, you are better off building the libraries yourself.
+Xterm can be built with either X11R5 or X11R6 libraries; however X11R6
+requires much more data to be installed before xterm will run.
+Xterm uses the <STRONG>Xaw</STRONG> library for popup menus.
+<LI>imake and <EM>xmkmf</EM>.
+These utilities produce a Makefile from the Imakefile.
+They are not essential, but useful, particularly on systems with
+unusual configurations.
+</UL>
+If you have a working <EM>xmkmf</EM> script (or correctly configured imake utility),
+all you need to do is type
+<PRE>
+<code>
+	xmkmf
+	make
+</code>
+</PRE>
+I have written a simple <EM>configure</EM> script for xterm which uses imake
+(or <EM>xmkmf</EM>) to generate a Makefile from the Makefile.in.
+I plan to restructure xterm to eliminate the hardcoded
+<STRONG>#ifdef</STRONG>'s, replacing them with definitions that can be derived
+with the configuration script.
+The <EM>configure</EM> script is more flexible than <EM>xmkmf</EM>, since it
+allows you to enable or disable a variety of features.
+Type
+<PRE>
+	configure --help
+</PRE>
+to get a list of options.
+<P>
+Though I plan to replace the hardcoded ifdef's with
+autoconfigured values, it will still continue to build properly with the imake environment,
+since that is how large distributions incorporate xterm.
+
+<H2><A NAME="report_bugs">How do I report bugs?</A></H2>
+You should report bugs to
+<A HREF="mailto:report@XFree86.org">report@XFree86.org</A>;
+however I am continuing development as I find time; your input is valuable:
+<A HREF="mailto:dickey@herndon4.his.com">mail</A>.
+See also
+<A HREF="../scripts/readme.html">Analyzing problems with configure scripts</A>
+
+<H1><A NAME="future_work">Ongoing/future work</A></H1>
+<UL>
+<LI>double-high/double-wide characters
+<P>I have implemented double size characters in stages:
+<ul>
+<li>Like Kermit, XFree86 xterm can show normal characters spaced at the proper intervals.
+<li>If your font server cooperates (e.g., X11R6), you can display many fixed
+fonts in double-size, though not all.
+<li>XFree86 xterm can also generate its own line-drawing characters,
+which normally are missing from fixed fonts except for those that
+were designed for xterm.
+<li>Other than the limitations which the font server may impose,
+the double size characters are drawn properly.
+</ul>
+<LI>soft (downloadable) fonts
+<LI>search scrollback
+It would be nice to be able to search the scrollback buffer.
+<LI>printer interface
+<P>
+Done, except for the corresponding support in the VT52 emulation.
+It would be nice to have a dialog to control this.
+<LI>allow alternate libraries for popup-menus and dialogs
+<P>
+My configure script currently provides tests for the variations of Athena
+widgets (Xaw3D, neXtaw).
+I intend to make additional changes to support Motif scrollbars and menus.
+<LI>blinking text.
+<P>
+Just for completeness (though no one seems to want this feature).
+<LI>Double-width font support for UTF-8 mode (for CJK users)
+<LI>popup window that shows hex code for content of a character cell
+and hexadecimal keyboard entry for all Unicode characters (ISO 14755)
+<LI>UTF-8 combining character support (simple glyph overstriking only)
+<LI>correct cut&amp;paste of TAB character
+</UL>
+
+</BODY>
+</HTML>
--- xfree86-1-3.3.6.orig/debian/xterm/conffiles
+++ xfree86-1-3.3.6/debian/xterm/conffiles
@@ -0,0 +1 @@
+/etc/X11/Xresources/xterm
--- xfree86-1-3.3.6.orig/debian/xterm/postrm
+++ xfree86-1-3.3.6/debian/xterm/postrm
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Debian xterm package post-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xterm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|purge) ;;
+  upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) exit 0 ;;
+esac
+
+if command -v suidunregister > /dev/null 2>&1; then
+  suidunregister -s xterm /usr/X11R6/bin/xterm
+fi
+
+if command -v update-menus > /dev/null 2>&1; then
+  update-menus
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xterm/README.Debian
+++ xfree86-1-3.3.6/debian/xterm/README.Debian
@@ -0,0 +1,54 @@
+Debian README for xterm package
+
+** Read this file and then see the Debian X FAQ in
+** /usr/share/doc/xfree86-common/FAQ.gz if you are wondering what has
+** happened to, for instance, your backspace and delete keys.
+
+As of version 3.3.4-1, xterm logs to the wtmp and lastlog files.  If you do
+not have a utmp group on your system, xterm will be installed setuid root
+instead of setgid utmp.  xterm drops its root privileges after it
+initializes, so if it is setuid this can result in corrupt wtmp entries.
+The best thing to do is make a utmp group in /etc/group, or upgrade to
+version 2.0.3.4 or later of the base-passwd package, so that you have a
+utmp group.
+
+The xterm terminal type on a Debian system is an alias for xterm-debian.
+This means that "xterm" and "xterm-debian" are interchangeable as values of
+the $TERM environment variable in the shell.  Since the xterm-debian type
+is typically not found on non-Debian systems, xterm is used as the system
+default.
+
+The terminal description for xterm-debian differs from that of
+xterm-xfree86 in exactly two respects:
+  1. kbs is defined as ^? (ASCII 127), not ^H (ASCII 8)
+  2. kdch1 is defined as the sequence: ^[ [ 3 ~ (no spaces, and ^[ is ASCII
+     27, a.k.a ESCAPE) instead of ^? (ASCII 127)
+^[[3~ is the DEC VT220 escape sequence for the keypad delete key (not the
+numeric keypad, the one with Page Up, Page Down, etc. on a PC keyboard).
+DEC VT100's, the text terminal wich xterm was designed to emulate, had no
+keypad delete key.  ^[[3~ is also what the Linux console terminal type
+generates for the keypad delete key.  Note that the terminal definitions
+that a Debian system uses are in the ncurses-term package, not in the xterm
+package itself, though the (pre-compiled) terminfo and termcap files that
+Debian uses may be found in the xterm documentation directory,
+/usr/share/doc/xterm.  People interested in reading further to stock up
+ammo for their backspace/delete and terminal type wars should consult Tom
+Dickey's (current maintainer of the xterm source code) FAQ, available in
+the file /usr/share/doc/xterm/xterm.faq{html,text.gz} and the website
+<http://vt100.net>.
+
+The default keymappings for xterm are different than they are upstream to
+comply with the Debian Keyboard Policy and make xterm's behavior more
+consistent with the Linux virtual console (and therefore with the behavior
+of DEC VT 220 terminals).
+
+The file /etc/X11/Xresources/xterm contains resource settings for xterm.
+If you wish to override some of the settings in the XTerm and XTerm-color
+app-defaults files, this is the place to do it.  See the X manual page for
+more information on X resources.  Debian makes a few changes to the default
+VT100 event translations used by xterm; these again have to do with the
+Debian keyboard policy and compliance with VT220's and the Linux virtual
+console.  See the comments within /etc/X11/Xresources/xterm for more
+details.
+
+Branden Robinson, 13 Mar 2000
--- xfree86-1-3.3.6.orig/debian/xterm/xterm.faq.doc-base
+++ xfree86-1-3.3.6/debian/xterm/xterm.faq.doc-base
@@ -0,0 +1,14 @@
+Document: xterm-faq
+Title: XTerm Frequently Asked Questions (FAQ)
+Author: Tom Dickey
+Abstract: This document provides answers to frequently asked questions
+ about the XTerm terminal emulator as it ships with the XFree86 distribution
+ of the X Window System.
+Section: XShells
+
+Format: text
+Files: /usr/share/doc/xterm/xterm.faq.text.gz
+
+Format: HTML
+Index: /usr/share/doc/xterm/xterm.faq.html
+Files: /usr/share/doc/xterm/xterm.faq.html
--- xfree86-1-3.3.6.orig/debian/xterm/menu
+++ xfree86-1-3.3.6/debian/xterm/menu
@@ -0,0 +1,6 @@
+?package(xterm):\
+ needs=x11\
+ section=XShells\
+ longtitle="Xterm: terminal emulator for X"\
+ title=Xterm\
+ command=xterm
--- xfree86-1-3.3.6.orig/debian/xterm/terminfo
+++ xfree86-1-3.3.6/debian/xterm/terminfo
@@ -0,0 +1,666 @@
+# $XConsortium: terminfo,v 1.11 94/10/13 21:24:31 gildea Exp $
+# $XFree86: xc/programs/xterm/terminfo,v 3.13.2.7 1999/05/10 13:10:05 hohndel Exp $
+#
+# XFree86 updates/notes/new entries (including xterm-8bit, xterm-16color)
+# - Thomas E. Dickey <dickey@herndon4.his.com>
+#
+# Special Capabilities:
+# --------------------
+# ich has a corresponding capability that inserts a single blank.  We could
+#	have used ich1=\E[@, which works with ncurses, but that is not standard
+#	behavior.  If it is set, then SVr4 vi (e.g., Solaris 2.6) emits both
+#	smir/rmir and ich1.
+# meml locks memory above the cursor; memu unlocks (ala HP terminals).  This
+#	is not recognized by some older (e.g., SVr3) tic programs, but none
+#	do more than warn about it.  Ignore the warning.
+# rmcup clears memory before switching to the alternate screen.  The older
+#	(deprecated) \E[?47h did not do this, requiring applications to
+#	embed a \E[2J in the rmcup string.  However, that behavior cannot
+#	be disabled via titeInhibit, making that resource not function as
+#	intended on systems with terminfo.
+# rs2/is2 are shorter with XFree86 xterm because it supports DECSTR.  We
+#	use the shorter sequence for compatibility with the termcap, which
+#	is trimmed to keep it shorter than 1023 characters.  It (escape \E[!p)
+#	replaces these in the conventional vt100 reset-string:
+#		\E7	- save cursor (fixes origin-mode side-effect)
+#		\E[r	- reset scrolling margins
+#		\E[m	- reset SGR (including color)
+#		\E[?7h	- reset wraparound mode (DECAWM)
+#		\E[?1l	- reset application cursor keys (DECCKM)
+#		\E[?6l	- reset origin mode (DECOM)
+#		\E8	- restore cursor
+#	DECSTR is recognized by XFree86 xterm even in vt52 mode.
+#
+# Editing Keypad:
+# --------------
+# XFree86 xterm emulates vt220 if the decTerminalID resource is set to 200 or
+# higher.  Otherwise it emulates a vt100 or vt52 depending on the value of the
+# resource.  When emulating a vt220, we support the editing keypad.  Sun and PC
+# keyboards have an editing keypad which is similar to the vt220:
+#
+#	VT220 editing keypad
+#	----------------------------
+#	Find      Insert      Remove
+#	Select    Prev        Next
+#	----------------------------
+#
+#	Sun/PC editing keypad
+#	----------------------------
+#	Insert    Home        PageUp
+#	Delete    End         PageDn
+#	----------------------------
+#
+# If the sunKeyboard resource is true, we map it this way (adjusting the values
+# of Home, End and Delete):
+#	VT220		      Sun/PC
+#	----------------------------
+#	Find		      Home
+#	Select		      End
+#	Insert		      Insert
+#	Remove		      Delete
+#	Prev		      PageUp
+#	Next		      PageDn
+#	----------------------------
+#
+# Note that all of the keys on the editing keypad transmit escape sequences.  A
+# vt220 does this only when in vt220 mode; when emulating a vt100 the editing
+# keypad is inactive.
+#
+# Alternative keycodes:
+# --------------------
+# Several of the function keys have alternative names, depending on the type of
+# host which your xterm is connected to.  DEC (i.e., the VMS system) uses F15
+# as the HELP key, F16 as the DO key.  Unix applications generally do not do
+# this.  Curses applications in particular, assign a unique keycode to each
+# capability string.  These terminal descriptions do not have conflicting
+# definitions, to ensure that Unix curses applications use a consistent set of
+# keycodes.  To get a VMS-bias, make these substitutions:
+#	1. change khome to kfnd
+#	2. change kend to kslt
+# Some legacy applications using the termcap emulation may expect kll where
+# we have specified kend.
+#
+xterm-xfree86|xterm-new|xterm terminal emulator (XFree86),
+	am,
+	bce,
+	km,
+	mc5i,
+	mir,
+	msgr,
+	xenl,
+	colors#8,
+	cols#80,
+	it#8,
+	lines#24,
+	pairs#64,
+	acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
+	bel=^G,
+	blink=\E[5m,
+	bold=\E[1m,
+	cbt=\E[Z,
+	civis=\E[?25l,
+	clear=\E[H\E[2J,
+	cnorm=\E[?25h,
+	cr=^M,
+	csr=\E[%i%p1%d;%p2%dr,
+	cub=\E[%p1%dD,
+	cub1=^H,
+	cud=\E[%p1%dB,
+	cud1=^J,
+	cuf=\E[%p1%dC,
+	cuf1=\E[C,
+	cup=\E[%i%p1%d;%p2%dH,
+	cuu=\E[%p1%dA,
+	cuu1=\E[A,
+	cvvis=\E[?25h,
+	dch=\E[%p1%dP,
+	dch1=\E[P,
+	dl=\E[%p1%dM,
+	dl1=\E[M,
+	ech=\E[%p1%dX,
+	ed=\E[J,
+	el=\E[K,
+	el1=\E[1K,
+	enacs=\E(B\E)0,
+	flash=\E[?5h\E[?5l,
+	home=\E[H,
+	hpa=\E[%i%p1%dG,
+	ht=^I,
+	hts=\EH,
+	ich=\E[%p1%d@,
+	il=\E[%p1%dL,
+	il1=\E[L,
+	ind=^J,
+	invis=\E[8m,
+	is2=\E[!p\E[?3;4l\E[4l\E>,
+	ka1=\EOw,
+	ka3=\EOu,
+	kb2=\EOy,
+	kbeg=\EOE,
+	kbs=^H,
+	kc1=\EOq,
+	kc3=\EOs,
+	kcub1=\EOD,
+	kcud1=\EOB,
+	kcuf1=\EOC,
+	kcuu1=\EOA,
+	kdch1=\177,
+	kend=\E[4~,
+	kent=\EOM,
+	kf1=\EOP,
+	kf10=\E[21~,
+	kf11=\E[23~,
+	kf12=\E[24~,
+	kf13=\E[25~,
+	kf14=\E[26~,
+	kf15=\E[28~,
+	kf16=\E[29~,
+	kf17=\E[31~,
+	kf18=\E[32~,
+	kf19=\E[33~,
+	kf2=\EOQ,
+	kf20=\E[34~,
+	kf3=\EOR,
+	kf4=\EOS,
+	kf5=\E[15~,
+	kf6=\E[17~,
+	kf7=\E[18~,
+	kf8=\E[19~,
+	kf9=\E[20~,
+	khome=\E[1~,
+	kich1=\E[2~,
+	kmous=\E[M,
+	knp=\E[6~,
+	kpp=\E[5~,
+	mc0=\E[i,
+	mc4=\E[4i,
+	mc5=\E[5i,
+	meml=\El,
+	memu=\Em,
+	op=\E[39;49m,
+	rc=\E8,
+	rev=\E[7m,
+	ri=\EM,
+	rmacs=^O,
+	rmam=\E[?7l,
+	rmcup=\E[?1047l\E[?1048l,
+	rmir=\E[4l,
+	rmkx=\E[?1l\E>,
+	rmso=\E[27m,
+	rmul=\E[24m,
+	rs1=\Ec,
+	rs2=\E[!p\E[?3;4l\E[4l\E>,
+	sc=\E7,
+	setab=\E[4%p1%dm,
+	setaf=\E[3%p1%dm,
+	setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
+	setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
+	sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m%?%p9%t\016%e\017%;,
+	sgr0=\E[m\017,
+	smacs=^N,
+	smam=\E[?7h,
+	smcup=\E[?1048h\E[?1047h,
+	smir=\E[4h,
+	smkx=\E[?1h\E=,
+	smso=\E[7m,
+	smul=\E[4m,
+	tbc=\E[3g,
+	u6=\E[%i%d;%dR,
+	u7=\E[6n,
+	u8=\E[?1;2c,
+	u9=\E[c,
+	vpa=\E[%i%p1%dd,
+# xterm-debian is identical to xterm-xfree86 except that it more strictly
+# conforms to DEC VT220 behavior in the case of the backspace and delete
+# keys; this is mandated by the keyboard configuration section of the
+# Debian Policy Manual.  Also see <http://vt100.net/docs/vt220-rm/>.
+xterm-debian|Debian xterm (VT220-conformant backspace and delete),
+	kbs=\177,
+	kdch1=\E3~,
+	use=xterm-xfree86,
+#
+# The xterm-xfree86 description has all of the features, but is not completely
+# compatible with vt220.  If you are using a Sun or PC keyboard, set the
+# sunKeyboard resource to true:
+#	+ maps the editing keypad
+#	+ interprets control-function-key as a second array of keys, so a
+#	  12-fkey keyboard can support vt220's 20-fkeys.
+#	+ maps numeric keypad "+" to ",".
+#
+xterm-vt220|XFree86 xterm emulating vt220,
+	kdch1=\E[3~,
+	kend=\E[4~,
+	khome=\E[1~,
+	use=xterm-xfree86,
+
+# Other variants:
+xterm-24|xterms|vs100|xterm terminal emulator (X Window System),
+	lines#24,
+	use=xterm,
+xterm-65|xterm with tall window 65x80 (X Window System),
+	lines#65,
+	use=xterm,
+xterm-bold|xterm with bold instead of underline (X Window System),
+	smso=\E[7m,
+	smul=\E[1m,
+	use=xterm,
+xterm-mono|monochrome xterm (X Window System),
+	colors@,
+	ncv@,
+	pairs@,
+	op@,
+	setab@,
+	setaf@,
+	setb@,
+	setf@,
+	sgr@,
+	use=xterm,
+#
+# This should work for the commonly used "color xterm" variations (XFree86
+# xterm, color_xterm, nxterm, rxvt):
+xterm-color|generic "ANSI" color xterm (X Window System),
+	colors#8,
+	ncv@,
+	pairs#64,
+	op=\E[m,
+	setab=\E[4%p1%dm,
+	setaf=\E[3%p1%dm,
+	use=xterm-r6,
+#
+xterm-boldso|xterm with bold for standout (X Window System),
+	rmso=\E[m,
+	smso=\E[1m,
+	use=xterm,
+#
+# vi may work better with this entry, because vi
+# doesn't use insert mode much
+xterm-ic|xterm-vi|xterm with insert character instead of insert mode,
+	mir@,
+	ich=\E[%p1%d@,
+	ich1=\E[@,
+	rmir@,
+	smir@,
+	use=xterm,
+#
+# This is used only for testing (it's not relevant to DEC VTxxx terminals, but
+# to ncurses).
+xterm-xmc|xterm with magic-cookie glitch,
+	xmc#1,
+	use=xterm,
+#
+# This one also is primarily for testing ncurses; while the ISO 6429 defines
+# the REP control, none of the DEC VTxxx terminals (VT52 through VT420) support
+# it.
+xterm-rep|xterm with repeat-character control,
+	rep=%p1%c\E[%p2%{1}%-%db,
+	use=xterm,
+#
+# This is mainly for testing xterm; the real VT220 will not let you switch
+# character sets without first altering the keyboard language in the setup
+# screen.  Some emulators allow this anyway.  (Note that these strings are
+# normally used only for printers).  The parameter to csnm and scs is the same
+# in both cases:  the keyboard language parameter returned by CSI ? 2 6 n.
+xterm-nrc|xterm with VT220 national replacement character sets,
+	csnm=%?%p1%{1}%=%tNorth American%e%p1%{2}%=%tBritish%e%p1%{3}%=%tFlemish%e%p1%{4}%=%tFrench Canadian%e%p1%{5}%=%tDanish%e%p1%{6}%=%tFinnish%e%p1%{7}%=%tGerman%e%p1%{8}%=%tDutch%e%p1%{9}%=%tItalian%e%p1%{10}%=%tSwiss (French)%e%p1%{11}%=%tSwiss (German)%e%p1%{12}%=%tSwedish%e%p1%{13}%=%tNorwegian%e%p1%{14}%=%tFrench/Belgian%e%p1%{15}%=%tSpanish%;,
+	scs=%?%p1%{1}%=%t\E(B%e%p1%{2}%=%t\E(A%e%p1%{3}%=%t\E(R%e%p1%{4}%=%t\E(9%e%p1%{5}%=%t\E(E%e%p1%{6}%=%t\E(5%e%p1%{7}%=%t\E(K%e%p1%{8}%=%t\E(4%e%p1%{9}%=%t\E(Y%e%p1%{10}%=%t\E(=%e%p1%{11}%=%t\E(=%e%p1%{12}%=%t\E(7%e%p1%{13}%=%t\E(E%e%p1%{14}%=%t\E(R%e%p1%{15}%=%t\E(Z%;,
+	use=xterm,
+#
+# Foreground 0-15 maps (with toggles) into 30-37 & 90-97
+# Background 0-15 maps (with toggles) into 40-47 & 100-107
+#
+# Originally I suppressed setaf/setab, since ANSI specifies only 8 colors, but
+# Stephen Marley persuaded me to allow the "ANSI" color controls to extend to
+# 16 colors.  (Note that ncurses 4.2 uses setf/setb from this description;
+# however 5.0 selects either according to their availability).  - T.Dickey
+#
+# SVr4 curses does not use more than 8 colors anyway, so using 16 colors is
+# either for terminfo-level applications or via ncurses.
+xterm-16color|xterm with 16 colors,
+	colors#16,
+	ncv#32,
+	pairs#256,
+	setab=\E[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm,
+	setaf=\E[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm,
+	setb=%p1%{8}%/%{6}%*%{4}%+\E[%d%p1%{8}%m%Pa%?%ga%{1}%=%t4%e%ga%{3}%=%t6%e%ga%{4}%=%t1%e%ga%{6}%=%t3%e%ga%d%;m,
+	setf=%p1%{8}%/%{6}%*%{3}%+\E[%d%p1%{8}%m%Pa%?%ga%{1}%=%t4%e%ga%{3}%=%t6%e%ga%{4}%=%t1%e%ga%{6}%=%t3%e%ga%d%;m,
+	use=xterm-xfree86,
+#
+# This is an 8-bit version of xterm, which emulates DEC vt220 with ANSI color.
+# To use it, your decTerminalID resource must be set to 200 or above.
+#
+#	HTS	\E H	\210
+#	RI	\E M	\215
+#	SS3	\E O	\217
+#	CSI	\E [	\233
+#
+xterm-8bit|xterm terminal emulator with 8-bit controls (X Window System),
+	am,
+	bce,
+	km,
+	mc5i,
+	mir,
+	msgr,
+	xenl,
+	colors#8,
+	cols#80,
+	it#8,
+	lines#24,
+	pairs#64,
+	acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
+	bel=^G,
+	blink=\2335m,
+	bold=\2331m,
+	cbt=\233Z,
+	civis=\233?25l,
+	clear=\233H\2332J,
+	cnorm=\233?25h,
+	cr=^M,
+	csr=\233%i%p1%d;%p2%dr,
+	cub=\233%p1%dD,
+	cub1=^H,
+	cud=\233%p1%dB,
+	cud1=^J,
+	cuf=\233%p1%dC,
+	cuf1=\233C,
+	cup=\233%i%p1%d;%p2%dH,
+	cuu=\233%p1%dA,
+	cuu1=\233A,
+	cvvis=\233?25h,
+	dch=\233%p1%dP,
+	dch1=\233P,
+	dl=\233%p1%dM,
+	dl1=\233M,
+	ech=\233%p1%dX,
+	ed=\233J,
+	el=\233K,
+	el1=\2331K,
+	enacs=\E(B\E)0,
+	flash=\233?5h\233?5l,
+	home=\233H,
+	hpa=\233%i%p1%dG,
+	ht=^I,
+	hts=\210,
+	ich=\233%p1%d@,
+	il=\233%p1%dL,
+	il1=\233L,
+	ind=^J,
+	invis=\2338m,
+	is2=\E7\E G\233r\233m\233?7h\233?1;3;4;6l\2334l\E8\E>,
+	ka1=\217w,
+	ka3=\217u,
+	kb2=\217y,
+	kbeg=\217E,
+	kbs=^H,
+	kc1=\217q,
+	kc3=\217s,
+	kcub1=\217D,
+	kcud1=\217B,
+	kcuf1=\217C,
+	kcuu1=\217A,
+	kdch1=\2333~,
+	kend=\2334~,
+	kent=\217M,
+	kf1=\23311~,
+	kf10=\23321~,
+	kf11=\23323~,
+	kf12=\23324~,
+	kf13=\23325~,
+	kf14=\23326~,
+	kf15=\23328~,
+	kf16=\23329~,
+	kf17=\23331~,
+	kf18=\23332~,
+	kf19=\23333~,
+	kf2=\23312~,
+	kf20=\23334~,
+	kf3=\23313~,
+	kf4=\23314~,
+	kf5=\23315~,
+	kf6=\23317~,
+	kf7=\23318~,
+	kf8=\23319~,
+	kf9=\23320~,
+	khome=\2331~,
+	kich1=\2332~,
+	kmous=\233M,
+	knp=\2336~,
+	kpp=\2335~,
+	mc0=\233i,
+	mc4=\2334i,
+	mc5=\2335i,
+	meml=\El,
+	memu=\Em,
+	op=\23339;49m,
+	rc=\E8,
+	rev=\2337m,
+	ri=\215,
+	rmacs=^O,
+	rmam=\233?7l,
+	rmcup=\233?1047l\233?1048l,
+	rmir=\2334l,
+	rmkx=\233?1l\E>,
+	rmso=\23327m,
+	rmul=\23324m,
+	rs1=\Ec,
+	rs2=\E7\E[62"p\E G\233r\233m\233?7h\233?1;3;4;6l\2334l\E8\E>,
+	sc=\E7,
+	setab=\2334%p1%dm,
+	setaf=\2333%p1%dm,
+	setb=\2334%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
+	setf=\2333%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
+	sgr=\2330%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m%?%p9%t\016%e\017%;,
+	sgr0=\233m^O,
+	smacs=^N,
+	smam=\233?7h,
+	smcup=\233?1048h\233?1047h,
+	smir=\2334h,
+	smkx=\233?1h\E=,
+	smso=\2337m,
+	smul=\2334m,
+	tbc=\2333g,
+	u6=\233[%i%d;%dR,
+	u7=\E[6n,
+	u8=\233[?1;2c,
+	u9=\E[c,
+	vpa=\233%i%p1%dd,
+#
+# Compatible with the R6 xterm, with the following changes:
+#	+ added acsc (perhaps some versions of tic assume the standard vt100
+#	  alternate character set)
+#	+ added u6, u7, u8, u9 strings for Daniel Weaver's tack program.
+#	+ added kmous string for ncurses.
+#	+ added khome/kend strings.
+xterm-r6|xterm-old|xterm X11R6 version,
+	am,
+	km,
+	mir,
+	msgr,
+	xenl,
+	cols#80,
+	it#8,
+	lines#24,
+	acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
+	bel=^G,
+	blink@,
+	bold=\E[1m,
+	clear=\E[H\E[2J,
+	cr=^M,
+	csr=\E[%i%p1%d;%p2%dr,
+	cub=\E[%p1%dD,
+	cub1=^H,
+	cud=\E[%p1%dB,
+	cud1=^J,
+	cuf=\E[%p1%dC,
+	cuf1=\E[C,
+	cup=\E[%i%p1%d;%p2%dH,
+	cuu=\E[%p1%dA,
+	cuu1=\E[A,
+	dch=\E[%p1%dP,
+	dch1=\E[P,
+	dl=\E[%p1%dM,
+	dl1=\E[M,
+	ed=\E[J,
+	el=\E[K,
+	enacs=\E)0,
+	home=\E[H,
+	ht=^I,
+	il=\E[%p1%dL,
+	il1=\E[L,
+	ind=^J,
+	is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
+	kbs=^H,
+	kcub1=\EOD,
+	kcud1=\EOB,
+	kcuf1=\EOC,
+	kcuu1=\EOA,
+	kdch1=\177,
+	kend=\E[4~,
+	kf1=\EOP,
+	kf10=\E[21~,
+	kf11=\E[23~,
+	kf12=\E[24~,
+	kf13=\E[25~,
+	kf14=\E[26~,
+	kf15=\E[28~,
+	kf16=\E[29~,
+	kf17=\E[31~,
+	kf18=\E[32~,
+	kf19=\E[33~,
+	kf2=\EOQ,
+	kf20=\E[34~,
+	kf3=\EOR,
+	kf4=\EOS,
+	kf5=\E[15~,
+	kf6=\E[17~,
+	kf7=\E[18~,
+	kf8=\E[19~,
+	kf9=\E[20~,
+	khome=\E[1~,
+	kich1=\E[2~,
+	kmous=\E[M,
+	knp=\E[6~,
+	kpp=\E[5~,
+	meml=\El,
+	memu=\Em,
+	rc=\E8,
+	rev=\E[7m,
+	ri=\EM,
+	rmacs=^O,
+	rmcup=\E[2J\E[?47l\E8,
+	rmir=\E[4l,
+	rmkx=\E[?1l\E>,
+	rmso=\E[m,
+	rmul=\E[m,
+	rs2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>,
+	sc=\E7,
+	sgr0=\E[m,
+	smacs=^N,
+	smcup=\E7\E[?47h,
+	smir=\E[4h,
+	smkx=\E[?1h\E=,
+	smso=\E[7m,
+	smul=\E[4m,
+	tbc=\E[3g,
+	u6=\E[%i%d;%dR,
+	u7=\E[6n,
+	u8=\E[?1;2c,
+	u9=\E[c,
+#
+# Compatible with the R5 xterm, with the following changes:
+#	+ changed 'blink=@', to 'blink@' (the former meant that "@" would start
+#	  a blink, the latter that it is not supported).
+#	+ changed kf1 through kf4 to correspond with actual usage.  Though X
+#	  supports keypad symbols for PF1 to PF4, and xterm interprets these
+#	  correctly, the F1 to F4 codes are commonly (but incorrectly) used.
+#	+ moved reset string from rs1 to rs2, to correlate better with termcap.
+#	+ make khome consistent with other entries.
+#	+ use rmul/smul, rmir/smir from termcap, but not rmcup/smcup because
+#	  not everyone wants the alternate screen.
+xterm-r5|xterm R5 version,
+	am,
+	km,
+	msgr,
+	xenl,
+	cols#80,
+	it#8,
+	lines#24,
+	bel=^G,
+	blink@,
+	bold=\E[1m,
+	clear=\E[H\E[2J,
+	cr=^M,
+	csr=\E[%i%p1%d;%p2%dr,
+	cub=\E[%p1%dD,
+	cub1=^H,
+	cud=\E[%p1%dB,
+	cud1=^J,
+	cuf=\E[%p1%dC,
+	cuf1=\E[C,
+	cup=\E[%i%p1%d;%p2%dH,
+	cuu=\E[%p1%dA,
+	cuu1=\E[A,
+	dch=\E[%p1%dP,
+	dch1=\E[P,
+	dl=\E[%p1%dM,
+	dl1=\E[M,
+	ed=\E[J,
+	el=\E[K,
+	home=\E[H,
+	ht=^I,
+	hts=\EH,
+	ich=\E[%p1%d@,
+	ich1=\E[@,
+	il=\E[%p1%dL,
+	il1=\E[L,
+	ind=^J,
+	kbs=^H,
+	kcub1=\EOD,
+	kcud1=\EOB,
+	kcuf1=\EOC,
+	kcuu1=\EOA,
+	kdch1=\177,
+	kdl1=\E[31~,
+	kel=\E[8~,
+	kend=\E[4~,
+	kf0=\EOq,
+	kf1=\E[11~,
+	kf10=\E[21~,
+	kf11=\E[23~,
+	kf12=\E[24~,
+	kf2=\E[12~,
+	kf3=\E[13~,
+	kf4=\E[14~,
+	kf5=\E[15~,
+	kf6=\E[17~,
+	kf7=\E[18~,
+	kf8=\E[19~,
+	kf9=\E[20~,
+	khome=\E[1~,
+	kich1=\E[2~,
+	kil1=\E[30~,
+	knp=\E[6~,
+	kpp=\E[5~,
+	rc=\E8,
+	rev=\E[7m,
+	ri=\EM,
+	rmir=\E[4l,
+	rmkx=\E[?1l\E>,
+	rmso=\E[m,
+	rmul=\E[m,
+	rs2=\E>\E[?1;3;4;5;6l\E[4l\E[?7h\E[m\E[r\E[2J\E[H,
+	sc=\E7,
+	sgr=\E[%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;m,
+	sgr0=\E[m,
+	smir=\E[4h,
+	smkx=\E[?1h\E=,
+	smso=\E[7m,
+	smul=\E[4m,
+	tbc=\E[3g,
+#
+# This is the only entry which you should have to customize, since "xterm"
+# is widely used for a variety of incompatible terminal emulations including
+# color_xterm and rxvt.
+xterm|X11 terminal emulator,
+	use=xterm-debian,
+#	use=xterm-xfree86,
+#	use=xterm-r6,
--- xfree86-1-3.3.6.orig/debian/xterm/ctlseqs.ms
+++ xfree86-1-3.3.6/debian/xterm/ctlseqs.ms
@@ -0,0 +1,1617 @@
+.\"#! troff -ms $1		-*- Nroff -*-
+.\" "Xterm Control Sequences" document
+.\" $XConsortium: ctlseqs.ms,v 1.16 94/12/28 20:45:48 gildea Exp $
+.\" $XFree86: xc/doc/specs/xterm/ctlseqs.ms,v 3.30 1999/10/13 04:20:46 dawes Exp $
+.\"
+.\"
+.\" Copyright 1999 by Thomas E. Dickey <dickey@herndon4.his.com>
+.\"
+.\"                         All Rights Reserved
+.\"
+.\" Permission is hereby granted, free of charge, to any person obtaining a
+.\" copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
+.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name(s) of the above copyright
+.\" holders shall not be used in advertising or otherwise to promote the
+.\" sale, use or other dealings in this Software without prior written
+.\" authorization.
+.\"
+.\"
+.\" Copyright 1991, 1994 X Consortium
+.\"
+.\" Permission is hereby granted, free of charge, to any person obtaining
+.\" a copy of this software and associated documentation files (the
+.\" "Software"), to deal in the Software without restriction, including
+.\" without limitation the rights to use, copy, modify, merge, publish,
+.\" distribute, sublicense, and/or sell copies of the Software, and to
+.\" permit persons to whom the Software is furnished to do so, subject to
+.\" the following conditions:
+.\"
+.\" The above copyright notice and this permission notice shall be
+.\" included in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of the X Consortium shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from the X Consortium.
+.\"
+.\" X Window System is a trademark of X Consortium, Inc.
+.\"
+.\" Originally written by Edward Moy, University of California,
+.\" Berkeley, edmoy@violet.berkeley.edu, for the X.V10R4 xterm.
+.\" The X Consortium staff has since updated it for X11.
+.\" Updated by Thomas Dickey <dickey@herndon4.his.com> for XFree86 3.2.
+.\"
+.\" Run this file through troff and use the -ms macro package.
+.\"
+.if n .pl 9999v		\" no page breaks in nroff
+.ND
+.de St
+.sp
+.nr PD 0
+.nr PI 1.5i
+.nr VS 16
+..
+.de Ed
+.nr PD .3v
+.nr VS 12
+..
+.ds CH \" as nothing
+.ds LH Xterm Control Sequences
+.nr s 6*\n(PS/10
+.ds L \s\nsBEL\s0
+.ds E \s\nsESC\s0
+.ds T \s\nsTAB\s0
+.ds X \s\nsETX\s0
+.ds N \s\nsENQ\s0
+.ds e \s\nsETB\s0
+.ds C \s\nsCAN\s0
+.ds S \s\nsSUB\s0
+.\" space between chars
+.ie t .ds s \|
+.el .ds s " \"
+.nr [W \w'\*L'u
+.nr w \w'\*E'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*T'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*X'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*N'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*e'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*C'u
+.if \nw>\n([W .nr [W \nw
+.nr w \w'\*S'u
+.if \nw>\n([W .nr [W \nw
+.nr [W +\w'\|\|'u
+.de []
+.nr w \w'\\$2'
+.nr H \\n([Wu-\\nwu
+.nr h \\nHu/2u
+.\" do fancy box in troff
+.ie t .ds \\$1 \(br\v'-1p'\(br\v'1p'\h'\\nhu'\\$2\h'\\nHu-\\nhu'\(br\l'-\\n([Wu\(ul'\v'-1p'\(br\l'-\\n([Wu\(rn'\v'1p'\*s
+.el .ds \\$1 \\$2\*s
+..
+.[] Et \v'-1p'\*X\v'1p'
+.[] En \v'-1p'\*N\v'1p'
+.[] Be \v'-1p'\*L\v'1p'
+.[] AP \v'-1p'\s\nsAPC\s0\v'1p'
+.[] Bs \v'-1p'\s\nsBS\s0\v'1p'
+.[] Cs \v'-1p'\s\nsCSI\s0\v'1p'
+.[] S3 \v'-1p'\s\nsSS3\s0\v'1p'
+.[] Dc \v'-1p'\s\nsDCS\s0\v'1p'
+.[] Os \v'-1p'\s\nsOSC\s0\v'1p'
+.[] PM \v'-1p'\s\nsPM\s0\v'1p'
+.[] ST \v'-1p'\s\nsST\s0\v'1p'
+.[] Ta \v'-1p'\*T\v'1p'
+.[] Lf \v'-1p'\s\nsLF\s0\v'1p'
+.[] Vt \v'-1p'\s\nsVT\s0\v'1p'
+.[] Ff \v'-1p'\s\nsFF\s0\v'1p'
+.[] Cr \v'-1p'\s\nsCR\s0\v'1p'
+.[] So \v'-1p'\s\nsSO\s0\v'1p'
+.[] Sp \v'-1p'\s\nsSP\s0\v'1p'
+.[] Si \v'-1p'\s\nsSI\s0\v'1p'
+.[] Eb \v'-1p'\*e\v'1p'
+.[] Ca \v'-1p'\*C\v'1p'
+.[] Su \v'-1p'\*S\v'1p'
+.[] Es \v'-1p'\*E\v'1p'
+.[] Fs \v'-1p'\s\nsFS\s0\v'1p'
+.[] Gs \v'-1p'\s\nsGS\s0\v'1p'
+.[] Rs \v'-1p'\s\nsRS\s0\v'1p'
+.[] Us \v'-1p'\s\nsUS\s0\v'1p'
+.[] XX \v'-1p'\s\nsXX\s0\v'1p'
+.[] $ $
+.[] ! !
+.[] # #
+.[] % %
+.[] (( (
+.[] ) )
+.[] * *
+.[] + +
+.[] 0 0
+.[] 1 1
+.[] 2 2
+.[] 3 3
+.[] 4 4
+.[] 5 5
+.[] 6 6
+.[] 7 7
+.[] 8 8
+.[] 9 9
+.[] : :
+.[] ; ;
+.[] = =
+.[] / /
+.[] < <
+.[] > >
+.[] ? ?
+.[] @ @
+.[] A A
+.[] cB B
+.[] C C
+.[] D D
+.[] E E
+.[] F F
+.[] G G
+.[] H H
+.[] I I
+.[] J J
+.[] K K
+.[] L L
+.[] M M
+.[] N N
+.[] O O
+.[] P P
+.[] Q Q
+.[] R R
+.[] S S
+.[] T T
+.[] V V
+.[] W W
+.[] XX X
+.[] Y Y
+.[] Z Z
+.[] [[ [
+.[] ]] ]
+.[] bS \\e
+.[] { {
+.[] ] ]
+.[] & &
+.[] ^ ^
+.[] _ _
+.[] qu \`
+.[] ` \`
+.[] a a
+.[] b b
+.[] c c
+.[] d d
+.[] f f
+.[] g g
+.[] h h
+.[] i i
+.[] j j
+.[] k k
+.[] l l
+.[] m m
+.[] n n
+.[] o o
+.[] p p
+.[] q q
+.[] r r
+.[] cs s
+.[] t t
+.[] u u
+.[] v v
+.[] w w
+.[] x x
+.[] y y
+.[] z z
+.[] | |
+.[] } }
+.[] ! !
+.[] c" \(lq
+.[] c~ ~
+.[] Sc \fIc\fP
+.ds Cc \fIC\fP
+.ds Cb \fIC\v'.3m'\h'-.2m'\s-2b\s0\v'-.3m'\fP
+.ds Cx \fIC\v'.3m'\h'-.2m'\s-2x\s0\v'-.3m'\fP
+.ds Cy \fIC\v'.3m'\h'-.2m'\s-2y\s0\v'-.3m'\fP
+.ds Pb \fIP\v'.3m'\h'-.2m'\s-2b\s0\v'-.3m'\fP
+.ds Pc \fIP\v'.3m'\h'-.2m'\s-2c\s0\v'-.3m'\fP
+.ds Pe \fIP\v'.3m'\h'-.2m'\s-2e\s0\v'-.3m'\fP
+.ds Pl \fIP\v'.3m'\h'-.2m'\s-2l\s0\v'-.3m'\fP
+.ds Pm \fIP\v'.3m'\h'-.2m'\s-2m\s0\v'-.3m'\fP
+.ds Pp \fIP\v'.3m'\h'-.2m'\s-2p\s0\v'-.3m'\fP
+.ds Pr \fIP\v'.3m'\h'-.2m'\s-2r\s0\v'-.3m'\fP
+.ds Ps \fIP\v'.3m'\h'-.2m'\s-2s\s0\v'-.3m'\fP
+.ds Pt \fIP\v'.3m'\h'-.2m'\s-2t\s0\v'-.3m'\fP
+.ds Pu \fIP\v'.3m'\h'-.2m'\s-2u\s0\v'-.3m'\fP
+.ds Pv \fIP\v'.3m'\h'-.2m'\s-2v\s0\v'-.3m'\fP
+.ds Ix \fIx\fP
+.ds Iy \fIy\fP
+.ds Iw \fIw\fP
+.ds Ih \fIh\fP
+.ds Ir \fIr\fP
+.ds Ic \fIc\fP
+.ie t .nr LL 6.5i
+.el .nr LL 72m
+.if n .na
+.TL
+Xterm Control Sequences
+.AU
+Edward Moy
+.AI
+University of California, Berkeley
+.sp
+Revised by
+.AU
+Stephen Gildea
+.AI
+X Consortium (1994)
+.AU
+Thomas Dickey
+.AI
+XFree86 Project (1996-1999)
+.AU
+.
+.am BT                  \" add page numbers after first page
+.ds CF %
+..
+.SH
+Definitions
+.IP \*(Sc
+The literal character \fIc\fP.
+.IP \*(Cc
+A single (required) character.
+.IP \*(Ps
+A single (usually optional) numeric parameter, composed of one of more digits.
+.IP \*(Pm
+A multiple numeric parameter composed of any number of single numeric
+parameters, separated by \*; character(s).
+.IP \*(Pt
+A text parameter composed of printable characters.
+.
+.SH
+C1 (8-Bit) Control Characters
+.ds RH C1 (8-Bit) Control Characters
+.LP
+The \fIxterm\fP program recognizes both 8-bit and 7-bit control characters.
+It generates 7-bit controls (by default) or 8-bit if S8C1T is enabled.
+The following pairs of 7-bit and 8-bit control characters are equivalent:
+.St
+.IP \\*(Es\\*D
+Index (IND: 0x84)
+.IP \\*(Es\\*E
+Next Line (NEL: 0x85)
+.IP \\*(Es\\*H
+Tab Set (HTS: 0x88)
+.IP \\*(Es\\*M
+Reverse Index (RI: 0x8d)
+.IP \\*(Es\\*N
+Single Shift Select of G2 Character Set (SS2: 0x8e): affects next character only
+.IP \\*(Es\\*O
+Single Shift Select of G3 Character Set (SS3: 0x8f): affects next character only
+.IP \\*(Es\\*P
+Device Control String (DCS: 0x90)
+.IP \\*(Es\\*V
+Start of Guarded Area (SPA: 0x96)
+.IP \\*(Es\\*W
+End of Guarded Area (EPA: 0x97)
+.IP \\*(Es\\(*X
+Start of String (SOS: 0x98)
+.IP \\*(Es\\*Z
+Return Terminal ID (DECID: 0x9a).  Obsolete form of \*(Cs\*c (DA).
+.IP \\*(Es\\*([[
+Control Sequence Introducer (CSI: 0x9b)
+.IP \\*(Es\\*(bS
+String Terminator (ST: 0x9c)
+.IP \\*(Es\\*(]]
+Operating System Command (OSC: 0x9d)
+.IP \\*(Es\\*^
+Privacy Message (PM: 0x9e)
+.IP \\*(Es\\*_
+Application Program Command (APC: 0x9f)
+.Ed
+.sp
+.LP
+These control characters are used in the vtXXX emulation.
+.
+.SH
+VT100 Mode
+.ds RH VT100 Mode
+.LP
+Most of these control sequences are standard VT102 control sequences,
+but there is support for later DEC VT terminals (i.e., VT220 and VT320),
+as well as ISO 6429 and \fIaixterm\fP color controls.
+VT102 features not supported are
+auto-repeat and blinking characters.
+There are additional control sequences to provide
+\fIxterm-\fPdependent functions, such as the scrollbar or window size.
+Where the function is specified by DEC or ISO 6429, the code assigned
+to it is given in parentheses.  The escape codes to designate and invoke
+character sets are specified by ISO 2022; see that document for a
+discussion of character sets.
+.
+.St
+.\"
+.LP
+.B
+Single-character functions
+.\"
+.IP \\*(Be
+Bell (Ctrl-G)
+.
+.IP \\*(Bs
+Backspace (Ctrl-H)
+.
+.IP \\*(Cr
+Carriage Return (Ctrl-M)
+.
+.IP \\*(En
+Return Terminal Status (Ctrl-E).
+Default response is the terminal name, e.g., "xterm", but may be overridden
+by a resource \fIanswerbackString\fP.
+.
+.IP \\*(Ff
+Form Feed or New Page (NP) (Ctrl-L) same as LF
+.
+.IP \\*(Lf
+Line Feed or New Line (NL) (Ctrl-J)
+.
+.IP \\*(So
+Shift Out (Ctrl-N) \(-> Switch to Alternate Character Set: invokes the
+G1 character set.
+.
+.IP \\*(Sp
+Space.
+.
+.IP \\*(Ta
+Horizontal Tab (HT) (Ctrl-I)
+.
+.IP \\*(Vt
+Vertical Tab (Ctrl-K) same as LF
+.
+.IP \\*(Si
+Shift In (Ctrl-O) \(-> Switch to Standard Character Set: invokes the
+G0 character set (the default).
+.Ed
+.\"
+.\"
+.\"
+.St
+.LP
+.B
+Controls beginning with ESC (other than those where ESC is part of a 7-bit equivalent to 8-bit C1 controls), ordered by the final character(s).
+.\"
+.IP \\*(Es\\*(Sp\\*F
+7-bit controls (S7C1T).
+.
+.IP \\*(Es\\*(Sp\\*G
+8-bit controls (S8C1T).
+.
+.IP \\*(Es\\*(Sp\\*L
+Set ANSI conformance level 1 (vt100, 7-bit controls).
+.
+.IP \\*(Es\\*(Sp\\*M
+Set ANSI conformance level 2 (vt200).
+.
+.IP \\*(Es\\*(Sp\\*N
+Set ANSI conformance level 3 (vt300).
+.
+.IP \\*(Es\\*#\\*3
+DEC double-height line, top half (DECDHL)
+.
+.IP \\*(Es\\*#\\*4
+DEC double-height line, bottom half (DECDHL)
+.
+.IP \\*(Es\\*#\\*5
+DEC single-width line (DECSWL)
+.
+.IP \\*(Es\\*#\\*6
+DEC double-width line (DECDWL)
+.
+.IP \\*(Es\\*#\\*8
+DEC Screen Alignment Test (DECALN)
+.
+.IP \\*(Es\\*%\\*@
+Select default character set, ISO 8859-1 (ISO 2022)
+.
+.IP \\*(Es\\*%\\*G
+Select UTF-8 character set (ISO 2022)
+.
+.IP \\*(Es\\*(((\\*(Cc
+Designate G0 Character Set (ISO 2022)
+.IP \\*(Es\\*)\\*(Cc
+Designate G1 Character Set (ISO 2022)
+.
+.IP \\*(Es\\**\\*(Cc
+Designate G2 Character Set (ISO 2022)
+.
+.IP \\*(Es\\*+\\*(Cc
+Designate G3 Character Set (ISO 2022)
+.br
+Final character \*(Cc for designating character sets
+(\*0, \*A and \*(cB apply to VT100 and up, the remainder to VT220 and up):
+  \*(Cc = \*0 \(-> DEC Special Character and Line Drawing Set
+  \*(Cc = \*A \(-> United Kingdom (UK)
+  \*(Cc = \*(cB \(-> United States (USASCII)
+  \*(Cc = \*4 \(-> Dutch
+  \*(Cc = \*C or \*5 \(-> Finnish
+  \*(Cc = \*R \(-> French
+  \*(Cc = \*Q \(-> French Canadian
+  \*(Cc = \*K \(-> German
+  \*(Cc = \*Y \(-> Italian
+  \*(Cc = \*E or \*6 \(-> Norwegian/Danish
+  \*(Cc = \*Z \(-> Spanish
+  \*(Cc = \*H or \*7 \(-> Swedish
+  \*(Cc = \*= \(-> Swiss
+.
+.IP \\*(Es\\*7
+Save Cursor (DECSC)
+.
+.IP \\*(Es\\*8
+Restore Cursor (DECRC)
+.
+.IP \\*(Es\\*=
+Application Keypad (DECPAM)
+.
+.IP \\*(Es\\*>
+Normal Keypad (DECPNM)
+.
+.IP \\*(Es\\*F
+Cursor to lower left corner of screen (if
+enabled by the \fBhpLowerleftBugCompat\fP resource).
+.
+.IP \\*(Es\\*c
+Full Reset (RIS)
+.
+.IP \\*(Es\\*l
+Memory Lock (per HP terminals).  Locks memory above the cursor.
+.
+.IP \\*(Es\\*m
+Memory Unlock (per HP terminals)
+.
+.IP \\*(Es\\*n
+Invoke the G2 Character Set (LS2)
+.
+.IP \\*(Es\\*o
+Invoke the G3 Character Set (LS3)
+.
+.IP \\*(Es\\*|
+Invoke the G3 Character Set as GR (LS3R).  Has no visible effect in \fIxterm\fP.
+.
+.IP \\*(Es\\*}
+Invoke the G2 Character Set as GR (LS2R).  Has no visible effect in \fIxterm\fP.
+.
+.IP \\*(Es\\*(c~
+Invoke the G1 Character Set as GR (LS1R).  Has no visible effect in \fIxterm\fP.
+.Ed
+.
+.St
+.LP
+.B
+Application Program-Control functions
+.IP \\*(AP\\*(Pt\\*s\\*(ST
+\fIxterm\fP implements no APC functions; \*(Pt is ignored.
+\*(Pt need not be printable characters.
+.Ed
+.
+.St
+.LP
+.B
+Device-Control functions
+.IP \\*(Dc\\*(Ps\\*;\\*(Ps\\*|\\*(Pt\\*s\\*(ST
+User-Defined Keys (DECUDK).
+The first parameter:
+  \*(Ps = \*0 \(-> Clear all UDK definitions before starting (default)
+  \*(Ps = \*1 \(-> Erase Below (default)
+.br
+The second parameter:
+  \*(Ps = \*0 \(-> Lock the keys (default)
+  \*(Ps = \*1 \(-> Do not lock.
+.br
+The third parameter is a ';'-separated list of strings denoting
+the key-code separated by a '/' from the hex-encoded key value.
+The key codes correspond to the DEC function-key codes (e.g., F6=17).
+.
+.IP \\*(Dc\\*$\\*q\\*(Pt\\*s\\*(ST
+Request Status String (DECRQSS).
+The string following the "q" is one of the following:
+  \*(c"\*q	\(-> DECSCA
+  \*(c"\*p	\(-> DECSCL
+  \*r		\(-> DECSTBM
+  \*m		\(-> SGR
+.br
+\fIxterm\fP responds with
+\*(Dc\*1\*$\*r\*(Pt\*s\*(ST
+for valid requests, replacing the \*(Pt with the corresponding \*(Cs
+string,
+or
+\*(Dc\*0\*$\*r\*(Pt\*s\*(ST
+for invalid requests.
+.Ed
+.\"
+.St
+.LP
+.B
+Functions using CSI, ordered by the final character(s)
+.IP \\*(Cs\\*(Ps\\*s\\*@
+Insert \*(Ps (Blank) Character(s) (default = 1) (ICH)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*A
+Cursor Up \*(Ps Times (default = 1) (CUU)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*(cB
+Cursor Down \*(Ps Times (default = 1) (CUD)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*C
+Cursor Forward \*(Ps Times (default = 1) (CUF)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*D
+Cursor Backward \*(Ps Times (default = 1) (CUB)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*E
+Cursor Next Line \*(Ps Times (default = 1) (CNL)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*F
+Cursor Preceding Line \*(Ps Times (default = 1) (CPL)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*G
+Cursor Character Absolute  [column] (default = [row,1]) (CHA)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*H
+Cursor Position [row;column] (default = [1,1]) (CUP)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*I
+Cursor Forward Tabulation \*(Ps tab stops (default = 1) (CHT)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*J
+Erase in Display (ED)
+  \*(Ps = \*0 \(-> Erase Below (default)
+  \*(Ps = \*1 \(-> Erase Above
+  \*(Ps = \*2 \(-> Erase All
+  \*(Ps = \*3 \(-> Erase Saved Lines (xterm)
+.
+.IP \\*(Cs\\*?\\*(Ps\\*s\\*J
+Erase in Display (DECSED)
+  \*(Ps = \*0 \(-> Selective Erase Below (default)
+  \*(Ps = \*1 \(-> Selective Erase Above
+  \*(Ps = \*2 \(-> Selective Erase All
+.
+.IP \\*(Cs\\*(Ps\\*s\\*K
+Erase in Line (EL)
+  \*(Ps = \*0 \(-> Erase to Right (default)
+  \*(Ps = \*1 \(-> Erase to Left
+  \*(Ps = \*2 \(-> Erase All
+.
+.IP \\*(Cs\\*?\\*(Ps\\*s\\*K
+Erase in Line (DECSEL)
+  \*(Ps = \*0 \(-> Selective Erase to Right (default)
+  \*(Ps = \*1 \(-> Selective Erase to Left
+  \*(Ps = \*2 \(-> Selective Erase All
+.
+.IP \\*(Cs\\*(Ps\\*s\\*L
+Insert \*(Ps Line(s) (default = 1) (IL)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*M
+Delete \*(Ps Line(s) (default = 1) (DL)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*P
+Delete \*(Ps Character(s) (default = 1) (DCH)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*S
+Scroll up \*(Ps lines (default = 1) (SU)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*T
+Scroll down \*(Ps lines (default = 1) (SD)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*;\\*(Ps\\*s\\*;\\*(Ps\\*s\\*;\\*(Ps\\*s\\*T
+Initiate hilite mouse tracking.
+Parameters are [func;startx;starty;firstrow;lastrow].
+See the section \fBMouse Tracking\fP.
+.
+.IP \\*(Cs\\*(Ps\\*s\\*(XX
+Erase \*(Ps Character(s) (default = 1) (ECH)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*Z
+Cursor Backward Tabulation \*(Ps tab stops (default = 1) (CBT)
+.
+.IP \\*(Cs\\*(Pm\\*s\\*`
+Character Position Absolute  [column] (default = [row,1]) (HPA)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*b
+Repeat the preceding graphic character \*(Ps times (REP)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*c
+Send Device Attributes (Primary DA)
+  \*(Ps = \*0, 1 or omitted \(-> request attributes from terminal.
+The response depends on the \fBdecTerminalId\fP resource setting.
+  \(-> \*(Cs\*?\*1\*;\*2\*c (``VT100 with Advanced Video Option'')
+  \(-> \*(Cs\*?\*1\*;\*0\*c (``VT101 with No Options'')
+  \(-> \*(Cs\*?\*6\*c (``VT102'')
+  \(-> \*(Cs\*?\*6\*0\*;\*1\*;\*2\*;\*6\*;\*8\*;\*9\*;\*1\*5\*;\*c (``VT220'')
+.br
+The VT100-style response parameters do not mean anything by themselves.
+VT220 parameters do, telling the host what features the terminal supports:
+  \(-> \*1 132-columns
+  \(-> \*2 Printer
+  \(-> \*6 Selective erase
+  \(-> \*8 User-defined keys
+  \(-> \*9 National replacement character sets
+  \(-> \*1\*5 Technical characters
+.
+.IP \\*(Cs\\*>\\*(Ps\\*s\\*c
+Send Device Attributes (Secondary DA)
+  \*(Ps = \*0, 1 or omitted \(-> request the terminal's identification code.
+The response depends on the \fBdecTerminalId\fP resource setting.
+It should apply only to VT220 and up, but \fIxterm\fP extends this to VT100.
+  \(-> \*(Cs\*(Pp\*s\*;\*(Pv\*s\*;\*(Pc\*s\*c
+.br
+where \*(Pc denotes the terminal type
+  \(-> \*0 (``VT100'')
+  \(-> \*1 (``VT220'')
+.br
+and \*(Pv is the firmware version (for \fIxterm\fP, this is the XFree86
+patch number, starting with 95).
+In a DEC terminal, \*(Pc indicates the ROM cartridge
+registration number and is always zero.
+.
+.IP \\*(Cs\\*(Pm\\*s\\*d
+Line Position Absolute  [row] (default = [1,column]) (VPA)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*f
+Horizontal and Vertical Position [row;column] (default = [1,1]) (HVP)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*g
+Tab Clear (TBC)
+  \*(Ps = \*0 \(-> Clear Current Column (default)
+  \*(Ps = \*3 \(-> Clear All
+.
+.IP \\*(Cs\\*(Pm\\*s\\*h
+Set Mode (SM)
+  \*(Ps = \*2 \(-> Keyboard Action Mode (AM)
+  \*(Ps = \*4 \(-> Insert Mode (IRM)
+  \*(Ps = \*1\*2 \(-> Send/receive (SRM)
+  \*(Ps = \*2\*0 \(-> Automatic Newline (LNM)
+.
+.IP \\*(Cs\\*?\\*(Pm\\*s\\*h
+DEC Private Mode Set (DECSET)
+  \*(Ps = \*1 \(-> Application Cursor Keys (DECCKM)
+  \*(Ps = \*2 \(-> Designate USASCII for character sets G0-G3 (DECANM),
+and set VT100 mode.
+  \*(Ps = \*3 \(-> 132 Column Mode (DECCOLM)
+  \*(Ps = \*4 \(-> Smooth (Slow) Scroll (DECSCLM)
+  \*(Ps = \*5 \(-> Reverse Video (DECSCNM)
+  \*(Ps = \*6 \(-> Origin Mode (DECOM)
+  \*(Ps = \*7 \(-> Wraparound Mode (DECAWM)
+  \*(Ps = \*8 \(-> Auto-repeat Keys (DECARM)
+  \*(Ps = \*9 \(-> Send Mouse X & Y on button press.
+See the section \fBMouse Tracking\fP.
+  \*(Ps = \*1\*8 \(-> Print form feed (DECPFF)
+  \*(Ps = \*1\*9 \(-> Set print extent to full screen (DECPEX)
+  \*(Ps = \*2\*5 \(-> Show Cursor (DECTCEM)
+  \*(Ps = \*3\*0 \(-> Show scrollbar (rxvt).
+  \*(Ps = \*3\*5 \(-> Enable shifted key-functions (rxvt).
+  \*(Ps = \*3\*8 \(-> Enter Tektronix Mode (DECTEK)
+  \*(Ps = \*4\*0 \(-> Allow 80 \z\(<-\(-> 132 Mode
+  \*(Ps = \*4\*1 \(-> \fImore\fP(1) fix (see \fIcurses\fP resource)
+  \*(Ps = \*4\*2 \(-> Enable Nation Replacement Character sets (DECNRCM)
+  \*(Ps = \*4\*4 \(-> Turn On Margin Bell
+  \*(Ps = \*4\*5 \(-> Reverse-wraparound Mode
+  \*(Ps = \*4\*6 \(-> Start Logging
+(normally disabled by a compile-time option)
+  \*(Ps = \*4\*7 \(-> Use Alternate Screen Buffer (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*6\*6 \(-> Application keypad (DECNKM)
+  \*(Ps = \*6\*7 \(-> Backarrow key sends delete (DECBKM)
+  \*(Ps = \*1\*0\*0\*0 \(-> Send Mouse X & Y on button press and release.
+See the section \fBMouse Tracking\fP.
+  \*(Ps = \*1\*0\*0\*1 \(-> Use Hilite Mouse Tracking.
+  \*(Ps = \*1\*0\*0\*2 \(-> Use Cell Motion Mouse Tracking.
+  \*(Ps = \*1\*0\*0\*3 \(-> Use All Motion Mouse Tracking.
+  \*(Ps = \*1\*0\*1\*0 \(-> Scroll to bottom on tty output (rxvt).
+  \*(Ps = \*1\*0\*1\*1 \(-> Scroll to bottom on key press (rxvt).
+  \*(Ps = \*1\*0\*3\*5 \(-> Enable special modifiers for Alt and NumLock keys.
+  \*(Ps = \*1\*0\*4\*7 \(-> Use Alternate Screen Buffer (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*4\*8 \(-> Save cursor as in DECSC (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*4\*9 \(-> Save cursor as in DECSC
+and use Alternate Screen Buffer, clearing it first (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*5\*1 \(-> Set Sun function-key mode.
+  \*(Ps = \*1\*0\*5\*2 \(-> Set HP function-key mode.
+  \*(Ps = \*1\*0\*6\*1 \(-> Set Sun/PC keyboard mode.
+.
+.IP \\*(Cs\\*(Pm\\*s\\*i
+Media Copy (MC)
+  \*(Ps = \*0 \(-> Print screen (default)
+  \*(Ps = \*4 \(-> Turn off printer controller mode
+  \*(Ps = \*5 \(-> Turn on printer controller mode
+.
+.IP \\*(Cs\\*?\\*(Pm\\*s\\*i
+Media Copy (MC, DEC-specific)
+  \*(Ps = \*1 \(-> Print line containing cursor
+  \*(Ps = \*4 \(-> Turn off autoprint mode
+  \*(Ps = \*5 \(-> Turn on autoprint mode
+  \*(Ps = \*1 \*0 \(-> Print composed display, ignores DECPEX
+  \*(Ps = \*1 \*1 \(-> Print all pages
+.
+.IP \\*(Cs\\*(Pm\\*s\\*l
+Reset Mode (RM)
+  \*(Ps = \*2 \(-> Keyboard Action Mode (AM)
+  \*(Ps = \*4 \(-> Replace Mode (IRM)
+  \*(Ps = \*1\*2 \(-> Send/receive (SRM)
+  \*(Ps = \*2\*0 \(-> Normal Linefeed (LNM)
+.
+.IP \\*(Cs\\*?\\*(Pm\\*s\\*l
+DEC Private Mode Reset (DECRST)
+  \*(Ps = \*1 \(-> Normal Cursor Keys (DECCKM)
+  \*(Ps = \*2 \(-> Designate VT52 mode (DECANM).
+  \*(Ps = \*3 \(-> 80 Column Mode (DECCOLM)
+  \*(Ps = \*4 \(-> Jump (Fast) Scroll (DECSCLM)
+  \*(Ps = \*5 \(-> Normal Video (DECSCNM)
+  \*(Ps = \*6 \(-> Normal Cursor Mode (DECOM)
+  \*(Ps = \*7 \(-> No Wraparound Mode (DECAWM)
+  \*(Ps = \*8 \(-> No Auto-repeat Keys (DECARM)
+  \*(Ps = \*9 \(-> Don't Send Mouse X & Y on button press
+  \*(Ps = \*1\*8 \(-> Don't print form feed (DECPFF)
+  \*(Ps = \*1\*9 \(-> Limit print to scrolling region (DECPEX)
+  \*(Ps = \*2\*5 \(-> Hide Cursor (DECTCEM)
+  \*(Ps = \*3\*0 \(-> Don't show scrollbar (rxvt).
+  \*(Ps = \*3\*5 \(-> Disable shifted key-functions (rxvt).
+  \*(Ps = \*4\*0 \(-> Disallow 80 \z\(<-\(-> 132 Mode
+  \*(Ps = \*4\*1 \(-> No \fImore\fP(1) fix (see \fIcurses\fP resource)
+  \*(Ps = \*4\*2 \(-> Disable Nation Replacement Character sets (DECNRCM)
+  \*(Ps = \*4\*4 \(-> Turn Off Margin Bell
+  \*(Ps = \*4\*5 \(-> No Reverse-wraparound Mode
+  \*(Ps = \*4\*6 \(-> Stop Logging
+(normally disabled by a compile-time option)
+  \*(Ps = \*4\*7 \(-> Use Normal Screen Buffer
+  \*(Ps = \*6\*6 \(-> Numeric keypad (DECNKM)
+  \*(Ps = \*6\*7 \(-> Backarrow key sends backspace (DECBKM)
+  \*(Ps = \*1\*0\*0\*0 \(-> Don't Send Mouse X & Y on button press and
+release.
+See the section \fBMouse Tracking\fP.
+  \*(Ps = \*1\*0\*0\*1 \(-> Don't Use Hilite Mouse Tracking
+  \*(Ps = \*1\*0\*0\*2 \(-> Don't Use Cell Motion Mouse Tracking
+  \*(Ps = \*1\*0\*0\*3 \(-> Don't Use All Motion Mouse Tracking
+  \*(Ps = \*1\*0\*1\*0 \(-> Don't scroll to bottom on tty output (rxvt).
+  \*(Ps = \*1\*0\*1\*1 \(-> Don't scroll to bottom on key press (rxvt).
+  \*(Ps = \*1\*0\*3\*5 \(-> Disable special modifiers for Alt and NumLock keys.
+  \*(Ps = \*1\*0\*4\*7 \(-> Use Normal Screen Buffer, clearing screen
+first if in the Alternate Screen (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*4\*8 \(-> Restore cursor as in DECRC (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*4\*9 \(-> Use Normal Screen Buffer and restore cursor
+as in DECRC (unless
+disabled by the \fBtiteInhibit\fP resource)
+  \*(Ps = \*1\*0\*5\*1 \(-> Reset Sun function-key mode.
+  \*(Ps = \*1\*0\*5\*2 \(-> Reset HP function-key mode.
+  \*(Ps = \*1\*0\*6\*1 \(-> Reset Sun/PC keyboard mode.
+.
+.IP \\*(Cs\\*(Pm\\*s\\*m
+Character Attributes (SGR)
+  \*(Ps = \*0 \(-> Normal (default)
+  \*(Ps = \*1 \(-> Bold
+  \*(Ps = \*4 \(-> Underlined
+  \*(Ps = \*5 \(-> Blink (appears as Bold)
+  \*(Ps = \*7 \(-> Inverse
+  \*(Ps = \*8 \(-> Invisible (hidden)
+  \*(Ps = \*2\*2 \(-> Normal (neither bold nor faint)
+  \*(Ps = \*2\*4 \(-> Not underlined
+  \*(Ps = \*2\*5 \(-> Steady (not blinking)
+  \*(Ps = \*2\*7 \(-> Positive (not inverse)
+  \*(Ps = \*2\*8 \(-> Visible (not hidden)
+  \*(Ps = \*3\*0 \(-> Set foreground color to Black
+  \*(Ps = \*3\*1 \(-> Set foreground color to Red
+  \*(Ps = \*3\*2 \(-> Set foreground color to Green
+  \*(Ps = \*3\*3 \(-> Set foreground color to Yellow
+  \*(Ps = \*3\*4 \(-> Set foreground color to Blue
+  \*(Ps = \*3\*5 \(-> Set foreground color to Magenta
+  \*(Ps = \*3\*7 \(-> Set foreground color to Cyan
+  \*(Ps = \*3\*7 \(-> Set foreground color to White
+  \*(Ps = \*3\*9 \(-> Set foreground color to default (original)
+  \*(Ps = \*4\*0 \(-> Set background color to Black
+  \*(Ps = \*4\*1 \(-> Set background color to Red
+  \*(Ps = \*4\*2 \(-> Set background color to Green
+  \*(Ps = \*4\*3 \(-> Set background color to Yellow
+  \*(Ps = \*4\*4 \(-> Set background color to Blue
+  \*(Ps = \*4\*5 \(-> Set background color to Magenta
+  \*(Ps = \*4\*6 \(-> Set background color to Cyan
+  \*(Ps = \*4\*7 \(-> Set background color to White
+  \*(Ps = \*4\*9 \(-> Set background color to default (original).
+.sp
+If 16-color support is compiled, the following apply.
+Assume that \fIxterm\fP's resources
+are set so that the ISO color codes are the first 8 of a set of 16.
+Then the \fIaixterm\fP colors are the bright versions of the ISO colors:
+  \*(Ps = \*9\*0 \(-> Set foreground color to Black
+  \*(Ps = \*9\*1 \(-> Set foreground color to Red
+  \*(Ps = \*9\*2 \(-> Set foreground color to Green
+  \*(Ps = \*9\*3 \(-> Set foreground color to Yellow
+  \*(Ps = \*9\*4 \(-> Set foreground color to Blue
+  \*(Ps = \*9\*5 \(-> Set foreground color to Magenta
+  \*(Ps = \*9\*7 \(-> Set foreground color to Cyan
+  \*(Ps = \*9\*7 \(-> Set foreground color to White
+  \*(Ps = \*1\*0\*0 \(-> Set background color to Black
+  \*(Ps = \*1\*0\*1 \(-> Set background color to Red
+  \*(Ps = \*1\*0\*2 \(-> Set background color to Green
+  \*(Ps = \*1\*0\*3 \(-> Set background color to Yellow
+  \*(Ps = \*1\*0\*4 \(-> Set background color to Blue
+  \*(Ps = \*1\*0\*5 \(-> Set background color to Magenta
+  \*(Ps = \*1\*0\*6 \(-> Set background color to Cyan
+  \*(Ps = \*1\*0\*7 \(-> Set background color to White
+.sp
+If \fIxterm\fP is compiled with the 16-color support disabled, it supports
+the following, from \fIrxvt\fP:
+  \*(Ps = \*1\*0\*0 \(-> Set foreground and background color to default
+.sp
+If 88- or 256-color support is compiled, the following apply.
+  \*(Ps = \*3\*8 ; \*5 ; \*(Ps \(-> Set background color to \*(Ps
+  \*(Ps = \*4\*8 ; \*5 ; \*(Ps \(-> Set foreground color to \*(Ps
+.sp
+.
+.IP \\*(Cs\\*(Ps\\*s\\*n
+Device Status Report (DSR)
+  \*(Ps = \*5 \(-> Status Report \*(Cs\*0\*n (``OK'')
+  \*(Ps = \*6 \(-> Report Cursor Position (CPR) [row;column] as
+.br
+\*(Cs\*(Ir\*s\*;\*(Ic\*s\*R
+.
+.IP \\*(Cs\\*?\\*(Ps\\*s\\*n
+Device Status Report (DSR, DEC-specific)
+  \*(Ps = \*6 \(-> Report Cursor Position (CPR) [row;column] as
+\*(Cs\*?\*(Ir\*s\*;\*(Ic\*s\*R
+(assumes page is zero).
+  \*(Ps = \*1\*5 \(-> Report Printer status as
+\*(Cs\*?\*1\*0\*s\*n (ready)
+or
+\*(Cs\*?\*1\*1\*s\*n (not ready)
+  \*(Ps = \*2\*5 \(-> Report UDK status as
+\*(Cs\*?\*2\*0\*s\*n (unlocked)
+or
+\*(Cs\*?\*2\*1\*s\*n (locked)
+  \*(Ps = \*2\*6 \(-> Report Keyboard status as
+.br
+\*(Cs\*?\*2\*7\*s\*;\*s\*1\*s\*;\*s\*0\*s\*;\*s\*0\*s\*n (North American)
+.br
+\*(Cs\*?\*5\*3\*s\*n Locator available, if compiled-in, or
+.br
+\*(Cs\*?\*5\*0\*s\*n No Locator, if not.
+.
+.IP \\*(Cs\\*s\\*!\\*p
+Soft terminal reset (DECSTR)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*(c"\\*p
+Set conformance level (DECSCL)
+Valid values for the first parameter:
+  \*(Ps = \*6\*1 \(-> VT100
+  \*(Ps = \*6\*2 \(-> VT200
+  \*(Ps = \*6\*3 \(-> VT300
+Valid values for the second parameter:
+  \*(Ps = \*0 \(-> 8-bit controls
+  \*(Ps = \*1 \(-> 7-bit controls (always set for VT100)
+  \*(Ps = \*2 \(-> 8-bit controls
+.
+.IP \\*(Cs\\*(Ps\\*s\\*(c"\\*q
+Select character protection attribute (DECSCA).
+Valid values for the parameter:
+  \*(Ps = \*0 \(-> DECSED and DECSEL can erase (default)
+  \*(Ps = \*1 \(-> DECSED and DECSEL cannot erase
+  \*(Ps = \*2 \(-> DECSED and DECSEL can erase
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*r
+Set Scrolling Region [top;bottom] (default = full size of window) (DECSTBM)
+.
+.IP \\*(Cs\\*?\\*(Pm\\*s\\*r
+Restore DEC Private Mode Values.  The value of \*(Ps previously saved is
+restored.  \*(Ps values are the same as for DECSET.
+.
+.IP \\*(Cs\\*?\\*(Pm\\*s\\*(cs
+Save DEC Private Mode Values.  \*(Ps values are the same as for DECSET.
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*;\\*(Ps\\*s\\*t
+Window manipulation (from \fIdtterm\fP, as well as extensions).
+Valid values for the first (and any additional parameters) are:
+  \*(Ps = \*1 \(-> De-iconify window.
+  \*(Ps = \*2 \(-> Iconify window.
+  \*(Ps = \*3 ; \fIx ; y\fP \(-> Move window to [x, y].
+  \*(Ps = \*4 ; \fIheight ; width\fP \(-> Resize the \fIxterm\fP window to height and width in pixels.
+  \*(Ps = \*5 \(-> Raise the \fIxterm\fP window to the front of the stacking order.
+  \*(Ps = \*6 \(-> Lower the \fIxterm\fP window to the bottom of the stacking order.
+  \*(Ps = \*7 \(-> Refresh the \fIxterm\fP window.
+  \*(Ps = \*8 ; \fIheight ; width\fP \(-> Resize the text area to [height;width] in characters.
+  \*(Ps = \*9 ; \*0 \(-> Restore maximized window.
+  \*(Ps = \*9 ; \*1 \(-> Maximize window (i.e., resize to screen size).
+  \*(Ps = \*1\*1 \(-> Report \fIxterm\fP window state.
+If the \fIxterm\fP window is open (non-iconified), it returns \*(Cs\*1\*t.
+If the \fIxterm\fP window is iconified, it returns \*(Cs\*2\*t.
+  \*(Ps = \*1\*3 \(-> Report \fIxterm\fP window position as
+\*(Cs\*3\*;\*(Ix\*;\*(Iy\*t
+  \*(Ps = \*1\*4 \(-> Report \fIxterm\fP window in pixels as
+\*(Cs\*s\*4\*s\*;\*s\fIheight\fP\*s\*;\*s\fIwidth\fP\*s\*t
+  \*(Ps = \*1\*8 \(-> Report the size of the text area in characters as
+\*(Cs\*s\*8\*s\*;\*s\fIheight\fP\*s\*;\*s\fIwidth\fP\*s\*t
+  \*(Ps = \*1\*9 \(-> Report the size of the screen in characters as
+\*(Cs\*s\*9\*s\*;\*s\fIheight\fP\*s\*;\*s\fIwidth\fP\*s\*t
+  \*(Ps = \*2\*0 \(-> Report \fIxterm\fP window's icon label as
+\*(Os\*s\*L\*s\fIlabel\fP\*s\*(ST
+  \*(Ps = \*2\*1 \(-> Report \fIxterm\fP window's title as
+\*(Os\*s\*l\*s\fItitle\fP\*s\*(ST
+  \*(Ps >= \*2\*4 \(-> Resize to \*(Ps lines (DECSLPP)
+.
+.IP \\*(Cs\\*(Pt\\*s\\*;\\*(Pl\\*s\\*;\\*(Pb\\*s\\*;\\*(Pr\\*s\\*(qu\\*w
+Enable Filter Rectangle (DECEFR)
+.br
+Parameters are [top;left;bottom;right].
+.br
+Defines the coordinates of a filter rectangle and activates it.
+Anytime the locator is detected outside of the filter rectangle,
+an outside rectangle event is generated and the rectangle is disabled.
+Filter rectangles are always treated as "one-shot" events.
+Any parameters that are omitted default to the current locator position.
+If all parameters are omitted, any locator motion will be reported.
+DECELR always cancels any prevous rectangle definition.
+.
+.IP \\*(Cs\\*(Ps\\*s\\*x
+Request Terminal Parameters (DECREQTPARM)
+.
+.IP \\*(Cs\\*(Ps\\*s\\*;\\*(Pu\\*s\\*(qu\\*z
+Enable Locator Reporting (DECELR)
+.br
+Valid values for the first parameter:
+  \*(Ps = \*0 \(-> Locator disabled (default)
+  \*(Ps = \*1 \(-> Locator enabled
+  \*(Ps = \*2 \(-> Locator enabled for one report, then disabled
+.br
+The second parameter specifies the coordinate unit for locator reports.
+.br
+Valid values for the second parameter:
+  \*(Pu = \*0 or omitted \(-> default to character cells
+  \*(Pu = \*1 \(-> device physical pixels
+  \*(Pu = \*2 \(-> character cells
+.
+.IP \\*(Cs\\*(Pm\\*s\\*(qu\\*{
+Select Locator Events (DECSLE)
+.br
+Valid values for the first (and any additional parameters) are:
+  \*(Ps = \*0 \(-> only respond to explicit host requests (DECRQLP)
+             (default) also cancels any filter rectangle
+  \*(Ps = \*1 \(-> report button down transitions
+  \*(Ps = \*2 \(-> do not report button down transitions
+  \*(Ps = \*3 \(-> report button up transitions
+  \*(Ps = \*4 \(-> do not report button up transitions
+.
+.IP \\*(Cs\\*(Ps\\*s\\*(qu\\*|
+Request Locator Position (DECRQLP)
+.br
+Valid values for the parameter are:
+  \*(Ps = \*0, 1 or omitted \(-> transmit a single DECLRP locator report
+.sp
+If Locator Reporting has been enabled by a DECELR, xterm will respond
+with a DECLRP Locator Report.  This report is also generated on button
+up and down events if they have been enabled with a DECSLE, or when
+the locator is detected outside of a filter rectangle, if filter rectangles
+have been enabled with a DECEFR.
+.sp
+  \(-> \*(Cs\*(Pe\*s\*;\*(Pb\*s\*;\*(Pr\*s\*;\*(Pc\*s\*;\*(Pp\*s\*&\*s\*w
+.sp
+Parameters are [event;button;row;column;page].
+.br
+Valid values for the event:
+  \*(Pe = \*0 \(-> locator unavailable - no other parameters sent
+  \*(Pe = \*1 \(-> request - xterm received a DECRQLP
+  \*(Pe = \*2 \(-> left button down
+  \*(Pe = \*3 \(-> left button up
+  \*(Pe = \*4 \(-> middle button down
+  \*(Pe = \*5 \(-> middle button up
+  \*(Pe = \*6 \(-> right button down
+  \*(Pe = \*7 \(-> right button up
+  \*(Pe = \*8 \(-> M4 button down
+  \*(Pe = \*9 \(-> M4 button up
+  \*(Pe = \*1\*0 \(-> locator outside filter rectangle
+.br
+``button'' parameter is a bitmask indicating which buttons are pressed:
+  \*(Pb = \*0 \(-> no buttons down
+  \*(Pb & \*1 \(-> right button down
+  \*(Pb & \*2 \(-> middle button down
+  \*(Pb & \*4 \(-> left button down
+  \*(Pb & \*8 \(-> M4 button down
+.br
+``row'' and ``column'' parameters are the coordinates of the locator
+position in the xterm window, encoded as ASCII decimal.
+.br
+The ``page'' parameter is not used by xterm, and will be omitted.
+.
+.Ed
+.
+.St
+.LP
+.B
+Operating System Controls
+.
+.IP \\*(Os\\*(Ps\\*s\\*;\\*(Pt\\*s\\*(ST
+.IP \\*(Os\\*(Ps\\*s\\*;\\*(Pt\\*s\\*(Be
+Set Text Parameters.
+For colors and font,
+if \*(Pt is a "?", the control sequence elicits a response which consists
+of the control sequence which would set the corresponding value.
+The \fIdtterm\fP control sequences allow you to determine the icon name
+and window title.
+  \*(Ps = \*0 \(-> Change Icon Name and Window Title to \*(Pt
+  \*(Ps = \*1 \(-> Change Icon Name to \*(Pt
+  \*(Ps = \*2 \(-> Change Window Title to \*(Pt
+  \*(Ps = \*3 \(-> Set X property on top-level window. \*(Pt should be in the form
+"\fIprop=value\fP", or just "\fIprop\fP" to delete the property
+  \*(Ps = \*4 ; \fIc ; name\fP \(-> Change Color #\fIc\fP to \fIcname\fP.  Any
+number of \fIc name\fP pairs may be given.
+  \*(Ps = \*1\*0 \(-> Change color names starting with text foreground to \*(Pt
+(a list of one or more color names or RGB specifications, separated by
+semicolon, up to eight, as per \fIXParseColor\fP).
+  \*(Ps = \*1\*1 \(-> Change colors starting with text background to \*(Pt
+  \*(Ps = \*1\*2 \(-> Change colors starting with text cursor to \*(Pt
+  \*(Ps = \*1\*3 \(-> Change colors starting with mouse foreground to \*(Pt
+  \*(Ps = \*1\*4 \(-> Change colors starting with mouse background to \*(Pt
+  \*(Ps = \*1\*5 \(-> Change colors starting with Tek foreground to \*(Pt
+  \*(Ps = \*1\*6 \(-> Change colors starting with Tek background to \*(Pt
+  \*(Ps = \*1\*7 \(-> Change colors starting with highlight to \*(Pt
+  \*(Ps = \*4\*6 \(-> Change Log File to \*(Pt (normally disabled by a
+compile-time option)
+  \*(Ps = \*5\*0 \(-> Set Font to \*(Pt
+If \*(Pt begins with a "#", index in the font menu, relative (if the
+next character is a plus or minus sign) or absolute.  A number is
+expected but not required after the sign (the default is the current
+entry for relative, zero for absolute indexing).
+.Ed
+.
+.St
+.LP
+.B
+Privacy Message
+.IP \\*(PM\\*(Pt\\*s\\*(ST
+\fIxterm\fP implements no PM functions; \*(Pt is ignored.
+\*(Pt need not be printable characters.
+.Ed
+.
+.SH
+PC-Style Function Keys
+.ds RH Function Keys
+.LP
+If \fIxterm\fP does minimal translation of the function keys, it usually does this
+with a PC-style keyboard, so PC-style function keys result.
+Sun keyboards are similar to PC keyboards.
+Both have cursor and scrolling operations printed on the keypad,
+which duplicate the smaller cursor and scrolling keypads.
+.LP
+X does not predefine NumLock (used for VT220 keyboards) or Alt (used as
+an extension for the Sun/PC keyboards) as modifiers.
+These keys are recognized as modifiers when enabled
+by the \fBnumLock\fP resource,
+or by the DECSET \*1\*0\*3\*5 control sequence.
+.LP
+The cursor keys transmit the following escape sequences depending on the
+mode specified via the \fBDECCKM\fP escape sequence.
+.TS
+center;
+cf3	cf3	cf3
+lf3w(2c)	lf3w(2c)	lf3w(2c) .
+Key	Normal	Application
+_
+Cursor Up	\*(Cs\*A	\*(S3\*A
+Cursor Down	\*(Cs\*(cB	\*(S3\*(cB
+Cursor Right	\*(Cs\*C	\*(S3\*C
+Cursor Left	\*(Cs\*D	\*(S3\*D
+.TE
+.LP
+The application keypad transmits the following escape sequences depending on the
+mode specified via the \fBDECPNM\fP and \fBDECPAM\fP escape sequences.
+Use the NumLock key to override the application mode.
+.LP
+Not all keys are present on the Sun/PC keypad (e.g., PF1, Tab), but are supported by
+the program.
+.TS
+center;
+cf3	cf3	cf3	cf3	cf3
+lf3w(2c)	lf3w(2c)	lf3w(2c)	lf3w(2c)	lf3w(2c) .
+Key	Numeric	Application	Terminfo	Termcap
+_
+Space	\*(Sp	\*(S3\*(Sp	-	-
+Tab	\*(Ta	\*(S3\*I	-	-
+Enter	\*(Cr	\*(S3\*M	kent	@8
+PF1	\*(S3\*P	\*(S3\*P	kf1	k1
+PF2	\*(S3\*Q	\*(S3\*Q	kf2	k2
+PF3	\*(S3\*R	\*(S3\*R	kf3	k3
+PF4	\*(S3\*S	\*(S3\*S	kf4	k4
+* \f1(multiply)\fP	*	\*(S3\*j	-	-
++ \f1(add)\fP	+	\*(S3\*k	-	-
+, \f1(comma)\fP	,	\*(S3\*l	-	-
+- \f1(minus)\fP	-	\*(S3\*m	-	-
+\. \f1(Delete)\fP	\.	\*(S3\*3\*(c~	-	-
+/ \f1(divide)\fP	/	\*(S3\*o	-	-
+0 \f1(Insert)\fP	0	\*(Cs\*2\*(c~	-	-
+1 \f1(End)\fP	1	\*(Cs\*4\*(c~	kc1	K4
+2 \f1(DownArrow)\fP	2	\*(Cs\*(cB	-	-
+3 \f1(PageDown)\fP	3	\*(Cs\*5\*(c~	kc3	K5
+4 \f1(LeftArrow)\fP	4	\*(Cs\*D	-	-
+5 \f1(Begin)\fP	5	\*(Cs\*E	kb2	K2
+6 \f1(RightArrow)\fP	6	\*(Cs\*C	-	-
+7 \f1(Home)\fP	7	\*(Cs\*1\*(c~	ka1	K1
+8 \f1(UpArrow)\fP	8	\*(Cs\*A	-	-
+9 \f1(PageUp)\fP	9	\*(Cs\*5\*(c~	ka3	K3
+= (equal)	\&=	\*(S3\*(XX	-	-
+.TE
+They also provide 12 function keys, as well as a few other special-purpose keys.
+.TS
+center;
+cf3	cf3
+lf3w(2c)	lf3w(2c) .
+Key	Escape Sequence
+_
+F1	\*(S3\*P
+F2	\*(S3\*Q
+F3	\*(S3\*R
+F4	\*(S3\*S
+F5	\*(Cs\*1\*5\*(c~
+F6	\*(Cs\*1\*7\*(c~
+F7	\*(Cs\*1\*8\*(c~
+F8	\*(Cs\*1\*9\*(c~
+F9	\*(Cs\*2\*0\*(c~
+F10	\*(Cs\*2\*1\*(c~
+F11	\*(Cs\*2\*3\*(c~
+F12	\*(Cs\*2\*4\*(c~
+.TE
+.LP
+Older versions of \fIxterm\fP implement different escape sequences for F1 through F4.
+These can be activated by setting the \fIoldXtermFKeys\fP resource.
+However, since they do not correspond to any hardware terminal, they have been deprecated.
+(The DEC VT220 reserves F1 through F5 for local functions such as \fBSetup\fP).
+.TS
+center;
+cf3	cf3
+lf3w(2c)	lf3w(2c) .
+Key	Escape Sequence
+_
+F1	\*(Cs\*1\*1\*(c~
+F2	\*(Cs\*1\*2\*(c~
+F3	\*(Cs\*1\*3\*(c~
+F4	\*(Cs\*1\*4\*(c~
+.TE
+In normal mode, i.e., a Sun/PC keyboard
+when the \fBsunKeyboard\fP resource is false,
+\fIxterm\fP recognizes function key modifiers
+which are parameters appended before the final character
+of the control sequence.
+.TS
+center;
+cf3	lf3
+cf3w(2c)	lf3w(2c) .
+Code	Modifiers
+_
+2	Shift
+3	Alt
+4	Shift + Alt
+5	Control
+6	Shift + Control
+7	Alt + Control
+8	Shift + Alt + Control
+.TE
+For example, shift-F5 would be sent as
+\*(Cs\*1\*5\*;\*2\*(c~
+.SH
+VT220-Style Function Keys
+.LP
+However, \fIxterm\fP is most useful as a DEC VT102 or VT220 emulator.
+Set the \fBsunKeyboard\fP resource to true to force a Sun/PC keyboard
+to act like a VT220 keyboard.
+.LP
+The VT102/VT220 application keypad transmits unique escape sequences in
+application mode, which are distinct from the cursor and scrolling keypad:
+.TS
+center;
+cf3	cf3	cf3
+lf3w(2c)	lf3w(2c)	lf3w(2c) .
+Key	Numeric	Application
+_
+Space	Space	\*(S3\*(Sp
+Tab	Tab	\*(S3\*I
+Enter	CR	\*(S3\*M
+PF1	\*(S3\*P	\*(S3\*P
+PF2	\*(S3\*Q	\*(S3\*Q
+PF3	\*(S3\*R	\*(S3\*R
+PF4	\*(S3\*S	\*(S3\*S
+* \f1(multiply)\fP	*	\*(S3\*j
++ \f1(add)\fP	+	\*(S3\*k
+, \f1(comma)\fP	,	\*(S3\*l
+- \f1(minus)\fP	-	\*(S3\*m
+\. \f1(period)\fP	\.	\*(S3\*n
+/ \f1(divide)\fP	/	\*(S3\*o
+0	0	\*(S3\*p
+1	1	\*(S3\*q
+2	2	\*(S3\*r
+3	3	\*(S3\*(cs
+4	4	\*(S3\*t
+5	5	\*(S3\*u
+6	6	\*(S3\*v
+7	7	\*(S3\*w
+8	8	\*(S3\*x
+9	9	\*(S3\*y
+= (equal)	\&=	\*(S3\*(XX
+.TE
+.LP
+The VT220 provides 8 additional function keys.
+With a Sun/PC keyboard, access these keys by Control/F1 for F13, etc.
+.TS
+center;
+cf3	cf3
+lf3w(2c)	lf3w(2c) .
+Key	Escape Sequence
+_
+F13	\*(Cs\*2\*5\*(c~
+F14	\*(Cs\*2\*6\*(c~
+F15	\*(Cs\*2\*8\*(c~
+F16	\*(Cs\*2\*9\*(c~
+F17	\*(Cs\*3\*1\*(c~
+F18	\*(Cs\*3\*2\*(c~
+F19	\*(Cs\*3\*3\*(c~
+F20	\*(Cs\*3\*4\*(c~
+.TE
+.SH
+VT52-Style Function Keys
+.LP
+A VT52 does not have function keys, but it does have a numeric keypad and cursor keys.
+They differ from the other emulations by the prefix.
+Also, the cursor keys do not change:
+.TS
+center;
+cf3	cf3
+lf3w(2c)	lf3w(2c) .
+Key	Normal/Application
+_
+Cursor Up	\*(Es\*A
+Cursor Down	\*(Es\*(cB
+Cursor Right	\*(Es\*C
+Cursor Left	\*(Es\*D
+.TE
+The keypad is similar:
+.TS
+center;
+cf3	cf3	cf3
+lf3w(2c)	lf3w(2c)	lf3w(2c) .
+Key	Numeric	Application
+_
+Space	Space	\*(Es\*?\*(Sp
+Tab	Tab	\*(Es\*?\*I
+Enter	CR	\*(Es\*?\*M
+PF1	\*(Es\*P	\*(Es\*P
+PF2	\*(Es\*Q	\*(Es\*Q
+PF3	\*(Es\*R	\*(Es\*R
+PF4	\*(Es\*S	\*(Es\*S
+* \f1(multiply)\fP	*	\*(Es\*?\*j
++ \f1(add)\fP	+	\*(Es\*?\*k
+, \f1(comma)\fP	,	\*(Es\*?\*l
+- \f1(minus)\fP	-	\*(Es\*?\*m
+\. \f1(period)\fP	\.	\*(Es\*?\*n
+/ \f1(divide)\fP	/	\*(Es\*?\*o
+0	0	\*(Es\*?\*p
+1	1	\*(Es\*?\*q
+2	2	\*(Es\*?\*r
+3	3	\*(Es\*?\*(cs
+4	4	\*(Es\*?\*t
+5	5	\*(Es\*?\*u
+6	6	\*(Es\*?\*v
+7	7	\*(Es\*?\*w
+8	8	\*(Es\*?\*x
+9	9	\*(Es\*?\*y
+= (equal)	\&=	\*(Es\*?\*(XX
+.TE
+.SH
+Sun-Style Function Keys
+.LP
+The \fIxterm\fP program provides support for Sun keyboards more directly, by
+a menu toggle that causes it to send Sun-style function key codes rather than VT220.
+Note, however, that the \fIsun\fP and \fIvt100\fP emulations are not really
+compatible.  For example, their wrap-margin behavior differs.
+.LP
+Only function keys are altered; keypad and cursor keys are the same.
+The emulation responds identically.
+See the xterm-sun terminfo entry for details.
+.SH
+HP-Style Function Keys
+.LP
+Similarly, \fIxterm\fP can be compiled to support HP keyboards.
+See the xterm-hp terminfo entry for details.
+.SH
+Mouse Tracking
+.ds RH Mouse Tracking
+.LP
+The VT widget can be set to send the mouse position and other
+information on button presses.  These modes are typically used by
+editors and other full-screen applications that want to make use of
+the mouse.
+
+There are six mutually exclusive modes.  One is DEC Locator mode, enabled by the
+DECELR \*(Cs\*(Ps\*s\*;\*(Ps\*s\*s\*'\*s\*z
+control sequence, and is not described here.  The remaining five
+modes are each enabled (or disabled) by a different parameter in
+DECSET \*(Cs\*?\*(Pm\*s\*h
+or
+DECRST \*(Cs\*?\*(Pm\*s\*l
+control sequence.
+
+Manifest constants for the parameter values
+are defined in \fBxcharmouse.h\fP as follows:
+.
+.DS
+#define SET_X10_MOUSE               9
+#define SET_VT200_MOUSE             1000
+#define SET_VT200_HIGHLIGHT_MOUSE   1001
+#define SET_BTN_EVENT_MOUSE         1002
+#define SET_ANY_EVENT_MOUSE         1003
+.DE
+.LP
+The motion reporting modes are strictly \fIxterm\fP extensions, and are not
+part of any standard, though they are analogous to the DEC VT200 DECELR
+locator reports.
+
+Parameters (such as pointer position and button number) for all mouse
+tracking escape sequences generated by \fIxterm\fP
+encode numeric parameters in a single character as
+\fIvalue\fP+32.
+For example, \*! specifies the value 1.
+The upper left character position on the terminal is denoted as 1,1.
+
+X10 compatibility mode sends an escape sequence only on button press,
+encoding the location and the mouse button pressed.
+It is enabled by specifying parameter 9 to DECSET.
+On button press, \fIxterm\fP sends
+\*(Cs\*M\*(Cb\*(Cx\*(Cy (6 characters).
+\*(Cb is button\-1.
+\*(Cx and \*(Cy are the x and y coordinates of the mouse when the
+button was pressed.
+
+Normal tracking mode sends an escape sequence on both button press and
+release.  Modifier key (shift, ctrl, meta) information is also sent.
+It is enabled by specifying parameter 1000 to DECSET.
+On button press or release, \fIxterm\fP sends
+\*(Cs\*M\*(Cb\*(Cx\*(Cy.
+The low three bits of \*(Cb encode button information:
+0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release,
+4=MB4 pressed, 5=MB5 pressed.
+The next two bits are reserved for future use, i.e., sending
+state information on the Meta and Control modifiers which are in effect
+when the button is pressed.
+.\" The upper bits encode the modifiers which were down when the button was
+.\" pressed and are added together:  4=Shift, 8=Meta, 16=Control.
+.\" Note however that the shift and control bits are normally unavailable
+.\" because \fIxterm\fP uses the control modifier with mouse for popup menus,
+.\" and the shift modifier is used in the default translations for button events.
+.\" The \fIMeta\fP modifier recognized by \fIxterm\fP is the \fImod1\fP mask,
+.\" and is not necessarily the "Meta" key (see \fIxmodmap\fP).
+\*(Cx and \*(Cy are the x and y coordinates of the mouse event, encoded as
+in X10 mode.
+
+Mouse hilite tracking notifies a program of a button press, receives a
+range of lines from the program, highlights the region covered by
+the mouse within that range until button release, and then sends the
+program the release coordinates.
+It is enabled by specifying parameter 1001 to DECSET.
+Highlighting is performed only for button 1, though other button events
+can be received.
+\fBWarning:\fP use of this mode requires a cooperating program or it will
+hang \fIxterm.\fP
+On button press, the same information as for normal tracking is
+generated; \fIxterm\fP then waits for the program to send mouse
+tracking information.
+\fIAll X events are ignored until the proper escape sequence is
+received from the pty:\fP
+\*(Cs\*(Ps\*s\*;\*(Ps\*s\*;\*(Ps\*s\*;\*(Ps\*s\*;\*(Ps\*s\*T.
+The parameters are \fIfunc, startx, starty, firstrow,\fP and \fIlastrow.\fP
+\fIfunc\fP is non-zero to initiate hilite tracking and zero to abort.
+\fIstartx\fP and \fIstarty\fP give the starting x and y location for
+the highlighted region.  The ending location tracks the mouse, but
+will never be above row \fIfirstrow\fP and will always be above row
+\fIlastrow.\fP  (The top of the screen is row 1.)
+When the button is released, \fIxterm\fP reports the ending position
+one of two ways: if the start and end coordinates are valid text
+locations: \*(Cs\*t\*(Cx\*(Cy.  If either coordinate is past
+the end of the line:
+\*(Cs\*T\*(Cx\*(Cy\*(Cx\*(Cy\*(Cx\*(Cy.
+The parameters are \fIstartx, starty, endx, endy, mousex,\fP and \fImousey.\fP
+\fIstartx, starty, endx, \fPand\fI endy\fP give the starting and
+ending character positions of the region.  \fImousex\fP and \fImousey\fP
+give the location of the mouse at button up, which may not be over a
+character.
+
+Button-event tracking is essentially the same as normal tracking, but
+\fIxterm\fP also reports button-motion events.  Motion events
+are reported only if the mouse pointer has moved to a different character
+cell.  It is enabled by specifying parameter 1002 to DECSET.
+On button press or release, \fIxterm\fP sends the same codes used by normal
+tracking mode.  On button-motion events, \fIxterm\fP adds 32 to the event code
+(the third character, \*(Cb).
+The low two bits of the event code encode the button information.
+The third bit is set to indicate motion.
+Additional bits specify modifier keys as in normal mode.
+For example, motion into cell x,y with button 1
+down is reported as \*(Cs\*M\*@\*(Cx\*(Cy.
+( \*@ = 32 + 0 (button 1) + 32 (motion indicator) ).
+Similarly, motion with button 3
+down is reported as \*(Cs\*M\*(cB\*(Cx\*(Cy.
+( \*(cB = 32 + 2 (button 3) + 32 (motion indicator) ).
+
+Any-event mode is the same as button-event mode, except that all motion
+events are reported instead of just those that enter a new character cell.
+It is enabled by specifying 1003 to DECSET.
+.
+.br
+.ds RH Tektronix 4014 Mode
+.SH
+Tektronix 4014 Mode
+.LP
+Most of these sequences are standard Tektronix 4014 control sequences.
+Graph mode supports the 12-bit addressing of the Tektronix 4014.
+The major features missing are
+the write-through and defocused modes.
+This document does not describe the commands used in the various
+Tektronix plotting modes but does describe the commands to switch modes.
+.St
+.IP \\*(Be
+Bell (Ctrl-G)
+.IP \\*(Bs
+Backspace (Ctrl-H)
+.IP \\*(Ta
+Horizontal Tab (Ctrl-I)
+.IP \\*(Lf
+Line Feed or New Line (Ctrl-J)
+.IP \\*(Vt
+Cursor up (Ctrl-K)
+.IP \\*(Ff
+Form Feed or New Page (Ctrl-L)
+.IP \\*(Cr
+Carriage Return (Ctrl-M)
+.IP \\*(Es\\*(Et
+Switch to VT100 Mode (ESC Ctrl-C)
+.IP \\*(Es\\*(En
+Return Terminal Status (ESC Ctrl-E)
+.IP \\*(Es\\*(Ff
+PAGE (Clear Screen) (ESC Ctrl-L)
+.IP \\*(Es\\*(So
+Begin 4015 APL mode (ignored by \fIxterm\fP) (ESC Ctrl-N)
+.IP \\*(Es\\*(Si
+End 4015 APL mode (ignored by \fIxterm\fP) (ESC Ctrl-O)
+.IP \\*(Es\\*(Eb
+COPY (Save Tektronix Codes to file COPYyyyy-mm-dd.hh:mm:ss) (ESC Ctrl-W)
+.IP \\*(Es\\*(Ca
+Bypass Condition (ESC Ctrl-X)
+.IP \\*(Es\\*(Su
+GIN mode (ESC Ctrl-Z)
+.IP \\*(Es\\*(Fs
+Special Point Plot Mode (ESC Ctrl-\e)
+.IP \\*(Es\\*8
+Select Large Character Set
+.IP \\*(Es\\*9
+Select #2 Character Set
+.IP \\*(Es\\*:
+Select #3 Character Set
+.IP \\*(Es\\*;
+Select Small Character Set
+.IP \\*(Os\\*(Ps\\*s\\*;\\*(Pt\\*s\\*(Be
+Set Text Parameters of VT window
+  \*(Ps = \*0 \(-> Change Icon Name and Window Title to \*(Pt
+  \*(Ps = \*1 \(-> Change Icon Name to \*(Pt
+  \*(Ps = \*2 \(-> Change Window Title to \*(Pt
+  \*(Ps = \*4\*6 \(-> Change Log File to \*(Pt (normally disabled by a
+compile-time option)
+.IP \\*(Es\\*`
+Normal Z Axis and Normal (solid) Vectors
+.IP \\*(Es\\*a
+Normal Z Axis and Dotted Line Vectors
+.IP \\*(Es\\*b
+Normal Z Axis and Dot-Dashed Vectors
+.IP \\*(Es\\*c
+Normal Z Axis and Short-Dashed Vectors
+.IP \\*(Es\\*d
+Normal Z Axis and Long-Dashed Vectors
+.IP \\*(Es\\*h
+Defocused Z Axis and Normal (solid) Vectors
+.IP \\*(Es\\*i
+Defocused Z Axis and Dotted Line Vectors
+.IP \\*(Es\\*j
+Defocused Z Axis and Dot-Dashed Vectors
+.IP \\*(Es\\*k
+Defocused Z Axis and Short-Dashed Vectors
+.IP \\*(Es\\*l
+Defocused Z Axis and Long-Dashed Vectors
+.IP \\*(Es\\*p
+Write-Thru Mode and Normal (solid) Vectors
+.IP \\*(Es\\*q
+Write-Thru Mode and Dotted Line Vectors
+.IP \\*(Es\\*r
+Write-Thru Mode and Dot-Dashed Vectors
+.IP \\*(Es\\*(cs
+Write-Thru Mode and Short-Dashed Vectors
+.IP \\*(Es\\*t
+Write-Thru Mode and Long-Dashed Vectors
+.IP \\*(Fs
+Point Plot Mode (Ctrl-\e)
+.IP \\*(Gs
+Graph Mode (Ctrl-])
+.IP \\*(Rs
+Incremental Plot Mode (Ctrl-^)
+.IP \\*(Us
+Alpha Mode (Ctrl-_)
+.Ed
+.
+.
+.br
+.ds RH VT52 Mode
+.SH
+VT52 Mode
+.LP
+Parameters for cursor movement are at the end of the \*(Es\*Y escape sequence.
+Each ordinate is encoded in a single character as \fIvalue\fP+32.
+For example, \*! is 1.
+The screen coodinate system is 0-based.
+.St
+.IP \\*(Es\\*A
+Cursor up.
+.IP \\*(Es\\*(cB
+Cursor down.
+.IP \\*(Es\\*C
+Cursor right.
+.IP \\*(Es\\*D
+Cursor left.
+.IP \\*(Es\\*F
+Enter graphics mode.
+.IP \\*(Es\\*G
+Exit graphics mode.
+.IP \\*(Es\\*H
+Move the cursor to the home position.
+.IP \\*(Es\\*I
+Reverse line feed.
+.IP \\*(Es\\*J
+Erase from the cursor to the end of the screen.
+.IP \\*(Es\\*K
+Erase from the cursor to the end of the line.
+.IP \\*(Es\\*Y\\*(Ps\\*s\\*(Ps
+Move the cursor to given row and column.
+.IP \\*(Es\\*Z
+Identify
+  \(-> \*(Es\*s\*/\*s\*Z (``I am a VT52.'')
+.IP \\*(Es\\*=
+Enter alternate keypad mode.
+.IP \\*(Es\\*>
+Exit alternate keypad mode.
+.IP \\*(Es\\*<
+Exit VT52 mode (Enter VT100 mode).
+.Ed
+.
+.if n .pl \n(nlu+1v
--- xfree86-1-3.3.6.orig/debian/xterm/termcap
+++ xfree86-1-3.3.6/debian/xterm/termcap
@@ -0,0 +1,138 @@
+# $XConsortium: termcap,v 1.13 94/10/13 21:24:32 gildea Exp $
+# $XFree86: xc/programs/xterm/termcap,v 3.9.2.6 1999/10/21 12:08:17 hohndel Exp $
+#
+# Note:
+#	termcap format is limited to 1023 characters.  This set of descriptions
+#	is a subset of the terminfo, since not all features can be fit into
+#	that limit.  The 'xterm' description supports color.  The monochrome
+#	'xtermm' drops color in favor of additional function keys.  If you need
+#	both, use terminfo.
+#
+#	The 1023-character limit applies to each entry after resolving the
+#	"tc=" strings.  Some implementations may discount all or part of the
+#	formatting characters in the entry (i.e., the backslash newline tab
+#	colon).  GNU termcap does not have this limit.
+#
+#	I checked the limits using ncurses "captoinfo -CrTv", which prints
+#	the resolved length of each entry in a comment at the end - T.Dickey
+#
+xf|xterm-xfree86|XFree86 xterm:\
+	:is=\E[!p\E[?3;4l\E[4l\E>:\
+	:rs=\E[!p\E[?3;4l\E[4l\E>:\
+	:AL=\E[%dL:DL=\E[%dM:DC=\E[%dP:DO=\E[%dB:UP=\E[%dA:\
+	:LE=\E[%dD:RI=\E[%dC:\
+	:al=\E[L:am:bl=^G:\
+	:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:co#80:\
+	:cs=\E[%i%d;%dr:ct=\E[3g:\
+	:dc=\E[P:dl=\E[M:ho=\E[H:\
+	:im=\E[4h:ei=\E[4l:mi:\
+	:ks=\E[?1h\E=:ke=\E[?1l\E>:\
+	:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\
+	:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:\
+	:k;=\E[21~:F1=\E[23~:F2=\E[24~:\
+	:kn#12:\
+	:kH=\E[4~::@7=\E[4~:kh=\E[1~:\
+	:@0=\E[1~:kI=\E[2~:kD=^?:\
+	:*6=\E[4~:kP=\E[5~:kN=\E[6~:\
+	:km:\
+	:kb=^H:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:\
+	:li#24:md=\E[1m:me=\E[m^O:mr=\E[7m:ms:nd=\E[C:\
+	:eA=\E)0:as=^N:ae=^O:ml=\El:mu=\Em:\
+	:sc=\E7:rc=\E8:sf=\n:so=\E[7m:se=\E[27m:sr=\EM:st=\EH:\
+	:ti=\E7\E[?47h:te=\E[2J\E[?47l\E8:\
+	:vi=\E[?25l:ve=\E[?25h:\
+	:up=\E[A:us=\E[4m:ue=\E[24m:xn:\
+	:ut:Co#8:op=\E[39;49m:AB=\E[4%dm:AF=\E[3%dm:\
+	:pa#64:Sf=\E[3%dm:Sb=\E[4%dm:
+# xterm-debian is identical to xterm-xfree86 except that it more strictly
+# conforms to DEC VT220 behavior in the case of the backspace and delete
+# keys; this is mandated by the keyboard configuration section of the
+# Debian Policy Manual.  Also see <http://vt100.net/docs/vt220-rm/>.
+xd|xterm-debian|Debian xterm (VT220-conformant backspace and delete):\
+	:kb=^?:kD=\E3~:\
+	:tc=xterm-xfree86:
+v1|xterm-24|xterms|vs100|24x80 xterm:\
+	:li#24:\
+	:tc=xterm:
+v2|xterm-65|65x80 xterm:\
+	:li#65:tc=xterm:
+vb|xterm-bold|xterm with bold for underline:\
+	:us=\E[1m:tc=xterm:
+vb|xterm-boldso|xterm with bold for standout:\
+	:se=\E[m:so=\E[1m:tc=xterm:
+vm|xtermm|monochrome xterm:\
+	:F1=\E[23~:F2=\E[24~:F3=\E[25~:F4=\E[26~:F5=\E[28~:\
+	:F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:\
+	:kn#20:\
+	:st@:ut@:Co@:NC@:op@:AB@:AF@:pa@:Sf@:Sb@:tc=xterm:
+#
+# This should work for the commonly used "color xterm" variations (XFree86
+# xterm, color_xterm, nxterm, rxvt).  You may have trouble with this using
+# conventional termcap because ncurses reports it is longer than 1023
+# characters.  That is because resolving it adds the alternate character-set
+# (you can suppress it with "ac@").
+vc|xterm-color|generic "ANSI" color xterm:\
+	:Co#8:NC@:pa#64:op=\E[m:AB=\E[4%dm:AF=\E[3%dm:tc=xterm-r6:
+vt|xterm-vt220|xterm emulating vt220:\
+	:tc=xterm-xfree86:
+#
+# vi may work better with this entry, because vi doesn't use insert mode much.
+# |xterm-ic|xterm-vi|xterm with insert character instead of insert mode:\
+vi|xterm-ic|xterm-vi|xterm with insert char:\
+	:im@:ei@:mi@:ic=\E[@:IC=\E[%d@:tc=xterm:
+#
+# Compatible with the R6 xterm
+r6|xterm-r6|xterm-old|X11R6 xterm:\
+	:is=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>:\
+	:rs=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>:\
+	:AL=\E[%dL:DL=\E[%dM:DC=\E[%dP:DO=\E[%dB:UP=\E[%dA:\
+	:LE=\E[%dD:RI=\E[%dC:\
+	:al=\E[L:am:bl=^G:\
+	:bs:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:co#80:\
+	:cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:ho=\E[H:\
+	:im=\E[4h:ei=\E[4l:mi:\
+	:ks=\E[?1h\E=:ke=\E[?1l\E>:\
+	:@7=\E[4~:kh=\E[1~:\
+	:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\
+	:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:\
+	:k;=\E[21~:\
+	:F1=\E[23~:F2=\E[24~:F3=\E[25~:F4=\E[26~:F5=\E[28~:\
+	:F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:\
+	:kn#20:\
+	:@0=\E[1~:kI=\E[2~:kD=\E[3~:\
+	:*6=\E[4~:kP=\E[5~:kN=\E[6~:\
+	:km:\
+	:kb=^H:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:\
+	:li#24:md=\E[1m:me=\E[m:mr=\E[7m:ms:nd=\E[C:pt:\
+	:eA=\E)0:as=^N:ae=^O:\
+	:ml=\El:mu=\Em:\
+	:sc=\E7:rc=\E8:sf=\n:so=\E[7m:se=\E[m:sr=\EM:\
+	:ti=\E7\E[?47h:te=\E[2J\E[?47l\E8:\
+	:up=\E[A:us=\E[4m:ue=\E[m:xn:
+#
+# Compatible with the R5 xterm
+r5|xterm-r5|X11R5 xterm X11R5:\
+	:AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:UP=\E[%dA:\
+	:al=\E[L:am:\
+	:bs:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:co#80:\
+	:cs=\E[%i%d;%dr:ct=\E[3g:\
+	:dc=\E[P:dl=\E[M:\
+	:im=\E[4h:ei=\E[4l:mi:\
+	:ho=\E[H:\
+	:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l\E[4l:\
+	:rs=\E>\E[?1;3;4;5;6l\E[4l\E[?7h\E[m\E[r\E[2J\E[H:\
+	:k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:kb=^H:kd=\EOB:ke=\E[?1l\E>:\
+	:kl=\EOD:km:kn#4:kr=\EOC:ks=\E[?1h\E=:ku=\EOA:\
+	:@7=\E[4~:kh=\E[1~:\
+	:li#24:md=\E[1m:me=\E[m:mr=\E[7m:ms:nd=\E[C:pt:\
+	:sc=\E7:rc=\E8:sf=\n:so=\E[7m:se=\E[m:sr=\EM:\
+	:te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:\
+	:up=\E[A:us=\E[4m:ue=\E[m:xn:
+#
+# This is the only entry which you should have to customize, since "xterm"
+# is widely used for a variety of incompatible terminal emulations including
+# color_xterm and rxvt.
+v0|xterm|X11 terminal emulator:\
+	:tc=xterm-debian:
+#	:tc=xterm-xfree86:
+#	:tc=xterm-r6:
--- xfree86-1-3.3.6.orig/debian/xterm/xresources
+++ xfree86-1-3.3.6/debian/xterm/xresources
@@ -0,0 +1,19 @@
+! /etc/X11/Xresources/xterm
+
+! Uncomment the following lines to make xterm appear much like a virtual
+! console, so that ANSI colors will make more sense.
+! XTerm*background: black
+! XTerm*foreground: gray90
+
+! DEC VT series terminal emulators (like xterm) must generate VT220-compliant
+! sequences for the backspace and delete keys per the Debian Policy Manual;
+! this provides compatibility with the Linux console.  Also, work around an
+! apparent bug in the default translations for the home and end keys in
+! xterm.  Note that this resource specification affects all programs with a
+! "vt100" widget in their resource class hierarchy, and that these
+! translation overrides do not apply if one of the listed modifier keys is
+! pressed (e.g., what shift-backspace does depends on the program in question).
+*VT100.Translations: #override ~Shift ~Ctrl ~Meta <Key>BackSpace: string("\177")\n\
+                               ~Shift ~Ctrl ~Meta <Key>Delete: string("\033[3~")\n\
+                               ~Shift ~Ctrl ~Meta <Key>Home: string("\033[1~")\n\
+                               ~Shift ~Ctrl ~Meta <Key>End: string("\033[4~")
--- xfree86-1-3.3.6.orig/debian/xterm/prerm
+++ xfree86-1-3.3.6/debian/xterm/prerm
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Debian xterm package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xterm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if command -v install-docs > /dev/null 2>&1; then
+  install-docs -r xterm-faq
+fi
+
+if [ -L /usr/doc/xterm ]; then
+  rm /usr/doc/xterm
+fi
+
+update-alternatives --remove x-terminal-emulator /usr/bin/X11/xterm
+
+exit
--- xfree86-1-3.3.6.orig/debian/xterm/postinst
+++ xfree86-1-3.3.6/debian/xterm/postinst
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Debian xterm package post-installation script
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xterm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xterm -a -d /usr/share/doc/xterm ]; then
+  ln -sf ../share/doc/xterm /usr/doc/xterm
+fi
+
+# if utmp group exists, use it
+if cut -d: -f1 < /etc/group | grep -qs utmp; then
+  XTERM_MODE=2755
+  XTERM_GROUP=utmp
+else
+  XTERM_MODE=4755
+  XTERM_GROUP=root
+fi
+
+if command -v suidregister > /dev/null 2>&1; then
+  suidregister -s xterm /usr/X11R6/bin/xterm root $XTERM_GROUP $XTERM_MODE
+else
+  chown root.$XTERM_GROUP /usr/X11R6/bin/xterm
+  chmod $XTERM_MODE /usr/X11R6/bin/xterm
+fi
+
+if command -v install-docs > /dev/null 2>&1; then
+  install-docs -i /usr/share/doc-base/xterm-faq
+fi
+
+if command -v update-menus > /dev/null 2>&1; then
+  update-menus
+fi
+
+update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/X11/xterm 20 \
+ --slave /usr/share/man/man1/x-terminal-emulator.1.gz x-terminal-emulator.1.gz /usr/X11R6/man/man1/xterm.1x.gz
+
+exit
--- xfree86-1-3.3.6.orig/debian/libc5.Xt-Imakefile.diff
+++ xfree86-1-3.3.6/debian/libc5.Xt-Imakefile.diff
@@ -0,0 +1,16 @@
+--- xc/lib/Xt/Imakefile.orig	Fri Nov  6 14:54:31 1998
++++ xc/lib/Xt/Imakefile	Sun Jan  9 15:25:50 2000
+@@ -150,11 +150,6 @@
+ 	Vendor.c \
+ 	sharedlib.c
+ 
+-#ifdef i386Architecture
+-XCOMM horrible kludge to work around egcs problem that makes Motif applications (like Netscape) crash - some parts of libXt must be compiled with "gcc-2.7.2 -O2" for them to work
+-Callback.o Destroy.o: CC=gcc272
+-#endif
+-
+ OBJS = \
+ 	$(MISCOBJS) \
+ 	ActionHook.o \
+
+
--- xfree86-1-3.3.6.orig/debian/create-arch-xsm
+++ xfree86-1-3.3.6/debian/create-arch-xsm
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xsm
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xsm \
+         $temp/etc/X11/xsm \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11/app-defaults \
+         $temp/usr/X11R6/lib/X11/xsm \
+         $temp/usr/X11R6/man/man1
+
+ln -s /etc/X11/xsm/system.xsm $temp/usr/X11R6/lib/X11/xsm/system.xsm
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xsm/
+cp debian/changelog $temp/usr/share/doc/xsm/changelog.Debian
+gzip -9 $temp/usr/share/doc/xsm/changelog.Debian
+
+# executables
+cp $tree/usr/X11R6/bin/smproxy \
+   $tree/usr/X11R6/bin/xsm \
+   $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/*
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/smproxy.1x \
+   $tree/usr/X11R6/man/man1/xsm.1x \
+   $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/*
+
+# library files
+cp $tree/usr/X11R6/lib/X11/app-defaults/XSm $temp/usr/X11R6/lib/X11/app-defaults
+
+# configuration files
+cp $tree/usr/X11R6/lib/X11/xsm/system.xsm $temp/etc/X11/xsm/system.xsm
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xsm/$FILE ]; then
+    cp debian/xsm/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxsm $temp/usr/X11R6/bin/smproxy \
+                                     $temp/usr/X11R6/bin/xsm
+dpkg-gencontrol -isp -P$temp -pxsm
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/create-arch-xdm
+++ xfree86-1-3.3.6/debian/create-arch-xdm
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xdm
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xdm \
+         $temp/etc/X11/xdm \
+         $temp/etc/init.d \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11/app-defaults \
+         $temp/usr/X11R6/lib/X11/xdm \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/X11R6/man/man5 \
+         $temp/var/log \
+         $temp/var/run \
+         $temp/var/lib/xdm
+
+ln -s /etc/X11/xdm/xdm-config $temp/usr/X11R6/lib/X11/xdm/xdm-config
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xdm/
+cp debian/changelog $temp/usr/share/doc/xdm/changelog.Debian
+gzip -9 $temp/usr/share/doc/xdm/changelog.Debian
+cp debian/xdm/README.Debian $temp/usr/share/doc/xdm/
+
+# executables
+cp $tree/usr/X11R6/bin/xdm $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/xdm
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/xdm.1x $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/*
+cp debian/xdm/xdm.options.5 $temp/usr/X11R6/man/man5/
+gzip -9 $temp/usr/X11R6/man/man5/*
+
+# library files
+cp $tree/usr/X11R6/lib/X11/xdm/chooser $temp/usr/X11R6/lib/X11/xdm
+cp $tree/usr/X11R6/lib/X11/app-defaults/Chooser $temp/usr/X11R6/lib/X11/app-defaults/
+if [ -f $tree/usr/X11R6/lib/X11/xdm/libXdmGreet.so ]; then
+    cp -a $tree/usr/X11R6/lib/X11/xdm/libXdmGreet.so.1.0 $temp/usr/X11R6/lib/X11/xdm/
+    strip --strip-unneeded $temp/usr/X11R6/lib/X11/xdm/libXdmGreet.so.1.0
+    ln -s libXdmGreet.so.1.0 $temp/usr/X11R6/lib/X11/xdm/libXdmGreet.so.1
+    ln -s libXdmGreet.so.1.0 $temp/usr/X11R6/lib/X11/xdm/libXdmGreet.so
+fi
+
+# configuration files
+cp debian/xdm/xdm.options $temp/etc/X11/xdm/
+cp debian/xdm/xdm-config $temp/etc/X11/xdm/
+cp debian/xdm/Xresources $temp/etc/X11/xdm/
+cp debian/xdm/Xresources_0 $temp/etc/X11/xdm/
+cp debian/xdm/Xaccess $temp/etc/X11/xdm/
+cp debian/xdm/Xservers $temp/etc/X11/xdm/
+cp debian/xdm/Xsetup $temp/etc/X11/xdm/
+cp debian/xdm/Xsetup_0 $temp/etc/X11/xdm/
+cp debian/xdm/Xstartup $temp/etc/X11/xdm/
+cp debian/xdm/Xstartup_0 $temp/etc/X11/xdm/
+cp debian/xdm/Xreset $temp/etc/X11/xdm/
+cp debian/xdm/Xreset_0 $temp/etc/X11/xdm/
+cp debian/xdm/init $temp/etc/init.d/xdm
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xdm/$FILE ]; then
+    cp debian/xdm/$FILE $temp/DEBIAN/
+  fi
+done
+
+dpkg-shlibdeps -pxdm $temp/usr/X11R6/bin/xdm $temp/usr/X11R6/lib/X11/xdm/chooser
+dpkg-gencontrol -isp -P$temp -pxdm
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/control
+++ xfree86-1-3.3.6/debian/control
@@ -0,0 +1,660 @@
+Source: xfree86-1
+Section: x11
+Priority: optional
+Maintainer: Branden Robinson <branden@debian.org>
+Standards-Version: 3.1.1
+Build-Depends: flex, bison, zlib1g-dev, libncurses5-dev, lynx | lynx-ssl, gcc272 [i386], altgcc [i386 m68k], libc5-altdev [i386 m68k], tcl8.2-dev [alpha i386], tk8.2-dev [alpha i386], sharutils [sparc]
+
+Package: rstart
+Architecture: all
+Depends: ssh | rsh-client
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: remote application start client
+ rstart is an implementation of a remote application start client based on
+ rsh.
+
+Package: rstartd
+Architecture: any
+Depends: ssh | rsh-server, ${rstartd:Depends}
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: remote application start daemon
+ rstartd is an implementation of a remote applications start daemon based on
+ rsh.
+
+Package: twm
+Architecture: any
+Depends: ${twm:Depends}, menu (>> 1.5)
+Replaces: xbase (<< 3.3.2.3a-2)
+Provides: x-window-manager
+Description: Tab window manager
+ twm is a window manager for the X Window System.  It provides title bars,
+ shaped windows, several forms of icon management, user-defined macro
+ functions, click-to-type and pointer-driven keyboard focus, and
+ user-specified key and pointer button bindings.
+
+Package: xbase
+Architecture: all
+Priority: extra
+Depends: rstart, rstartd, twm, xbase-clients, xdm, xfree86-common, xfs, xlib6g (>= 3.3.2.3a-11), xlib6g-dev (>= 3.3.2.3a-11), xmh, xproxy, xserver-common, xsm, xterm
+Description: XFree86 upgrade convenience package
+ Between Debian 2.0 ("hamm") and 2.1 ("slink") the XFree86 packages were
+ extensively reorganized; this package exists solely to smooth the transition
+ for people upgrading from Debian 2.0 or earlier.  Those whose have fresh
+ installations of Debian 2.1 or later have no need of this package.
+ .
+ Once this package has been installed it may be removed at any time; it
+ contains no programs, libraries, or documentation.
+ .
+ For the technically curious, this package exists solely to declare
+ dependencies on the packages among whom the old xbase package's files were
+ distributed.  The new packages are auto-selected by apt or dselect as a
+ result, and the X Window System is properly upgraded.
+ .
+ Additionally, the X font and static library packages have been renamed.  For
+ more information see the /usr/doc/xbase/README.Debian file in this package or
+ /usr/doc/xfree86-common/README.Debian-upgrade in the xfree86-common package.
+
+Package: xbase-clients
+Architecture: any
+Depends: cpp, ${xbase-clients:Depends}
+Conflicts: xbase (<< 3.3.2.3a-2), xserver-common (<< 3.3.2.3a-9), xmodmap, xaw-wrappers (<< 0.90), xfonts-100dpi (<< 3.3.3.1-3), xfonts-75dpi (<< 3.3.3.1-3), xfonts-base (<< 3.3.3.1-3), xfonts-cyrillic (<< 3.3.3.1-3), xfonts-scalable (<< 3.3.3.1-3), xfnt100 (<= 3.3.2.3a-1), xfnt75 (<= 3.3.2.3a-1), xfntbase (<= 3.3.2.3a-1), xfntcyr (<= 3.3.2.3a-1), xfntscl (<= 3.3.2.3a-1)
+Replaces: xbase (<< 3.3.2.3a-2), xserver-common (<< 3.3.2.3a-9), xf86setup (<< 3.3.2.3a-9), xmodmap
+Provides: xmodmap
+Description: miscellaneous X clients
+ An X client is a program that uses the X libraries to interface with an X
+ server, and thus with some input and output hardware like a graphics card,
+ monitor, keyboard, and pointing device (such as a mouse).
+ .
+ This package provides a miscellaneous assortment of X clients that ship with
+ the X Window System, including:
+  * xinit and startx, the programs that start an X session on demand from the
+    command line;
+  * a bitmap editor and conversion utilities;
+  * utilities for font display and format conversion;
+  * beforelight, a rudimentary screensaver;
+  * X resource display and editing utilities;
+  * X server testing and performance evaluation programs;
+  * graphical clocks (xclock and oclock);
+  * X session access control programs;
+  * tools for use with the XKEYBOARD (XKB) extension;
+  * xmodmap, a tool for remapping keys and pointer buttons;
+  * xvidtune, a video mode tuner for XFree86 X servers;
+  * a screen/window capture program, xwd (and viewer for the captures, xwud);
+ and several other programs of general utility in the X Window System.
+ .
+ xbase-clients depends on cpp because xrdb requires it; the conflicts,
+ replaces, and provides are due to package reorganizations and to ensure
+ up-to-date support mechanisms for xaw-wrappers and X font packages.
+
+Package: xdm
+Architecture: any
+Depends: xbase-clients, cpp, ${xdm:Depends}
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: X display manager
+ xdm manages a collection of X servers, which may be on the local host or
+ remote machines.  It provides services similar to those provided by init,
+ getty, and login on character-based terminals; prompting for login name and
+ password, authenticating the user, and running a session.  xdm supports XDMCP
+ (X Display Manager Control Protocol) and can also be used to run a chooser
+ process which presents the user with a menu of possible hosts that offer
+ XDMCP display management.
+
+Package: xext
+Architecture: any
+Depends: ${xext:Depends}, xserver
+Suggests: joystick, xfonts-pex
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: extensions to X servers
+ xext provides extensions to X servers.  This presently includes a system for
+ 3D rendering under X called PEX (the PHIGS/PHIGS-PLUS Extension to X, in
+ which PHIGS stands for Programmer's Hierarchical Interactive Graphics
+ System), XIE (X Image Extension), and XInput, which can manage the
+ following input devices:
+   * joystick (PC gameport type)
+   * Elographics touchscreen
+   * MicroTouch touchscreens (using stylus or finger)
+   * mouse
+   * Wacom eraser
+   * Wacom cursor
+   * SummaSketch tablet
+   * AceCad tablet
+   * CalComp DrawingBoard tablet
+   * SWITCH virtual device
+   * SGI button box
+ .
+ If you intend to use the joystick extension (and the joycal joystick
+ calibration program), and are using a Linux kernel version prior to 2.2, you
+ will need the joystick kernel module package.  The joystick extension is not
+ available in the m68k version of this package.
+
+Package: xf86setup
+Architecture: alpha i386
+Depends: xbase-clients, xfonts-100dpi | xfonts-75dpi, xfonts-base, xserver-common, xserver-vga16 | xserver, ${xf86setup:Depends}
+Replaces: xserver-vga16 (<< 3.3.2.3a-2), xbase (<< 3.3.2.3a-2)
+Description: X server configuration tools
+ xf86setup contains two X clients used to configure XFree86 X servers.
+ .
+ XF86Setup itself is used to either perform the initial setup of the servers
+ or to make adjustments to the existing configuration; when invoked from the
+ console to initially configure the XFree86 servers, it will start the VGA16
+ server and then allow configuration settings to be entered.  When run from
+ within an already running server environment (e.g. from an xterm window),
+ XF86Setup can be used to make adjustments to the current server
+ configuration.
+ .
+ Again, if you wish to use the XF86Setup program to perform initial
+ configuration of the X server (i.e., you do not have a working XF86Config
+ file), you MUST have the xserver-vga16 package installed.
+ .
+ xf86setup also contains a graphical mouse configuration utility, xmseconfig.
+ .
+ Note to Alpha users: The XF86Setup program has no awareness of TGA
+ hardware and cannot be used to configure the TGA server.  Because the VGA16
+ server does not work on the Alpha, XF86Setup can only be used to adjust an
+ existing X server configuration on that architecture.
+
+Package: xfree86-common
+Architecture: all
+Priority: standard
+Depends: debianutils (>= 1.6)
+Suggests: twm | x-window-manager, xbase-clients, xdm, xf86setup, xfonts-100dpi | xfonts-75dpi, xfonts-base, xfonts-scalable, xlib6g, xlib6g-dev, xserver-common, xserver-vga16 | xserver, xterm | x-terminal-emulator
+Replaces: xbase (<< 3.3.2.3a-9), xlib6g-dev (<< 3.3.2.3a-2), xmanpages (<< 3.3.4), xstd
+Description: X Window System (XFree86) infrastructure
+ xfree86-common contains the filesystem infrastructure required for further
+ installation of the X Window System in any configuration.
+ .
+ Those wishing an X server only (with remote font services and clients) will
+ also require the xserver-common package and an X server package.
+ .
+ The counterpart to the above configuration is a machine with the X libraries
+ (the xlib6g package), xbase-clients, a window manager, some X font packages,
+ and likely many more client packages.
+ .
+ Those who desire a standalone X workstation (and/or are fuzzy on the concepts
+ of X servers and X clients) will require both of the above sets of packages.
+ A recommended minimal list of packages for such a configuration is:
+ xbase-clients, xf86setup, xfonts-100dpi or xfonts-75dpi, xfonts-base,
+ xfonts-scalable, xlib6g, xserver-common, an xserver (several are available,
+ and which you use is largely dependent on your graphics hardware), a window
+ manager (several are available, and which you use is largely a matter of
+ preference), and a terminal emulator X client package (again, several are
+ available and which you use is your decision).
+ .
+ A number of terms are used to refer to the X Window System, including "X", "X
+ Version 11", "X11", "X11R6", and "X11R6.3".  The version of X used in Debian
+ is derived from the version released by the XFree86 Project, Inc., and is
+ thus often also referred to as "XFree86".  All of the preceding quoted terms
+ are functionally interchangeable in a Debian system.
+ .
+ Still confused?  Install this package and then read the files in
+ /usr/doc/xfree86-common/ for assistance.
+
+Package: xfs
+Architecture: any
+Depends: ${xfs:Depends}
+Suggests: xfonts-100dpi | xfonts-75dpi, xfonts-base, xfonts-scalable
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: X font server
+ xfs is a daemon that listens on a network port and serves X fonts to X
+ servers (and thus to X clients).  All X servers have the ability to serve
+ locally installed fonts for themselves, but xfs makes it possible to offload
+ that job from the X server, and/or have a central repository of fonts on a
+ networked machine running xfs so that all the machines running X servers on a
+ network do not require their own set of fonts.  xfs may also be invoked by
+ users to, for instance, make available X fonts in user accounts that are not
+ available to the X server or to an already running system xfs.
+
+Package: xlib6
+Architecture: i386 m68k
+Section: oldlibs
+Depends: xlib6g (>= 3.3.2.3a-8), ${xlib6:Depends}
+Replaces: xbase (<< 3.3.2.3a-2), elf-x11r6lib, xlib
+Conflicts: elf-x11r6lib, xlib
+Description: shared libraries required by libc5 X clients
+ The X libraries are the interface between X client programs and the
+ hardware-oriented X servers, and consist of routines to read input from the
+ keyboard and pointer, draw on the screen, etc., in an abstract manner that is
+ independent of the particular characteristics of the hardware.  The X
+ libraries communicate with X servers by means of the X protocol.  Xlib itself
+ provides the low-level functionality; Xt, the X Toolkit Instrinsics, is often
+ used as a foundation for widget libraries such as Lesstif or Athena.  Xaw,
+ the Athena widget set, provides a rudimentary set of graphical user-interface
+ elements (buttons, scrollbars, text boxes, etc.).  Several more libraries are
+ provided to implement the functions of various X extensions.
+ .
+ X clients compiled against libc5 require that the X libraries be compiled
+ against libc5 as well.  xlib6 provides such backward compatibility.
+
+Package: xlib6-altdev
+Architecture: i386 m68k
+Section: oldlibs
+Depends: xlib6 (>= 3.3.2.3a-8), libc5-altdev
+Suggests: xmanpages
+Description: include files and libraries for libc5 X client development
+ xlib6-altdev provides the standard set of include files for X and some
+ non-shared libraries (with debugging symbols) required for X client
+ development.  You only need to install it if you intend to compile X clients
+ against libc5 yourself.
+ .
+ This package only provides statically linked libraries that have no shared
+ object version in xlib6.
+ .
+ This package does not include the manual pages for the functions in the X
+ libraries; for those, install the xmanpages package.
+
+Package: xlib6g
+Architecture: any
+Priority: standard
+Depends: xfree86-common, ${xlib6g:Depends}
+Conflicts: xlib, xlib6 (<< 3.3.2.3a-8), xlib6g-dev (<< 3.3.2.3a-2)
+Replaces: xlib, xbase (<< 3.3.2.3a-2), xlib6 (<< 3.3.2.3a-8), xlib6g-dev (<< 3.3.2.3a-2)
+Description: shared libraries required by X clients
+ The X libraries are the interface between X client programs and the
+ hardware-oriented X servers, and consist of routines to read input from the
+ keyboard and pointer, draw on the screen, etc., in an abstract manner that is
+ independent of the particular characteristics of the hardware.  The X
+ libraries communicate with X servers by means of the X protocol.  Xlib itself
+ provides the low-level functionality; Xt, the X Toolkit Intrinsics, is often
+ used as a foundation for widget libraries such as Lesstif or Athena.  Xaw,
+ the Athena widget set, provides a rudimentary set of graphical user-interface
+ elements (buttons, scrollbars, text boxes, etc.).  Several more libraries are
+ provided to implement the functions of various X extensions.
+ .
+ xlib6g also contains the XKB specification files, locale data, and the bitmap
+ image files that ship with X11R6.3.
+
+Package: xlib6g-dev
+Architecture: any
+Depends: xlib6g (>= 3.3.2.3a-8), libc6-dev, cpp
+Suggests: xmanpages
+Conflicts: xdevel
+Replaces: xbase (<< 3.3.2.3a-2), xdevel
+Description: include files and libraries for X client development
+ xlib6g-dev provides the standard set of include files for X, and some static
+ libraries (with debugging symbols) required for X client development.  You
+ only need to install it if you intend to compile X clients yourself.
+ .
+ This package only provides statically linked libraries that have no shared
+ object version in xlib6g.  For statically linked versions of the libraries in
+ the xlib6g package, see the xlib6g-static package.
+ .
+ This package does not include the manual pages for the functions in the X
+ libraries; for those, install the xmanpages package.
+
+Package: xlib6g-static
+Architecture: any
+Depends: xlib6g, xlib6g-dev
+Conflicts: xslibg
+Replaces: xslibg
+Description: statically linked versions of the libraries in xlib6g
+ You only need to install this package if you intend to compile statically
+ linked X clients.  Static libraries with no shared version are in the
+ xlib6g-dev package.  The libraries in this package include debugging symbols.
+
+Package: xmh
+Architecture: any
+Section: mail
+Priority: extra
+Depends: nmh | mh, ${xmh:Depends}
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: X interface to MH mail system
+ xmh provides a graphical user interface to the MH (Message Handler) mail
+ system.  xmh is a very old X client and is not exactly a "living" piece of
+ software.  MH users will probably prefer the exmh package, which serves the
+ same function and continues to be actively developed.
+
+Package: xnest
+Architecture: any
+Depends: ${xnest:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Description: nested X server
+ xnest an X server that is itself an X client.  This allows you to run a
+ server within a server; this is occasionally useful for testing new window
+ managers and other X clients.
+ .
+ Xnest relies upon its parent X server for font services.
+
+Package: xproxy
+Architecture: any
+Depends: ${xproxy:Depends}
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: X proxy services
+ xproxy provides a low bandwidth X proxy (lbxproxy), an X firewall proxy
+ (xfwp), and a proxy manager service (proxymngr).
+ .
+ lbxproxy is useful for running X clients across a slow network connection.
+ Applications need not know anything about the Low Bandwidth extension to X
+ (LBX); they simply connect to lbxproxy as if it were another server.  The
+ proxy accepts client connections, multiplexes them over a single connection
+ to the X server, and performs various optimizations on the X protocol to make
+ it faster over low bandwidth and/or high latency connections.
+ .
+ xfwp is an application layer gateway proxy that may be run on a network
+ firewall host to forward X traffic across the firewall.
+ .
+ proxymngr is responsible for resolving requests from xfindproxy (in the
+ xbase-clients package) and other similar clients, starting new proxies when
+ appropriate, and keeping track of all the available proxy services.
+
+Package: xprt
+Architecture: any
+Depends: ${xnest:Depends}
+Description: X print server
+ xprt provides an X server with the print extension and special DDX
+ (Device-Dependent X) implementation.
+
+Package: xserver-3dlabs
+Architecture: alpha i386 sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Provides: xserver
+Description: X server for 3DLabs GLINT and Permedia-based graphics cards
+ xserver-3dlabs is an 8-bit PseudoColor, 16-bit TrueColor, 24-bit
+ TrueColor, and 32-bit TrueColor X server suitable for use with some 3DLabs
+ GLINT 500TX, GLINT MX, Permedia, and Permedia 2 graphic accelerator
+ boards.  24-bit operation is supported only on the Permedia 2.
+
+Package: xserver-8514
+Architecture: i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for ATI 8514/A-based graphics cards
+ xserver-8514 is an 8-bit PseudoColor X server suitable for use with ATI
+ 8514/A graphic accelerator boards.
+
+Package: xserver-agx
+Architecture: i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for IBM XGA and IIT AGX-based graphics cards
+ xserver-agx is an 8-bit PseudoColor and 16-bit TrueColor X server suitable
+ for use with IIT AGX or IBM XGA graphic accelerator boards.
+
+Package: xserver-common
+Architecture: any
+Depends: xfree86-common, makedev (>= 2.3.1-24), ${xserver-common:Depends}
+Suggests: xfonts-base, xfonts-100dpi | xfonts-75dpi, xfonts-scalable
+Conflicts: xbase (<< 3.3.2.3a-2), xsun-utils, xbase-clients (<< 3.3.6-1)
+Replaces: xbase (<< 3.3.2.3a-2), xserver-vga16 (<< 3.3.2.3a-2), xserver-agx (<< 3.3.2.3a-9), xserver-mach32 (<< 3.3.2.3a-9), xserver-mach64 (<< 3.3.2.3a-9), xserver-p9000 (<< 3.3.2.3a-9), xserver-s3 (<< 3.3.2.3a-9), xserver-s3v (<< 3.3.2.3a-9), xserver-tga (<< 3.3.2.3a-9), xserver-w32 (<< 3.3.2.3a-9), xsun-utils
+Description: files and utilities common to all X servers
+ The X server is the hardware interface of the X Window System.  Its job is to
+ communicate with video display and input devices, and present them in a
+ standardized, abstract fashion via the X protocol to X clients (X-based
+ programs).  The X server largely relieves programs of having to know or care
+ about the details of the hardware with which they are interacting (such
+ things as 32-bit versus 8-bit color, the layout of the keyboard, how many
+ buttons the mouse has, etc.).  The catch is that the X server must itself
+ know the technical specifications of the graphics hardware and monitor, the
+ keyboard layout, the protocol used by the mouse, and so forth.
+ .
+ Most of the X servers in Debian are authored by the XFree86 Project, Inc.,
+ which also distributes the rest of the X Window System source code for
+ convenience.  XFree86's X servers attempt where possible to take advantage of
+ acceleration features present within the video hardware.
+ .
+ xserver-common contains files required by all XFree86 X servers, and includes
+ a text-based program (xf86config) that configures the /etc/X11/XF86Config
+ file, whose primary purpose is to describe the computer's video and input
+ hardware to the X server.
+ .
+ All X servers either need fonts installed on the local host, or need to know
+ of a remote host that provides font services (with xfs, for instance).  The
+ former means that font packages are mandatory.  The latter means that font
+ packages may be gratuitous.  To err on the side of caution, install at least
+ the xfonts-base, xfonts-100dpi or xfonts-75dpi, and xfonts-scalable packages.
+ .
+ For a more sophisticated (and graphical) X server configuration tool, see
+ the xf86setup package (currently for the i386 architecture only).
+
+Package: xserver-fbdev
+Architecture: alpha arm i386 m68k powerpc sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Provides: xserver
+Description: X server for framebuffer-based graphics drivers
+ xserver-fbdev is an X server that uses the kernel-based framebuffer device
+ driver for display.
+ .
+ To use this server, you must have a kernel that supports the framebuffer
+ console device.  For the Alpha and i386 architectures, this capability is
+ absent from the 2.0 (and earlier) kernel series.  Users of these
+ architectures must use version 2.2 or later of the Linux kernel with support
+ for an appropriate framebuffer console driver to employ this X server.
+
+Package: xserver-i128
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for Number Nine Imagine 128 graphics cards
+ xserver-i128 is an X server suitable for use with Number Nine Imagine 128,
+ Ticket 2 Ride, Revolution 3D, and Revolution IV graphics cards.
+
+Package: xserver-mach32
+Architecture: i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for ATI Mach32-based graphics cards
+ xserver-mach32 is an 8-bit PseudoColor and 16-bit TrueColor X server suitable
+ for use with ATI Mach32 graphic accelerator boards.  16-bit operation is not
+ supported on all accelerator boards.
+
+Package: xserver-mach64
+Architecture: alpha i386 sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for ATI Mach64-based graphics cards
+ xserver-mach64 is an 8-bit PseudoColor, 16-bit TrueColor, and 32-bit
+ TrueColor X server suitable for use with ATI Mach64, 3D Rage, 3D Rage II, and
+ 3D Rage Pro accelerator boards.  16-bit and 32-bit operation is not supported
+ on all accelerator boards.
+
+Package: xserver-mach8
+Architecture: i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for ATI Mach8-based graphics cards
+ xserver-mach8 is an 8-bit PseudoColor X server suitable for use with ATI
+ Mach8 graphic accelerator boards.
+
+Package: xserver-mono
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for monochrome graphics cards and/or monitors
+ xserver-mono is a monochrome X server suitable for use with most VGA and SVGA
+ cards.  It also supports the Hercules monochrome card, the Hyundai HGC1280,
+ Sigma LaserView, Visa and Apollo monochrome cards.
+
+Package: xserver-p9000
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for Weitek P9000-based graphics cards
+ xserver-p9000 is an 8-bit PseudoColor, 16-bit TrueColor, and 32-bit TrueColor
+ X server suitable for use with Weitek Power 9000 (P9000) graphic accelerator
+ boards.
+
+Package: xserver-s3
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for S3 chipset-based graphics cards
+ xserver-s3 is an 8-bit PseudoColor, 16-bit TrueColor, and 32-bit TrueColor
+ X server suitable for use with S3 graphic accelerator boards (with some
+ exceptions, like the ViRGE and ViRGE/VX series).  16-bit and 32-bit operation
+ is not supported on all accelerator boards.
+
+Package: xserver-s3v
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for S3 ViRGE and ViRGE/VX-based graphics cards
+ xserver-s3v is an 8-bit PseudoColor and 16-bit TrueColor X server suitable
+ for use with S3 ViRGE and ViRGE/VX graphic accelerator boards. In most cases
+ use of this X server is deprecated in favor of the SVGA X server.
+
+Package: xserver-svga
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for SVGA graphics cards
+ xserver-svga is an 8-bit PseudoColor, 16-bit TrueColor, and 24-bit TrueColor
+ X server suitable for use with many Super VGA video cards; video chipsets
+ supported include models from Ark Logic, Alliance, ATI, Avance Logic, Chips &
+ Technologies, Cirrus Logic, Compaq, Cyrix, Epson, Genoa, Intel, Matrox, MX,
+ NCR, NVidia(/SGS Thomson), NeoMagic, Oak, RealTek, Rendition, S3, SiS, Tseng,
+ Video7(/Headland Technologies), and Western Digital(/Paradise).  16-bit and
+ 24-bit TrueColor are currently only supported for some chipsets.
+ .
+ Note to Intel i810 chipset users: full support of this graphics hardware is
+ only possible with a specialized kernel module.  See
+ /usr/doc/xserver-svga/README.Debian for more information.
+ .
+ Note to Alpha users: Only the Matrox, NVidia, S3 Virge, and Trident drivers
+ are provided for this architecture.  This server also does not support TGA
+ hardware.
+
+Package: xserver-tga
+Architecture: alpha
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Provides: xserver
+Description: X server for Digital Equipment Corporation TGA graphics cards
+ xserver-tga is an X server suitable for use with the Digital Equipment
+ Corporation TGA (DEC 21030) graphics cards found in some Alphas.
+
+Package: xserver-vga16
+Architecture: alpha i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for VGA graphics cards
+ xserver-vga16 is a 16-color X server suitable for use with most
+ VGA-compatible cards.  It also includes support for the non-VGA monochrome
+ cards supported by the xserver-mono package.  For most people this X server
+ is only useful to kick-start the XF86Setup program (in the xf86setup
+ package).
+ .
+ Note to Alpha users: This server does not support TGA hardware.
+
+Package: xserver-w32
+Architecture: i386
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Replaces: xbase (<< 3.3.2.1-1)
+Provides: xserver
+Description: X server for Tseng ET4000/W32 and ET6000-based graphics cards
+ xserver-w32 is an 8-bit PseudoColor X server suitable for use with Tseng
+ ET4000/W32, ET4000/W32i, ET4000/W32p, and ET6000 graphics accelerator boards.
+ For 16, 24 and 32 bit per pixel support on the ET6000, try the xserver-svga
+ package.
+
+Package: xserver-xsun
+Architecture: sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Conflicts: gpm
+Provides: xserver
+Description: X server for 8-bit Sun framebuffers
+ xserver-xsun is an X server suitable for use with CG3, CG6, and other 8-bit
+ framebuffers.  Monochrome framebuffer support is also compiled in.  Most Sun
+ (and some Sun clone) 8-bit framebuffers are supported.
+ .
+ It should be noted that this X server does not come from XFree86; as such,
+ the server is not built with support for the X protocol extensions
+ XFree86-DGA, XFree86-Misc, and XFree86-VidModeExtension.  X clients that
+ require these extensions will not work with this server.  It also does not
+ use the /etc/X11/XF86Config file, and demands exclusive access to the mouse
+ device (and thus cannot be used with the gpm package).
+
+Package: xserver-xsun-mono
+Architecture: sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Conflicts: gpm
+Provides: xserver
+Description: X server for monochrome Sun framebuffers
+ xserver-xsun-mono is an X server suitable for use with BWTWO (and other mono)
+ framebuffers.  Just about any monochrome framebuffer you can find will
+ probably work with this server, along with some color framebuffers operating
+ in mono mode.
+ .
+ It should be noted that this X server does not come from XFree86; as such,
+ the server is not built with support for the X protocol extensions
+ XFree86-DGA, XFree86-Misc, and XFree86-VidModeExtension.  X clients that
+ require these extensions will not work with this server.  It also does not
+ use the /etc/X11/XF86Config file, and demands exclusive access to the mouse
+ device (and thus cannot be used with the gpm package).
+
+Package: xserver-xsun24
+Architecture: sparc
+Depends: xserver-common (>= 3.3.6), ${xserver:Depends}
+Conflicts: gpm
+Provides: xserver
+Description: X server for 24-bit Sun framebuffers
+ xserver-xsun24 is an X server suitable for use with 24-bit color Sun
+ framebuffers.  This server is still a bit experimental and may have a few
+ minor problems.  Also, it supports a select few of the possible graphics
+ cards (and not all of those are recognized by the kernel, making the list
+ even shorter).  Assuming you have one of the few 24-bit framebuffers
+ recognized by the Linux kernel, this server might be something to try.
+ .
+ It should be noted that this X server does not come from XFree86; as such,
+ the server is not built with support for the X protocol extensions
+ XFree86-DGA, XFree86-Misc, and XFree86-VidModeExtension.  X clients that
+ require these extensions will not work with this server.  It also does not
+ use the /etc/X11/XF86Config file, and demands exclusive access to the mouse
+ device (and thus cannot be used with the gpm package).
+
+Package: xsm
+Architecture: any
+Depends: ${xsm:Depends}
+Replaces: xbase (<< 3.3.2.3a-2)
+Description: X session manager
+ A session is a group of applications, each of which has a particular state.
+ xsm allows you to create arbitrary sessions -- for example, you might have a
+ "light" session, a "development" session, or an "xterminal" session.  Each
+ session can have its own set of applications.  Within a session, you can
+ perform a "checkpoint" to save application state, or a "shutdown" to save
+ state and exit the session.  When you log back in to the system, you can load
+ a specific session, and you can delete sessions you no longer want to keep.
+ .
+ Many window managers and desktop environments for X also provide session
+ management services; this is the original X Consortium reference
+ implementation.
+
+Package: xterm
+Architecture: any
+Depends: ${xterm:Depends}
+Conflicts: xbase (<< 3.3.2.3a-2)
+Replaces: xbase (<< 3.3.2.3a-2)
+Provides: x-terminal-emulator
+Description: X terminal emulator
+ xterm is a terminal emulator for the X Window System.  It provides DEC VT102
+ and Tektronix 4014 compatible terminals for programs that cannot use the
+ window system directly.  This version implements ISO/ANSI colors and most of
+ the control sequences used by DEC VT220 terminals.
+
+Package: xvfb
+Architecture: any
+Depends: ${xvfb:Depends}
+Replaces: xbase (<< 3.3.2.1-2)
+Description: virtual framebuffer X server
+ xvfb provides an X server that can run on machines with no display hardware
+ and no physical input devices.  It emulates a dumb framebuffer using virtual
+ memory.  The primary use of this server was intended to be server testing,
+ but other novel uses for it have been found, including testing clients
+ against unusual depths and screen configurations, doing batch processing with
+ Xvfb as a background rendering engine, load testing, as an aid to porting the
+ X server to a new platform, and providing an unobtrusive way to run
+ applications that don't really need an X server but insist on having one
+ anyway.
+ .
+ This package should not be confused with xserver-fbdev, the X server that
+ interfaces with the kernel's framebuffer device; this package, xvfb, does not
+ use the video hardware and is not a "real" X server in the popular sense.
--- xfree86-1-3.3.6.orig/debian/postrm.template
+++ xfree86-1-3.3.6/debian/postrm.template
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Debian FOO package post-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of FOO package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove) ;;
+  purge) ;;
+  upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) exit 0 ;;
+esac
+
+exit
--- xfree86-1-3.3.6.orig/debian/create-arch-xbase-clients
+++ xfree86-1-3.3.6/debian/create-arch-xbase-clients
@@ -0,0 +1,314 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+
+temp=debian/tmp/xbase-clients
+
+umask 022
+
+rm -rf $temp
+
+# the standard xmodmap file does not apply to SPARC keyboards
+# there is dispute over xvidtune and whether some arches have any use for it
+# for now, everybody gets it
+case "$arch" in
+  sparc)
+    xvidtune=xvidtune
+    xvidtune_path=$temp/usr/X11R6/bin/xvidtune
+    xmodmap_std=
+    ;;
+  *)
+    xvidtune=xvidtune
+    xvidtune_path=$temp/usr/X11R6/bin/xvidtune
+    xmodmap_std=$tree/usr/X11R6/lib/X11/etc/xmodmap.std
+    ;;
+esac
+
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xbase-clients \
+         $temp/etc/X11/Xresources/ \
+         $temp/etc/X11/xinit \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11/app-defaults \
+         $temp/usr/X11R6/lib/X11/xinit \
+         $temp/usr/X11R6/lib/X11/xkb \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/lib/menu \
+         $temp/usr/lib/mime/packages \
+         $temp/usr/lib/xaw-wrappers/config \
+         $temp/usr/share/man/man8 \
+         $temp/usr/sbin
+
+ln -s /etc/X11/xinit/xinitrc $temp/usr/X11R6/lib/X11/xinit/xinitrc
+ln -s /etc/X11/xinit/xserverrc $temp/usr/X11R6/lib/X11/xinit/xserverrc
+ln -s ../../../bin/xkbcomp $temp/usr/X11R6/lib/X11/xkb/xkbcomp
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xbase-clients/
+cp debian/changelog $temp/usr/share/doc/xbase-clients/changelog.Debian
+gzip -9 $temp/usr/share/doc/xbase-clients/changelog.Debian
+cp debian/xbase-clients/README.Debian $temp/usr/share/doc/xbase-clients/
+
+# executables
+for file in Xmark \
+            appres \
+            atobm \
+            bdftopcf \
+            beforelight \
+            bitmap \
+            bmtoa \
+            dga \
+            editres \
+            fsinfo \
+            fslsfonts \
+            fstobdf \
+            iceauth \
+            mkfontdir \
+            oclock \
+            resize \
+            sessreg \
+            setxkbmap \
+            showrgb \
+            startx \
+            x11perf \
+            x11perfcomp \
+            xauth \
+            xclipboard \
+            xclock \
+            xcmsdb \
+            xconsole \
+            xcutsel \
+            xdpyinfo \
+            xfd \
+            xfindproxy \
+            xhost \
+            xieperf \
+            xinit \
+            xkbbell \
+            xkbcomp \
+            xkbevd \
+            xkbprint \
+            xkbvleds \
+            xkbwatch \
+            xmag \
+            xmodmap \
+            xkill \
+            xlogo \
+            xlsatoms \
+            xlsclients \
+            xlsfonts \
+            xon \
+            xprop \
+            xrdb \
+            xrefresh \
+            xrx \
+            xset \
+            xsetmode \
+            xsetpointer \
+            xsetroot \
+            xstdcmap \
+            $xvidtune \
+            xwd \
+            xwininfo \
+            xwud; do
+  cp $tree/usr/X11R6/bin/$file $temp/usr/X11R6/bin/
+  case "$file" in
+    Xmark|startx|x11perfcomp|xon) ;;
+    *) strip $temp/usr/X11R6/bin/$file ;;
+  esac
+done
+
+# move xconsole for Xaw replacement wrapping
+mv $temp/usr/X11R6/bin/xconsole $temp/usr/X11R6/bin/xconsole.real
+
+for file in update-fonts-alias \
+            update-fonts-scale; do
+  cp debian/xbase-clients/$file $temp/usr/sbin/
+done
+
+# manual pages
+for file in appres \
+            atobm \
+            bdftopcf \
+            beforelight \
+            bitmap \
+            bmtoa \
+            dga \
+            editres \
+            fsinfo \
+            fslsfonts \
+            fstobdf \
+            iceauth \
+            mkfontdir \
+            oclock \
+            resize \
+            sessreg \
+            setxkbmap \
+            showrgb \
+            startx \
+            x11perf \
+            x11perfcomp \
+            xauth \
+            xclipboard \
+            xclock \
+            xcmsdb \
+            xconsole \
+            xcutsel \
+            xdpyinfo \
+            xfd \
+            xfindproxy \
+            xhost \
+            xieperf \
+            xinit \
+            xkbcomp \
+            xkbevd \
+            xkbprint \
+            xmag \
+            xmodmap \
+            xkill \
+            xlogo \
+            xlsatoms \
+            xlsclients \
+            xlsfonts \
+            xon \
+            xprop \
+            xrdb \
+            xrefresh \
+            xrx \
+            xset \
+            xsetmode \
+            xsetpointer \
+            xsetroot \
+            xstdcmap \
+            $xvidtune \
+            xwd \
+            xwininfo \
+            xwud; do
+  cp $tree/usr/X11R6/man/man1/$file.1x $temp/usr/X11R6/man/man1/
+done
+
+for file in update-fonts-alias.8 \
+            update-fonts-scale.8; do
+  cp debian/xbase-clients/$file $temp/usr/share/man/man8/
+done
+
+cp debian/xbase-clients/Xmark.1x $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/* $temp/usr/share/man/man8/*
+
+for file in xkbbell \
+            xkbvleds \
+            xkbwatch; do
+  ln -s ../../../share/man/man7/undocumented.7.gz $temp/usr/X11R6/man/man1/$file.1x.gz
+done
+
+# library files
+for file in Bitmap \
+            Bitmap-color \
+            Beforelight \
+            Editres \
+            Editres-color \
+            Clock-color \
+            XClipboard \
+            XClock \
+            XConsole \
+            Xfd \
+            XLogo \
+            XLogo-color \
+            Xmag \
+            Xvidtune; do
+  cp $tree/usr/X11R6/lib/X11/app-defaults/$file \
+   $temp/usr/X11R6/lib/X11/app-defaults/
+done
+
+cp -a $tree/usr/X11R6/lib/X11/x11perfcomp/ $temp/usr/X11R6/lib/X11/
+if [ "$xmodmap_std" ]; then
+  cp $xmodmap_std $temp/usr/X11R6/lib/X11/
+fi
+
+# xaw-wrappers info
+cp debian/xbase-clients/xaw-wrappers $temp/usr/lib/xaw-wrappers/config/xbase-clients
+
+# menu system
+cp debian/xbase-clients/menu $temp/usr/lib/menu/xbase-clients
+
+# configuration files
+cp debian/xbase-clients/xresources $temp/etc/X11/Xresources/xbase-clients
+cp debian/xbase-clients/Xmodmap $temp/etc/X11/Xmodmap
+cp debian/xbase-clients/xinitrc $temp/etc/X11/xinit/
+
+# MIME support files
+cp debian/xbase-clients/mime $temp/usr/lib/mime/packages/xbase-clients
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xbase-clients/$FILE ]; then
+    cp debian/xbase-clients/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxbase-clients $temp/usr/X11R6/bin/appres \
+                               $temp/usr/X11R6/bin/atobm \
+                               $temp/usr/X11R6/bin/bdftopcf \
+                               $temp/usr/X11R6/bin/beforelight \
+                               $temp/usr/X11R6/bin/bitmap \
+                               $temp/usr/X11R6/bin/bmtoa \
+                               $temp/usr/X11R6/bin/dga \
+                               $temp/usr/X11R6/bin/editres \
+                               $temp/usr/X11R6/bin/fsinfo \
+                               $temp/usr/X11R6/bin/fslsfonts \
+                               $temp/usr/X11R6/bin/fstobdf \
+                               $temp/usr/X11R6/bin/iceauth \
+                               $temp/usr/X11R6/bin/mkfontdir \
+                               $temp/usr/X11R6/bin/oclock \
+                               $temp/usr/X11R6/bin/resize \
+                               $temp/usr/X11R6/bin/sessreg \
+                               $temp/usr/X11R6/bin/setxkbmap \
+                               $temp/usr/X11R6/bin/showrgb \
+                               $temp/usr/X11R6/bin/x11perf \
+                               $temp/usr/X11R6/bin/xauth \
+                               $temp/usr/X11R6/bin/xclipboard \
+                               $temp/usr/X11R6/bin/xclock \
+                               $temp/usr/X11R6/bin/xcmsdb \
+                               $temp/usr/X11R6/bin/xconsole.real \
+                               $temp/usr/X11R6/bin/xcutsel \
+                               $temp/usr/X11R6/bin/xdpyinfo \
+                               $temp/usr/X11R6/bin/xfd \
+                               $temp/usr/X11R6/bin/xfindproxy \
+                               $temp/usr/X11R6/bin/xhost \
+                               $temp/usr/X11R6/bin/xieperf \
+                               $temp/usr/X11R6/bin/xinit \
+                               $temp/usr/X11R6/bin/xkbcomp \
+                               $temp/usr/X11R6/bin/xkbevd \
+                               $temp/usr/X11R6/bin/xkbprint \
+                               $temp/usr/X11R6/bin/xmag \
+                               $temp/usr/X11R6/bin/xmodmap \
+                               $temp/usr/X11R6/bin/xkill \
+                               $temp/usr/X11R6/bin/xlogo \
+                               $temp/usr/X11R6/bin/xlsatoms \
+                               $temp/usr/X11R6/bin/xlsclients \
+                               $temp/usr/X11R6/bin/xlsfonts \
+                               $temp/usr/X11R6/bin/xprop \
+                               $temp/usr/X11R6/bin/xrdb \
+                               $temp/usr/X11R6/bin/xrefresh \
+                               $temp/usr/X11R6/bin/xrx \
+                               $temp/usr/X11R6/bin/xset \
+                               $temp/usr/X11R6/bin/xsetmode \
+                               $temp/usr/X11R6/bin/xsetpointer \
+                               $temp/usr/X11R6/bin/xsetroot \
+                               $temp/usr/X11R6/bin/xstdcmap \
+                               $xvidtune_path \
+                               $temp/usr/X11R6/bin/xwd \
+                               $temp/usr/X11R6/bin/xwininfo \
+                               $temp/usr/X11R6/bin/xwud
+dpkg-gencontrol -isp -P$temp -pxbase-clients
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/create-indep-rstart
+++ xfree86-1-3.3.6/debian/create-indep-rstart
@@ -0,0 +1,45 @@
+#!/bin/sh
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/rstart
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/bin \
+         $temp/usr/share/doc/rstart \
+         $temp/usr/share/man/man1
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/rstart/
+cp debian/changelog $temp/usr/share/doc/rstart/changelog.Debian
+gzip -9 $temp/usr/share/doc/rstart/changelog.Debian
+cp debian/rstart/README.Debian $temp/usr/share/doc/rstart/
+
+# executables
+cp $tree/usr/X11R6/bin/rstart $temp/usr/bin/
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/rstart.1x $temp/usr/share/man/man1/
+gzip -9 $temp/usr/share/man/man1/*
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/rstart/$FILE ]; then
+    cp debian/rstart/$FILE $temp/DEBIAN/
+  fi
+done
+
+dpkg-gencontrol -isp -P$temp -prstart
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/postinst.template
+++ xfree86-1-3.3.6/debian/postinst.template
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Debian FOO package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+# cleanup () {
+#   # unroll changes in FOO preinst
+# }
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of FOO package.' ;\
+      # echo -n 'Cleaning up...' ;\
+      # cleanup ;\
+      # echo 'done.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;; # cleanup
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/FOO -a -d /usr/share/doc/FOO ]; then
+  ln -sf ../share/doc/FOO /usr/doc/FOO
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/create-arch-xf86setup
+++ xfree86-1-3.3.6/debian/create-arch-xf86setup
@@ -0,0 +1,90 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xf86setup
+
+umask 022
+
+rm -rf $temp
+
+case "$arch" in
+  arm)
+    exit 0
+    ;;
+  m68k)
+    exit 0
+    ;;
+  powerpc)
+    exit 0
+    ;;
+  sparc)
+    exit 0
+    ;;
+  *)
+    ;;
+esac
+
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xf86setup \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11 \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/lib/menu
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xf86setup/
+# append XF86Setup-specific stuff to the copyright file
+echo >> $temp/usr/share/doc/xf86setup/copyright
+echo "********************************************************************************" >> $temp/usr/share/doc/xf86setup/copyright
+echo "Debian: moved from /usr/X11R6/lib/X11/XF86Setup/LICENSE" >> $temp/usr/share/doc/xf86setup/copyright
+cat $tree/usr/X11R6/lib/X11/XF86Setup/LICENSE >> $temp/usr/share/doc/xf86setup/copyright
+echo >> $temp/usr/share/doc/xf86setup/copyright
+echo "********************************************************************************" >> $temp/usr/share/doc/xf86setup/copyright
+echo "Debian: moved from /usr/X11R6/lib/X11/XF86Setup/tcllib/license.terms" >> $temp/usr/share/doc/xf86setup/copyright
+cat $tree/usr/X11R6/lib/X11/XF86Setup/tcllib/license.terms >> $temp/usr/share/doc/xf86setup/copyright
+
+cp debian/changelog $temp/usr/share/doc/xf86setup/changelog.Debian
+gzip -9 $temp/usr/share/doc/xf86setup/changelog.Debian
+
+# other documentation
+cp $tree/usr/X11R6/lib/X11/doc/QuickStart.doc $temp/usr/share/doc/xf86setup/
+
+# executables
+cp $tree/usr/X11R6/bin/XF86Setup $temp/usr/X11R6/bin/
+cp $tree/usr/X11R6/bin/xmseconfig $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/XF86Setup
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/XF86Setup.1x $temp/usr/X11R6/man/man1/
+cp $tree/usr/X11R6/man/man1/xmseconfig.1x $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/*
+
+# library files
+cp -a $tree/usr/X11R6/lib/X11/XF86Setup $temp/usr/X11R6/lib/X11/
+rm $temp/usr/X11R6/lib/X11/XF86Setup/LICENSE \
+   $temp/usr/X11R6/lib/X11/XF86Setup/tcllib/license.terms
+
+# menu system
+cp debian/xf86setup/menu $temp/usr/lib/menu/xf86setup
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xf86setup/$FILE ]; then
+    cp debian/xf86setup/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxf86setup $temp/usr/X11R6/bin/XF86Setup
+
+dpkg-gencontrol -isp -P$temp -pxf86setup
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/libc5.site.def.diff.in
+++ xfree86-1-3.3.6/debian/libc5.site.def.diff.in
@@ -0,0 +1,15 @@
+--- xc/config/cf/site.def.orig	Tue Dec  7 16:38:40 1999
++++ xc/config/cf/site.def	Tue Dec  7 16:39:06 1999
+@@ -121,8 +121,11 @@
+ #ifdef AfterVendorCF
+ 
+ #ifndef ProjectRoot
+-#define ProjectRoot /usr/X11R6
++#define ProjectRoot /usr/@ARCH@-linuxlibc1
+ #endif
++#define ForceNormalLib YES
++#undef BaseShLibReqs
++#define BaseShLibReqs -lc
+ 
+ /* Only set HasXdmAuth to YES if you have a Wraphelp.c file. */
+ /* #define HasXdmAuth YES */
--- xfree86-1-3.3.6.orig/debian/xvfb/prerm
+++ xfree86-1-3.3.6/debian/xvfb/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xvfb package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xvfb package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xvfb ]; then
+  rm /usr/doc/xvfb
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xvfb/postinst
+++ xfree86-1-3.3.6/debian/xvfb/postinst
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xvfb package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xvfb package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xvfb -a -d /usr/share/doc/xvfb ]; then
+  ln -sf ../share/doc/xvfb /usr/doc/xvfb
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/timebuild
+++ xfree86-1-3.3.6/debian/timebuild
@@ -0,0 +1,2 @@
+#!/bin/sh
+/usr/bin/time --verbose dpkg-buildpackage -us -uc -rfakeroot > ../build.log 2>&1
--- xfree86-1-3.3.6.orig/debian/xlib6g-dev/prerm
+++ xfree86-1-3.3.6/debian/xlib6g-dev/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6g-dev package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xlib6g-dev package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xlib6g-dev ]; then
+  rm /usr/doc/xlib6g-dev
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xlib6g-dev/postinst
+++ xfree86-1-3.3.6/debian/xlib6g-dev/postinst
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6g-dev package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xlib6g-dev package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xlib6g-dev -a -d /usr/share/doc/xlib6g-dev ]; then
+  ln -sf ../share/doc/xlib6g-dev /usr/doc/xlib6g-dev
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/create-compat-xlib6-altdev
+++ xfree86-1-3.3.6/debian/create-compat-xlib6-altdev
@@ -0,0 +1,120 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+. debian/scripts/xtree-libc5
+. debian/scripts/archmap
+temp=debian/tmp/xlib6-altdev
+
+MANBASE=usr/$arch-linuxlibc1/man
+BINBASE=usr/$arch-linuxlibc1/bin
+LIBBASE=usr/$arch-linuxlibc1/lib
+INCBASE=usr/$arch-linuxlibc1/include
+MANDIR=$temp/$MANBASE
+BINDIR=$temp/$BINBASE
+LIBDIR=$temp/$LIBBASE
+INCDIR=$temp/$INCBASE
+SHLIBDIR=$temp/usr/lib/libc5-compat
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xlib6-altdev \
+         $BINDIR \
+         $INCDIR \
+         $LIBDIR/X11 \
+         $MANDIR/man1 \
+         $SHLIBDIR
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xlib6-altdev/
+cp debian/changelog $temp/usr/share/doc/xlib6-altdev/changelog.Debian
+gzip -9 $temp/usr/share/doc/xlib6-altdev/changelog.Debian
+
+# executables
+for file in gccmakedep \
+            imake \
+            lndir \
+            makedepend \
+            makeg \
+            mergelib \
+            mkdirhier \
+            xmkmf; do
+  cp $tree/$BINBASE/$file $BINDIR
+done
+strip $BINDIR/imake \
+      $BINDIR/lndir \
+      $BINDIR/makedepend
+
+# manual pages
+for file in imake \
+            lndir \
+            makedepend \
+            makeg \
+            mkdirhier \
+            xmkmf; do
+  cp $tree/$MANBASE/man1/$file.1x $MANDIR/man1/
+done
+gzip -9 $MANDIR/man1/*
+
+for file in gccmakedep \
+            mergelib; do
+  ln -s ../../../share/man/man7/undocumented.7.gz $MANDIR/man1/$file.1x.gz
+done
+
+# include files
+cp -a $tree/$INCBASE/X11/ $INCDIR
+rm -r $INCDIR/X11/bitmaps/
+
+# library files
+# For every archive (static library), determine whether there is a dynamic
+# version (shared object); if so, make a symlink from the plain .so file to
+# the actual library (which has version numbers at the end).  If there is no
+# dynamic version, copy over the static version.  Static versions of libraries
+# that do have a dynamic version go in the -static package.
+for archive in $tree/$LIBBASE/lib*.a; do
+  sofile=$(echo $archive | sed 's:\.a$:.so:')
+  if [ -e $sofile ]; then
+    reallib=$(readlink $sofile)
+    linkname=$(basename $sofile)
+    ln -s ../../lib/libc5-compat/$reallib $LIBDIR/$linkname
+  else
+    # don't copy libz -- Debian already has one
+    if [ ! "$(basename $archive)" = "libz.a" ]; then
+      cp $archive $LIBDIR
+      # keep debugging symbols in static version
+      # strip --strip-debug $LIBDIR/$archive
+    fi
+  fi
+done
+
+# config files for imake
+cp -a $tree/$LIBBASE/X11/config $LIBDIR/X11
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xlib6-altdev/$FILE ]; then
+    cp debian/xlib6-altdev/$FILE $temp/DEBIAN/
+  fi
+done
+
+( unset LD_PRELOAD && dpkg-shlibdeps -pxlib6-altdev $BINDIR/imake \
+                                                    $BINDIR/lndir \
+                                                    $BINDIR/makedepend )
+
+dpkg-gencontrol -isp -P$temp -pxlib6-altdev
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/xlib6g-static/prerm
+++ xfree86-1-3.3.6/debian/xlib6g-static/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6g-static package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xlib6g-static package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xlib6g-static ]; then
+  rm /usr/doc/xlib6g-static
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xlib6g-static/postinst
+++ xfree86-1-3.3.6/debian/xlib6g-static/postinst
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6g-static package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xlib6g-static package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xlib6g-static -a -d /usr/share/doc/xlib6g-static ]; then
+  ln -sf ../share/doc/xlib6g-static /usr/doc/xlib6g-static
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/rules
+++ xfree86-1-3.3.6/debian/rules
@@ -0,0 +1,241 @@
+#!/usr/bin/make -f
+# Debian rules file for xfree86-1 source package
+# Originally by Stephen Early <sde1000@debian.org>
+# Modified by Mark W. Eichin <eichin@kitten.gen.ma.us>
+# Modified by Branden Robinson <branden@debian.org>
+# Modified by Adam Heath <doogie@debian.org>
+# Copyright 1996-2000 Software in the Public Interest.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+# Include Adam Heath's source archive/patch handling system,
+include debian/sys-build.mk
+
+define checkdir
+	test -f debian/rules
+endef
+
+# This is a horrendous kludge to ensure that some scripts we need are
+# executable.
+DUMMY:=$(shell if [ ! -x debian/setperms ]; then chmod 755 debian/setperms; fi)
+DUMMY:=$(shell debian/setperms)
+
+# Determine our architecture.
+BUILD_ARCH:=$(shell dpkg --print-gnu-build-architecture)
+# The DEB_HOST_ARCH variable may be set per the Debian cross-compilation
+# policy.
+ifdef DEB_HOST_ARCH
+ ARCH:=$(DEB_HOST_ARCH)
+else
+ # dpkg-cross sets the ARCH environment variable; if set, use it.
+ ifdef ARCH
+  ARCH:=$(ARCH)
+ else
+  ARCH:=$(BUILD_ARCH)
+ endif
+endif
+
+# Canonicalize the architecture name.
+ARCH_MAP:=$(shell debian/scripts/archmap $(ARCH))
+
+# Read in important variables.
+include debian/scripts/vars
+# Read in architecture-specific variables of importance.
+include debian/scripts/vars.$(ARCH_MAP)
+
+# Figure out what version of GNU libc 2 we're using.
+LIBC6MINORVERSION=$(shell debian/scripts/getglibcversion --minor)
+
+# Because of the stampdir magic, when you actually want to run a rule
+# over, you would have to remove the stamp manually.  Now, just do
+# 'debian/rules <target> <target> ... FORCE=1', and the stamp files
+# that match the given targets will be removed automagically.
+stampdir_targets=build build-libc6 build-old install install-libc6 install-old
+stampdir_targets+=source.make patchapply
+stampdir_targets+=source.build source.unpack fix.source.patch source.patch
+stampdir_targets+=unfix.source.patch
+ifdef FORCE
+ dummy:=$(shell rm -f $(patsubst %,$(STAMP_DIR)/%,$(filter $(stampdir_targets),$(MAKECMDGOALS))))
+endif
+
+# If this is defined, then none of the 'long' commands will be run.  Useful
+# for testing.
+# test_rules=1
+
+# This is where the upstream install rules will put their stuff.
+DEBTREEDIR:=$(CURDIR)/debian/xtree
+DEBTREEDIR5:=$(CURDIR)/debian/xtree-libc5
+
+ifdef COMPAT_ARCH
+ # We are compiling on an arch that has libc5 available.  So we define some
+ # makefile vars that are used later on to build the libc5 compatibility
+ # debs, and pass some defines to the top-level X makefile itself.
+ DOCOMPAT_SETUP:=setup.build-old
+ DOCOMPAT_BUILD:=build-old
+ DOCOMPAT_INSTALL:=install-old
+ DOCOMPAT_DEBS:=binary-compat
+ L5FLAGS=-DLinuxCLibMajorVersion=5 \
+         -DLinuxCLibMinorVersion=4 \
+         -DShLibDir=/usr/lib/libc5-compat \
+         -DUsrLibDir=/usr/$(ARCH_MAP)-linuxlibc1/lib \
+         -DBinDir=/usr/$(ARCH_MAP)-linuxlibc1/bin \
+         -DIncRoot=/usr/$(ARCH_MAP)-linuxlibc1/include
+endif
+
+L6FLAGS=-DLinuxCLibMajorVersion=6 \
+        -DLinuxCLibMinorVersion=$(LIBC6MINORVERSION)
+
+# All 'important' targets have 2 lines.  The one that is run by
+# dpkg-buildpackage or the user, and the one that does the actual work.  This
+# indirection is needed so that the 'stamp' files that signify when a rule is
+# done can be located in a separate 'stampdir.'  Recall that make has no way to
+# know when a goal has been met for a phony target (like "build" or "install").
+#
+# At the end of each stampdir target, be sure to run the command 'touch $@'
+# so that the target will not be run again.  Removing the file will make
+# make run the target over.
+
+build: $(STAMP_DIR)/build
+$(STAMP_DIR)/build: $(patsubst %,$(STAMP_DIR)/%,$(DOCOMPAT_BUILD)) $(STAMP_DIR)/build-libc6
+	touch $@
+
+install: $(STAMP_DIR)/build $(STAMP_DIR)/install
+$(STAMP_DIR)/install: $(patsubst %,$(STAMP_DIR)/%,$(DOCOMPAT_INSTALL)) $(STAMP_DIR)/install-libc6
+	touch $@
+
+# Compile the X Window System for libc6 (libraries, servers, and clients).
+build-libc6: $(STAMP_DIR)/build-libc6
+$(STAMP_DIR)/build-libc6: $(STAMP_DIR)/source.make
+	$(checkdir)
+ifndef test_rules
+	umask 022
+	$(MAKE) -C $(SOURCE_TREE) BOOTSTRAPCFLAGS="$(L6FLAGS)" SHELL="/bin/sh -e" World
+	# build Debian's X server wrapper
+	$(CC) -Wall -g -O2 -o debian/xserver-wrapper debian/xserver-wrapper.c
+endif
+	touch $@
+
+# Install everything built in the build-libc6 rule into our temporary
+# directory.
+install-libc6: $(STAMP_DIR)/install-libc6
+$(STAMP_DIR)/install-libc6: $(STAMP_DIR)/build-libc6
+ifndef test_rules
+	umask 022
+	$(MAKE) -C $(SOURCE_TREE) SHELL="/bin/sh -e" install install.man DESTDIR=$(DEBTREEDIR)
+	# i386 and Alpha version of the FBDev manpage (m68k and PowerPC will just use the 68 one, also present)
+	sed s/XF68/XF86/g < $(SOURCE_TREE)/programs/Xserver/hw/xfree68/XF68_FBDev.man \
+	                  > $(DEBTREEDIR)/usr/X11R6/man/man1/XF86_FBDev.1x
+	# remove reference to framebuffer driver being for m68k Linux kernels only
+	sed s:/m68k::g < $(SOURCE_TREE)/programs/Xserver/hw/xfree68/doc/README.fbdev \
+	               > $(DEBTREEDIR)/usr/X11R6/lib/X11/doc/README.fbdev
+	# install the changelogs
+	cp $(SOURCE_TREE)/programs/Xserver/hw/xfree86/CHANGELOG* $(DEBTREEDIR)/usr/X11R6/lib/X11/doc/
+	# install xterm's HTML changelog
+	cp $(SOURCE_TREE)/programs/xterm/xterm.log.html $(DEBTREEDIR)/usr/X11R6/lib/X11/doc/
+	# install xterm's control sequences document (if available)
+	if [ -e $(SOURCE_TREE)/programs/xterm/ctlseqs.ms ]; then \
+	 cp $(SOURCE_TREE)/programs/xterm/ctlseqs.ms $(DEBTREEDIR)/usr/X11R6/lib/X11/doc/; fi
+	# install xterm fun stuff (if available)
+	mkdir -p $(DEBTREEDIR)/usr/X11R6/lib/X11/xterm
+	for xtermdir in tektests unicode vttests; do if [ -e $(SOURCE_TREE)/programs/xterm/$$xtermdir ]; then \
+	 cp -a $(SOURCE_TREE)/programs/xterm/$$xtermdir $(DEBTREEDIR)/usr/X11R6/lib/X11/xterm/; fi; done
+	# install Debian's X server wrapper
+	install -m 755 debian/xserver-wrapper $(DEBTREEDIR)/usr/X11R6/bin/X
+endif
+	touch $@
+
+# Prepare a separate source tree for the libc5 build, with just a subset of the
+# X sources.
+setup.build-old: $(STAMP_DIR)/setup.build-old
+$(STAMP_DIR)/setup.build-old: $(STAMP_DIR)/source.make
+	$(checkdir)
+	-rm -rf $(SOURCE_TREE_LIBC5)
+	-mkdir -p $(SOURCE_TREE_LIBC5)
+	# copy over just bootstrap, config, and library stuff
+	for i in Imakefile Makefile config include lib; do cp -a $(SOURCE_TREE)/$$i $(SOURCE_TREE_LIBC5); done
+	# the X libs need access to the server header files as well
+	-mkdir -p $(SOURCE_TREE_LIBC5)/programs/Xserver
+	cp -a $(SOURCE_TREE)/programs/Xserver/include $(SOURCE_TREE_LIBC5)/programs/Xserver
+	# the debian/libc5.* files make changes to the source that we need to support the libc5 environment
+	sed 's/@ARCH@/$(ARCH_MAP)/' < debian/libc5.site.def.diff.in > debian/libc5.site.def.diff
+	for LIBC5PATCH in debian/libc5.*.diff; do (cd $(SOURCE_TREE_LIBC5) && patch -p1) < $$LIBC5PATCH; done
+	touch $@
+
+# Compile the X libraries in a libc5 environment.
+build-old: $(STAMP_DIR)/build-old
+$(STAMP_DIR)/build-old: $(STAMP_DIR)/setup.build-old
+ifndef test_rules
+	umask 022
+	PATH=/usr/$(ARCH_MAP)-linuxlibc1/bin:$$PATH \
+	 LD_LIBRARY_PATH=/usr/lib/libc5-compat/lib \
+	 $(MAKE) -C $(SOURCE_TREE_LIBC5) BOOTSTRAPCFLAGS="$(L5FLAGS)" SHELL="/bin/sh -e" World
+endif
+	touch $@
+
+# Install everything built in the build-old rule into a temporary directory for
+# libc5 stuff.
+install-old: $(STAMP_DIR)/install-old
+$(STAMP_DIR)/install-old: $(STAMP_DIR)/build-old
+ifndef test_rules
+	umask 022
+	PATH=/usr/$(ARCH_MAP)-linuxlibc1/bin:$$PATH \
+	 $(MAKE) -C $(SOURCE_TREE_LIBC5) BOOTSTRAPCFLAGS="$(L5FLAGS)" SHELL="/bin/sh -e" install install.man DESTDIR=$(DEBTREEDIR5)
+endif
+	touch $@
+
+clean-debian:
+	rm -rf debian/tmp $(STAMP_DIR) $(DEBTREEDIR) $(DEBTREEDIR5)
+	rm -f debian/xserver-wrapper debian/files debian/substvars debian/libc5.site.def.diff
+
+clean: source.clean clean-debian
+	$(checkdir)
+ifdef COMPAT_ARCH
+	rm -rf $(SOURCE_TREE_LIBC5)
+endif
+# Clean up backup files.
+	find . -name "*~" -print0 | xargs --no-run-if-empty -0 rm
+
+binary-arch binary-indep binary-compat:	checkroot
+binary-arch: $(DOCOMPAT_DEBS) $(STAMP_DIR)/binary-arch
+binary-indep: $(STAMP_DIR)/binary-indep
+binary-compat: $(STAMP_DIR)/binary-compat
+
+$(patsubst %,$(STAMP_DIR)/binary-%,arch indep compat): $(STAMP_DIR)/install
+	set -e && for i in debian/create-$(patsubst $(STAMP_DIR)/binary-%,%,$@)-* ; do $(SHELL) $$i ; done
+	touch $@
+
+binary: binary-arch binary-indep
+
+checkroot:
+	$(checkdir)
+	test $(shell id -u) = '0'
+
+# Use 'debian/rules environment' to help debug architecture-related problems
+# with the rules file.
+environment:
+	@echo 'Package build environment (not all variables may be set):'
+	@echo '$$(ARCH)' is "$(ARCH)"
+ifdef COMPAT_ARCH
+	@echo '$$(COMPAT_ARCH)' is "$(COMPAT_ARCH)"
+	@echo '$$(DOCOMPAT_SETUP)' is "$(DOCOMPAT_SETUP)"
+	@echo '$$(DOCOMPAT_BUILD)' is "$(DOCOMPAT_BUILD)"
+	@echo '$$(DOCOMPAT_INSTALL)' is "$(DOCOMPAT_INSTALL)"
+	@echo '$$(DOCOMPAT_DEBS)' is "$(DOCOMPAT_DEBS)"
+endif
+	@echo '$$(DEB_HOST_ARCH)' is "$(DEB_HOST_ARCH)"
+	@echo '$$(BUILD_ARCH)' is "$(BUILD_ARCH)"
+	@echo '$$(ARCH_MAP)' is "$(ARCH_MAP)"
+	@echo '$$(L6FLAGS)' is "$(L6FLAGS)"
+ifdef COMPAT_ARCH
+	@echo '$$(L5FLAGS)' is "$(L5FLAGS)"
+endif
+ifndef COMPAT_ARCH
+	@echo 'Not building libc5 compatibility packages.'
+endif
+	@echo 'See the control file for build dependencies; also ensure that Linux kernel 2.2.x'
+	@echo 'headers are installed (the FBDev X server needs them).'
+
+.PHONY: build install build-libc6 install-libc6 setup.build-old build-old \
+        install-old clean-debian clean binary-arch binary-compat binary-indep \
+        binary checkroot environment
--- xfree86-1-3.3.6.orig/debian/create-arch-xlib6g-dev
+++ xfree86-1-3.3.6/debian/create-arch-xlib6g-dev
@@ -0,0 +1,108 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xlib6g-dev
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xlib6g-dev \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11 \
+         $temp/usr/X11R6/man/man1
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xlib6g-dev/
+cp debian/changelog $temp/usr/share/doc/xlib6g-dev/changelog.Debian
+gzip -9 $temp/usr/share/doc/xlib6g-dev/changelog.Debian
+
+# executables
+for file in gccmakedep \
+            imake \
+            lndir \
+            makedepend \
+            makeg \
+            mergelib \
+            mkdirhier \
+            xmkmf; do
+  cp $tree/usr/X11R6/bin/$file $temp/usr/X11R6/bin/
+done
+strip $temp/usr/X11R6/bin/imake \
+      $temp/usr/X11R6/bin/lndir \
+      $temp/usr/X11R6/bin/makedepend
+
+# manual pages
+for file in imake \
+            lndir \
+            makedepend \
+            makeg \
+            mkdirhier \
+            xmkmf; do
+  cp $tree/usr/X11R6/man/man1/$file.1x $temp/usr/X11R6/man/man1/
+done
+gzip -9 $temp/usr/X11R6/man/man1/*
+
+for file in gccmakedep \
+            mergelib; do
+  ln -s ../../../share/man/man7/undocumented.7.gz $temp/usr/X11R6/man/man1/$file.1x.gz
+done
+
+# include files
+cp -a $tree/usr/X11R6/include/ $temp/usr/X11R6/
+rm -r $temp/usr/X11R6/include/X11/bitmaps/
+
+# library files
+# For every archive (static library), determine whether there is a dynamic
+# version (shared object); if so, make a symlink from the plain .so file to
+# the actual library (which has version numbers at the end).  If there is no
+# dynamic version, copy over the static version.  Static versions of libraries
+# that do have dynamic versions go in the -static package.
+for archive in $tree/usr/X11R6/lib/lib*.a; do
+  sofile=$(echo $archive | sed -e 's:\.a$:.so:')
+  if [ -e $sofile ]; then
+    reallib=$(readlink $sofile)
+    linkname=$(basename $sofile)
+    ln -s $reallib $temp/usr/X11R6/lib/$linkname
+  else
+    # don't copy libz -- Debian already has one
+    if [ ! "$(basename $archive)" = "libz.a" ]; then
+      cp $archive $temp/usr/X11R6/lib/
+      # keep debugging symbols in static version
+      # strip --strip-debug $temp/usr/X11R6/lib/$archive
+    fi
+  fi
+done
+
+# config files for imake
+cp -a $tree/usr/X11R6/lib/X11/config $temp/usr/X11R6/lib/X11/
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xlib6g-dev/$FILE ]; then
+    cp debian/xlib6g-dev/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxlib6g-dev $temp/usr/X11R6/bin/imake \
+                            $temp/usr/X11R6/bin/lndir \
+                            $temp/usr/X11R6/bin/makedepend
+
+dpkg-gencontrol -isp -P$temp -pxlib6g-dev
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/xsm/conffiles
+++ xfree86-1-3.3.6/debian/xsm/conffiles
@@ -0,0 +1 @@
+/etc/X11/xsm/system.xsm
--- xfree86-1-3.3.6.orig/debian/xsm/preinst
+++ xfree86-1-3.3.6/debian/xsm/preinst
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Debian xsm package pre-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+maplink () {
+  # returns what symlink should point to
+  case "$1" in
+    /usr/X11R6/lib/X11/xsm/system.xsm) echo /etc/X11/xsm/system.xsm ;;
+  esac;
+}
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+trap "echo ;\
+      echo 'Received signal.  Aborting installation of xsm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  install|upgrade) ;;
+  abort-upgrade) exit 0 ;;
+esac
+
+condecho=:
+
+# check symbolic link structure integrity
+for symlink in /usr/X11R6/lib/X11/xsm/system.xsm; do
+  if [ -L $symlink ]; then
+    if [ $(maplink $symlink) != $(readlink $symlink) ]; then
+      $condecho
+      echo "Warning: $symlink symbolic link points to the wrong"
+      echo "place.  Removing."
+      condecho=echo
+      rm $symlink
+    fi
+  elif [ -e $symlink ]; then
+    $condecho
+    echo "Warning: $symlink is not a symbolic link.  Moving to"
+    echo "$symlink.xsm-old."
+    condecho=echo
+    if [ ! -e $symlink.xsm-old ]; then
+      mv $symlink $symlink.xsm-old
+    else
+      $condecho
+      echo "ERROR: $symlink.xsm-old already exists!  Aborting"
+      echo "installation of xsm package.  Please clean up your crufty filesystem."
+      condecho=echo
+      exit 1
+    fi
+  fi
+done
+
+exit
--- xfree86-1-3.3.6.orig/debian/xsm/prerm
+++ xfree86-1-3.3.6/debian/xsm/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xsm package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xsm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xsm ]; then
+  rm /usr/doc/xsm
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xsm/postinst
+++ xfree86-1-3.3.6/debian/xsm/postinst
@@ -0,0 +1,76 @@
+#!/bin/sh
+# Debian xsm package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+cleanup () {
+  # unroll changes in xsm preinst
+  for file in /usr/X11R6/lib/X11/xsm/system.xsm; do
+    if [ -e $file.xsm-old ]; then
+      rm $file
+      mv $file.xsm-old $file
+    fi
+  done
+}
+
+# TODO comment out these two functions for stable release
+maplink () {
+  # returns what symlink should point to
+  case "$1" in
+    /usr/X11R6/lib/X11/xsm/system.xsm) echo /etc/X11/xsm/system.xsm ;;
+  esac;
+}
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xsm package.' ;\
+      echo -n 'Cleaning up...' ;\
+      cleanup ;\
+      echo 'done.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure)
+    cleanup
+    exit 0 ;;
+esac
+
+condecho=:
+
+# TODO sanity checks -- comment out these for stable release
+for symlink in /usr/X11R6/lib/X11/xsm/system.xsm; do
+  if [ -L $symlink ]; then
+    if [ $(maplink $symlink) != $(readlink $symlink) ]; then
+      $condecho
+      echo "ERROR: $symlink symbolic link points to the wrong"
+      echo "place.  Please report this message to <xsm@packages.debian.org>."
+      condecho=echo
+    fi
+  elif [ -e $symlink ]; then # $symlink is not a symbolic link
+    $condecho
+    echo "ERROR: $symlink is not a symbolic link."
+    echo "Please report this message to <xsm@packages.debian.org>."
+    condecho=echo
+  else
+    $condecho
+    echo "ERROR: $symlink symbolic link does not exist."
+    echo "Please report this message to <xsm@packages.debian.org>."
+  fi
+done
+
+if [ -d /usr/doc -a ! -e /usr/doc/xsm -a -d /usr/share/doc/xsm ]; then
+  ln -sf ../share/doc/xsm /usr/doc/xsm
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/create-compat-xlib6
+++ xfree86-1-3.3.6/debian/create-compat-xlib6
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/archmap
+. debian/scripts/xtree-libc5
+temp=debian/tmp/xlib6
+
+SHLIBBASE=usr/lib/libc5-compat
+INCBASE=usr/$arch-linuxlibc1/include
+LIBBASE=usr/$arch-linuxlibc1/lib
+SHLIBDIR=$temp/$SHLIBBASE
+SHLIBTREE=$tree/$LIBBASE
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xlib6 \
+         $temp/$SHLIBBASE \
+         $temp/$INCBASE/X11 \
+         $temp/$LIBBASE/X11 \
+         $temp/usr/X11R6/lib/X11
+
+ln -s ../../../X11R6/lib/X11/app-defaults $temp/$LIBBASE/X11/app-defaults
+ln -s ../../../X11R6/lib/X11/locale $temp/$LIBBASE/X11/locale
+ln -s ../../../X11R6/include/X11/bitmaps $temp/$INCBASE/X11/bitmaps
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xlib6/
+cp debian/changelog $temp/usr/share/doc/xlib6/changelog.Debian
+gzip -9 $temp/usr/share/doc/xlib6/changelog.Debian
+
+# library files
+cp $SHLIBTREE/X11/XErrorDB \
+   $SHLIBTREE/X11/XKeysymDB $temp/$LIBBASE/X11/
+cp $SHLIBTREE/lib*.so.*.* $SHLIBDIR
+
+for libmajmin in $SHLIBDIR/lib*.so.*.*; do
+  strip --strip-unneeded $libmajmin
+  chmod 644 $libmajmin
+  libmaj=$(echo $libmajmin | sed -e 's/^\(.*\)\.\(.*\)$/\1/')
+  ln -s `basename $libmajmin` $libmaj
+done
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm shlibs; do
+  if [ -e debian/xlib6/$FILE ]; then
+    cp debian/xlib6/$FILE $temp/DEBIAN/
+  fi
+done
+
+( unset LD_PRELOAD && dpkg-shlibdeps -Ldebian/xlib.shlibs -pxlib6 $SHLIBDIR/lib*.so.*.* )
+dpkg-gencontrol -isp -P$temp -pxlib6
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/xlib6-static/control-data
+++ xfree86-1-3.3.6/debian/xlib6-static/control-data
@@ -0,0 +1,11 @@
+Package: xlib6-static
+Architecture: i386 m68k
+Description: statically linked versions of the libraries in xlib6
+ You only need to install this package if you intend to compile statically
+ linked X clients against libc5.  Static libraries with no shared version are
+ in the xlib6-altdev package.  The libraries in this package include debugging
+ symbols.
+Section: oldlibs
+Depends: xlib6, xlib6-altdev
+Conflicts: xslib
+Replaces: xslib
--- xfree86-1-3.3.6.orig/debian/xlib6-static/create-compat-xlib6-static
+++ xfree86-1-3.3.6/debian/xlib6-static/create-compat-xlib6-static
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree-libc5
+. debian/scripts/archmap
+temp=debian/tmp/xlib6-static
+
+LIBBASE=usr/$arch-linuxlibc1/lib
+LIBDIR=$temp/$LIBBASE
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xlib6-static \
+         $LIBDIR
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xlib6-static/
+cp debian/changelog $temp/usr/share/doc/xlib6-static/changelog.Debian
+gzip -9 $temp/usr/share/doc/xlib6-static/changelog.Debian
+
+# library files
+# For every archive (static library), determine whether there is a dynamic
+# version (shared object); if so, copy the archive.
+for archive in $tree/$LIBBASE/lib*.a; do
+  sofile=$(echo $archive | sed 's:\.a$:.so:')
+  if [ -e $sofile ]; then
+    cp $archive $LIBDIR
+    # keep debugging symbols in static version
+    # strip --strip-debug $LIBDIR/`basename $archive`
+  fi
+done
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xlib6-static/$FILE ]; then
+    cp debian/xlib6-static/$FILE $temp/DEBIAN/
+  fi
+done
+
+dpkg-gencontrol -P$temp -pxlib6-static
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/xlib6-static/prerm
+++ xfree86-1-3.3.6/debian/xlib6-static/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6-static package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xlib6-static package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xlib6-static ]; then
+  rm /usr/doc/xlib6-static
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xlib6-static/postinst
+++ xfree86-1-3.3.6/debian/xlib6-static/postinst
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xlib6-static package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xlib6-static package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xlib6-static -a -d /usr/share/doc/xlib6-static ]; then
+  ln -sf ../share/doc/xlib6-static /usr/doc/xlib6-static
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/create-arch-xfs
+++ xfree86-1-3.3.6/debian/create-arch-xfs
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xfs
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xfs \
+         $temp/etc/X11/xfs \
+         $temp/etc/init.d/ \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11/fs \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/X11R6/man/man5 \
+         $temp/var/log \
+         $temp/var/run
+
+ln -s /etc/X11/xfs/config $temp/usr/X11R6/lib/X11/fs/config
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xfs/
+cp debian/changelog $temp/usr/share/doc/xfs/changelog.Debian
+gzip -9 $temp/usr/share/doc/xfs/changelog.Debian
+cp debian/xfs/README.Debian $temp/usr/share/doc/xfs/
+
+# executables
+cp $tree/usr/X11R6/bin/xfs $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/xfs
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/xfs.1x $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/xfs.1x
+cp debian/xfs/xfs.options.5 $temp/usr/X11R6/man/man5/
+gzip -9 $temp/usr/X11R6/man/man5/*
+
+# configuration files
+cp debian/xfs/config $temp/etc/X11/xfs/
+cp debian/xfs/xfs.options $temp/etc/X11/xfs/
+cp debian/xfs/init $temp/etc/init.d/xfs
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xfs/$FILE ]; then
+    cp debian/xfs/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxfs $temp/usr/X11R6/bin/xfs
+dpkg-gencontrol -isp -P$temp -pxfs
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/xext/prerm
+++ xfree86-1-3.3.6/debian/xext/prerm
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xext package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xext package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove|upgrade) ;;
+  failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/xext ]; then
+  rm /usr/doc/xext
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xext/postinst
+++ xfree86-1-3.3.6/debian/xext/postinst
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian xext package post-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xext package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;;
+esac
+
+if [ -d /usr/doc -a ! -e /usr/doc/xext -a -d /usr/share/doc/xext ]; then
+  ln -sf ../share/doc/xext /usr/doc/xext
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/libc5.Imakefile.diff
+++ xfree86-1-3.3.6/debian/libc5.Imakefile.diff
@@ -0,0 +1,13 @@
+--- xc/Imakefile.libc6	Mon Aug 23 22:31:26 1999
++++ xc/Imakefile	Mon Aug 23 22:31:47 1999
+@@ -18,8 +18,8 @@
+ #endif
+ #endif
+ 
+-        SUBDIRS = include config lib $(NLSSUBDIR) \
+-                  programs
++        SUBDIRS = include config lib \
++                  programs/Xserver/include
+ # Debian builds the doc and fonts dirs separately
+ #                  programs $(FONTSDIR) $(DOCSDIR)
+   LNINSTALLDIRS = lib
--- xfree86-1-3.3.6.orig/debian/xdm/xdm.options.5
+++ xfree86-1-3.3.6/debian/xdm/xdm.options.5
@@ -0,0 +1,86 @@
+.\" This manpage is copyright (C) 1998 Branden Robinson <branden@debian.org>.
+.\"
+.\" This is free software; you may redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as
+.\" published by the Free Software Foundation; either version 2,
+.\" or (at your option) any later version.
+.\"
+.\" This is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with the Debian GNU/Linux system; if not, write to the Free
+.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+.\" 02111-1307 USA
+.TH xdm.options 5 "17 February 2000" "Debian GNU/Linux"
+.SH NAME
+xdm.options \- configuration options for X display manager
+.SH DESCRIPTION
+.I /etc/X11/xdm/xdm.options
+contains a set of flags that determine some of the behavior of the
+X display manager
+.BR xdm (1).
+.PP
+.I /etc/X11/xdm/xdm.options
+may contain comments, which begin with a hash mark and end at the next
+newline, just like comments in shell scripts.  The rest of the file
+consists of options which are expressed as words separated by hyphens,
+with only one option per line.  If an option is present with the "no-"
+prefix, or absent, it is disabled, otherwise it is considered enabled.
+.PP
+Available options are:
+.IP ignore-nologin
+Normally, the contents of the /etc/nologin file will be displayed using
+.BR xmessage (1)
+(if xmessage is available), and the user will be returned to the xdm login
+screen after the xmessage is dismissed.  If this option is enabled, xdm
+starts a session as usual (after the xmessage is dismissed, if xmessage
+is available).
+.IP restart-on-upgrade
+Enable this option with caution on "production" machines; it causes the
+xdm daemon to be stopped and restarted on upgrade, even if the process
+has children (which means it is managing X sessions).  Typically when
+a package that contains a daemon is being installed or upgraded, its
+maintainer scripts stop a running daemon process before installing the
+new binary, and restart it after the new binary is installed.  Stopping
+xdm causes immediate termination of any sessions it manages; in some
+situations this could be an unwelcome surprise (for instance, for remote
+xdm users who had no idea the administrator was performing system
+maintenance).  On the other hand, for machines that stay up for long
+periods of time, leaving the old daemon running can be a bad idea if
+the new version has, for instance, a fix for a security vulnerability
+(overwriting xdm's executable on the file system has no effect on the
+copy of xdm in memory).  The xdm pre-removal script checks to see if the
+xdm process has any children; if it does, it is possible that someone's
+session would be killed by stopping xdm, so a warning is issued and an
+opportunity to abort the upgrade of xdm is provided.  If this option is
+disabled (the Debian default), xdm will be not be stopped or started
+during an install or upgrade; the administrator will have to do so by
+hand (with "/etc/init.d/xdm restart", or by rebooting the system) before
+the newly installed xdm binary is used.
+.IP run-xconsole
+This option opens an
+.BR xconsole (1)
+client to catch messages that would normally go to the Linux virtual
+console and thus be missed in many cases by the user.  By default, this
+option is only supported in the Xsetup file for display :0
+.RI ( /etc/X11/xdm/Xsetup_0 ),
+but any Xsetup script may use it if appropriately edited.  This option is
+disabled by default because sensitive information may be made visible to
+untrusted people (anyone who can see the screen, since one does not have to be
+logged in to view the xdm greeter screen).  Before enabling this option, it is
+a good idea to check and/or modify the system log daemon configuration.
+.IP use-sessreg
+If this option is enabled (the Debian default), the sessreg program will
+be invoked to register X sessions managed by xdm in the utmp and wtmp
+files.  Otherwise, it is not, and the utmp and wtmp files will have no
+record of xdm sessions.
+.SH SEE ALSO
+.BR sessreg (1),
+.BR xconsole (1),
+.BR xmessage (1),
+.BR xdm (1)
+.SH AUTHOR
+This manpage was written by Branden Robinson for Debian GNU/Linux.
--- xfree86-1-3.3.6.orig/debian/xdm/Xservers
+++ xfree86-1-3.3.6/debian/xdm/Xservers
@@ -0,0 +1,23 @@
+# /etc/X11/xdm/Xservers
+#
+# This file should contain entries to start the servers on the local machine;
+# if you have more than one display (not screen), you can add entries to the
+# list (one per line).  If you also have some X terminals connected which do
+# not support XDMCP, you can add them here as well.  Each X terminal line
+# should look like:
+#	XTerminalName:0 foreign
+#
+# When adding X servers, please keep the following things in mind:
+# - For each X server other than :0, the display number must be on the command
+#   line.
+# - This is the place to add the -bpp option to the command line.
+# - It is wise to add the vtXX  option to each local X server, since this is
+#   the only sure way of knowing in advance which X server attaches to which
+#   console.
+# - See the Xserver(1) manpage for a description of the deferglyphs option.
+#
+# Example:
+# :0 local /usr/bin/X11/X :0 vt9 -bpp 16
+# :1 local /usr/bin/X11/X :1 vt10 -bpp 8
+#
+:0 local /usr/bin/X11/X vt7 -deferglyphs 16
--- xfree86-1-3.3.6.orig/debian/xdm/Xresources_0
+++ xfree86-1-3.3.6/debian/xdm/Xresources_0
@@ -0,0 +1,40 @@
+! /etc/X11/xdm/Xresources_0
+!
+! X resources used by xdm sessions on display :0
+xlogin*login.translations: #override\
+        Ctrl<Key>R: abort-display()\n\
+        <Key>Delete: delete-character()\n\
+        <Key>F1: set-session-argument(failsafe) finish-field()\n\
+        Ctrl<Key>Return: set-session-argument(failsafe) finish-field()\n\
+        <Key>Return: set-session-argument() finish-field()\n\
+        <Key>Left: move-backward-character()\n\
+        <Key>Right: move-forward-character()\n\
+        <Key>Home: move-to-begining()\n\
+        <Key>End: move-to-end()\n\
+        <Key>KP_Enter: set-session-argument() finish-field()
+xlogin*borderWidth: 3
+xlogin*greeting: Debian GNU/Linux (CLIENTHOST)
+xlogin*namePrompt: login:\ 
+xlogin*fail: Login incorrect
+#ifdef COLOR
+xlogin*greetColor: CadetBlue
+xlogin*failColor: red
+*Foreground: black
+*Background: #fffff0
+#else
+xlogin*Foreground: black
+xlogin*Background: white
+#endif
+
+XConsole.text.geometry:	480x130
+XConsole.verbose:	true
+XConsole*iconic:	true
+XConsole*font:		fixed
+
+Chooser*geometry:		700x500+300+200
+Chooser*allowShellResize:	false
+Chooser*viewport.forceBars:	true
+Chooser*label.font:		*-new century schoolbook-bold-i-normal-*-240-*
+Chooser*label.label:		XDMCP Host Menu  from CLIENTHOST
+Chooser*list.font:		-*-*-medium-r-normal-*-*-230-*-*-c-*-iso8859-1
+Chooser*Command.font:		*-new century schoolbook-bold-r-normal-*-180-*
--- xfree86-1-3.3.6.orig/debian/xdm/Xstartup
+++ xfree86-1-3.3.6/debian/xdm/Xstartup
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xstartup
+#
+# This script is run as root after the user logs in.
+# If this script exits with a return code other than 0, the user's
+# session will not be started.
+
+PATH=$PATH:/usr/bin/X11
+
+if grep -qs ^ignore-nologin /etc/X11/xdm/xdm.options; then
+  if [ -f /etc/nologin ]; then
+    if command -v xmessage > /dev/null 2>&1; then
+      xmessage -file /etc/nologin -geometry 640x480
+    fi
+  fi
+elif [ -f /etc/nologin ]; then
+  if command -v /usr/bin/X11/xmessage > /dev/null 2>&1; then
+    xmessage -file /etc/nologin -geometry 640x480
+  fi
+  exit 1
+fi
+
+# insert a utmp entry for the session
+if grep -qs ^use-sessreg /etc/X11/xdm/xdm.options; then
+  exec sessreg -a -l $DISPLAY -u /var/run/utmp -x /etc/X11/xdm/Xservers $USER
+  # NOTREACHED
+fi
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/conffiles
+++ xfree86-1-3.3.6/debian/xdm/conffiles
@@ -0,0 +1,13 @@
+/etc/X11/xdm/Xaccess
+/etc/X11/xdm/Xreset
+/etc/X11/xdm/Xreset_0
+/etc/X11/xdm/Xresources
+/etc/X11/xdm/Xresources_0
+/etc/X11/xdm/Xservers
+/etc/X11/xdm/Xsetup
+/etc/X11/xdm/Xsetup_0
+/etc/X11/xdm/Xstartup
+/etc/X11/xdm/Xstartup_0
+/etc/X11/xdm/xdm-config
+/etc/X11/xdm/xdm.options
+/etc/init.d/xdm
--- xfree86-1-3.3.6.orig/debian/xdm/postrm
+++ xfree86-1-3.3.6/debian/xdm/postrm
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Debian xdm package post-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xdm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove) ;;
+  purge)
+    update-rc.d xdm remove > /dev/null 2>&1
+    ;;
+  upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) exit 0 ;;
+esac
+
+if [ "$(echo /var/lib/xdm/*)" != "/var/lib/xdm/*" ]; then
+  rm -r /var/lib/xdm/*
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xdm/README.Debian
+++ xfree86-1-3.3.6/debian/xdm/README.Debian
@@ -0,0 +1,76 @@
+Debian README for xdm package
+
+Newcomers to the X Window System should first read the file
+/usr/share/doc/xfree86-common/FAQ.  It would also be helpful to read
+/usr/share/doc/xfree86-common/README.Debian.
+
+Upgraders from Debian GNU/Linux 2.0 or earlier should be aware that the
+/etc/X11/config file is no longer used; its xdm-specific options are now in
+/etc/X11/xdm/xdm.options.
+
+The default configuration for the X display manager (xdm) under Debian
+GNU/Linux presumes that one wishes xdm to manage one local session.  (In
+other words, the xdm login screen occupies one virtual console
+automatically at boot.)  If one does not wish to run a local X server, the
+following line should be commented out of /etc/X11/xdm/Xservers:
+
+:0 local /usr/bin/X11/X vt7 -deferglyphs 16
+
+Several configuration files are shipped with the xdm package; they reside
+in the /etc/X11/xdm/ directory.  Extensive documentation about the xdm
+configuration files may be found in the xdm(1) manual page.
+
+xdm-config contains X resources specific to xdm itself.  See the X(1)
+manual page for more information about X resources, and the xdm(1) manual
+pages for documentation of the available xdm resources.
+
+Xresources contains X resources that are designed to be specfic to sessions
+running under xdm.  Note that this file does not contain the resource entries
+for xdm itself -- those are contained in the file xdm-config.  See the X(1)
+manual page for more information about X resources.
+
+Xresources_0 contains X resources that are designed to be specific to sessions
+running under xdm on server :0.
+
+The above three files, despite being X resource files, are not placed in the
+/etc/X11/Xresources directory (see /usr/share/doc/xbase/README.Debian) because
+they should not be used automatically in all X sessions; the /etc/X11/Xsession
+script merges in the resources of all files found in /etc/X11/Xresources, and
+this action would be inappropriate for these resource files.
+
+Xservers contains entries to start the X server(s) on the local machine, and
+on any remote X terminals that do not support XDMCP.  This file is internally
+documented.
+
+Xaccess determines what hosts on the network may use the services of the
+running xdm daemon.  This file is internally documented.  Note that as of
+version 3.3.4-1 of the xdm package, all remote XDMCP access is turned off
+by default.
+
+Xsetup is a shell script which is run when xdm is asked to manage a server
+other than :0.
+
+Xsetup_0 is a shell script which is run when xdm is asked to manage server
+:0.
+
+Xstartup is a shell script which is run (as root) after a user has logged in
+on a server other than :0 (though by default it is called by Xstartup_0).
+
+Xstartup_0 is a shell script which is run (as root) after a user has logged
+in on server :0 (by default it merely calls Xstartup).
+
+Xreset is a shell script which is run (as root) after a user's X session
+ends on a server other than :0 (though by default it is called by
+Xreset_0).
+
+Xreset_0 is a shell script which is run (as root) after a user's X session
+ends on server :0 (by default it merely calls Xreset).
+
+xdm.options contains configuration options for xdm that are specific to the
+Debian GNU/Linux system.  See the xdm.options(5) manual page for more
+information.
+
+The X Display Manager Control Protocol document referenced in the xdm(1)
+manual page may be found in the xbooks package.
+
+Branden Robinson, 17 Feb 2000
--- xfree86-1-3.3.6.orig/debian/xdm/preinst
+++ xfree86-1-3.3.6/debian/xdm/preinst
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Debian xdm package pre-installation script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+maplink () {
+  # returns what symlink should point to
+  case "$1" in
+    /usr/X11R6/lib/X11/xdm/xdm-config) echo /etc/X11/xdm/xdm-config ;;
+  esac;
+}
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+trap "echo ;\
+      echo 'Received signal.  Aborting installation of xdm package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  install|upgrade) ;;
+  abort-upgrade) exit 0 ;;
+esac
+
+condecho=:
+
+# check symbolic link structure integrity
+for symlink in /usr/X11R6/lib/X11/xdm/xdm-config; do
+  if [ -L $symlink ]; then
+    if [ $(maplink $symlink) != $(readlink $symlink) ]; then
+      $condecho
+      echo "Warning: $symlink symbolic link points to the wrong"
+      echo "place.  Removing."
+      condecho=echo
+      rm $symlink
+    fi
+  elif [ -e $symlink ]; then
+    $condecho
+    echo "Warning: $symlink is not a symbolic link.  Moving to"
+    echo "$symlink.xdm-old."
+    condecho=echo
+    if [ ! -e $symlink.xdm-old ]; then
+      mv $symlink $symlink.xdm-old
+    else
+      $condecho
+      echo "ERROR: $symlink.xdm-old already exists!  Aborting"
+      echo "installation of xdm package.  Please clean up your crufty filesystem."
+      condecho=echo
+      exit 1
+    fi
+  fi
+done
+
+exit
--- xfree86-1-3.3.6.orig/debian/xdm/xdm-config
+++ xfree86-1-3.3.6/debian/xdm/xdm-config
@@ -0,0 +1,21 @@
+! /etc/X11/xdm/xdm-config
+!
+! resources specific to xdm itself
+DisplayManager.authDir:		/var/lib/xdm
+DisplayManager.errorLogFile:	/var/log/xdm.log
+DisplayManager.pidFile:		/var/run/xdm.pid
+DisplayManager.keyFile:		/etc/X11/xdm/xdm-keys
+DisplayManager.servers:		/etc/X11/xdm/Xservers
+DisplayManager.accessFile:	/etc/X11/xdm/Xaccess
+DisplayManager._0.authorize:	true
+DisplayManager._0.resources:	/etc/X11/xdm/Xresources_0
+DisplayManager._0.setup:	/etc/X11/xdm/Xsetup_0
+DisplayManager._0.startup:	/etc/X11/xdm/Xstartup_0
+DisplayManager._0.reset:	/etc/X11/xdm/Xreset_0
+DisplayManager*resources:	/etc/X11/xdm/Xresources
+DisplayManager*setup:		/etc/X11/xdm/Xsetup
+DisplayManager*startup:		/etc/X11/xdm/Xstartup
+DisplayManager*reset:		/etc/X11/xdm/Xreset
+DisplayManager*session:		/etc/X11/Xsession
+DisplayManager*userPath:	/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
+DisplayManager*systemPath:	/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
--- xfree86-1-3.3.6.orig/debian/xdm/Xresources
+++ xfree86-1-3.3.6/debian/xdm/Xresources
@@ -0,0 +1,40 @@
+! /etc/X11/xdm/Xresources
+!
+! X resources used by xdm sessions
+xlogin*login.translations: #override\
+	Ctrl<Key>R: abort-display()\n\
+	<Key>Delete: delete-character()\n\
+	<Key>F1: set-session-argument(failsafe) finish-field()\n\
+	Ctrl<Key>Return: set-session-argument(failsafe) finish-field()\n\
+	<Key>Return: set-session-argument() finish-field()\n\
+        <Key>Left: move-backward-character()\n\
+        <Key>Right: move-forward-character()\n\
+        <Key>Home: move-to-begining()\n\
+        <Key>End: move-to-end()\n\
+        <Key>KP_Enter: set-session-argument() finish-field()
+xlogin*borderWidth: 3
+xlogin*greeting: Debian GNU/Linux (CLIENTHOST)
+xlogin*namePrompt: login:\ 
+xlogin*fail: Login incorrect
+#ifdef COLOR
+xlogin*greetColor: CadetBlue
+xlogin*failColor: red
+*Foreground: black
+*Background: #fffff0
+#else
+xlogin*Foreground: black
+xlogin*Background: white
+#endif
+
+XConsole.text.geometry:	480x130
+XConsole.verbose:	true
+XConsole*iconic:	true
+XConsole*font:		fixed
+
+Chooser*geometry:		700x500+300+200
+Chooser*allowShellResize:	false
+Chooser*viewport.forceBars:	true
+Chooser*label.font:		*-new century schoolbook-bold-i-normal-*-240-*
+Chooser*label.label:		XDMCP Host Menu  from CLIENTHOST
+Chooser*list.font:		-*-*-medium-r-normal-*-*-230-*-*-c-*-iso8859-1
+Chooser*Command.font:		*-new century schoolbook-bold-r-normal-*-180-*
--- xfree86-1-3.3.6.orig/debian/xdm/Xreset
+++ xfree86-1-3.3.6/debian/xdm/Xreset
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xreset
+#
+# This script is run as root after any X session ends.
+
+# Remove the utmp entry for the session
+if grep -qs ^use-sessreg /etc/X11/xdm/xdm.options; then
+  sessreg -d -l $DISPLAY -u /var/run/utmp -x /etc/X11/xdm/Xservers $USER
+fi
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/Xsetup
+++ xfree86-1-3.3.6/debian/xdm/Xsetup
@@ -0,0 +1,7 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xsetup
+#
+# This script is run whenever xdm is asked to manage a display other than :0
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/prerm
+++ xfree86-1-3.3.6/debian/xdm/prerm
@@ -0,0 +1,93 @@
+#!/bin/sh
+# Debian xdm package pre-removal script
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+parseans () {
+  if [ ! $1 ]; then
+    echo $default
+  else
+    echo $1 | cut -c1 | tr '[A-Z]' '[a-z]';
+  fi;
+}
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of xdm package.' ;\
+      echo ;\
+      exit 1" 1 3 15
+
+trap "echo ;\
+      echo 'Received keyboard interrupt.  Not stopping xdm daemon.' ;\
+      echo 'To activate the new version of the xdm daemon, type the' ;\
+      echo 'command \"/etc/init.d/xdm restart\" at the shell prompt.' ;\
+      echo ;\
+      exit 0" 2
+
+case "$1" in
+  remove|upgrade|failed-upgrade|deconfigure)
+    # we NEVER want to stop xdm without doing some checks first, see below
+    ;;
+esac
+
+if [ "$1" = "remove" -o "$1" = "upgrade" ]; then
+  if [ -L /usr/doc/xdm ]; then
+    rm /usr/doc/xdm
+  fi
+fi
+
+condecho=:
+
+stop=
+# are we supposed to restart on upgrade?
+if grep -qs ^restart-on-upgrade /etc/X11/xdm/xdm.options; then
+  # is there an xdm process running?
+  if start-stop-daemon --stop --quiet --signal 0 --exec /usr/bin/X11/xdm; then
+    # any children?
+    parents=$(pidof /usr/bin/X11/xdm || true)
+    children=
+    for process in $parents; do
+      # make sure we got numbers back
+      if ! [ $process -eq $process ] 2> /dev/null; then
+        # freak out
+        echo "xdm.prerm: pidof returned non-numeric value!"
+        exit 1
+      fi
+      # we could use grep -q here if ps would ignore SIGPIPE :-P
+      if (ps axj | grep "^ *$process" > /dev/null 2>&1); then
+        children=yes
+      fi
+    done
+    if [ "$children" ]; then
+        $condecho
+        echo "WARNING: Preparing to stop X display manager (xdm) daemon, and it appears to be"
+        echo "managing at least one running session.  If xdm is stopped now, those sessions"
+        echo "will be terminated.  Otherwise you may leave xdm running, and the new version"
+        echo "will take effect the next time xdm is restarted."
+        echo
+        condecho=echo
+        default=n
+        echo -n "Do you wish to stop the xdm daemon? (y/n) [$default] "
+        read answer
+        answer=$(parseans $answer)
+        case "$answer" in
+          y) stop=yes ;;
+          n) ;;
+          *) echo "\"$answer\" not understood.  Using default of \"$default\"." ;;
+        esac
+    else
+      stop=yes
+    fi
+  fi
+fi
+
+if [ "$stop" ]; then
+  /etc/init.d/xdm stop || true
+else
+  touch /var/run/xdm.upgrade
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/xdm/xdm.options
+++ xfree86-1-3.3.6/debian/xdm/xdm.options
@@ -0,0 +1,9 @@
+# /etc/X11/xdm.options
+#
+# configuration options for xdm
+# See xdm.options(5) for an explanation of the available options.
+
+no-ignore-nologin
+no-restart-on-upgrade
+no-run-xconsole
+use-sessreg
--- xfree86-1-3.3.6.orig/debian/xdm/postinst
+++ xfree86-1-3.3.6/debian/xdm/postinst
@@ -0,0 +1,132 @@
+#!/bin/sh
+# Debian xdm package post-installation script
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+cleanup () {
+  # unroll changes in xdm preinst
+  for file in /usr/X11R6/lib/X11/xdm/xdm-config; do
+    if [ -e $file.xdm-old ]; then
+      rm $file
+      mv $file.xdm-old $file
+    fi
+  done
+  /etc/init.d/xdm start
+}
+
+# TODO comment out these two functions for stable release
+maplink () {
+  # returns what symlink should point to
+  case "$1" in
+    /usr/X11R6/lib/X11/xdm/xdm-config) echo /etc/X11/xdm/xdm-config ;;
+  esac;
+}
+
+readlink () {
+  # perl kludge until readlink(1) from tetex-bin is moved into an essential package
+  # returns what symlink actually points to
+  perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' $1;
+}
+
+trap "echo ;\
+      echo 'Received signal.  Aborting configuration of xdm package.' ;\
+      echo -n 'Cleaning up...' ;\
+      cleanup ;\
+      echo 'done.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  configure) ;;
+  abort-upgrade|abort-remove|abort-deconfigure)
+    cleanup
+    exit 0 ;;
+  *)
+    echo "ERROR: xdm postinst called with unknown argument \"$1\"."
+    echo "Aborting configuration of xdm package."
+    echo -n "Cleaning up..."
+    cleanup
+    echo "done."
+    exit 1 ;;
+esac
+
+condecho=:
+
+# TODO sanity checks -- comment out these for stable release
+for symlink in /usr/X11R6/lib/X11/xdm/xdm-config; do
+  if [ -L $symlink ]; then
+    if [ $(maplink $symlink) != $(readlink $symlink) ]; then
+      $condecho
+      echo "ERROR: $symlink symbolic link points to the wrong"
+      echo "place.  Please report this message to <xdm@packages.debian.org>."
+      condecho=echo
+    fi
+  elif [ -e $symlink ]; then
+    $condecho
+    echo "ERROR: $symlink is not a symbolic link."
+    echo "Please report this message to <xdm@packages.debian.org>."
+    condecho=echo
+  else
+    $condecho
+    echo "ERROR: $symlink symbolic link does not exist."
+    echo "Please report this message to <xdm@packages.debian.org>."
+    condecho=echo
+  fi
+done
+
+if [ -d /usr/doc -a ! -e /usr/doc/xdm -a -d /usr/share/doc/xdm ]; then
+  ln -sf ../share/doc/xdm /usr/doc/xdm
+fi
+
+# deal with a bug in very old versions of xbase
+for dir in rc0.d rc1.d rc6.d; do
+  if [ -L etc/$dir/K1xdm ]; then
+    mv /etc/$dir/K1xdm /etc/$dir/K01xdm
+  fi
+done
+
+nostart=
+xdm_running=
+# don't start xdm if we are upgrading without stopping it
+if [ -e /var/run/xdm.upgrade ]; then
+  nostart=yes
+fi
+# or if we're currently in X on the display it attempts to manage by default
+for hostname in "" "localhost" "$(hostname)" "$(hostname -f)"; do
+  if echo $DISPLAY | grep -q "^$hostname:0.*"; then
+    nostart=yes
+  fi
+done
+# or if it's already running
+if start-stop-daemon --stop --quiet --signal 0 --pid /var/run/xdm.pid --exec /usr/bin/X11/xdm; then
+  nostart=yes
+  xdm_running=yes
+fi
+# or if the options file says not to
+if ! grep -qs ^restart-on-upgrade /etc/X11/xdm/xdm.options; then
+  nostart=yes
+fi
+
+update-rc.d xdm defaults 99 01 > /dev/null 2>&1
+
+if [ "$xdm_running" ]; then
+  if [ -d /var/state/xdm ]; then
+    $condecho
+    echo "Note: obsolete directory /var/state/xdm cannot be removed because xdm is still"
+    echo "running.  Reinstall the xdm package (or remove the directory manually) when xdm"
+    echo "is not running."
+    condecho=echo
+  fi
+else
+  if [ -d /var/state/xdm ]; then
+    rm -r /var/state/xdm
+  fi
+fi
+
+[ "$nostart" ] || /etc/init.d/xdm start || true
+
+exit
--- xfree86-1-3.3.6.orig/debian/xdm/Xaccess
+++ xfree86-1-3.3.6/debian/xdm/Xaccess
@@ -0,0 +1,67 @@
+# /etc/X11/xdm/Xaccess
+#
+# access control file for XDMCP connections
+#
+# To control Direct and Broadcast access:
+#
+#	pattern
+#
+# To control Indirect queries:
+#
+# 	pattern		list of hostnames and/or macros ...
+#
+# To use the chooser:
+#
+#	pattern		CHOOSER BROADCAST
+#
+# or
+#
+#	pattern		CHOOSER list of hostnames and/or macros ...
+#
+# To define macros:
+#
+#       %name		list of hosts ...
+#
+# The first form tells xdm which displays to respond to itself.
+# The second form tells xdm to forward indirect queries from hosts matching
+# the specified pattern to the indicated list of hosts.
+# The third form tells xdm to handle indirect queries using the chooser;
+# the chooser is directed to send its own queries out via the broadcast
+# address and display the results on the terminal.
+# The fourth form is similar to the third, except instead of using the
+# broadcast address, it sends DirectQuerys to each of the hosts in the list
+#
+# In all cases, xdm uses the first entry which matches the terminal;
+# for IndirectQuery messages only entries with right hand sides can
+# match, for Direct and Broadcast Query messages, only entries without
+# right hand sides can match.
+#
+
+#*					#any host can get a login window
+
+#
+# To hardwire a specific terminal to a specific host, you can
+# leave the terminal sending indirect queries to this host, and
+# use an entry of the form:
+#
+
+#terminal-a	host-a
+
+#
+# The nicest way to run the chooser is to just ask it to broadcast
+# requests to the network - that way new hosts show up automatically.
+# Sometimes, however, the chooser can't figure out how to broadcast,
+# so this may not work in all environments.
+#
+
+#*		CHOOSER BROADCAST	#any indirect host can get a chooser
+
+#
+# If you'd prefer to configure the set of hosts each terminal sees,
+# then just uncomment these lines (and comment the CHOOSER line above)
+# and edit the %hostlist line as appropriate
+#
+
+#%hostlist	host-a host-b
+
+#*		CHOOSER %hostlist	#
--- xfree86-1-3.3.6.orig/debian/xdm/Xreset_0
+++ xfree86-1-3.3.6/debian/xdm/Xreset_0
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xreset_0
+#
+# This script is run as root after the session on :0 ends.
+
+# Call the global Xreset script, if it exists
+if [ -x /etc/X11/xdm/Xreset ]; then
+  /etc/X11/xdm/Xreset
+fi
+
+# :0 specific reset commands go here
+if [ -e /var/run/xconsole_0.pid ]; then
+  pid=$(cat /var/run/xconsole_0.pid 2> /dev/null)
+  if [ "$pid" ]; then
+    kill $pid 2> /dev/null
+  fi
+  rm /var/run/xconsole_0.pid
+fi
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/init
+++ xfree86-1-3.3.6/debian/xdm/init
@@ -0,0 +1,90 @@
+#!/bin/sh
+# /etc/init.d/xdm: start or stop the X display manager
+
+set -e
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+DAEMON=/usr/bin/X11/xdm
+PIDFILE=/var/run/xdm.pid
+UPGRADEFILE=/var/run/xdm.upgrade
+
+test -x $DAEMON || exit 0
+
+stillrunning () {
+  if [ "$DAEMON" = "$(cat /proc/$DAEMONPID/cmdline 2> /dev/null)" ]; then
+    true
+  else
+    # if the daemon does not remove its own pidfile, we will
+    rm -f $PIDFILE $UPGRADEFILE
+    false
+  fi;
+}
+
+case "$1" in
+  start)
+    echo -n "Starting X display manager: xdm"
+    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON || echo -n " already running"
+    echo "."
+  ;;
+
+  restart)
+    /etc/init.d/xdm stop
+    if [ -f $PIDFILE ]; then
+      if stillrunning; then
+        exit 1
+      fi
+    fi
+    /etc/init.d/xdm start
+  ;;
+
+  reload)
+    echo -n "Reloading X display manager configuration..."
+    if start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --exec $DAEMON; then
+      echo "done."
+    else
+      echo "xdm not running."
+    fi
+  ;;
+
+  force-reload)
+    /etc/init.d/xdm reload
+  ;;
+
+  stop)
+    echo -n "Stopping X display manager: xdm"
+    if [ ! -f $PIDFILE ]; then
+      echo " not running (no $PIDFILE)."
+      exit 0
+    else
+      DAEMONPID=$(cat $PIDFILE | tr -d '[:blank:]')
+      KILLCOUNT=1
+      if [ ! -e $UPGRADEFILE ]; then
+        start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON || echo -n " not running"
+      fi
+      while [ $KILLCOUNT -le 5 ]; do
+        if stillrunning; then
+          kill $DAEMONPID
+        else
+          break
+        fi
+        sleep 1
+        KILLCOUNT=$(expr $KILLCOUNT + 1)
+      done
+      if stillrunning; then
+        echo -n " not responding to TERM signal (pid $DAEMONPID)"
+      else
+        if [ -e $UPGRADEFILE ]; then
+          rm $UPGRADEFILE
+        fi
+      fi
+    fi
+    echo "."
+  ;;
+
+  *)
+    echo "Usage: /etc/init.d/xdm {start|stop|restart|reload|force-reload}"
+    exit 1
+    ;;
+esac
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/Xsetup_0
+++ xfree86-1-3.3.6/debian/xdm/Xsetup_0
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xsetup_0
+#
+# This script is run whenever xdm is asked to manage a display on :0
+
+sysmodmap=/etc/X11/Xmodmap
+
+if grep -qs ^run-xconsole /etc/X11/xdm/xdm.options; then
+  if [ -e /var/run/xconsole_0.pid ]; then
+    # kill any running xconsole
+    pid=$(cat /var/run/xconsole_0.pid 2> /dev/null)
+    if [ "$pid" ]; then
+      kill $pid 2> /dev/null
+    fi
+    rm /var/run/xconsole_0.pid
+  fi
+  # start fresh xconsole and store its PID
+  xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed \
+   -exitOnFail -file /dev/xconsole &
+  echo $! > /var/run/xconsole_0.pid
+fi
+
+if [ -x /usr/bin/X11/xmodmap ]; then
+  if [ -f $sysmodmap ]; then
+    xmodmap $sysmodmap
+  fi
+fi
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/xdm/Xstartup_0
+++ xfree86-1-3.3.6/debian/xdm/Xstartup_0
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# /etc/X11/xdm/Xstartup_0
+#
+# This script is run as root after a user starts a session on :0.
+
+set -e
+
+# Call the global Xstartup script, if it exists
+if [ -x /etc/X11/xdm/Xstartup ]; then
+  /etc/X11/xdm/Xstartup || exit $?
+fi
+
+# :0 specific startup commands go here
+
+exit 0
--- xfree86-1-3.3.6.orig/debian/create-arch-xserver-common
+++ xfree86-1-3.3.6/debian/create-arch-xserver-common
@@ -0,0 +1,303 @@
+#!/bin/sh
+# Copyright 1998-2000 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xserver-common
+
+umask 022
+
+rm -rf $temp
+
+# This case is unlike the ones in the other create-* files because we do
+# not ship everything by default; every arch is different.  We also bomb
+# out on an unknown arch because this package is so hardware-dependent.
+
+case "$arch" in
+  alpha)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/AccelCards \
+               $tree/usr/X11R6/lib/X11/doc/Devices \
+               $tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/README.clkprog \
+               $tree/usr/X11R6/lib/X11/doc/README.mouse \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.3DLabs \
+                      $tree/usr/X11R6/lib/X11/doc/README.DECtga \
+                      $tree/usr/X11R6/lib/X11/doc/README.I128 \
+                      $tree/usr/X11R6/lib/X11/doc/README.MGA \
+                      $tree/usr/X11R6/lib/X11/doc/README.Mach64 \
+                      $tree/usr/X11R6/lib/X11/doc/README.P9000 \
+                      $tree/usr/X11R6/lib/X11/doc/README.S3 \
+                      $tree/usr/X11R6/lib/X11/doc/README.S3V \
+                      $tree/usr/X11R6/lib/X11/doc/README.fbdev \
+                      $tree/usr/X11R6/lib/X11/doc/README.trident"
+    clock_example_doc=$tree/usr/X11R6/lib/X11/etc/et4000clock.c
+    exec_files="$tree/usr/X11R6/bin/SuperProbe \
+                $tree/usr/X11R6/bin/reconfig \
+                $tree/usr/X11R6/bin/scanpci \
+                $tree/usr/X11R6/bin/xf86config"
+    superprobe_man=$tree/usr/X11R6/man/man1/SuperProbe.1x
+    reconfig_man=$tree/usr/X11R6/man/man1/reconfig.1x
+    xf86config_man=$tree/usr/X11R6/man/man1/xf86config.1x
+    cards=$tree/usr/X11R6/lib/X11/Cards
+    shlibdep_files="$temp/usr/X11R6/bin/SuperProbe \
+                    $temp/usr/X11R6/bin/X \
+                    $temp/usr/X11R6/bin/reconfig \
+                    $temp/usr/X11R6/bin/scanpci \
+                    $temp/usr/X11R6/bin/xf86config"
+    banner_dir=
+    ;;
+  arm)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/README.mouse \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.fbdev"
+    clock_example_doc=
+    exec_files=
+    superprobe_man=
+    reconfig_man=
+    xf86config_man=
+    cards=
+    shlibdep_files=$temp/usr/X11R6/bin/X
+    banner_dir=
+    ;;
+  i[34]86)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/AccelCards \
+               $tree/usr/X11R6/lib/X11/doc/Devices \
+               $tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/README.clkprog \
+               $tree/usr/X11R6/lib/X11/doc/README.mouse \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.3DLabs \
+                      $tree/usr/X11R6/lib/X11/doc/README.I128 \
+                      $tree/usr/X11R6/lib/X11/doc/README.MGA \
+                      $tree/usr/X11R6/lib/X11/doc/README.Mach32 \
+                      $tree/usr/X11R6/lib/X11/doc/README.Mach64 \
+                      $tree/usr/X11R6/lib/X11/doc/README.NVIDIA \
+                      $tree/usr/X11R6/lib/X11/doc/README.Oak \
+                      $tree/usr/X11R6/lib/X11/doc/README.P9000 \
+                      $tree/usr/X11R6/lib/X11/doc/README.S3 \
+                      $tree/usr/X11R6/lib/X11/doc/README.S3V \
+                      $tree/usr/X11R6/lib/X11/doc/README.SiS \
+                      $tree/usr/X11R6/lib/X11/doc/README.Video7 \
+                      $tree/usr/X11R6/lib/X11/doc/README.W32 \
+                      $tree/usr/X11R6/lib/X11/doc/README.WstDig \
+                      $tree/usr/X11R6/lib/X11/doc/README.agx \
+                      $tree/usr/X11R6/lib/X11/doc/README.apm \
+                      $tree/usr/X11R6/lib/X11/doc/README.ark \
+                      $tree/usr/X11R6/lib/X11/doc/README.ati \
+                      $tree/usr/X11R6/lib/X11/doc/README.chips \
+                      $tree/usr/X11R6/lib/X11/doc/README.cirrus \
+                      $tree/usr/X11R6/lib/X11/doc/README.cyrix \
+                      $tree/usr/X11R6/lib/X11/doc/README.epson \
+                      $tree/usr/X11R6/lib/X11/doc/README.fbdev \
+                      $tree/usr/X11R6/lib/X11/doc/README.i740 \
+                      $tree/usr/X11R6/lib/X11/doc/README.i810 \
+                      $tree/usr/X11R6/lib/X11/doc/README.neo \
+                      $tree/usr/X11R6/lib/X11/doc/README.r128 \
+                      $tree/usr/X11R6/lib/X11/doc/README.rendition \
+                      $tree/usr/X11R6/lib/X11/doc/README.trident \
+                      $tree/usr/X11R6/lib/X11/doc/README.tseng"
+    clock_example_doc=$tree/usr/X11R6/lib/X11/etc/et4000clock.c
+    exec_files="$tree/usr/X11R6/bin/SuperProbe \
+                $tree/usr/X11R6/bin/reconfig \
+                $tree/usr/X11R6/bin/scanpci \
+                $tree/usr/X11R6/bin/xf86config"
+    superprobe_man=$tree/usr/X11R6/man/man1/SuperProbe.1x
+    reconfig_man=$tree/usr/X11R6/man/man1/reconfig.1x
+    xf86config_man=$tree/usr/X11R6/man/man1/xf86config.1x
+    cards=$tree/usr/X11R6/lib/X11/Cards
+    shlibdep_files="$temp/usr/X11R6/bin/SuperProbe \
+                    $temp/usr/X11R6/bin/X \
+                    $temp/usr/X11R6/bin/reconfig \
+                    $temp/usr/X11R6/bin/scanpci \
+                    $temp/usr/X11R6/bin/xf86config"
+    banner_dir=
+    ;;
+  m68k)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/README.mouse \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.fbdev"
+    clock_example_doc=
+    exec_files=
+    superprobe_man=
+    reconfig_man=
+    xf86config_man=
+    cards=
+    shlibdep_files=$temp/usr/X11R6/bin/X
+    banner_dir=
+    ;;
+  powerpc)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/README.mouse \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.fbdev"
+    clock_example_doc=
+    exec_files=
+    superprobe_man=
+    reconfig_man=
+    xf86config_man=
+    cards=
+    shlibdep_files=$temp/usr/X11R6/bin/X
+    banner_dir=
+    ;;
+  sparc)
+    doc_files="$tree/usr/X11R6/lib/X11/doc/Monitors \
+               $tree/usr/X11R6/lib/X11/doc/QuickStart.doc \
+               $tree/usr/X11R6/lib/X11/doc/README \
+               $tree/usr/X11R6/lib/X11/doc/README.Config \
+               $tree/usr/X11R6/lib/X11/doc/README.DGA \
+               $tree/usr/X11R6/lib/X11/doc/README.Linux \
+               $tree/usr/X11R6/lib/X11/doc/RELNOTES \
+               $tree/usr/X11R6/lib/X11/doc/xinput"
+    server_doc_files="$tree/usr/X11R6/lib/X11/doc/README.Mach64"
+    clock_example_doc=
+    exec_files="$tree/usr/X11R6/bin/SuperProbe \
+                $tree/usr/X11R6/bin/constype \
+                $tree/usr/X11R6/bin/reconfig \
+                $tree/usr/X11R6/bin/scanpci"
+    superprobe_man=$tree/usr/X11R6/man/man1/SuperProbe.1x
+    reconfig_man=$tree/usr/X11R6/man/man1/reconfig.1x
+    xf86config_man=
+    cards=$tree/usr/X11R6/lib/X11/Cards
+    shlibdep_files="$temp/usr/X11R6/bin/SuperProbe \
+                    $temp/usr/X11R6/bin/X \
+                    $temp/usr/X11R6/bin/constype \
+                    $temp/usr/X11R6/bin/reconfig \
+                    $temp/usr/X11R6/bin/scanpci"
+    banner_dir=$temp/etc/X11/banner
+    ;;
+  *)
+    echo "Unknown architecture passed to create-xserver-common."
+    exit 1
+    ;;
+esac
+
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xserver-common/examples \
+         $temp/etc/X11/xserver \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/lib/X11/xserver \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/X11R6/man/man5 \
+         $temp/usr/share/man/man8 \
+         $temp/usr/sbin
+
+ln -s /etc/X11/xserver/SecurityPolicy $temp/usr/X11R6/lib/X11/xserver/SecurityPolicy
+ln -s /etc/X11/XF86Config $temp/usr/X11R6/lib/X11/XF86Config
+
+# Debian documentation
+cp debian/changelog $temp/usr/share/doc/xserver-common/changelog.Debian
+if [ "$doc_files" ]; then
+  cp $doc_files $temp/usr/share/doc/xserver-common/
+fi
+if [ "$server_doc_files" ]; then
+  cp $server_doc_files $temp/usr/share/doc/xserver-common/
+fi
+find $temp/usr/share/doc/xserver-common -type f | xargs gzip -9
+cp debian/copyright $temp/usr/share/doc/xserver-common/
+cp debian/xserver-common/README.Debian $temp/usr/share/doc/xserver-common/
+
+cp debian/xserver-common/XF86Config.eg $temp/usr/share/doc/xserver-common/examples/
+if [ "$clock_example_doc" ]; then
+  cp $clock_example_doc $temp/usr/share/doc/xserver-common/examples
+fi
+
+# executables
+if [ "$exec_files" ]; then
+  cp $exec_files $temp/usr/X11R6/bin/
+  strip $temp/usr/X11R6/bin/*
+fi
+cp debian/xserver-common/xserver-configure $temp/usr/sbin/
+cp $tree/usr/X11R6/bin/X $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/X
+
+# manual pages
+cp $superprobe_man \
+   $tree/usr/X11R6/man/man1/XFree86.1x \
+   $tree/usr/X11R6/man/man1/Xserver.1x \
+   $reconfig_man \
+   $xf86config_man \
+   $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/*
+cp debian/xserver-common/xserver-configure.8 $temp/usr/share/man/man8/
+gzip -9 $temp/usr/share/man/man8/*
+for binary_file in constype scanpci; do
+  if [ -e $temp/usr/X11R6/bin/$binary_file ]; then
+    ln -s ../../../share/man/man7/undocumented.7.gz $temp/usr/X11R6/man/man1/$binary_file.1x.gz
+  fi
+done
+cp $tree/usr/X11R6/man/man5/XF86Config.5x $temp/usr/X11R6/man/man5/
+gzip -9 $temp/usr/X11R6/man/man5/*
+
+# library files
+cp $cards \
+   $tree/usr/X11R6/lib/X11/rgb.txt \
+   $temp/usr/X11R6/lib/X11/
+
+# configuration files
+cp $tree/usr/X11R6/lib/X11/xserver/SecurityPolicy $temp/etc/X11/xserver/
+if [ "$banner_dir" ]; then
+  mkdir -p $banner_dir
+  for bannerfile in XBanner1.ras XBannerG.ras XBanner8.ras; do
+    uudecode < debian/xserver-common/"$bannerfile".uu -o $temp/etc/X11/banner/$bannerfile
+    echo /etc/X11/banner/$bannerfile >> $temp/DEBIAN/conffiles
+    chmod 644 $temp/etc/X11/banner/*
+  done
+fi
+
+# package system files
+if [ -e $temp/DEBIAN/conffiles ]; then
+  cat debian/xserver-common/conffiles >> $temp/DEBIAN/conffiles
+else
+  cp debian/xserver-common/conffiles $temp/DEBIAN/
+fi
+for FILE in postinst postrm preinst prerm; do
+  if [ -e debian/xserver-common/$FILE ]; then
+    cp debian/xserver-common/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxserver-common $shlibdep_files
+
+dpkg-gencontrol -isp -P$temp -pxserver-common
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/create-indep-xbase
+++ xfree86-1-3.3.6/debian/create-indep-xbase
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xbase
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xbase \
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xbase/
+cp debian/changelog $temp/usr/share/doc/xbase/changelog.Debian
+gzip -9 $temp/usr/share/doc/xbase/changelog.Debian
+cp debian/xfree86-common/README.Debian-upgrade $temp/usr/share/doc/xbase/README.Debian
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xbase/$FILE ]; then
+    cp debian/xbase/$FILE $temp/DEBIAN/
+  fi
+done
+
+dpkg-gencontrol -isp -P$temp -pxbase
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/prerm.template
+++ xfree86-1-3.3.6/debian/prerm.template
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Debian FOO package pre-removal script
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+trap "echo ;\
+      echo 'Received signal.  Aborting removal of FOO package.' ;\
+      echo ;\
+      exit 1" 1 2 3 15
+
+case "$1" in
+  remove) ;;
+  upgrade|failed-upgrade|deconfigure) exit 0 ;;
+esac
+
+if [ -L /usr/doc/FOO ]; then
+  rm /usr/doc/FOO
+fi
+
+exit
--- xfree86-1-3.3.6.orig/debian/libc5.xfree86.cf.diff
+++ xfree86-1-3.3.6/debian/libc5.xfree86.cf.diff
@@ -0,0 +1,11 @@
+--- xc/config/cf/xfree86.cf.orig	Tue Dec  7 16:38:40 1999
++++ xc/config/cf/xfree86.cf	Tue Dec  7 16:39:05 1999
+@@ -1201,7 +1201,7 @@
+ #ifdef UseInstalled
+ #define DefaultCCOptions /* -ansi */
+ #else
+-#define DefaultCCOptions -ansi -pedantic
++#define DefaultCCOptions -ansi
+ #endif
+ #endif
+ #if defined(UseInstalled) || XF86LinkKit
--- xfree86-1-3.3.6.orig/debian/copyright
+++ xfree86-1-3.3.6/debian/copyright
@@ -0,0 +1,192 @@
+This package is part of the Debian pre-packaged version of XFree86
+release 3.3.6.
+
+Version 3.3.6 was assembled by Branden Robinson <branden@debian.org> from:
+ftp://ftp.xfree86.org/pub/xfree86/3.3.6/source/X336src-1.tgz
+
+Unless otherwise noted, all modifications and additions to XFree86 found in
+Debian packages bear the following copyright:
+
+Copyright 1996-2000 Software in the Public Interest, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+SOFTWARE IN THE PUBLIC INTEREST, INC.  BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Software in the Public
+Interest, Inc. shall not be used in advertising or otherwise to promote the
+sale, use or other dealings in this Software without prior written
+authorization from Software in the Public Interest, Inc.
+
+********************************************************************************
+
+1.  XFree86 Copyright
+
+XFree86 code without an explicit copyright is covered by the following copy-
+right:
+
+Copyright (C) 1994-1998 The XFree86 Project, Inc.  All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the XFree86 Project shall not
+be used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the XFree86 Project.
+
+2.  Other Copyrights
+
+Portions of code are covered by the following copyrights:
+
+2.1  X Consortium
+
+Copyright (C) 1996 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X
+CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings in
+this Software without prior written authorization from the X Consortium.
+
+X Window System is a trademark of X Consortium, Inc.
+
+2.2  Berkeley-based copyrights:
+
+2.2.1  General
+
+Redistribution and use in source and binary forms, with or without modifica-
+tion, 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.  The name of the author may not be used to endorse or promote products
+      derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
+CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT
+SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEM-
+PLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTER-
+RUPTION) 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.
+
+2.2.2  UCB/LBL
+
+Copyright (c) 1993 The Regents of the University of California.  All rights
+reserved.
+
+This software was developed by the Computer Systems Engineering group at
+Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and contributed to
+Berkeley.
+
+All advertising materials mentioning features or use of this software must dis-
+play the following acknowledgement: This product includes software developed by
+the University of California, Lawrence Berkeley Laboratory.
+
+Redistribution and use in source and binary forms, with or without modifica-
+tion, 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.  All advertising materials mentioning features or use of this software
+      must display the following acknowledgement: This product includes soft-
+      ware developed by the University of California, Berkeley and its contrib-
+      utors.
+
+  4.  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 WAR-
+RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDI-
+RECT, 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 LIA-
+BILITY, 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.
+
+2.3  NVidia Corp
+
+Copyright (c) 1996-1998 NVIDIA, Corp.  All rights reserved.
+
+NOTICE TO USER: The source code is copyrighted under U.S. and international
+laws.  NVIDIA, Corp. of Sunnyvale, California owns the copyright and as design
+patents pending on the design and interface of the NV chips.  Users and posses-
+sors of this source code are hereby granted a nonexclusive, royalty-free copy-
+right and design patent license to use this code in individual and commercial
+software.
+
+Any use of this source code must include, in the user documentation and inter-
+nal comments to the code, notices to the end user as follows:
+
+Copyright (c) 1996-1998 NVIDIA, Corp.  NVIDIA design patents pending in the
+U.S. and foreign countries.
+
+NVIDIA, CORP.  MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
+CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WAR-
+RANTY OF ANY KIND.  NVIDIA, CORP. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA, CORP.  BE LIABLE FOR ANY
+SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSO-
+EVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.
--- xfree86-1-3.3.6.orig/debian/create-arch-xnest
+++ xfree86-1-3.3.6/debian/create-arch-xnest
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Copyright 1998, 1999 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
+
+set -e
+
+. debian/scripts/xtree
+. debian/scripts/archmap
+temp=debian/tmp/xnest
+
+umask 022
+
+rm -rf $temp
+mkdir -p $temp/DEBIAN \
+         $temp/usr/share/doc/xnest \
+         $temp/usr/X11R6/bin \
+         $temp/usr/X11R6/man/man1 \
+         $temp/usr/lib/menu
+
+# Debian documentation
+cp debian/copyright $temp/usr/share/doc/xnest/
+cp debian/changelog $temp/usr/share/doc/xnest/changelog.Debian
+gzip -9 $temp/usr/share/doc/xnest/changelog.Debian
+
+# executables
+cp $tree/usr/X11R6/bin/Xnest $temp/usr/X11R6/bin/
+strip $temp/usr/X11R6/bin/Xnest
+
+# manual pages
+cp $tree/usr/X11R6/man/man1/Xnest.1x $temp/usr/X11R6/man/man1/
+gzip -9 $temp/usr/X11R6/man/man1/Xnest.1x
+
+# package system files
+for FILE in conffiles postinst postrm preinst prerm; do
+  if [ -e debian/xnest/$FILE ]; then
+    cp debian/xnest/$FILE $temp/DEBIAN/
+  fi
+done
+
+env LD_PRELOAD= dpkg-shlibdeps -pxnest $temp/usr/X11R6/bin/Xnest
+dpkg-gencontrol -isp -P$temp -pxnest
+
+chown -R root.root $temp
+chmod -R a-s $temp
+
+dpkg --build $temp ..
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-08-s3savage_ix+mx
+++ xfree86-1-3.3.6/debian/patches/0000fix-08-s3savage_ix+mx
@@ -0,0 +1,1999 @@
+--- xc/programs/Xserver/hw/xfree86/etc/scanpci.c.336	Fri Dec  3 10:43:47 1999
++++ xc/programs/Xserver/hw/xfree86/etc/scanpci.c	Mon Jul 17 11:51:20 2000
+@@ -1253,10 +1253,15 @@
+                             { 0x8A13, "Trio3D/2X", NF },
+                             { 0x8A20, "Savage3D", NF },
+                             { 0x8A21, "Savage3D S3 (Macrovision Support)", NF },
++                            { 0x8A25, "Savage/NB", NF },
+                             { 0x8A22, "Savage4", NF },
+                             { 0x8C01, "ViRGE/MX", NF },
+                             { 0x8C02, "ViRGE/MX+", NF },
+                             { 0x8C03, "ViRGE/MX+MV", NF },
++                            { 0x8C10, "Savage/MX-MV", NF },
++                            { 0x8C11, "Savage/MX", NF },
++                            { 0x8C12, "Savage/IX-MV", NF },
++                            { 0x8C13, "Savage/IX", NF },
+                             { 0x9102, "Savage2000", NF },
+                             { 0x0000, (char *)NULL, NF } } },
+         { 0x8086, "Intel", {
+--- xc/programs/Xserver/hw/xfree86/vga256/vga/vgaPCI.h.336	Sat Jan  8 19:27:07 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/vga/vgaPCI.h	Mon Jul 17 11:56:42 2000
+@@ -288,6 +288,11 @@
+ #define PCI_CHIP_SAVAGE3D_M	0x8A21
+ #define PCI_CHIP_SAVAGE4	0x8A22
+ #define PCI_CHIP_SAVAGE2000	0x9102
++#define PCI_CHIP_SAVAGE_MX_MV	0x8C10
++#define PCI_CHIP_SAVAGE_MX	0x8C11
++#define PCI_CHIP_SAVAGE_IX_MV	0x8C12
++#define PCI_CHIP_SAVAGE_IX	0x8C13
++#define PCI_CHIP_SAVAGE_370	0x8A25
+ #define PCI_CHIP_868		0x8880
+ #define PCI_CHIP_928		0x88B0
+ #define PCI_CHIP_864_0		0x88C0
+@@ -589,6 +594,11 @@
+ 				{PCI_CHIP_SAVAGE3D_M,	"Savage3D (Macrovision Support)"},
+ 				{PCI_CHIP_SAVAGE4,	"Savage4"},
+ 				{PCI_CHIP_SAVAGE2000,	"Savage2000"},
++				{PCI_CHIP_SAVAGE_MX_MV,	"Savage/MX-MV"},
++				{PCI_CHIP_SAVAGE_MX,	"Savage/MX"},
++				{PCI_CHIP_SAVAGE_IX_MV,	"Savage/IX-MV"},
++				{PCI_CHIP_SAVAGE_IX,	"Savage/IX"},
++				{PCI_CHIP_SAVAGE_370,	"Savage/NB"},
+ 				{PCI_CHIP_868,		"868"},
+ 				{PCI_CHIP_928,		"928"},
+ 				{PCI_CHIP_864_0,	"864"},
+--- xc/programs/Xserver/hw/xfree86/SuperProbe/PCI.h.336	Thu Nov 18 16:52:49 1999
++++ xc/programs/Xserver/hw/xfree86/SuperProbe/PCI.h	Mon Jul 17 17:11:25 2000
+@@ -362,6 +362,12 @@
+ #define PCI_CHIP_SAVAGE3D_M	0x8A21
+ #define PCI_CHIP_SAVAGE4	0x8A22
+ #define PCI_CHIP_SAVAGE2000	0x9102
++#define PCI_CHIP_SAVAGE_MX_MV	0x8C10
++#define PCI_CHIP_SAVAGE_MX	0x8C11
++#define PCI_CHIP_SAVAGE_IX_MV	0x8C12
++#define PCI_CHIP_SAVAGE_IX	0x8C13
++#define PCI_CHIP_SAVAGE_NB	0x8A25
++#define PCI_CHIP_SAVAGE_MX_MV	0x8C10
+ 
+ /* ARK Logic */
+ #define PCI_CHIP_1000PV		0xA091
+--- xc/programs/Xserver/hw/xfree86/SuperProbe/Probe.h.336	Thu Nov 18 16:52:49 1999
++++ xc/programs/Xserver/hw/xfree86/SuperProbe/Probe.h	Mon Jul 17 17:10:07 2000
+@@ -611,6 +611,11 @@
+ #define CHIP_S3_Trio3D_2X	SVGA_TYPE(V_S3,40)	/* S3 Trio3D/2X	*/
+ #define CHIP_S3_Savage4 SVGA_TYPE(V_S3,41)	/* S3 Savage4		*/
+ #define CHIP_S3_Savage2000 SVGA_TYPE(V_S3,42)	/* S3 Savage2000        */
++#define CHIP_S3_SavageMX_MV SVGA_TYPE(V_S3,43)	/* S3 Savage/MX-MV      */
++#define CHIP_S3_SavageMX SVGA_TYPE(V_S3,44)	/* S3 Savage/MX         */
++#define CHIP_S3_SavageIX_MV SVGA_TYPE(V_S3,45)	/* S3 Savage/IX-MV      */
++#define CHIP_S3_SavageIX SVGA_TYPE(V_S3,46)	/* S3 Savage/IX         */
++#define CHIP_S3_SavageNB SVGA_TYPE(V_S3,47)	/* S3 Savage/NB         */
+ #define CHIP_TVGA_UNK	SVGA_TYPE(V_TRIDENT,0)	/* Trident unknown	*/
+ #define CHIP_TVGA8200	SVGA_TYPE(V_TRIDENT,1)	/* Trident LX8200	*/
+ #define CHIP_TVGA8800BR	SVGA_TYPE(V_TRIDENT,2)	/* Trident 8800BR	*/
+--- xc/programs/Xserver/hw/xfree86/SuperProbe/Print.c.336	Thu Nov 18 16:52:49 1999
++++ xc/programs/Xserver/hw/xfree86/SuperProbe/Print.c	Mon Jul 17 12:05:17 2000
+@@ -149,6 +149,11 @@
+ 		  "S3 Trio3D/2X",
+ 		  "S3 Savage4",
+ 		  "S3 Savage2000",
++		  "S3 Savage/MX-MV",
++		  "S3 Savage/MX",
++		  "S3 Savage/IX-MV",
++		  "S3 Savage/IX",
++		  "S3 Savage/NB",
+ 	       },
+ /* Trident */	{ "Trident (chipset unknown)",
+ 		  "Trident LX8200",
+--- xc/programs/Xserver/hw/xfree86/SuperProbe/S3.c.336	Fri Dec  3 10:41:34 1999
++++ xc/programs/Xserver/hw/xfree86/SuperProbe/S3.c	Mon Jul 17 17:11:04 2000
+@@ -194,6 +194,26 @@
+ 			        PCIProbed = TRUE;
+ 				*Chipset = CHIP_S3_Savage2000;
+ 				break;
++			case PCI_CHIP_SAVAGE_MX_MV:
++			        PCIProbed = TRUE;
++				*Chipset = CHIP_S3_SavageMX_MV;
++				break;
++			case PCI_CHIP_SAVAGE_MX:
++			        PCIProbed = TRUE;
++				*Chipset = CHIP_S3_SavageMX;
++				break;
++			case PCI_CHIP_SAVAGE_IX_MV:
++			        PCIProbed = TRUE;
++				*Chipset = CHIP_S3_SavageIX_MV;
++				break;
++			case PCI_CHIP_SAVAGE_IX:
++			        PCIProbed = TRUE;
++				*Chipset = CHIP_S3_SavageIX;
++				break;
++			case PCI_CHIP_SAVAGE_NB:
++			        PCIProbed = TRUE;
++				*Chipset = CHIP_S3_SavageNB;
++				break;
+ #if 0  /* use port probing then... */
+ 			default:
+ 			        PCIProbed = TRUE;
+@@ -428,6 +448,21 @@
+                            case PCI_CHIP_SAVAGE2000:
+                               *Chipset = CHIP_S3_Savage2000;
+ 			      break;
++                           case PCI_CHIP_SAVAGE_MX_MV:
++                              *Chipset = CHIP_S3_SavageMX_MV;
++			      break;
++                           case PCI_CHIP_SAVAGE_MX:
++                              *Chipset = CHIP_S3_SavageMX;
++			      break;
++                           case PCI_CHIP_SAVAGE_IX_MV:
++                              *Chipset = CHIP_S3_SavageIX_MV;
++			      break;
++                           case PCI_CHIP_SAVAGE_IX:
++                              *Chipset = CHIP_S3_SavageIX;
++			      break;
++                           case PCI_CHIP_SAVAGE_NB:
++                              *Chipset = CHIP_S3_SavageNB;
++			      break;
+ 			   default:
+ 			     Chip_data = rev;
+ 			     Chip_data = (Chip_data << 16) | chip_id;
+@@ -547,6 +582,19 @@
+ 			else if (Chipset == CHIP_S3_Savage2000)
+ 			{  
+ 			  int memsize[] = { 2, 4, 8, 12, 16, 32, 64, 32 };
++			  int sel = (config & 0xE0) >> 5;
++			  Mem = memsize[sel] * 1024;
++			}
++			else if (Chipset == CHIP_S3_SavageMX_MV || Chipset == CHIP_S3_SavageMX ||
++				 Chipset == CHIP_S3_SavageIX_MV || Chipset == CHIP_S3_SavageIX)
++			{  
++			  int memsize[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
++			  int sel = (config & 0x0E) >> 1;
++			  Mem = memsize[sel] * 1024;
++			}
++			else if (Chipset == CHIP_S3_SavageNB)
++			{  
++			  int memsize[] = { 0, 2, 4, 8, 16, 32, 2, 2 };
+ 			  int sel = (config & 0xE0) >> 5;
+ 			  Mem = memsize[sel] * 1024;
+ 			}
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/lrmi.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/lrmi.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/lrmi.c	Fri Jul 30 13:21:25 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/lrmi.c	Wed Jan 26 01:44:42 2000
+@@ -11,10 +11,10 @@
+ */
+ /* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/lrmi.c,v 1.1.2.1 1999/07/30 11:21:25 hohndel Exp $ */
+ 
+-#if defined(linux) && defined(__i386__)
+-
+ #include <stdio.h>
+ #include <string.h>
++
++#if defined(linux) && defined(__i386__)
+ #include <asm/vm86.h>
+ 
+ #ifdef USE_LIBC_VM86
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/newmmio.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/newmmio.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/newmmio.h	Fri Dec  3 10:46:00 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/newmmio.h	Wed Jan 26 01:44:43 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/newmmio.h,v 1.1.2.2 1999/12/01 12:49:32 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/newmmio.h,v 1.1.2.1 1999/07/30 11:21:27 hohndel Exp $ */
+ 
+ /* Copied over from accel/s3_virge */
+ 
+@@ -409,9 +409,9 @@
+  */
+ #define IN_SUBSYS_STAT() 	((((mmtr)s3savMmioMem)->subsys_regs.regs.subsystem_csr))
+ #define SET_SUBSYS_CRTL(val) 	do { write_mem_barrier(); ((((mmtr)s3savMmioMem)->subsys_regs.regs.subsystem_csr)) = (val); write_mem_barrier(); } while (0)
+-#define STATUS_WORD0            (*(volatile unsigned int*)(((char*)s3savMmioMem) + 0x48C00))
++#define STATUS_WORD0            S3_IN32(0x48C00)
+ /* Savage4 Rev B only: */
+-#define ALT_STATUS_WORD0        (*(volatile unsigned int*)(((char*)s3savMmioMem) + 0x48C60))
++#define ALT_STATUS_WORD0        S3_IN32(0x48C60)
+ 
+ 
+ #define SET_DAC_W_INDEX(index)  outb(DAC_W_INDEX, index)
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/regs3sav.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/regs3sav.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/regs3sav.h	Fri Dec  3 10:46:00 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/regs3sav.h	Thu Feb 10 21:21:14 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/regs3sav.h,v 1.1.2.2 1999/12/01 12:49:32 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/regs3sav.h,v 1.1.2.1 1999/07/30 11:21:28 hohndel Exp $ */
+ 
+ /* regs3v.h
+  *
+@@ -55,6 +55,25 @@
+        }\
+ }
+ 
++#if defined(__alpha__)
++#define mb() __asm__ __volatile__("mb": : :"memory")
++#define S3_IN8(addr)  xf86ReadSparse8(s3savMmioMemSparse, (addr))
++#define S3_IN16(addr) xf86ReadSparse16(s3savMmioMemSparse, (addr))
++#define S3_IN32(addr) *(volatile CARD32 *)((char*)s3savMmioMem + (addr))
++#define S3_OUT8(addr, val)  do { xf86WriteSparse8((val),s3savMmioMemSparse,(addr)); \
++				mb();} while(0)
++#define S3_OUT16(addr, val) do { xf86WriteSparse16((val),s3savMmioMemSparse,(addr)); \
++				mb();} while(0)
++#define S3_OUT32(addr, val) do { *(volatile CARD32 *)((char*)s3savMmioMem + (addr)) = (val); \
++				mb();} while(0)
++#else /* __alpha__ */
++#define S3_IN8(addr)  *(volatile CARD8 *)((char*)s3savMmioMem + (addr))
++#define S3_IN16(addr) *(volatile CARD16 *)((char*)s3savMmioMem + (addr))
++#define S3_IN32(addr) *(volatile CARD32 *)((char*)s3savMmioMem + (addr))
++#define S3_OUT8(addr, val)  *(volatile CARD8 *)((char*)s3savMmioMem + (addr)) = (val)
++#define S3_OUT16(addr, val) *(volatile CARD16 *)((char*)s3savMmioMem + (addr)) = (val)
++#define S3_OUT32(addr, val) *(volatile CARD32 *)((char*)s3savMmioMem + (addr)) = (val)
++#endif /* __alpha__ */
+ 
+ #define S3_ViRGE_SERIES(chip)     ((chip&0xfff0)==0x31e0)
+ #define S3_ViRGE_GX2_SERIES(chip) (chip == S3_ViRGE_GX2)
+@@ -66,18 +85,9 @@
+ #define S3_ANY_SERIES(chip)       (    S3_ViRGE_SERIES(chip)		\
+ 				    || S3_ViRGE_VX_SERIES(chip))
+ 
+-#define S3_SAVAGE3D_SERIES(chip)  ((chip == S3_SAVAGE3D_MV) ||\
+-				   (chip == S3_SAVAGE3D))
+-#define	S3_SAVAGE_MX_SERIES(chip)  ((chip == S3_SAVAGE_MX_MV) ||\
+-				   (chip == S3_SAVAGE_MX))
+-#define	S3_SAVAGE_IX_SERIES(chip) ((chip == S3_SAVAGE_IX_MV) ||\
+-				   (chip == S3_SAVAGE_IX))
+-#define S3_SAVAGE_MXIX(chip)	  (S3_SAVAGE_MX_SERIES(chip) || \
+-				   S3_SAVAGE_IX_SERIES(chip))
+-
+-#define S3_SAVAGE_SERIES(chip)    (((chip&0xfff0)==0x8a20) || \
+-				   (chip==0x9102) || \
+-				   S3_SAVAGE_MXIX(chip))
++#define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
++
++#define S3_SAVAGE_SERIES(chip)    ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
+ 
+ /* PCI data */
+ #define PCI_S3_VENDOR_ID	0x5333
+@@ -89,6 +99,7 @@
+ #define PCI_SAVAGE_MX		0x8C11
+ #define PCI_SAVAGE_IX_MV	0x8C12
+ #define PCI_SAVAGE_IX		0x8C13
++#define PCI_SAVAGE_370		0x8A25
+ 
+ #define PCI_ViRGE		0x5631
+ #define PCI_ViRGE_VX		0x883D
+@@ -101,12 +112,10 @@
+ #define S3_UNKNOWN		 0
+ #define S3_SAVAGE3D              1
+ #define S3_SAVAGE3D_MV           2
+-#define S3_SAVAGE4               3
+-#define S3_SAVAGE2000            4
+-#define S3_SAVAGE_MX_MV		 5
+-#define S3_SAVAGE_MX		 6
+-#define S3_SAVAGE_IX_MV		 7
+-#define S3_SAVAGE_IX		 8
++#define S3_SAVAGE_MX		 3
++#define S3_SAVAGE4               4
++#define S3_SAVAGE_370		 5
++#define S3_SAVAGE2000            6
+ 
+ #define S3_ViRGE		 1
+ #define S3_ViRGE_VX		 2
+@@ -403,48 +412,48 @@
+ }
+ LUTENTRY;
+ 
+-#define MAXLOOP 0xffffff /* timeout value for engine waits, ~6 secs */
++#define MAXLOOP 0xfffff /* timeout value for engine waits, ~6 secs */
+ /*
+  * The correct value for MAXFIFO actually depends on the size of the 
+  * command-overflow-buffer in MM48C14.  We happen to use 32K always.
+  */
+-#define MAXFIFO 0x80C0  /* Number of on-chip and off-chip FIFO slots */
+-void S3VGEReset(int from_timeout, int line, char *file);
++#define MAXFIFO 0x7f00  /* Number of on-chip and off-chip FIFO slots */
++void S3SAVGEReset(int from_timeout, int line, char *file);
+ 
+ /* Wait until "v" queue entries are free */
+ 
+ #define WaitQueue(v) \
+   if( s3vPriv.NoPCIRetry ) { \
+     if( (*s3vPriv.WaitQueue)(v) ) \
+-      S3VGEReset(1,__LINE__,__FILE__); \
++      S3SAVGEReset(1,__LINE__,__FILE__); \
+   }
+ 
+ /* Wait until GP is idle and queue is empty */
+ 
+ #define WaitIdleEmpty() \
+   if( (*s3vPriv.WaitIdleEmpty)() ) { \
+-   /*S3VGEReset(1,__LINE__,__FILE__);*/ \
++   /*S3SAVGEReset(1,__LINE__,__FILE__);*/ \
+   }
+ 
+ /* Wait until GP is idle */
+ 
+ #define WaitIdle() \
+   if( s3vPriv.WaitIdle() ) { \
+-    /*S3VGEReset(1,__LINE__,__FILE__);*/ \
++    /*S3SAVGEReset(1,__LINE__,__FILE__);*/ \
+   }
+ 
+ /* Wait until Command FIFO is empty */
+ 
+ #define WaitCommandEmpty() \
+   if( s3vPriv.WaitCommandEmpty() ) { \
+-    /* S3VGEReset(1,__LINE__,__FILE__); */ \
++    /* S3SAVGEReset(1,__LINE__,__FILE__); */ \
+   }
+ 
+ /* Wait until a DMA transfer is done */ 
+ #define WaitDMAEmpty() \
+   do { int loop=0; mem_barrier(); \
+        while  (((((mmtr)s3savMmioMem)->dma_regs.regs.cmd.write_pointer) != (((mmtr)s3savMmioMem)->dma_regs.regs.cmd.read_pointer)) && (loop++<MAXLOOP)); \
+-       if (loop >= MAXLOOP) S3VGEReset(1,__LINE__,__FILE__); \
++       if (loop >= MAXLOOP) S3SAVGEReset(1,__LINE__,__FILE__); \
+   } while(0)
+ 
+ #ifndef NULL
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3bci.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bci.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3bci.h	Fri Dec  3 10:46:00 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bci.h	Thu Feb  3 03:19:00 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bci.h,v 1.1.2.2 1999/12/01 12:49:33 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bci.h,v 1.1.2.1 1999/07/30 11:21:28 hohndel Exp $ */
+ 
+ #ifndef _S3BCI_H_
+ #define _S3BCI_H_
+@@ -10,10 +10,11 @@
+     dword |= (temp & 0xFF0000) >> 8; \
+     dword |= (temp & 0xFF000000) >> 24; }
+ 
+-#define BCI_GET_PTR unsigned int * bci_ptr = s3vPriv.BciMem
++#define BCI_GET_PTR volatile unsigned int * bci_ptr = s3vPriv.BciMem
++#define BCI_RESET bci_ptr = s3vPriv.BciMem
+ 
+ #if 1
+-#define BCI_SEND(dw)   ((*(unsigned int*)(bci_ptr++)) = (unsigned int)(dw))
++#define BCI_SEND(dw)   (*bci_ptr++ = (unsigned int)(dw))
+ #else
+ __inline__ void BCI_SEND_DEBUG(unsigned int * bci_base,
+     unsigned int * bci_ptr, unsigned int dw)
+@@ -49,7 +50,7 @@
+ #define BCI_CMD_DEST_SBD             0x00001000
+ #define BCI_CMD_DEST_SBD_NEW         0x00001400
+ 
+-#define BCI_CMD_SRC_TRANSPARENT      0x00000100
++#define BCI_CMD_SRC_TRANSPARENT      0x00000200
+ #define BCI_CMD_SRC_SOLID            0x00000000
+ #define BCI_CMD_SRC_GBD              0x00000020
+ #define BCI_CMD_SRC_COLOR            0x00000040
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3bitmap.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bitmap.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3bitmap.c	Fri Dec 31 18:20:59 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bitmap.c	Wed Jan 26 01:44:45 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bitmap.c,v 1.1.2.4 1999/12/28 12:14:04 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3bitmap.c,v 1.1.2.1 1999/07/30 11:21:30 hohndel Exp $ */
+ 
+ void SavageWriteBitmapScreenToScreenColorExpand
+ (
+@@ -13,7 +13,7 @@
+ {
+     BCI_GET_PTR;
+     unsigned int cmd;
+-    unsigned int bd_offset;
++    unsigned char * bd_offset;
+     unsigned int bd;
+     
+     cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
+@@ -25,11 +25,11 @@
+     bd |= BCI_BD_BW_DISABLE;
+     BCI_BD_SET_BPP(bd, 1);
+     BCI_BD_SET_STRIDE(bd, srcwidth);
+-    bd_offset = srcwidth * srcy + (srcx >> 3) + (int) src;
++    bd_offset = srcwidth * srcy + (srcx >> 3) + src;
+ 
+     WaitQueue(10);
+     BCI_SEND(cmd);
+-    BCI_SEND(bd_offset);
++    BCI_SEND((unsigned int)bd_offset);
+     BCI_SEND(bd);
+     BCI_SEND(fg);
+     BCI_SEND((bg != -1) ? bg : 0);
+@@ -62,7 +62,7 @@
+     cmd |= s3vAlu[rop];
+ 
+     if( !srcwidth )
+-        return;
++	return;
+ 
+     BCI_SEND(cmd);
+     BCI_SEND(BCI_CLIP_LR(x, x+w-1));
+@@ -84,19 +84,19 @@
+     
+     for (j = 0; j < h; j ++) {
+         BCI_SEND(BCI_X_Y(x, y+j));
+-	BCI_SEND(BCI_W_H(w, 1));
+-	srcp = (unsigned int*) src;
+-	for (i = count; i > 0; srcp ++, i --) {
+-	    /* We have to invert the bits in each byte. */
+-	    unsigned long u = *srcp;
+-	    u = ((u & 0x0f0f0f0f) << 4) | ((u & 0xf0f0f0f0) >> 4);
+-	    u = ((u & 0x33333333) << 2) | ((u & 0xcccccccc) >> 2);
+-	    u = ((u & 0x55555555) << 1) | ((u & 0xaaaaaaaa) >> 1);
+-	    BCI_SEND(u);
+-	}
+-	src += srcwidth;
++        BCI_SEND(BCI_W_H(w, 1));
++        srcp = (unsigned int*) src;
++        for (i = count; i > 0; srcp ++, i --) {
++            /* We have to invert the bits in each byte. */
++            unsigned long u = *srcp;
++            u = ((u & 0x0f0f0f0f) << 4) | ((u & 0xf0f0f0f0) >> 4);
++            u = ((u & 0x33333333) << 2) | ((u & 0xcccccccc) >> 2);
++            u = ((u & 0x55555555) << 1) | ((u & 0xaaaaaaaa) >> 1);
++            BCI_SEND(u);
++        }
++        src += srcwidth;
+         if( !--reset ) {
+-            bci_ptr = s3vPriv.BciMem;
++	    BCI_RESET;
+             reset = 65536 / srcwidth;
+         }
+     }
+@@ -144,6 +144,6 @@
+     }
+ 
+     for (i = count; i > 0; srcp ++, i --) {
+-	BCI_SEND(*srcp);
++        BCI_SEND(*srcp);
+     }
+ }
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_accel.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_accel.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_accel.c	Fri Dec  3 10:46:01 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_accel.c	Thu Feb 10 21:35:48 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_accel.c,v 1.1.2.4 1999/12/02 12:30:36 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_accel.c,v 1.1.2.1 1999/07/30 11:21:31 hohndel Exp $ */
+ 
+ /*
+  *
+@@ -7,7 +7,7 @@
+  */
+ 
+ /*
+- * The accel file for the ViRGE driver.  
++ * The accel file for the Savage driver.  
+  * 
+  * Created 20/03/97 by Sebastien Marineau
+  * Revision: 
+@@ -38,6 +38,9 @@
+ 
+ /* Globals used in driver */
+ extern pointer s3savMmioMem;
++#ifdef __alpha__
++extern pointer s3savMmioMemSparse;
++#endif
+ static int s3DummyTransferArea;
+ static int s3LineHWClipSet = 0;
+ 
+@@ -103,15 +106,10 @@
+ void
+ S3SAVInitialize2DEngine()
+ {
+-    unsigned long cobWater;
+-
+     outw(vgaCRIndex, 0x0140);
+     outb(vgaCRIndex, 0x31);
+     outb(vgaCRReg, 0x0c);
+ 
+-#define S3_IN32(off) (*(volatile unsigned int*)(((char*)s3savMmioMem)+(off)))
+-#define S3_OUT32(off, val) (*(volatile unsigned int*)(((char*)s3savMmioMem)+(off)) = val)
+-#define S3_OUT16(off, val) (*(volatile unsigned short*)(((char*)s3savMmioMem)+(off)) = val)
+     /* Setup plane masks */
+     S3_OUT32(0x8128, ~0); /* enable all write planes */
+     S3_OUT32(0x812C, ~0); /* enable all read planes */
+@@ -120,24 +118,18 @@
+ 
+     if( s3vPriv.chip < S3_SAVAGE2000 )
+     {
+-	/* Sav4 doc shows the smaller value in the upper DWORD. */
+-	/* However, that's not what the NT driver does. */
+-	if( s3vPriv.chip == S3_SAVAGE4 ) {
+-	    cobWater = (cob.Size >> 7) * 0x10001 - 0x01400300;
+-	}
+-	else {
+-	    cobWater = (cob.Size >> 2) * 0x10001 - 0x01C00EC0;
+-	}
+ 	/* Disable BCI */
+ 	S3_OUT32(0x48C18, S3_IN32(0x48C18) & 0x3FF0);
+ 	/* Disable shadow status update */
+ 	S3_OUT32(0x48C0C, 0);
+ 	/* Setup BCI command overflow buffer */
+ 	S3_OUT32(0x48C14, (cob.Offset >> 11) | (cob.Index << 29));
+-	/* Command overflow buffer HI/LOW watermarks */
+-	S3_OUT32(0x48C10, cobWater);
+ 	/* Enable BCI and command overflow buffer */
+-	S3_OUT32(0x48C18, S3_IN32(0x48C18) | 0x0C);
++	if( (s3vPriv.chip == S3_SAVAGE4) || (s3vPriv.chip == S3_SAVAGE_370)  )
++	    /* Disable COB on Savage4 */
++	    S3_OUT32(0x48C18, S3_IN32(0x48C18) | 0x08);
++	else
++	    S3_OUT32(0x48C18, S3_IN32(0x48C18) | 0x0C);
+     }
+     else
+     {
+@@ -147,9 +139,6 @@
+ 	S3_OUT32(0x48A30, 0);
+ 	/* Setup BCI command overflow buffer */
+ 	S3_OUT32(0x48C18, (cob.Offset >> 7) | (cob.Index));
+-	/* Command overflow buffer HI/LOW watermarks */
+-	S3_OUT32(0x48C10, 0x6090);
+-	S3_OUT32(0x48C14, 0x70A8);
+ 	/* Enable BCI and command overflow buffer */
+ 	S3_OUT32(0x48C18, S3_IN32(0x48C18) | 0x00280000 );
+     }
+@@ -339,6 +328,7 @@
+ 
+     xf86AccelInfoRec.ColorExpandFlags = SCANLINE_PAD_DWORD |
+ 					CPU_TRANSFER_PAD_DWORD | 
++					BIT_ORDER_IN_BYTE_MSBFIRST |
+ 					VIDEO_SOURCE_GRANULARITY_PIXEL |
+ 					LEFT_EDGE_CLIPPING;
+     /* WriteBitmap color expand */
+@@ -355,13 +345,12 @@
+              S3SAVSubsequentCPUToScreenColorExpand;
+ #endif
+ 
+-#if 0
++#if 1
+     xf86AccelInfoRec.SetupForCPUToScreenColorExpand =
+              S3SAVSetupForCPUToScreenColorExpand;
+     xf86AccelInfoRec.SubsequentCPUToScreenColorExpand =
+              S3SAVSubsequentCPUToScreenColorExpand;
+     xf86AccelInfoRec.CPUToScreenColorExpandBase = s3vPriv.BciMem;
+-             (void *) &IMG_TRANS;
+     xf86AccelInfoRec.CPUToScreenColorExpandRange = 128 * 1024;
+ #endif
+ 
+@@ -405,7 +394,7 @@
+      * enabled the PIXMAP_CACHE flag, then these lines can be omitted.
+      */
+ 
+-     if( s3vPriv.chip == S3_SAVAGE4 ) {
++     if( (s3vPriv.chip == S3_SAVAGE4) || (s3vPriv.chip == S3_SAVAGE_370) ) {
+ 	 cob.Index = 2 /*4*/;
+ 	 cob.Size = 0x8000 << cob.Index;
+      }
+@@ -438,16 +427,6 @@
+ void
+ S3SAVAccelSync()
+ {
+-#if 0
+-    BCI_GET_PTR;
+-
+-    WaitQueue(3);
+-    BCI_SEND(BCI_CMD_NOP | BCI_CMD_CLIP_NEW);
+-    BCI_SEND(BCI_CLIP_TL(0, 0));
+-    BCI_SEND(BCI_CLIP_BR(s3vPriv.ScissB, s3vPriv.Width));
+-#endif
+-
+-    WaitCommandEmpty();
+     WaitIdleEmpty();
+ }
+ 
+@@ -499,9 +478,11 @@
+       switch( s3vPriv.chip ) {
+         case S3_SAVAGE3D:
+         case S3_SAVAGE3D_MV:
++        case S3_SAVAGE_MX:
+ 	  success = (STATUS_WORD0 & 0x0008ffff) == 0x00080000;
+ 	  break;
+ 	case S3_SAVAGE4:
++	case S3_SAVAGE_370:
+ 	  success = (ALT_STATUS_WORD0 & 0x0081ffff) == 0x00800000;
+ 	  break;
+ 	case S3_SAVAGE2000:
+@@ -545,7 +526,7 @@
+         ErrorF("ViRGE register cache hits: %d misses: %d\n",
+             s3vCacheHit, s3vCacheMiss);    
+     s3vCacheHit = 0; s3vCacheMiss = 0;
+-
++    S3SAVSetGBD();
+ }
+ 
+ 
+@@ -579,9 +560,7 @@
+     BCI_SEND(cmd);
+     if (transparency_color != -1) {
+         BCI_SEND(transparency_color);
+-	ErrorF("CopyRect transparency\n");
+     }
+-    /*ErrorF("CopyRect command 0x%.8x sent\n", cmd);*/
+ #endif
+     s3SavedBciCmd = cmd;
+     s3SavedBgColor = transparency_color;
+@@ -609,13 +588,11 @@
+ 
+ #if BCI_REPEAT
+     WaitQueue(4);
+-    if (s3SavedBgColor != -1) 
+-	BCI_SEND(s3SavedBgColor);
+     BCI_SEND(BCI_X_Y(x1, y1));
+     BCI_SEND(BCI_X_Y(x2, y2));
+     BCI_SEND(BCI_W_H(w, h));
+ #else
+-    WaitQueue(5);
++    WaitQueue(6);
+     BCI_SEND(s3SavedBciCmd);
+     if (s3SavedBgColor != -1) 
+ 	BCI_SEND(s3SavedBgColor);
+@@ -643,6 +620,16 @@
+         | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
+         | BCI_CMD_DEST_GBD | BCI_CMD_SRC_SOLID;
+ 
++    /* Don't send a color if we don't have to. */
++
++    if( rop == GXcopy )
++    {
++	if( color == 0 )
++	    rop = GXclear;
++	else if( color == MaxMask[s3vPriv.Bpp] )
++	    rop = GXset;
++    }
++
+     if(
+       (rop != GXclear) &&
+       (rop != GXnoop) &&
+@@ -690,7 +677,7 @@
+     BCI_SEND(BCI_X_Y(x, y));
+     BCI_SEND(BCI_W_H(w, h));
+ #else
+-    WaitQueue(4);
++    WaitQueue(5);
+     BCI_SEND(s3SavedBciCmd);
+     if( s3SavedBciCmd & BCI_CMD_SEND_COLOR )
+ 	BCI_SEND(s3SavedFgColor);
+@@ -745,6 +732,7 @@
+     int cmd;
+ 
+     cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
++	| BCI_CMD_CLIP_LR
+         | BCI_CMD_DEST_GBD | BCI_CMD_SRC_MONO;
+ 
+     if(
+@@ -759,7 +747,8 @@
+ 
+     if (bg != -1)
+         cmd |= BCI_CMD_SEND_COLOR;
+-    else cmd |= BCI_CMD_SRC_TRANSPARENT;
++    else 
++	cmd |= BCI_CMD_SRC_TRANSPARENT;
+ 
+ #if BCI_REPEAT    
+     WaitQueue(3);
+@@ -783,51 +772,24 @@
+     WaitQueue(4);
+     BCI_SEND(BCI_X_Y(x, y));
+     BCI_SEND(BCI_W_H(w, h));
+-    BCI_SEND(((w + 31) / 32) * h);
+ #else
++    /* 7 is not enough.  XAA will be sending bitmap data next.  We */
++    /* should probably wait for empty/idle here. */
++
+     WaitQueue(7);
+-    if ( 0 ) {
++
+     BCI_SEND(s3SavedBciCmd);
+-#if 0
+-    if(skipleft != 0)  
+-        BCI_SEND(BCI_CLIP_LR(x + skipleft, s3vPriv.Width)); 
+-    else
+-        BCI_SEND(BCI_CLIP_LR(0, s3vPriv.Width));
+-#endif
+-    BCI_SEND(s3SavedFgColor);
+-    if (s3SavedBgColor != -1)  
++    BCI_SEND(BCI_CLIP_LR(x, x+w-1));
++    x -= skipleft;
++    w += skipleft;
++    w = (w + 31) & ~31;
++    if( s3SavedBciCmd & BCI_CMD_SEND_COLOR )
++	BCI_SEND(s3SavedFgColor);
++    if( s3SavedBgColor != -1 )
+ 	BCI_SEND(s3SavedBgColor);
+-    else BCI_SEND(0);
+     BCI_SEND(BCI_X_Y(x, y));
+     BCI_SEND(BCI_W_H(w, h));
+-    /*BCI_SEND(((w + 31) / 32) * h);*/
+-    } else {
+-        int i, j, count;
+-	s3SavedBciCmd = 0;
+-        BCI_SEND(0x4bcc8060);
+-        BCI_SEND(s3SavedFgColor);
+-        BCI_SEND(s3SavedBgColor);
+-	count = (w + 31) / 32;
+-	for (j = 0; j < 1; j ++) {
+-	    BCI_SEND(BCI_X_Y(x, y+j));
+-	    BCI_SEND(BCI_W_H(w, 1));
+-	    for (i = count; i > 0; i--) {
+-	        BCI_SEND(0xffffffff);
+-	    }
+-	}
+-    }
+ #endif
+-
+-    if(S3SAVROPHasSrc(s3SavedBciCmd<<1)) {
+-       xf86AccelInfoRec.CPUToScreenColorExpandBase = 
+-             (void *) bci_ptr;
+-       xf86AccelInfoRec.ColorExpandFlags &= (~CPU_TRANSFER_BASE_FIXED); 
+-       }
+-    else {    /* Fix for XAA bug */
+-       xf86AccelInfoRec.CPUToScreenColorExpandBase = 
+-             (void *) &s3DummyTransferArea;
+-       xf86AccelInfoRec.ColorExpandFlags |= CPU_TRANSFER_BASE_FIXED; 
+-       }
+ }
+ 
+ 
+@@ -978,7 +940,7 @@
+     dx = x2 - x1;
+     dy = y2 - y1;
+ 
+-#if 0
++#ifdef DEBUG_EXTRA
+     ErrorF("TwoPointLine, (%4d,%4d)-(%4d,%4d), clr %08x, last pt %s\n",
+         x1, y1, x2, y2, s3SavedFgColor, (bias & 0x100)?"NO ":"YES");
+ #endif
+@@ -1013,9 +975,10 @@
+ 
+     if( s3LineHWClipSet ) {
+ 	cmd |= BCI_CMD_CLIP_CURRENT;
++	s3LineHWClipSet = FALSE;
+     }
+ 
+-    WaitQueue(5); 
++    WaitQueue(5);
+     BCI_SEND( cmd );
+     if( cmd & BCI_CMD_SEND_COLOR )
+ 	BCI_SEND( s3SavedFgColor );
+@@ -1030,6 +993,10 @@
+ {
+     BCI_GET_PTR;
+     int cmd;
++
++#ifdef DEBUG_EXTRA
++    ErrorF("ClipRect, (%4d,%4d)-(%4d,%4d) \n", x1, y1, x2, y2 );
++#endif
+ 
+     cmd = BCI_CMD_NOP | BCI_CMD_CLIP_NEW;
+     WaitQueue(3);
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_cursor.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_cursor.c	Fri Dec  3 10:46:01 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c	Thu Mar 30 05:44:55 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c,v 1.1.2.2 1999/12/01 12:49:33 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c,v 1.1.2.1 1999/07/30 11:21:32 hohndel Exp $ */
+ 
+ /*
+  *
+@@ -110,8 +110,6 @@
+     * buffer.  Savage4 requires 4k alignment for the cursor image.
+     */
+ 
+-#define S3_IN32(off) (*(unsigned int*)(((char*)s3savMmioMem)+(off)))
+-
+    if( s3vPriv.chip < S3_SAVAGE2000) {
+       s3vCursorVRAMMemSegment = (S3_IN32(0x48C14) & 0x3FFF) * 2 - 4;
+    } else {
+@@ -416,16 +414,13 @@
+    xColorItem sourceColor, maskColor;
+    Bool bNeedExtra = FALSE;
+ 
+-   if( S3_SAVAGE_SERIES(s3vPriv.chip) )
++   /* Clock doubled modes need an extra cursor stack write. */
++   outb(0x3c4, 0x18);
++   if( inb(0x3c5) & 0x80 ) 
+    {
+-      /* Clock doubled modes need an extra cursor stack write. */
+-      outb(0x3c4, 0x18);
+-      if( inb(0x3c5) & 0x80 ) 
+-      {
+-         outb(0x3c4, 0x15);
+-	 if( inb(0x3c5) & 0x50 )
+-	    bNeedExtra = TRUE;
+-      }
++      outb(0x3c4, 0x15);
++      if( inb(0x3c5) & 0x50 )
++	 bNeedExtra = TRUE;
+    }
+ 
+    if (!xf86VTSema)
+@@ -434,49 +429,31 @@
+    if (!displayed)
+       return;
+ 
+-   switch (vgaBitsPerPixel) {
+-   case 8:
+-     if (!(S3_ViRGE_GX2_SERIES(s3vPriv.chip) || S3_ViRGE_MX_SERIES(s3vPriv.chip))) {
+-      vgaGetInstalledColormaps(pScr, &pmap);
+-      sourceColor.red = pCurs->foreRed;
+-      sourceColor.green = pCurs->foreGreen;
+-      sourceColor.blue = pCurs->foreBlue;
+-      FakeAllocColor(pmap, &sourceColor);
+-      maskColor.red = pCurs->backRed;
+-      maskColor.green = pCurs->backGreen;
+-      maskColor.blue = pCurs->backBlue;
+-      FakeAllocColor(pmap, &maskColor);
+-      FakeFreeColor(pmap, sourceColor.pixel);
+-      FakeFreeColor(pmap, maskColor.pixel);
++   /*
++    * The /MX family is apparently unique among the Savages, in that
++    * the cursor color is always straight RGB.  The rest of the Savages
++    * use palettized values at 8-bit when not clock doubled.
++    */
+ 
+-      outb(vgaCRIndex, 0x45);
+-      inb(vgaCRReg);	/* reset stack pointer */
+-      outb(vgaCRIndex, 0x4A);
+-      outb(vgaCRReg, sourceColor.pixel);
+-      outb(vgaCRReg, sourceColor.pixel);
+-      outb(vgaCRIndex, 0x45);
+-      inb(vgaCRReg);	/* reset stack pointer */
+-      outb(vgaCRIndex, 0x4B);
+-      outb(vgaCRReg, maskColor.pixel);
+-      outb(vgaCRReg, maskColor.pixel);
+-      break;
+-     }  /* else fall through for ViRGE/MX... */
++   if( s3vPriv.chip == S3_SAVAGE_MX )
++      bNeedExtra = TRUE;
++
++   switch (vgaBitsPerPixel) {
+    case 16:
+-     if (!(S3_ViRGE_GX2_SERIES(s3vPriv.chip) || S3_ViRGE_MX_SERIES(s3vPriv.chip))) {
+-      if (vga256InfoRec.weight.green == 5 && s3vPriv.chip != S3_ViRGE_VX) {
++      if (vga256InfoRec.weight.green == 5) {
+ 	 packedcolfg = ((pCurs->foreRed   & 0xf800) >>  1)
+ 	    | ((pCurs->foreGreen & 0xf800) >>  6)
+-	       | ((pCurs->foreBlue  & 0xf800) >> 11);
++	    | ((pCurs->foreBlue  & 0xf800) >> 11);
+ 	 packedcolbg = ((pCurs->backRed   & 0xf800) >>  1)
+ 	    | ((pCurs->backGreen & 0xf800) >>  6)
+-	       | ((pCurs->backBlue  & 0xf800) >> 11);
++	    | ((pCurs->backBlue  & 0xf800) >> 11);
+       } else {
+ 	 packedcolfg = ((pCurs->foreRed   & 0xf800) >>  0)
+ 	    | ((pCurs->foreGreen & 0xfc00) >>  5)
+-	       | ((pCurs->foreBlue  & 0xf800) >> 11);
++	    | ((pCurs->foreBlue  & 0xf800) >> 11);
+ 	 packedcolbg = ((pCurs->backRed   & 0xf800) >>  0)
+ 	    | ((pCurs->backGreen & 0xfc00) >>  5)
+-	       | ((pCurs->backBlue  & 0xf800) >> 11);
++	    | ((pCurs->backBlue  & 0xf800) >> 11);
+       }
+       outb(vgaCRIndex, 0x45);
+       inb(vgaCRReg);		/* reset stack pointer */
+@@ -499,7 +476,35 @@
+ 	  outb(vgaCRReg, packedcolbg>>8);
+       }
+       break;
+-     }  /* else fall through for ViRGE/MX... */
++   case 8:
++      if( !bNeedExtra )
++      {
++	 vgaGetInstalledColormaps(pScr, &pmap);
++	 sourceColor.red = pCurs->foreRed;
++	 sourceColor.green = pCurs->foreGreen;
++	 sourceColor.blue = pCurs->foreBlue;
++	 FakeAllocColor(pmap, &sourceColor);
++	 maskColor.red = pCurs->backRed;
++	 maskColor.green = pCurs->backGreen;
++	 maskColor.blue = pCurs->backBlue;
++	 FakeAllocColor(pmap, &maskColor);
++	 FakeFreeColor(pmap, sourceColor.pixel);
++	 FakeFreeColor(pmap, maskColor.pixel);
++
++	 outb(vgaCRIndex, 0x45);
++	 inb(vgaCRReg);	/* reset stack pointer */
++	 outb(vgaCRIndex, 0x4A);
++	 outb(vgaCRReg, sourceColor.pixel);
++	 outb(vgaCRReg, sourceColor.pixel);
++	 outb(vgaCRIndex, 0x45);
++	 inb(vgaCRReg);	/* reset stack pointer */
++	 outb(vgaCRIndex, 0x4B);
++	 outb(vgaCRReg, maskColor.pixel);
++	 outb(vgaCRReg, maskColor.pixel);
++	 break;
++      }
++      /* else */
++      /* FALLTHROUGH */
+    case 24:
+    case 32:
+       outb(vgaCRIndex, 0x45);
+@@ -513,7 +518,7 @@
+       inb(vgaCRReg);		/* reset stack pointer */
+       outb(vgaCRIndex, 0x4B);
+       outb(vgaCRReg, pCurs->backBlue >>8);
+-	 outb(vgaCRReg, pCurs->backGreen>>8);
++      outb(vgaCRReg, pCurs->backGreen>>8);
+       outb(vgaCRReg, pCurs->backRed  >>8);
+       break;
+    }
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_driver.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_driver.c	Fri Dec  3 10:46:01 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c	Mon Jun 19 22:11:04 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c,v 1.1.2.4 1999/12/01 12:49:34 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c,v 1.1.2.1 1999/07/30 11:21:33 hohndel Exp $ */
+ 
+ /*
+  *
+@@ -13,21 +13,16 @@
+  * Tim Roberts, 21-June-1999.
+  */
+ 
+-/* This is an intial version of the ViRGE driver for XAA 
++/* This is an intial version of the Savage driver for XAA 
+  * Started 09/03/97 by S. Marineau
+  *
+  * What works: 
+- * - Supports PCI hardware, ViRGE and ViRGE/VX, probably ViRGE/DXGX
+- * - Supports 8bpp, 16bpp and 24bpp. There is some support for 32bpp.
++ * - Supports PCI or AGP hardware, Savage3D, 4 or 2000.
++ * - Supports 8bpp, 16bpp and 32. There is no support for 24bpp.
+  * - VT switching seems to work well, no corruption. 
+- * - A whole slew of XConfig options for memory, PCI and acceleration
+  * - Acceleration is quite complete
+  * 
+  * 
+- * What does not work:
+- * - None of this doublescan stuff
+- *
+- * 
+  * What I attempt to do here:
+  *
+  *  - Rewrite the init/save functions from the accel server such that they
+@@ -78,6 +73,8 @@
+ #include "s3sav_driver.h"
+ #include "regs3sav.h"
+ 
++static const char S3SAVVersionId[] = "$Version: s3_savage 1.0.11 $";
++
+ /*
+  * If the symbol USEBIOS is defined, we try to use the onboard BIOS to do
+  * mode switches.  We query the VESA BIOS list, and match the requested
+@@ -173,10 +170,8 @@
+    { S3_SAVAGE3D_MV,  "Savage3D/MV"},
+    { S3_SAVAGE4,      "Savage4"},
+    { S3_SAVAGE2000,   "Savage2000"},
+-   { S3_SAVAGE_MX_MV, "Savage/MX-MV"},
+    { S3_SAVAGE_MX,    "Savage/MX"},
+-   { S3_SAVAGE_IX_MV, "Savage/IX-MV"},
+-   { S3_SAVAGE_IX,    "Savage/IX"},
++   { S3_SAVAGE_370,   "Savage/NB"},
+    { -1,              ""},
+    };
+ 
+@@ -189,6 +184,9 @@
+ 
+ int vgaCRIndex, vgaCRReg;
+ pointer s3savMmioMem = NULL;   /* MMIO base address */
++#ifdef __alpha__
++pointer s3savMmioMemSparse = NULL;
++#endif
+ extern vgaHWCursorRec vgaHWCursor;
+ 
+ #ifdef USEBIOS
+@@ -196,7 +194,6 @@
+ /* Information about the current BIOS modes. */
+ #define iabs(a)	((int)(a)>0?(a):(-(a)))
+ S3VMODETABLE * s3vModeTable = NULL;
+-unsigned short s3vModeCount = 0;
+ 
+ #endif
+ 
+@@ -222,6 +219,27 @@
+  * three chips, and even the idle vs busy state flipped in the Sav2K
+  */
+ 
++static void
++ResetBCI2K()
++{
++    CARD32 cob = S3_IN32( 0x48c18 );
++    /* if BCI is enabled and BCI is busy... */
++
++    if( 
++	(cob & 0x00000008) &&
++	! (ALT_STATUS_WORD0 & 0x00200000)
++    )
++    {
++	ErrorF( "Resetting BCI, stat = %08x...\n", ALT_STATUS_WORD0);
++	/* Turn off BCI */
++	S3_OUT32( 0x48c18, cob & ~8 );
++	usleep(10000);
++	/* Turn it back on */
++	S3_OUT32( 0x48c18, cob );
++	usleep(10000);
++    }
++}
++
+ /* Wait until "v" queue entries are free */
+ 
+ static int
+@@ -231,6 +249,7 @@
+     int slots = MAXFIFO - v;
+ 
+     mem_barrier();
++    loop &= STATUS_WORD0;
+     while( ((STATUS_WORD0 & 0x0000ffff) > slots) && (loop++ < MAXLOOP))
+ 	;
+     return loop >= MAXLOOP;
+@@ -245,7 +264,7 @@
+     if( !s3vPriv.NoPCIRetry )
+ 	return;
+     mem_barrier();
+-    while( ((ALT_STATUS_WORD0 & 0x0001ffff) > slots) && (loop++ < MAXLOOP))
++    while( ((ALT_STATUS_WORD0 & 0x001fffff) > slots) && (loop++ < MAXLOOP))
+ 	;
+     return loop >= MAXLOOP;
+ }
+@@ -261,6 +280,8 @@
+     mem_barrier();
+     while( ((ALT_STATUS_WORD0 & 0x000fffff) > slots) && (loop++ < MAXLOOP))
+ 	;
++    if( loop >= MAXLOOP )
++	ResetBCI2K();
+     return loop >= MAXLOOP;
+ }
+ 
+@@ -271,6 +292,7 @@
+ {
+     int loop = 0;
+     mem_barrier();
++    loop &= STATUS_WORD0;
+     while( ((STATUS_WORD0 & 0x0008ffff) != 0x80000) && (loop++ < MAXLOOP) )
+ 	;
+     return loop >= MAXLOOP;
+@@ -281,7 +303,7 @@
+ {
+     int loop = 0;
+     mem_barrier();
+-    while( ((ALT_STATUS_WORD0 & 0x0081ffff) != 0x00800000) && (loop++ < MAXLOOP) )
++    while( ((ALT_STATUS_WORD0 & 0x00a1ffff) != 0x00a00000) && (loop++ < MAXLOOP) )
+ 	;
+     return loop >= MAXLOOP;
+ }
+@@ -291,8 +313,13 @@
+ {
+     int loop = 0;
+     mem_barrier();
++    /* CAUTION!  How do we insure this read isn't optimized away? */
++    /* Is the "volatile" enough to do that? */
++    loop &= ALT_STATUS_WORD0;
+     while( ((ALT_STATUS_WORD0 & 0x009fffff) != 0) && (loop++ < MAXLOOP) )
+ 	;
++    if( loop >= MAXLOOP )
++	ResetBCI2K();
+     return loop >= MAXLOOP;
+ }
+ 
+@@ -323,6 +350,7 @@
+ {
+     int loop = 0;
+     mem_barrier();
++    loop &= ALT_STATUS_WORD0;
+     while( (ALT_STATUS_WORD0 & 0x00900000) && (loop++ < MAXLOOP) )
+ 	;
+     return loop >= MAXLOOP;
+@@ -355,6 +383,8 @@
+     mem_barrier();
+     while( (ALT_STATUS_WORD0 & 0x001fffff) && (loop++ < MAXLOOP) )
+ 	;
++    if( loop >= MAXLOOP )
++	ResetBCI2K();
+     return loop >= MAXLOOP;
+ }
+ 
+@@ -392,10 +422,12 @@
+       outb(vgaCRIndex, 0x38);      /* for register CR38, (REG_LOCK1) */
+       outb(vgaCRReg, 0x48);        /* unlock S3 register set for read/write */
+       outb(vgaCRIndex, 0x39);    
+-      outb(vgaCRReg, 0xa5);
++      outb(vgaCRReg, 0xa0);
++      #if 0
+       outb(vgaCRIndex, 0x40);
+       tmp = inb(vgaCRReg);
+       outb(vgaCRReg, tmp & ~0x01);   /* avoid lockups when reading I/O port 0x92e8 */
++      #endif
+       enterCalled = TRUE;
+       }
+ 
+@@ -512,49 +544,52 @@
+ 
+ 	/* Patch CR79.  These values are magical. */
+ 
+-	outb(vgaCRIndex, 0x6d);
+-	cr6d = inb(vgaCRReg);
++	if( s3vPriv.chip != S3_SAVAGE_MX )
++	{
++	    outb(vgaCRIndex, 0x6d);
++	    cr6d = inb(vgaCRReg);
+ 
+-	cr79 = 0x04;
++	    cr79 = 0x04;
+ 
+-	if( vga256InfoRec.displayWidth >= 1024 )
+-	{
+-	    if( vgaBitsPerPixel == 32 )
++	    if( vga256InfoRec.displayWidth >= 1024 )
+ 	    {
+-		if( restore->refresh >= 130 )
+-		    cr79 = 0x03;
+-		else if( vga256InfoRec.displayWidth >= 1280 )
+-		    cr79 = 0x02;
+-		else if(
+-		    (vga256InfoRec.displayWidth == 1024) &&
+-		    (restore->refresh >= 75)
+-		)
++		if( vgaBitsPerPixel == 32 )
+ 		{
+-		    if( cr6d && LCD_ACTIVE )
+-			cr79 = 0x05;
+-		    else
+-			cr79 = 0x08;
++		    if( restore->refresh >= 130 )
++			cr79 = 0x03;
++		    else if( vga256InfoRec.displayWidth >= 1280 )
++			cr79 = 0x02;
++		    else if(
++			(vga256InfoRec.displayWidth == 1024) &&
++			(restore->refresh >= 75)
++		    )
++		    {
++			if( cr6d && LCD_ACTIVE )
++			    cr79 = 0x05;
++			else
++			    cr79 = 0x08;
++		    }
+ 		}
+-	    }
+-	    else if( vgaBitsPerPixel == 16)
+-	    {
+-/* The windows driver uses 0x13 for 16-bit 130Hz, but I see terrible
+- * screen artifacts with that value.  Let's keep it low for now.
+- *		if( restore->refresh >= 130 )
+- *		    cr79 = 0x13;
+- *		else
+- */
+-		if( vga256InfoRec.displayWidth == 1024 )
++		else if( vgaBitsPerPixel == 16)
+ 		{
+-		    if( cr6d && LCD_ACTIVE )
+-			cr79 = 0x08;
+-		    else
+-			cr79 = 0x0e;
++    /* The windows driver uses 0x13 for 16-bit 130Hz, but I see terrible
++     * screen artifacts with that value.  Let's keep it low for now.
++     *		if( restore->refresh >= 130 )
++     *		    cr79 = 0x13;
++     *		else
++     */
++		    if( vga256InfoRec.displayWidth == 1024 )
++		    {
++			if( cr6d && LCD_ACTIVE )
++			    cr79 = 0x08;
++			else
++			    cr79 = 0x0e;
++		    }
+ 		}
+ 	    }
+ 	}
+ 
+-        if( s3vPriv.chip != S3_SAVAGE2000)
++        if( (s3vPriv.chip != S3_SAVAGE2000) && (s3vPriv.chip != S3_SAVAGE_MX) )
+ 	    outw(vgaCRIndex, (cr79 << 8) | 0x79);
+ 
+ 	/* Make sure 16-bit memory access is enabled. */
+@@ -584,7 +619,7 @@
+ 	    outb(vgaCRIndex, 0x73);
+ 	    outb(vgaCRReg, inb(vgaCRReg) & 0xdf );
+ 	}
+-	else
++	else if( s3vPriv.chip != S3_SAVAGE_MX )
+ 	{
+ 	    outb(vgaCRIndex, 0x68);
+ 	    if( !(inb(vgaCRReg) & 0x80) )
+@@ -616,6 +651,18 @@
+       S3SAVDisableSTREAMS();     /* If STREAMS was running, disable it */
+       }
+ 
++#ifdef USEBIOS
++   /*
++    * Some Savage/MX and /IX systems go nuts when trying to exit the
++    * server after WindowMaker has displayed a gradient background.  I
++    * haven't been able to find what causes it, but a non-destructive
++    * switch to mode 3 here seems to eliminate the issue.
++    */
++
++   if( s3vPriv.chip == S3_SAVAGE_MX )
++      S3SAVSetTextMode();
++#endif
++
+    /* Restore S3 extended regs */
+    outb(vgaCRIndex, 0x66);             
+    outb(vgaCRReg, restore->CR66);
+@@ -623,6 +670,8 @@
+    outb(vgaCRReg, restore->CR3A);
+    outb(vgaCRIndex, 0x31);    
+    outb(vgaCRReg, restore->CR31);
++   outb(vgaCRIndex, 0x32);    
++   outb(vgaCRReg, restore->CR32);
+    outb(vgaCRIndex, 0x58);             
+    outb(vgaCRReg, restore->CR58);
+ 
+@@ -637,6 +686,19 @@
+    outb(0x3c4, 0x15);
+    outb(0x3c5, restore->SR15); 
+ 
++   /* Restore flat panel expansion regsters. */
++   if( s3vPriv.chip == S3_SAVAGE_MX ) {
++      int i;
++      for( i = 0; i < 8; i++ ) {
++         outb(0x3c4, 0x54+i);
++	 outb(0x3c5, restore->SR54[i]);
++      }
++   }
++
++   outb(vgaCRIndex, 0x67);             
++   cr67 = inb(vgaCRReg) & 0xf; /* Possible hardware bug on VX? */
++   outb(vgaCRReg, 0);
++
+    /* Restore the standard VGA registers */
+    vgaHWRestore((vgaHWPtr)restore);
+ 
+@@ -660,7 +722,9 @@
+    /* Restore the desired video mode with CR67 */
+         
+    outb(vgaCRIndex, 0x67);             
++#if 0
+    cr67 = inb(vgaCRReg) & 0xf; /* Possible hardware bug on VX? */
++#endif
+    outb(vgaCRReg, 0x50 | cr67); 
+    usleep(10000);
+    outb(vgaCRIndex, 0x67);             
+@@ -703,6 +767,9 @@
+    outb(vgaCRIndex, 0xB0); /* Savage4 config3 */
+    outb(vgaCRReg, restore->CRB0);
+ 
++   outb(vgaCRIndex, 0x32);
++   outb(vgaCRReg, restore->CR32);
++
+    /* Unlock extended sequencer regs */
+    outb(0x3c4, 0x08);
+    outb(0x3c5, 0x06); 
+@@ -890,13 +957,15 @@
+    outb(0x3c5, 0x06); 
+ 
+    /* Now we save all the s3 extended regs we need */
+-   outb(vgaCRIndex, 0x31);             
++   outb(vgaCRIndex, 0x31);
+    save->CR31 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x34);             
++   outb(vgaCRIndex, 0x32);
++   save->CR32 = inb(vgaCRReg);
++   outb(vgaCRIndex, 0x34);
+    save->CR34 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x36);             
++   outb(vgaCRIndex, 0x36);
+    save->CR36 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x3a);             
++   outb(vgaCRIndex, 0x3a);
+    save->CR3A = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x40);
+    save->CR40 = inb(vgaCRReg);
+@@ -908,15 +977,15 @@
+    save->CR50 = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x51);
+    save->CR51 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x53);             
++   outb(vgaCRIndex, 0x53);
+    save->CR53 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x58);             
++   outb(vgaCRIndex, 0x58);
+    save->CR58 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x66);             
++   outb(vgaCRIndex, 0x66);
+    save->CR66 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x67);             
++   outb(vgaCRIndex, 0x67);
+    save->CR67 = inb(vgaCRReg);
+-   outb(vgaCRIndex, 0x68);             
++   outb(vgaCRIndex, 0x68);
+    save->CR68 = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x69);
+    save->CR69 = inb(vgaCRReg);
+@@ -971,6 +1040,15 @@
+    outb(0x3c4, 0x18);
+    save->SR18 = inb(0x3c5);
+ 
++   /* Save flat panel expansion regsters. */
++
++   if( s3vPriv.chip == S3_SAVAGE_MX ) {
++      int i;
++      for( i = 0; i < 8; i++ ) {
++         outb(0x3c4, 0x54+i);
++	 save->SR54[i] = inb(0x3c5);
++      }
++   }
+ 
+    /* And if streams is to be used, save that as well */
+ 
+@@ -1066,58 +1144,58 @@
+ static Bool
+ S3SAVProbe()
+ {
+-S3PCIInformation *pciInfo = NULL;
+-unsigned char config1, m, n, n1, n2, cr66, sr8;
+-int mclk;
+-DisplayModePtr pMode, pEnd;
+-
+-   if (vga256InfoRec.chipset) {
+-      if (StrCaseCmp(vga256InfoRec.chipset,S3SAVIdent(0)))
+-      return(FALSE);
+-   } 
+-
+-   /* Start with PCI probing, this should get us quite far already */
+-
+-   pciInfo = S3SAVGetPCIInfo();
+-   if (!pciInfo)
+-      return FALSE;
+-
+-   if (pciInfo && pciInfo->MemBase && !vga256InfoRec.MemBase) {
+-      if (pciInfo->ChipType >= S3_SAVAGE4) {
+-	 s3vPriv.MmioBase = pciInfo->MemBase + S3_NEWMMIO_REGBASE_S4;
+-	 s3vPriv.FrameBufferBase = pciInfo->MemBase1;
+-      }
+-      else {
++    S3PCIInformation *pciInfo = NULL;
++    unsigned char config1, m, n, n1, n2, cr66, sr8;
++    int mclk;
++    DisplayModePtr pMode, pEnd;
++
++    if (vga256InfoRec.chipset) {
++	if (StrCaseCmp(vga256InfoRec.chipset,S3SAVIdent(0)))
++	    return(FALSE);
++    } 
++
++    /* Start with PCI probing, this should get us quite far already */
++
++    pciInfo = S3SAVGetPCIInfo();
++    if (!pciInfo)
++	return FALSE;
++ 
++    if( !S3_SAVAGE_SERIES(pciInfo->ChipType) ) {
++       if (xf86Verbose > 1)
++	  ErrorF("%s %s: Unsupported (non-Savage) S3 chipset detected!\n", 
++	     XCONFIG_PROBED, vga256InfoRec.name);
++       return FALSE;
++    }
++    else {
++	s3vPriv.chip = pciInfo->ChipType;
++	ErrorF("%s %s: Detected S3 %s\n", XCONFIG_PROBED, vga256InfoRec.name, 
++	    xf86TokenToString(s3savChipTable, s3vPriv.chip));
++	ErrorF("%s %s: using driver for chipset \"%s\"\n",XCONFIG_PROBED, 
++	    vga256InfoRec.name, S3SAVIdent(0));
++    }
++
++    if( vgaBitsPerPixel == 24 ) {
++	ErrorF("%s %s: %s: This server cannot do depth 24.  Use depth 32.",
++	    XCONFIG_GIVEN, vga256InfoRec.name, vga256InfoRec.chipset
++	);
++	return FALSE;
++    }
++ 
++   if( pciInfo->MemBase && !vga256InfoRec.MemBase) {
++      if( S3_SAVAGE3D_SERIES(pciInfo->ChipType) ) {
+ 	 s3vPriv.MmioBase = pciInfo->MemBase + S3_NEWMMIO_REGBASE_S3;
+ 	 s3vPriv.FrameBufferBase = pciInfo->MemBase;
+       }
+-      vga256InfoRec.MemBase = s3vPriv.FrameBufferBase;
+-   }
+-   if (pciInfo)
+-      if(pciInfo->ChipType != S3_SAVAGE3D && 
+-	 pciInfo->ChipType != S3_SAVAGE3D_MV &&
+-	 pciInfo->ChipType != S3_SAVAGE4 &&
+-	 pciInfo->ChipType != S3_SAVAGE2000){
+-          if (xf86Verbose > 1)
+-             ErrorF("%s %s: Unsupported (non-Savage) S3 chipset detected!\n", 
+-                XCONFIG_PROBED, vga256InfoRec.name);
+-          return FALSE;
+-          }
+       else {
+-         s3vPriv.chip = pciInfo->ChipType;
+-         ErrorF("%s %s: Detected S3 %s\n",XCONFIG_PROBED,
+-            vga256InfoRec.name, xf86TokenToString(s3savChipTable, s3vPriv.chip));
+-         ErrorF("%s %s: using driver for chipset \"%s\"\n",XCONFIG_PROBED, 
+-            vga256InfoRec.name, S3SAVIdent(0));
+-	 }
++	 s3vPriv.MmioBase = pciInfo->MemBase + S3_NEWMMIO_REGBASE_S4;
++	 s3vPriv.FrameBufferBase = pciInfo->MemBase1;
++      }
++   }
+ 
+    vga256InfoRec.chipset = S3SAVIdent(0);
+ 
+-#ifdef __alpha__
+-   if (xf86bpp > 16)
+-     FatalError("%s %s: %d bpp not yet supported for Alpha/AXP\n",
+-		XCONFIG_GIVEN, vga256InfoRec.name, xf86bpp);
+-#endif
++   if( s3vPriv.FrameBufferBase && !vga256InfoRec.MemBase )
++      vga256InfoRec.MemBase = (CARD32)s3vPriv.FrameBufferBase;
+ 
+    /* Add/enable IO ports to list: call EnterLeave */
+    S3SAVEnterLeave(ENTER);
+@@ -1139,48 +1217,34 @@
+    /* And compute the amount of video memory and offscreen memory */
+    s3vPriv.MemOffScreen = 0;
+    if (!vga256InfoRec.videoRam) {
+-      if( (s3vPriv.ChipId == PCI_SAVAGE4) ||
+-      	  (s3vPriv.ChipId == PCI_SAVAGE2000)
+-      ) {
+-	 switch (config1 >> 5) {
+-	 case 0:
+-	    vga256InfoRec.videoRam = 2;
+-	    break;
+-	 case 1:
+-	    vga256InfoRec.videoRam = 4;
++      static unsigned char RamSavage3D[] = { 8, 4, 4, 2 };
++      static unsigned char RamSavage4[] =  { 2, 4, 8, 12, 16, 32, 64, 2 };
++      static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 };
++      static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 };
++
++      switch( s3vPriv.chip ) {
++         case S3_SAVAGE3D:
++         case S3_SAVAGE3D_MV:
++	    vga256InfoRec.videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ];
+ 	    break;
+-	 case 2:
+-	    vga256InfoRec.videoRam = 8;
+-	    break;
+-	 case 3:
+-	    vga256InfoRec.videoRam = 12;
+-	    break;
+-	 case 4:
+-	    vga256InfoRec.videoRam = 16;
++
++         case S3_SAVAGE4:
++         case S3_SAVAGE2000:
++	    vga256InfoRec.videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ];
+ 	    break;
+-	 case 5:
+-	    vga256InfoRec.videoRam = 32;
++
++	 case S3_SAVAGE_MX:
++	    vga256InfoRec.videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ];
+ 	    break;
+-	 case 6:
+-	    vga256InfoRec.videoRam = 64;
++
++	 case S3_SAVAGE_370:
++	    vga256InfoRec.videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ];
+ 	    break;
++
+ 	 default:
+-	    vga256InfoRec.videoRam = 2;
+-         }  
+-      }
+-      else {
+-	 switch((config1 & 0xC0) >> 6) {
+-	 case 0:
+-	    vga256InfoRec.videoRam = 8;
+-	    break;
+-	 case 1:
+-	 case 2:
+-	    vga256InfoRec.videoRam = 4;
++	    /* How did we get here? */
++	    vga256InfoRec.videoRam = 0;
+ 	    break;
+-	 case 3:
+-	 default:
+-	    vga256InfoRec.videoRam = 2;
+-	 }
+       }
+ 
+       vga256InfoRec.videoRam *= 1024;
+@@ -1217,27 +1281,17 @@
+    if (vga256InfoRec.dacSpeeds[3] <= 0 && vga256InfoRec.dacSpeeds[2] > 0)
+       vga256InfoRec.dacSpeeds[3] = vga256InfoRec.dacSpeeds[2];
+ 
+-   if (s3vPriv.chip == S3_SAVAGE3D ||
+-       s3vPriv.chip == S3_SAVAGE3D_MV ||
+-       s3vPriv.chip == S3_SAVAGE4 ||
+-       s3vPriv.chip == S3_SAVAGE2000) {
+-      if (vga256InfoRec.dacSpeeds[0] <= 0) vga256InfoRec.dacSpeeds[0] = 250000;
+-      if (vga256InfoRec.dacSpeeds[1] <= 0) vga256InfoRec.dacSpeeds[1] = 250000;
+-      if (vga256InfoRec.dacSpeeds[2] <= 0) vga256InfoRec.dacSpeeds[2] = 220000;
+-      if (vga256InfoRec.dacSpeeds[3] <= 0) vga256InfoRec.dacSpeeds[3] = 220000;
+-   }
+-   else {
+-      if (vga256InfoRec.dacSpeeds[0] <= 0) vga256InfoRec.dacSpeeds[0] = 250000;
+-      if (vga256InfoRec.dacSpeeds[1] <= 0) vga256InfoRec.dacSpeeds[1] = 250000;
+-      if (vga256InfoRec.dacSpeeds[2] <= 0) vga256InfoRec.dacSpeeds[2] = 220000;
+-      if (vga256InfoRec.dacSpeeds[3] <= 0) vga256InfoRec.dacSpeeds[3] = 220000;
+-   }
++   if (vga256InfoRec.dacSpeeds[0] <= 0) vga256InfoRec.dacSpeeds[0] = 250000;
++   if (vga256InfoRec.dacSpeeds[1] <= 0) vga256InfoRec.dacSpeeds[1] = 250000;
++   if (vga256InfoRec.dacSpeeds[2] <= 0) vga256InfoRec.dacSpeeds[2] = 220000;
++   if (vga256InfoRec.dacSpeeds[3] <= 0) vga256InfoRec.dacSpeeds[3] = 220000;
+ 
+    /* Set status word positions based on chip type. */
+ 
+    switch( s3vPriv.chip ) {
+       case S3_SAVAGE3D:
+       case S3_SAVAGE3D_MV:
++      case S3_SAVAGE_MX:
+          s3vPriv.WaitQueue = WaitQueue3D;
+ 	 s3vPriv.WaitIdle = WaitIdle3D;
+ 	 s3vPriv.WaitIdleEmpty = WaitIdleEmpty3D;
+@@ -1245,6 +1299,7 @@
+ 	 break;
+ 
+       case S3_SAVAGE4:
++      case S3_SAVAGE_370:
+          s3vPriv.WaitQueue = WaitQueue4;
+ 	 s3vPriv.WaitIdle = WaitIdle4;
+ 	 s3vPriv.WaitIdleEmpty = WaitIdleEmpty4;
+@@ -1325,7 +1380,7 @@
+       s3vPriv.HorizScaleFactor = 1;
+       }
+    else if (vgaBitsPerPixel == 16){
+-      s3vPriv.HorizScaleFactor = 2;
++      s3vPriv.HorizScaleFactor = 1;
+       }
+    else {     
+       s3vPriv.HorizScaleFactor = 1;
+@@ -1333,8 +1388,14 @@
+ 
+ 
+    /* And map MMIO memory, abort if we cannot */
+-   s3savMmioMem = xf86MapVidMem(vga256InfoRec.scrnIndex, MMIO_REGION,
+-	     (pointer) s3vPriv.MmioBase, S3_NEWMMIO_REGSIZE);
++#ifdef __alpha__
++   s3savMmioMemSparse = xf86MapVidMemSparse(
++      vga256InfoRec.scrnIndex, MMIO_REGION,
++      s3vPriv.MmioBase, S3_NEWMMIO_REGSIZE);
++#endif
++   s3savMmioMem = xf86MapVidMem(
++      vga256InfoRec.scrnIndex, MMIO_REGION,
++      s3vPriv.MmioBase, S3_NEWMMIO_REGSIZE);
+    s3vPriv.MmioMem = s3savMmioMem;
+    s3vPriv.BciMem = (char*)s3vPriv.MmioMem + 0x10000;
+ 
+@@ -1352,38 +1413,31 @@
+ #ifdef	USEBIOS
+    /* Go probe the BIOS for all the modes and refreshes at this depth. */
+ 
+-   /*
+-    * What I want here is an array of all mode numbers valid for this
+-    * depth, and the list of valid refresh rates to go with them.  
+-    *
+-    * x, y, mode, array[8] of refresh
+-    */
+-
+    if( s3vModeTable )
+    {
+-      xfree( s3vModeTable );
++      S3SAVFreeBIOSModeTable( &s3vModeTable );
+    }
+    
+-   s3vModeCount = S3SAVGetBIOSModeCount( vgaBitsPerPixel );
++   s3vModeTable = S3SAVGetBIOSModeTable( vgaBitsPerPixel );
+ 
+-   if( !s3vModeCount ) {
++   if( !s3vModeTable || !s3vModeTable->NumModes ) {
+      FatalError("%s %s: Failed to fetch any BIOS modes.\n",
+        XCONFIG_PROBED, vga256InfoRec.name
+      );
+    }
+ 
+-   s3vModeTable = (S3VMODETABLE*)xcalloc(sizeof(S3VMODETABLE), s3vModeCount);
+-   S3SAVGetBIOSModeTable( vgaBitsPerPixel, s3vModeTable );
+-
+    if( xf86Verbose )
+    {
+       int i;
+-      S3VMODETABLE* pmt;
++      PS3VMODEENTRY pmt;
+ 
+-      ErrorF("%s %s: Found %d modes at this depth:\n", 
+-         XCONFIG_PROBED, vga256InfoRec.name, s3vModeCount);
++      ErrorF( "%s %s: Found %d modes at this depth:\n", 
++         XCONFIG_PROBED, vga256InfoRec.name, s3vModeTable->NumModes);
+       
+-      for( i = 0, pmt = s3vModeTable; i < s3vModeCount; i++, pmt++ )
++      for(
++	  i = 0, pmt = s3vModeTable->Modes; 
++	  i < s3vModeTable->NumModes; 
++	  i++, pmt++ )
+       {
+          int j;
+          ErrorF( "[%03x] %d x %d", pmt->VesaMode, pmt->Width, pmt->Height );
+@@ -1480,9 +1534,7 @@
+          ErrorF("%s %s: %s: Horizontal mode timing overflow (%d)\n",
+             XCONFIG_PROBED, vga256InfoRec.name,
+             vga256InfoRec.chipset, mode->HTotal);
+-#ifndef	USEBIOS
+          return MODE_BAD;
+-#endif
+          }
+    if (mode->VTotal > 2047) {
+       if(verbose)
+@@ -1530,7 +1582,8 @@
+ unsigned char tmp;
+ 
+    if(s3vPriv.STREAMSRunning == FALSE) {
+-      Base = ((y * vga256InfoRec.displayWidth + x)
++      /* We can only adjust to even x's. */
++      Base = ((y * vga256InfoRec.displayWidth + (x & ~1))
+ 		* (vgaBitsPerPixel / 8)) >> 2;
+       if (vgaBitsPerPixel == 24) 
+ 	Base = Base+2 - (Base+2) % 3;
+@@ -1538,8 +1591,7 @@
+       /* Now program the start address registers */
+       outw(vgaCRIndex, (Base & 0x00FF00) | 0x0C);
+       outw(vgaCRIndex, ((Base & 0x00FF) << 8) | 0x0D);
+-      outb(vgaCRIndex, 0x69);
+-      outb(vgaCRReg, (Base & 0xFF0000) >> 16);   
++      outw(vgaCRIndex, ((Base & 0xFF0000) >> 8) | 0x69);
+       }
+    else {          /* Change start address for STREAMS case */
+       VerticalRetraceWait();
+@@ -1643,7 +1695,7 @@
+ int i, j;
+ unsigned int Refresh;
+ #ifdef USEBIOS
+-S3VMODETABLE * pmt;
++S3VMODEENTRY * pmt;
+ #endif
+ 
+    /* First we adjust the horizontal timings if needed */
+@@ -1678,7 +1730,9 @@
+    ErrorF( "Desired refresh rate = %dHz\n", Refresh );
+ #endif
+ 
+-   for( i = 0, pmt = s3vModeTable; i < s3vModeCount; i++, pmt++ )
++   for( i = 0, pmt = s3vModeTable->Modes; 
++      i < s3vModeTable->NumModes;
++      i++, pmt++ )
+    {
+       if( (pmt->Width == mode->HDisplay) && (pmt->Height == mode->VDisplay) )
+       {
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_driver.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_driver.h	Fri Dec  3 10:46:01 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h	Mon Jun 19 20:20:50 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h,v 1.1.2.2 1999/12/01 12:49:34 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h,v 1.1.2.1 1999/07/30 11:21:34 hohndel Exp $ */
+ 
+ /* Header file for ViRGE server */
+ 
+@@ -19,10 +19,10 @@
+    unsigned int refresh;
+ 
+    unsigned char SR8, SR10, SR11, SR12, SR13, SR15, SR18, SR29; /* SR9-SR1C, ext seq. */
+-   /*unsigned char SR54, SR55, SR56, SR57;*/
++   unsigned char SR54[8];
+    unsigned char Clock;
+    unsigned char s3DacRegs[0x101];
+-   unsigned char CR31, CR33, CR34, CR36, CR3A, CR3B, CR3C;
++   unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
+    unsigned char CR40, CR42, CR43, CR45;
+    unsigned char CR50, CR51, CR53, CR58, CR5B, CR5D, CR5E;
+    unsigned char CR65, CR66, CR67, CR68, CR69, CR6F; /* Video attrib. */
+@@ -47,8 +47,8 @@
+    int DevID;
+    int ChipType;
+    int ChipRev;
+-   unsigned long MemBase;
+-   unsigned long MemBase1;
++   unsigned char * MemBase;
++   unsigned char * MemBase1;
+ } S3PCIInformation;
+ 
+ /* Private data structure used for storing all variables needed in driver */
+@@ -57,8 +57,8 @@
+ typedef struct {
+    int chip;
+    unsigned short ChipId;
+-   unsigned int MmioBase;
+-   unsigned int FrameBufferBase;
++   unsigned char * MmioBase;
++   unsigned char * FrameBufferBase;
+    pointer MmioMem;
+    pointer BciMem;
+    int MemOffScreen;
+@@ -82,13 +82,20 @@
+ /* VESA BIOS Mode information. */
+ 
+ #ifdef USEBIOS
+-typedef struct _S3VMODETABLE {
++
++typedef struct _S3VMODEENTRY {
+    unsigned short Width;
+    unsigned short Height;
+    unsigned short VesaMode;
+    unsigned char RefreshCount;
+-   unsigned char RefreshRate[8];
++   unsigned char * RefreshRate;
++} S3VMODEENTRY, * PS3VMODEENTRY;
++
++typedef struct _S3VMODETABLE {
++   unsigned short NumModes;
++   S3VMODEENTRY Modes[1];
+ } S3VMODETABLE, * PS3VMODETABLE;
++
+ #endif
+ 
+ /* Function prototypes */
+@@ -99,8 +106,8 @@
+ extern void S3SAVWarpCursor();
+ extern void S3SAVQueryBestSize();
+ #ifdef USEBIOS
+-extern unsigned short S3SAVGetBIOSModeCount( int );
+-extern unsigned short S3SAVGetBIOSModeTable( int, S3VMODETABLE* );
++extern S3VMODETABLE* S3SAVGetBIOSModeTable( int );
++extern void S3SAVFreeBIOSModeTable( S3VMODETABLE** );
+ extern void S3SAVSetVESAMode( int, int );
+ extern void S3SAVSetTextMode( );
+ #endif
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_misc.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_misc.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_misc.c	Mon Dec 20 17:39:33 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_misc.c	Thu Feb 10 20:45:26 2000
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_misc.c,v 1.1.2.3 1999/12/20 14:36:28 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_misc.c,v 1.1.2.1 1999/07/30 11:21:35 hohndel Exp $ */
+ 
+ /*
+  *
+@@ -48,10 +48,26 @@
+ #include "regs3sav.h"
+ #include "s3sav_driver.h"
+ 
++/** Why isn't all of this included in s3sav_driver.c? **/
++
+ extern vgaPCIInformation *vgaPCIInfo;
+ extern SymTabRec s3savChipTable[];
+ extern S3VPRIV s3vPriv;
+ 
++static S3PCIInformation Mappings[] = {
++    { PCI_SAVAGE3D,	S3_SAVAGE3D },
++    { PCI_SAVAGE3D_MV,	S3_SAVAGE3D_MV },
++    { PCI_SAVAGE4,	S3_SAVAGE4 },
++    { PCI_SAVAGE2000,	S3_SAVAGE2000 },
++    { PCI_SAVAGE_MX_MV,	S3_SAVAGE_MX },
++    { PCI_SAVAGE_MX,	S3_SAVAGE_MX },
++    { PCI_SAVAGE_IX_MV,	S3_SAVAGE_MX },
++    { PCI_SAVAGE_IX,	S3_SAVAGE_MX },
++    { PCI_SAVAGE_370,	S3_SAVAGE_370 },
++};
++
++#define NMAPPINGS	(sizeof(Mappings)/sizeof(Mappings[0]))
++
+ 
+ /*
+  * s3vGetPCIInfo -- probe for PCI information
+@@ -68,42 +84,45 @@
+ 
+    if (vgaPCIInfo && vgaPCIInfo->AllCards) {
+       while (pcrp = vgaPCIInfo->AllCards[i]) {
+-         if (pcrp->_vendor == PCI_S3_VENDOR_ID &&
+-	     (pcrp->_base_class == PCI_CLASS_DISPLAY) &&
+-	     (pcrp->_sub_class == PCI_SUBCLASS_DISPLAY_VGA) &&
+-	     pcrp->_command != 0) {
++         if((pcrp->_vendor == PCI_S3_VENDOR_ID) && 
++	    (pcrp->_base_class == PCI_CLASS_DISPLAY) &&
++	    (pcrp->_sub_class == PCI_SUBCLASS_DISPLAY_VGA) &&
++	    (pcrp->_command != 0)
++	 ) {
+ 	    int ChipId = pcrp->_device;
++	    int j;
+ 	    if (vga256InfoRec.chipID) {
+ 	      ErrorF("%s %s: S3 chipset override, using chip_id = 0x%04x instead of 0x%04x\n",
+ 		  XCONFIG_GIVEN, vga256InfoRec.name, vga256InfoRec.chipID, ChipId);
+ 	      ChipId = vga256InfoRec.chipID;
+ 	    }
+ 	    found = TRUE;
++	
++	    for( j = 0; j < NMAPPINGS; j++ )
++	    {
++		if( ChipId == Mappings[j].DevID ) {
++		    info.ChipType = Mappings[j].ChipType;
++		    break;
++		}
++	    }
+ 
+-	    switch (ChipId) {
+-	    case PCI_SAVAGE3D:
+-	       info.ChipType = S3_SAVAGE3D;
+-	       break;
+-	    case PCI_SAVAGE3D_MV:
+-	       info.ChipType = S3_SAVAGE3D_MV;
+-	       break;
+-	    case PCI_SAVAGE4:
+-	       info.ChipType = S3_SAVAGE4;
+-	       break;
+-	    case PCI_SAVAGE2000:
+-	       info.ChipType = S3_SAVAGE2000;
+-	       break;
+-	    default:
+-	       info.ChipType = S3_UNKNOWN;
+-	       info.DevID = pcrp->_device;
+-	       break;
++	    if( j >= NMAPPINGS )
++	    {
++		info.ChipType = S3_UNKNOWN;
++		info.DevID = pcrp->_device;
+ 	    }
++
+ 	    info.ChipRev = pcrp->_rev_id;
+-	    if( (ChipId == PCI_SAVAGE4) || (ChipId == PCI_SAVAGE2000) ) {
+-	       info.MemBase = pcrp->_base0 & 0xFFFFFFF0;
+-	       info.MemBase1 = pcrp->_base1 & 0xFFFFFFF0;
++
++	    info.MemBase = pcrp->_base0 & 0xFFFFFFF0;
++
++	    if(
++		(ChipId == PCI_SAVAGE4) ||
++		(ChipId == PCI_SAVAGE2000) ||
++		(ChipId == PCI_SAVAGE_370)
++	    ) {
++		info.MemBase1 = pcrp->_base1 & 0xFFFFFFF0;
+ 	    }
+-	    else info.MemBase = pcrp->_base0 & 0xFFFFFFF0;
+ 	    break;
+          }
+       i++;
+diff -u xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_vbe.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_vbe.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage.336/s3sav_vbe.c	Fri Jul 30 13:21:37 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_vbe.c	Mon Jun 19 22:37:41 2000
+@@ -45,6 +45,8 @@
+ #include "vbe.h"
+ 
+ #ifdef USEBIOS
++unsigned short
++S3SAVGetBIOSModes( int, S3VMODEENTRY* );
+ 
+ struct
+ {
+@@ -137,16 +139,24 @@
+ void
+ S3SAVSetTextMode(void)
+ {
+-   struct LRMI_regs r;
++    struct LRMI_regs r;
+ 
+-   memset(&r, 0, sizeof(r));
++    ioperm( 0x80, 1, 1 );
++    ioperm( 0x61, 1, 1 );
++    ioperm( 0x40, 4, 1 );
+ 
+-   r.eax = 3;
++    memset(&r, 0, sizeof(r));
++
++    r.eax = 0x83;
++
++    if (!LRMI_int(0x10, &r))
++    {
++	ErrorF("Can't set text mode (vm86 failure)\n");
++    }
+ 
+-   if (!LRMI_int(0x10, &r))
+-   {
+-      ErrorF("Can't set text mode (vm86 failure)\n");
+-   }
++    ioperm( 0x40, 4, 0 );
++    ioperm( 0x61, 1, 0 );
++    ioperm( 0x80, 1, 1 );
+ }
+ 
+ 
+@@ -156,10 +166,12 @@
+     struct LRMI_regs r;
+ 
+     /* 
+-     * The Savage BIOS also writes to a debug card on port 80h.  It 
+-     * shouldn't, but we can work around it here.
++     * The Savage BIOS writes to a debug card on port 80h and to the
++     * timer chip at port 61.
+      */
+     ioperm( 0x80, 1, 1 );
++    ioperm( 0x61, 1, 1 );
++    ioperm( 0x40, 4, 1 );
+ 
+     /* First, establish the refresh rate for this mode. */
+ 
+@@ -177,13 +189,6 @@
+ 
+     /* Now, make this mode current. */
+ 
+-    /*
+-     * The Savage BIOS reprograms the timer chip.  One could argue that
+-     * these ports should be virtualized rather than laid wide open.
+-     */
+-    ioperm( 0x40, 4, 1 );
+-    ioperm( 0x61, 1, 1 );
+-
+     memset(&r, 0, sizeof(r));
+ 
+     r.eax = 0x4f02;
+@@ -204,15 +209,43 @@
+ }
+ 
+ 
+-unsigned short
+-S3SAVGetBIOSModeCount( int iDepth )
++void
++S3SAVFreeBIOSModeTable( S3VMODETABLE** ppTable )
+ {
+-    return S3SAVGetBIOSModeTable( iDepth, NULL );
++    int i;
++    PS3VMODEENTRY pMode = (*ppTable)->Modes;
++
++    for( i = (*ppTable)->NumModes; i--; )
++    {
++	if( pMode->RefreshRate )
++	{
++	    xfree( pMode->RefreshRate );
++	    pMode->RefreshRate = NULL;
++	}
++    }
++
++    xfree( *ppTable );
+ }
+ 
++S3VMODETABLE*
++S3SAVGetBIOSModeTable( int iDepth )
++{
++    int nModes = S3SAVGetBIOSModes( iDepth, NULL );
++    PS3VMODETABLE pTable;
++
++    pTable = (PS3VMODETABLE) 
++	xcalloc( 1, sizeof(S3VMODETABLE) + (nModes-1) * sizeof(S3VMODEENTRY) );
++    if( !pTable )
++	return NULL;
++
++    pTable->NumModes = nModes;
++    S3SAVGetBIOSModes( iDepth, pTable->Modes );
++
++    return pTable;
++}
+ 
+ unsigned short
+-S3SAVGetBIOSModeTable( int iDepth, S3VMODETABLE* s3vModeTable )
++S3SAVGetBIOSModes( int iDepth, S3VMODEENTRY* s3vModeTable )
+ {
+     struct LRMI_regs r;
+     short int *mode_list;
+@@ -325,6 +358,26 @@
+ 
+ 		do
+ 		{
++		    if( (iRefresh % 8) == 0 )
++		    {
++			if( s3vModeTable->RefreshRate )
++			{
++			    s3vModeTable->RefreshRate = (unsigned char *)
++				xrealloc( 
++				    s3vModeTable->RefreshRate,
++				    (iRefresh+8) * sizeof(unsigned char)
++				);
++			}
++			else
++			{
++			    s3vModeTable->RefreshRate = (unsigned char *)
++				xcalloc( 
++				    sizeof(unsigned char),
++				    (iRefresh+8)
++				);
++			}
++		    }
++
+ 		    r.eax = 0x4f14;
+ 		    r.ebx = 0x0201;		/* query refresh rates */
+ 		    if( !LRMI_int(0x10, &r) )
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-04-s3trio3d2x
+++ xfree86-1-3.3.6/debian/patches/0000fix-04-s3trio3d2x
@@ -0,0 +1,75 @@
+diff -u clean/xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.h
+--- clean/xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.h	Tue Jan 11 20:01:01 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.h	Mon Mar 13 16:56:47 2000
+@@ -19,7 +19,7 @@
+    unsigned char CR40, CR41, CR42, CR43, CR45;
+    unsigned char CR51, CR53, CR54, CR55, CR58, CR5D, CR5E;
+    unsigned char CR63, CR65, CR66, CR67, CR68, CR69, CR6D; /* Video attrib. */
+-   unsigned char CR86;
++   unsigned char CR85, CR86;
+    unsigned char CR90, CR91;
+    unsigned char ColorStack[8]; /* S3 hw cursor color stack CR4A/CR4B */
+    unsigned int  STREAMS[22];   /* Streams regs */
+diff -u clean/xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c
+--- clean/xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c	Tue Jan 11 20:01:01 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c	Tue Mar 14 01:05:09 2000
+@@ -471,6 +471,10 @@
+ 
+    outb(vgaCRIndex, 0x33);
+    outb(vgaCRReg, restore->CR33);
++   if (S3_TRIO_3D_2X_SERIES(s3vPriv.chip)) {
++      outb(vgaCRIndex, 0x85);
++      outb(vgaCRReg, restore->CR85);
++   }
+    if (s3vPriv.chip == S3_ViRGE_DXGX) {
+       outb(vgaCRIndex, 0x86);
+       outb(vgaCRReg, restore->CR86);
+@@ -702,6 +706,10 @@
+ 
+    outb(vgaCRIndex, 0x33);             
+    save->CR33 = inb(vgaCRReg);
++   if (S3_TRIO_3D_2X_SERIES(s3vPriv.chip)) {
++      outb(vgaCRIndex, 0x85);
++      save->CR85 = inb(vgaCRReg);
++   }
+    if (s3vPriv.chip == S3_ViRGE_DXGX) {
+       outb(vgaCRIndex, 0x86);
+       save->CR86 = inb(vgaCRReg);
+@@ -970,10 +978,12 @@
+       }
+       else if (S3_TRIO_3D_2X_SERIES(s3vPriv.chip)) {
+          switch((config1 & 0xE0) >> 5) {
+-         case 0:
+-            vga256InfoRec.videoRam = 8 * 1024;
++         case 0:  /* 8MB -- only 4MB usable for display/cursor */
++            vga256InfoRec.videoRam = 4 * 1024;
++            s3vPriv.MemOffScreen   = 4 * 1024;
+             break;
+          case 1:    /* 32 bit interface -- yuck */
++	    ErrorF("%s %s: found 32 bit interface for video memory -- yuck:(\n");
+          case 2:
+             vga256InfoRec.videoRam = 4 * 1024;
+             break;
+@@ -1071,6 +1081,12 @@
+       if (vga256InfoRec.dacSpeeds[2] <= 0) vga256InfoRec.dacSpeeds[2] = 135000;
+       if (vga256InfoRec.dacSpeeds[3] <= 0) vga256InfoRec.dacSpeeds[3] = 135000;
+    }
++   else if (S3_TRIO_3D_2X_SERIES(s3vPriv.chip)) {
++      if (vga256InfoRec.dacSpeeds[0] <= 0) vga256InfoRec.dacSpeeds[0] = 230000;
++      if (vga256InfoRec.dacSpeeds[1] <= 0) vga256InfoRec.dacSpeeds[1] = 230000;
++      if (vga256InfoRec.dacSpeeds[2] <= 0) vga256InfoRec.dacSpeeds[2] = 135000;
++      if (vga256InfoRec.dacSpeeds[3] <= 0) vga256InfoRec.dacSpeeds[3] = 135000;
++   }
+    else if (s3vPriv.chip == S3_ViRGE_DXGX || S3_ViRGE_GX2_SERIES(s3vPriv.chip)) {
+       if (vga256InfoRec.dacSpeeds[0] <= 0) vga256InfoRec.dacSpeeds[0] = 170000;
+       if (vga256InfoRec.dacSpeeds[1] <= 0) vga256InfoRec.dacSpeeds[1] = 170000;
+@@ -1874,6 +1890,9 @@
+    new->CR33 = 0x20;
+    if ((s3vPriv.chip == S3_ViRGE_DXGX) || (S3_TRIO_3D_SERIES(s3vPriv.chip))) {
+       new->CR86 = 0x80;  /* disable DAC power saving to avoid bright left edge */
++   }
++   if (S3_TRIO_3D_2X_SERIES(s3vPriv.chip)) {
++      new->CR85 = 0x1f;  /* avoid sreen flickering */
+    }
+    if (s3vPriv.chip == S3_ViRGE_DXGX || S3_ViRGE_GX2_SERIES(s3vPriv.chip) || 
+        S3_ViRGE_MX_SERIES(s3vPriv.chip) || S3_TRIO_3D_SERIES(s3vPriv.chip)) {
--- xfree86-1-3.3.6.orig/debian/patches/061_s3sav_cursor.c_fix.diff
+++ xfree86-1-3.3.6/debian/patches/061_s3sav_cursor.c_fix.diff
@@ -0,0 +1,11 @@
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c~	Mon Oct  9 14:40:44 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_cursor.c	Mon Oct  9 14:40:58 2000
+@@ -250,7 +250,7 @@
+    /* VerticalRetraceWait(); */
+ 
+    /* turn cursor off */
+-   S3VHideCursor();
++   S3SAVHideCursor();
+ 
+    /* move cursor off-screen */
+    outb(vgaCRIndex, 0x46);
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-06-s3trio3d2x
+++ xfree86-1-3.3.6/debian/patches/0000fix-06-s3trio3d2x
@@ -0,0 +1,12 @@
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c~	Wed May 24 08:23:35 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_driver.c	Tue Jun 13 16:30:41 2000
+@@ -983,7 +983,8 @@
+             s3vPriv.MemOffScreen   = 4 * 1024;
+             break;
+          case 1:    /* 32 bit interface -- yuck */
+-	    ErrorF("%s %s: found 32 bit interface for video memory -- yuck:(\n");
++	    ErrorF("%s %s: found 32 bit interface for video memory -- yuck:(\n",
++		  XCONFIG_PROBED, vga256InfoRec.name);
+          case 2:
+             vga256InfoRec.videoRam = 4 * 1024;
+             break;
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-07-s3trio64v2gx+netfinity
+++ xfree86-1-3.3.6/debian/patches/0000fix-07-s3trio64v2gx+netfinity
@@ -0,0 +1,157 @@
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/newmmio.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/newmmio.h
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/newmmio.h	Sat Feb  7 11:05:30 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/newmmio.h	Thu May 25 18:23:41 2000
+@@ -248,7 +248,7 @@
+ #define WaitQueue(v)					\
+ 	if(!s3PCIRetry) {				\
+ 	   mem_barrier();				\
+-	   while(inb(GP_STAT) & (0x0100 >> (v)));	\
++	   while(mmio_INB_GP_STAT() & (0x0100 >> (v)));	\
+ 	}
+ 
+ #define CMD_REG_WIDTH  0x200  	/* select 32bit command register */
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3.h
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3.h	Mon Oct 19 22:41:26 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3.h	Wed Jun 14 15:32:08 2000
+@@ -133,7 +133,9 @@
+ extern unsigned char s3InTi3026IndReg(unsigned char);
+ extern void s3OutTiIndReg(unsigned char, unsigned char, unsigned char);
+ extern unsigned char s3InTiIndReg(unsigned char);
+-  
++
++extern void S3AccelSetup();
++extern void S3AccelSetup_NewMMIO();
+ 
+ 
+ extern vgaVideoChipRec s3InfoRec;
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3accel.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3accel.c
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3accel.c	Sat Oct 24 09:55:01 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3accel.c	Wed Jun 14 15:37:11 2000
+@@ -209,6 +209,23 @@
+ 
+ }
+ 
++
++void
++#ifdef S3_NEWMMIO
++S3AccelSetup_NewMMIO() 
++#else
++S3AccelSetup() 
++#endif
++{
++  WaitQueue(5);
++  SET_SCISSORS(0,0,s3ScissR,s3ScissB);
++  if(s3Bpp > 2) {
++    if(s3newmmio)
++      SET_MULT_MISC(0x200);
++    else 
++      SET_MULT_MISC(0);
++  }
++}
+ 		/******************\
+ 		|	Sync	   |
+ 		\******************/
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3init.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3init.c
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3init.c	Sat Dec 11 18:32:06 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3init.c	Sun Jul 16 20:36:37 2000
+@@ -225,6 +225,8 @@
+ 					/* disabled anyway */
+ 
+ /* !! double negative? (MArk) */
++/* !! is used to guarantee that right hand operand of (binary) xor "^" 
++   really is a boolean 0/1 value (and not e.g. some bit mask)  (Harald) */
+    if ((S3_TRIO64V_SERIES(s3ChipId) && (s3ChipRev <= 0x53) && (s3Bpp==1)) ^
+        !!OFLG_ISSET(OPTION_TRIO64VP_BUG2, &vga256InfoRec.options)) {
+       /* set correct blanking for broken Trio64V+ to avoid bright left border:
+@@ -968,6 +970,20 @@
+    outb(DAC_MASK, 0x00);
+ 
+  /* Reset the 8514/A, and disable all interrupts. */
++
++   /* 
++    * XXX: resetting the Trio64V2/GX causes trouble with the SGRAM memory bus
++    * (gets out of sync?  same as setting CR88_6) which I don't know to fix,
++    * so better not reset that chip and cross fingers... 
++    * This happens at least for some IBM Netfinity boxes (e.g. 7000M10) with 1MB SGRAM.
++    */
++   if (S3_TRIO64V2_SERIES(s3ChipId)) {
++     outb(vgaCRIndex, 0x36);
++     tmp = inb(vgaCRReg);
++     if ((tmp & 0x0c) != 0x04) /* no SGRAM */
++       outw(SUBSYS_CNTL, GPCTRL_RESET | CHPTEST_NORMAL);
++   }
++   else /* do normal reset for S3 chip... */
+    outw(SUBSYS_CNTL, GPCTRL_RESET | CHPTEST_NORMAL);
+    outw(SUBSYS_CNTL, GPCTRL_ENAB | CHPTEST_NORMAL);
+ 
+@@ -997,14 +1013,10 @@
+ 	outb(vgaCRReg, s3SAM256);
+    }
+ 
+-   WaitQueue(5);
+-   SET_SCISSORS(0,0,s3ScissR,s3ScissB);
+-   if(s3Bpp > 2) {
+-	if(s3newmmio)
+-      	  SET_MULT_MISC(0x200);
+-	else 
+-      	  SET_MULT_MISC(0);
+-    }
++   if (s3newmmio)
++     S3AccelSetup_NewMMIO();
++   else 
++     S3AccelSetup();
+ 
+    return TRUE;
+ }
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3ramdacs.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3ramdacs.c
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3ramdacs.c	Mon Oct 19 22:41:27 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3ramdacs.c	Sun Jul 16 20:14:50 2000
+@@ -2741,7 +2741,7 @@
+ 
+       /* for Trio64+ we need corrected blank signal timing */
+       if (!(S3_TRIO64V_SERIES(s3ChipId) && (s3ChipRev <= 0x53)
+-	    || (S3_TRIO64V2_SERIES(s3ChipId))) ^ 
++	    /* || (S3_TRIO64V2_SERIES(s3ChipId)) */ ) ^ 
+ 	  !!OFLG_ISSET(OPTION_TRIO64VP_BUG1, &vga256InfoRec.options)) {
+ 	 cr33 |= 0x20;
+       }
+diff -ur xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3reg.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3reg.h
+--- xc336/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3reg.h	Sat Feb  7 11:05:45 1998
++++ xc3/programs/Xserver/hw/xfree86/vga256/drivers/s3_svga/s3reg.h	Wed Jun 14 15:19:34 2000
+@@ -441,10 +441,23 @@
+      unsigned char r, g, b;
+ } LUTENTRY;
+ 
++/*
++ * mmio reads from GP_STAT
++ */
++#if !defined(__alpha__)
++#define mmio_INB_GP_STAT() 	(*(((volatile unsigned char*)s3MmioMem)+GP_STAT) & 0xff)
++#define mmio_INW_GP_STAT() 	(*(((volatile unsigned short*)s3MmioMem)+GP_STAT/2))
++#else
++#define mmio_INB_GP_STAT() 	inb(GP_STAT)
++#define mmio_INW_GP_STAT() 	inw(GP_STAT)
++#endif
+ 
+ #define WaitIdle() 	do {  		\
+ 	mem_barrier(); 			\
+-	while(inw(GP_STAT) & GPBUSY); 	\
++	if (s3newmmio) 			\
++	    while(mmio_INW_GP_STAT() & GPBUSY); 	\
++	else 				\
++	    while(inw(GP_STAT) & GPBUSY); 	\
+ } while(0)
+ 
+ 
+@@ -466,7 +479,10 @@
+ #else
+    #define WaitQueue(v)   do {  		\
+ 	mem_barrier(); 				\
+-	while(inb(GP_STAT) & (0x0100 >> (v))); 	\
++	if (s3newmmio) 			\
++	   while(mmio_INB_GP_STAT() & (0x0100 >> (v))); 	\
++	else 				\
++	   while(inb(GP_STAT) & (0x0100 >> (v))); 	\
+    } while (0)
+ 
+    #define CMD_REG_WIDTH  0  	/* select 16bit command register */
--- xfree86-1-3.3.6.orig/debian/patches/060_SPARC_sunInit.c_access_stupidity.diff
+++ xfree86-1-3.3.6/debian/patches/060_SPARC_sunInit.c_access_stupidity.diff
@@ -0,0 +1,14 @@
+--- xc/programs/Xserver/hw/sun/sunInit.c.orig	Wed Jul 19 19:23:05 2000
++++ xc/programs/Xserver/hw/sun/sunInit.c	Wed Jul 19 19:24:17 2000
+@@ -409,8 +409,11 @@
+     sunFbs[screen].fd = -1;
+     if (strcmp (device, "/dev/fb") == 0 && devFbUsed)
+ 	return FALSE;
++#ifndef linux
++    /* access() checks real uid, not effective; bad news for mere mortals */
+     if (access (device, R_OK | W_OK) == -1)
+ 	return FALSE;
++#endif
+     if ((sunFbs[screen].fd = open(device, O_RDWR, 0)) == -1)
+ 	ret = FALSE;
+     else {
--- xfree86-1-3.3.6.orig/debian/patches/063_abs_is_in_stdlib.h_damnit.diff
+++ xfree86-1-3.3.6/debian/patches/063_abs_is_in_stdlib.h_damnit.diff
@@ -0,0 +1,23 @@
+--- xc/programs/Xserver/include/misc.h~	Tue Oct  3 19:52:01 2000
++++ xc/programs/Xserver/include/misc.h	Tue Oct  3 19:52:11 2000
+@@ -158,16 +158,16 @@
+ 
+ #define min(a, b) (((a) < (b)) ? (a) : (b))
+ #define max(a, b) (((a) > (b)) ? (a) : (b))
+-#if !defined(AMOEBA) && !defined(__EMX__)
++#ifdef X_NOT_STDC_ENV
+ #ifndef abs
+ #define abs(a) ((a) > 0 ? (a) : -(a))
+ #endif
+-#else /* AMOEBA || __EMX__ */
++#else /* we have a standard C environment */
+ /* abs() is a function, not a macro; include the file declaring
+  * it in case we haven't done that yet.
+- */  
++ */
+ #include <stdlib.h>
+-#endif /* AMOEBA */
++#endif /* X_NOT_STDC_ENV */
+ #ifndef Fabs
+ #define Fabs(a) ((a) > 0.0 ? (a) : -(a))	/* floating absolute value */
+ #endif
--- xfree86-1-3.3.6.orig/debian/patches/008_POWERPC+SPARC_mach64_fixes.diff
+++ xfree86-1-3.3.6/debian/patches/008_POWERPC+SPARC_mach64_fixes.diff
@@ -0,0 +1,96 @@
+--- xc/programs/Xserver/hw/xfree86/accel/mach64/mach64im.c.orig	Mon May 29 16:41:23 2000
++++ xc/programs/Xserver/hw/xfree86/accel/mach64/mach64im.c	Mon May 29 16:42:04 2000
+@@ -84,7 +84,7 @@
+     unsigned char bytes[4];
+ };
+ 
+-static inline unsigned int bit_reverse32(unsigned int bits)
++static __inline__ unsigned int bit_reverse32(unsigned int bits)
+ {
+     union intbytes c;
+ 
+@@ -117,7 +117,7 @@
+ 	d++; s++;			\
+     }
+ 
+-static inline void memcpy_double(void *d0, void *s0, long n)
++static __inline__ void memcpy_double(void *d0, void *s0, long n)
+ {
+     unsigned long d = (unsigned long)d0;
+     unsigned long s = (unsigned long)s0;
+--- xc/programs/Xserver/hw/xfree86/accel/mach64/mach64util.h.orig	Mon May 29 16:42:37 2000
++++ xc/programs/Xserver/hw/xfree86/accel/mach64/mach64util.h	Mon May 29 16:42:55 2000
+@@ -61,14 +61,14 @@
+ 	       (reverseByteOrder[(bits >>  0) & 0xff] << 24);
+ }
+ 
+-static __inline void
++static __inline__ void
+ memcpy8(unsigned char *dst, const unsigned char *src, unsigned int cnt)
+ {
+ 	while (cnt--)
+ 		*dst++ = *src++;
+ }
+ 
+-static __inline void
++static __inline__ void
+ memcpy16(unsigned short *dst, const unsigned short *src, unsigned int cnt)
+ {
+ 	unsigned int c = (cnt >> 1);
+@@ -77,7 +77,7 @@
+ 		*dst++ = *src++;
+ }
+ 
+-static __inline void
++static __inline__ void
+ memcpy32(unsigned int *dst, const unsigned int *src, unsigned int cnt)
+ {
+ 	unsigned int c = (cnt >> 2);
+--- xc/programs/Xserver/hw/xfree86/accel/mach64/regmach64.h.orig	Mon May 29 16:41:04 2000
++++ xc/programs/Xserver/hw/xfree86/accel/mach64/regmach64.h	Mon May 29 16:48:10 2000
+@@ -784,20 +784,20 @@
+ } mach64CRTCRegRec, *mach64CRTCRegPtr;
+ 
+ 
+-#ifdef FBDEV_SERVER
++#if defined(FBDEV_SERVER) || defined(__sparc__)
+ 
+ extern pointer mach64MemReg;
+ 
+ #if defined (__powerpc__)
+ 
+-static inline void regw(volatile unsigned long regindex, unsigned long regdata)
++static __inline__ void regw(volatile unsigned long regindex, unsigned long regdata)
+ {
+   register unsigned long base_addr = (unsigned long)mach64MemReg;
+ 
+   asm("stwbrx %0,%1,%2": : "r"(regdata), "b"(regindex), "r"(base_addr):"memory");
+ }
+ 
+-static inline unsigned long regr(volatile unsigned long regindex)
++static __inline__ unsigned long regr(volatile unsigned long regindex)
+ {
+   register unsigned long base_addr = (unsigned long)mach64MemReg, val;
+ 
+@@ -805,15 +805,16 @@
+   return(val);
+ }
+ 
+-static inline void regwbe(volatile unsigned long regindex, unsigned long regdata
+-)
++#endif /* __powerpc__ */
++
++#endif	/* FBDEV_SERVER || __sparc__ */
++
++#if (defined(FBDEV_SERVER) && defined(__powerpc__)) || defined(__sparc__)
++static __inline__ void regwbe(volatile unsigned long regindex, unsigned long regdata)
+ {
+   *(unsigned long *)(mach64MemReg + regindex) = regdata;
+ }
+-
+ #endif
+-
+-#endif	/* FBDEV_SERVER */
+ 
+ /* Wait until "v" queue entries are free */
+ #define WaitQueue(v)    { while ((regr(FIFO_STAT) & 0x0000ffff) > \
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-05-s3trio3d
+++ xfree86-1-3.3.6/debian/patches/0000fix-05-s3trio3d
@@ -0,0 +1,49 @@
+diff -u orig/regs3v.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/regs3v.h
+--- orig/regs3v.h	Thu Nov 18 16:57:17 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/regs3v.h	Thu May 25 14:16:00 2000
+@@ -46,13 +46,15 @@
+ 
+ 
+ #define VerticalRetraceWait() \
+-{ \
++{ unsigned char tmp; \
++   tmp = inb(vgaCRIndex); \
+    outb(vgaCRIndex, 0x17); \
+    if ( inb(vgaCRReg) & 0x80 ) { \
+        while ((inb(vgaIOBase + 0x0A) & 0x08) == 0x00) ; \
+        while ((inb(vgaIOBase + 0x0A) & 0x08) == 0x08) ; \
+        while ((inb(vgaIOBase + 0x0A) & 0x08) == 0x00) ; \
+        }\
++   outb(vgaCRIndex, tmp); \
+ }
+ 
+ #if 0 /* currently not used at all */
+diff -u orig/s3v_accel.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_accel.c
+--- orig/s3v_accel.c	Mon May 10 18:51:13 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3v/s3v_accel.c	Thu May 25 14:17:54 2000
+@@ -321,7 +321,8 @@
+ S3VGEReset(int from_timeout, int line, char *file)
+ {
+     unsigned long gs1, gs2;   /* -- debug info for graphics state -- */
+-    unsigned char tmp, sr1, resetidx;
++    /* HK: resetidx doesn't work yet, use read-only register for fake */
++    unsigned char tmp, sr1, resetidx=0x2e;  
+     int r;
+     int ge_was_on = 0;
+     int32  fifo_control, miu_control, streams_timeout, misc_timeout;
+@@ -411,6 +412,7 @@
+ 
+       if(tmp & 0x01) {
+         tmp &= ~0x01;
++	outb(vgaCRIndex,resetidx);
+         outb(vgaCRReg, tmp);
+         ge_was_on = 1;
+         usleep(10000);
+@@ -421,6 +423,7 @@
+       usleep(10000);
+ 
+       VerticalRetraceWait();
++      outb(vgaCRIndex,resetidx);
+       outb(vgaCRReg, (tmp & ~0x02));
+       usleep(10000);
+ 
--- xfree86-1-3.3.6.orig/debian/patches/064_Xserver_observe_XAUTHORITY.diff
+++ xfree86-1-3.3.6/debian/patches/064_Xserver_observe_XAUTHORITY.diff
@@ -0,0 +1,21 @@
+--- xc/programs/Xserver/dix/main.c~	Thu Nov  2 11:50:02 2000
++++ xc/programs/Xserver/dix/main.c	Thu Nov  2 11:51:14 2000
+@@ -241,6 +241,7 @@
+     char	*argv[];
+ {
+     int		i, j, k;
++    char	*xauthfile;
+     HWEventQueueType	alwaysCheckForInput[2];
+ 
+     /* Notice if we're restart.  Probably this is because we jumped through
+@@ -260,6 +261,10 @@
+     argcGlobal = argc;
+     argvGlobal = argv;
+     display = "0";
++    /* prep X authority file from environment; this can be overriden by a
++     * command line option */
++    xauthfile = getenv("XAUTHORITY");
++    if (xauthfile) InitAuthorization (xauthfile);
+     ProcessCommandLine(argc, argv);
+ 
+     alwaysCheckForInput[0] = 0;
--- xfree86-1-3.3.6.orig/debian/patches/033_trident_accel_fix.diff
+++ xfree86-1-3.3.6/debian/patches/033_trident_accel_fix.diff
@@ -0,0 +1,24 @@
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/tvga8900/t89_driver.c.orig	Mon May  1 02:15:09 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/tvga8900/t89_driver.c	Mon May  1 02:15:31 2000
+@@ -940,18 +940,17 @@
+ 	case CYBER939A:
+ 	case CYBER9520:
+ 	case CYBER9525:
+-		if(OFLG_ISSET(OPTION_ACCEL, &vga256InfoRec.options))
+-			tridentHasAcceleration = TRUE;
+-		/* no break needed, falling through ... */
+ 	case TGUI96xx:
+ 	case TGUI9680:
+ 	case TGUI9682:
+ 	case TGUI9685:
+ 	case CYBER9382:
+ 	case CYBER9385:
++		if(OFLG_ISSET(OPTION_ACCEL, &vga256InfoRec.options))
++			tridentHasAcceleration = TRUE;
+ 		TVGA8900.ChipHas16bpp = TRUE;
+ 		TVGA8900.ChipHas24bpp = TRUE;
+-		if (vgaBitsPerPixel == 24) 
++		if (vgaBitsPerPixel == 24)
+ 			tridentHasAcceleration = FALSE;
+ #ifdef PC98_TGUI
+ 		else
--- xfree86-1-3.3.6.orig/debian/patches/066_s3savage_tim_roberts_fixes.diff
+++ xfree86-1-3.3.6/debian/patches/066_s3savage_tim_roberts_fixes.diff
@@ -0,0 +1,218 @@
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_driver.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_driver.c	Wed Nov  8 01:28:44 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.c	Fri Sep 29 16:19:23 2000
+@@ -94,6 +94,7 @@
+ static void    S3SAVRestore();
+ static void    S3SAVAdjust();
+ static void    S3SAVFbInit();
++static int     S3SAVPitchAdjust();
+ void           S3SAVSetRead();
+ void           S3SAVAccelInit();
+ void           S3SAVInitialize2DEngine();
+@@ -721,12 +722,12 @@
+ 
+    /* Restore the desired video mode with CR67 */
+         
+-   outb(vgaCRIndex, 0x67);             
+ #if 0
++   outb(vgaCRIndex, 0x67);             
+    cr67 = inb(vgaCRReg) & 0xf; /* Possible hardware bug on VX? */
+-#endif
+    outb(vgaCRReg, 0x50 | cr67); 
+    usleep(10000);
++#endif
+    outb(vgaCRIndex, 0x67);             
+    outb(vgaCRReg, restore->CR67 & ~0x0c); /* Don't enable STREAMS yet */
+ 
+@@ -745,9 +746,11 @@
+    outb(vgaCRReg, restore->CR51);
+    
+    /* Memory timings */
+-   outb(vgaCRIndex, 0x36);             
++   outb(vgaCRIndex, 0x36);
+    outb(vgaCRReg, restore->CR36);
+-   outb(vgaCRIndex, 0x68);             
++   outb(vgaCRIndex, 0x60);
++   outb(vgaCRReg, restore->CR60);
++   outb(vgaCRIndex, 0x68);
+    outb(vgaCRReg, restore->CR68);
+    outb(vgaCRIndex, 0x69);
+    outb(vgaCRReg, restore->CR69);
+@@ -764,8 +767,11 @@
+    outb(vgaCRReg, restore->CR90);
+    outb(vgaCRIndex, 0x91);
+    outb(vgaCRReg, restore->CR91);
+-   outb(vgaCRIndex, 0xB0); /* Savage4 config3 */
+-   outb(vgaCRReg, restore->CRB0);
++   if( s3vPriv.chip == S3_SAVAGE4 )
++   {
++      outb(vgaCRIndex, 0xB0); /* Savage4 config3 */
++      outb(vgaCRReg, restore->CRB0);
++   }
+ 
+    outb(vgaCRIndex, 0x32);
+    outb(vgaCRReg, restore->CR32);
+@@ -981,6 +987,8 @@
+    save->CR53 = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x58);
+    save->CR58 = inb(vgaCRReg);
++   outb(vgaCRIndex, 0x60);
++   save->CR60 = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x66);
+    save->CR66 = inb(vgaCRReg);
+    outb(vgaCRIndex, 0x67);
+@@ -1135,10 +1143,29 @@
+ }
+ 
+ 
++/*
++ * This function adjusts the pitch to a multiple of 16 pixels.
++ */
++
++static int
++S3SAVPitchAdjust( void )
++{
++    int pitch = vga256InfoRec.virtualX;
++
++    if( pitch % 16 != 0 )
++    {
++	pitch = (pitch + 15) & ~15;
++
++	ErrorF("%s %s: %s: Display width padded to %d bytes.\n",
++	     XCONFIG_PROBED, vga256InfoRec.name, vga256InfoRec.chipset,
++	     pitch);
++    }
++    return pitch;
++}
++
++
+ /* 
+- * This is the main probe function for the virge chipsets.
+- * Right now, I have taken a shortcut and get most of the info from
+- * PCI probing.
++ * This is the main probe function for the Savage chipsets.
+  */
+ 
+ static Bool
+@@ -1511,6 +1538,8 @@
+    S3V.ChipLinearBase = vga256InfoRec.MemBase;
+    S3V.ChipLinearSize = vga256InfoRec.videoRam * 1024;
+ 
++   vgaSetPitchAdjustHook(S3SAVPitchAdjust);
++
+    return TRUE;   
+ }
+ 
+@@ -1782,9 +1811,9 @@
+    outb(vgaCRIndex, 0x3a);
+    tmp = inb(vgaCRReg);
+    if(!OFLG_ISSET(OPTION_PCI_BURST_ON, &vga256InfoRec.options)) 
+-      new->CR3A = tmp | 0x95;      /* ENH 256, no PCI burst! */
++      new->CR3A = tmp | 0x90;      /* ENH 256, no PCI burst! */
+    else 
+-      new->CR3A = (tmp & 0x7f) | 0x15; /* ENH 256, PCI burst */
++      new->CR3A = (tmp & 0x7f) | 0x10; /* ENH 256, PCI burst */
+ 
+    new->CR53 &= ~0x08;     /* Enables MMIO */
+    new->CR31 = 0x8c;     /* Dis. 64k window, en. ENH maps */    
+@@ -1806,12 +1835,22 @@
+ 
+    dclk = vga256InfoRec.clock[mode->Clock];
+    new->CR67 = 0x00;             /* Defaults */
+-   new->SR15 = 0x03 | 0x80; 
++   if( s3vPriv.chip != S3_SAVAGE2000 )
++      new->SR15 = 0x03 | 0x80; 
++   else
++      /* One-cycle writes broken on Savage2000? */
++      new->SR15 = 0x03;
+    new->SR18 = 0x00;
+    new->CR43 = 0x00;
+    new->CR45 = 0x00;
+    new->CR65 = 0x00;
+ 
++   outb(vgaCRIndex, 0x60);
++   new->CR60 = inb(vgaCRReg);
++
++   if( s3vPriv.chip == S3_SAVAGE_MX )
++       new->CR60 = 0x09;
++
+    outb(vgaCRIndex, 0x40);
+    new->CR40 = inb(vgaCRReg) & ~0x01;
+    
+@@ -1852,16 +1891,19 @@
+ 
+    {
+        if (vgaBitsPerPixel == 8) {
+-          if (dclk <= 110000) new->CR67 = 0x00; /* 8bpp, 135MHz */
+-          else new->CR67 = 0x10;                /* 8bpp, 220MHz */
++	  new->CR67 = 0x00;                /* 8bpp, 220MHz */
+           }
+        else if ((vgaBitsPerPixel == 16) && (vga256InfoRec.weight.green == 5)) {
+-          if (dclk <= 110000) new->CR67 = 0x20; /* 15bpp, 135MHz */
+-          else new->CR67 = 0x30;                /* 15bpp, 220MHz */
++	  if( s3vPriv.chip == S3_SAVAGE_MX )
++	    new->CR67 = 0x30;                /* 15bpp, 220MHz */
++	  else
++	    new->CR67 = 0x20;
+           }
+        else if (vgaBitsPerPixel == 16) {
+-          if (dclk <= 110000) new->CR67 = 0x40; /* 16bpp, 135MHz */
+-          else new->CR67 = 0x50;                /* 16bpp, 220MHz */
++	  if( s3vPriv.chip == S3_SAVAGE_MX )
++	    new->CR67 = 0x50;                 /* 16bpp, 220MHz */
++	  else
++	    new->CR67 = 0x40;
+           }
+        else if ((vgaBitsPerPixel == 24) || (vgaBitsPerPixel == 32)) {
+           new->CR67 = 0xd0;                     /* 24bpp, 135MHz */
+@@ -1967,8 +2009,12 @@
+    else
+       new->CR50 |= 0xC1; /* default to use GlobalBD */
+ 
+-   new->CR33 = 0x20;
++   if( s3vPriv.chip == S3_SAVAGE2000 )
++     new->CR33 = 0x08;
++   else
++     new->CR33 = 0x20;
+ 	 
++   new->std.CRTC[0x17] = 0xeb;
+ 
+    /* Now we handle various XConfig memory options and others */
+ 
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_driver.h xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_driver.h	Wed Nov  8 01:28:44 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_driver.h	Fri Sep  1 19:57:01 2000
+@@ -25,7 +25,7 @@
+    unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
+    unsigned char CR40, CR42, CR43, CR45;
+    unsigned char CR50, CR51, CR53, CR58, CR5B, CR5D, CR5E;
+-   unsigned char CR65, CR66, CR67, CR68, CR69, CR6F; /* Video attrib. */
++   unsigned char CR60, CR65, CR66, CR67, CR68, CR69, CR6F; /* Video attrib. */
+    unsigned char CR86, CR88;
+    unsigned char CR90, CR91, CRB0;
+    unsigned char ColorStack[8]; /* S3 hw cursor color stack CR4A/CR4B */
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_vbe.c xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_vbe.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage~/s3sav_vbe.c	Wed Nov  8 01:28:44 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/s3_savage/s3sav_vbe.c	Wed Oct 25 20:48:57 2000
+@@ -314,6 +314,21 @@
+ 
+     while (*mode_list != -1)
+     {
++	/*
++	 * This is a HACK to work around what I believe is a BUG in the
++	 * Toshiba Satellite BIOSes in 08/2000 and 09/2000.  The BIOS
++	 * table for 1024x600 says it has six refresh rates, when in fact
++	 * it only has 3.  This causes the BIOS to go into an infinite
++	 * loop until the user interrupts it, usually by pressing
++	 * Ctrl-Alt-F1.  For now, we'll just punt everything with a VESA
++	 * number greater than or equal to 0200.
++	 */
++	if( *mode_list >= 0x0200 )
++	{
++	    mode_list++;
++	    continue;
++	}
++
+ 	memset(&r, 0, sizeof(r));
+ 
+ 	r.eax = 0x4f01;
--- xfree86-1-3.3.6.orig/debian/patches/070_SECURITY.diff
+++ xfree86-1-3.3.6/debian/patches/070_SECURITY.diff
@@ -0,0 +1,819 @@
+--- xc/programs/xdm/Imakefile~	Sat Dec 11 12:34:51 1999
++++ xc/programs/xdm/Imakefile	Sun Feb 11 03:14:37 2001
+@@ -48,6 +48,10 @@
+ #define LinuxShadowSuite NO
+ #endif
+ 
++#if HasSnprintf
++SNPRINTF_DEFINES = -DHAS_SNPRINTF
++#endif
++
+ #if HasXdmAuth
+ XDMAUTH_DEFINES = -DHASXDMAUTH
+ XDMAUTHOBJS = xdmauth.o
+@@ -209,7 +213,7 @@
+   EXTRA_DEFINES =
+ #endif
+         DEFINES = -DBINDIR=\"$(BINDIR)\" -DXDMDIR=\"$(XDMDIR)\" \
+-		$(SIGNAL_DEFINES) $(CRYPT_DEFINES) \
++		$(SIGNAL_DEFINES) $(CRYPT_DEFINES) $(SNPRINTF_DEFINES) \
+ 		$(XDMAUTH_DEFINES) $(RPC_DEFINES) $(KRB5_DEFINES) \
+ 		$(PWD_DEFINES) $(CONN_DEFINES) \
+ 		$(GREET_DEFINES) $(FRAGILE_DEFINES) \
+--- xc/programs/xdm/xdmcp.c~	Sun Feb 11 13:33:49 2001
++++ xc/programs/xdm/xdmcp.c	Sun Feb 11 13:36:10 2001
+@@ -1111,8 +1111,15 @@
+     XdmcpHeader	header;
+     ARRAY8	status;
+ 
++#ifdef HAS_SNPRINTF
++    snprintf (buf, sizeof(buf),
++	     "Session %d failed for display %s: %s",
++	     sessionID, name, reason);
++#else
++    /* XXX insecure */
+     sprintf (buf, "Session %d failed for display %s: %s",
+ 	     sessionID, name, reason);
++#endif
+     Debug ("Send failed %d %s\n", sessionID, buf);
+     status.length = strlen (buf);
+     status.data = (CARD8Ptr) buf;
+--- xc/lib/X11/OpenDis.c~	Sun Feb 11 03:23:54 2001
++++ xc/lib/X11/OpenDis.c	Sun Feb 11 03:27:20 2001
+@@ -371,6 +371,13 @@
+ 	dpy->max_request_size	= u.setup->maxRequestSize;
+ 	mask = dpy->resource_mask;
+ 	dpy->resource_shift	= 0;
++	if (!mask)
++	{
++	    fprintf (stderr, "Xlib: connection to \"%s\" invalid setup\n",
++		     fullname);
++	    OutOfMemory(dpy, setup);
++	    return (NULL);
++	}
+ 	while (!(mask & 1)) {
+ 	    dpy->resource_shift++;
+ 	    mask = mask >> 1;
+@@ -380,6 +387,11 @@
+  * now extract the vendor string...  String must be null terminated,
+  * padded to multiple of 4 bytes.
+  */
++	/* Check for a sane vendor string length */
++	if (u.setup->nbytesVendor > 256) {
++	    OutOfMemory(dpy, setup);
++	    return (NULL);
++	}
+ 	dpy->vendor = (char *) Xmalloc((unsigned) (u.setup->nbytesVendor + 1));
+ 	if (dpy->vendor == NULL) {
+ 	    OutOfMemory(dpy, setup);
+@@ -390,6 +402,11 @@
+   	(void) strncpy(dpy->vendor, u.vendor, vendorlen);
+ 	dpy->vendor[vendorlen] = '\0';
+  	vendorlen = (vendorlen + 3) & ~3;	/* round up */
++	/* validate setup length */
++	if ((int) setuplength - sz_xConnSetup - vendorlen < 0) {
++	    OutOfMemory(dpy, setup);
++	    return (NULL);
++	}
+ 	memmove (setup, u.vendor + vendorlen,
+ 		 (int) setuplength - sz_xConnSetup - vendorlen);
+  	u.vendor = setup;
+@@ -568,6 +585,8 @@
+ 
+ 	    if (_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
+ 		if (reply.format == 8 && reply.propertyType == XA_STRING &&
++		    (reply.nItems + 1 > 0) &&
++		    (reply.nItems <= req->longLength * 4) &&
+ 		    (dpy->xdefaults = Xmalloc (reply.nItems + 1))) {
+ 		    _XReadPad (dpy, dpy->xdefaults, reply.nItems);
+ 		    dpy->xdefaults[reply.nItems] = '\0';
+--- xc/programs/xauth/process.c~	Sun Feb 11 03:30:16 2001
++++ xc/programs/xauth/process.c	Sun Feb 11 03:32:03 2001
+@@ -37,6 +37,7 @@
+ #include "xauth.h"
+ #include <ctype.h>
+ #include <errno.h>
++#include <sys/stat.h>
+ #ifdef X_NOT_STDC_ENV
+ extern int errno;
+ #endif
+@@ -769,7 +770,8 @@
+ static int write_auth_file (tmp_nam)
+     char *tmp_nam;
+ {
+-    FILE *fp;
++    FILE *fp = NULL;
++    int fd;
+     AuthList *list;
+ 
+     /*
+@@ -778,8 +780,11 @@
+     strcpy (tmp_nam, xauth_filename);
+     strcat (tmp_nam, "-n");		/* for new */
+     (void) unlink (tmp_nam);
+-    fp = fopen (tmp_nam, "wb");		/* umask is still set to 0077 */
++    /* CPhipps 2000/02/12 - fix file unlink/fopen race */
++    fd = open(tmp_nam, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
++    if (fd != -1) fp = fdopen (fd, "wb");
+     if (!fp) {
++	if (fd != -1) close(fd);
+ 	fprintf (stderr, "%s:  unable to open tmp file \"%s\"\n",
+ 		 ProgramName, tmp_nam);
+ 	return -1;
+--- xc/lib/Xau/AuLock.c~	Sun Feb 11 03:32:38 2001
++++ xc/lib/Xau/AuLock.c	Sun Feb 11 03:33:40 2001
+@@ -94,7 +94,9 @@
+     
+     while (retries > 0) {
+ 	if (creat_fd == -1) {
+-	    creat_fd = creat (creat_name, 0666);
++	    /* use open with O_EXCL instead of creat to avoid race */
++	    creat_fd = open (creat_name, O_WRONLY | O_CREAT | O_EXCL,
++			     S_IRUSR | S_IWUSR );
+ 	    if (creat_fd == -1) {
+ 		if (errno != EACCES)
+ 		    return LOCK_ERROR;
+--- xc/config/imake/imake.c~	Sun Feb 11 03:35:03 2001
++++ xc/config/imake/imake.c	Sun Feb 11 03:37:23 2001
+@@ -961,12 +961,22 @@
+ static void get_libc_version(inFile)
+   FILE* inFile;
+ {
+-  char *aout = tmpnam (NULL);
++  char aout[] = "/tmp/imakeXXXXXX";
+   FILE *fp;
+   const char *format = "%s -o %s -x c -";
+   char *cc;
+   int len;
+   char *command;
++
++  /* Pre-create temp file safely */
++  {
++    int tmpfd;
++    if ((tmpfd = mkstemp(aout)) == -1) {
++      perror("mkstemp");
++      abort();
++    }
++    close(tmpfd);
++  }
+ 
+   cc = getenv ("CC");
+   if (cc == NULL)
+--- xc/lib/xtrans/Xtrans.c~	Sun Feb 11 03:37:57 2001
++++ xc/lib/xtrans/Xtrans.c	Sun Feb 11 03:38:13 2001
+@@ -178,7 +178,7 @@
+      * a case insensitive match.
+      */
+ 
+-    strncpy (protobuf, protocol, PROTOBUFSIZE);
++    strncpy (protobuf, protocol, PROTOBUFSIZE - 1);
+ 
+     for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
+ 	if (isupper (protobuf[i]))
+--- xc/lib/xtrans/Xtranssock.c~	Thu Jul 29 04:22:32 1999
++++ xc/lib/xtrans/Xtranssock.c	Tue Oct 24 17:45:31 2000
+@@ -754,6 +754,29 @@
+ }
+ 
+ 
++#ifdef UNIXCONN
++static int
++set_sun_path(const char *port, const char *upath, char *path)
++{
++    struct sockaddr_un s;
++    int maxlen = sizeof(s.sun_path) - 1;
++
++    if (!port || !*port || !path)
++	return -1;
++
++    if (*port == '/') { /* a full pathname */
++	if (strlen(port) > maxlen)
++	    return -1;
++	sprintf(path, "%s", port);
++    } else {
++	if (strlen(port) + strlen(upath) > maxlen)
++	    return -1;
++	sprintf(path, "%s%s", upath, port);
++    }
++    return 0;
++}
++#endif
++
+ #ifdef TRANS_SERVER
+ 
+ static int
+@@ -957,10 +980,9 @@
+     sockname.sun_family = AF_UNIX;
+ 
+     if (port && *port) {
+-	if (*port == '/') { /* a full pathname */
+-	    sprintf (sockname.sun_path, "%s", port);
+-	} else {
+-	    sprintf (sockname.sun_path, "%s%s", UNIX_PATH, port);
++	if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) {
++	    PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
++	    return TRANS_CREATE_LISTENER_FAILED;
+ 	}
+     } else {
+ 	sprintf (sockname.sun_path, "%s%d", UNIX_PATH, getpid());
+@@ -1604,10 +1626,9 @@
+     
+     sockname.sun_family = AF_UNIX;
+ 
+-    if (*port == '/') { /* a full pathname */
+-	sprintf (sockname.sun_path, "%s", port);
+-    } else {
+-	sprintf (sockname.sun_path, "%s%s", UNIX_PATH, port);
++    if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) {
++	PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
++	return TRANS_CREATE_LISTENER_FAILED;
+     }
+ 
+ #if defined(BSD44SOCKETS) && !defined(Lynx)
+@@ -1623,10 +1644,9 @@
+      * This is gross, but it was in Xlib
+      */
+     old_sockname.sun_family = AF_UNIX;
+-    if (*port == '/') { /* a full pathname */
+-	sprintf (old_sockname.sun_path, "%s", port);
+-    } else {
+-	sprintf (old_sockname.sun_path, "%s%s", OLD_UNIX_PATH, port);
++    if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) {
++	PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0);
++	return TRANS_CONNECT_FAILED;
+     }
+     old_namelen = strlen (old_sockname.sun_path) +
+ 	sizeof (old_sockname.sun_family);
+--- xc/config/util/gccmdep.cpp~	Sun Feb 11 03:40:39 2001
++++ xc/config/util/gccmdep.cpp	Sun Feb 11 03:41:00 2001
+@@ -8,7 +8,7 @@
+ XCOMM Based on mdepend.cpp and code supplied by Hongjiu Lu <hjl@nynexst.com>
+ XCOMM
+ 
+-TMP=${TMPDIR-/tmp}/mdep$$
++TMP=`pwd`/.mdep$$
+ CC=CCCMD
+ RM=RMCMD
+ LN=LNCMD
+--- xc/programs/Xserver/xkb/xkbInit.c~	Tue Feb 24 08:20:07 1998
++++ xc/programs/Xserver/xkb/xkbInit.c	Thu Jun 15 16:58:34 2000
+@@ -915,8 +915,13 @@
+ #endif
+     else if (strncmp(argv[i], "-xkbmap", 7) == 0) {
+ 	if(++i < argc) {
+-	    XkbInitialMap= argv[i];
+-	    return 2;
++	    if (strlen(argv[i]) < PATH_MAX) {
++		XkbInitialMap= argv[i];
++		return 2;
++	    } else {
++		ErrorF("-xkbmap pathname too long\n");
++		return -1;
++	    }
+ 	}
+ 	else {
+ 	    return -1;
+@@ -924,8 +929,13 @@
+     }
+     else if (strncmp(argv[i], "-xkbdb", 7) == 0) {
+ 	if(++i < argc) {
+-	    XkbDB= argv[i];
+-	    return 2;
++	    if (strlen(argv[i]) < PATH_MAX) {
++		XkbDB= argv[i];
++		return 2;
++	    } else {
++		ErrorF("-xkbdb pathname too long\n");
++		return -1;
++	    }
+ 	}
+ 	else {
+ 	    return -1;
+Index: xc/programs/Xserver/os/secauth.c
+===================================================================
+RCS file: /home/x-cvs/xc/programs/Xserver/os/secauth.c,v
+retrieving revision 1.1.1.1
+retrieving revision 1.1.1.1.2.1
+diff -u -r1.1.1.1 -r1.1.1.1.2.1
+--- xc/programs/Xserver/os/secauth.c	1996/12/22 03:33:36	1.1.1.1
++++ xc/programs/Xserver/os/secauth.c	2001/01/26 21:37:25	1.1.1.1.2.1
+@@ -47,7 +47,7 @@
+     ClientPtr	client;
+     char	**reason;
+ {
+-    char	*policy = *dataP;
++    CARD8	*policy = *(CARD8 **)dataP;
+     int		length;
+     Bool	permit;
+     int		nPolicies;
+@@ -61,13 +61,13 @@
+     }
+ 
+     permit = (*policy++ == 0);
+-    nPolicies = *policy++;
++    nPolicies = (CARD8) *policy++;
+ 
+     length -= 2;
+ 
+     sitePolicies = SecurityGetSitePolicyStrings(&nSitePolicies);
+ 
+-    while (nPolicies) {
++    while (nPolicies > 0) {
+ 	int strLen, sitePolicy;
+ 
+ 	if (length == 0) {
+@@ -75,7 +75,7 @@
+ 	    return FALSE;
+ 	}
+ 
+-	strLen = *policy++;
++	strLen = (CARD8) *policy++;
+ 	if (--length < strLen) {
+ 	    *reason = InvalidPolicyReason;
+ 	    return FALSE;
+@@ -87,7 +87,7 @@
+ 	    {
+ 		char *testPolicy = sitePolicies[sitePolicy];
+ 		if ((strLen == strlen(testPolicy)) &&
+-		    (strncmp(policy, testPolicy, strLen) == 0))
++		    (strncmp((char *)policy, testPolicy, strLen) == 0))
+ 		{
+ 		    found = TRUE; /* need to continue parsing the policy... */
+ 		    break;
+@@ -107,7 +107,7 @@
+     }
+ 
+     *data_lengthP = length;
+-    *dataP = policy;
++    *dataP = (char *)policy;
+     return TRUE;
+ }
+ 
+Index: xc/lib/X11/XlibInt.c
+===================================================================
+RCS file: /home/x-cvs/xc/lib/X11/XlibInt.c,v
+retrieving revision 3.9.2.3
+retrieving revision 3.9.2.4
+diff -u -r3.9.2.3 -r3.9.2.4
+--- xc/lib/X11/XlibInt.c	1999/07/29 09:22:30	3.9.2.3
++++ xc/lib/X11/XlibInt.c	2001/01/26 21:43:36	3.9.2.4
+@@ -29,7 +29,7 @@
+ 
+ */
+ 
+-/* $XFree86: xc/lib/X11/XlibInt.c,v 3.9.2.3 1999/07/29 09:22:30 hohndel Exp $ */
++/* $XFree86: xc/lib/X11/XlibInt.c,v 3.9.2.4 2001/01/26 21:43:36 herrb Exp $ */
+ 
+ /*
+  *	XlibInt.c - Internal support routines for the C subroutine
+@@ -38,6 +38,8 @@
+ #define NEED_EVENTS
+ #define NEED_REPLIES
+ 
++#define GENERIC_LENGTH_LIMIT (1 << 29)
++
+ #include "Xlibint.h"
+ #include <X11/Xpoll.h>
+ #include <X11/Xtrans.h>
+@@ -1689,6 +1691,17 @@
+ 			!= (char *)rep)
+ 			continue;
+ 		}
++                /*
++                 * Don't accept ridiculously large values for
++                 * generic.length; doing so could cause stack-scribbling
++                 * problems elsewhere.
++                 */
++                if (rep->generic.length > GENERIC_LENGTH_LIMIT) {
++                    rep->generic.length = GENERIC_LENGTH_LIMIT;
++                    (void) fprintf(stderr,
++                                   "Xlib: suspiciously long reply length %d set to %d",
++                                   rep->generic.length, GENERIC_LENGTH_LIMIT);
++		}
+ 		if (extra <= rep->generic.length) {
+ 		    if (extra > 0)
+ 			/* 
+@@ -1827,6 +1840,13 @@
+ #endif
+ 	if (len > *lenp)
+ 	    _XEatData(dpy, len - *lenp);
++    }
++    if (len < SIZEOF(xReply))
++    {
++	_XIOError (dpy);
++	buf += *lenp;
++	*lenp = 0;
++	return buf;
+     }
+     if (len >= *lenp) {
+ 	buf += *lenp;
+Index: xc/lib/Xaw/AsciiSrc.c
+===================================================================
+RCS file: /home/x-cvs/xc/lib/Xaw/AsciiSrc.c,v
+retrieving revision 1.1.1.2.4.2
+retrieving revision 1.1.1.2.4.3
+diff -u -r1.1.1.2.4.2 -r1.1.1.2.4.3
+--- xc/lib/Xaw/AsciiSrc.c	1998/05/16 09:05:19	1.1.1.2.4.2
++++ xc/lib/Xaw/AsciiSrc.c	2001/01/26 22:34:21	1.1.1.2.4.3
+@@ -27,7 +27,7 @@
+ 
+ */
+ 
+-/* $XFree86: xc/lib/Xaw/AsciiSrc.c,v 1.1.1.2.4.2 1998/05/16 09:05:19 dawes Exp $ */
++/* $XFree86: xc/lib/Xaw/AsciiSrc.c,v 1.1.1.2.4.3 2001/01/26 22:34:21 herrb Exp $ */
+ 
+ /*
+  * AsciiSrc.c - AsciiSrc object. (For use with the text widget).
+@@ -48,8 +48,11 @@
+ #include <X11/Xaw/AsciiSrcP.h>
+ #include <X11/Xmu/Misc.h>
+ #include <X11/Xmu/CharSet.h>
+-#include <X11/Xaw/MultiSrcP.h> 
++#include <X11/Xaw/MultiSrcP.h>
+ 
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <fcntl.h>
+ 
+ #if (defined(ASCII_STRING) || defined(ASCII_DISK))
+ #  include <X11/Xaw/AsciiText.h> /* for Widget Classes. */
+@@ -980,7 +983,9 @@
+ AsciiSrcObject src;
+ Boolean newString;
+ {
+-    char * open_mode;
++    mode_t open_mode = 0;
++    const char *fdopen_mode = NULL;
++    int fd;
+     FILE * file;
+     char fileName[TMPSIZ];
+ 
+@@ -1022,7 +1027,8 @@
+ 	    XtErrorMsg("NoFile", "asciiSourceCreate", "XawError",
+ 		     "Creating a read only disk widget and no file specified.",
+ 		       NULL, 0);
+-	open_mode = "r";
++	open_mode = O_RDONLY;
++	fdopen_mode = "r";
+ 	break;
+     case XawtextAppend:
+     case XawtextEdit:
+@@ -1030,9 +1036,17 @@
+ 	    src->ascii_src.string = fileName;
+ 	    (void) tmpnam(src->ascii_src.string);
+ 	    src->ascii_src.is_tempfile = TRUE;
+-	    open_mode = "w";
+-	} else
+-	    open_mode = "r+";
++	    open_mode = O_WRONLY | O_CREAT | O_EXCL;
++	    fdopen_mode = "w";
++	} else {
++/* O_NOFOLLOW is a BSD & Linux extension */
++#ifdef O_NOFOLLOW
++	    open_mode = O_RDWR | O_NOFOLLOW;
++#else
++	    open_mode = O_RDWR; /* unsafe; subject to race conditions */
++#endif
++	    fdopen_mode = "r+";
++	}
+ 	break;
+     default:
+ 	XtErrorMsg("badMode", "asciiSourceCreate", "XawError",
+@@ -1051,11 +1065,14 @@
+     }
+     
+     if (!src->ascii_src.is_tempfile) {
+-	if ((file = fopen(src->ascii_src.string, open_mode)) != 0) {
+-	    (void) fseek(file, (Off_t)0, 2);
+-	    src->ascii_src.length = (XawTextPosition) ftell(file);
+-	    return file;
+-	} else {
++	if ((fd = open(src->ascii_src.string, open_mode, 0666))) {
++	    if ((file = fdopen(fd, fdopen_mode)) != NULL) {
++		(void)fseek(file, 0, SEEK_END);
++		src->ascii_src.length = (XawTextPosition)ftell(file);
++		return (file);
++	    }
++	}
++	{
+ 	    String params[2];
+ 	    Cardinal num_params = 2;
+ 	    
+@@ -1065,9 +1082,9 @@
+ 			    "openError", "asciiSourceCreate", "XawWarning",
+ 			    "Cannot open file %s; %s", params, &num_params);
+ 	}
+-    } 
++    }
+     src->ascii_src.length = 0;
+-    return((FILE *)NULL);
++    return(NULL);
+ }
+ 
+ static void
+Index: xc/lib/Xaw/MultiSrc.c
+===================================================================
+RCS file: /home/x-cvs/xc/lib/Xaw/MultiSrc.c,v
+retrieving revision 1.1.1.2.8.3
+retrieving revision 1.1.1.2.8.4
+diff -u -r1.1.1.2.8.3 -r1.1.1.2.8.4
+--- xc/lib/Xaw/MultiSrc.c	1998/05/16 09:05:20	1.1.1.2.8.3
++++ xc/lib/Xaw/MultiSrc.c	2001/01/26 22:34:21	1.1.1.2.8.4
+@@ -27,7 +27,7 @@
+  *
+  * Much code taken from X11R3 String and Disk Sources.
+  */
+-/* $XFree86: xc/lib/Xaw/MultiSrc.c,v 1.1.1.2.8.3 1998/05/16 09:05:20 dawes Exp $ */
++/* $XFree86: xc/lib/Xaw/MultiSrc.c,v 1.1.1.2.8.4 2001/01/26 22:34:21 herrb Exp $ */
+ 
+ /*
+ 
+@@ -74,6 +74,9 @@
+ #include <stdio.h>
+ #include <ctype.h>
+ #include <errno.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <fcntl.h>
+ 
+ /****************************************************************
+  *
+@@ -1075,7 +1078,9 @@
+     MultiSrcObject src;
+     Boolean newString;
+ {
+-    char * open_mode;
++    mode_t open_mode = 0;
++    const char *fdopen_mode = NULL;
++    int fd;
+     FILE * file;
+     char fileName[TMPSIZ];
+     Display *d = XtDisplayOfObject((Widget)src);
+@@ -1126,7 +1131,8 @@
+ 	    XtErrorMsg("NoFile", "multiSourceCreate", "XawError",
+ 		     "Creating a read only disk widget and no file specified.",
+ 		       NULL, 0);
+-	open_mode = "r";
++	open_mode = O_RDONLY;
++	fdopen_mode = "r";
+ 	break;
+     case XawtextAppend:
+     case XawtextEdit:
+@@ -1136,9 +1142,17 @@
+ 
+ 	    (void) tmpnam(src->multi_src.string);
+ 	    src->multi_src.is_tempfile = TRUE;
+-	    open_mode = "w";
+-	} else
+-	    open_mode = "r+";
++	    open_mode = O_WRONLY | O_CREAT | O_EXCL;
++	    fdopen_mode = "w";
++	} else {
++/* O_NOFOLLOW is a BSD & Linux extension */
++#ifdef O_NOFOLLOW	    
++	    open_mode = O_RDWR | O_NOFOLLOW;
++#else
++	    open_mode = O_RDWR;	/* unsafe; subject to race conditions */
++#endif
++	    fdopen_mode = "r+";
++	}
+ 	break;
+     default:
+ 	XtErrorMsg("badMode", "multiSourceCreate", "XawError",
+@@ -1159,11 +1173,14 @@
+     }
+     
+     if (!src->multi_src.is_tempfile) {
+-	if ((file = fopen(src->multi_src.string, open_mode)) != 0) {
+-	    (void) fseek(file, (Off_t)0, 2);
+-            src->multi_src.length = ftell (file);
+-	    return file;
+-	} else {
++	if ((fd = open(src->multi_src.string, open_mode, 0666))) {
++	    if ((file = fdopen(fd, fdopen_mode)) != NULL) {
++		(void)fseek(file, 0, SEEK_END);
++		src->multi_src.length = (XawTextPosition)ftell(file);
++		return (file);
++	    }
++	}
++	{
+ 	    String params[2];
+ 	    Cardinal num_params = 2;
+ 	    
+@@ -1173,9 +1190,9 @@
+ 			    "openError", "multiSourceCreate", "XawWarning",
+ 			    "Cannot open file %s; %s", params, &num_params);
+ 	}
+-    } 
++    }
+     src->multi_src.length = 0;
+-    return((FILE *)NULL);
++    return(NULL);
+ #undef StrLen
+ }
+ 
+Index: xc/config/cf/Imake.rules
+===================================================================
+RCS file: /home/x-cvs/xc/config/cf/Imake.rules,v
+retrieving revision 3.33.2.10
+retrieving revision 3.33.2.11
+diff -u -r3.33.2.10 -r3.33.2.11
+--- xc/config/cf/Imake.rules	1998/11/04 10:53:01	3.33.2.10
++++ xc/config/cf/Imake.rules	2001/01/27 11:07:39	3.33.2.11
+@@ -1,7 +1,7 @@
+ XCOMM ---------------------------------------------------------------------
+ XCOMM Imake rules for building libraries, programs, scripts, and data files
+ XCOMM rules:  $TOG: Imake.rules /main/222 1997/07/17 20:04:40 kaleb $
+-XCOMM rules:  $XFree86: xc/config/cf/Imake.rules,v 3.33.2.10 1998/11/04 10:53:01 dawes Exp $
++XCOMM rules:  $XFree86: xc/config/cf/Imake.rules,v 3.33.2.11 2001/01/27 11:07:39 herrb Exp $
+ 
+ /*
+  *		   MACHINE-INDEPENDENT RULES; DO NOT MODIFY
+@@ -1102,7 +1102,7 @@
+ #ifndef InstallManPageAliases
+ #define	InstallManPageAliases(file,destdir,aliases)			@@\
+ install.man::								@@\
+-	@(TMP=/tmp/tmp.$$$$; \						@@\
++	@(TMP=#tmp.$$$$; \						@@\
+ 	RemoveFile($${TMP}); \						@@\
+ 	echo .so `basename destdir`/file.$(MANSUFFIX) > $${TMP}; \	@@\
+ 	for i in aliases; do (set -x; \					@@\
+@@ -1139,7 +1139,7 @@
+ #ifndef InstallGenManPageAliases
+ #define	InstallGenManPageAliases(file,destdir,suffix,aliases)		@@\
+ install.man::								@@\
+-	@(TMP=/tmp/tmp.$$$$; \						@@\
++	@(TMP=#tmp.$$$$; \						@@\
+ 	RemoveFile($${TMP}); \						@@\
+ 	echo .so `basename destdir`/file.suffix > $${TMP}; \		@@\
+ 	for i in aliases; do (set -x; \					@@\
+Index: xc/lib/ICE/ICElibint.h
+diff -u xc/lib/ICE/ICElibint.h:1.1.1.1 xc/lib/ICE/ICElibint.h:1.1.1.1.12.1
+--- xc/lib/ICE/ICElibint.h:1.1.1.1	Wed Apr 27 02:09:13 1994
++++ xc/lib/ICE/ICElibint.h	Thu Feb  8 16:13:14 2001
+@@ -288,20 +288,24 @@
+ }
+ 
+ 
+-#define SKIP_STRING(_pBuf, _swap) \
++#define SKIP_STRING(_pBuf, _swap, _end) \
+ { \
+     CARD16 _len; \
+     EXTRACT_CARD16 (_pBuf, _swap, _len); \
+-    _pBuf += _len; \
+-    if (PAD32 (2 + _len)) \
++    if ((_pBuf+_len) < _end) { \
++      _pBuf += _len; \
++      if ( (PAD32 (2 + _len)) && ( (PAD32(2+_len) + _pBuf < _end) )) \
+         _pBuf += PAD32 (2 + _len); \
++    } else {\
++	return(0);\
++    }\
+ }
+ 
+-#define SKIP_LISTOF_STRING(_pBuf, _swap, _count) \
++#define SKIP_LISTOF_STRING(_pBuf, _swap, _count, _end) \
+ { \
+     int _i; \
+     for (_i = 0; _i < _count; _i++) \
+-        SKIP_STRING (_pBuf, _swap); \
++        SKIP_STRING (_pBuf, _swap, _end); \
+ }
+ 
+ 
+Index: xc/lib/ICE/process.c
+diff -u xc/lib/ICE/process.c:3.1 xc/lib/ICE/process.c:3.1.8.1
+--- xc/lib/ICE/process.c:3.1	Sat Sep 17 08:43:45 1994
++++ xc/lib/ICE/process.c	Thu Feb  8 16:13:14 2001
+@@ -819,7 +819,7 @@
+     int	 myAuthCount, hisAuthCount;
+     int	 found, i, j;
+     char *myAuthName, **hisAuthNames;
+-    char *pData, *pStart;
++    char *pData, *pStart, *pEnd;
+     char *vendor = NULL;
+     char *release = NULL;
+     int myAuthIndex = 0;
+@@ -843,10 +843,11 @@
+     }
+ 
+     pData = pStart;
++    pEnd = pStart + (length << 3);
+ 
+-    SKIP_STRING (pData, swap);				       /* vendor */
+-    SKIP_STRING (pData, swap);				       /* release */
+-    SKIP_LISTOF_STRING (pData, swap, (int) message->authCount);/* auth names */
++    SKIP_STRING (pData, swap, pEnd);				       /* vendor */
++    SKIP_STRING (pData, swap, pEnd);				       /* release */
++    SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd);/* auth names */
+     pData += (message->versionCount * 4);		       /* versions */
+ 
+     CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionSetup,
+@@ -1685,7 +1686,7 @@
+ 
+ {
+     iceConnectionReplyMsg 	*message;
+-    char 			*pData, *pStart;
++    char 			*pData, *pStart, *pEnd;
+     Bool			replyReady;
+ 
+     CHECK_AT_LEAST_SIZE (iceConn, ICE_ConnectionReply,
+@@ -1701,9 +1702,10 @@
+     }
+ 
+     pData = pStart;
++    pEnd = pStart + (length << 3);
+ 
+-    SKIP_STRING (pData, swap);				     /* vendor */
+-    SKIP_STRING (pData, swap);				     /* release */
++    SKIP_STRING (pData, swap, pEnd);				     /* vendor */
++    SKIP_STRING (pData, swap, pEnd);				     /* release */
+ 
+     CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionReply,
+ 	length, pData - pStart + SIZEOF (iceConnectionReplyMsg),
+@@ -1789,7 +1791,7 @@
+     int	 	      	found, i, j;
+     char	      	*myAuthName, **hisAuthNames;
+     char 	      	*protocolName;
+-    char 		*pData, *pStart;
++    char 		*pData, *pStart, *pEnd;
+     char 	      	*vendor = NULL;
+     char 	      	*release = NULL;
+     int  	      	accept_setup_now = 0;
+@@ -1824,11 +1826,12 @@
+     }
+ 
+     pData = pStart;
++    pEnd = pStart + (length << 3);
+ 
+-    SKIP_STRING (pData, swap);				       /* proto name */
+-    SKIP_STRING (pData, swap);				       /* vendor */
+-    SKIP_STRING (pData, swap);				       /* release */
+-    SKIP_LISTOF_STRING (pData, swap, (int) message->authCount);/* auth names */
++    SKIP_STRING (pData, swap, pEnd);				       /* proto name */
++    SKIP_STRING (pData, swap, pEnd);				       /* vendor */
++    SKIP_STRING (pData, swap, pEnd);				       /* release */
++    SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd);/* auth names */
+     pData += (message->versionCount * 4);		       /* versions */
+ 
+     CHECK_COMPLETE_SIZE (iceConn, ICE_ProtocolSetup,
+@@ -2170,7 +2173,7 @@
+ 
+ {
+     iceProtocolReplyMsg *message;
+-    char		*pData, *pStart;
++    char		*pData, *pStart, *pEnd;
+     Bool		replyReady;
+ 
+     CHECK_AT_LEAST_SIZE (iceConn, ICE_ProtocolReply,
+@@ -2186,9 +2189,10 @@
+     }
+ 
+     pData = pStart;
++    pEnd = pStart + (length << 3);
+ 
+-    SKIP_STRING (pData, swap);				     /* vendor */
+-    SKIP_STRING (pData, swap);				     /* release */
++    SKIP_STRING (pData, swap, pEnd);				     /* vendor */
++    SKIP_STRING (pData, swap, pEnd);				     /* release */
+ 
+     CHECK_COMPLETE_SIZE (iceConn, ICE_ProtocolReply,
+ 	length, pData - pStart + SIZEOF (iceProtocolReplyMsg),
+--- xc/config/util/mdepend.cpp~	Sun Jun 29 03:43:27 1997
++++ xc/config/util/mdepend.cpp	Sun Feb 11 13:55:54 2001
+@@ -29,15 +29,20 @@
+ 
+ silent='-'
+ 
+-TMP=/tmp/mdep$$
+-CPPCMD=${TMP}a
+-DEPENDLINES=${TMP}b
+-TMPMAKEFILE=${TMP}c
+-MAGICLINE=${TMP}d
+-ARGS=${TMP}e
++TMP=`pwd`/.mdep$$
++rm -rf ${TMP}
++if ! mkdir -p ${TMP}; then
++  echo "$0: cannot create ${TMP}, exit." 1>&2
++fi
++
++CPPCMD=${TMP}/a
++DEPENDLINES=${TMP}/b
++TMPMAKEFILE=${TMP}/c
++MAGICLINE=${TMP}/d
++ARGS=${TMP}/e
+ 
+-trap "rm -f ${TMP}*; exit 1" 1 2 15
+-trap "rm -f ${TMP}*; exit 0" 1 2 13
++trap "rm -rf ${TMP}; exit 1" 1 2 15
++trap "rm -rf ${TMP}; exit 0" 1 2 13
+ 
+ echo " \c" > $CPPCMD
+ if [ `wc -c < $CPPCMD` -eq 1 ]
+@@ -242,5 +246,5 @@
+ 
+ esac
+ 
+-rm -f ${TMP}*
++rm -rf ${TMP}
+ exit 0
--- xfree86-1-3.3.6.orig/debian/patches/001a-00_SPARC_programs_rgb.diff
+++ xfree86-1-3.3.6/debian/patches/001a-00_SPARC_programs_rgb.diff
@@ -0,0 +1,21 @@
+--- xc/programs/rgb/Imakefile.jj	Sun Oct  4 16:43:55 1998
++++ xc/programs/rgb/Imakefile	Thu Jan 13 10:57:07 2000
+@@ -21,7 +21,7 @@ XCOMM $XFree86: xc/programs/rgb/Imakefil
+          OBJS = $(OBJS1) $(OBJS2)
+      PROGRAMS = $(RGB_PROG) ProgramTargetName(showrgb)
+ #if !UseRgbTxt
+-#if defined(BSD386Architecture) || defined(NetBSDArchitecture) || defined(OpenBSDArchitecture)
++#if defined(BSD386Architecture) || defined(NetBSDArchitecture) || defined(OpenBSDArchitecture) || (defined(SparcArchitecture) && defined(LinuxArchitecture))
+     DATAFILES = rgb.db
+       DATADEP = rgb.db
+ #else
+@@ -40,6 +40,9 @@ XCOMM $XFree86: xc/programs/rgb/Imakefil
+        DBMLIB = DBMLibrary -lucb
+ #endif
+ #endif /*!UseRgbTxt */
++#if defined(LinuxSparc)
++       DBMLIB = -ldb
++#endif
+ 
+ all:: $(PROGRAMS) $(DATADEP)
+ 
--- xfree86-1-3.3.6.orig/debian/patches/010-03_upstream_DoS_fix.diff
+++ xfree86-1-3.3.6/debian/patches/010-03_upstream_DoS_fix.diff
@@ -0,0 +1,158 @@
+--- xc/programs/xterm/charproc.c.orig	Sun Jun 11 21:36:59 2000
++++ xc/programs/xterm/charproc.c	Sun Jun 11 21:41:54 2000
+@@ -197,6 +197,7 @@
+ #define XtNhpLowerleftBugCompat	"hpLowerleftBugCompat"
+ #define XtNinternalBorder	"internalBorder"
+ #define XtNjumpScroll		"jumpScroll"
++#define XtNlimitResize		"limitResize"
+ #define XtNkeyboardDialect      "keyboardDialect"
+ #define XtNlogFile		"logFile"
+ #define XtNlogInhibit		"logInhibit"
+@@ -266,6 +267,7 @@
+ #define XtCHighlightSelection	"HighlightSelection"
+ #define XtCHpLowerleftBugCompat	"HpLowerleftBugCompat"
+ #define XtCJumpScroll		"JumpScroll"
++#define XtCLimitResize		"LimitResize"
+ #define XtCLogInhibit		"LogInhibit"
+ #define XtCLogfile		"Logfile"
+ #define XtCLogging		"Logging"
+@@ -641,6 +643,9 @@
+ {XtNscrollBar, XtCScrollBar, XtRBoolean, sizeof(Boolean),
+ 	XtOffsetOf(XtermWidgetRec, misc.scrollbar),
+ 	XtRBoolean, (XtPointer) &defaultFALSE},
++{XtNlimitResize, XtCLimitResize, XtRInt, sizeof(int),
++	XtOffsetOf(XtermWidgetRec, misc.limit_resize),
++	XtRImmediate, (XtPointer) 1},
+ #ifdef SCROLLBAR_RIGHT
+ {XtNrightScrollBar, XtCRightScrollBar, XtRBoolean, sizeof(Boolean),
+ 	XtOffsetOf(XtermWidgetRec, misc.useRight),
+@@ -3554,40 +3559,49 @@
+ }
+ 
+ 
++#define okDimension(src,dst) ((src <= 32767) && ((dst = src) == src))
++
+ static void RequestResize(
+ 	XtermWidget termw,
+ 	int rows,
+ 	int cols,
+ 	int text)
+ {
+-	register TScreen	*screen	= &termw->screen;
++	TScreen	*screen	= &termw->screen;
++	unsigned long value;
+ 	Dimension replyWidth, replyHeight;
+ 	Dimension askedWidth, askedHeight;
+ 	XtGeometryResult status;
+ 	XWindowAttributes attrs;
+ 
+-	askedWidth  = cols;
+-	askedHeight = rows;
++	if ((askedWidth  = cols) < cols
++	 || (askedHeight = rows) < rows)
++		return;
+ 
+ 	if (askedHeight == 0
+-	 || askedWidth  == 0) {
++	 || askedWidth  == 0
++	 || term->misc.limit_resize > 0) {
+ 		XGetWindowAttributes(XtDisplay(termw),
+ 			RootWindowOfScreen(XtScreen(termw)), &attrs);
+ 	}
+ 
+ 	if (text) {
+-		if (rows != 0) {
++		if ((value = rows) != 0) {
+ 			if (rows < 0)
+-				askedHeight = screen->max_row + 1;
+-			askedHeight *= FontHeight(screen);
+-			askedHeight += (2 * screen->border);
++				value = screen->max_row + 1;
++			value *= FontHeight(screen);
++			value += (2 * screen->border);
++			if (!okDimension(value, askedHeight))
++				return;
+ 		}
+ 
+-		if (cols != 0) {
++		if ((value = cols) != 0) {
+ 			if (cols < 0)
+-				askedWidth = screen->max_col + 1;
+-			askedWidth  *= FontWidth(screen);
+-			askedWidth  += (2 * screen->border) + Scrollbar(screen);
++				value = screen->max_col + 1;
++			value *= FontWidth(screen);
++			value += (2 * screen->border) + Scrollbar(screen);
++			if (!okDimension(value, askedWidth))
++				return;
+ 		}
+ 
+ 	} else {
+@@ -3602,10 +3616,27 @@
+ 	if (cols == 0)
+ 		askedWidth  = attrs.width;
+ 
++	if (term->misc.limit_resize > 0) {
++		Dimension high = term->misc.limit_resize * attrs.height;
++		Dimension wide = term->misc.limit_resize * attrs.width;
++		if (high < attrs.height)
++			high = attrs.height;
++		if (askedHeight > high)
++			askedHeight = high;
++		if (wide < attrs.width)
++			wide = attrs.width;
++		if (askedWidth > wide)
++			askedWidth = wide;
++	}
++
+ 	status = XtMakeResizeRequest (
+ 	    (Widget) termw,
+ 	     askedWidth,  askedHeight,
+ 	    &replyWidth, &replyHeight);
++	TRACE(("charproc.c XtMakeResizeRequest %dx%d -> %dx%d (status %d)\n",
++		askedHeight, askedWidth,
++		replyHeight, replyWidth,
++		status));
+ 
+ 	if (status == XtGeometryYes ||
+ 	    status == XtGeometryDone) {
+@@ -3752,6 +3783,7 @@
+        wnew->screen.terminal_id = MAX_DECID;
+    wnew->screen.ansi_level = (wnew->screen.terminal_id / 100);
+    wnew->screen.visualbell = request->screen.visualbell;
++   wnew->misc.limit_resize = request->misc.limit_resize;
+ #if OPT_TEK4014
+    wnew->screen.TekEmu = request->screen.TekEmu;
+ #endif
+--- xc/programs/xterm/ptyx.h.orig	Sun Jun 11 21:36:59 2000
++++ xc/programs/xterm/ptyx.h	Sun Jun 11 21:40:00 2000
+@@ -873,6 +873,7 @@
+     char *T_geometry;
+     char *f_n;
+     char *f_b;
++    int limit_resize;
+ #ifdef ALLOWLOGGING
+     Boolean log_on;
+ #endif
+--- xc/programs/xterm/version.h.orig	Tue May 11 07:32:17 1999
++++ xc/programs/xterm/version.h	Sun Jun  4 15:17:31 2000
+@@ -6,4 +6,4 @@
+  * version of xterm has been built.  The number in parentheses is my patch
+  * number (T.Dickey).
+  */
+-#define XTERM_VERSION "XFree86 3.3.3.1b(88b)" 
++#define XTERM_VERSION "XFree86 3.3.6(88c)" 
+--- xc/programs/xterm/xterm.man.orig	Sun Jun 11 21:36:59 2000
++++ xc/programs/xterm/xterm.man	Sun Jun 11 21:40:00 2000
+@@ -1012,6 +1012,11 @@
+ which change character sets.
+ The default is ``B'', which corresponds to US ASCII.
+ .TP 8
++.B "limitResize (\fPclass\fB LimitResize)"
++Limits resizing of the screen via control sequence to a given multiple of
++the display dimensions.
++The default is ``1''.
++.TP 8
+ .B "loginShell (\fPclass\fB LoginShell)"
+ Specifies whether or not the shell to be run in the window should be started
+ as a login shell.  The default is ``false.''
--- xfree86-1-3.3.6.orig/debian/patches/010a_xterm_main.c_if-cleanups.diff
+++ xfree86-1-3.3.6/debian/patches/010a_xterm_main.c_if-cleanups.diff
@@ -0,0 +1,67 @@
+--- xc/programs/xterm/main.c.orig	Sun Dec  5 04:37:47 1999
++++ xc/programs/xterm/main.c	Wed Dec  8 14:27:41 1999
+@@ -148,7 +148,7 @@
+ static Bool IsPts = False;
+ #endif
+ 
+-#if (defined(ATT) && !defined(__sgi)) || (defined(SYSV) && defined(i386)) || (defined (__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
++#if (defined(ATT) && !defined(__sgi)) || (defined(SYSV) && defined(i386)) || ((__GLIBC__ > 2) || (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
+ #define USE_USG_PTYS
+ #else
+ #define USE_HANDSHAKE
+@@ -177,7 +177,7 @@
+ #define LASTLOG
+ #define WTMP
+ #undef  HAS_LTCHARS
+-#if (__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
++#if __GLIBC__ >= 2
+ #include <pty.h>
+ #endif
+ #endif
+@@ -398,8 +398,8 @@
+ #define HAS_SAVED_IDS_AND_SETEUID
+ #endif
+ 
+-/* Xpoll.h and <sys/param.h> on glibc 2.1 systems have colliding NBBY's */
+-#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
++/* Xpoll.h and <sys/param.h> on glibc 2 systems have colliding NBBY's */
++#if __GLIBC__ >= 2
+ #ifndef NOFILE
+ #define NOFILE OPEN_MAX
+ #endif
+@@ -2733,7 +2733,7 @@
+ 	qsetlogin( getlogin(), ttydev );
+ #endif
+ 		while (1) {
+-#if defined(TIOCNOTTY) && !((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)))
++#if defined(TIOCNOTTY) && ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
+ 			if (!no_dev_tty && (tty = open ("/dev/tty", O_RDWR)) >= 0) {
+ 				ioctl (tty, TIOCNOTTY, (char *) NULL);
+ 				close (tty);
+@@ -3314,7 +3314,7 @@
+ #if defined(SVR4) || defined(SCO325)
+ 		if (term->misc.login_shell)
+ 		    updwtmpx(WTMPX_FILE, &utmp);
+-#elif defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && !(defined(__powerpc__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
++#elif __GLIBC__ >= 2
+ 		if (term->misc.login_shell)
+ 		    updwtmp(etc_wtmp, &utmp);
+ #else
+@@ -4073,7 +4073,7 @@
+ #endif
+ 	char* ptyname;
+ 	char* ptynameptr = 0;
+-#if defined(WTMP) && !defined(SVR4) && !(defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && !(defined(__powerpc__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)))
++#if defined(WTMP) && !defined(SVR4) && !(__GLIBC__ >= 2)
+ 	int fd;			/* for /etc/wtmp */
+ 	int i;
+ #endif
+@@ -4118,7 +4118,7 @@
+ #if defined(SVR4) || defined(SCO325)
+ 		    if (term->misc.login_shell)
+ 			updwtmpx(WTMPX_FILE, utptr);
+-#elif defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2) && !(defined(__powerpc__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
++#elif __GLIBC__ >= 2
+ 		    strncpy (utmp.ut_line, utptr->ut_line, sizeof (utmp.ut_line));
+ 		    if (term->misc.login_shell)
+ 			updwtmp(etc_wtmp, utptr);
--- xfree86-1-3.3.6.orig/debian/patches/068_cyrix_driver_3.3.3.1.diff
+++ xfree86-1-3.3.6/debian/patches/068_cyrix_driver_3.3.3.1.diff
@@ -0,0 +1,3056 @@
+This is the 3.3.3.1 version of the Cyrix driver, which according to Telsa
+Gwynne, works, whereas the 3.3.6 Cyrix driver doesn't.
+
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/Imakefile xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/Imakefile
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/Imakefile	Thu Jun 24 01:06:24 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/Imakefile	Wed Oct 21 23:31:05 1998
+@@ -1,4 +1,4 @@
+-XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/Imakefile,v 1.1.2.9 1999/06/23 12:37:21 hohndel Exp $
++XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/Imakefile,v 1.1.2.7 1998/10/21 02:55:58 dawes Exp $
+ XCOMM
+ XCOMM This is an Imakefile for the cyrix driver.  
+ XCOMM 
+@@ -6,10 +6,10 @@
+ #include <Server.tmpl>
+ 
+ SRCS = cyrix_driver.c cyrix_accel.c cyrix_cursor.c cyrix_cmap.c cyrix_bank.s \
+-       cyrix_asm.s gxrender.c
++       cyrix_asm.s
+ 
+ OBJS = cyrix_driver.o cyrix_accel.o cyrix_cursor.o cyrix_cmap.o cyrix_bank.o \
+-       cyrix_asm.o gxrender.o
++       cyrix_asm.o
+ 
+ DEFINES = -DPSZ=8
+ 
+@@ -61,7 +61,6 @@
+ InstallLinkKitNonExecFile(cyrix_driver.c,$(LINKKITDIR)/drivers/vga256/cyrix)
+ InstallLinkKitNonExecFile(cyrix_bank.s,$(LINKKITDIR)/drivers/vga256/cyrix)
+ InstallLinkKitNonExecFile(cyrix_asm.s,$(LINKKITDIR)/drivers/vga256/cyrix)
+-InstallLinkKitNonExecFile(gxrender.c,$(LINKKITDIR)/drivers/vga256/cyrix)
+ InstallLinkKitNonExecFile(Imakefile,$(LINKKITDIR)/drivers/vga256/cyrix)
+ 
+ XCOMM
+@@ -82,4 +81,3 @@
+ XCOMM Install Link Kit Non Exec File(Imakefile,$(LINKKITDIR)/drivers/vga16/cyrix)
+ 
+ DependTarget()
+-
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix.h xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix.h
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix.h	Tue Dec 22 11:26:11 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix.h	Tue Dec 22 02:49:58 1998
+@@ -1,5 +1,5 @@
+ 
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix.h,v 1.1.2.6 1998/12/22 07:49:58 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix.h,v 1.1.2.5 1998/11/06 09:47:02 hohndel Exp $ */
+ 
+ /* this code is partly based on the MediaGX sources from the GGI project
+    based on CYRIX example code (gxvideo.c) and included with CYRIX and
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_accel.c xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_accel.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_accel.c	Thu Jun 24 01:06:24 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_accel.c	Tue Dec 22 02:49:58 1998
+@@ -1,7 +1,6 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_accel.c,v 1.1.2.6 1999/06/23 12:37:21 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_accel.c,v 1.1.2.4 1998/12/13 14:12:13 dawes Exp $ */
+ 
+ /*
+- * Copyright 1999 by Brian Falardeau.
+  * Copyright 1998 by Annius Groenink, Amsterdam.
+  *
+  * Permission to use, copy, modify, distribute, and sell this software and its
+@@ -33,6 +32,7 @@
+ #include "cyrix.h"
+ #include "miline.h"
+ 
++
+ /* size of color expand source area (embedded in frame buffer) */
+ #define CYRIXexpandSize       32768
+ 
+@@ -41,64 +41,17 @@
+    upper nybble inverted X raster operation (bits 0 - 3 correspond to
+    bits 3 - 0 and 7 - 4 in Windows style ROP).  In some routines,
+    the role of source and pattern is inverted. */
+-
+-/* The following ROPs only use pattern and destination data. */
+-/* They are used when the planemask specifies all planes (no mask). */
+-
+-static const int windowsROPpat[16] = { 
+-	0x00, /* GXclear = 0 */ 
+-	0xA0, /* GXand = pat AND dst */ 
+-	0x50, /* GXandReverse = pat AND NOT dst */
+-	0xF0, /* GXcopy = pat */ 
+-	0x0A, /* GXandInverted = NOT pat AND dst */ 
+-	0xAA, /* GXnoop = dst */ 
+-	0x5A, /* GXxor = pat XOR dst */  
+-	0xFA, /* GXor = pat OR dst */
+-	0x05, /* GXnor = NOT pat AND NOT dst */ 
+-	0xA5, /* GXequiv = NOT pat XOR dst */ 
+-	0x55, /* GXinvert = NOT dst */ 
+-	0xF5, /* GXorReverse = pat OR NOT dst */ 
+-	0x0F, /* GXcopyInverted = NOT pat */ 
+-	0xAF, /* GXorInverted = NOT pat OR dst */ 
+-	0x5F, /* GXnand = NOT pat OR NOT dst */ 
+-	0xFF, /* GXset = 1 */ 
+-};
+-
+-/* The following ROPs use source data to specify a planemask. */
+-/* If the planemask (src) is one, then the result is the appropriate */
+-/* combination of pattern and destination data.  If the planemask (src) */
+-/* is zero, then the result is always just destination data. */
+-
+-static const int windowsROPsrcMask[16] = { 
+-	0x22, /* GXclear => 0 if src = 1, dst if src = 0 */ 
+-	0xA2, /* GXand = pat AND dst if src = 1, dst if src = 0 */
+-	0x62, /* GXandReverse = pat AND NOT dst if src = 1, dst if src = 0 */
+-	0xE2, /* GXcopy = pat if src = 1, dst if src = 0 */ 
+- 	0x2A, /* GXandInverted = NOT pat AND dst if src = 1, dst if src = 0 */ 
+-	0xAA, /* GXnoop = dst if src = 1, dst if src = 0 */
+-	0x6A, /* GXxor = pat XOR dst if src = 1, dst if src = 0 */
+-	0xEA, /* GXor = pat OR dst if src = 1, dst if src = 0 */
+-    0x26, /* GXnor = NOT pat AND NOT dst if src = 1, dst if src = 0 */
+-	0xA6, /* GXequiv = NOT pat XOR dst if src = 1, dst if src = 0 */
+-	0x66, /* GXinvert = NOT dst if src = 1, dst if src = 0 */
+-	0xE6, /* GXorReverse = pat OR NOT dst if src = 1, dst if src = 0 */
+-    0x2E, /* GXcopyInverted = NOT pat if src = 1, dst if src = 0 */
+-	0xAE, /* GXorInverted = NOT pat OR dst if src = 1, dst if src = 0 */
+-	0x6E, /* GXnand = NOT pat OR NOT dst if src = 1, dst if src = 0 */
+-	0xEE, /* GXset = 1 if src = 1, dst if src = 0 */
+-};
+-
+-/* The following ROPs use pattern data to specify a planemask. */
+-/* If the planemask (pat) is one, then the result is the appropriate */
+-/* combination of source and destination data.  If the planemask (pat) */
+-/* is zero, then the result is always just destination data. */
+-
+ static const int windowsROPpatMask[16] = { 0x0A, 0x8A, 0x4A, 0xCA,
+                                            0x2A, 0xAA, 0x6A, 0xEA,
+                                            0x1A, 0x9A, 0x5A, 0xDA,
+                                            0x3A, 0xBA, 0x7A, 0xFA };
+ 
++static const int windowsROPsrcMask[16] = { 0x22, 0xA2, 0x62, 0xE2,
++                                           0x2A, 0xAA, 0x6A, 0xEA,
++                                           0x26, 0xA6, 0x66, 0xE6,
++                                           0x2E, 0xAE, 0x6E, 0xEE };
+ 
++static int bltBufWidth;
+ 
+ static int blitMode;
+ static int vectorMode;
+@@ -106,91 +59,33 @@
+ static int copyXdir;
+ static int setBlitModeOnSync = 0;
+ 
+-/* STATIC VARIABLES FOR THIS FILE */
+-/* Used to maintain state between setup and rendering calls. */
+-
+-static int CYRIXsavedROP;
+-static int CYRIXtransparent;
+-static int CYRIXtransColor;
+-static int CYRIXstartMonoExpand = 0;
+-
+-static unsigned short CYRIXsaveX, CYRIXsaveY, CYRIXsaveW, CYRIXsaveH;
+ 
+ /* Forward declaration of functions used in the driver */
+-
+ void CYRIXAccelSync();
+ void CYRIXAccelInit();
+ void CYRIXSetupForFillRectSolid();
+ void CYRIXSubsequentFillRectSolid();
+-void CYRIXSetupFor8x8PatternColorExpand();
+-void CYRIXSubsequent8x8PatternColorExpand();
+ void CYRIXSetupForScreenToScreenCopy();
+ void CYRIXSubsequentScreenToScreenCopy();
+-
+ void CYRIXSubsequentBresenhamLine();
++void CYRIXSetupFor8x8PatternColorExpand();
++void CYRIXSubsequent8x8PatternColorExpand();
+ void CYRIXSetupForCPUToScreenColorExpand();
+ void CYRIXSubsequentCPUToScreenColorExpand();
+ 
+-/* Routines in GXRENDER.C */
+-
+-void gxr_initialize(unsigned char *regptr, unsigned short bpp, 
+-	unsigned short BB0base, unsigned short BB1base, 
+-	unsigned short BBwidthPixels);
+-
+-void gxr_wait_until_idle(void);
+-
+-void gxr_load_solid_source(unsigned short color);
+-
+-void gxr_load_mono_source(unsigned short bgcolor, unsigned short fgcolor,
+-	unsigned short transparent);
+-
+-void gxr_load_solid_pattern(unsigned short color);
+-
+-void gxr_load_mono_pattern(unsigned short bgcolor, unsigned short fgcolor, 
+-	unsigned long data0, unsigned long data1, unsigned char transparency);
+-
+-void gxr_load_raster_operation(unsigned char rop);
+-
+-void gxr_pattern_fill(unsigned short x, unsigned short y, 
+-	unsigned short width, unsigned short height);
+-
+-void gxr_screen_to_screen_blt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height);
+-
+-void gxr_screen_to_screen_xblt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned short color);
+-
+-void gxr_text_glyph(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned char *data, unsigned short pitch); 
+-
+-void gxr_bresenham_line(unsigned short x, unsigned short y, 
+-	unsigned short length, unsigned short initerr, 
+-	unsigned short axialerr, unsigned short diagerr, 
+-	unsigned short flags);
+-
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXAccelInit
+-//
+-// This routine hooks the acceleration routines and sets appropriate flags.
+-//---------------------------------------------------------------------------
+-*/
+ 
++/* Acceleration init function, sets up pointers to our accelerated functions */
+ void 
+ CYRIXAccelInit() 
+-{
+-	int bltBufWidth;
+-
+-	/* General acceleration flags */
++{	/* General acceleration flags */
+ 	xf86AccelInfoRec.Flags = PIXMAP_CACHE
+ 	                       | BACKGROUND_OPERATIONS
++#if 0
++	                       | HARDWARE_PATTERN_MONO_TRANSPARENCY
++#endif
+ 	                       | HARDWARE_PATTERN_SCREEN_ORIGIN
+ 	                       | HARDWARE_PATTERN_BIT_ORDER_MSBFIRST
+-	                       | HARDWARE_PATTERN_PROGRAMMED_BITS
+-	                       | HARDWARE_PATTERN_MONO_TRANSPARENCY;
++	                       | HARDWARE_PATTERN_PROGRAMMED_BITS;
+ 
+ 	/* Sync */
+ 	xf86AccelInfoRec.Sync = CYRIXAccelSync;
+@@ -200,19 +95,22 @@
+ 	    CYRIXSetupForFillRectSolid;
+ 	xf86AccelInfoRec.SubsequentFillRectSolid = 
+ 	    CYRIXSubsequentFillRectSolid;
+-	xf86GCInfoRec.PolyFillRectSolidFlags = 0;
++	xf86GCInfoRec.PolyFillRectSolidFlags = NO_PLANEMASK;
+ 
+ 	/* ScreenToScreen copies */
+ 	xf86AccelInfoRec.SetupForScreenToScreenCopy =
+ 	    CYRIXSetupForScreenToScreenCopy;
+ 	xf86AccelInfoRec.SubsequentScreenToScreenCopy =
+ 	    CYRIXSubsequentScreenToScreenCopy;
+-	xf86GCInfoRec.CopyAreaFlags = TRANSPARENCY_GXCOPY;
+ 
+-	/* Bresenham lines */
++	xf86GCInfoRec.CopyAreaFlags = NO_PLANEMASK | GXCOPY_ONLY;
++
++#if 0
++	/* Bresenham lines - disable because of minor display errors */
+ 	xf86AccelInfoRec.SubsequentBresenhamLine =
+ 	    CYRIXSubsequentBresenhamLine;
+ 	xf86AccelInfoRec.ErrorTermBits = 15;
++#endif
+ 
+ 	/* 8x8 color-expanded patterns */
+ 	xf86AccelInfoRec.SetupFor8x8PatternColorExpand =
+@@ -222,6 +120,8 @@
+ 
+ 	/* Color expansion */
+ 	xf86AccelInfoRec.ColorExpandFlags = BIT_ORDER_IN_BYTE_MSBFIRST |
++	                                    NO_PLANEMASK |
++	                                    TRANSPARENCY_GXCOPY |
+ 	                                    SCANLINE_PAD_BYTE;
+ 
+ 	/* Use two blit buffers in a row for text expansion
+@@ -245,344 +145,255 @@
+ 
+ 	/* calculate the pixel width of a blit buffer for convenience */
+ 	bltBufWidth = CYRIXbltBufSize / (vgaBitsPerPixel / 8);
++} 
+ 
+-	/* pass parameters to GXRENDER.C file */
+ 
+-	gxr_initialize((unsigned char *) GXregisters, 
+-		(unsigned short) vgaBitsPerPixel,
+-		(unsigned short) CYRIXbltBuf0Address, 
+-		(unsigned short) CYRIXbltBuf1Address, 
+-		(unsigned short) bltBufWidth);
+-} 
++/* set colors - called through access macros in cyrix.h */
++static __inline__ void CYRIXsetColors01(reg, col0, col1)
++int reg;
++int col0;
++int col1;
++{	if (vgaBitsPerPixel == 16)
++		GX_REG(reg) = ((col1 & 0xFFFF) << 16) | (col0 & 0xFFFF);
++	else
++	{	col0 &= 0xFF;
++		col1 &= 0xFF;
++		GX_REG(reg) = (col1 << 24) | (col1 << 16) | (col0 << 8) | col0;
++}	}
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXAccelSync
+-//
+-// This routine is called before accessing the frame buffer directly to 
+-// make sure that the graphics pipeline is idle.  It is also called after
+-// loading the monochrome data into BB0 for bitmap to screen BLTs.
+-//---------------------------------------------------------------------------
+-*/
+ 
++/* The generic Sync() function that waits for everything to
++   be completed (e.g. before writing to the frame buffer
++   directly). */
+ void
+ CYRIXAccelSync()
+-{	
+-	/* CHECK IF END TO CPU TO SCREEN EXPAND BLT */
+-
+-	if (CYRIXstartMonoExpand)
+-	{	
+-		/* START CPU TO SCREEN EXPAND BLT */
+-		/* Data has already been loaded into BB0, so use NULL pointer. */
+-
+-		/* this is formally incorrect: XAA may use both BB0 and BB1
+-		   for the text source bitmap, so READ_DST_FB1 should not be
+-	       used.  So far, this problem has not manifested itself in
+-	       practice. */
+-
+-		CYRIXstartMonoExpand = 0;
+-		gxr_text_glyph(0, 0, CYRIXsaveX, CYRIXsaveY, CYRIXsaveW, 
+-			CYRIXsaveH, 0, 0);
++{	if (setBlitModeOnSync)
++	{	setBlitModeOnSync = 0;
++		CYRIXsetupSync();
++		CYRIXsetBlitMode();
+ 	}
+-	
+-	/* WAIT UNTIL IDLE */
+-
+-	gxr_wait_until_idle();
++	while (GX_REG(GP_BLIT_STATUS) &
++	       (BS_BLIT_BUSY|BS_PIPELINE_BUSY|BS_BLIT_PENDING));
+ }
+ 
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSetupForFillRectSolid
+-//
+-// This routine is called to setup the solid pattern color for future
+-// rectangular fills or vectors.
+-//---------------------------------------------------------------------------
+-*/
+-
++/* Solid rectangles */
+ void 
+ CYRIXSetupForFillRectSolid(color, rop, planemask)
+ int color, rop;
+ unsigned int planemask;
+-{
+-	/* LOAD THE SOLID PATTERN COLOR */
+-
+-	gxr_load_solid_pattern((unsigned short) color);
+-
+-	/* CHECK IF PLANEMASK IS NOT USED (ALL PLANES ENABLED) */
+-
+-	if (planemask == (unsigned int) -1)
+-	{
+-		/* use normal pattern ROPs if all planes are enabled */
+-
+-		gxr_load_raster_operation(windowsROPpat[rop & 0x0F]);
+-	}
+-	else
+-	{
+-		/* select ROP that uses planemask in src data */
+-
+-		gxr_load_solid_source((unsigned short) planemask);
+-		gxr_load_raster_operation(windowsROPsrcMask[rop & 0x0F]);
+-	}
++{	if (xf86GCInfoRec.PolyFillRectSolidFlags & NO_PLANEMASK)
++		planemask = 0xFFFF;
++	if (xf86GCInfoRec.PolyFillRectSolidFlags & GXCOPY_ONLY)
++		rop = GXcopy;
++
++	CYRIXsetupSync();
++	CYRIXsetSourceColors01(color, color);
++	CYRIXsetPatColors01(planemask, 0);
++	CYRIXsetPatMode(rop, RM_PAT_DISABLE);
++	blitMode = BM_READ_SRC_NONE | BM_WRITE_FB | BM_SOURCE_EXPAND
++	         | IfDest(rop, planemask, BM_READ_DST_FB0);
++	vectorMode = IfDest(rop, planemask, VM_READ_DST_FB);
+ }
+     
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSubsequentFillRectSolid
+-//
+-// This routine is called to fill a rectangular region using the previously
+-// specified solid pattern and raster operation.  
+-//
+-// Sample application uses:
+-//   - Window backgrounds. 
+-//   - x11perf: rectangle tests (-rect500).
+-//   - x11perf: fill trapezoid tests (-trap100).
+-//   - x11perf: horizontal line segments (-hseg500).
+-//---------------------------------------------------------------------------
+-*/
+     
+ void 
+ CYRIXSubsequentFillRectSolid(x, y, w, h)
+ int x, y, w, h;
+-{
+-	/* call routine to fill rectangular region */
+-
+-	gxr_pattern_fill((unsigned short) x, (unsigned short) y, 
+-		(unsigned short) w, (unsigned short) h);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSetupFor8x8PatternColorExpand
+-//
+-// This routine is called to setup the monochrome pattern (8x8) and raster 
+-// operation for future rectangular fills.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void CYRIXSetupFor8x8PatternColorExpand(patternx, patterny, bg, fg, rop, planemask)
+-int patternx, patterny;
+-int bg, fg, rop;
+-unsigned int planemask;
+-{	int trans = (bg == -1);
+-
+-	/* LOAD PATTERN COLORS AND DATA */
+-
+-	gxr_load_mono_pattern((unsigned short) bg, (unsigned short) fg,
+-		(unsigned long) patternx, (unsigned long) patterny, 
+-		(unsigned char) trans);
+-
+-	/* CHECK IF PLANEMASK IS NOT USED (ALL PLANES ENABLED) */
+-
+-	if (planemask == (unsigned int) -1)
+-	{
+-		/* use normal pattern ROPs if all planes are enabled */
+-
+-		gxr_load_raster_operation(windowsROPpat[rop & 0x0F]);
+-	}
+-	else
+-	{
+-		/* select ROP that uses planemask in src data */
+-
+-		gxr_load_solid_source((unsigned short) planemask);
+-		gxr_load_raster_operation(windowsROPsrcMask[rop & 0x0F]);
++{	/* divide the operation into columns if required; use twice the
++           blit buffer width because buffer 0 will overflow into buffer 1 */
++	while (w > 2 * bltBufWidth)
++	{	CYRIXSubsequentFillRectSolid(x, y, 2 * bltBufWidth, h);
++		x += 2 * bltBufWidth;
++		w -= 2 * bltBufWidth;
+ 	}
++	CYRIXsetupSync();
++	CYRIXsetDstXY(x, y);
++	CYRIXsetWH(w, h);
++	CYRIXsetBlitMode();
+ }
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSubsequent8x8PatternColorExpand
+-//
+-// This routine is called to fill a rectangular region using the previously
+-// specified monochrome pattern (8x8) and raster operation.
+-//
+-// Sample application uses:
+-//   - Patterned desktops
+-//   - x11perf: stippled rectangle tests (-srect500).
+-//   - x11perf: opaque stippled rectangle tests (-osrect500).
+-//---------------------------------------------------------------------------
+-*/
+-
+-void CYRIXSubsequent8x8PatternColorExpand(patternx, patterny, x, y, w, h)
+-int patternx, patterny;
+-int x, y, w, h;
+-{
+-	/* call routine to fill rectangular region */
+-
+-	gxr_pattern_fill((unsigned short) x, (unsigned short) y, 
+-		(unsigned short) w, (unsigned short) h);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSetupForScreenToScreenCopy
+-//
+-// This routine is called to setup the planemask and raster operation 
+-// for future screen to screen BLTs.
+-//---------------------------------------------------------------------------
+-*/
+ 
++/* Screen to screen copies */
+ void 
+ CYRIXSetupForScreenToScreenCopy(xdir, ydir, rop, planemask, transparency_color)
+ int xdir, ydir;
+ int rop;
+ unsigned int planemask;
+ int transparency_color;
+-{
+-	/* LOAD PLANEMASK INTO PATTERN DATA */
++{	if (xf86GCInfoRec.CopyAreaFlags & NO_PLANEMASK)
++		planemask = 0xFFFF;
++	if (xf86GCInfoRec.CopyAreaFlags & GXCOPY_ONLY)
++		rop = GXcopy;
++	if (xf86GCInfoRec.CopyAreaFlags & NO_TRANSPARENCY)
++		transparency_color = -1;
++
++	CYRIXsetupSync();
++	CYRIXsetPatColors01(planemask, 0);
++
++	if (transparency_color == -1)
++	{	CYRIXsetPatMode(rop, RM_PAT_DISABLE);
++		transMode = 0;
++	}
++	else
++	{	CYRIXsetPatModeTrans(RM_PAT_DISABLE);
++		transMode = 1;
+ 
+-	gxr_load_solid_pattern((unsigned short) planemask);
+-	
+-	/* SET RASTER OPERATION FOR USING PATTERN AS PLANE MASK */
++		if (xf86GCInfoRec.CopyAreaFlags & TRANSPARENCY_GXCOPY)
++			rop = GXcopy;
+ 
+-	gxr_load_raster_operation(windowsROPpatMask[rop & 0x0F]);
++		/* fill blit buffer 1 with the transparency color */
++		if (vgaBitsPerPixel == 16)
++		{	int              k   = CYRIXbltBufSize / 4;
++			CARD32           val = (transparency_color << 16) |
++			                       transparency_color;
++			volatile CARD32* buf = &(GX_REG(CYRIXbltBuf1Address));
++
++			while (--k >= 0) buf[k] = val;
++		}
++		else
++			memset(GXregisters + CYRIXbltBuf1Address,
++			       transparency_color, CYRIXbltBufSize);
++	}
+ 
+-	/* SAVE TRANSPARENCY FLAG */
++	blitMode = BM_READ_SRC_FB | BM_WRITE_FB | BM_SOURCE_COLOR
++	         | (transMode ? BM_READ_DST_NONE : IfDest(rop, planemask, BM_READ_DST_FB1))
++	         | (ydir < 0 ? BM_REVERSE_Y : 0);
+ 
+-	CYRIXtransparent = (transparency_color == -1) ? 0 : 1;
+-	CYRIXtransColor = transparency_color;
++	copyXdir = xdir;
+ }
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSubsequentScreenToScreenCopy
+-//
+-// This routine is called to perform a screen to screen BLT using the 
+-// previously specified planemask, raster operation, and transparency flag.
+-//
+-// Sample application uses (non-transparent):
+-//   - Moving windows.
+-//   - x11perf: scroll tests (-scroll500).
+-//   - x11perf: copy from window to window (-copywinwin500).
+-//
+-// No application found using transparency.
+-//---------------------------------------------------------------------------
+-*/
+-
+ void 
+ CYRIXSubsequentScreenToScreenCopy(x1, y1, x2, y2, w, h)
+ int x1, y1, x2, y2, w, h;
+-{
+-	if (CYRIXtransparent)
+-	{
+-		/* CALL ROUTINE FOR TRANSPARENT SCREEN TO SCREEN BLT */
+-		/* Should only be called for the "copy" raster operation. */
+-
+-		gxr_screen_to_screen_xblt(
+-			(unsigned short) x1, (unsigned short) y1, 
+-			(unsigned short) x2, (unsigned short) y2, 
+-			(unsigned short) w, (unsigned short) h, 
+-			(unsigned short) CYRIXtransColor);
++{	int up       = (blitMode & BM_REVERSE_Y);
++
++	/* divide the operation into columns when necessary */
++	if (copyXdir < 0)
++	{	int x_offset = w - bltBufWidth;
++
++		while (x_offset > 0)
++		{	CYRIXSubsequentScreenToScreenCopy(x1 + x_offset, y1,
++			                                  x2 + x_offset, y2,
++			                                  bltBufWidth, h);
++			x_offset -= bltBufWidth;
++			w -= bltBufWidth;
++	}	}
++	else while (w > bltBufWidth)
++	{	CYRIXSubsequentScreenToScreenCopy(x1, y1, x2, y2,
++		                                  bltBufWidth, h);
++		x1 += bltBufWidth;
++		x2 += bltBufWidth;
++		w -= bltBufWidth;
+ 	}
+-	else
+-	{
+-		/* CALL ROUTINE FOR NORMAL SCREEN TO SCREEN BLT */
+ 
+-		gxr_screen_to_screen_blt(
+-			(unsigned short) x1, (unsigned short) y1, 
+-			(unsigned short) x2, (unsigned short) y2, 
+-			(unsigned short) w, (unsigned short) h);
++	CYRIXsetupSync();
++	CYRIXsetSrcXY(x1, (up ? (y1 + h - 1) : y1));
++	CYRIXsetDstXY(x2, (up ? (y2 + h - 1) : y2));
++
++	/* in transparent mode, one line reads the transparency color
++	   into a processor-internal register, and the remaining lines
++	   can be done in a single second pass */
++	if (transMode)
++	{	blitMode |= BM_READ_DST_BB1;
++		CYRIXsetWH(w, 1);
++		CYRIXsetBlitMode();
++		h--;
++		if (!h) return;
++		if (up) { y1--; y2--; }
++		else { y1++; y2++; }
++		CYRIXsetupSync();
++		blitMode &= ~(BM_READ_DST_BB1);
+ 	}
++	CYRIXsetWH(w, h);
++	CYRIXsetBlitMode();
+ }
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSubsequentBresenhamLine
+-//
+-// This routine is called to render a vector using the specified Bresenham
+-// parameters.  
+-//
+-// Sample application uses:
+-//   - Window outlines on window move.
+-//   - x11perf: line segments (-seg500).
+-//---------------------------------------------------------------------------
+-*/
+ 
++/* Bresenham lines */
+ void
+ CYRIXSubsequentBresenhamLine(x1, y1, octant, err, e1, e2, length)
+ int x1, y1, octant, err, e1, e2, length;
+-{	
+-	unsigned short flags;
+-
+-	/* DETERMINE YMAJOR AND DIRECTION FLAGS */
+-
+-	if (octant & YMAJOR)
+-	{	flags = VM_Y_MAJOR;
+-		if (!(octant & XDECREASING)) flags |= VM_MINOR_INC;
+-		if (!(octant & YDECREASING)) flags |= VM_MAJOR_INC;
++{	if (octant & YMAJOR)
++	{	vectorMode = (vectorMode & VM_READ_DST_FB) | VM_Y_MAJOR;
++		if (!(octant & XDECREASING)) vectorMode |= VM_MINOR_INC;
++		if (!(octant & YDECREASING)) vectorMode |= VM_MAJOR_INC;
+ 	}
+ 	else
+-	{	flags = VM_X_MAJOR;
+-		if (!(octant & XDECREASING)) flags |= VM_MAJOR_INC;
+-		if (!(octant & YDECREASING)) flags |= VM_MINOR_INC;
++	{	vectorMode = (vectorMode & VM_READ_DST_FB) | VM_X_MAJOR;
++		if (!(octant & XDECREASING)) vectorMode |= VM_MAJOR_INC;
++		if (!(octant & YDECREASING)) vectorMode |= VM_MINOR_INC;
+ 	}
+ 
+-	/* CALL ROUTINE TO DRAW VECTOR */
+-
+-	gxr_bresenham_line((unsigned short) x1, (unsigned short) y1, 
+-		(unsigned short) length, (unsigned short) err, 
+-		(unsigned short) e1, (unsigned short) e2, (unsigned short) flags);	
++	CYRIXsetupSync();
++	CYRIXsetDstXY(x1, y1);
++	CYRIXsetWH(length, (err & 0xFFFF));
++	CYRIXsetSrcXY((e1 & 0xFFFF), (e2 & 0xFFFF));
++	CYRIXsetVectorMode();
+ }
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSetupForCPUToScreenColorExpand
+-//
+-// This routine is called to setup the planemask, colors, and raster 
+-// operation for future monocrome bitmap to screen BLTs.
+-//---------------------------------------------------------------------------
+-*/
+ 
+-void CYRIXSetupForCPUToScreenColorExpand(bg, fg, rop, planemask)
++/* 8x8 pattern color expand */
++void CYRIXSetupFor8x8PatternColorExpand(patternx, patterny, bg, fg, rop, planemask)
++int patternx, patterny;
+ int bg, fg, rop;
+ unsigned int planemask;
+ {	int trans = (bg == -1);
+ 
+-	/* LOAD SOURCE COLORS */
++	if (xf86AccelInfoRec.ColorExpandFlags & NO_PLANEMASK)
++		planemask = 0xFFFF;
++	if (trans && (xf86AccelInfoRec.ColorExpandFlags & TRANSPARENCY_GXCOPY))
++		rop = GXcopy;
++
++	CYRIXsetupSync();
++	CYRIXsetSourceColors01(planemask, planemask);
++	CYRIXsetPatColors01(trans ? 0 : bg, fg);
++	CYRIXsetPatData(patternx, patterny);
++	CYRIXsetPatModeX(rop, RM_PAT_MONO | (trans ? RM_PAT_TRANSPARENT : 0));
+ 
+-	gxr_load_mono_source((unsigned short) bg, (unsigned short) fg, 
+-		(unsigned short) trans);
++	blitMode = BM_READ_SRC_NONE | BM_WRITE_FB | BM_SOURCE_EXPAND
++	         | (trans ? IfDest(rop, planemask, BM_READ_DST_FB0) : BM_READ_DST_NONE);
++}
+ 
+-	/* LOAD PLANEMASK INTO PATTERN DATA */
++void CYRIXSubsequent8x8PatternColorExpand(patternx, patterny, x, y, w, h)
++int patternx, patterny;
++int x, y, w, h;
++{	CYRIXSubsequentFillRectSolid(x, y, w, h);
++}
+ 
+-	gxr_load_solid_pattern((unsigned short) planemask);
+-	
+-	/* SET RASTER OPERATION FOR USING PATTERN AS PLANE MASK */
+ 
+-	gxr_load_raster_operation(windowsROPpatMask[rop & 0x0F]);
+-}
++/* CPU-to-screen color expansion */
++void CYRIXSetupForCPUToScreenColorExpand(bg, fg, rop, planemask)
++int bg, fg, rop;
++unsigned int planemask;
++{	int trans = (bg == -1);
+ 
+-/*
+-//---------------------------------------------------------------------------
+-// CYRIXSubsequentCPUToScreenColorExpand
+-//
+-// This routine is called to render expanded monocrome bitmap data to the
+-// screen using the previously specified colors and raster operation.  Since
+-// the server loads the monochrome data into BB0, not the driver, this 
+-// routine just sets a flag and saves the parameters to use when the server
+-// is done loading the data and calls the CYRIXAccelSync function. 
+-//
+-// Sample application uses:
+-//   - Text in windows.
+-//   - x11perf: text (-ftext, -f8text, -f9text, ...).
+-//---------------------------------------------------------------------------
+-*/
++	if (trans && (xf86AccelInfoRec.ColorExpandFlags & TRANSPARENCY_GXCOPY))
++		rop = GXcopy;
++
++	CYRIXsetupSync();
++	CYRIXsetSourceColors01(trans ? 0 : bg, fg);
++	CYRIXsetPatColors01(planemask, 0);
++
++	CYRIXsetPatMode(rop, RM_PAT_DISABLE | (trans ? RM_SRC_TRANSPARENT : 0));
++
++	/* this is formally incorrect: XAA may use both BB0 and BB1
++	   for the text source bitmap, so READ_DST_FB1 should not be
++	   used.  So far, this problem has not manifested itself in
++	   practice. */
++	blitMode = BM_READ_SRC_BB0 | BM_WRITE_FB | BM_SOURCE_EXPAND
++	         | (trans ? IfDest(rop, planemask, BM_READ_DST_FB1) : BM_READ_DST_NONE);
++}
+ 
+ void CYRIXSubsequentCPUToScreenColorExpand(x, y, w, h, skipleft)
+ int x, y, w, h;
+ int skipleft;
+-{
+-	CYRIXstartMonoExpand = 1;
+-	CYRIXsaveX = x;
+-	CYRIXsaveY = y;
+-	CYRIXsaveW = w;
+-	CYRIXsaveH = h;
+-
+-	/* WAIT UNTIL IDLE BEFORE ALLOWING WRITES TO BLT BUFFERS */
+-	/* Server will load the monochrome data into BB0 after this. */
++{	CYRIXsetupSync();
++	CYRIXsetSrcXY(0, 0);
++	CYRIXsetDstXY(x, y);
++	CYRIXsetWH(w, h);
+ 
+-	gxr_wait_until_idle();
++	CYRIXAccelSync();
++	setBlitModeOnSync = 1;
+ }
+-
+-/* END OF FILE */
+ 
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_asm.s xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_asm.s
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_asm.s	Fri Nov  6 11:41:51 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_asm.s	Fri Nov  6 04:47:05 1998
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_asm.s,v 1.1.2.5 1998/11/06 09:47:05 hohndel Exp $
++/* $XFree86: CYRIX_bank.s $
+  *
+  * Copyright 1998 by Annius V. Groenink (A.V.Groenink@zfc.nl, avg@cwi.nl)
+  *
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_bank.s xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_bank.s
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_bank.s	Fri Nov  6 11:41:51 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_bank.s	Fri Nov  6 04:47:06 1998
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_bank.s,v 1.1.2.3 1998/11/06 09:47:06 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/VGADriverDoc/CYRIX_bank.s,v 3.4 1996/12/23 06:32:00 dawes Exp $ */
+ /*
+  * Copyright 1998 by Annius V. Groenink (A.V.Groenink@zfc.nl, avg@cwi.nl)
+  *
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_cmap.c xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cmap.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_cmap.c	Sun Sep 13 07:29:09 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cmap.c	Sun Sep 13 07:29:09 1998
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cmap.c,v 1.1.2.1 1998/09/13 12:29:09 hohndel Exp $ */
++/* $XFree86: $ */
+ /*
+  * Copyright 1998 by Annius Groenink, Amsterdam.
+  *
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_cursor.c xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cursor.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_cursor.c	Fri Nov  6 11:41:51 1998
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cursor.c	Fri Nov  6 04:47:07 1998
+@@ -1,4 +1,4 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_cursor.c,v 1.1.2.3 1998/11/06 09:47:07 hohndel Exp $ */
++/* $XFree86: $ */
+ /*
+  * Copyright 1998 by Annius V. Groenink (A.V.Groenink@zfc.nl, avg@cwi.nl).
+  *
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_driver.c xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_driver.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/cyrix_driver.c	Thu Jun 24 01:06:24 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_driver.c	Fri Nov  6 04:47:08 1998
+@@ -1,12 +1,9 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_driver.c,v 1.1.2.7 1999/06/23 12:37:22 hohndel Exp $ */
++/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/cyrix_driver.c,v 1.1.2.5 1998/10/25 09:49:22 hohndel Exp $ */
+ /*
+- * Copyright 1999 by Brian Falardeau 
+  * Copyright 1998 by Annius V. Groenink (A.V.Groenink@zfc.nl, avg@cwi.nl),
+  *                   Dirk H. Hohndel (hohndel@suse.de),
+  *                   Portions: the GGI project & confidential CYRIX databooks.
+  *
+- * Substitute Brian Falardeau into a copy of the following legal jargon...
+- *
+  * Permission to use, copy, modify, distribute, and sell this software and its
+  * documentation for any purpose is hereby granted without fee, provided that
+  * the above copyright notice appear in all copies and that both that
+@@ -25,17 +22,13 @@
+  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+  * PERFORMANCE OF THIS SOFTWARE.
+  */
++/* $XConsortium: $ */
+ 
+ /*************************************************************************/
+ 
+ /*
+    Log for the cyrix driver source as a whole
+ 
+-   May 1999, Brian Falardeau:
+-   - Fixed interaction with SoftVGA for setting 2K pitch at 1280x1024.
+-   - Added CRTC tables for 60 Hz and 75 Hz modes.
+-   - Removed enabling display compression directly for VSA1.
+-
+    5th Nov 1998 avg  - Fixed blit buffer organization using CPU_WRITE
+                        instruction.  Support for older chipsets (color
+                        treatment and different CPU_WRITE opcode).
+@@ -115,35 +108,50 @@
+ #include "extensions/xf86dgastr.h"
+ #endif
+ 
++#ifdef XF86VGA16
++#define MONOVGA
++#endif
+ 
++#if !defined(MONOVGA) && !defined(XF86VGA16)
+ #include "vga256.h"
++#endif
++
+ #include "cyrix.h"
+ 
+ pciTagRec CyrixPciTag;
+ extern vgaHWCursorRec vgaHWCursor;
+ 
+-#define NUM_STD_CRTC_REGS 25
+-#define NUM_EXT_CRTC_REGS 16
+-
+ typedef struct {
+ 	vgaHWRec std; /* IBM VGA */
+ 	struct vgaCYRIXext
+-	{	
+-		/* override of miscellaneous output register value */
+-
+-		unsigned char miscOutput;
+-
+-		/* override of standard CRTC register values */
+-
+-		unsigned char stdCRTCregs[NUM_STD_CRTC_REGS];
+-
+-		/* extended CRTC register values (specific to MediaGX) */
+-
+-		unsigned char extCRTCregs[NUM_EXT_CRTC_REGS];
++	{	/* extended SoftVGA registers */
++		unsigned char VerticalTimingExtension;
++		unsigned char ExtendedAddressControl;
++		unsigned char ExtendedOffset;
++		unsigned char ExtendedColorControl;
++		unsigned char DisplayCompression;
++		unsigned char DriverControl;
++		unsigned char DACControl;
++		unsigned char ClockControl;
++		unsigned char CrtClockFrequency;
++		unsigned char CrtClockFrequencyFraction;
++		unsigned char RefreshRate;
++
++		/* display controller hardware registers */
++		CARD32 DcGeneralCfg;
++		CARD32 DcCursStOffset;
++		CARD32 DcCbStOffset;
++		CARD32 DcLineDelta;
++		CARD32 DcBufSize;
++		CARD32 DcCursorX;
++		CARD32 DcCursorY;
++		CARD32 DcCursorColor;
+ 
+ 		/* graphics pipeline registers */
+-
+ 		CARD32 GpBlitStatus;
++
++		/* save area for cursor image */
++		char cursorPattern[256];
+ 	}	ext;
+ } vgaCYRIXRec, *vgaCYRIXPtr;
+ 
+@@ -158,9 +166,11 @@
+ static void	CYRIXRestore();
+ static void	CYRIXAdjust();
+ 
++#ifndef MONOVGA
+ static void	CYRIXFbInit();
+ static Bool	CYRIXScreenInit();
+ static Bool	CYRIXPitchAdjust();
++#endif
+ 
+ void	 CYRIXSetRead();
+ void	 CYRIXSetWrite();
+@@ -177,7 +187,11 @@
+ 	CYRIXAdjust,
+ 	vgaHWSaveScreen,
+ 	(void (*)())NoopDDA,     /* CYRIXGetMode */
++#ifndef MONOVGA
+ 	CYRIXFbInit,
++#else
++	(void (*)())NoopDDA,     /* CYRIXFbInit */
++#endif
+ 	CYRIXSetRead,
+ 	CYRIXSetWrite,
+ 	CYRIXSetReadWrite,
+@@ -191,9 +205,9 @@
+ 	VGA_NO_DIVIDE_VERT,      /* ChipInterlaceType */
+ 	{0,},                    /* ChipOptionFlags */
+ 	8,                       /* ChipRounding */
+-	TRUE,                    /* ChipUseLinearAddressing */
+-	0x40800000,              /* ChipLinearBase */
+-	0x001FFFFF,              /* ChipLinearSize */
++	FALSE,                   /* ChipUseLinearAddressing */
++	0,                       /* ChipLinearBase */
++	0,                       /* ChipLinearSize */
+ 	TRUE,                    /* ChipHas16bpp */
+ 	FALSE,                   /* ChipHas24bpp */
+ 	FALSE,                   /* ChipHas32bpp */
+@@ -207,10 +221,6 @@
+ 
+ char* GXregisters;
+ 
+-int CYRIXvsaversion;			/* VSA version */
+-#define CYRIX_VSA1	1
+-#define CYRIX_VSA2  2
+-
+ int CYRIXcbufferAddress;      /* relative to video base */
+ int CYRIXoffscreenAddress;
+ int CYRIXcursorAddress;
+@@ -225,94 +235,6 @@
+ 
+ #define newstate ((vgaCYRIXPtr)vgaNewVideoState)
+ 
+-typedef struct {
+-	int xsize;
+-	int ysize;
+-	int clock;
+-	unsigned char miscOutput;
+-	unsigned char stdCRTCregs[NUM_STD_CRTC_REGS];
+-	unsigned char extCRTCregs[NUM_EXT_CRTC_REGS];
+-} vgaCYRIXmode;
+-
+-vgaCYRIXmode CYRIXmodes[] =
+-{
+-/*------------------------------------------------------------------------------*/
+-	{ 640, 480,         /* 640x480 */
+-	  25,               /* 25 MHz clock = 60 Hz refresh rate */
+-	  0xE3,             /* miscOutput register */
+-	{ 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, /* standard CRTC */ 
+-	  0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0xEA, 0x0C, 0xDF, 0x50, 0x00, 0xE7, 0x04, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 800, 600,         /* 800x600 */
+-	  40,               /* 40 MHz clock = 60 Hz refresh rate */
+-	  0x23,             /* miscOutput register */
+-	{ 0x7F, 0x63, 0x64, 0x82, 0x6B, 0x1B, 0x72, 0xF0, /* standard CRTC */ 
+-	  0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x59, 0x0D, 0x57, 0x64, 0x00, 0x57, 0x73, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0xA0, 0x50, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 1024, 768,        /* 1024x768 */
+-	  65,               /* 65 MHz clock = 60 Hz refresh rate */
+-	  0xE3,             /* miscOutput register */
+-	{ 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xF5, /* standard CRTC */ 
+-	  0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x04, 0x0A, 0xFF, 0x80, 0x00, 0xFF, 0x25, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0x80, 0x41, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 1280, 1024,       /* 1280x1024 */
+-	  108,              /* 108 MHz clock = 60 Hz refresh rate */
+-	  0x23,             /* miscOutput register */
+-	{ 0xCF, 0x9F, 0xA0, 0x92, 0xAA, 0x19, 0x28, 0x52, /* standard CRTC */ 
+-	  0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x01, 0x04, 0xFF, 0xA0, 0x00, 0x00, 0x29, 0xE3, 0xFF },    
+-	{ 0x00, 0x51, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0x80, 0x6C, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 640, 480,         /* 640x480 */
+-	  31,               /* 31.5 MHz clock = 75 Hz refresh rate */
+-	  0xE3,             /* miscOutput register */
+-	{ 0x64, 0x4F, 0x4F, 0x88, 0x54, 0x9B, 0xF2, 0x1F, /* standard CRTC */ 
+-	  0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0xE1, 0x04, 0xDF, 0x50, 0x00, 0xDF, 0xF3, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0xA0, 0x3F, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-  	{ 800, 600,         /* 800x600 */
+-	  99,               /* 99 MHz clock = 75 Hz refresh rate */
+-	  0x23,             /* miscOutput register */
+-	{ 0x7F, 0x63, 0x63, 0x83, 0x68, 0x11, 0x6F, 0xF0, /* standard CRTC */ 
+-	  0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x59, 0x1C, 0x57, 0x64, 0x00, 0x57, 0x70, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0xA0, 0x63, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 1024, 768,        /* 1024x768 */
+-	  79,               /* 79 MHz clock = 75 Hz refresh rate */
+-	  0xE3,             /* miscOutput register */
+-	{ 0x9F, 0x7F, 0x7F, 0x83, 0x84, 0x8F, 0x1E, 0xF5, /* standard CRTC */ 
+-	  0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x01, 0x04, 0xFF, 0x80, 0x00, 0xFF, 0x1F, 0xE3, 0xFF },    
+-	{ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0x80, 0x4F, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-	{ 1280, 1024,       /* 1280x1024 */
+-	  135,              /* 135 MHz clock = 75 Hz refresh rate */
+-	  0x23,             /* miscOutput register */
+-	{ 0xCE, 0x9F, 0x9F, 0x92, 0xA4, 0x15, 0x28, 0x52, /* standard CRTC */ 
+-	  0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+-	  0x01, 0x04, 0xFF, 0xA0, 0x00, 0x00, 0x29, 0xE3, 0xFF },    
+-	{ 0x00, 0x51, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, /* extended CRTC */
+-	  0x00, 0x00, 0x01, 0x03, 0x80, 0x87, 0x00, 0x00 } },
+-/*------------------------------------------------------------------------------*/
+-};
+-
+-#define NUM_CYRIX_MODES sizeof(CYRIXmodes)/sizeof(vgaCYRIXmode)
+-
+ static char *
+ CYRIXIdent(n)
+ int n;
+@@ -478,6 +400,7 @@
+ 	vga256InfoRec.bankedMono = TRUE;
+ 	OFLG_SET(CLOCK_OPTION_PROGRAMABLE, &vga256InfoRec.clockOptions);
+ 
++#ifndef MONOVGA
+ 	/* define option set valid for the driver */
+ 	OFLG_SET(OPTION_SW_CURSOR, &CYRIX.ChipOptionFlags);
+ 	OFLG_SET(OPTION_HW_CURSOR, &CYRIX.ChipOptionFlags);
+@@ -496,12 +419,13 @@
+ 	CYRIX.ChipLinearSize  = (1024 * vga256InfoRec.videoRam);
+ 
+ 	CYRIX.ChipUseLinearAddressing = TRUE;
++#endif
+ 
+ 	/* map the entire area from GX_BASE (scratchpad area)
+ 	   up to the end of the control registers */
+ 	GXregisters = (char*)xf86MapVidMem(vga256InfoRec.scrnIndex,
+ 				    EXTENDED_REGION,
+-				    (void*)physbase, 0x20000);
++				    (void*)physbase, 0x9000);
+ 
+ 	if (!GXregisters)
+ 	{	ErrorF("%s %s: Cannot map hardware registers\n",
+@@ -509,80 +433,27 @@
+ 		goto probeFailed;
+ 	}
+ 
+-	/* check VSA version */
+-	/* VSA2 contains a "CX" signature at registers 0x35 and 0x36. */
+-	/* The SoftVGA interface changed slightly for VSA2.  Originally, */
+-	/* VSA2 was intended for MXi only, but it may someday be */
+-	/* provided for MediaGX systems as well. */
+-
+-	CYRIXvsaversion = CYRIX_VSA2;
+-	outb(vgaIOBase + 4, 0x35);
+-	if (inb(vgaIOBase + 5) != 'C') CYRIXvsaversion = CYRIX_VSA1;
+-	outb(vgaIOBase + 4, 0x36);
+-	if (inb(vgaIOBase + 5) != 'X') CYRIXvsaversion = CYRIX_VSA1;
+-	if (CYRIXvsaversion == CYRIX_VSA1)
+-	{
+-		ErrorF("%s %s: VSA1 detected\n", 
+-			XCONFIG_PROBED, vga256InfoRec.name);
+-	}
+-	else
+-	{
+-		ErrorF("%s %s: VSA2 detected\n", 
+-			XCONFIG_PROBED, vga256InfoRec.name);
+-	}
+ 	return(TRUE);
+ }
+ 
+-/*------------------------------------------------------------------------*\
+-** FbInit()
+-** 
+-** From README file: "The FbInit() function is required for drivers with
+-** accelerated graphics support.  It is used to replace default cfb.banked
+-** functions with accelerated chip-specific versions.
+-**
+-** For the Cyrix driver, this routine is also used to allocate video 
+-** memory.  This is more complicated than it needs to be...
+-**
+-** For VSA1, SoftVGA manages all of graphics memory, including the 
+-** compression buffer, cursor buffer, and offscreen memory.  The driver 
+-** should not allocate memory itself.  For offscreen memory it reads 
+-** registers 0x3C and 0x3D.  For the cursor buffer it reads the hardware 
+-** register after validating a mode.  For compression, it just sets bit 0
+-** of register 0x49 if it wants to use compression, and SoftVGA will 
+-** enable it if memory has been allocated.
+-**
+-** This model, however, breaks down for this driver.  There is a bug in 
+-** SoftVGA that keeps the 0x3C register from working properly.  This bug
+-** also prevents compression from being enabled when using a virtual 
+-** desktop.  This driver also cannot use the memory past 2 Meg, which 
+-** effects the memory calculation. 
+-**
+-** Therefore, this driver does what it is not supposed to and allocates
+-** video memory itself.  But, this is required due to bugs in SoftVGA and,
+-** as it turns out, works out fine (with limiting compression use).
+-**
+-** For VSA2, the driver is supposed to do this allocation itself.
+-\*------------------------------------------------------------------------*/
+ 
++#ifndef MONOVGA
+ static void
+ CYRIXFbInit()
+ {	int lineDelta    = vga256InfoRec.displayWidth * (vgaBitsPerPixel / 8);
+ 	int virtualDelta = vga256InfoRec.virtualX * (vgaBitsPerPixel / 8);
+-	int base;
+ 
+ 	vgaSetScreenInitHook(CYRIXScreenInit);
+ 
+-	/* always put the cursor at the end of video memory. */
+-
+-	CYRIXcursorAddress = CYRIX.ChipLinearSize - 256;
+-
+ 	/* offscreen memory is, normally, right after the frame buffer;
++	   always put the cursor at the end of video memory.
++	   
+ 	   (It would be nice to use the ignored 64KB block at the end of
+ 	   the video memory (2112 - 2048) for the hardware cursor, but
+ 	   it is not mapped.  This will not be a problem in Xfree 3.9 */
+-
+ 	CYRIXoffscreenAddress = (lineDelta * vga256InfoRec.virtualY);
+-	CYRIXoffscreenSize = CYRIXcursorAddress - CYRIXoffscreenAddress;
++	CYRIXcursorAddress    = CYRIX.ChipLinearSize - 256;
++	CYRIXoffscreenSize    = CYRIXcursorAddress - CYRIXoffscreenAddress;
+ 
+ 	/* if there is enough room between lines, put the compression
+ 	   buffer there */
+@@ -591,7 +462,7 @@
+ 		CYRIXcbLineDelta    = (lineDelta >> 2);
+ 		if (xf86Verbose > 1)
+ 			ErrorF("%s %s: Interleaving frame buffer and compression buffer\n",
+-				   XCONFIG_PROBED, vga256InfoRec.name);
++			       XCONFIG_PROBED, vga256InfoRec.name);
+ 	}
+ 	/* otherwise, put it directly after the virtual frame */
+ 	else
+@@ -600,7 +471,7 @@
+ 		if (cbuffer_size > CYRIXoffscreenSize)
+ 		{	CYRIXcbLineDelta  =  0;
+ 			ErrorF("%s %s: No room for the compression buffer\n",
+-				   XCONFIG_PROBED, vga256InfoRec.name);
++			       XCONFIG_PROBED, vga256InfoRec.name);
+ 		}
+ 		else
+ 		{	CYRIXcbufferAddress    = CYRIXoffscreenAddress;
+@@ -609,43 +480,25 @@
+ 			CYRIXoffscreenSize    -= cbuffer_size;
+ 	}	}
+ 
+-	/* print results of offscreen memory configuration */
+-
+-	if (CYRIXoffscreenSize <= 0)
+-	{
+-		ErrorF("%s %s: No offscreen memory available.\n", 
+-			XCONFIG_PROBED, vga256InfoRec.name);
+-	}
+-	else
+-	{
+-		ErrorF("%s %s: Offscreen memory from 0x%8.8X-0x%8.8X\n",
+-			XCONFIG_PROBED, vga256InfoRec.name, 
+-			CYRIXoffscreenAddress, 
+-			CYRIXoffscreenAddress+CYRIXoffscreenSize-1);
+-	}
+-
+-    /* call CYRIXAccelInit to setup the XAA accelerated functions */
+-
++        /* call CYRIXAccelInit to setup the XAA accelerated functions */
+ 	if (!OFLG_ISSET(OPTION_NOACCEL, &vga256InfoRec.options))
+ 		CYRIXAccelInit();
+ 
+ 	/* install hardware cursor routines */
+-
+ 	if (OFLG_ISSET(OPTION_HW_CURSOR, &vga256InfoRec.options))
+-	{	if (CYRIXoffscreenSize > 0)
++	{	if (CYRIXoffscreenSize >= 0)
+ 		{	vgaHWCursor.Initialized = TRUE;
+ 			vgaHWCursor.Init = CYRIXCursorInit;
+ 			vgaHWCursor.Restore = CYRIXRestoreCursor;
+ 			vgaHWCursor.Warp = CYRIXWarpCursor;
+ 			vgaHWCursor.QueryBestSize = CYRIXQueryBestSize;
+-			ErrorF("%s %s: Using hardware cursor at %8.8X\n",
+-				XCONFIG_PROBED, vga256InfoRec.name, CYRIXcursorAddress);
++			if (xf86Verbose)
++		           ErrorF("%s %s: Using hardware cursor\n",
++		                  XCONFIG_PROBED, vga256InfoRec.name);
+ 		}
+ 		else
+-		{
+ 			ErrorF("%s %s: No room for hardware cursor\n",
+-				XCONFIG_PROBED, vga256InfoRec.name);
+-		}
++		               XCONFIG_PROBED, vga256InfoRec.name);
+ 	}
+ }
+ 
+@@ -696,6 +549,7 @@
+ 
+ 	return pitch;
+ }
++#endif /* not MONOVGA */
+ 
+ 
+ static void
+@@ -747,121 +601,210 @@
+ 
+ static void
+ CYRIXresetVGA()
+-{
+-	int i;
++{	unsigned char temp;
++	/* switch off compression and cursor the hard way */
++	GX_REG(DC_UNLOCK)  = DC_UNLOCK_VALUE;
++	GX_REG(DC_GENERAL_CFG) &= ~(DC_GCFG_CMPE | DC_GCFG_DECE | DC_GCFG_FDTY | DC_GCFG_CURE);
++	GX_REG(DC_UNLOCK)  = 0;
++	CYRIXmarkLinesDirty();
+ 
+ 	/* reset SoftVGA extensions to standard VGA behaviour */
+-
+-	for (i = 0; i < NUM_EXT_CRTC_REGS; i++)
+-	{
+-		outb(vgaIOBase + 4, 0x40 + i);
+-		outb(vgaIOBase + 5, 0x00);
+-	}
++	outb(vgaIOBase + 4, CrtcExtendedAddressControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, temp & 0xf8);
++	outb(vgaIOBase + 4, CrtcExtendedStartAddress);
++	outb(vgaIOBase + 5, 0x00);
++	outb(vgaIOBase + 4, CrtcWriteMemoryAperture);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, temp & 0xe0);
++	outb(vgaIOBase + 4, CrtcReadMemoryAperture);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, temp & 0xe0);
++	outb(vgaIOBase + 4, CrtcDriverControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, temp & 0xfe);
++	outb(vgaIOBase + 4, CrtcDisplayCompression);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, temp & 0xf0);
+ }
+ 
+ static void
+ CYRIXRestore(restore)
+ vgaCYRIXPtr restore;
+-{	unsigned char i, temp, temp2;
+-	unsigned long value;
+-
+-	/* unlock extended CRTC registers */
+-
+-	outb(vgaIOBase + 4, 0x30);
+-	outb(vgaIOBase + 5, 0x57);
+-	outb(vgaIOBase + 5, 0x4C);
++{	unsigned char temp;
++	vgaProtect(TRUE);		/* Blank the screen */
+ 
+-	/* SIGNAL THE BEGINNING OF THE MODE SWITCH 
+-       SoftVGA will hold off validating the back end hardware. */
+-
+-	outb(vgaIOBase + 4, CrtcModeSwitchControl);
+-	outb(vgaIOBase + 5, 0x01);
++	/* it would be ideal to be able to use the ModeSwitchControl
++	   register to protect SoftVGA from reading the configuration
++	   before all registers have been written.  But that bit must be
++	   set somewhere in the middle of vgaHWRestore (after restoring
++	   the font). Luckily things seem to work without it. */
+ 
+ 	/* restore standard VGA portion */
+-
+ 	CYRIXresetVGA();
+ 	vgaHWRestore((vgaHWPtr)restore);
++	CYRIXmarkLinesDirty();
+ 
+-	/* override restored miscellaneous output regiter value */
+-	
+-	outb(0x3C2, restore->ext.miscOutput);
+-
+-	/* override restored standard CRTC register values */
+-
+-	outb(vgaIOBase + 4, 0x11); 
+-	outb(vgaIOBase + 5, 0x00);
+-	for (i = 0; i < NUM_STD_CRTC_REGS; i++)
+-	{
+-		outb(vgaIOBase + 4, i);
+-		outb(vgaIOBase + 5, restore->ext.stdCRTCregs[i]);
+-	}
+-	
+ 	/* restore SoftVGA extended registers */
++	outb(vgaIOBase + 4, CrtcDriverControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.DriverControl & 0x01)
++	                  | (temp & 0xfe));
++
++	outb(vgaIOBase + 4, CrtcVerticalTimingExtension);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.VerticalTimingExtension & 0x55)
++	                  | (temp & 0xaa));
++
++	outb(vgaIOBase + 4, CrtcExtendedAddressControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.ExtendedAddressControl & 0x07)
++	                  | (temp & 0xf8));
++
++	outb(vgaIOBase + 4, CrtcExtendedOffset);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.ExtendedOffset & 0x03)
++	                  | (temp & 0xfc));
++
++	outb(vgaIOBase + 4, CrtcExtendedColorControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.ExtendedColorControl & 0x07)
++	                  | (temp & 0xf8));
++
++	outb(vgaIOBase + 4, CrtcDisplayCompression);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.DisplayCompression & 0x0f)
++	                  | (temp & 0xf0));
++
++	outb(vgaIOBase + 4, CrtcDACControl);
++	temp = inb(vgaIOBase + 5);
++	outb(vgaIOBase + 5, (restore->ext.DACControl & 0x0e)
++	                  | (temp & 0xf1));
++
++	if (restore->std.NoClock >= 0)
++	{	outb(vgaIOBase + 4, CrtcClockControl);
++		temp = inb(vgaIOBase + 5);
++		outb(vgaIOBase + 5, (restore->ext.ClockControl & 0xb0)
++		                  | (temp & 0x4f));
++
++		outb(vgaIOBase + 4, CrtcClockFrequency);
++		outb(vgaIOBase + 5, restore->ext.CrtClockFrequency);
++
++		outb(vgaIOBase + 4, CrtcClockFrequencyFraction);
++		outb(vgaIOBase + 5, restore->ext.CrtClockFrequencyFraction);
++
++		outb(vgaIOBase + 4, CrtcRefreshRate);
++		outb(vgaIOBase + 5, restore->ext.RefreshRate);
++	}
++
++	/* let SoftVGA programming settle before we access DC registers,
++	   but don't wait too long */
++	usleep(1000);
++	CYRIXmarkLinesDirty();
++
++	/* restore display controller hardware registers */
++#ifndef MONOVGA
++#define DCFG_MASK       (DC_GCFG_FDTY | DC_GCFG_DECE | DC_GCFG_CMPE)
++#define GPBS_MASK       (BC_16BPP | BC_FB_WIDTH_2048)
+ 
+-	for (i = 0; i < NUM_EXT_CRTC_REGS; i++)
+-	{
+-		outb(vgaIOBase + 4, 0x40+i);
+-		outb(vgaIOBase + 5, restore->ext.extCRTCregs[i]);
+-	}
++	GX_REG(DC_UNLOCK) = DC_UNLOCK_VALUE;
+ 
+-	/* signal the end of the mode switch */
++	GX_REG(DC_CURS_ST_OFFSET) = restore->ext.DcCursStOffset;
++	GX_REG(DC_CB_ST_OFFSET)  = restore->ext.DcCbStOffset;
++	GX_REG(DC_LINE_DELTA)    = (GX_REG(DC_LINE_DELTA) & 0xFFC00FFF)
++	                         | (restore->ext.DcLineDelta & 0x003FF000);
++	GX_REG(DC_BUF_SIZE)      = (GX_REG(DC_BUF_SIZE) & 0xFFFF01FF)
++                                 | (restore->ext.DcBufSize & 0x0000FE00);
++	GX_REG(DC_CURSOR_X)      = restore->ext.DcCursorX;
++	GX_REG(DC_CURSOR_Y)      = restore->ext.DcCursorY;
++	GX_REG(DC_CURSOR_COLOR)  = restore->ext.DcCursorColor;
+ 
+-	outb(vgaIOBase + 4, CrtcModeSwitchControl);
+-	outb(vgaIOBase + 5, 0x00);
++	GX_REG(DC_GENERAL_CFG)   = (GX_REG(DC_GENERAL_CFG) & (~DCFG_MASK))
++	                         | (restore->ext.DcGeneralCfg & DCFG_MASK);
+ 
+-	/* wait until SoftVGA has validated the mode.
+-	   This is for VSA1 only, where SoftVGA waits until the next
+-	   vertical blank to recalculate the hardware state.  For VSA2
+-	   the hardware us updated immediately, so this is not needed. 
+-	   THIS MUST BE DONE FOR VSA1 before loading the GP_BLT_STATUS
+-	   register, otherwise SoftVGA will override the value. */
++	GX_REG(DC_UNLOCK) = 0;
+ 
+-	if (CYRIXvsaversion == CYRIX_VSA1)
+-	{
+-		outb(vgaIOBase + 4, 0x33); 
+-		while(inb(vgaIOBase + 5) & 0x80); 
+-	}
++	GX_REG(GP_BLIT_STATUS)   = (GX_REG(GP_BLIT_STATUS) & (~GPBS_MASK))
++	                         | (restore->ext.GpBlitStatus & GPBS_MASK);
+ 
+-	/* overrite what SoftVGA may have stored into GP_BLIT_STATUS */
++	/* restore cursor pattern */
++	if (restore->ext.DcCursStOffset < 1024 * vga256InfoRec.videoRam)
++		memcpy((char*)vgaLinearBase + restore->ext.DcCursStOffset,
++		       restore->ext.cursorPattern, 256);
++#endif
+ 
+-	GX_REG(GP_BLIT_STATUS) = restore->ext.GpBlitStatus;
++	vgaProtect(FALSE);		/* Turn on screen */
+ }
+ 
+ static void *
+ CYRIXSave(save)
+ vgaCYRIXPtr save;
+-{	unsigned char i;
+-	struct vgaCYRIXext ext;
++{	struct vgaCYRIXext ext;
+ 
+-	/* save miscellaneous output register */
++#ifndef MONOVGA
++	/* save graphics pipeline registers */
++	ext.GpBlitStatus   = GX_REG(GP_BLIT_STATUS);
+ 
+-	ext.miscOutput = inb(0x3CC);
++	/* save display controller hardware registers */
++	GX_REG(DC_UNLOCK)  = DC_UNLOCK_VALUE;
++	ext.DcGeneralCfg   = GX_REG(DC_GENERAL_CFG);
++	ext.DcCursStOffset = GX_REG(DC_CURS_ST_OFFSET);
++	ext.DcCbStOffset   = GX_REG(DC_CB_ST_OFFSET);
++	ext.DcLineDelta    = GX_REG(DC_LINE_DELTA);
++	ext.DcBufSize      = GX_REG(DC_BUF_SIZE);
++	ext.DcCursorX      = GX_REG(DC_CURSOR_X);
++	ext.DcCursorY      = GX_REG(DC_CURSOR_Y);
++	ext.DcCursorColor  = GX_REG(DC_CURSOR_COLOR);
++	GX_REG(DC_UNLOCK)  = 0;
++
++	/* save cursor pattern.
++	   In the 3.3.1 solution, we don't need to do this
++	   if it is in the extra 64KB block of frame buffer memory
++	   that we ignore (and is not mapped anyway) */
++	if (ext.DcCursStOffset < 1024 * vga256InfoRec.videoRam)
++		memcpy(ext.cursorPattern,
++		       (char*)vgaLinearBase + ext.DcCursStOffset, 256);
++#endif
+ 
+-	/* save standard CRTC registers */
++	/* save SoftVGA extended registers */
++	outb(vgaIOBase + 4, CrtcVerticalTimingExtension);
++	ext.VerticalTimingExtension = inb(vgaIOBase + 5);
+ 
+-	for (i = 0; i < NUM_STD_CRTC_REGS; i++)
+-	{
+-		outb(vgaIOBase + 4, i);
+-		ext.stdCRTCregs[i] = inb(vgaIOBase + 5);
+-	}
++	outb(vgaIOBase + 4, CrtcExtendedAddressControl);
++	ext.ExtendedAddressControl = inb(vgaIOBase + 5);
+ 
+-	/* save extended CRTC registers */
++	outb(vgaIOBase + 4, CrtcExtendedOffset);
++	ext.ExtendedOffset = inb(vgaIOBase + 5);
+ 
+-	for (i = 0; i < NUM_EXT_CRTC_REGS; i++)
+-	{
+-		outb(vgaIOBase + 4, 0x40+i);
+-		ext.extCRTCregs[i] = inb(vgaIOBase + 5);
+-	}
++	outb(vgaIOBase + 4, CrtcExtendedColorControl);
++	ext.ExtendedColorControl = inb(vgaIOBase + 5);
+ 
+-	/* save graphics pipeline registers */
++	outb(vgaIOBase + 4, CrtcDisplayCompression);
++	ext.DisplayCompression = inb(vgaIOBase + 5);
+ 
+-	ext.GpBlitStatus   = GX_REG(GP_BLIT_STATUS);
++	outb(vgaIOBase + 4, CrtcDriverControl);
++	ext.DriverControl = inb(vgaIOBase + 5);
+ 
+-	/* save standard VGA portion */
++	outb(vgaIOBase + 4, CrtcDACControl);
++	ext.DACControl = inb(vgaIOBase + 5);
++
++	outb(vgaIOBase + 4, CrtcClockControl);
++	ext.ClockControl = inb(vgaIOBase + 5);
++
++	outb(vgaIOBase + 4, CrtcClockFrequency);
++	ext.CrtClockFrequency = inb(vgaIOBase + 5);
+ 
++	outb(vgaIOBase + 4, CrtcClockFrequencyFraction);
++	ext.CrtClockFrequencyFraction = inb(vgaIOBase + 5);
++
++	outb(vgaIOBase + 4, CrtcRefreshRate);
++	ext.RefreshRate = inb(vgaIOBase + 5);
++
++	/* save standard VGA portion */
+ 	CYRIXresetVGA();
+ 	save = (vgaCYRIXPtr)vgaHWSave((vgaHWPtr)save, sizeof(vgaCYRIXRec));
+ 	save->ext = ext;
++
+ 	return ((void *) save);
+ }
+ 
+@@ -869,108 +812,101 @@
+ static Bool
+ CYRIXInit(mode)
+ DisplayModePtr mode;
+-{	int i, mode_index;
+-	int clock = vga256InfoRec.clock[mode->Clock] / 1000;
+-	int min, diff;
+-	int offset_shift = (vgaBitsPerPixel == 16) ? 2 :
++{	int offset_shift = (vgaBitsPerPixel == 16) ? 2 :
+                            (vgaBitsPerPixel == 8) ? 3 : 4;
+ 	int line_offset = vga256InfoRec.displayWidth >> offset_shift;
+ 
+ 	/* initialize standard VGA portion */
+-
+ 	if (!vgaHWInit(mode,sizeof(vgaCYRIXRec)))
+ 		return(FALSE);
+ 
+-	/* search for specified mode in the table */
+-    /* Need to find the entry with the closest dot clock value */ 
+-	/* Assume within at least 200 MHz and then maintain closest natch. */
+-
+-	mode_index = 0;
+-	min = 200; 
+-	for (i = 0; i < NUM_CYRIX_MODES; i++)
+-	{
+-		diff = clock - CYRIXmodes[i].clock;
+-		if (diff < 0) diff = -diff;
+-		if ((mode->CrtcHDisplay == CYRIXmodes[i].xsize) &&
+-			(mode->CrtcVDisplay == CYRIXmodes[i].ysize) &&
+-			(diff < min))
+-		{
+-			mode_index = i;
+-			min = diff;
+-		}
+-	}
+-
+-	/* override standard miscOutput register value */
+-
+-	newstate->ext.miscOutput = CYRIXmodes[mode_index].miscOutput;
++	newstate->std.CRTC[19] = line_offset;
+ 
+-	/* override standard CRTC register values */
++	/* initialize SoftVGA extended registers */
++	newstate->ext.VerticalTimingExtension =
++		((mode->CrtcVSyncStart & 0x400) >> 4) |
++		(((mode->CrtcVDisplay - 1) & 0x400) >> 8) |
++		(((mode->CrtcVTotal - 2) & 0x400) >> 10) |
++		((mode->CrtcVSyncStart & 0x400) >> 6);
+ 
+-	for (i = 0; i < NUM_STD_CRTC_REGS; i++)
+-	{
+-		newstate->ext.stdCRTCregs[i] = 
+-			CYRIXmodes[mode_index].stdCRTCregs[i];
+-	}
+-
+-	/* set extended CRTC registers */
+-
+-	for (i = 0; i < NUM_EXT_CRTC_REGS; i++)
+-	{
+-		newstate->ext.extCRTCregs[i] = 
+-			CYRIXmodes[mode_index].extCRTCregs[i];
+-	}
+-
+-	/* override pitch from the mode tables */
+-	/* (same tables are used for 8BPP and 16BPP) */
++	if (vgaBitsPerPixel < 8)
++		newstate->ext.ExtendedAddressControl = EAC_DIRECT_FRAME_BUFFER;
++	else
++		newstate->ext.ExtendedAddressControl = EAC_DIRECT_FRAME_BUFFER |
++		                                       EAC_PACKED_CHAIN4;
+ 
+-	newstate->ext.stdCRTCregs[19] = line_offset;
+-	newstate->ext.extCRTCregs[5] = ((line_offset >> 8) & 0x03);
++	newstate->ext.ExtendedOffset = ((line_offset >> 8) & 0x03);
+ 
+-	/* override color control from the mode tables */
+-	/* (same tables are used for 8BPP and 16BPP) */
++	newstate->ext.ExtendedColorControl = (vgaBitsPerPixel == 16)
++                                           ? ECC_16BPP | ECC_565_FORMAT
++                                           : ECC_8BPP;
++
++	/* display compression is set using the DC registers */
++	newstate->ext.DisplayCompression = 0x00;
++
++	/* we drive the palette through the display controller (in new
++	   chipsets only) in 8bpp and 16bpp (that is, whenever the
++	   hardware cursor is used). */
++	if (vgaBitsPerPixel < 8)
++		newstate->ext.DriverControl = 0x00;
++	else
++		newstate->ext.DriverControl = DRVCT_DISPLAY_DRIVER_ACTIVE;
+ 
+-	newstate->ext.extCRTCregs[6] = (vgaBitsPerPixel == 16)
+-		? ECC_16BPP | ECC_565_FORMAT : ECC_8BPP;
++	/* set `16 bit bus' or else compression will hang the
++	   system in 16bpp mode */
++	if (vgaBitsPerPixel == 16)
++		newstate->ext.DACControl = DACCT_ENABLE_16BIT_BUS;
++	else
++		newstate->ext.DACControl = 0;
+ 
+-	/* enable display compression when appropriate */
+ 
+-	if (CYRIXvsaversion == CYRIX_VSA1)
+-	{
+-		/* For VSA1, SoftVGA manages the compression buffer. */
+-		/* Enabling compression directly causes unpredictable results. */
+-		/* Only enable if not panning (there is a bug in SoftVGA that */
+-		/* will put the compression buffer in the wrong place when */
+-		/* using a virtual desktop. */
+-		/* By setting bit 0 of register 0x49, SoftVGA will enable */
+-		/* compression whenever possible, based on memory available */
+-		/* and starting address of memory. */
+-
+-	    if ((mode->CrtcVDisplay == vga256InfoRec.virtualY) &&
+-			(mode->CrtcHDisplay == vga256InfoRec.virtualX))
+-		{
+-			newstate->ext.extCRTCregs[9] = 0x01;
+-			ErrorF("%s %s: Display compression enabled.\n", 
+-				XCONFIG_PROBED, vga256InfoRec.name);
+-		}
+-		else
+-		{
+-			ErrorF("%s %s: Display compression disabled.\n", 
+-				XCONFIG_PROBED, vga256InfoRec.name);
+-		}
++	if (newstate->std.NoClock >= 0)
++	{	int entier_clock   = (vga256InfoRec.clock[mode->Clock] / 1000);
++		int clock_fraction = (vga256InfoRec.clock[mode->Clock] / 100)
++				   - (entier_clock * 10);
++
++		newstate->ext.ClockControl = CLKCT_EXT_CLOCK_MODE;
++		newstate->ext.CrtClockFrequency = entier_clock;
++		newstate->ext.CrtClockFrequencyFraction = clock_fraction;
++		newstate->ext.RefreshRate = 0 /* relevant to VGA BIOS only */;
++	}
++
++#ifndef MONOVGA
++	/* initialize masked contents of display controller
++	   hardware registers. */
++	newstate->ext.DcCursStOffset =  CYRIXcursorAddress;
++	newstate->ext.DcCbStOffset  =  CYRIXcbufferAddress;
++	newstate->ext.DcLineDelta   =  CYRIXcbLineDelta << 12;
++	newstate->ext.DcBufSize     =  0x41 << 9;
++	newstate->ext.DcCursorX     =  0;
++	newstate->ext.DcCursorY     =  0;
++	newstate->ext.DcCursorColor =  0;
++
++	/* Compression  is enabled only  when a buffer  was allocated by
++	   FbInit  and provided that the displayed screen is the virtual
++	   screen.  If the line delta is not 1024 or 2048, entire frames
++	   will be flagged dirty as opposed to lines.  Problems with 16bpp
++	   and line-dirty flagging seem to have been solved now.  */
++	if (CYRIXcbLineDelta != 0 &&
++	    mode->CrtcVDisplay == vga256InfoRec.virtualY &&
++	    mode->CrtcHDisplay == vga256InfoRec.virtualX)
++	{	newstate->ext.DcGeneralCfg = DC_GCFG_DECE
++		                           | DC_GCFG_CMPE;
++		if (/* vgaBitsPerPixel != 8 ||   -- this is OK now */
++		   (vga256InfoRec.displayWidth * (vgaBitsPerPixel / 8)) & 0x03FF)
++			newstate->ext.DcGeneralCfg |= DC_GCFG_FDTY;
+ 	}
+ 	else
+-	{
+-		/* ### TO DO ### */
+-		/* Enable display compression directly for VSA2. */
+-		/* For VSA2, the display driver manages all graphics memory. */
+-	}
++		newstate->ext.DcGeneralCfg = 0;
+ 
+-	/* initialize the graphics pipeline registers */
+ 
++	/* initialize the graphics pipeline registers */
+ 	newstate->ext.GpBlitStatus  =  ((vga256InfoRec.displayWidth == 2048) ?
+ 	                                BC_FB_WIDTH_2048 : BC_FB_WIDTH_1024) |
+ 	                               ((vgaBitsPerPixel == 16) ?
+ 	                                BC_16BPP : BC_8BPP);
++#endif
++
+ 	return(TRUE);
+ }
+ 
+@@ -978,68 +914,31 @@
+ CYRIXAdjust(x, y)
+ int x, y;
+ {	int Base = (y * vga256InfoRec.displayWidth + x);
+-	unsigned long active, sync, count1, count2;
+ 
+ 	if (vgaBitsPerPixel > 8) Base *= (vgaBitsPerPixel / 8);
+ 	if (vgaBitsPerPixel < 8) Base /= 2;
+ 
+-	/* wait until out of active display area */
+-
+-	active = GX_REG(DC_V_TIMING_1) & 0x07FF;	
+-	sync = GX_REG(DC_V_TIMING_3) & 0x07FF;
+-
+-	do
+-	{
+-		/* read twice to avoid transition values */
+-
+-		count1 = GX_REG(DC_V_LINE_CNT) & 0x07FF;
+-		count2 = GX_REG(DC_V_LINE_CNT) & 0x07FF;
+-	} while ((count1 != count2) || (count1 < active) || (count1 >= sync));
+-
+-	/* load the start address directly */
+-
++	/* doing this using the SoftVGA registers does not work reliably */
+ 	GX_REG(DC_UNLOCK) = DC_UNLOCK_VALUE;
+ 	GX_REG(DC_FB_ST_OFFSET) = Base;
+ 	GX_REG(DC_UNLOCK) = 0;
+ }
+ 
+-/*------------------------------------------------------------------------*\
+-** ValidMode()
+-** 
+-** From README file: "The ValidMode() function is required.  It is used to 
+-** check for any chipset dependent reasons why a graphics mode might not be
+-** valid.  It gets called by higher levels of the code after the Probe()
+-** stage.  In many cases no special checking will be required and this 
+-** function will simply return TRUE always."
+-**
+-** For the Cyrix driver, this routine loops through modes provided in a 
+-** table at the beginning of this file and returns OK if it finds a match.
+-** These tables were required to make the standard VESA 60 Hz and 75 Hz 
+-** modes work correctly.  Doing this, however, takes away the flexibility 
+-** of adding different resolutions or different refresh rates to the 
+-** XF86Config file.
+-\*------------------------------------------------------------------------*/
+-
+ static int
+ CYRIXValidMode(mode, verbose, flag)
+ DisplayModePtr mode;
+ Bool verbose;
+ int flag;
+-{
+-	int i;
+-
+-	/* loop through table of modes */
+-
+-	for (i = 0; i < NUM_CYRIX_MODES; i++)
+-	{
+-		if ((mode->CrtcHDisplay == CYRIXmodes[i].xsize) &&
+-			(mode->CrtcVDisplay == CYRIXmodes[i].ysize))
+-		{
+-			return MODE_OK;
+-		}
++{	/* note (avg): there seems to be a lot more to this if you look
++	   at the GGI code (adjustment). */
++	if (mode->CrtcHSyncStart - mode->CrtcHDisplay >= 24 ||
++            mode->CrtcHSyncStart - mode->CrtcHDisplay <= 8)
++	{	if (verbose)
++			ErrorF("%s %s: mode %s: horizontal sync out of range (sync - display should be between 8 and 24)\n",
++				XCONFIG_PROBED, vga256InfoRec.name, mode->name
++				);
++		return MODE_HSYNC;
+ 	}
+-	return MODE_BAD;
++	return(MODE_OK);
+ }
+-
+-/* END OF FILE */
+ 
+diff -urN xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/gxrender.c xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/gxrender.c
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix~/gxrender.c	Thu Jun 24 00:59:41 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/gxrender.c	Wed Dec 31 19:00:00 1969
+@@ -1,1237 +0,0 @@
+-/* $XFree86: xc/programs/Xserver/hw/xfree86/vga256/drivers/cyrix/gxrender.c,v 1.1.2.1 1999/06/24 05:59:41 hohndel Exp $ */
+-/*
+-//---------------------------------------------------------------------------
+-// gxrender.c
+-//
+-// This file gives examples of using the MediaGX graphics unit to provide
+-// acceleration for 2D display drivers.  It is intended to provide an 
+-// absraction layer for new display driver development.  This code handles
+-// the quirks of the MediaGX graphics unit to allow faster developemt times
+-// for new drivers.
+-//---------------------------------------------------------------------------
+-*/
+-
+-/* GRAPHICS PIPELINE REGISTER DEFINITIONS */
+-
+-#define GP_DST_XCOOR		0x8100		/* x destination origin	*/
+-#define GP_DST_YCOOR		0x8102		/* y destination origin	*/
+-#define GP_WIDTH			0x8104		/* pixel width */
+-#define GP_HEIGHT			0x8106		/* pixel height */
+-#define GP_SRC_XCOOR		0x8108		/* x source origin */
+-#define GP_SRC_YCOOR		0x810A		/* y source origin */
+-
+-#define GP_VECTOR_LENGTH	0x8104		/* vector length */
+-#define GP_INIT_ERROR		0x8106		/* vector initial error	*/
+-#define GP_AXIAL_ERROR		0x8108		/* axial error increment */
+-#define GP_DIAG_ERROR		0x810A		/* diagonal error increment */
+-
+-#define GP_SRC_COLOR_0		0x810C		/* source color 0 */
+-#define GP_SRC_COLOR_1		0x810E		/* source color 1 */
+-#define GP_PAT_COLOR_0		0x8110		/* pattern color 0 */
+-#define GP_PAT_COLOR_1		0x8112		/* pattern color 1 */
+-#define GP_PAT_COLOR_2		0x8114		/* pattern color 2 */
+-#define GP_PAT_COLOR_3		0x8116		/* pattern color 3 */
+-#define GP_PAT_DATA_0		0x8120		/* bits 31:0 of pattern	*/
+-#define GP_PAT_DATA_1		0x8124		/* bits 63:32 of pattern */
+-#define GP_PAT_DATA_2		0x8128		/* bits 95:64 of pattern */
+-#define GP_PAT_DATA_3		0x812C		/* bits 127:96 of pattern */
+-
+-#define GP_RASTER_MODE		0x8200		/* raster operation */
+-#define GP_VECTOR_MODE		0x8204		/* vector mode register	*/
+-#define GP_BLIT_MODE		0x8208		/* blit mode register */
+-#define GP_BLIT_STATUS		0x820C		/* blit status register	*/
+-
+-/* "GP_VECTOR_MODE" BIT DEFINITIONS */
+-
+-#define VM_X_MAJOR			0x0000		/* X major vector */
+-#define VM_Y_MAJOR			0x0001		/* Y major vector */
+-#define VM_MAJOR_INC		0x0002		/* positive major axis step */
+-#define VM_MINOR_INC		0x0004		/* positive minor axis step */
+-#define VM_READ_DST_FB		0x0008		/* read destination data */
+-
+-/* "GP_RASTER_MODE" BIT DEFINITIONS */
+-
+-#define RM_PAT_DISABLE		0x0000		/* pattern is disabled */
+-#define RM_PAT_MONO			0x0100		/* 1BPP pattern expansion */
+-#define RM_PAT_DITHER		0x0200		/* 2BPP pattern expansion */
+-#define RM_PAT_COLOR		0x0300		/* 8BPP or 16BPP pattern */
+-#define RM_PAT_MASK			0x0300		/* mask for pattern mode */
+-#define RM_PAT_TRANSPARENT	0x0400		/* transparent 1BPP pattern */
+-#define RM_SRC_TRANSPARENT	0x0800		/* transparent 1BPP source */
+-
+-/* "GP_BLIT_STATUS" BIT DEFINITIONS */
+-
+-#define BS_BLIT_BUSY		0x0001		/* blit engine is busy */
+-#define BS_PIPELINE_BUSY	0x0002		/* graphics pipeline is bus */
+-#define BS_BLIT_PENDING		0x0004		/* blit pending	*/
+-#define BC_8BPP				0x0000		/* 8BPP mode */
+-#define BC_16BPP			0x0100		/* 16BPP mode */
+-#define BC_FB_WIDTH_1024	0x0000		/* framebuffer width = 1024 */
+-#define BC_FB_WIDTH_2048	0x0200		/* framebuffer width = 2048 */
+-
+-/* "GP_BLIT_MODE" BIT DEFINITIONS */
+-
+-#define	BM_READ_SRC_NONE	0x0000		/* source foreground color */
+-#define BM_READ_SRC_FB		0x0001		/* read source from FB 	*/
+-#define BM_READ_SRC_BB0		0x0002		/* read source from BB0 */
+-#define BM_READ_SRC_BB1		0x0003		/* read source from BB1	*/
+-#define BM_READ_SRC_MASK	0x0003		/* read source mask */
+-
+-#define	BM_READ_DST_NONE	0x0000		/* no destination data */
+-#define BM_READ_DST_BB0		0x0008		/* destination from BB0	*/
+-#define BM_READ_DST_BB1		0x000C		/* destination from BB1	*/
+-#define BM_READ_DST_FB0		0x0010		/* dest from FB (store BB0) */
+-#define BM_READ_DST_FB1		0x0014		/* dest from FB (store BB1)*/
+-#define BM_READ_DST_MASK	0x001C		/* read destination mask */
+-
+-#define BM_WRITE_FB			0x0000		/* write to framebuffer	*/
+-#define	BM_WRITE_MEM		0x0020		/* write to memory */
+-#define BM_WRITE_MASK		0x0020		/* write mask */
+-
+-#define	BM_SOURCE_COLOR		0x0000		/* source is 8BPP or 16BPP */
+-#define BM_SOURCE_EXPAND	0x0040		/* source is 1BPP */
+-#define BM_SOURCE_TEXT		0x00C0		/* source is 1BPP text */
+-#define BM_SOURCE_MASK		0x00C0		/* source mask */
+-
+-#define BM_REVERSE_Y		0x0100		/* reverse Y direction */
+-
+-/* THE DRIVER NEEDS TO MAINTAIN THE SIZE AND LOCATION OF THE BLT BUFFERS
+-// These constants will work with 2K or 3K config, 8 or 16 BPP.  The driver
+-// should set them, however, to optimize for the current config.  Otherwise
+-// screen to screen BLTs, for example, may be visibly split into two vertical
+-// sections when they do not need to be.
+-*/
+-
+-/* STATIC VARIABLES FOR GXRENDER.C FILE */
+-
+-unsigned char *GXRregptr;
+-unsigned short GXRbpp;
+-unsigned short GXRbb0Base;
+-unsigned short GXRbb1Base;
+-unsigned short GXRbufferWidthPixels;
+-
+-unsigned short GXRpatternFlags;
+-unsigned short GXRsourceFlags;
+-unsigned short GXRsavedColor;
+-unsigned short GXRsavedRop;
+-unsigned short GXRusesDstData;
+-
+-/* MACROS FOR REGISTER ACCESS 
+-// These macros asssume that a pointer was specified during initialization.
+-// They also assume 32-bit access is possible (16-bit access such as for 
+-// Windows 98 display drivers would require different macros).
+-*/
+- 
+-#define WRITE_REG8(offset, value) \
+-	(*(volatile unsigned char *)(GXRregptr + (offset))) = (value)
+-
+-#define WRITE_REG16(offset, value) \
+-	(*(volatile unsigned short *)(GXRregptr + (offset))) = (value)
+-
+-#define WRITE_REG32(offset, value) \
+-	(*(volatile unsigned long *)(GXRregptr + (offset))) = (value)
+-
+-#define READ_REG16(offset) \
+-    (*(volatile unsigned short *)(GXRregptr + (offset)))
+-
+-#define READ_REG32(offset) \
+-    (*(volatile unsigned long *)(GXRregptr + (offset)))
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_INITIALIZE
+-//
+-// This routine initializes the parameters for the current configuration.
+-//
+-//     REGPTR     pointer to GX memory mapped registers
+-//     BPP        bits per pixel (8 pr 16)
+-//     
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_initialize(unsigned char *regptr, unsigned short bpp, 
+-	unsigned short BB0base, unsigned short BB1base, 
+-	unsigned short BBwidthPixels)
+-{
+-	GXRregptr = regptr;
+-	GXRbpp = bpp;
+-	GXRbb0Base = BB0base;
+-	GXRbb1Base = BB1base;
+-	GXRbufferWidthPixels = BBwidthPixels;
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_WAIT_UNTIL_IDLE
+-//
+-// This routine waits until the graphics engine is idle.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_wait_until_idle(void)
+-{
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_BUSY);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_LOAD_SOLID_SOURCE
+-//
+-// This routine is used to specify a solid source color.  For the Xfree96
+-// display driver, the source color is used to specify a planemask and the 
+-// ROP is adjusted accordingly.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_load_solid_source(unsigned short color)
+-{
+-	/* CLEAR TRANSPARENCY FLAG */
+-
+-	GXRsourceFlags = 0;
+-
+-	/* FORMAT 8 BPP COLOR */
+-	/* GX requires 8BPP color data be duplicated into bits [15:8]. */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		color &= 0x00FF;
+-		color |= (color << 8);
+-	}
+-	
+-	/* POLL UNTIL ABLE TO WRITE THE SOURCE COLOR */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_SRC_COLOR_0, color);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_LOAD_MONO_SOURCE
+-//
+-// This routine is used to specify the monochrome source colors.  
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_load_mono_source(unsigned short bgcolor, unsigned short fgcolor,
+-	unsigned short transparent)
+-{
+-	/* SET TRANSPARENCY FLAG */
+-
+-	GXRsourceFlags = transparent ? RM_SRC_TRANSPARENT : 0;
+-
+-	/* FORMAT 8 BPP COLOR */
+-	/* GX requires 8BPP color data be duplicated into bits [15:8]. */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		bgcolor &= 0x00FF;
+-		bgcolor |= (bgcolor << 8);
+-		fgcolor &= 0x00FF;
+-		fgcolor |= (fgcolor << 8);
+-	}
+-
+-	/* POLL UNTIL ABLE TO WRITE THE SOURCE COLOR */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_SRC_COLOR_0, bgcolor);
+- 	WRITE_REG16(GP_SRC_COLOR_1, fgcolor);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_LOAD_SOLID_PATTERN
+-//
+-// This routine is used to specify a solid pattern color.  It is called 
+-// before performing solid rectangle fills or more complicated BLTs that 
+-// use a solid pattern color. 
+-//
+-// The driver should always call "gxr_load_raster_operation" after a call 
+-// to this routine to make sure that the pattern flags are set appropriately.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_load_solid_pattern(unsigned short color)
+-{
+-	/* SET PATTERN FLAGS */
+-
+-	GXRpatternFlags = 0;
+-
+-	/* FORMAT 8 BPP COLOR */
+-	/* GX requires 8BPP color data be duplicated into bits [15:8]. */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		color &= 0x00FF;
+-		color |= (color << 8);
+-	}
+-
+-	/* SAVE THE REFORMATTED COLOR FOR LATER */
+-	/* Used to call the "gxr_solid_fill" routine for special cases. */
+-
+-	GXRsavedColor = color;
+-
+-	/* POLL UNTIL ABLE TO WRITE THE PATTERN COLOR */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_PAT_COLOR_0, color);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_LOAD_MONO_PATTERN
+-//
+-// This routine is used to specify a monochrome pattern. 
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_load_mono_pattern(unsigned short bgcolor, unsigned short fgcolor, 
+-	unsigned long data0, unsigned long data1, unsigned char transparent)
+-{
+-	/* SET PATTERN FLAGS */
+-
+-	GXRpatternFlags = transparent ? RM_PAT_MONO | RM_PAT_TRANSPARENT : 
+-		RM_PAT_MONO;
+-	
+-	/* FORMAT 8 BPP COLOR */
+-	/* GX requires 8BPP color data be duplicated into bits [15:8]. */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		bgcolor &= 0x00FF;
+-		bgcolor |= (bgcolor << 8);
+-		fgcolor &= 0x00FF;
+-		fgcolor |= (fgcolor << 8);
+-	}
+-
+-	/* POLL UNTIL ABLE TO WRITE THE PATTERN COLORS AND DATA */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_PAT_COLOR_0, bgcolor);
+- 	WRITE_REG16(GP_PAT_COLOR_1, fgcolor);
+- 	WRITE_REG32(GP_PAT_DATA_0, data0);
+- 	WRITE_REG32(GP_PAT_DATA_1, data1);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_LOAD_RASTER_OPERATION
+-//
+-// This routine loads the specified raster operation.  It sets the pattern
+-// flags appropriately.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_load_raster_operation(unsigned char rop)
+-{
+-	unsigned short rop16;
+-
+-	/* GENERATE 16-BIT VERSION OF ROP WITH PATTERN FLAGS */
+-
+-	rop16 = (unsigned short) rop | GXRpatternFlags;
+-	if ((rop & 0x33) ^ ((rop >> 2) & 0x33))
+-		rop16 |= GXRsourceFlags;
+-
+-	/* SAVE ROP FOR LATER COMPARISONS */
+-	/* Need to have the pattern flags included */
+-
+-	GXRsavedRop = rop16;
+-	
+-	/* SET FLAG INDICATING ROP REQUIRES DESTINATION DATA */
+-	/* True if even bits (0:2:4:6) do not equal the correspinding */
+-	/* even bits (1:3:5:7). */
+-
+-	GXRusesDstData = ((rop & 0x55) ^ ((rop >> 1) & 0x55));
+-
+-	/* POLL UNTIL ABLE TO WRITE THE PATTERN COLOR */
+-	/* Only one operation can be pending at a time. */ 
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_RASTER_MODE, rop16);
+-}
+-
+-/*
+-//---------------------------------------------------------------------------
+-// GXR_SOLID_FILL
+-//
+-// This routine MUST be used when performing a solid rectangle fill with 
+-// the ROPs of PATCOPY (0xF0), BLACKNESS (0x00), WHITENESS (0xFF), or 
+-// PATINVERT (0x0F).  There is a bug in GXm for these cases that requires a 
+-// workaround.  
+-//
+-// For BLACKNESS (ROP = 0x00), set the color to 0x0000.  
+-// For WHITENESS (ROP = 0xFF), set the color to 0xFFFF.
+-// For PATINVERT (ROP = 0x0F), invert the desired color.
+-//
+-//      X               screen X position (left)
+-//      Y               screen Y position (top)
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      COLOR           fill color
+-//
+-// THIS ROUTINE SHOULD NOT BE DIRECTLY CALLED FROM THE DRIVER.  The driver 
+-// should always use gxr_pattern_fill and let that routine call this one
+-// when approipriate.  This is to hide quirks specific to MediaGX hardware.
+-//---------------------------------------------------------------------------
+-*/
+-
+-void gxr_solid_fill(unsigned short x, unsigned short y, 
+-	unsigned short width, unsigned short height, unsigned short color)
+-{
+-	unsigned short section;
+-
+-	/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-	/* Only one operation can be pending at a time. */ 
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-
+-	/* SET REGISTERS TO DRAW RECTANGLE */
+-
+-	WRITE_REG16(GP_DST_XCOOR, x);
+-	WRITE_REG16(GP_DST_YCOOR, y);
+- 	WRITE_REG16(GP_HEIGHT, height);
+- 	WRITE_REG16(GP_RASTER_MODE, 0x00F0); /* PATCOPY */
+-	WRITE_REG16(GP_PAT_COLOR_0, color);
+-
+-	/* CHECK WIDTH FOR GX BUG WORKAROUND */ 
+-
+-	if (width <= 16)
+-	{
+-		/* OK TO DRAW SMALL RECTANGLE IN ONE PASS */
+-
+-		WRITE_REG16(GP_WIDTH, width);
+-	 	WRITE_REG16(GP_BLIT_MODE, 0);
+-	}
+-	else
+-	{
+-		/* DRAW FIRST PART OF RECTANGLE */
+-		/* Get to a 16 pixel boundary. */
+-
+-		section = 0x10 - (x & 0x0F);
+-		WRITE_REG16(GP_WIDTH, section);
+-	 	WRITE_REG16(GP_BLIT_MODE, 0);
+-
+-		/* POLL UNTIL ABLE TO LOAD THE SECOND RECTANGLE */
+-
+-		while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-		WRITE_REG16(GP_DST_XCOOR, x + section);
+-		WRITE_REG16(GP_DST_YCOOR, y);
+-		WRITE_REG16(GP_WIDTH, width - section);
+-	 	WRITE_REG16(GP_BLIT_MODE, 0);
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// GXR_PATTERN_FILL
+-//
+-// This routine is used to fill a rectangular region.  The pattern must 
+-// be previously loaded using one of gxr_load_*_pattern routines.  Also, the 
+-// raster operation must be previously specified using the 
+-// "gxr_load_raster_operation" routine.
+-//
+-//      X               screen X position (left)
+-//      Y               screen Y position (top)
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_pattern_fill(unsigned short x, unsigned short y, 
+-	unsigned short width, unsigned short height)
+-{
+-	unsigned short section, buffer_width, blit_mode;
+-
+-	/* CHECK IF OPTIMIZED SOLID CASES */
+-    /* Check all 16 bits of the ROP to include solid pattern flags. */
+-
+-	switch(GXRsavedRop)
+-	{
+-		/* CHECK FOR SPECIAL CASES WITHOUT DESTINATION DATA */
+-		/* Need hardware workaround for fast "burst write" cases. */
+-
+-		case 0x00F0:
+-			gxr_solid_fill(x, y, width, height, GXRsavedColor);
+-			break;
+-		case 0x000F:
+-			gxr_solid_fill(x, y, width, height, ~GXRsavedColor);
+-			break;
+-		case 0x0000:
+-			gxr_solid_fill(x, y, width, height, 0x0000);
+-			break;
+-		case 0x00FF:
+-			gxr_solid_fill(x, y, width, height, 0xFFFF);
+-			break;
+-		
+-		/* REMAINING CASES REQUIRE DESTINATION DATA OR NOT SOLID COLOR */
+-
+-		default:
+-			
+-			/* DETERMINE BLT MODE VALUE */
+-			/* Still here for non-solid patterns without destination data. */
+-
+-			blit_mode = GXRusesDstData ? BM_READ_DST_FB0 : 0;
+-
+-			/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-			/* Write the registers that do not change for each section. */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 			WRITE_REG16(GP_HEIGHT, height);
+-
+-			/* SINCE ONLY DESTINATION DATA, WE CAN USE BOTH BB0 AND BB1. */
+-			/* Therefore, width available = BLT buffer width * 2. */
+-
+-			buffer_width = GXRbufferWidthPixels << 1;
+-
+-			/* REPEAT UNTIL FINISHED WITH RECTANGLE */
+-			/* Perform BLT in vertical sections, as wide as the BLT buffer */
+-			/* allows.  Hardware does not split the operations, so */
+-			/* software must do it to avoid large scanlines that would */
+-			/* overflow the BLT buffers. */
+-
+-			while(width > 0)
+-			{
+-				/* DETERMINE WIDTH OF SECTION */
+-
+-				if (width > buffer_width) section = buffer_width;
+-				else section = width;
+-
+-				/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-
+-				while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-				WRITE_REG16(GP_DST_XCOOR, x);
+-				WRITE_REG16(GP_DST_YCOOR, y);
+-				WRITE_REG16(GP_WIDTH, section);
+-				WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-
+-				/* ADJUST PARAMETERS FOR NEXT SECTION */
+-
+-				width -= section;
+-				x += section;
+-			}
+-			break;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// SCREEN TO SCREEN BLT
+-//
+-// This routine should be used to perform a screen to screen BLT when the 
+-// ROP does not require destination data.
+-//
+-//      SRCX            screen X position to copy from
+-//      SRCY            screen Y position to copy from
+-//      DSTX            screen X position to copy to
+-//      DSTY            screen Y position to copy to
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_screen_to_screen_blt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height)
+-{
+-	unsigned short section, buffer_width;
+-	unsigned short blit_mode;
+-
+-	/* CHECK IF RASTER OPERATION REQUIRES DESTINATION DATA */
+-
+-	blit_mode = GXRusesDstData ? BM_READ_DST_FB1 | BM_READ_SRC_FB : 
+-		BM_READ_SRC_FB;
+-
+-	/* CHECK Y DIRECTION */
+-	/* Hardware has support for negative Y direction. */
+-
+-	if (dsty > srcy) 
+-	{
+-		blit_mode |= BM_REVERSE_Y;
+-		srcy += height - 1;
+-		dsty += height - 1;
+-	}
+-
+-	/* CHECK X DIRECTION */
+-	/* Hardware does not support negative X direction since at the time */ 
+-	/* of development all supported resolutions could fit a scanline of */ 
+-	/* data at once into the BLT buffers (using both BB0 and BB1).  This */
+-	/* code is more generic to allow for any size BLT buffer. */
+-
+-	if (dstx > srcx)
+-	{
+-		srcx += width;
+-		dstx += width;
+-	}
+-
+-	/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-	/* Write the registers that do not change for each section. */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_HEIGHT, height);
+-
+-	/* CHECK AVAILABLE BLT BUFFER SIZE */
+-	/* Can use both BLT buffers if no destination data is required. */
+-
+-	buffer_width = GXRusesDstData ? GXRbufferWidthPixels :
+-		GXRbufferWidthPixels << 1;
+-
+-	/* REPEAT UNTIL FINISHED WITH RECTANGLE */
+-	/* Perform BLT in vertical sections, as wide as the BLT buffer allows. */
+-	/* Hardware does not split the operations, so software must do it to */ 
+-	/* avoid large scanlines that would overflow the BLT buffers. */
+-
+-	while(width > 0)
+-	{
+-		/* CHECK WIDTH OF CURRENT SECTION */
+-
+-		if (width > buffer_width) section = buffer_width;
+-		else section = width;
+-
+-		/* PROGRAM REGISTERS THAT ARE THE SAME FOR EITHER X DIRECTION */
+-
+-		while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-		WRITE_REG16(GP_SRC_YCOOR, srcy);
+-		WRITE_REG16(GP_DST_YCOOR, dsty);
+-		WRITE_REG16(GP_WIDTH, section);
+-
+-		/* CHECK X DIRECTION */
+-
+-		if (dstx > srcx)
+-		{
+-			/* NEGATIVE X DIRECTION */
+-			/* Still positive X direction within the section. */
+-
+-			srcx -= section;
+-			dstx -= section;
+-			WRITE_REG16(GP_SRC_XCOOR, srcx);
+-			WRITE_REG16(GP_DST_XCOOR, dstx);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-		} 
+-		else
+-		{
+-			/* POSITIVE X DIRECTION */
+-
+-			WRITE_REG16(GP_SRC_XCOOR, srcx);
+-			WRITE_REG16(GP_DST_XCOOR, dstx);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-			dstx += section;
+-			srcx += section;
+-		}
+-		width -= section;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// SCREEN TO SCREEN TRANSPARENT BLT
+-//
+-// This routine should be used to perform a screen to screen BLT when a 
+-// specified color should by transparent.  The only supported ROP is SRCCOPY.
+-//
+-//      SRCX            screen X position to copy from
+-//      SRCY            screen Y position to copy from
+-//      DSTX            screen X position to copy to
+-//      DSTY            screen Y position to copy to
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      COLOR           transparent color
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_screen_to_screen_xblt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned short color)
+-{
+-	unsigned short section, buffer_width;
+-	unsigned short blit_mode = BM_READ_SRC_FB;
+-	unsigned short i;
+-
+-	/* CHECK Y DIRECTION */
+-	/* Hardware has support for negative Y direction. */
+-
+-	if (dsty > srcy) 
+-	{
+-		blit_mode |= BM_REVERSE_Y;
+-		srcy += height - 1;
+-		dsty += height - 1;
+-	}
+-
+-	/* CHECK X DIRECTION */
+-	/* Hardware does not support negative X direction since at the time */
+-	/* of development all supported resolutions could fit a scanline of */ 
+-	/* data at once into the BLT buffers (using both BB0 and BB1).  This */
+-	/* code is more generic to allow for any size BLT buffer. */
+-
+-	if (dstx > srcx)
+-	{
+-		srcx += width;
+-		dstx += width;
+-	}
+-
+-	/* CALCULATE BLT BUFFER SIZE */
+-	/* Need to use BB1 to store the BLT buffer data. */
+-
+-	buffer_width = GXRbufferWidthPixels;
+-
+-	/* WRITE TRANSPARENCY COLOR TO BLT BUFFER 1 */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		color &= 0x00FF;
+-		color |= (color << 8);
+-	}
+-
+-	/* WAIT UNTIL PIPELINE IS NOT BUSY BEFORE LOADING DATA INTO BB1 */
+-	/* Need to make sure any previous BLT using BB1 is complete. */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_PIPELINE_BUSY);
+-	for (i = 0; i < 16; i+=2)
+-	{
+-		WRITE_REG16(GXRbb1Base+i, color);
+-	}
+-
+-	/* DO BOGUS BLT TO LATCH DATA FROM BB1 */
+-	/* Already know graphics pipeline is idle. */
+-
+- 	WRITE_REG32(GP_DST_XCOOR, 0);
+- 	WRITE_REG32(GP_SRC_XCOOR, 0);
+- 	WRITE_REG16(GP_WIDTH, 16);
+- 	WRITE_REG16(GP_HEIGHT, 1);
+- 	WRITE_REG16(GP_RASTER_MODE, 0x00CC);
+- 	WRITE_REG16(GP_BLIT_MODE, BM_READ_SRC_FB | BM_READ_DST_BB1);
+-	
+-	/* WRITE REGISTERS FOR REAL SCREEN TO SCREEN BLT */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-	WRITE_REG16(GP_HEIGHT, height);
+- 	WRITE_REG16(GP_RASTER_MODE, 0x10C6);
+-	WRITE_REG32(GP_PAT_COLOR_0, 0xFFFFFFFF);
+-
+-	/* REPEAT UNTIL FINISHED WITH RECTANGLE */
+-	/* Perform BLT in vertical sections, as wide as the BLT buffer allows. */
+-	/* Hardware does not split the operations, so software must do it to */
+-	/* avoid large scanlines that would overflow the BLT buffers. */
+-
+-	while(width > 0)
+-	{
+-		/* CHECK WIDTH OF CURRENT SECTION */
+-
+-		if (width > buffer_width) section = buffer_width;
+-		else section = width;
+-
+-		/* PROGRAM REGISTERS THAT ARE THE SAME FOR EITHER X DIRECTION */
+-
+-		while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-		WRITE_REG16(GP_SRC_YCOOR, srcy);
+-		WRITE_REG16(GP_DST_YCOOR, dsty);
+-		WRITE_REG16(GP_WIDTH, section);
+-
+-		/* CHECK X DIRECTION */
+-		/* Again, this must be done in software, and can be removed if the */
+-		/* display driver knows that the BLT buffers will always be large */
+-		/* enough to contain an entire scanline of a screen to screen BLT. */
+-
+-		if (dstx > srcx)
+-		{
+-			/* NEGATIVE X DIRECTION */
+-			/* Still positive X direction within the section. */
+-
+-			srcx -= section;
+-			dstx -= section;
+-			WRITE_REG16(GP_SRC_XCOOR, srcx);
+-			WRITE_REG16(GP_DST_XCOOR, dstx);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-		} 
+-		else
+-		{
+-			/* POSITIVE X DIRECTION */
+-
+-			WRITE_REG16(GP_SRC_XCOOR, srcx);
+-			WRITE_REG16(GP_DST_XCOOR, dstx);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-			dstx += section;
+-			srcx += section;
+-		}
+-		width -= section;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// COLOR BITMAP TO SCREEN BLT
+-//
+-// This routine transfers color bitmap data to the screen.  For most cases,
+-// when the ROP is SRCCOPY, it may be faster to write a separate routine that
+-// copies the data to the frame buffer directly.  This routine should be 
+-// used when the ROP requires destination data.
+-//
+-// Transparency is handled by another routine.
+-//
+-//      SRCX            X offset within source bitmap
+-//      SRCY            Y offset within source bitmap
+-//      DSTX            screen X position to render data
+-//      DSTY            screen Y position to render data
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      *DATA           pointer to bitmap data
+-//      PITCH           pitch of bitmap data (bytes between scanlines)
+-//      ROP             ternary raster operation (0x00-0xFF).
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_color_bitmap_to_screen_blt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned char *data, unsigned short pitch, 
+-	unsigned char rop)
+-{
+-	unsigned short section, buffer_width;
+-	unsigned short blit_mode = BM_READ_SRC_BB0;
+-	unsigned short line_srcx, line_dstx, line_width;
+-	unsigned short offset, i;
+-
+-	/* CHECK IF ROP REQUIRES DESTINATION DATA */
+-	/* Even bits (0:2:4:6) do not equal corresponding odd bits (1:3:5:7). */
+-
+-	if ((rop & 0x55) ^ ((rop >> 1) & 0x55))
+-		blit_mode |= BM_READ_DST_FB1;
+-
+-	/* CHECK SIZE OF BLT BUFFER */
+-
+-	buffer_width = GXRbufferWidthPixels;
+-	
+-	/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-	/* Write the registers that do not change for each section. */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_HEIGHT, 1);
+- 	WRITE_REG16(GP_RASTER_MODE, (unsigned short) rop & 0x00FF);
+-
+-	/* REPEAT FOR EACH SCANLINE */
+-
+-	offset = srcy * pitch;
+-
+-	while(height > 0)
+-	{
+-		line_width = width;
+-		line_srcx = srcx;
+-		line_dstx = dstx;
+-
+-		while(line_width > 0)
+-		{
+-			/* CHECK WIDTH OF CURRENT SECTION */
+-
+-			if (line_width > buffer_width) section = buffer_width;
+-			else section = line_width;
+-
+-			/* TRANSFER SCANLINE OF BITMAP DATA TO BLT BUFFER 0 */
+-			/* Need to wait for BS_PIPELINE_BUSY to make sure that the */ 
+-			/* data in BB0 for the previous scanline is no longer used. */
+-			/* This can be heavily optimized to not do a byte at a time. */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_PIPELINE_BUSY);
+-			if (READ_REG16(GP_BLIT_STATUS) & BC_16BPP)
+-			{
+-				for (i = 0; i < section; i++)
+-				{
+-					WRITE_REG16(GXRbb0Base+i, data[offset+((line_srcx+i)<<1)]);
+-				}
+-			}
+-			else
+-			{
+-				for (i = 0; i < section; i++)
+-				{
+-					WRITE_REG8(GXRbb0Base+i, data[line_srcx+offset+i]);
+-				}
+-			}
+-
+-			/* RENDER FROM BB0 TO FRAME BUFFER */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-			WRITE_REG16(GP_DST_XCOOR, line_dstx);
+-			WRITE_REG16(GP_DST_YCOOR, dsty);
+-			WRITE_REG16(GP_WIDTH, section);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-
+-			line_width -= section;
+-			line_dstx += section;
+-			line_srcx += section;
+-		}
+-		height--;
+-		dsty++;
+-		offset += pitch;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// COLOR BITMAP TO SCREEN TRANSPARENT BLT
+-//
+-// This routine transfers color bitmap data to the screen with transparency.
+-// The transparent color is specified.  The only supported ROP is SRCCOPY, 
+-// meaning that transparency cannot be applied if the ROP requires 
+-// destination data (this is a hardware restriction).
+-//
+-//      SRCX            X offset within source bitmap
+-//      SRCY            Y offset within source bitmap
+-//      DSTX            screen X position to render data
+-//      DSTY            screen Y position to render data
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      *DATA           pointer to bitmap data
+-//      PITCH           pitch of bitmap data (bytes between scanlines)
+-//      COLOR           transparent color
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_color_bitmap_to_screen_xblt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned char *data, unsigned short pitch, 
+-	unsigned short color)
+-{
+-	unsigned short section, buffer_width;
+-	unsigned short blit_mode = BM_READ_SRC_BB0;
+-	unsigned short line_srcx, line_dstx, line_width;
+-	unsigned short offset, i, first_blt = 1;
+-
+-	/* CHECK SIZE OF BLT BUFFER */
+-
+-	buffer_width = GXRbufferWidthPixels;
+-	
+-	/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-	/* Write the registers that do not change for each section. */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_HEIGHT, 1);
+- 	WRITE_REG16(GP_RASTER_MODE, 0x10C6);
+-	WRITE_REG32(GP_PAT_COLOR_0, 0xFFFFFFFF);
+-
+-	/* CALCULATE OFFSET INTO BITMAP DATA */
+-
+-	offset = srcy * pitch;
+-
+-	/* REPEAT FOR EACH SCANLINE */
+-
+-	while(height > 0)
+-	{
+-		line_width = width;
+-		line_srcx = srcx;
+-		line_dstx = dstx;
+-
+-		while(line_width > 0)
+-		{
+-			/* CHECK WIDTH OF CURRENT SECTION */
+-
+-			if (line_width > buffer_width) section = buffer_width;
+-			else section = line_width;
+-
+-			/* TRANSFER SCANLINE OF BITMAP DATA TO BLT BUFFER 0 */
+-			/* Need to wait for BS_PIPELINE_BUSY to make sure that the */ 
+-			/* data in BB0 for the previous scanline is no longer used. */
+-			/* This can be heavily optimized to not do a byte at a time. */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_PIPELINE_BUSY);
+-			if (READ_REG16(GP_BLIT_STATUS) & BC_16BPP)
+-			{
+-				for (i = 0; i < section; i++)
+-				{
+-					WRITE_REG16(GXRbb0Base+i, data[offset+((line_srcx+i)<<1)]);
+-				}
+-			}
+-			else
+-			{
+-				for (i = 0; i < section; i++)
+-				{
+-					WRITE_REG8(GXRbb0Base+i, data[line_srcx+offset+i]);
+-				}
+-			}
+-
+-			/* RENDER FROM BB0 TO FRAME BUFFER */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-			WRITE_REG16(GP_DST_XCOOR, line_dstx);
+-			WRITE_REG16(GP_DST_YCOOR, dsty);
+-			WRITE_REG16(GP_WIDTH, section);
+-
+-			/* NEED TO DO EXTRA WORK FOR THE FIRST BLT */
+-
+-			if (first_blt)
+-			{
+-				/* WRITE TRANSPARENCY COLOR TO BLT BUFFER 1 */
+-				/* This can be heavily optimized to not do 16-bits at a time. */
+-
+-				if (READ_REG16(GP_BLIT_STATUS) & BC_16BPP)
+-				{
+-					for (i = 0; i < section; i++)
+-					{
+-						WRITE_REG16(GXRbb1Base+i*2, color);
+-					}
+-				}
+-				else
+-				{
+-					for (i = 0; i < section; i++)
+-					{
+-						WRITE_REG8(GXRbb1Base+i, (unsigned char) color);
+-					}
+-				}
+-				WRITE_REG16(GP_BLIT_MODE, BM_READ_SRC_BB0 | BM_READ_DST_BB1);
+-				first_blt = 0;
+-			}
+-			else
+-			{
+-				/* AFTER FIRST BLT, THE TRANSPARENCY DATA IS LATCHED */
+-				/* Save time by not reading data from BB1. */
+-
+-				WRITE_REG16(GP_BLIT_MODE, BM_READ_SRC_BB0);
+-			}
+-			line_width -= section;
+-			line_dstx += section;
+-			line_srcx += section;
+-		}
+-		height--;
+-		dsty++;
+-		offset += pitch;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// MONOCHROME BITMAP TO SCREEN BLT
+-//
+-// This routine transfers monochrome bitmap data to the screen.  
+-//
+-//      SRCX            X offset within source bitmap
+-//      SRCY            Y offset within source bitmap
+-//      DSTX            screen X position to render data
+-//      DSTY            screen Y position to render data
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      *DATA           pointer to bitmap data
+-//      PITCH           pitch of bitmap data (bytes between scanlines)
+-//      FGCOLOR         color for bits = 1
+-//      BGCOLOR         color for bits = 0
+-//      ROP             ternary raster operation (0x00-0xFF).
+-//      TRANSPARENT     zero for opaque, otherwise transparent
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_mono_bitmap_to_screen_blt(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned char *data, unsigned short pitch, 
+-	unsigned short fgcolor, unsigned short bgcolor, unsigned char rop,
+-	unsigned char transparent)
+-{
+-	unsigned short section, buffer_width;
+-	unsigned short blit_mode = BM_READ_SRC_BB0 | BM_SOURCE_EXPAND;
+-	unsigned short line_srcx, line_dstx, line_width;
+-	unsigned short offset, i, bytes, raster_mode;
+-
+-	/* FORMAT 8BPP COLOR */
+-    /* GX requires that 8BPP color data be duplicated into bits [15:8]. */
+-
+-	if (!(READ_REG16(GP_BLIT_STATUS) & BC_16BPP))
+-	{
+-		fgcolor &= 0x00FF;
+-		fgcolor |= (fgcolor << 8);
+-		bgcolor &= 0x00FF;
+-		bgcolor |= (bgcolor << 8);
+-	}
+-
+-	/* CHECK IF ROP REQUIRES DESTINATION DATA */
+-	/* Even bits (0:2:4:6) do not equal corresponding odd bits (1:3:5:7). */
+-
+-	if ((rop & 0x55) ^ ((rop >> 1) & 0x55))
+-		blit_mode |= BM_READ_DST_FB1;
+-
+-	/* CALCULATE RASTER MODE */
+-	/* Set mono flag.  Transparency	set based on input parameter. */
+-
+-	raster_mode = ((unsigned short) rop & 0x00FF);
+-	if (transparent) raster_mode |= RM_SRC_TRANSPARENT;
+-
+-	/* CHECK SIZE OF BLT BUFFER */
+-
+-	buffer_width = GXRbufferWidthPixels;
+-	
+-	/* CALCULATE OFFSET INTO BITMAP DATA */
+-
+-	offset = srcy * pitch;
+-
+-	/* POLL UNTIL ABLE TO WRITE TO THE REGISTERS */
+-	/* Write the registers that do not change for each section. */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+- 	WRITE_REG16(GP_HEIGHT, 1);
+- 	WRITE_REG16(GP_RASTER_MODE, raster_mode);
+- 	WRITE_REG16(GP_SRC_COLOR_0, bgcolor);
+- 	WRITE_REG16(GP_SRC_COLOR_1, fgcolor);
+-
+-	/* REPEAT FOR EACH SCANLINE */
+-
+-	while(height > 0)
+-	{
+-		line_width = width;
+-		line_srcx = srcx;
+-		line_dstx = dstx;
+-
+-		while(line_width > 0)
+-		{
+-			/* CHECK WIDTH OF CURRENT SECTION */
+-			/* Only divide into sections if reading destination data. */  
+-			/* Since the source data is monochrome, it will always fit. */
+-
+-			section = line_width;
+-			if ((line_width > buffer_width) && (blit_mode & BM_READ_DST_FB1)) 
+-				section = buffer_width;
+-
+-			/* BYTES TO TRANSFER */
+-			/* Add two bytes to handle truncating and alignment. */
+-
+-			bytes = (section >> 3) + 2;
+-
+-			/* TRANSFER SCANLINE OF BITMAP DATA TO BLT BUFFER 0 */
+-			/* Need to wait for BS_PIPELINE_BUSY to make sure that the */ 
+-			/* data in BB0 for the previous scanline is no longer used. */
+-			/* This can be heavily optimized to not do a byte at a time. */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_PIPELINE_BUSY);
+-			for (i = 0; i < bytes; i++)
+-			{
+-				WRITE_REG8(GXRbb0Base+i, data[(line_srcx >> 3)+offset+i]);
+-			}
+-
+-			/* RENDER FROM BB0 TO FRAME BUFFER */
+-
+-			while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-			WRITE_REG16(GP_DST_XCOOR, line_dstx);
+-			WRITE_REG16(GP_DST_YCOOR, dsty);
+-		 	WRITE_REG16(GP_SRC_XCOOR, line_srcx & 7);
+-			WRITE_REG16(GP_WIDTH, section);
+-			WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-
+-			line_width -= section;
+-			line_dstx += section;
+-			line_srcx += section;
+-		}
+-		height--;
+-		dsty++;
+-		offset += pitch;
+-	}
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// TEXT GLYPH
+-//
+-// This routine draws a single character of text.  It can only be used for 
+-// characters that are less than or equal to 64x64 in size, since it 
+-// transfers the entire data into the BLT buffers at once.  Larger characters
+-// should use the monochrome bitmap to screen routine.  The only supported 
+-// ROP is SRCCOPY, again since the BLT buffer size is limited. 
+-// 
+-//      SRCX            X offset within source bitmap
+-//      SRCY            Y offset within source bitmap
+-//      DSTX            screen X position to render data
+-//      DSTY            screen Y position to render data
+-//      WIDTH           width of rectangle, in pixels
+-//      HEIGHT          height of rectangle, in scanlines
+-//      *DATA           pointer to bitmap data (NULL if already loaded)
+-//      PITCH           pitch of bitmap data (bytes between scanlines)
+-//
+-// For the Xfree86 display driver, the OS is given a pointer to BB0.  
+-// Therefore, the data is already loaded when the driver is called, so the
+-// driver simply passes a NULL pointer to this routine.
+-//
+-// This same type of routine could be developed for "icons", or small 
+-// color bitmaps that can fit entirely in the BLT buffer. 
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_text_glyph(unsigned short srcx, unsigned short srcy,
+-	unsigned short dstx, unsigned short dsty, unsigned short width, 
+-	unsigned short height, unsigned char *data, unsigned short pitch)
+-{
+-	unsigned short offset, i, j, buffer_offset, bytes, blit_mode;
+-
+-	blit_mode = BM_READ_SRC_BB0 | BM_SOURCE_EXPAND;
+-	if (GXRusesDstData) blit_mode |= BM_READ_DST_FB1;
+-
+-	/* CHECK IF DATA NEEDS TO BE TRANSFERRED */
+-
+-	if (data != 0)
+-	{
+-		/* TRANSFER ENTIRE BITMAP DATA TO BLT BUFFER 0 */
+-		/* Need to wait for BS_PIPELINE_BUSY to make sure that the */ 
+-		/* data in BB0 for any previous BLT is no longer used. */
+-		/* This data transfer has lots of room for performance optimization. */
+-
+-		buffer_offset = 0;
+-		offset = srcy * pitch + (srcx >> 3);
+-		bytes = ((width + (srcx & 7) + 7) >> 3);
+-		while(READ_REG16(GP_BLIT_STATUS) & BS_PIPELINE_BUSY);
+-		for (j = 0; j < height; j++)
+-		{
+-			for (i = 0; i < bytes; i++)
+-			{
+-				WRITE_REG8(GXRbb0Base+buffer_offset, data[offset+i]);
+-				buffer_offset++;
+-			}
+-			offset += pitch;
+-		}
+-	}
+-
+-	/* RENDER FROM BB0 TO FRAME BUFFER */
+-	/* Already know that the pipeline is idle from loading data. */
+-
+-	WRITE_REG16(GP_DST_XCOOR, dstx);
+-	WRITE_REG16(GP_DST_YCOOR, dsty);
+- 	WRITE_REG16(GP_SRC_XCOOR, srcx & 7);
+-	WRITE_REG16(GP_WIDTH, width);
+- 	WRITE_REG16(GP_HEIGHT, height);
+-	WRITE_REG16(GP_BLIT_MODE, blit_mode);
+-}    
+-
+-/*
+-//----------------------------------------------------------------------------
+-// BRESENHAM LINE
+-//
+-// This routine draws a vector using the specified Bresenham parameters.  
+-// Currently this file does not support a routine that accepts the two 
+-// endpoints of a vector and calculates the Bresenham parameters.  If it 
+-// ever does, this routine is still required for vectors that have been 
+-// clipped.
+-//
+-//      X               screen X position to start vector
+-//      Y               screen Y position to start vector
+-//      LENGTH          length of the vector, in pixels
+-//      INITERR         Bresenham initial error term
+-//      AXIALERR        Bresenham axial error term
+-//      DIAGERR         Bresenham diagonal error term
+-//      FLAGS           VM_YMAJOR, VM_MAJOR_INC, VM_MINOR_INC
+-//----------------------------------------------------------------------------
+-*/
+-
+-void gxr_bresenham_line(unsigned short x, unsigned short y, 
+-		unsigned short length, unsigned short initerr, 
+-		unsigned short axialerr, unsigned short diagerr, 
+-		unsigned short flags)
+-{
+-	unsigned short vector_mode = flags;
+-	if (GXRusesDstData) vector_mode |= VM_READ_DST_FB;
+-
+-	/* CHECK NULL LENGTH */
+-
+-	if (!length) return;
+-
+-	/* LOAD THE REGISTERS FOR THE VECTOR */
+-
+-	while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING);
+-	WRITE_REG16(GP_DST_XCOOR, x);
+-	WRITE_REG16(GP_DST_YCOOR, y);
+-	WRITE_REG16(GP_VECTOR_LENGTH, length);
+-	WRITE_REG16(GP_INIT_ERROR, initerr);
+-	WRITE_REG16(GP_AXIAL_ERROR, axialerr);
+-	WRITE_REG16(GP_DIAG_ERROR, diagerr);
+-	WRITE_REG16(GP_VECTOR_MODE, vector_mode);
+-}
+-
+-/* END OF FILE */
+-
--- xfree86-1-3.3.6.orig/debian/patches/057_XLC_LOCALE_zh_CN.GBK.diff
+++ xfree86-1-3.3.6/debian/patches/057_XLC_LOCALE_zh_CN.GBK.diff
@@ -0,0 +1,73 @@
+--- xc.old/nls/XLC_LOCALE/zh_CN.GBK	Thu Jan  1 08:00:00 1970
++++ xc/nls/XLC_LOCALE/zh_CN.GBK	Tue Nov  9 13:59:14 1999
+@@ -0,0 +1,70 @@
++XCOMM 
++XCOMM  X11R6 L10N for Chinese GBK Encoding.
++XCOMM     modified from xc/nls/XLC_LOCALE/zh_TW.Big5
++XCOMM     by Sean Chen <seanc@turbolinux.com>
++XCOMM 
++
++XCOMM 
++XCOMM 	XLC_FONTSET category
++XCOMM 
++XLC_FONTSET
++XCOMM        fs0 class (7 bit ASCII)
++fs0     {
++        charset {
++                name    ISO8859-1:GL
++        }
++        font    {
++                primary         ISO8859-1:GL
++                vertical_rotate all
++        }
++}
++XCOMM        fs1 class
++fs1     {
++        charset {
++                name    GBK-0:GLGR
++        }
++        font    {
++                primary GBK-0:GLGR
++                substitute GB13000.1993-1:GLGR
++        }
++}
++END XLC_FONTSET
++
++XCOMM 
++XCOMM 	XLC_XLOCALE category
++XCOMM 
++XLC_XLOCALE
++
++encoding_name		zh_CN.GBK
++mb_cur_max		2
++state_depend_encoding	False
++
++wc_encoding_mask	\x00008000
++wc_shift_bits		8
++
++use_stdc_env		True
++force_convert_to_mb	True
++
++XCOMM 	cs0 class
++cs0	{
++	side		GL:Default
++	length		1
++	wc_encoding	\x00000000
++	ct_encoding	ISO8859-1:GL
++}
++
++XCOMM 	cs1 class
++cs1	{
++	side		none
++	length		2
++	byte1		\x81,\xfe
++	byte2		\x40,\x7e;\x80,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	GBK-0:GLGR:\x1b\x25\x2f\x32\x80\x88\x47\x42\x4b\x2d\x30\x02
++
++	mb_conversion	[\x8140,\xfefe]->\x0140
++	ct_conversion	[\x0140,\x7efe]->\x8140
++}
++
++END XLC_XLOCALE
--- xfree86-1-3.3.6.orig/debian/patches/069_dixfonts_fixup.diff
+++ xfree86-1-3.3.6/debian/patches/069_dixfonts_fixup.diff
@@ -0,0 +1,177 @@
+This is backported code from XFree86 4.x that keeps the X server from
+bombing out if it can't resolve a font server font path element.
+
+--- xc/programs/Xserver/dix/dixfonts.c.orig	Wed Jan 24 14:09:22 2001
++++ xc/programs/Xserver/dix/dixfonts.c	Wed Jan 24 14:16:51 2001
+@@ -1687,15 +1687,15 @@
+     return (FontPathElementPtr) 0;
+ }
+ 
+-
+ static int
+ #if NeedFunctionPrototypes
+-SetFontPathElements(int npaths, unsigned char *paths, int *bad)
++SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
+ #else
+-SetFontPathElements(npaths, paths, bad)
++SetFontPathElements(npaths, paths, bad, persist)
+     int         npaths;
+     unsigned char *paths;
+     int        *bad;
++    Bool	persist;
+ #endif
+ {
+     int         i,
+@@ -1716,63 +1716,83 @@
+ 	if (fpe_functions[i].set_path_hook)
+ 	    (*fpe_functions[i].set_path_hook) ();
+     }
+-    for (i = 0; i < npaths; i++) {
++    for (i = 0; i < npaths; i++) 
++    {
+ 	len = (unsigned int) (*cp++);
+ 
+-	if (len) {
++	if (len == 0) 
++	{
++	    if (persist)
++		ErrorF ("Removing empty element from the valid list of fontpaths\n");
++	    err = BadValue;
++	}
++	else
++	{
+ 	    /* if it's already in our active list, just reset it */
+ 	    /*
+ 	     * note that this can miss FPE's in limbo -- may be worth catching
+ 	     * them, though it'd muck up refcounting
+ 	     */
+ 	    fpe = find_existing_fpe(font_path_elements, num_fpes, cp, len);
+-	    if (fpe) {
++	    if (fpe) 
++	    {
+ 		err = (*fpe_functions[fpe->type].reset_fpe) (fpe);
+-		if (err == Successful) {
++		if (err == Successful) 
++		{
+ 		    UseFPE(fpe);/* since it'll be decref'd later when freed
+ 				 * from the old list */
+-		    fplist[valid_paths++] = fpe;
+-		    cp += len;
+-		    continue;
+ 		}
+-		/* if error or can't do it, act like it's a new one */
+-	    }
+-	    fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec));
+-	    if (!fpe) {
+-		err = BadAlloc;
+-		goto bail;
++		else
++		    fpe = 0;
+ 	    }
+-	    fpe->name = (char *) xalloc(len + 1);
+-	    if (!fpe->name) {
+-		xfree(fpe);
+-		err = BadAlloc;
+-		goto bail;
+-	    }
+-	    fpe->refcount = 1;
+-
+-	    strncpy(fpe->name, (char *) cp, (int) len);
+-	    cp += len;
+-	    fpe->name[len] = '\0';
+-	    fpe->name_length = len;
+-	    fpe->type = DetermineFPEType(fpe->name);
+-	    if (fpe->type == -1) {
+-		xfree(fpe->name);
+-		xfree(fpe);
+-		err = BadValue;
+-		goto bail;
++	    /* if error or can't do it, act like it's a new one */
++	    if (!fpe)
++	    {
++		fpe = (FontPathElementPtr) xalloc(sizeof(FontPathElementRec));
++		if (!fpe) 
++		{
++		    err = BadAlloc;
++		    goto bail;
++		}
++		fpe->name = (char *) xalloc(len + 1);
++		if (!fpe->name) 
++		{
++		    xfree(fpe);
++		    err = BadAlloc;
++		    goto bail;
++		}
++		fpe->refcount = 1;
++    
++		strncpy(fpe->name, (char *) cp, (int) len);
++		fpe->name[len] = '\0';
++		fpe->name_length = len;
++		fpe->type = DetermineFPEType(fpe->name);
++		if (fpe->type == -1)
++		    err = BadValue;
++		else
++		    err = (*fpe_functions[fpe->type].init_fpe) (fpe);
++		if (err != Successful)
++		{
++		    if (persist)
++		    {
++			ErrorF("Could not init font path element %s, removing from list!\n",
++			       fpe->name);
++		    }
++		    xfree (fpe->name);
++		    xfree (fpe);
++		}
+ 	    }
+-	    err = (*fpe_functions[fpe->type].init_fpe) (fpe);
+-	    if (err != Successful) {
+-		xfree(fpe->name);
+-		xfree(fpe);
+-		err = BadValue;
++	}
++	if (err != Successful)
++	{
++	    if (!persist)
+ 		goto bail;
+-	    }
++	}
++	else
++	{
+ 	    fplist[valid_paths++] = fpe;
+-	} else {
+-	    err = BadValue;
+-	    goto bail;
+ 	}
++	cp += len;
+     }
+ 
+     FreeFontPath(font_path_elements, num_fpes, FALSE);
+@@ -1784,8 +1804,8 @@
+     return Success;
+ bail:
+     *bad = i;
+-    while (--i >= 0)
+-	FreeFPE(fplist[i]);
++    while (--valid_paths >= 0)
++	FreeFPE(fplist[valid_paths]);
+     xfree(fplist);
+     return err;
+ }
+@@ -1804,7 +1824,7 @@
+ 	if (SetDefaultFontPath(defaultFontPath) != Success)
+ 	    return BadName;
+     } else {
+-	err = SetFontPathElements(npaths, paths, error);
++	err = SetFontPathElements(npaths, paths, error, FALSE);
+     }
+     return err;
+ }
+@@ -1844,7 +1864,7 @@
+     }
+     *nump = (unsigned char) size;
+ 
+-    err = SetFontPathElements(num, newpath, &bad);
++    err = SetFontPathElements(num, newpath, &bad, TRUE);
+ 
+     DEALLOCATE_LOCAL(newpath);
+ 
--- xfree86-1-3.3.6.orig/debian/patches/001-16_Cards_misc.diff
+++ xfree86-1-3.3.6/debian/patches/001-16_Cards_misc.diff
@@ -0,0 +1,68 @@
+--- xc/programs/Xserver/hw/xfree86/xf86config/Cards.orig	Mon Dec 20 11:40:07 1999
++++ xc/programs/Xserver/hw/xfree86/xf86config/Cards	Sun May 14 22:21:26 2000
+@@ -2038,24 +2038,24 @@
+ NAME WD 90C24 (laptop)
+ CHIPSET WD90C24
+ SERVER SVGA
+-LINE     #Chipset "wd90c24"
+-LINE     #Option "noaccel" # Use this if acceleration is causing problems
+-LINE     #Clocks 25.175 28.322 65     36     # These are not programmable
+-LINE     #Clocks 29.979 77.408 62.195 59.957 # These are programmable
+-LINE     #Clocks 31.5   35.501 75.166 50.114 # These are not programmable
+-LINE     #Clocks 39.822 72.038 44.744 80.092 # These are programmable
+-LINE     #Clocks 44.297                      # Must match Mclk
++LINE     Chipset "wd90c24"
++LINE     Option "noaccel" # Use this if acceleration is causing problems
++LINE     Clocks 25.175 28.322 65     36     # These are not programmable
++LINE     Clocks 29.979 77.408 62.195 59.957 # These are programmable
++LINE     Clocks 31.5   35.501 75.166 50.114 # These are not programmable
++LINE     Clocks 39.822 72.038 44.744 80.092 # These are programmable
++LINE     Clocks 44.297                      # Must match Mclk
+ 
+ 
+ NAME WD 90C24A or 90C24A2 (laptop)
+ CHIPSET WD90C24A
+ SERVER SVGA
+-LINE     #Chipset "wd90c24"
+-LINE     #Clocks 25.175 28.322 65     36     # These are not programmable
+-LINE     #Clocks 29.979 77.408 62.195 59.957 # These are programmable
+-LINE     #Clocks 31.5   35.501 75.166 50.114 # These are not programmable
+-LINE     #Clocks 39.822 72.038 44.744 80.092 # These are programmable
+-LINE     #Clocks 44.297                      # Must match Mclk
++LINE     Chipset "wd90c24"
++LINE     Clocks 25.175 28.322 65     36     # These are not programmable
++LINE     Clocks 29.979 77.408 62.195 59.957 # These are programmable
++LINE     Clocks 31.5   35.501 75.166 50.114 # These are not programmable
++LINE     Clocks 39.822 72.038 44.744 80.092 # These are programmable
++LINE     Clocks 44.297                      # Must match Mclk
+ 
+ # Avance Logic
+ 
+@@ -2376,7 +2376,7 @@
+ NAME SiS 5597
+ CHIPSET SiS5597
+ SERVER SVGA
+-LINE     # Option "no_accel" # Use this if acceleration is causing problems
++LINE     Option "no_accel" # Use this if acceleration is causing problems
+ LINE     # Option "fifo_moderate" 
+ LINE     # Option "fifo_conserv" 
+ LINE     # Option "fifo_aggresive" 
+@@ -2404,7 +2404,7 @@
+ NAME SiS 6326
+ CHIPSET SiS6326
+ SERVER SVGA
+-LINE     # Option "no_accel" # Use this if acceleration is causing problems
++LINE     Option "no_accel" # Use this if acceleration is causing problems
+ LINE     # Option "fifo_moderate" 
+ LINE     # Option "fifo_conserv" 
+ LINE     # Option "fifo_aggresive" 
+@@ -2454,6 +2454,9 @@
+ 
+ NAME Diamond SpeedStar A50
+ SEE SiS 6326
++LINE     Option "sw_cursor"
++LINE     Option "no_imageblt"
++LINE     Option "no_bitblt"
+ 
+ NAME AOpen PA50D
+ SEE SiS 6326
--- xfree86-1-3.3.6.orig/debian/patches/054_XLC_LOCALE_zh_CN.GB2312_substitute.diff
+++ xfree86-1-3.3.6/debian/patches/054_XLC_LOCALE_zh_CN.GB2312_substitute.diff
@@ -0,0 +1,10 @@
+--- xc/nls/XLC_LOCALE/zh.orig	Sat Jun  3 23:51:24 2000
++++ xc/nls/XLC_LOCALE/zh	Sat Jun  3 23:51:59 2000
+@@ -23,6 +23,7 @@
+ 	}
+ 	font	{
+ 		primary	GB2312.1980-0:GL
++		substitute	GB2312.1980-0:GLGR
+ 	}
+ }
+ END XLC_FONTSET
--- xfree86-1-3.3.6.orig/debian/patches/001a-01_SPARC_programs_xkbcomp_rules.diff
+++ xfree86-1-3.3.6/debian/patches/001a-01_SPARC_programs_xkbcomp_rules.diff
@@ -0,0 +1,113 @@
+--- xc/programs/xkbcomp/rules/Imakefile.jj	Fri Dec 27 08:08:51 1996
++++ xc/programs/xkbcomp/rules/Imakefile	Thu Jan 13 11:35:02 2000
+@@ -1,7 +1,7 @@
+ XCOMM $XConsortium: Imakefile /main/3 1996/09/13 10:59:07 kaleb $
+ 
+-    DATAFILES = sgi xfree86
+-    LISTFILES = sgi.lst xfree86.lst xfree86-it.lst
++    DATAFILES = sgi xfree86 sun
++    LISTFILES = sgi.lst xfree86.lst xfree86-it.lst sun.lst
+ 
+ all::
+ 
+--- xc/programs/xkbcomp/rules/sun.jj	Thu Jan 13 11:35:02 2000
++++ xc/programs/xkbcomp/rules/sun	Thu Jan 13 11:36:01 2000
+@@ -0,0 +1,37 @@
++// $TOG: sun /main/4 1999/09/14 18:51:12 jj $
++
++! model			=    keycodes			geometry
++  type4   		=    sun(type4)			sun(type4)
++  type5   		=    sun(type5)			sun
++  type5_euro		=    sun(type5_euro)		sun(type5euro)
++  type5_unix		=    sun(type5)			sun(type5unix)
++
++! model		layout	=  symbols
++  type4		us	=  sun/us(sun4)
++  type5		us	=  sun/us(sun5)
++  type5_unix	us	=  sun/us(sun5)
++  type4		en_US	=  sun/us(sun4)+iso9995-3(basic)
++  type5		en_US	=  sun/us(sun5)+iso9995-3(basic)
++  type5_unix	en_US	=  sun/us(sun5)+iso9995-3(basic)
++  type4		*	=  sun/us(sun4)+%l%(v)
++  type5		*	=  sun/us(sun5)+%l%(v)
++  type5_euro	*	=  sun/us(sun5)+%l%(v)
++
++! model   layout   =    compat     types
++  *       *        =    complete   complete
++
++! option                =   symbols
++  grp:switch            =   +group(switch)
++  grp:toggle            =   +group(toggle)
++  grp:shift_toggle      =   +group(shift_toggle)
++  grp:ctrl_shift_toggle =   +group(ctrl_shift_toggle)
++  grp:ctrl_alt_toggle   =   +group(ctrl_alt_toggle)
++  grp:caps_toggle	=   +group(caps_toggle)
++  ctrl:nocaps           =   +ctrl(nocaps)
++  ctrl:swapcaps         =   +ctrl(swapcaps)
++  ctrl:ctrl_ac          =   +ctrl(ctrl_ac)
++  ctrl:ctrl_aa          =   +ctrl(ctrl_aa)
++  keypad:overlay	=   +keypad(overlay)
++  keypad:overlay1	=   +keypad(overlay)
++  keypad:overlay2	=   +keypad(overlay)
++  lock:shift		=   +lock(shift)
+--- xc/programs/xkbcomp/rules/sun.lst.jj	Thu Jan 13 11:35:02 2000
++++ xc/programs/xkbcomp/rules/sun.lst	Thu Jan 13 11:36:01 2000
+@@ -0,0 +1,58 @@
++// $TOG: sun.lst /main/3 1999/09/14 18:51:12 jj $
++
++! model
++  type4			Sun Type4
++  type5			Sun Type5
++  type5_euro		Sun Type5 European
++  type5_unix		Sun Type5 Unix
++
++! layout
++  be			Belgian
++  bg			Bulgarian
++  ca			Canadian
++  cs			Czechoslovakian
++  de 			German
++  de_CH			Swiss German
++  dvorak		Dvorak (US)
++  dk			Danish
++  en_US			US/English w/ISO9995-3
++  es			Spanish
++  fi			Finnish
++  fr			French
++  fr_CH			Swiss French
++  gb			United Kingdom
++  hu			Hungarian
++  it			Italian
++  intl			US w/Compose Key
++  jp			Japanese
++  no			Norwegian
++  pl			Polish
++  pt			Portugese
++  ru			Russian
++  se			Swedish
++  th			Thai
++  us			US/ASCII
++
++! variant
++  nodeadkeys		Eliminate dead keys from European keyboards
++  typewriter		Cyrillic layout similar to manual typewriters
++  phonetic		Cyrillic layout similar to US/ASCII layout
++
++! option
++  grp			Group Shift/Lock behavior
++  grp:switch		Right Alt key switches group while held down
++  grp:toggle		Pressing Right Alt key toggles group
++  grp:shift_toggle	Pressing both shift keys together toggles group
++  grp:ctrl_shift_toggle	Pressing shift and control together toggles group
++  grp:ctrl_alt_toggle	Pressing alt and control together toggles group
++  grp:caps_toggle       Caps Lock key toggles group
++  ctrl			Control Key Position
++  ctrl:nocaps		Replace Caps Lock with another control key
++  ctrl:swapcaps		Swap positions of control and Caps Lock
++  ctrl:ctrl_ac		Control key is left of the 'A' key
++  ctrl:ctrl_aa		Control key is at the left of the bottom row
++  lock			Specify behavior of the lock key
++  lock:shift		Key is shift lock
++  lock:caps		Key is captals lock
++  lock:group		Key is group lock
++
--- xfree86-1-3.3.6.orig/debian/patches/055_mach64_ati_rage_pro_lt_fix.diff
+++ xfree86-1-3.3.6/debian/patches/055_mach64_ati_rage_pro_lt_fix.diff
@@ -0,0 +1,55 @@
+--- xc/programs/Xserver/hw/xfree86/accel/mach64/mach64.c.orig	Sun Jun  4 00:02:09 2000
++++ xc/programs/Xserver/hw/xfree86/accel/mach64/mach64.c	Sun Jun  4 00:06:30 2000
+@@ -1677,6 +1677,20 @@
+ 		(double)mach64LCDClock / 100.0);
+ 
+ 	/*
++	 * Original hack by Panu Outinen <panu@vertex.fi>: force 80MHz LCD
++	 * clock on 1400x1050 Mobility-P.  Modified by Steve Hsieh
++	 * <http://www.eecs.umich.edu/~steveh/inspiron/> to force LCD clock
++	 * to 107.85MHz if screen resolution is 1400x1050 and LCDClock is
++	 * currently less than that.
++	 */
++	if (mach64LCDHorizontal == 1400 && mach64LCDVertical == 1050
++	    && mach64LCDClock < 10785) {
++	    mach64LCDClock = 10785;
++	    ErrorF("1400x1050 LCD detected, forcing mach64LCDClock to %.2f MHz\n",
++		   (double)mach64LCDClock / 100.0);
++	}
++
++	/*
+ 	 * Determine porch data.  The intent here is to produce stretched modes
+ 	 * that approximate the horizontal sync and vertical refresh rates of
+ 	 * the mode on entry.
+--- xc/programs/Xserver/hw/xfree86/accel/mach64/mach64init.c.orig	Sun Jun  4 00:02:21 2000
++++ xc/programs/Xserver/hw/xfree86/accel/mach64/mach64init.c	Sun Jun  4 00:09:48 2000
+@@ -2498,8 +2498,12 @@
+ 		old_HORZ_STRETCHING = regr(HORZ_STRETCHING);
+ 		old_VERT_STRETCHING = regr(VERT_STRETCHING);
+ 		old_POWER_MANAGEMENT = regr(POWER_MANAGEMENT);
+-		/* Disable panel's APM */
+-		regw(POWER_MANAGEMENT, old_POWER_MANAGEMENT & ~PWR_MGT_ON);
++		/*
++		 * Enable panel's APM -- not sure why the stock
++		 * X server code explicitly disables this.
++		 * Steve Hsieh <http://www.eecs.umich.edu/~steveh/inspiron/>
++		 */
++		regw(POWER_MANAGEMENT, old_POWER_MANAGEMENT | PWR_MGT_ON);
+ 	    } else {
+ 		/* All others */
+ 		old_LCD_INDEX = inl(ioLCD_INDEX);
+@@ -2526,8 +2530,12 @@
+ 		old_EXT_VERT_STRETCH = inl(ioLCD_DATA);
+ 		outb(ioLCD_INDEX, LCD_POWER_MANAGEMENT);
+ 		old_POWER_MANAGEMENT = inl(ioLCD_DATA);
+-		/* Disable panel's APM */
+-		outl(ioLCD_DATA, old_POWER_MANAGEMENT & ~PWR_MGT_ON);
++		/*
++		 * Enable panel's APM -- not sure why the stock
++		 * X server code explicitly disables this.
++		 * Steve Hsieh <http://www.eecs.umich.edu/~steveh/inspiron/>
++		 */
++		outl(ioLCD_DATA, old_POWER_MANAGEMENT | PWR_MGT_ON);
+ 		if ((mach64ChipType != MACH64_LB_ID) &&
+ 		    (mach64ChipType != MACH64_LD_ID) &&
+ 		    (mach64ChipType != MACH64_LI_ID) &&
--- xfree86-1-3.3.6.orig/debian/patches/056_XLC_LOCALE_zh_CN+zh_HK_Imakefile.diff
+++ xfree86-1-3.3.6/debian/patches/056_XLC_LOCALE_zh_CN+zh_HK_Imakefile.diff
@@ -0,0 +1,12 @@
+--- xc.old/nls/XLC_LOCALE/Imakefile	Mon Jul 26 15:33:16 1999
++++ xc/nls/XLC_LOCALE/Imakefile	Mon Jun  5 23:57:02 2000
+@@ -66,6 +66,9 @@
+ LTarget(ko)
+ LTarget(koi8-r)
+ LTarget(zh)
++LTarget(zh_CN.GBK)
++LTarget(zh_HK.Big5)
++LTarget(zh_HK.Big5HKSCS)
+ LTarget(zh_TW)
+ LTarget(zh_TW.Big5)
+ LTarget(th_TH.TACTIS)
--- xfree86-1-3.3.6.orig/debian/patches/059_locale.alias_zh_CN.GBK.diff
+++ xfree86-1-3.3.6/debian/patches/059_locale.alias_zh_CN.GBK.diff
@@ -0,0 +1,13 @@
+--- xc.old/nls/locale.alias	Wed Jun  2 15:50:05 1999
++++ xc/nls/locale.alias	Wed Nov 10 14:00:14 1999
+@@ -315,8 +315,8 @@
+ tr						tr_TR.ISO8859-9
+ tr_TR						tr_TR.ISO8859-9
+ tr_TR.iso88599					tr_TR.ISO8859-9
+-zh						zh_CN.eucCN
+-zh_CN						zh_CN.eucCN
++XCOMM	zh						zh_CN.eucCN
++zh_CN						zh_CN.GBK
+ zh_CN.EUC					zh_CN.eucCN
+ zh_TW						zh_TW.eucTW
+ zh_TW.EUC					zh_TW.eucTW
--- xfree86-1-3.3.6.orig/debian/patches/010-01_upstream_patch_89.diff
+++ xfree86-1-3.3.6/debian/patches/010-01_upstream_patch_89.diff
@@ -0,0 +1,499 @@
+diff -u xc/programs/xterm/charproc.c.orig xc/programs/xterm/charproc.c
+--- xc/programs/xterm/charproc.c.orig	Fri Jul 30 09:12:10 1999
++++ xc/programs/xterm/charproc.c	Sun Jun 11 20:31:39 2000
+@@ -4419,7 +4419,7 @@
+ 		}
+ 	}
+ 
+-	TRACE(("%s @%d, calling drawXtermText\n", __FILE__, __LINE__))
++	TRACE(("%s @%d, ShowCursor calling drawXtermText\n", __FILE__, __LINE__))
+ 
+ 	drawXtermText(screen, flags, currentGC,
+ 		x = CurCursorX(screen, screen->cur_row, screen->cur_col),
+@@ -4485,11 +4485,11 @@
+ 	if (c == 0)
+ 		c = ' ';
+ 
+-	TRACE(("%s @%d, calling drawXtermText\n", __FILE__, __LINE__))
++	TRACE(("%s @%d, HideCursor calling drawXtermText\n", __FILE__, __LINE__))
+ 	drawXtermText(screen, flags, currentGC,
+-		CursorX(screen, screen->cursor_col),
++		CurCursorX(screen, screen->cursor_row, screen->cursor_col),
+ 		CursorY(screen, screen->cursor_row),
+-		curXtermChrSet(screen->cur_row),
++		curXtermChrSet(screen->cursor_row),
+ 		&c, 1);
+ 
+ 	screen->cursor_state = OFF;
+diff -u xc/programs/xterm/doublechr.c.orig xc/programs/xterm/doublechr.c
+--- xc/programs/xterm/doublechr.c.orig	Sat Oct 24 03:58:25 1998
++++ xc/programs/xterm/doublechr.c	Sun Jun 11 20:31:39 2000
+@@ -36,6 +36,7 @@
+ 
+ #include <xterm.h>
+ #include <data.h>
++#include <fontutils.h>
+ 
+ /*
+  * The first column is all that matters for double-size characters (since the
+@@ -50,10 +51,19 @@
+ {
+ 	register TScreen *screen = &term->screen;
+ 	int curcol = screen->cur_col;
++	int currow = screen->cur_row;
+ 	int len = screen->max_col + 1;
+ 	int width = len;
++	unsigned oldChrSet = SCRN_BUF_CSETS(screen, currow)[0];
+ 
+-	TRACE(("repaint_line(%2d,%2d) (%d)\n", screen->cur_row, screen->cur_col, newChrSet))
++	/*
++	 * Ignore repetition.
++	 */
++	if (oldChrSet == newChrSet)
++		return;
++
++	TRACE(("repaint_line(%2d,%2d) (%d)\n", currow, screen->cur_col, newChrSet))
++	HideCursor();
+ 
+ 	/* If switching from single-width, keep the cursor in the visible part
+ 	 * of the line.
+@@ -64,11 +74,24 @@
+ 			curcol = width;
+ 	}
+ 
++	/*
++	 * ScrnRefresh won't paint blanks for us if we're switching between a
++	 * single-size and double-size font.
++	 */
++	if (CSET_DOUBLE(oldChrSet) != CSET_DOUBLE(newChrSet)) {
++		ClearCurBackground(
++			screen,
++			CursorY (screen, currow),
++			CurCursorX (screen, currow, 0),
++			FontHeight(screen),
++			len * CurFontWidth(screen,currow));
++	}
++
+ 	/* FIXME: do VT220 softchars allow double-sizes? */
+-	memset(SCRN_BUF_CSETS(screen, screen->cur_row), newChrSet, len);
++	memset(SCRN_BUF_CSETS(screen, currow), newChrSet, len);
+ 
+ 	screen->cur_col = 0;
+-	ScrnRefresh (screen, screen->cur_row, 0, 1, len, True);
++	ScrnRefresh (screen, currow, 0, 1, len, True);
+ 	screen->cur_col = curcol;
+ }
+ #endif
+@@ -106,3 +129,53 @@
+ 	repaint_line(CSET_DWL);
+ #endif
+ }
++
++
++#if OPT_DEC_CHRSET
++/*
++ * Lookup/cache a GC for the double-size character display.  We save up to
++ * NUM_CHRSET values.
++ */
++GC
++xterm_DoubleGC(unsigned chrset, unsigned flags, GC old_gc)
++{
++	XGCValues gcv;
++	register TScreen *screen = &term->screen;
++	unsigned long mask = (GCForeground | GCBackground | GCFont);
++	int n = (chrset % NUM_CHRSET);
++	char *name = xtermSpecialFont(flags, chrset);
++
++	if (name == 0)
++		return 0;
++
++	if (screen->double_fn[n] != 0) {
++		if (!strcmp(screen->double_fn[n], name)) {
++			if (screen->double_fs[n] != 0) {
++				XCopyGC(screen->display, old_gc, ~GCFont, screen->double_gc[n]);
++				return screen->double_gc[n];
++			}
++		}
++	}
++	screen->double_fn[n] = name;
++
++	if (screen->double_fs[n] != 0) {
++		XFreeFont(screen->display, screen->double_fs[n]);
++		screen->double_fs[n] = 0;
++	}
++
++	TRACE(("xterm_DoubleGC %s %d: %s\n", flags&BOLD ? "BOLD" : "NORM", chrset, name))
++
++	if ((screen->double_fs[n] = XLoadQueryFont (screen->display, name)) == 0)
++		return 0;
++	TRACE(("-> OK\n"))
++
++	gcv.graphics_exposures = TRUE;	/* default */
++	gcv.font       = screen->double_fs[n]->fid;
++	gcv.foreground = screen->foreground;
++	gcv.background = term->core.background_pixel;
++
++	screen->double_gc[n] = XCreateGC (screen->display, TextWindow(screen), mask, &gcv);
++	XCopyGC(screen->display, old_gc, ~GCFont, screen->double_gc[n]);
++	return screen->double_gc[n];
++}
++#endif
+diff -u xc/programs/xterm/fontutils.c.orig xc/programs/xterm/fontutils.c
+--- xc/programs/xterm/fontutils.c.orig	Sun Nov  1 10:39:03 1998
++++ xc/programs/xterm/fontutils.c	Sun Jun 11 20:31:39 2000
+@@ -121,6 +121,7 @@
+ get_font_name_props(Display *dpy, XFontStruct *fs)
+ {
+ 	static FontNameProperties props;
++	static char *last_name;
+ 
+ 	register XFontProp *fp;
+ 	register int i;
+@@ -141,6 +142,13 @@
+ 		return 0;
+ 
+ 	/*
++	 * XGetAtomName allocates memory - don't leak
++	 */
++	if (last_name != 0)
++		XFree(last_name);
++	last_name = name;
++
++	/*
+ 	* Now split it up into parts and put them in
+ 	* their places. Since we are using parts of
+ 	* the original string, we must not free the Atom Name
+@@ -222,59 +230,86 @@
+      return ret;
+ }
+ 
+-#if 0
+ #ifdef OPT_DEC_CHRSET
+ /*
+  * Take the given font props and try to make a well formed font name specifying
+- * the same base font but changed depending on the given attributes and lflags.
++ * the same base font but changed depending on the given attributes and chrset.
+  *
+  * For double width fonts, we just double the X-resolution, for double height
+  * fonts we double the pixel-size and Y-resolution
+  */
+ char *
+-special_font_name(FontNameProperties *props, unsigned char atts,
+-		  LineFlagsElem lflags)
++xtermSpecialFont(unsigned atts, unsigned chrset)
+ {
+-     char tmp[MAX_FONTNAME];
+-     char *ret;
++#if OPT_TRACE
++	static char old_spacing[80];
++	static FontNameProperties old_props;
++#endif
++	TScreen *screen = &term->screen;
++	FontNameProperties *props;
++	char tmp[MAX_FONTNAME];
++	char *ret;
++	char *width;
++	int pixel_size;
++	int res_x;
++	int res_y;
++
++	props = get_font_name_props(screen->display, screen->fnt_norm);
++	if (props == 0)
++		return 0;
++
++	pixel_size = props->pixel_size;
++	res_x = props->res_x;
++	res_y = props->res_y;
++	if (atts & BOLD)
++		width = "bold";
++	else
++		width = props->width;
++
++	if (CSET_DOUBLE(chrset))
++		res_x *= 2;
++
++	if (chrset == CSET_DHL_TOP 
++	 || chrset == CSET_DHL_BOT) {
++		res_y *= 2;
++		pixel_size *= 2;
++	}
+ 
+-     char *width;
+-     int pixel_size = props->pixel_size;
+-     int res_x = props->res_x;
+-     int res_y = props->res_y;
+-
+-     if (atts & ATT_BOLD)
+-	  width = "bold";
+-     else
+-	  width = props->width;
+-
+-     if (lflags & LINE_D_WIDE)
+-	  res_x *= 2;
+-
+-     if (lflags & (LINE_D_UPPER | LINE_D_LOWER)) {
+-	  res_x *= 2;
+-	  res_y *= 2;
+-	  pixel_size *= 2;
+-     }
++#if OPT_TRACE
++	if (old_props.res_x      != res_x
++	 || old_props.res_x      != res_y
++	 || old_props.pixel_size != pixel_size
++	 || strcmp(old_props.spacing, props->spacing)) {
++		TRACE(("xtermSpecialFont(atts = %#x, chrset = %#x)\n", atts, chrset))
++		TRACE(("res_x      = %d\n", res_x))
++		TRACE(("res_y      = %d\n", res_y))
++		TRACE(("point_size = %s\n", props->point_size))
++		TRACE(("pixel_size = %d\n", pixel_size))
++		TRACE(("spacing    = %s\n", props->spacing))
++		old_props.res_x      = res_x;
++		old_props.res_x      = res_y;
++		old_props.pixel_size = pixel_size;
++		old_props.spacing    = strcpy(old_spacing, props->spacing);
++	}
++#endif
+ 
+-     sprintf(tmp, "%s-%s-%s-%d-%s-%d-%d-%s-*-%s",
+-	     props->beginning,
+-	     width,
+-	     props->middle,
+-	     pixel_size,
+-	     props->point_size,
+-	     res_x,
+-	     res_y,
+-	     props->spacing,
+-	     props->end);
++	sprintf(tmp, "%s-%s-%s-%d-%s-%d-%d-%s-*-%s",
++		props->beginning,
++		width,
++		props->middle,
++		pixel_size,
++		props->point_size,
++		res_x,
++		res_y,
++		props->spacing,
++		props->end);
+ 
+-     ret = XtMalloc(strlen(tmp) + 1);
+-     strcpy(ret, tmp);
++	ret = XtMalloc(strlen(tmp) + 1);
++	strcpy(ret, tmp);
+ 
+-     return ret;
++	return ret;
+ }
+ #endif /* OPT_DEC_CHRSET */
+-#endif
+ 
+ /*
+  * Double-check the fontname that we asked for versus what the font server
+@@ -330,6 +365,7 @@
+ 	Bool doresize,
+ 	int fontnum)
+ {
++	/* FIXME: use XFreeFontInfo */
+ 	FontNameProperties *fp;
+ 	XFontStruct *nfs = NULL;
+ 	XFontStruct *bfs = NULL;
+diff -u xc/programs/xterm/fontutils.h.orig xc/programs/xterm/fontutils.h
+--- xc/programs/xterm/fontutils.h.orig	Tue Oct 20 17:00:14 1998
++++ xc/programs/xterm/fontutils.h	Sun Jun 11 20:31:39 2000
+@@ -43,4 +43,8 @@
+ extern void xtermUpdateFontInfo (TScreen *screen, Bool doresize);
+ extern void xtermSetCursorBox (TScreen *screen);
+ 
++#if OPT_DEC_CHRSET
++extern char *xtermSpecialFont(unsigned atts, unsigned chrset);
++#endif
++
+ #endif /* included_fontutils_h */
+diff -u xc/programs/xterm/ptyx.h.orig xc/programs/xterm/ptyx.h
+--- xc/programs/xterm/ptyx.h.orig	Fri Jul 30 09:12:21 1999
++++ xc/programs/xterm/ptyx.h	Sun Jun 11 20:31:39 2000
+@@ -425,15 +425,16 @@
+ 
+ #if OPT_DEC_CHRSET
+ #define if_OPT_DEC_CHRSET(code) code
+-	/* Use 3 bits for encoding the double high/wide sense of characters */
++	/* Use 2 bits for encoding the double high/wide sense of characters */
+ #define CSET_SWL        0
+ #define CSET_DHL_TOP    1
+ #define CSET_DHL_BOT    2
+-#define CSET_DWL        4
++#define CSET_DWL        3
++#define NUM_CHRSET      4
+ 	/* Use remaining bits for encoding the other character-sets */
+ #define CSET_NORMAL(code)  ((code) == CSET_SWL)
+ #define CSET_DOUBLE(code)  (!CSET_NORMAL(code) && !CSET_EXTEND(code))
+-#define CSET_EXTEND(code)  ((code) >= 8)
++#define CSET_EXTEND(code)  ((code) > CSET_DWL)
+ #define CurMaxCol(screen, row) \
+ 	(CSET_DOUBLE(SCRN_BUF_CSETS(screen, row)[0]) \
+ 	? (screen->max_col / 2) \
+@@ -631,6 +632,9 @@
+ #endif
+ #if OPT_DEC_CHRSET
+ 	Char		chrset;		/* character-set index & code	*/
++	XFontStruct *	double_fs[NUM_CHRSET];
++	GC		double_gc[NUM_CHRSET];
++	char *		double_fn[NUM_CHRSET];
+ #endif
+ 	int		border;		/* inner border			*/
+ 	Cursor		arrow;		/* arrow cursor			*/
+diff -u xc/programs/xterm/resize.c.orig xc/programs/xterm/resize.c
+--- xc/programs/xterm/resize.c.orig	Thu Nov 18 10:59:57 1999
++++ xc/programs/xterm/resize.c	Sun Jun 11 20:31:39 2000
+@@ -554,10 +554,8 @@
+ 			 setname, termcap);
+ #endif /* USE_TERMCAP */
+ #ifdef USE_TERMINFO
+-#ifndef SVR4
+ 		printf ("%sCOLUMNS=%d;\nLINES=%d;\nexport COLUMNS LINES;\n",
+ 			setname, cols, rows);
+-#endif /* !SVR4 */
+ #endif	/* USE_TERMINFO */
+ 
+ 	} else {		/* not Bourne shell */
+@@ -568,10 +566,8 @@
+ 			 setname, termcap);
+ #endif /* USE_TERMCAP */
+ #ifdef USE_TERMINFO
+-#ifndef SVR4
+ 		printf ("set noglob;\n%ssetenv COLUMNS '%d';\nsetenv LINES '%d';\nunset noglob;\n",
+ 			setname, cols, rows);
+-#endif /* !SVR4 */
+ #endif	/* USE_TERMINFO */
+ 	}
+ 	exit(0);
+diff -u xc/programs/xterm/util.c.orig xc/programs/xterm/util.c
+--- xc/programs/xterm/util.c.orig	Sat Oct 24 03:58:29 1998
++++ xc/programs/xterm/util.c	Sun Jun 11 20:31:39 2000
+@@ -1310,17 +1310,57 @@
+ {
+ #if OPT_DEC_CHRSET
+ 	if (CSET_DOUBLE(chrset)) {
+-		Char *temp = (Char *) malloc(2 * len);
+-		int n = 0;
++		GC gc2 = xterm_DoubleGC(chrset, flags, gc);
++
+ 		TRACE(("DRAWTEXT%c[%4d,%4d] (%d) %d:%.*s\n",
+ 			screen->cursor_state == OFF ? ' ' : '*',
+ 			y, x, chrset, len, len, text))
+-		while (len--) {
+-			temp[n++] = *text++;
+-			temp[n++] = ' ';
++
++		if (gc2 != 0) {	/* draw actual double-sized characters */
++			XRectangle rect, *rp = &rect;
++			Cardinal nr = 1;
++
++			rect.x = 0;
++			rect.y = 0;
++			rect.width = 2 * len * FontWidth(screen);
++			rect.height = FontHeight(screen);
++
++			switch (chrset) {
++			case CSET_DHL_TOP:
++				rect.y = - (rect.height / 2);
++				y -= rect.y;
++				break;
++			case CSET_DHL_BOT:
++				rect.y = (rect.height / 2);
++				y -= rect.y;
++				break;
++			default:
++				nr = 0;
++				break;
++			}
++
++			if (nr)
++				XSetClipRectangles(screen->display, gc2,
++					x, y, rp, nr, YXBanded);
++			else
++				XSetClipMask(screen->display, gc2, None);
++
++			x = drawXtermText(screen, flags, gc2,
++				x, y, 0, text, len);
++			x += len * FontWidth(screen);
++
++			TRACE(("drewtext [%4d,%4d]\n", y, x))
++
++		} else {	/* simulate double-sized characters */
++			Char *temp = (Char *) malloc(2 * len);
++			int n = 0;
++			while (len--) {
++				temp[n++] = *text++;
++				temp[n++] = ' ';
++			}
++			x = drawXtermText(screen, flags, gc, x, y, 0, temp, n);
++			free(temp);
+ 		}
+-		x = drawXtermText(screen, flags, gc, x, y, 0, temp, n);
+-		free(temp);
+ 		return x;
+ 	}
+ #endif
+diff -u xc/programs/xterm/xterm.log.html.orig xc/programs/xterm/xterm.log.html
+--- xc/programs/xterm/xterm.log.html.orig	Sun Nov  1 10:39:05 1998
++++ xc/programs/xterm/xterm.log.html	Sun Jun 11 20:31:46 2000
+@@ -41,6 +41,7 @@
+ xc/programs/Xserver/hw/xfree86).
+ 
+ <UL>
++<LI><A HREF="#xterm_89">Patch #89 - 1998/11/20 - XFree86 3.9Nm</A>
+ <LI><A HREF="#xterm_88">Patch #88 - 1998/10/31 - XFree86 3.9Nk and 3.3.2h</A>
+ <LI><A HREF="#xterm_87">Patch #87 - 1998/10/21 - XFree86 3.9Nj and 3.3.2f</A>
+ <LI><A HREF="#xterm_86">Patch #86 - 1998/10/14 - XFree86 3.9Nj and 3.3.2e</A>
+@@ -131,6 +132,37 @@
+ <LI><A HREF="#xterm_02">Patch #2 - 1996/1/7</A>
+ <LI><A HREF="#xterm_01">Patch #1 - 1996/1/6</A>
+ </UL>
++
++<H1><A NAME="xterm_89">Patch #89 - 1998/11/20 - XFree86 3.9Nm</A></H1>
++This patch completes the implementation of double-sized character support
++for the VT100 emulation, and fixes a few minor bugs:
++
++<ul>
++<li>corrected the cursor position in HideCursor, which did not multiply
++the column by two when in doublesize mode.
++This bug, which did not appear in normal use, 
++dates back to my original <a href="#xterm_44">changes</a> to partly implement
++double-sized characters.
++I noticed it when cat'ing a typescript from vttest's double-sized character
++test.
++<li>ensure that the current line is repainted when switching between
++single and double width characters.
++<li>reduce the number of bits used for double-sized character coding
++from 3 to 2, to make more room for soft-font codes.
++<li>copy newer ifdef's from the XFree86 3.3.3 release's main.c,
++which address details of glibc and powerpc.
++<li>moved definition of DECL_ERRNO in xterm.h to match XFree86 3.3.3
++<li>modify <em>resize</em> to remove the ifdef on SVr4 that suppressed
++printing the script for $LINES and $COLUMNS.
++Solaris' resize utility does this; suppressing the behavior is unnecessary.
++</ul>
++I tested the double-sized characters using vttest and the xfsft patch.
++These fonts worked reasonably well:
++<pre>
++	-bitstream-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1
++	9x15
++</pre>
++The iso8859 font does not include box characters, of course, but looks good.
+ 
+ <H1><A NAME="xterm_88">Patch #88 - 1998/10/31 - XFree86 3.9Nk and 3.3.2h</A></H1>
+ This refines my #85 patch by checking for a case where the font server
+diff -u xc/programs/xterm/xterm.man.orig xc/programs/xterm/xterm.man
+--- xc/programs/xterm/xterm.man.orig	Mon May 10 12:53:49 1999
++++ xc/programs/xterm/xterm.man	Sun Jun 11 20:31:46 2000
+@@ -58,7 +58,9 @@
+ .SH EMULATIONS
+ The VT102 emulation is fairly complete, but does not support
+ autorepeat.
+-Double-size and blinking characters are partially implemented;
++Double-size characters are displayed properly if your font server supports
++scalable fonts.
++Blinking characters are partially implemented;
+ the emulation is functional but does not have the appearance of a real VT102.
+ The VT220 emulation does not support soft fonts, it is otherwise complete.
+ .IR Termcap (5)
--- xfree86-1-3.3.6.orig/debian/patches/007_xfree86_lnx_io_arches_without_ioperm_fix.diff
+++ xfree86-1-3.3.6/debian/patches/007_xfree86_lnx_io_arches_without_ioperm_fix.diff
@@ -0,0 +1,36 @@
+--- xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c.orig	Mon May 29 16:36:14 2000
++++ xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c	Mon May 29 16:38:56 2000
+@@ -76,11 +76,13 @@
+ 
+ static int
+ KDKBDREP_ioctl_ok(int rate, int delay) {
+-#if defined(KDKBDREP) && !defined(__sparc__)
++#if defined(KDKBDREP)
++	/*  && !defined(__sparc__) */
+      /* This ioctl is defined in <linux/kd.h> but is not
+ 	implemented anywhere - must be in some m68k patches.
+ 	Cannot blindly try unimplemented ioctls on sparc64 -
+ 	the 32<->64bit transition layer does not like it. */
++	/* Debian: we'll worry about this when we built native sparc64 binaries */
+    struct kbd_repeat kbdrep_s;
+ 
+    /* don't change, just test */
+@@ -185,8 +187,7 @@
+     return;
+ 
+ 
+-#ifndef __sparc__
+-  /* The ioport way - will crash on sparc */
++#if defined(__alpha__) || defined (__i386__) /* only these arches have an ISA bus */
+ 
+   for (i = 0; i < RATE_COUNT; i++)
+     if (rate >= valid_rates[i]) {
+@@ -211,7 +212,7 @@
+   usleep(100000);
+   outb(0x60, value);
+ 
+-#endif /* ! __sparc__ */
++#endif /* __alpha__ || __i386__ */
+ 
+   return;
+ }
--- xfree86-1-3.3.6.orig/debian/patches/058_XLC_LOCALE_zh_HK.Big5_and_zh_HK.Big5HKSCS.diff
+++ xfree86-1-3.3.6/debian/patches/058_XLC_LOCALE_zh_HK.Big5_and_zh_HK.Big5HKSCS.diff
@@ -0,0 +1,230 @@
+--- xc.old/nls/XLC_LOCALE/zh_HK.Big5	Wed Dec 31 17:00:00 1969
++++ xc/nls/XLC_LOCALE/zh_HK.Big5	Tue Jun  6 00:13:22 2000
+@@ -0,0 +1,70 @@
++XCOMM 
++XCOMM  (c) 1996, X11R6 L10N for Taiwan and Big5 Encoding Project
++XCOMM 
++XCOMM  modified for X11R6.3 by Hung-Chi Chu <hcchu@r350.ee.ntu.edu.tw> 1998/01/10
++XCOMM 
++XCOMM 	XLC_FONTSET category
++XCOMM
++XCOMM $XFree86: xc/nls/XLC_LOCALE/zh_TW.Big5,v 1.1.2.2 1999/07/30 13:19:19 hohndel Exp $
++XCOMM 
++XLC_FONTSET
++XCOMM        fs0 class (7 bit ASCII)
++fs0     {
++	charset {
++		name	ISO8859-1:GL
++	}
++	font    {
++		primary	ISO8859-1:GL
++		vertical_rotate all
++	}
++}
++XCOMM        fs1 class
++fs1     {
++	charset {
++		name	BIG5-0:GLGR
++	}
++	font    {
++		primary	BIG5-0:GLGR
++		substitute BIG5-0:GLGR
++	}
++}
++END XLC_FONTSET
++
++XCOMM 
++XCOMM 	XLC_XLOCALE category
++XCOMM 
++XLC_XLOCALE
++
++encoding_name		zh_HK.Big5
++mb_cur_max		2
++state_depend_encoding	False
++
++wc_encoding_mask	\x00008000
++wc_shift_bits		8
++
++use_stdc_env		True
++force_convert_to_mb	True
++
++XCOMM 	cs0 class
++cs0	{
++	side		GL:Default
++	length		1
++	wc_encoding	\x00000000
++	ct_encoding	ISO8859-1:GL
++}
++
++XCOMM 	cs1 class
++cs1	{
++	side		none
++	length		2
++	byte1		\xa1,\xf9
++	byte2		\x40,\x7e;\xa1,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5-0:GLGR:\x1b\x25\x2f\x32\x80\x89\x42\x49\x47\x35\x2d\x30\x02
++
++	mb_conversion	[\xa140,\xf9fe]->\x2140
++	ct_conversion	[\x2140,\x79fe]->\xa140
++}
++
++END XLC_XLOCALE
+--- xc.old/nls/XLC_LOCALE/zh_HK.Big5HKSCS	Wed Dec 31 17:00:00 1969
++++ xc/nls/XLC_LOCALE/zh_HK.Big5HKSCS	Tue Jun  6 00:13:32 2000
+@@ -0,0 +1,154 @@
++XCOMM 
++XCOMM  (c) 1996, X11R6 L10N for Taiwan and Big5 Encoding Project
++XCOMM 
++XCOMM  modified for X11R6.3 by Hung-Chi Chu <hcchu@r350.ee.ntu.edu.tw> 1998/01/10
++XCOMM 
++XCOMM 	XLC_FONTSET category
++XCOMM
++XCOMM $XFree86: xc/nls/XLC_LOCALE/zh_TW.Big5,v 1.1.2.2 1999/07/30 13:19:19 hohndel Exp $
++XCOMM 
++XCOMM Modified for HKSCS by Roger So <rogerso@sis.dhs.org>
++XCOMM
++
++XLC_FONTSET
++XCOMM fs0 class (7 bit ASCII)
++fs0     {
++	charset {
++		name	ISO8859-1:GL
++	}
++	font    {
++		primary		ISO8859-1:GL
++		vertical_rotate all
++	}
++}
++XCOMM fs1 class (standard Big5)
++fs1     {
++	charset {
++		name	BIG5-0:GLGR;BIG5-1:GLGR;BIG5-2:GLGR
++	}
++	font    {
++		primary		BIG5-0:GLGR
++		substitute	BIG5-0:GLGR
++	}
++}
++XCOMM fs2 class (HKSCS extensions)
++fs2     {
++	charset {
++		name	BIG5HKSCS-0:GLGR;BIG5HKSCS-1:GLGR;BIG5HKSCS-2:GLGR
++	}
++	font    {
++		primary		BIG5HKSCS-0:GLGR
++		substitute	BIG5HKSCS-0:GLGR
++	}
++}
++END XLC_FONTSET
++
++XCOMM===========================================================
++XCOMM 
++XCOMM 	XLC_XLOCALE category
++XCOMM 
++XLC_XLOCALE
++
++encoding_name		zh_HK.Big5HKSCS
++mb_cur_max		2
++state_depend_encoding	False
++
++wc_encoding_mask	\x00008000
++wc_shift_bits		8
++
++use_stdc_env		True
++force_convert_to_mb	True
++
++cs0	{
++	side		GL:Default
++	length		1
++	wc_encoding	\x00000000
++	ct_encoding	ISO8859-1:GL
++}
++
++XCOMM standard Big5, A140-C5FE + C940-F8FE
++cs1	{
++	side		none
++	length		2
++	byte1		\xa1,\xc5;\xc9,\xf8
++	byte2		\x40,\x7e;\xa1,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5-0:GLGR:\x1b\x25\x2f\x32\x80\x89\x42\x49\x47\x35\x2d\x30\x02
++
++	mb_conversion	[\x8140,\xfefe]->\x0140
++	ct_conversion	[\x0140,\x7efe]->\x8140
++}
++
++XCOMM standard Big5, C640-C67E
++cs2	{
++	side		none
++	length		2
++	byte1		\xc6
++	byte2		\x40,\x7e
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5-1:GLGR:\x1b\x25\x2f\x32\x80\x89\x42\x49\x47\x35\x2d\x31\x02
++
++	mb_conversion	[\x8140,\xfefe]->\x0140
++	ct_conversion	[\x0140,\x7efe]->\x8140
++}
++
++XCOMM standard Big5, F940-F9D5
++cs3	{
++	side		none
++	length		2
++	byte1		\xf9
++	byte2		\x40,\xd5
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5-2:GLGR:\x1b\x25\x2f\x32\x80\x89\x42\x49\x47\x35\x2d\x32\x02
++
++	mb_conversion	[\x8140,\xfefe]->\x0140
++	ct_conversion	[\x0140,\x7efe]->\x8140
++}
++
++
++XCOMM HKSCS extensions, 8540-A0FE + C740-C8FE + FA40-FEFE
++cs4     {
++	side		none
++	length		2
++	byte1		\x85,\xa0;\xc7,\xc8;\xfa,\xfe
++	byte2		\x40,\x7e;\xa1,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5HKSCS-0:GLGR:\x1b\x25\x2f\x32\x80\x8c\x42\x49\x47\x35\x48\x4b\x53\x43\x53\x2d\x30\x02
++
++	mb_conversion	[\x8140,\xfefe]->\0x0140
++	ct_conversion	[\x0140,\x7efe]->\0x8140
++}
++
++XCOMM HKSCS extensions, C6A1-C6FE
++cs5     {
++	side		none
++	length		2
++	byte1		\xc6
++	byte2		\xa1,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5HKSCS-1:GLGR:\x1b\x25\x2f\x32\x80\x8c\x42\x49\x47\x35\x48\x4b\x53\x43\x53\x2d\x31\x02
++
++	mb_conversion	[\x8140,\xfefe]->\0x0140
++	ct_conversion	[\x0140,\x7efe]->\0x8140
++}
++
++XCOMM HKSCS extensions, F9D6-F9FE
++cs6     {
++	side		none
++	length		2
++	byte1		\xf9
++	byte2		\xd6,\xfe
++
++	wc_encoding	\x00008000
++	ct_encoding	BIG5HKSCS-2:GLGR:\x1b\x25\x2f\x32\x80\x8c\x42\x49\x47\x35\x48\x4b\x53\x43\x53\x2d\x32\x02
++
++	mb_conversion	[\x8140,\xfefe]->\0x0140
++	ct_conversion	[\x0140,\x7efe]->\0x8140
++}
++
++END XLC_XLOCALE
--- xfree86-1-3.3.6.orig/debian/patches/025_egcs_xt_motif_netscape_bug_workaround.diff
+++ xfree86-1-3.3.6/debian/patches/025_egcs_xt_motif_netscape_bug_workaround.diff
@@ -0,0 +1,16 @@
+--- xc/lib/Xt/Imakefile.orig	Fri Nov  6 14:54:31 1998
++++ xc/lib/Xt/Imakefile	Sun Jan  9 15:25:50 2000
+@@ -150,6 +150,11 @@
+ 	Vendor.c \
+ 	sharedlib.c
+ 
++#ifdef i386Architecture
++XCOMM horrible kludge to work around egcs problem that makes Motif applications (like Netscape) crash - some parts of libXt must be compiled with "gcc-2.7.2 -O2" for them to work
++Callback.o Destroy.o: CC=gcc272
++#endif
++
+ OBJS = \
+ 	$(MISCOBJS) \
+ 	ActionHook.o \
+
+
--- xfree86-1-3.3.6.orig/debian/patches/010-02_upstream_patch_90.diff
+++ xfree86-1-3.3.6/debian/patches/010-02_upstream_patch_90.diff
@@ -0,0 +1,2664 @@
+diff -u xc/programs/xterm/INSTALL.orig xc/programs/xterm/INSTALL
+--- xc/programs/xterm/INSTALL.orig	Sat Oct 24 03:58:19 1998
++++ xc/programs/xterm/INSTALL	Sun Jun 11 20:41:08 2000
+@@ -36,6 +36,7 @@
+   --disable-active-icon   disable X11R6.3 active-icon feature (default: on)
+   --disable-ansi-color    disable ANSI color (default: on)
+   --disable-bold-color    disable PC-style mapping of bold colors (default: on)
++  --disable-boxchars      disable fallback-support for box chars
+   --disable-color-mode    disable default colorMode resource (default: on)
+   --disable-doublechars   disable support for double-size chars (default: on)
+   --disable-echo          test: display "compiling" commands (default: on)
+@@ -48,6 +49,7 @@
+   --disable-tek4014       disable tek4014 emulation (default: on)
+   --disable-vt52          disable VT52 emulation (default: on)
+   --disable-ziconbeep     disable -ziconbeep option (default: on)
++  --enable-hp-fkeys       enable support for HP-style function keys (default: off)
+   --enable-logfile-exec   enable exec'd logfile filter (default: off)
+   --enable-logging        enable logging (default: off)
+   --enable-trace          test: set to enable debugging traces (default: off)
+diff -u xc/programs/xterm/Makefile.in.orig xc/programs/xterm/Makefile.in
+--- xc/programs/xterm/Makefile.in.orig	Sat Oct 24 03:58:19 1998
++++ xc/programs/xterm/Makefile.in	Sun Jun 11 20:41:08 2000
+@@ -21,7 +21,7 @@
+ EXTRA_LOADFLAGS	= @IMAKE_LOADFLAGS@
+ 
+ CPPFLAGS	= -I. -I$(srcdir) -DHAVE_CONFIG_H $(X_CFLAGS) $(IMAKE_CFLAGS)
+-CFLAGS		= @CFLAGS@ $(EXTRA_CFLAGS) 
++CFLAGS		= @CFLAGS@ $(EXTRA_CFLAGS)
+ LIBS		= @LIBS@
+ 
+ prefix		= @prefix@
+@@ -37,7 +37,7 @@
+ SHELL		= /bin/sh
+ RM              = rm -f
+ 
+-LDFLAGS		= 
++LDFLAGS		=
+ 
+ INSTALL_DIRS    = $(bindir) $(libdir) $(mandir)
+ 
+@@ -77,7 +77,7 @@
+ 
+ main.o: version.h
+ 
+-$(OBJS1) : ptyx.h
++$(OBJS1) : ptyx.h xtermcfg.h
+ 
+ xterm : $(OBJS1)
+ 	@ECHO_LD@$(LINK) $(LDFLAGS) -o $@ $(OBJS1) $(X_LIBS) $(X_EXTRA_LIBS) $(LIBS) $(EXTRA_LOADFLAGS)
+diff -u xc/programs/xterm/XTerm.ad.orig xc/programs/xterm/XTerm.ad
+--- xc/programs/xterm/XTerm.ad.orig	Sat Oct 24 03:58:21 1998
++++ xc/programs/xterm/XTerm.ad	Sun Jun 11 20:41:08 2000
+@@ -25,6 +25,7 @@
+ *mainMenu*backarrow key*Label: Backarrow Key
+ *mainMenu*sun function-keys*Label: Sun Function-Keys
+ *mainMenu*sun keyboard*Label: Sun/PC Keyboard
++*mainMenu*hp function-keys*Label: HP Function-Keys
+ *mainMenu*suspend*Label:  Send STOP Signal
+ *mainMenu*continue*Label:  Send CONT Signal
+ *mainMenu*interrupt*Label:  Send INT Signal
+@@ -48,7 +49,7 @@
+ *vtMenu*cursesemul*Label:  Enable Curses Emulation
+ *vtMenu*visualbell*Label:  Enable Visual Bell
+ *vtMenu*marginbell*Label:  Enable Margin Bell
+-*vtMenu*altscreen*Label:  Show Alternate Screen
++*vtMenu*titeInhibit*Label:  Enable Alternate Screen Switching
+ *vtMenu*activeicon*Label: Enable Active Icon
+ *vtMenu*softreset*Label:  Do Soft Reset
+ *vtMenu*hardreset*Label:  Do Full Reset
+@@ -56,6 +57,7 @@
+ *vtMenu*tekshow*Label:  Show Tek Window
+ *vtMenu*tekmode*Label:  Switch to Tek Mode
+ *vtMenu*vthide*Label:  Hide VT Window
++*vtMenu*altscreen*Label:  Show Alternate Screen
+ 
+ *fontMenu.Label:  VT Fonts
+ *fontMenu*fontdefault*Label:	Default
+@@ -75,6 +77,8 @@
+ *fontMenu*fontescape*Label:	Escape Sequence
+ *fontMenu*fontsel*Label:		Selection
+ !fontescape and fontsel overridden by application
++*fontMenu*font-doublesize*Label: Doublesized Characters
++*fontMenu*font-loadable*Label:	VT220 Soft Fonts
+ 
+ *tekMenu.Label:  Tek Options
+ *tekMenu*tektextlarge*Label:  Large Characters
+diff -u xc/programs/xterm/charproc.c.orig xc/programs/xterm/charproc.c
+--- xc/programs/xterm/charproc.c.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/charproc.c	Sun Jun 11 20:45:46 2000
+@@ -145,6 +145,7 @@
+ 
+ #define XtNallowSendEvents	"allowSendEvents"
+ #define XtNalwaysHighlight	"alwaysHighlight"
++#define XtNanswerbackString	"answerbackString"
+ #define XtNappcursorDefault	"appcursorDefault"
+ #define XtNappkeypadDefault	"appkeypadDefault"
+ #define XtNautoWrap		"autoWrap"
+@@ -189,10 +190,17 @@
+ #define XtNeightBitControl	"eightBitControl"
+ #define XtNeightBitInput	"eightBitInput"
+ #define XtNeightBitOutput	"eightBitOutput"
++#define XtNfontDoublesize       "fontDoublesize"
++#define XtNgeometry		"geometry"
++#define XtNhighlightColor	"highlightColor"
+ #define XtNhighlightSelection	"highlightSelection"
+ #define XtNhpLowerleftBugCompat	"hpLowerleftBugCompat"
+ #define XtNinternalBorder	"internalBorder"
+ #define XtNjumpScroll		"jumpScroll"
++#define XtNkeyboardDialect      "keyboardDialect"
++#define XtNlogFile		"logFile"
++#define XtNlogInhibit		"logInhibit"
++#define XtNlogging		"logging"
+ #define XtNloginShell		"loginShell"
+ #define XtNmarginBell		"marginBell"
+ #define XtNmultiClickTime	"multiClickTime"
+@@ -230,22 +238,9 @@
+ #define XtNxmcInline		"xmcInline"
+ #define XtNxmcMoveSGR		"xmcMoveSGR"
+ 
+-#ifdef ALLOWLOGGING
+-#define XtNlogFile		"logFile"
+-#define XtNlogInhibit		"logInhibit"
+-#define XtNlogging		"logging"
+-#endif
+-
+-#ifdef NO_ACTIVE_ICON
+-#define XtNgeometry		"geometry"
+-#endif
+-
+-#if OPT_HIGHLIGHT_COLOR
+-#define XtNhighlightColor	"highlightColor"
+-#endif
+-
+ #define XtCAllowSendEvents	"AllowSendEvents"
+ #define XtCAlwaysHighlight	"AlwaysHighlight"
++#define XtCAnswerbackString	"AnswerbackString"
+ #define XtCAppcursorDefault	"AppcursorDefault"
+ #define XtCAppkeypadDefault	"AppkeypadDefault"
+ #define XtCAutoWrap		"AutoWrap"
+@@ -266,9 +261,14 @@
+ #define XtCEightBitControl	"EightBitControl"
+ #define XtCEightBitInput	"EightBitInput"
+ #define XtCEightBitOutput	"EightBitOutput"
++#define XtCFontDoublesize       "FontDoublesize"
++#define XtCGeometry		"Geometry"
+ #define XtCHighlightSelection	"HighlightSelection"
+ #define XtCHpLowerleftBugCompat	"HpLowerleftBugCompat"
+ #define XtCJumpScroll		"JumpScroll"
++#define XtCLogInhibit		"LogInhibit"
++#define XtCLogfile		"Logfile"
++#define XtCLogging		"Logging"
+ #define XtCLoginShell		"LoginShell"
+ #define XtCMarginBell		"MarginBell"
+ #define XtCMultiClickTime	"MultiClickTime"
+@@ -299,16 +299,7 @@
+ #define XtCXmcGlitch		"XmcGlitch"
+ #define XtCXmcInline		"XmcInline"
+ #define XtCXmcMoveSGR		"XmcMoveSGR"
+-
+-#ifdef ALLOWLOGGING
+-#define XtCLogInhibit		"LogInhibit"
+-#define XtCLogfile		"Logfile"
+-#define XtCLogging		"Logging"
+-#endif
+-
+-#ifdef NO_ACTIVE_ICON
+-#define XtCGeometry		"Geometry"
+-#endif
++#define XtCkeyboardDialect      "KeyboardDialect"
+ 
+ #define	doinput()		(bcnt-- > 0 ? *bptr++ : in_put())
+ 
+@@ -340,7 +331,10 @@
+  */
+ 
+ /* Defaults */
++#define DFT_KBD_DIALECT "B"
++#if OPT_ISO_COLORS
+ static  Boolean	defaultCOLORMODE   = DFT_COLORMODE;
++#endif
+ static  Boolean	defaultFALSE	   = FALSE;
+ static  Boolean	defaultTRUE	   = TRUE;
+ static  int	defaultZERO        = 0;
+@@ -350,7 +344,7 @@
+ static  int	defaultNMarginBell = N_MARGINBELL;
+ static  int	defaultMultiClickTime = MULTICLICKTIME;
+ static  int	defaultBellSuppressTime = BELLSUPPRESSMSEC;
+-static	int	default_DECID = DFT_DECID;
++static	int	default_DECID      = DFT_DECID;
+ static	char *	_Font_Selected_ = "yes";  /* string is arbitrary */
+ 
+ #if OPT_BLINK_CURS
+@@ -398,58 +392,71 @@
+ ";
+ 
+ static XtActionsRec actionsList[] = {
++    { "allow-send-events",	HandleAllowSends },
+     { "bell",			HandleBell },
++    { "clear-saved-lines",	HandleClearSavedLines },
+     { "create-menu",		HandleCreateMenu },
++    { "dired-button",		DiredButton },
++    { "hard-reset",		HandleHardReset },
+     { "ignore", 		HandleIgnore },
+     { "insert", 		HandleKeyPressed },  /* alias for insert-seven-bit */
+-    { "insert-seven-bit",	HandleKeyPressed },
+     { "insert-eight-bit",	HandleEightBitKeyPressed },
+     { "insert-selection",	HandleInsertSelection },
++    { "insert-seven-bit",	HandleKeyPressed },
+     { "keymap", 		HandleKeymapChange },
+     { "popup-menu",		HandlePopupMenu },
++    { "print", 			HandlePrint },
++    { "quit",			HandleQuit },
++    { "redraw", 		HandleRedraw },
++    { "scroll-back",		HandleScrollBack },
++    { "scroll-forw",		HandleScrollForward },
+     { "secure", 		HandleSecure },
+-    { "select-start",		HandleSelectStart },
+-    { "select-extend",		HandleSelectExtend },
++    { "select-cursor-end",	HandleKeyboardSelectEnd },
++    { "select-cursor-start",	HandleKeyboardSelectStart },
+     { "select-end",		HandleSelectEnd },
++    { "select-extend",		HandleSelectExtend },
+     { "select-set",		HandleSelectSet },
+-    { "select-cursor-start",	HandleKeyboardSelectStart },
+-    { "select-cursor-end",	HandleKeyboardSelectEnd },
+-    { "set-vt-font",		HandleSetFont },
+-    { "start-extend",		HandleStartExtend },
+-    { "start-cursor-extend",	HandleKeyboardStartExtend },
+-    { "string", 		HandleStringEvent },
+-    { "scroll-forw",		HandleScrollForward },
+-    { "scroll-back",		HandleScrollBack },
+-    /* menu actions */
+-    { "allow-send-events",	HandleAllowSends },
+-    { "set-visual-bell",	HandleSetVisualBell },
+-#ifdef ALLOWLOGGING
+-    { "set-logging",		HandleLogging },
+-#endif
+-    { "print", 			HandlePrint },
+-    { "redraw", 		HandleRedraw },
++    { "select-start",		HandleSelectStart },
+     { "send-signal",		HandleSendSignal },
+-    { "quit",			HandleQuit },
+     { "set-8-bit-control",	Handle8BitControl },
++    { "set-allow132",		HandleAllow132 },
++    { "set-altscreen",		HandleAltScreen },
++    { "set-appcursor",		HandleAppCursor },
++    { "set-appkeypad",		HandleAppKeypad },
++    { "set-autolinefeed",	HandleAutoLineFeed },
++    { "set-autowrap",		HandleAutoWrap },
+     { "set-backarrow",		HandleBackarrow },
+-    { "set-sun-function-keys",	HandleSunFunctionKeys },
+-    { "set-scrollbar",		HandleScrollbar },
++    { "set-cursesemul", 	HandleCursesEmul },
+     { "set-jumpscroll", 	HandleJumpscroll },
++    { "set-marginbell", 	HandleMarginBell },
+     { "set-reverse-video",	HandleReverseVideo },
+-    { "set-autowrap",		HandleAutoWrap },
+     { "set-reversewrap",	HandleReverseWrap },
+-    { "set-autolinefeed",	HandleAutoLineFeed },
+-    { "set-appcursor",		HandleAppCursor },
+-    { "set-appkeypad",		HandleAppKeypad },
+     { "set-scroll-on-key",	HandleScrollKey },
+     { "set-scroll-on-tty-output", HandleScrollTtyOutput },
+-    { "set-allow132",		HandleAllow132 },
+-    { "set-cursesemul", 	HandleCursesEmul },
+-    { "set-marginbell", 	HandleMarginBell },
+-    { "set-altscreen",		HandleAltScreen },
++    { "set-scrollbar",		HandleScrollbar },
++    { "set-sun-function-keys",	HandleSunFunctionKeys },
++    { "set-sun-keyboard",	HandleSunKeyboard },
++    { "set-titeInhibit",	HandleTiteInhibit },
++    { "set-visual-bell",	HandleSetVisualBell },
++    { "set-vt-font",		HandleSetFont },
+     { "soft-reset",		HandleSoftReset },
+-    { "hard-reset",		HandleHardReset },
+-    { "clear-saved-lines",	HandleClearSavedLines },
++    { "start-cursor-extend",	HandleKeyboardStartExtend },
++    { "start-extend",		HandleStartExtend },
++    { "string", 		HandleStringEvent },
++    { "vi-button",		ViButton },
++    { "visual-bell",		HandleVisualBell },
++#ifdef ALLOWLOGGING
++    { "set-logging",		HandleLogging },
++#endif
++#if OPT_DEC_CHRSET
++    { "set-font-doublesize",	HandleFontDoublesize },
++#endif
++#if OPT_DEC_SOFTFONT
++    { "set-font-loading",	HandleFontLoading },
++#endif
++#if OPT_HP_FUNC_KEYS
++    { "set-hp-function-keys",	HandleHpFunctionKeys },
++#endif
+ #if OPT_TEK4014
+     { "set-terminal-type",	HandleSetTerminalType },
+     { "set-visibility", 	HandleVisibility },
+@@ -458,9 +465,6 @@
+     { "tek-reset",		HandleTekReset },
+     { "tek-copy",		HandleTekCopy },
+ #endif
+-    { "visual-bell",		HandleVisualBell },
+-    { "dired-button",		DiredButton },
+-    { "vi-button",		ViButton },
+ };
+ 
+ static XtResource resources[] = {
+@@ -519,6 +523,9 @@
+ 	XtOffsetOf(XtermWidgetRec, screen.cursor_blink),
+         XtRInt, (XtPointer) &defaultBlinkTime},
+ #endif
++{XtNkeyboardDialect, XtCkeyboardDialect, XtRString, sizeof(String),
++	XtOffsetOf(XtermWidgetRec, screen.keyboard_dialect),
++	XtRString, (XtPointer) DFT_KBD_DIALECT},
+ {XtNeightBitInput, XtCEightBitInput, XtRBoolean, sizeof(Boolean),
+ 	XtOffsetOf(XtermWidgetRec, screen.input_eight_bits),
+ 	XtRBoolean, (XtPointer) &defaultTRUE},
+@@ -584,6 +591,9 @@
+ {XtNpointerShape,XtCCursor, XtRCursor, sizeof(Cursor),
+ 	XtOffsetOf(XtermWidgetRec, screen.pointer_cursor),
+ 	XtRString, (XtPointer) "xterm"},
++{XtNanswerbackString,XtCAnswerbackString, XtRString, sizeof(String),
++	XtOffsetOf(XtermWidgetRec, screen.answer_back),
++	XtRString, (XtPointer) DFT_TERMTYPE},
+ #ifdef OPT_PRINT_COLORS
+ {XtNprintAttributes,XtCPrintAttributes, XtRInt, sizeof(int),
+ 	XtOffsetOf(XtermWidgetRec, screen.print_attributes),
+@@ -689,6 +699,11 @@
+ {"font6", "Font6", XtRString, sizeof(String),
+ 	XtOffsetOf(XtermWidgetRec, screen.menu_font_names[fontMenu_font6]),
+ 	XtRString, (XtPointer) NULL},
++#if OPT_DEC_CHRSET
++{XtNfontDoublesize, XtCFontDoublesize, XtRBoolean, sizeof(Boolean),
++	XtOffsetOf(XtermWidgetRec, screen.font_doublesize),
++	XtRBoolean, (XtPointer) &defaultTRUE},
++#endif
+ #if OPT_INPUT_METHOD
+ {XtNinputMethod, XtCInputMethod, XtRString, sizeof(char*),
+ 	XtOffsetOf(XtermWidgetRec, misc.input_method),
+@@ -965,6 +980,7 @@
+ void resetCharsets(TScreen *screen)
+ {
+ 	screen->gsets[0] = 'B';			/* ASCII_G		*/
++	screen->gsets[0] = screen->keyboard_dialect[0]; /* e.g., ASCII_G */
+ 	screen->gsets[1] = '0';			/* line drawing		*/
+ 	screen->gsets[2] = 'B';			/* DEC supplemental.	*/
+ 	screen->gsets[3] = 'B';
+@@ -1023,7 +1039,7 @@
+ 		} else if (string_used+1 >= string_size) {
+ 			string_size += string_size;
+ 			string_area = (Char *)realloc(string_area, string_size);
+-			if (string_area == NULL) 
++			if (string_area == NULL)
+ 			    SysError(ERROR_VTREALLOC);
+ 		}
+ 		string_area[string_used++] = c;
+@@ -1116,10 +1132,8 @@
+ 			break;
+ 
+ 		 case CASE_ENQ:
+-#if 0
+-			for (count = 0; xterm_name[count] != 0; count++)
+-				unparseputc(xterm_name[count], screen->respond);
+-#endif
++			for (count = 0; screen->answer_back[count] != 0; count++)
++				unparseputc(screen->answer_back[count], screen->respond);
+ 			break;
+ 
+ 		 case CASE_BELL:
+@@ -1805,13 +1819,13 @@
+ 
+ 		 case CASE_DECSC:
+ 			/* DECSC */
+-			CursorSave(term, &screen->sc);
++			CursorSave(term);
+ 			parsestate = groundtable;
+ 			break;
+ 
+ 		 case CASE_DECRC:
+ 			/* DECRC */
+-			CursorRestore(term, &screen->sc);
++			CursorRestore(term);
+ 			if_OPT_ISO_COLORS(screen,{setExtendedFG();})
+ 			parsestate = groundtable;
+ 			break;
+@@ -2835,6 +2849,18 @@
+ #endif /* ALLOWLOGFILEONOFF */
+ 			break;
+ #endif
++		case 1049:		/* alternate buffer & cursor */
++			if (!termw->misc.titeInhibit) {
++			    if(func == bitset) {
++				CursorSave(termw);
++				ToAlternate(screen);
++				ClearScreen(screen);
++			    } else {
++				FromAlternate(screen);
++				CursorRestore(termw);
++			    }
++			}
++			break;
+ 		case 1047:
+ 		case 47:		/* alternate buffer */
+ 			if (!termw->misc.titeInhibit) {
+@@ -2880,9 +2906,9 @@
+ 		case 1048:
+ 			if (!termw->misc.titeInhibit) {
+ 		        	if(func == bitset)
+-					CursorSave(termw, &screen->sc);
++					CursorSave(termw);
+ 				else
+-					CursorRestore(termw, &screen->sc);
++					CursorRestore(termw);
+ 			}
+ 			break;
+ 		}
+@@ -2956,7 +2982,7 @@
+ 			break;
+ 		case 1048:
+ 			if (!termw->misc.titeInhibit) {
+-				CursorSave(termw, &screen->sc);
++				CursorSave(termw);
+ 			}
+ 			break;
+ 		}
+@@ -3071,7 +3097,7 @@
+ 			break;
+ 		case 1048:
+ 			if (!termw->misc.titeInhibit) {
+-				CursorRestore(termw, &screen->sc);
++				CursorRestore(termw);
+ 			}
+ 			break;
+ 		}
+@@ -3362,6 +3388,7 @@
+ {
+ 	if(screen->alternate)
+ 		return;
++	TRACE(("ToAlternate\n"))
+ 	if(!screen->altbuf)
+ 		screen->altbuf = Allocate(screen->max_row + 1, screen->max_col
+ 		 + 1, &screen->abuf_address);
+@@ -3375,6 +3402,7 @@
+ {
+ 	if(!screen->alternate)
+ 		return;
++	TRACE(("FromAlternate\n"))
+ 	screen->alternate = FALSE;
+ 	SwitchBufs(screen);
+ 	update_altscreen();
+@@ -3737,6 +3765,8 @@
+    wnew->screen.always_highlight = request->screen.always_highlight;
+    wnew->screen.pointer_cursor = request->screen.pointer_cursor;
+ 
++   wnew->screen.answer_back = request->screen.answer_back;
++
+    wnew->screen.printer_command = request->screen.printer_command;
+    wnew->screen.printer_autoclose = request->screen.printer_autoclose;
+    wnew->screen.printer_extent = request->screen.printer_extent;
+@@ -3746,6 +3776,7 @@
+    wnew->screen.print_attributes = request->screen.print_attributes;
+ #endif
+ 
++   wnew->screen.keyboard_dialect = request->screen.keyboard_dialect;
+    wnew->screen.input_eight_bits = request->screen.input_eight_bits;
+    wnew->screen.output_eight_bits = request->screen.output_eight_bits;
+    wnew->screen.control_eight_bits = request->screen.control_eight_bits;
+@@ -3765,6 +3796,10 @@
+    wnew->screen.menu_font_names[fontMenu_fontsel] = NULL;
+    wnew->screen.menu_font_number = fontMenu_fontdefault;
+ 
++#if OPT_DEC_CHRSET
++   wnew->screen.font_doublesize = request->screen.font_doublesize;
++#endif
++
+ #if OPT_ISO_COLORS
+    wnew->screen.boldColors    = request->screen.boldColors;
+    wnew->screen.colorAttrMode = request->screen.colorAttrMode;
+@@ -4005,19 +4040,7 @@
+ 	    XGCValues xgcv;
+ 
+ 	    XtVaGetValues(shell, XtNiconX, &iconX, XtNiconY, &iconY, NULL);
+-	    screen->iconVwin.f_width = screen->fnt_icon->max_bounds.width;
+-	    screen->iconVwin.f_height = (screen->fnt_icon->ascent +
+-					 screen->fnt_icon->descent);
+-
+-	    screen->iconVwin.width =
+-		(screen->max_col + 1) * screen->iconVwin.f_width;
+-	    screen->iconVwin.fullwidth = screen->iconVwin.width +
+-		2 * screen->border;
+-
+-	    screen->iconVwin.height =
+-		(screen->max_row + 1) * screen->iconVwin.f_height;
+-	    screen->iconVwin.fullheight = screen->iconVwin.height +
+-		2 * screen->border;
++	    xtermComputeFontInfo (screen, &(screen->iconVwin), screen->fnt_icon, 0);
+ 
+ 	    /* since only one client is permitted to select for Button
+ 	     * events, we have to let the window manager get 'em...
+@@ -4084,7 +4107,7 @@
+ 	screen->bot_marg = screen->max_row = Height(screen) /
+ 				screen->fullVwin.f_height - 1;
+ 
+-	screen->sc.row = screen->sc.col = screen->sc.flags = 0;
++	memset(screen->sc, 0, sizeof(screen->sc));
+ 
+ 	/* Mark screen buffer as unallocated.  We wait until the run loop so
+ 	   that the child process does not fork and exec with all the dynamic
+@@ -4105,7 +4128,7 @@
+ 		screen->fullVwin.scrollbar = 0;
+ 		ScrollBarOn (term, FALSE, TRUE);
+ 	}
+-	CursorSave (term, &screen->sc);
++	CursorSave (term);
+ 	return;
+ }
+ 
+@@ -4627,7 +4650,7 @@
+ 				xevents();
+ 		}
+ 		CursorSet(screen, 0, 0, term->flags);
+-		CursorSave(term, &screen->sc);
++		CursorSave(term);
+ 	} else {	/* DECSTR */
+ 		/*
+ 		 * There's a tiny difference, to accommodate usage of xterm.
+@@ -4644,9 +4667,8 @@
+ 		update_autowrap();
+ 		update_reversewrap();
+ 
+-		CursorSave(term, &screen->sc);
+-		screen->sc.row =
+-		screen->sc.col = 0;
++		CursorSave(term);
++		memset(screen->sc, 0, sizeof(screen->sc));
+ 	}
+ 	longjmp(vtjmpbuf, 1);	/* force ground state in parser */
+ }
+diff -u xc/programs/xterm/config.sub.orig xc/programs/xterm/config.sub
+--- xc/programs/xterm/config.sub.orig	Sat Apr 24 04:20:44 1999
++++ xc/programs/xterm/config.sub	Sun Jun 11 20:41:11 2000
+@@ -412,6 +412,14 @@
+ 		basic_machine=mips-unknown
+ 		os=-linux-gnu
+ 		;;
++	mipsel*-linux*)
++		basic_machine=mipsel-unknown
++		os=-linux-gnu
++		;;
++	mips*-linux*)
++		basic_machine=mips-unknown
++		os=-linux-gnu
++		;;
+ 	mips3*-*)
+ 		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+ 		;;
+@@ -585,6 +593,12 @@
+ 	tx39el)
+ 		basic_machine=mipstx39el-unknown
+ 		;;
++	tx39)
++		basic_machine=mipstx39-unknown
++		;;
++	tx39el)
++		basic_machine=mipstx39el-unknown
++		;;
+ 	tower | tower-32)
+ 		basic_machine=m68k-ncr
+ 		;;
+@@ -839,6 +853,9 @@
+ 		;;
+ 	*-be)
+ 		os=-beos
++		;;
++	s390-ibm)
++		os=-os390  #  /* S/390 -- gil -- 1451 */
+ 		;;
+ 	s390-ibm)
+ 		os=-os390  #  /* S/390 -- gil -- 1451 */
+diff -u xc/programs/xterm/configure.in.orig xc/programs/xterm/configure.in
+--- xc/programs/xterm/configure.in.orig	Fri Jul 30 09:12:16 1999
++++ xc/programs/xterm/configure.in	Sun Jun 11 20:41:14 2000
+@@ -224,6 +224,24 @@
+ 	AC_DEFINE(OPT_INITIAL_ERASE,0)
+ fi
+ 
++AC_MSG_CHECKING(if you want fallback-support for box characters)
++CF_ARG_DISABLE(boxchars,
++	[  --disable-boxchars      disable fallback-support for box chars],
++	[enable_boxchars=no],
++	[enable_boxchars=yes])
++AC_MSG_RESULT($enable_boxchars)
++test $enable_boxchars = no && AC_DEFINE(OPT_BOX_CHARS,0)
++
++AC_MSG_CHECKING(if you want support for HP-style function keys)
++CF_ARG_ENABLE(hp-fkeys,
++	[  --enable-hp-fkeys       enable support for HP-style function keys],
++	[enable_hp_fkeys=yes],
++	[enable_hp_fkeys=no])
++AC_MSG_RESULT($enable_hp_fkeys)
++if test $enable_hp_fkeys = yes ; then
++	AC_DEFINE(OPT_HP_FUNC_KEYS,1)
++fi
++
+ AC_MSG_CHECKING(if you want support for input-method)
+ CF_ARG_DISABLE(input-method,
+ 	[  --disable-input-method  disable input-method],
+diff -u xc/programs/xterm/cursor.c.orig xc/programs/xterm/cursor.c
+--- xc/programs/xterm/cursor.c.orig	Sat Oct 24 03:58:24 1998
++++ xc/programs/xterm/cursor.c	Sun Jun 11 20:41:14 2000
+@@ -107,7 +107,7 @@
+ 	_CheckSelection(screen);
+ }
+ 
+-/* 
++/*
+  * moves the cursor down n, no scrolling.
+  * Won't pass bottom margin or bottom of screen.
+  */
+@@ -126,7 +126,7 @@
+ 	_CheckSelection(screen);
+ }
+ 
+-/* 
++/*
+  * moves the cursor up n, no linestarving.
+  * Won't pass top margin or top of screen.
+  */
+@@ -145,7 +145,7 @@
+ 	_CheckSelection(screen);
+ }
+ 
+-/* 
++/*
+  * Moves cursor down amount lines, scrolls if necessary.
+  * Won't leave scrolling region. No carriage return.
+  */
+@@ -154,7 +154,7 @@
+ {
+ 	register int j;
+ 
+-	/* 
++	/*
+ 	 * indexing when below scrolling region is cursor down.
+ 	 * if cursor high enough, no scrolling necessary.
+ 	 */
+@@ -205,9 +205,10 @@
+  * Save Cursor and Attributes
+  */
+ void
+-CursorSave(register XtermWidget tw, register SavedCursor *sc)
++CursorSave(register XtermWidget tw)
+ {
+ 	register TScreen *screen = &tw->screen;
++	register SavedCursor *sc = &screen->sc[screen->alternate != False];
+ 
+ 	sc->saved = True;
+ 	sc->row = screen->cur_row;
+@@ -233,9 +234,10 @@
+  * Restore Cursor and Attributes
+  */
+ void
+-CursorRestore(register XtermWidget tw, register SavedCursor *sc)
++CursorRestore(register XtermWidget tw)
+ {
+ 	register TScreen *screen = &tw->screen;
++	register SavedCursor *sc = &screen->sc[screen->alternate != False];
+ 
+ 	/* Restore the character sets, unless we never did a save-cursor op.
+ 	 * In that case, we'll reset the character sets.
+@@ -270,7 +272,7 @@
+ CursorNextLine(TScreen *screen, int count)
+ {
+ 	CursorDown(screen, count < 1 ? 1 : count);
+-	CarriageReturn(screen); 	
++	CarriageReturn(screen);
+ 	do_xevents();
+ }
+ 
+diff -u xc/programs/xterm/data.c.orig xc/programs/xterm/data.c
+--- xc/programs/xterm/data.c.orig	Fri Jul 30 09:12:16 1999
++++ xc/programs/xterm/data.c	Sun Jun 11 20:41:14 2000
+@@ -58,9 +58,13 @@
+ #endif	/* DEBUG */
+ 
+ XtAppContext app_con;
+-XtermWidget term;		/* master data structure for client */
++XtermWidget term;	/* master data structure for client */
+ char *xterm_name;	/* argv[0] */
+ Boolean sunFunctionKeys;
++
++#if OPT_HP_FUNC_KEYS
++Boolean hpFunctionKeys;
++#endif
+ 
+ #if OPT_ZICONBEEP
+ int zIconBeep;  /* non-zero means beep; see charproc.c for details -IAN! */
+diff -u xc/programs/xterm/data.h.orig xc/programs/xterm/data.h
+--- xc/programs/xterm/data.h.orig	Fri Jul 30 09:12:16 1999
++++ xc/programs/xterm/data.h	Sun Jun 11 20:49:25 2000
+@@ -55,7 +55,9 @@
+ extern char *ttydev;
+ extern char *xterm_name;
+ extern Boolean sunFunctionKeys;
+-
++#if OPT_HP_FUNC_KEYS
++extern Boolean hpFunctionKeys;
++#endif
+ #if OPT_ZICONBEEP 
+ extern int zIconBeep; 
+ extern Boolean zIconBeep_flagged; 
+diff -u xc/programs/xterm/fontutils.c.orig xc/programs/xterm/fontutils.c
+--- xc/programs/xterm/fontutils.c.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/fontutils.c	Sun Jun 11 20:41:14 2000
+@@ -230,7 +230,7 @@
+      return ret;
+ }
+ 
+-#ifdef OPT_DEC_CHRSET
++#if OPT_DEC_CHRSET
+ /*
+  * Take the given font props and try to make a well formed font name specifying
+  * the same base font but changed depending on the given attributes and chrset.
+@@ -269,7 +269,7 @@
+ 	if (CSET_DOUBLE(chrset))
+ 		res_x *= 2;
+ 
+-	if (chrset == CSET_DHL_TOP 
++	if (chrset == CSET_DHL_TOP
+ 	 || chrset == CSET_DHL_BOT) {
+ 		res_y *= 2;
+ 		pixel_size *= 2;
+@@ -379,6 +379,7 @@
+ 	Pixel new_revers;
+ 	char *tmpname = NULL;
+ 	Boolean proportional = False;
++	int ch;
+ 
+ 	if (!nfontname) return 0;
+ 
+@@ -492,6 +493,21 @@
+ 	screen->fnt_norm = nfs;
+ 	screen->fnt_bold = bfs;
+ 	screen->fnt_prop = proportional;
++	screen->fnt_boxes = True;
++
++#if OPT_BOX_CHARS
++	/*
++	 * Xterm uses the first 32 character positions of a font for the
++	 * line-drawing characters.  Check that they are all present.
++	 */
++	for (ch = 0; ch < 32; ch++) {
++		if (xtermMissingChar(ch, nfs)
++		 || xtermMissingChar(ch, bfs)) {
++			screen->fnt_boxes = False;
++			break;
++		}
++	}
++#endif
+ 
+ 	screen->enbolden = (nfs == bfs);
+ 	set_menu_font (False);
+@@ -547,28 +563,49 @@
+ }
+ 
+ /*
++ * Compute useful values for the font/window sizes
++ */
++void
++xtermComputeFontInfo (TScreen *screen, struct _vtwin *win, XFontStruct *font, int sbwidth)
++{
++	int i, j, width, height;
++
++	win->f_width  = (font->max_bounds.width);
++	win->f_height = (font->ascent + font->descent);
++	i = 2 * screen->border + sbwidth;
++	j = 2 * screen->border;
++	width  = (screen->max_col + 1) * win->f_width + i;
++	height = (screen->max_row + 1) * win->f_height + j;
++	win->fullwidth  = width;
++	win->fullheight = height;
++	win->width  = width - i;
++	win->height = height - j;
++}
++
++
++/* save this information as a side-effect for double-sized characters */
++void
++xtermSaveFontInfo (TScreen *screen, XFontStruct *font)
++{
++	screen->fnt_wide = (font->max_bounds.width);
++	screen->fnt_high = (font->ascent + font->descent);
++}
++
++/*
+  * After loading a new font, update the structures that use its size.
+  */
+ void
+ xtermUpdateFontInfo (TScreen *screen, Bool doresize)
+ {
+-	int i, j, width, height, scrollbar_width;
++	int scrollbar_width;
++	struct _vtwin *win = &(screen->fullVwin);
+ 
+-	screen->fullVwin.f_width  = (screen->fnt_norm->max_bounds.width);
+-	screen->fullVwin.f_height = (screen->fnt_norm->ascent +
+-	screen->fnt_norm->descent);
+ 	scrollbar_width = (term->misc.scrollbar
+ 			? screen->scrollWidget->core.width +
+ 			  screen->scrollWidget->core.border_width
+ 			: 0);
+-	i = 2 * screen->border + scrollbar_width;
+-	j = 2 * screen->border;
+-	width  = (screen->max_col + 1) * screen->fullVwin.f_width + i;
+-	height = (screen->max_row + 1) * screen->fullVwin.f_height + j;
+-	screen->fullVwin.fullwidth  = width;
+-	screen->fullVwin.fullheight = height;
+-	screen->fullVwin.width  = width - i;
+-	screen->fullVwin.height = height - j;
++	xtermComputeFontInfo (screen, win, screen->fnt_norm, scrollbar_width);
++	xtermSaveFontInfo(screen, screen->fnt_norm);
+ 
+ 	if (doresize) {
+ 		if (VWindow(screen)) {
+@@ -581,3 +618,259 @@
+ 	}
+ 	xtermSetCursorBox (screen);
+ }
++
++#if OPT_BOX_CHARS
++/*
++ * Returns true if the given character is missing from the specified font.
++ */
++Bool
++xtermMissingChar(int ch, XFontStruct *font)
++{
++	XCharStruct	*pc = 0;
++
++	if (font != 0
++	&& font->per_char != 0
++	&& !font->all_chars_exist) {
++		if (ch < (int) font->min_char_or_byte2
++		 || ch > (int) font->max_char_or_byte2) {
++			TRACE(("MissingChar %c\n", ch))
++			return True;
++		}
++		if (font->min_byte1 == 0
++		 && font->max_byte1 == 0) {
++			pc = font->per_char + (ch - font->min_char_or_byte2);
++		} /* FIXME: this does not handle doublebyte characters */
++		if (pc != 0
++		 && (pc->lbearing + pc->rbearing) == 0
++		 && (pc->ascent   + pc->descent) == 0
++		 && (pc->width == 0)) {
++			TRACE(("MissingChar %c\n", ch))
++			return True;
++		}
++	}
++	return False;
++}
++
++/*
++ * The grid is abitrary, enough resolution that nothing's lost in initialization.
++ */
++#define BOX_HIGH 60
++#define BOX_WIDE 60
++
++#define MID_HIGH (BOX_HIGH/2)
++#define MID_WIDE (BOX_WIDE/2)
++
++/*
++ * ...since we'll scale the values anyway.
++ */
++#define SCALE_X(n) n = (n * (screen->fnt_wide-1)) / (BOX_WIDE-1)
++#define SCALE_Y(n) n = (n * (screen->fnt_high-1)) / (BOX_HIGH-1)
++
++/*
++ * Draw the given graphic character, if it is simple enough (i.e., a
++ * line-drawing character).
++ */
++void
++xtermDrawBoxChar(TScreen *screen, int ch, unsigned flags, GC gc, int x, int y)
++{
++	static const short
++		diamond[] = {
++			MID_WIDE,     BOX_HIGH/4,   3*BOX_WIDE/4, MID_WIDE,
++			3*BOX_WIDE/4, MID_WIDE,     MID_WIDE,     3*BOX_HIGH/4,
++			MID_WIDE,     3*BOX_HIGH/4, BOX_WIDE/4,   MID_HIGH,
++			BOX_WIDE/4,   MID_HIGH,     MID_WIDE,     BOX_HIGH/4,
++			MID_WIDE,     BOX_HIGH/3,   2*BOX_WIDE/3, MID_WIDE,
++			2*BOX_WIDE/3, MID_WIDE,     MID_WIDE,     2*BOX_HIGH/3,
++			MID_WIDE,     2*BOX_HIGH/3, BOX_WIDE/3,   MID_HIGH,
++			BOX_WIDE/3,   MID_HIGH,     MID_WIDE,     BOX_HIGH/3,
++			BOX_WIDE/4,   MID_HIGH,     3*BOX_WIDE/4, MID_HIGH,
++			MID_WIDE,     BOX_HIGH/4,   MID_WIDE,     3*BOX_HIGH/4,
++			-1
++		},
++		degrees[] = {
++			MID_WIDE,     BOX_HIGH/4,   2*BOX_WIDE/3, 3*BOX_HIGH/8,
++			2*BOX_WIDE/3, 3*BOX_HIGH/8, MID_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_HIGH,     BOX_WIDE/3,   3*BOX_HIGH/8,
++			BOX_WIDE/3,   3*BOX_HIGH/8, MID_WIDE,     BOX_HIGH/4,
++			-1
++		},
++		lower_right_corner[] = {
++			0,            MID_HIGH,     MID_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_HIGH,     MID_WIDE,     0,
++			-1
++		},
++		upper_right_corner[] = {
++			0,            MID_HIGH,     MID_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_HIGH,     MID_WIDE,     BOX_HIGH,
++			-1
++		},
++		upper_left_corner[] = {
++			MID_WIDE,     MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_HIGH,     MID_WIDE,     BOX_HIGH,
++			-1
++		},
++		lower_left_corner[] = {
++			MID_WIDE,     0,            MID_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_WIDE,     BOX_WIDE,     MID_HIGH,
++			-1
++		},
++		cross[] = {
++			0,            MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			MID_WIDE,     0,            MID_WIDE,     BOX_HIGH,
++			-1
++		},
++		scan_line_1[] = {
++			0,            0,            BOX_WIDE,     0,
++			-1
++		},
++		scan_line_3[] = {
++			0,            BOX_HIGH/4,   BOX_WIDE,     BOX_HIGH/4,
++			-1
++		},
++		scan_line_7[] = {
++			0,            MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			-1
++		},
++		scan_line_9[] = {
++			0,            3*BOX_HIGH/4, BOX_WIDE,     3*BOX_HIGH/4,
++			-1
++		},
++		horizontal_line[] = {
++			0,            BOX_HIGH,     BOX_WIDE,     BOX_HIGH,
++			-1
++		},
++		left_tee[] = {
++			MID_WIDE,     0,            MID_WIDE,     BOX_HIGH,
++			MID_WIDE,     MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			-1
++		},
++		right_tee[] = {
++			MID_WIDE,     0,            MID_WIDE,     BOX_HIGH,
++			MID_WIDE,     MID_HIGH,     0,            MID_HIGH,
++			-1
++		},
++		bottom_tee[] = {
++			0,            MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			MID_WIDE,     0,            MID_WIDE,     MID_HIGH,
++			-1
++		},
++		top_tee[] = {
++			0,            MID_HIGH,     BOX_WIDE,     MID_HIGH,
++			MID_WIDE,     MID_HIGH,     MID_WIDE,     BOX_HIGH,
++			-1
++		},
++		vertical_line[] = {
++			MID_WIDE,     0,            MID_WIDE,     BOX_HIGH,
++			-1
++		},
++		less_than_or_equal[] = {
++			5*BOX_WIDE/6, BOX_HIGH/6,   BOX_WIDE/5,   MID_HIGH,
++			5*BOX_WIDE/6, 5*BOX_HIGH/6, BOX_WIDE/5,   MID_HIGH,
++			BOX_WIDE/6,   5*BOX_HIGH/6, 5*BOX_WIDE/6, 5*BOX_HIGH/6,
++			-1
++		},
++		greater_than_or_equal[] = {
++			BOX_WIDE/6,   BOX_HIGH/6,   5*BOX_WIDE/6, MID_HIGH,
++			BOX_WIDE/6,   5*BOX_HIGH/6, 5*BOX_WIDE/6, MID_HIGH,
++			BOX_WIDE/6,   5*BOX_HIGH/6, 5*BOX_WIDE/6, 5*BOX_HIGH/6,
++			-1
++		};
++
++	static const short *lines[] = {
++		0,			/* 00 */
++		diamond,		/* 01 */
++		0,			/* 02 */
++		0,			/* 03 */
++		0,			/* 04 */
++		0,			/* 05 */
++		0,			/* 06 */
++		degrees,		/* 07 */
++		0,			/* 08 */
++		0,			/* 09 */
++		0,			/* 0A */
++		lower_right_corner,	/* 0B */
++		upper_right_corner,	/* 0C */
++		upper_left_corner,	/* 0D */
++		lower_left_corner,	/* 0E */
++		cross,			/* 0F */
++		scan_line_1,		/* 10 */
++		scan_line_3,		/* 11 */
++		scan_line_7,		/* 12 */
++		scan_line_9,		/* 13 */
++		horizontal_line,	/* 14 */
++		left_tee,		/* 15 */
++		right_tee,		/* 16 */
++		bottom_tee,		/* 17 */
++		top_tee,		/* 18 */
++		vertical_line,		/* 19 */
++		less_than_or_equal,	/* 1A */
++		greater_than_or_equal,	/* 1B */
++		0,			/* 1C */
++		0,			/* 1D */
++		0,			/* 1E */
++		0,			/* 1F */
++	};
++
++	XGCValues values;
++	GC gc2;
++	const short *p;
++
++	TRACE(("DRAW_BOX(%d) cell %dx%d at %d,%d%s\n",
++		ch, screen->fnt_high, screen->fnt_wide, y, x,
++		(ch < 0 || ch >= (int)(sizeof(lines)/sizeof(lines[0]))) ? "-BAD": ""))
++
++	if (!XGetGCValues(screen->display, gc, GCBackground, &values))
++		return;
++
++	values.foreground = values.background;
++	gc2 = XCreateGC(screen->display, TextWindow(screen), GCForeground, &values);
++
++	XFillRectangle(
++		screen->display, TextWindow(screen), gc2, x, y,
++		screen->fnt_wide,
++		screen->fnt_high);
++
++	XCopyGC(screen->display, gc, (1<<GCLastBit)-1, gc2);
++	XSetLineAttributes(screen->display, gc2,
++		(flags&BOLD)
++			? ((screen->fnt_high > 6)
++			  ? screen->fnt_high/6
++			  : 1)
++			: ((screen->fnt_high > 8)
++			  ? screen->fnt_high/8
++			  : 1),
++		LineSolid,
++		CapProjecting,
++		JoinMiter);
++
++	if (ch >= 0
++	 && ch < (int)(sizeof(lines)/sizeof(lines[0]))
++	 && (p = lines[ch]) != 0) {
++		int	coord[4];
++		int	n = 0;
++		while (*p >= 0) {
++			coord[n++] = *p++;
++			if (n == 4) {
++				SCALE_X(coord[0]); SCALE_Y(coord[1]);
++				SCALE_X(coord[2]); SCALE_Y(coord[3]);
++				XDrawLine(
++					screen->display,
++					TextWindow(screen), gc2,
++					x + coord[0], y + coord[1],
++					x + coord[2], y + coord[3]);
++				n = 0;
++			}
++		}
++	}
++#if 0	/* bounding rectangle, for debugging */
++	else {
++		XDrawRectangle(
++			screen->display, TextWindow(screen), gc, x, y,
++			screen->fnt_wide-1,
++			screen->fnt_high-1);
++	}
++#endif
++
++	XFreeGC(screen->display, gc2);
++}
++#endif
+diff -u xc/programs/xterm/fontutils.h.orig xc/programs/xterm/fontutils.h
+--- xc/programs/xterm/fontutils.h.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/fontutils.h	Sun Jun 11 20:41:14 2000
+@@ -40,11 +40,18 @@
+ #include <ptyx.h>
+ 
+ extern int xtermLoadFont (TScreen *screen, char *nfontname, char *bfontname, Bool doresize, int fontnum);
++extern void xtermComputeFontInfo (TScreen *screen, struct _vtwin *win, XFontStruct *font, int sbwidth);
++extern void xtermSaveFontInfo (TScreen *screen, XFontStruct *font);
+ extern void xtermUpdateFontInfo (TScreen *screen, Bool doresize);
+ extern void xtermSetCursorBox (TScreen *screen);
+ 
+ #if OPT_DEC_CHRSET
+ extern char *xtermSpecialFont(unsigned atts, unsigned chrset);
++#endif
++
++#if OPT_BOX_CHARS
++extern Bool xtermMissingChar(int ch, XFontStruct *font);
++extern void xtermDrawBoxChar(TScreen *screen, int ch, unsigned flags, GC gc, int x, int y);
+ #endif
+ 
+ #endif /* included_fontutils_h */
+diff -u xc/programs/xterm/input.c.orig xc/programs/xterm/input.c
+--- xc/programs/xterm/input.c.orig	Sat Oct 24 03:58:25 1998
++++ xc/programs/xterm/input.c	Sun Jun 11 20:41:14 2000
+@@ -45,6 +45,9 @@
+ 
+ static int decfuncvalue (KeySym keycode);
+ static int sunfuncvalue (KeySym keycode);
++#if OPT_HP_FUNC_KEYS
++static int hpfuncvalue (KeySym keycode);
++#endif
+ 
+ static void
+ AdjustAfterInput (register TScreen *screen)
+@@ -187,6 +190,13 @@
+ 	}
+ #endif
+ 
++#if OPT_HP_FUNC_KEYS
++	if (hpFunctionKeys
++	 && (reply.a_final = hpfuncvalue (keysym)) != 0) {
++		reply.a_type = ESC;
++		unparseseq(&reply, pty);
++	} else
++#endif
+ 	if (IsPFKey(keysym)) {
+ 		reply.a_type = SS3;
+ 		reply.a_final = keysym-XK_KP_F1+'P';
+@@ -368,6 +378,43 @@
+ 	}
+ }
+ 
++#if OPT_HP_FUNC_KEYS
++static int
++hpfuncvalue (KeySym  keycode)
++{
++  	switch (keycode) {
++		case XK_Up:		return('A');
++		case XK_Down:		return('B');
++		case XK_Right:		return('C');
++		case XK_Left:		return('D');
++		case XK_End:		return('F');
++		case XK_Clear:		return('J');
++		case XK_Delete:		return('P');
++		case XK_Insert:		return('Q');
++		case XK_Next:		return('S');
++		case XK_Prior:		return('T');
++		case XK_Home:		return('h');
++		case XK_F1:		return('p');
++		case XK_F2:		return('q');
++		case XK_F3:		return('r');
++		case XK_F4:		return('s');
++		case XK_F5:		return('t');
++		case XK_F6:		return('u');
++		case XK_F7:		return('v');
++		case XK_F8:		return('w');
++#ifdef XK_KP_Insert
++		case XK_KP_Delete:	return('P');
++		case XK_KP_Insert:	return('Q');
++#endif
++#ifdef DXK_Remove
++		case DXK_Remove:	return('P');
++#endif
++		case XK_Select:		return('F');
++		case XK_Find:		return('h');
++		default:		return 0;
++	}
++}
++#endif
+ 
+ static int
+ sunfuncvalue (KeySym  keycode)
+diff -u xc/programs/xterm/main.c.orig xc/programs/xterm/main.c
+--- xc/programs/xterm/main.c.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/main.c	Sun Jun 11 20:55:35 2000
+@@ -791,6 +791,9 @@
+     Boolean ptyInitialErase;	/* if true, use pty's sense of erase char */
+     Boolean backarrow_is_erase;	/* override backspace/delete */ 
+ #endif
++#if OPT_HP_FUNC_KEYS
++    Boolean hpFunctionKeys;
++#endif
+     Boolean wait_for_map;
+     Boolean useInsertMode;
+ #if OPT_ZICONBEEP
+@@ -836,6 +839,10 @@
+     {"backarrowKeyIsErase", "BackarrowKeyIsErase", XtRBoolean, sizeof(Boolean), 
+         offset(backarrow_is_erase), XtRString, "false"}, 
+ #endif
++#if OPT_HP_FUNC_KEYS
++    {"hpFunctionKeys", "HpFunctionKeys", XtRBoolean, sizeof (Boolean),
++	offset(hpFunctionKeys), XtRString, "false"},
++#endif
+     {"waitForMap", "WaitForMap", XtRBoolean, sizeof (Boolean),
+ 	offset(wait_for_map), XtRString, "false"},
+     {"useInsertMode", "UseInsertMode", XtRBoolean, sizeof (Boolean),
+@@ -907,6 +914,10 @@
+ {"-ie",		"*ptyInitialErase", XrmoptionNoArg,	(caddr_t) "on"},
+ {"+ie",		"*ptyInitialErase", XrmoptionNoArg,	(caddr_t) "off"},
+ #endif
++#if OPT_HP_FUNC_KEYS
++{"-hf",		"*hpKeyboard",  XrmoptionNoArg,		(caddr_t) "on"},
++{"+hf",		"*hpKeyboard",  XrmoptionNoArg,		(caddr_t) "off"},
++#endif
+ {"-j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "on"},
+ {"+j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "off"},
+ /* parse logging options anyway for compatibility */
+@@ -1016,6 +1027,9 @@
+ #if OPT_HIGHLIGHT_COLOR
+ { "-hc",		   "selection background color" },
+ #endif
++#if OPT_HP_FUNC_KEYS
++{ "-/+hf",		   "turn on/off HP Function Key escape codes" },
++#endif
+ #if OPT_INITIAL_ERASE 
+ { "-/+ie",		   "turn on/off initialization of 'erase' from pty" }, 
+ #endif 
+@@ -1047,7 +1061,9 @@
+ { "-/+si",                 "turn on/off scroll-on-tty-output inhibit" },
+ { "-/+sk",                 "turn on/off scroll-on-keypress" },
+ { "-sl number",            "number of scrolled lines to save" },
++#if OPT_SUNPC_KBD
+ { "-/+sp",                 "turn on/off Sun/PC Function/Keypad mapping" },
++#endif
+ #if OPT_TEK4014
+ { "-/+t",                  "turn on/off Tek emulation window" },
+ #endif
+@@ -1589,6 +1605,9 @@
+ 	sunFunctionKeys = resource.sunFunctionKeys;
+ #if OPT_SUNPC_KBD
+ 	sunKeyboard = resource.sunKeyboard;
++#endif
++#if OPT_HP_FUNC_KEYS
++	hpFunctionKeys = resource.hpFunctionKeys;
+ #endif
+ 	if (strcmp(xterm_name, "-") == 0) xterm_name = DFT_TERMTYPE;
+ 	if (resource.icon_geometry != NULL) {
+diff -u xc/programs/xterm/menu.c.orig xc/programs/xterm/menu.c
+--- xc/programs/xterm/menu.c.orig	Sat Oct 24 03:58:26 1998
++++ xc/programs/xterm/menu.c	Sun Jun 11 20:41:14 2000
+@@ -77,9 +77,9 @@
+ static void do_securekbd       PROTO_XT_CALLBACK_ARGS;
+ static void do_softreset       PROTO_XT_CALLBACK_ARGS;
+ static void do_sun_fkeys       PROTO_XT_CALLBACK_ARGS;
+-static void do_sun_kbd         PROTO_XT_CALLBACK_ARGS;
+ static void do_suspend         PROTO_XT_CALLBACK_ARGS;
+ static void do_terminate       PROTO_XT_CALLBACK_ARGS;
++static void do_titeInhibit     PROTO_XT_CALLBACK_ARGS;
+ static void do_visualbell      PROTO_XT_CALLBACK_ARGS;
+ static void do_vtfont          PROTO_XT_CALLBACK_ARGS;
+ 
+@@ -91,6 +91,22 @@
+ static void do_activeicon      PROTO_XT_CALLBACK_ARGS;
+ #endif /* NO_ACTIVE_ICON */
+ 
++#if OPT_DEC_CHRSET
++static void do_font_doublesize PROTO_XT_CALLBACK_ARGS;
++#endif
++
++#if OPT_DEC_SOFTFONT
++static void do_font_loadable   PROTO_XT_CALLBACK_ARGS;
++#endif
++
++#if OPT_HP_FUNC_KEYS
++static void do_hp_fkeys        PROTO_XT_CALLBACK_ARGS;
++#endif
++
++#if OPT_SUNPC_KBD
++static void do_sun_kbd         PROTO_XT_CALLBACK_ARGS;
++#endif
++
+ #if OPT_TEK4014
+ static void do_tekcopy         PROTO_XT_CALLBACK_ARGS;
+ static void do_tekhide         PROTO_XT_CALLBACK_ARGS;
+@@ -126,7 +142,12 @@
+     { "8-bit control",	do_8bit_control, NULL },
+     { "backarrow key",	do_backarrow,	NULL },
+     { "sun function-keys",do_sun_fkeys,	NULL },
++#if OPT_SUNPC_KBD
+     { "sun keyboard",	do_sun_kbd,	NULL },
++#endif
++#if OPT_HP_FUNC_KEYS
++    { "hp function-keys",do_hp_fkeys,	NULL },
++#endif
+     { "line2",		NULL,		NULL },
+     { "suspend",	do_suspend,	NULL },
+     { "continue",	do_continue,	NULL },
+@@ -138,62 +159,73 @@
+     { "quit",		do_quit,	NULL }};
+ 
+ MenuEntry vtMenuEntries[] = {
+-    { "scrollbar",	do_scrollbar, NULL },		/*  0 */
+-    { "jumpscroll",	do_jumpscroll, NULL },		/*  1 */
+-    { "reversevideo",	do_reversevideo, NULL },	/*  2 */
+-    { "autowrap",	do_autowrap, NULL },		/*  3 */
+-    { "reversewrap",	do_reversewrap, NULL },		/*  4 */
+-    { "autolinefeed",	do_autolinefeed, NULL },	/*  5 */
+-    { "appcursor",	do_appcursor, NULL },		/*  6 */
+-    { "appkeypad",	do_appkeypad, NULL },		/*  7 */
+-    { "scrollkey",	do_scrollkey, NULL },		/*  8 */
+-    { "scrollttyoutput",do_scrollttyoutput, NULL },	/*  9 */
+-    { "allow132",	do_allow132, NULL },		/* 10 */
+-    { "cursesemul",	do_cursesemul, NULL },		/* 11 */
+-    { "visualbell",	do_visualbell, NULL },		/* 12 */
+-    { "marginbell",	do_marginbell, NULL },		/* 13 */
+-    { "altscreen",	do_altscreen, NULL },		/* 14 */
++    { "scrollbar",	do_scrollbar,	NULL },
++    { "jumpscroll",	do_jumpscroll,	NULL },
++    { "reversevideo",	do_reversevideo, NULL },
++    { "autowrap",	do_autowrap,	NULL },
++    { "reversewrap",	do_reversewrap, NULL },
++    { "autolinefeed",	do_autolinefeed, NULL },
++    { "appcursor",	do_appcursor,	NULL },
++    { "appkeypad",	do_appkeypad,	NULL },
++    { "scrollkey",	do_scrollkey,	NULL },
++    { "scrollttyoutput",do_scrollttyoutput, NULL },
++    { "allow132",	do_allow132,	NULL },
++    { "cursesemul",	do_cursesemul,	NULL },
++    { "visualbell",	do_visualbell,	NULL },
++    { "marginbell",	do_marginbell,	NULL },
++    { "titeInhibit",	do_titeInhibit,	NULL },
+ #ifndef NO_ACTIVE_ICON
+-    { "activeicon",	do_activeicon, NULL },		/* 15 */
++    { "activeicon",	do_activeicon,	NULL },
+ #endif /* NO_ACTIVE_ICON */
+-    { "line1",		NULL, NULL },			/* 16 */
+-    { "softreset",	do_softreset, NULL },		/* 17 */
+-    { "hardreset",	do_hardreset, NULL },		/* 18 */
+-    { "clearsavedlines",do_clearsavedlines, NULL },	/* 19 */
++    { "line1",		NULL,		NULL },
++    { "softreset",	do_softreset,	NULL },
++    { "hardreset",	do_hardreset,	NULL },
++    { "clearsavedlines",do_clearsavedlines, NULL },
++    { "line2",		NULL,		NULL },
+ #if OPT_TEK4014
+-    { "line2",		NULL, NULL },			/* 20 */
+-    { "tekshow",	do_tekshow, NULL },		/* 21 */
+-    { "tekmode",	do_tekmode, NULL },		/* 22 */
+-    { "vthide",		do_vthide, NULL },		/* 23 */
++    { "tekshow",	do_tekshow,	NULL },
++    { "tekmode",	do_tekmode,	NULL },
++    { "vthide",		do_vthide,	NULL },
+ #endif
++    { "altscreen",	do_altscreen,	NULL },
+     };
+ 
+ MenuEntry fontMenuEntries[] = {
+-    { "fontdefault",	do_vtfont, NULL },		/*  0 */
+-    { "font1",		do_vtfont, NULL },		/*  1 */
+-    { "font2",		do_vtfont, NULL },		/*  2 */
+-    { "font3",		do_vtfont, NULL },		/*  3 */
+-    { "font4",		do_vtfont, NULL },		/*  4 */
+-    { "font5",		do_vtfont, NULL },		/*  5 */
+-    { "font6",		do_vtfont, NULL },		/*  6 */
+-    { "fontescape",	do_vtfont, NULL },		/*  7 */
+-    { "fontsel",	do_vtfont, NULL }};		/*  8 */
+-    /* this should match NMENUFONTS in ptyx.h */
++    { "fontdefault",	do_vtfont,	NULL },
++    { "font1",		do_vtfont,	NULL },
++    { "font2",		do_vtfont,	NULL },
++    { "font3",		do_vtfont,	NULL },
++    { "font4",		do_vtfont,	NULL },
++    { "font5",		do_vtfont,	NULL },
++    { "font6",		do_vtfont,	NULL },
++    { "fontescape",	do_vtfont,	NULL },
++    { "fontsel",	do_vtfont,	NULL },
++    /* down to here should match NMENUFONTS in ptyx.h */
++#if OPT_DEC_CHRSET || OPT_DEC_SOFTFONT
++    { "line1",		NULL,		NULL },
++#if OPT_DEC_CHRSET
++    { "font-doublesize",do_font_doublesize,NULL },
++#endif
++#if OPT_DEC_SOFTFONT
++    { "font-loadable",	do_font_loadable,NULL },
++#endif
++#endif /* toggles for font extensions */
++    };
+ 
+ #if OPT_TEK4014
+ MenuEntry tekMenuEntries[] = {
+-    { "tektextlarge",	do_tektextlarge, NULL },	/*  0 */
+-    { "tektext2",	do_tektext2, NULL },		/*  1 */
+-    { "tektext3",	do_tektext3, NULL },		/*  2 */
+-    { "tektextsmall",	do_tektextsmall, NULL },	/*  3 */
+-    { "line1",		NULL, NULL },			/*  4 */
+-    { "tekpage",	do_tekpage, NULL },		/*  5 */
+-    { "tekreset",	do_tekreset, NULL },		/*  6 */
+-    { "tekcopy",	do_tekcopy, NULL },		/*  7 */
+-    { "line2",		NULL, NULL },			/*  8 */
+-    { "vtshow",		do_vtshow, NULL },		/*  9 */
+-    { "vtmode",		do_vtmode, NULL },		/* 10 */
+-    { "tekhide",	do_tekhide, NULL }};		/* 11 */
++    { "tektextlarge",	do_tektextlarge, NULL },
++    { "tektext2",	do_tektext2,	NULL },
++    { "tektext3",	do_tektext3,	NULL },
++    { "tektextsmall",	do_tektextsmall, NULL },
++    { "line1",		NULL,		NULL },
++    { "tekpage",	do_tekpage,	NULL },
++    { "tekreset",	do_tekreset,	NULL },
++    { "tekcopy",	do_tekcopy,	NULL },
++    { "line2",		NULL,		NULL },
++    { "vtshow",		do_vtshow,	NULL },
++    { "vtmode",		do_vtmode,	NULL },
++    { "tekhide",	do_tekhide,	NULL }};
+ #endif
+ 
+ static Widget create_menu (
+@@ -266,12 +298,13 @@
+ 				 FALSE);
+ 	    }
+ 	    update_sun_fkeys();
++	    update_hp_fkeys();
+ #if !defined(SIGTSTP) || defined(AMOEBA)
+ 	    set_sensitivity (screen->mainMenu,
+ 			     mainMenuEntries[mainMenu_suspend].widget, FALSE);
+ #endif
+ #if !defined(SIGCONT) || defined(AMOEBA)
+-	    set_sensitivity (screen->mainMenu, 
++	    set_sensitivity (screen->mainMenu,
+ 			     mainMenuEntries[mainMenu_continue].widget, FALSE);
+ #endif
+ 	}
+@@ -296,6 +329,8 @@
+ 	    update_cursesemul();
+ 	    update_visualbell();
+ 	    update_marginbell();
++	    update_altscreen();
++	    update_titeInhibit();
+ #ifndef NO_ACTIVE_ICON
+ 	    if (!screen->fnt_icon || !screen->iconVwin.window) {
+ 		set_sensitivity (screen->vtMenu,
+@@ -312,12 +347,19 @@
+ 	if (!screen->fontMenu) {
+ 	    screen->fontMenu = create_menu (term, toplevel, "fontMenu",
+ 					    fontMenuEntries,
+-					    NMENUFONTS);  
++					    XtNumber(fontMenuEntries));
+ 	    set_menu_font (True);
+ 	    set_sensitivity (screen->fontMenu,
+ 			     fontMenuEntries[fontMenu_fontescape].widget,
+ 			     (screen->menu_font_names[fontMenu_fontescape]
+ 			      ? TRUE : FALSE));
++	    update_font_doublesize();
++	    update_font_loadable();
++#if OPT_DEC_SOFTFONT	/* FIXME: not implemented */
++	    set_sensitivity (screen->fontMenu,
++			     fontMenuEntries[fontMenu_font_loadable].widget,
++			     FALSE);
++#endif
+ 	}
+ 	FindFontSelection (NULL, True);
+ 	set_sensitivity (screen->fontMenu,
+@@ -400,7 +442,7 @@
+     for (; nentries > 0; nentries--, entries++) {
+ 	cb[0].callback = (XtCallbackProc) entries->function;
+ 	cb[0].closure = (caddr_t) entries->name;
+-	entries->widget = XtCreateManagedWidget (entries->name, 
++	entries->widget = XtCreateManagedWidget (entries->name,
+ 						 (entries->function ?
+ 						  smeBSBObjectClass :
+ 						  smeLineObjectClass), m,
+@@ -547,7 +589,6 @@
+     update_sun_fkeys();
+ }
+ 
+-
+ #if OPT_SUNPC_KBD
+ static void do_sun_kbd (
+ 	Widget gw GCC_UNUSED,
+@@ -560,6 +601,18 @@
+ #endif
+ 
+ 
++#if OPT_HP_FUNC_KEYS
++static void do_hp_fkeys (
++	Widget gw GCC_UNUSED,
++	XtPointer closure GCC_UNUSED,
++	XtPointer data GCC_UNUSED)
++{
++    hpFunctionKeys = ! hpFunctionKeys;
++    update_hp_fkeys();
++}
++#endif
++
++
+ /*
+  * The following cases use the pid instead of the process group so that we
+  * don't get hosed by programs that change their process group
+@@ -836,6 +889,16 @@
+     ToggleAlternate(screen);
+ }
+ 
++/* ARGSUSED */
++static void do_titeInhibit (
++	Widget gw GCC_UNUSED,
++	XtPointer closure GCC_UNUSED,
++	XtPointer data GCC_UNUSED)
++{
++    term->misc.titeInhibit = !term->misc.titeInhibit;
++    update_titeInhibit();
++}
++
+ #ifndef NO_ACTIVE_ICON
+ /* ARGSUSED */
+ static void do_activeicon (
+@@ -879,7 +942,7 @@
+ 	XtPointer closure GCC_UNUSED,
+ 	XtPointer data GCC_UNUSED)
+ {
+-    VTReset (TRUE, TRUE); 
++    VTReset (TRUE, TRUE);
+ }
+ 
+ 
+@@ -926,6 +989,29 @@
+     Bell(XkbBI_MinorError, 0);
+ }
+ 
++#if OPT_DEC_CHRSET
++static void do_font_doublesize (
++	Widget gw GCC_UNUSED,
++	XtPointer closure GCC_UNUSED,
++	XtPointer data GCC_UNUSED)
++{
++    term->screen.font_doublesize = ! term->screen.font_doublesize;
++    update_font_doublesize();
++    Redraw ();
++}
++#endif
++
++#if OPT_DEC_SOFTFONT
++static void do_font_loadable (
++	Widget gw GCC_UNUSED,
++	XtPointer closure GCC_UNUSED,
++	XtPointer data GCC_UNUSED)
++{
++    term->misc.font_loadable = ! term->misc.font_loadable;
++    update_font_loadable();
++}
++#endif
++
+ 
+ /*
+  * tek menu
+@@ -1006,7 +1092,7 @@
+ 	set_vt_visibility (FALSE);
+ 	if (!screen->TekEmu && TekRefresh) dorefresh ();
+ 	end_vt_mode ();			/* WARNING: this does a longjmp... */
+-    } else 
++    } else
+       Bell(XkbBI_MinorError, 0);
+ }
+ 
+@@ -1244,6 +1330,18 @@
+ }
+ #endif
+ 
++#if OPT_HP_FUNC_KEYS
++void HandleHpFunctionKeys(
++	Widget w,
++	XEvent *event GCC_UNUSED,
++	String *params,
++	Cardinal *param_count)
++{
++    handle_toggle (do_hp_fkeys, (int) hpFunctionKeys,
++		   params, *param_count, w, (XtPointer)0, (XtPointer)0);
++}
++#endif
++
+ void HandleScrollbar(
+ 	Widget w,
+ 	XEvent *event GCC_UNUSED,
+@@ -1385,6 +1483,17 @@
+ 		   params, *param_count, w, (XtPointer)0, (XtPointer)0);
+ }
+ 
++void HandleTiteInhibit(
++	Widget w,
++	XEvent *event GCC_UNUSED,
++	String *params,
++	Cardinal *param_count)
++{
++    /* eventually want to see if sensitive or not */
++    handle_toggle (do_titeInhibit, ! ((int) term->misc.titeInhibit),
++		   params, *param_count, w, (XtPointer)0, (XtPointer)0);
++}
++
+ /* ARGSUSED */
+ void HandleSoftReset(
+ 	Widget w,
+@@ -1414,6 +1523,30 @@
+ {
+     do_clearsavedlines(w, (XtPointer)0, (XtPointer)0);
+ }
++
++#if OPT_DEC_CHRSET
++void HandleFontDoublesize(
++	Widget w,
++	XEvent *event GCC_UNUSED,
++	String *params,
++	Cardinal *param_count)
++{
++    handle_toggle (do_font_doublesize, (int) term->screen.font_doublesize,
++		   params, *param_count, w, (XtPointer)0, (XtPointer)0);
++}
++#endif
++
++#if OPT_DEC_SOFTFONT
++void HandleFontLoading(
++	Widget w,
++	XEvent *event GCC_UNUSED,
++	String *params,
++	Cardinal *param_count)
++{
++    handle_toggle (do_font_loadable, (int) term->misc.font_loadable,
++		   params, *param_count, w, (XtPointer)0, (XtPointer)0);
++}
++#endif
+ 
+ #if OPT_TEK4014
+ void HandleSetTerminalType(
+diff -u xc/programs/xterm/menu.h.orig xc/programs/xterm/menu.h
+--- xc/programs/xterm/menu.h.orig	Fri Jul 30 09:12:19 1999
++++ xc/programs/xterm/menu.h	Sun Jun 11 20:57:10 2000
+@@ -66,7 +66,10 @@
+ extern void HandleClearSavedLines  PROTO_XT_ACTIONS_ARGS;
+ extern void HandleCreateMenu       PROTO_XT_ACTIONS_ARGS;
+ extern void HandleCursesEmul       PROTO_XT_ACTIONS_ARGS;
++extern void HandleFontDoublesize   PROTO_XT_ACTIONS_ARGS;
++extern void HandleFontLoading      PROTO_XT_ACTIONS_ARGS;
+ extern void HandleHardReset        PROTO_XT_ACTIONS_ARGS;
++extern void HandleHpFunctionKeys   PROTO_XT_ACTIONS_ARGS;
+ extern void HandleJumpscroll       PROTO_XT_ACTIONS_ARGS;
+ extern void HandleLogging          PROTO_XT_ACTIONS_ARGS;
+ extern void HandleMarginBell       PROTO_XT_ACTIONS_ARGS;
+@@ -89,12 +92,13 @@
+ extern void HandleTekCopy          PROTO_XT_ACTIONS_ARGS;
+ extern void HandleTekPage          PROTO_XT_ACTIONS_ARGS;
+ extern void HandleTekReset         PROTO_XT_ACTIONS_ARGS;
++extern void HandleTiteInhibit      PROTO_XT_ACTIONS_ARGS;
+ extern void HandleVisibility       PROTO_XT_ACTIONS_ARGS;
+ 
+ extern void DoSecureKeyboard (Time tp);
+ 
+ /*
+- * The following definitions MUST match the order of entries given in 
++ * The following definitions MUST match the order of entries given in
+  * the mainMenuEntries, vtMenuEntries, and tekMenuEntries arrays in menu.c.
+  */
+ 
+@@ -116,6 +120,9 @@
+ #if OPT_SUNPC_KBD
+     mainMenu_sun_kbd,
+ #endif
++#if OPT_HP_FUNC_KEYS
++    mainMenu_hp_fkeys,
++#endif
+     mainMenu_line2,
+     mainMenu_suspend,
+     mainMenu_continue,
+@@ -147,7 +154,7 @@
+     vtMenu_cursesemul,
+     vtMenu_visualbell,
+     vtMenu_marginbell,
+-    vtMenu_altscreen,
++    vtMenu_titeInhibit,
+ #ifndef NO_ACTIVE_ICON
+     vtMenu_activeicon,
+ #endif /* NO_ACTIVE_ICON */
+@@ -161,6 +168,7 @@
+     vtMenu_tekmode,
+     vtMenu_vthide,
+ #endif
++    vtMenu_altscreen,
+     vtMenu_LAST
+ } vtMenuIndices;
+ 
+@@ -178,9 +186,14 @@
+ #define fontMenu_lastBuiltin fontMenu_font6
+     fontMenu_fontescape,
+     fontMenu_fontsel,
++/* number of non-line items down to here should match NMENUFONTS in ptyx.h */
++#if OPT_DEC_CHRSET
++    fontMenu_line1,
++    fontMenu_font_doublesize,
++    fontMenu_font_loadable,
++#endif
+     fontMenu_LAST
+ } fontMenuIndices;
+-/* number of non-line items should match NMENUFONTS in ptyx.h */
+ 
+ 
+ /*
+@@ -263,6 +276,15 @@
+ 		    sunKeyboard)
+ #endif
+ 
++#if OPT_HP_FUNC_KEYS
++#define update_hp_fkeys() \
++  update_menu_item (term->screen.mainMenu, \
++		    mainMenuEntries[mainMenu_hp_fkeys].widget, \
++		    hpFunctionKeys)
++#else
++#define update_hp_fkeys() /*nothing*/
++#endif
++
+ #define update_scrollbar() \
+   update_menu_item (term->screen.vtMenu, \
+ 		    vtMenuEntries[vtMenu_scrollbar].widget, \
+@@ -317,7 +339,7 @@
+   update_menu_item (term->screen.vtMenu, \
+ 		    vtMenuEntries[vtMenu_allow132].widget, \
+ 		    term->screen.c132)
+-  
++
+ #define update_cursesemul() \
+   update_menu_item (term->screen.vtMenu, \
+ 		    vtMenuEntries[vtMenu_cursesemul].widget, \
+@@ -338,12 +360,35 @@
+ 		    vtMenuEntries[vtMenu_altscreen].widget, \
+ 		    term->screen.alternate)
+ 
++#define update_titeInhibit() \
++  update_menu_item (term->screen.vtMenu, \
++		    vtMenuEntries[vtMenu_titeInhibit].widget, \
++		    !(term->misc.titeInhibit))
++
+ #ifndef NO_ACTIVE_ICON
+ #define update_activeicon() \
+   update_menu_item (term->screen.vtMenu, \
+ 		    vtMenuEntries[vtMenu_activeicon].widget, \
+ 		    term->misc.active_icon)
+ #endif /* NO_ACTIVE_ICON */
++
++#if OPT_DEC_CHRSET
++#define update_font_doublesize() \
++  update_menu_item (term->screen.fontMenu, \
++		    fontMenuEntries[fontMenu_font_doublesize].widget, \
++		    term->screen.font_doublesize)
++#else
++#define update_font_doublesize() /* nothing */
++#endif
++
++#if OPT_DEC_SOFTFONT
++#define update_font_loadable() \
++  update_menu_item (term->screen.fontMenu, \
++		    fontMenuEntries[fontMenu_font_loadable].widget, \
++		    term->misc.font_loadable)
++#else
++#define update_font_loadable() /* nothing */
++#endif
+ 
+ #if OPT_TEK4014
+ #define update_tekshow() \
+diff -u xc/programs/xterm/os2main.c.orig xc/programs/xterm/os2main.c
+--- xc/programs/xterm/os2main.c.orig	Fri Jul 30 09:12:20 1999
++++ xc/programs/xterm/os2main.c	Sun Jun 11 20:41:14 2000
+@@ -243,6 +243,9 @@
+ #if OPT_SUNPC_KBD
+     Boolean sunKeyboard;
+ #endif
++#if OPT_HP_FUNC_KEYS
++    Boolean hpFunctionKeys;
++#endif
+     Boolean wait_for_map;
+     Boolean useInsertMode;
+ #if OPT_ZICONBEEP
+@@ -282,6 +285,10 @@
+     {"sunKeyboard", "SunKeyboard", XtRBoolean, sizeof (Boolean),
+ 	offset(sunKeyboard), XtRString, "false"},
+ #endif
++#if OPT_HP_FUNC_KEYS
++    {"hpFunctionKeys", "HpFunctionKeys", XtRBoolean, sizeof (Boolean),
++	offset(hpFunctionKeys), XtRString, "false"},
++#endif
+     {"waitForMap", "WaitForMap", XtRBoolean, sizeof (Boolean),
+         offset(wait_for_map), XtRString, "false"},
+     {"useInsertMode", "UseInsertMode", XtRBoolean, sizeof (Boolean),
+@@ -349,6 +356,10 @@
+ #if OPT_HIGHLIGHT_COLOR
+ {"-hc",		"*highlightColor", XrmoptionSepArg,	(caddr_t) NULL},
+ #endif
++#if OPT_HP_FUNC_KEYS
++{"-hf",		"*hpKeyboard",  XrmoptionNoArg,		(caddr_t) "on"},
++{"+hf",		"*hpKeyboard",  XrmoptionNoArg,		(caddr_t) "off"},
++#endif
+ {"-j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "on"},
+ {"+j",		"*jumpScroll",	XrmoptionNoArg,		(caddr_t) "off"},
+ /* parse logging options anyway for compatibility */
+@@ -458,6 +469,9 @@
+ #if OPT_HIGHLIGHT_COLOR
+ { "-hc",		   "selection background color" },
+ #endif
++#if OPT_HP_FUNC_KEYS
++{ "-/+hf",                 "turn on/off HP Function Key escape codes" },
++#endif
+ { "-/+im",		   "use insert mode for TERMCAP" },
+ { "-/+j",                  "turn on/off jump scroll" },
+ #ifdef ALLOWLOGGING
+@@ -486,7 +500,9 @@
+ { "-/+si",                 "turn on/off scroll-on-tty-output inhibit" },
+ { "-/+sk",                 "turn on/off scroll-on-keypress" },
+ { "-sl number",            "number of scrolled lines to save" },
++#if OPT_SUNPC_KBD
+ { "-/+sp",                 "turn on/off Sun/PC Function/Keypad mapping" },
++#endif
+ #if OPT_TEK4014
+ { "-/+t",                  "turn on/off Tek emulation window" },
+ #endif
+@@ -892,6 +908,9 @@
+ 	sunFunctionKeys = resource.sunFunctionKeys;
+ #if OPT_SUNPC_KBD
+ 	sunKeyboard = resource.sunKeyboard;
++#endif
++#if OPT_HP_FUNC_KEYS
++	hpFunctionKeys = resource.hpFunctionKeys;
+ #endif
+ 	if (strcmp(xterm_name, "-") == 0) xterm_name = DFT_TERMTYPE;
+ 	if (resource.icon_geometry != NULL) {
+diff -u xc/programs/xterm/ptyx.h.orig xc/programs/xterm/ptyx.h
+--- xc/programs/xterm/ptyx.h.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/ptyx.h	Sun Jun 11 20:59:01 2000
+@@ -90,49 +90,49 @@
+ ** allow for mobility of the pty master/slave directories
+ */
+ #ifndef PTYDEV
+-#ifdef __hpux 
++#ifdef __hpux
+ #define	PTYDEV		"/dev/ptym/ptyxx"
+-#else	/* !__hpux */ 
++#else	/* !__hpux */
+ #ifndef __osf__
+ #define	PTYDEV		"/dev/ptyxx"
+ #endif
+-#endif	/* !__hpux */ 
++#endif	/* !__hpux */
+ #endif	/* !PTYDEV */
+ 
+ #ifndef TTYDEV
+-#ifdef __hpux 
++#ifdef __hpux
+ #define TTYDEV		"/dev/pty/ttyxx"
+-#else	/* !__hpux */ 
++#else	/* !__hpux */
+ #if defined(__osf__) || (defined(linux) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1))
+ #define TTYDEV		"/dev/ttydirs/xxx/xxxxxxxxxxxxxx"
+ #else
+ #define	TTYDEV		"/dev/ttyxx"
+ #endif
+-#endif	/* !__hpux */ 
++#endif	/* !__hpux */
+ #endif	/* !TTYDEV */
+ 
+ #ifndef PTYCHAR1
+-#ifdef __hpux 
++#ifdef __hpux
+ #define PTYCHAR1	"zyxwvutsrqp"
+-#else	/* !__hpux */ 
++#else	/* !__hpux */
+ #ifdef __EMX__
+ #define PTYCHAR1	"pq"
+ #else
+ #define	PTYCHAR1	"pqrstuvwxyzPQRSTUVWXYZ"
+ #endif  /* !__EMX__ */
+-#endif	/* !__hpux */ 
++#endif	/* !__hpux */
+ #endif	/* !PTYCHAR1 */
+ 
+ #ifndef PTYCHAR2
+-#ifdef __hpux 
++#ifdef __hpux
+ #define	PTYCHAR2	"fedcba9876543210"
+-#else	/* !__hpux */ 
++#else	/* !__hpux */
+ #ifdef __FreeBSD__
+ #define	PTYCHAR2	"0123456789abcdefghijklmnopqrstuv"
+ #else /* !__FreeBSD__ */
+ #define	PTYCHAR2	"0123456789abcdef"
+ #endif /* !__FreeBSD__ */
+-#endif	/* !__hpux */ 
++#endif	/* !__hpux */
+ #endif	/* !PTYCHAR2 */
+ 
+ #ifndef TTYFORMAT
+@@ -209,7 +209,7 @@
+ #define DFT_DECID 100			/* default VT100 */
+ #endif
+ 
+-#define NMENUFONTS 9			/* entries in fontMenu */
++#define NMENUFONTS 9			/* font entries in fontMenu */
+ 
+ #define	NBOX	5			/* Number of Points in box	*/
+ #define	NPARAM	10			/* Max. parameters		*/
+@@ -308,10 +308,22 @@
+ 
+ #define OPT_BLINK_CURS  0 /* FIXME: do this later (96/7/31) */
+ 
++#ifndef OPT_BOX_CHARS
++#define OPT_BOX_CHARS	1 /* true if xterm can simulate box-characters */
++#endif
++
+ #ifndef OPT_DEC_CHRSET
+ #define OPT_DEC_CHRSET  1 /* true if xterm is configured for DEC charset */
+ #endif
+ 
++#ifndef OPT_DEC_SOFTFONT
++#define OPT_DEC_SOFTFONT 0 /* true if xterm is configured for VT220 softfonts */
++#endif
++
++#ifndef OPT_HP_FUNC_KEYS
++#define OPT_HP_FUNC_KEYS 0 /* true if xterm supports HP-style function keys */
++#endif
++
+ #ifndef OPT_I18N_SUPPORT
+ #if (XtSpecificationRelease >= 6)
+ #define OPT_I18N_SUPPORT 1 /* true if xterm uses internationalization support */
+@@ -379,7 +391,13 @@
+ /***====================================================================***/
+ 
+ #if OPT_AIX_COLORS && !OPT_ISO_COLORS
+-fixme: You must have ANSI/ISO colors to support AIX colors
++/* You must have ANSI/ISO colors to support AIX colors */
++#undef OPT_AIX_COLORS
++#endif
++
++#if OPT_PC_COLORS && !OPT_ISO_COLORS
++/* You must have ANSI/ISO colors to support PC colors */
++#undef OPT_PC_COLORS
+ #endif
+ 
+ /***====================================================================***/
+@@ -631,6 +649,7 @@
+ 	Pixel		highlightcolor;	/* Highlight background color	*/
+ #endif
+ #if OPT_DEC_CHRSET
++	Boolean		font_doublesize;/* enable font-scaling		*/
+ 	Char		chrset;		/* character-set index & code	*/
+ 	XFontStruct *	double_fs[NUM_CHRSET];
+ 	GC		double_gc[NUM_CHRSET];
+@@ -666,6 +685,7 @@
+ #endif /* NO_ACTIVE_ICON */
+ 	Cursor pointer_cursor;		/* pointer cursor in window	*/
+ 
++	String	answer_back;		/* response to ENQ		*/
+ 	String	printer_command;	/* pipe/shell command string	*/
+ 	Boolean printer_autoclose;	/* close printer when offline	*/
+ 	Boolean printer_extent;		/* print complete page		*/
+@@ -676,6 +696,9 @@
+ #endif
+ 
+ 	Boolean		fnt_prop;	/* true if proportional fonts	*/
++	Boolean		fnt_boxes;	/* true if font has box-chars	*/
++	Dimension	fnt_wide;
++	Dimension	fnt_high;
+ 	XFontStruct	*fnt_norm;	/* normal font of terminal	*/
+ 	XFontStruct	*fnt_bold;	/* bold font of terminal	*/
+ #ifndef NO_ACTIVE_ICON
+@@ -735,10 +758,11 @@
+ 	Boolean 	multiscroll;	/* true if multi-scroll		*/
+ 	int		scrolls;	/* outstanding scroll count,
+ 					    used only with multiscroll	*/
+-	SavedCursor	sc;		/* data for restore cursor	*/
++	SavedCursor	sc[2];		/* data for restore cursor	*/
+ 	int		save_modes[24];	/* save dec/xterm private modes	*/
+ 
+ 	/* Improved VT100 emulation stuff.				*/
++	String		keyboard_dialect; /* default keyboard dialect	*/
+ 	char		gsets[4];	/* G0 through G3.		*/
+ 	char		curgl;		/* Current GL setting.		*/
+ 	char		curgr;		/* Current GR setting.		*/
+@@ -882,6 +906,9 @@
+     int icon_border_width;
+     Pixel icon_border_pixel;
+ #endif /* NO_ACTIVE_ICON */
++#if OPT_DEC_SOFTFONT
++    Boolean font_loadable;
++#endif
+ } Misc;
+ 
+ typedef struct {int foo;} XtermClassPart, TekClassPart;
+diff -u xc/programs/xterm/screen.c.orig xc/programs/xterm/screen.c
+--- xc/programs/xterm/screen.c.orig	Thu Nov 18 10:59:57 1999
++++ xc/programs/xterm/screen.c	Sun Jun 11 20:41:14 2000
+@@ -693,7 +693,10 @@
+ 		 || (cb[col] != cs)
+ #endif
+ 		 ) {
+-		   TRACE(("%s @%d, calling drawXtermText %d..%d\n", __FILE__, __LINE__, lastind, col))
++		   TRACE(("%s @%d, calling drawXtermText %d..%d:%.*s\n",
++		   	__FILE__, __LINE__,
++		   	lastind, col,
++			col - lastind, &chars[lastind]))
+ 		   x = drawXtermText(screen, flags, gc, x, y,
+ 		   	cs,
+ 			&chars[lastind], col - lastind);
+@@ -721,7 +724,10 @@
+ 			chars[col] = ' ';
+ 	   }
+ 
+-	   TRACE(("%s @%d, calling drawXtermText %d..%d\n", __FILE__, __LINE__, lastind, col))
++	   TRACE(("%s @%d, calling drawXtermText %d..%d:%.*s\n",
++	   	__FILE__, __LINE__,
++		lastind, col,
++		col - lastind, &chars[lastind]))
+ 	   drawXtermText(screen, flags, gc, x, y,
+ 	   	cs,
+ 		&chars[lastind], col - lastind);
+diff -u xc/programs/xterm/termcap.orig xc/programs/xterm/termcap
+--- xc/programs/xterm/termcap.orig	Thu Nov 18 10:59:58 1999
++++ xc/programs/xterm/termcap	Sun Jun 11 20:41:14 2000
+@@ -39,7 +39,7 @@
+ 	:li#24:md=\E[1m:me=\E[m^O:mr=\E[7m:ms:nd=\E[C:\
+ 	:eA=\E)0:as=^N:ae=^O:ml=\El:mu=\Em:\
+ 	:sc=\E7:rc=\E8:sf=\n:so=\E[7m:se=\E[27m:sr=\EM:st=\EH:\
+-	:ti=\E7\E[?47h:te=\E[2J\E[?47l\E8:\
++	:ti=\E[?1049h:te=\E[?1049l:\
+ 	:vi=\E[?25l:ve=\E[?25h:\
+ 	:up=\E[A:us=\E[4m:ue=\E[24m:xn:\
+ 	:ut:Co#8:op=\E[39;49m:AB=\E[4%dm:AF=\E[3%dm:\
+diff -u xc/programs/xterm/terminfo.orig xc/programs/xterm/terminfo
+--- xc/programs/xterm/terminfo.orig	Mon May 10 12:53:48 1999
++++ xc/programs/xterm/terminfo	Sun Jun 11 20:41:14 2000
+@@ -13,7 +13,7 @@
+ # meml locks memory above the cursor; memu unlocks (ala HP terminals).  This
+ #	is not recognized by some older (e.g., SVr3) tic programs, but none
+ #	do more than warn about it.  Ignore the warning.
+-# rmcup clears memory before switching to the alternate screen.  The older
++# smcup clears memory before switching to the alternate screen.  The older
+ #	(deprecated) \E[?47h did not do this, requiring applications to
+ #	embed a \E[2J in the rmcup string.  However, that behavior cannot
+ #	be disabled via titeInhibit, making that resource not function as
+@@ -183,7 +183,7 @@
+ 	ri=\EM,
+ 	rmacs=^O,
+ 	rmam=\E[?7l,
+-	rmcup=\E[?1047l\E[?1048l,
++	rmcup=\E[?1049l,
+ 	rmir=\E[4l,
+ 	rmkx=\E[?1l\E>,
+ 	rmso=\E[27m,
+@@ -199,7 +199,7 @@
+ 	sgr0=\E[m\017,
+ 	smacs=^N,
+ 	smam=\E[?7h,
+-	smcup=\E[?1048h\E[?1047h,
++	smcup=\E[?1049h,
+ 	smir=\E[4h,
+ 	smkx=\E[?1h\E=,
+ 	smso=\E[7m,
+@@ -428,7 +428,7 @@
+ 	ri=\215,
+ 	rmacs=^O,
+ 	rmam=\233?7l,
+-	rmcup=\233?1047l\233?1048l,
++	rmcup=\233?1049l,
+ 	rmir=\2334l,
+ 	rmkx=\233?1l\E>,
+ 	rmso=\23327m,
+@@ -444,7 +444,7 @@
+ 	sgr0=\233m^O,
+ 	smacs=^N,
+ 	smam=\233?7h,
+-	smcup=\233?1048h\233?1047h,
++	smcup=\233?1049h,
+ 	smir=\2334h,
+ 	smkx=\233?1h\E=,
+ 	smso=\2337m,
+diff -u xc/programs/xterm/util.c.orig xc/programs/xterm/util.c
+--- xc/programs/xterm/util.c.orig	Sun Jun 11 20:31:39 2000
++++ xc/programs/xterm/util.c	Sun Jun 11 20:41:14 2000
+@@ -33,6 +33,7 @@
+ #include <data.h>
+ #include <error.h>
+ #include <menu.h>
++#include <fontutils.h>
+ 
+ #include <ctype.h>
+ 
+@@ -1295,6 +1296,16 @@
+ }
+ 
+ /*
++ * Set the fnt_wide/fnt_high values to a known state, based on the currently
++ * active font.
++ */
++#ifndef NO_ACTIVE_ICON
++#define SAVE_FONT_INFO(screen) xtermSaveFontInfo (screen, IsIcon(screen) ? screen->fnt_icon : screen->fnt_norm)
++#else
++#define SAVE_FONT_INFO(screen) xtermSaveFontInfo (screen, screen->fnt_norm)
++#endif
++
++/*
+  * Draws text with the specified combination of bold/underline
+  */
+ int
+@@ -1310,46 +1321,85 @@
+ {
+ #if OPT_DEC_CHRSET
+ 	if (CSET_DOUBLE(chrset)) {
+-		GC gc2 = xterm_DoubleGC(chrset, flags, gc);
++		GC gc2 = screen->font_doublesize
++			? xterm_DoubleGC(chrset, flags, gc)
++			: 0;
+ 
+ 		TRACE(("DRAWTEXT%c[%4d,%4d] (%d) %d:%.*s\n",
+ 			screen->cursor_state == OFF ? ' ' : '*',
+ 			y, x, chrset, len, len, text))
+ 
+ 		if (gc2 != 0) {	/* draw actual double-sized characters */
++			XFontStruct *fs = screen->double_fs[chrset % NUM_CHRSET];
+ 			XRectangle rect, *rp = &rect;
+ 			Cardinal nr = 1;
++			int adjust;
++
++			SAVE_FONT_INFO (screen);
++			screen->fnt_wide *= 2;
+ 
+ 			rect.x = 0;
+ 			rect.y = 0;
+-			rect.width = 2 * len * FontWidth(screen);
++			rect.width = len * screen->fnt_wide;
+ 			rect.height = FontHeight(screen);
+ 
+ 			switch (chrset) {
+ 			case CSET_DHL_TOP:
+ 				rect.y = - (rect.height / 2);
+ 				y -= rect.y;
++				screen->fnt_high *= 2;
+ 				break;
+ 			case CSET_DHL_BOT:
+ 				rect.y = (rect.height / 2);
+ 				y -= rect.y;
++				screen->fnt_high *= 2;
+ 				break;
+ 			default:
+ 				nr = 0;
+ 				break;
+ 			}
+ 
++			/*
++			 * Though it is the right "size", a given bold font may
++			 * be shifted up by a pixel or two.  Shift it back into
++			 * the clipping rectangle.
++			 */
++			if (nr != 0) {
++				adjust = fs->ascent
++					+ fs->descent
++					- (2 * FontHeight(screen));
++				rect.y -= adjust;
++				y += adjust;
++			}
++
+ 			if (nr)
+ 				XSetClipRectangles(screen->display, gc2,
+ 					x, y, rp, nr, YXBanded);
+ 			else
+ 				XSetClipMask(screen->display, gc2, None);
+ 
+-			x = drawXtermText(screen, flags, gc2,
+-				x, y, 0, text, len);
+-			x += len * FontWidth(screen);
++			/*
++			 * If we're trying to use proportional font, or if the
++			 * font server didn't give us what we asked for wrt
++			 * width, position each character independently.
++			 */
++			if (screen->fnt_prop
++			 || (fs->min_bounds.width != fs->max_bounds.width)
++			 || (fs->min_bounds.width != 2 * FontWidth(screen)))
++			{
++				while (len--) {
++					x = drawXtermText(screen, flags, gc2,
++						x, y, 0, text++, 1);
++					x += FontWidth(screen);
++				}
++			} else {
++				x = drawXtermText(screen, flags, gc2,
++					x, y, 0, text, len);
++				x += len * FontWidth(screen);
++			}
+ 
+ 			TRACE(("drewtext [%4d,%4d]\n", y, x))
++			SAVE_FONT_INFO (screen);
+ 
+ 		} else {	/* simulate double-sized characters */
+ 			Char *temp = (Char *) malloc(2 * len);
+@@ -1407,20 +1457,47 @@
+ 		return x;
+ 	}
+ 
+-	TRACE(("drawtext%c[%4d,%4d] (%d) %d:%.*s\n",
+-		screen->cursor_state == OFF ? ' ' : '*',
+-		y, x, chrset, len, len, text))
+-	y += FontAscent(screen);
+-	XDrawImageString(screen->display, TextWindow(screen), gc,
+-		x, y,  (char *)text, len);
+-	if ((flags & (BOLD|BLINK)) && screen->enbolden)
+-		XDrawString(screen->display, TextWindow(screen), gc,
+-			x+1, y,  (char *)text, len);
+-	if ((flags & UNDERLINE) && screen->underline) {
+-		if (FontDescent(screen) > 1)
+-			y++;
+-		XDrawLine(screen->display, TextWindow(screen), gc,
+-			x, y, x + len * FontWidth(screen) - 1, y);
++	/* If the font is complete, draw it as-is */
++	if (screen->fnt_boxes) {
++		TRACE(("drawtext%c[%4d,%4d] (%d) %d:%.*s\n",
++			screen->cursor_state == OFF ? ' ' : '*',
++			y, x, chrset, len, len, text))
++		y += FontAscent(screen);
++		XDrawImageString(screen->display, TextWindow(screen), gc,
++			x, y,  (char *)text, len);
++		if ((flags & (BOLD|BLINK)) && screen->enbolden)
++			XDrawString(screen->display, TextWindow(screen), gc,
++				x+1, y,  (char *)text, len);
++		if ((flags & UNDERLINE) && screen->underline) {
++			if (FontDescent(screen) > 1)
++				y++;
++			XDrawLine(screen->display, TextWindow(screen), gc,
++				x, y, x + len * FontWidth(screen) - 1, y);
++		}
++#if OPT_BOX_CHARS
++#define DrawX(col) x + (col * FontWidth(screen))
++#define DrawSegment(first,last) (void)drawXtermText(screen, flags, gc, DrawX(first), y, chrset, text+first, last-first)
++	} else {	/* fill in missing box-characters */
++		XFontStruct *font = (flags & BOLD)
++				  ? screen->fnt_bold
++				  : screen->fnt_norm;
++		int last, first = 0;
++
++		screen->fnt_boxes = True;
++		for (last = 0; last < len; last++) {
++			if (xtermMissingChar(text[last], font)) {
++				if (last > first) {
++					DrawSegment(first,last);
++				}
++				xtermDrawBoxChar(screen, text[last], flags, gc, DrawX(last), y);
++				first = last + 1;
++			}
++		}
++		if (last > first) {
++			DrawSegment(first,last);
++		}
++		screen->fnt_boxes = False;
++#endif
+ 	}
+ 
+ 	return x + len * FontWidth(screen);
+@@ -1653,7 +1730,7 @@
+ 				bfr = (bfr != 0)
+ 					? realloc(bfr, length)
+ 					: malloc(length);
+-				if (bfr == NULL) 
++				if (bfr == NULL)
+ 				    SysError(ERROR_MMALLOC);
+ 			}
+ 			for (j = 0; j < n; j++)
+diff -u xc/programs/xterm/xterm.h.orig xc/programs/xterm/xterm.h
+--- xc/programs/xterm/xterm.h.orig	Fri Jul 30 09:12:24 1999
++++ xc/programs/xterm/xterm.h	Sun Jun 11 20:41:14 2000
+@@ -179,8 +179,8 @@
+ extern void CursorForward (TScreen *screen, int  n);
+ extern void CursorNextLine (TScreen *screen, int count);
+ extern void CursorPrevLine (TScreen *screen, int count);
+-extern void CursorRestore (XtermWidget tw, SavedCursor *sc);
+-extern void CursorSave (XtermWidget tw, SavedCursor *sc);
++extern void CursorRestore (XtermWidget tw);
++extern void CursorSave (XtermWidget tw);
+ extern void CursorSet (TScreen *screen, int row, int col, unsigned flags);
+ extern void CursorUp (TScreen *screen, int  n);
+ extern void Index (TScreen *screen, int amount);
+@@ -352,6 +352,7 @@
+ 		/* FIXME: Reverse-Video? */
+ #define getXtermBackground(flags, color) term->core.background_pixel
+ #define getXtermForeground(flags, color) term->screen.foreground
++#define makeColorPair(fg, bg) 0
+ #define xtermColorPair() 0
+ 
+ #define useCurBackground(flag) /*nothing*/
+diff -u xc/programs/xterm/xterm.log.html.orig xc/programs/xterm/xterm.log.html
+--- xc/programs/xterm/xterm.log.html.orig	Sun Jun 11 20:31:46 2000
++++ xc/programs/xterm/xterm.log.html	Sun Jun 11 20:41:14 2000
+@@ -41,6 +41,7 @@
+ xc/programs/Xserver/hw/xfree86).
+ 
+ <UL>
++<LI><A HREF="#xterm_90">Patch #90 - 1998/12/13 - XFree86 3.9Nq</A>
+ <LI><A HREF="#xterm_89">Patch #89 - 1998/11/20 - XFree86 3.9Nm</A>
+ <LI><A HREF="#xterm_88">Patch #88 - 1998/10/31 - XFree86 3.9Nk and 3.3.2h</A>
+ <LI><A HREF="#xterm_87">Patch #87 - 1998/10/21 - XFree86 3.9Nj and 3.3.2f</A>
+@@ -133,6 +134,84 @@
+ <LI><A HREF="#xterm_01">Patch #1 - 1996/1/6</A>
+ </UL>
+ 
++<H1><A NAME="xterm_90">Patch #90 - 1998/12/13 - XFree86 3.9Nq</A></H1>
++This implements several small fixes and enhancements.  The chief one implements
++fallback support for line drawing characters with fonts that do not include
++those characters.  But I implemented that last.
++
++<ul>
++	<li>If any of the glyphs in positions 0-31 (used by xterm to implement
++	  the VT100 alternate character set) are zero-sized (i.e., missing),
++	  xterm will reserve a normal space for the glyph when drawing.  I
++	  implemented a simple stroke-drawing function to draw the line-drawing
++	  characters and a couple of the other (simpler) characters such as
++	  diamond.  (This was suggested by Vikas Agnihotri).
++
++	<li>Modify the computation of doublesize characters to work around font
++	  servers which shift the scaled characters up/down or do not give the
++	  correct width.
++
++	<li>Add popup menu item and corresponding resource settings to disable
++	  the font-scaling logic for doublesize characters to work around
++	  (older) font servers which simply do not draw the fonts scaled to the
++	  size that they said they would.  I see this problem on a SunOS system
++	  running X11R5; the X11R6 servers seem well behaved.
++
++	<li>Implement new escape sequence, private mode 1049, which combines
++	  the switch to/from alternate screen mode with screen clearing and
++	  cursor save/restore.  Unlike the existing escape sequence, this
++	  clears the alternate screen when switching to it rather than when
++	  switching to the normal screen, thus retaining the alternate screen
++	  contents for select/paste operations.
++
++	<p>When I implemented the popup menu entry to toggle between the normal
++	  and alternate screens, I considered only pasting from the normal
++	  screen to the alternate; this improvement allows either direction.
++
++	<li>Changed the termcap and terminfo for xterm-xfree86 and xterm-8bit
++	  to use the new 1049 private mode.
++
++	<li>Modify the logic which switches between normal and alternate
++	  screens so that the save/restore cursor operations apply only to the
++	  current screen.  That means that applications which use the terminfo
++	  smcur/rmcur or termcap ti/te capabilities will restore the cursor to
++	  the original position on the normal screen rather than to the most
++	  recent place where a save-cursor operation was performed.
++
++	<p>I note that a real VT100 terminal would not behave in this way,
++	  but it is a moot point since the VT100 does not implement alternate
++	  screen, and therefore the save/restore cursor sequence would not be
++	  used in this context.  I reviewed the logic which switches between
++	  normal and alternate screens based on some recent newsgroup postings
++	  as well as a proposed patch in the Debian group which attempts to
++	  do this (the patch has a bug, however, so I did not use it).
++
++	<li>Add popup menu entry for toggling the titeInhibit resource.
++
++	<li>Add new resource answerbackString, which overrides the default
++	  "xterm" returned by xterm when responding to an ENQ (control/E)
++	  character (request by Rajesh Vaidheeswarran &lt;rv@fore.com&gt;).
++
++	<li>Add new resource keyboardDialect for setting the NRC display
++	  character set (request by Tomas Vanhala, who notes that I should
++	  add logic to translate the keyboard as well).
++
++	<li>Add new command-line option and corresponding resources for making
++	  xterm generate escape sequences compatible with HP terminals.  Like
++	  the existing Sun escape sequences, this is available as a popup menu
++	  item.  It is enabled by the configure script with the option
++	  --enable-hp-fkeys (requested by Toni Mueller &lt;sales@oeko.net&gt;).
++
++	<li>Add configure script option --disable-boxchars to disable the
++	  fallback support for line drawing characters.
++
++	<li>Fix ifdef's for configure script --disable-ansi-color, and reviewed
++	  all configure options to ensure that all can be enabled/disabled
++	  appropriately.
++
++	<li>Update config.guess and config.sub, from Lynx.
++</ul>
++
+ <H1><A NAME="xterm_89">Patch #89 - 1998/11/20 - XFree86 3.9Nm</A></H1>
+ This patch completes the implementation of double-sized character support
+ for the VT100 emulation, and fixes a few minor bugs:
+@@ -140,7 +219,7 @@
+ <ul>
+ <li>corrected the cursor position in HideCursor, which did not multiply
+ the column by two when in doublesize mode.
+-This bug, which did not appear in normal use, 
++This bug, which did not appear in normal use,
+ dates back to my original <a href="#xterm_44">changes</a> to partly implement
+ double-sized characters.
+ I noticed it when cat'ing a typescript from vttest's double-sized character
+@@ -213,15 +292,15 @@
+ Several small fixes and enhancements, including a patch from
+ Bjorn Helgaas:
+ <ul>
+-	<li>correct initialization of TERMCAP environment variable, which 
+-	  was frequently set to garbage on non-Linux systems because 
+-	  "termcap" and "newtc" contained random data from the stack. 
+- 
+-	<li>remove the LINEWRAPPED attribute from lines as they are cleared. 
+-	  Previously, the attribute was set but never cleared. 
+- 
+-	<li>make word and line selections work even when lines are wrapped 
+-	  by xterm.  Previously, selections were limited to one screen line. 
++	<li>correct initialization of TERMCAP environment variable, which
++	  was frequently set to garbage on non-Linux systems because
++	  "termcap" and "newtc" contained random data from the stack.
++
++	<li>remove the LINEWRAPPED attribute from lines as they are cleared.
++	  Previously, the attribute was set but never cleared.
++
++	<li>make word and line selections work even when lines are wrapped
++	  by xterm.  Previously, selections were limited to one screen line.
+ </ul>
+ as well as
+ <ul>
+@@ -319,7 +398,7 @@
+ 	  (those keys are too valuable to give up for a fine point of
+ 	  emulation).
+ 
+-	<li>corrected a couple of places in terminfo where I missed using the 
++	<li>corrected a couple of places in terminfo where I missed using the
+ 	  vt220-style editing-keypad codes for Find/Select (mapped to Home/End).
+ 
+ 	<li>checked termcap file against terminfo, fix several places where it
+@@ -331,17 +410,17 @@
+ This patch fixes several small bugs:
+ <ul>
+ 	<li>use X_EXTRA_LIBS in standalone Makefile.in (patch by Tomas Vanhala).
+- 
++
+ 	<li>add new resource 'oldXtermFKeys' which provides backward compatibility
+ 	  for F1-F4 control sequences with TOG's xterm.
+- 
++
+ 	<li>determine the server's default foreground/background Pixel values,
+ 	  needed if the -flipPixels X server option is used (reported by
+ 	  David Dawes).
+ 
+ 	<li>correct logic for F1-F4 function keys so that they generate VT100
+ 	  compatible escape sequences in VT220 mode, since that is what the
+-	  numeric keypad is supposed to do (reported by Ron Johnson, Jr. 
++	  numeric keypad is supposed to do (reported by Ron Johnson, Jr.
+ 	  &lt;ronjohn@communique.net&gt;).
+ 
+ 	<li>modify logic for editing keypad to work more like VT220: don't
+@@ -407,7 +486,7 @@
+ 
+ 	<li>document SGR 8, 28 (invisible/visible), add corresponding
+ 	  capabilities to terminfo description.
+-<p>	  
++<p>
+ 	  I would also add the 'prot protected capability, but the control
+ 	  sequences for that would not be recognized or properly ignored by the
+ 	  older xterm programs.
+@@ -593,20 +672,20 @@
+ <p>
+ From his description:
+ <blockquote>
+- This set of patches is the latest incarnation of patches originally 
+-written by Ian! D Allen, then of the University of Waterloo and now of 
+-who knows where; I have been carrying them forward from xterm to xterm 
+-ever since about X11R4.  What they do is add an option so that when an 
+-iconified xterm receives output it prepends '*** ' to its icon title 
+-and (optionally) beeps the bell; deiconifying the xterm removes the 
+-'*** '. Over the years I've found this to be incredibly convenient for 
+-monitoring all sorts of low-activity things. 
++ This set of patches is the latest incarnation of patches originally
++written by Ian! D Allen, then of the University of Waterloo and now of
++who knows where; I have been carrying them forward from xterm to xterm
++ever since about X11R4.  What they do is add an option so that when an
++iconified xterm receives output it prepends '*** ' to its icon title
++and (optionally) beeps the bell; deiconifying the xterm removes the
++'*** '. Over the years I've found this to be incredibly convenient for
++monitoring all sorts of low-activity things.
+ </blockquote>
+ 
+ <H1><A NAME="xterm_71">Patch #71 - 1998/4/12 - XFree86 3.9Ag and 3.3.2</A></H1>
+ 
+ This patch is a slightly modified version of one by Richard Braakman, which
+-prevents buffer overflow in the input-method and preedit-type parsing in xterm. 
++prevents buffer overflow in the input-method and preedit-type parsing in xterm.
+ I changed a couple of details to make the code more maintainable, and looked
+ for similar things - copying into a fixed-size buffer (found none, though I did
+ spot an unused variable).
+diff -u xc/programs/xterm/xterm.man.orig xc/programs/xterm/xterm.man
+--- xc/programs/xterm/xterm.man.orig	Sun Jun 11 20:31:46 2000
++++ xc/programs/xterm/xterm.man	Sun Jun 11 21:02:24 2000
+@@ -129,6 +129,8 @@
+ .IR vi (1)
+ to switch to the alternate screen for editing and to restore the screen
+ on exit.
++A popup menu entry makes it simple to switch between the normal and
++alternate screens for cut and paste.
+ .PP
+ In either VT102 or Tektronix mode, there are escape sequences to change the
+ name of the windows.
+@@ -162,7 +164,8 @@
+ This causes \fIxterm\fP to print out a verbose message describing its options.
+ The message is written to the standard error.
+ .PP
+-The other options are used to control the appearance and behavior:
++The other options are used to control the appearance and behavior.
++Not all options are necessarily configured into your copy of \fIxterm\fP.
+ .TP 8
+ .B \-132
+ Normally, the VT102 DECCOLM escape sequence that switches between 80 and
+@@ -303,6 +306,14 @@
+ set the stty erase value using the \fBkD\fP string from the termcap entry as 
+ a reference, if available. 
+ .TP 8
++.BI \-hf
++This option indicates that HP Function Key escape codes should be generated
++for function keys.
++.TP 8
++.BI \+hf
++This option indicates that HP Function Key escape codes should not be generated
++for function keys.
++.TP 8
+ .B \-im
+ Turn on the \fBuseInsertMode\fP resource.
+ .TP 8
+@@ -616,6 +627,10 @@
+ classes as well as:
+ .\".in +1in
+ .TP 8
++.B "hpFunctionKeys (\fPclass\fB HpFunctionKeys)"
++Specifies whether or not HP Function Key escape codes should be generated for
++function keys instead of standard escape sequences.
++.TP 8
+ .B "backarrowKeyIsErase (\fPclass\fB BackarrowKeyIsErase)" 
+ Tie the VTxxx \fBbackarrowKey\fP and \fBptyInitialErase\fP resources 
+ together by setting the DECBKM state according to whether the initial value of 
+@@ -717,7 +732,12 @@
+ the X protocol SendEvent request) should be interpreted or discarded.
+ The default is ``false'' meaning they are discarded.  Note that allowing
+ such events creates a very large security hole.
+-.sp
++.TP 8
++.B "answerbackString (\fPclass\fB AnswerbackString)"
++Specifies the string that xterm sends in response to an ENQ (control/E)
++character from the host.
++The default is the terminal name, e.g., ``xterm''.
++A hardware VT100 implements this feature as a setup option.
+ .TP 8
+ .B "alwaysHighlight (\fPclass\fB AlwaysHighlight)"
+ Specifies whether or not \fIxterm\fP should always display a highlighted
+@@ -932,6 +952,15 @@
+ .B "font6 (\fPclass\fB Font6)"
+ Specifies the name of the sixth alternative font.
+ .TP 8
++.B "fontDoublesize (\fPclass\fB FontDoublesize)"
++Specifies whether \fIxterm\fP should attempt to use font scaling to draw
++doublesize characters.
++Some older font servers cannot do this properly, will return misleading
++font metrics.
++The default is ``true''.
++If disabled, \fIxterm\fP will simulate doublesize characters by drawing
++normal characters with spaces between them.
++.TP 8
+ .B "foreground (\fPclass\fB Foreground)"
+ Specifies the color to use for displaying text in the window.  Setting the
+ class name instead of the instance name is an easy way to have everything
+@@ -976,6 +1005,13 @@
+ .B "jumpScroll (\fPclass\fB JumpScroll)"
+ Specifies whether or not jump scroll should be used.  The default is ``true.''
+ .TP 8
++.B "keyboardDialect (\fPclass\fB KeyboardDialect)"
++Specifies the initial keyboard dialect, as well as the default value when
++the terminal is reset.
++The value given is the same as the final character in the control sequences
++which change character sets.
++The default is ``B'', which corresponds to US ASCII.
++.TP 8
+ .B "loginShell (\fPclass\fB LoginShell)"
+ Specifies whether or not the shell to be run in the window should be started
+ as a login shell.  The default is ``false.''
+@@ -1131,6 +1167,9 @@
+ screen-oriented programs) from the TERMCAP string.  If set,
+ \fIxterm\fP also ignores the escape sequence to switch to the
+ alternate screen.
++\fIXterm\fP supports terminfo in a different way, supporting composite control
++sequences (also known as private modes) 1047, 1048 and 1049 which have the same
++effect as the original 47 control sequence.
+ .TP 8
+ .B "translations (\fPclass\fB Translations)"
+ Specifies the key and button bindings for menus, selections, ``programmed
+@@ -1294,8 +1333,8 @@
+ .B "marginbell (\fPclass\fB SmeBSB)"
+ This entry invokes the \fBset-marginbell(toggle)\fP action.
+ .TP 8
+-.B "altscreen (\fPclass\fB SmeBSB)"
+-This entry invokes the \fBset-altscreen(toggle)\fP action.
++.B "titeInhibit (\fPclass\fB SmeBSB)"
++This entry invokes the \fBset-titeInhibit(toggle)\fP action.
+ .TP 8
+ .B "activeicon (\fPclass\fB SMeBSB)"
+ This entry toggles active icons on and off if this feature was
+@@ -1326,6 +1365,9 @@
+ .TP 8
+ .B "vthide (\fPclass\fB SmeBSB)"
+ This entry invokes the \fBset-visibility(vt,off)\fP action.
++.TP 8
++.B "altscreen (\fPclass\fB SmeBSB)"
++This entry invokes the \fBset-altscreen(toggle)\fP action.
+ .\".in -1in
+ .sp
+ .PP
+@@ -1853,6 +1895,18 @@
+ This action toggles the \fBcurses\fP resource and is also invoked from the
+ \fBcursesemul\fP entry in \fIvtMenu\fP.
+ .TP 8
++.B "set-font-doublesize(\fIon/off/toggle\fP)"
++This action toggles the \fBfontDoublesize\fP resource and is also invoked by
++the \fBfont-doublesize\fP entry in \fIfontMenu\fP.
++.\" .TP 8
++.\" .B "set-font-loadable(\fIon/off/toggle\fP)"
++.\" This action toggles the \fBfontLoadable\fP resource and is also invoked by
++.\" the \fBfont-loadable\fP entry in \fIfontMenu\fP.
++.TP 8
++.B "set-hp-functionkeys(\fIon/off/toggle\fP)"
++This action toggles the \fBhpFunctionKeys\fP resource and is also invoked by
++the \fBhp function-keys\fP entry in \fImainMenu\fP.
++.TP 8
+ .B "set-jumpscroll(\fIon/off/toggle\fP)"
+ This action toggles the \fBjumpscroll\fP resource and is also invoked by the
+ \fBjumpscroll\fP entry in \fIvtMenu\fP.
+@@ -1884,6 +1938,14 @@
+ This action toggles the \fBscrollbar\fP resource and is also invoked by
+ the \fBscrollbar\fP entry in \fIvtMenu\fP.
+ .TP 8
++.B "set-sun-functionkeys(\fIon/off/toggle\fP)"
++This action toggles the \fBsunFunctionKeys\fP resource and is also invoked by
++the \fBsun function-keys\fP entry in \fImainMenu\fP.
++.TP 8
++.B "set-sun-keyboard(\fIon/off/toggle\fP)"
++This action toggles the \fBsunKeyboard\fP resource and is also invoked by
++the \fBsun keyboard\fP entry in \fImainMenu\fP.
++.TP 8
+ .B "set-tek-text(\fIlarge/2/3/small\fP)"
+ This action sets font used in the Tektronix window to the value of the
+ resources \fBtektextlarge\fP, \fBtektext2\fP, \fBtektext3\fP, and
+@@ -1895,6 +1957,10 @@
+ according to the \fItype\fP string.  It is also invoked by the
+ \fBtekmode\fP entry in \fIvtMenu\fP and the \fBvtmode\fP entry in
+ \fItekMenu\fP.
++.TP 8
++.B "set-titeInhibit(\fIon/off/toggle\fP)"
++This action toggles the \fBtiteInhibit\fP resource,
++which controls switching between the alternate and current screens.
+ .TP 8
+ .B "set-visibility(\fIvt/tek\fP,\fIon/off/toggle\fP)"
+ This action controls whether or not the \fIvt\fP or \fItek\fP windows are
+diff -u xc/programs/xterm/xtermcfg.hin.orig xc/programs/xterm/xtermcfg.hin
+--- xc/programs/xterm/xtermcfg.hin.orig	Sat Oct 24 03:58:30 1998
++++ xc/programs/xterm/xtermcfg.hin	Sun Jun 11 20:41:14 2000
+@@ -51,8 +51,10 @@
+ #undef NO_ACTIVE_ICON	/* CF_ARG_DISABLE(active-icon) */
+ #undef OWN_TERMINFO_DIR	/* AC_ARG_WITH(own-terminfo) */
+ #undef OPT_AIX_COLORS	/* CF_ARG_DISABLE(16-color) */
++#undef OPT_BOX_CHARS	/* CF_ARG_DISABLE(boxchars) */
+ #undef OPT_DEC_CHRSET	/* CF_ARG_DISABLE(doublechars) */
+ #undef OPT_HIGHLIGHT_COLOR /* CF_ARG_DISABLE(highlighting) */
++#undef OPT_HP_FUNC_KEYS	/* CF_ARG_ENABLE(hp-fkeys) */
+ #undef OPT_I18N_SUPPORT	/* CF_ARG_DISABLE(i18n) */
+ #undef OPT_INPUT_METHOD	/* CF_ARG_DISABLE(input-method) */
+ #undef OPT_ISO_COLORS	/* CF_ARG_DISABLE(ansi-color) */
--- xfree86-1-3.3.6.orig/debian/patches/000e_SPARC_sun.cf.diff
+++ xfree86-1-3.3.6/debian/patches/000e_SPARC_sun.cf.diff
@@ -0,0 +1,18 @@
+diff -urN xc/config/cf/sun.cf.orig xc/config/cf/sun.cf
+--- xc/config/cf/sun.cf.orig	Thu Jul 16 02:23:03 1998
++++ xc/config/cf/sun.cf	Fri Mar 12 17:26:00 1999
+@@ -251,6 +251,14 @@
+ # ifndef BuildPexExt
+ #  define BuildPexExt	  (XsunServer || Xsun24Server)
+ # endif
++#if (OSMajorVersion > 4)
++# ifdef UseGas
++#  define AsVISOption		-Av9a
++# else
++#  define AsVISOption		-xarch=v8plus
++#endif
++# define AsOutputArchSize	32
++#endif
+ #endif /* not i386Architecture */
+ 
+ #if (OSMajorVersion > 4) && defined(i386Architecture)
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-01-r128
+++ xfree86-1-3.3.6/debian/patches/0000fix-01-r128
@@ -0,0 +1,68 @@
+
+7 February 2000
+
+This patch fixes a text corruption problem that shows up with the
+Rage 128 driver in 3.3.6.  To use this patch you need either the
+XFree86 source tree or the LinkKit.  This patch cannot be used to
+patch binaries directly.  Updated binaries for most platforms should
+be available soon.
+
+To apply the patch to the XFree86 source tree, go the directory containing
+the main "xc" directory, and run:
+
+  patch -p0 -E < this-file
+
+
+
+Index: xc/programs/Xserver/hw/xfree86/vga256/drivers/r128/r128_accel.c
+===================================================================
+RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/vga256/drivers/r128/Attic/r128_accel.c,v
+retrieving revision 1.1.2.3
+diff -u -r1.1.2.3 r128_accel.c
+--- r128_accel.c	1999/11/18 15:37:32	1.1.2.3
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/r128/r128_accel.c	2000/01/28 03:23:14
+@@ -179,7 +179,7 @@
+     R128InfoPtr   info      = R128PTR();
+     unsigned char *R128MMIO = info->MMIO;
+ 
+-    R128WaitForFifo(3);
++    R128WaitForFifo(4);
+     OUTREG(R128_DP_GUI_MASTER_CNTL, (info->dp_gui_master_cntl
+ 				     | R128_GMC_BRUSH_SOLID_COLOR
+ 				     | R128_GMC_SRC_DATATYPE_COLOR
+@@ -188,6 +188,8 @@
+ 				     | R128_AUX_CLIP_DIS));
+     OUTREG(R128_DP_BRUSH_FRGD_CLR,  color);
+     OUTREG(R128_DP_WRITE_MASK,      planemask);
++    OUTREG(R128_DP_CNTL,            (R128_DST_X_LEFT_TO_RIGHT
++				     | R128_DST_Y_TOP_TO_BOTTOM));
+ }
+ 
+ /* Subsequent XAA FillRectSolid. */
+@@ -364,6 +366,9 @@
+     OUTREG(R128_DST_Y_X,            ((info->scanline_y++ << 16)
+ 				     | info->scanline_x));
+     OUTREG(R128_DST_HEIGHT_WIDTH,   info->scanline_h_w);
++
++				/* Correct for new XAA offset calculation */
++    p += ((srcAddr/8-1)/4);
+ 
+ #if R128_FAST_COLOR_EXPAND
+     while (left) {
+Index: xc/programs/Xserver/hw/xfree86/vga256/vga/vga.h
+===================================================================
+RCS file: /home/x-cvs/xc/programs/Xserver/hw/xfree86/vga256/vga/Attic/vga.h,v
+retrieving revision 3.23.2.7
+diff -u -r3.23.2.7 vga.h
+--- vga.h	1998/07/30 06:24:18	3.23.2.7
++++ xc/programs/Xserver/hw/xfree86/vga256/vga/vga.h	2000/02/05 19:31:53
+@@ -30,7 +30,7 @@
+ 
+ #define VGA2_PATCHLEVEL "0"
+ #define VGA16_PATCHLEVEL "0"
+-#define SVGA_PATCHLEVEL "0"
++#define SVGA_PATCHLEVEL "1"
+ 
+ #include "X.h"
+ #include "misc.h"
+
--- xfree86-1-3.3.6.orig/debian/patches/010b_xterm_manpage_utmp_pathname.diff
+++ xfree86-1-3.3.6/debian/patches/010b_xterm_manpage_utmp_pathname.diff
@@ -0,0 +1,25 @@
+--- xc/programs/xterm/xterm.man.orig	Mon May 10 09:10:05 1999
++++ xc/programs/xterm/xterm.man	Wed Dec  8 14:30:07 1999
+@@ -491,11 +491,11 @@
+ .TP 8
+ .B \-ut
+ This option indicates that \fIxterm\fP shouldn't write a record into the
+-the system log file \fI/etc/utmp\fP.
++the system log file \fI/var/run/utmp\fP.
+ .TP 8
+ .B \+ut
+ This option indicates that \fIxterm\fP should write a record into the system
+-log file \fI/etc/utmp\fP.
++log file \fI/var/run/utmp\fP.
+ .TP 8
+ .B \-vb
+ This option indicates that a visual bell is preferred over an audible one.
+@@ -697,7 +697,7 @@
+ .TP 8
+ .B "utmpInhibit (\fPclass\fB UtmpInhibit)"
+ Specifies whether or not \fIxterm\fP should try to record the user's terminal
+-in \fI/etc/utmp\fP.
++in \fI/var/run/utmp\fP.
+ .TP 8
+ .B "waitForMap (\fPclass\fB WaitForMap)"
+ Specifies whether or not \fIxterm\fP should wait for the initial window map
--- xfree86-1-3.3.6.orig/debian/patches/001a-02_SPARC_programs_Xserver.diff
+++ xfree86-1-3.3.6/debian/patches/001a-02_SPARC_programs_Xserver.diff
@@ -0,0 +1,69 @@
+--- xc/programs/Xserver/Imakefile.jj	Fri Dec  3 10:39:48 1999
++++ xc/programs/Xserver/Imakefile	Thu Jan 13 11:31:57 2000
+@@ -251,13 +251,21 @@ XCOMM Sun server
+ XCOMM
+ MFBDIR = mfb
+ CFB8DIR = cfb
++#ifdef LinuxArchitecture
++DDXDIR3 = hw/sun
++#else
+ DDXDIR1 = hw/sun
++#endif
+ #ifndef AmoebaArchitecture
+-SUNOBJS = hw/sun/sunInit.o
++#ifdef LinuxArchitecture
++SUNOBJS = hw/sun/sunInit.o hw/sun/sunGX.o hw/sun/sunCfb.o hw/sun/stubs.o
++#else
++SUNOBJS = hw/sun/sunInit.o hw/sun/sunGX.o hw/sun/sunCfb.o
++#endif
+ #else
+-SUNOBJS = hw/sun/sunInitColor.o
++SUNOBJS = hw/sun/sunInitColor.o hw/sun/sunGX.o hw/sun/sunCfb.o
+ #endif
+-SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(DDXDIR1) $(DEPDIRS)
++SUNDIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) hw/sun $(DEPDIRS)
+ SUNLIBS = hw/sun/LibraryTargetName(sun) CFB8Libs
+ SUNSYSLIBS = $(WIDECHARSYSLIB) $(SYSLIBS)
+ SetUIDServerTarget(Xsun,$(SUNDIRS),$(SUNOBJS),$(SUNLIBS),$(SUNSYSLIBS))
+@@ -276,10 +284,19 @@ CFB8DIR = cfb
+ CFB16DIR = cfb16
+ CFB24DIR = cfb24
+ CFB32DIR = cfb32
++#ifdef LinuxArchitecture
++DDXDIR3 = hw/sun
++#else
+ DDXDIR1 = hw/sun
+-SUN24DIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) $(DDXDIR1) $(DEPDIRS)
+-SUN24OBJS = hw/sun/sunInitMulti.o
+-SUN24LIBS = hw/sun/LibraryTargetName(sun) CFBLibs
++#endif
++DDXDIR2 = hw/sun/FFB hw/sun/LEO
++SUN24DIRS = $(STDDIRS) $(MFBDIR) $(CFB8DIR) $(CFB16DIR) $(CFB24DIR) $(CFB32DIR) hw/sun hw/sun/FFB hw/sun/LEO $(DEPDIRS)
++#ifdef LinuxArchitecture
++SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/sunGX.o hw/sun/sunCfb.o hw/sun/sunCfb24.o hw/sun/stubs.o
++#else
++SUN24OBJS = hw/sun/sunInitMulti.o hw/sun/sunGX.o hw/sun/sunCfb.o hw/sun/sunCfb24.o
++#endif
++SUN24LIBS = hw/sun/LibraryTargetName(sun) hw/sun/FFB/LibraryTargetName(FFB) hw/sun/LEO/LibraryTargetName(LEO) CFBLibs
+ SetUIDServerTarget(Xsun24,$(SUN24DIRS),$(SUN24OBJS),$(SUN24LIBS),$(SYSLIBS))
+ #ifndef ServerToInstall
+ #define ServerToInstall Xsun24
+@@ -292,9 +309,17 @@ XCOMM
+ XCOMM Sun monochrome server
+ XCOMM
+ MFBDIR = mfb
++#ifdef LinuxArchitecture
++DDXDIR3 = hw/sun
++#else
+ DDXDIR1 = hw/sun
+-SUNMDIRS = $(STDDIRS) $(MFBDIR) $(DDXDIR1) $(DEPDIRS)
++#endif
++SUNMDIRS = $(STDDIRS) $(MFBDIR) hw/sun $(DEPDIRS)
++#ifdef LinuxArchitecture
++SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o hw/sun/stubs.o
++#else
+ SUNMOBJS = hw/sun/sunInitMono.o hw/sun/sunInExMono.o
++#endif
+ SUNMLIBS = hw/sun/LibraryTargetName(sun) MFBBareLibs $(OTHEREXTS)
+ SetUIDServerTarget(XsunMono,$(SUNMDIRS),$(SUNMOBJS),$(SUNMLIBS),$(SYSLIBS))
+ #ifndef ServerToInstall
--- xfree86-1-3.3.6.orig/debian/patches/034_locale.dir_zh_CN+zh_HK_support.diff
+++ xfree86-1-3.3.6/debian/patches/034_locale.dir_zh_CN+zh_HK_support.diff
@@ -0,0 +1,13 @@
+--- xc/nls/locale.dir.orig	Mon May  1 23:25:06 2000
++++ xc/nls/locale.dir	Mon Jun  5 23:49:33 2000
+@@ -170,6 +170,10 @@
+ iso8859-9/XLC_LOCALE 	tr_TR.ISO8859-9
+ iso8859-5/XLC_LOCALE 	uk_UA.ISO8859-5
+ zh/XLC_LOCALE		zh_CN.eucCN
++zh/XLC_LOCALE		zh_CN.GB2312
++zh_CN.GBK/XLC_LOCALE	zh_CN.GBK
++zh_HK.Big5/XLC_LOCALE		zh_HK.Big5
++zh_HK.Big5HKSCS/XLC_LOCALE	zh_HK.Big5HKSCS
+ zh_TW/XLC_LOCALE	zh_TW.eucTW
+ zh_TW.Big5/XLC_LOCALE	zh_TW.Big5
+ en_US.utf/XLC_LOCALE    en_US.utf
--- xfree86-1-3.3.6.orig/debian/patches/035_XLC_LOCALE_zh_TW.Big5_substitute.diff
+++ xfree86-1-3.3.6/debian/patches/035_XLC_LOCALE_zh_TW.Big5_substitute.diff
@@ -0,0 +1,10 @@
+--- xc/nls/XLC_LOCALE/zh_TW.Big5.orig	Mon May  1 23:29:12 2000
++++ xc/nls/XLC_LOCALE/zh_TW.Big5	Mon May  1 23:29:54 2000
+@@ -25,6 +25,7 @@
+         }
+         font    {
+                 primary BIG5-0:GLGR
++                substitute BIG5-0:GLGR
+         }
+ }
+ END XLC_FONTSET
--- xfree86-1-3.3.6.orig/debian/patches/010c_xterm-debian_termcap_terminfo.diff
+++ xfree86-1-3.3.6/debian/patches/010c_xterm-debian_termcap_terminfo.diff
@@ -0,0 +1,140 @@
+--- xc/programs/xterm/termcap.orig	Sat Feb 26 02:54:36 2000
++++ xc/programs/xterm/termcap	Sat Feb 26 04:23:59 2000
+@@ -44,6 +44,13 @@
+ 	:up=\E[A:us=\E[4m:ue=\E[24m:xn:\
+ 	:ut:Co#8:op=\E[39;49m:AB=\E[4%dm:AF=\E[3%dm:\
+ 	:pa#64:Sf=\E[3%dm:Sb=\E[4%dm:
++# xterm-debian is identical to xterm-xfree86 except that it more strictly
++# conforms to DEC VT220 behavior in the case of the backspace and delete
++# keys; this is mandated by the keyboard configuration section of the
++# Debian Policy Manual.  Also see <http://vt100.net/docs/vt220-rm/>.
++xd|xterm-debian|Debian xterm (VT220-conformant backspace and delete):\
++	:kb=^?:kD=\E[3~:\
++	:tc=xterm-xfree86:
+ v1|xterm-24|xterms|vs100|24x80 xterm:\
+ 	:li#24:\
+ 	:tc=xterm:
+@@ -126,5 +133,6 @@
+ # is widely used for a variety of incompatible terminal emulations including
+ # color_xterm and rxvt.
+ v0|xterm|X11 terminal emulator:\
+-	:tc=xterm-xfree86:
++	:tc=xterm-debian:
++#	:tc=xterm-xfree86:
+ #	:tc=xterm-r6:
+--- xc/programs/xterm/terminfo.orig	Sat Feb 26 02:54:40 2000
++++ xc/programs/xterm/terminfo	Sat Feb 26 04:24:02 2000
+@@ -66,20 +66,20 @@
+ # vt220 does this only when in vt220 mode; when emulating a vt100 the editing
+ # keypad is inactive.
+ #
+-# Alternative keycodes: 
+-# -------------------- 
+-# Several of the function keys have alternative names, depending on the type of 
+-# host which your xterm is connected to.  DEC (i.e., the VMS system) uses F15 
+-# as the HELP key, F16 as the DO key.  Unix applications generally do not do 
+-# this.  Curses applications in particular, assign a unique keycode to each 
+-# capability string.  These terminal descriptions do not have conflicting 
+-# definitions, to ensure that Unix curses applications use a consistent set of 
+-# keycodes.  To get a VMS-bias, make these substitutions: 
+-#	1. change khome to kfnd 
+-#	2. change kend to kslt 
+-# Some legacy applications using the termcap emulation may expect kll where 
+-# we have specified kend. 
+-# 
++# Alternative keycodes:
++# --------------------
++# Several of the function keys have alternative names, depending on the type of
++# host which your xterm is connected to.  DEC (i.e., the VMS system) uses F15
++# as the HELP key, F16 as the DO key.  Unix applications generally do not do
++# this.  Curses applications in particular, assign a unique keycode to each
++# capability string.  These terminal descriptions do not have conflicting
++# definitions, to ensure that Unix curses applications use a consistent set of
++# keycodes.  To get a VMS-bias, make these substitutions:
++#	1. change khome to kfnd
++#	2. change kend to kslt
++# Some legacy applications using the termcap emulation may expect kll where
++# we have specified kend.
++#
+ xterm-xfree86|xterm-new|xterm terminal emulator (XFree86),
+ 	am,
+ 	bce,
+@@ -144,7 +144,7 @@
+ 	kcud1=\EOB,
+ 	kcuf1=\EOC,
+ 	kcuu1=\EOA,
+-	kdch1=\177, 
++	kdch1=\177,
+ 	kend=\E[4~,
+ 	kent=\EOM,
+ 	kf1=\EOP,
+@@ -210,6 +210,14 @@
+ 	u8=\E[?1;2c,
+ 	u9=\E[c,
+ 	vpa=\E[%i%p1%dd,
++# xterm-debian is identical to xterm-xfree86 except that it more strictly
++# conforms to DEC VT220 behavior in the case of the backspace and delete
++# keys; this is mandated by the keyboard configuration section of the
++# Debian Policy Manual.  Also see <http://vt100.net/docs/vt220-rm/>.
++xterm-debian|Debian xterm (VT220-conformant backspace and delete),
++	kbs=\177,
++	kdch1=\E[3~,
++	use=xterm-xfree86,
+ #
+ # The xterm-xfree86 description has all of the features, but is not completely
+ # compatible with vt220.  If you are using a Sun or PC keyboard, set the
+@@ -218,7 +226,7 @@
+ #	+ interprets control-function-key as a second array of keys, so a
+ #	  12-fkey keyboard can support vt220's 20-fkeys.
+ #	+ maps numeric keypad "+" to ",".
+-#	  
++#
+ xterm-vt220|XFree86 xterm emulating vt220,
+ 	kdch1=\E[3~,
+ 	kend=\E[4~,
+@@ -303,7 +311,7 @@
+ # Originally I suppressed setaf/setab, since ANSI specifies only 8 colors, but
+ # Stephen Marley persuaded me to allow the "ANSI" color controls to extend to
+ # 16 colors.  (Note that ncurses 4.2 uses setf/setb from this description;
+-# however 5.0 selects either according to their availability).  - T.Dickey 
++# however 5.0 selects either according to their availability).  - T.Dickey
+ #
+ # SVr4 curses does not use more than 8 colors anyway, so using 16 colors is
+ # either for terminfo-level applications or via ncurses.
+@@ -316,7 +324,7 @@
+ 	setb=%p1%{8}%/%{6}%*%{4}%+\E[%d%p1%{8}%m%Pa%?%ga%{1}%=%t4%e%ga%{3}%=%t6%e%ga%{4}%=%t1%e%ga%{6}%=%t3%e%ga%d%;m,
+ 	setf=%p1%{8}%/%{6}%*%{3}%+\E[%d%p1%{8}%m%Pa%?%ga%{1}%=%t4%e%ga%{3}%=%t6%e%ga%{4}%=%t1%e%ga%{6}%=%t3%e%ga%d%;m,
+ 	use=xterm-xfree86,
+-# 
++#
+ # This is an 8-bit version of xterm, which emulates DEC vt220 with ANSI color.
+ # To use it, your decTerminalID resource must be set to 200 or above.
+ #
+@@ -505,7 +513,7 @@
+ 	kcud1=\EOB,
+ 	kcuf1=\EOC,
+ 	kcuu1=\EOA,
+-	kdch1=\177, 
++	kdch1=\177,
+ 	kend=\E[4~,
+ 	kf1=\EOP,
+ 	kf10=\E[21~,
+@@ -610,7 +618,7 @@
+ 	kcud1=\EOB,
+ 	kcuf1=\EOC,
+ 	kcuu1=\EOA,
+-	kdch1=\177, 
++	kdch1=\177,
+ 	kdl1=\E[31~,
+ 	kel=\E[8~,
+ 	kend=\E[4~,
+@@ -652,6 +660,7 @@
+ # This is the only entry which you should have to customize, since "xterm"
+ # is widely used for a variety of incompatible terminal emulations including
+ # color_xterm and rxvt.
+-xterm|X11 terminal emulator, 
+-	use=xterm-xfree86,
++xterm|X11 terminal emulator,
++	use=xterm-debian,
++#	use=xterm-xfree86,
+ #	use=xterm-r6,
--- xfree86-1-3.3.6.orig/debian/patches/001-25_Xserver_os_Imakefile_ffsl.diff
+++ xfree86-1-3.3.6/debian/patches/001-25_Xserver_os_Imakefile_ffsl.diff
@@ -0,0 +1,17 @@
+diff -urN xfree86-3.3.3.1.upstream/programs/Xserver/os/Imakefile xfree86-3.3.3.1/programs/Xserver/os/Imakefile
+--- xfree86-3.3.3.1.upstream/programs/Xserver/os/Imakefile	Thu Nov  5 14:27:42 1998
++++ xfree86-3.3.3.1/programs/Xserver/os/Imakefile	Tue Mar 16 18:57:33 1999
+@@ -69,11 +69,11 @@
+            SRCS = WaitFor.c access.c connection.c io.c oscolor.c \
+                   osinit.c utils.c auth.c mitauth.c secauth.c $(XDMAUTHSRCS) \
+                   $(RPCSRCS) $(KRB5SRCS) xdmcp.c decompress.c OtherSources \
+-                  transport.c xalloc.c $(LBX_SRCS)
++                  transport.c xalloc.c ffsl.c $(LBX_SRCS)
+            OBJS = WaitFor.o access.o connection.o io.o oscolor.o \
+                   osinit.o utils.o auth.o mitauth.o secauth.o $(XDMAUTHOBJS) \
+                   $(RPCOBJS) $(KRB5OBJS) xdmcp.o decompress.o OtherObjects \
+-                  transport.o xalloc.o $(LBX_OBJS)
++                  transport.o xalloc.o ffsl.o $(LBX_OBJS)
+ 
+ #if SpecialMalloc
+      MEM_DEFINES = -DSPECIAL_MALLOC
--- xfree86-1-3.3.6.orig/debian/patches/010d_ALPHA_xterm_scren.c_cpp_bug_damnit.diff
+++ xfree86-1-3.3.6/debian/patches/010d_ALPHA_xterm_scren.c_cpp_bug_damnit.diff
@@ -0,0 +1,14 @@
+--- xc/programs/xterm/screen.c.orig	Sun Dec 12 04:04:05 1999
++++ xc/programs/xterm/screen.c	Sun Dec 12 04:05:27 1999
+@@ -29,6 +29,11 @@
+ 
+ /* screen.c */
+ 
++/* ghastly kludge for a ghastly bug */
++#ifdef __alpha__
++#undef __OPTIMIZE__
++#endif
++
+ #include <xterm.h>
+ #include <error.h>
+ #include <data.h>
--- xfree86-1-3.3.6.orig/debian/patches/026_xkb_symbols_macintosh_bksp_del_swap.diff
+++ xfree86-1-3.3.6/debian/patches/026_xkb_symbols_macintosh_bksp_del_swap.diff
@@ -0,0 +1,20 @@
+--- xc/programs/xkbcomp/symbols/macintosh/us.orig	Tue Feb 22 09:24:06 2000
++++ xc/programs/xkbcomp/symbols/macintosh/us	Tue Feb 22 09:24:39 2000
+@@ -20,7 +20,7 @@
+     key <AE10> {	[	  0,	parenright	]	};
+     key <AE11> {	[     minus,	underscore	]	};
+     key <AE12> {	[     equal,	plus		]	};
+-    key <BKSP> {	[ 	Delete			]	};
++    key <BKSP> {	[ 	BackSpace		]	};
+ 
+     key  <TAB> {	[ 	Tab,	ISO_Left_Tab	]	};
+     key <AD01> {	[	  q,	Q 		]	};
+@@ -98,7 +98,7 @@
+     key  <INS> {	[  Insert		]	};
+     key <HOME> {	[  Home			]	};
+     key <PGUP> {	[  Prior		]	};
+-    key <DELE> {	[  BackSpace		]	};
++    key <DELE> {	[  Delete		]	};
+     key  <END> {	[  End			]	};
+     key <PGDN> {	[  Next			]	};
+ 
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-02-svr4
+++ xfree86-1-3.3.6/debian/patches/0000fix-02-svr4
@@ -0,0 +1,62 @@
+--- solx86_mmap.c	1996/12/23 06:51:19	3.1
++++ xc/programs/Xserver/hw/xfree86/os-support/solx86/solx86_mmap.c	2000/02/08 20:32:10	3.1.2.1
+@@ -43,6 +43,8 @@
+ 	int fd;
+ 	unsigned char *ptr;
+ 	char	solx86_vtname[10];
++	int mlen;
++	int psize = 4096;	/* XXX x86 only */
+ 
+ 	/*
+      	 * Solaris 2.1 x86 SVR4 (10/27/93)
+@@ -56,8 +58,9 @@
+         	ErrorF("xf86ReadBios: Failed to open %s (%s)\n", solx86_vtname,
+                		strerror(errno));
+         	return(-1);
+-	}	
+-	ptr = mmap((caddr_t)0, 0x8000, PROT_READ, MAP_SHARED, fd, (off_t)Base);
++	}
++	mlen = (Offset + Len + psize - 1) & ~psize;
++	ptr = mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED, fd, (off_t)Base);
+ 	if ((int)ptr == -1)
+ 	{
+ 		ErrorF("xf86ReadBios: %s mmap failed\n", solx86_vtname);
+@@ -65,7 +68,7 @@
+ 		return(-1);
+ 	}
+ 	(void)memcpy(Buf, (void *)(ptr + Offset), Len);
+-	(void)munmap((caddr_t)ptr, 0x8000);
++	(void)munmap((caddr_t)ptr, mlen);
+ 	(void)close(fd);
+ 	return(Len);
+ }
+--- bios_V4mmap.c	1996/12/23 06:51:24	3.4
++++ xc/programs/Xserver/hw/xfree86/os-support/sysv/bios_V4mmap.c	2000/02/08 20:32:11	3.4.2.1
+@@ -42,6 +42,8 @@
+ {
+ 	int fd;
+ 	unsigned char *ptr;
++	int mlen;
++	int psize = 4096;	/* XXX x86 only */
+ 
+ 	if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
+ 	{
+@@ -49,7 +51,8 @@
+ 		       strerror(errno));
+ 		return(-1);
+ 	}
+-	ptr = (unsigned char *)mmap((caddr_t)0, 0x8000, PROT_READ, MAP_SHARED,
++	mlen = (Offset + Len + psize - 1) & ~psize;
++	ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED,
+ 				    fd, (off_t)Base);
+ 	if ((int)ptr == -1)
+ 	{
+@@ -58,7 +61,7 @@
+ 		return(-1);
+ 	}
+ 	(void)memcpy(Buf, (void *)(ptr + Offset), Len);
+-	(void)munmap((caddr_t)ptr, 0x8000);
++	(void)munmap((caddr_t)ptr, mlen);
+ 	(void)close(fd);
+ 	return(Len);
+ }
--- xfree86-1-3.3.6.orig/debian/patches/0000fix-03-mmap
+++ xfree86-1-3.3.6/debian/patches/0000fix-03-mmap
@@ -0,0 +1,44 @@
+--- bios_DGmmap.c	1999/07/19 11:46:43	1.1.2.2
++++ xc/programs/Xserver/hw/xfree86/os-support/dgux/bios_DGmmap.c	2000/02/11 21:26:16
+@@ -51,7 +51,7 @@
+ 		return(-1);
+ 	}
+ 	psize = sysconf(_SC_PAGESIZE);
+-	mlen = (Offset + Len + psize -1) & ~psize;
++	mlen = (Offset + Len + psize -1) & ~(psize - 1);
+ 	ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED,
+ 					fd, (off_t)Base);
+ 	if ((int)ptr == -1)
+--- lynx_mmap.c	1996/09/29 13:38:29	3.2
++++ xc/programs/Xserver/hw/xfree86/os-support/lynxos/lynx_mmap.c	2000/02/11 21:26:28
+@@ -44,7 +44,7 @@
+ 	char *p;
+ 	int mlen;
+ 
+-	mlen = (Offset + Len + 4095) & ~4096;
++	mlen = (Offset + Len + 4095) & ~4095;
+ 	p = smem_create("BIOS-probe", (char *)Base, mlen, SM_READ);
+ 	if (p == NULL)
+ 	{
+--- solx86_mmap.c	2000/02/08 20:32:10	3.1.2.1
++++ xc/programs/Xserver/hw/xfree86/os-support/solx86/solx86_mmap.c	2000/02/11 21:26:40
+@@ -59,7 +59,7 @@
+                		strerror(errno));
+         	return(-1);
+ 	}
+-	mlen = (Offset + Len + psize - 1) & ~psize;
++	mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ 	ptr = mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED, fd, (off_t)Base);
+ 	if ((int)ptr == -1)
+ 	{
+--- bios_V4mmap.c	2000/02/08 20:32:11	3.4.2.1
++++ xc/programs/Xserver/hw/xfree86/os-support/sysv/bios_V4mmap.c	2000/02/11 21:26:47
+@@ -51,7 +51,7 @@
+ 		       strerror(errno));
+ 		return(-1);
+ 	}
+-	mlen = (Offset + Len + psize - 1) & ~psize;
++	mlen = (Offset + Len + psize - 1) & ~(psize - 1);
+ 	ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, MAP_SHARED,
+ 				    fd, (off_t)Base);
+ 	if ((int)ptr == -1)
--- xfree86-1-3.3.6.orig/debian/patches/010e_xterm_logging_race_fixes.diff
+++ xfree86-1-3.3.6/debian/patches/010e_xterm_logging_race_fixes.diff
@@ -0,0 +1,194 @@
+--- xc/programs/xterm/Tekproc.c.orig	Wed Mar  1 09:10:52 2000
++++ xc/programs/xterm/Tekproc.c	Wed Mar  1 11:54:58 2000
+@@ -1726,7 +1726,8 @@
+ 
+ 	    setgid(screen->gid);
+ 	    setuid(screen->uid);
+-	    tekcopyfd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
++	    /* Close the window of opportunity by opening with O_EXCL. */
++	    tekcopyfd = open(buf, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ 	    if (tekcopyfd < 0)
+ 		_exit(1);
+ 	    sprintf(initbuf, "%c%c%c%c",
+--- xc/programs/xterm/main.c.orig	Wed Mar  1 09:18:05 2000
++++ xc/programs/xterm/main.c	Wed Mar  1 13:05:34 2000
+@@ -119,7 +119,11 @@
+ #define BSDLY	0
+ #define VTDLY	0
+ #define FFDLY	0
++#else /* MINIX */
++#ifdef DEBUG
++#include <time.h>
+ #endif
++#endif /* MINIX */
+ 
+ #ifdef att
+ #define ATT
+@@ -179,6 +183,7 @@
+ #undef  HAS_LTCHARS
+ #if __GLIBC__ >= 2
+ #include <pty.h>
++#include <stdlib.h> /* getpt() */
+ #endif
+ #endif
+ 
+@@ -1767,10 +1772,20 @@
+ 	/* Set up stderr properly.  Opening this log file cannot be
+ 	 done securely by a privileged xterm process (although we try),
+ 	 so the debug feature is disabled by default. */
++	time_t tstamp;
++	struct tm *tstruct;
++	char dbglogfile[35];
+ 	int i = -1;
+ 	if(debug) {
+-	        creat_as (getuid(), getgid(), "xterm.debug.log", 0666);
+-		i = open ("xterm.debug.log", O_WRONLY | O_TRUNC, 0666);
++		time(&tstamp);
++		tstruct = localtime(&tstamp);
++		sprintf(dbglogfile, "xterm.debug.log.%d-%02d-%02d.%02d:%02d:%02d",
++			tstruct->tm_year + 1900, tstruct->tm_mon + 1,
++			tstruct->tm_mday, tstruct->tm_hour,
++			tstruct->tm_min, tstruct->tm_sec);
++		if(creat_as (getuid(), getgid(), dbglogfile, 0666)) {
++			i = open (dbglogfile, O_WRONLY | O_TRUNC, 0666);
++		}
+ 	}
+ 	if(i >= 0) {
+ #if defined(USE_SYSV_TERMIO) && !defined(SVR4) && !defined(linux)
+@@ -1772,7 +1787,8 @@
+ #ifndef linux
+ 		stderr->_file = i;
+ #else
+-		setfileno(stderr, i);
++		fclose(stderr);
++		stderr = fdopen(i, "w"); /* you can do this with glibc */
+ #endif
+ #endif	/* USE_SYSV_TERMIO */
+ 
+--- xc/programs/xterm/misc.c.orig	Wed Mar  1 09:19:17 2000
++++ xc/programs/xterm/misc.c	Wed Mar  1 12:20:40 2000
+@@ -34,6 +34,9 @@
+ #include <ctype.h>
+ #include <pwd.h>
+ 
++#include <sys/types.h>
++#include <sys/wait.h>
++
+ #include <X11/Xatom.h>
+ #include <X11/cursorfont.h>
+ 
+@@ -506,21 +509,26 @@
+ #if defined(ALLOWLOGGING) || defined(DEBUG)
+ 
+ /*
+- * create a file only if we could with the permissions of the real user id.
++ * Create a file only if we could with the permissions of the real user id.
+  * We could emulate this with careful use of access() and following
+  * symbolic links, but that is messy and has race conditions.
+  * Forking is messy, too, but we can't count on setreuid() or saved set-uids
+  * being available.
+  *
+- * Note:  when called for user logging, we have ensured that the real and
++ * Note: When called for user logging, we have ensured that the real and
+  * effective user ids are the same, so this remains as a convenience function
+  * for the debug logs.
++ *
++ * Returns 1 if we can proceed to open the file in relative safety, 0
++ * otherwise.
+  */
+-void
++int
+ creat_as(int uid, int gid, char *pathname, int mode)
+ {
+     int fd;
+     int pid;
++    int retval = 0;
++    int childstat;
+ #ifndef HAVE_WAITPID
+     int waited;
+     SIGNAL_T (*chldfunc) (int);
+@@ -534,19 +542,19 @@
+     case 0:			/* child */
+ 	setgid(gid);
+ 	setuid(uid);
+-	fd = open(pathname, O_WRONLY|O_CREAT|O_APPEND, mode);
++	fd = open(pathname, O_WRONLY|O_CREAT|O_EXCL, mode);
+ 	if (fd >= 0) {
+ 	    close(fd);
+ 	    _exit(0);
+ 	} else
+ 	    _exit(1);
+     case -1:			/* error */
+-	return;
++	return retval;
+     default:			/* parent */
+ #ifdef HAVE_WAITPID
+-	waitpid(pid, NULL, 0);
++	waitpid(pid, &childstat, 0);
+ #else
+-	waited = wait(NULL);
++	waited = wait(&childstat);
+ 	signal(SIGCHLD, chldfunc);
+ 	/*
+ 	  Since we had the signal handler uninstalled for a while,
+@@ -558,6 +566,8 @@
+ 		Cleanup(0);
+ 	while ( (waited=nonblocking_wait()) > 0);
+ #endif
++	if(WIFEXITED(childstat)) retval = 1;
++	return retval;
+     }
+ }
+ #endif
+@@ -673,19 +683,17 @@
+ #endif
+ 	} else {
+ 		if(access(screen->logfile, F_OK) != 0) {
+-		    if (errno == ENOENT)
+-			creat_as(screen->uid, screen->gid,
+-				 screen->logfile, 0644);
+-		    else
+-			return;
++		    if (errno != ENOENT) return;
+ 		}
+ 
++		if(!(creat_as(screen->uid, screen->gid, screen->logfile, 0644))
++		    return;
+ 		if(access(screen->logfile, F_OK) != 0
+ 		   || access(screen->logfile, W_OK) != 0)
+ 		    return;
+ 		if((screen->logfd = open(screen->logfile, O_WRONLY | O_APPEND,
+ 					 0644)) < 0)
+-			return;
++		    return;
+ 	}
+ 	screen->logstart = CURRENT_EMU_VAL(screen, Tbptr, bptr);
+ 	screen->logging = TRUE;
+--- xc/programs/xterm/resize.c.orig	Wed Mar  1 12:53:48 2000
++++ xc/programs/xterm/resize.c	Wed Mar  1 13:00:21 2000
+@@ -282,6 +282,7 @@
+ #endif
+ #else
+ #include <curses.h>
++#include <term.h> /* tgetent() */
+ #endif /* HAVE_TERMCAP_H  */
+ #endif
+ 
+--- xc/programs/xterm/xterm.h.orig	Wed Mar  1 11:53:37 2000
++++ xc/programs/xterm/xterm.h	Wed Mar  1 11:54:22 2000
+@@ -223,6 +223,7 @@
+ extern int XStrCmp (char *s1, char *s2);
+ extern int xerror (Display *d, XErrorEvent *ev);
+ extern int xioerror (Display *dpy);
++extern int creat_as (int uid, int gid, char *pathname, int mode);
+ extern void Bell (int which, int percent);
+ extern void Changename (char *name);
+ extern void Changetitle (char *name);
+@@ -241,7 +242,6 @@
+ extern void Setenv (char *var, char *value);
+ extern void SysError (int i);
+ extern void VisualBell (void);
+-extern void creat_as (int uid, int gid, char *pathname, int mode);
+ extern void do_dcs (Char *buf, size_t len);
+ extern void do_osc (Char *buf, int len);
+ extern void do_xevents (void);
--- xfree86-1-3.3.6.orig/debian/patches/001a-03_SPARC_programs_Xserver_cfb.diff
+++ xfree86-1-3.3.6/debian/patches/001a-03_SPARC_programs_Xserver_cfb.diff
@@ -0,0 +1,107 @@
+--- xc/programs/Xserver/cfb/stipsparc.s.jj	Wed Apr 27 09:14:23 1994
++++ xc/programs/Xserver/cfb/stipsparc.s	Thu Jan 13 10:56:59 2000
+@@ -85,7 +85,7 @@ in this Software without prior written a
+ #define ForEachBits	LY4
+ #define NextBits	LY5
+ 
+-#ifdef SVR4
++#if defined(SVR4) || ( defined(linux) && defined(__ELF__) )
+ #ifdef TETEXT
+ #define	_cfbStippleStack	cfbStippleStackTE
+ #else
+--- xc/programs/Xserver/cfb/stipsprc32.s.jj	Wed Apr 27 09:14:23 1994
++++ xc/programs/Xserver/cfb/stipsprc32.s	Thu Jan 13 10:56:59 2000
+@@ -81,7 +81,7 @@ in this Software without prior written a
+ #define ForEachBits	LY4
+ #define NextBits	LY5
+ 
+-#ifdef SVR4
++#if defined(SVR4) || ( defined(linux) && defined(__ELF__) )
+ #ifdef TETEXT
+ #define	_cfb32StippleStack	cfb32StippleStackTE
+ #else
+--- xc/programs/Xserver/cfb/cfbrrop.h.jj	Wed Jan  8 21:32:41 1997
++++ xc/programs/Xserver/cfb/cfbrrop.h	Thu Jan 13 10:56:59 2000
+@@ -71,8 +71,8 @@ in this Software without prior written a
+ #define RROP_DECLARE	register unsigned long	rrop_xor;
+ #define RROP_SOLID(dst)	    (*(dst) = (rrop_xor))
+ #define RROP_SOLID_MASK(dst,mask) (*(dst) = (*(dst) & ~(mask)) | ((rrop_xor) & (mask)))
+-#define RROP_SOLID_lu(dst)	    stl_u(rrop_xor, dst)
+-#define RROP_SOLID_MASK_lu(dst,mask) stl_u((ldl_u(dst) & ~(mask)) | ((rrop_xor) & (mask)), dst)
++#define RROP_SOLID_lu(dst)	    stq_u(rrop_xor, dst)
++#define RROP_SOLID_MASK_lu(dst,mask) stq_u((ldq_u(dst) & ~(mask)) | ((rrop_xor) & (mask)), dst)
+ #endif
+ #define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Copy)
+ #endif /* GXcopy */
+@@ -107,6 +107,8 @@ in this Software without prior written a
+ #define RROP_FETCH_GCPRIV(devPriv)  rrop_xor = (devPriv)->xor;
+ #define RROP_SOLID(dst)	    (*(dst) ^= (rrop_xor))
+ #define RROP_SOLID_MASK(dst,mask) (*(dst) ^= ((rrop_xor) & (mask)))
++#define RROP_SOLID_lu(dst)  stq_u(ldq_u(dst) ^ rrop_xor, dst)
++#define RROP_SOLID_MASK_lu(dst,mask) stq_u(ldq_u(dst) ^ ((rrop_xor) & (mask)), dst)
+ #endif
+ #define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,Xor)
+ #endif /* GXxor */
+@@ -261,6 +263,8 @@ in this Software without prior written a
+ 				    rrop_xor = (devPriv)->xor;
+ #define RROP_SOLID(dst)	    (*(dst) = DoRRop (*(dst), rrop_and, rrop_xor))
+ #define RROP_SOLID_MASK(dst,mask)   (*(dst) = DoMaskRRop (*(dst), rrop_and, rrop_xor, (mask)))
++#define RROP_SOLID_lu(dst)  stq_u(DoRRop (ldq_u(dst), rrop_and, rrop_xor), dst)
++#define RROP_SOLID_MASK_lu(dst,mask) stq_u(DoMaskRRop (ldq_u(dst), rrop_and, rrop_xor, (mask)), dst)
+ #endif
+ #define RROP_NAME(prefix)   RROP_NAME_CAT(prefix,General)
+ #endif /* GXset */
+--- xc/programs/Xserver/cfb/cfb8line.c.jj	Fri Nov 13 15:14:33 1998
++++ xc/programs/Xserver/cfb/cfb8line.c	Thu Jan 13 11:31:01 2000
+@@ -898,7 +898,11 @@ FUNC_NAME(cfb8LineSS1Rect) (pDrawable, p
+ 		if (x1_or_len)
+ 		  {
+ 		    maskpartialbits(y1_or_e1, x1_or_len, e)
+-		      RROP_SOLID_MASK((unsigned long *) addrp, e);
++#ifdef __sparc__
++                      RROP_SOLID_MASK_lu((unsigned long *) addrp, e);
++#else
++                      RROP_SOLID_MASK((unsigned long *) addrp, e);
++#endif
+ 		  }
+ 	      }
+ 	    else
+@@ -909,13 +913,13 @@ FUNC_NAME(cfb8LineSS1Rect) (pDrawable, p
+ 		    RROP_SOLID_MASK((unsigned long *) addrp, e);
+ 		    addrp += PPW;
+ 	    	}
+-#if 0
++#ifdef __sparc__
+ 		RROP_SPAN_lu(addrp, x1_or_len)
+ #else
+ 		RROP_SPAN(addrp, x1_or_len)
+ #endif
+ 	    	if (e3)
+-#if 0
++#ifdef __sparc__
+ 		    RROP_SOLID_MASK_lu((unsigned long *) addrp, e3);
+ #else
+ 		    RROP_SOLID_MASK((unsigned long *) addrp, e3);
+--- xc/programs/Xserver/cfb/cfballpriv.c.jj	Wed Apr 27 09:14:13 1994
++++ xc/programs/Xserver/cfb/cfballpriv.c	Thu Jan 13 11:57:37 2000
+@@ -77,9 +77,17 @@ cfbAllocatePrivates(pScreen, window_inde
+ 	return FALSE;
+     cfbPuntCopyPlane = miCopyPlane;
+ #ifdef CFB_NEED_SCREEN_PRIVATE
+-    cfbScreenPrivateIndex = AllocateScreenPrivateIndex ();
+-    if (cfbScreenPrivateIndex == -1)
+-	return FALSE;
++    {
++	    static int cfbGeneration = -1;
++
++	    if (cfbGeneration != serverGeneration)
++	    {
++		    cfbScreenPrivateIndex = AllocateScreenPrivateIndex ();
++		    if (cfbScreenPrivateIndex == -1)
++			    return FALSE;
++		    cfbGeneration = serverGeneration;
++	    }
++    }
+ #endif
+     return TRUE;
+ }
--- xfree86-1-3.3.6.orig/debian/patches/032_i810_chipset_support.diff
+++ xfree86-1-3.3.6/debian/patches/032_i810_chipset_support.diff
@@ -0,0 +1,127 @@
+--- xc/include/Xpoll.h.orig	Sun Jan 30 19:21:15 2000
++++ xc/include/Xpoll.h	Sun Jan 30 20:14:16 2000
+@@ -127,51 +127,55 @@
+  * macros if the system has fewer than 256 bits in the fd_set bit
+  * array.
+  */
++#ifndef __FDS_BITS
++#define __FDS_BITS(p) ((p)->fds_bits)
++#endif
++
+ #define XFD_ANYSET(p) \
+-		((p)->fds_bits[0] || (p)->fds_bits[1] || \
+-		(p)->fds_bits[2] || (p)->fds_bits[3] || \
+-		(p)->fds_bits[4] || (p)->fds_bits[5] || \
+-		(p)->fds_bits[6] || (p)->fds_bits[7])
++		(__FDS_BITS(p)[0] || __FDS_BITS(p)[1] || \
++		__FDS_BITS(p)[2] || __FDS_BITS(p)[3] || \
++		__FDS_BITS(p)[4] || __FDS_BITS(p)[5] || \
++		__FDS_BITS(p)[6] || __FDS_BITS(p)[7])
+ 
+ #define XFD_COPYSET(src,dst) \
+-		(dst)->fds_bits[0] = (src)->fds_bits[0]; \
+-		(dst)->fds_bits[1] = (src)->fds_bits[1]; \
+-		(dst)->fds_bits[2] = (src)->fds_bits[2]; \
+-		(dst)->fds_bits[3] = (src)->fds_bits[3]; \
+-		(dst)->fds_bits[4] = (src)->fds_bits[4]; \
+-		(dst)->fds_bits[5] = (src)->fds_bits[5]; \
+-		(dst)->fds_bits[6] = (src)->fds_bits[6]; \
+-		(dst)->fds_bits[7] = (src)->fds_bits[7];
++		__FDS_BITS(dst)[0] = __FDS_BITS(src)[0]; \
++		__FDS_BITS(dst)[1] = __FDS_BITS(src)[1]; \
++		__FDS_BITS(dst)[2] = __FDS_BITS(src)[2]; \
++		__FDS_BITS(dst)[3] = __FDS_BITS(src)[3]; \
++		__FDS_BITS(dst)[4] = __FDS_BITS(src)[4]; \
++		__FDS_BITS(dst)[5] = __FDS_BITS(src)[5]; \
++		__FDS_BITS(dst)[6] = __FDS_BITS(src)[6]; \
++		__FDS_BITS(dst)[7] = __FDS_BITS(src)[7];
+ 
+ #define XFD_ANDSET(dst,b1,b2) \
+-		(dst)->fds_bits[0] = ((b1)->fds_bits[0] & (b2)->fds_bits[0]); \
+-		(dst)->fds_bits[1] = ((b1)->fds_bits[1] & (b2)->fds_bits[1]); \
+-		(dst)->fds_bits[2] = ((b1)->fds_bits[2] & (b2)->fds_bits[2]); \
+-		(dst)->fds_bits[3] = ((b1)->fds_bits[3] & (b2)->fds_bits[3]); \
+-		(dst)->fds_bits[4] = ((b1)->fds_bits[4] & (b2)->fds_bits[4]); \
+-		(dst)->fds_bits[5] = ((b1)->fds_bits[5] & (b2)->fds_bits[5]); \
+-		(dst)->fds_bits[6] = ((b1)->fds_bits[6] & (b2)->fds_bits[6]); \
+-		(dst)->fds_bits[7] = ((b1)->fds_bits[7] & (b2)->fds_bits[7]);
++		__FDS_BITS(dst)[0] = (__FDS_BITS(b1)[0] & __FDS_BITS(b2)[0]); \
++		__FDS_BITS(dst)[1] = (__FDS_BITS(b1)[1] & __FDS_BITS(b2)[1]); \
++		__FDS_BITS(dst)[2] = (__FDS_BITS(b1)[2] & __FDS_BITS(b2)[2]); \
++		__FDS_BITS(dst)[3] = (__FDS_BITS(b1)[3] & __FDS_BITS(b2)[3]); \
++		__FDS_BITS(dst)[4] = (__FDS_BITS(b1)[4] & __FDS_BITS(b2)[4]); \
++		__FDS_BITS(dst)[5] = (__FDS_BITS(b1)[5] & __FDS_BITS(b2)[5]); \
++		__FDS_BITS(dst)[6] = (__FDS_BITS(b1)[6] & __FDS_BITS(b2)[6]); \
++		__FDS_BITS(dst)[7] = (__FDS_BITS(b1)[7] & __FDS_BITS(b2)[7]);
+ 
+ #define XFD_ORSET(dst,b1,b2) \
+-		(dst)->fds_bits[0] = ((b1)->fds_bits[0] | (b2)->fds_bits[0]); \
+-		(dst)->fds_bits[1] = ((b1)->fds_bits[1] | (b2)->fds_bits[1]); \
+-		(dst)->fds_bits[2] = ((b1)->fds_bits[2] | (b2)->fds_bits[2]); \
+-		(dst)->fds_bits[3] = ((b1)->fds_bits[3] | (b2)->fds_bits[3]); \
+-		(dst)->fds_bits[4] = ((b1)->fds_bits[4] | (b2)->fds_bits[4]); \
+-		(dst)->fds_bits[5] = ((b1)->fds_bits[5] | (b2)->fds_bits[5]); \
+-		(dst)->fds_bits[6] = ((b1)->fds_bits[6] | (b2)->fds_bits[6]); \
+-		(dst)->fds_bits[7] = ((b1)->fds_bits[7] | (b2)->fds_bits[7]);
++		__FDS_BITS(dst)[0] = (__FDS_BITS(b1)[0] | __FDS_BITS(b2)[0]); \
++		__FDS_BITS(dst)[1] = (__FDS_BITS(b1)[1] | __FDS_BITS(b2)[1]); \
++		__FDS_BITS(dst)[2] = (__FDS_BITS(b1)[2] | __FDS_BITS(b2)[2]); \
++		__FDS_BITS(dst)[3] = (__FDS_BITS(b1)[3] | __FDS_BITS(b2)[3]); \
++		__FDS_BITS(dst)[4] = (__FDS_BITS(b1)[4] | __FDS_BITS(b2)[4]); \
++		__FDS_BITS(dst)[5] = (__FDS_BITS(b1)[5] | __FDS_BITS(b2)[5]); \
++		__FDS_BITS(dst)[6] = (__FDS_BITS(b1)[6] | __FDS_BITS(b2)[6]); \
++		__FDS_BITS(dst)[7] = (__FDS_BITS(b1)[7] | __FDS_BITS(b2)[7]);
+ 
+ #define XFD_UNSET(dst,b1) \
+-		(dst)->fds_bits[0] &= ~((b1)->fds_bits[0]); \
+-		(dst)->fds_bits[1] &= ~((b1)->fds_bits[1]); \
+-		(dst)->fds_bits[2] &= ~((b1)->fds_bits[2]); \
+-		(dst)->fds_bits[3] &= ~((b1)->fds_bits[3]); \
+-		(dst)->fds_bits[4] &= ~((b1)->fds_bits[4]); \
+-		(dst)->fds_bits[5] &= ~((b1)->fds_bits[5]); \
+-		(dst)->fds_bits[6] &= ~((b1)->fds_bits[6]); \
+-		(dst)->fds_bits[7] &= ~((b1)->fds_bits[7]);
++		__FDS_BITS(dst)[0] &= ~(__FDS_BITS(b1)[0]); \
++		__FDS_BITS(dst)[1] &= ~(__FDS_BITS(b1)[1]); \
++		__FDS_BITS(dst)[2] &= ~(__FDS_BITS(b1)[2]); \
++		__FDS_BITS(dst)[3] &= ~(__FDS_BITS(b1)[3]); \
++		__FDS_BITS(dst)[4] &= ~(__FDS_BITS(b1)[4]); \
++		__FDS_BITS(dst)[5] &= ~(__FDS_BITS(b1)[5]); \
++		__FDS_BITS(dst)[6] &= ~(__FDS_BITS(b1)[6]); \
++		__FDS_BITS(dst)[7] &= ~(__FDS_BITS(b1)[7]);
+ 
+ #else /* USE_POLL */
+ #include <sys/poll.h>
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/Imakefile.orig	Sat Dec 11 17:31:20 1999
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/Imakefile	Sun Jan 30 18:19:50 2000
+@@ -21,7 +21,8 @@
+        mga/?*.c mx/?*.c ncr77c22/?*.c oak/?*.c pvga1/?*.c realtek/?*.c \
+        sis/?*.c tvga8900/?*.c video7/?*.c nv/?*.c compaq/?*.c s3v/?*.c \
+        rendition/?*.c p9x00/?*.c cyrix/?*.c neo/?*.c spc8110/?*.c \
+-       s3_svga.c/?*.c i740/?*.c tdfx/?*.c r128/?*.c smi/?*.c
++       s3_svga.c/?*.c i740/?*.c tdfx/?*.c r128/?*.c smi/?*.c \
++       i810/?*.c
+ XCOMM s3_savage/?*.c 
+ 
+ OBJS = al2101/?*_drv.o ali/?*_drv.o apm/?*_drv.o ark/?*_drv.o ati/?*_drv.o \
+@@ -32,7 +33,8 @@
+        nv/?*_drv.o compaq/?*_drv.o s3v/?*_drv.o rendition/?*_drv.o \
+        p9x00/?*_drv.o cyrix/?*_drv.o neo/?*_drv.o spc8110/?*_drv.o \
+        s3_svga/?*_drv.o i740/?*_drv.o tdfx/?*_drv.o r128/?*_drv.o \
+-       smi/?*_drv.o
++       smi/?*_drv.o \
++       i810/?*.o
+ XCOMM s3_savage/?*.o 
+ 
+ #endif
+--- xc/programs/Xserver/hw/xfree86/vga256/drivers/i810/i810_memory.c.orig	Thu May 25 10:14:09 2000
++++ xc/programs/Xserver/hw/xfree86/vga256/drivers/i810/i810_memory.c	Thu May 25 10:14:24 2000
+@@ -54,7 +54,7 @@
+ #include "i810.h"
+ #include "i810_reg.h"
+ 
+-#include <agpgart.h>
++#include "os-support/linux/agpgart.h"
+ 
+ /* DcachePtr will be set up, but not used. 
+  */
--- xfree86-1-3.3.6.orig/debian/patches/001a-04_SPARC_programs_Xserver_hw_sun.diff
+++ xfree86-1-3.3.6/debian/patches/001a-04_SPARC_programs_Xserver_hw_sun.diff
@@ -0,0 +1,18208 @@
+--- xc/programs/Xserver/hw/sun/Imakefile.jj	Sun Dec 22 04:35:34 1996
++++ xc/programs/Xserver/hw/sun/Imakefile	Thu Jan 13 11:31:13 2000
+@@ -16,24 +16,29 @@ SRCS1 =	sunInit.c \
+ SRCS =	$(SRCS1) kbd_mode.c constype.c
+ 
+ #ifdef i386Architecture
+-OFILES = sunInit.o
++OFILES = sunInit.o sunGX.o sunCfb.o sunCfb24.o
+ #else
+-OFILES = sunInit.o sunInitMono.o sunInExMono.o sunInitMulti.o
++OFILES = sunInit.o sunInitMono.o sunInExMono.o sunInitMulti.o sunGX.o sunCfb.o sunCfb24.o
+ #endif
+ 
+-OBJS = 	sunCfb.o \
+-	sunCfb24.o \
+-	sunCursor.o \
++#ifdef LinuxArchitecture
++LINUXOBJS = linux.o stubs.o
++#else
++LINUXOBJS =
++#endif
++
++OBJS =  sunCursor.o \
+ 	sunFbs.o \
+ 	sunIo.o \
+ 	sunKbd.o \
+ 	sunMfb.o \
+ 	sunMouse.o \
+-	sunGX.o \
+-	sunKeyMap.o
++	sunKeyMap.o \
++	$(LINUXOBJS)
+ 
+    INCLUDES = -I. -I../.. -I../../mi -I../../mfb -I../../cfb -I../../cfb32 \
+-	      -I../../include -I$(XINCLUDESRC) -I$(FONTINCSRC)
++	      -I../../include -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC) \
++	      -I$(LIBSRC)/font/include
+    LINTLIBS = ../../dix/llib-ldix.ln ../../os/llib-los.ln \
+ 	      ../mfb/llib-lmfb.ln ../mi/llib-lmi.ln ../cfb/llib-lcfb.ln
+ 
+@@ -46,9 +51,17 @@ lintlib:
+ NormalLibraryTarget(sun,$(OBJS))
+ NormalLintTarget($(SRCS1))
+ 
++#ifdef LinuxArchitecture
++LinkSourceFile(stubs.c,../../Xi)
++#endif
++
++SpecialCObjectRule(sunCfb,,)
++SpecialCObjectRule(sunCfb24,,)
++SpecialCObjectRule(sunGX,,)
++
+ #ifndef i386Architecture
+ sunInExMono.o: $(ICONFIGFILES)
+-ObjectFromSpecialSource(sunInExMono,../../mi/miinitext,$(EXT_DEFINES) -UPEXEXT)
++ObjectFromSpecialSource(sunInExMono,../../mi/miinitext,$(EXT_DEFINES) -UPEXEXT -UXINPUT -UXF86VIDMODE -UXFreeXDGA -UXF86MISC -UGLXEXT)
+ ObjectFromSpecialSource(sunInitMono,sunInit,-DSUNMAXDEPTH=1)
+ ObjectFromSpecialSource(sunInitMulti,sunInit,-DSUNMAXDEPTH=32)
+ #endif
+--- xc/programs/Xserver/hw/sun/Xsun.man.jj	Sun Dec 22 04:35:35 1996
++++ xc/programs/Xserver/hw/sun/Xsun.man	Thu Jan 13 10:56:59 2000
+@@ -42,13 +42,14 @@ that runs the program \fIxinit(1)\fP.
+ supports the BW2 monochrome frame buffer.
+ .I Xsun
+ supports the CG2, CG3, CG4, and CG6 8-bit color frame buffers in
+-addition to the BW2 monochrome frame buffer. On Solaris 2.5 it also
+-supports the TCX as an 8-bit color frame buffer.
++addition to the BW2 monochrome frame buffer. On Solaris 2.5 and on Linux
++it also supports the TCX as an 8-bit color frame buffer.
+ .I Xsun24
+ supports the cgeight 24-bit color frame buffer in addition to the
+ 8-bit color and monochrome frame buffers that
+ .I Xsun
+-supports.
++supports. On Linux it supports TCX, CG14 and Creator/Creator3D in
++24-bit color mode in addition to these.
+ .PP
+ If specific framebuffer device files aren't specified on the command 
+ line with the \fI\-dev\fP switch or in the \fIXDEVICE\fP environment
+--- xc/programs/Xserver/hw/sun/constype.c.jj	Mon Dec 23 07:30:11 1996
++++ xc/programs/Xserver/hw/sun/constype.c	Thu Jan 13 10:56:59 2000
+@@ -77,18 +77,24 @@ main (argc, argv)
+ #include <fcntl.h>
+ #include <sys/fbio.h>
+ #else
++#ifdef linux
++#include <asm/types.h>
++#include <asm/fbio.h>
++#else
+ #ifndef CSRG_BASED
+ #include <sun/fbio.h>
+ #else
+ #include <machine/fbio.h>
+ #endif
+ #endif
++#endif
+ 
+ /* Sun doesn't see fit to update <sys/fbio.h> to reflect the addition
+  * of the TCX 
+  */
+ #define XFBTYPE_TCX		21
+-#define XFBTYPE_LASTPLUSONE	22
++#define XFBTYPE_FFB		22
++#define XFBTYPE_LASTPLUSONE	23
+ 
+ /* decoding as of Release 3.4 : fbio.h 1.3 87/01/09 SMI */
+ 	/* the convention for entries in this table is to translate the
+@@ -162,6 +168,9 @@ int wu_fbid(devname, fbname, fbtype)
+ 	if (fbattr.fbtype.fb_type>=FBTYPE_LASTPLUSONE) {
+ 	    if (fbattr.fbtype.fb_type == XFBTYPE_TCX) {
+ 		*fbname = "tcx";
++		return 0;
++	    } else if (fbattr.fbtype.fb_type == XFBTYPE_FFB) {
++		*fbname = "creator/ffb";
+ 		return 0;
+ 	    } else {
+ 		*fbname = "unk";
+--- xc/programs/Xserver/hw/sun/kbd_mode.c.jj	Mon Dec 23 07:30:12 1996
++++ xc/programs/Xserver/hw/sun/kbd_mode.c	Thu Jan 13 10:56:59 2000
+@@ -53,12 +53,41 @@ static  char sccsid[] = "@(#)kbd_mode.c 
+ #include </sys/sparc/dev/kbd.h>
+ #endif
+ #else
+-#ifndef CSRG_BASED
++#ifdef CSRG_BASED
++#include <machine/kbio.h>
++#include <machine/kbd.h>
++#else
++#ifndef linux
+ #include <sundev/kbio.h>
+ #include <sundev/kbd.h>
+ #else
+-#include <machine/kbio.h>
+-#include <machine/kbd.h>
++#include <asm/kbio.h>
++/*
++ * Commands to the Sun-2 keyboard.
++ */
++#define KBD_CMD_RESET           0x01    /* Reset keyboard as if power-up */
++#define KBD_CMD_BELL            0x02    /* Turn on the bell */
++#define KBD_CMD_NOBELL          0x03    /* Turn off the bell */
++#define KBD_CMD_LED1            0x04    /* Turn on LED 1 */
++#define KBD_CMD_NOLED1          0x05    /* Turn off LED 1 */
++#define KBD_CMD_LED2            0x06    /* Turn on LED 2 */
++#define KBD_CMD_NOLED2          0x07    /* Turn off LED 2 */
++
++/*
++ * Commands to the Type 3 keyboard.  KBD_CMD_BELL & KBD_CMD_NOBELL work
++ * as well.
++ */
++#define KBD_CMD_CLICK           0x0A    /* Turn on the click annunciator */
++#define KBD_CMD_NOCLICK         0x0B    /* Turn off the click annunciator */
++
++/*
++ * Commands to the Type 4 keyboard, in addition to those above.
++ */
++#define KBD_CMD_SETLED          0x0E    /* Set keyboard LED's */
++#define KBD_CMD_GETLAYOUT       0x0F    /* Request that keyboard indicate layout
++ */
++
++#endif
+ #endif
+ #endif
+ #include <stdio.h>
+--- xc/programs/Xserver/hw/sun/linux.c.jj	Thu Jan 13 10:56:59 2000
++++ xc/programs/Xserver/hw/sun/linux.c	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,541 @@
++/* $Xsun: xc/programs/Xserver/hw/xc/programs/Xserver/hw/sun/linux.c,v 3.3 1995/06/24 10:29:11 dawes Exp $ */
++/*
++ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
++ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
++ * Copyright 1996,1998 by Jakub Jelinek <jj@sunsite.mff.cuni.cz>
++ *
++ * Permission to use, copy, modify, distribute, and sell this software and its
++ * documentation for any purpose is hereby granted without fee, provided that
++ * the above copyright notice appear in all copies and that both that
++ * copyright notice and this permission notice appear in supporting
++ * documentation, and that the names of Orest Zborowski and David Wexelblat 
++ * not be used in advertising or publicity pertaining to distribution of 
++ * the software without specific, written prior permission.  Orest Zborowski
++ * and David Wexelblat make no representations about the suitability of this 
++ * software for any purpose.  It is provided "as is" without express or 
++ * implied warranty.
++ *
++ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD 
++ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 
++ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE 
++ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
++ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
++ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
++ *
++ */
++/* $XConsortium: linux.c /main/4 1995/11/13 05:58:38 kaleb $ */
++
++#define NEED_EVENTS
++#include "sun.h"
++#include <linux/vt.h>
++#include <unistd.h>
++#include <fcntl.h>
++#include <asm/ioctls.h>
++#include <signal.h>
++#include <linux/kd.h>
++#include <sys/stat.h>
++#include <sys/mman.h>
++#include <errno.h>
++#include <stdio.h>
++
++static Bool KeepTty = FALSE;
++static int VTnum = -1;
++static int activeVT = -1;
++int consoleFd = -1;
++int vtno;
++static Bool linuxExiting = FALSE;
++Bool vtRequestsPending = FALSE;
++void *vtOn;
++Bool vtSema = TRUE;
++DevicePtr linuxMouse, linuxKeyboard;
++Bool NoVT = FALSE;
++static int cursorOn = FALSE;
++static int console_screen_idx = -1;
++static PixmapPtr ppix = NULL;
++static pointer sunscreen = NULL;
++static int sunscreen_devKind;
++extern char *defaultFontPath;
++
++static void linuxEnterLeaveVT(Bool enter)
++{
++    ScreenPtr pScreen;
++    PixmapPtr pspix;
++    BoxRec pixBox;
++    RegionRec pixReg;
++    DDXPointRec pixPt;
++    int i;
++
++    if (console_screen_idx < 0) return;
++    pScreen = screenInfo.screens[console_screen_idx];
++    pspix = sunGetScreenPixmap (console_screen_idx);
++    if (!pspix) return;
++    pixBox.x1 = 0; pixBox.x2 = pScreen->width;
++    pixBox.y1 = 0; pixBox.y2 = pScreen->height;
++    pixPt.x = 0; pixPt.y = 0;
++    (pScreen->RegionInit)(&pixReg, &pixBox, 1);
++    if (enter) {
++        if (pspix->devPrivate.ptr != sunscreen && ppix) {
++            pspix->devPrivate.ptr = sunscreen;
++            pspix->devKind = sunscreen_devKind;
++            if (sunFbs[console_screen_idx].DoBitblt)
++            	sunFbs[console_screen_idx].DoBitblt(&ppix->drawable, &pspix->drawable, GXcopy, 
++            					    &pixReg, &pixPt, 0xFFFFFFFF >> (32 - ppix->drawable.bitsPerPixel));
++            else
++                sunDoBitBlt(&ppix->drawable, &pspix->drawable, ppix->drawable.bitsPerPixel, &pixReg, &pixPt);
++            pspix = ppix;
++            ppix = NULL;
++            pScreen->DestroyPixmap(pspix);
++        }
++    } else {
++    	ppix = (pScreen->CreatePixmap)(pScreen, pScreen->width, 
++    				       pScreen->height, pScreen->rootDepth);
++    	if (ppix) {
++            if (sunFbs[console_screen_idx].DoBitblt)
++            	sunFbs[console_screen_idx].DoBitblt(&pspix->drawable, &ppix->drawable, GXcopy, 
++            					    &pixReg, &pixPt, 0xFFFFFFFF >> (32 - ppix->drawable.bitsPerPixel));
++            else
++    	        sunDoBitBlt(&pspix->drawable, &ppix->drawable, ppix->drawable.bitsPerPixel, &pixReg, &pixPt);
++    	    sunscreen = pspix->devPrivate.ptr;
++    	    sunscreen_devKind = pspix->devKind;
++    	    pspix->devKind = ppix->devKind;
++    	    pspix->devPrivate.ptr = ppix->devPrivate.ptr;
++    	}
++    }
++}
++
++void linuxSetConsoleFb (int idx)
++{
++    console_screen_idx = idx;
++}
++
++static void vtRequest(int sig)
++{
++    vtRequestsPending = TRUE;
++    signal(SIGUSR1,vtRequest);
++}
++
++static void linuxEnterLeaveDev(Bool enter)
++{
++    int j;
++
++    if (enter && console_screen_idx >= 0 && sunFbs [console_screen_idx].vtchange)
++	(*sunFbs [console_screen_idx].vtchange) (console_screen_idx, enter);
++    linuxEnterLeaveVT(enter);
++    if (enter) {
++    	int fd;
++    	Firm_event evBuf[20];
++    	sunKbdPrivPtr kbdPriv;
++    	DeviceIntPtr pKeyboard;
++    	
++	SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
++	EnableDevice((DeviceIntPtr)linuxMouse);
++	EnableDevice((DeviceIntPtr)linuxKeyboard);
++	pKeyboard = (DeviceIntPtr)LookupKeyboardDevice();
++	kbdPriv = (sunKbdPrivPtr)(pKeyboard->public.devicePrivate);
++	fd = kbdPriv->fd;
++	read (fd, evBuf, sizeof(evBuf));
++    } else {
++    	if (console_screen_idx >= 0 && sunFbs [console_screen_idx].vtchange)
++	    (*sunFbs [console_screen_idx].vtchange) (console_screen_idx, enter);
++	DisableDevice((DeviceIntPtr)linuxMouse);
++	DisableDevice((DeviceIntPtr)linuxKeyboard);
++    }
++    for (j = 0; j < MAXSCREENS; j++) {
++    	if (j != console_screen_idx && sunFbs[j].fd != -1) {
++    		int i = enter;
++    		ioctl (sunFbs[j].fd, FBIOSVIDEO, &i);
++    	}
++    }
++}
++
++static void VTSwitch()
++{
++    if (NoVT) return;	
++    vtRequestsPending = FALSE;
++    if (vtSema) {
++	if (!linuxExiting)
++	    linuxEnterLeaveDev(FALSE);
++	else
++	    ErrorF("Exiting...\n\n");
++	if (ioctl(consoleFd, VT_RELDISP, 1) < 0) {
++	    if (!linuxExiting)
++	        linuxEnterLeaveDev(TRUE);
++	    else
++	    	ErrorF("Exiting failed\n\n");
++	} else {
++	    CursorPtr pCursor;
++	    sunCursorPtr pCurPriv;
++	
++	    vtSema = FALSE;
++	    if (console_screen_idx >= 0) {
++                pCurPriv = (&(GetScreenPrivate(screenInfo.screens[console_screen_idx])->hardwareCursor));
++                if (pCurPriv)
++                    pCurPriv->use_ioctl = 1;
++                if (pCurPriv && pCurPriv->has_cursor && pCurPriv->pCursor != NULL) {
++    	            pCursor = pCurPriv->pCursor;
++	    	    sunDisableCursor(screenInfo.screens[console_screen_idx]);
++	    	    pCurPriv->pCursor = pCursor;
++    	        }
++		vtOn = (void *)(screenInfo.screens[console_screen_idx]);
++    	    }
++	}
++    } else {
++	sunCursorPtr pCurPriv;
++	
++    	vtOn = NULL;
++
++	if (console_screen_idx >= 0) {    	
++            pCurPriv = (&(GetScreenPrivate(screenInfo.screens[console_screen_idx])->hardwareCursor));
++            if (pCurPriv)
++                pCurPriv->use_ioctl = 1;
++            if (pCurPriv && pCurPriv->has_cursor && pCurPriv->pCursor != NULL)
++	    	sunRealizeCursor(screenInfo.screens[console_screen_idx], pCurPriv->pCursor);
++    	}
++	if (ioctl(consoleFd, VT_RELDISP, VT_ACKACQ) < 0) {
++    	    vtOn = (void *)(screenInfo.screens[console_screen_idx]);
++	    return;
++	}
++	vtSema = TRUE;
++	if (console_screen_idx >= 0) {
++	    sunRefreshColormap (console_screen_idx);
++	    linuxEnterLeaveDev(TRUE);
++	}
++    }
++}
++
++/* ARGSUSED */
++void linuxBlock(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
++{
++}
++
++/* ARGSUSED */
++void linuxWakeup(pointer blockData, int result, pointer pReadmask)
++{
++    if (vtRequestsPending) VTSwitch();
++}
++
++static char *linuxGetPathElem(char **pnt)
++{
++  char *p1;
++
++  p1 = *pnt;
++  *pnt = index(*pnt, ',');
++  if (*pnt != NULL) {
++    **pnt = '\0';
++    *pnt += 1;
++  }
++  return(p1);
++}
++
++#define DIR_FILE "/fonts.dir"
++
++/*
++ * linuxValidateFontPath --
++ *	Validates the user-specified font path.  Each element that
++ *	begins with a '/' is checked to make sure the directory exists.
++ *	If the directory exists, the existence of a file named 'fonts.dir'
++ *	is checked.  If either check fails, an error is printed and the
++ *	element is removed from the font path.
++ */
++#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type))
++static char * linuxValidateFontPath(char *path)
++{
++  char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem;
++  struct stat stat_buf;
++  int flag;
++  int dirlen;
++
++  tmp_path = (char *)xcalloc(1,strlen(path)+1);
++  out_pnt = tmp_path;
++  path_elem = NULL;
++  next = path;
++  while (next != NULL) {
++    path_elem = linuxGetPathElem(&next);
++    if (*path_elem == '/') {
++      dir_elem = (char *)xcalloc(1, strlen(path_elem) + 1);
++      if ((p1 = strchr(path_elem, ':')) != 0)
++	dirlen = p1 - path_elem;
++      else
++	dirlen = strlen(path_elem);
++      strncpy(dir_elem, path_elem, dirlen);
++      dir_elem[dirlen] = '\0';
++      flag = stat(dir_elem, &stat_buf);
++      if (flag == 0)
++	if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR))
++	  flag = -1;
++      if (flag != 0) {
++        ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem);
++	ErrorF("         Entry deleted from font path.\n");
++	continue;
++      }
++      else {
++	p1 = (char *)xalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
++	strcpy(p1, dir_elem);
++	strcat(p1, DIR_FILE);
++	flag = stat(p1, &stat_buf);
++	if (flag == 0)
++	  if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG))
++	    flag = -1;
++	xfree(p1);
++	if (flag != 0) {
++	  ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n", 
++		 dir_elem);
++	  ErrorF("          Entry deleted from font path.\n");
++	  ErrorF("          (Run 'mkfontdir' on \"%s\").\n", dir_elem);
++	  continue;
++	}
++      }
++      xfree(dir_elem);
++    }
++
++    /*
++     * Either an OK directory, or a font server name.  So add it to
++     * the path.
++     */
++    if (out_pnt != tmp_path)
++      *out_pnt++ = ',';
++    strcat(out_pnt, path_elem);
++    out_pnt += strlen(path_elem);
++  }
++  return(tmp_path);
++}
++
++void OpenLinuxConsole()
++{
++    int i, fd;
++    struct vt_mode VT;
++    char vtname[11];
++    struct vt_stat vts;
++    char *p;
++
++    if (NoVT) return;
++    for (i = 0; i < MAXSCREENS; i++)
++    	sunFbs [i].vtchange = 0;
++    if (serverGeneration == 1) 
++    {
++	/* check if we're run with euid==0 */
++	if (geteuid() != 0)
++	{
++	    FatalError("OpenLinuxConsole: Server must be suid root\n");
++	}
++
++	RegisterBlockAndWakeupHandlers(linuxBlock, linuxWakeup, (void *)0);
++	/*
++	 * setup the virtual terminal manager
++	 */
++	if (VTnum != -1)
++	{
++	    vtno = VTnum;
++	}
++	else 
++	{
++	    if ((fd = open("/dev/console",O_WRONLY,0)) < 0) 
++	    {
++		FatalError(
++		    "OpenLinuxConsole: Cannot open /dev/console (%s)\n",
++		    strerror(errno));
++	    }
++	    if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) ||
++		(vtno == -1))
++	    {
++		FatalError("OpenLinuxConsole: Cannot find a free VT\n");
++	    }
++	    close(fd);
++	}
++	ErrorF("(using VT number %d)\n\n", vtno);
++
++	sprintf(vtname,"/dev/tty%d",vtno); /* /dev/tty1-64 */
++
++	if (!KeepTty)
++	{
++	    setpgrp();
++	}
++
++	if ((consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0)
++	{
++	    FatalError("OpenLinuxConsole: Cannot open %s (%s)\n",
++		       vtname, strerror(errno));
++	}
++
++	p = xalloc(strlen(defaultFontPath)+1);
++	if (p) {
++	    strcpy (p, defaultFontPath);	
++	    defaultFontPath = linuxValidateFontPath(p);
++	    xfree(p);
++	} else
++	    defaultFontPath = "";
++	
++	if (!*defaultFontPath)
++	    FatalError("No valid FontPath could be found\n");
++
++	/* change ownership of the vt */
++	chown(vtname, getuid(), getgid());
++
++	/*
++	 * the current VT device we're running on is not "console", we want
++	 * to grab all consoles too
++	 */
++	chown("/dev/console", getuid(), getgid());
++	chown("/dev/tty0", getuid(), getgid());
++
++	/*
++	 * Linux doesn't switch to an active vt after the last close of a vt,
++	 * so we do this ourselves by remembering which is active now.
++	 */
++	if (ioctl(consoleFd, VT_GETSTATE, &vts) == 0)
++	{
++	    activeVT = vts.v_active;
++	}
++	
++	if (!KeepTty)
++	{
++	    /*
++	     * Detach from the controlling tty to avoid char loss
++	     */
++	    if ((i = open("/dev/tty",O_RDWR)) >= 0)
++	    {
++		ioctl(i, TIOCNOTTY, 0);
++		close(i);
++	    }
++	}
++
++	/*
++	 * now get the VT
++	 */
++	if (ioctl(consoleFd, VT_ACTIVATE, vtno) != 0)
++	{
++	    ErrorF("OpenLinuxConsole: VT_ACTIVATE failed\n");
++	}
++	if (ioctl(consoleFd, VT_WAITACTIVE, vtno) != 0)
++	{
++	    ErrorF("OpenLinuxConsole: VT_WAITACTIVE failed\n");
++	}
++	if (ioctl(consoleFd, VT_GETMODE, &VT) < 0) 
++	{
++	    FatalError ("OpenLinuxConsole: VT_GETMODE failed\n");
++	}
++
++	signal(SIGUSR1, vtRequest);
++
++	VT.mode = VT_PROCESS;
++	VT.relsig = SIGUSR1;
++	VT.acqsig = SIGUSR1;
++	if (ioctl(consoleFd, VT_SETMODE, &VT) < 0) 
++	{
++	    FatalError("OpenLinuxConsole: VT_SETMODE VT_PROCESS failed\n");
++	}
++    }
++    else 
++    {
++	/* serverGeneration != 1 */
++	/*
++	 * now get the VT
++	 */
++	if (ioctl(consoleFd, VT_ACTIVATE, vtno) != 0)
++	{
++	    ErrorF("OpenLinuxConsole: VT_ACTIVATE failed\n");
++	}
++	if (ioctl(consoleFd, VT_WAITACTIVE, vtno) != 0)
++	{
++	    ErrorF("OpenLinuxConsole: VT_WAITACTIVE failed\n");
++	}
++    }
++    return;
++}
++
++void CloseLinuxConsole()
++{
++    struct vt_mode   VT;
++    int i, j;
++
++    if (NoVT) return;
++    /*
++     * Perform a switch back to the active VT when we were started
++     */
++    for (j = 0; j < MAXSCREENS; j++) {
++    	if (sunFbs[j].fd != -1) {
++    	    if (sunFbs[j].origcmap.count == 16) {
++    	        ioctl(sunFbs[j].fd, FBIOPUTCMAP, &sunFbs[j].origcmap);
++    	    }
++    	    for (i = 0; i < 8; i++)
++    	        if (sunFbs[j].sizes[i]) {
++    	            munmap(sunFbs[j].maps[i], sunFbs[j].sizes[i]);
++    	            sunFbs[j].sizes[i] = 0;
++    	        }
++    	    close(sunFbs[j].fd);
++    	}
++    }
++    if (ioctl(consoleFd, VT_GETMODE, &VT) != -1)
++    {
++	VT.mode = VT_AUTO;
++	if (ioctl(consoleFd, VT_SETMODE, &VT) < 0) { /* set dflt vt handling */
++	    ErrorF("OpenLinuxConsole: VT_SETMODE failed\n");
++	}
++    }
++    linuxExiting = TRUE;
++    if (activeVT >= 0)
++    {
++	if (ioctl(consoleFd, VT_ACTIVATE, activeVT) < 0) {
++	    ErrorF("OpenLinuxConsole: VT_ACTIVATE failed\n");
++	}
++	if (ioctl(consoleFd, VT_WAITACTIVE, activeVT) < 0) {
++	    ErrorF("OpenLinuxConsole: VT_WAITACTIVE failed\n");
++	}
++	activeVT = -1;
++    }
++    close(consoleFd);                /* make the vt-manager happy */
++    return;
++}
++
++int linuxProcessArgument (int argc, char *argv[], int i)
++{
++	/*
++	 * Keep server from detaching from controlling tty.  This is useful 
++	 * when debugging (so the server can receive keyboard signals).
++	 */
++	if (!strcmp(argv[i], "-novt"))
++	{
++		NoVT = TRUE;
++		return 1;
++	}
++	if (!strcmp(argv[i], "-keeptty"))
++	{
++		KeepTty = TRUE;
++		return 1;
++	}
++	if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
++	{
++		if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
++		{
++			UseMsg();
++			VTnum = -1;
++			return 0;
++		}
++		return 1;
++	}
++	return 0;
++}
++
++#ifdef DPMSExtension
++/*
++ * DPMSSet --
++ *      Device dependent DPMS mode setting hook.  This is called whenever
++ *      the DPMS mode is to be changed.
++ */
++void
++DPMSSet(CARD16 level)
++{
++}
++
++/*
++ * DPMSSupported --
++ *      Return TRUE if any screen supports DPMS.
++ */
++Bool
++DPMSSupported(void)
++{
++    return FALSE;
++}
++#endif /* DPMSExtension */
++                                           
+--- xc/programs/Xserver/hw/sun/sun.h.jj	Mon Dec 23 07:30:13 1996
++++ xc/programs/Xserver/hw/sun/sun.h	Thu Jan 13 11:31:57 2000
+@@ -34,7 +34,17 @@ extern char *getenv();
+ /* system headers common to both SunOS and Solaris */
+ #include <sys/param.h>
+ #include <sys/file.h>
++
++#ifdef linux
++#ifdef __GLIBC__
++#include <termios.h>
++#else
++#include <linux/termios.h>
++#endif
++#else
+ #include <sys/filio.h>
++#endif
++
+ #include <sys/ioctl.h>
+ #include <sys/resource.h>
+ 
+@@ -52,7 +62,7 @@ extern char *getenv();
+ 
+ #include <fcntl.h>
+ 
+-#ifndef __bsdi_
++#if !defined(__bsdi_) && !defined(linux)
+ # ifndef CSRG_BASED
+ #  ifndef i386
+ #   include <poll.h>
+@@ -72,7 +82,8 @@ extern int errno;
+ #endif
+ 
+ /* 
+- * Sun specific headers Sun moved in Solaris, and are different for NetBSD.
++ * Sun specific headers Sun moved in Solaris, and are different for NetBSD
++ * and Linux.
+  *
+  * Even if only needed by one source file, I have put them here 
+  * to simplify finding them...
+@@ -88,17 +99,49 @@ extern int errno;
+ # define usleep(usec) poll((struct pollfd *) 0, (size_t) 0, usec / 1000)
+ #else
+ # ifndef CSRG_BASED
+-#  include <sun/fbio.h>
+-#  include <sundev/kbd.h>
+-#  include <sundev/kbio.h>
+-#  include <sundev/msio.h>
+-#  include <sundev/vuid_event.h>
+-#  include <pixrect/pixrect.h>
+-#  include <pixrect/memreg.h>
++#  ifdef linux
++#   define KB_KLUNK        0x00            /* Micro Switch 103SD32-2 */
++#   define KB_VT100        0x01            /* Keytronics VT100 compatible */
++#   define KB_SUN2         0x02            /* Sun-2 custom keyboard */
++#   define KB_SUN3         0x03            /* Type 3 Sun keyboard */
++#   define KB_SUN4         0x04            /* Type 4 Sun keyboard */
++#   define KB_VT220        0x81            /* Emulation vt220 */
++#   define KB_VT220I       0x82            /* International vt220 Emulation */
++#   define KB_ASCII        0x0F            /* Ascii terminal masquerading as kbd */
++#   define KBD_CMD_RESET           0x01    /* Reset keyboard as if power-up */
++#   define KBD_CMD_BELL            0x02    /* Turn on the bell */
++#   define KBD_CMD_NOBELL          0x03    /* Turn off the bell */
++#   define KBD_CMD_LED1            0x04    /* Turn on LED 1 */
++#   define KBD_CMD_NOLED1          0x05    /* Turn off LED 1 */
++#   define KBD_CMD_LED2            0x06    /* Turn on LED 2 */
++#   define KBD_CMD_NOLED2          0x07    /* Turn off LED 2 */
++#   define KBD_CMD_CLICK           0x0A    /* Turn on the click annunciator */
++#   define KBD_CMD_NOCLICK         0x0B    /* Turn off the click annunciator */
++#   define KBD_CMD_SETLED          0x0E    /* Set keyboard LED's */
++#   define KBD_CMD_GETLAYOUT       0x0F    /* Request that keyboard indicate layout */
++#   define LED_NUM_LOCK    0x1
++#   define LED_COMPOSE     0x2
++#   define LED_SCROLL_LOCK 0x4
++#   define LED_CAPS_LOCK   0x8
++#   include <asm/types.h>
++#   include <asm/fbio.h>
++#   include <asm/kbio.h>
++#   include <asm/vuid_event.h>
++#   include <asm/memreg.h>
++#   include <signal.h>
++#  else
++#   include <sun/fbio.h>
++#   include <sundev/kbd.h>
++#   include <sundev/kbio.h>
++#   include <sundev/msio.h>
++#   include <sundev/vuid_event.h>
++#   include <pixrect/pixrect.h>
++#   include <pixrect/memreg.h>
+ extern int ioctl();
+ extern int getrlimit();
+ extern int setrlimit();
+ extern int getpagesize();
++#  endif
+ # else
+ #  ifdef CSRG_BASED
+ #   include <machine/fbio.h>
+@@ -119,10 +162,16 @@ extern int getpagesize();
+  * Sun doesn't see fit to add the TCX to <sys/fbio.h>
+  */
+ #ifndef SVR4
++#ifndef linux
+ /* On SunOS 4.1.x the TCX pretends to be a CG3 */
+ #define XFBTYPE_LASTPLUSONE	FBTYPE_LASTPLUSONE	
+ #else
+ #define XFBTYPE_TCX		21
++#define XFBTYPE_FFB		22
++#define XFBTYPE_LASTPLUSONE	23
++#endif
++#else
++#define XFBTYPE_TCX		21
+ #define XFBTYPE_LASTPLUSONE	22
+ #endif
+ 
+@@ -182,6 +231,7 @@ extern int monitorResolution;
+ # define BWTWO3DEV	"/dev/fbs/bwtwo3"
+ # define CGEIGHT0DEV	"/dev/fbs/cgeight0"
+ # define TCX0DEV	"/dev/fbs/tcx0"
++# define FFB0DEV	"/dev/fbs/ffb0"
+ #else
+ # define CGTWO0DEV	"/dev/cgtwo0"
+ # define CGTWO1DEV	"/dev/cgtwo1"
+@@ -201,6 +251,9 @@ extern int monitorResolution;
+ # define BWTWO2DEV	"/dev/bwtwo2"
+ # define BWTWO3DEV	"/dev/bwtwo3"
+ # define CGEIGHT0DEV	"/dev/cgeight0"
++# define TCX0DEV	"/dev/tcx0"
++# define MDI0DEV	"/dev/cgfourteen0"
++# define FFB0DEV	"/dev/creator0"
+ #endif
+ 
+ /*
+@@ -241,6 +294,10 @@ typedef struct {
+     int		    width, height;
+     Bool	    has_cursor;
+     CursorPtr	    pCursor;		/* current cursor */
++#ifdef linux
++    int             x, y;
++    int             use_ioctl;
++#endif
+ } sunCursorRec, *sunCursorPtr;
+ 
+ typedef struct {
+@@ -249,6 +306,7 @@ typedef struct {
+     void	    (*UpdateColormap)();
+     sunCursorRec    hardwareCursor;
+     Bool	    hasHardwareCursor;
++    WindowExposuresProcPtr	WindowExposures;
+ } sunScreenRec, *sunScreenPtr;
+ 
+ #define GetScreenPrivate(s)   ((sunScreenPtr) ((s)->devPrivates[sunScreenIndex].ptr))
+@@ -260,6 +318,21 @@ typedef struct {
+     struct fbtype   info;	/* Frame buffer characteristics */
+     void	    (*EnterLeave)();/* screen switch */
+     unsigned char*  fbPriv;	/* fbattr stuff, for the real type */
++    void *	    private;
++#ifdef linux
++    struct fbcmap   origcmap;
++    void	    (*vtchange)(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    int /* enter */
++#endif
++    );
++    int		    cursor_type;
++    void *	    cursor_regs;
++    unsigned long   maps[8];
++    unsigned long   sizes[8];
++    void	    (*DoBitblt)();
++#endif    
+ } fbFd;
+ 
+ typedef Bool (*sunFbInitProc)(
+@@ -276,6 +349,13 @@ typedef struct {
+     char*		name;	/* /usr/include/fbio names */
+ } sunFbDataRec;
+ 
++#ifdef linux
++extern void		*vtOn;
++#define VT_HIDDEN(pscreen)	(vtOn == (void *)(pscreen))
++#else
++#define VT_HIDDEN(pscreen)	0
++#endif
++
+ #ifdef XKB
+ extern Bool		noXkbExtension;
+ #endif
+@@ -291,6 +371,8 @@ extern Bool		sunActiveZaphod;
+ extern Bool		sunFbInfo;
+ extern Bool		sunCG4Frob;
+ extern Bool		sunNoGX;
++extern Bool		sunNoFFB;
++extern Bool		sunNoLeo;
+ extern int		sunScreenIndex;
+ extern int*		sunProtected;
+ 
+@@ -318,9 +400,13 @@ extern void sunNonBlockConsoleOff(
+ #if defined(SVR4) || defined(CSRG_BASED)
+     void
+ #else
++#ifdef linux
++    int /* status */, void * /* arg */
++#else
+     char* /* arg */
+ #endif
+ #endif
++#endif
+ );
+ 
+ extern void sunEnqueueEvents(
+@@ -336,6 +422,13 @@ extern int sunGXInit(
+ #endif
+ );
+ 
++extern int sunFFBAccelInit(
++#if NeedFunctionPrototypes
++    ScreenPtr /* pScreen */,
++    fbFd* /* fb */
++#endif
++);
++
+ extern Bool sunSaveScreen(
+ #if NeedFunctionPrototypes
+     ScreenPtr /* pScreen */,
+@@ -353,7 +446,7 @@ extern pointer sunMemoryMap(
+ #if NeedFunctionPrototypes
+     size_t /* len */,
+     off_t /* off */,
+-    int /* fd */
++    int /* scr */
+ #endif
+ );
+ 
+@@ -491,5 +584,37 @@ extern int sunListInstalledColormaps(
+     Colormap* /* pCmapList */
+ #endif
+ );
++
++#ifdef linux
++
++extern void sunDoBitBlt(
++#if NeedFunctionPrototypes
++    DrawablePtr /* ppix */,
++    DrawablePtr /* pspix */,
++    int /* bpp */,
++    RegionPtr /* pixReg */,
++    DDXPointPtr /* pixPt */
++#endif
++);
++
++extern void sunRefreshColormap(
++#if NeedFunctionPrototypes
++    int /* idx */
++#endif
++);
++
++extern PixmapPtr sunGetScreenPixmap(
++#if NeedFunctionPrototypes
++    int /* screen */
++#endif
++);
++
++extern void linuxSetConsoleFb(
++#if NeedFunctionPrototypes
++    int /* idx */
++#endif
++);
++
++#endif
+ 
+ #endif
+--- xc/programs/Xserver/hw/sun/sunCfb.c.jj	Mon Feb 16 01:40:55 1998
++++ xc/programs/Xserver/hw/sun/sunCfb.c	Thu Jan 13 11:31:13 2000
+@@ -98,6 +98,7 @@ static void CGUpdateColormap(pScreen, de
+ {
+     struct fbcmap sunCmap;
+ 
++    if (VT_HIDDEN(pScreen)) return;
+     sunCmap.index = dex;
+     sunCmap.count = count;
+     sunCmap.red = &rmap[dex];
+@@ -221,7 +222,6 @@ static void CGStoreColors(pmap, ndef, pd
+ static void CGScreenInit (pScreen)
+     ScreenPtr	pScreen;
+ {
+-#ifndef STATIC_COLOR /* { */
+     SetupScreen (pScreen);
+     pScreen->InstallColormap = sunInstallColormap;
+     pScreen->UninstallColormap = sunUninstallColormap;
+@@ -233,7 +233,6 @@ static void CGScreenInit (pScreen)
+ 	pScreen->whitePixel = pScreen->blackPixel;
+ 	pScreen->blackPixel = pixel;
+     }
+-#endif /* } */
+ }
+ 
+ static void checkMono (argc, argv)
+@@ -244,7 +243,7 @@ static void checkMono (argc, argv)
+ 
+     for (i = 1; i < argc; i++)
+ 	if (strcmp (argv[i], "-mono") == 0)
+-	    ErrorF ("-mono not appropriate for CG3/CG4/CG6\n");
++	    ErrorF ("-mono not appropriate for CG3/CG4/CG6/TCX/FFB/CG14\n");
+ }
+ 
+ /*
+@@ -270,21 +269,36 @@ Bool sunCG3Init (screen, pScreen, argc, 
+ 	cfbCreateDefColormap, sunSaveScreen, 0);
+ }
+ 
+-Bool sunTCXInit (screen, pScreen, argc, argv)
++#define TCX_MMAP_CURSOR_OFFSET 0x70004000
++Bool sunTCX8Init (screen, pScreen, argc, argv)
+     int	    	  screen;    	/* what screen am I going to be */
+     ScreenPtr	  pScreen;  	/* The Screen to initialize */
+     int	    	  argc;	    	/* The number of the Server's arguments. */
+     char    	  **argv;   	/* The arguments themselves. Don't change! */
+ {
++    Bool ret;
++    struct fbcurpos maxsize;
++    char *p;
++
+     checkMono (argc, argv);
+     sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
+-    return sunInitCommon (screen, pScreen, (off_t) 0,
++    ret = sunInitCommon (screen, pScreen, (off_t) 0,
+ 	sunCfbScreenInit, CGScreenInit,
+ 	cfbCreateDefColormap, sunSaveScreen, 0);
++#ifdef linux	
++    if ((ioctl (sunFbs[screen].fd, FBIOGCURMAX, &maxsize) != -1) &&
++        ((p = sunMemoryMap (4096, (off_t) TCX_MMAP_CURSOR_OFFSET,
++        screen)) != NULL)) {
++        sunFbs[screen].cursor_type = FBTYPE_SUNFAST_COLOR; /* thc is same as on cg6 */
++        sunFbs[screen].cursor_regs = ((char *)p) + 0x8fc;
++    }
++#endif
++    return ret;
+ }
+ 
+ #if !defined(i386) && !defined(__bsdi__) /* { */
+ 
++#ifndef linux /* { */
+ #ifdef SVR4 /* { */
+ #include <sys/cg2reg.h>
+ #else
+@@ -417,10 +431,13 @@ Bool sunCG4Init (screen, pScreen, argc, 
+ 	cfbCreateDefColormap, sunSaveScreen, (int) ((CG4Ptr) 0)->cpixel);
+ }
+ 
++#endif /* } !linux */
++
+ #ifdef FBTYPE_SUNFAST_COLOR /* { */
+ 
+ #define CG6_MMAP_OFFSET 0x70000000
+ #define CG6_IMAGE_OFFSET 0x16000
++#define CG6_CURSOR_OFFSET 0x58fc
+ 
+ Bool sunCG6Init (screen, pScreen, argc, argv)
+     int		screen;    	/* The index of pScreen in the ScreenInfo */
+@@ -439,12 +456,16 @@ Bool sunCG6Init (screen, pScreen, argc, 
+ 			sunFbs[screen].info.fb_height + CG6_IMAGE_OFFSET
+ 	if ((fb = sunMemoryMap (FBSIZE,
+ 			     (off_t) CG6_MMAP_OFFSET, 
+-			     sunFbs[screen].fd)) == NULL)
++			     screen)) == NULL)
+ 	    return FALSE;
+ 	sunFbs[screen].fb = fb;
+ #undef FBSIZE
+     }
+     sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
++#ifdef linux
++    sunFbs[screen].cursor_type = FBTYPE_SUNFAST_COLOR;
++    sunFbs[screen].cursor_regs = sunFbs[screen].fb + CG6_CURSOR_OFFSET;
++#endif    
+     if (!sunCfbSetupScreen (pScreen, 
+ 	    sunFbs[screen].fb + CG6_IMAGE_OFFSET,
+ 	    sunFbs[screen].info.fb_width, 
+--- xc/programs/Xserver/hw/sun/sunCfb24.c.jj	Wed Apr 27 09:14:49 1994
++++ xc/programs/Xserver/hw/sun/sunCfb24.c	Thu Jan 13 11:57:59 2000
+@@ -26,6 +26,12 @@ Except as contained in this notice, the 
+ used in advertising or otherwise to promote the sale, use or other dealings in
+ this Software without prior written authorization from the X Consortium.
+ 
++TCX, LEO and FFB/Creator support
++Copyright (C) 1996,1997,1998,1999 Jakub Jelinek
++
++CG14/mdi support
++Copyright (C) 1996 Miguel de Icaza
++
+ */
+ 
+ /*
+@@ -46,6 +52,10 @@ this Software without prior written auth
+ #define PSZ 32
+ #include "sun.h"
+ #include "cfb/cfb.h"
++#include "gcstruct.h"
++#include "mi/migc.h"
++#include "mi/mi.h"
++#include "mi/mibstorest.h"
+ 
+ #define PIXPG_24BIT_COLOR 5
+ #define PIXPG_24BIT_COLOR_INDEX (PIXPG_24BIT_COLOR << 25)
+@@ -104,16 +114,13 @@ static void CG24StoreColors (pmap, ndef,
+ static void CG24ScreenInit (pScreen)
+     ScreenPtr pScreen;
+ {
+-#ifndef STATIC_COLOR
+     SetupScreen (pScreen);
+-#endif
+     int i;
+ 
+     /* Make sure the overlay plane is disabled */
+     for (i = 0; i < CG8_COLOR_OFFSET; i++)
+ 	sunFbs[pScreen->myNum].fb[i] = 0;
+ 
+-#ifndef STATIC_COLOR
+     pScreen->InstallColormap = sunInstallColormap;
+     pScreen->UninstallColormap = sunUninstallColormap;
+     pScreen->ListInstalledColormaps = sunListInstalledColormaps;
+@@ -124,7 +131,6 @@ static void CG24ScreenInit (pScreen)
+ 	pScreen->whitePixel = pScreen->blackPixel;
+ 	pScreen->blackPixel = pixel;
+     }
+-#endif
+ }
+ 
+ Bool sunCG8Init (screen, pScreen, argc, argv)
+@@ -137,5 +143,524 @@ Bool sunCG8Init (screen, pScreen, argc, 
+     return sunInitCommon (screen, pScreen, (off_t) 0,
+ 	cfb32ScreenInit, CG24ScreenInit,
+ 	cfbCreateDefColormap, sunSaveScreen, CG8_COLOR_OFFSET);
++}
++
++#define TCX_MMAP_RAM_OFFSET	0x01000000
++#define TCX_MMAP_CURSOR_OFFSET	0x70004000
++#define TCX_MMAP_CONTROL_OFFSET	0x28000000
++
++#define TCX_CPLANE_MODE	0x3000000
++
++static void sunTCX24UpdateColormap(pScreen, index, count, rmap, gmap, bmap)
++    ScreenPtr	pScreen;
++    int		index, count;
++    u_char	*rmap, *gmap, *bmap;
++{
++}
++
++static void sunTCX24StoreColors (pmap, ndef, pdefs)
++    ColormapPtr pmap;
++    int ndef;
++    xColorItem* pdefs;
++{
++}
++
++static void sunTCX24ScreenInit (pScreen)
++    ScreenPtr pScreen;
++{
++    SetupScreen (pScreen);
++
++    pScreen->InstallColormap = sunInstallColormap;
++    pScreen->UninstallColormap = sunUninstallColormap;
++    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
++    pScreen->StoreColors = sunTCX24StoreColors;
++    pPrivate->UpdateColormap = sunTCX24UpdateColormap;
++    if (sunFlipPixels) {
++	Pixel pixel = pScreen->whitePixel;
++	pScreen->whitePixel = pScreen->blackPixel;
++	pScreen->blackPixel = pixel;
++    }
++}
++
++#ifdef linux
++static void tcx_vtchange (screen, enter)
++    int screen;
++    int enter;
++{
++    unsigned	*p, *q;
++    
++    memset (sunFbs[screen].fb, 0, sunFbs[screen].info.fb_width * sunFbs[screen].info.fb_height * 4);
++    if (enter)
++        for (p = sunFbs[screen].private, q = p + sunFbs[screen].info.fb_width * sunFbs[screen].info.fb_height; p < q; p++)
++	    *p = (*p & 0xffffff) | TCX_CPLANE_MODE;
++}
++#endif
++
++Bool sunTCX24Init (screen, pScreen, argc, argv)
++    int		    screen;    	/* what screen am I going to be */
++    ScreenPtr	    pScreen;  	/* The Screen to initialize */
++    int		    argc;    	/* The number of the Server's arguments. */
++    char	    **argv;   	/* The arguments themselves. Don't change! */
++{
++    pointer	fb;
++    unsigned	*p, *q;
++
++    if (!sunScreenAllocate (pScreen))
++	return FALSE;
++    if (!sunFbs[screen].fb) {
++#define FBSIZE (size_t) sunFbs[screen].info.fb_width * sunFbs[screen].info.fb_height * 4
++	if ((fb = sunMemoryMap (FBSIZE,
++			     (off_t) TCX_MMAP_RAM_OFFSET, 
++			     screen)) == NULL) {
++	    return FALSE;
++        }
++	sunFbs[screen].fb = fb;
++#ifdef linux	
++	if ((p = sunMemoryMap (4096,
++			    (off_t) TCX_MMAP_CURSOR_OFFSET,
++			    screen)) != NULL) {
++	    sunFbs[screen].cursor_type = FBTYPE_SUNFAST_COLOR; /* thc is same as on cg6 */
++	    sunFbs[screen].cursor_regs = ((char *)p) + 0x8fc;
++	}
++#endif	
++	if ((p = sunMemoryMap (FBSIZE,
++			    (off_t) TCX_MMAP_CONTROL_OFFSET,
++			    screen)) == NULL) {
++	    return FALSE;
++	}
++#ifdef linux
++	sunFbs[screen].vtchange = tcx_vtchange;
++	sunFbs[screen].private = (void *)p;
++#endif	    
++	memset (fb, 0, FBSIZE);
++	for (q = p + (FBSIZE / 4); p < q; p++)
++	    *p = (*p & 0xffffff) | TCX_CPLANE_MODE;
++#undef FBSIZE
++    }
++    sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
++    if (!cfb32SetupScreen (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    sunFbs[screen].info.fb_width))
++	return FALSE;
++    if (!cfbSetVisualTypes (24, 1 << TrueColor, 8))
++        return FALSE;
++    if (!cfb32FinishScreenInit (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    sunFbs[screen].info.fb_width))
++	return FALSE;
++    sunTCX24ScreenInit (pScreen);
++    if (!sunScreenInit (pScreen)) {
++	return FALSE;
++    }
++    sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
++    return cfbCreateDefColormap(pScreen);
++}
++
++static void sunCG14UpdateColormap(pScreen, index, count, rmap, gmap, bmap)
++    ScreenPtr	pScreen;
++    int		index, count;
++    u_char	*rmap, *gmap, *bmap;
++{
++}
++
++static void sunCG14StoreColors (pmap, ndef, pdefs)
++    ColormapPtr pmap;
++    int ndef;
++    xColorItem* pdefs;
++{
++}
++
++static void sunCG14ScreenInit (pScreen)
++    ScreenPtr pScreen;
++{
++    SetupScreen (pScreen);
++
++    pScreen->InstallColormap   = sunInstallColormap;
++    pScreen->UninstallColormap = sunUninstallColormap;
++    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
++    pScreen->StoreColors = sunCG14StoreColors;
++    pPrivate->UpdateColormap = sunCG14UpdateColormap;
++    if (sunFlipPixels) {
++	Pixel pixel = pScreen->whitePixel;
++	pScreen->whitePixel = pScreen->blackPixel;
++	pScreen->blackPixel = pixel;
++    }
++}
++
++#ifdef linux
++static void cg14_vtchange (screen, enter)
++    int screen;
++    int enter;
++{
++    int mode;
++    
++    if (enter)
++	mode = 32;
++    else
++	mode = 8;
++    ioctl (sunFbs [screen].fd, MDI_SET_PIXELMODE, &mode);
++}
++#endif
++
++#define CG14_XLUT 0x3000
++
++Bool sunCG14Init (screen, pScreen, argc, argv)
++    int		    screen;    	/* what screen am I going to be */
++    ScreenPtr	    pScreen;  	/* The Screen to initialize */
++    int		    argc;    	/* The number of the Server's arguments. */
++    char	    **argv;   	/* The arguments themselves. Don't change! */
++{
++    pointer	fb;
++    unsigned	*p, *q;
++    char        *control;
++    char        *clut;
++    
++    if (!sunScreenAllocate (pScreen))
++	return FALSE;
++    if (!sunFbs[screen].fb) {
++#define FBSIZE (size_t) sunFbs[screen].info.fb_width * sunFbs[screen].info.fb_height * 4
++	if ((fb = sunMemoryMap (FBSIZE,
++			     (off_t) MDI_CHUNKY_BGR_MAP, 
++			     screen)) == NULL) {
++	    return FALSE;
++        }
++	{
++	    int bpp_32 = 32;
++	    ioctl (sunFbs [screen].fd, MDI_SET_PIXELMODE, &bpp_32);
++	}
++	sunFbs[screen].fb = fb;
++	if ((p = sunMemoryMap (FBSIZE,
++			    (off_t) MDI_PLANAR_X32_MAP,
++			    screen)) == NULL) {
++	    return FALSE;
++	}
++	if ((clut = sunMemoryMap (4096, (off_t) CG14_XLUT, screen)) == NULL){
++	    return FALSE;
++	}
++#ifdef linux
++	sunFbs[screen].vtchange = cg14_vtchange;
++	sunFbs[screen].private = (void *)p;
++#endif	    
++	memset (fb, 0, FBSIZE);
++	/* Clear the X channel and the Xlut */
++	memset (p,    0, FBSIZE / 4);
++	memset (clut, 0, 0x200);
++      
++#undef FBSIZE
++    }
++    sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
++    if (!cfb32SetupScreen (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    sunFbs[screen].info.fb_width))
++	return FALSE;
++    if (!cfbSetVisualTypes (24, 1 << TrueColor, 8))
++        return FALSE;
++    if (!cfb32FinishScreenInit (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    sunFbs[screen].info.fb_width))
++	return FALSE;
++    sunCG14ScreenInit (pScreen);
++    if (!sunScreenInit (pScreen)) {
++	return FALSE;
++    }
++    sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
++    return cfbCreateDefColormap(pScreen);
++}
++
++#define LEO_MMAP_RAM_OFFSET	0x00000000
++
++static void sunLeoUpdateColormap(pScreen, index, count, rmap, gmap, bmap)
++    ScreenPtr	pScreen;
++    int		index, count;
++    u_char	*rmap, *gmap, *bmap;
++{
++}
++
++static void sunLeoStoreColors (pmap, ndef, pdefs)
++    ColormapPtr pmap;
++    int ndef;
++    xColorItem* pdefs;
++{
++}
++
++static void sunLeoScreenInit (pScreen)
++    ScreenPtr pScreen;
++{
++    SetupScreen (pScreen);
++
++    pScreen->InstallColormap = sunInstallColormap;
++    pScreen->UninstallColormap = sunUninstallColormap;
++    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
++    pScreen->StoreColors = sunLeoStoreColors;
++    pPrivate->UpdateColormap = sunLeoUpdateColormap;
++    if (sunFlipPixels) {
++	Pixel pixel = pScreen->whitePixel;
++	pScreen->whitePixel = pScreen->blackPixel;
++	pScreen->blackPixel = pixel;
++    }
++}
++
++Bool sunLeoInit (screen, pScreen, argc, argv)
++    int		    screen;    	/* what screen am I going to be */
++    ScreenPtr	    pScreen;  	/* The Screen to initialize */
++    int		    argc;    	/* The number of the Server's arguments. */
++    char	    **argv;   	/* The arguments themselves. Don't change! */
++{
++    pointer	fb;
++    unsigned	*p, *q;
++
++    if (!sunScreenAllocate (pScreen))
++	return FALSE;
++    if (!sunFbs[screen].fb) {
++	if ((fb = sunMemoryMap (0x803000,
++			     (off_t) LEO_MMAP_RAM_OFFSET, 
++			     screen)) == NULL) {
++	    return FALSE;
++        }
++	sunFbs[screen].fb = fb;
++	sunFbs[screen].private = (void *)((char *)fb + 0x800000);
++#ifdef linux	
++	sunFbs[screen].cursor_type = FBTYPE_SUNLEO;
++	sunFbs[screen].cursor_regs = ((char *)fb + 0x802010);
++#endif	
++    }
++    sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
++    if (!cfb32SetupScreen (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    /* sunFbs[screen].info.fb_width */ 2048))
++	return FALSE;
++    if (!cfbSetVisualTypes (24, 1 << TrueColor, 8))
++        return FALSE;
++    if (!sunLeoAccelInit (pScreen, &sunFbs[screen], sunNoLeo))
++        return FALSE;
++    if (!cfb32FinishScreenInit (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    /* sunFbs[screen].info.fb_width */ 2048))
++	return FALSE;
++    sunLeoScreenInit (pScreen);
++    if (!sunScreenInit (pScreen)) {
++	return FALSE;
++    }
++    sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
++    return cfbCreateDefColormap(pScreen);
++}
++
++#define FFB_MMAP_RAM_OFFSET	0x05004000
++#define FFB_MMAP_CURSOR_OFFSET	0x0bc06000
++#define FFB_MMAP_CONTROL_OFFSET	0x04000000
++
++static void sunFFBUpdateColormap(pScreen, index, count, rmap, gmap, bmap)
++    ScreenPtr	pScreen;
++    int		index, count;
++    u_char	*rmap, *gmap, *bmap;
++{
++}
++
++static void sunFFBStoreColors (pmap, ndef, pdefs)
++    ColormapPtr pmap;
++    int ndef;
++    xColorItem* pdefs;
++{
++}
++
++extern miBSFuncRec CreatorBSFuncRec;
++extern miBSFuncRec cfbBSFuncRec;
++#ifdef CFB_NEED_SCREEN_PRIVATE
++extern Bool cfbCreateScreenResources(ScreenPtr);
++#endif
++
++int
++sunFFBFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, accel)
++    register ScreenPtr pScreen;
++    pointer pbits;		/* pointer to screen bitmap */
++    int xsize, ysize;		/* in pixels */
++    int dpix, dpiy;		/* dots per inch */
++    int width;			/* pixel width of frame buffer */
++    int accel;			/* Using Creator acceleration? */
++{
++    int	i, j;
++#ifdef CFB_NEED_SCREEN_PRIVATE
++    pointer oldDevPrivate;
++#endif
++    VisualPtr	visuals;
++    DepthPtr	depths;
++    int		nvisuals;
++    int		ndepths;
++    int		rootdepth;
++    VisualID	defaultVisual;
++
++    rootdepth = 0;
++    if (!cfbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
++			 &defaultVisual,((unsigned long)1<<(PSZ-1)), 8))
++	return FALSE;
++#ifdef CFB_NEED_SCREEN_PRIVATE
++    oldDevPrivate = pScreen->devPrivate;
++#endif
++    if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
++			rootdepth, ndepths, depths,
++			defaultVisual, nvisuals, visuals,
++			(miBSFuncPtr) 0))
++	return FALSE;
++    /* overwrite miCloseScreen with our own */
++    pScreen->CloseScreen = cfbCloseScreen;
++    /* init backing store here so we can overwrite CloseScreen without stepping
++     * on the backing store wrapped version */
++    if (accel != 0)
++	    miInitializeBackingStore (pScreen, &CreatorBSFuncRec);
++    else
++	    miInitializeBackingStore (pScreen, &cfbBSFuncRec);
++#ifdef CFB_NEED_SCREEN_PRIVATE
++    pScreen->CreateScreenResources = cfbCreateScreenResources;
++    pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
++    pScreen->devPrivate = oldDevPrivate;
++#endif
++    return TRUE;
++}
++
++static void sunFFBScreenInit (pScreen)
++    ScreenPtr pScreen;
++{
++    SetupScreen (pScreen);
++
++    pScreen->InstallColormap = sunInstallColormap;
++    pScreen->UninstallColormap = sunUninstallColormap;
++    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
++    pScreen->StoreColors = sunFFBStoreColors;
++    pPrivate->UpdateColormap = sunFFBUpdateColormap;
++    if (sunFlipPixels) {
++	Pixel pixel = pScreen->whitePixel;
++	pScreen->whitePixel = pScreen->blackPixel;
++	pScreen->blackPixel = pixel;
++    }
++}
++
++Bool sunFFBInit (screen, pScreen, argc, argv)
++    int		    screen;    	/* what screen am I going to be */
++    ScreenPtr	    pScreen;  	/* The Screen to initialize */
++    int		    argc;    	/* The number of the Server's arguments. */
++    char	    **argv;   	/* The arguments themselves. Don't change! */
++{
++    pointer	fb;
++    unsigned	*p, *q;
++    int use_accel = (sunNoFFB == FALSE);
++
++    if (!sunScreenAllocate (pScreen))
++	return FALSE;
++    if (!sunFbs[screen].fb) {
++	if ((fb = sunMemoryMap (0x1000000,
++			     (off_t) FFB_MMAP_RAM_OFFSET, 
++			     screen)) == NULL) {
++	    return FALSE;
++        }
++	sunFbs[screen].fb = fb;
++#ifdef linux	
++	if ((p = sunMemoryMap (8192,
++			    (off_t) FFB_MMAP_CURSOR_OFFSET,
++			    screen)) != NULL) {
++	    sunFbs[screen].cursor_type = XFBTYPE_FFB;
++	    sunFbs[screen].cursor_regs = ((char *)p) + 0x8;
++	}
++#endif	
++	if ((p = sunMemoryMap (16384,
++			    (off_t) FFB_MMAP_CONTROL_OFFSET,
++			    screen)) == NULL) {
++	    return FALSE;
++	}
++	sunFbs[screen].private = (void *)p;
++    }
++    sunFbs[screen].EnterLeave = (void (*)())NoopDDA;
++    if (!cfb32SetupScreen (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    /* sunFbs[screen].info.fb_width */ 2048))
++	return FALSE;
++    if (!cfbSetVisualTypes (24, 1 << TrueColor, 8))
++        return FALSE;
++
++    {
++	    volatile unsigned int *afb_fem;
++	    unsigned int val;
++	    char *uregs;
++
++	    /* OK, a fun gross hack to detect if this is
++	     * AFB and if so whether the correct firmware
++	     * has been loaded.  The machine will flatline
++	     * if you try to use certain acceleration features
++	     * without the full firmware loaded.
++	     *
++	     * The bootup Elite3D/AFB firmware is minimal, and
++	     * will leave the FloatEnableMask register at a
++	     * value of 0x01.  Creator{,3D} lacks the FEM register
++	     * and will return a "nonsense" value on attempts to
++	     * read this location.  After experimentation, an
++	     * appropriate definition for "nonsense" seems to
++	     * be anything with all low 7 bits not 0x3f, 0x07,
++	     * of 0x01.
++	     *
++	     * If the FEM register is non-zero and is some value
++	     * other than 0x1 (usually 0x3f or 0x7 depending upon
++	     * whether the card has 3 or 6 floats) we can assume
++	     * the correct firmware has been loaded. -DaveM
++	     */
++	    uregs = sunFbs[screen].private;
++	    afb_fem = ((volatile unsigned int *)(uregs + 0x1540));
++	    val = *afb_fem;
++	    if ((val & 0x7f) != 0x3f &&
++		(val & 0x7f) != 0x07 &&
++		(val & 0x7f) != 0x01) {
++		    ErrorF("FFB: Detected Creator/Creator3D, "
++			   "using acceleration unless -noFFB.\n");
++	    } else {
++		    char *kregs;
++
++		    ErrorF("FFB: Detected Elite3D M3/M6, checking firmware.\n");
++		    if (val == 0x1) {
++			    ErrorF("FFB: Firmware not loaded, "
++				   "forcing no acceleration.\n");
++			    use_accel = 0;
++		    } else {
++			    ErrorF("FFB: Firmware is loaded, "
++				   "allowing acceleration unless -noFFB.\n");
++		    }
++	    }
++    }
++
++    if (use_accel) {
++        if (!sunFFBAccelInit (pScreen, &sunFbs[screen]))
++            return FALSE;
++    }
++    if (!sunFFBFinishScreenInit (pScreen, 
++	    sunFbs[screen].fb,
++	    sunFbs[screen].info.fb_width, 
++	    sunFbs[screen].info.fb_height,
++	    monitorResolution, monitorResolution, 
++	    /* sunFbs[screen].info.fb_width */ 2048, use_accel))
++	return FALSE;
++    sunFFBScreenInit (pScreen);
++    if (!sunScreenInit (pScreen)) {
++	return FALSE;
++    }
++    sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
++    return cfbCreateDefColormap(pScreen);
+ }
+ 
+--- xc/programs/Xserver/hw/sun/sunCursor.c.jj	Sun Sep 29 14:47:11 1996
++++ xc/programs/Xserver/hw/sun/sunCursor.c	Thu Jan 13 11:31:57 2000
+@@ -47,7 +47,7 @@ from the X Consortium.
+ 
+ static void sunLoadCursor();
+ 
+-static Bool
++Bool
+ sunRealizeCursor (pScreen, pCursor)
+     ScreenPtr	pScreen;
+     CursorPtr	pCursor;
+@@ -55,6 +55,7 @@ sunRealizeCursor (pScreen, pCursor)
+     SetupCursor(pScreen);
+     int	    x, y;
+ 
++    if (VT_HIDDEN(pScreen)) return TRUE;
+     /* miRecolorCursor does this */
+     if (pCurPriv->pCursor == pCursor)
+     {
+@@ -120,6 +121,7 @@ sunLoadCursor (pScreen, pCursor, x, y)
+     DDXPointRec	ptSrc;
+     unsigned char   source_temp[1024], mask_temp[1024];
+ 
++    if (VT_HIDDEN(pScreen)) return;
+     fbcursor.set = FB_CUR_SETALL;
+     fbcursor.enable = 1;
+     fbcursor.pos.x = x;
+@@ -157,6 +159,186 @@ sunLoadCursor (pScreen, pCursor, x, y)
+     }
+     fbcursor.size.x = w;
+     fbcursor.size.y = h;
++#ifdef linux
++    switch (sunFbs[pScreen->myNum].cursor_type) {
++    case XFBTYPE_FFB:
++	{
++	    	int xs = 0, ys = 0;
++		volatile unsigned int *dac = (volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs;
++		unsigned int u, u1, i;
++	    	
++	    	if (pCurPriv->use_ioctl) {
++			ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
++	    		pCurPriv->use_ioctl = 0;
++		}
++		x -= fbcursor.hot.x;
++		y -= fbcursor.hot.y;
++	 	if (x < 0) {
++			xs = - x;
++	    		x = 0;
++		}
++	    	if (y < 0) {
++			ys = - y;
++	    		y = 0;
++		}
++		pCurPriv->x = xs;
++		pCurPriv->y = ys;
++		dac[0] = 0x100;
++		dac[1] = 3;
++		dac[0] = 0x104;
++		dac[1] = (y << 16) | (x & 0xffff);
++		dac[0] = 0x102;
++		dac[1] = (r[0] | (g[0]<<8) | (b[0]<<16));
++		dac[1] = (r[1] | (g[1]<<8) | (b[1]<<16));
++		if (xs > 64) xs = 64;
++		if (ys > 64) ys = 64;
++		if (w <= 32) {
++			if (xs >= w)
++				u = 0;
++			else
++				u = 0xffffffff << (32 - w + xs);
++			dac[0] = 0x80;
++			for (i = ys; i < h; i++) {
++				dac[1] = (((int *)fbcursor.mask)[i] << xs) & u;
++				dac[1] = 0;
++			}
++			for (; i < 64 + ys; i++) {
++				dac[1] = 0; dac[1] = 0;
++			}
++			dac[0] = 0;
++			for (i = ys; i < h; i++) {
++				dac[1] = ((((int *)fbcursor.mask)[i] & ((int *)fbcursor.image)[i]) << xs) & u;
++				dac[1] = 0;
++			}
++			for (; i < 64 + ys; i++) {
++				dac[1] = 0; dac[1] = 0;
++			}
++		} else {
++			if (xs >= w)
++				u = 0;
++			else if (xs >= 32)
++				u = 0xffffffff << (32 - w + xs);
++			else {
++				u = 0xffffffff << (64 - w + xs);
++		    		dac[0] = 0x80;
++				if (!xs) {
++					for (i = ys; i < h; i++) {
++						dac[1] = ((int *)fbcursor.mask)[2*i];
++						dac[1] = ((int *)fbcursor.mask)[2*i+1] & u;
++	    				}
++	    				for (; i < 64 + ys; i++) {
++						dac[1] = 0; dac[1] = 0;
++					}
++	    				dac[0] = 0;
++					for (i = ys; i < h; i++) {
++						dac[1] = ((int *)fbcursor.mask)[2*i] & ((int *)fbcursor.image)[2*i];
++	    					dac[1] = ((int *)fbcursor.mask)[2*i+1] & ((int *)fbcursor.image)[2*i+1] & u;
++		    			}
++				} else {
++					for (i = ys; i < h; i++) {
++						dac[1] = (((int *)fbcursor.mask)[2*i] << xs) | ((((int *)fbcursor.mask)[2*i+1] >> (32 - xs)));
++						dac[1] = (((int *)fbcursor.mask)[2*i+1] << xs) & u;
++	    				}
++	    				for (; i < 64 + ys; i++) {
++						dac[1] = 0; dac[1] = 0;
++					}
++	    				dac[0] = 0;
++					for (i = ys; i < h; i++) {
++						u1 = ((int *)fbcursor.mask)[2*i+1] & ((int *)fbcursor.image)[2*i+1];
++						dac[1] = ((((int *)fbcursor.mask)[2*i] & ((int *)fbcursor.image)[2*i]) << xs) |
++							 (u1 >> (32 - xs));
++	    					dac[1] = (u1 << xs) & u;
++		    			}
++		    		}
++				for (; i < 64 + ys; i++) {
++					dac[1] = 0; dac[1] = 0;
++				}
++				dac[0] = 0x100;
++				dac[1] = 0;
++			}
++			dac[0] = 0x80;
++			for (i = ys; i < h; i++) {
++				dac[1] = (((int *)fbcursor.mask)[2*i] << (xs - 32)) & u;
++				dac[1] = 0;
++			}
++			for (; i < 64 + ys; i++) {
++				dac[1] = 0; dac[1] = 0;
++			}
++			dac[0] = 0;
++			for (i = ys; i < h; i++) {
++				dac[1] = ((((int *)fbcursor.mask)[2*i] & ((int *)fbcursor.image)[2*i]) << (xs - 32)) & u;
++				dac[1] = 0;
++			}
++			for (; i < 64 + ys; i++) {
++				dac[1] = 0; dac[1] = 0;
++			}
++		}
++		dac[0] = 0x100;
++		dac[1] = 0;
++		return;
++	}
++    case FBTYPE_SUNLEO:
++	{
++	    	int xs = 0, ys = 0;
++		volatile unsigned int *lx = (volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs;
++		unsigned int u, m, n, i, j, mask;
++	    	
++	    	if (pCurPriv->use_ioctl) {
++			ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
++	    		pCurPriv->use_ioctl = 0;
++		}
++		x -= fbcursor.hot.x;
++		y -= fbcursor.hot.y;
++	 	if (x < 0) {
++			xs = - x;
++	    		x = 0;
++		}
++	    	if (y < 0) {
++			ys = - y;
++	    		y = 0;
++		}
++		pCurPriv->x = xs;
++		pCurPriv->y = ys;
++		lx[1] &= ~0x80;
++		lx[2] = (x & 0x7ff) | ((y & 0x7ff) << 11);
++		while (lx[1] & 6);
++		lx[0] = 0x50;
++		lx[3] = (r[0] | (g[0]<<8) | (b[0]<<16));
++		lx[3] = (r[1] | (g[1]<<8) | (b[1]<<16));
++		if (xs > 32) xs = 32;
++		if (ys > 32) ys = 32;
++		if (xs >= w)
++			u = 0;
++		else
++			u = 0xffffffff << (32 - w + xs);
++		lx[0] = 0;
++		for (i = ys; i < h; i++) {
++			m = (((int *)fbcursor.mask)[i] << xs) & u;
++			mask = 0;
++			for (j = 0, n = 1; j < 32; j++, n <<= 1)
++				if (m & n)
++					mask |= (0x80000000 >> j);
++			lx[3] = mask;
++		}
++		for (; i < 32 + ys; i++)
++			lx[3] = 0;
++		lx[0] = 0x20;
++		for (i = ys; i < h; i++) {
++			m = ((((int *)fbcursor.mask)[i] & ((int *)fbcursor.image)[i]) << xs) & u;
++			mask = 0;
++			for (j = 0, n = 1; j < 32; j++, n <<= 1)
++				if (m & n)
++					mask |= (0x80000000 >> j);
++			lx[3] = mask;
++		}
++		for (; i < 32 + ys; i++)
++			lx[3] = 0;
++		lx[1] |= 0x33;
++		lx[1] |= 0x80;
++		return;
++	}
++    }
++#endif
+ #ifndef Lynx
+     (void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
+ #else
+@@ -173,7 +355,7 @@ sunSetCursor (pScreen, pCursor, x, y)
+     SetupCursor(pScreen);
+ 
+     if (pCursor)
+-    	sunLoadCursor (pScreen, pCursor, x, y);
++	sunLoadCursor (pScreen, pCursor, x, y);
+     else
+ 	sunDisableCursor (pScreen);
+     pCurPriv->pCursor = pCursor;
+@@ -187,6 +369,66 @@ sunMoveCursor (pScreen, x, y)
+     SetupCursor(pScreen);
+     struct fbcurpos pos;
+ 
++#ifdef linux
++    if (VT_HIDDEN(pScreen)) return;
++    switch (sunFbs[pScreen->myNum].cursor_type) {
++    case FBTYPE_SUNFAST_COLOR:
++	*(volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs =
++	    ((x - pCurPriv->pCursor->bits->xhot) << 16) |
++	    ((y - pCurPriv->pCursor->bits->yhot) & 0xffff);
++	return;
++    case FBTYPE_MDICOLOR:
++	*(volatile unsigned char *)sunFbs[pScreen->myNum].cursor_regs |= 4;
++	*(((volatile unsigned short *)sunFbs[pScreen->myNum].cursor_regs)+2) = 
++	    ((x - pCurPriv->pCursor->bits->xhot) & 0xfff);
++	*(((volatile unsigned short *)sunFbs[pScreen->myNum].cursor_regs)+3) = 
++	    ((y - pCurPriv->pCursor->bits->yhot) & 0xfff);
++	return;
++    case FBTYPE_SUNLEO:
++	x -= pCurPriv->pCursor->bits->xhot;
++	y -= pCurPriv->pCursor->bits->yhot;
++	if (x < 0 || y < 0 || pCurPriv->x || pCurPriv->y) {
++		int xx = - x, yy = - y;
++		if (x > 0) xx = 0;
++		if (y > 0) yy = 0;
++		if (xx != pCurPriv->x || yy != pCurPriv->y) {
++			sunLoadCursor(pScreen, pCurPriv->pCursor,
++				      x + pCurPriv->pCursor->bits->xhot,
++				      y + pCurPriv->pCursor->bits->yhot);
++			return;    				  
++		}
++		if (x < 0) x = 0;
++		if (y < 0) y = 0;
++	}
++	*(((volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs)+1) &= ~0x80;
++	*(((volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs)+2) =
++	    (x & 0x7ff) | ((y & 0x7ff) << 11);
++	*(((volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs)+1) |= 0x30;
++	*(((volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs)+1) |= 0x80;
++	return;
++    case XFBTYPE_FFB:
++	x -= pCurPriv->pCursor->bits->xhot;
++	y -= pCurPriv->pCursor->bits->yhot;
++	if (x < 0 || y < 0 || pCurPriv->x || pCurPriv->y) {
++		int xx = - x, yy = - y;
++		if (x > 0) xx = 0;
++		if (y > 0) yy = 0;
++		if (xx != pCurPriv->x || yy != pCurPriv->y) {
++			sunLoadCursor(pScreen, pCurPriv->pCursor,
++				      x + pCurPriv->pCursor->bits->xhot,
++				      y + pCurPriv->pCursor->bits->yhot);
++			return;    				  
++		}
++		if (x < 0) x = 0;
++		if (y < 0) y = 0;
++	}
++	*(volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs = 0x104;
++	*(((volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs)+1) =
++	    (((y) & 0xffff) << 16) |
++	    ((x) & 0xffff);
++	return;
++    }
++#endif
+     pos.x = x;
+     pos.y = y;
+ #ifndef Lynx
+@@ -254,6 +496,11 @@ Bool sunCursorInitialize (pScreen)
+ 	return FALSE;
+     pCurPriv->width = maxsize.x;
+     pCurPriv->height= maxsize.y;
++#ifdef linux
++    pCurPriv->x = 0;
++    pCurPriv->y = 0;
++    pCurPriv->use_ioctl = 1;
++#endif    
+     pScreen->QueryBestSize = sunQueryBestSize;
+     miPointerInitialize (pScreen,
+ 			 &sunPointerSpriteFuncs,
+@@ -279,14 +526,29 @@ void sunDisableCursor (pScreen)
+     SetupCursor (pScreen);
+     struct fbcursor fbcursor;
+ 
++    if (VT_HIDDEN(pScreen)) return;
+     if (pCurPriv->has_cursor)
+     {
+-    	fbcursor.set = FB_CUR_SETCUR;
+-    	fbcursor.enable = 0;
++	fbcursor.set = FB_CUR_SETCUR;
++	fbcursor.enable = 0;
++#ifdef linux
++	switch (sunFbs[pScreen->myNum].cursor_type) {
++	case XFBTYPE_FFB:
++	    	if (pCurPriv->use_ioctl)
++		    	(void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
++		else {
++	    		volatile unsigned int *dac = (volatile unsigned int *)sunFbs[pScreen->myNum].cursor_regs;
++			dac[0] = 0x104;
++			dac[1] = 0xffffffff;
++		}
++		pCurPriv->pCursor = NULL;
++		return;
++	}
++#endif    	
+ #ifndef Lynx
+-    	(void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
++	(void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
+ #else
+-    	(void) sunIoctl (&sunFbs[pScreen->myNum], FBIOSCURSOR, &fbcursor);
++	(void) sunIoctl (&sunFbs[pScreen->myNum], FBIOSCURSOR, &fbcursor);
+ #endif
+ 	pCurPriv->pCursor = NULL;
+     }
+--- xc/programs/Xserver/hw/sun/sunFbs.c.jj	Wed Jan  3 08:08:59 1996
++++ xc/programs/Xserver/hw/sun/sunFbs.c	Thu Jan 13 11:29:27 2000
+@@ -79,22 +79,271 @@ int sunScreenIndex;
+ 
+ static unsigned long generation = 0;
+ 
++/****************************************************************/
++/* Drawing a banner at start up time                            */
++/****************************************************************/
++
++#include <sys/stat.h>
++#include <fntfilio.h>
++#include <gcstruct.h>
++
++#define LOGO_PATH "/etc/X11/banner/XBanner%c.ras"
++
++/* Sun Rasterfile definitions */
++typedef struct rasterfile {
++	int ras_magic;
++	int ras_width;
++	int ras_height;
++	int ras_depth;
++	int ras_length;
++	int ras_type;
++	int ras_maptype;
++	int ras_maplength;
++} RASHDR;
++
++#define RT_STANDARD	1
++#define RMT_NONE	0
++#define RMT_EQUAL_RGB	1
++#define RMT_RAW		2
++#define RAS_MAGIC	0x59a66a95
++
++static void clearLogoWindowExposures(WindowPtr pWin, RegionPtr pRegion, RegionPtr pOtherRegion)
++{
++    SetupScreen(pWin->drawable.pScreen);
++
++    if (!pWin->parent) {
++        RegionPtr   expose = (*pWin->drawable.pScreen->RegionCreate)(NULL, 0);
++        (*pWin->drawable.pScreen->RegionCopy)(expose, &pWin->clipList);
++        (*pPrivate->WindowExposures)(pWin, expose, pOtherRegion);
++        (*pWin->drawable.pScreen->RegionDestroy)(expose);
++        pWin->drawable.pScreen->WindowExposures = pPrivate->WindowExposures;
++	return;
++    }
++    (*pPrivate->WindowExposures)(pWin, pRegion, pOtherRegion);
++}
++
++static int paintLogo(ScreenPtr pScreen)
++{
++    int visual;
++    int depth;
++    unsigned char c, *p, *buf;
++    unsigned int *q;
++    int i, csize, rascsize;
++    struct stat s;
++    FontFilePtr fnt;
++    ColormapPtr cptr;
++    RASHDR ras;
++    unsigned char *rawcmap;
++    unsigned char *red, *green, *blue;
++    unsigned char *xr = NULL, *xg, *xb;
++    int x, y, w, h;
++    PixmapPtr pPixmap;
++    xRectangle rect;
++    DrawablePtr pDst;
++    ChangeGCVal attr[2];
++    long rgf;
++    GCPtr pGC;
++    RegionPtr pRgn;
++    unsigned char name[256];
++    VisualPtr pVisual;
++    extern WindowPtr *WindowTable;
++    SetupScreen(pScreen);
++
++    /* Grab root visual */
++    for (pVisual = pScreen->visuals; pVisual->vid != pScreen->rootVisual; pVisual++);
++    visual = pVisual->class;
++    depth = pScreen->rootDepth;
++    cptr = (ColormapPtr)LookupIDByType(WindowTable[pScreen->myNum]->drawable.pScreen->defColormap,RT_COLORMAP);
++    csize = pVisual->ColormapEntries;
++    pDst = (DrawablePtr)WindowTable[pScreen->myNum];
++
++    /* Open the appropriate logo file */
++    c = '1';
++    if (depth == 8 && visual == PseudoColor)
++	c = '8';
++    else if (depth == 24 && (visual == TrueColor || visual == DirectColor))
++	c = '8';
++    else if (depth == 8 && (visual == StaticGray || visual == GrayScale))
++	c = 'G';
++    else if (depth > 1)
++	return -EINVAL;
++    p = name + sprintf(name, LOGO_PATH, c);
++    strcpy ((char *)p, ".gz");
++    if (stat(name, &s)) {
++        strcpy ((char *)p, ".Z");
++        if (stat(name, &s)) {
++	    *p = '\0';
++	    if (stat(name, &s))
++                return -ENOENT;
++        }
++    }
++    fnt = FontFileOpen(name);
++    if (!fnt) return -EBADF;
++
++    FontFileRead(fnt, (char *)&ras, sizeof (ras));
++    if (ras.ras_magic != RAS_MAGIC) {
++	FontFileClose(fnt); return -EBADF;
++    }
++
++    h = ras.ras_height;
++    if (c != '1') {
++	switch (visual) {
++	case PseudoColor:
++	case GrayScale:
++	case TrueColor:
++		xr = (unsigned char *)xcalloc(256, 3);
++		xg = xr + 256; xb = xg + 256;
++		/* Start with black screen */
++		pPrivate->UpdateColormap(pScreen, 0, 256, xr, xg, xb);
++		break;
++	default:
++		break;
++	}
++	/* Read Colormap */
++	rawcmap = (unsigned char *)xalloc(ras.ras_maplength);
++	FontFileRead(fnt, rawcmap, ras.ras_maplength);
++	rascsize = ras.ras_maplength / 3;
++	red = rawcmap; green = rawcmap + rascsize; blue = rawcmap + 2 * rascsize;
++	if (c != '1' && depth == 24 && cptr->pVisual->nplanes == 24) {
++		if (cptr->pVisual->redMask == 0xff0000 &&
++		    cptr->pVisual->greenMask == 0xff00 &&
++		    cptr->pVisual->blueMask == 0xff) {
++			red = blue;
++			blue = rawcmap;
++		}
++	}
++	switch (visual) {
++	case PseudoColor:
++	case GrayScale:
++		memcpy(xr + 256 - rascsize, red, rascsize);
++		memcpy(xg + 256 - rascsize, green, rascsize);
++		memcpy(xb + 256 - rascsize, blue, rascsize);
++		xr[pScreen->blackPixel] = 0;
++		xg[pScreen->blackPixel] = 0;
++		xb[pScreen->blackPixel] = 0;
++		xr[pScreen->whitePixel] = 0xff;
++		xg[pScreen->whitePixel] = 0xff;
++		xb[pScreen->whitePixel] = 0xff;
++		break;
++	case TrueColor:
++		for (i = 0; i < 256; i++) {
++			xr[i] = i;
++			xg[i] = i;
++			xb[i] = i;
++		}
++	default:
++		break;
++	}
++	w = (ras.ras_width + 1) & ~1;
++    } else
++	w = (ras.ras_width + 15) & ~15;
++	
++    pGC = CreateScratchGC(pScreen, pScreen->rootDepth);
++    attr[0].val = pScreen->whitePixel;
++    dixChangeGC(NullClient, pGC, (GCForeground), NULL, attr);
++    ValidateGC(pDst, pGC);
++    rect.x = 0; rect.y = 0; rect.width = pScreen->width; rect.height = pScreen->height;
++    (*pGC->ops->PolyFillRect)(pDst, pGC, 1, &rect);
++
++    pPixmap = (*pScreen->CreatePixmap)(pScreen, w, h, depth);
++    p = (unsigned char *)pPixmap->devPrivate.ptr;
++
++    if (c != '1') {
++	buf = (unsigned char *)xalloc(w);
++	while (h-- > 0) {
++		FontFileRead(fnt, buf, w);
++		switch (visual) {
++		case TrueColor:
++		case DirectColor:
++			q = (unsigned *)p;
++			for (i = 0; i < w; i++)
++				*q++ = red[buf[i]] | (green[buf[i]] << 8) | (blue[buf[i]] << 16);
++			break;
++		case StaticGray:
++			for (i = 0; i < w; i++)
++				*p++ = red[buf[i]];
++			p -= w;
++			break;
++		default:
++			for (i = 0; i < w; i++)
++				*p++ = buf[i] - rascsize;
++			p -= w;
++			break;
++		}
++		p += pPixmap->devKind;
++	}
++	xfree(buf);
++    } else {
++    	while (h-- > 0) {
++    		FontFileRead(fnt, p, w);
++    		p += pPixmap->devKind;
++    	}
++    }
++    FontFileClose(fnt);
++    
++    x = (pScreen->width - w) >> 1; y = (pScreen->height - ras.ras_height) >> 1;
++    if (c != '1') {
++    	pRgn = (*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDst, pGC, 0, 0, 
++    				     ras.ras_width, ras.ras_height, x, y);
++    	switch (visual) {
++    	case PseudoColor:
++    	case GrayScale:
++    	case TrueColor:
++    		pPrivate->UpdateColormap(pScreen, 0, 256, xr, xg, xb);
++    		xfree(xr);
++    		break;
++    	}
++    } else {
++    	attr[0].val = pScreen->blackPixel;
++    	attr[1].val = pScreen->whitePixel;
++    	rgf = pScreen->rgf; pScreen->rgf = (unsigned)~2;
++    	dixChangeGC(NullClient, pGC, (GCForeground | GCBackground), NULL, attr);
++    	ValidateGC(pDst, pGC);
++    	pRgn = (*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDst, pGC, 0, 0, 
++    				      ras.ras_width, ras.ras_height, x, y, 1);
++  	pScreen->rgf = rgf;
++    }
++    if (rawcmap) xfree(rawcmap);
++    if (pRgn) (*pScreen->RegionDestroy)(pRgn);
++    FreeGC(pGC, 0);
++    (*pScreen->DestroyPixmap)(pPixmap);
++    return 0;
++}
++
++static void paintLogoWindowExposures(WindowPtr pWin, RegionPtr pRegion, RegionPtr pOtherRegion)
++{
++    ScreenPtr pScreen = pWin->drawable.pScreen;
++    SetupScreen(pScreen);
++    int err;
++
++    if (paintLogo(pScreen) < 0) {
++	/* Fall back to x tailed all over the screen */
++	(*pPrivate->WindowExposures)(pWin, pRegion, pOtherRegion);
++	pScreen->WindowExposures = pPrivate->WindowExposures;
++    } else
++	/* Clear the logo next time :) */
++	pScreen->WindowExposures = clearLogoWindowExposures;
++}
++
++
+ #if NeedFunctionPrototypes
+ pointer sunMemoryMap (
+     size_t	len,
+     off_t	off,
+-    int		fd)
++    int		scr)
+ #else
+-pointer sunMemoryMap (len, off, fd)
++pointer sunMemoryMap (len, off, scr)
+     size_t	len;
+     off_t	off;
+-    int		fd;
++    int		scr;
+ #endif
+ {
+     int		pagemask, mapsize;
+     caddr_t	addr;
+     pointer	mapaddr;
++    int		fd;
+ 
++    fd = sunFbs[scr].fd;
+ #ifdef SVR4
+     pagemask = sysconf(_SC_PAGESIZE) - 1;
+ #else 
+@@ -103,7 +352,7 @@ pointer sunMemoryMap (len, off, fd)
+     mapsize = ((int) len + pagemask) & ~pagemask;
+     addr = 0;
+ 
+-#if !defined(__bsdi__) && !defined(_MAP_NEW)
++#if !defined(linux) && !defined(__bsdi__) && !defined(_MAP_NEW)
+     if ((addr = (caddr_t) valloc (mapsize)) == NULL) {
+ 	Error ("Couldn't allocate frame buffer memory");
+ 	(void) close (fd);
+@@ -129,6 +378,13 @@ pointer sunMemoryMap (len, off, fd)
+ 	(void) close (fd);
+ 	mapaddr = (pointer) NULL;
+     }
++#ifdef linux
++    for (fd = 0; fd < 8; fd++)
++        if (!sunFbs[scr].sizes[fd])
++            break;
++    sunFbs[scr].maps[fd] = (unsigned long)mapaddr;
++    sunFbs[scr].sizes[fd] = mapsize;
++#endif    
+     return mapaddr;
+ }
+ 
+@@ -233,6 +489,8 @@ Bool sunScreenInit (pScreen)
+ #ifdef XKB
+     }
+ #endif
++    pPrivate->WindowExposures = pScreen->WindowExposures;
++    pScreen->WindowExposures  = paintLogoWindowExposures;
+     if (!sunCursorInitialize (pScreen))
+ 	miDCInitialize (pScreen, &sunPointerScreenFuncs);
+     return TRUE;
+@@ -267,7 +525,7 @@ Bool sunInitCommon (scrn, pScrn, offset,
+     if (!fb) {
+ 	if ((fb = sunMemoryMap ((size_t) sunFbs[scrn].info.fb_size, 
+ 			     offset, 
+-			     sunFbs[scrn].fd)) == NULL)
++			     scrn)) == NULL)
+ 	    return FALSE;
+ 	sunFbs[scrn].fb = fb;
+     }
+--- xc/programs/Xserver/hw/sun/sunGX.c.jj	Sat Jul  8 08:55:54 1995
++++ xc/programs/Xserver/hw/sun/sunGX.c	Thu Jan 13 11:31:13 2000
+@@ -418,7 +418,8 @@ sunGXCopyArea(pSrcDrawable, pDstDrawable
+     int width, height;
+     int dstx, dsty;
+ {
+-    if (pSrcDrawable->type != DRAWABLE_WINDOW)
++    if (pSrcDrawable->type != DRAWABLE_WINDOW || 
++        VT_HIDDEN(pSrcDrawable->pScreen))
+ 	return cfbCopyArea (pSrcDrawable, pDstDrawable,
+             pGC, srcx, srcy, width, height, dstx, dsty);
+     return cfbBitBlt (pSrcDrawable, pDstDrawable,
+@@ -552,6 +553,9 @@ RegionPtr sunGXCopyPlane(pSrcDrawable, p
+     RegionPtr		ret;
+     int			(*doBitBlt)();
+ 
++    if (VT_HIDDEN(pSrcDrawable->pScreen)) 
++        return cfbCopyPlane(pSrcDrawable, pDstDrawable, pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
++    
+     if (pSrcDrawable->bitsPerPixel == 1 && pDstDrawable->bitsPerPixel == 8)
+     {
+     	if (bitPlane == 1)
+@@ -664,6 +668,11 @@ sunGXPolyFillRect(pDrawable, pGC, nrectF
+     int		    n;
+     int		    xorg, yorg;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        cfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit);
++        return;
++    }
++
+     priv = (cfbPrivGC *) pGC->devPrivates[cfbGCPrivateIndex].ptr;
+     prgnClip = priv->pCompositeClip;
+     prect = prectInit;
+@@ -815,6 +824,10 @@ sunGXFillSpans (pDrawable, pGC, n, ppt, 
+     register int    r;
+     BoxPtr	    extents;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        (gxPriv->FillSpans)(pDrawable, pGC, n, ppt, pwidth, fSorted);
++        return;
++    }
+     GXDrawInit(gx,pGC->fgPixel,gx_solid_rop_table[pGC->alu]|POLY_O,pGC->planemask)
+     if (gxPriv->stipple)
+ 	GXStippleInit(gx,gxPriv->stipple);
+@@ -1074,6 +1087,10 @@ sunGXPolyFillArc (pDraw, pGC, narcs, par
+     int			old_width = 0;
+ #endif
+ 
++    if (VT_HIDDEN(pDraw->pScreen)) {
++        (gxPriv->PolyFillArc)(pDraw, pGC, narcs, parcs);
++        return;
++    }
+     GXDrawInit(gx,pGC->fgPixel,gx_solid_rop_table[pGC->alu]|POLY_O,pGC->planemask);
+     if (gxPriv->stipple)
+ 	GXStippleInit(gx,gxPriv->stipple);
+@@ -1191,6 +1208,10 @@ sunGXFillPoly1Rect (pDrawable, pGC, shap
+     } GXPointRec, *GXPointPtr;
+     GXPointPtr	    tri, qua;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        (gxPriv->FillPolygon)(pDrawable, pGC, shape, mode, count, ptsIn);
++        return;
++    }
+     if (count < 3)
+ 	return;
+     if (shape != Convex && count > 4)
+@@ -1324,6 +1345,10 @@ sunGXPolySeg1Rect (pDrawable, pGC, nseg,
+     int		    r;
+     unsigned char   *baseAddr, *loAddr, *hiAddr, *saveAddr = 0, save;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        (gxPriv->PolySegment)(pDrawable, pGC, nseg, pSeg);
++        return;
++    }
+     GXDrawInit(gx,pGC->fgPixel,gx_solid_rop_table[pGC->alu]|POLY_O,pGC->planemask);
+     if (gxPriv->stipple)
+ 	GXStippleInit(gx,gxPriv->stipple);
+@@ -1391,6 +1416,10 @@ sunGXPolylines1Rect (pDrawable, pGC, mod
+     Bool	    careful;
+     Bool	    capNotLast;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        (gxPriv->Polylines)(pDrawable, pGC, mode, npt, ppt);
++        return;
++    }
+     if (!--npt)
+ 	return;
+     GXDrawInit(gx,pGC->fgPixel,gx_solid_rop_table[pGC->alu]|POLY_O,pGC->planemask);
+@@ -1513,6 +1542,11 @@ sunGXPolyFillRect1Rect (pDrawable, pGC, 
+     int		    r;
+     int		    x, y;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        miPolyRectangle (pDrawable, pGC, nrect, prect);
++        return;
++    }
++    
+     GXDrawInit(gx,pGC->fgPixel,gx_solid_rop_table[pGC->alu]|POLY_N,pGC->planemask);
+     if (gxPriv->stipple)
+ 	GXStippleInit(gx,gxPriv->stipple);
+@@ -1551,6 +1585,11 @@ sunGXPolyGlyphBlt (pDrawable, pGC, x, y,
+     BoxPtr	    extents;
+     BoxRec	    box;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        sunGXPrivGCPtr gxPriv = sunGXGetGCPrivate (pGC);
++        (gxPriv->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
++        return;
++    }
+     clip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
+     extents = &clip->extents;
+ 
+@@ -1634,6 +1673,11 @@ sunGXTEGlyphBlt (pDrawable, pGC, x, y, n
+     RegionPtr	    clip;
+     unsigned long   rop;
+ 
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        sunGXPrivGCPtr gxPriv = sunGXGetGCPrivate (pGC);
++        (gxPriv->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
++        return;
++    }
+     widthGlyph = FONTMAXBOUNDS(pfont,characterWidth);
+     h = FONTASCENT(pfont) + FONTDESCENT(pfont);
+     clip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
+@@ -1744,6 +1788,11 @@ sunGXPolyTEGlyphBlt (pDrawable, pGC, x, 
+     CharInfoPtr *ppci;		/* array of character info */
+     pointer pglyphBase;		/* start of array of glyphs */
+ {
++    if (VT_HIDDEN(pDrawable->pScreen)) {
++        sunGXPrivGCPtr gxPriv = sunGXGetGCPrivate (pGC);
++        (gxPriv->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
++        return;
++    }
+     sunGXTEGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, (char *) 1);
+ }
+ 
+@@ -2380,6 +2429,19 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 		pGC->ops->devPrivate.val = 1;
+ 	    }
+ 	}
++#ifdef linux	
++	if (newops = cfbMatchCommon (pGC, devPriv))
++	{
++	    gxPriv->FillSpans = newops->FillSpans;
++	    gxPriv->PolyFillArc = newops->PolyFillArc;
++	    gxPriv->FillPolygon = newops->FillPolygon;
++	    gxPriv->PolySegment = newops->PolySegment;
++	    gxPriv->Polylines = newops->Polylines;
++	    gxPriv->PolyGlyphBlt = newops->PolyGlyphBlt;
++	    gxPriv->ImageGlyphBlt = newops->ImageGlyphBlt;
++	}
++#endif	
++	
+     }
+ 
+     canGX = pGC->fillStyle == FillSolid || gxPriv->stipple;
+@@ -2388,8 +2450,15 @@ sunGXValidateGC (pGC, changes, pDrawable
+     if (new_line)
+     {
+ 	pGC->ops->FillPolygon = miFillPolygon;
+-	if (devPriv->oneRect && canGX)
++	if (devPriv->oneRect && canGX) 
++	{
++#ifdef linux	
++	    gxPriv->FillPolygon = miFillPolygon;
++	    if (pGC->fillStyle == FillSolid)
++	        gxPriv->FillPolygon = (devPriv->rop == GXcopy) ? cfbFillPoly1RectCopy : cfbFillPoly1RectGeneral;
++#endif	        
+ 	    pGC->ops->FillPolygon = sunGXFillPoly1Rect;
++	}
+ 	if (pGC->lineWidth == 0)
+ 	{
+ 	    if ((pGC->lineStyle == LineSolid) && (pGC->fillStyle == FillSolid))
+@@ -2418,12 +2487,7 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 	case LineSolid:
+ 	    if(pGC->lineWidth == 0)
+ 	    {
+-		if (devPriv->oneRect && canGX && widOK)
+-		{
+-		    pGC->ops->PolySegment = sunGXPolySeg1Rect;
+-		    pGC->ops->Polylines = sunGXPolylines1Rect;
+-		}
+-		else if (pGC->fillStyle == FillSolid)
++		if (pGC->fillStyle == FillSolid)
+ 		{
+ 		    if (devPriv->oneRect)
+ 		    {
+@@ -2438,6 +2502,16 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 		}
+ 		else
+ 		    pGC->ops->Polylines = miZeroLine;
++		    
++		if (devPriv->oneRect && canGX && widOK)
++		{
++#ifdef linux		
++		    gxPriv->PolySegment = pGC->ops->PolySegment;
++		    gxPriv->Polylines = pGC->ops->Polylines;
++#endif		    
++		    pGC->ops->PolySegment = sunGXPolySeg1Rect;
++		    pGC->ops->Polylines = sunGXPolylines1Rect;
++		}
+ 	    }
+ 	    else
+ 		pGC->ops->Polylines = miWideLine;
+@@ -2466,6 +2540,13 @@ sunGXValidateGC (pGC, changes, pDrawable
+         {
+ 	    if (pGC->fillStyle == FillSolid) 
+ 	    {
++#ifdef linux
++		gxPriv->PolyGlyphBlt = 
++#ifdef WriteBitGroup
++			(devPriv->rop == GXcopy) ? cfbPolyGlyphBlt8 : 
++#endif
++			miPolyGlyphBlt;
++#endif	    
+ 		if (TERMINALFONT (pGC->font))
+ 		    pGC->ops->PolyGlyphBlt = sunGXPolyTEGlyphBlt;
+ 		else
+@@ -2483,9 +2564,14 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 
+ 
+     if (new_fillspans) {
+-	if (canGX)
+-	    pGC->ops->FillSpans = sunGXFillSpans;
+-	else switch (pGC->fillStyle) {
++	switch (pGC->fillStyle) {
++	case FillSolid:
++	    switch(devPriv->rop) {
++	        case GXcopy: pGC->ops->FillSpans = cfbSolidSpansCopy; break;
++	        case GXxor: pGC->ops->FillSpans = cfbSolidSpansXor; break;
++	        default: pGC->ops->FillSpans = cfbSolidSpansGeneral; break;
++	    }
++	    break;
+ 	case FillTiled:
+ 	    if (devPriv->pRotatedPixmap)
+ 	    {
+@@ -2512,6 +2598,12 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 	default:
+ 	    FatalError("cfbValidateGC: illegal fillStyle\n");
+ 	}
++	if (canGX) {
++#ifdef linux	
++	    gxPriv->FillSpans = pGC->ops->FillSpans;
++#endif	    
++	    pGC->ops->FillSpans = sunGXFillSpans;
++	}
+     } /* end of new_fillspans */
+ 
+     if (new_fillarea) {
+@@ -2519,6 +2611,11 @@ sunGXValidateGC (pGC, changes, pDrawable
+ 	pGC->ops->PolyFillArc = miPolyFillArc;
+ 	if (canGX)
+ 	{
++#ifdef linux
++	    gxPriv->PolyFillArc = miPolyFillArc;
++	    if (pGC->fillStyle == FillSolid)
++		gxPriv->PolyFillArc = (devPriv->rop == GXcopy) ? cfbPolyFillArcSolidCopy : cfbPolyFillArcSolidGeneral;	    
++#endif	
+ 	    pGC->ops->PolyFillArc = sunGXPolyFillArc;
+ 	    pGC->ops->PolyFillRect = sunGXPolyFillRect;
+ 	    if (devPriv->oneRect)
+@@ -2554,6 +2651,20 @@ sunGXCreateGC (pGC)
+     gxPriv = sunGXGetGCPrivate(pGC);
+     gxPriv->type = DRAWABLE_WINDOW;
+     gxPriv->stipple = 0;
++#ifdef linux    
++    gxPriv->FillSpans = cfbSolidSpansCopy;
++    gxPriv->PolyFillArc = cfbPolyFillArcSolidCopy;
++    gxPriv->FillPolygon = miFillPolygon;
++    gxPriv->PolySegment = cfbSegmentSS;
++    gxPriv->Polylines = cfbLineSS;
++#ifdef WriteBitGroup    
++    gxPriv->PolyGlyphBlt = cfbImageGlyphBlt8;
++    gxPriv->ImageGlyphBlt = cfbPolyGlyphBlt8;
++#else
++    gxPriv->PolyGlyphBlt = miImageGlyphBlt;
++    gxPriv->ImageGlyphBlt = miPolyGlyphBlt;
++#endif    
++#endif    
+     return TRUE;
+ }
+ 
+@@ -2703,17 +2814,10 @@ sunGXChangeWindowAttributes (pWin, mask)
+ 		    pPrivWin->fastBorder = TRUE;
+ 		    pPrivWin->oldRotate.x = pBgWin->drawable.x;
+ 		    pPrivWin->oldRotate.y = pBgWin->drawable.y;
++		    break;
+ 		}
+-		else
+-		{
+-		    pPrivWin->fastBorder = TRUE;
+-		}
+-	    }
+-	    else
+-	    {
+-		pPrivWin->fastBorder = FALSE;
+ 	    }
+-	    break;
++	    /* Fall through */
+ 	case CWBorderPixel:
+ 	    pPrivWin->fastBorder = FALSE;
+ 	    break;
+@@ -2733,6 +2837,10 @@ sunGXPaintWindow(pWin, pRegion, what)
+     WindowPtr	pBgWin;
+     pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
+ 
++    if (VT_HIDDEN(pWin->drawable.pScreen)) {
++    	cfbPaintWindow(pWin, pRegion, what);
++        return;
++    }
+     switch (what) {
+     case PW_BACKGROUND:
+ 	stipple = sunGXGetWindowPrivate(pWin);
+@@ -2828,6 +2936,11 @@ sunGXCopyWindow(pWin, ptOldOrg, prgnSrc)
+     WindowPtr pwinRoot;
+     extern WindowPtr *WindowTable;
+ 
++    if (VT_HIDDEN(pWin->drawable.pScreen)) {
++    	cfbCopyWindow(pWin, ptOldOrg, prgnSrc);
++    	return;
++    }
++    
+     pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
+ 
+     prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
+--- xc/programs/Xserver/hw/sun/sunGX.h.jj	Wed Apr 27 09:14:49 1994
++++ xc/programs/Xserver/hw/sun/sunGX.h	Thu Jan 13 10:56:59 2000
+@@ -229,6 +229,89 @@ typedef struct _sunGXStipple {
+ typedef struct _sunGXPrivGC {
+     int		    type;
+     sunGXStipplePtr stipple;
++    
++    void	(* FillSpans)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*nInit*/,
++		DDXPointPtr /*pptInit*/,
++		int * /*pwidthInit*/,
++		int /*fSorted*/
++#endif
++);
++
++    void	(* Polylines)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*mode*/,
++		int /*npt*/,
++		DDXPointPtr /*pptInit*/
++#endif
++);
++
++    void	(* PolySegment)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*nseg*/,
++		xSegment * /*pSegs*/
++#endif
++);
++
++    void	(* PolyArc)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*narcs*/,
++		xArc * /*parcs*/
++#endif
++);
++
++    void	(* FillPolygon)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*shape*/,
++		int /*mode*/,
++		int /*count*/,
++		DDXPointPtr /*pPts*/
++#endif
++);
++
++    void	(* PolyFillArc)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*narcs*/,
++		xArc * /*parcs*/
++#endif
++);
++
++    void	(* ImageGlyphBlt)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*x*/,
++		int /*y*/,
++		unsigned int /*nglyph*/,
++		CharInfoPtr * /*ppci*/,
++		pointer /*pglyphBase*/
++#endif
++);
++
++    void	(* PolyGlyphBlt)(
++#if NeedNestedPrototypes
++		DrawablePtr /*pDrawable*/,
++		GCPtr /*pGC*/,
++		int /*x*/,
++		int /*y*/,
++		unsigned int /*nglyph*/,
++		CharInfoPtr * /*ppci*/,
++		pointer /*pglyphBase*/
++#endif
++);
+ } sunGXPrivGCRec, *sunGXPrivGCPtr;
+ 
+ #define sunGXGetGCPrivate(g)	    ((sunGXPrivGCPtr) \
+--- xc/programs/Xserver/hw/sun/sunInit.c.jj	Mon Feb 16 01:40:55 1998
++++ xc/programs/Xserver/hw/sun/sunInit.c	Thu Jan 13 11:31:57 2000
+@@ -51,6 +51,10 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ #include    "mi.h"
+ #include    "mibstore.h"
+ #include    "cfb.h"
++#include    <errno.h>
++#ifdef linux
++#include    <sys/stat.h>
++#endif
+ 
+ /* maximum pixmap depth */
+ #ifndef SUNMAXDEPTH
+@@ -77,6 +81,9 @@ extern Bool sunBW2Init(
+ #define CG6I NULL
+ #define CG8I NULL
+ #define TCXI NULL
++#define CG14I NULL
++#define FFBI NULL
++#define LEOI NULL
+ #else /* }{ */
+ extern Bool sunCG3Init(
+ #if NeedFunctionPrototypes
+@@ -87,7 +94,7 @@ extern Bool sunCG3Init(
+ #endif
+ );
+ #define CG3I sunCG3Init
+-#if defined(i386) || defined(__bsdi__) /* { */
++#if defined(linux) || defined(i386) || defined(__bsdi__) /* { */
+ #define CG2I NULL
+ #define CG4I NULL
+ #else /* }{ */
+@@ -124,7 +131,7 @@ extern Bool sunCG6Init(
+ #define CG6I NULL
+ #endif /* } */
+ #ifdef XFBTYPE_TCX  /* { */
+-extern Bool sunTCXInit(
++static Bool sunTCXInit(
+ #if NeedFunctionPrototypes
+     int /* screen */,
+     ScreenPtr /* pScreen */,
+@@ -136,6 +143,57 @@ extern Bool sunTCXInit(
+ #else /* }{ */
+ #define TCXI NULL
+ #endif /* } */
++
++#ifdef FBTYPE_MDICOLOR
++extern Bool sunCG14Init(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    ScreenPtr /* pScreen */,
++    int /* argc */,
++    char** /* argv */
++#endif
++);
++#define CG14I sunCG14Init
++#else /* }{ */
++#define FBTYPE_MDICOLOR NULL
++#endif
++#if SUNMAXDEPTH < 9
++#undef CG14I
++#define CG14I NULL
++#endif
++
++#ifdef FBTYPE_SUNLEO
++extern Bool sunLeoInit(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    ScreenPtr /* pScreen */,
++    int /* argc */,
++    char** /* argv */
++#endif
++);
++#define LEOI sunLeoInit
++#endif
++#if SUNMAXDEPTH < 9
++#undef LEOI
++#define LEOI NULL
++#endif
++
++#ifdef XFBTYPE_FFB
++extern Bool sunFFBInit(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    ScreenPtr /* pScreen */,
++    int /* argc */,
++    char** /* argv */
++#endif
++);
++#define FFBI sunFFBInit
++#endif
++#if SUNMAXDEPTH < 9
++#undef FFBI
++#define FFBI NULL
++#endif
++
+ #if SUNMAXDEPTH > 8 /* { */
+ #ifdef FBTYPE_MEMCOLOR /* { */
+ extern Bool sunCG8Init(
+@@ -170,6 +228,8 @@ Bool sunFlipPixels = FALSE;
+ Bool sunFbInfo = FALSE;
+ Bool sunCG4Frob = FALSE;
+ Bool sunNoGX = FALSE;
++Bool sunNoFFB = FALSE;
++Bool sunNoLeo = FALSE;
+ 
+ sunKbdPrivRec sunKbdPriv = {
+     -1,		/* fd */
+@@ -214,14 +274,17 @@ sunFbDataRec sunFbData[XFBTYPE_LASTPLUSO
+   { NULL, "SUNGT         (gt)" },
+ #endif
+ #ifdef FBTYPE_SUNLEO
+-  { NULL, "SUNLEO        (zx)" },
++  { LEOI, "SUNLEO        (zx)" },
+ #endif
+ #ifdef FBTYPE_MDICOLOR
+-  { NULL, "MDICOLOR      (cgfourteen)" },
++  { CG14I, "MDICOLOR      (cgfourteen)" },
+ #endif
+ #ifdef XFBTYPE_TCX
+   { TCXI, "TCX           (tcx)" },
+ #endif
++#ifdef XFBTYPE_FFB
++  { FFBI, "FFB           (creator)" },
++#endif
+ #endif /* } */
+ };
+ 
+@@ -232,6 +295,9 @@ sunFbDataRec sunFbData[XFBTYPE_LASTPLUSO
+ #if SUNMAXDEPTH == 1 /* { */
+ static char *fallbackList[] = {
+     BWTWO0DEV, BWTWO1DEV, BWTWO2DEV
++#ifdef linux
++    , "/dev/fb"
++#endif    
+ };
+ #else /* }{ */
+ static char *fallbackList[] = {
+@@ -288,6 +354,40 @@ static PixmapFormatRec	formats[] = {
+ };
+ #define NUMFORMATS	(sizeof formats)/(sizeof formats[0])
+ 
++#if SUNMAXDEPTH > 1 /* { */
++#ifdef XFBTYPE_TCX /* { */
++extern Bool sunTCX8Init(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    ScreenPtr /* pScreen */,
++    int /* argc */,
++    char** /* argv */
++#endif
++);
++
++#if SUNMAXDEPTH > 8
++extern Bool sunTCX24Init(
++#if NeedFunctionPrototypes
++    int /* screen */,
++    ScreenPtr /* pScreen */,
++    int /* argc */,
++    char** /* argv */
++#endif
++);
++#endif
++
++static Bool sunTCXInit(int screen, ScreenPtr pScreen, int argc, char** argv)
++{
++#if SUNMAXDEPTH > 8
++    if (sunFbs [screen].info.fb_depth > 8) /* Is it 24bit deep TCX or just tcx-8-bit? */
++    	return sunTCX24Init (screen, pScreen, argc, argv);
++    else
++#endif
++        return sunTCX8Init (screen, pScreen, argc, argv);
++}
++#endif /* } */
++#endif /* } */
++
+ /*
+  * OpenFrameBuffer --
+  *	Open a frame buffer according to several rules.
+@@ -362,7 +462,20 @@ static int OpenFrameBuffer(device, scree
+     }
+     if (!ret)
+ 	sunFbs[screen].fd = -1;
+-    return ret;
++#ifdef linux
++    else {
++        sunFbs[screen].cursor_type = 0;
++        sunFbs[screen].cursor_regs = 0;
++        sunFbs[screen].origcmap.index = 0;
++        sunFbs[screen].origcmap.count = 16;
++        sunFbs[screen].origcmap.red = (unsigned char *)xalloc(64);
++        sunFbs[screen].origcmap.green = (unsigned char *)xalloc(64);
++        sunFbs[screen].origcmap.blue = (unsigned char *)xalloc(64);
++        if (ioctl (sunFbs[screen].fd, FBIOGETCMAP, &(sunFbs[screen].origcmap)) < 0)
++            sunFbs[screen].origcmap.count = 0;
++    }
++#endif
++     return ret;
+ }
+ 
+ /*-
+@@ -406,9 +519,13 @@ void sunNonBlockConsoleOff(
+ #if defined(SVR4) || defined(CSRG_BASED)
+     void
+ #else
++#ifdef linux
++    int status, void *arg
++#else
+     char* arg
+ #endif
+ #endif
++#endif
+ )
+ {
+     register int i;
+@@ -470,7 +587,7 @@ static void getKbdType()
+  * matter since no 386i has ever been shipped with a type 3 keyboard.
+  * SunOS 4.1 no longer needs this kludge.
+  */
+-#if !defined(i386) && !defined(KIOCGKEY)
++#if !defined(i386) && !defined(KIOCGKEY) && !defined(linux)
+ #define TYPE4KEYBOARDOVERRIDE
+ #endif
+ 
+@@ -552,6 +669,10 @@ void OsVendorInit(
+     }
+ }
+ 
++#ifdef linux
++extern void OpenLinuxConsole();
++#endif
++ 
+ /*-
+  *-----------------------------------------------------------------------
+  * InitOutput --
+@@ -611,6 +732,9 @@ void InitOutput(pScreenInfo, argc, argv)
+ 	    ErrorF("InitOutput: can't put stderr in non-block mode\n");
+ 	}
+     }
++#ifdef linux
++    OpenLinuxConsole();
++#endif
+     pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+     pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+@@ -634,6 +758,18 @@ void InitOutput(pScreenInfo, argc, argv)
+ 	sunDevsInited = TRUE;
+ 	xfree (devList);
+     }
++#ifdef linux
++     for (scr = 0; scr < MAXSCREENS; scr++)
++       if (sunFbs[scr].fd != -1) {
++           struct stat mystat;
++
++           if (fstat (sunFbs[scr].fd, &mystat) >= 0)
++               if ((mystat.st_rdev & 0xff) == 0) {
++                   linuxSetConsoleFb (scr);
++                   break;
++               }
++       }
++#endif
+     for (scr = 0; scr < MAXSCREENS; scr++)
+ 	if (sunFbs[scr].fd != -1)
+ 	    (void) AddScreen (sunFbData[sunFbs[scr].info.fb_type].init, 
+@@ -662,11 +798,18 @@ void InitInput(argc, argv)
+ {
+     DeviceIntPtr	p, k;
+     extern Bool mieqInit();
++#ifdef linux
++    extern DeviceIntPtr linuxMouse, linuxKeyboard;
++#endif
+ 
+     p = AddInputDevice(sunMouseProc, TRUE);
+     k = AddInputDevice(sunKbdProc, TRUE);
+     if (!p || !k)
+ 	FatalError("failed to create input devices in InitInput");
++#ifdef linux
++    linuxMouse = p;
++    linuxKeyboard = k;
++#endif
+ 
+     RegisterPointerDevice(p);
+     RegisterKeyboardDevice(k);
+@@ -677,7 +820,19 @@ void InitInput(argc, argv)
+     (void) OsSignal(SIGPOLL, SigIOHandler);
+ #define WANT_SIGNALS(fd) ioctl(fd, I_SETSIG, S_INPUT | S_HIPRI)
+ #else
++#ifdef linux
++    {
++       struct sigaction act;
++
++       sigemptyset(&act.sa_mask);
++       sigaddset(&act.sa_mask, SIGIO);
++       act.sa_flags = SA_RESTART;
++       act.sa_handler = SigIOHandler;
++       sigaction(SIGIO, &act, 0);
++    }
++#else
+     (void) OsSignal(SIGIO, SigIOHandler);
++#endif
+ #define WANT_SIGNALS(fd) fcntl(fd, F_SETOWN, getpid())
+ #endif
+     if (sunKbdPriv.fd >= 0) {
+@@ -919,3 +1074,71 @@ sunCfbScreenInit(pScreen, pbits, xsize, 
+ 
+ #endif  /* SUNMAXDEPTH == 32 */
+ #endif  /* SUNMAXDEPTH */
++
++#ifdef linux
++void
++sunDoBitBlt(ppix, pspix, bpp, pixReg, pixPt)
++    DrawablePtr ppix, pspix;
++    int bpp;
++    RegionPtr pixReg;
++    DDXPointPtr pixPt;
++{
++    switch (bpp) {
++    	case 1:
++    	    mfbDoBitblt(ppix, pspix, GXcopy, pixReg, pixPt);
++    	    break;
++#if SUNMAXDEPTH > 1
++    	case 8:
++    	    cfbDoBitblt(ppix, pspix, GXcopy, pixReg, pixPt, 0xFF);
++    	    break;
++#endif
++#if SUNMAXDEPTH > 8
++    	case 16:
++    	    cfb16DoBitblt(ppix, pspix, GXcopy, pixReg, pixPt, 0xFFFF);
++    	    break;
++    	case 24:
++    	case 32:
++    	    cfb32DoBitblt(ppix, pspix, GXcopy, pixReg, pixPt, 0xFFFFFFFF);
++    	    break;
++#endif
++    }
++}
++
++void
++sunRefreshColormap(idx)
++    int idx;
++{
++    SetupScreen(screenInfo.screens[idx]);
++    ColormapPtr cmap;
++
++#if SUNMAXDEPTH > 1
++    /* Hack to restore correct cmap */
++    cmap = pPrivate->installedMap;
++    if (cmap) {
++	WalkTree(cmap->pScreen,TellLostMap,(pointer) &(cmap->mid));
++	pPrivate->installedMap = NULL;
++	sunInstallColormap(cmap);
++    }
++#endif
++}
++
++PixmapPtr
++sunGetScreenPixmap(screen)
++    int screen;
++{
++    ScreenPtr pScreen = screenInfo.screens [screen];
++    
++    switch (pScreen->rootDepth) {
++    	case 1: return (PixmapPtr) pScreen->devPrivate;
++#if SUNMAXDEPTH > 1
++    	case 8:	return (PixmapPtr) pScreen->devPrivate;
++#endif    	
++#if SUNMAXDEPTH > 8
++    	case 16: return (PixmapPtr) pScreen->devPrivates [cfb16ScreenPrivateIndex].ptr;
++    	case 24:
++    	case 32: return (PixmapPtr) pScreen->devPrivates [cfb32ScreenPrivateIndex].ptr;
++#endif
++    	default: ErrorF ("Wrong depth %d\n", pScreen->rootDepth); return NULL;
++    }
++}
++#endif
+--- xc/programs/Xserver/hw/sun/sunIo.c.jj	Wed May 21 17:02:18 1997
++++ xc/programs/Xserver/hw/sun/sunIo.c	Thu Jan 13 11:31:57 2000
+@@ -175,8 +175,12 @@ void AbortDDX()
+ #if defined(SVR4) || defined(CSRG_BASED)
+     sunNonBlockConsoleOff ();
+ #else
++#ifdef linux
++    sunNonBlockConsoleOff (0, NULL);
++#else
+     sunNonBlockConsoleOff (NULL);
+ #endif
++#endif
+     for (i = 0; i < screenInfo.numScreens; i++)
+     {
+ 	pScreen = screenInfo.screens[i];
+@@ -189,7 +193,13 @@ void AbortDDX()
+ void
+ ddxGiveUp()
+ {
++#ifdef linux
++    extern void CloseLinuxConsole();
++#endif
+     AbortDDX ();
++#ifdef linux
++    CloseLinuxConsole();
++#endif
+ }
+ 
+ int
+@@ -199,9 +209,19 @@ ddxProcessArgument (argc, argv, i)
+     int	i;
+ {
+     extern void UseMsg();
+-
+ #ifdef XKB
+     int noxkb = 0, n;
++#endif    
++
++#ifdef linux
++    extern int linuxProcessArgument(int argc, char *argv[], int i);
++    int ret;
++
++    ret = linuxProcessArgument(argc, argv, i);
++    if (ret) return ret;
++#endif    
++ 
++#ifdef XKB
+     /* 
+      * peek in argv and see if -kb because noXkbExtension won't 
+      * get set until too late to useful here.
+@@ -271,6 +291,14 @@ ddxProcessArgument (argc, argv, i)
+ 	sunNoGX = TRUE;
+ 	return 1;
+     }
++    if (strcmp (argv[i], "-noFFB") == 0) {
++    	sunNoFFB = TRUE;
++    	return 1;
++    }
++    if (strcmp (argv[i], "-noLEO") == 0) {
++    	sunNoLeo = TRUE;
++    	return 1;
++    }
+     return 0;
+ }
+ 
+@@ -290,5 +318,12 @@ ddxUseMsg()
+ #ifdef UNDOCUMENTED
+     ErrorF("-cg4frob            don't use the mono plane of the cgfour\n");
+     ErrorF("-noGX               treat the GX as a dumb frame buffer\n");
++    ErrorF("-noFFB              treat the Creator/Creator3D as a dumb frame buffer\n");
++    ErrorF("-noLEO              treat the LEO (ZX) as a dumb frame buffer\n");
++#endif
++#ifdef linux
++    ErrorF("vtXX                use the specified VT number\n");
++    ErrorF("-keeptty               ");
++    ErrorF("don't detach controlling tty (for debugging only)\n");
+ #endif
+ }
+--- xc/programs/Xserver/hw/sun/sunKbd.c.jj	Sun Oct  4 17:31:14 1998
++++ xc/programs/Xserver/hw/sun/sunKbd.c	Thu Jan 13 11:36:01 2000
+@@ -81,6 +81,11 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ extern KeySymsRec sunKeySyms[];
+ extern SunModmapRec* sunModMaps[];
+ 
++#ifdef linux
++extern int consoleFd;
++#include <linux/vt.h>
++#endif
++
+ long	  	  sunAutoRepeatInitiate = 1000 * AUTOREPEAT_INITIATE;
+ long	  	  sunAutoRepeatDelay = 1000 * AUTOREPEAT_DELAY;
+ 
+@@ -437,11 +442,14 @@ static void sunKbdCtrl (device, ctrl)
+ #if NeedFunctionPrototypes
+ static void sunInitKbdNames (
+     XkbComponentNamesRec* names,
+-    sunKbdPrivPtr pKbd)
++    sunKbdPrivPtr pKbd,
++    char **model,
++    char **layout)
+ #else
+-static void sunInitKbdNames (names, pKbd)
++static void sunInitKbdNames (names, pKbd, model, layout)
+     XkbComponentNamesRec* names;
+     sunKbdPrivPtr pKbd;
++    char **model, **layout;
+ #endif
+ {
+ #ifndef XKBBUFSIZE
+@@ -451,6 +459,8 @@ static void sunInitKbdNames (names, pKbd
+     static char geometrybuf[XKBBUFSIZE];
+     static char  symbolsbuf[XKBBUFSIZE];
+ 
++    *model = "type4";
++    *layout = "us";
+     names->keymap = NULL;
+     names->compat = "compat/complete";
+     names->types  = "types/complete";
+@@ -489,6 +499,8 @@ static void sunInitKbdNames (names, pKbd
+ 	    (void) strcat (names->keycodes, "sun(type5_se)");
+ 	    (void) strcat (names->symbols,
+ 			   "sun/se(sun5)+se(fixdollar)");
++	    *model = "type5_euro";
++	    *layout = "se";
+ 	    return;
+ 	    break;
+ 	case 90:		/* "Compact 1", Sweden (???) */
+@@ -510,6 +522,7 @@ static void sunInitKbdNames (names, pKbd
+ 		(void) strcat (names->symbols, "sun/us(sun4)");
+ 	} else {
+ 	    (void) strcat (names->keycodes, "sun(type5)");
++	    *model = "type5";
+ 
+ 	    switch (pKbd->layout) {
+ 	    case 33: case 80: /* U.S. */
+@@ -520,9 +533,11 @@ static void sunInitKbdNames (names, pKbd
+ 		break;
+ 	    case 34: case 81: /* U.S. Unix */
+ 		(void) strcat (names->geometry, "sun(type5unix)");
++		*model = "type5_unix";
+ 		break;
+ 	    default:
+ 		(void) strcat (names->geometry, "sun(type5euro)");
++		*model = "type5_euro";
+ 	    }
+ 
+ 	    if (sunSwapLkeys)
+@@ -559,50 +574,50 @@ static void sunInitKbdNames (names, pKbd
+ 	case  0: case  1: case 33: case 34: case 80: case 81: 
+ 	    break;
+ 	case  3:
+-	    (void) strcat (names->symbols, "+ca"); break;
++	    *layout = "ca"; break;
+ 	case  4: case 36: case 83: 
+-	    (void) strcat (names->symbols, "+dk"); break;
++	    *layout = "dk"; break;
+ 	case  5: case 37: case 84: 
+-	    (void) strcat (names->symbols, "+de"); break;
++	    *layout = "de"; break;
+ 	case  6: case 38: case 85: 
+-	    (void) strcat (names->symbols, "+it"); break;
++	    *layout = "it"; break;
+ 	case  8: case 40: case 87: 
+-	    (void) strcat (names->symbols, "+no"); break;
++	    *layout = "no"; break;
+ 	case  9: case 41: case 88: 
+-	    (void) strcat (names->symbols, "+pt"); break;
++	    *layout = "pt"; break;
+ 	case 10: case 42: case 89: 
+-	    (void) strcat (names->symbols, "+es"); break;
++	    *layout = "es"; break;
+ 	    /* case 11: case 43: */ /* handled earlier */
+ 	case 90: 
+-	    (void) strcat (names->symbols, "+se"); break; 
++	    *layout = "se"; break; 
+ 	case 12: case 44: case 91: 
+-	    (void) strcat (names->symbols, "+fr_CH"); break;
++	    *layout = "fr_CH"; break;
+ 	case 13: case 45: case 92: 
+-	    (void) strcat (names->symbols, "+de_CH"); break;
++	    *layout = "de_CH"; break;
+ 	case 14: case 46: case 93: 
+-	    (void) strcat (names->symbols, "+gb"); break; /* s/b en_UK */
++	    *layout = "gb"; break; /* s/b en_UK */
+ 	case 52:
+-	    (void) strcat (names->symbols, "+pl"); break;
++	    *layout = "pl"; break;
+ 	case 53:
+-	    (void) strcat (names->symbols, "+cs"); break;
++	    *layout = "cs"; break;
+ 	case 54:
+-	    (void) strcat (names->symbols, "+ru"); break;
++	    *layout = "ru"; break;
+ #if 0
+ 	/* don't have symbols defined for these yet, let them default */
+ 	case  2:
+-	    (void) strcat (names->symbols, "+fr_BE"); break;
++	    *layout = "fr_BE"; break;
+ 	case  7: case 39: case 86: 
+-	    (void) strcat (names->symbols, "+nl"); break;
++	    *layout = "nl"; break;
+ 	case 50: case 97:
+-	    (void) strcat (names->symbols, "+fr_CA"); break;
++	    *layout = "fr_CA"; break;
+ 	case 16: case 47: case 94: 
+-	    (void) strcat (names->symbols, "+ko"); break;
++	    *layout = "ko"; break;
+ 	case 17: case 48: case 95: 
+-	    (void) strcat (names->symbols, "+tw"); break;
++	    *layout = "tw"; break;
+ 	case 32: case 49: case 96: 
+-	    (void) strcat (names->symbols, "+jp"); break;
++	    *layout = "jp"; break;
+ 	case 51:
+-	    (void) strcat (names->symbols, "+hu"); break;
++	    *layout = "hu"; break;
+ #endif
+ 	/* 
+ 	 * by setting the symbols to NULL XKB will use the symbols in
+@@ -611,6 +626,10 @@ static void sunInitKbdNames (names, pKbd
+ 	default: 
+ 	    names->symbols = NULL; return; break;
+ 	}
++	if (strcmp (*layout, "us")) {
++	    (void) strcat (names->symbols, "+");
++	    (void) strcat (names->symbols, *layout);
++	}
+     }
+ }
+ #endif /* XKB */
+@@ -698,7 +717,9 @@ int sunKbdProc (device, what)
+ #ifdef XKB
+ 	} else {
+ 	    XkbComponentNamesRec names;
+-	    sunInitKbdNames (&names, &sunKbdPriv);
++	    char *model, *layout;
++	    sunInitKbdNames (&names, &sunKbdPriv, &model, &layout);
++	    XkbSetRulesDflts ("sun", model, layout, NULL, NULL);
+ 	    XkbInitKeyboardDeviceStruct((DeviceIntPtr) pKeyboard, &names,
+ 					workingKeySyms, workingModMap,
+ 					sunBell, sunKbdCtrl);
+@@ -888,6 +909,10 @@ void sunKbdEnqueueEvent (device, fe)
+     xEvent		xE;
+     BYTE		keycode;
+     CARD8		keyModifiers;
++#ifdef linux
++    KeySym		ksym;
++    extern Bool		NoVT;
++#endif
+ 
+     keycode = (fe->id & 0x7f) + MIN_KEYCODE;
+ 
+@@ -908,6 +933,39 @@ void sunKbdEnqueueEvent (device, fe)
+     xE.u.keyButtonPointer.time = TVTOMILLI(fe->time);
+     xE.u.u.type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress);
+     xE.u.u.detail = keycode;
++#ifdef linux
++    if ((device->key->state & ControlMask)
++#ifdef XKB    
++	/* For unknown reason, XKB mapping of ALT_L migrated from Mod3 to Mod2... */
++       && ((!noXkbExtension && (device->key->state & Mod2Mask)) ||
++           (noXkbExtension && (device->key->state & Mod3Mask)))
++#else
++       && (device->key->state & Mod3Mask)
++#endif       
++       )
++       switch (ksym = device->key->curKeySyms.map[(fe->id - 1) * device->key->curKeySyms.mapWidth]) {
++               case XK_BackSpace:
++                       if (xE.u.u.type == KeyPress)
++                           GiveUp(0);
++                       return;
++               case XK_F1:
++               case XK_F2:
++               case XK_F3:
++               case XK_F4:
++               case XK_F5:
++               case XK_F6:
++               case XK_F7:
++               case XK_F8:
++               case XK_F9:
++               case XK_F10:
++               case XK_F11:
++               case XK_F12:
++                       if (!NoVT && xE.u.u.type == KeyPress)
++                           ioctl(consoleFd, VT_ACTIVATE, ksym - XK_F1 + 1);
++                       return;
++       }
++#endif
++
+ #ifdef XKB
+     if (noXkbExtension) {
+ #endif
+--- xc/programs/Xserver/hw/sun/sunKeyMap.c.jj	Sun Oct  4 17:31:15 1998
++++ xc/programs/Xserver/hw/sun/sunKeyMap.c	Thu Jan 13 11:34:25 2000
+@@ -5638,7 +5638,7 @@ KeySym *sunType4KeyMaps[] = {
+ 	NULL, /* Hungary5 */	/* 51 */
+ 	NULL, /* Poland5 */	/* 52 */
+ 	NULL, /* Czech5 */	/* 53 */
+-	NULL, /* Russia5 */	/* 54 */
++	US5Keymap, /* Russia5 *//* 54 */
+ 	NULL, 			/* 55 */
+ 	NULL,			/* 56 */
+ 	NULL,			/* 57 */
+@@ -5750,7 +5750,7 @@ SunModmapRec *sunType4ModMaps[] = {
+ 	NULL, /* Hungary5 */	/* 51 */
+ 	NULL, /* Poland5 */	/* 52 */
+ 	NULL, /* Czech5 */	/* 53 */
+-	NULL, /* Russia5 */	/* 54 */
++	US5Keymap, /* Russia5 *//* 54 */
+ 	NULL, 			/* 55 */
+ 	NULL,			/* 56 */
+ 	NULL,			/* 57 */
+--- xc/programs/Xserver/hw/sun/FFB/FFBbcopy.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBbcopy.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,492 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Bit-blit copies.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++#ifdef FFB_BLOCKCOPY_IMPLEMENTED
++/* Due to VIS based copyarea and ffb rop vertscroll being significantly faster
++ * than the blockcopy rop, blockcopy was not implemented at all in the final
++ * FFB hardware design.  This code is left here for hack value.  -DaveM
++ */
++void
++CreatorDoHWBitblt(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++		  DDXPointPtr pptSrc, unsigned long planemask)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pSrc->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	BoxPtr pboxTmp;
++	DDXPointPtr pptTmp;
++	int nbox;
++	BoxPtr pboxNext, pboxBase, pbox;
++
++	nbox = REGION_NUM_RECTS(prgnDst);
++	pbox = REGION_RECTS(prgnDst);
++
++	FFB_WRITE_ATTRIBUTES(ffbPriv,
++			     FFB_PPC_VCE_DISABLE|FFB_PPC_ACE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++			     FFB_PPC_VCE_MASK|FFB_PPC_ACE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++			     planemask,
++			     FFB_ROP_NEW,
++			     FFB_DRAWOP_BCOPY, ffbPriv->fg_cache,
++			     FFB_FBC_DEFAULT);
++	
++	/* need to blit rectangles in different orders, depending on the direction of copy
++           so that an area isnt overwritten before it is blitted */
++	if (pptSrc->y < pbox->y1 && nbox > 1) {
++		if (pptSrc->x < pbox->x1) {
++			pboxTmp = pbox + nbox;
++			pptTmp = pptSrc + nbox;
++			while(nbox--) {
++				pboxTmp--;
++				pptTmp--;
++				FFBFifo(ffbPriv, 6);
++				FFB_WRITE64(&ffb->by, pptTmp->y, pptTmp->x);
++				FFB_WRITE64_2(&ffb->dy, pboxTmp->y1, pboxTmp->x1);
++				FFB_WRITE64_3(&ffb->bh,
++					      (pboxTmp->y2 - pboxTmp->y1),
++					      (pboxTmp->x2 - pboxTmp->x1));
++			}
++		} else {
++			/* keep ordering in each band, reverse order of bands */
++			pboxBase = pboxNext = pbox+nbox-1;
++			
++			while (pboxBase >= pbox) { /* for each band */
++				/* find first box in band */
++				while (pboxNext >= pbox && pboxBase->y1 == pboxNext->y1)
++					pboxNext--;
++		
++				pboxTmp = pboxNext + 1;			/* first box in band */
++				pptTmp = pptSrc + (pboxTmp - pbox);	/* first point in band */
++		
++				while (pboxTmp <= pboxBase) { /* for each box in band */
++					FFBFifo(ffbPriv, 6);
++					FFB_WRITE64(&ffb->by, pptTmp->y, pptTmp->x);
++					FFB_WRITE64_2(&ffb->dy, pboxTmp->y1, pboxTmp->x1);
++					FFB_WRITE64_3(&ffb->bh,
++						      (pboxTmp->y2 - pboxTmp->y1),
++						      (pboxTmp->x2 - pboxTmp->x1));
++					++pboxTmp;
++					++pptTmp;	
++				}
++				pboxBase = pboxNext;
++			}
++		}
++	} else {
++		if((pptSrc->x < pbox->x1) && (nbox > 1)) {
++			pboxBase = pboxNext = pbox;
++			while(pboxBase < pbox+nbox) {
++				while((pboxNext<pbox+nbox) &&
++				      (pboxNext->y1 == pboxBase->y1))
++					pboxNext++;
++				pboxTmp = pboxNext;
++				pptTmp = pptSrc + (pboxTmp - pbox);
++				while(pboxTmp != pboxBase) {
++					--pboxTmp;
++					--pptTmp;
++					FFBFifo(ffbPriv, 6);
++					FFB_WRITE64(&ffb->by, pptTmp->y, pptTmp->x);
++					FFB_WRITE64_2(&ffb->dy, pboxTmp->y1, pboxTmp->x1);
++					FFB_WRITE64_3(&ffb->bh,
++						      (pboxTmp->y2 - pboxTmp->y1),
++						      (pboxTmp->x2 - pboxTmp->x1));
++				}
++				pboxBase = pboxNext;
++			}
++		} else {
++			/* dont need to change order of anything */
++			pptTmp = pptSrc;
++			pboxTmp = pbox;
++	    
++			while (nbox--) {
++				FFBFifo(ffbPriv, 6);
++				FFB_WRITE64(&ffb->by, pptTmp->y, pptTmp->x);
++				FFB_WRITE64_2(&ffb->dy, pboxTmp->y1, pboxTmp->x1);
++				FFB_WRITE64_3(&ffb->bh,
++					      (pboxTmp->y2 - pboxTmp->y1),
++					      (pboxTmp->x2 - pboxTmp->x1));
++				pboxTmp++;
++				pptTmp++;
++			}
++		}
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++#endif /* FFB_BLOCKCOPY_IMPLEMENTED */
++
++/* We know here that only y is changing and that the hw attributes
++ * have been set higher up in the call chain.
++ */
++void
++CreatorDoVertBitblt(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++		    DDXPointPtr pptSrc, unsigned long planemask)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pSrc->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	BoxPtr pbox;
++	int nbox;
++
++	pbox = REGION_RECTS(prgnDst);
++	nbox = REGION_NUM_RECTS(prgnDst);
++
++	/* No garbage please. */
++	if(nbox <= 0)
++		return;
++
++	FFBLOG("VSCROLL(%d): ", nbox);
++
++	/* Need to blit rectangles in different orders, depending
++	 * on the direction of copy so that an area isnt overwritten
++	 * before it is blitted.
++	 */
++	if (nbox > 1 && pptSrc->y < pbox->y1) {
++		BoxPtr pboxBase = pbox + nbox - 1;
++		BoxPtr pboxNext = pboxBase;
++
++		/* Keep ordering in each band, reverse order of bands. */
++		while (pboxBase >= pbox) { /* for each band */
++			BoxPtr pboxTmp;
++			DDXPointPtr pptTmp;
++
++			/* find first box in band */
++			while (pboxNext >= pbox && pboxBase->y1 == pboxNext->y1)
++				pboxNext--;
++		
++			pboxTmp = pboxNext + 1;			/* first box in band */
++			pptTmp = pptSrc + (pboxTmp - pbox);	/* first point in band */
++			while (pboxTmp <= pboxBase) {
++				FFBLOG("1[%08x:%08x:%08x:%08x:%08x:%08x] ",
++				       pptTmp->x, pptTmp->y, pboxTmp->x1, pboxTmp->y1,
++				       pboxTmp->x2, pboxTmp->y2);
++				FFBFifo(ffbPriv, 7);
++				ffb->drawop = FFB_DRAWOP_VSCROLL;
++				FFB_WRITE64(&ffb->by, pptTmp->y, pptTmp->x);
++				FFB_WRITE64_2(&ffb->dy, pboxTmp->y1, pboxTmp->x1);
++				FFB_WRITE64_3(&ffb->bh, (pboxTmp->y2 - pboxTmp->y1),
++					      (pboxTmp->x2 - pboxTmp->x1));
++				pboxTmp++;
++				pptTmp++;
++			}
++			pboxBase = pboxNext;
++		}
++	} else {
++		/* Dont need to change order of anything. */
++		while (nbox--) {
++			FFBLOG("2[%08x:%08x:%08x:%08x:%08x:%08x] ",
++			       pptSrc->x, pptSrc->y, pbox->x1, pbox->y1,
++			       pbox->x2, pbox->y2);
++			FFBFifo(ffbPriv, 7);
++			ffb->drawop = FFB_DRAWOP_VSCROLL;
++			FFB_WRITE64(&ffb->by, pptSrc->y, pptSrc->x);
++			FFB_WRITE64_2(&ffb->dy, pbox->y1, pbox->x1);
++			FFB_WRITE64_3(&ffb->bh, (pbox->y2 - pbox->y1),
++				      (pbox->x2 - pbox->x1));
++			pbox++;
++			pptSrc++;
++		}
++	}
++	ffbPriv->rp_active = 1;
++	FFBLOG("done\n");
++	FFBSync(ffbPriv, ffb);
++}
++
++#ifdef USE_VIS
++extern void VISmoveImageLR(unsigned char *, unsigned char *, long, long, long, long);
++extern void VISmoveImageRL(unsigned char *, unsigned char *, long, long, long, long);
++
++/* The hw attributes have been set by someone higher up in the call
++ * chain.
++ */
++void
++CreatorDoBitblt(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++		DDXPointPtr pptSrc, unsigned long planemask)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDst->pScreen);
++	BoxPtr pboxTmp, pboxNext, pboxBase, pbox;
++	DDXPointPtr pptTmp;
++	unsigned char *psrcBase, *pdstBase;
++	int nbox, widthSrc, widthDst, careful, use_prefetch;
++
++	cfbGetByteWidthAndPointer (pSrc, widthSrc, psrcBase)
++	cfbGetByteWidthAndPointer (pDst, widthDst, pdstBase)
++	
++	careful = ((pSrc == pDst) ||
++		  ((pSrc->type == DRAWABLE_WINDOW) &&
++		   (pDst->type == DRAWABLE_WINDOW)));
++	use_prefetch = (ffbPriv->use_blkread_prefetch &&
++			(psrcBase == (unsigned char *)ffbPriv->fb));
++
++	pbox = REGION_RECTS(prgnDst);
++	nbox = REGION_NUM_RECTS(prgnDst);
++
++	pptTmp = pptSrc;
++	pboxTmp = pbox;
++
++	FFBLOG("GCOPY(%d): ", nbox);
++
++	if (careful && pptSrc->y < pbox->y1) {
++		if (pptSrc->x < pbox->x1) {
++			/* reverse order of bands and rects in each band */
++			pboxTmp=pbox+nbox;
++                        pptTmp=pptSrc+nbox;
++
++			while (nbox--){
++				pboxTmp--;
++				pptTmp--;
++				FFBLOG("[%08x:%08x:%08x:%08x:%08x:%08x] ",
++				       pptTmp->x, pptTmp->y, pboxTmp->x1, pboxTmp->y1,
++				       pboxTmp->x2, pboxTmp->y2);
++				if (pptTmp->x < pbox->x2) {
++					if (use_prefetch) {
++						FFBFifo(ffbPriv, 1);
++						ffbPriv->regs->mer = FFB_MER_EDRA;
++						ffbPriv->rp_active = 1;
++						FFBWait(ffbPriv, ffbPriv->regs);
++					}
++					VISmoveImageRL ((psrcBase +
++							 ((pptTmp->y + pboxTmp->y2 - pboxTmp->y1 - 1) *
++							  widthSrc) +
++							 (pptTmp->x * (PSZ / 8))),
++				        	        (pdstBase +
++							 ((pboxTmp->y2 - 1) * widthDst) +
++							 (pboxTmp->x1 * (PSZ / 8))),
++					                (pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++				        	        (pboxTmp->y2 - pboxTmp->y1),
++					                -widthSrc, -widthDst);
++				} else {
++					if (use_prefetch) {
++						FFBFifo(ffbPriv, 1);
++						ffbPriv->regs->mer = FFB_MER_EIRA;
++						ffbPriv->rp_active = 1;
++						FFBWait(ffbPriv, ffbPriv->regs);
++					}
++					VISmoveImageLR ((psrcBase +
++							 ((pptTmp->y + pboxTmp->y2 - pboxTmp->y1 - 1) *
++							  widthSrc) +
++							 (pptTmp->x * (PSZ / 8))),
++				        	        (pdstBase +
++							 ((pboxTmp->y2 - 1) * widthDst) +
++							 (pboxTmp->x1 * (PSZ / 8))),
++					                (pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++				        	        (pboxTmp->y2 - pboxTmp->y1),
++					                -widthSrc, -widthDst);
++				}
++			}
++		} else {
++			/* keep ordering in each band, reverse order of bands */
++			pboxBase = pboxNext = pbox+nbox-1;
++
++			while (pboxBase >= pbox) {			/* for each band */
++
++				/* find first box in band */
++				while (pboxNext >= pbox &&
++				       pboxBase->y1 == pboxNext->y1)
++					pboxNext--;
++		
++				pboxTmp = pboxNext+1;			/* first box in band */
++				pptTmp = pptSrc + (pboxTmp - pbox);	/* first point in band */
++		
++				FFBLOG("[%08x:%08x:%08x:%08x:%08x:%08x] ",
++				       pptTmp->x, pptTmp->y, pboxTmp->x1, pboxTmp->y1,
++				       pboxTmp->x2, pboxTmp->y2);
++				while (pboxTmp <= pboxBase) {		/* for each box in band */
++					if (use_prefetch) {
++						FFBFifo(ffbPriv, 1);
++						ffbPriv->regs->mer = FFB_MER_EIRA;
++						ffbPriv->rp_active = 1;
++						FFBWait(ffbPriv, ffbPriv->regs);
++					}
++					VISmoveImageLR ((psrcBase +
++							 ((pptTmp->y + pboxTmp->y2 - pboxTmp->y1 - 1) *
++							  widthSrc) +
++							 (pptTmp->x * (PSZ / 8))),
++				        	        (pdstBase +
++							 ((pboxTmp->y2 - 1) * widthDst) +
++							 (pboxTmp->x1 * (PSZ / 8))),
++					                (pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++				        	        (pboxTmp->y2 - pboxTmp->y1),
++					                -widthSrc, -widthDst);
++					++pboxTmp;
++					++pptTmp;	
++				}
++				pboxBase = pboxNext;
++			
++			}
++		}
++	} else {
++		if (careful && pptSrc->x < pbox->x1) {
++			/* reverse order of rects in each band */
++
++			pboxBase = pboxNext = pbox;
++
++			while (pboxBase < pbox+nbox) { /* for each band */
++
++				/* find last box in band */
++				while (pboxNext < pbox+nbox &&
++				       pboxNext->y1 == pboxBase->y1)
++					pboxNext++;
++
++				pboxTmp = pboxNext;			/* last box in band */
++				pptTmp = pptSrc + (pboxTmp - pbox);	/* last point in band */
++
++				while (pboxTmp != pboxBase) {		/* for each box in band */
++					--pboxTmp;
++					--pptTmp;
++					FFBLOG("[%08x:%08x:%08x:%08x:%08x:%08x] ",
++					       pptTmp->x, pptTmp->y, pboxTmp->x1, pboxTmp->y1,
++					       pboxTmp->x2, pboxTmp->y2);
++					if (pptTmp->x < pbox->x2) {
++						if (use_prefetch) {
++							FFBFifo(ffbPriv, 1);
++							ffbPriv->regs->mer = FFB_MER_EDRA;
++							ffbPriv->regs->mer = FFB_MER_EIRA;
++							ffbPriv->rp_active = 1;
++						}
++						VISmoveImageRL ((psrcBase +
++								 (pptTmp->y * widthSrc) +
++								 (pptTmp->x * (PSZ / 8))),
++						                (pdstBase +
++								 (pboxTmp->y1 * widthDst) +
++								 (pboxTmp->x1 * (PSZ / 8))),
++						                (pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++			        	        		(pboxTmp->y2 - pboxTmp->y1),
++						                widthSrc, widthDst);
++					} else {
++						if (use_prefetch) {
++							FFBFifo(ffbPriv, 1);
++							ffbPriv->regs->mer = FFB_MER_EIRA;
++							ffbPriv->rp_active = 1;
++							FFBWait(ffbPriv, ffbPriv->regs);
++						}
++						VISmoveImageLR ((psrcBase +
++								 (pptTmp->y * widthSrc) +
++								 (pptTmp->x * (PSZ / 8))),
++						                (pdstBase +
++								 (pboxTmp->y1 * widthDst) +
++								 (pboxTmp->x1 * (PSZ / 8))),
++				                		(pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++					        	        (pboxTmp->y2 - pboxTmp->y1),
++						                widthSrc, widthDst);
++					}
++				}
++				pboxBase = pboxNext;
++			}
++		} else {
++			while (nbox--) {
++				FFBLOG("[%08x:%08x:%08x:%08x:%08x:%08x] ",
++				       pptTmp->x, pptTmp->y, pboxTmp->x1, pboxTmp->y1,
++				       pboxTmp->x2, pboxTmp->y2);
++				if (use_prefetch) {
++					FFBFifo(ffbPriv, 1);
++					ffbPriv->regs->mer = FFB_MER_EIRA;
++					ffbPriv->rp_active = 1;
++					FFBWait(ffbPriv, ffbPriv->regs);
++				}
++				VISmoveImageLR ((psrcBase +
++						 (pptTmp->y * widthSrc) +
++						 (pptTmp->x * (PSZ / 8))),
++				                (pdstBase +
++						 (pboxTmp->y1 * widthDst) +
++						 (pboxTmp->x1 * (PSZ / 8))),
++				                (pboxTmp->x2 - pboxTmp->x1) * (PSZ / 8),
++			        	        (pboxTmp->y2 - pboxTmp->y1),
++				                widthSrc, widthDst);
++				pboxTmp++;
++				pptTmp++;
++			}
++		}
++	}
++	if (use_prefetch) {
++		FFBFifo(ffbPriv, 1);
++		ffbPriv->regs->mer = FFB_MER_DRA;
++		ffbPriv->rp_active = 1;
++		FFBWait(ffbPriv, ffbPriv->regs);
++	}
++	FFBLOG("done\n");
++}
++
++RegionPtr
++CreatorCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
++		GCPtr pGC, int srcx, int srcy, int width, int height, int dstx, int dsty)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDstDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	RegionPtr ret;
++	unsigned char *dptr, *sptr;
++	int garbage;
++	
++	if (VT_HIDDEN(pDstDrawable->pScreen)) {
++		return cfbCopyArea (pSrcDrawable, pDstDrawable,
++				    pGC, srcx, srcy, width, height, dstx, dsty);
++	}
++	cfbGetByteWidthAndPointer (pDstDrawable, garbage, dptr);
++	cfbGetByteWidthAndPointer (pSrcDrawable, garbage, sptr);
++	FFBLOG("CreatorCopyArea: SFB(%p) s(%p) d(%p) alu(%x) pmsk(%08x) src(%08x:%08x) dst(%08x:%08x)\n",
++	       ffbPriv->fb, sptr, dptr, pGC->alu, pGC->planemask,
++	       srcx, srcy, dstx, dsty);
++	if (pGC->alu != GXcopy && dptr != (unsigned char *) ffbPriv->fb) {
++		if(sptr == (unsigned char *) ffbPriv->fb)
++			FFBWait(ffbPriv, ffb);
++		return cfbCopyArea (pSrcDrawable, pDstDrawable,
++				    pGC, srcx, srcy, width, height, dstx, dsty);
++	}
++	/* Try to use hw VSCROLL if possible */
++	if (!ffbPriv->disable_vscroll &&/* must not be ffb1 in hires */
++	    pGC->alu == GXcopy &&	/* it must be a copy */
++	    dstx == srcx &&		/* X must be unchanging */
++	    dsty != srcy &&		/* Y must be changing */
++	    sptr == dptr &&		/* src and dst must be the framebuffer */
++	    dptr == (unsigned char *) ffbPriv->fb) {
++		FFB_WRITE_ATTRIBUTES_VSCROLL(ffbPriv, pGC->planemask);
++		ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
++				 pGC, srcx, srcy, width, height, dstx, dsty, (void (*)())CreatorDoVertBitblt, 0);
++	} else {
++		if(dptr == (unsigned char *) ffbPriv->fb)
++			FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, pGC->planemask, pGC->alu);
++		if(dptr == (unsigned char *) ffbPriv->fb ||
++		   sptr == (unsigned char *) ffbPriv->fb)
++			FFBWait(ffbPriv, ffb);
++		ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
++				 pGC, srcx, srcy, width, height, dstx, dsty, (void (*)())CreatorDoBitblt, 0);
++	}
++	FFBLOG("CreatorCopyArea: Done, returning %p\n",
++	       ret);
++	return ret;
++}
++
++#endif /* USE_VIS */
+--- xc/programs/Xserver/hw/sun/FFB/FFBchecks.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBchecks.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,303 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - stipple/tile/line-pattern
++ * verification.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++#undef DEBUG_STIPPLE
++
++int
++CreatorCheckTile (PixmapPtr pPixmap, CreatorStipplePtr stipple, int ox, int oy, int ph)
++{
++	unsigned int *sbits;
++	unsigned int fg = 0, bg = 0;
++	int fgset = 0, bgset = 0;
++	unsigned int *tilebitsLine, *tilebits, tilebit;
++	unsigned int sbit, mask;
++	int nbwidth;
++	int h, w;
++	int x, y;
++	int s_y, s_x;
++
++	h = pPixmap->drawable.height;
++	if (h > 32 || (h & (h - 1))) {
++#ifdef DEBUG_STIPPLE
++		ErrorF("CheckTile: Cannot do in hw, h[%x]\n", h);
++#endif
++		return FALSE;
++	}
++	w = pPixmap->drawable.width;
++	if (w > 32 || (w & (w - 1))) {
++#ifdef DEBUG_STIPPLE
++		ErrorF("CheckTile: Cannot do in hw, w[%x]\n", w);
++#endif
++		return FALSE;
++	}
++	stipple->patalign = (oy << 16) | ox;
++	sbits = stipple->bits;
++	tilebitsLine = (unsigned int *) pPixmap->devPrivate.ptr;
++	nbwidth = pPixmap->devKind / sizeof(unsigned int);
++
++	for (y = 0; y < h; y++) {
++		tilebits = tilebitsLine;
++		tilebitsLine += nbwidth;
++		sbit = 0;
++		mask = 1 << 31;
++		for (x = 0; x < w; x++) {
++			tilebit = *tilebits++;
++			if (fgset && tilebit == fg)
++				sbit |=  mask;
++			else if (!bgset || tilebit != bg) {
++				if (!fgset) {
++					fgset = 1;
++					fg = tilebit;
++					sbit |= mask;
++				} else if (!bgset) {
++					bgset = 1;
++					bg = tilebit;
++				} else {
++#ifdef DEBUG_STIPPLE
++					ErrorF("CheckTile: Cannot do in hw, both bg and fg set.\n");
++#endif
++					return FALSE;
++				}
++			}
++			mask >>= 1;
++		}
++		for (s_x = w; s_x < 32; s_x <<= 1)
++			sbit = sbit | (sbit >> s_x);
++		sbit = (sbit >> ox) | (sbit << (32 - ox));
++		for (s_y = y; s_y < 32; s_y += h)
++			sbits[(s_y + oy) & 31] = sbit;
++	}
++	stipple->pagable = 1;
++	for(y = 0; y < (32 - ph); y++) {
++		if(sbits[y] != sbits[(y+ph) & (32 - 1)]) {
++			stipple->pagable = 0;
++			break;
++		}
++	}
++	stipple->fg = fg | 0xff000000;
++	stipple->bg = bg | 0xff000000;
++	stipple->inhw = 0;
++	return TRUE;
++}
++
++int
++CreatorCheckStipple (PixmapPtr pPixmap, CreatorStipplePtr stipple, int ox, int oy, int ph)
++{
++	unsigned int *sbits;
++	unsigned int *stippleBits;
++	unsigned int sbit, mask, nbwidth;
++	int h, w;
++	int y;
++	int s_y, s_x;
++
++	h = pPixmap->drawable.height;
++	if (h > 32 || (h & (h - 1))) {
++#ifdef DEBUG_STIPPLE
++		ErrorF("CheckStipple: Cannot do in hw, h[%x]\n", h);
++#endif
++		return FALSE;
++	}
++	w = pPixmap->drawable.width;
++	if (w > 32 || (w & (w - 1))) {
++#ifdef DEBUG_STIPPLE
++		ErrorF("CheckStipple: Cannot do in hw, w[%x]\n", w);
++#endif
++		return FALSE;
++	}
++	stipple->patalign = (oy << 16) | ox;
++	sbits = stipple->bits;
++	stippleBits = (unsigned int *) pPixmap->devPrivate.ptr;
++	nbwidth = pPixmap->devKind / sizeof(unsigned int);
++	mask = ~0 << (32 - w);
++	for (y = 0; y < h; y++) {
++		sbit = (*stippleBits) & mask;
++		stippleBits += nbwidth;
++		for (s_x = w; s_x < 32; s_x <<= 1)
++			sbit = sbit | (sbit >> s_x);
++		sbit = (sbit >> ox) | (sbit << (32 - ox));
++		for (s_y = y; s_y < 32; s_y += h)
++			sbits[(s_y + oy) & 31] = sbit;
++	}
++	stipple->pagable = 1;
++	for(y = 0; y < (32 - ph); y++) {
++		if(sbits[y] != sbits[(y+ph) & (32 - 1)]) {
++			stipple->pagable = 0;
++			break;
++		}
++	}
++	stipple->inhw = 0;
++	return TRUE;
++}
++
++int
++CreatorCheckLinePattern(GCPtr pGC, CreatorPrivGCPtr gcPriv)
++{
++	unsigned int linepat = 0;
++	unsigned char *dashp = (unsigned char *)pGC->dash;
++	int ndash = pGC->numInDashList;
++	int doff = (int) pGC->dashOffset;
++	int smallest_dashlen;
++	int i, nbits;
++
++	for(i = 0; i < ndash; i++)
++		nbits += dashp[i];
++	if(nbits <= 16) {
++		/* We can do it simply, so don't try to use all of
++		 * the hair below.
++		 */
++		nbits = 0;
++		for(i = 0; i < ndash; i++) {
++			int this_bits = dashp[i];
++			if((i & 1) == 0) {
++				int x;
++
++				for(x = 0; x < this_bits; x++)
++					linepat |= (1<<(nbits + x));
++			}
++			nbits += this_bits;
++		}
++		smallest_dashlen = 1;
++	} else {
++		/* Iteratively find a usable line pattern bitmap and
++		 * assosciated scale.  This is slow, but it works.
++		 * Feel free to come up with something more efficient. -DaveM
++		 */
++		smallest_dashlen = 0;
++		while(smallest_dashlen++ < 16) {
++			int bits_so_far = 0;
++
++			for(i = 0; i < ndash; i++) {
++				if((dashp[i] % smallest_dashlen) != 0)
++					break;
++				bits_so_far += dashp[i] / smallest_dashlen;
++				if(bits_so_far >= 16)
++					return FALSE;
++			}
++			if(i == ndash)
++				break;
++		}
++		if(smallest_dashlen == 16)
++			return FALSE;
++
++		/* Compute the final scaled line pattern. */
++		nbits = 0;
++		for(i = 0; i < ndash; i++) {
++			int this_bits = dashp[i] / smallest_dashlen;
++
++			nbits += this_bits;
++			if((i & 1) != 0)
++				continue;
++			while(this_bits--)
++				linepat |= (1<<(nbits - this_bits - 1));
++		}
++	}
++
++	/* We're golden... */
++	linepat = ((linepat << FFB_LPAT_PATTERN_SHIFT)					|
++		   (smallest_dashlen << FFB_LPAT_SCALEVAL_SHIFT)			|
++		   ((nbits & 0xf) << FFB_LPAT_PATLEN_SHIFT)				|
++		   (((doff / smallest_dashlen) & 0xf) << FFB_LPAT_PATPTR_SHIFT)	|
++		   (((doff % smallest_dashlen) & 0xf) << FFB_LPAT_SCALEPTR_SHIFT));
++	gcPriv->linepat = linepat;
++	return TRUE;
++}
++
++/* cache one stipple; figuring out if we can use the stipple is as hard as
++ * computing it, so we just use this one and leave it here if it
++ * can't be used this time
++ */
++
++CreatorStipplePtr FFB_tmpStipple;
++
++int
++CreatorCheckFill (GCPtr pGC, DrawablePtr pDrawable)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	CreatorStipplePtr stipple;
++	unsigned int alu;
++	int xrot, yrot, ph = FFB_FFPARMS(ffbPriv).pagefill_height;
++
++	if (pGC->fillStyle == FillSolid) {
++		if (gcPriv->stipple) {
++			xfree (gcPriv->stipple);
++			gcPriv->stipple = 0;
++		}
++		return TRUE;
++	}
++	if (!(stipple = gcPriv->stipple)) {
++		if (!FFB_tmpStipple) {
++			FFB_tmpStipple = (CreatorStipplePtr) xalloc (sizeof *FFB_tmpStipple);
++			if (!FFB_tmpStipple)
++				return FALSE;
++		}
++		stipple = FFB_tmpStipple;
++	}
++	xrot = (pGC->patOrg.x + pDrawable->x) & 31;
++	yrot = (pGC->patOrg.y + pDrawable->y) & 31;
++	alu = pGC->alu;
++	switch (pGC->fillStyle) {
++	case FillTiled:
++		if (!CreatorCheckTile (pGC->tile.pixmap, stipple, xrot, yrot, ph)) {
++			if (gcPriv->stipple) {
++				xfree (gcPriv->stipple);
++				gcPriv->stipple = 0;
++			}
++			return FALSE;
++		}
++		break;
++	case FillStippled:
++		alu |= FFB_ROP_EDIT_BIT;
++	case FillOpaqueStippled:
++		if (!CreatorCheckStipple (pGC->stipple, stipple, xrot, yrot, ph)) {
++			if (gcPriv->stipple) {
++				xfree (gcPriv->stipple);
++				gcPriv->stipple = 0;
++			}
++			return FALSE;
++		}
++		stipple->fg = pGC->fgPixel | 0xff000000;
++		stipple->bg = pGC->bgPixel | 0xff000000;
++		break;
++	}
++	stipple->alu = alu;
++	gcPriv->stipple = stipple;
++	if (stipple == FFB_tmpStipple)
++		FFB_tmpStipple = 0;
++	return TRUE;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBcircle.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBcircle.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,212 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Circle rops.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++#include "mifillarc.h"
++
++/* Wheee, circles... */
++static void
++CreatorFillEllipseSolid(DrawablePtr pDrawable, GCPtr pGC, xArc *arc)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	miFillArcRec info;
++	int x, y, e, yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
++
++	/* Get the RP ready. */
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     FFB_DRAWOP_RECTANGLE, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++
++	/* Start computing the rects. */
++	miFillArcSetup(arc, &info);
++	MIFILLARCSETUP();
++	if(pGC->miTranslate) {
++		xorg += pDrawable->x;
++		yorg += pDrawable->y;
++	}
++	while(y > 0) {
++		MIFILLARCSTEP(slw);
++		if(slw > 0) {
++			/* Render. */
++			FFBFifo(ffbPriv, 4);
++			FFB_WRITE64(&ffb->by, yorg - y, xorg - x);
++			FFB_WRITE64_2(&ffb->bh, 1, slw);
++			if(miFillArcLower(slw)) {
++				FFBFifo(ffbPriv, 4);
++				FFB_WRITE64(&ffb->by, yorg + y + dy, xorg - x);
++				FFB_WRITE64_2(&ffb->bh, 1, slw);
++			}
++		}
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++#define ADDSPAN(l,r) \
++    if (r >= l) { \
++	FFBFifo(ffbPriv, 4); \
++	FFB_WRITE64(&ffb->by, ya, l); \
++	FFB_WRITE64_2(&ffb->bh, 1, r - l + 1); \
++    }
++
++#define ADDSLICESPANS(flip) \
++    if (!flip) \
++    { \
++	ADDSPAN(xl, xr); \
++    } \
++    else \
++    { \
++	xc = xorg - x; \
++	ADDSPAN(xc, xr); \
++	xc += slw - 1; \
++	ADDSPAN(xl, xc); \
++    }
++
++static void
++CreatorFillArcSliceSolid(DrawablePtr pDrawable, GCPtr pGC, xArc *arc)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	miFillArcRec info;
++	miArcSliceRec slice;
++	DDXPointPtr points, pts;
++	int x, y, e, yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
++	int ya, xl, xr, xc;
++	int *widths, *wids;
++
++	/* Get the RP ready. */
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     FFB_DRAWOP_RECTANGLE, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++	miFillArcSetup(arc, &info);
++	miFillArcSliceSetup(arc, &slice, pGC);
++	MIFILLARCSETUP();
++	slw = arc->height;
++	if (slice.flip_top || slice.flip_bot)
++		slw += (arc->height >> 1) + 1;
++	if (pGC->miTranslate) {
++		xorg += pDrawable->x;
++		yorg += pDrawable->y;
++		slice.edge1.x += pDrawable->x;
++		slice.edge2.x += pDrawable->x;
++	}
++	while (y > 0) {
++		MIFILLARCSTEP(slw);
++		MIARCSLICESTEP(slice.edge1);
++		MIARCSLICESTEP(slice.edge2);
++		if (miFillSliceUpper(slice)) {
++			ya = yorg - y;
++			MIARCSLICEUPPER(xl, xr, slice, slw);
++			ADDSLICESPANS(slice.flip_top);
++		}
++		if (miFillSliceLower(slice)) {
++			ya = yorg + y + dy;
++			MIARCSLICELOWER(xl, xr, slice, slw);
++			ADDSLICESPANS(slice.flip_bot);
++		}
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++void
++CreatorPolyFillArcSolid (DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc *parcs)
++{
++	RegionPtr cclip;
++	xArc *arc;
++	BoxRec box;
++	int i, x2, y2;
++
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		miPolyFillArc(pDrawable, pGC, narcs, parcs);
++		return;
++	}
++	FFBLOG("CreatorPolyFillArcSolid: narcs(%d)\n", narcs);
++	cclip = cfbGetCompositeClip(pGC);
++	for(arc = parcs, i = narcs; --i >= 0; arc++) {
++		if(miFillArcEmpty(arc))
++			continue;
++		if(miCanFillArc(arc)) {
++			box.x1 = arc->x + pDrawable->x;
++			box.y1 = arc->y + pDrawable->y;
++			box.x2 = x2 = box.x1 + (int)arc->width + 1;
++			box.y2 = y2 = box.y1 + (int)arc->height + 1;
++			if((x2 & ~0x7ff) == 0 &&
++			   (y2 & ~0x7ff) == 0 &&
++			   (RECT_IN_REGION(pDrawable->pScreen, cclip, &box) == rgnIN)) {
++				if(arc->angle2 >= FULLCIRCLE ||
++				   arc->angle2 <= -FULLCIRCLE)
++					CreatorFillEllipseSolid(pDrawable, pGC, arc);
++				else
++					CreatorFillArcSliceSolid(pDrawable, pGC, arc);
++				continue;
++			}
++		}
++		/* Use slow mi code if we can't handle it simply. */
++		miPolyFillArc(pDrawable, pGC, 1, arc);
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBclip.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBclip.c	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,102 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - clip setting.
++ *
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBclip.h"
++
++unsigned int
++FFBSetClip(CreatorPrivScreenPtr ffbPriv, ffb_fbcPtr ffb, RegionPtr pClip, int numRects)
++{
++	unsigned int xy1, xy2;
++		
++	if (numRects == 1) {
++		xy1 = (pClip->extents.y1 << 16) | pClip->extents.x1;
++		xy2 = ((pClip->extents.y2 - 1) << 16) | (pClip->extents.x2 - 1);
++		if (ffbPriv->clips[0] == xy1 && ffbPriv->clips[1] == xy2)
++			return FFB_PPC_VCE_2D|FFB_PPC_ACE_DISABLE;
++		FFBFifo(ffbPriv, 2);
++		FFB_WRITE64(&ffb->vclipmin, xy1, xy2);
++		ffbPriv->clips[0] = xy1;
++		ffbPriv->clips[1] = xy2;
++		return FFB_PPC_VCE_2D|FFB_PPC_ACE_DISABLE;
++	} else if (numRects <= 5) {
++		ffb_auxclipPtr auxclip;
++		BoxPtr pBox = REGION_RECTS(pClip);
++		int i, j;
++		unsigned int xy3, xy4;
++
++		xy1 = (pBox->y1 << 16) | pBox->x1;
++		xy2 = ((pBox->y2 - 1) << 16) | (pBox->x2 - 1);
++		if (ffbPriv->clips[0] == xy1 && ffbPriv->clips[1] == xy2) {
++			j = 0;
++			for (i = 1; i < numRects; i++) {
++				xy3 = (pBox[i].y1 << 16) | pBox[i].x1;
++				xy4 = ((pBox[i].y2 - 1) << 16) | (pBox[i].x2 - 1);
++				if (j || xy3 != ffbPriv->clips[2*i] || xy4 != ffbPriv->clips[2*i+1]) {
++					j = 1;
++					ffbPriv->clips[2*i] = xy3;
++					ffbPriv->clips[2*i+1] = xy4;
++				}
++			}
++			for (; i < 5; i++) {
++				if (j || ffbPriv->clips[2*i] != 1 || ffbPriv->clips[2*i+1]) {
++					j = 1;
++					ffbPriv->clips[2*i] = 1;
++					ffbPriv->clips[2*i+1] = 0;
++				}
++			}
++			if (!j)
++				return FFB_PPC_VCE_2D|FFB_PPC_ACE_AUX_ADD;
++			FFBFifo(ffbPriv, 8);
++			auxclip = ffb->auxclip;
++			for (i = 1; i < 5; i++, auxclip++)
++				FFB_WRITE64P(&auxclip->min, &ffbPriv->clips[2*i]);
++			return FFB_PPC_VCE_2D|FFB_PPC_ACE_AUX_ADD;
++		}
++		FFBFifo(ffbPriv, 10);
++		FFB_WRITE64(&ffb->vclipmin, xy1, xy2);
++		ffbPriv->clips[0] = xy1;
++		ffbPriv->clips[1] = xy2;
++		auxclip = ffb->auxclip;
++		pBox++;
++		for (i = 1; i < numRects; i++, auxclip++, pBox++) {
++			xy3 = (pBox->y1 << 16) | pBox->x1;
++			xy4 = ((pBox->y2 - 1) << 16) | (pBox->x2 - 1);
++			FFB_WRITE64(&auxclip->min, xy3, xy4);
++			ffbPriv->clips[2*i] = xy3;
++			ffbPriv->clips[2*i+1] = xy4;
++		}
++		for (; i < 5; i++, auxclip++) {
++			FFB_WRITE64(&auxclip->min, 1, 0);
++			ffbPriv->clips[2*i] = 1;
++			ffbPriv->clips[2*i+1] = 0;
++		}
++		return FFB_PPC_VCE_2D|FFB_PPC_ACE_AUX_ADD;
++	}
++	return 0;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBclip.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBclip.h	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,48 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - clipping defines.
++ *
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#ifndef FFBCLIP_H
++#define FFBCLIP_H
++
++extern unsigned int FFBSetClip(CreatorPrivScreenPtr ffbPriv,
++			       ffb_fbcPtr ffb,
++			       RegionPtr pClip,
++			       int numRects);
++static __inline__ void
++FFBSet1Clip(CreatorPrivScreenPtr ffbPriv, ffb_fbcPtr ffb, BoxPtr extents)
++{
++	unsigned int xy1, xy2;
++	
++	xy1 = (extents->y1 << 16) | extents->x1;
++	xy2 = ((extents->y2 - 1) << 16) | (extents->x2 - 1);
++	if (ffbPriv->clips[0] == xy1 && ffbPriv->clips[1] == xy2)
++		return;
++	FFBFifo(ffbPriv, 2);
++	FFB_WRITE64(&ffb->vclipmin, xy1, xy2);
++	ffbPriv->clips[0] = xy1;
++	ffbPriv->clips[1] = xy2;
++}
++
++#endif /* FFBCLIP_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBcplane.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBcplane.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,374 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Plane copies.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++#include "mi/mi.h"
++
++/* Blatantly stolen from mach64 driver. */
++#define mfbmaskbits(x, w, startmask, endmask, nlw) \
++	startmask = starttab[(x)&0x1f]; \
++	endmask = endtab[((x)+(w)) & 0x1f]; \
++	if (startmask) \
++		nlw = (((w) - (32 - ((x)&0x1f))) >> 5); \
++	else \
++		nlw = (w) >> 5;
++
++#define mfbmaskpartialbits(x, w, mask) \
++	mask = partmasks[(x)&0x1f][(w)&0x1f];
++
++#define LeftMost    0
++#define StepBit(bit, inc)  ((bit) += (inc))
++
++
++#define GetBits(psrc, nBits, curBit, bitPos, bits) {\
++	bits = 0; \
++	while (nBits--) { \
++		bits |= ((*psrc++ >> bitPos) & 1) << curBit; \
++		StepBit (curBit, 1); \
++	} \
++}
++
++static void
++CreatorCopyPlane32to1 (DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, int rop, RegionPtr prgnDst, 
++		       DDXPointPtr pptSrc, unsigned long planemask, unsigned long bitPlane)
++{
++	int				srcx, srcy, dstx, dsty, width, height;
++	unsigned long		*psrcBase;
++	unsigned long		*pdstBase;
++	int				widthSrc, widthDst;
++	unsigned int		*psrcLine;
++	unsigned int		*pdstLine;
++	register unsigned int   *psrc;
++	register int		i;
++	register int		curBit;
++	register int		bitPos;
++	register unsigned int   bits;
++	register unsigned int   *pdst;
++	unsigned int		startmask, endmask;
++	int				niStart, niEnd;
++	int				bitStart, bitEnd;
++	int				nl, nlMiddle;
++	int				nbox;
++	BoxPtr			pbox;
++	int result;
++
++	extern int starttab[32], endtab[32];
++	extern unsigned int partmasks[32][32];
++
++	if (!(planemask & 1))
++		return;
++
++	/* must explicitly ask for "int" widths, as code below expects it */
++	/* on some machines (Sparc64), "long" and "int" are not the same size */
++	cfbGetTypedWidthAndPointer (pSrcDrawable, widthSrc, psrcBase, int, unsigned long)
++	cfbGetTypedWidthAndPointer (pDstDrawable, widthDst, pdstBase, int, unsigned long)
++
++	bitPos = ffs (bitPlane) - 1;
++
++	nbox = REGION_NUM_RECTS(prgnDst);
++	pbox = REGION_RECTS(prgnDst);
++	while (nbox--) {
++		dstx = pbox->x1;
++		dsty = pbox->y1;
++		srcx = pptSrc->x;
++		srcy = pptSrc->y;
++		width = pbox->x2 - pbox->x1;
++		height = pbox->y2 - pbox->y1;
++		pbox++;
++		pptSrc++;
++		psrcLine = (unsigned int *)psrcBase + srcy * widthSrc + srcx;
++		pdstLine = (unsigned int *)pdstBase + dsty * widthDst + (dstx >> 5);
++		if (dstx + width <= 32) {
++			mfbmaskpartialbits(dstx, width, startmask);
++			nlMiddle = 0;
++			endmask = 0;
++		} else {
++			mfbmaskbits (dstx, width, startmask, endmask, nlMiddle);
++		}
++		if (startmask) {
++			niStart = 32 - (dstx & 0x1f);
++			bitStart = LeftMost;
++			StepBit (bitStart, (dstx & 0x1f));
++		}
++		if (endmask) {
++			niEnd = (dstx + width) & 0x1f;
++			bitEnd = LeftMost;
++		}
++		if (rop == GXcopy) {
++			while (height--) {
++				psrc = psrcLine;
++				pdst = pdstLine;
++				psrcLine += widthSrc;
++				pdstLine += widthDst;
++				if (startmask) {
++					i = niStart;
++					curBit = bitStart;
++					GetBits (psrc, i, curBit, bitPos, bits);
++				
++					*pdst = (*pdst & ~startmask) | bits;
++					pdst++;
++				}
++				nl = nlMiddle;
++				
++				while (nl--) {
++					i = 32;
++					curBit = LeftMost;
++					GetBits (psrc, i, curBit, bitPos, bits);
++					*pdst++ = bits;
++				}
++				if (endmask) {
++					i = niEnd;
++					curBit = bitEnd;
++					GetBits (psrc, i, curBit, bitPos, bits);
++
++					*pdst = (*pdst & ~endmask) | bits;
++				}
++			}
++		} else {
++			while (height--) {
++				psrc = psrcLine;
++				pdst = pdstLine;
++				psrcLine += widthSrc;
++				pdstLine += widthDst;
++				if (startmask) {
++					i = niStart;
++					curBit = bitStart;
++					GetBits (psrc, i, curBit, bitPos, bits);
++					DoRop (result, rop, bits, *pdst);
++				
++					*pdst = (*pdst & ~startmask) | (result & startmask);
++					pdst++;
++				}
++				nl = nlMiddle;
++				while (nl--) {
++					i = 32;
++					curBit = LeftMost;
++					GetBits (psrc, i, curBit, bitPos, bits);
++					DoRop (result, rop, bits, *pdst);
++					*pdst = result;
++					++pdst;
++				}
++				if (endmask) {
++					i = niEnd;
++					curBit = bitEnd;
++					GetBits (psrc, i, curBit, bitPos, bits);
++					DoRop (result, rop, bits, *pdst);
++				
++					*pdst = (*pdst & ~endmask) | (result & endmask);
++				}
++			}
++		}
++	}
++}
++
++static unsigned int copyPlaneFG, copyPlaneBG;
++
++static void
++CreatorCopyPlane1to32 (DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, int rop, RegionPtr prgnDst, DDXPointPtr pptSrc, unsigned long planemask, unsigned long bitPlane)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDstDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int srcx, srcy, dstx, dsty, width, height;
++	int xoffSrc, widthSrc;
++	unsigned int *psrcBase, *psrc, *psrcStart;
++	unsigned int w, tmp, i;
++	int nbox;
++	BoxPtr pbox;
++
++	{
++		unsigned int ppc = (FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|
++				    FFB_PPC_TBE_OPAQUE|FFB_PPC_CS_CONST);
++		unsigned int ppc_mask = (FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|
++					 FFB_PPC_TBE_MASK|FFB_PPC_CS_MASK);
++		unsigned int rop = FFB_ROP_EDIT_BIT | GXcopy;
++
++		if((ffbPriv->ppc_cache & ppc_mask) != ppc ||
++		   ffbPriv->fg_cache != copyPlaneFG ||
++		   ffbPriv->fbc_cache != FFB_FBC_DEFAULT ||
++		   ffbPriv->rop_cache != rop ||
++		   ffbPriv->pmask_cache != planemask ||
++		   ffbPriv->bg_cache != copyPlaneBG) {
++			ffbPriv->ppc_cache &= ~ppc_mask;
++			ffbPriv->ppc_cache |= ppc;
++			ffbPriv->fg_cache = copyPlaneFG;
++			ffbPriv->fbc_cache = FFB_FBC_DEFAULT;
++			ffbPriv->rop_cache = rop;
++			ffbPriv->pmask_cache = planemask;
++			ffbPriv->bg_cache = copyPlaneBG;
++			ffbPriv->rp_active = 1;
++			FFBFifo(ffbPriv, 6);
++			ffb->ppc = ppc;
++			ffb->fg = copyPlaneFG;
++			ffb->fbc = FFB_FBC_DEFAULT;
++			ffb->rop = rop;
++			ffb->pmask = planemask;
++			ffb->bg = copyPlaneBG;
++		}
++	}
++
++	cfbGetTypedWidthAndPointer (pSrcDrawable, widthSrc, psrcBase, unsigned int, unsigned int)
++
++	nbox = REGION_NUM_RECTS(prgnDst);
++	pbox = REGION_RECTS(prgnDst);
++	while (nbox--) {
++		dstx = pbox->x1;
++		dsty = pbox->y1;
++		srcx = pptSrc->x;
++		srcy = pptSrc->y;
++		width = pbox->x2 - dstx;
++		height = pbox->y2 - dsty;
++		pbox++;
++		pptSrc++;
++		if (!width)
++			continue;
++		psrc = psrcBase + srcy * widthSrc + (srcx >> 5);
++		for (xoffSrc = srcx & 0x1f; height--; psrc = psrcStart + widthSrc) {
++			w = width;
++			psrcStart = psrc;
++			FFBFifo(ffbPriv, (1 + (xoffSrc != 0)));
++			ffb->fontxy = ((dsty++ << 16) | (dstx & 0xffff));
++			if (xoffSrc) {
++				tmp = 32 - xoffSrc;
++				if (tmp > w)
++					tmp = w;
++				FFB_WRITE_FONTW(ffbPriv, ffb, tmp);
++				FFB_WRITE_FONTINC(ffbPriv, ffb, tmp);
++				ffb->font = *psrc++ << xoffSrc;
++				w -= tmp;
++			}
++			if (!w)
++				continue;
++			FFB_WRITE_FONTW(ffbPriv, ffb, 32);
++			FFB_WRITE_FONTINC(ffbPriv, ffb, 32);
++			while (w >= 256) {
++				FFBFifo(ffbPriv, 8);
++				for (i = 0; i < 8; i++)
++					ffb->font = *psrc++;
++				w -= 256;
++			}
++			while (w >= 32) {
++				FFBFifo(ffbPriv, 1);
++				ffb->font = *psrc++;
++				w -= 32;
++			}
++			if (w) {
++				FFB_WRITE_FONTW(ffbPriv, ffb, w);
++				FFBFifo(ffbPriv, 1);
++				ffb->font = *psrc++;
++			}
++		}
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++RegionPtr CreatorCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
++			   GCPtr pGC, int srcx, int srcy, int width, int height,
++			   int dstx, int dsty, unsigned long bitPlane)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pSrcDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	RegionPtr ret;
++
++	if (VT_HIDDEN(pDstDrawable->pScreen))
++		return cfbCopyPlane(pSrcDrawable, pDstDrawable, pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
++    
++	FFBLOG("CreatorCopyPlane: sbpp(%d) dbpp(%d) src[%08x:%08x] dst[%08x:%08x] bplane(%08x)\n",
++	       pSrcDrawable->bitsPerPixel, pDstDrawable->bitsPerPixel,
++	       srcx, srcy, dstx, dsty, bitPlane);
++	if (pSrcDrawable->bitsPerPixel == 1 && pDstDrawable->bitsPerPixel == 32) {
++		if (bitPlane == 1) {
++			copyPlaneFG = pGC->fgPixel;
++			copyPlaneBG = pGC->bgPixel;
++			ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
++					 pGC, srcx, srcy, width, height, dstx, dsty, CreatorCopyPlane1to32, bitPlane);
++		} else
++			ret = miHandleExposures (pSrcDrawable, pDstDrawable,
++						 pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
++	} else if (pSrcDrawable->bitsPerPixel == 32 && pDstDrawable->bitsPerPixel == 1) {
++		extern int InverseAlu[16];
++		int oldalu;
++
++		oldalu = pGC->alu;
++		if ((pGC->fgPixel & 1) == 0 && (pGC->bgPixel&1) == 1)
++			pGC->alu = InverseAlu[pGC->alu];
++		else if ((pGC->fgPixel & 1) == (pGC->bgPixel & 1))
++			pGC->alu = mfbReduceRop(pGC->alu, pGC->fgPixel);
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, PMSK, GXcopy);
++		FFBWait(ffbPriv, ffb);
++		ret = cfbBitBlt (pSrcDrawable, pDstDrawable,
++				 pGC, srcx, srcy, width, height, dstx, dsty,
++				 CreatorCopyPlane32to1, bitPlane);
++		pGC->alu = oldalu;
++	} else {
++		PixmapPtr pBitmap;
++		ScreenPtr pScreen = pSrcDrawable->pScreen;
++		GCPtr pGC1;
++
++		pBitmap = (*pScreen->CreatePixmap) (pScreen, width, height, 1);
++		if (!pBitmap)
++			return NULL;
++		pGC1 = GetScratchGC (1, pScreen);
++		if (!pGC1) {
++			(*pScreen->DestroyPixmap) (pBitmap);
++			return NULL;
++		}
++		/*
++		 * don't need to set pGC->fgPixel,bgPixel as copyPlane8to1
++		 * ignores pixel values, expecting the rop to "do the
++		 * right thing", which GXcopy will.
++		 */
++		ValidateGC ((DrawablePtr) pBitmap, pGC1);
++		/* no exposures here, scratch GC's don't get graphics expose */
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, PMSK, GXcopy);
++		FFBWait(ffbPriv, ffb);
++		cfbBitBlt (pSrcDrawable, (DrawablePtr) pBitmap,
++			   pGC1, srcx, srcy, width, height, 0, 0, CreatorCopyPlane32to1, bitPlane);
++		copyPlaneFG = pGC->fgPixel;
++		copyPlaneBG = pGC->bgPixel;
++		cfbBitBlt ((DrawablePtr) pBitmap, pDstDrawable, pGC,
++			   0, 0, width, height, dstx, dsty, CreatorCopyPlane1to32, 1);
++		FreeScratchGC (pGC1);
++		(*pScreen->DestroyPixmap) (pBitmap);
++		/* compute resultant exposures */
++		ret = miHandleExposures (pSrcDrawable, pDstDrawable, pGC,
++					 srcx, srcy, width, height,
++					 dstx, dsty, bitPlane);
++	}
++	return ret;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBfifo.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBfifo.h	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,82 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - fifo macros.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#ifndef FFBFIFO_H
++#define FFBFIFO_H
++
++#include "sunFFB.h"
++
++#if 1
++/* The idling didn't really buy us anything. */
++#define FFB_IDLE(__x)	do { } while(0)
++#else
++/* Testing on my UltraI-170 indicated that each poll of
++ * the FFB ucmd register cost this many cycles.  I consider
++ * this a lower bound which we will use to tune the idler
++ * here.  The whole idea behind this is to save PIO's.  -DaveM
++ */
++#define FFB_UCMD_READ_COST	32
++#define FFB_IDLE(__x) \
++do {	int __idle, __lim = ((__x) * (FFB_UCMD_READ_COST)); \
++	for(__idle = 0; __idle < (__lim); __idle++) \
++		__asm__ __volatile__("" : : : "memory"); \
++} while(0)
++#endif
++
++/* This is the smallest FFB fifo size I know of. -DaveM */
++#define FFB_FIFO_MIN	124
++
++#define FFBFifo(__fpriv, __n) \
++do { 	int __cur_slots = (__fpriv)->fifo_cache; \
++	if((__cur_slots - (__n)) < 0) { \
++		ffb_fbcPtr __ffb = ffbPriv->regs; \
++		do {	FFB_IDLE(__n); \
++			__cur_slots = (((int)__ffb->ucsr & FFB_UCSR_FIFO_MASK) - 4); \
++		} while((__cur_slots - (__n)) < 0); \
++	} (__fpriv)->fifo_cache = (__cur_slots - (__n)); \
++} while(0)
++
++/* While we are polling for the raster processor to idle, cache the
++ * fifo count as well.
++ */
++#define FFBWait(__fpriv, __ffb) \
++if ((__fpriv)->rp_active != 0) { \
++	unsigned int __regval = (__ffb)->ucsr; \
++	while((__regval & FFB_UCSR_RP_BUSY) != 0) { \
++		FFB_IDLE(__regval & FFB_UCSR_FIFO_MASK); \
++		__regval = (__ffb)->ucsr; \
++	} \
++	(__fpriv)->fifo_cache = ((int)(__regval & FFB_UCSR_FIFO_MASK)) - 4; \
++	(__fpriv)->rp_active = 0; \
++} while(0)
++
++/* DEBUGGING */
++#if 0
++#define FFBSync(__fpriv, __ffb)	FFBWait(__fpriv, __ffb)
++#else
++#define FFBSync(__fpriv, __ffb)	do { } while(0)
++#endif
++
++#endif /* FFBFIFO_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBfrect.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBfrect.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,712 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Rectangle filling.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++#define PAGEFILL_DISABLED(ffbPriv) ((ffbPriv)->disable_pagefill != 0)
++#define FASTFILL_AP_DISABLED(ffbPriv) ((ffbPriv)->disable_fastfill_ap != 0)
++
++void
++CreatorFillBoxStipple (DrawablePtr pDrawable, int nBox, BoxPtr pBox, CreatorStipplePtr stipple)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	unsigned int bits[32];
++	unsigned int newalign;
++
++	FFBLOG("CreatorFillBoxStipple: nbox(%d)\n", nBox);
++	newalign = ((pDrawable->y & 31) << 16) | (pDrawable->x & 31);
++	if (stipple->patalign != newalign) {
++		int x, y, i;
++		
++		x = (pDrawable->x - (stipple->patalign & 0xffff)) & 31;
++		y = (pDrawable->y - (stipple->patalign >> 16)) & 31;
++		if (x | y) {
++			memcpy(bits, stipple->bits, sizeof(bits));
++			for (i = 0; i < 32; i++)
++				stipple->bits[(i + y) & 31] =
++					(bits[i] >> x) | (bits[i] << (32 - x));
++			stipple->inhw = 0;
++		}
++		stipple->patalign = newalign;
++	}
++
++	FFBSetStipple(ffbPriv, ffb, stipple,
++		      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++		      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK);
++	FFB_WRITE_PMASK(ffbPriv, ffb, ~0);
++	FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++	FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++
++	while(nBox--) {
++		register int x, y, w, h;
++
++		x = pBox->x1;
++		y = pBox->y1;
++		w = (pBox->x2 - x);
++		h = (pBox->y2 - y);
++		FFBFifo(ffbPriv, 4);
++		FFB_WRITE64(&ffb->by, y, x);
++		FFB_WRITE64_2(&ffb->bh, h, w);
++		pBox++;
++	}
++
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++enum ffb_fillrect_method { fillrect_page,
++			   fillrect_fast, fillrect_fast_opaque,
++			   fillrect_normal };
++
++#define BOX_AREA(__w, __h)	((int)(__w) * (int)(__h))
++
++/* Compute the page aligned box for a page mode fast fill.
++ * In 'ework' this returns greater than zero if there are some odd
++ * edges to take care of which are outside of the page aligned area.
++ * It will place less than zero there if the box is too small,
++ * indicating that a different method must be used to fill it.
++ */
++#define CreatorPageFillParms(ffbPriv, ffp, x, y, w, h, px, py, pw, ph, ework) \
++do {	int xdiff, ydiff; \
++	int pf_bh = ffp->pagefill_height; \
++	int pf_bw = ffp->pagefill_width; \
++	py = ((y + (pf_bh - 1)) & ~(pf_bh - 1)); \
++	ydiff = py - y; \
++	px = ffbPriv->Pf_AlignTab[x + (pf_bw - 1)]; \
++	xdiff = px - x; \
++	ph = ((h - ydiff) & ~(pf_bh - 1)); \
++	if(ph <= 0) \
++		ework = -1; \
++	else { \
++		pw = ffbPriv->Pf_AlignTab[w - xdiff]; \
++		if(pw <= 0) { \
++			ework = -1; \
++		} else { \
++			ework = (((xdiff > 0)		|| \
++				  (ydiff > 0)		|| \
++				  ((w - pw) > 0)	|| \
++				  ((h - ph) > 0))) ? 1 : 0; \
++		} \
++	} \
++} while(0);
++
++/* Compute fixups of non-page aligned areas after a page fill.
++ * Return the number of fixups needed.
++ */
++static __inline__ int
++CreatorComputePageFillFixups(xRectangle *fixups,
++			     int x, int y, int w, int h,
++			     int paligned_x, int paligned_y,
++			     int paligned_w, int paligned_h)
++{
++	int nfixups = 0;
++
++	/* FastFill Left */
++	if(paligned_x != x) {
++		fixups[nfixups].x = x;
++		fixups[nfixups].y = paligned_y;
++		fixups[nfixups].width = paligned_x - x;
++		fixups[nfixups].height = paligned_h;
++		nfixups++;
++	}
++	/* FastFill Top */
++	if(paligned_y != y) {
++		fixups[nfixups].x = x;
++		fixups[nfixups].y = y;
++		fixups[nfixups].width = w;
++		fixups[nfixups].height = paligned_y - y;
++		nfixups++;
++	}
++	/* FastFill Right */
++	if((x+w) != (paligned_x+paligned_w)) {
++		fixups[nfixups].x = (paligned_x+paligned_w);
++		fixups[nfixups].y = paligned_y;
++		fixups[nfixups].width = (x+w) - fixups[nfixups].x;
++		fixups[nfixups].height = paligned_h;
++		nfixups++;
++	}
++	/* FastFill Bottom */
++	if((y+h) != (paligned_y+paligned_h)) {
++		fixups[nfixups].x = x;
++		fixups[nfixups].y = (paligned_y+paligned_h);
++		fixups[nfixups].width = w;
++		fixups[nfixups].height = (y+h) - fixups[nfixups].y;
++		nfixups++;
++	}
++	return nfixups;
++}
++
++/* Fill a set of boxes, pagefill and fastfill not allowed. */
++static void
++CreatorBoxFillNormal(CreatorPrivScreenPtr ffbPriv,
++		     int nbox, BoxPtr pbox)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	FFBLOG("BFNormal: ");
++	if(nbox)
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++	while(nbox--) {
++		register int x, y, w, h;
++
++		x = pbox->x1;
++		y = pbox->y1;
++		w = (pbox->x2 - x);
++		h = (pbox->y2 - y);
++		pbox++;
++		FFBLOG("[%08x:%08x:%08x:%08x] ", x, y, w, h);
++		FFBFifo(ffbPriv, 4);
++		FFB_WRITE64(&ffb->by, y, x);
++		FFB_WRITE64_2(&ffb->bh, h, w);
++	}
++	FFBLOG("\n");
++}
++
++/* Fill a set of boxes, only non-pagemode fastfill is allowed. */
++static void
++CreatorBoxFillFast(CreatorPrivScreenPtr ffbPriv,
++		   int nbox, BoxPtr pbox)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	FFBLOG("BFFast: ");
++	while(nbox--) {
++		struct fastfill_parms *ffp = &FFB_FFPARMS(ffbPriv);
++		register int x, y, w, h;
++
++		x = pbox->x1;
++		y = pbox->y1;
++		w = (pbox->x2 - x);
++		h = (pbox->y2 - y);
++		pbox++;
++		if(BOX_AREA(w, h) < ffp->fastfill_small_area) {
++			/* Too small for fastfill to be useful. */
++			FFBLOG("NRM(%08x:%08x:%08x:%08x) ",
++			       x, y, w, h);
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++			FFBFifo(ffbPriv, 4);
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, h, w);
++		} else {
++			FFBLOG("FST(%08x:%08x:%08x:%08x:[%08x:%08x]) ",
++			       x, y, w, h,
++			       (w + (x & (ffp->fastfill_width - 1))),
++			       (h + (y & (ffp->fastfill_height - 1))));
++			if (ffbPriv->ffb_res == ffb_res_high &&
++			    ((x & 7) != 0 || (w & 7) != 0)) {
++				FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++				if ((x & 7) != 0) {
++					register int nx = x;
++					register int nw;
++
++					nw = 8 - (nx & 7);
++					if (nw > w)
++						nw = w;
++					FFBFifo(ffbPriv, 4);
++					FFB_WRITE64(&ffb->by, y, nx);
++					FFB_WRITE64_2(&ffb->bh, h, nw);
++					x += nw;
++					w -= nw;
++				}
++				if ((w & 7) != 0) {
++					register int nx, nw;
++
++					nw = (w & 7);
++					nx = x + (w - nw);
++					FFBFifo(ffbPriv, 4);
++					FFB_WRITE64(&ffb->by, y, nx);
++					FFB_WRITE64_2(&ffb->bh, h, nw);
++					w -= nw;
++				}
++				if (w <= 0)
++					goto next_rect;
++			}
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_FASTFILL);
++			FFBFifo(ffbPriv, 10);
++			ffb->by = FFB_FASTFILL_COLOR_BLK;
++			FFB_WRITE64(&ffb->dy, 0, 0);
++			FFB_WRITE64_2(&ffb->bh,
++				      ffp->fastfill_height,
++				      (ffp->fastfill_width * 4));
++			FFB_WRITE64_3(&ffb->dy, y, x);
++			ffb->bh = (h + (y & (ffp->fastfill_height - 1)));
++			FFB_WRITE64(&ffb->by, FFB_FASTFILL_BLOCK,
++				    (w + (x & (ffp->fastfill_width - 1))));
++		}
++	next_rect:
++		;
++	}
++	FFBLOG("\n");
++}
++
++/* Fill a set of boxes, any fastfill method is allowed. */
++static void
++CreatorBoxFillPage(CreatorPrivScreenPtr ffbPriv,
++		   int nbox, BoxPtr pbox)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	FFBLOG("BFPage: ");
++	while(nbox--) {
++		struct fastfill_parms *ffp = &FFB_FFPARMS(ffbPriv);
++		register int x, y, w, h;
++
++		x = pbox->x1;
++		y = pbox->y1;
++		w = (pbox->x2 - x);
++		h = (pbox->y2 - y);
++		pbox++;
++		if(BOX_AREA(w, h) < ffp->fastfill_small_area) {
++			/* Too small for fastfill or page fill to be useful. */
++			FFBLOG("NRM(%08x:%08x:%08x:%08x) ",
++			       x, y, w, h);
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++			FFBFifo(ffbPriv, 4);
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, h, w);
++		} else {
++			int paligned_y, paligned_x;
++			int paligned_h, paligned_w;
++			int extra_work;
++
++			if (ffbPriv->ffb_res == ffb_res_high &&
++			    ((x & 7) != 0 || (w & 7) != 0)) {
++				FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++				if ((x & 7) != 0) {
++					register int nx = x;
++					register int nw;
++
++					nw = 8 - (nx & 7);
++					if (nw > w)
++						nw = w;
++					FFBFifo(ffbPriv, 4);
++					FFB_WRITE64(&ffb->by, y, nx);
++					FFB_WRITE64_2(&ffb->bh, h, nw);
++					x += nw;
++					w -= nw;
++				}
++				if ((w & 7) != 0) {
++					register int nx, nw;
++
++					nw = (w & 7);
++					nx = x + (w - nw);
++					FFBFifo(ffbPriv, 4);
++					FFB_WRITE64(&ffb->by, y, nx);
++					FFB_WRITE64_2(&ffb->bh, h, nw);
++					w -= nw;
++				}
++				if (w <= 0)
++					goto next_rect;
++			}
++
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_FASTFILL);
++			if((w < (ffp->pagefill_width<<1)) ||
++			   (h < (ffp->pagefill_height<<1)))
++				goto do_fastfill;
++
++			CreatorPageFillParms(ffbPriv, ffp,
++					     x, y, w, h,
++					     paligned_x, paligned_y,
++					     paligned_w, paligned_h, extra_work);
++
++			/* See if the aligned area is large enough for
++			 * page fill to be worthwhile.
++			 */
++			if(extra_work < 0 ||
++			   BOX_AREA(paligned_w, paligned_h) < ffp->pagefill_small_area) {
++		   do_fastfill:
++				FFBLOG("FST(%08x:%08x:%08x:%08x:[%08x:%08x]) ",
++				       x, y, w, h,
++				       (w + (x & (ffp->fastfill_width - 1))),
++				       (h + (y & (ffp->fastfill_height - 1))));
++				FFBFifo(ffbPriv, 10);
++				ffb->by = FFB_FASTFILL_COLOR_BLK;
++				FFB_WRITE64(&ffb->dy, 0, 0);
++				FFB_WRITE64_2(&ffb->bh,
++					      ffp->fastfill_height,
++					      (ffp->fastfill_width * 4));
++				FFB_WRITE64_3(&ffb->dy, y, x);
++				ffb->bh = (h + (y & (ffp->fastfill_height - 1)));
++				FFB_WRITE64(&ffb->by, FFB_FASTFILL_BLOCK,
++					    (w + (x & (ffp->fastfill_width - 1))));
++			} else {
++				/* Ok, page fill is worth it, let it rip. */
++				FFBLOG("PAG(%08x:%08x:%08x:%08x) ",
++				       paligned_x, paligned_y, paligned_w, paligned_h);
++				FFBFifo(ffbPriv, 15);
++				ffb->by = FFB_FASTFILL_COLOR_BLK;
++				FFB_WRITE64(&ffb->dy, 0, 0);
++				FFB_WRITE64_2(&ffb->bh, ffp->fastfill_height, (ffp->fastfill_width * 4));
++				ffb->by = FFB_FASTFILL_BLOCK_X;
++				FFB_WRITE64(&ffb->dy, 0, 0);
++				FFB_WRITE64_2(&ffb->bh, ffp->pagefill_height, (ffp->pagefill_width * 4));
++				FFB_WRITE64_3(&ffb->dy, paligned_y, paligned_x);
++				ffb->bh = paligned_h;
++				FFB_WRITE64(&ffb->by, FFB_FASTFILL_PAGE, paligned_w);
++
++				if(extra_work) {
++					register int nfixups;
++
++					/* Ok, we're going to do at least one fixup. */
++					nfixups = CreatorComputePageFillFixups(ffbPriv->Pf_Fixups,
++									       x, y, w, h,
++									       paligned_x, paligned_y,
++									       paligned_w, paligned_h);
++
++					/* NOTE: For the highres case we have already
++					 *       aligned the outermost X and W coordinates.
++					 *	 Therefore we can be assured that the fixup
++					 *	 X and W coordinates below will be 8 pixel
++					 *	 aligned as well.  Do the math, it works. -DaveM
++					 */
++
++					FFBFifo(ffbPriv, 5 + (nfixups * 5));
++					ffb->by = FFB_FASTFILL_COLOR_BLK;
++					FFB_WRITE64(&ffb->dy, 0, 0);
++					FFB_WRITE64_2(&ffb->bh, ffp->fastfill_height, (ffp->fastfill_width * 4));
++
++					while(--nfixups >= 0) {
++						register int xx, yy, ww, hh;
++
++						xx = ffbPriv->Pf_Fixups[nfixups].x;
++						yy = ffbPriv->Pf_Fixups[nfixups].y;
++						FFB_WRITE64(&ffb->dy, yy, xx);
++						ww = (ffbPriv->Pf_Fixups[nfixups].width +
++						      (xx & (ffp->fastfill_width - 1)));
++						hh = (ffbPriv->Pf_Fixups[nfixups].height +
++						      (yy & (ffp->fastfill_height - 1)));
++						FFBLOG("FIXUP(%08x:%08x:%08x:%08x) ",
++						       xx, yy, ww, hh);
++						if(nfixups != 0) {
++							ffb->by = FFB_FASTFILL_BLOCK;
++							FFB_WRITE64_2(&ffb->bh, hh, ww);
++						} else {
++							ffb->bh = hh;
++							FFB_WRITE64(&ffb->by, FFB_FASTFILL_BLOCK, ww);
++						}
++					}
++				}
++			}
++		}
++	next_rect:
++		;
++	}
++	FFBLOG("\n");
++}
++
++void
++CreatorFillBoxSolid (DrawablePtr pDrawable, int nBox, BoxPtr pBox, unsigned long pixel)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	unsigned int fbc = FFB_FBC_FASTFILL;
++
++	/* In the high-resolution modes, the Creator3D transforms
++	 * the framebuffer such that the dual-buffers present become
++	 * one large single buffer.  As such you need to enable both
++	 * A and B write buffers for page fills to work properly under
++	 * this configuration. -DaveM
++	 */
++	if (ffbPriv->ffb_res == ffb_res_high)
++		fbc |= FFB_FBC_WB_B;
++
++	FFBLOG("CreatorFillBoxSolid: nbox(%d)\n", nBox);
++	FFB_WRITE_ATTRIBUTES(ffbPriv,
++			     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++			     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++			     ~0,
++			     (FFB_ROP_EDIT_BIT|GXcopy),
++			     FFB_DRAWOP_FASTFILL, pixel | 0xff000000,
++			     fbc);
++	if (PAGEFILL_DISABLED(ffbPriv))
++		CreatorBoxFillNormal(ffbPriv, nBox, pBox);
++	else
++		CreatorBoxFillPage(ffbPriv, nBox, pBox);
++
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++static void
++FFBSetStippleFast(CreatorPrivScreenPtr ffbPriv, ffb_fbcPtr ffb,
++		  CreatorStipplePtr stipple,
++		  unsigned int ppc, unsigned int ppc_mask)
++{
++	ppc |= FFB_PPC_APE_ENABLE | FFB_PPC_TBE_TRANSPARENT;
++	ppc_mask |= FFB_PPC_APE_MASK | FFB_PPC_TBE_MASK;
++	FFB_WRITE_PPC(ffbPriv, ffb, ppc, ppc_mask);
++	FFB_WRITE_ROP(ffbPriv, ffb, (FFB_ROP_EDIT_BIT|stipple->alu));
++	FFB_WRITE_FG(ffbPriv, ffb, stipple->fg);
++	FFBFifo(ffbPriv, 32);
++	FFB_STIPPLE_LOAD(&ffb->pattern[0], &stipple->bits[0]);
++}
++
++static void
++FFBSetStippleFastIdentity(CreatorPrivScreenPtr ffbPriv,
++			  ffb_fbcPtr ffb,
++			  CreatorStipplePtr stipple)
++{
++	int i;
++
++	FFB_WRITE_FG(ffbPriv, ffb, stipple->bg);
++	FFBFifo(ffbPriv, 32);
++	for(i = 0; i < 32; i++)
++		ffb->pattern[i] = ~stipple->bits[i];
++	stipple->inhw = 0;
++	ffbPriv->laststipple = NULL;
++}
++
++void
++CreatorPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill, xRectangle *prectInit)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	xRectangle	*prect;
++	RegionPtr	prgnClip;
++	register BoxPtr	pbox;
++	register BoxPtr	pboxClipped;
++	BoxPtr		pboxClippedBase;
++	BoxPtr		pextent;
++	CreatorPrivGCPtr gcPriv;
++	cfbPrivGC	*priv;
++	int		numRects;
++	int		n;
++	int		xorg, yorg;
++    
++	/* No garbage please. */
++	if(nrectFill <= 0)
++		return;
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		cfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit);
++		return;
++	}
++	gcPriv = CreatorGetGCPrivate (pGC);
++	FFBLOG("CreatorPolyFillRect: nrect(%d) ALU(%x) STIP(%p) pmsk(%08x)\n",
++	       nrectFill, pGC->alu, gcPriv->stipple, pGC->planemask);
++	priv = (cfbPrivGC *) pGC->devPrivates[cfbGCPrivateIndex].ptr;
++	prgnClip = priv->pCompositeClip;
++	prect = prectInit;
++	xorg = pDrawable->x;
++	yorg = pDrawable->y;
++	if (xorg || yorg) {
++		prect = prectInit;
++		n = nrectFill;
++		while (n--) {
++			prect->x += xorg;
++			prect->y += yorg;
++			prect++;
++		}
++	}
++
++	prect = prectInit;
++	numRects = REGION_NUM_RECTS (prgnClip) * nrectFill;
++	if (numRects > 64) {
++		pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
++		if (!pboxClippedBase)
++			return;
++	} else
++		pboxClippedBase = ffbPriv->ClippedBoxBuf;
++
++	pboxClipped = pboxClippedBase;
++	if (REGION_NUM_RECTS(prgnClip) == 1) {
++		int x1, y1, x2, y2, bx2, by2;
++
++		pextent = REGION_RECTS(prgnClip);
++		x1 = pextent->x1;
++		y1 = pextent->y1;
++		x2 = pextent->x2;
++		y2 = pextent->y2;
++		while (nrectFill--) {
++			if ((pboxClipped->x1 = prect->x) < x1)
++				pboxClipped->x1 = x1;
++
++			if ((pboxClipped->y1 = prect->y) < y1)
++				pboxClipped->y1 = y1;
++
++			bx2 = (int) prect->x + (int) prect->width;
++			if (bx2 > x2)
++				bx2 = x2;
++			pboxClipped->x2 = bx2;
++
++			by2 = (int) prect->y + (int) prect->height;
++			if (by2 > y2)
++				by2 = y2;
++			pboxClipped->y2 = by2;
++
++			prect++;
++			if ((pboxClipped->x1 < pboxClipped->x2) &&
++			    (pboxClipped->y1 < pboxClipped->y2))
++				pboxClipped++;
++		}
++	} else {
++		int x1, y1, x2, y2, bx2, by2;
++
++		pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
++		x1 = pextent->x1;
++		y1 = pextent->y1;
++		x2 = pextent->x2;
++		y2 = pextent->y2;
++		while (nrectFill--) {
++			BoxRec box;
++
++			if ((box.x1 = prect->x) < x1)
++				box.x1 = x1;
++
++			if ((box.y1 = prect->y) < y1)
++				box.y1 = y1;
++
++			bx2 = (int) prect->x + (int) prect->width;
++			if (bx2 > x2)
++				bx2 = x2;
++			box.x2 = bx2;
++
++			by2 = (int) prect->y + (int) prect->height;
++			if (by2 > y2)
++				by2 = y2;
++			box.y2 = by2;
++
++			prect++;
++
++			if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
++				continue;
++
++			n = REGION_NUM_RECTS (prgnClip);
++			pbox = REGION_RECTS(prgnClip);
++
++			/* Clip the rectangle to each box in the clip region
++			 * this is logically equivalent to calling Intersect()
++			 */
++			while(n--) {
++				pboxClipped->x1 = max(box.x1, pbox->x1);
++				pboxClipped->y1 = max(box.y1, pbox->y1);
++				pboxClipped->x2 = min(box.x2, pbox->x2);
++				pboxClipped->y2 = min(box.y2, pbox->y2);
++				pbox++;
++
++				/* see if clipping left anything */
++				if(pboxClipped->x1 < pboxClipped->x2 &&
++				   pboxClipped->y1 < pboxClipped->y2)
++					pboxClipped++;
++			}
++		}
++	}
++	/* Now fill the pre-clipped boxes. */
++	if(pboxClipped != pboxClippedBase) {
++		enum ffb_fillrect_method how = fillrect_page;
++		int num = (pboxClipped - pboxClippedBase);
++		int f_w = pboxClippedBase->x2 - pboxClippedBase->x1;
++		int f_h = pboxClippedBase->y2 - pboxClippedBase->y1;
++		unsigned int fbc = FFB_FBC_FASTFILL;
++		unsigned int drawop = FFB_DRAWOP_FASTFILL;
++
++		if (PAGEFILL_DISABLED(ffbPriv) ||
++		    pGC->alu != GXcopy ||
++		    BOX_AREA(f_w, f_h) < 128) {
++			fbc = FFB_FBC_DEFAULT;
++			drawop = FFB_DRAWOP_RECTANGLE;
++			how = fillrect_normal;
++		} else if (gcPriv->stipple != NULL) {
++			if (FASTFILL_AP_DISABLED(ffbPriv)) {
++				fbc = FFB_FBC_DEFAULT;
++				drawop = FFB_DRAWOP_RECTANGLE;
++				how = fillrect_normal;
++			} else {
++				if ((gcPriv->stipple->alu & FFB_ROP_EDIT_BIT) != 0)
++					how = fillrect_fast;
++				else
++					how = fillrect_fast_opaque;
++				if (pGC->planemask != PMSK)
++					fbc = FFB_FBC_DEFAULT;
++			}
++		}
++
++		/* In the high-resolution modes, the Creator3D transforms
++		 * the framebuffer such that the dual-buffers present become
++		 * one large single buffer.  As such you need to enable both
++		 * A and B write buffers for page/fast fills to work properly
++		 * under this configuration. -DaveM
++		 */
++		if (ffbPriv->ffb_res == ffb_res_high)
++			fbc |= FFB_FBC_WB_B;
++
++		/* Setup the attributes. */
++		if (gcPriv->stipple == NULL) {
++			FFB_WRITE_ATTRIBUTES(ffbPriv,
++					     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++					     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++					     pGC->planemask,
++					     (FFB_ROP_EDIT_BIT|pGC->alu),
++					     drawop,
++					     pGC->fgPixel | 0xff000000,
++					     fbc);
++		} else {
++			if (how == fillrect_fast_opaque) {
++				FFBSetStippleFast(ffbPriv, ffb, gcPriv->stipple,
++						  FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++						  FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++			} else {
++				FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++					      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++					      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++			}
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, drawop);
++			FFB_WRITE_FBC(ffbPriv, ffb, fbc);
++		}
++
++		/* Now render. */
++		if(how == fillrect_normal)
++			CreatorBoxFillNormal(ffbPriv, num, pboxClippedBase);
++		else if(how == fillrect_fast || how == fillrect_fast_opaque)
++			CreatorBoxFillFast(ffbPriv, num, pboxClippedBase);
++		else
++			CreatorBoxFillPage(ffbPriv, num, pboxClippedBase);
++
++		if(how == fillrect_fast_opaque) {
++			FFBSetStippleFastIdentity(ffbPriv, ffb, gcPriv->stipple);
++			CreatorBoxFillFast(ffbPriv, num, pboxClippedBase);
++		}
++
++		ffbPriv->rp_active = 1;
++		FFBSync(ffbPriv, ffb);
++	}
++	if (pboxClippedBase != ffbPriv->ClippedBoxBuf)
++		DEALLOCATE_LOCAL (pboxClippedBase);
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBfspans.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBfspans.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,123 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Fill spans.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++void
++CreatorFillSpans (DrawablePtr pDrawable, GCPtr pGC,
++		  int n, DDXPointPtr ppt,
++		  int *pwidth, int fSorted)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int ppc, numRects, *pwidthFree;
++	DDXPointPtr pptFree;
++	RegionPtr clip = cfbGetCompositeClip(pGC);
++	int nTmp = n * miFindMaxBand(clip);
++
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->FillSpans)(pDrawable, pGC, n, ppt, pwidth, fSorted);
++		return;
++	}
++#endif
++	FFBLOG("CreatorFillSpans: n(%d) fsorted(%d)\n", n, fSorted);
++	pwidthFree = (int *)ALLOCATE_LOCAL(nTmp * sizeof(int));
++	pptFree = (DDXPointRec *)ALLOCATE_LOCAL(nTmp * sizeof(DDXPointRec));
++	if (!pptFree || !pwidthFree) {
++		if (pptFree) DEALLOCATE_LOCAL(pptFree);
++		if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
++		return;
++	}
++	n = miClipSpans(clip,
++			ppt, pwidth, n,
++			pptFree, pwidthFree, fSorted);
++	pwidth = pwidthFree;
++	ppt = pptFree;
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     FFB_DRAWOP_BRLINEOPEN, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_BRLINEOPEN);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++	FFBFifo(ffbPriv, 1);
++	ffb->lpat = 0;
++
++	if (ffbPriv->has_brline_bug) {
++		while(n--) {
++			register int x, y, w;
++
++			x = ppt->x;
++			y = ppt->y;
++			w = *pwidth++;
++			FFBFifo(ffbPriv, 5);
++			ffb->ppc = 0;
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, y, (x + w));
++			ppt++;
++		}
++	} else {
++		while(n--) {
++			register int x, y, w;
++
++			x = ppt->x;
++			y = ppt->y;
++			w = *pwidth++;
++			FFBFifo(ffbPriv, 4);
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, y, (x + w));
++			ppt++;
++		}
++	}
++
++	DEALLOCATE_LOCAL(pptFree);
++	DEALLOCATE_LOCAL(pwidthFree);
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBgc.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBgc.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,618 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - GC implementation.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++#include "FFBgc.h"
++
++#include "scrnintstr.h"
++#include "pixmapstr.h"
++#include "fontstruct.h"
++#include "dixfontstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++#include "migc.h"
++#include "mi.h"
++#include "mispans.h"
++
++GCOps CreatorTEOps1Rect = {
++	CreatorFillSpans,
++	CreatorSetSpans,
++	cfbPutImage,
++	CreatorCopyArea,
++	CreatorCopyPlane,
++	CreatorPolyPoint,
++	CreatorPolylines,
++	CreatorPolySegment,
++	miPolyRectangle,
++	CreatorZeroPolyArc,
++	CreatorFillPolygon,
++	CreatorPolyFillRect,
++	CreatorPolyFillArcSolid,
++	miPolyText8,
++	miPolyText16,
++	miImageText8,
++	miImageText16,
++	CreatorTEGlyphBlt,
++	CreatorPolyTEGlyphBlt,
++	miPushPixels
++#ifdef NEED_LINEHELPER
++	,NULL
++#endif
++};
++
++GCOps CreatorTEOps = {
++	CreatorFillSpans,
++	CreatorSetSpans,
++	cfbPutImage,
++	CreatorCopyArea,
++	CreatorCopyPlane,
++	CreatorPolyPoint,
++	CreatorLineSSStub,
++	CreatorSegmentSSStub,
++	miPolyRectangle,
++	CreatorZeroPolyArc,
++	CreatorFillPolygon,
++	CreatorPolyFillRect,
++	CreatorPolyFillArcSolid,
++	miPolyText8,
++	miPolyText16,
++	miImageText8,
++	miImageText16,
++	CreatorTEGlyphBlt,
++	CreatorPolyTEGlyphBlt,
++	miPushPixels
++#ifdef NEED_LINEHELPER
++	,NULL
++#endif
++};
++
++GCOps CreatorNonTEOps1Rect = {
++	CreatorFillSpans,
++	CreatorSetSpans,
++	cfbPutImage,
++	CreatorCopyArea,
++	CreatorCopyPlane,
++	CreatorPolyPoint,
++	CreatorPolylines,
++	CreatorPolySegment,
++	miPolyRectangle,
++	CreatorZeroPolyArc,
++	CreatorFillPolygon,
++	CreatorPolyFillRect,
++	CreatorPolyFillArcSolid,
++	miPolyText8,
++	miPolyText16,
++	miImageText8,
++	miImageText16,
++	miImageGlyphBlt,
++	CreatorPolyGlyphBlt,
++	miPushPixels
++#ifdef NEED_LINEHELPER
++	,NULL
++#endif
++};
++
++GCOps CreatorNonTEOps = {
++	CreatorFillSpans,
++	CreatorSetSpans,
++	cfbPutImage,
++	CreatorCopyArea,
++	CreatorCopyPlane,
++	CreatorPolyPoint,
++	CreatorLineSSStub,
++	CreatorSegmentSSStub,
++	miPolyRectangle,
++	CreatorZeroPolyArc,
++	CreatorFillPolygon,
++	CreatorPolyFillRect,
++	CreatorPolyFillArcSolid,
++	miPolyText8,
++	miPolyText16,
++	miImageText8,
++	miImageText16,
++	miImageGlyphBlt,
++	CreatorPolyGlyphBlt,
++	miPushPixels
++#ifdef NEED_LINEHELPER
++	,NULL
++#endif
++};
++
++#define FONTWIDTH(font)	(FONTMAXBOUNDS(font,rightSideBearing) - \
++			 FONTMINBOUNDS(font,leftSideBearing))
++#define FONTHEIGHT(font) (FONTMAXBOUNDS(font,ascent) + \
++			  FONTMINBOUNDS(font,descent))
++
++static GCOps *
++CreatorMatchCommon (GCPtr pGC, cfbPrivGCPtr devPriv)
++{
++	if (pGC->lineWidth != 0) return 0;
++	if (pGC->lineStyle != LineSolid) return 0;
++	if (pGC->fillStyle != FillSolid) return 0;
++	if (devPriv->rop != GXcopy) return 0;
++	if (pGC->font &&
++	    FONTWIDTH (pGC->font) <= 32 &&
++	    FONTHEIGHT (pGC->font) <= 100 &&
++	    FONTMINBOUNDS(pGC->font,characterWidth) >= 0) {
++		if (TERMINALFONT(pGC->font))
++			if (devPriv->oneRect)
++				return &CreatorTEOps1Rect;
++			else
++				return &CreatorTEOps;
++		else
++			if (devPriv->oneRect)
++				return &CreatorNonTEOps1Rect;
++			else
++				return &CreatorNonTEOps;
++	}
++	return 0;
++}
++
++static void
++CreatorDestroyGC (GCPtr pGC)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++        
++	if (gcPriv->stipple)
++		xfree (gcPriv->stipple);
++	miDestroyGC (pGC);
++}
++
++static __inline__ void
++CreatorNewLine(GCPtr pGC, cfbPrivGCPtr devPriv, CreatorPrivGCPtr gcPriv, int accel)
++{
++	pGC->ops->FillPolygon = miFillPolygon;
++	pGC->ops->PolyRectangle = miPolyRectangle;
++	if (pGC->lineWidth == 0)
++		pGC->ops->PolyArc = miZeroPolyArc;
++	else
++		pGC->ops->PolyArc = miPolyArc;
++	if (accel) {
++#ifdef linux
++		gcPriv->FillPolygon = miFillPolygon;
++		if (pGC->fillStyle == FillSolid)
++			gcPriv->FillPolygon = (devPriv->rop == GXcopy) ? cfbFillPoly1RectCopy : cfbFillPoly1RectGeneral;
++#endif
++		pGC->ops->FillPolygon = CreatorFillPolygon;
++		if (pGC->lineWidth == 0)
++			pGC->ops->PolyArc = CreatorZeroPolyArc;
++	}
++	pGC->ops->PolySegment = miPolySegment;
++	gcPriv->linepat = 0;
++
++	/* Segment and Line ops are only accelerated if there is
++	 * one clipping region.
++	 */
++	if (accel && !devPriv->oneRect)
++		accel = 0;
++
++	if (pGC->lineStyle == LineSolid) {
++		if(pGC->lineWidth == 0) {
++			if (pGC->fillStyle == FillSolid) {
++				pGC->ops->Polylines = CreatorLineSSStub;
++				pGC->ops->PolySegment = CreatorSegmentSSStub;
++			} else
++				pGC->ops->Polylines = miZeroLine;
++			if (accel) {
++#ifdef linux
++				gcPriv->PolySegment = pGC->ops->PolySegment;
++				gcPriv->Polylines = pGC->ops->Polylines;
++#endif
++				pGC->ops->PolySegment = CreatorPolySegment;
++				pGC->ops->Polylines = CreatorPolylines;
++			}
++		} else {
++			pGC->ops->Polylines = miWideLine;
++		}
++	} else if(pGC->lineStyle == LineOnOffDash) {
++		if (pGC->lineWidth == 0 && pGC->fillStyle == FillSolid) {
++			pGC->ops->Polylines = CreatorLineSDStub;
++			pGC->ops->PolySegment = CreatorSegmentSDStub;
++			if(accel &&
++			   CreatorCheckLinePattern(pGC, gcPriv)) {
++#ifdef linux
++				gcPriv->PolySegment = pGC->ops->PolySegment;
++				gcPriv->Polylines = pGC->ops->Polylines;
++#endif
++				pGC->ops->PolySegment = CreatorPolySegment;
++				pGC->ops->Polylines = CreatorPolylines;
++			}
++		} else {
++			pGC->ops->Polylines = miWideDash;
++		}
++	} else if(pGC->lineStyle == LineDoubleDash) {
++		if (pGC->lineWidth == 0 && pGC->fillStyle == FillSolid) {
++			pGC->ops->Polylines = CreatorLineSDStub;
++			pGC->ops->PolySegment = CreatorSegmentSDStub;
++		} else {
++			pGC->ops->Polylines = miWideDash;
++		}
++	}
++}
++
++static __inline__ void
++CreatorNewGlyph(GCPtr pGC, CreatorPrivGCPtr gcPriv)
++{
++	if (FONTWIDTH(pGC->font) > 32 ||
++	    FONTHEIGHT(pGC->font) > 100 ||
++	    FONTMINBOUNDS(pGC->font,characterWidth) < 0) {
++		pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
++		pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
++	} else {
++		if (pGC->fillStyle == FillSolid) {
++#ifdef linux
++			gcPriv->PolyGlyphBlt =
++#ifdef WriteBitGroup
++				(devPriv->rop == GXcopy) ? cfbPolyGlyphBlt8 :
++#endif
++				miPolyGlyphBlt;
++#endif
++			if (TERMINALFONT (pGC->font)) {
++				pGC->ops->PolyGlyphBlt = CreatorPolyTEGlyphBlt;
++			} else {
++				pGC->ops->PolyGlyphBlt = CreatorPolyGlyphBlt;
++			}
++		} else {
++			pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
++		}			
++
++		/* special case ImageGlyphBlt for terminal emulator fonts */
++		if (TERMINALFONT(pGC->font))
++			pGC->ops->ImageGlyphBlt = CreatorTEGlyphBlt;
++		else
++			pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
++	}
++}
++
++static __inline__ void
++CreatorNewFillSpans(GCPtr pGC, cfbPrivGCPtr devPriv, CreatorPrivGCPtr gcPriv, int accel)
++{
++	if (pGC->fillStyle == FillSolid) {
++		pGC->ops->FillSpans = CreatorSolidSpansGeneralStub;
++	} else if(pGC->fillStyle == FillTiled) {
++		if (devPriv->pRotatedPixmap) {
++			if (pGC->alu == GXcopy && (pGC->planemask & PMSK) == PMSK)
++				pGC->ops->FillSpans = CreatorTile32FSCopyStub;
++			else
++				pGC->ops->FillSpans = CreatorTile32FSGeneralStub;
++		} else
++			pGC->ops->FillSpans = CreatorUnnaturalTileFSStub;
++	} else if(pGC->fillStyle == FillStippled) {
++		if (devPriv->pRotatedPixmap)
++			pGC->ops->FillSpans = Creator8Stipple32FSStub;
++		else
++			pGC->ops->FillSpans = CreatorUnnaturalStippleFSStub;
++	} else if(pGC->fillStyle == FillOpaqueStippled) {
++		if (devPriv->pRotatedPixmap)
++			pGC->ops->FillSpans = Creator8OpaqueStipple32FSStub;
++		else
++			pGC->ops->FillSpans = CreatorUnnaturalStippleFSStub;
++	} else
++		FatalError("CreatorValidateGC: illegal fillStyle\n");
++	if (accel) {
++#ifdef linux
++		gcPriv->FillSpans = pGC->ops->FillSpans;
++#endif
++		pGC->ops->FillSpans = CreatorFillSpans;
++	}
++}
++
++static __inline__ void
++CreatorNewFillArea(GCPtr pGC, cfbPrivGCPtr devPriv, CreatorPrivGCPtr gcPriv, int accel)
++{
++  	if (accel) {
++		pGC->ops->PolyFillRect = CreatorPolyFillRect;
++		pGC->ops->PolyFillArc = CreatorPolyFillArcSolid;
++	} else {
++		pGC->ops->PolyFillRect = miPolyFillRect;
++		if(pGC->fillStyle == FillSolid || pGC->fillStyle == FillTiled)
++			pGC->ops->PolyFillRect = CreatorPolyFillRectStub;
++		pGC->ops->PolyFillArc = miPolyFillArc;
++	}
++	pGC->ops->PushPixels = mfbPushPixels;
++}
++
++void
++CreatorValidateGC (GCPtr pGC, Mask changes, DrawablePtr pDrawable)
++{
++	int	mask;		/* stateChanges */
++	int	new_rrop;
++	int	new_line, new_text, new_fillspans, new_fillarea;
++	int	new_rotate;
++	int	xrot, yrot;
++	/* flags for changing the proc vector */
++	cfbPrivGCPtr devPriv;
++	CreatorPrivGCPtr gcPriv;
++	int	oneRect;
++	int	accel, drawableChanged;
++
++	gcPriv = CreatorGetGCPrivate (pGC);
++	if (pDrawable->type != DRAWABLE_WINDOW) {
++		if (gcPriv->type == DRAWABLE_WINDOW) {
++			extern GCOps cfbNonTEOps;
++
++			miDestroyGCOps (pGC->ops);
++			pGC->ops = &cfbNonTEOps;
++			changes = (1 << (GCLastBit+1)) - 1;
++			pGC->stateChanges = changes;
++			gcPriv->type = pDrawable->type;
++		}
++		cfbValidateGC (pGC, changes, pDrawable);
++
++		/* Our high speed VIS copyarea can
++		 * be used on pixmaps too.
++		 * But don't clobber someones ops prototype!!
++		 */
++		if (!pGC->ops->devPrivate.val) {
++			pGC->ops = miCreateGCOps(pGC->ops);
++			pGC->ops->devPrivate.val = 1;
++		}
++		pGC->ops->CopyArea = CreatorCopyArea;
++		return;
++	}
++	if (gcPriv->type != DRAWABLE_WINDOW) {
++		changes = (1 << (GCLastBit+1)) - 1;
++		gcPriv->type = DRAWABLE_WINDOW;
++	}
++
++	new_rotate = pGC->lastWinOrg.x != pDrawable->x || 
++		     pGC->lastWinOrg.y != pDrawable->y;
++	if(new_rotate != 0) {
++		pGC->lastWinOrg.x = pDrawable->x;
++		pGC->lastWinOrg.y = pDrawable->y;
++	}
++
++	devPriv = cfbGetGCPrivate(pGC);
++	new_rrop = FALSE;
++	new_line = FALSE;
++	new_text = FALSE; 
++	new_fillspans = FALSE;
++	new_fillarea = FALSE;
++
++	drawableChanged = (pDrawable->serialNumber !=
++			   (pGC->serialNumber & (DRAWABLE_SERIAL_BITS)));
++#define CLIP_BITS	(GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)
++	/* If the client clip is different or moved OR the subwindowMode has
++	 * changed OR the window's clip has changed since the last validation,
++	 * we need to recompute the composite clip .
++	 */
++	if ((changes & CLIP_BITS) != 0 || drawableChanged) {
++		miComputeCompositeClip(pGC, pDrawable);
++		oneRect = REGION_NUM_RECTS(devPriv->pCompositeClip) == 1;
++		if (oneRect != devPriv->oneRect) {
++			new_line = TRUE;
++			devPriv->oneRect = oneRect;
++		}
++	}
++
++	/* A while loop with a switch statement inside?  No thanks.  -DaveM */
++	mask = changes;
++	if((mask & (GCFunction | GCForeground | GCPlaneMask)) != 0)
++		new_rrop = TRUE;
++	if((mask & (GCPlaneMask | GCFillStyle | GCFont)) != 0)
++		new_text = TRUE;
++	if((mask & (GCLineStyle | GCLineWidth | GCFillStyle)) != 0)
++		new_line = TRUE;
++	if((mask & (GCFillStyle | GCTile | GCStipple)) != 0)
++		new_fillspans = new_fillarea = TRUE;
++	if(new_rotate == FALSE &&
++	   (mask & (GCTileStipXOrigin | GCTileStipYOrigin)) != 0)
++		new_rotate = TRUE;
++	if((mask & GCStipple) != 0) {
++		if(pGC->stipple) {
++			int width = pGC->stipple->drawable.width;
++			PixmapPtr nstipple;
++
++			if((width <= PGSZ) && !(width & (width - 1)) &&
++			   (nstipple = cfbCopyPixmap(pGC->stipple))) {
++				cfbPadPixmap(nstipple);
++				(*pGC->pScreen->DestroyPixmap)(pGC->stipple);
++				pGC->stipple = nstipple;
++			}
++		}
++	}
++
++	/* If the drawable has changed, check its depth and ensure suitable
++	 * entries are in the proc vector.
++	 */
++	if (drawableChanged)
++		new_fillspans = TRUE;	/* deal with FillSpans later */
++
++	if (new_rotate || new_fillspans) {
++		Bool new_pix = FALSE;
++
++		xrot = pGC->patOrg.x + pDrawable->x;
++		yrot = pGC->patOrg.y + pDrawable->y;
++ 		if (!CreatorCheckFill (pGC, pDrawable)) {
++			switch (pGC->fillStyle) {
++			case FillTiled:
++				if (!pGC->tileIsPixel)
++				{
++					int width = pGC->tile.pixmap->drawable.width * PSZ;
++
++					if ((width <= 32) && !(width & (width - 1))) {
++						cfbCopyRotatePixmap(pGC->tile.pixmap,
++								    &devPriv->pRotatedPixmap,
++								    xrot, yrot);
++						new_pix = TRUE;
++					}
++				}
++				break;
++			case FillStippled:
++			case FillOpaqueStippled:
++				{
++					int width = pGC->stipple->drawable.width;
++
++					if ((width <= PGSZ) && !(width & (width - 1)))
++					{
++						mfbCopyRotatePixmap(pGC->stipple,
++								    &devPriv->pRotatedPixmap, xrot, yrot);
++						new_pix = TRUE;
++					}
++				}
++				break;
++			}
++		}
++		if (!new_pix && devPriv->pRotatedPixmap) {
++			(*pGC->pScreen->DestroyPixmap)(devPriv->pRotatedPixmap);
++			devPriv->pRotatedPixmap = (PixmapPtr) NULL;
++		}
++	}
++
++	if (new_rrop) {
++		int old_rrop;
++
++		if (gcPriv->stipple) {
++			if (pGC->fillStyle == FillStippled)
++				gcPriv->stipple->alu = pGC->alu|FFB_ROP_EDIT_BIT;
++			else
++				gcPriv->stipple->alu = pGC->alu;
++			if (pGC->fillStyle != FillTiled) {
++				gcPriv->stipple->fg = pGC->fgPixel | 0xff000000;
++				gcPriv->stipple->bg = pGC->bgPixel | 0xff000000;
++			}
++		}
++
++		old_rrop = devPriv->rop;
++		devPriv->rop = cfbReduceRasterOp (pGC->alu, pGC->fgPixel,
++						  pGC->planemask,
++						  &devPriv->and, &devPriv->xor);
++		if (old_rrop == devPriv->rop)
++			new_rrop = FALSE;
++		else {
++			new_line = TRUE;
++			new_text = TRUE;
++			new_fillspans = TRUE;
++			new_fillarea = TRUE;
++		}
++	}
++
++	if (new_rrop || new_fillspans || new_text || new_fillarea || new_line) {
++		GCOps *newops;
++		int using_creator_ops = 0;
++
++		if ((newops = CreatorMatchCommon (pGC, devPriv))) {
++			if (pGC->ops->devPrivate.val)
++				miDestroyGCOps (pGC->ops);
++			pGC->ops = newops;
++			new_rrop = new_line = new_fillspans = new_text = new_fillarea = 0;
++			using_creator_ops = 1;
++		} else {
++			if (!pGC->ops->devPrivate.val) {
++				pGC->ops = miCreateGCOps (pGC->ops);
++				pGC->ops->devPrivate.val = 1;
++			}
++
++			/* We have to make sure the copyarea op always
++			 * points to our special routine as it maintains the
++			 * synchronization between the raster processor and direct
++			 * access to the frame buffer.
++			 */
++			pGC->ops->CopyArea = CreatorCopyArea;
++		}
++#ifdef linux	
++		if ((newops = cfbMatchCommon (pGC, devPriv))) {
++			gcPriv->FillSpans = newops->FillSpans;
++			gcPriv->FillPolygon = newops->FillPolygon;
++			gcPriv->PolySegment = newops->PolySegment;
++			gcPriv->Polylines = newops->Polylines;
++			gcPriv->PolyGlyphBlt = newops->PolyGlyphBlt;
++			gcPriv->ImageGlyphBlt = newops->ImageGlyphBlt;
++
++			if (using_creator_ops) {
++				/* Fixup line/segment backup ops. */
++				if (pGC->ops->PolySegment == CreatorPolySegment)
++					gcPriv->PolySegment = CreatorSegmentSSStub;
++				if (pGC->ops->Polylines == CreatorPolylines)
++					gcPriv->Polylines = CreatorLineSSStub;
++			}
++		}
++#endif	
++	}
++
++	accel = pGC->fillStyle == FillSolid || gcPriv->stipple;
++
++	/* deal with the changes we've collected */
++	if (new_line)
++		CreatorNewLine(pGC, devPriv, gcPriv, accel);
++
++	if (new_text && pGC->font)
++		CreatorNewGlyph(pGC, gcPriv);
++
++	if (new_fillspans)
++		CreatorNewFillSpans(pGC, devPriv, gcPriv, accel);
++
++	if (new_fillarea)
++		CreatorNewFillArea(pGC, devPriv, gcPriv, accel);
++}
++
++GCFuncs	CreatorGCFuncs = {
++	CreatorValidateGC,
++	miChangeGC,
++	miCopyGC,
++	CreatorDestroyGC,
++	miChangeClip,
++	miDestroyClip,
++	miCopyClip
++};
++
++Bool
++CreatorCreateGC (GCPtr pGC)
++{
++	CreatorPrivGCPtr gcPriv;
++	
++	if (pGC->depth == 1)
++		return mfbCreateGC (pGC);
++	if (!cfbCreateGC (pGC))
++		return FALSE;
++
++	pGC->ops = & CreatorNonTEOps;
++	pGC->funcs = & CreatorGCFuncs;
++	gcPriv = CreatorGetGCPrivate (pGC);
++	gcPriv->type = DRAWABLE_WINDOW;
++	gcPriv->linepat = 0;
++	gcPriv->stipple = 0;
++#ifdef linux
++	gcPriv->FillSpans = CreatorSolidSpansGeneralStub;
++	gcPriv->FillPolygon = miFillPolygon;
++	gcPriv->PolySegment = CreatorSegmentSSStub;
++	gcPriv->Polylines = CreatorLineSSStub;
++	gcPriv->PolyGlyphBlt = miPolyGlyphBlt;
++	gcPriv->ImageGlyphBlt = miImageGlyphBlt;
++#endif
++	return TRUE;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBgc.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBgc.h	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,154 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Accel func declarations.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFBGC_H
++#define FFBGC_H
++
++#ifdef USE_VIS
++extern void CreatorDoBitblt(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++			    DDXPointPtr pptSrc, unsigned long planemask);
++
++extern void CreatorDoVertBitblt(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++				DDXPointPtr pptSrc, unsigned long planemask);
++
++extern RegionPtr CreatorCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
++				 GCPtr pGC, int srcx, int srcy, int width, int height,
++				 int dstx, int dsty);
++#else /* !USE_VIS */
++#define CreatorCopyArea cfbCopyArea
++#endif /* !USE_VIS */
++
++extern RegionPtr CreatorCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
++				  GCPtr pGC, int srcx, int srcy, int width, int height,
++				  int dstx, int dsty, unsigned long bitPlane);
++
++extern void CreatorFillBoxSolid (DrawablePtr pDrawable, int nBox,
++				 BoxPtr pBox, unsigned long pixel);
++
++extern void CreatorFillBoxStipple (DrawablePtr pDrawable,
++				   int nBox, BoxPtr pBox, CreatorStipplePtr stipple);
++
++extern void CreatorPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
++				int nrectFill, xRectangle *prectInit);
++
++extern void CreatorFillSpans (DrawablePtr pDrawable, GCPtr pGC,
++			      int n, DDXPointPtr ppt,
++			      int *pwidth, int fSorted);
++
++extern void CreatorPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
++			     int npt, xPoint *pptInit);
++
++extern void CreatorPolySegment (DrawablePtr pDrawable, GCPtr pGC,
++				int nseg, xSegment *pSeg);
++
++extern void CreatorFillPolygon (DrawablePtr pDrawable, GCPtr pGC,
++				int shape, int mode, int count, DDXPointPtr ppt);
++
++extern void CreatorPolylines (DrawablePtr pDrawable, GCPtr pGC,
++			      int mode, int npt, DDXPointPtr ppt);
++
++extern void CreatorPolyGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++				 unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase);
++
++extern void CreatorTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++			       unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase);
++
++extern void CreatorPolyTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++				   unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase);
++
++extern void CreatorPolyFillArcSolid (DrawablePtr pDrawable, GCPtr pGC,
++				    int narcs, xArc *parcs);
++
++extern void CreatorZeroPolyArc(DrawablePtr pDrawable, GCPtr pGC,
++			       int narcs, xArc *parcs);
++
++extern int CreatorCheckTile (PixmapPtr pPixmap, CreatorStipplePtr stipple,
++			     int ox, int oy, int ph);
++
++extern int CreatorCheckStipple (PixmapPtr pPixmap, CreatorStipplePtr stipple,
++				int ox, int oy, int ph);
++
++extern int CreatorCheckLinePattern(GCPtr pGC, CreatorPrivGCPtr gcPriv);
++
++extern int CreatorCheckFill (GCPtr pGC, DrawablePtr pDrawable);
++
++extern void CreatorSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *pcharsrc,
++			    DDXPointPtr ppt, int *pwidth, int nspans, int fSorted);
++
++/* Stuff still not accelerated fully. */
++extern void CreatorSegmentSSStub (DrawablePtr pDrawable, GCPtr pGC,
++				  int nseg, xSegment *pSeg);
++
++extern void CreatorLineSSStub (DrawablePtr pDrawable, GCPtr pGC,
++			       int mode, int npt, DDXPointPtr ppt);
++
++extern void CreatorSegmentSDStub (DrawablePtr pDrawable, GCPtr pGC,
++				  int nseg, xSegment *pSeg);
++
++extern void CreatorLineSDStub (DrawablePtr pDrawable, GCPtr pGC,
++			       int mode, int npt, DDXPointPtr ppt);
++
++extern void CreatorSolidSpansGeneralStub (DrawablePtr pDrawable, GCPtr pGC,
++					  int nInit, DDXPointPtr pptInit,
++					  int *pwidthInit, int fSorted);
++
++extern void CreatorPolyGlyphBlt8Stub (DrawablePtr pDrawable, GCPtr pGC,
++				      int x, int y, unsigned int nglyph, CharInfoPtr *ppci,
++				      pointer pglyphBase);
++
++extern void CreatorImageGlyphBlt8Stub (DrawablePtr pDrawable, GCPtr pGC,
++				       int x, int y, unsigned int nglyph,
++				       CharInfoPtr *ppci, pointer pglyphBase);
++
++extern void CreatorTile32FSCopyStub(DrawablePtr pDrawable, GCPtr pGC,
++				    int nInit, DDXPointPtr pptInit,
++				    int *pwidthInit, int fSorted);
++
++extern void CreatorTile32FSGeneralStub(DrawablePtr pDrawable, GCPtr pGC,
++				       int nInit, DDXPointPtr pptInit,
++				       int *pwidthInit, int fSorted);
++
++extern void CreatorUnnaturalTileFSStub(DrawablePtr pDrawable, GCPtr pGC,
++				       int nInit, DDXPointPtr pptInit,
++				       int *pwidthInit, int fSorted);
++
++extern void Creator8Stipple32FSStub(DrawablePtr pDrawable, GCPtr pGC,
++				    int nInit, DDXPointPtr pptInit,
++				    int *pwidthInit, int fSorted);
++
++extern void CreatorUnnaturalStippleFSStub(DrawablePtr pDrawable, GCPtr pGC,
++					  int nInit, DDXPointPtr pptInit,
++					  int *pwidthInit, int fSorted);
++
++extern void Creator8OpaqueStipple32FSStub(DrawablePtr pDrawable, GCPtr pGC,
++					  int nInit, DDXPointPtr pptInit,
++					  int *pwidthInit, int fSorted);
++
++extern void CreatorPolyFillRectStub(DrawablePtr pDrawable, GCPtr pGC,
++				    int nrectFill, xRectangle *prectInit);
++
++#endif /* FFBGC_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBline.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBline.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,203 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Line rops.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBstip.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "mi/miline.h"
++
++#undef DEBUG_LINES
++
++/* The scheme here is similar as for segments, except that
++ * if there are any out of range coordinate, we fully punt
++ * and do all of the pieces in software.  This is as to
++ * avoid complexity in final line capping, sloped lines, line
++ * patterns etc.
++ */
++#define IN_RANGE(_extent, _x, _y) \
++	((_x) >= (_extent)->x1	&&	(_x) <  (_extent)->x2	&& \
++	 (_y) >= (_extent)->y1	&&	(_y) <  (_extent)->y2)
++
++
++void
++CreatorPolylines (DrawablePtr pDrawable, GCPtr pGC, int mode, int nptInit, DDXPointPtr pptInit)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	DDXPointPtr ppt;
++	BoxPtr extent;
++	int x, y, xorg, yorg, npt, capLast;
++
++	npt = nptInit;
++	if (npt <= 1)
++		return;
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->Polylines)(pDrawable, pGC, mode, nptInit, pptInit);
++		return;
++	}
++#endif
++	ppt = pptInit;
++	xorg = pDrawable->x;
++	yorg = pDrawable->y;
++	x = ppt->x + xorg;
++	y = ppt->y + yorg;
++	extent = REGION_RECTS(cfbGetCompositeClip(pGC));
++	if (!IN_RANGE(extent, x, y))
++		goto punt_rest;
++	ppt++;
++	while(npt--) {
++		if (mode == CoordModeOrigin) {
++			x = ppt->x + xorg;
++			y = ppt->y + yorg;
++		} else {
++			x += ppt->x;
++			y += ppt->y;
++		}
++		if (!IN_RANGE(extent, x, y))
++			goto punt_rest;
++		ppt++;
++	}
++	FFBLOG("CreatorPolylines: npt(%d) lpat(%08x) alu(%x) pmsk(%08x)\n",
++	       npt, gcPriv->linepat, pGC->alu, pGC->planemask);
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT | pGC->alu,
++				     FFB_DRAWOP_BRLINEOPEN,
++				     pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_BRLINEOPEN);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++	ffbPriv->rp_active = 1;
++
++	ppt = pptInit;
++	npt = nptInit;
++	x = ppt->x + xorg;
++	y = ppt->y + yorg;
++
++	FFBFifo(ffbPriv, 3);
++	ffb->lpat = gcPriv->linepat;
++	ffb->by = y;
++	ffb->bx = x;
++	ppt++;
++	npt--;
++	capLast = pGC->capStyle != CapNotLast;
++	if (mode == CoordModeOrigin) {
++		if (capLast)
++			npt--;
++		if (ffbPriv->has_brline_bug) {
++			while (npt--) {
++				x = ppt->x + xorg;
++				y = ppt->y + yorg;
++				ppt++;
++				FFBFifo(ffbPriv, 3);
++				ffb->ppc = 0;
++				FFB_WRITE64(&ffb->bh, y, x);
++			}
++		} else {
++			while (npt--) {
++				x = ppt->x + xorg;
++				y = ppt->y + yorg;
++				ppt++;
++				FFBFifo(ffbPriv, 2);
++				FFB_WRITE64(&ffb->bh, y, x);
++			}
++		}
++		if (capLast) {
++			register int x2, y2;
++
++			x2 = ppt->x + xorg;
++			y2 = ppt->y + yorg;
++
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_BRLINECAP);
++			FFBFifo(ffbPriv, 5);
++			ffb->ppc = 0;
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, y2, x2);
++		}
++	} else {
++		if (capLast)
++			npt--;
++		if (ffbPriv->has_brline_bug) {
++			while (npt--) {
++				x += ppt->x;
++				y += ppt->y;
++				ppt++;
++
++				FFBFifo(ffbPriv, 3);
++				ffb->ppc = 0;
++				FFB_WRITE64(&ffb->bh, y, x);
++			}
++		} else {
++			while (npt--) {
++				x += ppt->x;
++				y += ppt->y;
++				ppt++;
++
++				FFBFifo(ffbPriv, 2);
++				FFB_WRITE64(&ffb->bh, y, x);
++			}
++		}
++		if (capLast) {
++			register int x2, y2;
++
++			x2 = x + ppt->x;
++			y2 = y + ppt->y;
++
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_BRLINECAP);
++			FFBFifo(ffbPriv, 5);
++			ffb->ppc = 0;
++			FFB_WRITE64(&ffb->by, y, x);
++			FFB_WRITE64_2(&ffb->bh, y2, x2);
++		}
++	}
++	FFBSync(ffbPriv, ffb);
++	return;
++
++punt_rest:
++	gcPriv->Polylines(pDrawable, pGC, mode, nptInit, pptInit);
++	return;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBloops.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBloops.h	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,211 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - fast inner loops.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFBLOOPS_H
++#define FFBLOOPS_H
++
++#ifdef USE_VIS
++extern void FFB_STIPPLE_LOAD(volatile unsigned int *d,
++			     unsigned int *s);
++
++extern void FFB_PPT_BOX_LOOP(CreatorPrivScreenPtr ffbpriv,
++			     ffb_fbcPtr ffb,
++			     BoxPtr pbox, BoxPtr pbox_last,
++			     DDXPointPtr ppt);
++
++extern void FFB_BOX_LOOP(CreatorPrivScreenPtr ffbpriv,
++			 ffb_fbcPtr ffb,
++			 BoxPtr pbox,
++			 BoxPtr pbox_last);
++
++extern void FFB_RECT_LOOP(CreatorPrivScreenPtr ffbpriv,
++			  ffb_fbcPtr ffb,
++			  xRectangle *prect,
++			  xRectangle *prect_last,
++			  int xOrg, int yOrg);
++
++extern void FFB_PPT_WIDTH_LOOP(CreatorPrivScreenPtr ffbpriv,
++			       ffb_fbcPtr ffb,
++			       DDXPointPtr ppt, DDXPointPtr ppt_last,
++			       int *pwidth);
++
++extern DDXPointPtr FFB_PPT_LOOP1(CreatorPrivScreenPtr ffbpriv,
++				 ffb_fbcPtr ffb,
++				 DDXPointPtr ppt, DDXPointPtr ppt_last,
++				 int xOrg, int yOrg);
++
++extern DDXPointPtr FFB_PPT_LOOP2(CreatorPrivScreenPtr ffbpriv,
++				 ffb_fbcPtr ffb,
++				 DDXPointPtr ppt, DDXPointPtr ppt_last,
++				 int x, int y);
++
++extern DDXPointPtr FFB_LINE_LOOP1(CreatorPrivScreenPtr ffbpriv,
++				  ffb_fbcPtr ffb,
++				  DDXPointPtr ppt, DDXPointPtr ppt_last,
++				  int xOrg, int yOrg);
++
++extern DDXPointPtr FFB_LINE_LOOP2(CreatorPrivScreenPtr ffbpriv,
++				  ffb_fbcPtr ffb,
++				  DDXPointPtr ppt, DDXPointPtr ppt_last,
++				  int *x, int *y);
++
++#else /* !USE_VIS */
++
++#define FFB_STIPPLE_LOAD(_d,_s)				\
++do {							\
++	volatile unsigned int *d = (_d);		\
++	unsigned int *s = (_s);				\
++	int i;						\
++							\
++	for (i = 0; i < (32 / 2); i++, d+=2, s+=2)	\
++		FFB_WRITE64(d, s[0], s[1]);		\
++} while (0)
++
++#define FFB_PPT_BOX_LOOP(ffbPriv, ffb, pbox, _pbox_last, ppt)				\
++do {											\
++	BoxPtr pbox_last = (BoxPtr)(_pbox_last);					\
++	while (pbox <= pbox_last) {							\
++		FFBFifo(ffbPriv, 7);							\
++		ffb->drawop = FFB_DRAWOP_VSCROLL;					\
++		FFB_WRITE64(&ffb->by, ppt->y, ppt->x);					\
++		FFB_WRITE64_2(&ffb->dy, pbox->y1, pbox->x1);				\
++		FFB_WRITE64_3(&ffb->bh, (pbox->y2 - pbox->y1), (pbox->x2 - pbox->x1));	\
++		pbox++; ppt++;								\
++	}										\
++} while (0)
++
++#define FFB_BOX_LOOP(ffbPriv, ffb, pbox, _pbox_last)					\
++do {											\
++	BoxPtr pbox_last = (BoxPtr)(_pbox_last);					\
++	while (pbox <= pbox_last) {							\
++		FFBFifo(ffbPriv, 4);							\
++		FFB_WRITE64(&ffb->by, pbox->y1, pbox->x1);				\
++		FFB_WRITE64_2(&ffb->bh, (pbox->y2 - pbox->y1), (pbox->x2 - pbox->x1));	\
++		pbox++;									\
++	}										\
++} while (0)
++
++#define FFB_RECT_LOOP(ffbPriv, ffb, prect, _prect_last, xOrg, yOrg)			\
++do {											\
++	xRectangle *prect_last = (xRectangle *)(_prect_last);				\
++	for (; prect <= prect_last; prect++) {						\
++		register int x, y, w, h;						\
++		x = prect->x + xOrg;							\
++		y = prect->y + yOrg;							\
++		w = prect->width;							\
++		h = prect->height;							\
++		if (extents->x2 <= x ||							\
++		    extents->x1 >= x + w ||						\
++		    extents->y2 <= y ||							\
++		    extents->y1 >= y + h)						\
++			continue;							\
++		FFBFifo(ffbPriv, 4);							\
++		FFB_WRITE64(&ffb->by, y, x);						\
++		FFB_WRITE64_2(&ffb->bh, h, w);						\
++	}										\
++} while (0)
++
++#define FFB_PPT_WIDTH_LOOP(ffbPriv, ffb, ppt, _ppt_last, pwidth)			\
++do {											\
++	DDXPointPtr ppt_last = (DDXPointPtr)(_ppt_last);				\
++	while (ppt <= ppt_last) {							\
++		register int x, y, w;							\
++		x = ppt->x;								\
++		y = ppt->y;								\
++		w = *pwidth++;								\
++		FFBFifo(ffbPriv, 5);							\
++		ffb->ppc = 0;								\
++		FFB_WRITE64(&ffb->by, y, x);						\
++		FFB_WRITE64_2(&ffb->bh, y, (x + w));					\
++		ppt++;									\
++	}										\
++} while (0)
++
++static __inline__ DDXPointPtr FFB_PPT_LOOP1(CreatorPrivScreenPtr ffbPriv,
++				 ffb_fbcPtr ffb,
++				 DDXPointPtr ppt, DDXPointPtr ppt_last,
++				 int xOrg, int yOrg)
++{
++	while (ppt <= ppt_last) {
++		FFBFifo(ffbPriv, 2);
++		FFB_WRITE64_2(&ffb->bh, (ppt->y + yOrg), (ppt->x + xOrg));
++		ppt++;
++	}
++	return ppt;
++}
++
++static __inline__ DDXPointPtr FFB_PPT_LOOP2(CreatorPrivScreenPtr ffbPriv,
++					    ffb_fbcPtr ffb,
++					    DDXPointPtr ppt, DDXPointPtr ppt_last,
++					    int x, int y)
++{
++	register int __x = x, __y = y;
++	while (ppt <= ppt_last) {
++		FFBFifo(ffbPriv, 2);
++		__x += ppt->x;
++		__y += ppt->y;
++		FFB_WRITE64_2(&ffb->bh, __y, __x);
++		ppt++;
++	}
++	return ppt;
++}
++
++static __inline__ DDXPointPtr FFB_LINE_LOOP1(CreatorPrivScreenPtr ffbPriv,
++					     ffb_fbcPtr ffb,
++					     DDXPointPtr ppt, DDXPointPtr ppt_last,
++					     int xOrg, int yOrg)
++{
++	while (ppt <= ppt_last) {
++		FFBFifo(ffbPriv, 3);
++		ffb->ppc = 0;
++		FFB_WRITE64_2(&ffb->bh, (ppt->y + yOrg), (ppt->x + xOrg));
++		ppt++;
++	}
++	return ppt;
++}
++
++static __inline__ DDXPointPtr FFB_LINE_LOOP2(CreatorPrivScreenPtr ffbPriv,
++					     ffb_fbcPtr ffb,
++					     DDXPointPtr ppt, DDXPointPtr ppt_last,
++					     int *x, int *y)
++{
++	register int __x = *x, __y = *y;
++	while (ppt <= ppt_last) {
++		FFBFifo(ffbPriv, 3);
++		ffb->ppc = 0;
++		__x += ppt->x;
++		__y += ppt->y;
++		FFB_WRITE64_2(&ffb->bh, __y, __x);
++		ppt++;
++	}
++	*x = __x;
++	*y = __y;
++	return ppt;
++}
++
++#endif /* !USE_VIS */
++
++#endif /* FFBLOOPS_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBplygon.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBplygon.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,171 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Polygon rops.
++ *
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++void
++CreatorFillPolygon (DrawablePtr pDrawable, GCPtr pGC, int shape, int mode, int count, DDXPointPtr ppt)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	BoxRec box;
++	int lx, rx, ty, by;
++	int t, b, i, j, k, l, tt;
++	int xy[12] FFB_ALIGN64;
++	int xOrg, yOrg;
++
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->FillPolygon)(pDrawable, pGC, shape, mode, count, ppt);
++		return;
++	}
++#endif
++
++	FFBLOG("CreatorFillPolygon: ALU(%x) PMSK(%08x) shape(%d) mode(%d) count(%d)\n",
++	       pGC->alu, pGC->planemask, shape, mode, count);
++	if (count < 3)
++		return;
++	
++	if (shape != Convex && count > 3) {
++		miFillPolygon (pDrawable, pGC, shape, mode, count, ppt);
++		return;
++	}
++	
++	xOrg = pDrawable->x;
++	yOrg = pDrawable->y;
++
++	ppt->x += xOrg;
++	ppt->y += yOrg;	
++	lx = ppt->x;
++	rx = ppt->x;
++	ty = ppt->y;
++	by = ppt->y;
++	t = b = 0;
++	tt = 1;
++	for (i = 1; i < count; i++) {
++		if (mode == CoordModeOrigin) {
++			ppt[i].x += xOrg;
++			ppt[i].y += yOrg;
++		} else {
++			ppt[i].x += ppt[i-1].x;
++			ppt[i].y += ppt[i-1].y;
++		}
++		if (ppt[i].x < lx)
++			lx = ppt[i].x;
++		if (ppt[i].x > rx)
++			rx = ppt[i].x;
++		if (ppt[i].y < ty) {
++			ty = ppt[i].y;
++			t = i;
++			tt = 1;
++		} else if (ppt[i].y == ty)
++			tt++;
++		if (ppt[i].y > by) {
++			by = ppt[i].y;
++			b = i;
++		}
++	}
++	if (tt > 2) {
++		miFillConvexPoly(pDrawable, pGC, count, ppt);
++		return;
++	} else if (tt == 2) {
++		i = t - 1;
++		if (i < 0)
++			i = count - 1;
++		if (ppt[i].y == ppt[t].y)
++			t = i;
++	}
++	box.x1 = lx;
++	box.x2 = rx + 1;
++	box.y1 = ty;
++	box.y2 = by + 1;
++	
++	switch (RECT_IN_REGION(pGC->pScreen, cfbGetCompositeClip(pGC), &box)) {
++	case rgnPART:
++		miFillConvexPoly(pDrawable, pGC, count, ppt);
++	case rgnOUT:
++		return;
++	}
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     FFB_DRAWOP_POLYGON, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_POLYGON);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}	
++	xy[0] = ppt[t].y;
++	xy[1] = ppt[t].x;
++	j = t + 1;
++	if (j == count) j = 0;
++	xy[2] = ppt[j].y;
++	xy[3] = ppt[j].x;
++	j = t + 2;
++	if (j >= count)
++		j -= count;
++	for (i = 2 * count - 4; i; i -= k) {
++		b = 2;
++		for (k = 0; k < i && k < 8; k+=2) {
++			xy[4 + k] = ppt[j].y;
++			xy[4 + k + 1] = ppt[j].x;
++			if (xy[4 + k] > xy[b])
++				b = 4 + k;
++			j++; if (j == count) j = 0;
++		}
++		FFBFifo(ffbPriv, 4 + k);
++		for (l = 0; l < b - 2; l+=2)
++			FFB_WRITE64P(&ffb->by, &xy[l]);
++		FFB_WRITE64P(&ffb->bh, &xy[l]);
++		for (l+=2; l <= k; l+=2)
++			FFB_WRITE64P(&ffb->by, &xy[l]);
++		FFB_WRITE64P(&ffb->ebyi, &xy[l]);
++		xy[2] = xy[l];
++		xy[3] = xy[l+1];
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBpoint.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBpoint.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,118 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Point rops.
++ *
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++void
++CreatorPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
++		 int npt, xPoint *pptInit)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	RegionPtr clip;
++	int numRects;
++	register int off, c1, c2;
++	register char *addrp;
++	register int *ppt, pt, i;
++	BoxPtr pbox;
++	xPoint *pptPrev;
++
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		cfbPolyPoint(pDrawable, pGC, mode, npt, pptInit);
++		return;
++	}
++	FFBLOG("CreatorPolyPoint: ALU(%x) PMSK(%08x) mode(%d) npt(%d)\n",
++	       pGC->alu, pGC->planemask, mode, npt);
++	if (pGC->alu == GXnoop)
++		return;
++
++	clip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
++	numRects = REGION_NUM_RECTS(clip);
++	off = *(int *)&pDrawable->x;
++	off -= (off & 0x8000) << 1;
++	if (mode == CoordModePrevious && npt > 1) {
++		for (pptPrev = pptInit + 1, i = npt - 1; --i >= 0; pptPrev++) {
++			pptPrev->x += pptPrev[-1].x;
++			pptPrev->y += pptPrev[-1].y;
++		}
++	}
++	{
++		unsigned int ppc = FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST;
++		unsigned int ppc_mask = FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK;
++		unsigned int fg = pGC->fgPixel;
++		unsigned int fbc = FFB_FBC_DEFAULT;
++		unsigned int rop = FFB_ROP_EDIT_BIT | pGC->alu;
++		unsigned int pmask = pGC->planemask;
++
++		if((ffbPriv->ppc_cache & ppc_mask) != ppc ||
++		   ffbPriv->fg_cache != fg ||
++		   ffbPriv->fbc_cache != fbc ||
++		   ffbPriv->rop_cache != rop ||
++		   ffbPriv->pmask_cache != pmask) {
++			ffbPriv->ppc_cache &= ~ppc_mask;
++			ffbPriv->ppc_cache |= ppc;
++			ffbPriv->fg_cache = fg;
++			ffbPriv->fbc_cache = fbc;
++			ffbPriv->rop_cache = rop;
++			ffbPriv->pmask_cache = pmask;
++			ffbPriv->rp_active = 1;
++			FFBFifo(ffbPriv, 5);
++			ffb->ppc = ppc;
++			ffb->fg = fg;
++			ffb->fbc = fbc;
++			ffb->rop = rop;
++			ffb->pmask = pmask;
++		}
++	}
++	FFBWait(ffbPriv, ffb);
++
++	addrp = (char *)ffbPriv->fb + (pDrawable->y << 13) + (pDrawable->x << 2);
++	pbox = REGION_RECTS(clip);
++	while (numRects--) {
++		c1 = *(int *)&pbox->x1 - off;
++		c2 = *(int *)&pbox->x2 - off - 0x00010001;
++		for (ppt = (int *)pptInit, i = npt; --i >= 0; ) {
++			pt = *ppt++;
++			if (!(((pt - c1) | (c2 - pt)) & 0x80008000))
++				*(unsigned int *)(addrp + ((pt << 13) & 0xffe000) + ((pt >> 14) & 0x1ffc)) = 0;
++		}
++		pbox++;
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBrcache.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBrcache.h	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,212 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - register caching.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFBRCACHE_H
++#define FFBRCACHE_H
++
++/* We only need to write the bits which actually change,
++ * writing unnessary bits causes the operation to go more
++ * slowly. -DaveM
++ *
++ * We used to have some hairy code here which tried to
++ * avoid writing attribute bits unnecessarily.  It has been
++ * removed because various two bit fields have different
++ * semantics.  For example, for some the higher bit is the
++ * edit bit, for others there are three state patterns
++ * and zero is a special "no edit" value.  Ho hum, it was
++ * a nice idea...
++ */
++#define FFB_WRITE_PPC(__fpriv, __ffb, __val, __chg_mask) \
++do {	unsigned int oldval = (__fpriv)->ppc_cache; \
++	unsigned int __t; \
++	__t = (oldval & (__chg_mask)) ^ (__val); \
++	if (__t) { \
++		unsigned int newval = oldval & ~(__chg_mask); \
++		newval |= (__val); \
++		(__fpriv)->ppc_cache = newval; \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->ppc = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_PMASK(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->pmask_cache != (__val)) { \
++		(__fpriv)->pmask_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->pmask = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_ROP(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->rop_cache != (__val)) { \
++		(__fpriv)->rop_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->rop = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_DRAWOP(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->drawop_cache != (__val)) { \
++		(__fpriv)->drawop_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->drawop = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_FG(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->fg_cache != (__val)) { \
++		(__fpriv)->fg_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->fg = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_BG(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->bg_cache != (__val)) { \
++		(__fpriv)->bg_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->bg = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_FONTW(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->fontw_cache != (__val)) { \
++		(__fpriv)->fontw_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->fontw = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_FONTINC(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->fontinc_cache != (__val)) { \
++		(__fpriv)->fontinc_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->fontinc = (__val); \
++	} \
++} while(0)
++
++#define FFB_WRITE_FBC(__fpriv, __ffb, __val) \
++do {	if((__fpriv)->fbc_cache != (__val)) { \
++		(__fpriv)->fbc_cache = (__val); \
++		FFBFifo((__fpriv), 1); \
++		(__ffb)->fbc = (__val); \
++	} \
++} while(0)
++
++extern void __FFB_Write_Attributes(CreatorPrivScreenPtr ffbPriv,
++				   unsigned int ppc,
++				   unsigned int ppc_mask,
++				   unsigned int pmask,
++				   unsigned int rop,
++				   int drawop, int fg,
++				   unsigned int fbc);
++
++#define FFB_WRITE_ATTRIBUTES(__fpriv, __ppc, __ppc_mask, __pmask, __rop, __drawop, __fg, __fbc) \
++	if((((__fpriv)->ppc_cache & (__ppc_mask)) != (__ppc))			|| \
++	   ((__fpriv)->pmask_cache != (__pmask))				|| \
++	   ((__fpriv)->rop_cache != (__rop))					|| \
++	   (((__drawop) != -1) && ((__fpriv)->drawop_cache != (__drawop)))	|| \
++	   ((__fpriv)->fg_cache != (__fg))					|| \
++	   ((__fpriv)->fbc_cache != (__fbc))) \
++		__FFB_Write_Attributes((__fpriv), (__ppc), (__ppc_mask), (__pmask), \
++				       (__rop), (__drawop), (__fg), (__fbc))
++
++/* Setup to access the smart frame buffer (SFB) directly where the
++ * pixel color comes from the cpu on writes.
++ */
++#define FFB_WRITE_ATTRIBUTES_SFB_VAR(__fpriv, __pmask, __alu) \
++do {	unsigned int ppc = FFB_PPC_FW_DISABLE | FFB_PPC_VCE_DISABLE | FFB_PPC_APE_DISABLE | FFB_PPC_CS_VAR; \
++	unsigned int ppc_mask = FFB_PPC_FW_MASK | FFB_PPC_VCE_MASK | FFB_PPC_APE_MASK | FFB_PPC_CS_MASK; \
++	unsigned int rop = FFB_ROP_EDIT_BIT | (__alu); \
++	if(((__fpriv)->ppc_cache & ppc_mask) != ppc || \
++	   (__fpriv)->fbc_cache != FFB_FBC_DEFAULT || \
++	   (__fpriv)->rop_cache != rop || \
++	   (__fpriv)->pmask_cache != (__pmask)) { \
++		ffb_fbcPtr __ffb = (__fpriv)->regs; \
++		(__fpriv)->ppc_cache &= ~ppc_mask; \
++		(__fpriv)->ppc_cache |= ppc; \
++		(__fpriv)->fbc_cache = FFB_FBC_DEFAULT; \
++		(__fpriv)->rop_cache = rop; \
++		(__fpriv)->pmask_cache = (__pmask); \
++		(__fpriv)->rp_active = 1; \
++		FFBFifo(__fpriv, 4); \
++		(__ffb)->ppc = ppc; \
++		(__ffb)->fbc = FFB_FBC_DEFAULT; \
++		(__ffb)->rop = rop; \
++		(__ffb)->pmask = (__pmask); \
++	} \
++} while(0)
++
++/* VSCROLL Attributes:
++ *
++ * PPC) VCE_DISABLE must be set, all other attributes are effectively
++ *      ignored since this drawop just copies pixels within the ram
++ *      chips and bypasses the pixel processor entirely
++ * FBC) all options are allowed, but the SRC/DST buffers are determined
++ *      solely by the WB_* setting, that is, the RB_* setting is effectively
++ *      ignored since the pixels are copied directly through the write buffer
++ * ROP) must be FFB_ROP_OLD
++ * PMASK) all options allowed
++ */
++#define FFB_WRITE_ATTRIBUTES_VSCROLL(__fpriv, __pmask) \
++do {	unsigned int ppc = FFB_PPC_FW_DISABLE | FFB_PPC_VCE_DISABLE; \
++	unsigned int ppc_mask = FFB_PPC_FW_MASK | FFB_PPC_VCE_MASK; \
++	unsigned int rop = FFB_ROP_OLD; \
++	if(((__fpriv)->ppc_cache & ppc_mask) != ppc || \
++	   (__fpriv)->fbc_cache != FFB_FBC_DEFAULT || \
++	   (__fpriv)->rop_cache != rop || \
++	   (__fpriv)->pmask_cache != (__pmask) || \
++	   (__fpriv)->drawop_cache != FFB_DRAWOP_VSCROLL) { \
++		ffb_fbcPtr __ffb = (__fpriv)->regs; \
++		(__fpriv)->ppc_cache &= ~ppc_mask; \
++		(__fpriv)->ppc_cache |= ppc; \
++		(__fpriv)->fbc_cache = FFB_FBC_DEFAULT; \
++		(__fpriv)->rop_cache = rop; \
++		(__fpriv)->pmask_cache = (__pmask); \
++		(__fpriv)->drawop_cache = FFB_DRAWOP_VSCROLL; \
++		(__fpriv)->rp_active = 1; \
++		FFBFifo(__fpriv, 5); \
++		(__ffb)->ppc = ppc; \
++		(__ffb)->fbc = FFB_FBC_DEFAULT; \
++		(__ffb)->rop = rop; \
++		(__ffb)->pmask = (__pmask); \
++		(__ffb)->drawop = FFB_DRAWOP_VSCROLL; \
++	} \
++} while(0)
++
++#define FFB_FBC_DEFAULT				\
++(FFB_FBC_WB_A|FFB_FBC_WM_COMBINED|		\
++ FFB_FBC_RB_A|FFB_FBC_SB_BOTH|			\
++ FFB_FBC_ZE_OFF|FFB_FBC_YE_OFF|FFB_FBC_XE_OFF|	\
++ FFB_FBC_RGBE_MASK)
++
++#define FFB_FBC_FASTFILL			\
++(FFB_FBC_WB_A|FFB_FBC_WM_COMBINED|		\
++ FFB_FBC_RB_A|FFB_FBC_SB_BOTH|			\
++ FFB_FBC_ZE_OFF|FFB_FBC_YE_OFF|FFB_FBC_XE_ON|	\
++ FFB_FBC_RGBE_ON)
++
++#endif /* FFBRCACHE_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBregs.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBregs.h	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,511 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - register layout.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFBREGS_H
++#define FFBREGS_H
++
++/* Auxilliary clips. */
++typedef struct  {
++	volatile unsigned int min;
++	volatile unsigned int max;
++} ffb_auxclip, *ffb_auxclipPtr;
++
++/* FFB register set. */
++typedef struct _ffb_fbc {
++	/* Next vertex registers, on the right we list which drawops
++	 * use said register and the logical name the register has in
++	 * that context.
++	 */					/* DESCRIPTION		DRAWOP(NAME)	*/
++/*0x00*/unsigned int		pad1[3];	/* Reserved				*/
++/*0x0c*/volatile unsigned int	alpha;		/* ALPHA Transparency			*/
++/*0x10*/volatile unsigned int	red;		/* RED					*/
++/*0x14*/volatile unsigned int	green;		/* GREEN				*/
++/*0x18*/volatile unsigned int	blue;		/* BLUE					*/
++/*0x1c*/volatile unsigned int	z;		/* DEPTH				*/
++/*0x20*/volatile unsigned int	y;		/* Y			triangle(DOYF)	*/
++						/*                      aadot(DYF)	*/
++						/*                      ddline(DYF)	*/
++						/*                      aaline(DYF)	*/
++/*0x24*/volatile unsigned int	x;		/* X			triangle(DOXF)	*/
++						/*                      aadot(DXF)	*/
++						/*                      ddline(DXF)	*/
++						/*                      aaline(DXF)	*/
++/*0x28*/unsigned int		pad2[2];	/* Reserved				*/
++/*0x30*/volatile unsigned int	ryf;		/* Y (alias to DOYF)	ddline(RYF)	*/
++						/*			aaline(RYF)	*/
++						/*			triangle(RYF)	*/
++/*0x34*/volatile unsigned int	rxf;		/* X			ddline(RXF)	*/
++						/*			aaline(RXF)	*/
++						/*			triangle(RXF)	*/
++/*0x38*/unsigned int		pad3[2];	/* Reserved				*/
++/*0x40*/volatile unsigned int	dmyf;		/* Y (alias to DOYF)	triangle(DMYF)	*/
++/*0x44*/volatile unsigned int	dmxf;		/* X			triangle(DMXF)	*/
++/*0x48*/unsigned int		pad4[2];	/* Reserved				*/
++/*0x50*/volatile unsigned int	ebyi;		/* Y (alias to RYI)	polygon(EBYI)	*/
++/*0x54*/volatile unsigned int	ebxi;		/* X			polygon(EBXI)	*/
++/*0x58*/unsigned int		pad5[2];	/* Reserved				*/
++/*0x60*/volatile unsigned int	by;		/* Y			brline(RYI)	*/
++						/*			fastfill(OP)	*/
++						/*			polygon(YI)	*/
++						/*			rectangle(YI)	*/
++						/*			bcopy(SRCY)	*/
++						/*			vscroll(SRCY)	*/
++/*0x64*/volatile unsigned int	bx;		/* X			brline(RXI)	*/
++						/*			polygon(XI)	*/
++						/*			rectangle(XI)	*/
++						/*			bcopy(SRCX)	*/
++						/*			vscroll(SRCX)	*/
++						/*			fastfill(GO)	*/
++/*0x68*/volatile unsigned int	dy;		/* destination Y	fastfill(DSTY)	*/
++						/*			bcopy(DSRY)	*/
++						/*			vscroll(DSRY)	*/
++/*0x6c*/volatile unsigned int	dx;		/* destination X	fastfill(DSTX)	*/
++						/*			bcopy(DSTX)	*/
++						/*			vscroll(DSTX)	*/
++/*0x70*/volatile unsigned int	bh;		/* Y (alias to RYI)	brline(DYI)	*/
++						/*			dot(DYI)	*/
++						/*			polygon(ETYI)	*/
++						/* Height		fastfill(H)	*/
++						/*			bcopy(H)	*/
++						/*			vscroll(H)	*/
++						/* Y count		fastfill(NY)	*/
++/*0x74*/volatile unsigned int	bw;		/* X			dot(DXI)	*/
++						/*			brline(DXI)	*/
++						/*			polygon(ETXI)	*/
++						/*			fastfill(W)	*/
++						/*			bcopy(W)	*/
++						/*			vscroll(W)	*/
++						/*			fastfill(NX)	*/
++/*0x78*/unsigned int		pad6[2];	/* Reserved				*/
++/*0x80*/unsigned int		pad7[32];	/* Reserved				*/
++	
++	/* Setup Unit's vertex state register */
++/*100*/	volatile unsigned int	suvtx;
++/*104*/	unsigned int		pad8[63];	/* Reserved				*/
++	
++	/* Frame Buffer Control Registers */
++/*200*/	volatile unsigned int	ppc;		/* Pixel Processor Control		*/
++/*204*/	volatile unsigned int	wid;		/* Current WID				*/
++/*208*/	volatile unsigned int	fg;		/* FG data				*/
++/*20c*/	volatile unsigned int	bg;		/* BG data				*/
++/*210*/	volatile unsigned int	consty;		/* Constant Y				*/
++/*214*/	volatile unsigned int	constz;		/* Constant Z				*/
++/*218*/	volatile unsigned int	xclip;		/* X Clip				*/
++/*21c*/	volatile unsigned int	dcss;		/* Depth Cue Scale Slope		*/
++/*220*/	volatile unsigned int	vclipmin;	/* Viewclip XY Min Bounds		*/
++/*224*/	volatile unsigned int	vclipmax;	/* Viewclip XY Max Bounds		*/
++/*228*/	volatile unsigned int	vclipzmin;	/* Viewclip Z Min Bounds		*/
++/*22c*/	volatile unsigned int	vclipzmax;	/* Viewclip Z Max Bounds		*/
++/*230*/	volatile unsigned int	dcsf;		/* Depth Cue Scale Front Bound		*/
++/*234*/	volatile unsigned int	dcsb;		/* Depth Cue Scale Back Bound		*/
++/*238*/	volatile unsigned int	dczf;		/* Depth Cue Z Front			*/
++/*23c*/	volatile unsigned int	dczb;		/* Depth Cue Z Back			*/
++/*240*/	unsigned int		pad9;		/* Reserved				*/
++/*244*/	volatile unsigned int	blendc;		/* Alpha Blend Control			*/
++/*248*/	volatile unsigned int	blendc1;	/* Alpha Blend Color 1			*/
++/*24c*/	volatile unsigned int	blendc2;	/* Alpha Blend Color 2			*/
++/*250*/	volatile unsigned int	fbramitc;	/* FB RAM Interleave Test Control	*/
++/*254*/	volatile unsigned int	fbc;		/* Frame Buffer Control			*/
++/*258*/	volatile unsigned int	rop;		/* Raster OPeration			*/
++/*25c*/	volatile unsigned int	cmp;		/* Frame Buffer Compare			*/
++/*260*/	volatile unsigned int	matchab;	/* Buffer AB Match Mask			*/
++/*264*/	volatile unsigned int	matchc;		/* Buffer C(YZ) Match Mask		*/
++/*268*/	volatile unsigned int	magnab;		/* Buffer AB Magnitude Mask		*/
++/*26c*/	volatile unsigned int	magnc;		/* Buffer C(YZ) Magnitude Mask		*/
++/*270*/	volatile unsigned int	fbcfg0;		/* Frame Buffer Config 0		*/
++/*274*/	volatile unsigned int	fbcfg1;		/* Frame Buffer Config 1		*/
++/*278*/	volatile unsigned int	fbcfg2;		/* Frame Buffer Config 2		*/
++/*27c*/	volatile unsigned int	fbcfg3;		/* Frame Buffer Config 3		*/
++/*280*/	volatile unsigned int	ppcfg;		/* Pixel Processor Config		*/
++/*284*/	volatile unsigned int	pick;		/* Picking Control			*/
++/*288*/	volatile unsigned int	fillmode;	/* FillMode				*/
++/*28c*/	volatile unsigned int	fbramwac;	/* FB RAM Write Address Control		*/
++/*290*/	volatile unsigned int	pmask;		/* RGB PlaneMask			*/
++/*294*/	volatile unsigned int	xpmask;		/* X PlaneMask				*/
++/*298*/	volatile unsigned int	ypmask;		/* Y PlaneMask				*/
++/*29c*/	volatile unsigned int	zpmask;		/* Z PlaneMask				*/
++/*2a0*/	ffb_auxclip		auxclip[4]; 	/* Auxilliary Viewport Clip		*/
++	
++	/* New 3dRAM III support regs */
++/*2c0*/	volatile unsigned int	rawblend2;
++/*2c4*/	volatile unsigned int	rawpreblend;
++/*2c8*/	volatile unsigned int	rawstencil;
++/*2cc*/	volatile unsigned int	rawstencilctl;
++/*2d0*/	volatile unsigned int	threedram1;
++/*2d4*/	volatile unsigned int	threedram2;
++/*2d8*/	volatile unsigned int	passin;
++/*2dc*/	volatile unsigned int	rawclrdepth;
++/*2e0*/	volatile unsigned int	rawpmask;
++/*2e4*/	volatile unsigned int	rawcsrc;
++/*2e8*/	volatile unsigned int	rawmatch;
++/*2ec*/	volatile unsigned int	rawmagn;
++/*2f0*/	volatile unsigned int	rawropblend;
++/*2f4*/	volatile unsigned int	rawcmp;
++/*2f8*/	volatile unsigned int	rawwac;
++/*2fc*/	volatile unsigned int	fbramid;
++	
++/*300*/	volatile unsigned int	drawop;		/* Draw OPeration			*/
++/*304*/	unsigned int		pad10[2];	/* Reserved				*/
++/*30c*/	volatile unsigned int	lpat;		/* Line Pattern control			*/
++/*310*/	unsigned int		pad11;		/* Reserved				*/
++/*314*/	volatile unsigned int	fontxy;		/* XY Font coordinate			*/
++/*318*/	volatile unsigned int	fontw;		/* Font Width				*/
++/*31c*/	volatile unsigned int	fontinc;	/* Font Increment			*/
++/*320*/	volatile unsigned int	font;		/* Font bits				*/
++/*324*/	unsigned int		pad12[3];	/* Reserved				*/
++/*330*/	volatile unsigned int	blend2;
++/*334*/	volatile unsigned int	preblend;
++/*338*/	volatile unsigned int	stencil;
++/*33c*/	volatile unsigned int	stencilctl;
++
++/*340*/	unsigned int		pad13[4];	/* Reserved				*/
++/*350*/	volatile unsigned int	dcss1;		/* Depth Cue Scale Slope 1		*/
++/*354*/	volatile unsigned int	dcss2;		/* Depth Cue Scale Slope 2		*/
++/*358*/	volatile unsigned int	dcss3;		/* Depth Cue Scale Slope 3		*/
++/*35c*/	volatile unsigned int	widpmask;
++/*360*/	volatile unsigned int	dcs2;
++/*364*/	volatile unsigned int	dcs3;
++/*368*/	volatile unsigned int	dcs4;
++/*36c*/	unsigned int		pad14;		/* Reserved				*/
++/*370*/	volatile unsigned int	dcd2;
++/*374*/	volatile unsigned int	dcd3;
++/*378*/	volatile unsigned int	dcd4;
++/*37c*/	unsigned int		pad15;		/* Reserved				*/
++/*380*/	volatile unsigned int	pattern[32];	/* area Pattern				*/
++/*400*/	unsigned int		pad16[8];	/* Reserved				*/
++/*420*/	volatile unsigned int	reset;		/* chip RESET				*/
++/*424*/	unsigned int		pad17[247];	/* Reserved				*/
++/*800*/	volatile unsigned int	devid;		/* Device ID				*/
++/*804*/	unsigned int		pad18[63];	/* Reserved				*/
++/*900*/	volatile unsigned int	ucsr;		/* User Control & Status Register	*/
++/*904*/	unsigned int		pad19[31];	/* Reserved				*/
++/*980*/	volatile unsigned int	mer;		/* Mode Enable Register			*/
++/*984*/	unsigned int		pad20[1439];	/* Reserved				*/
++} ffb_fbc, *ffb_fbcPtr;
++
++/* Draw operations */
++#define FFB_DRAWOP_DOT		0x00
++#define FFB_DRAWOP_AADOT	0x01
++#define FFB_DRAWOP_BRLINECAP	0x02
++#define FFB_DRAWOP_BRLINEOPEN	0x03
++#define FFB_DRAWOP_DDLINE	0x04
++#define FFB_DRAWOP_AALINE	0x05
++#define FFB_DRAWOP_TRIANGLE	0x06
++#define FFB_DRAWOP_POLYGON	0x07
++#define FFB_DRAWOP_RECTANGLE	0x08
++#define FFB_DRAWOP_FASTFILL	0x09
++#define FFB_DRAWOP_BCOPY	0x0a	/* Not implemented in any FFB, VIS is faster		*/
++#define FFB_DRAWOP_VSCROLL	0x0b	/* Up to 12x faster than BCOPY, 3-4x faster than VIS	*/
++
++/* FastFill operation codes. */
++#define FFB_FASTFILL_PAGE	0x01
++#define FFB_FASTFILL_BLOCK	0x02
++#define FFB_FASTFILL_COLOR_BLK	0x03
++#define FFB_FASTFILL_BLOCK_X	0x04
++
++/* Spanfill Unit Line Pattern */
++#define FFB_LPAT_SCALEPTR	0xf0000000
++#define FFB_LPAT_SCALEPTR_SHIFT	28
++#define FFB_LPAT_PATPTR		0x0f000000
++#define FFB_LPAT_PATPTR_SHIFT	24
++#define FFB_LPAT_SCALEVAL	0x00f00000
++#define FFB_LPAT_SCALEVAL_SHIFT	20
++#define FFB_LPAT_PATLEN		0x000f0000
++#define FFB_LPAT_PATLEN_SHIFT	16
++#define FFB_LPAT_PATTERN	0x0000ffff
++#define FFB_LPAT_PATTERN_SHIFT	0
++
++/* Pixel processor control */
++/* Force WID */
++#define FFB_PPC_FW_DISABLE	0x800000
++#define FFB_PPC_FW_ENABLE	0xc00000
++#define FFB_PPC_FW_MASK		0xc00000
++/* Auxiliary clip */
++#define FFB_PPC_ACE_DISABLE	0x040000
++#define FFB_PPC_ACE_AUX_SUB	0x080000
++#define FFB_PPC_ACE_AUX_ADD	0x0c0000
++#define FFB_PPC_ACE_MASK	0x0c0000
++/* Depth cue */
++#define FFB_PPC_DCE_DISABLE	0x020000
++#define FFB_PPC_DCE_ENABLE	0x030000
++#define FFB_PPC_DCE_MASK	0x030000
++/* Alpha blend */
++#define FFB_PPC_ABE_DISABLE	0x008000
++#define FFB_PPC_ABE_ENABLE	0x00c000
++#define FFB_PPC_ABE_MASK	0x00c000
++/* View clip */
++#define FFB_PPC_VCE_DISABLE	0x001000
++#define FFB_PPC_VCE_2D		0x002000
++#define FFB_PPC_VCE_3D		0x003000
++#define FFB_PPC_VCE_MASK	0x003000
++/* Area pattern */
++#define FFB_PPC_APE_DISABLE	0x000800
++#define FFB_PPC_APE_ENABLE	0x000c00
++#define FFB_PPC_APE_MASK	0x000c00
++/* Transparent background */
++#define FFB_PPC_TBE_OPAQUE	0x000200
++#define FFB_PPC_TBE_TRANSPARENT	0x000300
++#define FFB_PPC_TBE_MASK	0x000300
++/* Z source */
++#define FFB_PPC_ZS_VAR		0x000080
++#define FFB_PPC_ZS_CONST	0x0000c0
++#define FFB_PPC_ZS_MASK		0x0000c0
++/* Y source */
++#define FFB_PPC_YS_VAR		0x000020
++#define FFB_PPC_YS_CONST	0x000030
++#define FFB_PPC_YS_MASK		0x000030
++/* X source */
++#define FFB_PPC_XS_WID		0x000004
++#define FFB_PPC_XS_VAR		0x000008
++#define FFB_PPC_XS_CONST	0x00000c
++#define FFB_PPC_XS_MASK		0x00000c
++/* Color (BGR) source */
++#define FFB_PPC_CS_VAR		0x000002
++#define FFB_PPC_CS_CONST	0x000003
++#define FFB_PPC_CS_MASK		0x000003
++
++/* X Clip */
++#define FFB_XCLIP_XREF		0x000000ff
++#define FFB_XCLIP_TEST_MASK	0x00070000
++#define FFB_XCLIP_TEST_ALWAYS	0x00000000
++#define FFB_XCLIP_TEST_GT	0x00010000
++#define FFB_XCLIP_TEST_EQ	0x00020000
++#define FFB_XCLIP_TEST_GE	0x00030000
++#define FFB_XCLIP_TEST_NEVER	0x00040000
++#define FFB_XCLIP_TEST_LE	0x00050000
++#define FFB_XCLIP_TEST_NE	0x00060000
++#define FFB_XCLIP_TEST_LT	0x00070000
++
++/* FB Control register */
++/* Write buffer dest */
++#define FFB_FBC_WB_A		0x20000000
++#define FFB_FBC_WB_B		0x40000000
++#define FFB_FBC_WB_AB		0x60000000
++#define FFB_FBC_WB_C		0x80000000
++#define FFB_FBC_WB_AC		0xa0000000
++#define FFB_FBC_WB_BC		0xc0000000
++#define FFB_FBC_WB_ABC		0xe0000000
++#define FFB_FBC_WB_MASK		0xe0000000
++/* Write enable */
++#define FFB_FBC_WE_FORCEOFF	0x00100000
++#define FFB_FBC_WE_FORCEON	0x00200000
++#define FFB_FBC_WE_USE_WMASK	0x00300000
++#define FFB_FBC_WE_MASK		0x00300000
++/* Write group mode */
++#define FFB_FBC_WM_RSVD		0x00040000
++#define FFB_FBC_WM_COMBINED	0x00080000
++#define FFB_FBC_WM_SEPARATE	0x000c0000
++#define FFB_FBC_WM_MASK		0x000c0000
++/* Read buffer src */
++#define FFB_FBC_RB_A		0x00004000
++#define FFB_FBC_RB_B		0x00008000
++#define FFB_FBC_RB_C		0x0000c000
++#define FFB_FBC_RB_MASK		0x0000c000
++/* Stereo buf dest */
++#define FFB_FBC_SB_LEFT		0x00001000
++#define FFB_FBC_SB_RIGHT	0x00002000
++#define FFB_FBC_SB_BOTH		0x00003000
++#define FFB_FBC_SB_MASK		0x00003000
++/* Z plane group enable */
++#define FFB_FBC_ZE_OFF		0x00000400
++#define FFB_FBC_ZE_ON		0x00000800
++#define FFB_FBC_ZE_MASK		0x00000c00
++/* Y plane group enable */
++#define FFB_FBC_YE_OFF		0x00000100
++#define FFB_FBC_YE_ON		0x00000200
++#define FFB_FBC_YE_MASK		0x00000300
++/* X plane group enable */
++#define FFB_FBC_XE_OFF		0x00000040
++#define FFB_FBC_XE_ON		0x00000080
++#define FFB_FBC_XE_MASK		0x000000c0
++/* B plane group enable */
++#define FFB_FBC_BE_OFF		0x00000010
++#define FFB_FBC_BE_ON		0x00000020
++#define FFB_FBC_BE_MASK		0x00000030
++/* G plane group enable */
++#define FFB_FBC_GE_OFF		0x00000004
++#define FFB_FBC_GE_ON		0x00000008
++#define FFB_FBC_GE_MASK		0x0000000c
++/* R plane group enable */
++#define FFB_FBC_RE_OFF		0x00000001
++#define FFB_FBC_RE_ON		0x00000002
++#define FFB_FBC_RE_MASK		0x00000003
++/* Combined */
++#define FFB_FBC_RGBE_OFF	0x00000015
++#define FFB_FBC_RGBE_ON		0x0000002a
++#define FFB_FBC_RGBE_MASK	0x0000003f
++
++/* Raster OP */
++#define FFB_ROP_YZ_MASK		0x008f0000
++#define FFB_ROP_X_MASK		0x00008f00
++#define FFB_ROP_RGB_MASK	0x0000008f
++
++/* Now the rops themselves which get shifted into the
++ * above fields.
++ */
++#define FFB_ROP_EDIT_BIT	0x80
++#define FFB_ROP_ZERO		0x80
++#define FFB_ROP_NEW_AND_OLD	0x81
++#define FFB_ROP_NEW_AND_NOLD	0x82
++#define FFB_ROP_NEW		0x83
++#define FFB_ROP_NNEW_AND_OLD	0x84
++#define FFB_ROP_OLD		0x85
++#define FFB_ROP_NEW_XOR_OLD	0x86
++#define FFB_ROP_NEW_OR_OLD	0x87
++#define FFB_ROP_NNEW_AND_NOLD	0x88
++#define FFB_ROP_NNEW_XOR_NOLD	0x89
++#define FFB_ROP_NOLD		0x8a
++#define FFB_ROP_NEW_OR_NOLD	0x8b
++#define FFB_ROP_NNEW		0x8c
++#define FFB_ROP_NNEW_OR_OLD	0x8d
++#define FFB_ROP_NNEW_OR_NOLD	0x8e
++#define FFB_ROP_ONES		0x8f
++
++/* FB Compare */
++#define FFB_CMP_MATCHC_MASK	0x8f000000
++#define FFB_CMP_MAGNC_MASK	0x00870000
++#define FFB_CMP_MATCHAB_MASK	0x0000ff00
++#define FFB_CMP_MAGNAB_MASK	0x000000ff
++
++/* Compare Match codes */
++#define FFB_CMP_MATCH_EDIT_BIT	0x80
++#define FFB_CMP_MATCH_ALWAYS	0x80
++#define FFB_CMP_MATCH_NEVER	0x81
++#define FFB_CMP_MATCH_EQ	0x82
++#define FFB_CMP_MATCH_NE	0x83
++#define FFB_CMP_MATCH_A_ALWAYS	0xc0
++#define FFB_CMP_MATCH_B_ALWAYS	0xa0
++
++/* Compare Magnitude codes */
++#define FFB_CMP_MAGN_EDIT_BIT	0x80
++#define FFB_CMP_MAGN_ALWAYS	0x80
++#define FFB_CMP_MAGN_GT		0x81
++#define FFB_CMP_MAGN_EQ		0x82
++#define FFB_CMP_MAGN_GE		0x83
++#define FFB_CMP_MAGN_NEVER	0x84
++#define FFB_CMP_MAGN_LE		0x85
++#define FFB_CMP_MAGN_NE		0x86
++#define FFB_CMP_MAGN_LT		0x87
++#define FFB_CMP_MAGN_A_ALWAYS	0xc0
++#define FFB_CMP_MAGN_B_ALWAYS	0xa0
++
++/* User Control and Status */
++#define FFB_UCSR_FIFO_MASK	0x00000fff
++#define FFB_UCSR_PICK_NO_HIT	0x00020000
++#define FFB_UCSR_PICK_HIT	0x00030000
++#define FFB_UCSR_PICK_DISABLE	0x00080000
++#define FFB_UCSR_PICK_ENABLE	0x000c0000
++#define FFB_UCSR_FB_BUSY	0x01000000
++#define FFB_UCSR_RP_BUSY	0x02000000
++#define FFB_UCSR_ALL_BUSY	(FFB_UCSR_RP_BUSY|FFB_UCSR_FB_BUSY)
++#define FFB_UCSR_READ_ERR	0x40000000
++#define FFB_UCSR_FIFO_OVFL	0x80000000
++#define FFB_UCSR_ALL_ERRORS	(FFB_UCSR_READ_ERR|FFB_UCSR_FIFO_OVFL)
++
++/* Mode Enable Register */
++#define FFB_MER_EIRA		0x00000080 /* Enable read-ahead, increasing */
++#define FFB_MER_EDRA		0x000000c0 /* Enable read-ahead, decreasing */
++#define FFB_MER_DRA		0x00000040 /* No read-ahead */
++
++/* FBram Config 0 */
++#define FFB_FBCFG0_RFTIME	0xff800000
++#define FFB_FBCFG0_XMAX		0x007c0000
++#define FFB_FBCFG0_YMAX		0x0003ffc0
++#define FFB_FBCFG0_RES_MASK	0x00000030
++#define FFB_FBCFG0_RES_HIGH	0x00000030 /* 1920x1360 */
++#define FFB_FBCFG0_RES_STD	0x00000020 /* 1280x1024 */
++#define FFB_FBCFG0_RES_STEREO	0x00000010 /* 960x580 */
++#define FFB_FBCFG0_RES_PRTRAIT	0x00000000 /* 1280x2048 */
++#define FFB_FBCFG0_ITRLACE	0x00000000
++#define FFB_FBCFG0_SEQUENTIAL	0x00000008
++#define FFB_FBCFG0_DRENA	0x00000004
++#define FFB_FBCFG0_BPMODE	0x00000002
++#define FFB_FBCFG0_RFRSH_RST	0x00000001
++
++#if 0
++/* XXX We don't use this right now... -DaveM */
++typedef struct _ffb_dac {
++	volatile unsigned int	cfg;
++	volatile unsigned int	cfgdata;
++	volatile unsigned int	cur;
++	volatile unsigned int	curdata;
++} ffb_dac, *ffb_dacPtr;
++#endif
++
++/* Writing 2 32-bit registers at a time using 64-bit stores. -DaveM */
++#if defined(__GNUC__) && defined(USE_VIS)
++/* 64-bit register writing support.
++ * Note: "lo" means "low address".
++ */
++#define FFB_WRITE64_COMMON(__regp, __lo32, __hi32, REG0, REG1) \
++do {	__extension__ register unsigned int __r0 __asm__(""#REG0); \
++	__extension__ register unsigned int __r1 __asm__(""#REG1); \
++	__r0 = (__lo32); \
++	__r1 = (__hi32); \
++	__asm__ __volatile__ ("sllx\t%0, 32, %%g1\n\t" \
++			      "srl\t%1, 0, %1\n\t" \
++			      "or\t%%g1, %1, %%g1\n\t" \
++			      "stx\t%%g1, %2" \
++	 : : "r" (__r0), "r" (__r1), "m" (*(__regp)) : "g1"); \
++} while(0)
++
++#define FFB_WRITE64P(__regp, __srcp) \
++do {	__asm__ __volatile__ ("ldx\t%0, %%g2;" \
++			      "stx\t%%g2, %1" \
++	 : : "m" (*(__srcp)), "m" (*(__regp)) \
++         : "g2"); \
++} while(0)			      
++
++#define FFB_WRITE64(__regp, __lo32, __hi32) \
++	FFB_WRITE64_COMMON(__regp, __lo32, __hi32, g2, g3)
++#define FFB_WRITE64_2(__regp, __lo32, __hi32) \
++	FFB_WRITE64_COMMON(__regp, __lo32, __hi32, g4, g5)
++#define FFB_WRITE64_3(__regp, __lo32, __hi32) \
++	FFB_WRITE64_COMMON(__regp, __lo32, __hi32, o4, o5)
++
++#else /* Do not use 64-bit writes. */
++
++#define FFB_WRITE64(__regp, __lo32, __hi32) \
++do {	volatile unsigned int *__p = (__regp); \
++	*__p = (__lo32); \
++	*(__p + 1) = (__hi32); \
++} while(0)
++
++#define FFB_WRITE64P(__regp, __srcp) \
++do {	volatile unsigned int *__p = (__regp); \
++	unsigned int *__q = (__srcp); \
++	*__p = *__q; \
++	*(__p + 1) = *(__q + 1); \
++} while(0)
++
++#define FFB_WRITE64_2(__regp, __lo32, __hi32) \
++	FFB_WRITE64(__regp, __lo32, __hi32)
++#define FFB_WRITE64_3(__regp, __lo32, __hi32) \
++	FFB_WRITE64(__regp, __lo32, __hi32)
++#endif
++
++#endif /* FFBREGS_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBseg.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBseg.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,177 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Segment rops.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "mi/miline.h"
++
++#undef DEBUG_LINES
++
++/* The general strategy is to do the drawing completely in hardware
++ * iff:
++ * 1) Single region rect
++ * 2) Both ends of the segment lie within it
++ */
++#define SEG_DRAWOP(__pgc) ((__pgc)->capStyle == CapNotLast ? \
++			   FFB_DRAWOP_BRLINEOPEN : \
++			   FFB_DRAWOP_BRLINECAP)
++static void
++ReloadSegmentAttrs(CreatorPrivScreenPtr ffbPriv, CreatorPrivGCPtr gcPriv, GCPtr pGC)
++{
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     (FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|
++				      FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST),
++				     (FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|
++				      FFB_PPC_APE_MASK|FFB_PPC_CS_MASK),
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT | pGC->alu,
++				     SEG_DRAWOP(pGC),
++				     pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		ffb_fbcPtr ffb = ffbPriv->regs;
++
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, SEG_DRAWOP(pGC));
++	}
++}
++
++void
++CreatorPolySegment (DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment *pSeg)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	BoxPtr extent;
++	int xorg, yorg, lpat;
++
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->PolySegment)(pDrawable, pGC, nseg, pSeg);
++		return;
++	}
++#endif
++	if(nseg == 0)
++		return;
++	FFBLOG("CreatorPolySegment: ALU(%x) PMSK(%08x) nseg(%d) lpat(%08x)\n",
++	       pGC->alu, pGC->planemask, nseg, gcPriv->linepat);
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
++				     FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT | pGC->alu,
++				     SEG_DRAWOP(pGC),
++				     pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_CS_CONST,
++			      FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, SEG_DRAWOP(pGC));
++	}
++
++	ffbPriv->rp_active = 1;
++	xorg = pDrawable->x;
++	yorg = pDrawable->y;
++	extent = REGION_RECTS(cfbGetCompositeClip(pGC));
++	lpat = gcPriv->linepat;
++	if (lpat == 0) {
++		FFBFifo(ffbPriv, 1);
++		ffb->lpat = 0;
++		while(nseg--) {
++			register int x1 = pSeg->x1 + xorg;
++			register int y1 = pSeg->y1 + yorg;
++			register int x2 = pSeg->x2 + xorg;
++			register int y2 = pSeg->y2 + yorg;
++
++			if (x1 >= extent->x1	&&	x2 >= extent->x1	&&
++			    x1 < extent->x2	&&	x2 < extent->x2		&&
++			    y1 >= extent->y1	&&	y2 >= extent->y1	&&
++			    y1 < extent->y2	&&	y2 < extent->y2) {
++				if (ffbPriv->has_brline_bug) {
++					FFBFifo(ffbPriv, 5);
++					ffb->ppc = 0;
++					FFB_WRITE64(&ffb->by, y1, x1);
++					FFB_WRITE64_2(&ffb->bh, y2, x2);
++				} else {
++					FFBFifo(ffbPriv, 4);
++					FFB_WRITE64(&ffb->by, y1, x1);
++					FFB_WRITE64_2(&ffb->bh, y2, x2);
++				}
++			} else {
++				gcPriv->PolySegment(pDrawable, pGC, 1, pSeg);
++				ReloadSegmentAttrs(ffbPriv, gcPriv, pGC);
++				ffbPriv->rp_active = 1;
++			}
++			pSeg++;
++		}
++	} else {
++		while(nseg--) {
++			register int x1 = pSeg->x1 + xorg;
++			register int y1 = pSeg->y1 + yorg;
++			register int x2 = pSeg->x2 + xorg;
++			register int y2 = pSeg->y2 + yorg;
++
++			if (x1 >= extent->x1	&&	x2 >= extent->x1	&&
++			    x1 < extent->x2	&&	x2 < extent->x2		&&
++			    y1 >= extent->y1	&&	y2 >= extent->y1	&&
++			    y1 < extent->y2	&&	y2 < extent->y2) {
++				FFBFifo(ffbPriv, 5);
++				ffb->lpat = lpat;
++				FFB_WRITE64(&ffb->by, y1, x1);
++				FFB_WRITE64_2(&ffb->bh, y2, x2);
++			} else {
++				gcPriv->PolySegment(pDrawable, pGC, 1, pSeg);
++				ReloadSegmentAttrs(ffbPriv, gcPriv, pGC);
++				ffbPriv->rp_active = 1;
++			}
++			pSeg++;
++		}
++	}
++
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBstip.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBstip.c	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,61 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - stipple setting.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBstip.h"
++
++void
++FFBSetStipple(CreatorPrivScreenPtr ffbPriv, ffb_fbcPtr ffb,
++	      CreatorStipplePtr stipple,
++	      unsigned int ppc, unsigned int ppc_mask)
++{
++	int transparent = ((stipple->alu & FFB_ROP_EDIT_BIT) != 0);
++
++	if(transparent)
++		ppc |= FFB_PPC_APE_ENABLE|FFB_PPC_TBE_TRANSPARENT;
++	else
++		ppc |= FFB_PPC_APE_ENABLE|FFB_PPC_TBE_OPAQUE;
++	ppc_mask |= FFB_PPC_APE_MASK|FFB_PPC_TBE_MASK;
++	FFB_WRITE_PPC(ffbPriv, ffb, ppc, ppc_mask);
++	FFB_WRITE_ROP(ffbPriv, ffb, FFB_ROP_EDIT_BIT|stipple->alu);
++
++	if (stipple->inhw && ffbPriv->laststipple == stipple) {
++		FFB_WRITE_FG(ffbPriv, ffb, stipple->fg);
++		if(!transparent)
++			FFB_WRITE_BG(ffbPriv, ffb, stipple->bg);
++		return;
++	}
++	FFBFifo(ffbPriv, 32);
++	FFB_STIPPLE_LOAD(&ffb->pattern[0], &stipple->bits[0]);
++	FFB_WRITE_FG(ffbPriv, ffb, stipple->fg);
++	if(!transparent)
++		FFB_WRITE_BG(ffbPriv, ffb, stipple->bg);
++	stipple->inhw = 1;
++	ffbPriv->laststipple = stipple;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBstip.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBstip.h	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,35 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - stipple defines.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFBSTIP_H
++#define FFBSTIP_H
++
++extern void FFBSetStipple(CreatorPrivScreenPtr ffbPriv,
++			  ffb_fbcPtr ffb,
++			  CreatorStipplePtr stipple,
++			  unsigned int ppc, unsigned int ppc_mask);
++
++#endif /* FFBSTIP_H */
+--- xc/programs/Xserver/hw/sun/FFB/FFBstubs.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBstubs.c	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,385 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Unaccelerated stuff.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek   (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
++ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++/* Sorry, have to expose some CFB internals to get the stubs right. -DaveM */
++struct cfb_gcstate {
++	unsigned long pmask;
++	int alu, rop, and, xor;
++};
++
++#define CFB_STATE_SAVE(__statep, __gcp, __privp) \
++do {	(__statep)->pmask = (__gcp)->planemask; \
++	(__statep)->alu = (__gcp)->alu; \
++	(__statep)->rop = (__privp)->rop; \
++	(__statep)->and = (__privp)->and; \
++	(__statep)->xor = (__privp)->xor; \
++} while(0)
++
++#define CFB_STATE_RESTORE(__statep, __gcp, __privp) \
++do {	(__gcp)->planemask = (__statep)->pmask; \
++	(__gcp)->alu = (__statep)->alu; \
++	(__privp)->rop = (__statep)->rop; \
++	(__privp)->and = (__statep)->and; \
++	(__privp)->xor = (__statep)->xor; \
++} while(0)
++
++#define CFB_STATE_SET_SFB(__gcp, __privp) \
++do {	(__gcp)->alu = GXcopy; \
++	(__gcp)->planemask = PMSK; \
++	(__privp)->rop = GXcopy; \
++	(__privp)->and = 0; \
++	(__privp)->xor = (__gcp)->fgPixel; \
++} while(0)
++
++/* Stubs so we can wait for the raster processor to
++ * unbusy itself before we let the cfb code write
++ * directly to the framebuffer.
++ */
++void
++CreatorSolidSpansGeneralStub (DrawablePtr pDrawable, GCPtr pGC,
++			      int nInit, DDXPointPtr pptInit,
++			      int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	if (!VT_HIDDEN(pDrawable->pScreen)) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, 0xffffffff, pGC->alu);
++		FFBWait(ffbPriv, ffb);
++		cfbSolidSpansCopy(pDrawable, pGC, nInit, pptInit,
++				  pwidthInit, fSorted);
++		return;
++	}
++	cfbSolidSpansGeneral(pDrawable, pGC, nInit, pptInit,
++			     pwidthInit, fSorted);
++}
++
++void
++CreatorSegmentSSStub (DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment *pSeg)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbSegmentSS(pDrawable, pGC, nseg, pSeg);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorLineSSStub (DrawablePtr pDrawable, GCPtr pGC,
++		   int mode, int npt, DDXPointPtr ppt)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbLineSS(pDrawable, pGC, mode, npt, ppt);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorSegmentSDStub (DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment *pSeg)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbSegmentSD(pDrawable, pGC, nseg, pSeg);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorLineSDStub (DrawablePtr pDrawable, GCPtr pGC,
++		   int mode, int npt, DDXPointPtr ppt)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbLineSD(pDrawable, pGC, mode, npt, ppt);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorPolyGlyphBlt8Stub (DrawablePtr pDrawable, GCPtr pGC,
++			  int x, int y, unsigned int nglyph, CharInfoPtr *ppci,
++			  pointer pglyphBase)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbPolyGlyphBlt8(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorImageGlyphBlt8Stub (DrawablePtr pDrawable, GCPtr pGC,
++			   int x, int y, unsigned int nglyph,
++			   CharInfoPtr *ppci, pointer pglyphBase)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbImageGlyphBlt8(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorTile32FSCopyStub(DrawablePtr pDrawable, GCPtr pGC,
++			int nInit, DDXPointPtr pptInit,
++			int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbTile32FSCopy(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorTile32FSGeneralStub(DrawablePtr pDrawable, GCPtr pGC,
++			   int nInit, DDXPointPtr pptInit,
++			   int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbTile32FSGeneral(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorUnnaturalTileFSStub(DrawablePtr pDrawable, GCPtr pGC,
++			   int nInit, DDXPointPtr pptInit,
++			   int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++Creator8Stipple32FSStub(DrawablePtr pDrawable, GCPtr pGC,
++			int nInit, DDXPointPtr pptInit,
++			int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!VT_HIDDEN(pDrawable->pScreen)) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfb8Stipple32FS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorUnnaturalStippleFSStub(DrawablePtr pDrawable, GCPtr pGC,
++			      int nInit, DDXPointPtr pptInit,
++			      int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++Creator8OpaqueStipple32FSStub(DrawablePtr pDrawable, GCPtr pGC,
++			      int nInit, DDXPointPtr pptInit,
++			      int *pwidthInit, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfb8OpaqueStipple32FS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
++
++void
++CreatorPolyFillRectStub(DrawablePtr pDrawable, GCPtr pGC,
++			int nrectFill, xRectangle *prectInit)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int vt_hidden = VT_HIDDEN(pDrawable->pScreen);
++	struct cfb_gcstate cfb_state;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++
++	FFBLOG("STUB(%s:%d)\n", __FILE__, __LINE__);
++	CFB_STATE_SAVE(&cfb_state, pGC, devPriv);
++	if (!vt_hidden) {
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, cfb_state.pmask, cfb_state.alu);
++		FFBWait(ffbPriv, ffb);
++		CFB_STATE_SET_SFB(pGC, devPriv);
++	}
++	cfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit);
++	if(!vt_hidden)
++		CFB_STATE_RESTORE(&cfb_state, pGC, devPriv);
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBwline.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBwline.c	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,901 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Wide line rops.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include <math.h>
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++#include "miwideline.h"
++
++/* Wheee, wide lines... */
++extern int miPolyBuildEdge();
++
++static int LeftClip, RightClip, TopClip, BottomClip;
++
++#define Y_IN_BOX(y)	(((y) >= TopClip) && ((y) <= BottomClip))
++#define CLIPSTEPEDGE(edgey,edge,edgeleft)	\
++if (ybase == edgey) {				\
++	if (edgeleft) {				\
++		if (edge->x > xcl)		\
++			xcl = edge->x;		\
++	} else {				\
++		if (edge->x < xcr)		\
++			xcr = edge->x;		\
++	}					\
++	edgey++;				\
++	edge->x += edge->stepx;			\
++	edge->e += edge->dx;			\
++	if (edge->e > 0) {			\
++		edge->x += edge->signdx;	\
++		edge->e -= edge->dy;		\
++	}					\
++}
++
++#define CreatorPointHelper(ffbPriv, x, y)			\
++do {								\
++	ffb_fbcPtr ffb = (ffbPriv)->regs;			\
++	FFB_WRITE_DRAWOP((ffbPriv), ffb, FFB_DRAWOP_DOT);	\
++	FFBFifo(ffbPriv, 2);					\
++	FFB_WRITE64(&ffb->bh, (y), (x));			\
++} while (0)
++
++static void CreatorFillRectHelper(CreatorPrivScreenPtr ffbPriv,
++				  int x, int y, int dx, int dy)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int x2 = x + dx - 1;
++	int y2 = y + dy - 1;
++	
++	if(x < LeftClip)
++		x = LeftClip;
++	if(x2 > RightClip)
++		x2 = RightClip;
++	if(y < TopClip)
++		y = TopClip;
++	if(y2 > BottomClip)
++		y2 = BottomClip;
++
++	dx = x2 - x + 1;
++	dy = y2 - y + 1;
++
++	if((dx > 0) && (dy > 0)) {
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++		FFBFifo(ffbPriv, 4);
++		FFB_WRITE64(&ffb->by, y, x);
++		FFB_WRITE64_2(&ffb->bh, dy, dx);
++	}
++}
++
++/* The span helper does not check for y being clipped, caller beware */
++static void CreatorSpanHelper(CreatorPrivScreenPtr ffbPriv,
++			      int x1, int y, int width)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	int x2 = x1 + width - 1;
++
++	if(x1 < LeftClip)
++		x1 = LeftClip;
++	if(x2 > RightClip)
++		x2 = RightClip;
++	width = x2 - x1 + 1;	
++
++	if(width > 0) {
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++		FFBFifo(ffbPriv, 4);
++		FFB_WRITE64(&ffb->by, y, x1);
++		FFB_WRITE64_2(&ffb->bh, 1, width);
++	}
++}
++
++#define FixError(x, dx, dy, e, sign, step, h)	{	\
++	e += (h) * dx;					\
++	x += (h) * step;				\
++	if(e > 0) {					\
++		x += e * sign/dy;			\
++		e %= dy;				\
++		if(e) {					\
++			x += sign;			\
++			e -= dy;			\
++		}					\
++	} 	 					\
++}
++
++static void
++CreatorFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC,
++		       int y, int overall_height,
++		       PolyEdgePtr left, PolyEdgePtr right, 
++		       int left_count, int right_count)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	int left_x, left_e, left_stepx, left_signdx, left_dy, left_dx;
++	int right_x, right_e, right_stepx, right_signdx, right_dy, right_dx, height;
++	int left_height = 0;
++	int right_height = 0;
++	int xorg = 0;
++    
++	if (pGC->miTranslate) {
++		y += pDrawable->y;
++		xorg = pDrawable->x;
++	}
++
++	while ((left_count || left_height) && (right_count || right_height)) {
++		if (!left_height && left_count) { 
++			left_height = left->height; 
++			left_x = left->x + xorg; 
++			left_stepx = left->stepx; 
++			left_signdx = left->signdx; 
++			left_e = left->e; 
++			left_dy = left->dy; 
++			left_dx = left->dx; 
++			left_count--; 
++			left++;
++		}
++		if (!right_height && right_count) { 
++			right_height = right->height; 
++			right_x = right->x + xorg + 1; 
++			right_stepx = right->stepx; 
++			right_signdx = right->signdx; 
++			right_e = right->e; 
++			right_dy = right->dy; 
++			right_dx = right->dx; 
++			right_count--; 
++			right++; 
++		}
++
++		height = (left_height > right_height) ? right_height : left_height;
++
++		left_height -= height;
++		right_height -= height;
++		while (height--) {
++			if((right_x > left_x) && Y_IN_BOX(y))
++				CreatorSpanHelper(ffbPriv, left_x, y, right_x - left_x);
++
++			y++;
++    	
++			left_x += left_stepx; 
++			left_e += left_dx; 
++			if (left_e > 0) { 
++				left_x += left_signdx; 
++				left_e -= left_dy; 
++			}
++			right_x += right_stepx; 
++			right_e += right_dx; 
++			if (right_e > 0) { 
++				right_x += right_signdx; 
++				right_e -= right_dy; 
++			}
++		}
++	}
++}
++
++static void
++CreatorWideSegment (DrawablePtr pDrawable, GCPtr pGC,
++		    int x1, int y1, int x2, int y2, 
++		    Bool projectLeft, Bool projectRight,
++		    LineFacePtr leftFace, LineFacePtr rightFace)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	double l, L, r, xa, ya, projectXoff, projectYoff, k, maxy;
++	int x, y, dx, dy, finaly, lefty, righty, topy, bottomy, signdx;
++	PolyEdgePtr left, right, top, bottom;
++	PolyEdgeRec lefts[2], rights[2];
++	LineFacePtr tface;
++	int lw = pGC->lineWidth;
++
++	/* draw top-to-bottom always */
++	if (y2 < y1 || y2 == y1 && x2 < x1) {
++		x = x1;
++		x1 = x2;
++		x2 = x;
++
++		y = y1;
++		y1 = y2;
++		y2 = y;
++
++		x = projectLeft;
++		projectLeft = projectRight;
++		projectRight = x;
++
++		tface = leftFace;
++		leftFace = rightFace;
++		rightFace = tface;
++	}
++
++	dy = y2 - y1;
++	signdx = 1;
++	dx = x2 - x1;
++	if (dx < 0)
++		signdx = -1;
++
++	leftFace->x = x1;
++	leftFace->y = y1;
++	leftFace->dx = dx;
++	leftFace->dy = dy;
++
++	rightFace->x = x2;
++	rightFace->y = y2;
++	rightFace->dx = -dx;
++	rightFace->dy = -dy;
++
++	if (!dy) {
++		rightFace->xa = 0;
++		rightFace->ya = (double) lw / 2.0;
++		rightFace->k = -(double) (lw * dx) / 2.0;
++		leftFace->xa = 0;
++		leftFace->ya = -rightFace->ya;
++		leftFace->k = rightFace->k;
++		x = x1;
++		if (projectLeft)
++			x -= (lw >> 1);
++		y = y1 - (lw >> 1);
++		dx = x2 - x;
++		if (projectRight)
++			dx += (lw + 1 >> 1);
++		dy = lw;
++		if(pGC->miTranslate) {
++			x += pDrawable->x;
++			y += pDrawable->y;
++		}
++		CreatorFillRectHelper(ffbPriv, x, y, dx, dy);	
++	} else if (!dx) {
++		leftFace->xa =  (double) lw / 2.0;
++		leftFace->ya = 0;
++		leftFace->k = (double) (lw * dy) / 2.0;
++		rightFace->xa = -leftFace->xa;
++		rightFace->ya = 0;
++		rightFace->k = leftFace->k;
++		y = y1;
++		if (projectLeft)
++			y -= lw >> 1;
++		x = x1 - (lw >> 1);
++		dy = y2 - y;
++		if (projectRight)
++			dy += (lw + 1 >> 1);
++		dx = lw;
++		if(pGC->miTranslate) {
++			x += pDrawable->x;
++			y += pDrawable->y;
++		}
++		CreatorFillRectHelper(ffbPriv, x, y, dx, dy);
++	} else {
++		l = ((double) lw) / 2.0;
++		L = sqrt((double)(dx*dx + dy*dy));
++
++		if (dx < 0) {
++			right = &rights[1];
++			left = &lefts[0];
++			top = &rights[0];
++			bottom = &lefts[1];
++		} else {
++			right = &rights[0];
++			left = &lefts[1];
++			top = &lefts[0];
++			bottom = &rights[1];
++		}
++		r = l / L;
++
++		/* coord of upper bound at integral y */
++		ya = -r * dx;
++		xa = r * dy;
++
++		if (projectLeft | projectRight) {
++			projectXoff = -ya;
++			projectYoff = xa;
++		}
++
++		/* xa * dy - ya * dx */
++		k = l * L;
++
++		leftFace->xa = xa;
++		leftFace->ya = ya;
++		leftFace->k = k;
++		rightFace->xa = -xa;
++		rightFace->ya = -ya;
++		rightFace->k = k;
++
++		if (projectLeft)
++			righty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
++						  k, dx, dy, x1, y1, 0, right);
++		else
++			righty = miPolyBuildEdge (xa, ya,
++						  k, dx, dy, x1, y1, 0, right);
++
++		/* coord of lower bound at integral y */
++		ya = -ya;
++		xa = -xa;
++
++		/* xa * dy - ya * dx */
++		k = - k;
++
++		if (projectLeft)
++			lefty = miPolyBuildEdge (xa - projectXoff, ya - projectYoff,
++						 k, dx, dy, x1, y1, 1, left);
++		else
++			lefty = miPolyBuildEdge (xa, ya,
++						 k, dx, dy, x1, y1, 1, left);
++
++		/* coord of top face at integral y */
++		if (signdx > 0) {
++			ya = -ya;
++			xa = -xa;
++		}
++
++		if (projectLeft) {
++			double xap = xa - projectXoff;
++			double yap = ya - projectYoff;
++			topy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
++						-dy, dx, x1, y1, dx > 0, top);
++		}
++		else
++			topy = miPolyBuildEdge(xa, ya, 0.0, 
++					       -dy, dx, x1, y1, dx > 0, top);
++
++		/* coord of bottom face at integral y */
++		if (projectRight) {
++			double xap = xa + projectXoff;
++			double yap = ya + projectYoff;
++			bottomy = miPolyBuildEdge (xap, yap, xap * dx + yap * dy,
++						   -dy, dx, x2, y2, dx < 0, bottom);
++			maxy = -ya + projectYoff;
++		} else {
++			bottomy = miPolyBuildEdge (xa, ya, 0.0,
++						   -dy, dx, x2, y2, dx < 0, bottom);
++			maxy = -ya;
++		}
++
++		finaly = ICEIL (maxy) + y2;
++
++		if (dx < 0) {
++			left->height = bottomy - lefty;
++			right->height = finaly - righty;
++			top->height = righty - topy;
++		} else {
++			right->height =  bottomy - righty;
++			left->height = finaly - lefty;
++			top->height = lefty - topy;
++		}
++		bottom->height = finaly - bottomy;
++		CreatorFillPolyHelper (pDrawable, pGC, topy, 
++				       bottom->height + bottomy - topy, lefts, rights, 2, 2);
++	}
++}
++
++static void
++CreatorLineArcI (DrawablePtr pDraw, GCPtr pGC, int xorg, int yorg)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDraw->pScreen);
++	int x, y, e, ex, slw;
++
++	if (pGC->miTranslate) {
++		xorg += pDraw->x;
++		yorg += pDraw->y;
++	}
++
++	slw = pGC->lineWidth;
++	if (slw == 1) {
++		CreatorPointHelper(ffbPriv, xorg, yorg);
++		return;
++	}
++
++	y = (slw >> 1) + 1;
++	if (slw & 1)
++		e = - ((y << 2) + 3);
++	else
++		e = - (y << 3);
++	ex = -4;
++	x = 0;
++	while (y) {
++		e += (y << 3) - 4;
++		while (e >= 0) {
++			x++;
++			e += (ex = -((x << 3) + 4));
++		}
++		y--;
++		slw = (x << 1) + 1;
++		if ((e == ex) && (slw > 1))
++			slw--;
++	    
++		if(Y_IN_BOX(yorg - y))
++			CreatorSpanHelper(ffbPriv, xorg - x, yorg - y, slw);
++
++		if ((y != 0) && ((slw > 1) || (e != ex)) && Y_IN_BOX(yorg + y))	
++			CreatorSpanHelper(ffbPriv, xorg - x, yorg + y, slw);
++	}
++}
++
++static void
++CreatorLineArcD (DrawablePtr pDraw, GCPtr pGC,
++		 double xorg, double yorg,
++		 PolyEdgePtr edge1, int edgey1, Bool edgeleft1,
++		 PolyEdgePtr edge2, int edgey2, Bool edgeleft2)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDraw->pScreen);
++	double radius, x0, y0, el, er, yk, xlk, xrk, k;
++	int xbase, ybase, y, boty, xl, xr, xcl, xcr, ymin, ymax, ymin1, ymin2;
++	Bool edge1IsMin, edge2IsMin;
++
++	xbase = floor(xorg);
++	x0 = xorg - xbase;
++	ybase = ICEIL (yorg);
++	y0 = yorg - ybase;
++	if (pGC->miTranslate) {
++		xbase += pDraw->x;
++		ybase += pDraw->y;
++		edge1->x += pDraw->x;
++		edge2->x += pDraw->x;
++		edgey1 += pDraw->y;
++		edgey2 += pDraw->y;
++	}
++
++	xlk = x0 + x0 + 1.0;
++	xrk = x0 + x0 - 1.0;
++	yk = y0 + y0 - 1.0;
++	radius = ((double)pGC->lineWidth) / 2.0;
++	y = floor(radius - y0 + 1.0);
++	ybase -= y;
++	ymin = ybase;
++	ymax = 65536;
++	edge1IsMin = FALSE;
++	ymin1 = edgey1;
++	if (edge1->dy >= 0) {
++		if (!edge1->dy) {
++			if (edgeleft1)
++				edge1IsMin = TRUE;
++			else
++				ymax = edgey1;
++			edgey1 = 65536;
++		} else if ((edge1->signdx < 0) == edgeleft1)
++			edge1IsMin = TRUE;
++	}
++	edge2IsMin = FALSE;
++	ymin2 = edgey2;
++	if (edge2->dy >= 0) {
++		if (!edge2->dy) {
++			if (edgeleft2)
++				edge2IsMin = TRUE;
++			else
++				ymax = edgey2;
++			edgey2 = 65536;
++		} else if ((edge2->signdx < 0) == edgeleft2)
++			edge2IsMin = TRUE;
++	}
++	if (edge1IsMin) {
++		ymin = ymin1;
++		if (edge2IsMin && (ymin1 > ymin2))
++			ymin = ymin2;
++	} else if (edge2IsMin)
++		ymin = ymin2;
++	el = radius * radius - ((y + y0) * (y + y0)) - (x0 * x0);
++	er = el + xrk;
++	xl = 1;
++	xr = 0;
++	if (x0 < 0.5) {
++		xl = 0;
++		el -= xlk;
++	}
++	boty = (y0 < -0.5) ? 1 : 0;
++	if (ybase + y - boty > ymax)
++		boty = ymax - ybase - y;
++	while (y > boty) {
++		k = (y << 1) + yk;
++		er += k;
++		while (er > 0.0) {
++			xr++;
++			er += xrk - (xr << 1);
++		}
++		el += k;
++		while (el >= 0.0) {
++			xl--;
++			el += (xl << 1) - xlk;
++		}
++		y--;
++		ybase++;
++		if (ybase < ymin)
++			continue;
++		xcl = xl + xbase;
++		xcr = xr + xbase;
++		CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
++		CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
++		if((xcr >= xcl) && Y_IN_BOX(ybase)) 
++			CreatorSpanHelper(ffbPriv, xcl, ybase, xcr - xcl + 1);
++	}
++	er = xrk - (xr << 1) - er;
++	el = (xl << 1) - xlk - el;
++	boty = floor(-y0 - radius + 1.0);
++	if (ybase + y - boty > ymax)
++		boty = ymax - ybase - y;
++	while (y > boty) {
++		k = (y << 1) + yk;
++		er -= k;
++		while ((er >= 0.0) && (xr >= 0)) {
++			xr--;
++			er += xrk - (xr << 1);
++		}
++		el -= k;
++		while ((el > 0.0) && (xl <= 0)) {
++			xl++;
++			el += (xl << 1) - xlk;
++		}
++		y--;
++		ybase++;
++		if (ybase < ymin)
++			continue;
++		xcl = xl + xbase;
++		xcr = xr + xbase;
++		CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
++		CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
++		if((xcr >= xcl) && Y_IN_BOX(ybase)) 
++			CreatorSpanHelper(ffbPriv, xcl, ybase, xcr - xcl + 1);
++	}
++}
++
++
++static void
++CreatorLineArc (DrawablePtr pDraw, GCPtr pGC,
++		LineFacePtr leftFace, LineFacePtr rightFace,
++		double xorg, double yorg,
++		Bool isInt)
++{
++	int xorgi, yorgi, edgey1, edgey2;
++	PolyEdgeRec	edge1, edge2;
++	Bool edgeleft1, edgeleft2;
++
++	if (isInt) {
++		xorgi = leftFace ? leftFace->x : rightFace->x;
++		yorgi = leftFace ? leftFace->y : rightFace->y;
++	}
++	edgey1 = 65536;
++	edgey2 = 65536;
++	edge1.x = 0; /* not used, keep memory checkers happy */
++	edge1.dy = -1;
++	edge2.x = 0; /* not used, keep memory checkers happy */
++	edge2.dy = -1;
++	edgeleft1 = FALSE;
++	edgeleft2 = FALSE;
++
++	if ((pGC->lineWidth > 2) &&
++	    (pGC->capStyle == CapRound && pGC->joinStyle != JoinRound ||
++	     pGC->joinStyle == JoinRound && pGC->capStyle == CapButt)) {
++		if (isInt) {
++			xorg = (double) xorgi;
++			yorg = (double) yorgi;
++		}
++
++		if (leftFace && rightFace) {
++			miRoundJoinClip (leftFace, rightFace, &edge1, &edge2,
++					 &edgey1, &edgey2, &edgeleft1, &edgeleft2);
++		} else if (leftFace) { 
++			edgey1 = miRoundCapClip (leftFace, isInt, &edge1, &edgeleft1);
++		} else if (rightFace) {
++			edgey2 = miRoundCapClip (rightFace, isInt, &edge2, &edgeleft2);
++		}
++
++		isInt = FALSE;
++	}
++
++	if (isInt)
++		CreatorLineArcI(pDraw, pGC, xorgi, yorgi);
++	else
++		CreatorLineArcD(pDraw, pGC, xorg, yorg, 
++				&edge1, edgey1, edgeleft1,
++				&edge2, edgey2, edgeleft2);
++}
++
++static void
++CreatorLineJoin (DrawablePtr pDrawable, GCPtr pGC, LineFacePtr pLeft, LineFacePtr pRight)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	double mx, my, denom;
++	PolyVertexRec vertices[4];
++	PolySlopeRec slopes[4];
++	PolyEdgeRec left[4], right[4];
++	int edgecount, nleft, nright, y, height, swapslopes;
++	int joinStyle = pGC->joinStyle;
++	int lw = pGC->lineWidth;
++
++	if (lw == 1) {
++		/* Lines going in the same direction have no join */
++		if ((pLeft->dx >= 0) == (pRight->dx <= 0))
++			return;
++		if (joinStyle != JoinRound) {
++			denom = - pLeft->dx * (double)pRight->dy + pRight->dx *
++				(double)pLeft->dy;
++			if (denom == 0.0)
++				return;	/* no join to draw */
++		}
++		if (joinStyle != JoinMiter) {
++			if(pGC->miTranslate)
++				CreatorPointHelper(ffbPriv,
++						   pLeft->x + pDrawable->x,
++						   pLeft->y + pDrawable->y);
++			else
++				CreatorPointHelper(ffbPriv, pLeft->x, pLeft->y);	
++			return;
++		}
++	} else {
++		if (joinStyle == JoinRound) {
++			CreatorLineArc(pDrawable, pGC, pLeft, pRight,
++				       (double)0.0, (double)0.0, TRUE);
++			return;
++		}
++		denom = - pLeft->dx * (double)pRight->dy + pRight->dx * 
++			(double)pLeft->dy;
++		if (denom == 0.0)
++			return;	/* no join to draw */
++	}
++
++	swapslopes = 0;
++	if (denom > 0) {
++		pLeft->xa = -pLeft->xa;
++		pLeft->ya = -pLeft->ya;
++		pLeft->dx = -pLeft->dx;
++		pLeft->dy = -pLeft->dy;
++	} else {
++		swapslopes = 1;
++		pRight->xa = -pRight->xa;
++		pRight->ya = -pRight->ya;
++		pRight->dx = -pRight->dx;
++		pRight->dy = -pRight->dy;
++	}
++
++	vertices[0].x = pRight->xa;
++	vertices[0].y = pRight->ya;
++	slopes[0].dx = -pRight->dy;
++	slopes[0].dy =  pRight->dx;
++	slopes[0].k = 0;
++
++	vertices[1].x = 0;
++	vertices[1].y = 0;
++	slopes[1].dx =  pLeft->dy;
++	slopes[1].dy = -pLeft->dx;
++	slopes[1].k = 0;
++
++	vertices[2].x = pLeft->xa;
++	vertices[2].y = pLeft->ya;
++
++	if (joinStyle == JoinMiter) {
++		my = (pLeft->dy  * (pRight->xa * pRight->dy - pRight->ya * pRight->dx) -
++		      pRight->dy * (pLeft->xa  * pLeft->dy  - pLeft->ya  * pLeft->dx ))/
++			denom;
++		if (pLeft->dy != 0) 
++			mx = pLeft->xa + (my - pLeft->ya) *
++				(double) pLeft->dx / (double) pLeft->dy;
++		else
++			mx = pRight->xa + (my - pRight->ya) *
++				(double) pRight->dx / (double) pRight->dy;
++    	
++		/* check miter limit */
++		if ((mx * mx + my * my) * 4 > SQSECANT * lw * lw)
++			joinStyle = JoinBevel;
++	}
++
++	if (joinStyle == JoinMiter) {
++		slopes[2].dx = pLeft->dx;
++		slopes[2].dy = pLeft->dy;
++		slopes[2].k =  pLeft->k;
++		if (swapslopes) {
++			slopes[2].dx = -slopes[2].dx;
++			slopes[2].dy = -slopes[2].dy;
++			slopes[2].k  = -slopes[2].k;
++		}
++		vertices[3].x = mx;
++		vertices[3].y = my;
++		slopes[3].dx = pRight->dx;
++		slopes[3].dy = pRight->dy;
++		slopes[3].k  = pRight->k;
++		if (swapslopes) {
++			slopes[3].dx = -slopes[3].dx;
++			slopes[3].dy = -slopes[3].dy;
++			slopes[3].k  = -slopes[3].k;
++		}
++		edgecount = 4;
++	} else {
++		double	scale, dx, dy, adx, ady;
++
++		adx = dx = pRight->xa - pLeft->xa;
++		ady = dy = pRight->ya - pLeft->ya;
++		if (adx < 0)
++			adx = -adx;
++		if (ady < 0)
++			ady = -ady;
++		scale = ady;
++		if (adx > ady)
++			scale = adx;
++		slopes[2].dx = (dx * 65536) / scale;
++		slopes[2].dy = (dy * 65536) / scale;
++		slopes[2].k = ((pLeft->xa + pRight->xa) * slopes[2].dy -
++			       (pLeft->ya + pRight->ya) * slopes[2].dx) / 2.0;
++		edgecount = 3;
++	}
++
++	y = miPolyBuildPoly (vertices, slopes, edgecount, pLeft->x, pLeft->y,
++			     left, right, &nleft, &nright, &height);
++	CreatorFillPolyHelper(pDrawable, pGC, y, height, left, right, nleft, nright);
++}
++
++void
++CreatorWideLineSolid (DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr pPts)
++{
++	int x1, y1, x2, y2, first = TRUE;
++	Bool projectLeft, projectRight, somethingDrawn = FALSE, selfJoin = FALSE;
++	LineFaceRec leftFace, rightFace, prevRightFace, firstFace;
++	cfbPrivGCPtr devPriv = cfbGetGCPrivate(pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	RegionPtr clip;
++	int numRects;
++	unsigned int ppc;
++	BoxPtr pbox;
++
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		miWideLine(pDrawable, pGC, mode, npt, pPts);
++		return;
++	}
++	clip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
++	numRects = REGION_NUM_RECTS(clip);
++	if (!numRects)
++		return;
++	if (!(ppc = FFBSetClip(ffbPriv, ffb, clip, numRects))) {
++		miWideLine(pDrawable, pGC, mode, npt, pPts);
++		return;
++	}
++
++	LeftClip = 2048; TopClip = 2048;
++	RightClip = 0; BottomClip = 0;
++	for (pbox = REGION_RECTS(clip); numRects; numRects--, pbox++) {
++		if (pbox->x1 < LeftClip) LeftClip = pbox->x1;
++		if (pbox->x2 > RightClip) RightClip = pbox->x2 - 1;
++		if (pbox->y1 < TopClip) TopClip = pbox->y1;
++		if (pbox->y2 > BottomClip) BottomClip = pbox->y2 - 1;
++	}
++
++	FFB_WRITE_ATTRIBUTES(ffbPriv,
++			     ppc|FFB_PPC_APE_DISABLE|FFB_PPC_TBE_OPAQUE|
++			     FFB_PPC_XS_CONST|FFB_PPC_YS_CONST|FFB_PPC_ZS_CONST|FFB_PPC_CS_CONST,
++			     FFB_PPC_VCE_MASK|FFB_PPC_ACE_MASK|FFB_PPC_APE_MASK|FFB_PPC_TBE_MASK|
++			     FFB_PPC_XS_MASK|FFB_PPC_YS_MASK|FFB_PPC_ZS_MASK|FFB_PPC_CS_MASK,
++			     pGC->planemask,
++			     FFB_ROP_EDIT_BIT|pGC->alu,
++			     -1, pGC->fgPixel,
++			     FFB_FBC_DEFAULT);
++
++	x2 = pPts->x;
++	y2 = pPts->y;
++	if (npt > 1) {
++		if (mode == CoordModePrevious) {
++			int nptTmp;
++			register DDXPointPtr pPtsTmp;
++    
++			x1 = x2;
++			y1 = y2;
++			nptTmp = npt;
++			pPtsTmp = pPts + 1;
++			while (--nptTmp) {
++				x1 += pPtsTmp->x;
++				y1 += pPtsTmp->y;
++				++pPtsTmp;
++			}
++			if ((x2 == x1) && (y2 == y1))
++				selfJoin = TRUE;
++		} else if ((x2 == pPts[npt-1].x) && (y2 == pPts[npt-1].y)) 
++			selfJoin = TRUE;
++	}
++
++	projectLeft = ((pGC->capStyle == CapProjecting) && !selfJoin);
++	projectRight = FALSE;
++
++	while (--npt) {
++		x1 = x2;
++		y1 = y2;
++		++pPts;
++		x2 = pPts->x;
++		y2 = pPts->y;
++		if (mode == CoordModePrevious) {
++			x2 += x1;
++			y2 += y1;
++		}
++		if ((x1 != x2) || (y1 != y2)) {
++			somethingDrawn = TRUE;
++			if ((npt == 1) && (pGC->capStyle == CapProjecting) && !selfJoin)
++				projectRight = TRUE;
++			CreatorWideSegment(pDrawable, pGC, x1, y1, x2, y2,
++					   projectLeft, projectRight, &leftFace, &rightFace);
++			if (first) {
++				if (selfJoin)
++					firstFace = leftFace;
++				else if (pGC->capStyle == CapRound) {
++					if (pGC->lineWidth == 1) {
++						if(pGC->miTranslate) 
++							CreatorPointHelper(ffbPriv,
++									   x1 + pDrawable->x, 
++									   y1 + pDrawable->y);
++						else
++							CreatorPointHelper(ffbPriv, x1, y1);
++					} else
++						CreatorLineArc(pDrawable, pGC,
++							       &leftFace, (LineFacePtr) NULL,
++							       (double)0.0, (double)0.0,
++							       TRUE);
++				}
++			} else 
++				CreatorLineJoin (pDrawable, pGC, &leftFace, &prevRightFace);
++
++			prevRightFace = rightFace;
++			first = FALSE;
++			projectLeft = FALSE;
++		}
++		if (npt == 1 && somethingDrawn) {
++			if (selfJoin)
++				CreatorLineJoin (pDrawable, pGC, &firstFace, &rightFace);
++			else if (pGC->capStyle == CapRound) {
++				if (pGC->lineWidth == 1) {
++					if(pGC->miTranslate) 
++						CreatorPointHelper(ffbPriv,
++								   x2 + pDrawable->x, 
++								   y2 + pDrawable->y);
++					else
++						CreatorPointHelper(ffbPriv, x2, y2);
++				} else
++					CreatorLineArc (pDrawable, pGC, 
++							(LineFacePtr) NULL, &rightFace,
++							(double)0.0, (double)0.0,
++							TRUE);
++			}
++		}
++	}
++
++	/* handle crock where all points are coincedent */
++	if (!somethingDrawn) {
++		projectLeft = (pGC->capStyle == CapProjecting);
++		CreatorWideSegment (pDrawable, pGC,
++				    x2, y2, x2, y2, projectLeft, projectLeft,
++				    &leftFace, &rightFace);
++		if (pGC->capStyle == CapRound) {
++			CreatorLineArc (pDrawable, pGC, 
++					&leftFace, (LineFacePtr) NULL,
++					(double)0.0, (double)0.0,
++					TRUE);
++			rightFace.dx = -1;	/* sleezy hack to make it work */
++			CreatorLineArc (pDrawable, pGC,
++					(LineFacePtr) NULL, &rightFace,
++					(double)0.0, (double)0.0,
++					TRUE);
++		}
++	}
++	ffbPriv->rp_active = 1;
++}
+--- xc/programs/Xserver/hw/sun/FFB/Imakefile.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/Imakefile	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,83 @@
++#include <Server.tmpl>
++
++SRCS =	sunFFB.c FFBattr.c FFBstip.c FFBbcopy.c FFBcplane.c \
++	FFBfspans.c FFBpoint.c FFBseg.c FFBplygon.c FFBline.c FFBglyph.c \
++	FFBfrect.c FFBcircle.c FFBchecks.c FFBstubs.c FFBgc.c \
++	FFBgspans.c FFBsspans.c FFBzeroarc.c
++
++#if defined(AsVISOption) && defined(UseElfFormat)
++VISOFILES = VISmoveImage.o sunFFBasm.o
++VISOPTIONS = -DUSE_VIS
++ASVISOPTION = AsVISOption
++GCCVISOPTION = -Wa,$(ASVISOPTION)
++#if AsOutputArchSize == 32
++#define FFBCObjectRule(name)										@@\
++name.o: name.c												@@\
++	ObjectCompile(-mv8 -mtune=ultrasparc $(GCCVISOPTION) $(VISOPTIONS))				@@\
++	dd if=/dev/zero bs=1 count=3 | dd of=$@ bs=1 count=3 seek=36 conv=notrunc			@@\
++	echo -e '\002' | dd of=$@ bs=1 count=1 seek=19 conv=notrunc					@@\
++													@@\
++name.i: name.c												@@\
++	CPPOnlyCompile(name.c,-mv8 $(GCCVISOPTION) $(VISOPTIONS))					@@\
++													@@\
++CenterLoadTarget(debug_src,name.c,NullParameter,$(ALLDEFINES) -mv8 $(GCCVISOPTION) $(VISOPTIONS))
++#define FFBsObjectRule(name)										@@\
++name.o: name.s												@@\
++	$(RM) $@											@@\
++	$(CPP) $*.s | $(AS) $(ASVISOPTION) -o $@ -							@@\
++	dd if=/dev/zero bs=1 count=3 | dd of=$@ bs=1 count=3 seek=36 conv=notrunc			@@\
++	echo -e '\002' | dd of=$@ bs=1 count=1 seek=19 conv=notrunc
++#else
++#define FFBCObjectRule(name) SpecialCObjectRule(name,,-mv8 $(GCCVISOPTION) $(VISOPTIONS))
++#define FFBsObjectRule(name)										@@\
++name.o: name.s												@@\
++	$(RM) $@											@@\
++	$(CPP) $*.s | $(AS) $(ASVISOPTION) -o $@ -
++#endif
++#else
++VISOFILES =
++VISOPTIONS =
++ASVISOPTION =
++#define FFBCObjectRule(name)
++#define FFBsObjectRule(name)
++#endif
++
++FFBOBJS =	sunFFB.o FFBattr.o FFBstip.o FFBbcopy.o FFBcplane.o \
++		FFBfspans.o FFBpoint.o FFBseg.o FFBplygon.o FFBline.o \
++		FFBglyph.o FFBfrect.o FFBcircle.o FFBchecks.o \
++		FFBstubs.o FFBgc.o FFBgspans.o FFBsspans.o FFBzeroarc.o \
++		$(VISOFILES)
++
++INCLUDES = -I. -I../ -I../../.. \
++	   -I../../../mi -I../../../mfb -I../../../cfb -I../../../cfb32 \
++	   -I../../../include -I$(XINCLUDESRC) -I$(FONTINCSRC) -I$(EXTINCSRC) \
++	   -I$(LIBSRC)/font/include
++LINTLIBS = ../../../dix/llib-ldix.ln ../../../os/llib-los.ln \
++	   ../../mfb/llib-lmfb.ln ../../mi/llib-lmi.ln ../../cfb/llib-lcfb.ln
++
++NormalLibraryObjectRule()
++NormalLibraryTarget(FFB,$(FFBOBJS))
++
++FFBCObjectRule(sunFFB)
++FFBCObjectRule(FFBattr)
++FFBCObjectRule(FFBstip)
++FFBCObjectRule(FFBbcopy)
++FFBCObjectRule(FFBcplane)
++FFBCObjectRule(FFBfspans)
++FFBCObjectRule(FFBpoint)
++FFBCObjectRule(FFBseg)
++FFBCObjectRule(FFBplygon)
++FFBCObjectRule(FFBline)
++FFBCObjectRule(FFBglyph)
++FFBCObjectRule(FFBfrect)
++FFBCObjectRule(FFBcircle)
++FFBCObjectRule(FFBchecks)
++FFBCObjectRule(FFBstubs)
++FFBCObjectRule(FFBgc)
++FFBCObjectRule(FFBgspans)
++FFBCObjectRule(FFBsspans)
++FFBCObjectRule(FFBzeroarc)
++FFBsObjectRule(VISmoveImage)
++FFBsObjectRule(sunFFBasm)
++
++DependTarget()
+--- xc/programs/Xserver/hw/sun/FFB/sunFFB.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/sunFFB.c	Thu Jan 13 12:14:21 2000
+@@ -0,0 +1,853 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#define	PSZ	32
++#include	<asm/types.h>
++#include	<math.h>
++#include	"sun.h"
++
++#include	"scrnintstr.h"
++#include	"pixmapstr.h"
++#include	"regionstr.h"
++#include	"mistruct.h"
++#include	"fontstruct.h"
++#include	"dixfontstr.h"
++#include	"cfb/cfb.h"
++#include	"cfb/cfbmskbits.h"
++#include	"cfb/cfb8bit.h"
++#include	"mibstore.h"
++#include	"mifillarc.h"
++#include	"miwideline.h"
++#include	"miline.h"
++#include	"fastblt.h"
++#include	"mergerop.h"
++#include	"migc.h"
++#include	"mi.h"
++
++#include	"sunFFB.h"
++#include	"FFBfifo.h"
++#include	"FFBrcache.h"
++#include	"FFBloops.h"
++#include	"FFBregs.h"
++#include	"FFBstip.h"
++#include 	"FFBgc.h"
++
++int	CreatorScreenPrivateIndex;
++int	CreatorGCPrivateIndex;
++int	CreatorWindowPrivateIndex;
++int	CreatorGeneration;
++static void CreatorDestroyGC (GCPtr pGC);
++
++/* Indexed by ffb resolution enum. */
++struct fastfill_parms ffb_fastfill_parms[] = {
++	/* fsmall, psmall,  ffh,  ffw,  pfh,  pfw */
++	{  0x00c0, 0x1400, 0x04, 0x08, 0x10, 0x50 },	/* Standard: 1280 x 1024 */
++	{  0x0140, 0x2800, 0x04, 0x10, 0x10, 0xa0 },	/* High:     1920 x 1360 */
++	{  0x0080, 0x0a00, 0x02, 0x08, 0x08, 0x50 },	/* Stereo:   960  x 580  */
++/*XXX*/	{  0x00c0, 0x0a00, 0x04, 0x08, 0x08, 0x50 },	/* Portrait: 1280 x 2048 XXX */
++};
++
++static Bool
++CreatorCreateWindow (WindowPtr pWin)
++{
++	if (!cfbCreateWindow (pWin))
++		return FALSE;
++	pWin->devPrivates[CreatorWindowPrivateIndex].ptr = 0;
++	return TRUE;
++}
++
++static Bool
++CreatorDestroyWindow (WindowPtr pWin)
++{
++	CreatorStipplePtr stipple;
++	if ((stipple = CreatorGetWindowPrivate(pWin)))
++		xfree (stipple);
++	return cfbDestroyWindow (pWin);
++}
++
++extern CreatorStipplePtr FFB_tmpStipple;
++
++static int
++CreatorChangeWindowAttributes (WindowPtr pWin, Mask mask)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pWin->drawable.pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	CreatorStipplePtr stipple;
++	Mask index;
++	WindowPtr pBgWin;
++	register cfbPrivWin *pPrivWin;
++	int width;
++
++	FFBLOG("CreatorChangeWindowAttributes: WIN(%p) mask(%08x)\n",
++	       pWin, mask);
++	pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
++	/*
++	 * When background state changes from ParentRelative and
++	 * we had previously rotated the fast border pixmap to match
++	 * the parent relative origin, rerotate to match window
++	 */
++	if (mask & (CWBackPixmap | CWBackPixel) &&
++	    pWin->backgroundState != ParentRelative &&
++	    pPrivWin->fastBorder &&
++	    (pPrivWin->oldRotate.x != pWin->drawable.x ||
++	     pPrivWin->oldRotate.y != pWin->drawable.y)) {
++		cfbXRotatePixmap(pPrivWin->pRotatedBorder,
++				 pWin->drawable.x - pPrivWin->oldRotate.x);
++		cfbYRotatePixmap(pPrivWin->pRotatedBorder,
++				 pWin->drawable.y - pPrivWin->oldRotate.y);
++		pPrivWin->oldRotate.x = pWin->drawable.x;
++		pPrivWin->oldRotate.y = pWin->drawable.y;
++	}
++	while (mask) {
++		index = lowbit(mask);
++		mask &= ~index;
++		switch (index) {
++		case CWBackPixmap:
++			stipple = CreatorGetWindowPrivate(pWin);
++			if (pWin->backgroundState == None ||
++			    pWin->backgroundState == ParentRelative) {
++				pPrivWin->fastBackground = FALSE;
++				if (stipple) {
++					xfree (stipple);
++					CreatorSetWindowPrivate(pWin,0);
++				}
++				/* Rotate border to match parent origin */
++				if (pWin->backgroundState == ParentRelative &&
++				    pPrivWin->pRotatedBorder)  {
++					for (pBgWin = pWin->parent;
++					     pBgWin->backgroundState == ParentRelative;
++					     pBgWin = pBgWin->parent);
++					cfbXRotatePixmap(pPrivWin->pRotatedBorder,
++							 pBgWin->drawable.x - pPrivWin->oldRotate.x);
++					cfbYRotatePixmap(pPrivWin->pRotatedBorder,
++							 pBgWin->drawable.y - pPrivWin->oldRotate.y);
++					pPrivWin->oldRotate.x = pBgWin->drawable.x;
++					pPrivWin->oldRotate.y = pBgWin->drawable.y;
++				}
++				break;
++			}
++			if (!stipple) {
++				if (!FFB_tmpStipple)
++					FFB_tmpStipple = (CreatorStipplePtr)
++						xalloc (sizeof *FFB_tmpStipple);
++				stipple = FFB_tmpStipple;
++			}
++			if (stipple) {
++				int ph = FFB_FFPARMS(ffbPriv).pagefill_height;
++
++				if(CreatorCheckTile (pWin->background.pixmap, stipple,
++						     ((DrawablePtr)pWin)->x & 31,
++						     ((DrawablePtr)pWin)->y & 31, ph)) {
++					stipple->alu = GXcopy;
++					pPrivWin->fastBackground = FALSE;
++					if (stipple == FFB_tmpStipple) {
++						CreatorSetWindowPrivate(pWin, stipple);
++						FFB_tmpStipple = 0;
++					}
++					break;
++				}
++			}
++			if ((stipple = CreatorGetWindowPrivate(pWin))) {
++				xfree (stipple);
++				CreatorSetWindowPrivate(pWin,0);
++			}
++			if (((width = (pWin->background.pixmap->drawable.width * PSZ)) <= 32) &&
++			    !(width & (width - 1))) {
++				cfbCopyRotatePixmap(pWin->background.pixmap,
++						    &pPrivWin->pRotatedBackground,
++						    pWin->drawable.x,
++						    pWin->drawable.y);
++				if (pPrivWin->pRotatedBackground) {
++					pPrivWin->fastBackground = TRUE;
++					pPrivWin->oldRotate.x = pWin->drawable.x;
++					pPrivWin->oldRotate.y = pWin->drawable.y;
++				} else
++					pPrivWin->fastBackground = FALSE;
++				break;
++			}
++			pPrivWin->fastBackground = FALSE;
++			break;
++
++		case CWBackPixel:
++			pPrivWin->fastBackground = FALSE;
++			break;
++
++		case CWBorderPixmap:
++			/* don't bother with accelerator for border tiles (just lazy) */
++			if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= 32) &&
++			    !(width & (width - 1))) {
++				for (pBgWin = pWin;
++				     pBgWin->backgroundState == ParentRelative;
++				     pBgWin = pBgWin->parent)
++					;
++				cfbCopyRotatePixmap(pWin->border.pixmap,
++						    &pPrivWin->pRotatedBorder,
++						    pBgWin->drawable.x,
++						    pBgWin->drawable.y);
++				if (pPrivWin->pRotatedBorder) {
++					pPrivWin->fastBorder = TRUE;
++					pPrivWin->oldRotate.x = pBgWin->drawable.x;
++					pPrivWin->oldRotate.y = pBgWin->drawable.y;
++				} else
++					pPrivWin->fastBorder = FALSE;
++			} else
++				pPrivWin->fastBorder = FALSE;
++			break;
++			
++		case CWBorderPixel:
++			pPrivWin->fastBorder = FALSE;
++			break;
++		}
++	}
++	return (TRUE);
++}
++
++static void
++CreatorPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pWin->drawable.pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	register cfbPrivWin *pPrivWin;
++	CreatorStipplePtr stipple;
++	WindowPtr pBgWin;
++
++	if (VT_HIDDEN(pWin->drawable.pScreen)) {
++		cfbPaintWindow(pWin, pRegion, what);
++		return;
++	}
++	FFBLOG("CreatorPaintWindow: WIN(%p) what(%d)\n", pWin, what);
++	pPrivWin = cfbGetWindowPrivate(pWin);
++	switch (what) {
++	case PW_BACKGROUND:
++		stipple = CreatorGetWindowPrivate(pWin);
++		switch (pWin->backgroundState) {
++		case None:
++			return;
++		case ParentRelative:
++			do {
++				pWin = pWin->parent;
++			} while (pWin->backgroundState == ParentRelative);
++			(*pWin->drawable.pScreen->PaintWindowBackground)(pWin, pRegion, what);
++			return;
++		case BackgroundPixmap:
++			if (stipple) {
++				CreatorFillBoxStipple ((DrawablePtr)pWin, 
++						       (int)REGION_NUM_RECTS(pRegion),
++						       REGION_RECTS(pRegion),
++						       stipple);
++				return;
++			}
++			FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, 0xffffffff, GXcopy);
++			FFBWait(ffbPriv, ffb);
++			if (pPrivWin->fastBackground) {
++				cfbFillBoxTile32 ((DrawablePtr)pWin,
++						  (int)REGION_NUM_RECTS(pRegion),
++						  REGION_RECTS(pRegion),
++						  pPrivWin->pRotatedBackground);
++			} else {
++				cfbFillBoxTileOdd ((DrawablePtr)pWin,
++						   (int)REGION_NUM_RECTS(pRegion),
++						   REGION_RECTS(pRegion),
++						   pWin->background.pixmap,
++						   (int) pWin->drawable.x, (int) pWin->drawable.y);
++			}
++			return;
++		case BackgroundPixel:
++			CreatorFillBoxSolid ((DrawablePtr)pWin,
++					     (int)REGION_NUM_RECTS(pRegion),
++					     REGION_RECTS(pRegion),
++					     pWin->background.pixel);
++			return;
++		}
++		break;
++	case PW_BORDER:
++		if (pWin->borderIsPixel) {
++			CreatorFillBoxSolid ((DrawablePtr)pWin,
++					     (int)REGION_NUM_RECTS(pRegion),
++					     REGION_RECTS(pRegion),
++					     pWin->border.pixel);
++			return;
++		}
++		FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, 0xffffffff, GXcopy);
++		FFBWait(ffbPriv, ffb);
++		if (pPrivWin->fastBorder) {
++			cfbFillBoxTile32 ((DrawablePtr)pWin,
++					  (int)REGION_NUM_RECTS(pRegion),
++					  REGION_RECTS(pRegion),
++					  pPrivWin->pRotatedBorder);
++		} else {
++			for (pBgWin = pWin;
++			     pBgWin->backgroundState == ParentRelative;
++			     pBgWin = pBgWin->parent)
++				;
++
++			cfbFillBoxTileOdd ((DrawablePtr)pWin,
++					   (int)REGION_NUM_RECTS(pRegion),
++					   REGION_RECTS(pRegion),
++					   pWin->border.pixmap,
++					   (int) pBgWin->drawable.x,
++					   (int) pBgWin->drawable.y);
++		}
++		return;
++	}
++}
++
++#ifdef USE_VIS
++static void 
++CreatorCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pWin->drawable.pScreen);
++	DDXPointPtr pptSrc;
++	DDXPointPtr ppt;
++	RegionPtr prgnDst;
++	BoxPtr pbox;
++	int dx, dy;
++	int i, nbox;
++	WindowPtr pwinRoot;
++	extern WindowPtr *WindowTable;
++
++	FFBLOG("CreatorCopyWindow: WIN(%p)\n", pWin);
++	dx = ptOldOrg.x - pWin->drawable.x;
++	dy = ptOldOrg.y - pWin->drawable.y;
++
++	pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
++
++	prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
++
++	REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
++	REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip, prgnSrc);
++
++	pbox = REGION_RECTS(prgnDst);
++	nbox = REGION_NUM_RECTS(prgnDst);
++	if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
++		return;
++	ppt = pptSrc;
++
++	for (i = nbox; --i >= 0; ppt++, pbox++) {
++		ppt->x = pbox->x1 + dx;
++		ppt->y = pbox->y1 + dy;
++	}
++
++	if (!ffbPriv->disable_vscroll &&
++	    (!dx && dy && !VT_HIDDEN(pWin->drawable.pScreen))) {
++		CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pWin->drawable.pScreen);
++		ffb_fbcPtr ffb = ffbPriv->regs;
++
++		FFB_WRITE_ATTRIBUTES_VSCROLL(ffbPriv, PMSK);
++		CreatorDoVertBitblt ((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
++				     GXcopy, prgnDst, pptSrc, ~0L);
++	} else {
++		if(!VT_HIDDEN(pWin->drawable.pScreen)) {
++			CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pWin->drawable.pScreen);
++			ffb_fbcPtr ffb = ffbPriv->regs;
++
++			FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, PMSK, GXcopy);
++			FFBWait(ffbPriv, ffb);
++		}
++		CreatorDoBitblt ((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
++				 GXcopy, prgnDst, pptSrc, ~0L);
++	}
++	DEALLOCATE_LOCAL(pptSrc);
++	REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
++}
++
++static void
++CreatorSaveAreas(PixmapPtr pPixmap, RegionPtr prgnSave, int xorg, int yorg, WindowPtr pWin)
++{
++	ScreenPtr pScreen = pPixmap->drawable.pScreen;
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	register DDXPointPtr pPt;
++	DDXPointPtr pPtsInit;
++	register BoxPtr pBox;
++	register int i;
++	PixmapPtr pScrPix;
++    
++	FFBLOG("CreatorSaveAreas: WIN(%p)\n", pWin);
++	i = REGION_NUM_RECTS(prgnSave);
++	pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
++	if (!pPtsInit)
++		return;
++    
++	pBox = REGION_RECTS(prgnSave);
++	pPt = pPtsInit;
++	while (--i >= 0) {
++		pPt->x = pBox->x1 + xorg;
++		pPt->y = pBox->y1 + yorg;
++		pPt++;
++		pBox++;
++	}
++
++#ifdef CFB_NEED_SCREEN_PRIVATE
++	pScrPix = (PixmapPtr) pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
++#else
++	pScrPix = (PixmapPtr) pScreen->devPrivate;
++#endif
++
++	/* SRC is the framebuffer, DST is a pixmap */
++	FFBWait(ffbPriv, ffb);
++	CreatorDoBitblt((DrawablePtr) pScrPix, (DrawablePtr)pPixmap,
++			GXcopy, prgnSave, pPtsInit, ~0L);
++
++	DEALLOCATE_LOCAL (pPtsInit);
++}
++
++static void
++CreatorRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg, int yorg, WindowPtr pWin)
++{
++	CreatorPrivScreenPtr ffbPriv;
++	ffb_fbcPtr ffb;
++	register DDXPointPtr pPt;
++	DDXPointPtr pPtsInit;
++	register BoxPtr pBox;
++	register int i;
++	ScreenPtr pScreen = pPixmap->drawable.pScreen;
++	PixmapPtr pScrPix;
++    
++	FFBLOG("CreatorRestoreAreas: WIN(%p)\n", pWin);
++	i = REGION_NUM_RECTS(prgnRestore);
++	pPtsInit = (DDXPointPtr)ALLOCATE_LOCAL(i*sizeof(DDXPointRec));
++	if (!pPtsInit)
++		return;
++    
++	pBox = REGION_RECTS(prgnRestore);
++	pPt = pPtsInit;
++	while (--i >= 0) {
++		pPt->x = pBox->x1 - xorg;
++		pPt->y = pBox->y1 - yorg;
++		pPt++;
++		pBox++;
++	}
++
++#ifdef CFB_NEED_SCREEN_PRIVATE
++	pScrPix = (PixmapPtr) pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
++#else
++	pScrPix = (PixmapPtr) pScreen->devPrivate;
++#endif
++	ffbPriv = CreatorGetScreenPrivate(pScreen);
++	ffb = ffbPriv->regs;
++
++	/* SRC is a pixmap, DST is the framebuffer */
++	FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, PMSK, GXcopy);
++	FFBWait(ffbPriv, ffb);
++	CreatorDoBitblt((DrawablePtr)pPixmap, (DrawablePtr) pScrPix,
++			GXcopy, prgnRestore, pPtsInit, ~0L);
++
++	DEALLOCATE_LOCAL (pPtsInit);
++}
++
++static void
++CreatorGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char* pdstLine)
++{
++	BoxRec box;
++	DDXPointRec ptSrc;
++	RegionRec rgnDst;
++	ScreenPtr pScreen;
++	PixmapPtr pPixmap;
++
++	FFBLOG("CreatorGetImage: s[%08x:%08x] wh[%08x:%08x]\n", sx, sy, w, h);
++	if ((w == 0) || (h == 0))
++		return;
++	if (pDrawable->bitsPerPixel == 1) {
++		mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
++		return;
++	}
++	pScreen = pDrawable->pScreen;
++	if(format == ZPixmap) {
++		CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pScreen);
++		ffb_fbcPtr ffb = ffbPriv->regs;
++
++		/* We have to have the full planemask. */
++		FFBWait(ffbPriv, ffb);
++		if((planeMask & PMSK) != PMSK) {
++			cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
++			return;
++		}
++
++		/* SRC is the framebuffer, DST is a pixmap */
++		if(w == 1 && h == 1) {
++			unsigned int *dstPixel = (unsigned int *)pdstLine;
++			unsigned char *sfb = (unsigned char *)ffbPriv->fb;
++
++			/* Benchmarks do this make sure the acceleration hardware
++			 * has completed all of it's operations, therefore I feel
++			 * it is not cheating to special case this because if
++			 * anything it gives the benchmarks more accurate results.
++			 */
++			*dstPixel = *((unsigned int *)(sfb +
++						       ((sy + pDrawable->y) << 13) +
++						       ((sx + pDrawable->x) << 2)));
++			return;
++		}
++		pPixmap = GetScratchPixmapHeader(pScreen, w, h, 
++						 pDrawable->depth, pDrawable->bitsPerPixel,
++						 PixmapBytePad(w,pDrawable->depth), (pointer)pdstLine);
++		if (!pPixmap)
++			return;
++		ptSrc.x = sx + pDrawable->x;
++		ptSrc.y = sy + pDrawable->y;
++		box.x1 = 0;
++		box.y1 = 0;
++		box.x2 = w;
++		box.y2 = h;
++		REGION_INIT(pScreen, &rgnDst, &box, 1);
++		CreatorDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
++				&ptSrc, planeMask);
++		REGION_UNINIT(pScreen, &rgnDst);
++		FreeScratchPixmapHeader(pPixmap);
++	} else
++		miGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
++}
++
++#endif /* USE_VIS */
++
++extern void
++CreatorGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
++		int *pwidth, int nspans, char *pchardstStart);
++
++#ifdef linux
++static void CreatorVtChange (int screen, int enter)
++{
++	ScreenPtr pScreen = screenInfo.screens[screen];
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pScreen); 
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	ffbPriv->rp_active = 1;
++	FFBWait(ffbPriv, ffb);	
++	ffbPriv->fifo_cache = -1;
++	ffbPriv->fbc_cache = FFB_FBC_WB_A|FFB_FBC_WM_COMBINED|
++			     FFB_FBC_RB_A|FFB_FBC_SB_BOTH|FFB_FBC_XE_OFF|
++			     FFB_FBC_ZE_OFF|FFB_FBC_YE_OFF|FFB_FBC_RGBE_MASK;
++	ffbPriv->ppc_cache = (FFB_PPC_FW_DISABLE|
++			      FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST|
++			      FFB_PPC_XS_CONST|FFB_PPC_YS_CONST|FFB_PPC_ZS_CONST|
++			      FFB_PPC_DCE_DISABLE|FFB_PPC_ABE_DISABLE|FFB_PPC_TBE_OPAQUE);
++	ffbPriv->pmask_cache = ~0;
++	ffbPriv->rop_cache = FFB_ROP_EDIT_BIT;
++	ffbPriv->drawop_cache = FFB_DRAWOP_RECTANGLE;
++	ffbPriv->fg_cache = ffbPriv->bg_cache = 0;
++	ffbPriv->fontw_cache = 32;
++	ffbPriv->fontinc_cache = (1 << 16) | 0;
++	ffbPriv->laststipple = NULL;
++	FFBFifo(ffbPriv, 9);
++	ffb->fbc = ffbPriv->fbc_cache;
++	ffb->ppc = ffbPriv->ppc_cache;
++	ffb->pmask = ffbPriv->pmask_cache;
++	ffb->rop = ffbPriv->rop_cache;
++	ffb->drawop = ffbPriv->drawop_cache;
++	ffb->fg = ffbPriv->fg_cache;
++	ffb->bg = ffbPriv->bg_cache;
++	ffb->fontw = ffbPriv->fontw_cache;
++	ffb->fontinc = ffbPriv->fontinc_cache;
++	ffbPriv->rp_active = 1;
++	FFBWait(ffbPriv, ffb);
++}
++
++static void
++CreatorDoBitbltWrapper(DrawablePtr pSrc, DrawablePtr pDst, int alu, RegionPtr prgnDst,
++		       DDXPointPtr pptSrc, unsigned long planemask)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDst->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	/* SRC is pixmap, DST is framebuffer */
++	FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, planemask, alu);
++	FFBWait(ffbPriv, ffb);
++	CreatorDoBitblt(pSrc, pDst, alu, prgnDst, pptSrc, planemask);
++}
++#endif
++
++/* Multiplies and divides suck... */
++static void CreatorAlignTabInit(CreatorPrivScreenPtr ffbPriv)
++{
++	struct fastfill_parms *ffp = &FFB_FFPARMS(ffbPriv);
++	short *tab = ffbPriv->Pf_AlignTab;
++	int i;
++
++	for(i = 0; i < 0x800; i++) {
++		int alignval;
++
++		alignval = (i / ffp->pagefill_width) * ffp->pagefill_width;
++		*tab++ = alignval;
++	}
++}
++
++extern Bool CreatorCreateGC (GCPtr pGC);
++
++#ifdef DEBUG_FFB
++FILE *FDEBUG_FD = NULL;
++#endif
++
++/* Exported for sunCfb24.c */
++miBSFuncRec CreatorBSFuncRec = {
++    CreatorSaveAreas,
++    CreatorRestoreAreas,
++    (void (*)()) 0,
++    (PixmapPtr (*)()) 0,
++    (PixmapPtr (*)()) 0,
++};
++
++int sunFFBAccelInit (ScreenPtr pScreen, fbFd *fb)
++{
++	CreatorPrivScreenPtr ffbPriv;
++	ffb_fbcPtr ffb;
++
++	if (serverGeneration != CreatorGeneration) {
++		CreatorScreenPrivateIndex = AllocateScreenPrivateIndex ();
++		if (CreatorScreenPrivateIndex == -1) return FALSE;
++		CreatorGCPrivateIndex = AllocateGCPrivateIndex ();
++		CreatorWindowPrivateIndex = AllocateWindowPrivateIndex ();
++		CreatorGeneration = serverGeneration;
++	}
++	
++	/* Allocate private structures holding pointer to both videoRAM and control registers.
++	   We do not have to map these by ourselves, because the XServer did it for us; we
++	   only copy the pointers to out structures. */
++	if (!AllocateGCPrivate(pScreen, CreatorGCPrivateIndex, sizeof(CreatorPrivGCRec))) return FALSE;
++	if (!AllocateWindowPrivate(pScreen, CreatorWindowPrivateIndex, 0)) return FALSE;
++	pScreen->devPrivates[CreatorScreenPrivateIndex].ptr = xalloc(sizeof (CreatorPrivScreenRec));
++	ffbPriv = CreatorGetScreenPrivate (pScreen); 
++	ffbPriv->fifo_cache = 0;
++	ffbPriv->regs = ffb = (ffb_fbcPtr) fb->private;
++	ffbPriv->dfb24 = (unsigned *) fb->fb;
++	ffbPriv->sfb32 = (unsigned *)
++		sunMemoryMap (0x1000000, FFB_SFB32_VOFF, fb - sunFbs);
++	if (!ffbPriv->sfb32)
++		return FALSE;
++	ffbPriv->strapping_bits = (volatile unsigned int *)
++		sunMemoryMap (8192, FFB_EXP_VOFF, fb - sunFbs);
++	if (!ffbPriv->strapping_bits)
++		return FALSE;
++#if 0
++	ErrorF("STRAPPING BITS [%08x] [%02x]\n",
++	       *(ffbPriv->strapping_bits),
++	       *((volatile unsigned char *)ffbPriv->strapping_bits));
++#endif
++	/* Now probe for the type of FFB/AFB chip we have. */
++	{
++		volatile unsigned int *afb_fem;
++		unsigned int val;
++
++		afb_fem = ((volatile unsigned int *)
++			   ((char *)ffb + 0x1540));
++		val = *afb_fem;
++		val &= 0xff;
++		if (val == 0x3f || val == 0x07) {
++			if (val == 0x3f) {
++				ffbPriv->ffb_type = afb_m6;
++				ErrorF("AFB: Detected Elite3D/M6.\n");
++			} else {
++				ffbPriv->ffb_type = afb_m3;
++				ErrorF("AFB: Detected Elite3D/M3.\n");
++			}
++		} else {
++			unsigned char sbits = *((volatile unsigned char *)ffbPriv->strapping_bits);
++			sbits = *((volatile unsigned char *)ffbPriv->strapping_bits);
++			switch (sbits & 0x78) {
++			case (0x0 << 5) | (0x0 << 3):
++				ffbPriv->ffb_type = ffb1_prototype;
++				ErrorF("FFB: Detected FFB1 pre-FCS prototype, ");
++				break;
++			case (0x0 << 5) | (0x1 << 3):
++				ffbPriv->ffb_type = ffb1_standard;
++				ErrorF("FFB: Detected FFB1, ");
++				break;
++			case (0x0 << 5) | (0x3 << 3):
++				ffbPriv->ffb_type = ffb1_speedsort;
++				ErrorF("FFB: Detected FFB1-SpeedSort, ");
++				break;
++			case (0x1 << 5) | (0x0 << 3):
++				ffbPriv->ffb_type = ffb2_prototype;
++				ErrorF("FFB: Detected FFB2/vertical pre-FCS prototype, ");
++				break;
++			case (0x1 << 5) | (0x1 << 3):
++				ffbPriv->ffb_type = ffb2_vertical;
++				ErrorF("FFB: Detected FFB2/vertical, ");
++				break;
++			case (0x1 << 5) | (0x2 << 3):
++				ffbPriv->ffb_type = ffb2_vertical_plus;
++				ErrorF("FFB: Detected FFB2+/vertical, ");
++				break;
++			case (0x2 << 5) | (0x0 << 3):
++				ffbPriv->ffb_type = ffb2_horizontal;
++				ErrorF("FFB: Detected FFB2/horizontal, ");
++				break;
++			case (0x2 << 5) | (0x2 << 3):
++				ffbPriv->ffb_type = ffb2_horizontal;
++				ErrorF("FFB: Detected FFB2+/horizontal, ");
++				break;
++			default:
++				ffbPriv->ffb_type = ffb2_vertical;
++				ErrorF("FFB: Unknown boardID[%08x], assuming FFB2, ", sbits);
++				break;
++			};
++			if (sbits & (1 << 2))
++				ErrorF("DoubleRES, ");
++			if (sbits & (1 << 1))
++				ErrorF("Z-buffer, ");
++			if (sbits & (1 << 0))
++				ErrorF("Double-buffered.\n");
++			else
++				ErrorF("Single-buffered.\n");
++		}
++	}
++
++	((PixmapPtr)pScreen->devPrivates [cfb32ScreenPrivateIndex].ptr)->devPrivate.ptr = ffbPriv->sfb32;
++	ffbPriv->fb = ffbPriv->sfb32;
++	fb->fb = (unsigned char *)ffbPriv->sfb32;
++		
++	/* Replace various screen functions. */
++	pScreen->CreateGC = CreatorCreateGC;
++	pScreen->CreateWindow = CreatorCreateWindow;
++	pScreen->ChangeWindowAttributes = CreatorChangeWindowAttributes;
++	pScreen->DestroyWindow = CreatorDestroyWindow;
++	pScreen->PaintWindowBackground = CreatorPaintWindow;
++	pScreen->PaintWindowBorder = CreatorPaintWindow;
++	pScreen->GetSpans = CreatorGetSpans;
++#ifdef USE_VIS
++	pScreen->CopyWindow = CreatorCopyWindow;
++	pScreen->GetImage = CreatorGetImage;
++	/* We used to write over the cfbBSFuncRec members here,
++	 * that was evil and wrong.  If we do that, and have one
++	 * FFB in accelerated mode, and another not (f.e. Elite3D
++	 * without firmware loaded) we crash at the first backing
++	 * store operation.  So instead we handle this properly
++	 * via CreatorBSFuncRec and some code in sunCfb24.c
++	 */
++#endif
++
++	/* Set FFB line-bias for clipping. */
++	miSetZeroLineBias(pScreen, OCTANT3 | OCTANT4 | OCTANT6 | OCTANT1);
++
++	FFB_DEBUG_init();
++#if 0
++	FDEBUG("FFB: cfg0(%08x) cfg1(%08x) cfg2(%08x) cfg3(%08x) ppcfg(%08x)\n",
++	       ffb->fbcfg0, ffb->fbcfg1, ffb->fbcfg2, ffb->fbcfg3, ffb->ppcfg);
++#endif
++
++	/* Determine the screen resolution active, needed to figure out
++	 * the fastfill/pagefill parameters.
++	 */
++	switch(ffb->fbcfg0 & FFB_FBCFG0_RES_MASK) {
++	default:
++	case FFB_FBCFG0_RES_STD:
++		ffbPriv->ffb_res = ffb_res_standard;
++		break;
++	case FFB_FBCFG0_RES_HIGH:
++		ffbPriv->ffb_res = ffb_res_high;
++		break;
++	case FFB_FBCFG0_RES_STEREO:
++		ffbPriv->ffb_res = ffb_res_stereo;
++		break;
++	case FFB_FBCFG0_RES_PRTRAIT:
++		ffbPriv->ffb_res = ffb_res_portrait;
++		break;
++	};
++	CreatorAlignTabInit(ffbPriv);
++
++	/* Next, determine the hwbug workarounds and feature enables
++	 * we should be using on this board.
++	 */
++	ffbPriv->disable_pagefill = 0;
++	ffbPriv->disable_vscroll = 0;
++	ffbPriv->has_brline_bug = 0;
++	ffbPriv->use_blkread_prefetch = 0;
++	if (ffbPriv->ffb_type == ffb1_prototype ||
++	    ffbPriv->ffb_type == ffb1_standard ||
++	    ffbPriv->ffb_type == ffb1_speedsort) {
++		ffbPriv->has_brline_bug = 1;
++		if (ffbPriv->ffb_res == ffb_res_high)
++			ffbPriv->disable_vscroll = 1;
++		if (ffbPriv->ffb_res == ffb_res_high ||
++		    ffbPriv->ffb_res == ffb_res_stereo)
++			ffbPriv->disable_pagefill = 1;
++
++	} else {
++		/* FFB2 has blkread prefetch.  AFB supposedly does too
++		 * but the chip locks up on me when I try to use it. -DaveM
++		 */
++#define AFB_PREFETCH_IS_BUGGY	1
++		if (!AFB_PREFETCH_IS_BUGGY ||
++		    (ffbPriv->ffb_type != afb_m3 &&
++		     ffbPriv->ffb_type != afb_m6)) {
++			ffbPriv->use_blkread_prefetch = 1;
++		}
++		/* XXX I still cannot get page/block fast fills
++		 * XXX to work reliably on any of my AFB boards. -DaveM
++		 */
++#define AFB_FASTFILL_IS_BUGGY	1
++		if (AFB_FASTFILL_IS_BUGGY &&
++		    (ffbPriv->ffb_type == afb_m3 ||
++		     ffbPriv->ffb_type == afb_m6))
++			ffbPriv->disable_pagefill = 1;
++	}
++	ffbPriv->disable_fastfill_ap = 0;
++	if (ffbPriv->ffb_res == ffb_res_stereo ||
++	    ffbPriv->ffb_res == ffb_res_high)
++		ffbPriv->disable_fastfill_ap = 1;
++
++	ffbPriv->ppc_cache = (FFB_PPC_FW_DISABLE|
++			      FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST|
++			      FFB_PPC_XS_CONST|FFB_PPC_YS_CONST|FFB_PPC_ZS_CONST|
++			      FFB_PPC_DCE_DISABLE|FFB_PPC_ABE_DISABLE|FFB_PPC_TBE_OPAQUE);
++	ffbPriv->pmask_cache = ~0;
++	ffbPriv->rop_cache = FFB_ROP_ZERO;
++	ffbPriv->drawop_cache = FFB_DRAWOP_RECTANGLE;
++	ffbPriv->fg_cache = ffbPriv->bg_cache = 0;
++	ffbPriv->fontw_cache = 32;
++	ffbPriv->fontinc_cache = (1 << 16) | 0;
++	ffbPriv->fbc_cache = FFB_FBC_WB_A|FFB_FBC_WM_COMBINED|
++			     FFB_FBC_RB_A|FFB_FBC_SB_BOTH|FFB_FBC_XE_OFF|
++			     FFB_FBC_ZE_OFF|FFB_FBC_YE_OFF|FFB_FBC_RGBE_MASK;
++	ffbPriv->laststipple = NULL;
++
++	/* We will now clear the screen: we'll draw a rectangle covering all the
++	 * viewscreen, using a 'blackness' ROP.
++	 */
++	FFBFifo(ffbPriv, 13);
++	ffb->fbc = ffbPriv->fbc_cache;
++	ffb->ppc = ffbPriv->ppc_cache;
++	ffb->pmask = ffbPriv->pmask_cache;
++	ffb->rop = ffbPriv->rop_cache;
++	ffb->drawop = ffbPriv->drawop_cache;
++	ffb->fg = ffbPriv->fg_cache;
++	ffb->bg = ffbPriv->bg_cache;
++	ffb->fontw = ffbPriv->fontw_cache;
++	ffb->fontinc = ffbPriv->fontinc_cache;
++	FFB_WRITE64(&ffb->by, 0, 0);
++	FFB_WRITE64_2(&ffb->bh, fb->info.fb_height, fb->info.fb_width);
++	ffbPriv->rp_active = 1;
++	FFBWait(ffbPriv, ffb);
++	
++#ifdef linux
++	fb->vtchange = CreatorVtChange;
++	fb->DoBitblt = CreatorDoBitbltWrapper;
++#endif
++
++	/* Success */
++	return TRUE;
++}
+--- xc/programs/Xserver/hw/sun/FFB/sunFFB.h.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/sunFFB.h	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,221 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - defines.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#ifndef FFB_H
++#define FFB_H
++
++#include "Xmd.h"
++#include "gcstruct.h"
++#include "FFBregs.h"
++
++/* Various offsets in virtual (ie. mmap()) spaces Linux and Solaris support. */
++/* Note: do not mmap FFB_DFB8R_VOFF and following mappings using one mmap together
++   with any previous SFB mapping, otherwise the OS won't be able to use 4M pages
++   for the DFB mappings. -jj */
++#define	FFB_SFB8R_VOFF		0x00000000
++#define	FFB_SFB8G_VOFF		0x00400000
++#define	FFB_SFB8B_VOFF		0x00800000
++#define	FFB_SFB8X_VOFF		0x00c00000
++#define	FFB_SFB32_VOFF		0x01000000
++#define	FFB_SFB64_VOFF		0x02000000
++#define	FFB_FBC_REGS_VOFF	0x04000000
++#define	FFB_BM_FBC_REGS_VOFF	0x04002000
++#define	FFB_DFB8R_VOFF		0x04004000
++#define	FFB_DFB8G_VOFF		0x04404000
++#define	FFB_DFB8B_VOFF		0x04804000
++#define	FFB_DFB8X_VOFF		0x04c04000
++#define	FFB_DFB24_VOFF		0x05004000
++#define	FFB_DFB32_VOFF		0x06004000
++#define	FFB_DFB422A_VOFF	0x07004000	/* DFB 422 mode write to A */
++#define	FFB_DFB422AD_VOFF	0x07804000	/* DFB 422 mode with line doubling */
++#define	FFB_DFB24B_VOFF		0x08004000	/* DFB 24bit mode write to B */
++#define	FFB_DFB422B_VOFF	0x09004000	/* DFB 422 mode write to B */
++#define	FFB_DFB422BD_VOFF	0x09804000	/* DFB 422 mode with line doubling */
++#define	FFB_SFB16Z_VOFF		0x0a004000	/* 16bit mode Z planes */
++#define	FFB_SFB8Z_VOFF		0x0a404000	/* 8bit mode Z planes */
++#define	FFB_SFB422_VOFF		0x0ac04000	/* SFB 422 mode write to A/B */
++#define	FFB_SFB422D_VOFF	0x0b404000	/* SFB 422 mode with line doubling */
++#define	FFB_FBC_KREGS_VOFF	0x0bc04000
++#define	FFB_DAC_VOFF		0x0bc06000
++#define	FFB_PROM_VOFF		0x0bc08000
++#define	FFB_EXP_VOFF		0x0bc18000
++ 
++#if defined(__GNUC__) && defined(USE_VIS)
++#define FFB_ALIGN64	__attribute__((aligned(8)))
++#else
++#define FFB_ALIGN64
++#endif
++
++typedef struct {
++	unsigned int fg FFB_ALIGN64, bg;	/* FG/BG colors for stipple	*/
++	unsigned int patalign;			/* X/Y alignment of bits	*/
++	unsigned char alu;			/* ALU operation		*/
++	unsigned char inhw;			/* Cached in FFB		*/
++	unsigned char pagable;			/* Can be used in a pagefill	*/
++	unsigned char ph;			/* Page buffer height		*/
++	unsigned int bits[32];			/* The stipple bits themselves	*/
++} CreatorStippleRec, *CreatorStipplePtr;
++
++typedef struct {
++	int type;
++	unsigned int linepat;
++	CreatorStipplePtr stipple;
++	void (*PolyGlyphBlt) (DrawablePtr, GCPtr, int, int, unsigned int, CharInfoPtr *, pointer);
++	void (*ImageGlyphBlt) (DrawablePtr, GCPtr, int, int, unsigned int, CharInfoPtr *, pointer);
++	void (*FillSpans) (DrawablePtr, GCPtr, int, DDXPointPtr, int *, int);
++	void (*Polylines)(DrawablePtr, GCPtr, int, int, DDXPointPtr);
++	void (*PolySegment)(DrawablePtr, GCPtr, int, xSegment *);
++	void (*FillPolygon)(DrawablePtr, GCPtr, int, int, int, DDXPointPtr);
++} CreatorPrivGCRec, *CreatorPrivGCPtr;
++
++enum ffb_resolution {
++	ffb_res_standard = 0,	/* 1280 x 1024 */
++	ffb_res_high,		/* 1920 x 1360 */
++	ffb_res_stereo,		/* 960  x 580 */
++	ffb_res_portrait	/* 1280 x 2048 */
++};
++
++enum ffb_chip_type {
++	ffb1_prototype = 0,	/* Early pre-FCS FFB */
++	ffb1_standard,		/* First FCS FFB, 100Mhz UPA, 66MHz gclk */
++	ffb1_speedsort,		/* Second FCS FFB, 100Mhz UPA, 75MHz gclk */
++	ffb2_prototype,		/* Early pre-FCS vertical FFB2 */
++	ffb2_vertical,		/* First FCS FFB2/vertical, 100Mhz UPA, 100MHZ gclk,
++				   75(SingleBuffer)/83(DoubleBuffer) MHz fclk */
++	ffb2_vertical_plus,	/* Second FCS FFB2/vertical, same timings */
++	ffb2_horizontal,	/* First FCS FFB2/horizontal, same timings as FFB2/vert */
++	ffb2_horizontal_plus,	/* Second FCS FFB2/horizontal, same timings */
++	afb_m3,			/* FCS Elite3D, 3 float chips */
++	afb_m6			/* FCS Elite3D, 6 float chips */
++};
++
++typedef struct {
++	unsigned short fifo_cache;
++	unsigned short rp_active;
++	ffb_fbcPtr regs;
++	unsigned int ppc_cache;
++	unsigned int pmask_cache;
++	unsigned int rop_cache;
++	unsigned int drawop_cache;
++	unsigned int fg_cache;
++	unsigned int bg_cache;
++	unsigned int fontw_cache;
++	unsigned int fontinc_cache;
++	unsigned int fbc_cache;
++	enum ffb_chip_type ffb_type;
++	CreatorStipplePtr laststipple;
++	unsigned *fb;
++	unsigned *sfb32;
++	unsigned *dfb24;
++
++	/* Slot offset 0x0200000, used to probe board type. */
++	volatile unsigned int *strapping_bits;
++
++	/* Needed for some 3DRAM revisions and ffb1 in hires */
++	unsigned char disable_pagefill;
++
++	/* Needed for FFB2/AFB when in stereo or hires */
++	unsigned char disable_fastfill_ap;
++
++	/* Needed for FFB1 in highres mode */
++	unsigned char disable_vscroll;
++
++	/* Needed on all FFB1 boards. */
++	unsigned char has_brline_bug;
++
++	/* Available on FFB2 and AFB */
++	unsigned char use_blkread_prefetch;
++
++	enum ffb_resolution ffb_res;
++	BoxRec ClippedBoxBuf[64];
++	xRectangle Pf_Fixups[4];
++	short Pf_AlignTab[0x800];
++} CreatorPrivScreenRec, *CreatorPrivScreenPtr;
++
++/* The fastfill and pagefill buffer sizes change based upon
++ * the resolution.
++ */
++struct fastfill_parms {
++	int	fastfill_small_area;
++	int	pagefill_small_area;
++
++	int	fastfill_height;
++	int	fastfill_width;
++	int	pagefill_height;
++	int	pagefill_width;
++};
++
++extern struct fastfill_parms ffb_fastfill_parms[];
++
++#define FFB_FFPARMS(__fpriv)	(ffb_fastfill_parms[(__fpriv)->ffb_res])
++
++extern int  CreatorScreenPrivateIndex;
++extern int  CreatorGCPrivateIndex;
++extern int  CreatorWindowPrivateIndex;
++
++#define CreatorGetScreenPrivate(s)					\
++((CreatorPrivScreenPtr) (s)->devPrivates[CreatorScreenPrivateIndex].ptr)
++
++#define CreatorGetGCPrivate(g)						\
++((CreatorPrivGCPtr) (g)->devPrivates [CreatorGCPrivateIndex].ptr)
++
++#define CreatorGetWindowPrivate(w)					\
++((CreatorStipplePtr) (w)->devPrivates[CreatorWindowPrivateIndex].ptr)
++                            
++#define CreatorSetWindowPrivate(w,p) 					\
++((w)->devPrivates[CreatorWindowPrivateIndex].ptr = (pointer) p)
++
++#undef DEBUG_FFB
++
++#ifdef DEBUG_FFB
++
++#include <stdio.h>
++
++extern FILE *FDEBUG_FD;
++
++static __inline__ void FFB_DEBUG_init(void)
++{
++	FDEBUG_FD = fopen("/tmp/FFB.DEBUG", "a");
++}
++#define FDEBUG(__x, __a...)	\
++do {	fprintf(FDEBUG_FD, __x, ## __a); \
++	fflush(FDEBUG_FD); \
++} while(0)
++#else
++#define FFB_DEBUG_init()	do { } while(0)
++#define FDEBUG(__x, __a...)	do { } while(0)
++#endif
++
++/* Enable this to get very verbose tracing of the driver onto stderr. */
++#undef TRACE_FFB
++#ifdef TRACE_FFB
++#define FFBLOG(__x, __a...)	ErrorF(__x, ## __a)
++#else
++#define FFBLOG(__x, __a...)	do { } while(0)
++#endif
++
++#endif /* FFB_H */
+--- xc/programs/Xserver/hw/sun/FFB/sunFFBasm.s.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/sunFFBasm.s	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,344 @@
++/* $Id$
++ * sunFFBasm.S: Fast Creator raster op inner loops.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++ */
++
++/* Hardware register offsets */
++#define FFB_BY		0x0060
++#define FFB_DY		0x0068
++#define FFB_BH		0x0070
++#define FFB_PPC		0x0200
++#define FFB_DRAWOP	0x0300
++#define FFB_UCSR	0x0900
++
++#define FFB_DRAWOP_VSCROLL	0x0b
++
++#define FIFO_CACHE	0x00
++
++#define BOX_X1		0x00
++#define BOX_Y1		0x02
++#define BOX_X2		0x04
++#define BOX_Y2		0x06
++
++#define POINT_X		0x00
++#define POINT_Y		0x02
++
++#define RECT_X		0x00
++#define RECT_Y		0x02
++#define RECT_W		0x04
++#define RECT_H		0x06
++
++#define SEG_X1		0x00
++#define SEG_Y1		0x02
++#define SEG_X2		0x04
++#define SEG_Y2		0x06
++
++	.text
++
++	.align	32
++	.globl	FFB_STIPPLE_LOAD
++	/* %o0 = &ffbregs->pattern[0]
++	 * %o1 = &stipple->bits[0]
++	 */
++FFB_STIPPLE_LOAD:
++	cmp	%g0, 0
++1:	ldx	[%o1 + 0x00], %g1
++	ldx	[%o1 + 0x08], %g2
++	ldx	[%o1 + 0x10], %g3
++
++	ldx	[%o1 + 0x18], %g4
++	add	%o0, 0x40, %o0
++	ldx	[%o1 + 0x20], %g5
++	ldx	[%o1 + 0x28], %o2
++
++	ldx	[%o1 + 0x30], %o3
++	ldx	[%o1 + 0x38], %o4
++	stx	%g1, [%o0 - 0x40]
++	stx	%g2, [%o0 - 0x38]
++
++	stx	%g3, [%o0 - 0x30]
++	stx	%g4, [%o0 - 0x28]
++	add	%o1, 0x40, %o1
++	stx	%g5, [%o0 - 0x20]
++
++	stx	%o2, [%o0 - 0x18]
++	stx	%o3, [%o0 - 0x10]
++	stx	%o4, [%o0 - 0x08]
++	be,pt	%icc, 1b
++
++	 cmp	%g0, 1
++	retl
++	 nop
++
++#define	FIFO_WAIT(ffbregs, goal, this_label, done_label) \
++this_label: \
++	lduw	[ffbregs + FFB_UCSR], %g1; \
++	and	%g1, 0xfff, %g1; \
++	subcc	%g1, (4 + goal), %g1; \
++	bge,pt	%icc, done_label; \
++	 nop; \
++	ba,a,pt	%xcc, this_label
++
++	.align	32
++	.globl	FFB_PPT_BOX_LOOP
++	/* This is only used (currently) by vscroll, so we put
++	 * the creator hwbug workaround in here (writing
++	 * the drawop each iteration).
++	 *
++	 * %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = pbox, %o3 = pbox_last, %o4 = ppt
++	 */
++FFB_PPT_BOX_LOOP:
++	lduh	[%o0 + FIFO_CACHE], %g1	/* Load		Group		*/
++	sethi	%hi(FFB_DRAWOP), %g2	/* IEU0				*/
++	cmp	%o2, %o3		/* IEU1				*/
++	bgu,pn	%icc, 2f		/* CTI				*/
++
++	 or	%g2,%lo(FFB_DRAWOP),%g2	/* IEU0		Group		*/
++1:	lduh	[%o4 + POINT_X], %g3	/* Load		Group		*/
++	lduh	[%o4 + POINT_Y], %g4	/* Load		Group		*/
++	lduh	[%o2 + BOX_Y2], %g5	/* Load		Group		*/
++
++	lduh	[%o2 + BOX_Y1], %o5	/* Load		Group		*/
++	sllx	%g4, 32, %g4		/* IEU0				*/
++	or	%g3, %g4, %g3		/* IEU0		Group		*/
++	sub	%g5, %o5, %g5		/* IEU1				*/
++
++	sllx	%o5, 32, %g4		/* IEU0		Group		*/
++	sllx	%g5, 32, %g5		/* IEU0		Group		*/
++	lduh	[%o2 + BOX_X2], %o5	/* Load				*/
++	add	%o4, 0x4, %o4		/* IEU1				*/
++
++	lduh	[%o2 + BOX_X1], %g7	/* Load		Group		*/
++	add	%o2, 0x8, %o2		/* IEU0				*/
++	sub	%o5, %g7, %o5		/* IEU0		Group		*/
++	or	%g4, %g7, %g4		/* IEU1				*/
++
++	or	%g5, %o5, %g5		/* IEU0		Group		*/
++	subcc	%g1, 7, %g1		/* IEU1				*/
++	bl,pn	%icc, FFB_PPT_BOX_WAIT	/* CTI				*/
++9:	 cmp	%o2, %o3		/* IEU1		Group		*/
++
++	/* This works around BUG ID 1189858 -DaveM */
++	mov	FFB_DRAWOP_VSCROLL, %o5	/* IEU0				*/
++	stw	%o5, [%o1 + %g2]	/* STORE			*/
++	stx	%g3, [%o1 + FFB_BY]	/* STORE	Group		*/
++	stx	%g4, [%o1 + FFB_DY]	/* STORE	Group		*/
++
++	bleu,pt	%icc, 1b		/* CTI				*/
++	 stx	%g5, [%o1 + FFB_BH]	/* STORE	Group		*/
++2:	retl				/* CTI		Group		*/
++	 sth	%g1, [%o0 + FIFO_CACHE]	/* STORE			*/
++
++	FIFO_WAIT(%o1, 7, FFB_PPT_BOX_WAIT, 9b)
++
++	.align	32
++	.globl	FFB_BOX_LOOP
++	/* %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = pbox, %o3 = pbox_last
++	 */
++FFB_BOX_LOOP:
++	lduh	[%o0 + FIFO_CACHE], %g1	/* Load		Group		*/
++	cmp	%o2, %o3		/* IEU0				*/
++	bgu,pn	%icc, 2f		/* CTI				*/
++	 nop				/* IEU0		Group		*/
++
++1:	lduw	[%o2 + BOX_X1], %g4	/* Load		Group		*/
++	lduw	[%o2 + BOX_X2], %g3	/* Load		Group		*/
++	sllx	%g4, 32, %o5		/* IEU0				*/
++	srl	%g4, 16, %g7		/* IEU0		Group		*/
++
++	add	%o2, 8, %o2		/* IEU1				*/
++	sllx	%g3, 32, %g5		/* IEU0		Group		*/
++	subcc	%g1, 4, %g1		/* IEU1				*/
++	srl	%g3, 16, %o4		/* IEU0		Group		*/
++
++	or	%o5, %g7, %o5		/* IEU1				*/
++	or	%g5, %o4, %g5		/* IEU0		Group		*/
++	bl,pn	%icc, FFB_BOX_WAIT	/* CTI				*/
++	 sub	%g5, %o5, %g5		/* IEU0		Group		*/
++
++9:	cmp	%o2, %o3		/* IEU1				*/
++	stx	%o5, [%o1 + FFB_BY]	/* Store			*/
++	bleu,pt	%icc, 1b		/* CTI		Group		*/
++	 stx	%g5, [%o1 + FFB_BH]	/* Store			*/
++2:	retl				/* CTI		Group		*/
++	 sth	%g1, [%o0 + FIFO_CACHE]	/* Store			*/
++
++	FIFO_WAIT(%o1, 4, FFB_BOX_WAIT, 9b)
++
++	.align	32
++	.globl	FFB_RECT_LOOP
++	/* %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = prect, %o3 = prect_last,
++	 * %o4 = xOrg, %o5 = yOrg
++	 */
++FFB_RECT_LOOP:
++	lduh	[%o0 + FIFO_CACHE], %g1	/* Load		Group		*/
++	sllx	%o5, 32, %o5		/* IEU0				*/
++	cmp	%o2, %o3		/* IEU1				*/
++	bgu,pn	%icc, 2f		/* CTI				*/
++
++	 or	%o4, %o5, %o4		/* IEU0		Group		*/
++1:	lduh	[%o2 + RECT_X], %g4	/* Load		Group		*/
++	lduh	[%o2 + RECT_Y], %o5	/* Load		Group		*/
++	lduh	[%o2 + RECT_W], %g3	/* Load		Group		*/
++
++	lduh	[%o2 + RECT_H], %g2	/* Load		Group		*/
++	sllx	%o5, 32, %g7		/* IEU0				*/
++	add	%o2, 8, %o2		/* IEU1				*/
++	orcc	%g7, %g4, %g7		/* IEU1		Group		*/
++
++	sllx	%g2, 32, %g5		/* IEU0				*/
++	or	%g5, %g3, %g5		/* IEU0		Group		*/
++	add	%g7, %o4, %g7		/* IEU1				*/
++	subcc	%g1, 4, %g1		/* IEU1		Group		*/
++
++	bl,pn	%icc, FFB_RECT_WAIT	/* CTI				*/
++9:	 cmp	%o2, %o3		/* IEU1		Group		*/
++	stx	%g7, [%o1 + FFB_BY]	/* Store			*/
++	bleu,pt	%icc, 1b		/* CTI				*/
++
++	 stx	%g5, [%o1 + FFB_BH]	/* Store	Group		*/
++2:	retl				/* CTI		Group		*/
++	 sth	%g1, [%o0 + FIFO_CACHE]	/* Store			*/
++
++	FIFO_WAIT(%o1, 4, FFB_RECT_WAIT, 9b)
++
++	.align	32
++	.globl	FFB_PPT_WIDTH_LOOP
++	/* %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = ppt, %o3 = ppt_last,
++	 * %o4 = pwidth
++	 */
++FFB_PPT_WIDTH_LOOP:
++	lduh	[%o0 + FIFO_CACHE], %g1	/* Load		Group		*/
++	cmp	%o2, %o3		/* IEU1				*/
++	bgu,pn	%icc, 2f		/* CTI				*/
++	 nop
++
++8:	lduw	[%o2 + POINT_X], %g4	/* Load		Group		*/
++	lduw	[%o4], %g2		/* Load		Group		*/
++	sllx	%g4, 32, %g7
++1:	srl	%g4, 16, %g5		/* IEU0		Group		*/
++
++	add	%o2, 4, %o2		/* IEU1				*/
++	brz,pn	%g2, 8b			/* CTI+IEU1	Group		*/
++	 add	%o4, 4, %o4		/* IEU0				*/
++	or	%g5, %g7, %g7		/* IEU0		Group		*/
++
++	subcc	%g1, 5, %g1		/* IEU1				*/
++	bl,pn	%icc, FFB_PPT_WIDTH_WAIT/* CTI				*/
++	 add	%g7, %g2, %o5		/* IEU0		Group		*/
++9:	stw	%g0, [%o1 + FFB_PPC]	/* Store	Group		*/
++
++	cmp	%o2, %o3		/* IEU1				*/
++	stx	%g7, [%o1 + FFB_BY]	/* Store	Group		*/
++	bleu,pt	%icc, 8b		/* CTI				*/
++	 stx	%o5, [%o1 + FFB_BH]	/* Store	Group		*/
++
++2:	retl				/* CTI		Group		*/
++	 sth	%g1, [%o0 + FIFO_CACHE]	/* Store			*/
++
++	FIFO_WAIT(%o1, 5, FFB_PPT_WIDTH_WAIT, 9b)
++
++	.align	32
++	.globl	FFB_LINE_LOOP1
++	/* %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = ppt, %o3 = ppt_last,
++	 * %o4 = xOrg, %o5 = yOrg
++	 *
++	 * We return ppt_last + 1.
++	 */
++FFB_LINE_LOOP1:
++	lduh	[%o0 + FIFO_CACHE], %g1
++	sllx	%o5, 32, %o5
++	and	%o4, 0x7ff, %o4
++	cmp	%o2, %o3
++
++	bgu,pn	%icc, 2f
++	 or	%o4, %o5, %o4
++1:	lduw	[%o2 + POINT_X], %g4
++	sllx	%g4, 32, %g7
++
++	srl	%g4, 16, %g3
++	add	%o2, 4, %o2
++	or	%g7, %g3, %g7
++	subcc	%g1, 3, %g1
++ 
++	bl,pn	%icc, FFB_LINE1_WAIT
++	 add	%g7, %o4, %g7
++9:	cmp	%o2, %o3
++	stw	%g0, [%o1 + FFB_PPC]
++
++	bleu,pt	%icc, 1b
++	 stx	%g7, [%o1 + FFB_BH]
++2:	nop
++	sth	%g1, [%o0 + FIFO_CACHE]
++
++	retl
++	 mov	%o2, %o0
++
++	FIFO_WAIT(%o1, 3, FFB_LINE1_WAIT, 9b)
++
++	.align	32
++	.globl	FFB_LINE_LOOP2
++	/* %o0 = ffbpriv, %o1 = ffbregs,
++	 * %o2 = ppt, %o3 = ppt_last,
++	 * %o4 = &xOrg, %o5 = &yOrg
++	 *
++	 * We return ppt_last + 1.
++	 * The only difference between the previous routine
++	 * is that here we accumulate the origin values.
++	 */
++FFB_LINE_LOOP2:
++	lduw	[%o5], %g5
++	lduw	[%o4], %g2
++	lduh	[%o0 + FIFO_CACHE], %g1
++	sllx	%g5, 32, %g5
++
++	and	%g2, 0x7ff, %g2
++	cmp	%o2, %o3
++	bgu,pn	%icc, 2f
++	 or	%g5, %g2, %g5
++
++1:	lduw	[%o2 + POINT_X], %g4
++	sllx	%g4, 32, %g7
++	srl	%g4, 16, %g3
++	add	%o2, 4, %o2
++ 
++	or	%g7, %g3, %g7
++	subcc	%g1, 3, %g1
++	bl,pn	%icc, FFB_LINE2_WAIT
++	 add	%g7, %g5, %g5
++
++9:	cmp	%o2, %o3
++	stw	%g0, [%o1 + FFB_PPC]
++	bleu,pt	%icc, 1b
++	 stx	%g5, [%o1 + FFB_BH]
++
++2:	sth	%g1, [%o0 + FIFO_CACHE]
++	srlx	%g5, 32, %g4
++	stw	%g5, [%o4]
++	stw	%g4, [%o5]
++
++	retl
++	 mov	%o2, %o0
++
++	FIFO_WAIT(%o1, 3, FFB_LINE2_WAIT, 9b)
+--- xc/programs/Xserver/hw/sun/FFB/FFBrect.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBrect.c	Thu Jan 13 11:31:13 2000
+@@ -0,0 +1,210 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Non-filled rects.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek   (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
++ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++#include "FFBclip.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++/* Heavily derived from mipolyrect.c code, see there for authors. */
++
++/* This about it, capping makes not a single difference ever,
++ * always the upper left corner coordinate will be pixelated.
++ */
++void
++CreatorPolyRectangle(DrawablePtr pDrawable, GCPtr pGC,
++		     int nrects, xRectangle *pRects)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	xRectangle *pR = pRects;
++	RegionPtr clip;
++	unsigned int ppc, line_drawop;
++	int bound_tmp, i, numRects;
++
++	if(VT_HIDDEN(pDrawable->pScreen)) {
++		miPolyRectangle(pDrawable, pGC, nrects, pRects);
++		return;
++	}
++	if(nrects <= 0)
++		return;
++	clip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
++	numRects = REGION_NUM_RECTS(clip);
++	if (!numRects)
++		return;
++	if(!(ppc = FFBSetClip(ffbPriv, ffb, clip, numRects))) {
++		miPolyRectangle(pDrawable, pGC, nrects, pRects);
++		return;
++	}
++	if(pGC->lineStyle == LineDoubleDash)
++		line_drawop = FFB_DRAWOP_DDLINE;
++	else
++		line_drawop = FFB_DRAWOP_BRLINECAP;
++	if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     ppc|FFB_PPC_APE_DISABLE|FFB_PPC_TBE_OPAQUE|
++				     FFB_PPC_XS_CONST|FFB_PPC_YS_CONST|FFB_PPC_ZS_CONST|FFB_PPC_CS_CONST,
++				     FFB_PPC_VCE_MASK|FFB_PPC_ACE_MASK|FFB_PPC_APE_MASK|FFB_PPC_TBE_MASK|
++				     FFB_PPC_XS_MASK|FFB_PPC_YS_MASK|FFB_PPC_ZS_MASK|FFB_PPC_CS_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     -1, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++		if(pGC->lineStyle == LineDoubleDash)
++			FFB_WRITE_BG(ffbPriv, ffb, pGC->bgPixel);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      ppc|
++			      FFB_PPC_XS_CONST|FFB_PPC_YS_CONST|FFB_PPC_ZS_CONST|FFB_PPC_CS_CONST,
++			      FFB_PPC_VCE_MASK|FFB_PPC_ACE_MASK|
++			      FFB_PPC_XS_MASK|FFB_PPC_YS_MASK|FFB_PPC_ZS_MASK|FFB_PPC_CS_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++
++#define MINBOUND(dst,eqn)	bound_tmp = eqn; \
++				if (bound_tmp < -32768) \
++				    bound_tmp = -32768; \
++				dst = bound_tmp;
++
++#define MAXBOUND(dst,eqn)	bound_tmp = eqn; \
++				if (bound_tmp > 32767) \
++				    bound_tmp = 32767; \
++				dst = bound_tmp;
++
++#define MAXUBOUND(dst,eqn)	bound_tmp = eqn; \
++				if (bound_tmp > 65535) \
++				    bound_tmp = 65535; \
++				dst = bound_tmp;
++
++	if (pGC->lineStyle == LineSolid &&
++	    pGC->joinStyle == JoinMiter &&
++	    pGC->lineWidth != 0) {
++		int ntmp;
++		int offset1, offset2, offset3;
++		int x, y, width, height;
++		int tx, ty, tw, th;
++
++		ntmp = (nrects << 2);
++		offset2 = pGC->lineWidth;
++		offset1 = offset2 >> 1;
++		offset3 = offset2 - offset1;
++		for (i = 0; i < nrects; i++) {
++			x = pR->x;
++			y = pR->y;
++			width = pR->width;
++			height = pR->height;
++			pR++;
++			if (width == 0 && height == 0) {
++				FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_DOT);
++				FFBFifo(ffbPriv, 2);
++				FFB_WRITE64(&ffb->bh, y + pDrawable->y, x + pDrawable->x);
++				continue;
++			}
++			FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_RECTANGLE);
++			if (height < offset2 || width < offset1) {
++				if (height == 0) {
++					tx = x;
++					tw = width;
++				} else {
++					MINBOUND (tx, x - offset1);
++					MAXUBOUND (tw, width + offset2);
++				}
++				if (width == 0) {
++					ty = y;
++					th = height;
++				} else {
++					MINBOUND (ty, y - offset1);
++					MAXUBOUND (th, height + offset2);
++				}
++				FFBFifo(ffbPriv, 4);
++				FFB_WRITE64(&ffb->by, ty + pDrawable->y, tx + pDrawable->x);
++				FFB_WRITE64_2(&ffb->bh, th, tw);
++			} else {
++				MINBOUND(tx, x - offset1);
++				MINBOUND(ty, y - offset1);
++				MAXUBOUND(tw, width + offset2);
++				th = offset2;
++				FFBFifo(ffbPriv, 13);
++				FFB_WRITE64(&ffb->by, ty + pDrawable->y, tx + pDrawable->x);
++				FFB_WRITE64_2(&ffb->bh, th, tw);
++				MAXBOUND(ty, y + offset3);
++				tw = offset2;
++				th = height - offset2;
++				ffb->by = ty + pDrawable->y;
++				FFB_WRITE64_2(&ffb->bh, th, tw);
++				MAXBOUND(tx, x + width - offset1);
++				ffb->bx = tx + pDrawable->x;
++				ffb->bw = tw;				
++				MINBOUND(tx, x - offset1);
++				MAXBOUND(ty, y + height - offset1);
++				MAXUBOUND(tw, width + offset2);
++				th = offset2;
++				FFB_WRITE64(&ffb->by, ty + pDrawable->y, tx + pDrawable->x);
++				FFB_WRITE64_2(&ffb->bh, th, tw);
++			}
++		}
++	} else {
++		int xOrg = pDrawable->x;
++		int yOrg = pDrawable->y;
++		unsigned int linepat = gcPriv->linepat;
++
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, line_drawop);
++		if(linepat == 0) {
++			FFBFifo(ffbPriv, 1);
++			ffb->lpat = 0;
++		}
++		for (i=0; i < nrects; i++) {
++			register int x0, xCoord, y0, yCoord;
++
++			x0 = xCoord = pR->x;
++			y0 = yCoord = pR->y;
++			FFBFifo(ffbPriv, 11);
++			if(linepat)
++				ffb->lpat = linepat;
++			else
++				ffb->ppc = 0;
++			FFB_WRITE64(&ffb->by, (yCoord + yOrg), (xCoord + xOrg));
++			MAXBOUND(xCoord, pR->x + (int) pR->width);
++			FFB_WRITE64(&ffb->bh, (yCoord + yOrg), (xCoord + xOrg));
++			MAXBOUND(yCoord, pR->y + (int) pR->height);
++			FFB_WRITE64_2(&ffb->bh, (yCoord + yOrg), (xCoord + xOrg));
++			FFB_WRITE64_3(&ffb->bh, (yCoord + yOrg), (x0 + xOrg));
++			FFB_WRITE64(&ffb->bh, (y0 + yOrg), (x0 + xOrg));
++			pR++;
++		}
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBsspans.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBsspans.c	Thu Jan 13 11:32:35 2000
+@@ -0,0 +1,145 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Set spans.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++/* PPC does all of the planemask and ROP'ing on the written pixels,
++ * and we know various other things are constant, so this is easy.
++ */
++static void
++CreatorSetScanline(int y, int xOrigin, int xStart, int xEnd,
++		   unsigned int *psrc, char *sfb)
++{
++	unsigned int *pdst = (unsigned int *)(sfb +
++					      (y << 13) +
++					      (xStart << 2));
++	int w = xEnd - xStart;
++
++	psrc += (xStart - xOrigin);
++	while(w--)
++		*pdst++ = *psrc++;
++}
++
++void
++CreatorSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *pcharsrc,
++		DDXPointPtr ppt, int *pwidth, int nspans, int fSorted)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	unsigned int *psrc = (unsigned int *)pcharsrc;
++	BoxPtr pbox, pboxLast, pboxTest;
++	DDXPointPtr pptLast;
++	RegionPtr prgnDst;
++	char *addrp;
++	int xStart, xEnd, yMax;
++
++	if(VT_HIDDEN(pDrawable->pScreen) ||
++	   pDrawable->type != DRAWABLE_WINDOW) {
++		cfbSetSpans(pDrawable, pGC, pcharsrc, ppt,
++			    pwidth, nspans, fSorted);
++		return;
++	}
++	FFBLOG("CreatorSetSpans: ALU(%x) PMSK(%08x) nspans(%d) fsorted(%d)\n",
++	       pGC->alu, pGC->planemask, nspans, fSorted);
++	if (pGC->alu == GXnoop)
++		return;
++
++	/* Get SFB ready. */
++	FFB_WRITE_ATTRIBUTES_SFB_VAR(ffbPriv, pGC->planemask, pGC->alu);
++	FFBWait(ffbPriv, ffb);
++
++	addrp = (char *) ffbPriv->fb;
++	yMax = (int) pDrawable->y + (int) pDrawable->height;
++	prgnDst = cfbGetCompositeClip(pGC);
++	pbox = REGION_RECTS(prgnDst);
++	pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
++	pptLast = ppt + nspans;
++	if(fSorted) {
++		pboxTest = pbox;
++		while(ppt < pptLast) {
++			pbox = pboxTest;
++			if(ppt->y >= yMax)
++				break;
++			while(pbox < pboxLast) {
++				if(pbox->y1 > ppt->y) {
++					break;
++				} else if(pbox->y2 <= ppt->y) {
++					pboxTest = ++pbox;
++					continue;
++				} else if(pbox->x1 > ppt->x + *pwidth) {
++					break;
++				} else if(pbox->x2 <= ppt->x) {
++					pbox++;
++					continue;
++				}
++				xStart = max(pbox->x1, ppt->x);
++				xEnd = min(ppt->x + *pwidth, pbox->x2);
++				CreatorSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, addrp);
++				if(ppt->x + *pwidth <= pbox->x2)
++					break;
++				else
++					pbox++;
++			}
++			ppt++;
++			psrc += *pwidth++;
++		}
++	} else {
++		while(ppt < pptLast) {
++			if(ppt->y >= 0 && ppt->y < yMax) {
++				for(pbox = REGION_RECTS(prgnDst); pbox < pboxLast; pbox++) {
++					if(pbox->y1 > ppt->y) {
++						break;
++					} else if(pbox->y2 <= ppt->y) {
++						pbox++;
++						break;
++					}
++					if(pbox->x1 <= ppt->x + *pwidth &&
++					   pbox->x2 > ppt->x) {
++						xStart = max(pbox->x1, ppt->x);
++						xEnd = min(pbox->x2, ppt->x + *pwidth);
++						CreatorSetScanline(ppt->y, ppt->x,
++								   xStart, xEnd,
++								   psrc, addrp);
++					}
++				}
++			}
++			ppt++;
++			psrc += *pwidth++;
++		}
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBgspans.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBgspans.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,93 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Get spans.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++#include "cfb/cfbmskbits.h"
++
++void
++CreatorGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
++		int *pwidth, int nspans, char *pchardstStart)
++{
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	unsigned int *pdst = (unsigned int *)pchardstStart;
++	char *addrp = (char *) ffbPriv->fb;
++	int w;
++
++	FFBLOG("CreatorGetSpans: wmax(%d) nspans(%d)\n", wMax, nspans);
++
++	/* Punt early for this case. */
++	if(pDrawable->bitsPerPixel == 1) {
++		mfbGetSpans(pDrawable, wMax, ppt, pwidth,
++			    nspans, pchardstStart);
++		return;
++	}
++
++	/* This code only works when sucking bits directly from
++	 * the framebuffer.
++	 */
++	if(VT_HIDDEN(pDrawable->pScreen) ||
++	   pDrawable->type != DRAWABLE_WINDOW) {
++		cfbGetSpans(pDrawable, wMax, ppt, pwidth,
++			    nspans, pchardstStart);
++		return;
++	}
++
++	/* We're just reading pixels from SFB, and we never change
++	 * the read buffer (yet) so just make sure RP is not busy.
++	 */
++	FFBWait(ffbPriv, ffb);
++
++	if ((nspans == 1) && (*pwidth == 1)) {
++		*pdst = *(unsigned int *)(addrp + (ppt->y << 13) + (ppt->x << 2));
++		return;
++	}
++
++	while(nspans--) {
++		int w = min(ppt->x + *pwidth, 2048) - ppt->x;
++		unsigned int *psrc = (unsigned int *) (addrp +
++						       (ppt->y << 13) +
++						       (ppt->x << 2));
++		unsigned int *pdstNext = pdst + w;
++
++		while (w--)
++			*psrc++ = *pdst++;
++		pdst = pdstNext;
++		ppt++;
++		pwidth++;
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBzeroarc.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBzeroarc.c	Thu Jan 13 11:32:35 2000
+@@ -0,0 +1,504 @@
++/* $Id$ Acceleration for the Creator and Creator3D framebuffer - Zero arc
++ * rops.
++ *
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Derived from mi/mizerarc.c, see there for authors.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
++ * IN THE SOFTWARE.
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBstip.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++
++#include "cfb/cfb.h"
++
++#include "mi.h"
++#include "mizerarc.h"
++
++#define FULLCIRCLE (360 * 64)
++#define OCTANT (45 * 64)
++#define QUADRANT (90 * 64)
++#define HALFCIRCLE (180 * 64)
++#define QUADRANT3 (270 * 64)
++
++typedef struct {
++	int skipStart;
++	int haveStart;
++	DDXPointRec startPt;
++	int haveLast;
++	int skipLast;
++	DDXPointRec endPt;
++	int dashIndex;
++	int dashOffset;
++	int dashIndexInit;
++	int dashOffsetInit;
++} DashInfo;
++
++#define Pixelate(xval,yval,ext) 				\
++if (((xval)+xoff) >= (ext)->x1 &&				\
++    ((xval)+xoff) < (ext)->x2 &&				\
++    ((yval)+yoff) >= (ext)->y1 &&				\
++    ((yval)+yoff) < (ext)->y2) {				\
++	FFBFifo(ffbPriv, 2);					\
++	FFB_WRITE64(&ffb->bh, ((yval)+yoff), ((xval)+xoff));	\
++}
++
++#define Pixelate1(xval,yval,ext)				\
++if (((xval)+xoff) >= (ext)->x1 &&				\
++    ((xval)+xoff) < (ext)->x2 &&				\
++    ((yval)+yoff) >= (ext)->y1 &&				\
++    ((yval)+yoff) < (ext)->y2) {				\
++	FFBFifo(ffbPriv, 2);					\
++	FFB_WRITE64(&ffb->bh, ((yval)+yoff), ((xval)+xoff));	\
++}
++
++#define DoPix(idx,xval,yval,ext) if (mask & (1 << idx)) Pixelate(xval, yval,ext);
++
++static void
++CreatorZeroArcPts(xArc *arc, DrawablePtr pDrawable, GCPtr pGC, BoxPtr pextent)
++{
++	miZeroArcRec info;
++	register int x, y, a, b, d, mask;
++	register int k1, k3, dx, dy;
++	int xoff, yoff;
++	Bool do360;
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	xoff = 0;
++	yoff = 0;
++	if (pGC->miTranslate) {
++		xoff = pDrawable->x;
++		yoff = pDrawable->y;
++	}
++	do360 = miZeroArcSetup(arc, &info, TRUE);
++	MIARCSETUP();
++	mask = info.initialMask;
++	if (!(arc->width & 1)) {
++		DoPix(1, info.xorgo, info.yorg, pextent);
++		DoPix(3, info.xorgo, info.yorgo, pextent);
++	}
++	if (!info.end.x || !info.end.y) {
++		mask = info.end.mask;
++		info.end = info.altend;
++	}
++	if (do360 && (arc->width == arc->height) && !(arc->width & 1)) {
++		int yorgh = info.yorg + info.h;
++		int xorghp = info.xorg + info.h;
++		int xorghn = info.xorg - info.h;
++		int lastx = 0, lasty = 0;
++
++		while (1) {
++			if (a < 0)
++				break;
++			Pixelate1(info.xorg + x, info.yorg + y, pextent);
++			Pixelate1(info.xorg - x, info.yorg + y, pextent);
++			Pixelate1(info.xorg - x, info.yorgo - y, pextent);
++			Pixelate1(info.xorg + x, info.yorgo - y, pextent);
++			Pixelate1(xorghp - y, yorgh - x, pextent);
++			Pixelate1(xorghn + y, yorgh - x, pextent);
++			Pixelate1(xorghn + y, yorgh + x, pextent);
++			lastx = xorghp - y; lasty = yorgh + x;
++			Pixelate1(xorghp - y, yorgh + x, pextent);
++			MIARCCIRCLESTEP(;);
++		}
++		if (x <= 0 || lastx != info.xorg + x || lasty != info.yorg + y) {
++			Pixelate1(info.xorg + x, info.yorg + y, pextent);
++			Pixelate1(info.xorg - x, info.yorg + y, pextent);
++			Pixelate1(info.xorg - x, info.yorgo - y, pextent);
++			Pixelate1(info.xorg + x, info.yorgo - y, pextent);
++		}
++		x = info.w;
++		y = info.h;
++	} else if (do360) {
++		while (y < info.h || x < info.w) {
++			MIARCOCTANTSHIFT(;);
++			Pixelate1(info.xorg + x, info.yorg + y, pextent);
++			Pixelate1(info.xorgo - x, info.yorg + y, pextent);
++			Pixelate1(info.xorgo - x, info.yorgo - y, pextent);
++			Pixelate1(info.xorg + x, info.yorgo - y, pextent);
++			MIARCSTEP(;,;);
++		}
++	} else {
++		while (y < info.h || x < info.w) {
++			MIARCOCTANTSHIFT(;);
++			if ((x == info.start.x) || (y == info.start.y)) {
++				mask = info.start.mask;
++				info.start = info.altstart;
++			}
++			DoPix(0, info.xorg + x, info.yorg + y, pextent);
++			DoPix(1, info.xorgo - x, info.yorg + y, pextent);
++			DoPix(2, info.xorgo - x, info.yorgo - y, pextent);
++			DoPix(3, info.xorg + x, info.yorgo - y, pextent);
++			if (x == info.end.x || y == info.end.y) {
++				mask = info.end.mask;
++				info.end = info.altend;
++			}
++			MIARCSTEP(;,;);
++		}
++	}
++	if (x == info.start.x || y == info.start.y)
++		mask = info.start.mask;
++	DoPix(0, info.xorg + x, info.yorg + y, pextent);
++	DoPix(2, info.xorgo - x, info.yorgo - y, pextent);
++	if (arc->height & 1) {
++		DoPix(1, info.xorgo - x, info.yorg + y, pextent);
++		DoPix(3, info.xorg + x, info.yorgo - y, pextent);
++	}
++}
++
++#undef DoPix
++#define DoPix(idx,xval,yval) \
++	if (mask & (1 << idx)) \
++	{ \
++	arcPts[idx]->x = xval; \
++	arcPts[idx]->y = yval; \
++	arcPts[idx]++; \
++	}
++
++static void
++CreatorZeroArcDashPts(GCPtr pGC, xArc *arc, DashInfo *dinfo, DDXPointPtr points,
++                      int maxPts, DDXPointPtr *evenPts, DDXPointPtr *oddPts)
++{
++	miZeroArcRec info;
++	register int x, y, a, b, d, mask;
++	register int k1, k3, dx, dy;
++	int dashRemaining;
++	DDXPointPtr arcPts[4];
++	DDXPointPtr startPts[5], endPts[5];
++	int deltas[5];
++	DDXPointPtr startPt, pt, lastPt, pts;
++	int i, j, delta, ptsdelta, seg, startseg;
++
++	for (i = 0; i < 4; i++)
++		arcPts[i] = points + (i * maxPts);
++	miZeroArcSetup(arc, &info, FALSE);
++	MIARCSETUP();
++	mask = info.initialMask;
++	startseg = info.startAngle / QUADRANT;
++	startPt = arcPts[startseg];
++	if (!(arc->width & 1)) {
++		DoPix(1, info.xorgo, info.yorg);
++		DoPix(3, info.xorgo, info.yorgo);
++	}
++	if (!info.end.x || !info.end.y) {
++		mask = info.end.mask;
++		info.end = info.altend;
++	}
++	while (y < info.h || x < info.w) {
++		MIARCOCTANTSHIFT(;);
++		if ((x == info.firstx) || (y == info.firsty))
++			startPt = arcPts[startseg];
++		if ((x == info.start.x) || (y == info.start.y)) {
++			mask = info.start.mask;
++			info.start = info.altstart;
++		}
++		DoPix(0, info.xorg + x, info.yorg + y);
++		DoPix(1, info.xorgo - x, info.yorg + y);
++		DoPix(2, info.xorgo - x, info.yorgo - y);
++		DoPix(3, info.xorg + x, info.yorgo - y);
++		if (x == info.end.x || y == info.end.y) {
++			mask = info.end.mask;
++			info.end = info.altend;
++		}
++		MIARCSTEP(;,;);
++	}
++	if (x == info.firstx || y == info.firsty)
++		startPt = arcPts[startseg];
++	if (x == info.start.x || y == info.start.y)
++		mask = info.start.mask;
++	DoPix(0, info.xorg + x, info.yorg + y);
++	DoPix(2, info.xorgo - x, info.yorgo - y);
++	if (arc->height & 1) {
++		DoPix(1, info.xorgo - x, info.yorg + y);
++		DoPix(3, info.xorg + x, info.yorgo - y);
++	}
++	for (i = 0; i < 4; i++) {
++		seg = (startseg + i) & 3;
++		pt = points + (seg * maxPts);
++		if (seg & 1) {
++			startPts[i] = pt;
++			endPts[i] = arcPts[seg];
++			deltas[i] = 1;
++		} else {
++			startPts[i] = arcPts[seg] - 1;
++			endPts[i] = pt - 1;
++			deltas[i] = -1;
++		}
++	}
++	startPts[4] = startPts[0];
++	endPts[4] = startPt;
++	startPts[0] = startPt;
++	if (startseg & 1) {
++		if (startPts[4] != endPts[4])
++			endPts[4]--;
++		deltas[4] = 1;
++	} else {
++		if (startPts[0] > startPts[4])
++			startPts[0]--;
++		if (startPts[4] < endPts[4])
++			endPts[4]--;
++		deltas[4] = -1;
++	}
++	if (arc->angle2 < 0) {
++		DDXPointPtr tmps, tmpe;
++		int tmpd;
++
++		tmpd = deltas[0];
++		tmps = startPts[0] - tmpd;
++		tmpe = endPts[0] - tmpd;
++		startPts[0] = endPts[4] - deltas[4];
++		endPts[0] = startPts[4] - deltas[4];
++		deltas[0] = -deltas[4];
++		startPts[4] = tmpe;
++		endPts[4] = tmps;
++		deltas[4] = -tmpd;
++		tmpd = deltas[1];
++		tmps = startPts[1] - tmpd;
++		tmpe = endPts[1] - tmpd;
++		startPts[1] = endPts[3] - deltas[3];
++		endPts[1] = startPts[3] - deltas[3];
++		deltas[1] = -deltas[3];
++		startPts[3] = tmpe;
++		endPts[3] = tmps;
++		deltas[3] = -tmpd;
++		tmps = startPts[2] - deltas[2];
++		startPts[2] = endPts[2] - deltas[2];
++		endPts[2] = tmps;
++		deltas[2] = -deltas[2];
++	}
++	for (i = 0; i < 5 && startPts[i] == endPts[i]; i++);
++	if (i == 5)
++		return;
++	pt = startPts[i];
++	for (j = 4; startPts[j] == endPts[j]; j--);
++	lastPt = endPts[j] - deltas[j];
++	if (dinfo->haveLast &&
++	    (pt->x == dinfo->endPt.x) && (pt->y == dinfo->endPt.y)) {
++		startPts[i] += deltas[i];
++	} else {
++		dinfo->dashIndex = dinfo->dashIndexInit;
++		dinfo->dashOffset = dinfo->dashOffsetInit;
++	}
++	if (!dinfo->skipStart && (info.startAngle != info.endAngle)) {
++		dinfo->startPt = *pt;
++		dinfo->haveStart = TRUE;
++	} else if (!dinfo->skipLast && dinfo->haveStart &&
++		 (lastPt->x == dinfo->startPt.x) &&
++		 (lastPt->y == dinfo->startPt.y) &&
++		 (lastPt != startPts[i]))
++		endPts[j] = lastPt;
++	if (info.startAngle != info.endAngle) {
++		dinfo->haveLast = TRUE;
++		dinfo->endPt = *lastPt;
++	}
++	dashRemaining = pGC->dash[dinfo->dashIndex] - dinfo->dashOffset;
++	for (i = 0; i < 5; i++) {
++		pt = startPts[i];
++		lastPt = endPts[i];
++		delta = deltas[i];
++		while (pt != lastPt) {
++			if (dinfo->dashIndex & 1) {
++				pts = *oddPts;
++				ptsdelta = -1;
++			} else {
++				pts = *evenPts;
++				ptsdelta = 1;
++			}
++			while ((pt != lastPt) && --dashRemaining >= 0) {
++				*pts = *pt;
++				pts += ptsdelta;
++				pt += delta;
++			}
++			if (dinfo->dashIndex & 1)
++				*oddPts = pts;
++			else
++				*evenPts = pts;
++			if (dashRemaining <= 0) {
++				if (++(dinfo->dashIndex) == pGC->numInDashList)
++					dinfo->dashIndex = 0;
++				dashRemaining = pGC->dash[dinfo->dashIndex];
++			}
++		}
++	}
++	dinfo->dashOffset = pGC->dash[dinfo->dashIndex] - dashRemaining;
++}
++
++void
++CreatorZeroPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc *parcs)
++{
++	int maxPts = 0;
++	register int n;
++	register xArc *arc;
++	register int i;
++	register int j, k;
++	DDXPointPtr points, pts, oddPts;
++	int numPts;
++	DashInfo dinfo;
++	CreatorPrivScreenPtr ffbPriv;
++	ffb_fbcPtr ffb;
++	RegionPtr clip;
++	int numRects, ppc;
++	BoxPtr pbox;
++	CreatorPrivGCPtr gcPriv;
++	register int off, c1, c2;
++	register char *addrp;
++	register int *ppt, pt, pix;
++	
++	gcPriv = CreatorGetGCPrivate (pGC);
++	ffbPriv = CreatorGetScreenPrivate(pDrawable->pScreen);
++	ffb = ffbPriv->regs;
++	clip = cfbGetCompositeClip(pGC);
++	numRects = REGION_NUM_RECTS(clip);
++	if (!numRects)
++		return;
++	if (VT_HIDDEN(pDrawable->pScreen) ||
++	    (pGC->lineStyle == LineSolid && numRects != 1)) {
++		miZeroPolyArc(pDrawable, pGC, narcs, parcs);
++		return;
++	}
++	FFBLOG("CreatorZeroPolyArc: ALU(%x) PMSK(%08x) narcs(%d)\n",
++	       pGC->alu, pGC->planemask, narcs);
++	if (pGC->lineStyle == LineSolid)
++		for (arc = parcs, i = narcs, j = 0; --i >= 0; arc++) {
++			if (!miCanZeroArc(arc))
++				miPolyArc(pDrawable, pGC, 1, arc);
++			else
++				j++;
++		}
++	else
++		for (arc = parcs, i = narcs, j = 0; --i >= 0; arc++) {
++			if (!miCanZeroArc(arc))
++				miPolyArc(pDrawable, pGC, 1, arc);
++			else {
++				j++;
++				if (arc->width > arc->height)
++					n = arc->width + (arc->height >> 1);
++				else
++					n = arc->height + (arc->width >> 1);
++				if (n > maxPts)
++					maxPts = n;
++			}
++		}
++	if (!j)
++		return;
++
++	if (pGC->lineStyle != LineSolid) {
++		numPts = maxPts << 2;
++		points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * (numPts + (maxPts << 1)));
++		if (!points) return;
++		dinfo.haveStart = FALSE;
++		dinfo.skipStart = FALSE;
++		dinfo.haveLast = FALSE;
++		dinfo.dashIndexInit = 0;
++		dinfo.dashOffsetInit = 0;
++		miStepDash((int)pGC->dashOffset, &dinfo.dashIndexInit,
++			   (unsigned char *) pGC->dash, (int)pGC->numInDashList,
++			   &dinfo.dashOffsetInit);
++		off = *(int *)&pDrawable->x;
++		off -= (off & 0x8000) << 1;
++		addrp = (char *)ffbPriv->fb + (pDrawable->y << 13) + (pDrawable->x << 2);
++		ppc = FFB_PPC_CS_VAR;
++	} else
++		ppc = FFB_PPC_CS_CONST;
++
++        if(gcPriv->stipple == NULL) {
++		FFB_WRITE_ATTRIBUTES(ffbPriv,
++				     ppc|FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE,
++				     FFB_PPC_CS_MASK|FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK,
++				     pGC->planemask,
++				     FFB_ROP_EDIT_BIT|pGC->alu,
++				     FFB_DRAWOP_DOT, pGC->fgPixel,
++				     FFB_FBC_DEFAULT);
++	} else {
++		FFBSetStipple(ffbPriv, ffb, gcPriv->stipple,
++			      ppc|FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE,
++			      FFB_PPC_CS_MASK|FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK);
++		FFB_WRITE_PMASK(ffbPriv, ffb, pGC->planemask);
++		FFB_WRITE_DRAWOP(ffbPriv, ffb, FFB_DRAWOP_DOT);
++		FFB_WRITE_FBC(ffbPriv, ffb, FFB_FBC_DEFAULT);
++	}
++	if((ppc & FFB_PPC_CS_MASK) == FFB_PPC_CS_VAR)
++		FFBWait(ffbPriv, ffb);
++
++	for (arc = parcs, i = narcs; --i >= 0; arc++) {
++		if (miCanZeroArc(arc)) {
++			if (pGC->lineStyle == LineSolid)
++				CreatorZeroArcPts(arc, pDrawable, pGC, REGION_RECTS(clip));
++			else {
++				pts = points;
++				oddPts = &points[(numPts >> 1) - 1];
++				dinfo.skipLast = i;
++				CreatorZeroArcDashPts(pGC, arc, &dinfo,
++						      oddPts + 1, maxPts, &pts, &oddPts);
++				dinfo.skipStart = TRUE;
++				n = pts - points;
++				pbox = REGION_RECTS(clip);
++				j = numRects;
++				pix = pGC->fgPixel;
++				while (j--) {
++					c1 = *(int *)&pbox->x1 - off;
++					c2 = *(int *)&pbox->x2 - off - 0x00010001;
++					for (ppt = (int *)points, k = n; --k >= 0; ) {
++						pt = *ppt++;
++						if (!(((pt - c1) | (c2 - pt)) & 0x80008000))
++							*(unsigned int *)(addrp + ((pt << 13) & 0xffe000) + ((pt >> 14) & 0x1ffc)) = pix;
++					}
++					pbox++;
++				}
++				if (pGC->lineStyle != LineDoubleDash)
++					continue;
++				if ((pGC->fillStyle == FillSolid) || (pGC->fillStyle == FillStippled))
++					pix = pGC->bgPixel;
++				pts = &points[numPts >> 1];
++				oddPts++;
++				n = pts - oddPts;
++				pbox = REGION_RECTS(clip);
++				j = numRects;
++				while (j--) {
++					c1 = *(int *)&pbox->x1 - off;
++					c2 = *(int *)&pbox->x2 - off - 0x00010001;
++					for (ppt = (int *)oddPts, k = n; --k >= 0; ) {
++						pt = *ppt++;
++						if (!(((pt - c1) | (c2 - pt)) & 0x80008000))
++							*(unsigned int *)(addrp + ((pt << 13) & 0xffe000) + ((pt >> 14) & 0x1ffc)) = pix;
++					}
++					pbox++;
++				}
++			}
++		}
++	}
++	if (pGC->lineStyle != LineSolid) {
++		DEALLOCATE_LOCAL(points);
++	} else {
++		ffbPriv->rp_active = 1;
++		FFBSync(ffbPriv, ffb);
++	}
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBattr.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBattr.c	Thu Jan 13 11:31:44 2000
+@@ -0,0 +1,60 @@
++/* $Id$
++ * Attribute setting for the Creator and Creator3D framebuffer.
++ *
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
++ * IN THE SOFTWARE.
++ */
++
++#define	PSZ	32
++
++#include "sunFFB.h"
++#include "FFBfifo.h"
++#include "FFBrcache.h"
++
++/* If we're going to write any attributes, write them all. */
++void __FFB_Write_Attributes(CreatorPrivScreenPtr ffbPriv,
++			    unsigned int ppc,
++			    unsigned int ppc_mask,
++			    unsigned int pmask,
++			    unsigned int rop,
++			    int drawop, int fg,
++			    unsigned int fbc)
++{
++	ffb_fbcPtr ffb = ffbPriv->regs;
++
++	FFBLOG("WRATTRS: PPC[%08x:%08x] PMSK[%08x] ROP[%08x] DOP[%08x] FG[%08x] FBC[%08x]\n",
++	       ppc, ppc_mask, pmask, rop, drawop, fg, fbc);
++	ffbPriv->ppc_cache &= ~ppc_mask;
++	ffbPriv->ppc_cache |= ppc;
++	ffbPriv->fg_cache = fg;
++	ffbPriv->fbc_cache = fbc;
++	ffbPriv->rop_cache = rop;
++	ffbPriv->pmask_cache = pmask;
++	ffbPriv->drawop_cache = drawop;
++	ffbPriv->rp_active = 1;
++	FFBFifo(ffbPriv, 6);
++	ffb->ppc = ppc;
++	ffb->fg = fg;
++	ffb->fbc = fbc;
++	ffb->rop = rop;
++	ffb->pmask = pmask;
++	ffb->drawop = drawop;
++}
+--- xc/programs/Xserver/hw/sun/FFB/FFBglyph.c.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/FFBglyph.c	Thu Jan 13 11:35:02 2000
+@@ -0,0 +1,391 @@
++/* $Id$
++ * Acceleration for the Creator and Creator3D framebuffer - Glyph rops.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
++ * Copyright (C) 1999 David S. Miller (davem@redhat.com)
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
++ * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
++ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
++ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
++ * USE OR OTHER DEALINGS IN THE SOFTWARE.
++ *
++ */
++
++#define PSZ 32
++
++#include "sun.h"
++
++#include "sunFFB.h"
++#include "FFBregs.h"
++#include "FFBrcache.h"
++#include "FFBfifo.h"
++#include "FFBloops.h"
++
++#include "pixmapstr.h"
++#include "scrnintstr.h"
++#include "fontstruct.h"
++#include "dixfontstr.h"
++
++#include "cfb/cfb.h"
++
++void
++CreatorPolyGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++		     unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	FontPtr pfont = pGC->font;
++	RegionPtr clip = cfbGetCompositeClip(pGC);
++	BoxPtr pbox = REGION_RECTS(clip);
++	int nbox = REGION_NUM_RECTS(clip);
++	int skippix, skipglyph, width, n, i;
++	int Left, Right, Top, Bottom, LeftEdge, RightEdge;
++
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pGlyphBase);
++		return;
++	}
++#endif
++
++	FFBLOG("CreatorPolyGlyphBlt: xy[%08x:%08x] nglyph(%d)\n", x, y, nglyph);
++	x += pDrawable->x;
++	y += pDrawable->y;
++
++	width = 0;
++	for(i = 0; i < (nglyph - 1); i++)
++		width += (ppci[i])->metrics.characterWidth;
++
++	Left   = x + (ppci[0])->metrics.leftSideBearing;
++	Right  = x + (width + (ppci[nglyph - 1])->metrics.rightSideBearing);
++	Top    = y - FONTMAXBOUNDS(pfont, ascent);
++	Bottom = y + FONTMAXBOUNDS(pfont, descent);
++
++	while(nbox && (Top >= pbox->y2)) {
++		pbox++;
++		nbox--;
++	}
++
++	if(!nbox || Bottom < pbox->y1)
++		return;
++
++	/* Ok, setup the chip. */
++	{
++		unsigned int ppc = (FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|
++				    FFB_PPC_TBE_TRANSPARENT|FFB_PPC_CS_CONST);
++		unsigned int ppc_mask = (FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|
++					 FFB_PPC_TBE_MASK|FFB_PPC_CS_MASK);
++		unsigned int pmask = pGC->planemask;
++		unsigned int rop = FFB_ROP_EDIT_BIT | pGC->alu;
++		unsigned int fg = pGC->fgPixel;
++		unsigned int fbc = FFB_FBC_DEFAULT;
++
++		if((ffbPriv->ppc_cache & ppc_mask) != ppc ||
++		   ffbPriv->fg_cache != fg ||
++		   ffbPriv->fbc_cache != fbc ||
++		   ffbPriv->rop_cache != rop ||
++		   ffbPriv->pmask_cache != pmask ||
++		   ffbPriv->fontinc_cache != ((1<<16) | 0)) {
++			ffbPriv->ppc_cache &= ~ppc_mask;
++			ffbPriv->ppc_cache |= ppc;
++			ffbPriv->fg_cache = fg;
++			ffbPriv->fbc_cache = fbc;
++			ffbPriv->rop_cache = rop;
++			ffbPriv->pmask_cache = pmask;
++			ffbPriv->fontinc_cache = ((1<<16) | 0);
++			ffbPriv->rp_active = 1;
++			FFBFifo(ffbPriv, 6);
++			ffb->ppc = ppc;
++			ffb->fg = fg;
++			ffb->fbc = fbc;
++			ffb->rop = rop;
++			ffb->pmask = pmask;
++			ffb->fontinc = ((1 << 16) | 0);
++		}
++	}
++
++	while(nbox && (Bottom >= pbox->y1)) {
++		LeftEdge  = max(Left, pbox->x1);
++		RightEdge = min(Right, pbox->x2);
++		if(RightEdge > LeftEdge) {
++			int walk, x_start;
++
++			skippix = LeftEdge - x;
++			skipglyph = walk = 0;
++			while(skippix >= (walk + (ppci[skipglyph])->metrics.rightSideBearing)) {
++				walk += (ppci[skipglyph])->metrics.characterWidth;
++				skipglyph++;
++			}
++			x_start = x + walk;
++			skippix = RightEdge - x;
++			n = 0;
++			i = skipglyph;
++			while((i < nglyph) &&
++			      (skippix > (walk + (ppci[i])->metrics.leftSideBearing))) {
++				walk += (ppci[i])->metrics.characterWidth;
++				i++;
++				n++;
++			}
++			if(n) {
++				CharInfoPtr *ppci_iter = ppci + skipglyph;
++				CharInfoPtr pci;
++				unsigned int *bits;
++				int w, h, x0, y0, xskip, yskip;
++
++				while(n--) {
++					pci = *ppci_iter++;
++					w = GLYPHWIDTHPIXELS(pci);
++					h = GLYPHHEIGHTPIXELS(pci);
++					if(!w || !h)
++						goto next_glyph;
++
++					x0 = x_start + pci->metrics.leftSideBearing;
++					y0 = y - pci->metrics.ascent;
++					bits = (unsigned int *) pci->bits;
++
++					/* Now clip it to the bits we should actually
++					 * render.
++					 */
++					xskip = yskip = 0;
++					if(pbox->x1 > x0) {
++						xskip = pbox->x1 - x0;
++						w -= xskip;
++						x0 = pbox->x1;
++						if(w <= 0)
++							goto next_glyph;
++					}
++					if(pbox->y1 > y0) {
++						yskip = pbox->y1 - y0;
++						h -= yskip;
++						y0 = pbox->y1;
++						if(h <= 0)
++							goto next_glyph;
++					}
++					if(pbox->x2 < (x0 + w)) {
++						w = pbox->x2 - x0;
++						if(w <= 0)
++							goto next_glyph;
++					}
++					if(pbox->y2 < (y0 + h)) {
++						h = pbox->y2 - y0;
++						if(h <= 0)
++							goto next_glyph;
++					}
++
++					FFB_WRITE_FONTW(ffbPriv, ffb, w);
++					FFBFifo(ffbPriv, 1 + h);
++					ffb->fontxy = ((y0 << 16) | x0);
++					for(i = 0; i < h; i++)
++						ffb->font = bits[yskip + i] << xskip;
++
++				next_glyph:
++					x_start += pci->metrics.characterWidth;
++				}
++			}
++		}
++		nbox--;
++		pbox++;
++	}
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++void
++CreatorTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++		   unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase)
++{
++	CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++	CreatorPrivScreenPtr ffbPriv = CreatorGetScreenPrivate (pGC->pScreen);
++	ffb_fbcPtr ffb = ffbPriv->regs;
++	RegionPtr clip = cfbGetCompositeClip(pGC);
++	int nbox = REGION_NUM_RECTS(clip);
++	BoxPtr pbox = REGION_RECTS(clip);
++	FontPtr pfont = pGC->font;
++	int glyphWidth = FONTMAXBOUNDS(pfont, characterWidth);
++	int skippix, skipglyphs, Left, Right, Top, Bottom;
++	int LeftEdge, RightEdge, ytop, ybot, h, w;
++
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		(gcPriv->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pGlyphBase);
++		return;
++	}
++#endif
++	FFBLOG("CreatorTEGlyphBlt: xy[%08x:%08x] nglyph(%d) pgbase(%p)\n",
++	       x, y, nglyph, pGlyphBase);
++
++	Left = x + pDrawable->x;
++	Right = Left + (glyphWidth * nglyph);
++	y += pDrawable->y;
++	Top = y - FONTASCENT(pfont);
++	Bottom = y + FONTDESCENT(pfont);
++
++	while(nbox && (Top >= pbox->y2)) {
++		pbox++;
++		nbox--;
++	}
++
++	if(!nbox || Bottom <= pbox->y1)
++		return;
++
++	/* Ok, setup the chip. */
++	{
++		unsigned int ppc = FFB_PPC_FW_DISABLE|FFB_PPC_VCE_DISABLE|FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST;
++		unsigned int ppc_mask = FFB_PPC_FW_MASK|FFB_PPC_VCE_MASK|FFB_PPC_APE_MASK|FFB_PPC_TBE_MASK|FFB_PPC_CS_MASK;
++		unsigned int pmask = pGC->planemask;
++		unsigned int rop;
++		unsigned int fg = pGC->fgPixel;
++		unsigned int bg = pGC->bgPixel;
++		unsigned int fbc = FFB_FBC_DEFAULT;
++
++		if(pGlyphBase) {
++			ppc |= FFB_PPC_TBE_TRANSPARENT;
++			rop = FFB_ROP_EDIT_BIT | pGC->alu;
++		} else {
++			ppc |= FFB_PPC_TBE_OPAQUE;
++			rop = FFB_ROP_EDIT_BIT | GXcopy;
++		}
++		if((ffbPriv->ppc_cache & ppc_mask) != ppc ||
++		   ffbPriv->fg_cache != fg ||
++		   ffbPriv->fbc_cache != fbc ||
++		   ffbPriv->rop_cache != rop ||
++		   ffbPriv->pmask_cache != pmask ||
++		   ffbPriv->fontinc_cache != ((1<<16) | 0) ||
++		   (!pGlyphBase && ffbPriv->bg_cache != bg)) {
++			ffbPriv->ppc_cache &= ~ppc_mask;
++			ffbPriv->ppc_cache |= ppc;
++			ffbPriv->fg_cache = fg;
++			ffbPriv->fbc_cache = fbc;
++			ffbPriv->rop_cache = rop;
++			ffbPriv->pmask_cache = pmask;
++			ffbPriv->fontinc_cache = ((1<<16) | 0);
++			if(!pGlyphBase)
++				ffbPriv->bg_cache = bg;
++			FFBFifo(ffbPriv, (!pGlyphBase ? 7 : 6));
++			ffb->ppc = ppc;
++			ffb->fg = fg;
++			ffb->fbc = fbc;
++			ffb->rop = rop;
++			ffb->pmask = pmask;
++			ffb->fontinc = ((1 << 16) | 0);
++			if(!pGlyphBase)
++				ffb->bg = bg;
++		}
++	}
++
++	while(nbox && (Bottom > pbox->y1)) {
++		LeftEdge = max(Left, pbox->x1);
++		RightEdge = min(Right, pbox->x2);
++
++		if(RightEdge > LeftEdge) {
++			ytop = max(Top, pbox->y1);
++			ybot = min(Bottom, pbox->y2);
++
++			if((skippix = LeftEdge - Left)) {
++				skipglyphs = skippix / glyphWidth;
++				skippix %= glyphWidth;
++			} else
++				skipglyphs = 0;
++			w = RightEdge - LeftEdge;
++
++			/* Get aligned onto a character. */
++			if(skippix) {
++				unsigned int *gbits = (unsigned int *) ppci[skipglyphs++]->bits;
++
++				FFB_WRITE_FONTW(ffbPriv, ffb, (glyphWidth - skippix));
++				FFBFifo(ffbPriv, 1 + (ybot - ytop));
++				ffb->fontxy = ((ytop << 16) | LeftEdge);
++				for(h = (ytop - Top); h < (ybot - Top); h++)
++					ffb->font = gbits[h] << skippix;
++				LeftEdge += (glyphWidth - skippix);
++				w -= (glyphWidth - skippix);
++			}
++			/* And now blit the rest with unrolled loops. */
++#define 		LoopIt(chunkW, loadup, fetch) \
++			FFB_WRITE_FONTW(ffbPriv, ffb, chunkW); \
++			while (w >= chunkW) { \
++				loadup \
++				FFBFifo(ffbPriv, 1 + (ybot - ytop)); \
++				ffb->fontxy = ((ytop << 16) | LeftEdge); \
++				for(h = (ytop - Top); h < (ybot - Top); h++) \
++					ffb->font = fetch; \
++				LeftEdge += chunkW; \
++				w -= chunkW; \
++			}
++			if(glyphWidth <= 8) {
++				int chunk_size = glyphWidth << 2;
++				LoopIt(chunk_size,
++				       unsigned int *char1 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char2 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char3 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char4 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);,
++				       (*char1++ | ((*char2++ | ((*char3++ | (*char4++ >> glyphWidth))
++								 >> glyphWidth))
++						    >> glyphWidth)))
++			} else if(glyphWidth <= 10) {
++				int chunk_size = (glyphWidth << 1) + glyphWidth;
++				LoopIt(chunk_size,
++				       unsigned int *char1 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char2 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char3 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);,
++				       (*char1++ | ((*char2++ | (*char3++ >> glyphWidth)) >> glyphWidth)));
++			} else if(glyphWidth <= 16) {
++				int chunk_size = glyphWidth << 1;
++				LoopIt(chunk_size,
++				       unsigned int *char1 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);
++				       unsigned int *char2 = ((unsigned int *)ppci[skipglyphs++]->bits)+(ytop-Top);,
++				       (*char1++ | (*char2++ >> glyphWidth)));
++			}
++#undef LoopIt
++			/* Take care of any final glyphs. */
++			while(w > 0) {
++				unsigned int *gbits = (unsigned int *) ppci[skipglyphs++]->bits;
++				int pix = glyphWidth;
++
++				if(w < pix)
++					pix = w;
++				FFB_WRITE_FONTW(ffbPriv, ffb, pix);
++				FFBFifo(ffbPriv, 1 + (ybot - ytop));
++				ffb->fontxy = ((ytop << 16) | LeftEdge);
++				for(h = (ytop - Top); h < (ybot - Top); h++)
++					ffb->font = gbits[h];
++				LeftEdge += pix;
++				w -= pix;
++			}
++		}
++		nbox--;
++		pbox++;
++	}
++
++	ffbPriv->rp_active = 1;
++	FFBSync(ffbPriv, ffb);
++}
++
++void
++CreatorPolyTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, int x, int y,
++		       unsigned int nglyph, CharInfoPtr *ppci, pointer pGlyphBase)
++{
++#ifdef linux
++	if (VT_HIDDEN(pDrawable->pScreen)) {
++		CreatorPrivGCPtr gcPriv = CreatorGetGCPrivate (pGC);
++		(gcPriv->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pGlyphBase);
++		return;
++	}
++#endif
++	CreatorTEGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, (char *) 1);
++}
+--- xc/programs/Xserver/hw/sun/FFB/VISmoveImage.s.jj	Thu Jan 13 11:31:13 2000
++++ xc/programs/Xserver/hw/sun/FFB/VISmoveImage.s	Thu Jan 13 11:57:59 2000
+@@ -0,0 +1,2705 @@
++/* $Id$
++ * VISmoveImage.S: High speed moveImage operations utilizing the UltraSPARC
++ *                 Visual Instruction Set.
++ *
++ * Copyright (C) 1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++ */
++
++/* NOTE NOTE NOTE: All loads in these routines _MUST_ be 64-byte block
++ *                 loads.  If any non-block loads are done to the frame-
++ *                 buffer when prefetching is enabled (which we use, when
++ *		   available) this will cause lockups on FFB2 due to a
++ *		   hardware bug. -DaveM
++ */
++
++/* 
++   void
++   VISmoveImageLR(unsigned char *src, unsigned char *dst, long w, long h, long skind, long dkind)
++   {
++     int i;
++
++     // Handles copying non-overlapping images and for overlapping images
++     // copying where dstx <= srcx.
++     // To copy overlapping images where dsty > srcy, set src and dst
++     // to start of the last scanline and negate both skind and dkind arguments.
++
++     assert(abs(skind) >= w && abs(dkind) >= w);
++
++     while (h--) {
++       for (i = 0; i < w; i++)
++         *d++ = *s++;
++       s += skind - w;
++       d += dkind - w;
++     }
++   }
++
++   void
++   VISmoveImageRL(unsigned char *src, unsigned char *dst, long w, long h, long skind, long dkind)
++   {
++     int i;
++
++     // Handles copying non-overlapping images and for overlapping images
++     // copying where dstx >= srcx.
++     // To copy overlapping images where dsty > srcy, set src and dst
++     // to start of the last scanline and negate both skind and dkind arguments.
++
++     assert(abs(skind) >= w && abs(dkind) >= w);
++
++     s += w;
++     d += w;
++     while (h--) {
++       for (i = 0; i < w; i++)
++         *--d = *--s;
++       s += skind + w;
++       d += dkind + w;
++     }
++   }
++
++ */
++
++#if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__)
++#define SMUL			mulx
++#define ICC			xcc
++#else
++#define SMUL			smul
++#define ICC			icc
++#endif
++
++#define ASI_PST8_P		0xc0
++#define ASI_BLK_P		0xf0
++#define SYNC			0x40
++
++/* Register usage:								*/
++/*   integer registers:								*/
++#define src			i0
++#define dst			i1
++#define w			i2
++#define h			i3
++#define skind			i4
++#define dkind			i5
++#define branchbase		l0
++#define tmp1			l1
++#define tmp4			l2
++#define tmp5			l3
++#define leftw			l4
++#define rightw			l5
++#define srcstart		l6
++#define mode			l7
++#define fregset			o0		/* Must be [og]? for v8plusa */
++#define srcend			o1
++#define srcn			o2
++#define srcnext			o3
++#define rightw2			o4
++#define tmp2			o5		/* Must be [og]? for v8plusa */
++#define narrow			o7
++#define prepw			g1		/* Must be [og]? for v8plusa */
++#define srcstop			g2
++#define srcnotdone		g3
++#define curw			g4		/* Must be [og]? for v8plusa */
++#define leftw2			rightw2
++#define tmp3			g5		/* Must be [og]? for v8plusa */
++/*   floating point registers:							*/
++#define ftmp1			f0
++#define ftmp2			f2
++#define ftmp3			f4
++#define ftmp4			f6
++#define ftmp5			f8
++#define ftmp6			f10
++#define ftmp7			f12
++#define ftmp8			f14
++#define store_regs		f16-f31
++#define load_bank1		f32-f46
++#define load_bank2		f48-f62
++#define fnop			fmovd	%ftmp2, %ftmp2
++
++#define LOAD(f32,f46,tgt,tgtr)							\
++	subcc			%curw, 64, %curw;				\
++	bleu,pn			%ICC, tgt;					\
++	 fmovd			%f46, %ftmp1;					\
++	ldda			[%src] ASI_BLK_P, %f32;				\
++	add			%src, 64, %src;					\
++tgtr:
++
++#define PREPLOAD(f32,f46,tgt,tgtr)						\
++	brlez,pn		%prepw, tgt;					\
++	 fmovd			%f46, %ftmp1;					\
++	ldda			[%src] ASI_BLK_P, %f32;				\
++	add			%src, 64, %src;					\
++tgtr:
++
++#define STORE									\
++	stda			%f16, [%dst] ASI_BLK_P;
++
++#define FREG_FROB(f0,A0,F2,f2,A1,F4,f4,A2,F6,f6,A3,F8,f8,A4,F10,