consio.c revision 1.3.4.2 1 1.3.4.2 nathanw /* $NetBSD: consio.c,v 1.3.4.2 2002/01/08 00:28:48 nathanw Exp $ */
2 1.3.4.2 nathanw
3 1.3.4.2 nathanw /*
4 1.3.4.2 nathanw * Copyright (c) 2001 MINOURA Makoto.
5 1.3.4.2 nathanw * All rights reserved.
6 1.3.4.2 nathanw *
7 1.3.4.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 nathanw * modification, are permitted provided that the following conditions
9 1.3.4.2 nathanw * are met:
10 1.3.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.3.4.2 nathanw *
16 1.3.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.3.4.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.3.4.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.3.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.3.4.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.3.4.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.3.4.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.3.4.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.3.4.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.3.4.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.3.4.2 nathanw */
27 1.3.4.2 nathanw
28 1.3.4.2 nathanw #include <machine/stdarg.h>
29 1.3.4.2 nathanw #include <lib/libkern/libkern.h>
30 1.3.4.2 nathanw #include <lib/libsa/stand.h>
31 1.3.4.2 nathanw
32 1.3.4.2 nathanw #include "libx68k.h"
33 1.3.4.2 nathanw
34 1.3.4.2 nathanw #include "iocs.h"
35 1.3.4.2 nathanw #include "consio.h"
36 1.3.4.2 nathanw
37 1.3.4.2 nathanw enum {
38 1.3.4.2 nathanw ITE = 0,
39 1.3.4.2 nathanw SERIAL = 1,
40 1.3.4.2 nathanw } x68k_console_device;
41 1.3.4.2 nathanw
42 1.3.4.2 nathanw int
43 1.3.4.2 nathanw consio_init(int device)
44 1.3.4.2 nathanw {
45 1.3.4.2 nathanw if (device < 0) { /* undetemined yet */
46 1.3.4.2 nathanw if (KEYCTRL & 8)
47 1.3.4.2 nathanw device = ITE;
48 1.3.4.2 nathanw else {
49 1.3.4.2 nathanw IOCS_B_PRINT ("No keyboard; "
50 1.3.4.2 nathanw "switching to serial console...");
51 1.3.4.2 nathanw device = SERIAL;
52 1.3.4.2 nathanw }
53 1.3.4.2 nathanw }
54 1.3.4.2 nathanw
55 1.3.4.2 nathanw switch (device) {
56 1.3.4.2 nathanw case ITE:
57 1.3.4.2 nathanw x68k_console_device = ITE;
58 1.3.4.2 nathanw /* set palette here */
59 1.3.4.2 nathanw IOCS_OS_CURON ();
60 1.3.4.2 nathanw break;
61 1.3.4.2 nathanw case SERIAL:
62 1.3.4.2 nathanw x68k_console_device = SERIAL;
63 1.3.4.2 nathanw IOCS_OS_CUROF ();
64 1.3.4.2 nathanw IOCS_SET232C (SERPARAM);
65 1.3.4.2 nathanw }
66 1.3.4.2 nathanw
67 1.3.4.2 nathanw return x68k_console_device;
68 1.3.4.2 nathanw }
69 1.3.4.2 nathanw
70 1.3.4.2 nathanw int
71 1.3.4.2 nathanw getchar (void)
72 1.3.4.2 nathanw {
73 1.3.4.2 nathanw int r;
74 1.3.4.2 nathanw
75 1.3.4.2 nathanw switch (x68k_console_device) {
76 1.3.4.2 nathanw case ITE:
77 1.3.4.2 nathanw while ((r = IOCS_B_KEYINP () & 0xff) == 0);
78 1.3.4.2 nathanw return r;
79 1.3.4.2 nathanw case SERIAL:
80 1.3.4.2 nathanw while ((r = IOCS_INP232C () & 0xff) == 0);
81 1.3.4.2 nathanw return r;
82 1.3.4.2 nathanw }
83 1.3.4.2 nathanw
84 1.3.4.2 nathanw return -1;
85 1.3.4.2 nathanw }
86 1.3.4.2 nathanw
87 1.3.4.2 nathanw void
88 1.3.4.2 nathanw putchar (int c)
89 1.3.4.2 nathanw {
90 1.3.4.2 nathanw if (c == '\n')
91 1.3.4.2 nathanw putchar('\r');
92 1.3.4.2 nathanw switch (x68k_console_device) {
93 1.3.4.2 nathanw case ITE:
94 1.3.4.2 nathanw IOCS_B_PUTC (c);
95 1.3.4.2 nathanw case SERIAL:
96 1.3.4.2 nathanw IOCS_OUT232C (c);
97 1.3.4.2 nathanw }
98 1.3.4.2 nathanw }
99 1.3.4.2 nathanw
100 1.3.4.2 nathanw int
101 1.3.4.2 nathanw check_getchar (void)
102 1.3.4.2 nathanw {
103 1.3.4.2 nathanw switch (x68k_console_device) {
104 1.3.4.2 nathanw case ITE:
105 1.3.4.2 nathanw return IOCS_B_KEYSNS () & 0xff;
106 1.3.4.2 nathanw case SERIAL:
107 1.3.4.2 nathanw return IOCS_ISNS232C () & 0xff;
108 1.3.4.2 nathanw }
109 1.3.4.2 nathanw
110 1.3.4.2 nathanw return -1;
111 1.3.4.2 nathanw }
112 1.3.4.2 nathanw
113 1.3.4.2 nathanw int
114 1.3.4.2 nathanw awaitkey_1sec (void)
115 1.3.4.2 nathanw {
116 1.3.4.2 nathanw int i, c;
117 1.3.4.2 nathanw
118 1.3.4.2 nathanw while (check_getchar())
119 1.3.4.2 nathanw getchar();
120 1.3.4.2 nathanw
121 1.3.4.2 nathanw for (i = 0; i < 100 && (c = check_getchar()) == 0; i++) {
122 1.3.4.2 nathanw while (MFP_TIMERC > 100)
123 1.3.4.2 nathanw (void) JOYA;
124 1.3.4.2 nathanw while (MFP_TIMERC <= 100)
125 1.3.4.2 nathanw (void) JOYA;
126 1.3.4.2 nathanw }
127 1.3.4.2 nathanw
128 1.3.4.2 nathanw while (check_getchar())
129 1.3.4.2 nathanw getchar();
130 1.3.4.2 nathanw
131 1.3.4.2 nathanw return c;
132 1.3.4.2 nathanw }
133 1.3.4.2 nathanw
134 1.3.4.2 nathanw __dead void
135 1.3.4.2 nathanw panic(const char *fmt,...)
136 1.3.4.2 nathanw {
137 1.3.4.2 nathanw va_list ap;
138 1.3.4.2 nathanw
139 1.3.4.2 nathanw va_start(ap, fmt);
140 1.3.4.2 nathanw
141 1.3.4.2 nathanw printf(fmt, ap);
142 1.3.4.2 nathanw printf("\n");
143 1.3.4.2 nathanw va_end(ap);
144 1.3.4.2 nathanw
145 1.3.4.2 nathanw exit(1);
146 1.3.4.2 nathanw }
147 1.3.4.2 nathanw
148 1.3.4.2 nathanw extern void put_image(int, int);
149 1.3.4.2 nathanw
150 1.3.4.2 nathanw void
151 1.3.4.2 nathanw print_title(const char *fmt, ...)
152 1.3.4.2 nathanw {
153 1.3.4.2 nathanw va_list ap;
154 1.3.4.2 nathanw
155 1.3.4.2 nathanw if (x68k_console_device == ITE) {
156 1.3.4.2 nathanw int y, y1;
157 1.3.4.2 nathanw char *buf = alloca(240); /* about 3 lines */
158 1.3.4.2 nathanw char *p;
159 1.3.4.2 nathanw
160 1.3.4.2 nathanw y = y1 = (IOCS_B_LOCATE(-1, -1) & 0xffff) + 1;
161 1.3.4.2 nathanw put_image (8, y*16-6);
162 1.3.4.2 nathanw IOCS_B_LOCATE(0, y+3);
163 1.3.4.2 nathanw IOCS_B_PRINT("\360D\360a\360e\360m\360o\360n "
164 1.3.4.2 nathanw "\360l\360o\360g\360o "
165 1.3.4.2 nathanw "\360(\360C\360)\3601\3609\3609\3608\360 "
166 1.3.4.2 nathanw "\360b\360y\360 "
167 1.3.4.2 nathanw "\360M\360a\360r\360s\360h\360a\360l\360l\360 "
168 1.3.4.2 nathanw "\360K\360i\360r\360k\360 "
169 1.3.4.2 nathanw "\360M\360c\360K\360u\360s\360i\360c\360k\360.");
170 1.3.4.2 nathanw va_start(ap, fmt);
171 1.3.4.2 nathanw vsnprintf(buf, 240, fmt, ap);
172 1.3.4.2 nathanw va_end(ap);
173 1.3.4.2 nathanw while ((p = strchr(buf, '\n')) != 0) {
174 1.3.4.2 nathanw *p = 0;
175 1.3.4.2 nathanw IOCS_B_LOCATE(9, ++y);
176 1.3.4.2 nathanw IOCS_B_PRINT(buf);
177 1.3.4.2 nathanw buf = p+1;
178 1.3.4.2 nathanw }
179 1.3.4.2 nathanw IOCS_B_LOCATE(9, ++y);
180 1.3.4.2 nathanw IOCS_B_PRINT(buf);
181 1.3.4.2 nathanw IOCS_B_LOCATE(0, y1+5);
182 1.3.4.2 nathanw } else {
183 1.3.4.2 nathanw va_start(ap, fmt);
184 1.3.4.2 nathanw vprintf(fmt, ap);
185 1.3.4.2 nathanw va_end(ap);
186 1.3.4.2 nathanw printf("\n");
187 1.3.4.2 nathanw }
188 1.3.4.2 nathanw }
189