syscons.h revision 8017
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.7 1995/04/04 20:04:17 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) \
42			 || (ch) < 0x07)
43
44/* macros for "intelligent" screen update */
45#define mark_for_update(scp, x)	{\
46			  	    if ((x) < scp->start) scp->start = (x);\
47				    else if ((x) > scp->end) scp->end = (x);\
48				}
49#define mark_all(scp)		{\
50				    scp->start = 0;\
51				    scp->end = scp->xsize * scp->ysize;\
52				}
53
54/* status flags */
55#define LOCK_KEY_MASK	0x0000F
56#define LED_MASK	0x00007
57#define UNKNOWN_MODE	0x00010
58#define KBD_RAW_MODE	0x00020
59#define SWITCH_WAIT_REL	0x00040
60#define SWITCH_WAIT_ACQ	0x00080
61#define BUFFER_SAVED	0x00100
62#define CURSOR_ENABLED 	0x00200
63#define CURSOR_SHOWN 	0x00400
64#define MOUSE_ENABLED	0x00800
65#define UPDATE_MOUSE	0x01000
66
67/* configuration flags */
68#define VISUAL_BELL	0x00001
69#define BLINK_CURSOR	0x00002
70#define CHAR_CURSOR	0x00004
71
72/* video hardware memory addresses */
73#define VIDEOMEM	0x000A0000
74
75/* misc defines */
76#define FALSE		0
77#define TRUE		1
78#define MAX_ESC_PAR 	5
79#define	LOAD		1
80#define SAVE		0
81#define	COL		80
82#define	ROW		25
83#define BELL_DURATION	5
84#define BELL_PITCH	800
85#define TIMER_FREQ	1193182			/* should be in isa.h */
86#define CONSOLE_BUFSIZE 1024
87#define PCBURST		128
88#define FONT_8		0x001
89#define FONT_14		0x002
90#define FONT_16		0x004
91#define HISTORY_SIZE	100*80
92
93/* defines related to hardware addresses */
94#define	MONO_BASE	0x3B4			/* crt controller base mono */
95#define	COLOR_BASE	0x3D4			/* crt controller base color */
96#define MISC		0x3C2			/* misc output register */
97#define ATC		IO_VGA+0x00		/* attribute controller */
98#define TSIDX		IO_VGA+0x04		/* timing sequencer idx */
99#define TSREG		IO_VGA+0x05		/* timing sequencer data */
100#define PIXMASK		IO_VGA+0x06		/* pixel write mask */
101#define PALRADR		IO_VGA+0x07		/* palette read address */
102#define PALWADR		IO_VGA+0x08		/* palette write address */
103#define PALDATA		IO_VGA+0x09		/* palette data register */
104#define GDCIDX		IO_VGA+0x0E		/* graph data controller idx */
105#define GDCREG		IO_VGA+0x0F		/* graph data controller data */
106
107/* special characters */
108#define cntlc		0x03
109#define cntld		0x04
110#define bs		0x08
111#define lf		0x0a
112#define cr		0x0d
113#define del		0x7f
114
115#define DEAD_CHAR 	0x07			/* char used for cursor */
116
117typedef struct term_stat {
118	int 		esc;			/* processing escape sequence */
119	int 		num_param;		/* # of parameters to ESC */
120	int	 	last_param;		/* last parameter # */
121	int 		param[MAX_ESC_PAR];	/* contains ESC parameters */
122	int 		cur_attr;		/* current attributes */
123	int 		std_attr;		/* normal attributes */
124	int 		rev_attr;		/* reverse attributes */
125} term_stat;
126
127typedef struct scr_stat {
128	u_short 	*scr_buf;		/* buffer when off screen */
129	int 		xpos;			/* current X position */
130	int 		ypos;			/* current Y position */
131	int 		xsize;			/* X size */
132	int 		ysize;			/* Y size */
133	int		start;			/* modified area start */
134	int		end;			/* modified area end */
135	term_stat 	term;			/* terminal emulation stuff */
136	int	 	status;			/* status (bitfield) */
137	u_short 	*cursor_pos;		/* cursor buffer position */
138	u_short		cursor_saveunder;	/* saved chars under cursor */
139	char		cursor_start;		/* cursor start line # */
140	char		cursor_end;		/* cursor end line # */
141	u_short		*mouse_pos;		/* mouse buffer position */
142	u_short		*mouse_oldpos;		/* mouse old buffer position */
143	u_short		mouse_saveunder[4];	/* saved chars under mouse */
144	short		mouse_xpos;		/* mouse x coordinate */
145	short		mouse_ypos;		/* mouse y coordinate */
146	u_char		mouse_cursor[128];	/* mouse cursor bitmap store */
147	u_short		bell_duration;
148	u_short		bell_pitch;
149	u_char		border;			/* border color */
150	u_char	 	mode;			/* mode */
151	u_char		font;			/* font on this screen */
152	pid_t 		pid;			/* pid of controlling proc */
153	struct proc 	*proc;			/* proc* of controlling proc */
154	struct vt_mode 	smode;			/* switch mode */
155	u_short		*history;		/* circular history buffer */
156	u_short		*history_head;		/* current head position */
157	u_short		*history_pos;		/* position shown on screen */
158	u_short		*history_save;		/* save area index */
159	int		history_size;		/* size of history buffer */
160	struct apmhook  r_hook;			/* reconfiguration support */
161} scr_stat;
162
163typedef struct default_attr {
164	int             std_attr;               /* normal attributes */
165	int 		rev_attr;		/* reverse attributes */
166} default_attr;
167
168/* function prototypes */
169int scprobe(struct isa_device *dev);
170int scattach(struct isa_device *dev);
171int scopen(dev_t dev, int flag, int mode, struct proc *p);
172int scclose(dev_t dev, int flag, int mode, struct proc *p);
173int scread(dev_t dev, struct uio *uio, int flag);
174int scwrite(dev_t dev, struct uio *uio, int flag);
175int scparam(struct tty *tp, struct termios *t);
176int scioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p);
177void scxint(dev_t dev);
178void scstart(struct tty *tp);
179void scintr(int unit);
180int pcmmap(dev_t dev, int offset, int nprot);
181static void scinit(void);
182static u_int scgetc(int noblock);
183       struct tty *scdevtotty(dev_t dev);
184static scr_stat *get_scr_stat(dev_t dev);
185static scr_stat *alloc_scp();
186static void init_scp(scr_stat *scp);
187static int get_scr_num();
188static void scrn_timer();
189static void clear_screen(scr_stat *scp);
190static int switch_scr(scr_stat *scp, u_int next_scr);
191static void exchange_scr(void);
192static inline void move_crsr(scr_stat *scp, int x, int y);
193static void scan_esc(scr_stat *scp, u_char c);
194static inline void draw_cursor(scr_stat *scp, int show);
195static void ansi_put(scr_stat *scp, u_char *buf, int len);
196static u_char *get_fstr(u_int c, u_int *len);
197static void update_leds(int which);
198static void history_to_screen(scr_stat *scp);
199static int history_up_line(scr_stat *scp);
200static int history_down_line(scr_stat *scp);
201static void kbd_wait(void);
202static void kbd_cmd(u_char command);
203static void set_mode(scr_stat *scp);
204       void set_border(int color);
205static void set_vgaregs(char *modetable);
206static void set_font_mode();
207static void set_normal_mode();
208static void copy_font(int operation, int font_type, char* font_image);
209static void set_destructive_cursor(scr_stat *scp, int force);
210static void draw_mouse_image(scr_stat *scp);
211static void save_palette(void);
212       void load_palette(void);
213static void do_bell(scr_stat *scp, int pitch, int duration);
214static void blink_screen(scr_stat *scp);
215
216#endif /* SYSCONS_H */
217