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