blob: 63f1354ff21e5ac413abfcc785862ee5605e4779 [file] [log] [blame]
PulkoMandy612e2cf2021-09-20 23:00:40 +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 "Resource.h"
40
41static unsigned char cursx, cursy;
42static unsigned char color;
43
44unsigned int vram[2048];
45unsigned 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
51void 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;
PulkoMandybb8de5f2021-09-21 21:27:57 +020071 *PPU_BG1_CTRL = 0x08;
PulkoMandy612e2cf2021-09-20 23:00:40 +020072 *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
PulkoMandybb8de5f2021-09-21 21:27:57 +020079 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);
PulkoMandy612e2cf2021-09-20 23:00:40 +0200126
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/*-----------------------------------------------------------------------------------*/
142unsigned char
143wherex(void)
144{
145 return cursx;
146}
147/*-----------------------------------------------------------------------------------*/
148unsigned char
149wherey(void)
150{
151 return cursy;
152}
153/*-----------------------------------------------------------------------------------*/
154void
155clrscr(void)
156{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200157 memset(vram, 32, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT);
PulkoMandy612e2cf2021-09-20 23:00:40 +0200158 memset(vram_attr, 0, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT / 2);
159}
160/*-----------------------------------------------------------------------------------*/
161void
162revers(unsigned char c)
163{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200164 if (c != 0) color |= 8;
165 else color &= ~8;
PulkoMandy612e2cf2021-09-20 23:00:40 +0200166}
167/*-----------------------------------------------------------------------------------*/
168void
169cputc(char c)
170{
171 ctk_arch_draw_char(c, cursx, cursy, 0, color);
172 ++cursx;
173}
174/*-----------------------------------------------------------------------------------*/
175void
176cputs(char *str)
177{
178 int i;
179 for (i = 0; str[i]; i++) {
180 cputc(str[i]);
181 }
182}
183/*-----------------------------------------------------------------------------------*/
184void
185cclear(unsigned char length)
186{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200187 memset(vram + cursy * VRAM_WIDTH + cursx, 32, length);
188 memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), (color | color << 8), length >> 1);
PulkoMandy612e2cf2021-09-20 23:00:40 +0200189 cursx += length;
190}
191/*-----------------------------------------------------------------------------------*/
192void
193chline(unsigned char length)
194{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200195 memset(vram + cursy * VRAM_WIDTH + cursx, '-', length);
196 memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), (color |color << 8), length >> 1);
PulkoMandy612e2cf2021-09-20 23:00:40 +0200197 cursx += length;
198}
199/*-----------------------------------------------------------------------------------*/
200void
201cvline(unsigned char length)
202{
203 int i;
PulkoMandybb8de5f2021-09-21 21:27:57 +0200204 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 }
PulkoMandy612e2cf2021-09-20 23:00:40 +0200216 }
217}
218/*-----------------------------------------------------------------------------------*/
219void
220gotoxy(unsigned char x, unsigned char y)
221{
222 cursx = x;
223 cursy = y;
224}
225/*-----------------------------------------------------------------------------------*/
226void
227cclearxy(unsigned char x, unsigned char y, unsigned char length)
228{
229 gotoxy(x, y);
230 cclear(length);
231}
232/*-----------------------------------------------------------------------------------*/
233void
234chlinexy(unsigned char x, unsigned char y, unsigned char length)
235{
236 gotoxy(x, y);
237 chline(length);
238}
239/*-----------------------------------------------------------------------------------*/
240void
241cvlinexy(unsigned char x, unsigned char y, unsigned char length)
242{
243 gotoxy(x, y);
244 cvline(length);
245}
246/*-----------------------------------------------------------------------------------*/
247void
248cputsxy(unsigned char x, unsigned char y, char *str)
249{
250 gotoxy(x, y);
251 cputs(str);
252}
253/*-----------------------------------------------------------------------------------*/
254void
255cputcxy(unsigned char x, unsigned char y, char c)
256{
257 gotoxy(x, y);
258 cputc(c);
259}
260/*-----------------------------------------------------------------------------------*/
261void
262textcolor(unsigned char c)
263{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200264 color = c;
PulkoMandy612e2cf2021-09-20 23:00:40 +0200265}
266/*-----------------------------------------------------------------------------------*/
267void
268bgcolor(unsigned char c)
269{
270
271}
272/*-----------------------------------------------------------------------------------*/
273void
274bordercolor(unsigned char c)
275{
276
277}
278/*-----------------------------------------------------------------------------------*/
279void
280screensize(unsigned char *x, unsigned char *y)
281{
282 *x = LIBCONIO_SCREEN_WIDTH;
283 *y = LIBCONIO_SCREEN_HEIGHT;
284}
285/*-----------------------------------------------------------------------------------*/