Skip to content

Commit 4aa38e4

Browse files
committed
Added color versions of all uzebox Print functions
1 parent a12d8c2 commit 4aa38e4

File tree

5 files changed

+131
-18
lines changed

5 files changed

+131
-18
lines changed

NOTES.MD

-13
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,6 @@ scratch or locals:
223223

224224
# colors
225225

226-
TODO: come up with good color values simulating the 8 terminal ANSI colors:
227-
228-
| num | color | hex |
229-
|-----+---------+-----|
230-
| 0 | black | 00 |
231-
| 1 | red | |
232-
| 2 | green | |
233-
| 3 | yellow | |
234-
| 4 | blue | |
235-
| 5 | magenta | |
236-
| 6 | cyan | |
237-
| 7 | white | ff |
238-
239226
Looking at the ANSI VGA RGB values:
240227

241228
255 -> 7 for 3-bit, 3 for 2-bit

library.s

+26-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "common.def.h"
44

55
;;; TODO:
6-
;;; * add all the usual Print functions, but that take color options
76
;;; * for SetTile/GetTile*, do bounds checking?
87

98
.global ClearVram
@@ -12,8 +11,9 @@
1211
.global SetTileColor
1312
.global GetTileColor
1413
.global SetTileBoth
15-
1614
.global SetFont
15+
.global FillColor
16+
1717
.global SetTileTable
1818
.global InitializeVideoMode
1919
.global DisplayLogo
@@ -39,6 +39,30 @@ ClearVram:
3939

4040
ret
4141

42+
;;; ========================================
43+
;;; FillColor
44+
;;; r24: X pos (8-bit)
45+
;;; r22: Y pos (8-bit)
46+
;;; r20: number of cells to set the color of (8-bit)
47+
;;; r18: color palette index (4-bit)
48+
FillColor:
49+
push r16
50+
51+
mov r16, r20
52+
movw r20, r18
53+
54+
0:
55+
rcall SetTileColor
56+
inc r24
57+
dec r16
58+
brne 0b
59+
60+
pop r16
61+
ret
62+
63+
;;; ================================================================================
64+
;;; Tile getter and setter functions
65+
4266
;;; ========================================
4367
;;; get_tile_addr_text
4468
;;; A helper function, not intended for use outside this library

main.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* 3: scramble VRAM
1414
* 4: fake terminal output (TODO, NYI)
1515
*/
16-
#define EXAMPLE 4
16+
#define EXAMPLE 0
1717

1818
ColorCombo m96_palette[16] = {
1919
#if EXAMPLE >= 0 && EXAMPLE < 4
@@ -69,7 +69,7 @@ void button_update() {
6969
_btn.prev = _btn.down;
7070
}
7171

72-
#if EXAMPLE < 4
72+
#if EXAMPLE > 0 && EXAMPLE < 4
7373
static void palette_randomize() {
7474
for (u8 i = 0; i < 16; i++) {
7575
m96_palette[i].fg = GetPrngNumber(0);
@@ -115,7 +115,29 @@ int main() {
115115
SetTile(SCREEN_TILES_H-1, SCREEN_TILES_V-1, '2'-32);
116116
SetTile(0, SCREEN_TILES_V-1, '3'-32);
117117

118-
Print(4, 0, PSTR("foo bar baz"));
118+
PrintColor(32, 2, PSTR("hurg nurg wurg"), 1);
119+
120+
u8 x = 10;
121+
u8 line = 4;
122+
PrintRamColor(x, line++, "foo bar baz", 1);
123+
PrintBinaryByteColor(x, line++, 0x7f, 1);
124+
PrintHexByteColor(x, line++, 0x7f, 1);
125+
PrintHexIntColor(x, line++, 0x03f2, 1);
126+
PrintHexLongColor(x, line++, 0xdeadbeef, 1);
127+
PrintHexLongColor(x, line++, 0x0000beef, 1);
128+
129+
PrintLongColor(x, line++, 0xdeadbeef, 1);
130+
PrintLongColor(x, line++, 0x00adbeef, 1);
131+
132+
PrintByteColor(x, line++, 0x7f, false, 1);
133+
PrintByteColor(x, line++, 0x7f, true, 1);
134+
135+
PrintIntColor(x, line++, 5234, false, 1);
136+
PrintIntColor(x, line++, 65234, false, 1);
137+
PrintIntColor(x, line++, 5234, true, 1);
138+
PrintIntColor(x, line++, 65234, true, 1);
139+
140+
PrintCharColor(x, line++, 'A', 1);
119141

120142
while (true)
121143
WaitVsync(1);

print_functions.c

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <uzebox.h>
2+
#include <avr/pgmspace.h>
3+
#include <string.h>
4+
5+
#include "video.h"
6+
7+
static u8 ilen(unsigned long val) {
8+
u8 ret = 0;
9+
while (val) {
10+
val /= 10;
11+
ret++;
12+
}
13+
return ret;
14+
}
15+
16+
void PrintColor(int x,int y,const char *string,int color) {
17+
Print(x, y, string);
18+
FillColor(x, y, strlen_P(string), color);
19+
}
20+
21+
void PrintRamColor(int x,int y,char *string,int color) {
22+
PrintRam(x, y, (unsigned char*)string);
23+
FillColor(x, y, strlen(string), color);
24+
}
25+
26+
void PrintBinaryByteColor(char x,char y,unsigned char byte,int color) {
27+
PrintBinaryByte(x, y, byte);
28+
FillColor(x, y, 8, color);
29+
}
30+
31+
void PrintHexByteColor(char x,char y,unsigned char byte,int color) {
32+
PrintHexByte(x, y, byte);
33+
FillColor(x, y, 2, color);
34+
}
35+
36+
void PrintHexIntColor(char x,char y,int byte,int color) {
37+
PrintHexInt(x, y, byte);
38+
FillColor(x, y, 4, color);
39+
}
40+
41+
void PrintHexLongColor(char x,char y, uint32_t value,int color) {
42+
PrintHexLong(x, y, value);
43+
FillColor(x, y, 8, color);
44+
}
45+
46+
void PrintLongColor(int x,int y, unsigned long val,int color) {
47+
PrintLong(x, y, val);
48+
u8 l = ilen(val);
49+
FillColor(x-l+1, y, l, color);
50+
}
51+
52+
void PrintByteColor(int x,int y, unsigned char val,bool zeropad,int color) {
53+
PrintByte(x, y, val, zeropad);
54+
u8 l = ilen(val);
55+
FillColor(x-l+1, y, l, color);
56+
}
57+
58+
void PrintCharColor(int x,int y,char c,int color) {
59+
PrintChar(x, y, c);
60+
SetTileColor(x, y, color);
61+
}
62+
63+
void PrintIntColor(int x,int y, unsigned int i,bool zeropad,int color) {
64+
PrintInt(x, y, i, zeropad);
65+
u8 l = zeropad ? 5 : ilen(i);
66+
FillColor(x-l+1, y, l, color);
67+
}

video.h

+13
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@ extern void SetTileColor(u8 x, u8 y, u8 index);
1212
extern u8 GetTileColor(u8 x, u8 y);
1313
extern void SetTileBoth(u8 x, u8 y, u8 tile, u8 index);
1414

15+
extern void FillColor(u8 x, u8 y, u8 length, u8 index);
16+
17+
void PrintColor(int x,int y,const char *string,int color);
18+
void PrintRamColor(int x,int y,char *string,int color);
19+
void PrintBinaryByteColor(char x,char y,unsigned char byte,int color);
20+
void PrintHexByteColor(char x,char y,unsigned char byte,int color);
21+
void PrintHexIntColor(char x,char y,int byte,int color);
22+
void PrintHexLongColor(char x,char y, uint32_t value,int color);
23+
void PrintLongColor(int x,int y, unsigned long val,int color);
24+
void PrintByteColor(int x,int y, unsigned char val,bool zeropad,int color);
25+
void PrintCharColor(int x,int y,char c,int color);
26+
void PrintIntColor(int x,int y, unsigned int,bool zeropad,int color);
27+
1528
#endif

0 commit comments

Comments
 (0)