2 * Copyright (c) 1995-1998 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
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 without specific prior written permission.
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.
28 * $FreeBSD: src/sys/dev/syscons/syscons.h,v 1.60.2.6 2002/09/15 22:30:45 dd Exp $
29 * $DragonFly: src/sys/dev/misc/syscons/syscons.h,v 1.6 2004/05/19 22:52:44 dillon Exp $
32 #ifndef _DEV_SYSCONS_SYSCONS_H_
33 #define _DEV_SYSCONS_SYSCONS_H_
35 /* machine-dependent part of the header */
38 #include <pc98/pc98/sc_machdep.h>
39 #elif defined(__i386__)
40 /* nothing for the moment */
41 #elif defined(__alpha__)
42 /* nothing for the moment */
45 /* default values for configuration options */
48 #define MAXCONS 16 /* power of 2 */
53 #define SC_NO_CUTPASTE 1
56 #ifdef SC_NO_MODE_CHANGE
60 /* Always load font data if the pixel (raster text) mode is to be used. */
62 #undef SC_NO_FONT_LOADING
66 * If font data is not available, the `arrow'-shaped mouse cursor cannot
67 * be drawn. Use the alternative drawing method.
69 #ifdef SC_NO_FONT_LOADING
70 #undef SC_ALT_MOUSE_IMAGE
71 #define SC_ALT_MOUSE_IMAGE 1
74 #ifndef SC_CURSOR_CHAR
75 #define SC_CURSOR_CHAR (0x07)
79 #define SC_MOUSE_CHAR (0xd0)
82 #if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
84 #define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
87 #ifndef SC_DEBUG_LEVEL
88 #define SC_DEBUG_LEVEL 0
91 #define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
93 #define SC_DRIVER_NAME "sc"
94 #define SC_VTY(dev) minor(dev)
95 #define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
96 #define SC_STAT(dev) ((scr_stat *)(dev)->si_drv1)
100 #define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
104 /* macros for "intelligent" screen update */
105 #define mark_for_update(scp, x) {\
106 if ((x) < scp->start) scp->start = (x);\
107 else if ((x) > scp->end) scp->end = (x);\
109 #define mark_all(scp) {\
111 scp->end = scp->xsize * scp->ysize - 1;\
114 /* vty status flags (scp->status) */
115 #define UNKNOWN_MODE 0x00010 /* unknown video mode */
116 #define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
117 #define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
118 #define BUFFER_SAVED 0x00200 /* vty buffer is saved */
119 #define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
120 #define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
121 #define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
122 #define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
123 #define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
124 #define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
125 #define SAVER_RUNNING 0x20000 /* screen saver is running */
126 #define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
127 #define VR_CURSOR_ON 0x80000 /* text cursor is on */
128 #define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
137 #ifndef BELL_DURATION
138 #define BELL_DURATION ((5 * hz + 99) / 100)
139 #define BELL_PITCH 800
142 /* virtual terminal buffer */
143 typedef struct sc_vtb {
145 #define VTB_VALID (1 << 0)
146 #define VTB_ALLOCED (1 << 1)
148 #define VTB_INVALID 0
150 #define VTB_FRAMEBUFFER 2
151 #define VTB_RINGBUFFER 3
155 vm_offset_t vtb_buffer;
156 int vtb_tail; /* valid for VTB_RINGBUFFER only */
162 struct video_adapter;
166 typedef struct sc_softc {
167 int unit; /* unit # */
168 int config; /* configuration flags */
169 #define SC_VESA800X600 (1 << 7)
170 #define SC_AUTODETECT_KBD (1 << 8)
171 #define SC_KERNEL_CONSOLE (1 << 9)
173 int flags; /* status flags */
174 #define SC_VISUAL_BELL (1 << 0)
175 #define SC_QUIET_BELL (1 << 1)
176 #define SC_BLINK_CURSOR (1 << 2)
177 #define SC_CHAR_CURSOR (1 << 3)
178 #define SC_MOUSE_ENABLED (1 << 4)
179 #define SC_SCRN_IDLE (1 << 5)
180 #define SC_SCRN_BLANKED (1 << 6)
181 #define SC_SAVER_FAILED (1 << 7)
182 #define SC_SCRN_VTYLOCK (1 << 8)
184 #define SC_INIT_DONE (1 << 16)
185 #define SC_SPLASH_SCRN (1 << 17)
187 int keyboard; /* -1 if unavailable */
188 struct keyboard *kbd;
191 struct video_adapter *adp;
192 int initial_mode; /* initial video mode */
197 struct scr_stat *cur_scp;
198 struct scr_stat *new_scp;
199 struct scr_stat *old_scp;
200 int delayed_next_scr;
202 char font_loading_in_progress;
203 char switch_in_progress;
204 char videoio_in_progress;
205 char write_in_progress;
206 char blink_in_progress;
208 long scrn_time_stamp;
214 u_char scr_rmap[256];
216 #ifdef _SC_MD_SOFTC_DECLARED_
217 sc_md_softc_t md; /* machine dependent vars */
220 #ifndef SC_NO_PALETTE_LOADING
221 u_char palette[256*3];
224 #ifndef SC_NO_FONT_LOADING
240 typedef struct scr_stat {
241 int index; /* index of this vty */
242 struct sc_softc *sc; /* pointer to softc */
243 struct sc_rndr_sw *rndr; /* renderer */
247 int xpos; /* current X position */
248 int ypos; /* current Y position */
249 int xsize; /* X text size */
250 int ysize; /* Y text size */
251 int xpixel; /* X graphics size */
252 int ypixel; /* Y graphics size */
253 int xoff; /* X offset in pixel mode */
254 int yoff; /* Y offset in pixel mode */
256 u_char *font; /* current font */
257 int font_size; /* fontsize in Y direction */
259 int start; /* modified area start */
260 int end; /* modified area end */
262 struct sc_term_sw *tsw;
265 int status; /* status (bitfield) */
266 int kbd_mode; /* keyboard I/O mode */
268 int cursor_pos; /* cursor buffer position */
269 int cursor_oldpos; /* cursor old buffer position */
270 u_short cursor_saveunder_char; /* saved char under cursor */
271 u_short cursor_saveunder_attr; /* saved attr under cursor */
272 char cursor_base; /* cursor base line # */
273 char cursor_height; /* cursor height */
275 int mouse_pos; /* mouse buffer position */
276 int mouse_oldpos; /* mouse old buffer position */
277 short mouse_xpos; /* mouse x coordinate */
278 short mouse_ypos; /* mouse y coordinate */
279 short mouse_oldxpos; /* mouse previous x coordinate */
280 short mouse_oldypos; /* mouse previous y coordinate */
281 short mouse_buttons; /* mouse buttons */
282 int mouse_cut_start; /* mouse cut start pos */
283 int mouse_cut_end; /* mouse cut end pos */
284 struct proc *mouse_proc; /* proc* of controlling proc */
285 pid_t mouse_pid; /* pid of controlling proc */
286 int mouse_signal; /* signal # to report with */
288 u_short bell_duration;
291 u_char border; /* border color */
293 pid_t pid; /* pid of controlling proc */
294 struct proc *proc; /* proc* of controlling proc */
295 struct vt_mode smode; /* switch mode */
297 sc_vtb_t *history; /* circular history buffer */
298 int history_pos; /* position shown on screen */
299 int history_size; /* size of history buffer */
301 int splash_save_mode; /* saved mode for splash screen */
302 int splash_save_status; /* saved status for splash screen */
303 #ifdef _SCR_MD_STAT_DECLARED_
304 scr_md_stat_t md; /* machine dependent vars */
309 #define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
311 #ifndef SC_NORM_REV_ATTR
312 #define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
314 #ifndef SC_KERNEL_CONS_ATTR
315 #define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
317 #ifndef SC_KERNEL_CONS_REV_ATTR
318 #define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
321 /* terminal emulator */
324 #define SC_DFLT_TERM "*" /* any */
327 typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
328 #define SC_TE_COLD_INIT 0
329 #define SC_TE_WARM_INIT 1
330 typedef int sc_term_term_t(scr_stat *scp, void **tcp);
331 typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len);
332 typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
333 caddr_t data, int flag, struct thread *td);
334 typedef int sc_term_reset_t(scr_stat *scp, int code);
335 #define SC_TE_HARD_RESET 0
336 #define SC_TE_SOFT_RESET 1
337 typedef void sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
338 typedef void sc_term_clear_t(scr_stat *scp);
339 typedef void sc_term_notify_t(scr_stat *scp, int event);
340 #define SC_TE_NOTIFY_VTSWITCH_IN 0
341 #define SC_TE_NOTIFY_VTSWITCH_OUT 1
342 typedef int sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
344 typedef struct sc_term_sw {
345 LIST_ENTRY(sc_term_sw) link;
346 char *te_name; /* name of the emulator */
347 char *te_desc; /* description */
348 char *te_renderer; /* matching renderer */
349 size_t te_size; /* size of internal buffer */
350 int te_refcount; /* reference counter */
351 sc_term_init_t *te_init;
352 sc_term_term_t *te_term;
353 sc_term_puts_t *te_puts;
354 sc_term_ioctl_t *te_ioctl;
355 sc_term_reset_t *te_reset;
356 sc_term_default_attr_t *te_default_attr;
357 sc_term_clear_t *te_clear;
358 sc_term_notify_t *te_notify;
359 sc_term_input_t *te_input;
362 extern struct linker_set scterm_set;
364 #define SCTERM_MODULE(name, sw) \
365 DATA_SET(scterm_set, sw); \
367 scterm_##name##_event(module_t mod, int type, void *data) \
371 return sc_term_add(&sw); \
373 if (sw.te_refcount > 0) \
375 return sc_term_remove(&sw); \
381 static moduledata_t scterm_##name##_mod = { \
383 scterm_##name##_event, \
386 DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
387 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
389 /* renderer function table */
390 typedef void vr_clear_t(scr_stat *scp, int c, int attr);
391 typedef void vr_draw_border_t(scr_stat *scp, int color);
392 typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip);
393 typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
394 typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink,
396 typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip);
397 typedef void vr_set_mouse_t(scr_stat *scp);
398 typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
400 typedef struct sc_rndr_sw {
402 vr_draw_border_t *draw_border;
404 vr_set_cursor_t *set_cursor;
405 vr_draw_cursor_t *draw_cursor;
406 vr_blink_cursor_t *blink_cursor;
407 vr_set_mouse_t *set_mouse;
408 vr_draw_mouse_t *draw_mouse;
411 typedef struct sc_renderer {
414 sc_rndr_sw_t *rndrsw;
415 LIST_ENTRY(sc_renderer) link;
418 extern struct linker_set scrndr_set;
420 #define RENDERER(name, mode, sw, set) \
421 static struct sc_renderer scrndr_##name##_##mode = { \
424 DATA_SET(scrndr_set, scrndr_##name##_##mode); \
425 DATA_SET(set, scrndr_##name##_##mode)
427 #define RENDERER_MODULE(name, set) \
428 SET_DECLARE(set, sc_renderer_t); \
430 scrndr_##name##_event(module_t mod, int type, void *data) \
432 sc_renderer_t **list; \
436 SET_FOREACH(list, set) { \
437 error = sc_render_add(*list); \
443 SET_FOREACH(list, set) { \
444 error = sc_render_remove(*list); \
454 static moduledata_t scrndr_##name##_mod = { \
456 scrndr_##name##_event, \
459 DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, \
460 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
470 #define ISTEXTSC(scp) (!((scp)->status \
471 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
472 #define ISGRAPHSC(scp) (((scp)->status \
473 & (UNKNOWN_MODE | GRAPHICS_MODE)))
474 #define ISPIXELSC(scp) (((scp)->status \
475 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
477 #define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
479 #define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
480 #define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
481 #define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
483 #define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
485 #define kbd_read_char(kbd, wait) \
486 (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
487 #define kbd_check_char(kbd) \
488 (*kbdsw[(kbd)->kb_index]->check_char)((kbd))
489 #define kbd_enable(kbd) \
490 (*kbdsw[(kbd)->kb_index]->enable)((kbd))
491 #define kbd_disable(kbd) \
492 (*kbdsw[(kbd)->kb_index]->disable)((kbd))
493 #define kbd_lock(kbd, lockf) \
494 (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
495 #define kbd_ioctl(kbd, cmd, arg) \
497 ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
498 #define kbd_clear_state(kbd) \
499 (*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
500 #define kbd_get_fkeystr(kbd, fkey, len) \
501 (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
502 #define kbd_poll(kbd, on) \
503 (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
506 extern int (*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data,
507 int flag, struct thread *td);
509 int sc_probe_unit(int unit, int flags);
510 int sc_attach_unit(int unit, int flags);
512 int set_mode(scr_stat *scp);
514 void sc_set_border(scr_stat *scp, int color);
515 void sc_load_font(scr_stat *scp, int page, int size, u_char *font,
516 int base, int count);
517 void sc_save_font(scr_stat *scp, int page, int size, u_char *font,
518 int base, int count);
519 void sc_show_font(scr_stat *scp, int page);
521 void sc_touch_scrn_saver(void);
522 void sc_puts(scr_stat *scp, u_char *buf, int len);
523 void sc_draw_cursor_image(scr_stat *scp);
524 void sc_remove_cursor_image(scr_stat *scp);
525 void sc_set_cursor_image(scr_stat *scp);
526 int sc_clean_up(scr_stat *scp);
527 int sc_switch_scr(sc_softc_t *sc, u_int next_scr);
528 void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
529 int sc_init_emulator(scr_stat *scp, char *name);
530 void sc_paste(scr_stat *scp, u_char *p, int count);
531 void sc_bell(scr_stat *scp, int pitch, int duration);
534 #ifndef SC_NO_HISTORY
535 int sc_alloc_history_buffer(scr_stat *scp, int lines,
536 int prev_ysize, int wait);
537 void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
538 void sc_hist_save(scr_stat *scp);
539 #define sc_hist_save_one_line(scp, from) \
540 sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
541 int sc_hist_restore(scr_stat *scp);
542 void sc_hist_home(scr_stat *scp);
543 void sc_hist_end(scr_stat *scp);
544 int sc_hist_up_line(scr_stat *scp);
545 int sc_hist_down_line(scr_stat *scp);
546 int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
547 int flag, struct thread *td);
548 #endif /* SC_NO_HISTORY */
551 #ifndef SC_NO_CUTPASTE
552 void sc_alloc_cut_buffer(scr_stat *scp, int wait);
553 void sc_draw_mouse_image(scr_stat *scp);
554 void sc_remove_mouse_image(scr_stat *scp);
555 int sc_inside_cutmark(scr_stat *scp, int pos);
556 void sc_remove_cutmarking(scr_stat *scp);
557 void sc_remove_all_cutmarkings(sc_softc_t *scp);
558 void sc_remove_all_mouse(sc_softc_t *scp);
560 #define sc_draw_mouse_image(scp)
561 #define sc_remove_mouse_image(scp)
562 #define sc_inside_cutmark(scp, pos) FALSE
563 #define sc_remove_cutmarking(scp)
564 #define sc_remove_all_cutmarkings(scp)
565 #define sc_remove_all_mouse(scp)
566 #endif /* SC_NO_CUTPASTE */
567 #ifndef SC_NO_SYSMOUSE
568 void sc_mouse_move(scr_stat *scp, int x, int y);
569 int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
570 int flag, struct thread *td);
571 #endif /* SC_NO_SYSMOUSE */
574 int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
575 int xsize, int ysize, int fontsize);
576 int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
577 int sc_set_pixel_mode(scr_stat *scp, struct tty *tp,
578 int xsize, int ysize, int fontsize);
579 int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
582 int sc_render_add(sc_renderer_t *rndr);
583 int sc_render_remove(sc_renderer_t *rndr);
584 sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode);
587 void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
588 void *buffer, int wait);
589 void sc_vtb_destroy(sc_vtb_t *vtb);
590 size_t sc_vtb_size(int cols, int rows);
591 void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
593 int sc_vtb_getc(sc_vtb_t *vtb, int at);
594 int sc_vtb_geta(sc_vtb_t *vtb, int at);
595 void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
596 vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
597 vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at);
598 int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
600 #define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
601 #define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
602 #define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
604 void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
606 void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
608 void sc_vtb_seek(sc_vtb_t *vtb, int pos);
609 void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
610 void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
611 void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
612 void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
615 int sysmouse_event(mouse_info_t *info);
618 void sc_move_cursor(scr_stat *scp, int x, int y);
619 void sc_clear_screen(scr_stat *scp);
620 int sc_term_add(sc_term_sw_t *sw);
621 int sc_term_remove(sc_term_sw_t *sw);
622 sc_term_sw_t *sc_term_match(char *name);
623 sc_term_sw_t *sc_term_match_by_number(int index);
625 /* machine dependent functions */
626 int sc_max_unit(void);
627 sc_softc_t *sc_get_softc(int unit, int flags);
628 sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
629 int sc_get_cons_priority(int *unit, int *flags);
630 void sc_get_bios_values(bios_values_t *values);
631 int sc_tone(int herz);
633 #endif /* !_DEV_SYSCONS_SYSCONS_H_ */