Change VGA font
Posted: Sun May 27, 2012 1:26 am
Hi!
I've read this:
http://forum.osdev.org/viewtopic.php?f=1&t=20862
http://www.osdever.net/FreeVGA/vga/vgafunc.htm
and wanted to program VGA font loading in my OS.
Here is my code:
I tried this on bochs and real PC, but the font doesn't change! OK, I copied and pasted the code from http://forum.osdev.org/viewtopic.php?f=1&t=20862, but the same - the font stay unchanged. I breaked my mind, but I can't guess what's wrong.
Please, I need help.
P.S: If it is important: I'm working in the 32-bit protected mode.
I've read this:
http://forum.osdev.org/viewtopic.php?f=1&t=20862
http://www.osdever.net/FreeVGA/vga/vgafunc.htm
and wanted to program VGA font loading in my OS.
Here is my code:
Code: Select all
#include <system.h>
#include <inline.h>
#define COLUMNS 80
#define ROWS 25
#define VIDEO_ADDR 0xB8000
/* @iport - index port, @iport + 1 - data port */
static inline void vga_write_reg(u16_t iport, byte_t reg, byte_t val){
to_port_b(iport, reg); /* Select register */
to_port_b(iport + 1, val); /* Do writing through data port */
}
/* @iport - index port, @iport + 1 - data port */
static inline byte_t vga_read_reg(u16_t iport, byte_t reg){
to_port_b(iport, reg); /* Select register */
return from_port_b(iport + 1); /* Do reading through data port */
}
#define VGA_SEQ_INDEX_PORT 0x3C4
#define VGA_SEQ_DATA_PORT 0x3C5
#define VGA_GC_INDEX_PORT 0x3CE
#define VGA_GC_DATA_PORT 0x3CF
#define VGA_CRTC_INDEX_PORT 0x3D4
#define VGA_CRTC_DATA_PORT 0x3D5
#define VGA_SEQ_MAP_MASK_REG 0x02
#define VGA_SEQ_CHARSET_REG 0x03
#define VGA_SEQ_MEMORY_MODE_REG 0x04
#define VGA_GC_READ_MAP_SELECT_REG 0x04
#define VGA_GC_GRAPHICS_MODE_REG 0x05
#define VGA_GC_MISC_REG 0x06
#define BYTES_PER_GLYPTH 16
#define BYTES_SKIP 16
#define CHARSET_LENGTH 256
#define FONT_SIZE CHARSET_LENGTH * BYTES_PER_GLYPTH
static void set_font(unsigned char font[FONT_SIZE]){
int i, j;
unsigned char *p = (unsigned char *)0xB8000;
byte_t mem_mode, graphics_mode;
/* Panel 2 write enable */
vga_write_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_MAP_MASK_REG, 0x04);
/* To be shure, that the first font in the plane 2 is selected */
vga_write_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_CHARSET_REG, 0x00);
mem_mode = vga_read_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_MEMORY_MODE_REG);
vga_write_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_MEMORY_MODE_REG, 0x06);
/* I think this line is unnecessary */
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_READ_MAP_SELECT_REG, 0x02);
graphics_mode = vga_read_reg(VGA_GC_INDEX_PORT, VGA_GC_GRAPHICS_MODE_REG);
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_GRAPHICS_MODE_REG, 0x00);
/* And this line is unnecessary too, since I now, that address is 0xB8000 */
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_MISC_REG, 0x0C);
/* Write charmap */
for(i = 0; i < CHARSET_LENGTH; i++){
for(j = 0; j < BYTES_PER_GLYPTH; j++){
*p = *font;
++p;
++font;
}
p += BYTES_SKIP;
}
/* Restore VGA to normal operation */
/* Panels 0 and 1 write enable */
vga_write_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_MAP_MASK_REG, 0x03);
vga_write_reg(VGA_SEQ_INDEX_PORT, VGA_SEQ_MEMORY_MODE_REG, mem_mode);
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_READ_MAP_SELECT_REG, 0x00);
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_GRAPHICS_MODE_REG, graphics_mode);
vga_write_reg(VGA_GC_INDEX_PORT, VGA_GC_MISC_REG, 0x0C);
}
Please, I need help.
P.S: If it is important: I'm working in the 32-bit protected mode.