Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* Copyright 1992 by Holger Veit |
2 | * May be freely used with Bill Jolitz's port of | |
3 | * 386bsd and may be included in a 386bsd collection | |
4 | * as long as binary and source are available and reproduce the above | |
5 | * copyright. | |
6 | * | |
7 | * You may freely modify this code and contribute improvements based | |
8 | * on this code as long as you don't claim to be the original author. | |
9 | * Commercial use of this source requires permittance of the copyright | |
10 | * holder. A general license for 386bsd will override this restriction. | |
11 | * | |
12 | * Use at your own risk. The copyright holder or any person who makes | |
13 | * this code available for the public (administrators of public archives | |
14 | * for instance) are not responsible for any harm to hardware or software | |
15 | * that might happen due to wrong application or program faults. | |
16 | * | |
17 | * @(#) $RCSfile: co_vty.c,v $ $Revision: 1.6 $ (Contributed to 386bsd) $Date: 93/01/23 23:14:58 $ | |
18 | * | |
19 | * This file includes the data table for virtual terminals | |
20 | */ | |
21 | static char *rcsid = "$Header: /usr/src/sys.386bsd/i386/isa/codrv/RCS/co_vty.c,v 1.6 93/01/23 23:14:58 root Exp Locker: root $"; | |
22 | ||
23 | /* | |
24 | * History: see CO_HISTORY | |
25 | */ | |
26 | ||
27 | #include <machine/stdarg.h> | |
28 | #include "co_hdr.h" | |
29 | ||
30 | #ifdef MINITERM | |
31 | #define NVTY 1 | |
32 | #else | |
33 | #include "vty.h" | |
34 | #endif | |
35 | ||
36 | #if NVTY > 0 | |
37 | ||
38 | #if NVTY > 12 | |
39 | #undef NVTY | |
40 | #define NVTY 12 | |
41 | #endif | |
42 | ||
43 | #else /* ! NVTY > 0 */ | |
44 | #undef NVTY | |
45 | #define NVTY 1 | |
46 | #endif /* ! NVTY > 0 */ | |
47 | ||
48 | struct vty vtys[NVTY]; | |
49 | struct tty pccons[NVTY]; | |
50 | int nvty = NVTY; | |
51 | ||
52 | /* | |
53 | * returns a pointer to a vty, when called with a | |
54 | * vty devmajor/minor, 0 when called with /dev/kbd | |
55 | */ | |
56 | struct vty *dev2vty(dev_t dev) | |
57 | { | |
58 | register m = minor(dev); | |
59 | ||
60 | /* check whether called from a vty or kbd: | |
61 | * kbd has global scope | |
62 | */ | |
63 | if (major(dev)==consoftc.cs_mymajor) | |
64 | return 0; | |
65 | ||
66 | return &vtys[m>=nvty?0:m]; | |
67 | } | |
68 | ||
69 | /* | |
70 | * initialize the vty data structure | |
71 | */ | |
72 | void vty_init(int first) | |
73 | { | |
74 | int i,adr; | |
75 | struct vty *vp; | |
76 | struct outmode *std,*kern; | |
77 | ||
78 | /* first mode: only 1 vty for startup, must be extended | |
79 | * when remainder of system is up | |
80 | */ | |
81 | nvty = first ? 1 : NVTY; | |
82 | ||
83 | for (i=0; i<nvty; i++) { | |
84 | vp = &vtys[i]; | |
85 | std = &vp->om[0]; | |
86 | kern= &vp->om[1]; | |
87 | vp->op = std; | |
88 | ||
89 | vp->vtynum = i; | |
90 | ||
91 | std->escstate = | |
92 | kern->escstate = 0; /* "ESC_NONE" */ | |
93 | std->parcnt = | |
94 | kern->parcnt = 0; | |
95 | ||
96 | emul_setattributes(vp, 0, 0); /* set std attributes */ | |
97 | emul_setattributes(vp, 0, 1); /* set kernel attributes */ | |
98 | emul_setattributes(vp, 4, 0); /* set so attributes */ | |
99 | std->f2 = | |
100 | kern->f2 = 0; | |
101 | vp->so = 0; | |
102 | ||
103 | vp->pitch = 0x31b; /* default 1.500 kHz */ | |
104 | vp->duration = hz/4; | |
105 | ||
106 | /* initialize vty tty structure */ | |
107 | vp->ttyp = &pccons[i]; | |
108 | vp->ttycnt = 0; | |
109 | ||
110 | /* set default # of rows and columns */ | |
111 | vp->ncol = DEFAULTCOL; | |
112 | vp->nrow = DEFAULTROW; | |
113 | vp->size = vp->ncol * vp->nrow; | |
114 | vp->visible = | |
115 | vp->altgrlock = | |
116 | vp->shiftlock = | |
117 | vp->scroll = | |
118 | vp->num = | |
119 | vp->caps = 0; | |
120 | ||
121 | /* set Screen */ | |
122 | if (first) { | |
123 | /* set console to screen */ | |
124 | vp->Crtat = vp->crtat = Crtat; | |
125 | vp->col = vp->row = 0; | |
126 | vp->vbuf = 0; | |
127 | actvty = vp; | |
128 | emul_clearcursor(vp,2); | |
129 | } | |
130 | else { | |
131 | /* now also vm is initialized */ | |
132 | vp->vbuf = (u_short*)malloc(vp->size*CHR, M_TEMP, M_NOWAIT); | |
133 | if (i > 0) { | |
134 | vp->crtat = vp->Crtat = vp->vbuf; | |
135 | vp->col = vp->row = 0; | |
136 | actvty = vp; | |
137 | emul_clearcursor(vp,2); | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | /* execute the local vt_emulator initializations */ | |
143 | vtemul_init(); | |
144 | ||
145 | /* set active vty */ | |
146 | vty_setactive(0,2); | |
147 | } | |
148 | ||
149 | /* | |
150 | * set the active vty, which writes to screen (-1: suspend writing to screen) | |
151 | * sw=0: only set page for writing | |
152 | * sw=1: do a physical switch (save/restore pages first) | |
153 | * sw=2: do a logical switch (don't save/restore pages) | |
154 | * sw=3: restore page without saving old page | |
155 | */ | |
156 | void vty_setactive(int vtyno,int sw) | |
157 | { | |
158 | struct vty *oldvty; | |
159 | register struct vty *vp; | |
160 | int pos,s; | |
161 | ||
162 | /* protect switch */ | |
163 | vtswsema = 1; | |
164 | ||
165 | /* to disable writing to screen entirely */ | |
166 | if (vtyno == -1) { | |
167 | pos = actvty->crtat - actvty->Crtat; | |
168 | actvty->Crtat = actvty->vbuf; | |
169 | actvty->crtat = actvty->Crtat + pos; | |
170 | return; | |
171 | } | |
172 | ||
173 | if (vtyno < nvty) { | |
174 | ||
175 | /* save old vty, and set new one */ | |
176 | oldvty = actvty; | |
177 | vp = actvty = &vtys[vtyno]; | |
178 | ||
179 | switch (sw) { | |
180 | case 0: | |
181 | break; | |
182 | case 1: | |
183 | /* save screen */ | |
184 | bcopy(Crtat,oldvty->vbuf,oldvty->size*CHR); | |
185 | /*FALLTHRU*/ | |
186 | case 3: | |
187 | /* restore videopage of new vty */ | |
188 | bcopy(vp->vbuf,Crtat,vp->size*CHR); | |
189 | /*FALLTHRU*/ | |
190 | case 2: | |
191 | /* adjust old pointers */ | |
192 | pos = oldvty->crtat - oldvty->Crtat; | |
193 | oldvty->Crtat = oldvty->vbuf; | |
194 | oldvty->crtat = oldvty->vbuf + pos; | |
195 | oldvty->visible = 0; | |
196 | ||
197 | /* set the write pointers | |
198 | * these normally point to the vbuf, but on a visible | |
199 | * active screen they point to video memory | |
200 | */ | |
201 | pos = vp->crtat - vp->Crtat; | |
202 | vp->Crtat = Crtat; | |
203 | vp->crtat = vp->Crtat + pos; | |
204 | ||
205 | /* set cursor */ | |
206 | vga_setcursorpos(pos); | |
207 | ||
208 | /* restore LEDS */ | |
209 | kbd_setleds(leds(vp)); | |
210 | ||
211 | actvty->visible = 1; | |
212 | } | |
213 | } | |
214 | ||
215 | vtswsema = 0; | |
216 | } | |
217 | ||
218 | #ifndef MINITERM | |
219 | /* | |
220 | * switch to next vty | |
221 | */ | |
222 | void vty_next() | |
223 | { | |
224 | int n = actvty->vtynum; | |
225 | if (nvty==1) return; | |
226 | ||
227 | n = (n+1) % nvty; | |
228 | ||
229 | vty_setactive(n,1); | |
230 | } | |
231 | ||
232 | /* | |
233 | * switch to previous vty | |
234 | */ | |
235 | void vty_previous() | |
236 | { | |
237 | int n = actvty->vtynum; | |
238 | if (nvty==1) return; | |
239 | ||
240 | n = (n==0) ? nvty-1 : n-1; | |
241 | ||
242 | vty_setactive(n,1); | |
243 | } | |
244 | #endif /*!MINITERM*/ | |
245 | ||
246 | /* | |
247 | * vty_broadcast: Send a message to all vtys | |
248 | */ | |
249 | void | |
250 | #ifdef __STDC__ | |
251 | vty_broadcast(const char *fmt, ...) | |
252 | #else | |
253 | vty_broadcast(fmt /*, va_alist */) | |
254 | char *fmt; | |
255 | #endif | |
256 | { | |
257 | int i; | |
258 | va_list ap; | |
259 | ||
260 | #define TOCONS 0x01 /* inherited from /sys/kern/subr_prf.c */ | |
261 | #define TOTTY 0x02 /* inherited from /sys/kern/subr_prf.c */ | |
262 | va_start(ap, fmt); | |
263 | for (i=0; i<nvty; i++) { | |
264 | kprintf(fmt,TOCONS, vtys[i].ttyp, ap); | |
265 | } | |
266 | va_end(ap); | |
267 | } |