ReflexBall Rally
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Macros
ansi.c
Go to the documentation of this file.
1
#include <eZ8.h>
// special encore constants, macros and flash routines
2
#include <sio.h>
// special encore serial i/o routines
3
#include "
ansi.h
"
4
5
void
fgcolor
(
unsigned
char
foreground) {
6
/* Value foreground Value foreground
7
------------------------------------------------
8
0 Black 8 Dark Gray
9
1 Red 9 Light Red
10
2 Green 10 Light Green
11
3 Brown 11 Yellow
12
4 Blue 12 Light Blue
13
5 Purple 13 Light Purple
14
6 Cyan 14 Light Cyan
15
7 Light Gray 15 White
16
*/
17
int
type = 22;
// normal text
18
if
(foreground > 7) {
19
type = 1;
// bold text
20
foreground -= 8;
21
}
22
printf(
"%c[%d;%dm"
,
ESC
, type, foreground+30);
23
}
24
25
void
bgcolor
(
unsigned
char
background) {
26
/* IMPORTANT: When you first use this function you cannot get back to true white background in HyperTerminal.
27
Why is that? Because ANSI does not support true white background (ANSI white is gray to most human eyes).
28
The designers of HyperTerminal, however, preferred black text on white background, which is why
29
the colors are initially like that, but when the background color is first changed there is no
30
way comming back.
31
Hint: Use resetbgcolor(); clrscr(); to force HyperTerminal into gray text on black background.
32
33
Value Color
34
------------------
35
0 Black
36
1 Red
37
2 Green
38
3 Brown
39
4 Blue
40
5 Purple
41
6 Cyan
42
7 Gray
43
*/
44
printf(
"%c[%dm"
,
ESC
, background+40);
45
}
46
47
void
color
(
unsigned
char
foreground,
unsigned
char
background) {
// Combination of fgcolor() and bgcolor() - uses less bandwidth
48
int
type = 22;
// Normal text
49
if
(foreground > 7) {
50
type = 1;
// Bold text
51
foreground -= 8;
52
}
53
printf(
"%c[%d;%d;%dm"
,
ESC
, type, foreground+30, background+40);
54
}
55
56
void
resetbgcolor
() {
// Reset background color
57
printf(
"%c[m"
,
ESC
);
// Gray on black text, no underline, no blink, no reverse
58
}
59
60
void
clrscr
() {
// Clear screen
61
printf(
"%c[2J"
,
ESC
);
62
}
63
64
void
clreol
() {
// Clear line
65
printf(
"%c[K"
,
ESC
);
66
}
67
68
void
gotoxy
(
unsigned
char
x,
unsigned
char
y) {
// Move the marker to the (x,y)-coordinate
69
printf(
"%c[%d;%dH"
,
ESC
, y, x);
70
}
71
72
void
graphicCommand
(
char
command) {
// Private helper function
73
printf(
"%c[%dm"
,
ESC
, command);
74
}
75
76
void
underline
(
char
on) {
// Used to turn underline on and off
77
char
command = 4;
78
if
(!on)
79
command += 20;
80
graphicCommand
(command);
81
}
82
83
void
blink
(
char
on) {
// Used to blink the text
84
char
command = 5;
85
if
(!on)
86
command += 20;
87
graphicCommand
(command);
88
}
89
90
void
reverse
(
char
on) {
// Used to reverse the background and forground of the text
91
char
command = 7;
92
if
(!on)
93
command += 20;
94
graphicCommand
(command);
95
}
96
97
unsigned
char
strlen
(
char
*
string
) {
// Calculate the length of a string
98
unsigned
char
length = 0;
99
while
(*
string
++ !=
'\0'
)
100
length++;
101
return
length;
102
}
103
104
// Used to draw a horizontal line with the corners specified in left and right
105
void
drawTopBot
(
unsigned
char
x,
unsigned
char
y,
unsigned
char
width,
unsigned
char
left,
unsigned
char
right,
unsigned
char
side) {
106
int
i;
107
gotoxy
(x,y);
108
printf(
"%c"
,left);
109
for
(i=0;i<width;i++)
110
printf(
"%c"
,side);
111
printf(
"%c"
,right);
112
}
113
114
// Used to draw vertical sides
115
void
drawSides
(
unsigned
char
x1
,
unsigned
char
y1
,
unsigned
char
x2
,
unsigned
char
y2
,
unsigned
char
side) {
116
int
i, j;
117
for
(i=y1+1;i<
y2
;i++) {
118
gotoxy
(x1,i);
119
printf(
"%c"
,side);
120
gotoxy
(x2,i);
121
printf(
"%c"
,side);
122
}
123
}
124
125
void
saveCursor
() {
// Save the position of the cursor
126
printf(
"%c[s"
,
ESC
);
127
}
128
129
void
getSavedCursor
() {
// Get the last saved position
130
printf(
"%c[u"
,
ESC
);
131
}
132
133
void
moveCursor
(
char
dir,
unsigned
char
n) {
// Move cursor in some direction
134
printf(
"%c[%d%c"
,
ESC
, n, dir);
135
}
Generated by
1.8.4