Last updated: 2/21/94

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

Greetings:


This distribution contains an updated version of my
software cursor patch for Linux 0.99 pl15. 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.


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

- Updated for pl15

- Tried to add support for selecting properly sized underline cursor
  with different SVGA modes.

- Changed escape codes for underline/block selection to avoid silly
  conflict with my Dorio (DEC) terminal.

- Added support for resetting of cursor mode to bootup defaults using
  the reset_term() function. (Thanks to Davor Jadrijevic
  <davj@ds5000.irb.hr>)


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.

- 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.

- Can be safely used with selection 1.5, dosemu and X without problems.
  (At least, I haven't found any. :)

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

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

This is meant to work with any VGA/SVGA hardware in any resolution. It
is 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.

Note: I bumped into a sticky problem with trying to retain the standard
      hardware cursor. The hardare cursor is generated by turning on the
      bottom two rows of pixels in a given character cell. For instance,
      a standard 80x25 VGA text screen displays characters in a 9x16
      pixel font. To create the cursor, rows 15 and 16 of the cell are
      turned on. The trouble is, SVGA modes (80x50, 132x44 and so on)
      use different size fonts (9x14, 8x8, etc...). As you might guess,
      turning on rows 15 and 16 of a character cell that's only 14
      rows high doesn't work.

      I've solved this problem (for now) by using a lookup table: the size
      of a character cell varies depending on the number of text lines, so
      I've selected a cursor value for each possible line count value
      (all values were copied from the table of video modes in setup.S).
      For VGA modes with 25 lines, one value is used, for modes with
      50 lines we use another, and so on. There's a default too in case
      a match can't be found. When the console is initialized at boot
      time, the table is consulted and a value selected. 

      This is *not* the right way to do this. Ideally, there should be a
      way to read the hardware cursor values or the size of the font
      currently in use by probing the card, but I'll be darned if I
      know how to do it. Furthermore, since I don't have the capability
      test all of the possible video modes, some of the values in the
      lookup table could be wrong (I only have my own ET4000 board to
      test with). If anyone knows how to accomplish this without 
      bending over backwards, I'd love to hear from you.

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 from 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. 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>[?32h     switch hardware cursor to block mode
	<ESC>[?32l     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.

Previously, I used the value <ESC>[?34h and <ESC>[?34l to switch
the block/underline modes. I discovered recently that these codes
are in fact used by some terminals (in particular the Dorio terminal
which I won in a contest at UNIX Expo '93 and am now using on my
Linux box :) to switch the direction on which characters are displayed
on the screen. By that I mean that one code causes characters to be
printed on the screen from right to left, while the other changes it
back to left to right. No, really. It's true. You wouldn't believe
the shock I got when I typed 'cursor block' at the terminal and
everything started coming out backwards. Anyway, I changed the codes
to avoid this conflict. For those of you who actually enjoy
reading from right to left, sorry: you're out of luck.

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.

***NOTE***: if you have a previous version of the 'cursor' program installed
            you MUST replace it with this one. There: I've said it.

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.


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                                   "The turban is not for sale."
Internet : ghod@drycas.club.cc.cmu.edu                  -David Letterman
Bitnet   : GHOD@DRYCAS
