Home | History | Annotate | Line # | Download | only in boot
console.c revision 1.3.26.1
      1  1.3.26.1  nathanw /* $NetBSD: console.c,v 1.3.26.1 2002/01/08 00:23:00 nathanw 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.3.26.1  nathanw struct Console {
     70  1.3.26.1  nathanw 	int magic;
     71  1.3.26.1  nathanw 	struct AmigaIO *cnior;
     72  1.3.26.1  nathanw 	struct TimerIO *tmior;
     73  1.3.26.1  nathanw 	struct MsgPort *cnmp;
     74  1.3.26.1  nathanw 	struct Screen *s;
     75  1.3.26.1  nathanw 	struct Window *w;
     76  1.3.26.1  nathanw } *ConsoleBase;
     77  1.3.26.1  nathanw static struct Console myConsole;
     78       1.1       is 
     79       1.1       is u_int16_t timelimit;
     80       1.1       is 
     81       1.1       is int
     82  1.3.26.1  nathanw consinit(void *consptr) {
     83  1.3.26.1  nathanw 	struct Console *mc;
     84       1.1       is 
     85  1.3.26.1  nathanw 	if (consptr != NULL) {
     86  1.3.26.1  nathanw 		/* Check magic? */
     87  1.3.26.1  nathanw 		ConsoleBase = consptr;		/* Use existing console */
     88  1.3.26.1  nathanw 		return (0);
     89  1.3.26.1  nathanw 	}
     90  1.3.26.1  nathanw 
     91  1.3.26.1  nathanw 	mc = &myConsole;
     92       1.1       is 	IntuitionBase = OpenLibrary("intuition.library", 36L);
     93       1.1       is 	if (IntuitionBase == 0)
     94       1.1       is 		goto err;
     95       1.1       is 
     96  1.3.26.1  nathanw 	mc->s = OpenScreenTagList(0, screentags);
     97  1.3.26.1  nathanw 	if (!mc->s)
     98       1.1       is 		goto err;
     99       1.1       is 
    100  1.3.26.1  nathanw 	windowtags[1] = (u_int32_t)mc->s;
    101  1.3.26.1  nathanw 	mc->w = OpenWindowTagList(0, windowtags);
    102  1.3.26.1  nathanw 	if (!mc->w)
    103       1.1       is 		goto err;
    104       1.1       is 
    105  1.3.26.1  nathanw 	mc->cnmp = CreateMsgPort();
    106       1.1       is 
    107  1.3.26.1  nathanw 	if (!mc->cnmp)
    108       1.1       is 		goto err;
    109       1.1       is 
    110  1.3.26.1  nathanw 	mc->cnior = (struct AmigaIO *)CreateIORequest(mc->cnmp, sizeof(struct AmigaIO));
    111  1.3.26.1  nathanw 	if (!mc->cnior)
    112       1.1       is 		goto err;
    113       1.1       is 
    114  1.3.26.1  nathanw 	mc->cnior->buf = (void *)mc->w;
    115  1.3.26.1  nathanw 	if (OpenDevice("console.device", 0, mc->cnior, 0))
    116       1.1       is 		goto err;
    117       1.1       is 
    118  1.3.26.1  nathanw 	mc->tmior = (struct TimerIO *)CreateIORequest(mc->cnmp, sizeof(struct TimerIO));
    119  1.3.26.1  nathanw 	if (!mc->tmior)
    120       1.1       is 		goto err;
    121       1.1       is 
    122  1.3.26.1  nathanw 	if (OpenDevice("timer.device", 0, (struct AmigaIO*)mc->tmior, 0))
    123       1.1       is 		goto err;
    124       1.1       is 
    125  1.3.26.1  nathanw 	ConsoleBase = mc;
    126       1.1       is 	return 0;
    127       1.1       is 
    128       1.1       is err:
    129       1.1       is #ifdef notyet
    130  1.3.26.1  nathanw 	if (mc->tmior)
    131  1.3.26.1  nathanw 		DeleteIORequest(mc->tmior);
    132       1.1       is 
    133  1.3.26.1  nathanw 	if (mc->cnior)
    134  1.3.26.1  nathanw 		DeleteIORequest(mc->cnior);
    135       1.1       is 
    136  1.3.26.1  nathanw 	if (mc->cnmp)
    137  1.3.26.1  nathanw 		DeleteMsgPort(mc->cnmp);
    138       1.1       is 
    139  1.3.26.1  nathanw 	if (mc->w)
    140  1.3.26.1  nathanw 		CloseWindow(mc->w);
    141       1.1       is 
    142  1.3.26.1  nathanw 	if (mc->s)
    143  1.3.26.1  nathanw 		CloseScreen(mc->s);
    144       1.1       is 	if (IntuitionBase)
    145       1.1       is 		CloseLibrary(IntuitionBase);
    146       1.1       is #endif
    147       1.1       is 
    148       1.1       is 	return 1;
    149       1.1       is }
    150       1.1       is 
    151  1.3.26.1  nathanw #ifdef _PRIMARY_BOOT
    152  1.3.26.1  nathanw int
    153  1.3.26.1  nathanw consclose()
    154  1.3.26.1  nathanw {
    155  1.3.26.1  nathanw 	struct Console *mc = ConsoleBase;
    156  1.3.26.1  nathanw 
    157  1.3.26.1  nathanw 	if (mc == NULL)
    158  1.3.26.1  nathanw 		return 0;
    159  1.3.26.1  nathanw 	if (mc->tmior) {
    160  1.3.26.1  nathanw 		CloseDevice((struct AmigaIO *)mc->tmior);
    161  1.3.26.1  nathanw 		DeleteIORequest(mc->tmior);
    162  1.3.26.1  nathanw 	}
    163  1.3.26.1  nathanw 
    164  1.3.26.1  nathanw 	if (mc->cnior) {
    165  1.3.26.1  nathanw 		CloseDevice(mc->cnior);
    166  1.3.26.1  nathanw 		DeleteIORequest(mc->cnior);
    167  1.3.26.1  nathanw 	}
    168  1.3.26.1  nathanw 
    169  1.3.26.1  nathanw 	if (mc->cnmp)
    170  1.3.26.1  nathanw 		DeleteMsgPort(mc->cnmp);
    171  1.3.26.1  nathanw 
    172  1.3.26.1  nathanw 	if (mc->w)
    173  1.3.26.1  nathanw 		CloseWindow(mc->w);
    174  1.3.26.1  nathanw 
    175  1.3.26.1  nathanw 	if (mc->s)
    176  1.3.26.1  nathanw 		CloseScreen(mc->s);
    177  1.3.26.1  nathanw 	if (IntuitionBase)
    178  1.3.26.1  nathanw 		CloseLibrary(IntuitionBase);
    179  1.3.26.1  nathanw 	ConsoleBase = NULL;
    180  1.3.26.1  nathanw 	return 0;
    181  1.3.26.1  nathanw }
    182  1.3.26.1  nathanw #endif
    183  1.3.26.1  nathanw 
    184       1.1       is void
    185       1.1       is putchar(c)
    186       1.1       is 	char c;
    187       1.1       is {
    188  1.3.26.1  nathanw 	struct Console *mc = ConsoleBase;
    189  1.3.26.1  nathanw 
    190  1.3.26.1  nathanw 	mc->cnior->length = 1;
    191  1.3.26.1  nathanw 	mc->cnior->buf = &c;
    192  1.3.26.1  nathanw 	mc->cnior->cmd = Cmd_Wr;
    193  1.3.26.1  nathanw 	(void)DoIO(mc->cnior);
    194       1.1       is }
    195       1.1       is 
    196       1.1       is void
    197       1.1       is puts(s)
    198       1.1       is 	char *s;
    199       1.1       is {
    200  1.3.26.1  nathanw 	struct Console *mc = ConsoleBase;
    201  1.3.26.1  nathanw 
    202  1.3.26.1  nathanw 	mc->cnior->length = -1;
    203  1.3.26.1  nathanw 	mc->cnior->buf = s;
    204  1.3.26.1  nathanw 	mc->cnior->cmd = Cmd_Wr;
    205  1.3.26.1  nathanw 	(void)DoIO(mc->cnior);
    206       1.1       is }
    207       1.1       is 
    208       1.1       is int
    209       1.1       is getchar()
    210       1.1       is {
    211       1.1       is 	struct AmigaIO *ior;
    212       1.1       is 	char c = -1;
    213  1.3.26.1  nathanw 	struct Console *mc = ConsoleBase;
    214       1.1       is 
    215  1.3.26.1  nathanw 	mc->cnior->length = 1;
    216  1.3.26.1  nathanw 	mc->cnior->buf = &c;
    217  1.3.26.1  nathanw 	mc->cnior->cmd = Cmd_Rd;
    218       1.1       is 
    219  1.3.26.1  nathanw 	SendIO(mc->cnior);
    220       1.1       is 
    221       1.1       is 	if (timelimit) {
    222  1.3.26.1  nathanw 		mc->tmior->cmd = Cmd_Addtimereq;
    223  1.3.26.1  nathanw 		mc->tmior->secs = timelimit;
    224  1.3.26.1  nathanw 		mc->tmior->usec = 2; /* Paranoid */
    225  1.3.26.1  nathanw 		SendIO((struct AmigaIO *)mc->tmior);
    226  1.3.26.1  nathanw 
    227  1.3.26.1  nathanw 		ior = WaitPort(mc->cnmp);
    228  1.3.26.1  nathanw 		if (ior == mc->cnior)
    229  1.3.26.1  nathanw 			AbortIO((struct AmigaIO *)mc->tmior);
    230  1.3.26.1  nathanw 		else /* if (ior == mc->tmior) */ {
    231  1.3.26.1  nathanw 			AbortIO(mc->cnior);
    232       1.1       is 			c = '\n';
    233       1.1       is 		}
    234  1.3.26.1  nathanw 		WaitIO((struct AmigaIO *)mc->tmior);
    235       1.1       is 		timelimit = 0;
    236       1.1       is 	}
    237  1.3.26.1  nathanw 	(void)WaitIO(mc->cnior);
    238       1.1       is 	return c;
    239       1.1       is }
    240