xref: /original-bsd/sys/news3400/news3400/cons.c (revision d1003170)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Kazumasa Utashiro of Software Research Associates, Inc.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)cons.c	7.1 (Berkeley) 06/04/92
11  */
12 
13 #include "param.h"
14 #include "proc.h"
15 #include "systm.h"
16 #include "buf.h"
17 #include "ioctl.h"
18 #include "tty.h"
19 #include "file.h"
20 #include "conf.h"
21 
22 dev_t consdev = (dev_t)NULL;	/* initialized by consinit() */
23 struct tty *constty = 0;
24 
25 vcopen(dev, flag, mode, p)
26 	dev_t dev;
27 	int flag, mode;
28 	struct proc *p;
29 {
30 	if ((dev = consdev) == NULL)
31 		return 0;
32 	return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
33 }
34 
35 vcclose(dev, flag, mode, p)
36 	dev_t dev;
37 	int flag, mode;
38 	struct proc *p;
39 {
40 	if ((dev = consdev) == NULL)
41 		return 0;
42 	return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
43 }
44 
45 vcread(dev, uio, flag)
46 	dev_t dev;
47 	struct uio *uio;
48 {
49 	if ((dev = consdev) == NULL)
50 		return 0;
51 	return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
52 }
53 
54 vcwrite(dev, uio, flag)
55 	dev_t dev;
56 	struct uio *uio;
57 	int flag;
58 {
59 	if ((dev = consdev) == NULL)
60 		return 0;
61 	return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
62 }
63 
64 vcstop(tp, flag)
65 	struct tty *tp;
66 	int flag;
67 {
68 	dev_t dev;
69 
70 	if ((dev = consdev) == NULL)
71 		return 0;
72 	return ((*cdevsw[major(dev)].d_stop)(tp, flag));
73 }
74 
75 vcioctl(dev, cmd, data, flag, p)
76 	dev_t dev;
77 	caddr_t data;
78 	struct proc *p;
79 {
80 	if ((dev = consdev) == NULL)
81 		return 0;
82 	return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
83 }
84 
85 /*ARGSUSED*/
86 vcselect(dev, rw, p)
87 	dev_t dev;
88 	int rw;
89 	struct proc *p;
90 {
91 	if ((dev = consdev) == NULL)
92 		return 1;
93 	return (ttselect(dev, rw, p));
94 }
95 
96 /*
97  * Get character from console.
98  */
99 cngetc()
100 {
101 	/* notyet */
102 	return(0);
103 }
104 
105 #define	SCC_CONSOLE	0
106 /*
107  * Print a character on console.
108  */
109 cnputc(c)
110 	int c;
111 {
112 	int s;
113 	int (*putc)(), scccons_putc(), bmcons_putc();
114 
115 	if (consdev == NULL)
116 		return 0;
117 
118 	if (consdev == makedev(1, 0))
119 		putc = scccons_putc;
120 	else
121 		putc = bmcons_putc;
122 
123 	s = splhigh();
124 	putc(c);
125 	if (c == '\n')
126 		putc('\r');
127 	splx(s);
128 }
129 
130 scccons_putc(c)
131 	int c;
132 {
133 	char cnbuf[1];
134 
135 	cnbuf[0] = (char)c;
136 	scc_error_write(SCC_CONSOLE, cnbuf, 1);
137 }
138 
139 bmcons_putc(c)
140 	int c;
141 {
142 	char cnbuf[1];
143 
144 	cnbuf[0] = (char)c;
145 	vt100_write(0, cnbuf, 1);
146 }
147