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