Home | History | Annotate | Line # | Download | only in boot
console.c revision 1.7.78.3
      1  1.7.78.3      yamt /* $NetBSD: console.c,v 1.7.78.3 2010/03/11 15:02:01 yamt 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  *
     19       1.2        is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.2        is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.2        is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.2        is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.2        is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.2        is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.2        is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.2        is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.2        is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.2        is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.2        is  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1        is  */
     31       1.1        is 
     32       1.1        is /*
     33       1.1        is  * Bootblock support routines for Intuition console support.
     34       1.1        is  */
     35       1.1        is 
     36       1.1        is #include <sys/types.h>
     37       1.1        is 
     38       1.6  junyoung #include <lib/libsa/stand.h>
     39       1.1        is #include "samachdep.h"
     40       1.1        is 
     41       1.1        is #include "amigatypes.h"
     42       1.1        is #include "amigagraph.h"
     43       1.1        is #include "amigaio.h"
     44       1.1        is #include "libstubs.h"
     45       1.1        is 
     46       1.1        is const u_int32_t screentags[] = {
     47       1.1        is 	SA_Type, CUSTOMSCREEN,
     48       1.1        is 	SA_DisplayID, 0x8000,
     49       1.1        is 	SA_ShowTitle, 0,
     50       1.1        is 	SA_Quiet, 1,
     51       1.1        is 	0
     52       1.1        is };
     53       1.1        is 
     54       1.1        is u_int32_t windowtags[] = {
     55       1.1        is 	WA_CustomScreen, 0L,
     56       1.1        is 	WA_Borderless, 1L,
     57       1.1        is 	WA_Backdrop, 1L,
     58       1.1        is 	WA_Activate, 1L,
     59       1.1        is 	0
     60       1.1        is };
     61       1.1        is 
     62       1.4    mhitch struct Console {
     63       1.4    mhitch 	int magic;
     64       1.4    mhitch 	struct AmigaIO *cnior;
     65       1.4    mhitch 	struct TimerIO *tmior;
     66       1.4    mhitch 	struct MsgPort *cnmp;
     67       1.4    mhitch 	struct Screen *s;
     68       1.4    mhitch 	struct Window *w;
     69       1.4    mhitch } *ConsoleBase;
     70       1.4    mhitch static struct Console myConsole;
     71       1.1        is 
     72       1.1        is u_int16_t timelimit;
     73       1.1        is 
     74       1.1        is int
     75       1.4    mhitch consinit(void *consptr) {
     76       1.4    mhitch 	struct Console *mc;
     77       1.1        is 
     78       1.4    mhitch 	if (consptr != NULL) {
     79       1.4    mhitch 		/* Check magic? */
     80       1.4    mhitch 		ConsoleBase = consptr;		/* Use existing console */
     81       1.4    mhitch 		return (0);
     82       1.4    mhitch 	}
     83       1.4    mhitch 
     84       1.4    mhitch 	mc = &myConsole;
     85       1.1        is 	IntuitionBase = OpenLibrary("intuition.library", 36L);
     86       1.1        is 	if (IntuitionBase == 0)
     87       1.1        is 		goto err;
     88       1.1        is 
     89       1.4    mhitch 	mc->s = OpenScreenTagList(0, screentags);
     90       1.4    mhitch 	if (!mc->s)
     91       1.1        is 		goto err;
     92       1.1        is 
     93       1.4    mhitch 	windowtags[1] = (u_int32_t)mc->s;
     94       1.4    mhitch 	mc->w = OpenWindowTagList(0, windowtags);
     95       1.4    mhitch 	if (!mc->w)
     96       1.1        is 		goto err;
     97       1.1        is 
     98       1.4    mhitch 	mc->cnmp = CreateMsgPort();
     99       1.1        is 
    100       1.4    mhitch 	if (!mc->cnmp)
    101       1.1        is 		goto err;
    102       1.1        is 
    103       1.4    mhitch 	mc->cnior = (struct AmigaIO *)CreateIORequest(mc->cnmp, sizeof(struct AmigaIO));
    104       1.4    mhitch 	if (!mc->cnior)
    105       1.1        is 		goto err;
    106       1.1        is 
    107       1.4    mhitch 	mc->cnior->buf = (void *)mc->w;
    108       1.4    mhitch 	if (OpenDevice("console.device", 0, mc->cnior, 0))
    109       1.1        is 		goto err;
    110       1.1        is 
    111       1.4    mhitch 	mc->tmior = (struct TimerIO *)CreateIORequest(mc->cnmp, sizeof(struct TimerIO));
    112       1.4    mhitch 	if (!mc->tmior)
    113       1.1        is 		goto err;
    114       1.1        is 
    115       1.4    mhitch 	if (OpenDevice("timer.device", 0, (struct AmigaIO*)mc->tmior, 0))
    116       1.1        is 		goto err;
    117       1.1        is 
    118  1.7.78.3      yamt #ifdef SERCONSOLE
    119  1.7.78.3      yamt 	RawIOInit();
    120  1.7.78.3      yamt #endif
    121  1.7.78.3      yamt 
    122       1.4    mhitch 	ConsoleBase = mc;
    123       1.1        is 	return 0;
    124       1.1        is 
    125       1.1        is err:
    126       1.1        is #ifdef notyet
    127       1.4    mhitch 	if (mc->tmior)
    128       1.4    mhitch 		DeleteIORequest(mc->tmior);
    129       1.1        is 
    130       1.4    mhitch 	if (mc->cnior)
    131       1.4    mhitch 		DeleteIORequest(mc->cnior);
    132       1.1        is 
    133       1.4    mhitch 	if (mc->cnmp)
    134       1.4    mhitch 		DeleteMsgPort(mc->cnmp);
    135       1.1        is 
    136       1.4    mhitch 	if (mc->w)
    137       1.4    mhitch 		CloseWindow(mc->w);
    138       1.1        is 
    139       1.4    mhitch 	if (mc->s)
    140       1.4    mhitch 		CloseScreen(mc->s);
    141       1.1        is 	if (IntuitionBase)
    142       1.1        is 		CloseLibrary(IntuitionBase);
    143       1.1        is #endif
    144       1.1        is 
    145       1.1        is 	return 1;
    146       1.1        is }
    147       1.1        is 
    148       1.4    mhitch #ifdef _PRIMARY_BOOT
    149       1.4    mhitch int
    150  1.7.78.2      yamt consclose(void)
    151       1.4    mhitch {
    152       1.4    mhitch 	struct Console *mc = ConsoleBase;
    153       1.4    mhitch 
    154       1.4    mhitch 	if (mc == NULL)
    155       1.4    mhitch 		return 0;
    156       1.4    mhitch 	if (mc->tmior) {
    157       1.4    mhitch 		CloseDevice((struct AmigaIO *)mc->tmior);
    158       1.4    mhitch 		DeleteIORequest(mc->tmior);
    159       1.4    mhitch 	}
    160       1.4    mhitch 
    161       1.4    mhitch 	if (mc->cnior) {
    162       1.4    mhitch 		CloseDevice(mc->cnior);
    163       1.4    mhitch 		DeleteIORequest(mc->cnior);
    164       1.4    mhitch 	}
    165       1.4    mhitch 
    166       1.4    mhitch 	if (mc->cnmp)
    167       1.4    mhitch 		DeleteMsgPort(mc->cnmp);
    168       1.4    mhitch 
    169       1.4    mhitch 	if (mc->w)
    170       1.4    mhitch 		CloseWindow(mc->w);
    171       1.4    mhitch 
    172       1.4    mhitch 	if (mc->s)
    173       1.4    mhitch 		CloseScreen(mc->s);
    174       1.4    mhitch 	if (IntuitionBase)
    175       1.4    mhitch 		CloseLibrary(IntuitionBase);
    176       1.4    mhitch 	ConsoleBase = NULL;
    177       1.4    mhitch 	return 0;
    178       1.4    mhitch }
    179       1.4    mhitch #endif
    180       1.4    mhitch 
    181       1.1        is void
    182  1.7.78.2      yamt putchar(int c)
    183       1.1        is {
    184       1.4    mhitch 	struct Console *mc = ConsoleBase;
    185  1.7.78.3      yamt 	char buf = c;
    186       1.4    mhitch 
    187       1.4    mhitch 	mc->cnior->length = 1;
    188  1.7.78.3      yamt 	mc->cnior->buf = &buf;
    189       1.4    mhitch 	mc->cnior->cmd = Cmd_Wr;
    190  1.7.78.3      yamt 
    191  1.7.78.3      yamt #ifdef SERCONSOLE
    192  1.7.78.3      yamt 	RawPutChar((int32_t)c);
    193  1.7.78.3      yamt #endif
    194  1.7.78.3      yamt 
    195       1.4    mhitch 	(void)DoIO(mc->cnior);
    196       1.1        is }
    197       1.1        is 
    198       1.1        is void
    199  1.7.78.2      yamt puts(char *s)
    200       1.1        is {
    201       1.4    mhitch 	struct Console *mc = ConsoleBase;
    202       1.4    mhitch 
    203       1.4    mhitch 	mc->cnior->length = -1;
    204       1.4    mhitch 	mc->cnior->buf = s;
    205       1.4    mhitch 	mc->cnior->cmd = Cmd_Wr;
    206  1.7.78.3      yamt 
    207  1.7.78.3      yamt #ifdef SERCONSOLE
    208  1.7.78.3      yamt 	while (*s)
    209  1.7.78.3      yamt 		RawPutChar(*s++);
    210  1.7.78.3      yamt #endif
    211  1.7.78.3      yamt 
    212       1.4    mhitch 	(void)DoIO(mc->cnior);
    213       1.1        is }
    214       1.1        is 
    215       1.1        is int
    216  1.7.78.2      yamt getchar(void)
    217       1.1        is {
    218       1.1        is 	struct AmigaIO *ior;
    219  1.7.78.3      yamt 	char c = '\n';
    220       1.4    mhitch 	struct Console *mc = ConsoleBase;
    221  1.7.78.3      yamt 	unsigned long ticks;
    222  1.7.78.3      yamt #ifdef SERCONSOLE
    223  1.7.78.3      yamt 	int32_t r;
    224  1.7.78.3      yamt #endif
    225       1.1        is 
    226       1.4    mhitch 	mc->cnior->length = 1;
    227       1.4    mhitch 	mc->cnior->buf = &c;
    228       1.4    mhitch 	mc->cnior->cmd = Cmd_Rd;
    229       1.1        is 
    230       1.4    mhitch 	SendIO(mc->cnior);
    231       1.1        is 
    232  1.7.78.3      yamt 	ticks = 10 * timelimit;
    233  1.7.78.3      yamt 	do {
    234  1.7.78.3      yamt 		if (timelimit == 0)
    235  1.7.78.3      yamt 			ticks = 2;
    236  1.7.78.3      yamt 
    237       1.4    mhitch 		mc->tmior->cmd = Cmd_Addtimereq;
    238  1.7.78.3      yamt 		mc->tmior->secs = 0;
    239  1.7.78.3      yamt 		mc->tmior->usec = 100000;
    240       1.4    mhitch 		SendIO((struct AmigaIO *)mc->tmior);
    241       1.4    mhitch 
    242       1.4    mhitch 		ior = WaitPort(mc->cnmp);
    243  1.7.78.3      yamt 		if (ior == mc->cnior) {
    244       1.4    mhitch 			AbortIO((struct AmigaIO *)mc->tmior);
    245  1.7.78.3      yamt 			ticks = 1;
    246  1.7.78.3      yamt 		} else /* if (ior == mc->tmior) */ {
    247  1.7.78.3      yamt #ifdef SERCONSOLE
    248  1.7.78.3      yamt 			r = RawMayGetChar();
    249  1.7.78.3      yamt 			if (r != -1) {
    250  1.7.78.3      yamt 				c = r;
    251  1.7.78.3      yamt 				ticks = 1;
    252  1.7.78.3      yamt 			}
    253  1.7.78.3      yamt #endif
    254  1.7.78.3      yamt 			if (ticks == 1)
    255  1.7.78.3      yamt 				AbortIO((struct AmigaIO *)mc->cnior);
    256       1.1        is 		}
    257       1.4    mhitch 		WaitIO((struct AmigaIO *)mc->tmior);
    258  1.7.78.3      yamt 
    259  1.7.78.3      yamt 		--ticks;
    260  1.7.78.3      yamt 	} while (ticks != 0);
    261  1.7.78.3      yamt 	timelimit = 0;
    262  1.7.78.3      yamt 
    263       1.4    mhitch 	(void)WaitIO(mc->cnior);
    264       1.1        is 	return c;
    265       1.1        is }
    266