Trying to get a string printed on screen
Posted: Fri Mar 20, 2009 3:45 am
Hi,
i'v done the bare bones tutorial and now i'm trying go write a small lib for i/o. Actually i'm on the functions for printing on screen.
I've done a function for printing a char on the screen, located 1 after the last char (code for this is attached after my post).
Now i'll try to write a function for printing a whole string instead of only on character, but it prints nothin....
Here's the code, which isn't working.
This is the code for only one character, it's working:
i'v done the bare bones tutorial and now i'm trying go write a small lib for i/o. Actually i'm on the functions for printing on screen.
I've done a function for printing a char on the screen, located 1 after the last char (code for this is attached after my post).
Now i'll try to write a function for printing a whole string instead of only on character, but it prints nothin....
Here's the code, which isn't working.
Code: Select all
void print(char str[]);
.....
print("hi");
.....
void print(char str[]) {
unsigned int count=0;
while(str[count] != 0) {
printc(str[count]);
count++;
}
}
Code: Select all
void printc(unsigned char c) {
unsigned char *videoram = (unsigned char *) 0xB8000;
unsigned char *video_mode = (unsigned char *) 0x500;
unsigned char x = video_mode[0];
unsigned char y = video_mode[1];
unsigned char color = video_mode[2];
int pos_char = (x*2)+(y*160);
videoram[pos_char] = c;
videoram[pos_char+1] = color;
x++;
if(x == 80) {
x = 0;
y++;
}
if(y == 25) {
y = 0;
}
video_mode[0] = x;
video_mode[1] = y;
set_cursor(x, y);
}