Page 4 of 5

Posted: Thu Mar 13, 2008 4:57 am
by eddyb
there isn't any problem, i've made commands which change the color, test some graphs, and they worked.

My problem now is that i want to figure out some gets code (for commands)...

Code: Select all

char gets()
{
	while(text_m[strlen(text_m)-1] != '\n');
	memcpy(&text_ex, &text_m, strlen(&text_m));
	//puts(text_ex);
	memset(text_m, 0, strlen(text_m));
	printf("so, 1: %s\tso, 2:%s\n", &text_ex, &text_m);
	return text_ex;
}

text_ex is an export var. but isn't printed anything on the screen :evil: :(
(printf function works pretty in other cases...)
PS: the wait code wait, indeed :D

Posted: Thu Mar 13, 2008 9:03 am
by jal
eddyb wrote:My problem now is that i want to figure out some gets code (for commands)...
Your problem is that you lack any decent programming skills. Time and time again you make the most basic stupid idiotic mistakes, bugging everyone with your crap. Let's analyze some of your code:

Code: Select all

while(text_m[strlen(text_m)-1] != '\n');
This is a while loop. That means it only terminates if some condition is met. That condition here is "text_m[strlen(text_m)-1] != '\n'". So if there's not a '\n' at the end of the string, the while loop never terminates. And if there is a '\n' at the end, the while loop does exactly nothing, as it is an empty loop.

Code: Select all

memcpy(&text_ex, &text_m, strlen(&text_m));
text_ex and text_m are arrays. Arrays are already pointers. You should never precede them with an ampersand (and in case they are not arrays but char pointers, you take the address of the pointer, not the array they point too - recipe for desaster!). Furthermore, you are doing a memcpy, but use a strlen to determine the length. Why not use strcpy? You'd only not want to use strcpy if you do not want the terminating zero. However, look at the next statement:

Code: Select all

//puts(text_ex);
That assumes text_ex is a zero-terminated string. (Yes, I know it's commented out, but the printf below has the same problem!)

Code: Select all

memset(text_m, 0, strlen(text_m));
Why do you not use sizeof(text_m) instead of strlen(text_m)? Of course text_m could be defined as an external and you do not know the size, but in that case use a #define that sets the buffer's length, to be used in both the variable declaration and the memset.

Code: Select all

printf("so, 1: %s\tso, 2:%s\n", &text_ex, &text_m);
Again, don't use an ampersand for text_ex and text_m as they are arrays (and, worse, if they are char pointers, you use the address of the char pointer instead of the pointer itself, which is desastrous). Also, text_ex is not guaranteed to be zero-terminated as you use memcpy instead of strcpy (see above), amd text_m is an empty string as you've just emptied it, so why print it?

Code: Select all

return text_ex;
You have thread unsafe code, as I bet text_ex is just a global, and not situated in the thread local storage?

text_ex is an export var.
There's no such thing as an "export var" in C. And please stop using all these stupid smileys.


JAL

Posted: Thu Mar 13, 2008 10:31 am
by eddyb
my sorries...
yah, this is my stile....
i think i need to make getchar() first...
doesn't matter ...

Posted: Thu Mar 13, 2008 10:44 am
by Paw
eddyb wrote:my sorries...
yah, this is my stile....
i think i need to make getchar() first...
doesn't matter ...
You didn't actually read and understand what Jal was trying to tell you. It's not a matter of style. It's a matter of producing functional code in the first place. This cannot be accomplished by mimicking what is supposed to be C or guessing what you want to write. You need to learn and understand the language.

Posted: Thu Mar 13, 2008 11:04 am
by eddyb
ok, got getchar code:

Code: Select all

char getch()
{
	if(!ex)
		while(!ex);
	ex = 0;	
	return text_buf;
}
let's explain:
1)
ex: it's a volatile interger(thanks for volatile tip :wink: ) that if is set, the value in text_buf is new. ex is set by KB handler.
text_buf: it's a char that contains the newest key pressed
2)
if isn't a new value, wait until a new value is in text_buf.
when a new value is got, unset ex, because we use that value.
then, return text_buf.

Posted: Thu Mar 13, 2008 11:52 am
by Combuster
There's a race condition in there. :roll:

EDIT: And you still didn't read what JAL said. Is it a habit of you to not listen? I caught you twice posting copyrighted material, and you didn't listen when I said you should read the license, and made EXACTLY the same mistake again.

Posted: Thu Mar 13, 2008 2:25 pm
by jal

Code: Select all

if(!ex)
		while(!ex);
The if is superfluous, because if ex is set, the while loop is not called, but if you had only the while loop, it would skip as well if ex is set. It seems you do not even understand the very basics of structured programming. Also, 'ex' is a lousy variable name, as it does not give away it's meaning.

Code: Select all

ex = 0;
You are trying to make a kind of signalling or synchronisation here between the keyboard handler and the library code. However, testing and setting a global variable by two different threads (or by the main code and an interrupt handler) should always be atomic. This is no way, not even close, of synchronizing.
ex: it's a volatile integer that if is set, the value in text_buf is new. ex is set by KB handler.
text_buf: it's a char that contains the newest key pressed
Another misnomer: if the variable contains the newest key pressed, then why do you call it "text" and "buffer"? There's no text in there. text_buf implies that you have a buffer filled with text. And like I said above, this is a horrible approach that will fail in any but the most simple circumstances.
if isn't a new value, wait until a new value is in text_buf.
when a new value is got, unset ex, because we use that value.
then, return text_buf.
The basic idea is somewhat right. The implementation of it is mindboggling simplistic. I do not really think you're an idiot for producing such code (we all have to learn at some point), but I do think you're an idiot for trying to do OS development, as you have obviously not even 1% of the skills required.


JAL

Posted: Fri Mar 14, 2008 12:39 am
by eddyb
I've a big problem with understanding English...
cause I'm a 12 years boy that learned English in 2 weeks cause my English teacher explained like hell.

jal has right. but these functions are raw(the first was more an trying and the second wasn't finished completely). with the if before while is right, that remain there but I've removed. text_buf i have it before and it remain there. i've not understand the problem with ex. i have such "flags vars" also, at mouse driver.

Posted: Fri Mar 14, 2008 1:39 am
by jal
eddyb wrote:I've a big problem with understanding English...
cause I'm a 12 years boy that learned English in 2 weeks cause my English teacher explained like hell.
Well, that explains it all. You should have told before, I'd be less hard on you :). For a 12-year old beginner, your code is not so bad (nor your English). However, I would advise you to first study programming in general, making application programs etc., then try OS development. OS development is one of the most difficult areas of programming (some say the most difficult, but personally I think (modern) games programming is even more difficult), and can only be tried if one is a really proficient programmer. It's like taking a 2-day course in general engineering, then expect to be able to build a car or a house. You'd be doomed to fail.


JAL

Posted: Fri Mar 14, 2008 2:05 am
by zaleschiemilgabriel
Your English is pretty good for a 12 year old. :)

Posted: Fri Mar 14, 2008 8:40 am
by eddyb
jal wrote:However, I would advise you to first study programming in general, making application programs etc., then try OS development. OS development is one of the most difficult areas of programming (some say the most difficult, but personally I think (modern) games programming is even more difficult)
I've developed a lot on .netfx, in Visual Basic, Visual C#, even XNA (that is a framework on DirectX for game programming). But I've never had an idea for something new. so, I've came to OS developing, where i really can do something new.

Posted: Fri Mar 14, 2008 8:45 am
by zaleschiemilgabriel
Well, you have lots of managed/high-level programming experience, but that's not what you need here. OS development is low-level stuff. It's basically what stands at the far end of the tunnel you're in. :)

Re: loops...

Posted: Fri Mar 14, 2008 9:06 am
by eddyb
Brendan wrote: It's much much more likely that your IRQ isn't firing, that you've disabled IRQs (e.g. the CLI instruction), that you failed to send an EOI, that you didn't tell the compiler that "timer_ticks" is volatile, or something else.
Brendan said about EOI, but i never had the idea that mean end of interrupt...

ON:
"Parallels encountered an internal exception......":

Code: Select all

char *gets()
{
	char temp[]="";
	char tc;
	while(tc!='\n')
	{
		tc = getch();
		temp[strlen(temp)] = tc;
	}
	//temp[strlen(temp)] = '\0';
	return temp;
}
yah. i hate strings...

Posted: Fri Mar 14, 2008 9:21 am
by Combuster
eddyb wrote:I've developed a lot on .netfx, in Visual Basic, Visual C#, even XNA (that is a framework on DirectX for game programming). But I've never had an idea for something new. so, I've came to OS developing, where i really can do something new.
Which brings us to the conclusion that you miss at least three of the prerequisites:
1) no assembly
2) no C
3) no knowledge on hardware internals.
jal wrote:However, I would advise you to first study programming in general, making application programs etc., then try OS development. OS development is one of the most difficult areas of programming (some say the most difficult, but personally I think (modern) games programming is even more difficult)
I wrote a 3D platformer, submitted it for a compo, and won, while I spent only half time on it compared to all my OS work, which isn't exactly something to show off with yet.
Apart from that, you have libraries and tools at various levels in the game development world, which lack in OSdev world.

Posted: Fri Mar 14, 2008 2:11 pm
by jal
Combuster wrote:I wrote a 3D platformer, submitted it for a compo, and won,
Just fmi, what compo was that?
while I spent only half time on it compared to all my OS work, which isn't exactly something to show off with yet.
Apart from that, you have libraries and tools at various levels in the game development world, which lack in OSdev world.
Sure, but I'd hate to have to code a modern 3D engine with all the physics and stuff. But I'm just terrible at maths, that doesn't help either. I'm not talking about a Rick Dangerous clone here, of course :).


JAL