9 static unsigned char _font[256 * 32];
 
  11 /* Must be called from a firstrun context, where we don't care about saving
 
  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 */);
 
  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);
 
  28 void text_render(char *buf, int x, int y, int w, int h)
 
  30         unsigned char *video = (unsigned char *)0xB8000;
 
  31         unsigned int textx = x / 9;
 
  32         unsigned int texty = y / 14;
 
  34         unsigned char ch, at, font;
 
  35         smram_state_t old_state = smram_save_state();
 
  37         outputf("text_render: (%d,%d),(%d,%d)", buf, x, y, w, h);
 
  39         smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
 
  40         for (cy = y; cy < (y + h); cy++)
 
  45                 ch = video[texty * 160 + textx * 2];
 
  46                 at = video[texty * 160 + textx * 2 + 1];
 
  47                 font = _font[ch * 32 + cy % 14];
 
  48                 for (cx = x; cx < (x + w); cx++)
 
  50                         unsigned int pos = cx % 9;
 
  54                                 ch = video[texty * 160 + textx * 2];
 
  55                                 at = video[texty * 160 + textx * 2 + 1];
 
  56                                 font = _font[ch * 32 + cy % 14];
 
  58                         /* XXX always BGR888 */
 
  59                         if (pos == 8)   /* 9th pixel is cloned */
 
  61                         if ((font >> (7 - pos)) & 1)
 
  63                                 *(buf++) = (at & 0x01) ? 0xFF : 0x00;
 
  64                                 *(buf++) = (at & 0x02) ? 0xFF : 0x00;
 
  65                                 *(buf++) = (at & 0x04) ? 0xFF : 0x00;
 
  67                                 *(buf++) = (at & 0x10) ? 0xFF : 0x00;
 
  68                                 *(buf++) = (at & 0x20) ? 0xFF : 0x00;
 
  69                                 *(buf++) = (at & 0x40) ? 0xFF : 0x00;
 
  74         smram_restore_state(old_state);
 
  77 uint32_t text_checksum(int x, int y, int w, int h)
 
  79         unsigned char *video = (unsigned char *)0xB8000;
 
  80         unsigned int textx = x / 9;
 
  81         unsigned int texty = y / 14;
 
  85         smram_state_t old_state = smram_save_state();
 
  87         smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
 
  89         for (cy = y; cy < (y + h); cy++)
 
  94                 cksm ^= crc32(video + texty * 160 + textx * 2, (w / 9 + 1) * 2);        /* Err on the side of 'too many'. */
 
  97         smram_restore_state(old_state);