Page 1 of 1

alternate one character color

Posted: Thu Jan 03, 2013 5:57 pm
by Spocky
Hello everyone.

I'm making some C code for a little demo I've begin. During the intro I want to make a "RUN" follow by a square who will be white and black during some time. But when I try this code (I'm in hires mode):

Code: Select all

	curset(18,10,3);
	hchar(0x52,0,1);//R
	curset(18+7,10,3);
	hchar(0x55,0,1);//U
	curset(18+14,10,3);
	hchar(0x4E,0,1);//N
	
	while(i<10)
		{
			curset(18+21,9,3);
			hchar(0x7F,0,1);
			tmp=clock();
			while((tmp-clock())<150){}
			curset(18+21,9,3);
			hchar(0x7F,0,0);
			tmp=clock();
			while((tmp-clock())<150){}
			i++;
		}
I have only a white square. How can I do what I want (It's only for the square of course not for the "RUN")?

Re: alternate one character color

Posted: Fri Jan 04, 2013 2:35 am
by polluks
BTW if you write

Code: Select all

hchar('R',0,1);
you don't need a comment :wink:

Re: alternate one character color

Posted: Fri Jan 04, 2013 2:27 pm
by Chema
Hi Spocky,

I have never used the hchar C function, but it calls the ROM routine for diplaying characters in HIRES (CHAR). If that is the case, then your idea should work.

This BASIC code does it:

Code: Select all

 5 HIRES
 6 CURSET 120,100,3
 10 CHAR #7F,0,1
 20 WAIT 20
 30 CHAR #7F,0,0
 35 WAIT 20
 40 GOTO 10
However I think there is not a C wrapper for the wait function, so I guess that is what you are trying to do with your while loops and clock. Maybe the error is there. The vars accessed by clock decrement each 1/100th of a second, I think, so 150 would be something like 1.5 secs, which is enough.

Mmmm... not sure what could be happening here. Maybe the code is being optimized as to remove the while loops (as they do nothing)? Maybe there is an error in the implementation of clock?. Maybe an error in the compiler? (I sometimes had to make a variable global to avoid strange errors).

I'd try to change the loops to something like for(i=0;i<10000;i++); and see what happens. If that fails, try to put a getchar(); and see if it blinks when you press return...

Still there is a much much simpler solution to your problem. Use the flashing attribute. Plot a flash attribute, plot the square, plot a remove flash attribute. The flash attribute must be plotted at each of the 8 rows the char uses, of course...

And, beware, hchar is extremely slow. There are much faster ways of plotting chars on hires screen (like simply copying the data in the charset area into the HIRES screen).

Re: alternate one character color

Posted: Fri Jan 04, 2013 3:02 pm
by Spocky
I've try to put the getchar function and it's work as I want.

So as you said, I should have a probelem with my method to make a wait but also as you said, I've seen nothing to make a wait with C code. So I will search for it. Could be really interesting to be able to make this.

Thanks for the help :wink:

Re: alternate one character color

Posted: Sat Jan 05, 2013 8:00 pm
by Dbug

Code: Select all

while((tmp-clock())<150){}
Should it not be "clock()-tmp" instead?

Re: alternate one character color

Posted: Sat Jan 05, 2013 9:06 pm
by Spocky
I've tried the clock()-tmp version. The only things I have is a freeze and I don't know why. So I will keep the for method I think

Re: alternate one character color

Posted: Sat Jan 05, 2013 11:15 pm
by Dbug
Apparently the values returned by clock() are decrementing unsigned int, try to use "unsigned int" for your intermediate value storing.

Re: alternate one character color

Posted: Sun Jan 06, 2013 4:02 pm
by Spocky
With this is good.

So put the tmp as unsigned int and the code is:

Code: Select all

			tmp=clock();
			while((tmp-clock())<100){};
Thanks for your help

Re: alternate one character color

Posted: Sun Jan 06, 2013 10:41 pm
by Dbug
You are welcome :)

It's the kind of thing I like to actually solve, because I don't like the idea of having wrongly generated code in the sdk!

Re: alternate one character color

Posted: Sun Jan 06, 2013 10:48 pm
by Spocky
I don't like to have it in my code too because it's as if I didn't think as I should :wink:

Re: alternate one character color

Posted: Tue Jan 08, 2013 2:08 pm
by Chema
Argh, should have guessed there was an easy and more obvious explanation for all this...

Anyway, it is still maybe worth considering the flash attribute option...