VGA doesn't print
Posted: Mon May 26, 2014 6:37 am
ok, so i coded my semi-working os with getting help from bare bones and Brandon F. 's kernel tutorial and i have a little problem,
my problem is that when i run my kernel.iso (in qemu) the os is supposed to clear the screen and print the char 'C' to the screen on 0xb8000,
but when i run it, nothing happens and i have a blinking cursor, and when i hold Alt+Ctrl+2 and when i type xp from 0xb8000 to 0xb8009
i see the following:
and after a minute or so when i check them again, all of them are set to 0.
these are the code i use for vga:
and this is my vga structure:
and these are my putch() and init_video() functions
my problem is that when i run my kernel.iso (in qemu) the os is supposed to clear the screen and print the char 'C' to the screen on 0xb8000,
but when i run it, nothing happens and i have a blinking cursor, and when i hold Alt+Ctrl+2 and when i type xp from 0xb8000 to 0xb8009
i see the following:
Code: Select all
xp 0xb8000
00000000000b8000: 0x07200720
xp 0xb8001
00000000000b8001: 0x20072007
xp 0xb8002
00000000000b8002: 0x07200720
xp 0xb8003
00000000000b8003: 0x20072007
xp 0xb8004
00000000000b8004: 0x07200720
xp 0xb8005
00000000000b8005: 0x20072007
xp 0xb8006
00000000000b8006: 0x07200720
xp 0xb8007
00000000000b8007: 0x20072007
xp 0xb8008
00000000000b8008: 0x07200720
xp 0xb8009
00000000000b8009: 0x20072007
these are the code i use for vga:
Code: Select all
void kmain(void)
{
init_video();
putch('C');
for (;;);
}
Code: Select all
struct {
uint16 *textmemptr;
uint16 attrib;
uint16 csr_x ,csr_y;
}VGA;
Code: Select all
void scroll()
{
uint16 blank, temp;
blank = 0x20 | (VGA.attrib << 8);
if(VGA.csr_y >= 25)
{
temp = VGA.csr_y - 25 + 1;
memcpyw (VGA.textmemptr, VGA.textmemptr + temp * 80, (25 - temp) * 80 * 2);
memsetw (VGA.textmemptr + (25 - temp) * 80, blank, 80);
VGA.csr_y = 25 - 1;
}
}
void move_csr()
{
uint8 temp;
temp = VGA.csr_y * 80 + VGA.csr_x;
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
void cls()
{
uint16 blank;
int i;
blank = 0x20 | (VGA.attrib << 8);
for(i = 0; i < 25; i++)
memsetw (VGA.textmemptr + i * 80, blank, 80);
VGA.csr_x = 0;
VGA.csr_y = 0;
move_csr();
}
void putch(uint8 c)
{
uint16 *where;
uint16 att = VGA.attrib << 8;
if(c == 0x08)
{
if(VGA.csr_x != 0) VGA.csr_x--;
}
else if(c == 0x09)
{
VGA.csr_x = (VGA.csr_x + 8) & ~(8 - 1);
}
else if(c == '\r')
{
VGA.csr_x = 0;
}
else if(c == '\n')
{
VGA.csr_x = 0;
VGA.csr_y++;
}
else if(c >= ' ')
{
where = VGA.textmemptr + (VGA.csr_y * 80 + VGA.csr_x);
*where = c | att;
VGA.csr_x++;
}
if(VGA.csr_x >= 80)
{
VGA.csr_x = 0;
VGA.csr_y++;
}
scroll();
move_csr();
}
void init_video()
{
VGA.textmemptr = (uint16 *)0xb8000;
VGA.attrib = 0x0F;
VGA.csr_x = 0;
VGA.csr_y = 0;
cls();
}