PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +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 "Resource.h" |
| 40 | |
| 41 | static unsigned char cursx, cursy; |
| 42 | static unsigned char color; |
| 43 | |
| 44 | unsigned int vram[2048]; |
| 45 | unsigned int vram_attr[1024]; |
| 46 | |
| 47 | |
| 48 | #define make_color(r, g, b) ((r << 10) | (g << 5) | (b << 0)) |
| 49 | #define VRAM_WIDTH 64 |
| 50 | |
| 51 | void conio_init(void) |
| 52 | { |
| 53 | static volatile int* const PPU_BG1_SCROLL_X = 0x2810; |
| 54 | static volatile int* const PPU_BG1_SCROLL_Y = 0x2811; |
| 55 | static volatile int* const PPU_BG1_ATTR = 0x2812; |
| 56 | static volatile int* const PPU_BG1_CTRL = 0x2813; |
| 57 | static volatile int* const PPU_BG1_TILE_ADDR = 0x2814; |
| 58 | static volatile int* const PPU_BG1_ATTR_ADDR = 0x2815; |
| 59 | |
| 60 | static volatile int* const PPU_BG2_CTRL = 0x2819; |
| 61 | |
| 62 | static volatile int* const PPU_BG1_SEGMENT_ADDR = 0x2820; |
| 63 | |
| 64 | static volatile int* const PPU_SPRITE_CTRL = 0x2842; |
| 65 | static volatile int* const PPU_COLOR = 0x2B00; |
| 66 | int i; |
| 67 | |
| 68 | *PPU_BG1_SCROLL_X = 0; |
| 69 | *PPU_BG1_SCROLL_Y = 0; |
| 70 | *PPU_BG1_ATTR = 0; |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 71 | *PPU_BG1_CTRL = 0x08; |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 72 | *PPU_BG2_CTRL = 0; |
| 73 | *PPU_SPRITE_CTRL = 0; |
| 74 | |
| 75 | *PPU_BG1_TILE_ADDR = vram; |
| 76 | *PPU_BG1_ATTR_ADDR = vram_attr; |
| 77 | *PPU_BG1_SEGMENT_ADDR = RES_FONT_BIN_SA >> 6; |
| 78 | |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 79 | PPU_COLOR[0] = make_color(0, 0, 0); // Border, unused? |
| 80 | PPU_COLOR[1] = make_color(31, 31, 31); |
| 81 | |
| 82 | PPU_COLOR[16] = make_color(0, 0, 0); // Screen |
| 83 | PPU_COLOR[17] = make_color(18, 18, 31); |
| 84 | |
| 85 | PPU_COLOR[32] = make_color(0, 0, 0); // Windows, widgets, menu |
| 86 | PPU_COLOR[33] = make_color(15, 15, 15); |
| 87 | |
| 88 | PPU_COLOR[48] = make_color(0, 0, 0); // Open menu |
| 89 | PPU_COLOR[49] = make_color(31, 15, 15); |
| 90 | |
| 91 | PPU_COLOR[64] = make_color(0, 0, 0); // Active menu item |
| 92 | PPU_COLOR[65] = make_color(30, 30, 30); |
| 93 | |
| 94 | PPU_COLOR[80] = make_color(12, 12, 31); // Focused window/dialog |
| 95 | PPU_COLOR[81] = make_color(31, 31, 15); |
| 96 | |
| 97 | PPU_COLOR[96] = make_color(0, 0, 8); // Hyperlinks |
| 98 | PPU_COLOR[97] = make_color(24, 24, 31); |
| 99 | |
| 100 | PPU_COLOR[112] = make_color(12, 12, 12); // Focused widget |
| 101 | PPU_COLOR[113] = make_color(24, 24, 24); |
| 102 | |
| 103 | PPU_COLOR[129] = make_color(0, 0, 0); // Border, unused? |
| 104 | PPU_COLOR[128] = make_color(31, 31, 31); |
| 105 | |
| 106 | PPU_COLOR[129+16] = make_color(0, 0, 0); // Screen |
| 107 | PPU_COLOR[128+16] = make_color(18, 18, 31); |
| 108 | |
| 109 | PPU_COLOR[129+32] = make_color(0, 0, 0); // Windows, widgets, menu |
| 110 | PPU_COLOR[128+32] = make_color(15, 15, 15); |
| 111 | |
| 112 | PPU_COLOR[129+48] = make_color(0, 0, 0); // Open menu |
| 113 | PPU_COLOR[128+48] = make_color(31, 15, 15); |
| 114 | |
| 115 | PPU_COLOR[129+64] = make_color(0, 0, 0); // Active menu item |
| 116 | PPU_COLOR[128+64] = make_color(30, 30, 30); |
| 117 | |
| 118 | PPU_COLOR[129+80] = make_color(12, 12, 31); // Focused window/dialog |
| 119 | PPU_COLOR[128+80] = make_color(31, 31, 15); |
| 120 | |
| 121 | PPU_COLOR[129+96] = make_color(0, 0, 8); // Hyperlinks |
| 122 | PPU_COLOR[128+96] = make_color(24, 24, 31); |
| 123 | |
| 124 | PPU_COLOR[129+112] = make_color(12, 12, 12); // Focused widget |
| 125 | PPU_COLOR[128+112] = make_color(24, 24, 24); |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 126 | |
| 127 | PPU_COLOR[0] = make_color(0, 0, 0); // Border |
| 128 | PPU_COLOR[1] = make_color(18, 18, 31); // Screen |
| 129 | PPU_COLOR[3] = make_color(31, 31, 31); // Menu |
| 130 | PPU_COLOR[4] = make_color(31, 15, 15); // Active menu item |
| 131 | PPU_COLOR[5] = make_color(30, 30, 30); // Dialogs |
| 132 | PPU_COLOR[6] = make_color(12, 12, 31); // Hyperlinks |
| 133 | PPU_COLOR[7] = make_color(24, 24, 31); // Moving window |
| 134 | PPU_COLOR[8] = make_color(24, 24, 24); // Inactive window |
| 135 | |
| 136 | PPU_COLOR[2+16] = make_color(31, 31, 31); |
| 137 | PPU_COLOR[6+16] = make_color(0, 0, 31); |
| 138 | PPU_COLOR[7+16] = make_color(31, 0, 31); |
| 139 | } |
| 140 | |
| 141 | /*-----------------------------------------------------------------------------------*/ |
| 142 | unsigned char |
| 143 | wherex(void) |
| 144 | { |
| 145 | return cursx; |
| 146 | } |
| 147 | /*-----------------------------------------------------------------------------------*/ |
| 148 | unsigned char |
| 149 | wherey(void) |
| 150 | { |
| 151 | return cursy; |
| 152 | } |
| 153 | /*-----------------------------------------------------------------------------------*/ |
| 154 | void |
| 155 | clrscr(void) |
| 156 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 157 | memset(vram, 32, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT); |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 158 | memset(vram_attr, 0, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT / 2); |
| 159 | } |
| 160 | /*-----------------------------------------------------------------------------------*/ |
| 161 | void |
| 162 | revers(unsigned char c) |
| 163 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 164 | if (c != 0) color |= 8; |
| 165 | else color &= ~8; |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 166 | } |
| 167 | /*-----------------------------------------------------------------------------------*/ |
| 168 | void |
| 169 | cputc(char c) |
| 170 | { |
| 171 | ctk_arch_draw_char(c, cursx, cursy, 0, color); |
| 172 | ++cursx; |
| 173 | } |
| 174 | /*-----------------------------------------------------------------------------------*/ |
| 175 | void |
| 176 | cputs(char *str) |
| 177 | { |
| 178 | int i; |
| 179 | for (i = 0; str[i]; i++) { |
| 180 | cputc(str[i]); |
| 181 | } |
| 182 | } |
| 183 | /*-----------------------------------------------------------------------------------*/ |
| 184 | void |
| 185 | cclear(unsigned char length) |
| 186 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 187 | memset(vram + cursy * VRAM_WIDTH + cursx, 32, length); |
| 188 | memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), (color | color << 8), length >> 1); |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 189 | cursx += length; |
| 190 | } |
| 191 | /*-----------------------------------------------------------------------------------*/ |
| 192 | void |
| 193 | chline(unsigned char length) |
| 194 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 195 | memset(vram + cursy * VRAM_WIDTH + cursx, '-', length); |
| 196 | memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), (color |color << 8), length >> 1); |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 197 | cursx += length; |
| 198 | } |
| 199 | /*-----------------------------------------------------------------------------------*/ |
| 200 | void |
| 201 | cvline(unsigned char length) |
| 202 | { |
| 203 | int i; |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 204 | if (cursx & 1) { |
| 205 | for(i = 0; i < length; ++i) { |
| 206 | vram_attr[(cursy * VRAM_WIDTH + cursx) >> 1] &= 0xff; |
| 207 | vram_attr[(cursy * VRAM_WIDTH + cursx) >> 1] |= color << 8; |
| 208 | vram[cursy++ * VRAM_WIDTH + cursx] = '|'; |
| 209 | } |
| 210 | } else { |
| 211 | for(i = 0; i < length; ++i) { |
| 212 | vram_attr[(cursy * VRAM_WIDTH + cursx) >> 1] &= 0xff00; |
| 213 | vram_attr[(cursy * VRAM_WIDTH + cursx) >> 1] |= color; |
| 214 | vram[cursy++ * VRAM_WIDTH + cursx] = '|'; |
| 215 | } |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | /*-----------------------------------------------------------------------------------*/ |
| 219 | void |
| 220 | gotoxy(unsigned char x, unsigned char y) |
| 221 | { |
| 222 | cursx = x; |
| 223 | cursy = y; |
| 224 | } |
| 225 | /*-----------------------------------------------------------------------------------*/ |
| 226 | void |
| 227 | cclearxy(unsigned char x, unsigned char y, unsigned char length) |
| 228 | { |
| 229 | gotoxy(x, y); |
| 230 | cclear(length); |
| 231 | } |
| 232 | /*-----------------------------------------------------------------------------------*/ |
| 233 | void |
| 234 | chlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 235 | { |
| 236 | gotoxy(x, y); |
| 237 | chline(length); |
| 238 | } |
| 239 | /*-----------------------------------------------------------------------------------*/ |
| 240 | void |
| 241 | cvlinexy(unsigned char x, unsigned char y, unsigned char length) |
| 242 | { |
| 243 | gotoxy(x, y); |
| 244 | cvline(length); |
| 245 | } |
| 246 | /*-----------------------------------------------------------------------------------*/ |
| 247 | void |
| 248 | cputsxy(unsigned char x, unsigned char y, char *str) |
| 249 | { |
| 250 | gotoxy(x, y); |
| 251 | cputs(str); |
| 252 | } |
| 253 | /*-----------------------------------------------------------------------------------*/ |
| 254 | void |
| 255 | cputcxy(unsigned char x, unsigned char y, char c) |
| 256 | { |
| 257 | gotoxy(x, y); |
| 258 | cputc(c); |
| 259 | } |
| 260 | /*-----------------------------------------------------------------------------------*/ |
| 261 | void |
| 262 | textcolor(unsigned char c) |
| 263 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame^] | 264 | color = c; |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 265 | } |
| 266 | /*-----------------------------------------------------------------------------------*/ |
| 267 | void |
| 268 | bgcolor(unsigned char c) |
| 269 | { |
| 270 | |
| 271 | } |
| 272 | /*-----------------------------------------------------------------------------------*/ |
| 273 | void |
| 274 | bordercolor(unsigned char c) |
| 275 | { |
| 276 | |
| 277 | } |
| 278 | /*-----------------------------------------------------------------------------------*/ |
| 279 | void |
| 280 | screensize(unsigned char *x, unsigned char *y) |
| 281 | { |
| 282 | *x = LIBCONIO_SCREEN_WIDTH; |
| 283 | *y = LIBCONIO_SCREEN_HEIGHT; |
| 284 | } |
| 285 | /*-----------------------------------------------------------------------------------*/ |