Text function doesn't work

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
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Text function doesn't work

Post by Pyrofan1 »

Code: Select all

void Putch(unsigned char c,unsigned char forecolor,unsigned char backcolor)
{
     	unsigned short attrib=((backcolor<<4)|(forecolor&0x0F))<<8;
     	unsigned short *where;
	if(c=='\n')
	{
		x_pos=0;
		y_pos++;
	}
	else
	if(c=='\r')
	{
		x_pos=0;
	}
	else
	if(c=='\t')
	{
		Putch(' ',BLACK,BLACK);
		Putch(' ',BLACK,BLACK);
		Putch(' ',BLACK,BLACK);
		Putch(' ',BLACK,BLACK);
		Putch(' ',BLACK,BLACK);
	}
	else
	{
     		where=((unsigned short*)0xB8000)+(y_pos*80+x_pos);
     		*where=c|attrib;
		x_pos++;
	}
} 
when i try to use this function i get no text displayed.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

The only thing that I can think of would be to make sure that x_pos and y_pos are correct.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

make sure that x_pos and y_pos are correct.
thank you, i hate it when it's something simple.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

your tab case seems akward should i not some thing like this for 4 spaces tab. Your code doesn't do tab justice ;-)

Code: Select all

x_pos = (x_pos & ~3) + 4;
Author of COBOS
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

@Pyrofan1

Just a suggestion:

At the point you are at, I would say that you should create a console structure so that you can easily keep track of foreground, bground, x and y easily. Use something like this:

Code: Select all

struct console_t
{
  int x, y;
  char color;
};
And if you really need to get the foreground and background colors out, just do a mask

Code: Select all

foreground = color & 0xF0;
background = color & 0x0F;
(^^^ That should be right, not sure though )

--t0xic
Post Reply