Home | History | Annotate | Line # | Download | only in boot
console.c revision 1.3
      1 /* $NetBSD: console.c,v 1.3 1999/02/16 23:34:11 is Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Ignatios Souvatzis.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Bootblock support routines for Intuition console support.
     41  */
     42 
     43 #include <sys/types.h>
     44 
     45 #include <stand.h>
     46 #include "samachdep.h"
     47 
     48 #include "amigatypes.h"
     49 #include "amigagraph.h"
     50 #include "amigaio.h"
     51 #include "libstubs.h"
     52 
     53 const u_int32_t screentags[] = {
     54 	SA_Type, CUSTOMSCREEN,
     55 	SA_DisplayID, 0x8000,
     56 	SA_ShowTitle, 0,
     57 	SA_Quiet, 1,
     58 	0
     59 };
     60 
     61 u_int32_t windowtags[] = {
     62 	WA_CustomScreen, 0L,
     63 	WA_Borderless, 1L,
     64 	WA_Backdrop, 1L,
     65 	WA_Activate, 1L,
     66 	0
     67 };
     68 
     69 struct AmigaIO *cnior;
     70 struct TimerIO *tmior;
     71 struct MsgPort *cnmp;
     72 
     73 u_int16_t timelimit;
     74 
     75 int
     76 consinit() {
     77 	struct Screen *s = 0;
     78 	struct Window *w = 0;
     79 
     80 	IntuitionBase = OpenLibrary("intuition.library", 36L);
     81 	if (IntuitionBase == 0)
     82 		goto err;
     83 
     84 	s = OpenScreenTagList(0, screentags);
     85 	if (!s)
     86 		goto err;
     87 
     88 	windowtags[1] = (u_int32_t)s;
     89 	w = OpenWindowTagList(0, windowtags);
     90 	if (!w)
     91 		goto err;
     92 
     93 	cnmp = CreateMsgPort();
     94 
     95 	if (!cnmp)
     96 		goto err;
     97 
     98 	cnior = (struct AmigaIO *)CreateIORequest(cnmp, sizeof(struct AmigaIO));
     99 	if (!cnior)
    100 		goto err;
    101 
    102 	cnior->buf = (void *)w;
    103 	if (OpenDevice("console.device", 0, cnior, 0))
    104 		goto err;
    105 
    106 	tmior = (struct TimerIO *)CreateIORequest(cnmp, sizeof(struct TimerIO));
    107 	if (!tmior)
    108 		goto err;
    109 
    110 	if (OpenDevice("timer.device", 0, (struct AmigaIO*)tmior, 0))
    111 		goto err;
    112 
    113 	return 0;
    114 
    115 err:
    116 #ifdef notyet
    117 	if (tmior)
    118 		DeleteIORequest(tmior);
    119 
    120 	if (cnior)
    121 		DeleteIORequest(cnior);
    122 
    123 	if (cnmp)
    124 		DeleteMsgPort(cnmp);
    125 
    126 	if (w)
    127 		CloseWindow(w);
    128 
    129 	if (s)
    130 		CloseScreen(s);
    131 	if (IntuitionBase)
    132 		CloseLibrary(IntuitionBase);
    133 #endif
    134 
    135 	return 1;
    136 }
    137 
    138 void
    139 putchar(c)
    140 	char c;
    141 {
    142 	cnior->length = 1;
    143 	cnior->buf = &c;
    144 	cnior->cmd = Cmd_Wr;
    145 	(void)DoIO(cnior);
    146 }
    147 
    148 void
    149 puts(s)
    150 	char *s;
    151 {
    152 	cnior->length = -1;
    153 	cnior->buf = s;
    154 	cnior->cmd = Cmd_Wr;
    155 	(void)DoIO(cnior);
    156 }
    157 
    158 int
    159 getchar()
    160 {
    161 	struct AmigaIO *ior;
    162 	char c = -1;
    163 
    164 	cnior->length = 1;
    165 	cnior->buf = &c;
    166 	cnior->cmd = Cmd_Rd;
    167 
    168 	SendIO(cnior);
    169 
    170 	if (timelimit) {
    171 		tmior->cmd = Cmd_Addtimereq;
    172 		tmior->secs = timelimit;
    173 		tmior->usec = 2; /* Paranoid */
    174 		SendIO((struct AmigaIO *)tmior);
    175 
    176 		ior = WaitPort(cnmp);
    177 		if (ior == cnior)
    178 			AbortIO((struct AmigaIO *)tmior);
    179 		else /* if (ior == tmior) */ {
    180 			AbortIO(cnior);
    181 			c = '\n';
    182 		}
    183 		WaitIO((struct AmigaIO *)tmior);
    184 		timelimit = 0;
    185 	}
    186 	(void)WaitIO(cnior);
    187 	return c;
    188 }
    189