Printing to the screen

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.
Locked
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Printing to the screen

Post by gsingh2011 »

This code is giving me the errors:

Source Files/kernel.c:17: error: expected ‘;’ before ‘)’ token
Source Files/kernel.c:17: error: expected expression before ‘)’ token

but I have all of my ; in the right places so I can't figure out what's wrong with it...

Code: Select all

volatile unsigned char* videoram = (volatile unsigned char *) 0xb8000;

void printstr(char string[])
{
	int i = 0;
	for (i = 0, i < 2, i++)
	{
		videoram[2*i] = string[i];
		videoram[1+(2*i)] = 0x07;
	}
}

void kmain( void* mbd, unsigned int magic )
{
	printstr("Hi");
}
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Printing to the screen

Post by Firestryke31 »

Is that the whole file as it appears? I'm guessing not, seeing as there's not even 17 lines there. I'd also guess that line 17 is the "void printstr(char string[])" but I may be wrong. IIRC you can't pass variable length arrays in C/C++, but I've always used the fact that (code wise) pointers and arrays are practically interchangeable, so I may be wrong. I would have used "void printstr(char *string)" instead. The function itself would be the same.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Printing to the screen

Post by neon »

Code: Select all

for (i = 0, i < 2, i++)
This is an error. The comma operator has a different function then the use of the semicolon which is used to end expressions. Thus you need to use semicolons not colons. (This is basic C...)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: Printing to the screen

Post by gsingh2011 »

Ah.. Thanks. It's one of those things that happens when you've been sitting at a computer too long..

Anyway, it compiles without errors now but nothing shows up when I run it. Anyone know why?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Printing to the screen

Post by neon »

If you are building it with GCC, insure your linker script has a .rodata section in it.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Printing to the screen

Post by Firestryke31 »

Wow, I completely missed that. I've been staring at ASM for too long...
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Printing to the screen

Post by Troy Martin »

Firestryke31 wrote:I've been staring at ASM for too long...
That's how I feel every time I look at C and find bazillions of things I think are wrong in the code.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
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: Printing to the screen

Post by Combuster »

Okay, you should so seriously not write an OS. You can't write code, you can't debug code. You just failed the required knowledge test.

Go start with the basics and see you again in a year (at the least!)
"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 ]
Locked