| @@ -1,230 +1,230 @@ | | | @@ -1,230 +1,230 @@ |
1 | /* $NetBSD: console.c,v 1.9 2009/03/14 21:04:04 dsl Exp $ */ | | 1 | /* $NetBSD: console.c,v 1.10 2009/03/17 00:13:43 he Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1996 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1996 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Ignatios Souvatzis. | | 8 | * by Ignatios Souvatzis. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Bootblock support routines for Intuition console support. | | 33 | * Bootblock support routines for Intuition console support. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/types.h> | | 36 | #include <sys/types.h> |
37 | | | 37 | |
38 | #include <lib/libsa/stand.h> | | 38 | #include <lib/libsa/stand.h> |
39 | #include "samachdep.h" | | 39 | #include "samachdep.h" |
40 | | | 40 | |
41 | #include "amigatypes.h" | | 41 | #include "amigatypes.h" |
42 | #include "amigagraph.h" | | 42 | #include "amigagraph.h" |
43 | #include "amigaio.h" | | 43 | #include "amigaio.h" |
44 | #include "libstubs.h" | | 44 | #include "libstubs.h" |
45 | | | 45 | |
46 | const u_int32_t screentags[] = { | | 46 | const u_int32_t screentags[] = { |
47 | SA_Type, CUSTOMSCREEN, | | 47 | SA_Type, CUSTOMSCREEN, |
48 | SA_DisplayID, 0x8000, | | 48 | SA_DisplayID, 0x8000, |
49 | SA_ShowTitle, 0, | | 49 | SA_ShowTitle, 0, |
50 | SA_Quiet, 1, | | 50 | SA_Quiet, 1, |
51 | 0 | | 51 | 0 |
52 | }; | | 52 | }; |
53 | | | 53 | |
54 | u_int32_t windowtags[] = { | | 54 | u_int32_t windowtags[] = { |
55 | WA_CustomScreen, 0L, | | 55 | WA_CustomScreen, 0L, |
56 | WA_Borderless, 1L, | | 56 | WA_Borderless, 1L, |
57 | WA_Backdrop, 1L, | | 57 | WA_Backdrop, 1L, |
58 | WA_Activate, 1L, | | 58 | WA_Activate, 1L, |
59 | 0 | | 59 | 0 |
60 | }; | | 60 | }; |
61 | | | 61 | |
62 | struct Console { | | 62 | struct Console { |
63 | int magic; | | 63 | int magic; |
64 | struct AmigaIO *cnior; | | 64 | struct AmigaIO *cnior; |
65 | struct TimerIO *tmior; | | 65 | struct TimerIO *tmior; |
66 | struct MsgPort *cnmp; | | 66 | struct MsgPort *cnmp; |
67 | struct Screen *s; | | 67 | struct Screen *s; |
68 | struct Window *w; | | 68 | struct Window *w; |
69 | } *ConsoleBase; | | 69 | } *ConsoleBase; |
70 | static struct Console myConsole; | | 70 | static struct Console myConsole; |
71 | | | 71 | |
72 | u_int16_t timelimit; | | 72 | u_int16_t timelimit; |
73 | | | 73 | |
74 | int | | 74 | int |
75 | consinit(void *consptr) { | | 75 | consinit(void *consptr) { |
76 | struct Console *mc; | | 76 | struct Console *mc; |
77 | | | 77 | |
78 | if (consptr != NULL) { | | 78 | if (consptr != NULL) { |
79 | /* Check magic? */ | | 79 | /* Check magic? */ |
80 | ConsoleBase = consptr; /* Use existing console */ | | 80 | ConsoleBase = consptr; /* Use existing console */ |
81 | return (0); | | 81 | return (0); |
82 | } | | 82 | } |
83 | | | 83 | |
84 | mc = &myConsole; | | 84 | mc = &myConsole; |
85 | IntuitionBase = OpenLibrary("intuition.library", 36L); | | 85 | IntuitionBase = OpenLibrary("intuition.library", 36L); |
86 | if (IntuitionBase == 0) | | 86 | if (IntuitionBase == 0) |
87 | goto err; | | 87 | goto err; |
88 | | | 88 | |
89 | mc->s = OpenScreenTagList(0, screentags); | | 89 | mc->s = OpenScreenTagList(0, screentags); |
90 | if (!mc->s) | | 90 | if (!mc->s) |
91 | goto err; | | 91 | goto err; |
92 | | | 92 | |
93 | windowtags[1] = (u_int32_t)mc->s; | | 93 | windowtags[1] = (u_int32_t)mc->s; |
94 | mc->w = OpenWindowTagList(0, windowtags); | | 94 | mc->w = OpenWindowTagList(0, windowtags); |
95 | if (!mc->w) | | 95 | if (!mc->w) |
96 | goto err; | | 96 | goto err; |
97 | | | 97 | |
98 | mc->cnmp = CreateMsgPort(); | | 98 | mc->cnmp = CreateMsgPort(); |
99 | | | 99 | |
100 | if (!mc->cnmp) | | 100 | if (!mc->cnmp) |
101 | goto err; | | 101 | goto err; |
102 | | | 102 | |
103 | mc->cnior = (struct AmigaIO *)CreateIORequest(mc->cnmp, sizeof(struct AmigaIO)); | | 103 | mc->cnior = (struct AmigaIO *)CreateIORequest(mc->cnmp, sizeof(struct AmigaIO)); |
104 | if (!mc->cnior) | | 104 | if (!mc->cnior) |
105 | goto err; | | 105 | goto err; |
106 | | | 106 | |
107 | mc->cnior->buf = (void *)mc->w; | | 107 | mc->cnior->buf = (void *)mc->w; |
108 | if (OpenDevice("console.device", 0, mc->cnior, 0)) | | 108 | if (OpenDevice("console.device", 0, mc->cnior, 0)) |
109 | goto err; | | 109 | goto err; |
110 | | | 110 | |
111 | mc->tmior = (struct TimerIO *)CreateIORequest(mc->cnmp, sizeof(struct TimerIO)); | | 111 | mc->tmior = (struct TimerIO *)CreateIORequest(mc->cnmp, sizeof(struct TimerIO)); |
112 | if (!mc->tmior) | | 112 | if (!mc->tmior) |
113 | goto err; | | 113 | goto err; |
114 | | | 114 | |
115 | if (OpenDevice("timer.device", 0, (struct AmigaIO*)mc->tmior, 0)) | | 115 | if (OpenDevice("timer.device", 0, (struct AmigaIO*)mc->tmior, 0)) |
116 | goto err; | | 116 | goto err; |
117 | | | 117 | |
118 | ConsoleBase = mc; | | 118 | ConsoleBase = mc; |
119 | return 0; | | 119 | return 0; |
120 | | | 120 | |
121 | err: | | 121 | err: |
122 | #ifdef notyet | | 122 | #ifdef notyet |
123 | if (mc->tmior) | | 123 | if (mc->tmior) |
124 | DeleteIORequest(mc->tmior); | | 124 | DeleteIORequest(mc->tmior); |
125 | | | 125 | |
126 | if (mc->cnior) | | 126 | if (mc->cnior) |
127 | DeleteIORequest(mc->cnior); | | 127 | DeleteIORequest(mc->cnior); |
128 | | | 128 | |
129 | if (mc->cnmp) | | 129 | if (mc->cnmp) |
130 | DeleteMsgPort(mc->cnmp); | | 130 | DeleteMsgPort(mc->cnmp); |
131 | | | 131 | |
132 | if (mc->w) | | 132 | if (mc->w) |
133 | CloseWindow(mc->w); | | 133 | CloseWindow(mc->w); |
134 | | | 134 | |
135 | if (mc->s) | | 135 | if (mc->s) |
136 | CloseScreen(mc->s); | | 136 | CloseScreen(mc->s); |
137 | if (IntuitionBase) | | 137 | if (IntuitionBase) |
138 | CloseLibrary(IntuitionBase); | | 138 | CloseLibrary(IntuitionBase); |
139 | #endif | | 139 | #endif |
140 | | | 140 | |
141 | return 1; | | 141 | return 1; |
142 | } | | 142 | } |
143 | | | 143 | |
144 | #ifdef _PRIMARY_BOOT | | 144 | #ifdef _PRIMARY_BOOT |
145 | int | | 145 | int |
146 | consclose() | | 146 | consclose() |
147 | { | | 147 | { |
148 | struct Console *mc = ConsoleBase; | | 148 | struct Console *mc = ConsoleBase; |
149 | | | 149 | |
150 | if (mc == NULL) | | 150 | if (mc == NULL) |
151 | return 0; | | 151 | return 0; |
152 | if (mc->tmior) { | | 152 | if (mc->tmior) { |
153 | CloseDevice((struct AmigaIO *)mc->tmior); | | 153 | CloseDevice((struct AmigaIO *)mc->tmior); |
154 | DeleteIORequest(mc->tmior); | | 154 | DeleteIORequest(mc->tmior); |
155 | } | | 155 | } |
156 | | | 156 | |
157 | if (mc->cnior) { | | 157 | if (mc->cnior) { |
158 | CloseDevice(mc->cnior); | | 158 | CloseDevice(mc->cnior); |
159 | DeleteIORequest(mc->cnior); | | 159 | DeleteIORequest(mc->cnior); |
160 | } | | 160 | } |
161 | | | 161 | |
162 | if (mc->cnmp) | | 162 | if (mc->cnmp) |
163 | DeleteMsgPort(mc->cnmp); | | 163 | DeleteMsgPort(mc->cnmp); |
164 | | | 164 | |
165 | if (mc->w) | | 165 | if (mc->w) |
166 | CloseWindow(mc->w); | | 166 | CloseWindow(mc->w); |
167 | | | 167 | |
168 | if (mc->s) | | 168 | if (mc->s) |
169 | CloseScreen(mc->s); | | 169 | CloseScreen(mc->s); |
170 | if (IntuitionBase) | | 170 | if (IntuitionBase) |
171 | CloseLibrary(IntuitionBase); | | 171 | CloseLibrary(IntuitionBase); |
172 | ConsoleBase = NULL; | | 172 | ConsoleBase = NULL; |
173 | return 0; | | 173 | return 0; |
174 | } | | 174 | } |
175 | #endif | | 175 | #endif |
176 | | | 176 | |
177 | void | | 177 | void |
178 | putchar(char c) | | 178 | putchar(int c) |
179 | { | | 179 | { |
180 | struct Console *mc = ConsoleBase; | | 180 | struct Console *mc = ConsoleBase; |
181 | | | 181 | |
182 | mc->cnior->length = 1; | | 182 | mc->cnior->length = 1; |
183 | mc->cnior->buf = &c; | | 183 | mc->cnior->buf = &c; |
184 | mc->cnior->cmd = Cmd_Wr; | | 184 | mc->cnior->cmd = Cmd_Wr; |
185 | (void)DoIO(mc->cnior); | | 185 | (void)DoIO(mc->cnior); |
186 | } | | 186 | } |
187 | | | 187 | |
188 | void | | 188 | void |
189 | puts(char *s) | | 189 | puts(char *s) |
190 | { | | 190 | { |
191 | struct Console *mc = ConsoleBase; | | 191 | struct Console *mc = ConsoleBase; |
192 | | | 192 | |
193 | mc->cnior->length = -1; | | 193 | mc->cnior->length = -1; |
194 | mc->cnior->buf = s; | | 194 | mc->cnior->buf = s; |
195 | mc->cnior->cmd = Cmd_Wr; | | 195 | mc->cnior->cmd = Cmd_Wr; |
196 | (void)DoIO(mc->cnior); | | 196 | (void)DoIO(mc->cnior); |
197 | } | | 197 | } |
198 | | | 198 | |
199 | int | | 199 | int |
200 | getchar() | | 200 | getchar() |
201 | { | | 201 | { |
202 | struct AmigaIO *ior; | | 202 | struct AmigaIO *ior; |
203 | char c = -1; | | 203 | char c = -1; |
204 | struct Console *mc = ConsoleBase; | | 204 | struct Console *mc = ConsoleBase; |
205 | | | 205 | |
206 | mc->cnior->length = 1; | | 206 | mc->cnior->length = 1; |
207 | mc->cnior->buf = &c; | | 207 | mc->cnior->buf = &c; |
208 | mc->cnior->cmd = Cmd_Rd; | | 208 | mc->cnior->cmd = Cmd_Rd; |
209 | | | 209 | |
210 | SendIO(mc->cnior); | | 210 | SendIO(mc->cnior); |
211 | | | 211 | |
212 | if (timelimit) { | | 212 | if (timelimit) { |
213 | mc->tmior->cmd = Cmd_Addtimereq; | | 213 | mc->tmior->cmd = Cmd_Addtimereq; |
214 | mc->tmior->secs = timelimit; | | 214 | mc->tmior->secs = timelimit; |
215 | mc->tmior->usec = 2; /* Paranoid */ | | 215 | mc->tmior->usec = 2; /* Paranoid */ |
216 | SendIO((struct AmigaIO *)mc->tmior); | | 216 | SendIO((struct AmigaIO *)mc->tmior); |
217 | | | 217 | |
218 | ior = WaitPort(mc->cnmp); | | 218 | ior = WaitPort(mc->cnmp); |
219 | if (ior == mc->cnior) | | 219 | if (ior == mc->cnior) |
220 | AbortIO((struct AmigaIO *)mc->tmior); | | 220 | AbortIO((struct AmigaIO *)mc->tmior); |
221 | else /* if (ior == mc->tmior) */ { | | 221 | else /* if (ior == mc->tmior) */ { |
222 | AbortIO(mc->cnior); | | 222 | AbortIO(mc->cnior); |
223 | c = '\n'; | | 223 | c = '\n'; |
224 | } | | 224 | } |
225 | WaitIO((struct AmigaIO *)mc->tmior); | | 225 | WaitIO((struct AmigaIO *)mc->tmior); |
226 | timelimit = 0; | | 226 | timelimit = 0; |
227 | } | | 227 | } |
228 | (void)WaitIO(mc->cnior); | | 228 | (void)WaitIO(mc->cnior); |
229 | return c; | | 229 | return c; |
230 | } | | 230 | } |