9 #include <video_defines.h>
11 static unsigned char _font[256 * 32];
13 /* XXX reunify this with vga-overlay? */
14 #define VRAM_BASE 0xA0000UL
15 #define TEXT_CONSOLE_OFFSET 0x18000UL
17 #define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET)
19 static unsigned char vga_read(unsigned char idx)
21 outb(CRTC_IDX_REG, idx);
22 return inb(CRTC_DATA_REG);
25 static char * vga_base()
29 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
30 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
34 /* Must be called from a firstrun context, where we don't care about saving
38 unsigned char oldread;
40 smram_state_t old_state = smram_save_state();
41 outb(0x3CE, 0x04 /* Read register */);
43 outb(0x3CF, 0x02 /* Font plane */);
45 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
46 memcpy(_font, p2v(0xB8000), sizeof(_font));
47 smram_restore_state(old_state);
52 void text_render(char *buf, int x, int y, int w, int h)
54 unsigned char *video = (unsigned char *)vga_base();
55 unsigned int textx = x / 9;
56 unsigned int texty = y / 14;
58 unsigned char ch, at, font;
59 smram_state_t old_state = smram_save_state();
61 outputf("text_render: (%d,%d),(%d,%d)", buf, x, y, w, h);
63 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
64 for (cy = y; cy < (y + h); cy++)
69 ch = video[texty * 160 + textx * 2];
70 at = video[texty * 160 + textx * 2 + 1];
71 font = _font[ch * 32 + cy % 14];
72 for (cx = x; cx < (x + w); cx++)
74 unsigned int pos = cx % 9;
78 ch = video[texty * 160 + textx * 2];
79 at = video[texty * 160 + textx * 2 + 1];
80 font = _font[ch * 32 + cy % 14];
82 /* XXX always BGR888 */
83 if (pos == 8) /* 9th pixel is cloned */
85 if ((font >> (7 - pos)) & 1)
87 *(buf++) = (at & 0x01) ? 0xFF : 0x00;
88 *(buf++) = (at & 0x02) ? 0xFF : 0x00;
89 *(buf++) = (at & 0x04) ? 0xFF : 0x00;
91 *(buf++) = (at & 0x10) ? 0xFF : 0x00;
92 *(buf++) = (at & 0x20) ? 0xFF : 0x00;
93 *(buf++) = (at & 0x40) ? 0xFF : 0x00;
98 smram_restore_state(old_state);
101 uint32_t text_checksum(int x, int y, int w, int h)
103 unsigned char *video = (unsigned char *)vga_base();
104 unsigned int textx = x / 9;
105 unsigned int texty = y / 14;
108 smram_state_t old_state = smram_save_state();
110 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
112 for (cy = y; cy < (y + h); cy++)
117 cksm = crc32(video + texty * 160 + textx * 2, (w / 9) * 2 + 2, cksm); /* Err on the side of 'too many'. */
120 smram_restore_state(old_state);