Page 1 of 1

Purple Text

Posted: Sat Feb 12, 2011 8:56 am
by gareth
Hi! I am new to OS Development. Whenever I run my kernel, I get this:

EDIT: Just to be clearer, the problem is the purple background.

Image

This is my entry:

Code: Select all

#include "io/io.h"
#include "misc/ops.h"
#include "misc/startup_test.h"

void kmain(void* mbd, unsigned int magic)
{
	if(magic != 0x2BADB002)
	{
		put_string("Invalid Magic Number. Maybe you should get a wizard next time!\n");
		k_hang();
	}

	clear_screen();
	k_startup_test();
	put_string("Hello People,\n\nThis is a test.\n\nSee if you can pass it.\n\nYou failed.\n\n");
}
And this is IO.h:

Code: Select all

/* io.h AOS Willow */

#define IO_IO_H

#define WHITE_ON_BLACK 0x07
#define VIDRAM_START 0xB8000
#define VIDRAM_END 0xB8FA0

unsigned char *videoram = (unsigned char *) VIDRAM_START;
const char cursor = '_';

int row = 1;
int column = 1;

void reset_cursor()
{
	*videoram = 0x00; // Erase Cursor
	videoram++;
	*videoram = 0x00;
	row = 1;
	column = 1;
	update_videoram();
}

void update_videoram()
{
	int x = (row - 1) * 160; // Number of characters to skip for rows
	int y = (column - 1); // Number of characters to skip for columns
	videoram = VIDRAM_START + (x + y);
}

void move_cursor(int newrow, int newcolumn)
{
	row = newrow;
	column = newcolumn;
	update_videoram();
	*videoram = cursor; // Set cursor
}

void clear_screen()
{
	reset_cursor();
	for(videoram = VIDRAM_START; videoram < VIDRAM_END; videoram++)
	{
		*videoram = 0x0;
	}
	reset_cursor();
}

void put_char(char data) // Wrapper for put_coloured_char
{
	put_coloured_char(WHITE_ON_BLACK, data);
}

void put_coloured_char(char colour, char data)
{
	*videoram = 0x00; // Remove cursor
	void write_char()
	{
		*videoram = data;
		videoram++;
		*videoram = colour;
		column++;
		update_videoram();
		*videoram = cursor; // Set cursor
		videoram++;
		*videoram = colour;
		videoram--;
		if(column < 160) column++;
		else
		{	
			if(row < 25)
			{
				row++;
				column = 1;
			}

			else clear_screen();
		}

		update_videoram();
	}

	if(videoram <= VIDRAM_END) // Is cursor in bounds?
	{
		if(data == '\n')
		{
			// Newline
			if(row < 25) row++;
			else
			{
				clear_screen();
				return; // Screen has been cleared. No need to continue
			}
			column = 1;
			update_videoram();
		}

		else
		{
			write_char();
		}
	}
	else // Clear screen before printing
	{
		clear_screen();
		write_char();
	}
}


void put_string(const char *string) // Wrapper for put_coloured_string
{
	put_coloured_string(WHITE_ON_BLACK, string);
}

void put_coloured_string(char colour, const char *string)
{
	while(*string != 0)
	{
		put_coloured_char(colour, *string);
		string++;
	}
}
Yes, I know I used a nested function, but I didn't want to include the code twice in the same function for size reasons.

Any help would be greatly appreciated.

Re: Purple Text

Posted: Sat Feb 12, 2011 9:13 am
by NickJohnson
0x07 is not white on black: 0x0F is.

Re: Purple Text

Posted: Sat Feb 12, 2011 9:36 am
by gareth
No luck. Whatever I enter, it still shows the same colours.

Re: Purple Text

Posted: Sat Feb 12, 2011 9:54 am
by gareth
What could the problem be? I've checked over and over! :cry:

Re: Purple Text

Posted: Sat Feb 12, 2011 11:49 am
by neon
Debug your code:

What is the value of 'colour' when it writes it to display?
Does it ever get changed?
What happens if you just write a single character to display with attribute 0x07?
Are their any changes if running on real hardware or other environments?

Re: Purple Text

Posted: Sat Feb 12, 2011 2:42 pm
by MDM
0xF0 (not 0x0F aka 0xF) is black on white, however, it sounds like you've got some form of other problem. Have you tried reading whats in 0xB8000?

Re: Purple Text

Posted: Sat Feb 12, 2011 3:11 pm
by DLBuunk
You are not incrementing the pointer to video-RAM before you write the cursor, so you end up overwriting the attribute byte with an underscore, which happens to encode white on purple.

Re: Purple Text

Posted: Sat Feb 12, 2011 4:41 pm
by gareth
DLBuunk wrote:You are not incrementing the pointer to video-RAM before you write the cursor, so you end up overwriting the attribute byte with an underscore, which happens to encode white on purple.
Thanks, I'll try that tomorrow when I get to that computer.

Cheers.

Re: Purple Text

Posted: Sat Feb 12, 2011 4:43 pm
by gareth
MDM wrote:0xF0 (not 0x0F aka 0xF) is black on white, however, it sounds like you've got some form of other problem. Have you tried reading whats in 0xB8000?
It's supposed to be white on black, but thanks anyway.

Re: Purple Text

Posted: Sat Feb 12, 2011 4:51 pm
by MDM
Ah, excuse my blunder of reading. Black on white is impossible, closest you can get is black on grey (the background color is 3 bits, the fourth bit is the special attribute which doesn't turn grey into white).

Re: Purple Text

Posted: Sat Feb 12, 2011 8:10 pm
by Coty
MDM wrote:Ah, excuse my blunder of reading. Black on white is impossible, closest you can get is black on grey (the background color is 3 bits, the fourth bit is the special attribute which doesn't turn grey into white).
False. Read here; http://forum.osdev.org/viewtopic.php?f=1&t=22632

Re: Purple Text

Posted: Sat Feb 12, 2011 8:28 pm
by MDM
However, as far as I know he hasn't disabled the blinking.

Re: Purple Text

Posted: Mon Feb 14, 2011 3:41 pm
by gareth
gareth wrote:
DLBuunk wrote:You are not incrementing the pointer to video-RAM before you write the cursor, so you end up overwriting the attribute byte with an underscore, which happens to encode white on purple.
Thanks, I'll try that tomorrow when I get to that computer.

Cheers.
Thanks, that worked. Also changed it so it calls move_cursor in the write_char function. Next I'm gonna make the White-On-Black wrapper functions macros to increase speed and decrease size.

Cheers!