/*
 * $Header: /smsa/bsd:include/dev/screen.h:bsd  1.15  $
 * $Source: /smsa/bsd:include/dev/screen.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 */

#ifndef __dev_screen_h
#define __dev_screen_h

#ifdef	_KERNEL

/* screen.h
 *
 * Low-level screen driving facilities: kernel internal interface.
 *
 */

/* Graphics palette set */
typedef struct
{
    unsigned int main[16+1];			/* main palette + border */
    unsigned int cursor[3];			/* cursor colours (TBD) */
} SCRPalette, *SCRPaletteRef;

/* Text colour set (for non-high-res modes) */
typedef VCTextColourSet SCRColours, *SCRColoursRef;

/*
 * Mode sets: used in configuring driver according to monitor type and
 * user configuration settings
*/
typedef int SCR_ModeSet, *SCR_ModeSetRef;
#define SCR_MODESET0		0
#define SCR_MODESET1(mode)	(1 << (mode))
#define SCR_MODESET_INCL(m,ms)	(SCR_MODESET1(m) | (ms))
#define SCR_MODESETS(mode)	SCR_MODESET1(SCR_Mode_/**/mode)
#define SCR_MODESETR(low,high)	((~0 << SCR_Mode_/**/low) & \
				 ~(~0 << (SCR_Mode_/**/high + 1)))
#define SCR_IN_MODESET(mode,set) ((SCR_MODESET1(mode) & (set)) != 0)

/* procedures */

extern void SCR_configure (int vdu_type, bool allow_8bpp);
extern void SCR_initialise (int mode, int polarity, bool csync, bool isync);
extern SCR_ModeSet SCR_allowed_modes (void);

/*
 * SCR_shutdown is called just before rebooting.  It must santise the
 * state of the hardware so that RISC OS can cope.  It is needed
 * because RISC OS 2.00 does not cope with the VIDC clock control
 * support.
*/
extern void SCR_shutdown (void);

extern void SCR_set_medium_res_type (bool is_multi);

extern void SCR_set_mode (int mode);
extern void SCR_set_polarity (int polarity);		/* for monochrome modes */
extern void SCR_set_colours (SCRColoursRef c);	/* for colour-able modes */
extern void SCR_get_default_colours (SCRColoursRef c, int polarity);
extern void SCR_set_font (int fontno);
extern void SCR_set_cursor_mode (int speed, int type);
extern void SCR_set_border_colour (int red, int green, int blue);
extern void SCR_set_blank_time (int seconds);
extern void SCR_set_blank_lull (int seconds);
extern int  SCR_get_blank_lull (void);

extern void SCR_blink_border (bool blink);
extern void SCR_position_cursor (int xy, int flags);
extern void SCR_scroll_up (void);
extern void SCR_scroll_down (void);
extern void SCR_copy_lines (int dst_y, int count, int src_y);
extern void SCR_blank_lines (int y, int count);
extern void SCR_clear_screen (void);
/* Frame-buffer stuff */
extern void SCR_clear_fb (void);
extern caddr_t SCR_fbbase (int fbtype);
extern void SCR_get_default_palette (int mode, SCRPaletteRef p);
extern void SCR_set_palette (SCRPaletteRef p);
extern void SCR_get_cursor_info (unsigned int fbtype, VCCursorInfoRef ci);

typedef void (*SCR_DisplayCharsProc) (int xy, int count,
				      unsigned char *buff, int mode);
typedef void (*SCR_BlankCharsProc) (int xy, int count);

extern struct _SCR_procs
{
    SCR_DisplayCharsProc display_chars;
    SCR_BlankCharsProc blank_chars;
} SCR_procs;


#define SCR_display_chars	(*SCR_procs.display_chars)
#define SCR_blank_chars		(*SCR_procs.blank_chars)


/*
 * SCR_active is the global flag for whether the VC interface is in use.
 * Anyone can set this to #0 to indicate that the screen display should be
 * activated for the next N seconds (where N is the screen-blank interval
 * set by calling SCR_set_blank_time).  The vertical flyback interrupt
 * routine restarts its count whenever it finds this flag #0, and also sets
 * the flag back to 0.  If the count runs out, the screen is blanked until
 * screen_active is seen #0 again.
 */
extern int SCR_active;
#define SCR_refresh()	SCR_active = 1		/* Macro for marking VC activity */


/* Text modes */

/* low-res first */
#define SCR_Mode_L80x20		0
#define SCR_Mode_L80x25		1
#define SCR_Mode_L80x24		2		/* VT220 exact size (low-res) */
#define SCR_Mode_L80x30		3
/* medium res */
#define SCR_Mode_M80x20		4
#define	SCR_Mode_M80x25		5
#define SCR_Mode_M80x24		6		/* VT220 on medium res (multi-sync) */
#define SCR_Mode_M80x30		7
/* Super VGA */
#define SCR_Mode_S100x30	8		/* using 8x10*2 chars */
#define SCR_Mode_S100x37	9		/* using 8x8*2 chars */
#define SCR_Mode_S80x20		10		/* note: out of size order */
#define	SCR_Mode_S80x25		11		/* ditto */
/* then high-resolution ones */
#define SCR_Mode_H80x20		12		/* "console" mode: smaller (high-res) */
#define SCR_Mode_H80x25		13		/* "console" mode: smaller (high-res) */
#define SCR_Mode_H96x32	        14		/* slightly bigger (high-res)*/
#define SCR_Mode_H144x45	15		/* much bigger (high-res)*/

/* How many text modes there are: */
#define SCR_Text_Modes		16

/*
 * Graphics modes
 */
#define SCR_First_Graphics_Mode	SCR_Mode_LGraphics_1
#define SCR_Mode_LGraphics_1	16		/* low-res mono graphics */
#define SCR_Mode_LGraphics_4	17		/* low-res colour graphics */
#define SCR_Mode_LGraphics_8	18		/* 8bpp low-res col. graphics */
#define SCR_Mode_MGraphics_1	19		/* medium res mono graphics */
#define SCR_Mode_MGraphics_2	20
#define SCR_Mode_MGraphics_4	21		/* medium res colour graphics */
#define SCR_Mode_MGraphics_8	22		/* 8bpp med-res col. graphics */
#define SCR_Mode_SGraphics_1	23		/* 1bpp super-VGA 768x600 */
#define SCR_Mode_SGraphics_2	24		/* 2bpp super-VGA 768x600 */
#define SCR_Mode_SGraphics_4	25		/* 4bpp super-VGA 800x600 */
#define SCR_Mode_HGraphics	26		/* high-res graphics */
#define SCR_Last_Graphics_Mode	SCR_Mode_HGraphics

/* How many graphics modes there are: */
#define SCR_Graphics_Modes	(SCR_Last_Graphics_Mode - SCR_First_Graphics_Mode + 1)

/*
 * Count of how many modes there are:
 */
#define	SCR_Mode_Count		(SCR_Last_Graphics_Mode + 1)

/* Monitor/Mode compatibility map */
#define SCR_MODESET_LOW_RES	(SCR_MODESETR(L80x20,L80x30) | \
				 SCR_MODESETR(LGraphics_1,LGraphics_8))
#define SCR_MODESET_MULTISCAN	(SCR_MODESETR(L80x20,S100x37) | \
				 SCR_MODESETR(LGraphics_1,SGraphics_4))
#define SCR_MODESET_HIGH_RES	(SCR_MODESETR(H80x20,H144x45) | \
				 SCR_MODESETS(HGraphics))
#define SCR_MODESET_VGA		(SCR_MODESETR(M80x20,M80x30) | \
				 SCR_MODESETR(MGraphics_1,MGraphics_8))
#define SCR_MODESET_SUPER_VGA	(SCR_MODESETR(M80x20,S100x37) | \
				 SCR_MODESETR(MGraphics_1,SGraphics_4))

/* Font-switching (only affects ISO base char set) */
#define SCR_Font_basic		0
#define SCR_Font_fine		1
#define SCR_Font__count		2

/* Polarity codes for SCR_set_polarity */
#define SCR_Polarity_w_on_b	0
#define SCR_Polarity_b_on_w	1
#define SCR_Polarity_Count	2		/* how many Polarities(!!) */

/*
 * The following sets of defines give values to be used for the mode
 * parameter to SCR_display_chars.  The SCR_Col_xxx, SCR_Att_Flash and
 * SCR_Att_Bold bits are or'ed together to produce the logical pixel 
 * bits.  The SCR_Att_Inverse bit when present causes reversal of the 
 * sense of the bits defining the character layout - i.e. foreground 
 * pixels become background and vice versa. Note that in some modes 
 * some of these values are indistinguishable, e.g. flashing colours
 * are not implemented in the high-resolution modes or any other 1-bit
 * per pixel mode. Those attributes which affect individual characters 
 * are defined in the bottom byte of the mode value since they are
 * stored in one byte/character by the upper level code.  The Col and
 * CSet fields are ordered sets of values, whereas the individual
 * Att bits are in no particular order (and are in fact not contiguous).
 */

/* Bold attribute */
#define SCR_Att_Bold			0x0001

/* "Colours" - select one of three (Black is useless) */
#define SCR_Col_Black			0x0000	/* unusable */
#define SCR_Col_C1	        	0x0002
#define SCR_Col_C2			0x0004
#define SCR_Col_C3			0x0006
#define SCR_Col__shift			1
#define SCR_Col__bits			2
#define SCR_Col__count			4
#define SCR_Col__mask			0x0006

/* Attribute bit which for convenience is adjacent to the colour bits */
#define SCR_Att_Flash			0x0008

#define SCR_Colour_Mask	(SCR_Att_Bold|SCR_Col__mask|SCR_Att_Flash)

/*
 * Character sets
 */
#define SCR_CSet_ISO_base		0x0000
#define SCR_CSet_DEC_special		0x0010
#define SCR_CSet_DEC_supplemental	0x0020
#define SCR_CSet_ISO_latin_1		0x0030
#define SCR_CSet__shift			4
#define SCR_CSet__bits			2
#define SCR_CSet__count			4
#define SCR_CSet__mask			0x0030

/* Attributes - OR in 0 or more desired attributes */
#define SCR_Att_Inverse			0x0040
#define SCR_Att_Underlined		0x0080
#define SCR_Att_DoubleWide		0x0100
#define SCR_Att_DoubleHigh		0x0200
#define SCR_Att_TopHalf			0x0400		/* flag - off => bottom half */

/* Cursor "speed" settings (SCR_set_cursor_mode) */
#define SCR_Cursor_Speed_off	0
#define SCR_Cursor_Speed_slow	1
#define SCR_Cursor_Speed_fast	2
#define SCR_Cursor_Speed_on	3
#define SCR_Cursor_Speed_Count	4		/* how many of above Speeds */

/* Cursor "type" settings (SCR_set_cursor_mode) */
#define SCR_Cursor_Type_block	0
#define SCR_Cursor_Type_uline	1
#define SCR_Cursor_Type_Count	2		/* how many of above Types */

/* Border levels (SCR_set_border_level) */
#define SCR_Border_Level_black	0
#define SCR_Border_Level_white	15
#define SCR_Border_Level_Count	16

#endif/*_KERNEL*/

#endif/*__dev_screen_h*/

/* EOF screen.h */
