Skip to content

Commit a12d8c2

Browse files
committed
Added VGA color example
1 parent baafb2e commit a12d8c2

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

NOTES.MD

+29
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ TODO: come up with good color values simulating the 8 terminal ANSI colors:
236236
| 6 | cyan | |
237237
| 7 | white | ff |
238238

239+
Looking at the ANSI VGA RGB values:
240+
241+
255 -> 7 for 3-bit, 3 for 2-bit
242+
170 -> 5 for 3-bit, 2 for 2-bit
243+
85 -> 2 for 3-bit, 1 for 2-bit
244+
0 -> 0 for 3-bit, 0 for 2-bit
245+
246+
low-intensity:
247+
0: 0, 0, 0: 00 000 000: 00
248+
1: 170, 0, 0: 00 000 101: 05
249+
2: 0, 170, 0: 00 101 000: 28
250+
3: 170, 85, 0: 00 010 101: 15
251+
4: 0, 0, 170: 10 000 000: 80
252+
5: 170, 0, 170: 10 000 101: 85
253+
6: 0, 170, 170: 10 101 000: a8
254+
7: 170, 170, 170: 10 101 101: ad
255+
256+
high-intensity:
257+
0: 85, 85, 85: 01 010 010: 52
258+
1: 255, 85, 85: 01 010 111: 57
259+
2: 85, 255, 85: 01 111 010: 7a
260+
3: 255, 255, 85: 01 111 111: 7f
261+
4: 85, 85, 255: 11 010 010: d2
262+
5: 255, 85, 255: 11 010 111: d7
263+
6: 85, 255, 255: 11 111 010: fa
264+
7: 255, 255, 255: 11 111 111: ff
265+
266+
## older colors I had
267+
239268
colors: B- G-- R--
240269
grey: 01 010 010: 0x52
241270
blue: 11 000 000: 0xc0

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# mode96
2+
23
A video driver for the Uzebox.
34

45
This is a codetile-based 36x28 video mode that can support up to 256 different 1bpp tiles, where
@@ -17,4 +18,8 @@ ASCII tileset (96 tiles), displayed with 12 of 16 possible different palettes:
1718

1819
Scrambled VRAM, showing characters with 16 different palettes:
1920

20-
![example 3](https://imgur.com/MB2Hu8H.png)
21+
![example 3](https://imgur.com/HkS2Qxu.png)
22+
23+
A simulation of basic VGA colors from ANSI escape codes:
24+
25+
![example 4](https://imgur.com/ChugAQ6.png)

main.c

+58-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
#include <avr/pgmspace.h>
55
#include <uzebox.h>
66

7+
#include <stdio.h>
8+
79
/* EXAMPLES
810
* 0: just for miscellaneous debugging code
911
* 1: show ASCII with 12 different palettes
1012
* 2: show color values
1113
* 3: scramble VRAM
1214
* 4: fake terminal output (TODO, NYI)
1315
*/
14-
#define EXAMPLE 1
16+
#define EXAMPLE 4
1517

1618
ColorCombo m96_palette[16] = {
19+
#if EXAMPLE >= 0 && EXAMPLE < 4
1720
{ 0xc0, 0x15 }, // blue on orange
1821
{ 0x02, 0x10 }, // red on green
1922
{ 0x83, 0x36 }, // violet on yellow
@@ -28,6 +31,27 @@ ColorCombo m96_palette[16] = {
2831
{ 0xa7, 0xfd },
2932
{ 0x39, 0x05 },
3033
{ 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
3155
};
3256

3357
typedef struct {
@@ -45,12 +69,14 @@ void button_update() {
4569
_btn.prev = _btn.down;
4670
}
4771

72+
#if EXAMPLE < 4
4873
static void palette_randomize() {
4974
for (u8 i = 0; i < 16; i++) {
5075
m96_palette[i].fg = GetPrngNumber(0);
5176
m96_palette[i].bg = GetPrngNumber(0);
5277
}
5378
}
79+
#endif
5480

5581
#if EXAMPLE == 2
5682
static void palette_display() {
@@ -141,6 +167,37 @@ int main() {
141167
}
142168
}
143169

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+
144201
#else
145202
#error Unknown example
146203
#endif

0 commit comments

Comments
 (0)