]>
Commit | Line | Data |
---|---|---|
1 | #include <io.h> | |
2 | #include <text.h> | |
3 | #include <paging.h> | |
4 | #include <minilib.h> | |
5 | #include <stdint.h> | |
6 | #include <output.h> | |
7 | #include <smram.h> | |
8 | ||
9 | static unsigned char _font[256 * 32]; | |
10 | ||
11 | /* Must be called from a firstrun context, where we don't care about saving | |
12 | * 0x3CE state. */ | |
13 | void text_init() | |
14 | { | |
15 | unsigned char oldread; | |
16 | smram_state_t old_state = smram_save_state(); | |
17 | outb(0x3CE, 0x05 /* Mode register */); | |
18 | outb(0x3CF, inb(0x3CF) & ~(0x10 /* Odd/even */)); | |
19 | outb(0x3CE, 0x04 /* Read register */); | |
20 | oldread = inb(0x3CF); | |
21 | outb(0x3CF, 0x02 /* Font plane */); | |
22 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
23 | memcpy(_font, p2v(0xB8000), sizeof(_font)); | |
24 | smram_restore_state(old_state); | |
25 | outb(0x3CF, oldread); | |
26 | } | |
27 | ||
28 | void text_render(char *buf, int x, int y, int w, int h) | |
29 | { | |
30 | unsigned char *video = (unsigned char *)0xB8000; | |
31 | unsigned int textx = x / 9; | |
32 | unsigned int texty = y / 14; | |
33 | unsigned int cx, cy; | |
34 | unsigned char ch, at, font; | |
35 | smram_state_t old_state = smram_save_state(); | |
36 | ||
37 | outputf("text_render: buf %08x, (%d,%d),(%d,%d)", buf, x, y, w, h); | |
38 | ||
39 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
40 | for (cy = y; cy < (y + h); cy++) | |
41 | { | |
42 | texty = cy / 14; | |
43 | textx = cx / 9; | |
44 | ch = video[texty * 50 + textx * 2]; | |
45 | at = video[texty * 50 + textx * 2 + 1]; | |
46 | font = _font[ch * 32 + cy % 14]; | |
47 | for (cx = x; cx < (x + w); cx++) | |
48 | { | |
49 | unsigned int pos = cx % 9; | |
50 | if (pos == 0) | |
51 | { | |
52 | textx = cx / 9; | |
53 | ch = video[texty * 50 + textx * 2]; | |
54 | at = video[texty * 50 + textx * 2 + 1]; | |
55 | font = _font[ch * 32 + cy % 14]; | |
56 | } | |
57 | /* XXX always BGR888 */ | |
58 | if (pos == 8) /* 9th pixel is cloned */ | |
59 | pos = 7; | |
60 | if ((font >> (7 - pos)) & 1) | |
61 | { | |
62 | *(buf++) = (at & 0x01) ? 0xFF : 0x00; | |
63 | *(buf++) = (at & 0x02) ? 0xFF : 0x00; | |
64 | *(buf++) = (at & 0x04) ? 0xFF : 0x00; | |
65 | } else { | |
66 | *(buf++) = (at & 0x10) ? 0xFF : 0x00; | |
67 | *(buf++) = (at & 0x20) ? 0xFF : 0x00; | |
68 | *(buf++) = (at & 0x40) ? 0xFF : 0x00; | |
69 | } | |
70 | *(buf++) = 0; | |
71 | } | |
72 | } | |
73 | smram_restore_state(old_state); | |
74 | } | |
75 | ||
76 | uint32_t text_checksum(int x, int y, int w, int h) | |
77 | { | |
78 | unsigned char *video = (unsigned char *)0xB8000; | |
79 | unsigned int textx = x / 9; | |
80 | unsigned int texty = y / 14; | |
81 | int cx, cy; | |
82 | unsigned char ch, at; | |
83 | uint32_t cksm = 0; | |
84 | smram_state_t old_state = smram_save_state(); | |
85 | ||
86 | outputf("checksum: (%d,%d),(%d,%d)", x,y,w,h); | |
87 | ||
88 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
89 | ||
90 | for (cy = y; cy < (y + h); cy++) | |
91 | { | |
92 | texty = cy / 14; | |
93 | textx = cx / 9; | |
94 | ch = video[texty * 50 + textx * 2]; | |
95 | at = video[texty * 50 + textx * 2 + 1]; | |
96 | for (cx = x; cx < (x + w); cx++) | |
97 | { | |
98 | unsigned int pos = cx % 9; | |
99 | if (pos == 0) | |
100 | { | |
101 | textx = cx / 9; | |
102 | ch = video[texty * 50 + textx * 2]; | |
103 | at = video[texty * 50 + textx * 2 + 1]; | |
104 | } | |
105 | ||
106 | cksm += ch + (at << 16); | |
107 | } | |
108 | } | |
109 | ||
110 | smram_restore_state(old_state); | |
111 | ||
112 | outputf("checksum: %08x", cksm); | |
113 | ||
114 | return cksm; | |
115 | } |