4
4
#include <avr/pgmspace.h>
5
5
#include <uzebox.h>
6
6
7
+ #include <stdio.h>
8
+
7
9
/* EXAMPLES
8
10
* 0: just for miscellaneous debugging code
9
11
* 1: show ASCII with 12 different palettes
10
12
* 2: show color values
11
13
* 3: scramble VRAM
12
14
* 4: fake terminal output (TODO, NYI)
13
15
*/
14
- #define EXAMPLE 1
16
+ #define EXAMPLE 4
15
17
16
18
ColorCombo m96_palette [16 ] = {
19
+ #if EXAMPLE >= 0 && EXAMPLE < 4
17
20
{ 0xc0 , 0x15 }, // blue on orange
18
21
{ 0x02 , 0x10 }, // red on green
19
22
{ 0x83 , 0x36 }, // violet on yellow
@@ -28,6 +31,27 @@ ColorCombo m96_palette[16] = {
28
31
{ 0xa7 , 0xfd },
29
32
{ 0x39 , 0x05 },
30
33
{ 0xff , 0x00 },
34
+
35
+ #elif EXAMPLE == 4
36
+ // an imitation of ANSI color codes on a VGA display
37
+ { 0x00 , 0x52 }, // low-intensity
38
+ { 0x05 , 0x00 },
39
+ { 0x28 , 0x00 },
40
+ { 0x15 , 0x00 },
41
+ { 0x80 , 0x00 },
42
+ { 0x85 , 0x00 },
43
+ { 0xa8 , 0x00 },
44
+ { 0xad , 0x00 },
45
+
46
+ { 0x52 , 0x00 }, // high-intensity
47
+ { 0x57 , 0x00 },
48
+ { 0x7a , 0x00 },
49
+ { 0x7f , 0x00 },
50
+ { 0xd2 , 0x00 },
51
+ { 0xd7 , 0x00 },
52
+ { 0xfa , 0x00 },
53
+ { 0xff , 0x00 },
54
+ #endif
31
55
};
32
56
33
57
typedef struct {
@@ -45,12 +69,14 @@ void button_update() {
45
69
_btn .prev = _btn .down ;
46
70
}
47
71
72
+ #if EXAMPLE < 4
48
73
static void palette_randomize () {
49
74
for (u8 i = 0 ; i < 16 ; i ++ ) {
50
75
m96_palette [i ].fg = GetPrngNumber (0 );
51
76
m96_palette [i ].bg = GetPrngNumber (0 );
52
77
}
53
78
}
79
+ #endif
54
80
55
81
#if EXAMPLE == 2
56
82
static void palette_display () {
@@ -141,6 +167,37 @@ int main() {
141
167
}
142
168
}
143
169
170
+ #elif EXAMPLE == 4
171
+ Print (8 , 0 , PSTR ("ANSI VGA simulation" ));
172
+ Print (0 , 2 , PSTR ("normal" ));
173
+ Print (18 , 2 , PSTR ("bright" ));
174
+
175
+ for (u8 i = 0 ; i < SCREEN_TILES_H ; i ++ )
176
+ for (u8 j = 0 ; j < SCREEN_TILES_V ; j ++ )
177
+ SetTileColor (i , j , 7 );
178
+
179
+ u8 x = 0 ;
180
+ u8 line = 3 ;
181
+ char buf [18 ];
182
+ for (u8 color = 0 ; color < 16 ; color ++ ) {
183
+ snprintf_P (buf , sizeof (buf ), PSTR ("%2d: color %2d: %02X" ),
184
+ color + (color > 7 ? 82 : 30 ), color ,
185
+ m96_palette [color ].fg );
186
+
187
+ PrintRam (x , line , (unsigned char * )buf );
188
+ for (u8 i = 0 ; i < sizeof (buf ); i ++ )
189
+ SetTileColor (x + i , line , color );
190
+
191
+ line ++ ;
192
+ if (color == 7 ) {
193
+ x = 18 ;
194
+ line = 3 ;
195
+ }
196
+ }
197
+
198
+ while (true)
199
+ WaitVsync (1 );
200
+
144
201
#else
145
202
#error Unknown example
146
203
#endif
0 commit comments