Home | History | Annotate | Line # | Download | only in libsa
consio.c revision 1.1
      1 /*	$NetBSD: consio.c,v 1.1 2001/09/27 10:03:27 minoura Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 MINOURA Makoto.
      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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include <machine/stdarg.h>
     29 #include <lib/libsa/stand.h>
     30 
     31 #include "libx68k.h"
     32 
     33 #include "iocs.h"
     34 #include "consio.h"
     35 
     36 enum {
     37 	ITE = 0,
     38 	SERIAL = 1,
     39 } x68k_console_device;
     40 
     41 int
     42 consio_init(int device)
     43 {
     44 	if (device < 0) {	/* undetemined yet */
     45 		if (KEYCTRL & 8)
     46 			device = ITE;
     47 		else {
     48 			IOCS_B_PRINT ("No keyboard; "
     49 				      "switching to serial console...");
     50 			device = SERIAL;
     51 		}
     52 	}
     53 
     54 	switch (device) {
     55 	case ITE:
     56 		x68k_console_device = ITE;
     57 		/* set palette here */
     58 		IOCS_OS_CURON ();
     59 		break;
     60 	case SERIAL:
     61 		x68k_console_device = SERIAL;
     62 		IOCS_OS_CUROF ();
     63 		IOCS_SET232C (SERPARAM);
     64 	}
     65 
     66 	return x68k_console_device;
     67 }
     68 
     69 int
     70 getchar (void)
     71 {
     72 	int r;
     73 
     74 	switch (x68k_console_device) {
     75 	case ITE:
     76 		while ((r = IOCS_B_KEYINP () & 0xff) == 0);
     77 		return r;
     78 	case SERIAL:
     79 		while ((r = IOCS_INP232C () & 0xff) == 0);
     80 		return r;
     81 	}
     82 
     83 	return -1;
     84 }
     85 
     86 void
     87 putchar (int c)
     88 {
     89 	if (c == '\n')
     90 		putchar('\r');
     91 	switch (x68k_console_device) {
     92 	case ITE:
     93 		IOCS_B_PUTC (c);
     94 	case SERIAL:
     95 		IOCS_OUT232C (c);
     96 	}
     97 }
     98 
     99 int
    100 check_getchar (void)
    101 {
    102 	switch (x68k_console_device) {
    103 	case ITE:
    104 		return IOCS_B_KEYSNS () & 0xff;
    105 	case SERIAL:
    106 		return IOCS_ISNS232C () & 0xff;
    107 	}
    108 
    109 	return -1;
    110 }
    111 
    112 int
    113 awaitkey_1sec (void)
    114 {
    115 	int i, c;
    116 
    117 	while (check_getchar())
    118 		getchar();
    119 
    120 	for (i = 0; i < 100 && (c = check_getchar()) == 0; i++) {
    121 		while (MFP_TIMERC > 100)
    122 			(void) JOYA;
    123 		while (MFP_TIMERC <= 100)
    124 			(void) JOYA;
    125 	}
    126 
    127 	while (check_getchar())
    128 		getchar();
    129 
    130 	return c;
    131 }
    132 
    133 __dead void
    134 panic(const char *fmt,...)
    135 {
    136 	va_list ap;
    137 
    138 	va_start(ap, fmt);
    139 
    140 	printf(fmt, ap);
    141 	printf("\n");
    142 	va_end(ap);
    143 
    144 	exit(1);
    145 }
    146 
    147 void
    148 print_title(const char *fmt, ...)
    149 {
    150 	va_list ap;
    151 
    152 	/* Print the logo image here */
    153 
    154 	va_start(ap, fmt);
    155 	printf(fmt, ap);
    156 	printf("\n");
    157 	va_end(ap);
    158 }
    159