11 static unsigned int cd
[] = {
12 COLOR0
, COLOR1
, COLOR2
, COLOR3
,
13 COLOR4
, COLOR5
, COLOR6
, COLOR7
,
14 COLOR8
, COLOR9
, COLOR10
, COLOR11
,
15 COLOR12
, COLOR13
, COLOR14
, COLOR15
};
16 static int rows
, cols
;
22 if (sizeof(fbval_t
) != FBM_BPP(fb_mode())) {
23 fprintf(stderr
, "pad_init: fbval_t doesn't match fb depth\n");
27 fprintf(stderr
, "pad_init: loading font failed\n");
30 rows
= fb_rows() / font_rows();
31 cols
= fb_cols() / font_cols();
41 #define CR(a) (((a) >> 16) & 0x0000ff)
42 #define CG(a) (((a) >> 8) & 0x0000ff)
43 #define CB(a) ((a) & 0x0000ff)
44 #define COLORMERGE(f, b, c) ((b) + (((f) - (b)) * (c) >> 8u))
46 static unsigned mixed_color(int fg
, int bg
, unsigned char val
)
48 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
49 unsigned char r
= COLORMERGE(CR(fore
), CR(back
), val
);
50 unsigned char g
= COLORMERGE(CG(fore
), CG(back
), val
);
51 unsigned char b
= COLORMERGE(CB(fore
), CB(back
), val
);
52 return FB_VAL(r
, g
, b
);
55 static unsigned color2fb(int c
)
57 return FB_VAL(CR(cd
[c
]), CG(cd
[c
]), CB(cd
[c
]));
60 #define NCACHE (1 << 11)
61 static fbval_t cache
[NCACHE
* MAXDOTS
];
67 static int glyph_hash(int c
, int fg
, int bg
)
69 return (c
^ (fg
<< 7) ^ (bg
<< 6)) & (NCACHE
- 1);
72 static fbval_t
*bitmap(int c
, short fg
, short bg
)
74 unsigned char bits
[MAXDOTS
];
78 int nbits
= font_rows() * font_cols();
79 if (c
< 0 || (c
< 256 && (!isprint(c
) || isspace(c
))))
81 glyph
= &cacheid
[glyph_hash(c
, fg
, bg
)];
82 fbbits
= &cache
[glyph_hash(c
, fg
, bg
) * MAXDOTS
];
83 if (glyph
->c
== c
&& glyph
->fg
== fg
&& glyph
->bg
== bg
)
85 if (font_bitmap(bits
, c
))
90 for (i
= 0; i
< nbits
; i
++)
91 fbbits
[i
] = mixed_color(fg
, bg
, bits
[i
]);
95 #define MAXFBWIDTH (1 << 12)
96 static void fb_box(int sr
, int sc
, int er
, int ec
, fbval_t val
)
98 static fbval_t line
[MAXFBWIDTH
];
101 for (i
= 0; i
< cn
; i
++)
103 for (i
= sr
; i
< er
; i
++)
104 fb_set(i
, sc
, line
, cn
);
107 void pad_put(int ch
, int r
, int c
, int fg
, int bg
)
109 int sr
= font_rows() * r
;
110 int sc
= font_cols() * c
;
111 int frows
= font_rows(), fcols
= font_cols();
113 fbval_t
*bits
= bitmap(ch
, fg
, bg
);
115 fb_box(sr
, sc
, sr
+ frows
, sc
+ fcols
, color2fb(bg
));
117 for (i
= 0; i
< frows
; i
++)
118 fb_set(sr
+ i
, sc
, bits
+ (i
* fcols
), fcols
);
121 void pad_blank(int c
)
123 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(c
));
126 void pad_blankrow(int r
, int bg
)
128 int sr
= r
* font_rows();
129 int er
= r
== rows
- 1 ? fb_rows() : (r
+ 1) * font_rows();
130 fb_box(sr
, 0, er
, fb_cols(), color2fb(bg
));