blob: 0b1d6a24473bb20864d560caf0da6ff62d738f1a [file] [log] [blame]
Adrien Destugues69b1f062017-06-05 13:44:30 +02001/*
2 * Copyright (c) 2002, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the Contiki desktop environment
31 *
32 * $Id: libconio.c,v 1.6 2004/09/12 20:24:55 adamdunkels Exp $
33 *
34 */
35
36#include <string.h>
37#include "libconio.h"
38
39#include "lib/textmode/textmode.h"
40
41static unsigned char cursx, cursy;
42static unsigned char color;
43
44/*-----------------------------------------------------------------------------------*/
45unsigned char
46wherex(void)
47{
48 return cursx;
49}
50/*-----------------------------------------------------------------------------------*/
51unsigned char
52wherey(void)
53{
54 return cursy;
55}
56/*-----------------------------------------------------------------------------------*/
57void
58clrscr(void)
59{
60 memset(vram, 0, LIBCONIO_SCREEN_WIDTH * LIBCONIO_SCREEN_HEIGHT);
61 memset(vram_attr, 0, LIBCONIO_SCREEN_WIDTH * LIBCONIO_SCREEN_HEIGHT);
62}
63/*-----------------------------------------------------------------------------------*/
64void
65revers(unsigned char c)
66{
67 if (c != 0) color |= 16;
68 else color &= ~16;
69}
70/*-----------------------------------------------------------------------------------*/
71void
72cputc(char c)
73{
74 ctk_arch_draw_char(c, cursx, cursy, 0, color);
75 ++cursx;
76}
77/*-----------------------------------------------------------------------------------*/
78void
79cputs(char *str)
80{
81 cursx += print_at(cursx, cursy, color, str);
82}
83/*-----------------------------------------------------------------------------------*/
84void
85cclear(unsigned char length)
86{
87 memset((uint8_t*)vram + cursy * LIBCONIO_SCREEN_WIDTH + cursx, 0, length);
88 memset((uint8_t*)vram_attr + cursy * LIBCONIO_SCREEN_WIDTH + cursx, color, length);
89 cursx += length;
90}
91/*-----------------------------------------------------------------------------------*/
92void
93chline(unsigned char length)
94{
95 memset((uint8_t*)vram + cursy * LIBCONIO_SCREEN_WIDTH + cursx, 196, length);
96 memset((uint8_t*)vram_attr + cursy * LIBCONIO_SCREEN_WIDTH + cursx, color, length);
97 cursx += length;
98}
99/*-----------------------------------------------------------------------------------*/
100void
101cvline(unsigned char length)
102{
103 int i;
104 for(i = 0; i < length; ++i) {
105 vram_attr[cursy][cursx] = color;
106 vram[cursy++][cursx] = 179;
107 }
108}
109/*-----------------------------------------------------------------------------------*/
110void
111gotoxy(unsigned char x, unsigned char y)
112{
113 cursx = x;
114 cursy = y;
115}
116/*-----------------------------------------------------------------------------------*/
117void
118cclearxy(unsigned char x, unsigned char y, unsigned char length)
119{
120 gotoxy(x, y);
121 cclear(length);
122}
123/*-----------------------------------------------------------------------------------*/
124void
125chlinexy(unsigned char x, unsigned char y, unsigned char length)
126{
127 gotoxy(x, y);
128 chline(length);
129}
130/*-----------------------------------------------------------------------------------*/
131void
132cvlinexy(unsigned char x, unsigned char y, unsigned char length)
133{
134 gotoxy(x, y);
135 cvline(length);
136}
137/*-----------------------------------------------------------------------------------*/
138void
139cputsxy(unsigned char x, unsigned char y, char *str)
140{
141 gotoxy(x, y);
142 cputs(str);
143}
144/*-----------------------------------------------------------------------------------*/
145void
146cputcxy(unsigned char x, unsigned char y, char c)
147{
148 gotoxy(x, y);
149 cputc(c);
150}
151/*-----------------------------------------------------------------------------------*/
152void
153textcolor(unsigned char c)
154{
155 color &= 16;
156 color |= c;
157}
158/*-----------------------------------------------------------------------------------*/
159void
160bgcolor(unsigned char c)
161{
162
163}
164/*-----------------------------------------------------------------------------------*/
165void
166bordercolor(unsigned char c)
167{
168
169}
170/*-----------------------------------------------------------------------------------*/
171void
172screensize(unsigned char *x, unsigned char *y)
173{
174 *x = LIBCONIO_SCREEN_WIDTH;
175 *y = LIBCONIO_SCREEN_HEIGHT;
176}
177/*-----------------------------------------------------------------------------------*/