HomeForumsWhat's newResources 
 
 
Tips on this code.....
slinga - Mar 29, 2003
   slinga Mar 29, 2003 

  
if((data & pad_asign[1])== 0)

cursor = cursor++%7;

if((data & pad_asign[0])== 0)

cursor = (cursor--)%7;



How come the first code doesn't work properly, but the second set does?

Cursor is just some test I'll display next to each option in the menu. When the user hits down, the cursor moves down a line, when the user hits up, the cursor moves up. I also wanted the cursor to wrap, meaning if your at the top and you hit up, you reach the bottom. Hence why I used mod. This isn't urgent seeing how I have a work around, but it's bugging me. Thanks in advance.


  
if((data & pad_asign[1])== 0)

cursor = (cursor+1)%7;

if((data & pad_asign[0])== 0)

{

cursor = (cursor-1)%7;

if(cursor<0)

cursor = 6;

}



   slinga Mar 29, 2003 
Something's wrong with the edit option (it's displaying html)...

Anyway, here's another quick question. How do I clear the entire screen? I can do it manually, but I'm sure there's a function I'm overlooking.

system("clear"); does nothing apparently...

   vbt Mar 29, 2003 
to clear text I used "reset_vbar", I'm sure there is a better method to do that and I think there was a function to clear bitmap named something like that : slClearBitMap

   antime Mar 29, 2003 
Slinga, the problem with your code is the use of the postfix operators. The result of a postfix increment or decrement is the value of the expression before the operator is applied, so if cursor happens to be 6, the expression becomes

Code:
  
cursor = 6%7; cursor = cursor +1;
and then you're out of range.

The solution is to use the prefix operators, like so:

Code:
  
if((data & pad_asign[1])== 0) cursor = ++cursor%7; if((data & pad_asign[0])== 0) { cursor = --cursor; if(cursor<0) cursor = 6; }
You still have to check the sign when decrementing, but that's just how math works.

(Disclaimer: I'm not a language lawyer, but that's how I've understood it works.)

   vreuzon Mar 30, 2003 
in sgl302j\DOC0A_US (I guess we use the same antime's archive), a mysterious

file : PACKS.TXT, describing the text debug functions. Here's the reset_vbar part :

Code:
  
****************************************************************************** void set_vbar((Uint16)xps) ****************************************************************************** Function: Displays a vertical bar at x coordinate xps for checking the CPU operation time. ****************************************************************************** void reset_vbar((Uint16)xps) ****************************************************************************** Function: Erases the bar displayed by set_vbar(). Combine the two functions above with slSynch() to monitor CPU usage. Example: while(-1){ slExecuteEvent(); /* Event processing */ reset_vbar(39); /* Vertical bar erase */ slSynch(); /* Wait video sync */ set_vbar(39); /* Display vertical bar */ } Screen display starts immediately after slSynch(), and the vertical bar is written to VRAM. The vertical bar is erased from VRAM after all events have been processed from the start of slExecuteEvent(). Therefore, it is possible to measure CPU use by the length of time the bar is visible on screen. Note: The number of lines used to set characters changes based on the screen resolution. In low resolution (224 or 240 lines), the upper 32 lines are overwritten. In high resolution (448 or 480 lines, interlaced), 64 lines are rewritten.

Slinga : Why dont you write your Code:
  
cursor = ++cursor%7;
in two lines ? It would be more readable, and not slower: trust the compiler.