-#define CH_VLINE 0x16
-
-/* color defines */
-
-/* make GTIA color value */
-#define _gtia_mkcolor(hue,lum) (((hue) << 4) | ((lum) << 1))
-
-/* luminance values go from 0 (black) to 7 (white) */
-
-/* hue values */
-#define HUE_GREY 0
-#define HUE_GOLD 1
-#define HUE_GOLDORANGE 2
-#define HUE_REDORANGE 3
-#define HUE_ORANGE 4
-#define HUE_MAGENTA 5
-#define HUE_PURPLE 6
-#define HUE_BLUE 7
-#define HUE_BLUE2 8
-#define HUE_CYAN 9
-#define HUE_BLUEGREEN 10
-#define HUE_BLUEGREEN2 11
-#define HUE_GREEN 12
-#define HUE_YELLOWGREEN 13
-#define HUE_YELLOW 14
-#define HUE_YELLOWRED 15
-
-/* Color defines, similar to c64 colors (untested) */
-#define COLOR_BLACK _gtia_mkcolor(HUE_GREY,0)
-#define COLOR_WHITE _gtia_mkcolor(HUE_GREY,7)
-#define COLOR_RED _gtia_mkcolor(HUE_REDORANGE,1)
-#define COLOR_CYAN _gtia_mkcolor(HUE_CYAN,3)
-#define COLOR_VIOLET _gtia_mkcolor(HUE_PURPLE,4)
-#define COLOR_GREEN _gtia_mkcolor(HUE_GREEN,2)
-#define COLOR_BLUE _gtia_mkcolor(HUE_BLUE,2)
-#define COLOR_YELLOW _gtia_mkcolor(HUE_YELLOW,7)
-#define COLOR_ORANGE _gtia_mkcolor(HUE_ORANGE,5)
-#define COLOR_BROWN _gtia_mkcolor(HUE_YELLOW,2)
-#define COLOR_LIGHTRED _gtia_mkcolor(HUE_REDORANGE,6)
-#define COLOR_GRAY1 _gtia_mkcolor(HUE_GREY,2)
-#define COLOR_GRAY2 _gtia_mkcolor(HUE_GREY,3)
-#define COLOR_LIGHTGREEN _gtia_mkcolor(HUE_GREEN,6)
-#define COLOR_LIGHTBLUE _gtia_mkcolor(HUE_BLUE,6)
-#define COLOR_GRAY3 _gtia_mkcolor(HUE_GREY,5)
-
-/* color register functions */
-extern void __fastcall__ setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace);
-extern void __fastcall__ setcolor_low (unsigned char color_reg, unsigned char color_value);
-extern unsigned char __fastcall__ getcolor (unsigned char color_reg);
-
-/* other screen functions */
-extern void __fastcall__ scroll (signed char numlines);
+#define CH_VLINE 0x7C
+
+
+/*****************************************************************************/
+/* Masks for joy_read */
+/*****************************************************************************/
+
+#define JOY_UP_MASK 0x01
+#define JOY_DOWN_MASK 0x02
+#define JOY_LEFT_MASK 0x04
+#define JOY_RIGHT_MASK 0x08
+#define JOY_BTN_1_MASK 0x10
+
+#define JOY_FIRE_MASK JOY_BTN_1_MASK
+#define JOY_FIRE(v) ((v) & JOY_FIRE_MASK)
+
+
+/*****************************************************************************/
+/* Keyboard values returned by kbcode / CH */
+/*****************************************************************************/
+
+#define KEY_NONE ((unsigned char) 0xFF)
+
+#define KEY_0 ((unsigned char) 0x32)
+#define KEY_1 ((unsigned char) 0x1F)
+#define KEY_2 ((unsigned char) 0x1E)
+#define KEY_3 ((unsigned char) 0x1A)
+#define KEY_4 ((unsigned char) 0x18)
+#define KEY_5 ((unsigned char) 0x1D)
+#define KEY_6 ((unsigned char) 0x1B)
+#define KEY_7 ((unsigned char) 0x33)
+#define KEY_8 ((unsigned char) 0x35)
+#define KEY_9 ((unsigned char) 0x30)
+
+#define KEY_A ((unsigned char) 0x3F)
+#define KEY_B ((unsigned char) 0x15)
+#define KEY_C ((unsigned char) 0x12)
+#define KEY_D ((unsigned char) 0x3A)
+#define KEY_E ((unsigned char) 0x2A)
+#define KEY_F ((unsigned char) 0x38)
+#define KEY_G ((unsigned char) 0x3D)
+#define KEY_H ((unsigned char) 0x39)
+#define KEY_I ((unsigned char) 0x0D)
+#define KEY_J ((unsigned char) 0x01)
+#define KEY_K ((unsigned char) 0x05)
+#define KEY_L ((unsigned char) 0x00)
+#define KEY_M ((unsigned char) 0x25)
+#define KEY_N ((unsigned char) 0x23)
+#define KEY_O ((unsigned char) 0x08)
+#define KEY_P ((unsigned char) 0x0A)
+#define KEY_Q ((unsigned char) 0x2F)
+#define KEY_R ((unsigned char) 0x28)
+#define KEY_S ((unsigned char) 0x3E)
+#define KEY_T ((unsigned char) 0x2D)
+#define KEY_U ((unsigned char) 0x0B)
+#define KEY_V ((unsigned char) 0x10)
+#define KEY_W ((unsigned char) 0x2E)
+#define KEY_X ((unsigned char) 0x16)
+#define KEY_Y ((unsigned char) 0x2B)
+#define KEY_Z ((unsigned char) 0x17)
+
+#define KEY_COMMA ((unsigned char) 0x20)
+#define KEY_PERIOD ((unsigned char) 0x22)
+#define KEY_SLASH ((unsigned char) 0x26)
+#define KEY_SEMICOLON ((unsigned char) 0x02)
+#define KEY_PLUS ((unsigned char) 0x06)
+#define KEY_ASTERISK ((unsigned char) 0x07)
+#define KEY_DASH ((unsigned char) 0x0E)
+#define KEY_EQUALS ((unsigned char) 0x0F)
+#define KEY_LESSTHAN ((unsigned char) 0x36)
+#define KEY_GREATERTHAN ((unsigned char) 0x37)
+
+#define KEY_ESC ((unsigned char) 0x1C)
+#define KEY_TAB ((unsigned char) 0x2C)
+#define KEY_SPACE ((unsigned char) 0x21)
+#define KEY_RETURN ((unsigned char) 0x0C)
+#define KEY_DELETE ((unsigned char) 0x34)
+#define KEY_CAPS ((unsigned char) 0x3C)
+#define KEY_INVERSE ((unsigned char) 0x27)
+#define KEY_HELP ((unsigned char) 0x11)
+
+/* Function keys only exist on the 1200XL model. */
+#define KEY_F1 ((unsigned char) 0x03)
+#define KEY_F2 ((unsigned char) 0x04)
+#define KEY_F3 ((unsigned char) 0x13)
+#define KEY_F4 ((unsigned char) 0x14)
+
+/* N.B. Cannot read Ctrl key alone */
+#define KEY_CTRL ((unsigned char) 0x80)
+
+/* N.B. Cannot read Shift key alone via KBCODE;
+** instead, check "Shfit key press" bit of SKSTAT register.
+** Also, no way to tell left Shift from right Shift.
+*/
+#define KEY_SHIFT ((unsigned char) 0x40)
+
+
+/* Composed keys
+** (Other combinations are possible, including Shift+Ctrl+key,
+** though not all such combinations are available.)
+*/
+
+#define KEY_EXCLAMATIONMARK (KEY_1 | KEY_SHIFT)
+#define KEY_QUOTE (KEY_2 | KEY_SHIFT)
+#define KEY_HASH (KEY_3 | KEY_SHIFT)
+#define KEY_DOLLAR (KEY_4 | KEY_SHIFT)
+#define KEY_PERCENT (KEY_5 | KEY_SHIFT)
+#define KEY_AMPERSAND (KEY_6 | KEY_SHIFT)
+#define KEY_APOSTROPHE (KEY_7 | KEY_SHIFT)
+#define KEY_AT (KEY_8 | KEY_SHIFT)
+#define KEY_OPENINGPARAN (KEY_9 | KEY_SHIFT)
+#define KEY_CLOSINGPARAN (KEY_0 | KEY_SHIFT)
+#define KEY_UNDERLINE (KEY_DASH | KEY_SHIFT)
+#define KEY_BAR (KEY_EQUALS | KEY_SHIFT)
+#define KEY_COLON (KEY_SEMICOLON | KEY_SHIFT)
+#define KEY_BACKSLASH (KEY_PLUS | KEY_SHIFT)
+#define KEY_CIRCUMFLEX (KEY_ASTERISK | KEY_SHIFT)
+#define KEY_OPENINGBRACKET (KEY_COMMA | KEY_SHIFT)
+#define KEY_CLOSINGBRACKET (KEY_PERIOD | KEY_SHIFT)
+#define KEY_QUESTIONMARK (KEY_SLASH | KEY_SHIFT)
+#define KEY_CLEAR (KEY_LESSTHAN | KEY_SHIFT)
+#define KEY_INSERT (KEY_GREATERTHAN | KEY_SHIFT)
+
+#define KEY_UP (KEY_UNDERLINE | KEY_CTRL)
+#define KEY_DOWN (KEY_EQUALS | KEY_CTRL)
+#define KEY_LEFT (KEY_PLUS | KEY_CTRL)
+#define KEY_RIGHT (KEY_ASTERISK | KEY_CTRL)
+
+
+/*****************************************************************************/
+/* Color register functions */
+/*****************************************************************************/
+
+extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace);
+extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value);
+extern unsigned char __fastcall__ _getcolor (unsigned char color_reg);
+
+/*****************************************************************************/
+/* Other screen functions */
+/*****************************************************************************/
+
+extern int __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */
+extern void __fastcall__ _scroll (signed char numlines);