Purple Text

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Purple Text

Post 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.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Purple Text

Post by NickJohnson »

0x07 is not white on black: 0x0F is.
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Re: Purple Text

Post by gareth »

No luck. Whatever I enter, it still shows the same colours.
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Re: Purple Text

Post by gareth »

What could the problem be? I've checked over and over! :cry:
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Purple Text

Post 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?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: Purple Text

Post 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?
DLBuunk
Member
Member
Posts: 39
Joined: Sun May 18, 2008 9:36 am
Location: The Netherlands

Re: Purple Text

Post 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.
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Re: Purple Text

Post 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.
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Re: Purple Text

Post 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.
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: Purple Text

Post 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).
User avatar
Coty
Member
Member
Posts: 286
Joined: Thu Feb 12, 2009 5:12 pm

Re: Purple Text

Post 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
My hero, is Mel.
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: Purple Text

Post by MDM »

However, as far as I know he hasn't disabled the blinking.
gareth
Posts: 6
Joined: Tue Oct 14, 2008 7:43 am

Re: Purple Text

Post 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!
Post Reply