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