Text printing not working (C)

Programming, for all ages and all languages.
Post Reply
niou
Posts: 1
Joined: Fri Aug 24, 2012 1:35 am

Text printing not working (C)

Post by niou »

Hello everybody!

I was happily developing my own kernel and it worked great!
But something went wrong...

This code worked:

Code: Select all

void putch (const char character) {
	volatile ushort *where;
	where = (ushort*)0xb8000 + (1 * 2);
	*where = character | (0x0f << 8);
}
But this one didn't!!

Code: Select all

void putch (const char character) {
	volatile ushort *where;
	ushort x = 1;
	where = (ushort*)0xb8000 + (x * 2);
	*where = character | (0x0f << 8);
}
While the first code prints the character on the screen, the second does nothing!! ):
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Text printing not working (C)

Post by Combuster »

My crystal ball says you're either using CLI;HLT; in a VM or you're not using your compiler properly.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Text printing not working (C)

Post by Nable »

Use bochs debugger, use it one more time, do it harder! (:
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Text printing not working (C)

Post by bluemoon »

It may not be the root cause but...

Code: Select all

ushort x = 1;
where = (ushort*)0xb8000 + (x * 2);
You are mixing ushort for pointer arithmetic, it's not a good habit, try:

Code: Select all

uintptr_t x = 1;
where = (uint16_t*)( (uintptr_t)0xb8000 + x*2 );
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Text printing not working (C)

Post by Love4Boobies »

There's no need for uintptr_t there. But yes, I would also like to complain about using ushort, which doesn't exist.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply