-GLOBAL HINSTANCE putty_inst;
-
-#define ATTR_ACTCURS 0x80000000UL /* active cursor (block) */
-#define ATTR_PASCURS 0x40000000UL /* passive cursor (box) */
-#define ATTR_INVALID 0x20000000UL
-#define ATTR_WRAPPED 0x10000000UL
-
-#define ATTR_ASCII 0x00000000UL /* normal ASCII charset ESC ( B */
-#define ATTR_GBCHR 0x00100000UL /* UK variant charset ESC ( A */
-#define ATTR_LINEDRW 0x00200000UL /* line drawing charset ESC ( 0 */
-
-#define ATTR_BOLD 0x00000100UL
-#define ATTR_UNDER 0x00000200UL
-#define ATTR_REVERSE 0x00000400UL
-#define ATTR_FGMASK 0x0000F000UL
-#define ATTR_BGMASK 0x000F0000UL
-#define ATTR_FGSHIFT 12
-#define ATTR_BGSHIFT 16
-
-#define ATTR_DEFAULT 0x00098000UL
-#define ATTR_DEFFG 0x00008000UL
-#define ATTR_DEFBG 0x00090000UL
-#define ATTR_CUR_XOR 0x000BA000UL
-#define ERASE_CHAR (ATTR_DEFAULT | ' ')
+/* Three attribute types:
+ * The ATTRs (normal attributes) are stored with the characters in the main
+ * display arrays
+ *
+ * The TATTRs (temporary attributes) are generated on the fly, they can overlap
+ * with characters but not with normal attributes.
+ *
+ * The LATTRs (line attributes) conflict with no others and only have one
+ * value per line. But on area clears the LATTR cells are set to the erase_char
+ * (or DEFAULT_ATTR + 'E')
+ *
+ * ATTR_INVALID is an illegal colour combination.
+ */
+
+#define TATTR_ACTCURS 0x4UL /* active cursor (block) */
+#define TATTR_PASCURS 0x2UL /* passive cursor (box) */
+#define TATTR_RIGHTCURS 0x1UL /* cursor-on-RHS */
+
+#define LATTR_NORM 0x00000000UL
+#define LATTR_WIDE 0x01000000UL
+#define LATTR_TOP 0x02000000UL
+#define LATTR_BOT 0x03000000UL
+#define LATTR_MODE 0x03000000UL
+#define LATTR_WRAPPED 0x10000000UL
+
+#define ATTR_INVALID 0x00FF0000UL
+
+/* Like Linux use the F000 page for direct to font. */
+#define ATTR_OEMCP 0x0000F000UL /* OEM Codepage DTF */
+#define ATTR_ACP 0x0000F100UL /* Ansi Codepage DTF */
+
+/* These are internal use overlapping with the UTF-16 surrogates */
+#define ATTR_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
+#define ATTR_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
+#define ATTR_SCOACS 0x0000DA00UL /* SCO Alternate charset */
+#define ATTR_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
+#define CSET_MASK 0x0000FF00UL /* Character set mask; MUST be 0xFF00 */
+
+#define DIRECT_CHAR(c) ((c&0xFC00)==0xD800)
+#define DIRECT_FONT(c) ((c&0xFE00)==0xF000)
+
+#define UCSERR (ATTR_LINEDRW|'a') /* UCS Format error character. */
+#define UCSWIDE 0x303F
+
+#define ATTR_NARROW 0x20000000UL
+#define ATTR_WIDE 0x10000000UL
+#define ATTR_BOLD 0x01000000UL
+#define ATTR_UNDER 0x02000000UL
+#define ATTR_REVERSE 0x04000000UL
+#define ATTR_BLINK 0x08000000UL
+#define ATTR_FGMASK 0x000F0000UL
+#define ATTR_BGMASK 0x00F00000UL
+#define ATTR_COLOURS 0x00FF0000UL
+#define ATTR_FGSHIFT 16
+#define ATTR_BGSHIFT 20
+
+#define ATTR_DEFAULT 0x00980000UL
+#define ATTR_DEFFG 0x00080000UL
+#define ATTR_DEFBG 0x00900000UL
+#define ERASE_CHAR (ATTR_DEFAULT | ATTR_ASCII | ' ')