syscons.h revision 7498
1/*-
2 * Copyright (c) 1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer
10 *    in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software withough specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *	$Id: syscons.h,v 1.4 1995/03/03 08:37:08 sos Exp $
29 */
30
31#ifndef SYSCONS_H
32#define SYSCONS_H
33
34/* vm things */
35#define	ISMAPPED(pa, width) \
36	(((pa) <= (u_long)0x1000 - (width)) \
37	 || ((pa) >= 0xa0000 && (pa) <= 0x100000 - (width)))
38#define	pa_to_va(pa)	(KERNBASE + (pa))	/* works if ISMAPPED(pa...) */
39
40/* printable chars */
41#define PRINTABLE(ch)	((ch)>0x1B || ((ch)>0x0d && (ch)<0x1b) || (ch)<0x07)
42
43/* status flags */
44#define LOCK_KEY_MASK	0x0000F
45#define LED_MASK	0x00007
46#define UNKNOWN_MODE	0x00010
47#define KBD_RAW_MODE	0x00020
48#define SWITCH_WAIT_REL	0x00040
49#define SWITCH_WAIT_ACQ	0x00080
50#define BUFFER_SAVED	0x00100
51#define CURSOR_ENABLED 	0x00200
52#define CURSOR_SHOWN 	0x00400
53#define MOUSE_ENABLED	0x00800
54#define UPDATE_MOUSE	0x01000
55#define UPDATE_SCREEN	0x02000
56
57/* configuration flags */
58#define VISUAL_BELL	0x00001
59#define BLINK_CURSOR	0x00002
60#define CHAR_CURSOR	0x00004
61
62/* video hardware memory addresses */
63#define VIDEOMEM	0x000A0000
64
65/* misc defines */
66#define FALSE		0
67#define TRUE		1
68#define MAX_ESC_PAR 	5
69#define	LOAD		1
70#define SAVE		0
71#define	COL		80
72#define	ROW		25
73#define BELL_DURATION	5
74#define BELL_PITCH	800
75#define TIMER_FREQ	1193182			/* should be in isa.h */
76#define CONSOLE_BUFSIZE 1024
77#define PCBURST		128
78#define FONT_8		0x001
79#define FONT_14		0x002
80#define FONT_16		0x004
81#define HISTORY_SIZE	100*80
82
83/* defines related to hardware addresses */
84#define	MONO_BASE	0x3B4			/* crt controller base mono */
85#define	COLOR_BASE	0x3D4			/* crt controller base color */
86#define MISC		0x3C2			/* misc output register */
87#define ATC		IO_VGA+0x00		/* attribute controller */
88#define TSIDX		IO_VGA+0x04		/* timing sequencer idx */
89#define TSREG		IO_VGA+0x05		/* timing sequencer data */
90#define PIXMASK		IO_VGA+0x06		/* pixel write mask */
91#define PALRADR		IO_VGA+0x07		/* palette read address */
92#define PALWADR		IO_VGA+0x08		/* palette write address */
93#define PALDATA		IO_VGA+0x09		/* palette data register */
94#define GDCIDX		IO_VGA+0x0E		/* graph data controller idx */
95#define GDCREG		IO_VGA+0x0F		/* graph data controller data */
96
97/* special characters */
98#define cntlc	0x03
99#define cntld	0x04
100#define bs	0x08
101#define lf	0x0a
102#define cr	0x0d
103#define del	0x7f
104
105typedef struct term_stat {
106	int 		esc;			/* processing escape sequence */
107	int 		num_param;		/* # of parameters to ESC */
108	int	 	last_param;		/* last parameter # */
109	int 		param[MAX_ESC_PAR];	/* contains ESC parameters */
110	int 		cur_attr;		/* current attributes */
111	int 		std_attr;		/* normal attributes */
112	int 		rev_attr;		/* reverse attributes */
113} term_stat;
114
115typedef struct scr_stat {
116	u_short 	*scr_buf;		/* buffer when off screen */
117	int 		xpos;			/* current X position */
118	int 		ypos;			/* current Y position */
119	int 		xsize;			/* X size */
120	int 		ysize;			/* Y size */
121	int		start;			/* modified area start */
122	int		end;			/* modified area end */
123	term_stat 	term;			/* terminal emulation stuff */
124	int	 	status;			/* status (bitfield) */
125	u_short 	*cursor_pos;		/* cursor buffer position */
126	u_short		cursor_saveunder;	/* saved chars under cursor */
127	char		cursor_start;		/* cursor start line # */
128	char		cursor_end;		/* cursor end line # */
129	u_short		*mouse_pos;		/* mouse buffer position */
130	u_short		*mouse_oldpos;		/* mouse old buffer position */
131	u_short		mouse_saveunder[4];	/* saved chars under mouse */
132	short		mouse_xpos;		/* mouse x coordinate */
133	short		mouse_ypos;		/* mouse y coordinate */
134	u_char		mouse_cursor[128];	/* mouse cursor bitmap store */
135	u_short		bell_duration;
136	u_short		bell_pitch;
137	u_char		border;			/* border color */
138	u_char	 	mode;			/* mode */
139	u_char		font;			/* font on this screen */
140	pid_t 		pid;			/* pid of controlling proc */
141	struct proc 	*proc;			/* proc* of controlling proc */
142	struct vt_mode 	smode;			/* switch mode */
143	u_short		*history;		/* circular history buffer */
144	u_short		*history_head;		/* current head position */
145	u_short		*history_pos;		/* position shown on screen */
146	u_short		*history_save;		/* save area index */
147	int		history_size;		/* size of history buffer */
148	struct apmhook  r_hook;			/* reconfiguration support */
149} scr_stat;
150
151typedef struct default_attr {
152	int             std_attr;               /* normal attributes */
153	int 		rev_attr;		/* reverse attributes */
154} default_attr;
155
156/* function prototypes */
157int scprobe(struct isa_device *dev);
158int scattach(struct isa_device *dev);
159int scopen(dev_t dev, int flag, int mode, struct proc *p);
160int scclose(dev_t dev, int flag, int mode, struct proc *p);
161int scread(dev_t dev, struct uio *uio, int flag);
162int scwrite(dev_t dev, struct uio *uio, int flag);
163int scparam(struct tty *tp, struct termios *t);
164int scioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p);
165void scxint(dev_t dev);
166void scstart(struct tty *tp);
167void pccnprobe(struct consdev *cp);
168void pccninit(struct consdev *cp);
169void pccnputc(dev_t dev, char c);
170int pccngetc(dev_t dev);
171int pccncheckc(dev_t dev);
172void scintr(int unit);
173int pcmmap(dev_t dev, int offset, int nprot);
174static void scinit(void);
175static u_int scgetc(int noblock);
176       struct tty *scdevtotty(dev_t dev);
177static scr_stat *get_scr_stat(dev_t dev);
178static scr_stat *alloc_scp();
179static void init_scp(scr_stat *scp);
180static int get_scr_num();
181static void scrn_timer();
182static void clear_screen(scr_stat *scp);
183static int switch_scr(scr_stat *scp, u_int next_scr);
184static void exchange_scr(void);
185static inline void move_crsr(scr_stat *scp, int x, int y);
186static void scan_esc(scr_stat *scp, u_char c);
187static inline void draw_cursor(scr_stat *scp, int show);
188static void ansi_put(scr_stat *scp, u_char *buf, int len);
189static u_char *get_fstr(u_int c, u_int *len);
190static void update_leds(int which);
191static void history_to_screen(scr_stat *scp);
192static int history_up_line(scr_stat *scp);
193static int history_down_line(scr_stat *scp);
194static void kbd_wait(void);
195static void kbd_cmd(u_char command);
196static void set_mode(scr_stat *scp);
197       void set_border(int color);
198static void set_vgaregs(char *modetable);
199static void set_font_mode();
200static void set_normal_mode();
201static void copy_font(int operation, int font_type, char* font_image);
202static void set_destructive_cursor(scr_stat *scp);
203static void draw_mouse_image(scr_stat *scp);
204static void save_palette(void);
205       void load_palette(void);
206static void do_bell(scr_stat *scp, int pitch, int duration);
207static void blink_screen(scr_stat *scp);
208
209#endif /* SYSCONS_H */
210