blob: 938cb62af769c75fe1722c603d25bcf3df24b797 [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;
71 *PPU_BG1_CTRL = 0x0a; // TODO 0x08 so that vram_attr is actually used for something. Once we can figure out how it works. There will be only 4 possible "colors" this way...
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
79 for (i = 0; i < 255; i++)
80 PPU_COLOR[i] = i;
81
82 PPU_COLOR[0] = make_color(0, 0, 0); // Border
83 PPU_COLOR[1] = make_color(18, 18, 31); // Screen
84 PPU_COLOR[3] = make_color(31, 31, 31); // Menu
85 PPU_COLOR[4] = make_color(31, 15, 15); // Active menu item
86 PPU_COLOR[5] = make_color(30, 30, 30); // Dialogs
87 PPU_COLOR[6] = make_color(12, 12, 31); // Hyperlinks
88 PPU_COLOR[7] = make_color(24, 24, 31); // Moving window
89 PPU_COLOR[8] = make_color(24, 24, 24); // Inactive window
90
91 PPU_COLOR[2+16] = make_color(31, 31, 31);
92 PPU_COLOR[6+16] = make_color(0, 0, 31);
93 PPU_COLOR[7+16] = make_color(31, 0, 31);
94}
95
96/*-----------------------------------------------------------------------------------*/
97unsigned char
98wherex(void)
99{
100 return cursx;
101}
102/*-----------------------------------------------------------------------------------*/
103unsigned char
104wherey(void)
105{
106 return cursy;
107}
108/*-----------------------------------------------------------------------------------*/
109void
110clrscr(void)
111{
112 memset(vram, 0, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT);
113 memset(vram_attr, 0, VRAM_WIDTH * LIBCONIO_SCREEN_HEIGHT / 2);
114}
115/*-----------------------------------------------------------------------------------*/
116void
117revers(unsigned char c)
118{
119 if (c != 0) color |= 16;
120 else color &= ~16;
121}
122/*-----------------------------------------------------------------------------------*/
123void
124cputc(char c)
125{
126 ctk_arch_draw_char(c, cursx, cursy, 0, color);
127 ++cursx;
128}
129/*-----------------------------------------------------------------------------------*/
130void
131cputs(char *str)
132{
133 int i;
134 for (i = 0; str[i]; i++) {
135 cputc(str[i]);
136 }
137}
138/*-----------------------------------------------------------------------------------*/
139void
140cclear(unsigned char length)
141{
142 memset(vram + cursy * VRAM_WIDTH + cursx, 0, length);
143 memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), color, length >> 1);
144 cursx += length;
145}
146/*-----------------------------------------------------------------------------------*/
147void
148chline(unsigned char length)
149{
150 memset(vram + cursy * VRAM_WIDTH + cursx, 196, length);
151 memset(vram_attr + ((cursy * VRAM_WIDTH + cursx) >> 1), color, length >> 1);
152 cursx += length;
153}
154/*-----------------------------------------------------------------------------------*/
155void
156cvline(unsigned char length)
157{
158 int i;
159 for(i = 0; i < length; ++i) {
160 vram_attr[(cursy * VRAM_WIDTH + cursx) >> 1] = color;
161 vram[cursy++ * VRAM_WIDTH + cursx] = 179;
162 }
163}
164/*-----------------------------------------------------------------------------------*/
165void
166gotoxy(unsigned char x, unsigned char y)
167{
168 cursx = x;
169 cursy = y;
170}
171/*-----------------------------------------------------------------------------------*/
172void
173cclearxy(unsigned char x, unsigned char y, unsigned char length)
174{
175 gotoxy(x, y);
176 cclear(length);
177}
178/*-----------------------------------------------------------------------------------*/
179void
180chlinexy(unsigned char x, unsigned char y, unsigned char length)
181{
182 gotoxy(x, y);
183 chline(length);
184}
185/*-----------------------------------------------------------------------------------*/
186void
187cvlinexy(unsigned char x, unsigned char y, unsigned char length)
188{
189 gotoxy(x, y);
190 cvline(length);
191}
192/*-----------------------------------------------------------------------------------*/
193void
194cputsxy(unsigned char x, unsigned char y, char *str)
195{
196 gotoxy(x, y);
197 cputs(str);
198}
199/*-----------------------------------------------------------------------------------*/
200void
201cputcxy(unsigned char x, unsigned char y, char c)
202{
203 gotoxy(x, y);
204 cputc(c);
205}
206/*-----------------------------------------------------------------------------------*/
207void
208textcolor(unsigned char c)
209{
210 color &= 16;
211 color |= c;
212}
213/*-----------------------------------------------------------------------------------*/
214void
215bgcolor(unsigned char c)
216{
217
218}
219/*-----------------------------------------------------------------------------------*/
220void
221bordercolor(unsigned char c)
222{
223
224}
225/*-----------------------------------------------------------------------------------*/
226void
227screensize(unsigned char *x, unsigned char *y)
228{
229 *x = LIBCONIO_SCREEN_WIDTH;
230 *y = LIBCONIO_SCREEN_HEIGHT;
231}
232/*-----------------------------------------------------------------------------------*/