altos/vidtime: Check for value change in normal code, not irq
[fw/altos] / src / draw / ao_text.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include "ao.h"
16 #include "ao_draw.h"
17 #include "ao_draw_int.h"
18 #include "ao_font.h"
19
20 const struct ao_font ao_font = {
21         .width = GLYPH_WIDTH,
22         .height = GLYPH_HEIGHT,
23         .ascent = GLYPH_ASCENT,
24         .descent = GLYPH_HEIGHT - GLYPH_ASCENT,
25 };
26
27 void
28 ao_text(const struct ao_bitmap  *dst,
29         int16_t                 x,
30         int16_t                 y,
31         char                    *string,
32         uint32_t                fill,
33         uint8_t                 rop)
34 {
35         uint32_t        src[GLYPH_HEIGHT];
36         char            c;
37         int             h;
38
39         struct ao_bitmap        src_bitmap = {
40                 .base = src,
41                 .stride = 1,
42                 .width = GLYPH_WIDTH,
43                 .height = GLYPH_HEIGHT
44         };
45
46         y -= GLYPH_ASCENT;
47
48         rop = (rop & 3) | 0x4;
49
50         if ((fill&1) == 0)
51                 rop ^= 3;
52
53         while ((c = *string++)) {
54                 const uint8_t   *bytes = &glyph_bytes[glyph_pos[(uint8_t) c]];
55
56                 for (h = 0; h < GLYPH_HEIGHT; h++)
57                         src[h] = bytes[h];
58
59                 ao_copy(dst,
60                         x, y, GLYPH_WIDTH, GLYPH_HEIGHT,
61                         &src_bitmap,
62                         0, 0, rop);
63                 x += GLYPH_WIDTH;
64         }
65 }