Contiki 2.6

libconio_z80.c

00001 /*
00002  * Copyright (c) 2007, Takahide Matsutsuka.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above
00011  *    copyright notice, this list of conditions and the following
00012  *    disclaimer in the documentation and/or other materials provided
00013  *    with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote
00015  *    products derived from this software without specific prior
00016  *    written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00019  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00022  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00024  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * $Id: libconio_z80.c,v 1.1 2007/09/19 12:48:26 matsutsuka Exp $
00031  *
00032  */
00033  /*
00034   * \file
00035   *     Arcitecture-depend libconio module, which supposes
00036   *     the machine has character VRAM and optional attribute VRAM
00037   *     on the main memory.
00038   * \author
00039   *     Takahide Matsutsuka <markn@markn.org>
00040   */
00041 
00042 #include "contiki.h"
00043 #include "sys/log.h"
00044 #include "libconio.h"
00045 #include "libconio_z80.h"
00046 
00047 /*---------------------------------------------------------------------------*/
00048 static void scroll() {
00049   unsigned char y;
00050   uint16_t src, dst;
00051   for (y = 0; y < LIBCONIO_CONF_SCREEN_HEIGHT - 1; y++) {
00052     dst = LIBCONIO_VRAM_OFFSET(0, y);
00053     src = LIBCONIO_VRAM_OFFSET(0, y + 1);
00054     memcpy(LIBCONIO_VRAM_CHAR + dst,
00055            LIBCONIO_VRAM_CHAR + src,
00056            LIBCONIO_CONF_SCREEN_WIDTH);
00057 #ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
00058     memcpy(LIBCONIO_VRAM_ATTR + dst,
00059            LIBCONIO_VRAM_ATTR + src,
00060            LIBCONIO_CONF_SCREEN_WIDTH);
00061 #endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
00062   }
00063   dst = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
00064   memset(LIBCONIO_VRAM_CHAR + dst, ' ',
00065          LIBCONIO_CONF_SCREEN_WIDTH);
00066 #ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
00067   memset(LIBCONIO_VRAM_ATTR + dst, LIBCONIO_COLOR_NORMAL,
00068          LIBCONIO_CONF_SCREEN_WIDTH);
00069 #endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
00070 
00071   gotoxy(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
00072 }
00073 /*---------------------------------------------------------------------------*/
00074 /* make sure that the position is inside screen */
00075 static void adjust(unsigned char *x, unsigned char *y) {
00076   if (*x > LIBCONIO_CONF_SCREEN_WIDTH) {
00077     *y += *x / LIBCONIO_CONF_SCREEN_WIDTH;
00078     *x = *x % LIBCONIO_CONF_SCREEN_WIDTH;
00079     gotoxy(*x, *y);
00080   }
00081 }
00082 /*---------------------------------------------------------------------------*/
00083 void ctk_arch_draw_char(char c,
00084                         unsigned char xpos,
00085                         unsigned char ypos,
00086                         unsigned char reversed,
00087                         unsigned char color) {
00088   uint16_t off;
00089   adjust(&xpos, &ypos);
00090 
00091   off = LIBCONIO_VRAM_OFFSET(xpos, ypos);
00092   if (off >= LIBCONIO_VRAM_OFFSET_MAX) {
00093     scroll();
00094     off = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
00095   }
00096   *(char *)(LIBCONIO_VRAM_CHAR + off) = c;
00097 #ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
00098   *(char *)(LIBCONIO_VRAM_ATTR + off) = reversed ?
00099     LIBCONIO_COLOR_REVERSED : LIBCONIO_COLOR_NORMAL;
00100 #endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
00101 }
00102 /*---------------------------------------------------------------------------*/