9 #define MAXSQUARES 1 << 15
10 #define SQRADDR(r, c) (&screen[(r) * cols + (c)])
12 static int rows
, cols
;
16 static struct square
{
22 static unsigned int cd
[] = {
23 0x0a0a0a, 0xc04444, 0x339933, 0xcccc66,
24 0x5566bc, 0xcd66af, 0xa166cd, 0xeeeeee,
25 0x71a3b7, 0xc08888, 0x779977, 0xcccc99,
26 0x8899bc, 0xcd99af, 0xa199cd, 0xdedede};
32 rows
= fb_rows() / font_rows();
33 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 u16_t
mixed_color(int fg
, int bg
, u8_t val
)
48 unsigned int fore
= cd
[fg
], back
= cd
[bg
];
49 u8_t r
= COLORMERGE(CR(fore
), CR(back
), val
);
50 u8_t g
= COLORMERGE(CG(fore
), CG(back
), val
);
51 u8_t b
= COLORMERGE(CB(fore
), CB(back
), val
);
52 return fb_color(r
, g
, b
);
55 static u16_t
color2fb(int c
)
57 return mixed_color(fg
, c
, 0);
70 static void pad_show(int r
, int c
, int reverse
)
72 int sr
= font_rows() * r
;
73 int sc
= font_cols() * c
;
74 struct square
*sqr
= SQRADDR(r
, c
);
75 int fgcolor
= sqr
->c
? sqr
->fg
: fg
;
76 int bgcolor
= sqr
->c
? sqr
->bg
: bg
;
84 fb_box(sr
, sc
, sr
+ font_rows(), sc
+ font_cols(), color2fb(bgcolor
));
87 bits
= font_bitmap(sqr
->c
, 0);
88 for (i
= 0; i
< font_rows() * font_cols(); i
++)
90 fb_put(sr
+ i
/ font_cols(), sc
+ i
% font_cols(),
91 mixed_color(fgcolor
, bgcolor
, bits
[i
]));
94 void pad_put(int ch
, int r
, int c
)
96 struct square
*sqr
= SQRADDR(r
, c
);
97 if (!ch
|| !strchr("\a\b\f\n\r\v", ch
)) {
105 static void pad_empty(int sr
, int er
)
107 memset(SQRADDR(sr
, 0), 0, (er
- sr
) * sizeof(screen
[0]) * cols
);
110 void pad_scroll(int sr
, int nr
, int n
)
112 pad_show(row
, col
, 0);
113 fb_scroll(sr
* font_rows(), nr
* font_rows(),
114 n
* font_rows(), color2fb(bg
));
115 memmove(SQRADDR(sr
+ n
, 0), SQRADDR(sr
, 0),
116 nr
* cols
* sizeof(screen
[0]));
118 pad_empty(sr
, sr
+ n
);
120 pad_empty(sr
+ nr
+ n
, sr
+ nr
);
121 pad_show(row
, col
, 1);
126 fb_box(0, 0, fb_rows(), fb_cols(), color2fb(bg
));
127 memset(screen
, 0, sizeof(screen
));
130 void pad_move(int r
, int c
)
132 pad_show(row
, col
, 0);
133 row
= MIN(r
, rows
- 1);
134 col
= MIN(c
, cols
- 1);
135 pad_show(row
, col
, 1);