alternate one character color

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
Post Reply
Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

alternate one character color

Post by Spocky » Thu Jan 03, 2013 5:57 pm

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")?

User avatar
polluks
Officer Cadet
Posts: 52
Joined: Tue Jun 05, 2012 10:09 pm
Location: Germany
Contact:

Re: alternate one character color

Post by polluks » Fri Jan 04, 2013 2:35 am

BTW if you write

Code: Select all

hchar('R',0,1);
you don't need a comment :wink:
cc65 development
Oric Atmos + Cumulus
Acorn Electron

User avatar
Chema
Game master
Posts: 1973
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: alternate one character color

Post by Chema » Fri Jan 04, 2013 2:27 pm

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).

Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

Re: alternate one character color

Post by Spocky » Fri Jan 04, 2013 3:02 pm

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:

User avatar
Dbug
Site Admin
Posts: 2325
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post by Dbug » Sat Jan 05, 2013 8:00 pm

Code: Select all

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

Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

Re: alternate one character color

Post by Spocky » Sat Jan 05, 2013 9:06 pm

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

User avatar
Dbug
Site Admin
Posts: 2325
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post by Dbug » Sat Jan 05, 2013 11:15 pm

Apparently the values returned by clock() are decrementing unsigned int, try to use "unsigned int" for your intermediate value storing.

Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

Re: alternate one character color

Post by Spocky » Sun Jan 06, 2013 4:02 pm

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

User avatar
Dbug
Site Admin
Posts: 2325
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post by Dbug » Sun Jan 06, 2013 10:41 pm

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!

Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

Re: alternate one character color

Post by Spocky » Sun Jan 06, 2013 10:48 pm

I don't like to have it in my code too because it's as if I didn't think as I should :wink:

User avatar
Chema
Game master
Posts: 1973
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: alternate one character color

Post by Chema » Tue Jan 08, 2013 2:08 pm

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...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest