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