199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * spinconsole.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Author: Maksym Sobolyev <sobomax@sippysoft.com>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2009 Sippy Software, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Subject to the following obligations and disclaimer of warranty, use and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * redistribution of this software, in source or object code forms, with or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without modifications are expressly permitted by Whistle Communications;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * provided, however, that:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Any and all reproductions of the source or object code must include the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * copyright notice above and the following disclaimer of warranties; and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. No rights are granted, in any manner or form, to use Whistle
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Communications, Inc. trademarks, including the mark "WHISTLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * such appears in the above copyright notice or in the software.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
199767f8919635c4928607450d9e0abb932109ceToomas Soome * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
199767f8919635c4928607450d9e0abb932109ceToomas Soome * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <stand.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <bootstrap.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void get_pos(int *x, int *y);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void curs_move(int *_x, int *_y, int x, int y);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(EFI)
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void efi_cons_efiputchar(int c);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void vidc_biosputchar(int c);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void spinc_probe(struct console *cp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int spinc_init(struct console *cp, int arg);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void spinc_putchar(struct console *cp, int c);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int spinc_getchar(struct console *cp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int spinc_ischar(struct console *cp);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct console spinconsole = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome "spin",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "spin port",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome spinc_probe,
199767f8919635c4928607450d9e0abb932109ceToomas Soome spinc_init,
199767f8919635c4928607450d9e0abb932109ceToomas Soome spinc_putchar,
199767f8919635c4928607450d9e0abb932109ceToomas Soome spinc_getchar,
199767f8919635c4928607450d9e0abb932109ceToomas Soome spinc_ischar,
199767f8919635c4928607450d9e0abb932109ceToomas Soome NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomespinc_probe(struct console *cp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomespinc_init(struct console *cp __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome int arg __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return(0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomespinc_putchar(struct console *cp __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome int c __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef TERM_EMU
199767f8919635c4928607450d9e0abb932109ceToomas Soome static int curx, cury;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome static unsigned tw_chars = 0x5C2D2F7C; /* "\-/|" */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static time_t lasttime;
199767f8919635c4928607450d9e0abb932109ceToomas Soome time_t now;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome now = time(NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (now < (lasttime + 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome lasttime = now;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef TERM_EMU
199767f8919635c4928607450d9e0abb932109ceToomas Soome get_pos(&curx, &cury);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (curx > 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome curs_move(&curx, &cury, curx - 1, cury);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(EFI)
199767f8919635c4928607450d9e0abb932109ceToomas Soome efi_cons_efiputchar((char)tw_chars);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome vidc_biosputchar((char)tw_chars);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomespinc_getchar(struct console *cp __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return(-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomespinc_ischar(struct console *cp __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return(0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}