mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-09 23:54:32 +00:00
VRAM based default implementation of libconio_arch.
This commit is contained in:
parent
f9a01d6282
commit
91a57c89ba
102
cpu/z80/lib/libconio_arch.c
Normal file
102
cpu/z80/lib/libconio_arch.c
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Takahide Matsutsuka.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: libconio_arch.c,v 1.1 2007/09/09 12:21:54 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* \file
|
||||
* Arcitecture-depend libconio module, which supposes
|
||||
* the machine has character VRAM and optional attribute VRAM
|
||||
* on memory.
|
||||
* \author
|
||||
* Takahide Matsutsuka <markn@markn.org>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/log.h"
|
||||
#include "libconio.h"
|
||||
#include "libconio_arch.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void scroll() {
|
||||
unsigned char y;
|
||||
u16_t src, dst;
|
||||
for (y = 0; y < LIBCONIO_CONF_SCREEN_HEIGHT - 1; y++) {
|
||||
dst = LIBCONIO_VRAM_OFFSET(0, y);
|
||||
src = LIBCONIO_VRAM_OFFSET(0, y + 1);
|
||||
memcpy(LIBCONIO_VRAM_CHAR + dst,
|
||||
LIBCONIO_VRAM_CHAR + src,
|
||||
LIBCONIO_CONF_SCREEN_WIDTH);
|
||||
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
|
||||
memcpy(LIBCONIO_VRAM_ATTR + dst,
|
||||
LIBCONIO_VRAM_ATTR + src,
|
||||
LIBCONIO_CONF_SCREEN_WIDTH);
|
||||
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
|
||||
}
|
||||
dst = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
|
||||
memset(LIBCONIO_VRAM_CHAR + dst, ' ',
|
||||
LIBCONIO_CONF_SCREEN_WIDTH);
|
||||
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
|
||||
memset(LIBCONIO_VRAM_ATTR + dst, LIBCONIO_COLOR_NORMAL,
|
||||
LIBCONIO_CONF_SCREEN_WIDTH);
|
||||
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
|
||||
|
||||
gotoxy(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* make sure that the position is inside screen */
|
||||
static void adjust(unsigned char *x, unsigned char *y) {
|
||||
if (*x > LIBCONIO_CONF_SCREEN_WIDTH) {
|
||||
*y += *x / LIBCONIO_CONF_SCREEN_WIDTH;
|
||||
*x = *x % LIBCONIO_CONF_SCREEN_WIDTH;
|
||||
gotoxy(*x, *y);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void ctk_arch_draw_char(char c,
|
||||
unsigned char xpos,
|
||||
unsigned char ypos,
|
||||
unsigned char reversed,
|
||||
unsigned char color) {
|
||||
u16_t off;
|
||||
adjust(&xpos, &ypos);
|
||||
|
||||
off = LIBCONIO_VRAM_OFFSET(xpos, ypos);
|
||||
if (off >= LIBCONIO_VRAM_OFFSET_MAX) {
|
||||
scroll();
|
||||
off = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
|
||||
}
|
||||
*(char *)(LIBCONIO_VRAM_CHAR + off) = c;
|
||||
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
|
||||
*(char *)(LIBCONIO_VRAM_ATTR + off) = reversed ?
|
||||
LIBCONIO_COLOR_REVERSED : LIBCONIO_COLOR_NORMAL;
|
||||
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
88
cpu/z80/lib/libconio_arch.h
Normal file
88
cpu/z80/lib/libconio_arch.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Takahide Matsutsuka.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: libconio_arch.h,v 1.1 2007/09/09 12:21:54 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* \file
|
||||
* Arcitecture-depend libconio module, which supposes
|
||||
* the machine has character VRAM and optional attribute VRAM
|
||||
* on memory.
|
||||
* \author
|
||||
* Takahide Matsutsuka <markn@markn.org>
|
||||
*/
|
||||
|
||||
#ifndef __LIBCONIO_ARCH_H__
|
||||
#define __LIBCONIO_ARCH_H__
|
||||
|
||||
#ifndef LIBCONIO_VRAM_CHAR
|
||||
#error "must specify vram address for characters!"
|
||||
#endif /* LIBCONIO_VRAM_CHAR */
|
||||
|
||||
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
|
||||
#ifndef LIBCONIO_VRAM_ATTR
|
||||
#error "must specify vram address for attributes!"
|
||||
#endif /* LIBCONIO_VRAM_ATTR */
|
||||
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
|
||||
|
||||
#ifndef LIBCONIO_CONF_SCREEN_WIDTH
|
||||
#define LIBCONIO_CONF_SCREEN_WIDTH 32
|
||||
#endif /* LIBCONIO_CONF_SCREEN_WIDTH */
|
||||
|
||||
#ifndef LIBCONIO_CONF_SCREEN_HEIGHT
|
||||
#define LIBCONIO_CONF_SCREEN_HEIGHT 16
|
||||
#endif /* LIBCONIO_CONF_SCREEN_HEIGHT */
|
||||
|
||||
#ifndef LIBCONIO_COLOR_REVERSED
|
||||
#define LIBCONIO_COLOR_REVERSED 0x21
|
||||
#endif /* LIBCONIO_COLOR_REVERSED */
|
||||
|
||||
#ifndef LIBCONIO_COLOR_NORMAL
|
||||
#define LIBCONIO_COLOR_NORMAL 0x20
|
||||
#endif /* LIBCONIO_COLOR_NORMAL */
|
||||
|
||||
/*
|
||||
* An offset caluclation logic.
|
||||
* The default supposes the VRAM is sequential
|
||||
*/
|
||||
#ifndef LIBCONIO_VRAM_OFFSET
|
||||
#define LIBCONIO_VRAM_OFFSET(x, y) (y) * LIBCONIO_CONF_SCREEN_WIDTH + (x)
|
||||
#endif /* VRAM_OFFSET */
|
||||
|
||||
/*
|
||||
* A maximum offset + 1.
|
||||
* If offset is equal or more than this maximum, the screen will scroll.
|
||||
*/
|
||||
#ifndef LIBCONIO_VRAM_OFFSET_MAX
|
||||
#define LIBCONIO_VRAM_OFFSET_MAX \
|
||||
(LIBCONIO_CONF_SCREEN_HEIGHT * LIBCONIO_CONF_SCREEN_WIDTH)
|
||||
#endif /* VRAM_MAX */
|
||||
|
||||
#endif /* __LIBCONIO_ARCH_H__ */
|
Loading…
Reference in New Issue
Block a user