-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxfont.c
353 lines (295 loc) · 10.5 KB
/
xfont.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
* Copyright (c) 1992, 1993 Arno Augustin, Frank Hoering, University of
* Erlangen-Nuremberg, Germany.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* Erlangen-Nuremberg, Germany.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include "font.h"
//#include "layer6.h"
#include "attrib.h"
#include "xfont.h"
#include "rawfont.h"
struct btxchar {
struct btxchar *link; /* NULL: use this char, else: use linked char */
char *raw; /* pointer to raw font data */
char bits; /* depth in case of DRC */
}; /* 0: normal (index = yd*2+xd) */
/* 1: xdouble */
/* 2: ydouble */
/* 3: xydouble */
unsigned char *memimage = NULL;
typedef struct {
unsigned char red;
unsigned char green;
unsigned char blue;
} color;
/* local variables */
static struct btxchar btx_font[6*96];
static int fullrow_bg[24]; /* fullrow background color for eacch row */
static int dclut[4]; /* map the 4-color DRC's */
static color colormap[32+4+24]; /* store pixel value for each colorcell */
/* local functions */
static void xdraw_normal_char(struct btxchar *ch, int x, int y, int xd, int yd, int ul, struct btxchar *dia, int fg, int bg, int fontheight);
static void xdraw_multicolor_char(struct btxchar *ch, int x, int y, int xd, int yd, int fontheight);
/*
* initialize character sets.
*/
void init_fonts()
{
static char raw_del[] = { 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f };
int n;
/* primary graphic, 2nd suppl. mosaic, suppl. graphic, 3rd suppl. mosaic */
for(n=0; n<4*96; n++) {
btx_font[n].raw = raw_font+n*2*FONT_HEIGHT;
btx_font[n].bits = 1;
btx_font[n].link = NULL;
}
/* link chars into '1st supplementary mosaic' (L) set */
for(n=0; n<32; n++) {
btx_font[SUP1*96+n].link = btx_font+SUP2*96+n;
btx_font[SUP1*96+n+32].link = btx_font+PRIM*96+n+32;
btx_font[SUP1*96+n+64].link = btx_font+SUP2*96+n+64;
}
/* initialize the DEL character of the L set */
btx_font[L*96+0x7f-0x20].link = NULL;
btx_font[L*96+0x7f-0x20].raw = raw_del;
btx_font[L*96+0x7f-0x20].bits = 1;
/* initialize DRCS font to all NULL's */
btx_font[DRCS*96+0].link = btx_font; /* link 'SPACE' */
for(n=1; n<96; n++) {
btx_font[DRCS*96+n].bits = 0;
btx_font[DRCS*96+n].raw = NULL;
btx_font[DRCS*96+n].link = NULL;
}
}
/*
* draw the specified character at cursor position x, y (zero based).
* The character is stretched according to xdouble, ydouble (1=stretch,
* 0=don't).
*/
void xputc(int c, int set, int x, int y, int xdouble, int ydouble, int underline, int diacrit, int fg, int bg, int fontheight, int rows)
{
struct btxchar *ch, *dia;
if(x<0 || y<0 || x>39 || y>rows-1) return;
ch = btx_font + set*96 + c - 0x20;
/* folow the link pointer */
if(ch->link) ch = ch->link;
/* a yet undefined DRC should be drawn - draw a SPACE */
if(!ch->raw) ch = btx_font;
if(ch->bits==1) {
dia = diacrit ? btx_font + SUPP*96 + diacrit - 0x20 : NULL;
xdraw_normal_char(ch, x, y, xdouble, ydouble, underline, dia, fg, bg, fontheight);
}
else { /* 2/4 bits */
xdraw_multicolor_char(ch, x, y, xdouble, ydouble, fontheight);
}
}
#define set_mem(x, y, col) { \
memimage[(y)*480*3 + (x)*3 + 0] = colormap[col].red; \
memimage[(y)*480*3 + (x)*3 + 1] = colormap[col].green; \
memimage[(y)*480*3 + (x)*3 + 2] = colormap[col].blue; }
static void xdraw_normal_char(struct btxchar *ch, int x, int y, int xd, int yd, int ul, struct btxchar *dia, int fg, int bg, int fontheight)
{
int i, j, z, s, yy, yyy, xxx;
if(fg==TRANSPARENT) fg = 32+4+y;
if(bg==TRANSPARENT) bg = 32+4+y;
z=y*fontheight;
for(yy=0; yy<fontheight; yy++) {
for(yyy=0; yyy<(yd+1); yyy++) {
s=x*FONT_WIDTH;
for(j=0; j<2; j++)
for(i=5; i>=0; i--)
for(xxx=0; xxx<(xd+1); xxx++, s++)
set_mem(s, z, ( (ch->raw[yy*2+j]&(1<<i)) ||
(dia && (dia->raw[yy*2+j]&(1<<i))) )
? fg : bg);
z++;
}
}
if(ul)
for(yyy=0; yyy<(yd+1); yyy++)
for(xxx=0; xxx<FONT_WIDTH*(xd+1); xxx++)
set_mem(x*FONT_WIDTH+xxx,
y*fontheight+(fontheight-1)*(yd+1)+yyy, fg);
}
static void xdraw_multicolor_char(struct btxchar *ch, int x, int y, int xd, int yd, int fontheight)
{
int c, i, j, z, s, p, yy, xxx, yyy;
z=y*fontheight;
for(yy=0; yy<fontheight; yy++) {
for(yyy=0; yyy<(yd+1); yyy++) {
s=x*FONT_WIDTH;
for(j=0; j<2; j++)
for(i=5; i>=0; i--) {
for(p=0, c=0; p<ch->bits; p++)
if(ch->raw[p*2*FONT_HEIGHT+yy*2+j]&(1<<i)) c |= 1<<p;
if(ch->bits==2) {
c = dclut[c];
if(c==TRANSPARENT) c = 32+4+y;
}
else c += 16;
for(xxx=0; xxx<(xd+1); xxx++, s++) set_mem(s, z, c);
}
z++;
}
}
}
void xcursor(int x, int y, int fontheight)
{
/* this inverts the character at the given location */
for (int yy = y * fontheight; yy < y * fontheight + fontheight; yy++) {
for (int xx = x * 12; xx < x * 12 + 12; xx++) {
memimage[(yy)*480*3 + (xx)*3 + 0] ^= 0xFF;
memimage[(yy)*480*3 + (xx)*3 + 1] ^= 0xFF;
memimage[(yy)*480*3 + (xx)*3 + 2] ^= 0xFF;
}
}
}
/*
* defines the raw bitmap data for a DRC 'c'. If 'c' was in use before,
* its old raw data is freed.
*/
void define_raw_DRC(int c, char *data, int bits)
{
struct btxchar *ch = btx_font + DRCS*96 + c - 0x20;
int n;
if(ch->raw) free(ch->raw);
if(! (ch->raw = malloc(2*FONT_HEIGHT*bits)) ) {
perror("XCEPT: no mem for raw DRCS");
exit(1);
}
ch->bits = bits;
for(n=0; n<2*FONT_HEIGHT*bits; n++) ch->raw[n] = data[n];
ch->link = NULL;
}
/*
* free the current DRCS completely
*/
void free_DRCS()
{
int n;
btx_font[DRCS*96+0].link = btx_font; /* link 'SPACE' */
for(n=DRCS*96+1; n<(DRCS+1)*96; n++) {
if(btx_font[n].raw) {
free(btx_font[n].raw);
btx_font[n].raw = NULL;
}
btx_font[n].link = NULL;
btx_font[n].bits = 0;
}
}
/*
* initialize colormap entries for clut 0-3, DCLUT + fullrow background
*/
void default_colors()
{
int n;
/* clut 0 + clut 1 */
for(n=0; n<16; n++) { /* page 112) */
if(n==8) { colormap[n] = colormap[0]; continue; }
colormap[n].red = ((n&1)>0) ? ( ((n&8)==0) ? 0xff : 0x7f ) : 0;
colormap[n].green = ((n&2)>0) ? ( ((n&8)==0) ? 0xff : 0x7f ) : 0;
colormap[n].blue = ((n&4)>0) ? ( ((n&8)==0) ? 0xff : 0x7f ) : 0;
}
/* clut 2 + clut 3 */
for(n=0; n<8; n++) {
colormap[n+16].red = colormap[n+24].red = n&1 ? 0xff : 0;
colormap[n+16].green = colormap[n+24].green = n&2 ? 0xff : 0;
colormap[n+16].blue = colormap[n+24].blue = n&4 ? 0xff : 0;
}
/* DCLUT */
for(n=0; n<4; n++) {
colormap[32+n].red = colormap[n].red;
colormap[32+n].green = colormap[n].green;
colormap[32+n].blue = colormap[n].blue;
dclut[n] = n;
}
/* fullrow background (BLACK) */
for(n=0; n<24; n++) {
colormap[32+4+n].red = colormap[0].red;
colormap[32+4+n].green = colormap[0].green;
colormap[32+4+n].blue = colormap[0].blue;
fullrow_bg[n] = 0;
}
}
/*
* define new RGB values for color 'index' in colormap
*/
void define_color(unsigned int index, unsigned int r, unsigned int g, unsigned int b)
{
int i;
colormap[index].red = r << 4;
colormap[index].green = g << 4;
colormap[index].blue = b << 4;
/* if DCLUT contains this color, change DCLUT color too */
for(i=0; i<4; i++)
if(dclut[i]==index) define_DCLUT(i, index);
/* if fullrow_bg contains this color, change fullrow color too */
for(i=0; i<24; i++)
if(fullrow_bg[i]==index) define_fullrow_bg(i, index);
}
/*
* set RGB values for DCLUT color 'entry' to those of color 'index'.
*/
void define_DCLUT(int entry, int index)
{
dclut[entry] = index;
colormap[32+entry].red = colormap[index].red;
colormap[32+entry].green = colormap[index].green;
colormap[32+entry].blue = colormap[index].blue;
}
/*
* set RGB values for fullrow_bg of 'row' to those of color 'index'.
*/
void define_fullrow_bg(int row, int index)
{
fullrow_bg[row] = index;
colormap[32+4+row].red = colormap[index].red;
colormap[32+4+row].green = colormap[index].green;
colormap[32+4+row].blue = colormap[index].blue;
}
void init_xfont()
{
memimage = malloc(480*240*3);
init_fonts();
default_colors();
}
void get_column_colour(int column, int *r, int *g, int *b)
{
int c=column;
if (c<0) c=0;
if (c>=24) c=23;
*r=colormap[32+4+c].red;
*g=colormap[32+4+c].green;
*b=colormap[32+4+c].blue;
}