/*
 * $Header: /smsa/bsd:include/dev/vcioctl.h:bsd  1.14  $
 * $Source: /smsa/bsd:include/dev/vcioctl.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 *
 */
/* vcioctl.h
 *
 * Definitions for IOCTL interface to Video Console driver
 *
 * Needs ioctl.h, fbioctl.h.
 */
#ifndef	__dev_vcioctl_h
#define	__dev_vcioctl_h

/*
 * Console/terminal ioctls: (V, 0..19, ...)
 */


/* Structure for getting/setting setup-parameters of VT220-style console */

typedef struct vciocparam
{
    unsigned char param_no;
    unsigned char param_val;
} VCIOCParam, *VCIOCParamRef;

#define VCIOCGPARAM	_IOWR('V', 0, VCIOCParam)
#define VCIOCSPARAM	_IOW('V', 1, VCIOCParam)

/* Values of param_no and param_val in VCIOCParam */

/*
 * Screen mode
 */
#define VC_SCREEN_MODE		0
/*
 * For screen mode, the param_val values are relative to the
 * lowest-size/resolution mode for the current monitor type 
 * (see VCIOCGVDUTYPE), as follows:
 *
 * low-res monitor:  
 * 	L80x20	0
 * 	L80x24	1
 * 	L80x30	2
 * multi-scan monitor:
 * 	L80x20	0
 * 	L80x24	1
 * 	L80x30	2
 *      M80x20	3
 * 	M80x24	4
 * 	M80x30	5
 * high-res monitor:
 *	H80x20	0
 *	H96x32	1
 *	H144x45	2
 * medium-res-only (near VGA) monitor:
 *      M80x20	0
 * 	M80x24	1
 * 	M80x30	2
 */

/*
 * Video polarity 
 */
#define VC_VIDEO_POLARITY	1
#define   VC_VIDEO_POLARITY_W_ON_B	0
#define   VC_VIDEO_POLARITY_B_ON_W	1

/*
 * Border level.  Note: this facility is made obsolete by the colour
 * control commands defined below.
 */
#define VC_BORDER_LEVEL		2

/* Font control */
#define VC_FONT			3
#define   VC_VONT_BASIC			0
#define   VC_VONT_FINE			1

/*
 * Autowrap - text at end of line causes newline
 * This is a simple boolean: param_val =0: off =1: on;
 * do not use any other value: it will be ignored.
 */
#define	VC_AUTOWRAP		4

/*
 * BS wrap: if on, BS at start of line causes cursor to move to 
 * end of previous line.  Another simple boolean.
 */
#define	VC_BS_WRAP		5

/* Cursor on/off: another simple boolean */
#define VC_CURSOR_VISIBLE	6

/* Cursor blink rate */
#define VC_CURSOR_BLINK		7
#define   VC_CURSOR_BLINK_SLOW		0
#define	  VC_CURSOR_BLINK_FAST		1
#define   VC_CURSOR_BLINK_OFF		2	/* (cursor steady) */

/* Cursor type */
#define VC_CURSOR_TYPE		8
#define   VC_CURSOR_TYPE_BLOCK		0
#define   VC_CURSOR_TYPE_LINE		1

/* Screen blanking */
#define VC_SCREEN_BLANK		9
#define   VC_SCREEN_BLANK_OFF		0	/* screen permanently on */
#define   VC_SCREEN_BLANK_1_MIN		1
#define   VC_SCREEN_BLANK_3_MIN		2
#define   VC_SCREEN_BLANK_10_MIN	3

/* Bell sound parameters */
#define VC_BELL_LEVEL		10
#define   VC_BELL_LEVEL_OFF		0
#define   VC_BELL_LEVEL_FAINT		1
#define   VC_BELL_LEVEL_QUIET		2
#define   VC_BELL_LEVEL_MEDIUM		3
#define   VC_BELL_LEVEL_LOUD		4

#define VC_BELL_TIME		11
#define   VC_BELL_TIME_40_MS		0
#define   VC_BELL_TIME_70_MS		1
#define   VC_BELL_TIME_100_MS		2
#define   VC_BELL_TIME_150_MS		3
#define   VC_BELL_TIME_200_MS		4
#define   VC_BELL_TIME_300_MS		5

/*
 * Global keyboard mode, i.e. the behaviour of the
 *    function keys, 
 *    Insert,Home,Page Up/Down,Copy,Delete keys
 *    numeric keypad keys.
 * Cursor keys are separately controlled by "cursor key mode".
 */
#define VC_KEYBOARD_MODE	12
#define   VC_KEYBOARD_MODE_VT200	0
#define   VC_KEYBOARD_MODE_AVC		1

#define VC_CURSOR_KEY_MODE	13
#define   VC_CURSOR_KEY_MODE_AVC	0
#define   VC_CURSOR_KEY_MODE_COPY_AVC	1
#define   VC_CURSOR_KEY_MODE_VT200	2
#define   VC_CURSOR_KEY_MODE_COPY_VT200	3
#define   VC_CURSOR_KEY_MODE_EMACS	4
#define   VC_CURSOR_KEY_MODE_COPY_EMACS	5
#define   VC_CURSOR_KEY_MODE_COPY	6
#define   VC_CURSOR_KEY_MODE_COPY_VI	7

/*
 * What the "BS" key (actually marked "<-|") generates when pressed without 
 * and with the shift key, e.g. VC_BS_KEY_ACTION_BS_DEL means generate BS if
 * shift isn't pressed, DEL if shift is pressed.
 */
#define VC_BS_KEY_ACTION	14
#define   VC_BS_KEY_ACTION_BS_BS	0
#define   VC_BS_KEY_ACTION_BS_DEL	1
#define   VC_BS_KEY_ACTION_DEL_DEL	2
#define   VC_BS_KEY_ACTION_DEL_BS	3

/* Autorepeat on keys: simple boolean */
#define VC_AUTOREPEAT		15

/* Delay time before autorepeat starts for a key */
#define VC_KEY_DELAY		16
#define   VC_KEY_DELAY_60_MS		0
#define   VC_KEY_DELAY_100_MS		1
#define   VC_KEY_DELAY_150_MS		2
#define   VC_KEY_DELAY_200_MS		3
#define   VC_KEY_DELAY_300_MS		4
#define   VC_KEY_DELAY_400_MS		5
#define   VC_KEY_DELAY_600_MS		6
#define   VC_KEY_DELAY_800_MS		7

/* Inter-key interval once autorepeat has started */
#define VC_KEY_SPACE		17
#define   VC_KEY_SPACE_10_MS		0
#define   VC_KEY_SPACE_20_MS		1
#define   VC_KEY_SPACE_30_MS		2
#define   VC_KEY_SPACE_40_MS		3
#define   VC_KEY_SPACE_50_MS		4
#define   VC_KEY_SPACE_75_MS		5
#define   VC_KEY_SPACE_100_MS		6
#define   VC_KEY_SPACE_150_MS		7
#define   VC_KEY_SPACE_200_MS		8
#define   VC_KEY_SPACE_300_MS		9
#define   VC_KEY_SPACE_400_MS		10
#define   VC_KEY_SPACE_500_MS		11

/* End of definitions for VCIOC{G,S}PARAM ioctl */


/*
 * Text colour control.
 *
 * This is applicable to any of the virtual terminals.  The 
 * current settings for a terminal may be read (they are all
 * initially grey-scales) and set by the respective commands
 * No check is performed on the sensibility of the colour 
 * relationships (e.g. having all colours the same is 
 * possible!); however the colour values used must be (12+1)-bit,
 * i.e. 4x(R,G,B)+supremacy, as defined below for colour f/b 
 * palette-control ioctls, and any value containing a 1 in a 
 * bit position greater than bit 12 will cause EINVAL to be
 * returned.  Note that two sets of colours are defined: those
 * for "normal" (i.e. "white on black"), and "inverse" (i.e. 
 * "black on white") modes, as defined in the VT200 emulator.
 */

#define VC_COLOUR_BITS		(3*4)
#define VC_COLOUR_MASK		((1 << VC_COLOUR_BITS) - 1)
#define VC_SUPREMACY		(1 << 12)
#define VC_COLOUR_VMASK		(VC_SUPREMACY | VC_COLOUR_MASK)

#define VC_TCS__ENTRIES	10
typedef struct _vctextcolourset_
{
    unsigned int tcs_entry[VC_TCS__ENTRIES];
} VCTextColourSet, *VCTextColourSetRef;
#define VC_TCS_BORDER	0			/* round the edge */
#define tcs_border	tcs_entry[VC_TCS_BORDER]	
#define VC_TCS_DISPLAY	1			/* background colour */
#define tcs_display	tcs_entry[VC_TCS_DISPLAY] 
#define VC_TCS_CURSOR	2			/* normal cursor colour */
#define tcs_cursor	tcs_entry[VC_TCS_CURSOR] 
#define VC_TCS_ICURSOR	3			/* cursor over inverse char */
#define tcs_icursor	tcs_entry[VC_TCS_ICURSOR] 
#define VC_TCS_NORMAL1	4			/* normal char colour 1 */
#define tcs_normal1	tcs_entry[VC_TCS_NORMAL1]	
#define VC_TCS_BOLD1	5			/* bold attribute chars 1 */
#define tcs_bold1	tcs_entry[VC_TCS_BOLD1]		
#define VC_TCS_NORMAL2	6			/* normal char colour 2 */
#define tcs_normal2	tcs_entry[VC_TCS_NORMAL2]	
#define VC_TCS_BOLD2	7			/* bold attribute chars 2 */
#define tcs_bold2	tcs_entry[VC_TCS_BOLD2]		
#define VC_TCS_NORMAL3	8			/* normal char colour 3 */
#define tcs_normal3	tcs_entry[VC_TCS_NORMAL3]	
#define VC_TCS_BOLD3	9			/* bold attribute chars 3 */
#define tcs_bold3	tcs_entry[VC_TCS_BOLD3]		


typedef struct _vctextcolours_
{
    VCTextColourSet tc_tcs[2];
} VCTextColours, *VCTextColoursRef;
#define VC_TC_W_ON_B	0
#define tc_w_on_b	tc_tcs[VC_TC_W_ON_B]
#define VC_TC_B_ON_W	1
#define tc_b_on_w	tc_tcs[VC_TC_B_ON_W]

#define VCIOCGTEXTCOLOURS	_IOR('V', 4, VCTextColours)
#define VCIOCSTEXTCOLOURS	_IOW('V', 4, VCTextColours)


/*
 * Event-device (kbd, mouse) ioctls: (V, 20..39, ...)
 */

#define VCIOCMOUSELINK	_IOW('V', 20, int) /* set/reset kbd-mouse events link */

typedef struct _vciocrepeat_
{
    unsigned char start_gap_csec;		/* 0 -> no auto-repeat */
    unsigned char repeat_gap_csec;
} VCIOCRepeat, *VCIOCRepeatRef;

#define VCIOCGAUTORPT	_IOR('V', 21, VCIOCRepeat) /* get auto-repeat params */
#define VCIOCSAUTORPT	_IOW('V', 22, VCIOCRepeat) /* set auto-repeat params */
#define VCIOCKBDTYPE	_IOR('V', 23, int)	/* read keyboard type */

#define VC_KBD_TYPE_UNKNOWN	(-1)		/* initial value(!?) */
#define VC_KBD_TYPE_A500		0	/* A500 */
#define VC_KBD_TYPE_AXXX_UK		1	/* Archimedes/R140 UK (old-name) */
#define VC_KBD_TYPE_ARCH_UK		1	/* Archimedes/R140 UK */
/* Note the non-contiguity of the various international ID codes... */
#define VC_KBD_TYPE_ARCH_FRANCE 	6	/* Archimedes/R140 French */
#define VC_KBD_TYPE_ARCH_GERMANY	7	/* Archimedes/R140 German */
#define VC_KBD_TYPE__COUNT		4	/* total known KB types */

typedef struct _vcioceventcount_
{
    unsigned int kbd_events;
    unsigned int mouse_events;
} VCIOCEventCount, *VCIOCEventCountRef;

/*
 * Get address of user-readable struct holding event count.
 * This call can be used on the kbd and mouse devices.
 */
#define VCIOCEVENTCOUNT	_IOR('V', 24, VCIOCEventCountRef)

/*
 * Frame Buffer (screen) device ioctls: (V, 40..59, ...)
 *
 * Note that the palette control ioctls for historical/accidental
 * reasons actually use numbers 20 and 21; this cannot readily be
 * changed: note that the VCIOCMOUSELINK and VCIOCGAUTORPT commands
 * which share use of these numbers are (a) inapplicable to the
 * frame buffer device, and (b) have different argument sizes and
 * are hence actually different in coding.
 */

/*
 * Palette description structure: defines up to 20 entries in an
 * arbitary sized word-wide device palette.  This is for use with the 
 * frame buffer device.  The "start" field of the VCIOCPalette struct
 * defines which entry of the real device palette corresponds to 
 * "value[0]" in the struct.  The "count" field specifies how many
 * contiguous real palette entries (up to a maximum of 20) are to 
 * be written to (VCIOCSPALETTE) or read from (VCIOCGPALETTE).
 * With the current fb devices, entries are specified according to
 * attached monitor type, as indicated below.
 *
 * Low and medium resolution monitors
 *   The entries are indexed as:
 *	4 bits/pixel modes:
 *         0-15: main palette
 *         16:   border colour
 *      1 bit/pixel modes:
 *         0-1:  main palette
 *         2:    border colour
 *   Each entry is constructed as 13 bits:
 *	bits 0..3  red level (0-15)
 *           4..7  green level (0-15)
 *           8..11 blue level (0-15)
 *      bit 12     supremacy bit (for external video mixing)
 *   Current hardware does not make use of the supremacy bit, which
 *   will normally be set to 0.
 *
 * High resolution monitors
 *   The entries are indexed as:
 *     0: background colour
 *     1: foreground colour
 *     2: border pattern
 *
 *   Each colour entry is constructed as for the low/medium resolution
 *   monitor case, however there are only 2 displayable "colours",
 *   black and white.  The sum of the three nominal colour levels
 *   is used to decide which displayable colour will be used: if
 *   the sum is greater than (15*3) div 2, i.e. > 22, white will be
 *   used, otherwise black.  The most obvious scheme is to use the
 *   value 0x000 for black, 0xFFF for white.  For the border pattern
 *   entry, the least significant 4 bits of the entry are replicated
 *   horizontally throughout the border area, giving variously solid
 *   black, vertical stripe patterns or solid white, according to the
 *   value: 0 gives black, 15 white, interim values stripes.
 */

typedef struct _vciocpalette_
{
    unsigned int  start;			/* initial entry # */
    unsigned int  count;			/* how many to do */
#define VCIOCPALETTE_MAX	20
    unsigned int  value[VCIOCPALETTE_MAX];	/* entry settings */
} VCIOCPalette, *VCIOCPaletteRef;

#define VCIOCGPALETTE	_IOWR('V', 20, VCIOCPalette) /* get palette entries */
#define VCIOCSPALETTE	_IOW('V', 21, VCIOCPalette) /* set palette entries */


/* Hardware cursor control */

#define VC_CURSOR_BPP		2	/* bits/pixel (fixed in h/ware) */
#define VC_CURSOR_WIDTH		32	/* pixels in x-dim (fixed in h/ware) */
#define VC_CURSOR_PATTERNS	8	/* how many patterns available */
#define VC_CURSOR_RASTER_PAIRS	(256/2)	/* total number of raster pairs */

typedef struct vc_cursor_pattern
{
    struct vc_cursor_pos
    {
	short x, y;			/* position of top left corner */
    } pos;
    struct vc_cursor_size
    {
	unsigned char rp_start, r_count;	/* position of pattern data */
    } size;
    unsigned int col1:13, col2:13, col3:13;	/* logical colours 1-3 */
} VCCursorPattern, *VCCursorPatternRef;

typedef struct vc_cursor
{
    int display, __pad[3];
    VCCursorPattern pattern[VC_CURSOR_PATTERNS];
    struct vc_cursor_raster_pair
    {
	unsigned long hrow[2][2];		/* aligned data units */
    } raster_pair[VC_CURSOR_RASTER_PAIRS];
} VCCursor, *VCCursorRef;

/* Values of display field: */
#define VC_CURSOR_OFF		-2	/* disable cursor display */
#define VC_CURSOR_CHANGING	-1	/* user modifying */
#define VC_CURSOR_PATTERN_0	0	/* display pattern 0, add pattern # */

typedef struct vc_cursor_info
{
    VCCursorRef base;			/* address of cursor structure */
    int min_x;				/* left-most cursor TL position */
    int min_y;				/* first y value for cursor start */
    int max_x;				/* right-most cursor TL position */
    int max_y;				/* last y value for cursor start */
    int pixel_hor_scale;		/* = 1 (low/med-res), = 4 (high-res) */
} VCCursorInfo, *VCCursorInfoRef;

/* Command to get information on the user-modifiable hardware cursor area */
#define VCIOCGETCURSORINFO	_IOR('V', 42, VCCursorInfo)

/*
 * Commands to control auto-blanking on the frame buffer display.
 *
 * **NOTE: These commands are now made obsolete by the generic frame buffer 
 * interface ioctl commands FBIO{GET,SET}BLANK{TIMEOUT,LULL} defined in
 * <dev/fbioctl.h>, which should be used in preference.**
 *
 * The commands VCIOC{GET,SET}FBBLANKTIME respectively read/write a time
 * value, measured in seconds, for the blanking timeout on the frame
 * buffer.  A value greater then zero enables auto-blanking, by which
 * lack of I/O activity on the fb+kbd display screen (not including
 * changes to the fb memory) over the specified interval causes the
 * screen display to be disabled.  Subsequent I/O activity re-enables the
 * display and restarts the timer.  A zero or negative value causes the
 * display to be permanently enabled.  The VCIOCSETFBBLANKTIME call has a
 * side-effect of enabling the screen (if the FB is being displayed at
 * the time).
 */

#define VCIOCGETFBBLANKTIME	_IOR('V', 44, int)
#define VCIOCSETFBBLANKTIME	_IOW('V', 45, int)

/* ioctls (V, 60..79, ...) */


/*
 * Generic ioctls: (V, 80..99, ...) 
 *
 * These may be applied to a file descriptor for an VC-controlled
 * device (i.e. /dev/{console,fb,kbd,mouse,ttyv[0-9]}).
 */


/*
 * Make a simple tone (at a fixed pitch, around 473Hz): four amplitude
 * levels (faint,quiet,medium,loud) are possible; the length is specified
 * in msec (but is resolved in units of about 8ms).
 */
typedef struct _vcioctone_
{
    unsigned int amplitude;			/* 0..3 */
    unsigned int length;			/* 0..9999 msec */
} VCIOCTone, *VCIOCToneRef;

#define VCIOCTONE	_IOW('V', 80, VCIOCTone)

/*
 * Setting of VDU type:  the call
 *   int vdutype;
 *   ioctl (fd, VCIOCGVDUTYPE, &vdutype);
 * returns the current vdu type code.
 * The old call:
 *   ioctl (fd, VCIOCSVDUTYPE, &vdutype); 
 * which used to allow the superuser to the CMOS RAM flag for
 * vdu type and reconfigure the VC driver, is no longer supported.
 */
#define VCIOCGVDUTYPE	_IOR('V', 82, int)

/*
 * Historical accident: vdu types were defined both here 
 * and in <dev/cmos.h>, so we use an include file to
 * maintain consistency.
 */
#ifndef	__dev_vdu_type_h
#include "vdu_type.h"
#endif

#endif/*__dev_vcioctl_h*/

/* EOF vcioctl.h */
