blob: 07b8113c1592da9b727bc440cdc381907f0363a7 [file] [log] [blame]
adamdunkelsca9ddcb2003-03-19 14:13:31 +00001/*
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.
adamdunkels23e64ae2004-07-04 15:15:19 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000015 * 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 *
adamdunkelsa2f3c422004-09-12 20:24:53 +000032 * $Id: libconio.c,v 1.6 2004/09/12 20:24:55 adamdunkels Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000033 *
34 */
35
adamdunkelsa2f3c422004-09-12 20:24:53 +000036#include <string.h>
adamdunkelsca9ddcb2003-03-19 14:13:31 +000037#include "libconio.h"
38
39static unsigned char cursx, cursy;
40static unsigned char reversed;
adamdunkels92b84572003-08-09 13:35:43 +000041static unsigned char color;
adamdunkelsca9ddcb2003-03-19 14:13:31 +000042
43/*-----------------------------------------------------------------------------------*/
44unsigned char
45wherex(void)
46{
47 return cursx;
48}
49/*-----------------------------------------------------------------------------------*/
adamdunkels50d99c72003-04-02 18:50:17 +000050unsigned char
51wherey(void)
52{
53 return cursy;
54}
55/*-----------------------------------------------------------------------------------*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +000056void
57clrscr(void)
58{
59 unsigned char x, y;
60
61 for(x = 0; x < LIBCONIO_SCREEN_WIDTH; ++x) {
62 for(y = 0; y < LIBCONIO_SCREEN_HEIGHT; ++y) {
63 gotoxy(x, y);
64 cputc(' ');
65 }
66 }
67}
68/*-----------------------------------------------------------------------------------*/
69void
70revers(unsigned char c)
71{
72 reversed = c;
73}
74/*-----------------------------------------------------------------------------------*/
75void
76cputc(char c)
77{
adamdunkels92b84572003-08-09 13:35:43 +000078 ctk_arch_draw_char(c, cursx, cursy, reversed, color);
adamdunkelsca9ddcb2003-03-19 14:13:31 +000079 ++cursx;
80}
81/*-----------------------------------------------------------------------------------*/
82void
83cputs(char *str)
84{
adamdunkelsa2f3c422004-09-12 20:24:53 +000085 while(*str != 0) {
86 cputc(*str++);
87 }
88
89 /* int i;
adamdunkelsca9ddcb2003-03-19 14:13:31 +000090 for(i = 0; i < strlen(str); ++i) {
91 cputc(str[i]);
adamdunkelsa2f3c422004-09-12 20:24:53 +000092 }*/
adamdunkelsca9ddcb2003-03-19 14:13:31 +000093}
94/*-----------------------------------------------------------------------------------*/
95void
96cclear(unsigned char length)
97{
98 int i;
99 for(i = 0; i < length; ++i) {
100 cputc(' ');
101 }
102}
103/*-----------------------------------------------------------------------------------*/
104void
105chline(unsigned char length)
106{
107 int i;
108 for(i = 0; i < length; ++i) {
109 cputc('-');
110 }
111}
112/*-----------------------------------------------------------------------------------*/
113void
114cvline(unsigned char length)
115{
116 int i;
117 for(i = 0; i < length; ++i) {
adamdunkels92b84572003-08-09 13:35:43 +0000118 cputc('|');
119 --cursx;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000120 ++cursy;
121 }
122}
123/*-----------------------------------------------------------------------------------*/
124void
125gotoxy(unsigned char x, unsigned char y)
126{
127 cursx = x;
128 cursy = y;
129}
130/*-----------------------------------------------------------------------------------*/
131void
132cclearxy(unsigned char x, unsigned char y, unsigned char length)
133{
134 gotoxy(x, y);
135 cclear(length);
136}
137/*-----------------------------------------------------------------------------------*/
138void
139chlinexy(unsigned char x, unsigned char y, unsigned char length)
140{
141 gotoxy(x, y);
142 chline(length);
143}
144/*-----------------------------------------------------------------------------------*/
145void
146cvlinexy(unsigned char x, unsigned char y, unsigned char length)
147{
148 gotoxy(x, y);
149 cvline(length);
150}
151/*-----------------------------------------------------------------------------------*/
152void
153cputsxy(unsigned char x, unsigned char y, char *str)
154{
155 gotoxy(x, y);
156 cputs(str);
157}
158/*-----------------------------------------------------------------------------------*/
159void
160cputcxy(unsigned char x, unsigned char y, char c)
161{
162 gotoxy(x, y);
163 cputc(c);
164}
165/*-----------------------------------------------------------------------------------*/
166void
167textcolor(unsigned char c)
168{
adamdunkels92b84572003-08-09 13:35:43 +0000169 color = c;
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000170}
171/*-----------------------------------------------------------------------------------*/
adamdunkels50d99c72003-04-02 18:50:17 +0000172void
173bgcolor(unsigned char c)
174{
175
176}
177/*-----------------------------------------------------------------------------------*/
178void
179bordercolor(unsigned char c)
180{
181
182}
183/*-----------------------------------------------------------------------------------*/
184void
185screensize(unsigned char *x, unsigned char *y)
186{
adamdunkelscc088732003-04-15 21:22:35 +0000187 *x = LIBCONIO_SCREEN_WIDTH;
188 *y = LIBCONIO_SCREEN_HEIGHT;
adamdunkels50d99c72003-04-02 18:50:17 +0000189}
190/*-----------------------------------------------------------------------------------*/