CTerm terminal chariteristics:
------------------------------

End of line behaviour (wrapping):
The cursor is moved to the first character of the next line
as soon as a character is written to the last column of the
current line, not on the next character.  A tab will wrap
to the next line only if the current cursor position is the
last character on the line.

Control characters:

CR:
	Move cursor position to column 1 of the current line

LF:
	Move cursor position to same column of the next row.
	If current row is the last row, scrolls the screen up
	and fills the new row with the current attribute.

BS:
	Non-destructive backspace.  Moves cursor position to
	the previous column unless the current column is the
	first, in which case no operation is performed.

0x07:
	Beep

TAB:
	Moves to the next tab stop.  Does not overwrite any
	characters in between.  If the starting position is
	last column, advances to next line.  If starting
	position is the last column of the last line, performs
	a scroll, filling the new line at bottom with the
	current attribute and moves to the first character in
	the new line.

Control Codes:
--------------

Control codes are in the following format:
ESC {SPACE to '/'}{'0' (ZERO) to '~'}
	There may be multiple characters from the {SPACE to '/'} set
	before the terminating '0' to '~'

	Legal combinations which are not handled are silently dropped.

ESC D	(Disabled in current code)
	Scrolls window up one line filling the bottom line with the
	current attribute.
	SOURCE: BANSI.TXT

ESC M	(Disabled in current code)
	Scrolls window down one line filling the top line with the
	current attribute
	SOURCE: BANSI.TXT

Control Sequences:
------------------

Control sequences start with the Control Sequence Introducer which is
ESC [  CSI will be used to express this from now on.

Control sequences are in the following format:
CSI {'0' (ZERO) to '?'}{SPACE to '/'}{'@' to '~'}
	There may be multiple characters from the {'0' (ZERO) to '?'}
	and {SPACE to '/'} before the terminating {'@' to '~'} character.

	Legal combinations not handled are silently dropped.
	Illegal combinations are displayed.

Sequence Parameters:
	Parameters are expressed by the {'0' (ZERO) to '?'} character set.
	Sequences which use parameters use decimal parameters separated by
	a ';'.  The use of a ':' from the set is reserved.
	If the parameter string begins with '<', '=', '>', or '?' then
	this is a non-standard extension to the ANSI spec.

	Parameters will be shown as pX where X will be a decimal position
	number.  Surrounded by [] indicates the parameter is optional.

CSI = [p1] M
	NON-STANDARD EXTENSION.
	Defaults:  p1 = 0
	Sets the current state of ANSI music parsing.
	0 - Only CSI | will introduce an ANSI music string.
	1 - Both CSI | and CSI N will introduce an ANSI music string.
	2 - CSI |, CSI N, and CSI M will all intriduce and ANSI music string.
	    In this mode, Delete Line will not be available.

	SOURCE: CTerm only.

CSI = [ p1 [ ; p2 ] ] {
	NON-STANDARD EXTENSION.
	Defaults:  p1 = 255  p2 = 0
	Indicates that a font block is following.
	p1 indicates the font slot to place the loaded font into.  This must
	be higher than the last default defined font (See CSI sp D for list
	of predefined fonts)  p2 indicates font size according to the
	following table:
		0 - 8x16 font, 4096 bytes.
		1 - 8x14 font, 3586 bytes.
		2 - 8x8 font, 2048 bytes.

	SOURCE: CTerm only.


CSI [ p1 [ ; p2 ] ] * r
	NON-STANDARD EXTENSION.
	Set the output emulation speed.
	If p1 or p2 are omitted, causes output speed emulation to stop
	p1 may be empty.
	Sequence is ignored if p1 is not empty, 0, or 1.
	The value of p2 sets the output speed emulation as follows:

	Value		Speed
	-----		-----
	empty, 0	Unlimited
	1		300
	2		600
	3		1200
	4		2400
	5		4800
	6		9600
	7		19200
	8		38400
	9		57600
	10		76800
	11		115200

	SOURCE: VT4xx Specification from http://www.vt100.net/

CSI [ p1 ] @
	Insert Character(s)
	Defaults: p1 = 1
	Moves text from the current position to the right edge p1 characters
	to the right, with rightmost charaters going off-screen and the
	resulting hole being filled with the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] A
	Cursor Up
	Defaults: p1 = 1
	Moves the cursor position up p1 lines from the current position.
	Attempting to move past the screen boundaries stops the cursor
	at the screen boundary.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] B
	Cursor Down
	Defaults: p1 = 1
	Moves the cursor position down p1 lines from the current position.
	Attempting to move past the screen boundaries stops the cursor
	at the screen boundary.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] C
	Cursor Right
	Defaults: p1 = 1
	Moves the cursor position right p1 columns from the current position.
	Attempting to move past the screen boundaries stops the cursor
	at the screen boundary.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] D
	Cursor Left
	Defaults: p1 = 1
	Moves the cursor position left p1 columns from the current position.
	Attempting to move past the screen boundaries stops the cursor
	at the screen boundary.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 [ ; p2 ] ] sp D
	Font Selection
	Defaults: p1 = 0  p2 = 0
	"sp" indicates a single space character.
	Sets font p1 to be the one indicated bu p2.  Currently only the primary
	font (Font zero) is supported.  p2 must be between 0 and 255.  Not all
	output types support font selection.  Only X11 and SDL currently do.
	Currently included fonts are:
		0  - Codepage 437 English
		1  - Codepage 1251 Cyrillic, (swiss)
		2  - Russian koi8-r
		3  - ISO-8859-2 Central European
		4  - ISO-8859-4 Baltic wide (VGA 9bit mapped)
		5  - Codepage 866 (c) Russian
		6  - ISO-8859-9 Turkish
		7  - haik8 codepage (use only with armscii8 screenmap)
		8  - ISO-8859-8 Hebrew
		9  - Ukrainian font koi8-u
		10 - ISO-8859-15 West European, (thin)
		11 - ISO-8859-4 Baltic (VGA 9bit mapped)
		12 - Russian koi8-r (b)
		13 - ISO-8859-4 Baltic wide
		14 - ISO-8859-5 Cyrillic
		15 - ARMSCII-8 Character set
		16 - ISO-8859-15 West European
		17 - Codepage 850 Multilingual Latin I, (thin)
		18 - Codepage 850 Multilingual Latin I
		19 - Codepage 885 Norwegian, (thin)
		20 - Codepage 1251 Cyrillic
		21 - ISO-8859-7 Greek
		22 - Russian koi8-r (c)
		23 - ISO-8859-4 Baltic
		24 - ISO-8859-1 West European
		25 - Codepage 866 Russian
		26 - Codepage 437 English, (thin)
		27 - Codepage 866 (b) Russian
		28 - Codepage 885 Norwegian
		29 - Ukrainian font cp866u
		30 - ISO-8859-1 West European, (thin)
		31 - Codepage 1131 Belarusian, (swiss)
	Not all fonts are supported in all modes.  If a font is not supported in
	the current mode, no action is taken.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] E
	Cursor Next Line
	Defaults: p1 = 1
	Moves the cursor position down p1 columns from the current position.
	Moving past the bottom of the screen scrolls the screen up the remaining
	number of lines filling newly added lines with the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 [ ; p2 ] ] H
CSI [ p1 [ ; p2 ] ] f
	Cusror Position
	Defaults: p1 = 1  p2 = 1
	Moves the cursor to the p2th column of the p1th line.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] J
	Erase in Page
	Defaults: p1 = 0
	Erases from the current screen according to the value of p1
	0 - Erase from the current position to the end of the screen.
	1 - Erase from the current position to the start of the screen.
	2 - Erase entire screen.  As a violation of ECMA-048, also moves
	    the cursor to position 1/1 as a number of BBS programs assume
	    this behaviour.
	Erased characters are set to the current attribute.

	SOURCE BANSI.TXT

CSI [ p1 ] K
	Erase in Line
	Defaults: p1 = 0
	Erases from the current line according to the value pf p1
	0 - Erase from the current position to the end of the line.
	1 - Erase from the current position to the start of the line.
	2 - Erase entire line.
	Erased characters are set to the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] L
	Insert Line(s)
	Defaults: p1 = 1
	Inserts p1 lines at the current line position.  The current line and
	those after it are scrolled down and the new empty lines are filled with
	the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] M
	Delete Line(s) / "ANSI" Music
	Defaults: p1 = 1
	Deletes the current line and the p1 - 1 lines after it scrolling the
	first non-deleted line up to the current line and filling the newly
	empty lines at the end of the screen with the current attribute.
	If "ANSI" Music is fully enabled (CSI = 2 M), performs "ANSI" music
	instead.
	See "ANSI" MUSIC section for more details.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
	SOURCE: BANSI.TXT

CSI N
	"ANSI" Music / Not implemented.
	If "ANSI" Music is set to BananaCom (CSI = 1 M) or fully enabled
	(CSI = 2 M) performs "ANSI" muisic.  See "ANSI" MUSIC section for more
	details.

	SOURCE: BANSI.TXT

CSI [ p1 ] P
	Delete Character
	Defaults: p1 = 1
	Deletes the character at the current position by shifting all characters
	from the current column + p1 left to the current column.  Opened blanks
	at the end of the line are filled with the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] S
	Scroll Up
	Defaults: p1 = 1
	Scrolls all text on the screen up p1 lines.  New lines emptied at the
	bottom are filled with the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] T
	Scroll Down
	Defaults: p1 = 1
	Scrolls all text on the screen down p1 lines.  New lines emptied at the
	top are filled with the current attribute.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI U
	NON-STANDARD (Disabled in current code)
	Clear screen with default attribute.
	This code is *supposed* to go to the "next page" according to the
	ANSI/ECMA specs with CSI V going to "previous page"

	SOURCE: BANSI.TXT

CSI [ p1 ] Z
	Cursor Backward Tabulation
	Defaults: p1 = 1
	Move the cursor to the p1th preceeding tab stop.  Will not go past the
	start of the line.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] c
	Device Attributes
	Defaults: p1 = 0
	If p1 is 0, CTerm will reply with the sequence:
	CSI [ = 67;84;101;114;109;pN... c
	64;84;101;114;109 is the ASCII values of the "CTerm" string.  pN is the
	CVS revision ID of CTerm with dots converted to semi-colons.
	Use the CVS revision to detect if a specific feature is available.  If
	you are adding features to a forked version of cterm, please do so by
	adding an extra parameter to the end, not by incrementing any existing
	one!

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 [ ; pX ... ] ] m
	Select Graphic Rendition
	Defaults: p1 = 0
	Sets or clears one or more text attributes.  Unlimited parameters are
	supported and are applied in received order.  The following are
	supoprted:
	                                        Blink Bold FG BG (Modified)
	0 -  Default attribute, white on black     X    X  X  X
	1 -  Bright Intensity                           X
	2 -  Dim intensty                               X
	5 -  Blink (By definition, slow blink)     X
	6 -  Blink (By definition, fast blink)     X
	     NOTE: Both blinks are the same speed.
	7 -  Negative Image - Reverses FG and BG           X  X
	8 -  Concealed characters, sets the                X
	     forground colour to the background
		 colour.
	22 - Normal intensity                           X
	25 - Steady (Not blinking)                 X
	27 - Positive Image - Reverses FG and BG           X  X
	     NOTE: This should be a separate
		       attribute than 7 but this
			   implementation makes them equal
	30 - Black foreground                              X
	31 - Red foreground                                X
	32 - Green foreground                              X
	33 - Yellow foreground                             X
	34 - Blue foreground                               X
	35 - Magenta foreground                            X
	36 - Cyan foreground                               X
	37 - White foreground                              X
	39 - Default foreground (same as white)	           X
	40 - Black background                                 X
	41 - Red background                                   X
	42 - Green background                                 X
	43 - Yellow background                                X
	44 - Blue background                                  X
	45 - Magenta background                               X
	46 - Cyan background                                  X
	47 - White background                                 X
	49 - Default background (same as black)               X

	All others are ignored.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

CSI [ p1 ] n
	Device Status Report
	Defaults: p1 = 0
	A request for a status report.  CTerm handles the following three
	requests:
	5	- Request a DSR
		  CTerm will always reply with CSI 0 n indicating 
		  "ready, no malfunction detected"
	6	- Request active cursor position
		  CTerm will reply with CSI y ; x R where y is the current line
		  and x is
		  the current row.
	255	- NON-STANDARD EXTENSION
		  Replies as though a CSI [ 6 n was recieved with the cursor in
		  the bottom right corner.  ie: Returns the terminal size as a
		  position report.

	SOURCE: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
		(parameters 5 and 6 only)
	SOURCE: BANSI.TXT (parameter 255)

CSI s
	NON-STANDARD EXTENSION
	Save Current Position
	Saves the current cursor position for later restoring with CSI u
	although this is non-standard, it's so widely used in the BBS world that
	any terminal program MUST implement it.

	SOURCE: ANSI.SYS

CSI u
	NON-STANDARD EXTENSION
	Restore Cursor Position
	Move the cursor to the last position saved by CSI s.  If no position has
	been saved, the cursor is not moved.

	SOURCE: ANSI.SYS

"ANSI" Music
============
This is the place where the BBS world completely fell on it's face in ANSI
useage.  A programmer with either TeleMate or QModem (the first two programs to
support "ANSI" music as far as I can tell) decided they needed a method of
playing music on a BBS conenction.  They decided to add an "unused" ANSI code
and go their merry way.  Since their product didn't implement CSI M (Delete
line) they assumed it was unused and blissfully broke the spec.  They defined
"ANSI" music as:
CSI M <music string> 0x0a

They used a subset of IBM BASICs PLAY statement functionality for ANSI music
strings which oftem start with "MF" or "MB", so the M after the CSI was often
considered as part of the music string.  You would see things such as:
CSI MFABCD 0x0a and the F would not be played as a note.  This just added
further confusion to the mess.

Later on, BananaCom realized the conflict between delete line and music, so they
added *another* broken code CSI N (Properly, erase in field... not implemented
in many BBS clients) which was to provide an "unbroken" method of playing music
strings.  They also used CSI Y to disambiguate delete line, CSI Y is supposed
to be a vertical tab (also not implemented in very many clients).  BananaCom
also introduced many more non-standard and stardard-breaking control sequences
which are not supported by CTerm.

CTerm has further introduced a standard compliant ANSI music introducer CSI |

By default, CTerm allows both CSI N and CSI | to introduce a music string.
Allowed introducers are set by CSI = p1 M as defined above.

The details of ANSI music are as follows then:
The following characters are allowed in music strings:
"aAbBcCdDeEfFgGlLmMnNoOpPsStT0123456789.-+#<> "
If any character not in this list is present, the music string is ignored as
is the introducing code.

If the introducing code is CSI M the first char is examined, and if it is
a one of "BbFfLlSs" or if it is "N" or "n" and is not followed by a decimal
digit, then the music string is treated as though an M is located in front
of the first character.

The music string is then parsed with the following sequences supported:
Mx sets misc music parameters where x is one of the following:
	F - Plays music in the foreground, waiting for music to complete
	    playing before more characters are processed.
	B - Play music in the background, allowing normal processing to
	    continue.
	N - "Normal" not legato, not stacatto
	L - Play notes legato
	S - Play notes stacatto
T### Sets the tempo of the music where ### is one or more decimal digits.
	If the decimal number is greater than 255, it is forced to 255.
	If it is less than 32, it is forced to 32.  The number signifies
	quarter notes per minute.
	The default tempo is 120.
O### Sets the octave of the music where ### is one or more decimal digits.
	If the decimal number is greater than 6, it is forced to 6.
	The default octave is 4.
N### Plays a single note by number.  Valid values are 0 - 71.  Invalid
	values are played as silence.  Note zero is C in octave 0.
	See following section for valid note modifiers.
A, B, C, D, E, G, or P Plays the named note or pause from the current
	octave.  An "Octave" is the rising sequence of the following notes:
	C, C#, D, D#, E, F, F#, G, G#, A, A#, B
	This is contrary to normal music terminology.
	The special note "P" is a pause.
	Notes may be followed by one or more modifier characters which
	are applied in order.  If one overrides a previous one, the last
	is used.  The valid modifiers are:
	+ - Sharp.  The next highest semitone is played.
		Each sharp character will move up one semitone, so "C++"
		is equivilent to "D".
	# - Sharp.  The next highest semitone is played.
		Each sharp character will move up one semitone, so "C##"
		is equivilent to "D".
	- - Flat.  The next lowest semitone is played.
		Each flat character will move down one semitone, so "D--"
		is equivilent to "C".
	. - Duration is 1.5 times what it would otherwise be.  Dots are not
		cumulative, so "C.." is equivilent to "C."
	### - Notelength as a reciprical of the fraction of a whole note to
		play the note for.  For example, 4 would indicate a 1/4 note.
		The default note length is 4.
L### Set the notelength parameter for all following notes which do not have
	one specified (ie: override the quarter-note default)  Leval note lengths
	are 1-64 indicating the recibrical of the fraction (ie: 4 indicates a 1/4
	note).
<	Move the the next lowest octave.
	Octave cannot go above six or below zero.
>	Move to the next highest octave.
	Octave cannot go above six or below zero.

The lowest playable character is C in octave zero.  The frequencies for the
six C notes for the seven octaves in rising order are:
65406, 130810, 261620, 523250, 1046500, 2093000, 4186000

Purists will note that the lower three octaves are not exactly one half of
the next higher octave in frequency.  This is due to lost resolution of
low frequences.  The notes *sound* correct to me.  If anyone can give me
an excellent reason to change them (and more correct integer values for all
notes) I am willing to do that assuming the notes still sound "right".

!!!PLEASE NOTE!!! If you are playing some ANSI Music then ask the user if they
heard it, ALWAYS follow it with an 0x0b 0x0a is the shift lock character which
*will* cause people with anything but an ANSI-BBS terminal (ie: *nix users using
the bundled telnet app) to have their screen messed up.  0x0b "undoes" the 0x0a.
