static void write_font(unsigned char *buf, unsigned font_height) { unsigned char seq2, seq4, gc4, gc5, gc6; unsigned i; /* save registers set_plane() modifies GC 4 and SEQ 2, so save them as well */ outport(VGA_SEQ_INDEX, 2); seq2 = inport(VGA_SEQ_DATA); outport(VGA_SEQ_INDEX, 4); seq4 = inport(VGA_SEQ_DATA); /* turn off even-odd addressing (set flat addressing) assume: chain-4 addressing already off */ outport(VGA_SEQ_DATA, seq4 | 0x04); outport(VGA_GC_INDEX, 4); gc4 = inport(VGA_GC_DATA); outport(VGA_GC_INDEX, 5); gc5 = inport(VGA_GC_DATA); /* turn off even-odd addressing */ outport(VGA_GC_DATA, gc5 & ~0x10); outport(VGA_GC_INDEX, 6); gc6 = inport(VGA_GC_DATA); /* turn off even-odd addressing */ outport(VGA_GC_DATA, gc6 & ~0x02); /* write font to plane P4 */ set_plane(2); /* write font 0 */ for(i = 0; i < 256; i++) { //vmemwr(16384u * 0 + i * 32, buf, font_height); memcpy((char*)buf, (char*)(i*32 + 0xA0000), font_height); buf += font_height; } #if 0 /* write font 1 */ for(i = 0; i < 256; i++) { vmemwr(16384u * 1 + i * 32, buf, font_height); buf += font_height; } #endif /* restore registers */ outport(VGA_SEQ_INDEX, 2); outport(VGA_SEQ_DATA, seq2); outport(VGA_SEQ_INDEX, 4); outport(VGA_SEQ_DATA, seq4); outport(VGA_GC_INDEX, 4); outport(VGA_GC_DATA, gc4); outport(VGA_GC_INDEX, 5); outport(VGA_GC_DATA, gc5); outport(VGA_GC_INDEX, 6); outport(VGA_GC_DATA, gc6); }
void VGAWriteFont(uint8_t* buffer, uint8_t font_height) { /* These are the registers we have to save and restore. */ uint8_t seq2, seq4, gc4, gc5, gc6; outb(VGA_SEQ_INDEX, 2); seq2 = inb(VGA_SEQ_DATA); outb(VGA_SEQ_INDEX, 4); seq4 = inb(VGA_SEQ_DATA); /* turn off even-odd addressing (set flat addressing) assume: chain-4 addressing already off */ outb(VGA_SEQ_DATA, seq4 | 0x04); outb(VGA_GC_INDEX, 4); gc4 = inb(VGA_GC_DATA); outb(VGA_GC_INDEX, 5); gc5 = inb(VGA_GC_DATA); /* turn off even-odd addressing */ outb(VGA_GC_DATA, gc5 & ~0x10); outb(VGA_GC_INDEX, 6); gc6 = inb(VGA_GC_DATA); /* Turn off even-odd addressing. */ outb(VGA_GC_DATA, gc6 & ~0x02); /* Write font to plane P4. */ VGASetPlane(2); /* Write font. */ for(size_t i = 0; i < 256; i++) { vmemwr(16384u * 0 + i * 32, buffer, font_height); buffer += font_height; } /* Restore registers. */ outb(VGA_SEQ_INDEX, 2); outb(VGA_SEQ_DATA, seq2); outb(VGA_SEQ_INDEX, 4); outb(VGA_SEQ_DATA, seq4); outb(VGA_GC_INDEX, 4); outb(VGA_GC_DATA, gc4); outb(VGA_GC_INDEX, 5); outb(VGA_GC_DATA, gc5); outb(VGA_GC_INDEX, 6); outb(VGA_GC_DATA, gc6); }