Last updated: 12/5/93

Introduction:
------------

Greetings:


This distribution contains an updated and improved version of my
software cursor patch for Linux 0.99 pl14. This patch provides
modifications for the Linux console driver that allow it to generate
a non-blinking software cursor to replace the sometimes irritating
blinking cursor generated by the PC's video hardware. The software
cursor can be any one of eight colors and each virtual console's cursor
color can be different, if desired. Support is provided for switching
from software to hardware cursors on the fly, and as well as changing
the hardware cursor for the usual flashing underline to a flashing
block.

 Note: Unfortunately, this patch will not apply cleanly to kernels
       earlier than 0.99.14 due to some small changes in the console
       driver. It can be applied by hand, but not without some work.


Changes since the last release:
------------------------------

- Updated for pl14

- Small code cleanups in set_cursor()

- Fix for a bug I bet you never knew existed: writing characters to
  a VC while it's in KD_GRAPHICS mode would hose the software
  cursor state for that VC.

- Used 'curs_state' byte to store three different state flags and
  'hcurstype' info rather than using seperate bytes.

- Each virtual console's cursor can now be a different color

- Implimented run-time cursor color changes using escape codes.

- Hardware cursor (if selected) can now be switched from flashing
  underline to flashing block at run time (also using escape codes).

- Got rid of the HCURSTYPE #define. Found out the hard way that mono
  and CGA cards generate characters using fewer vertical pixels than
  VGA/SVGA cards, which means each needs different values to generate
  the standard underline cursor. (*blush*) 'hcurstype' is now set
  automatically at bootup. This means that the hardware cursor is
  now always an underline by default, but you can easily change it
  with the 'cursor' program once the system is up.


Features:
--------

- With this patch, the standard hardware-generated 'blinking underline'
  cursor can be replaced with a software-generated non-blinking block
  cursor. This is meant to help people who:

	* Have laptops/portables with LCD screens that make 
	  it hard to find the cursor
		
	* Want to add an extra touch of color to their consoles

	* Can't stand blinking cursors
	
- The software cursor color on a given VC can be changed on the fly using
  VT-200 style escape codes. (I know I said I wasn't going to implement this
  last time. Alright, so I caved: sue me. :)

- Each VC's cursor type is maintained seperately: you can have half of them
  using the software generated cursor, half of them using the hardware
  cursor, or any combination in between. Each VC's software cursor color
  is also maintained seperately: you can have a blue cursor on VC #1, red
  on VC #2, green on VC #3, and so on.

- The software cursor color on a given VC can be changed at any time
  using VT-200 style escape codes. To make things simple, I've included
  a small C program that can generate all the cursor control codes for
  you.

- The hardware cursor can be switched from a blinking underline to
  blinking block at run time using escape codes. The hardware cursor
  state is also maintained for each VC: half of them can be set to
  use underlines, the other half blocks, or any combination in between.

- The software cursor color remains unchanged even if the foreground or
  background screen colors change. The exception is if you make the
  background color the same as the cursor color: this would render the
  cursor 'invisible', so the cursor will shift to a complement color
  to avoid this condition.


System requirements:
-------------------

- Linux 0.99.14 kernel sources
- gcc 2.4.5 or higher (preferably higher)
- Some manner of video hardware

This patch will work with any VGA/SVGA hardware in any resolution. It
is also known to work with monochrome Hercules adpapters, though I have
no idea what happens when you try to change cursor colors. It *should*
also work with CGA displays, though this has not been tested. If you
have a CGA adapter, try it and let me know how it works.


Configuration:
-------------

Since this is a fairly simple patch, I haven't made an entry for it
in the config.in. However, there are 2 #defines incorporated into
/linux/drivers/char/concole.c that control default cursor behavior:

#define NOBLINK 1
#define SCURSCOLOR 112

If NOBLINK is #defined to be 1, all VCs will default to software generated
cursors at boot time. If it is #defined to be 0, they'll default to the usual 
hardware cursors instead.

SCURSCOLOR sets the default software cursor color for all virtual consoles.
Legal values are:

  0     16   32    48   64  80      96     112
  black blue green cyan red magenta yellow white

Note that setting the cursor color to black will actually work, only
it will appear white on a black background since the code is smart 
enough to prevent the cursor form accidentally becoming 'invisible' due
to a bad choice of screen colors. Where other colors are concerned,
conflicts will be avoided by shifting either the cursor or the text
beneath it to its complement color. The complement of black is
obviously white, and vice-versa. The complement of blue is yellow
(which looks more orange that it does yellow, but it's called yellow
in all the references I have so we'll stick with it), the complement
of green is magenta, and so forth. 

The values listed above for NOBLINK and SCURSCOLOR are the defaults. If
you elect to leave them unchanged, your kernel will boot with white
non-blinking cursors on all of your virtual consoles. You can use the
'cursor' program later to change them however you want.


Escape codes:
------------

You can switch from software to hardware generated cursors on the fly
using a VT-200 style escape code as follows:

	<ESC>[?33h     switch to hardware cursor
	<ESC>[?33l     switch to software cursor
	<ESC>[?34h     switch hardware cursor to block mode
	<ESC>[?34l     switch hardware cursor to underline mode

Note that the two codes that control the hardware cursor characteristics
may not appear to have any effect if you issue them while in software
cursor mode. If you are already in hardware cursor mode, then you can use
them to change the hardware cursor's characteristics and see the results
immediately. Using them while in software cursor mode will work, but you
won't notice the effect until you switch to the hardware cursor.

You can change the software cursor color using these additional codes:

        <ESC>[100m    black
        <ESC>[116m    blue
        <ESC>[132m    green
        <ESC>[148m    cyan
        <ESC>[164m    red
        <ESC>[180m    nagenta
        <ESC>[196m    yellow
        <ESC>[212m    white

Note that the number values in the color codes are the same as those listed
previously, except that they are offset by 100. I did this to make these
codes sufficiently bogus that they would not conflict with any existing codes
that I don't know about. I don't think there are any applications that go 
anywhere near these values.


Installation:
------------

This distribution includes the following three files:

README
cursor.c
noblink.diff

The file noblink.diff is a context diff against
/linux/drivers/char/console.c and can be applied as follows:

# cd /linux/drivers/char
# patch < noblink.diff

Check for rejects. Once you're sure the patch has been properly
installed, you can go ahead and build your new kernel. If you still
have the objects from a previous build around, all you have to do is
cd to /linux and type 'make.' If you are compiling for the first time,
configure and build according to the kernel README file.

Note that you may wish to change the #defines mentioned above to suit
your tastes, though the defaults are fairly sane and should work for
any display, including monocrhome.

Once the kernel is finished compiling, you can build the 'cursor' program.
All this program does is generate the cursor control codes for you so you
won't have to memorize them. With it, you can change the software cursor
color, switch from the software cursor back to the default hardware cursor 
*and* change the hardware cursor from a flashing underline to a flashing
block or vice-versa.

'cursor' simply prints the escape codes on the standard output. If
you want, you can redirect its output to another tty device, as in:

% cursor blue > /dev/tty2

This will change VC #2's cursor blue. (You must have write permission to
/dev/tty2 to do this, of course.) The cursor will remain blue until
another escape code is used to change it back.

Compile it with the following command:

# cc -O -s -N -o cursor cursor.c

/usr/local/bin is probably the best place for it to be installed. It does
not require any special privileges.


Acknowledgements:
----------------

Thanks once again to Michael Haardt for testing this on a Hercules
display.


Schmoozing:
----------

As always, questions, comments, complaints, flames, suggestions, bug reports,
bug fixes, or large sums of cash are welcomed and encouraged.

Share and enjoy!

-Bill Paul                                   "A black hole is what happens
Internet : ghod@drycas.club.cc.cmu.edu         when God divides by zero."
Bitnet   : GHOD@DRYCAS
