Adrien Destugues | 69b1f06 | 2017-06-05 13:44:30 +0200 | [diff] [blame^] | 1 | /* |
| 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 | |
| 41 | static unsigned char cursx, cursy; |
| 42 | static unsigned char color; |
| 43 | |
| 44 | /*-----------------------------------------------------------------------------------*/ |
| 45 | unsigned char |
| 46 | wherex(void) |
| 47 | { |
| 48 | return cursx; |
| 49 | } |
| 50 | /*-----------------------------------------------------------------------------------*/ |
| 51 | unsigned char |
| 52 | wherey(void) |
| 53 | { |
| 54 | return cursy; |
| 55 | } |
| 56 | /*-----------------------------------------------------------------------------------*/ |
| 57 | void |
| 58 | clrscr(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 | /*-----------------------------------------------------------------------------------*/ |
| 64 | void |
| 65 | revers(unsigned char c) |
| 66 | { |
| 67 | if (c != 0) color |= 16; |
| 68 | else color &= ~16; |
| 69 | } |
| 70 | /*-----------------------------------------------------------------------------------*/ |
| 71 | void |
| 72 | cputc(char c) |
| 73 | { |
| 74 | ctk_arch_draw_char(c, cursx, cursy, 0, color); |
| 75 | ++cursx; |
| 76 | } |
| 77 | /*-----------------------------------------------------------------------------------*/ |
| 78 | void |
| 79 | cputs(char *str) |
| 80 | { |
| 81 | cursx += print_at(cursx, cursy, color, str); |
| 82 | } |
| 83 | /*-----------------------------------------------------------------------------------*/ |
| 84 | void |
| 85 | cclear(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 | /*-----------------------------------------------------------------------------------*/ |
| 92 | void |
| 93 | chline(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 | /*-----------------------------------------------------------------------------------*/ |
| 100 | void |
| 101 | cvline(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 | /*-----------------------------------------------------------------------------------*/ |
| 110 | void |
| 111 | gotoxy(unsigned char x, unsigned char y) |
| 112 | { |
| 113 | cursx = x; |
| 114 | cursy = y; |
| 115 | } |
| 116 | /*-----------------------------------------------------------------------------------*/ |
| 117 | void |
| 118 | cclearxy(unsigned char x, unsigned char y, unsigned char length) |
| 119 | { |
| 120 | gotoxy(x, y); |
| 121 | cclear(length); |
| 122 | } |
| 123 | /*-----------------------------------------------------------------------------------*/ |
| 124 | void |
| 125 | chlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 126 | { |
| 127 | gotoxy(x, y); |
| 128 | chline(length); |
| 129 | } |
| 130 | /*-----------------------------------------------------------------------------------*/ |
| 131 | void |
| 132 | cvlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 133 | { |
| 134 | gotoxy(x, y); |
| 135 | cvline(length); |
| 136 | } |
| 137 | /*-----------------------------------------------------------------------------------*/ |
| 138 | void |
| 139 | cputsxy(unsigned char x, unsigned char y, char *str) |
| 140 | { |
| 141 | gotoxy(x, y); |
| 142 | cputs(str); |
| 143 | } |
| 144 | /*-----------------------------------------------------------------------------------*/ |
| 145 | void |
| 146 | cputcxy(unsigned char x, unsigned char y, char c) |
| 147 | { |
| 148 | gotoxy(x, y); |
| 149 | cputc(c); |
| 150 | } |
| 151 | /*-----------------------------------------------------------------------------------*/ |
| 152 | void |
| 153 | textcolor(unsigned char c) |
| 154 | { |
| 155 | color &= 16; |
| 156 | color |= c; |
| 157 | } |
| 158 | /*-----------------------------------------------------------------------------------*/ |
| 159 | void |
| 160 | bgcolor(unsigned char c) |
| 161 | { |
| 162 | |
| 163 | } |
| 164 | /*-----------------------------------------------------------------------------------*/ |
| 165 | void |
| 166 | bordercolor(unsigned char c) |
| 167 | { |
| 168 | |
| 169 | } |
| 170 | /*-----------------------------------------------------------------------------------*/ |
| 171 | void |
| 172 | screensize(unsigned char *x, unsigned char *y) |
| 173 | { |
| 174 | *x = LIBCONIO_SCREEN_WIDTH; |
| 175 | *y = LIBCONIO_SCREEN_HEIGHT; |
| 176 | } |
| 177 | /*-----------------------------------------------------------------------------------*/ |