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 !
Spocky
2nd Star Corporal
Posts: 28
Joined: Sun Nov 18, 2012 10:56 am
Location: Melun (France)

alternate one character color

Post 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")?
User avatar
polluks
Pilot Officer
Posts: 76
Joined: Tue Jun 05, 2012 10:09 pm
Location: Germany
Contact:

Re: alternate one character color

Post by polluks »

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: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: alternate one character color

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

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: 4438
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post by Dbug »

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 »

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: 4438
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post by Dbug »

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 »

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: 4438
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: alternate one character color

Post 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!
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 »

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: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: alternate one character color

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