]>
Commit | Line | Data |
---|---|---|
cdde55f5 JW |
1 | #include <io.h> |
2 | #include <text.h> | |
3 | #include <paging.h> | |
4 | #include <minilib.h> | |
5 | #include <stdint.h> | |
74032dae JW |
6 | #include <output.h> |
7 | #include <smram.h> | |
cdde55f5 JW |
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; | |
74032dae | 16 | smram_state_t old_state = smram_save_state(); |
cdde55f5 JW |
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 */); | |
74032dae | 22 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); |
cdde55f5 | 23 | memcpy(_font, p2v(0xB8000), sizeof(_font)); |
74032dae | 24 | smram_restore_state(old_state); |
cdde55f5 JW |
25 | outb(0x3CF, oldread); |
26 | } | |
27 | ||
66cd7e82 | 28 | void text_render(char *buf, int x, int y, int w, int h) |
cdde55f5 | 29 | { |
74032dae | 30 | unsigned char *video = (unsigned char *)0xB8000; |
cdde55f5 JW |
31 | unsigned int textx = x / 9; |
32 | unsigned int texty = y / 14; | |
33 | unsigned int cx, cy; | |
34 | unsigned char ch, at, font; | |
74032dae | 35 | smram_state_t old_state = smram_save_state(); |
cdde55f5 | 36 | |
53b39ad0 | 37 | outputf("text_render: (%d,%d),(%d,%d)", buf, x, y, w, h); |
74032dae JW |
38 | |
39 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
cdde55f5 JW |
40 | for (cy = y; cy < (y + h); cy++) |
41 | { | |
77671f96 | 42 | cx = x; |
cdde55f5 JW |
43 | texty = cy / 14; |
44 | textx = cx / 9; | |
45 | ch = video[texty * 50 + textx * 2]; | |
46 | at = video[texty * 50 + textx * 2 + 1]; | |
47 | font = _font[ch * 32 + cy % 14]; | |
48 | for (cx = x; cx < (x + w); cx++) | |
49 | { | |
50 | unsigned int pos = cx % 9; | |
51 | if (pos == 0) | |
52 | { | |
53 | textx = cx / 9; | |
54 | ch = video[texty * 50 + textx * 2]; | |
55 | at = video[texty * 50 + textx * 2 + 1]; | |
56 | font = _font[ch * 32 + cy % 14]; | |
57 | } | |
58 | /* XXX always BGR888 */ | |
59 | if (pos == 8) /* 9th pixel is cloned */ | |
60 | pos = 7; | |
61 | if ((font >> (7 - pos)) & 1) | |
62 | { | |
63 | *(buf++) = (at & 0x01) ? 0xFF : 0x00; | |
64 | *(buf++) = (at & 0x02) ? 0xFF : 0x00; | |
65 | *(buf++) = (at & 0x04) ? 0xFF : 0x00; | |
66 | } else { | |
67 | *(buf++) = (at & 0x10) ? 0xFF : 0x00; | |
68 | *(buf++) = (at & 0x20) ? 0xFF : 0x00; | |
69 | *(buf++) = (at & 0x40) ? 0xFF : 0x00; | |
70 | } | |
66cd7e82 | 71 | *(buf++) = 0; |
cdde55f5 JW |
72 | } |
73 | } | |
74032dae | 74 | smram_restore_state(old_state); |
cdde55f5 JW |
75 | } |
76 | ||
77 | uint32_t text_checksum(int x, int y, int w, int h) | |
78 | { | |
74032dae | 79 | unsigned char *video = (unsigned char *)0xB8000; |
cdde55f5 JW |
80 | unsigned int textx = x / 9; |
81 | unsigned int texty = y / 14; | |
82 | int cx, cy; | |
83 | unsigned char ch, at; | |
84 | uint32_t cksm = 0; | |
74032dae JW |
85 | smram_state_t old_state = smram_save_state(); |
86 | ||
74032dae | 87 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); |
cdde55f5 JW |
88 | |
89 | for (cy = y; cy < (y + h); cy++) | |
90 | { | |
77671f96 | 91 | cx = x; |
cdde55f5 JW |
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 | ||
74032dae JW |
110 | smram_restore_state(old_state); |
111 | ||
cdde55f5 JW |
112 | return cksm; |
113 | } |