Page 1 of 1

some thing about printing string

Posted: Thu Jan 12, 2012 7:57 pm
by sebastian93921
I'm the beginner or OSdev
but i having a problem in kernel in C language.

Code: Select all

int k_main(void)
{
	kclrscr();
	kprint("Protected Mode process ...\n");
	kprint("First prototype - Sebastian Ko \n\nDate: 12/01/2012\n");
	kprintc("\nNO \\t or value type \n",GRAY_TXT);
	
	kprint("Register checking ... ");
	if(reg() == 0)kprintc("OK\n",GRAY_TXT);
	else kprintc("Fail\n",GRAY_TXT);
	
        return 0;
}
while my kernel is type as above, it will show this output
1.PNG
but while i add the same code with copying kprint("First prototype - Sebastian Ko \n\nDate: 12/01/2012\n"); twice next to the same sentence.
the output will becomes this
2.PNG
Can any people help me ?? :oops:

the Method of kprint and kprintc

Code: Select all

unsigned int line = 0;							//Line in screen (Text)
unsigned int text_pos = 0;						//Text position


//Easiest print method
void kprint(char *message){kprintc(message,0x0B);};


void kprintc(char *message,double text_color)	//Print with change default color
{
	char *vidmem 	= (char *) 0xb8000;			//define video memory
	unsigned int i	= 0;						//define memory position

	i=((line*80*2)+(text_pos*2));				//Memory MUST be line * colume * TxtSpace (160 Means Over Screen of line,line++)	
	
	while(*message!=0)
	{
		if(line > CONSOLE_MAX_LINE)line = 0;
		
		//\n \r \t is 1 char
		if(*message == '\n') 					//Check for a new line
		{	
			text_pos = 0;						//reset text position
			line++;
			i=(line*80*2);
			*message++;
		}else if(*message == '\r'){				//Return to head from line
			text_pos = 0;						//reset text position
			i = (line*80*2);
			*message++;
		}else{									//print Message (Char)
			vidmem[i]=*message;
			*message++;
			i++;
			vidmem[i]=text_color;
			i++;
			text_pos++;
		}
	}
};

Re: some thing about printing string

Posted: Fri Jan 13, 2012 7:23 am
by bluemoon

Code: Select all

*message++;
Are you sure?

Re: some thing about printing string

Posted: Fri Jan 13, 2012 7:46 am
by bluemoon
Yes it works and harmless, but for one engaging OSDev one should not mix up message++ with *message++. For the size of kernel codebase, this habit may lead to unmaintainable code. #-o

Re: some thing about printing string

Posted: Fri Jan 13, 2012 1:02 pm
by sebastian93921
THX for reply :D
i fix the *message++ with no pointer on it now :D
it works!!

and double color I changed to "unsigned int color"
would it be correct?

and why I use message++ but don't use *(message++) since message is a array ?? :(

THX :)

Re: some thing about printing string

Posted: Fri Jan 13, 2012 1:23 pm
by bluemoon
I kindly advice to read the C++ reference for the difference between message++ and *message++.

Re: some thing about printing string

Posted: Sat Jan 14, 2012 11:40 am
by sebastian93921
berkus wrote:
sebastian93921 wrote:and why I use message++ but don't use *(message++) since message is a array ?? :(
message is not an array. It's a pointer. And since you need to learn up what a pointer is, I call for missing Required_Knowledge. It would be beneficial for you to program some applications in C first. You're bound to fail with kernel development.
i know this is a pointer, but the pointer can use message++, such as the message[i++] :(

now i have the problem with changed the code of kprint() with your advice.
but when i executing the kernel by these code.

Code: Select all

int k_main(void)
{
	kclrscr();
	kprint("Anti-Web OS - Protected Mode process ...\n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("First prototype - Sebastian Ko \n");
	kprint("\nDate : ");kprint(COM_DATE);kprint("\n");
	kprintc("\nNO \\t or value type \n",GRAY_TXT);
	
	kprint("Register checking ... ");
	if(reg() == 0)kprintc("OK\n",GRAY_TXT);
	else kprintc("Fail\n",GRAY_TXT);
	
	//for(;;)kgetChar();
	
}
it will having the same problem, like this
1.PNG
is it the problem of the stack pointer of ESP?
how can it fix?

THX :)

Re: some thing about printing string

Posted: Sat Jan 14, 2012 1:41 pm
by VolTeK
I have never used qemu, but i believe it has a debugger.

Problems like those can be solved by you debugging. In fact it will solve ther other 40% (or more) problems you will have in future. Look into it

Re: some thing about printing string

Posted: Sat Jan 14, 2012 4:13 pm
by gravaera
Man, these printf things are so hard to get right. Printf too ADVANCED D:

EDIT: I have a solution, we should dumb things down a bit, like make a multiple-choice version of printf where you choose from a set of predefined messages and distribute it as a library.

Re: some thing about printing string

Posted: Sun Jan 15, 2012 10:46 am
by sebastian93921
gravaera wrote:Man, these printf things are so hard to get right. Printf too ADVANCED D:

EDIT: I have a solution, we should dumb things down a bit, like make a multiple-choice version of printf where you choose from a set of predefined messages and distribute it as a library.
Can you explain more ?? :D
THX

Re: some thing about printing string

Posted: Mon Jan 16, 2012 12:13 am
by sebastian93921
i know the problems now, when i set the floppy drive(load disk?) in bootloader, i just set 2 of sector need to be read in disk :(

Re: some thing about printing string

Posted: Mon Jan 16, 2012 1:52 am
by VolTeK
Did you write your bootloader.