1 /* $NetBSD: console.c,v 1.12 2009/10/11 10:00:10 mlelstv Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
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
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Bootblock support routines for Intuition console support.
36 #include <sys/types.h>
38 #include <lib/libsa/stand.h>
39 #include "samachdep.h"
41 #include "amigatypes.h"
42 #include "amigagraph.h"
46 const u_int32_t screentags
[] = {
47 SA_Type
, CUSTOMSCREEN
,
54 u_int32_t windowtags
[] = {
64 struct AmigaIO
*cnior
;
65 struct TimerIO
*tmior
;
70 static struct Console myConsole
;
75 consinit(void *consptr
) {
78 if (consptr
!= NULL
) {
80 ConsoleBase
= consptr
; /* Use existing console */
85 IntuitionBase
= OpenLibrary("intuition.library", 36L);
86 if (IntuitionBase
== 0)
89 mc
->s
= OpenScreenTagList(0, screentags
);
93 windowtags
[1] = (u_int32_t
)mc
->s
;
94 mc
->w
= OpenWindowTagList(0, windowtags
);
98 mc
->cnmp
= CreateMsgPort();
103 mc
->cnior
= (struct AmigaIO
*)CreateIORequest(mc
->cnmp
, sizeof(struct AmigaIO
));
107 mc
->cnior
->buf
= (void *)mc
->w
;
108 if (OpenDevice("console.device", 0, mc
->cnior
, 0))
111 mc
->tmior
= (struct TimerIO
*)CreateIORequest(mc
->cnmp
, sizeof(struct TimerIO
));
115 if (OpenDevice("timer.device", 0, (struct AmigaIO
*)mc
->tmior
, 0))
128 DeleteIORequest(mc
->tmior
);
131 DeleteIORequest(mc
->cnior
);
134 DeleteMsgPort(mc
->cnmp
);
142 CloseLibrary(IntuitionBase
);
152 struct Console
*mc
= ConsoleBase
;
157 CloseDevice((struct AmigaIO
*)mc
->tmior
);
158 DeleteIORequest(mc
->tmior
);
162 CloseDevice(mc
->cnior
);
163 DeleteIORequest(mc
->cnior
);
167 DeleteMsgPort(mc
->cnmp
);
175 CloseLibrary(IntuitionBase
);
184 struct Console
*mc
= ConsoleBase
;
187 mc
->cnior
->length
= 1;
188 mc
->cnior
->buf
= &buf
;
189 mc
->cnior
->cmd
= Cmd_Wr
;
192 RawPutChar((int32_t)c
);
195 (void)DoIO(mc
->cnior
);
201 struct Console
*mc
= ConsoleBase
;
203 mc
->cnior
->length
= -1;
205 mc
->cnior
->cmd
= Cmd_Wr
;
212 (void)DoIO(mc
->cnior
);
220 struct Console
*mc
= ConsoleBase
;
226 mc
->cnior
->length
= 1;
228 mc
->cnior
->cmd
= Cmd_Rd
;
232 ticks
= 10 * timelimit
;
237 mc
->tmior
->cmd
= Cmd_Addtimereq
;
239 mc
->tmior
->usec
= 100000;
240 SendIO((struct AmigaIO
*)mc
->tmior
);
242 ior
= WaitPort(mc
->cnmp
);
243 if (ior
== mc
->cnior
) {
244 AbortIO((struct AmigaIO
*)mc
->tmior
);
246 } else /* if (ior == mc->tmior) */ {
255 AbortIO((struct AmigaIO
*)mc
->cnior
);
257 WaitIO((struct AmigaIO
*)mc
->tmior
);
260 } while (ticks
!= 0);
263 (void)WaitIO(mc
->cnior
);