no vga output
Posted: Mon Sep 26, 2005 3:20 pm
hi!
I tried to write a kernel to test some of the stuff I read about, but it doesn't seem to do anything Just a black screen and then nothing
I just call
in main()
Here's the VGA code:
I tried to write a kernel to test some of the stuff I read about, but it doesn't seem to do anything Just a black screen and then nothing
I just call
Code: Select all
cls();
puts("foobar!");
Here's the VGA code:
Code: Select all
#include "system.h"
unsigned short *videomem = (unsigned short *)0xB8000;;
unsigned int cursor_x = 0, cursor_y = 0;
unsigned char color = 0x0F, clearcolor = 0x0F;
void update_cursor()
{
unsigned temp;
/* The equation for finding the index in a linear
* chunk of memory can be represented by:
* Index = [(y * width) + x] */
temp = cursor_y * 80 + cursor_x;
/* This sends a command to indicies 14 and 15 in the
* CRT Control Register of the VGA controller. These
* are the high and low bytes of the index that show
* where the hardware cursor is to be 'blinking'. To
* learn more, you should look up some VGA specific
* programming documents. A great start to graphics:
* http://www.brackeen.com/home/vga */
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
// Clears the screen
void cls() {
unsigned short blank = 0x20 | (clearcolor << 8); // A blank character
int i;
for(i = 0; i < 25; i++) // Loop through all rows
memsetw(videomem + i*80, blank, 80); // Clear one row
cursor_x = 0; // Move the cursor
cursor_y = 0;
update_cursor();
}
// These functions set your output color. Top four bytes are background, last for are foreground (text) color
void setClearColor(int fg, int bg) {
clearcolor = (bg << 4) | (fg & 0x0F);
}
void setColor(int fg, int bg) {
color = (bg << 4) | (fg & 0x0F);
}
void scroll(){
if(cursor_y > 24) {
unsigned short blank = 0x20 | (clearcolor << 8); // A blank character
memcpy(videomem, videomem + 80, 80 * 24);
memsetw(videomem + 24*80, blank, 80);
cursor_y = 24;
update_cursor();
}
}
void putch(unsigned char c) {
unsigned short *where = videomem + (80 * cursor_y + cursor_x);
if(c == '\b') { // Backspace character, clear the previous character if we're not at the beginning of the line
if(cursor_x != 0) {
cursor_x--;
*where = 0x20 | (clearcolor << 8);
}
} else if (c == '\t') { // A tab character, move the cursor to a point where cursor_x is divisible by 8
cursor_x = (cursor_x + 8) & ~(8 - 1);
if(cursor_x >= 79) { // end of line
cursor_x = 7;
cursor_y++;
scroll();
}
} else if (c == '\n') { // Newline, go to the beginning of the next line.
cursor_x = 0;
cursor_y++;
scroll();
} else if (c == '\r') {
cursor_x = 0;
} else if (c >= ' ') {
*where = c | (color << 8);
if(cursor_x >= 79) {
cursor_x = 0;
cursor_y++;
scroll();
} else {
cursor_x++;
}
}
update_cursor();
}
void puts(unsigned char *text) {
int i;
for(i = 0; i < strlen(text); i++)
putch(text[i]);
}
void initvga() {
videomem = (unsigned short *)0xB8000;
cls();
}