10 static int rows
, cols
;
11 static unsigned int cd
[] = {
12 0x0a0a0a, 0xc04444, 0x339933, 0xcccc66,
13 0x5566bc, 0xcd66af, 0xa166cd, 0xeeeeee,
14 0x71a3b7, 0xc08888, 0x779977, 0xcccc99,
15 0x8899bc, 0xcd99af, 0xa199cd, 0xdedede};
21 rows
= fb_rows() / font_rows();
22 cols
= fb_cols() / font_cols();
30 #define CR(a) (((a) >> 16) & 0x0000ff)
31 #define CG(a) (((a) >> 8) & 0x0000ff)
32 #define CB(a) ((a) & 0x0000ff)
33 #define COLORMERGE(f, b, c) ((b) + (((f) - (b)) * (c) >> 8u))
35 static fbval_t
mixed_color(int fg
, int bg
, unsigned char val
)
37 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
38 unsigned char r
= COLORMERGE(CR(fore
), CR(back
), val
);
39 unsigned char g
= COLORMERGE(CG(fore
), CG(back
), val
);
40 unsigned char b
= COLORMERGE(CB(fore
), CB(back
), val
);
41 return fb_color(r
, g
, b
);
44 static fbval_t
color2fb(int c
)
46 return fb_color(CR(cd
[c
]), CG(cd
[c
]), CB(cd
[c
]));
49 #define NCACHE ((1 << 11) - 1)
50 static fbval_t cache
[NCACHE
* MAXDOTS
];
56 static int glyph_hash(struct glyph
*g
)
58 return (g
->c
| (((g
->fg
+ 1) ^ g
->bg
) << 7)) % NCACHE
;
61 static fbval_t
*bitmap(int c
, short fg
, short bg
)
65 struct glyph glyph
= {0};
68 int nbits
= font_rows() * font_cols();
69 if (!isprint(c
) || isspace(c
))
74 hash
= glyph_hash(&glyph
);
75 fbbits
= &cache
[hash
* MAXDOTS
];
76 if (!memcmp(&glyph
, &cacheid
[hash
], sizeof(glyph
)))
78 cacheid
[hash
] = glyph
;
79 bits
= font_bitmap(c
, fg
>= 8);
80 for (i
= 0; i
< nbits
; i
++)
81 fbbits
[i
] = mixed_color(fg
, bg
, bits
[i
]);
85 void pad_put(int ch
, int r
, int c
, int fg
, int bg
)
87 int sr
= font_rows() * r
;
88 int sc
= font_cols() * c
;
89 int frows
= font_rows(), fcols
= font_cols();
91 fbval_t
*bits
= bitmap(ch
, fg
, bg
);
93 fb_box(sr
, sc
, sr
+ frows
, sc
+ fcols
, color2fb(bg
));
95 for (i
= 0; i
< frows
; i
++)
96 fb_set(sr
+ i
, sc
, bits
+ (i
* fcols
), fcols
);
99 void pad_scroll(int sr
, int nr
, int n
, int c
)
101 fb_scroll(sr
* font_rows(), nr
* font_rows(),
102 n
* font_rows(), color2fb(c
));
105 void pad_blank(int c
)
107 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(c
));