Re: [cc65] odd results

Date view Thread view Subject view

From: troy silvey (
Date: 2001-02-26 04:17:07

>Is this the whole routine? What is 'more'? Is the second if (more==1) 
>ever true?

This is the complete routine. It waits for  either the space bar
to be pressed (60) to change the menu choice, or the return key
 (1) to make the choice and exit the routine. If the space bar is
pressed, the sprite is moved, pmenu is incremented and
flow returns to the top of the routine to wait for the next
key press. pmenu ranges form 255(-1) to 7.
 *time is the jiffy clock to add a delay to key
presses and *clearkeybuffer keeps the buffer from spraying
charters on the screen when I get to other routines.
'more' is just a reusable global variable.
The routine exits when "return" key (1) is pressed. It is supposed
to return the value pmenu to be used in a switch routine.
pmenu holds the right values in this routine, but nothing
is returned to the calling main function. This is the same
function I found the bug in with the VIC.spr0_y=VIC.spr0_y+4;
statments, so I wondered if there was a  bug with the
return value. 

*** update to trouble shooting
Here is what I found........

I have been using VisualC++ 6 as my editor. My code is
simple and Ansi enough that it will compile with VC++
without errors.  It has great syntax error catching for a
newbie like me.
This function was  originally written with
out the return value at the end of the function. I want to
exit the function when more==1 and continue in a loop
if it is not. VC++ gave a warning about the missing
return at the end of the function, even though the
intended return was in the (more==1) subroutine. I added the
bogus return to end the warning. When CC65 compiles,
it is not returning the value in the (more==1) block.
it returns the value at the second incorrect return; statement.
It should never reach this second return; . And if I remove
it, the first and proper return statment returns the correct
carry value.  The code is working ok now, but what if I wanted
to return differrent values from different blocks. CC65 is
not sending back the right on in this function.     

I have these lines in main......
    printf("carry = %d ", carry);

carry is a value from 255(-1) to 7 in the function.
I added print statements to prove it in my program.

unsigned char choiceA(unsigned char pmenu)
    while (!((more=*keypress)==60 || more==1))
    if (more==60)
            if (VIC.spr0_y>162)
            if (pmenu>6)
    if (more==1)
             return pmenu; // *** this is when I want to exit
    *time1=0;	// delay the user imput to stop sprite run-a-way
    while (*time1<10)
    return 0; // **** bogus return to make the compiler happy
                     // and the reason I keep getting 0 for a carry value
                     // what ever I put here get returned. not pmenu


Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.

Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET