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.
31 #ifndef _DEV_SYSCONS_SYSCONS_H_
32 #define _DEV_SYSCONS_SYSCONS_H_
34 /* machine-dependent part of the header */
37 #include <pc98/pc98/sc_machdep.h>
38 #elif defined(__i386__)
39 /* nothing for the moment */
40 #elif defined(__alpha__)
41 /* nothing for the moment */
44 /* default values for configuration options */
52 #define SC_NO_CUTPASTE 1
55 #ifdef SC_NO_MODE_CHANGE
59 #ifndef SC_CURSOR_CHAR
60 #define SC_CURSOR_CHAR (0x07)
64 #define SC_MOUSE_CHAR (0xd0)
67 #if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
69 #define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
72 #ifndef SC_DEBUG_LEVEL
73 #define SC_DEBUG_LEVEL 0
76 #define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
78 #define SC_DRIVER_NAME "sc"
79 #define SC_VTY(dev) minor(dev)
80 #define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
81 #define SC_STAT(dev) ((scr_stat *)(dev)->si_drv1)
85 #define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
89 /* macros for "intelligent" screen update */
90 #define mark_for_update(scp, x) {\
91 if ((x) < scp->start) scp->start = (x);\
92 else if ((x) > scp->end) scp->end = (x);\
94 #define mark_all(scp) {\
96 scp->end = scp->xsize * scp->ysize - 1;\
99 /* vty status flags (scp->status) */
100 #define UNKNOWN_MODE 0x00010 /* unknown video mode */
101 #define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
102 #define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
103 #define BUFFER_SAVED 0x00200 /* vty buffer is saved */
104 #define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
105 #define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
106 #define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
107 #define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
108 #define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
109 #define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
110 #define SAVER_RUNNING 0x20000 /* screen saver is running */
111 #define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
112 #define VR_CURSOR_ON 0x80000 /* text cursor is on */
113 #define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
122 #ifndef BELL_DURATION
123 #define BELL_DURATION 5
124 #define BELL_PITCH 800
127 /* virtual terminal buffer */
128 typedef struct sc_vtb {
130 #define VTB_VALID (1 << 0)
132 #define VTB_INVALID 0
134 #define VTB_FRAMEBUFFER 2
135 #define VTB_RINGBUFFER 3
139 vm_offset_t vtb_buffer;
140 int vtb_tail; /* valid for VTB_RINGBUFFER only */
146 struct video_adapter;
150 typedef struct sc_softc {
151 int unit; /* unit # */
152 int config; /* configuration flags */
153 #define SC_VESA800X600 (1 << 7)
154 #define SC_AUTODETECT_KBD (1 << 8)
155 #define SC_KERNEL_CONSOLE (1 << 9)
157 int flags; /* status flags */
158 #define SC_VISUAL_BELL (1 << 0)
159 #define SC_QUIET_BELL (1 << 1)
160 #define SC_BLINK_CURSOR (1 << 2)
161 #define SC_CHAR_CURSOR (1 << 3)
162 #define SC_MOUSE_ENABLED (1 << 4)
163 #define SC_SCRN_IDLE (1 << 5)
164 #define SC_SCRN_BLANKED (1 << 6)
165 #define SC_SAVER_FAILED (1 << 7)
167 #define SC_INIT_DONE (1 << 16)
168 #define SC_SPLASH_SCRN (1 << 17)
170 int keyboard; /* -1 if unavailable */
171 struct keyboard *kbd;
174 struct video_adapter *adp;
175 int initial_mode; /* initial video mode */
180 struct scr_stat *cur_scp;
181 struct scr_stat *new_scp;
182 struct scr_stat *old_scp;
183 int delayed_next_scr;
185 char font_loading_in_progress;
186 char switch_in_progress;
187 char videoio_in_progress;
188 char write_in_progress;
189 char blink_in_progress;
191 long scrn_time_stamp;
197 u_char scr_rmap[256];
199 #ifdef _SC_MD_SOFTC_DECLARED_
200 sc_md_softc_t md; /* machine dependent vars */
203 #ifndef SC_NO_PALETTE_LOADING
204 u_char palette[256*3];
207 #ifndef SC_NO_FONT_LOADING
223 typedef struct scr_stat {
224 int index; /* index of this vty */
225 struct sc_softc *sc; /* pointer to softc */
226 struct sc_rndr_sw *rndr; /* renderer */
230 int xpos; /* current X position */
231 int ypos; /* current Y position */
232 int xsize; /* X text size */
233 int ysize; /* Y text size */
234 int xpixel; /* X graphics size */
235 int ypixel; /* Y graphics size */
236 int xoff; /* X offset in pixel mode */
237 int yoff; /* Y offset in pixel mode */
239 u_char *font; /* current font */
240 int font_size; /* fontsize in Y direction */
242 int start; /* modified area start */
243 int end; /* modified area end */
245 struct sc_term_sw *tsw;
248 int status; /* status (bitfield) */
249 int kbd_mode; /* keyboard I/O mode */
251 int cursor_pos; /* cursor buffer position */
252 int cursor_oldpos; /* cursor old buffer position */
253 u_short cursor_saveunder_char; /* saved char under cursor */
254 u_short cursor_saveunder_attr; /* saved attr under cursor */
255 char cursor_base; /* cursor base line # */
256 char cursor_height; /* cursor height */
258 int mouse_pos; /* mouse buffer position */
259 int mouse_oldpos; /* mouse old buffer position */
260 short mouse_xpos; /* mouse x coordinate */
261 short mouse_ypos; /* mouse y coordinate */
262 short mouse_oldxpos; /* mouse previous x coordinate */
263 short mouse_oldypos; /* mouse previous y coordinate */
264 short mouse_buttons; /* mouse buttons */
265 int mouse_cut_start; /* mouse cut start pos */
266 int mouse_cut_end; /* mouse cut end pos */
267 struct proc *mouse_proc; /* proc* of controlling proc */
268 pid_t mouse_pid; /* pid of controlling proc */
269 int mouse_signal; /* signal # to report with */
271 u_short bell_duration;
274 u_char border; /* border color */
276 pid_t pid; /* pid of controlling proc */
277 struct proc *proc; /* proc* of controlling proc */
278 struct vt_mode smode; /* switch mode */
280 sc_vtb_t *history; /* circular history buffer */
281 int history_pos; /* position shown on screen */
282 int history_size; /* size of history buffer */
284 int splash_save_mode; /* saved mode for splash screen */
285 int splash_save_status; /* saved status for splash screen */
286 #ifdef _SCR_MD_STAT_DECLARED_
287 scr_md_stat_t md; /* machine dependent vars */
292 #define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
294 #ifndef SC_NORM_REV_ATTR
295 #define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
297 #ifndef SC_KERNEL_CONS_ATTR
298 #define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
300 #ifndef SC_KERNEL_CONS_REV_ATTR
301 #define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
304 /* terminal emulator */
307 #define SC_DFLT_TERM "*" /* any */
310 typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
311 #define SC_TE_COLD_INIT 0
312 #define SC_TE_WARM_INIT 1
313 typedef int sc_term_term_t(scr_stat *scp, void **tcp);
314 typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len);
315 typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
316 caddr_t data, int flag, struct proc *p);
317 typedef int sc_term_reset_t(scr_stat *scp, int code);
318 #define SC_TE_HARD_RESET 0
319 #define SC_TE_SOFT_RESET 1
320 typedef void sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
321 typedef void sc_term_clear_t(scr_stat *scp);
322 typedef void sc_term_notify_t(scr_stat *scp, int event);
323 #define SC_TE_NOTIFY_VTSWITCH_IN 0
324 #define SC_TE_NOTIFY_VTSWITCH_OUT 1
325 typedef int sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
327 typedef struct sc_term_sw {
328 LIST_ENTRY(sc_term_sw) link;
329 char *te_name; /* name of the emulator */
330 char *te_desc; /* description */
331 char *te_renderer; /* matching renderer */
332 size_t te_size; /* size of internal buffer */
333 int te_refcount; /* reference counter */
334 sc_term_init_t *te_init;
335 sc_term_term_t *te_term;
336 sc_term_puts_t *te_puts;
337 sc_term_ioctl_t *te_ioctl;
338 sc_term_reset_t *te_reset;
339 sc_term_default_attr_t *te_default_attr;
340 sc_term_clear_t *te_clear;
341 sc_term_notify_t *te_notify;
342 sc_term_input_t *te_input;
345 extern struct linker_set scterm_set;
347 #define SCTERM_MODULE(name, sw) \
348 DATA_SET(scterm_set, sw); \
350 scterm_##name##_event(module_t mod, int type, void *data) \
354 return sc_term_add(&sw); \
356 if (sw.te_refcount > 0) \
358 return sc_term_remove(&sw); \
364 static moduledata_t scterm_##name##_mod = { \
366 scterm_##name##_event, \
369 DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
370 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
372 /* renderer function table */
373 typedef void vr_clear_t(scr_stat *scp, int c, int attr);
374 typedef void vr_draw_border_t(scr_stat *scp, int color);
375 typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip);
376 typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
377 typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink,
379 typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip);
380 typedef void vr_set_mouse_t(scr_stat *scp);
381 typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
383 typedef struct sc_rndr_sw {
385 vr_draw_border_t *draw_border;
387 vr_set_cursor_t *set_cursor;
388 vr_draw_cursor_t *draw_cursor;
389 vr_blink_cursor_t *blink_cursor;
390 vr_set_mouse_t *set_mouse;
391 vr_draw_mouse_t *draw_mouse;
394 typedef struct sc_renderer {
397 sc_rndr_sw_t *rndrsw;
398 LIST_ENTRY(sc_renderer) link;
401 extern struct linker_set scrndr_set;
403 #define RENDERER(name, mode, sw, set) \
404 static struct sc_renderer scrndr_##name##_##mode## = { \
407 DATA_SET(scrndr_set, scrndr_##name##_##mode##); \
408 DATA_SET(set, scrndr_##name##_##mode##)
410 #define RENDERER_MODULE(name, set) \
412 scrndr_##name##_event(module_t mod, int type, void *data) \
414 sc_renderer_t **list; \
419 list = (sc_renderer_t **)set.ls_items; \
420 while ((p = *list++) != NULL) { \
421 error = sc_render_add(p); \
427 list = (sc_renderer_t **)set.ls_items; \
428 while ((p = *list++) != NULL) { \
429 error = sc_render_remove(p); \
439 static moduledata_t scrndr_##name##_mod = { \
441 scrndr_##name##_event, \
444 DECLARE_MODULE(scrndr_##name##, scrndr_##name##_mod, \
445 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
455 #define ISTEXTSC(scp) (!((scp)->status \
456 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
457 #define ISGRAPHSC(scp) (((scp)->status \
458 & (UNKNOWN_MODE | GRAPHICS_MODE)))
459 #define ISPIXELSC(scp) (((scp)->status \
460 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
462 #define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
465 #ifdef SC_ALT_MOUSE_IMAGE
466 #define ISMOUSEAVAIL(af) (1)
468 #define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
469 #endif /* SC_ALT_MOUSE_IMAGE */
470 #define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
471 #define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
472 #endif /* ISMOUSEAVAIL */
474 #define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
476 #define kbd_read_char(kbd, wait) \
477 (*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
478 #define kbd_check_char(kbd) \
479 (*kbdsw[(kbd)->kb_index]->check_char)((kbd))
480 #define kbd_enable(kbd) \
481 (*kbdsw[(kbd)->kb_index]->enable)((kbd))
482 #define kbd_disable(kbd) \
483 (*kbdsw[(kbd)->kb_index]->disable)((kbd))
484 #define kbd_lock(kbd, lockf) \
485 (*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
486 #define kbd_ioctl(kbd, cmd, arg) \
488 ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
489 #define kbd_clear_state(kbd) \
490 (*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
491 #define kbd_get_fkeystr(kbd, fkey, len) \
492 (*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
493 #define kbd_poll(kbd, on) \
494 (*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
497 extern int (*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data,
498 int flag, struct proc *p);
500 int sc_probe_unit(int unit, int flags);
501 int sc_attach_unit(int unit, int flags);
502 int sc_resume_unit(int unit);
504 int set_mode(scr_stat *scp);
506 void sc_set_border(scr_stat *scp, int color);
507 void sc_load_font(scr_stat *scp, int page, int size, u_char *font,
508 int base, int count);
509 void sc_save_font(scr_stat *scp, int page, int size, u_char *font,
510 int base, int count);
511 void sc_show_font(scr_stat *scp, int page);
513 void sc_touch_scrn_saver(void);
514 void sc_puts(scr_stat *scp, u_char *buf, int len);
515 void sc_draw_cursor_image(scr_stat *scp);
516 void sc_remove_cursor_image(scr_stat *scp);
517 void sc_set_cursor_image(scr_stat *scp);
518 int sc_clean_up(scr_stat *scp);
519 int sc_switch_scr(sc_softc_t *sc, u_int next_scr);
520 void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
521 int sc_init_emulator(scr_stat *scp, char *name);
522 void sc_paste(scr_stat *scp, u_char *p, int count);
523 void sc_bell(scr_stat *scp, int pitch, int duration);
526 #ifndef SC_NO_HISTORY
527 int sc_alloc_history_buffer(scr_stat *scp, int lines,
528 int prev_ysize, int wait);
529 void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
530 void sc_hist_save(scr_stat *scp);
531 #define sc_hist_save_one_line(scp, from) \
532 sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
533 int sc_hist_restore(scr_stat *scp);
534 void sc_hist_home(scr_stat *scp);
535 void sc_hist_end(scr_stat *scp);
536 int sc_hist_up_line(scr_stat *scp);
537 int sc_hist_down_line(scr_stat *scp);
538 int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
539 int flag, struct proc *p);
540 #endif /* SC_NO_HISTORY */
543 #ifndef SC_NO_CUTPASTE
544 void sc_alloc_cut_buffer(scr_stat *scp, int wait);
545 void sc_draw_mouse_image(scr_stat *scp);
546 void sc_remove_mouse_image(scr_stat *scp);
547 int sc_inside_cutmark(scr_stat *scp, int pos);
548 void sc_remove_cutmarking(scr_stat *scp);
549 void sc_remove_all_cutmarkings(sc_softc_t *scp);
550 void sc_remove_all_mouse(sc_softc_t *scp);
552 #define sc_inside_cutmark(scp, pos) FALSE
553 #define sc_remove_cutmarking(scp)
554 #endif /* SC_NO_CUTPASTE */
555 #ifndef SC_NO_SYSMOUSE
556 void sc_mouse_move(scr_stat *scp, int x, int y);
557 int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
558 int flag, struct proc *p);
559 #endif /* SC_NO_SYSMOUSE */
562 int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
563 int xsize, int ysize, int fontsize);
564 int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
565 int sc_set_pixel_mode(scr_stat *scp, struct tty *tp,
566 int xsize, int ysize, int fontsize);
567 int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
570 int sc_render_add(sc_renderer_t *rndr);
571 int sc_render_remove(sc_renderer_t *rndr);
572 sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode);
575 void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
576 void *buffer, int wait);
577 void sc_vtb_destroy(sc_vtb_t *vtb);
578 size_t sc_vtb_size(int cols, int rows);
579 void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
581 int sc_vtb_getc(sc_vtb_t *vtb, int at);
582 int sc_vtb_geta(sc_vtb_t *vtb, int at);
583 void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
584 vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
585 vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at);
586 int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
588 #define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
589 #define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
590 #define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
592 void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
594 void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
596 void sc_vtb_seek(sc_vtb_t *vtb, int pos);
597 void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
598 void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
599 void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
600 void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
603 int sysmouse_event(mouse_info_t *info);
606 void sc_move_cursor(scr_stat *scp, int x, int y);
607 void sc_clear_screen(scr_stat *scp);
608 int sc_term_add(sc_term_sw_t *sw);
609 int sc_term_remove(sc_term_sw_t *sw);
610 sc_term_sw_t *sc_term_match(char *name);
611 sc_term_sw_t *sc_term_match_by_number(int index);
613 /* machine dependent functions */
614 int sc_max_unit(void);
615 sc_softc_t *sc_get_softc(int unit, int flags);
616 sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
617 int sc_get_cons_priority(int *unit, int *flags);
618 void sc_get_bios_values(bios_values_t *values);
619 int sc_tone(int herz);
621 #endif /* !_DEV_SYSCONS_SYSCONS_H_ */