Re: [cc65] ATARI Multijoy Joystickdriver

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-01-01 22:17:26


Hi!

On Wed, Jan 01, 2003 at 09:32:48PM +0100, Christian Groessler wrote:
> Looking at libsrc/cbm/where.s this is not done. Is this a bug? Or
> should every C callable function which is defined as returning a char
> in fact return an int?

Yes it should. The C standard calls this "int promotion". Expressions are
always evaluated with type int, never using smaller data types. For cc65, int
promotion is done when loading the character into the primary register (a/x).
The original compiler had signed characters, which meant that sign extension
was quite expensive, and doing it when loading saved some code.

The effect of having sign extension when loading is that the compiler expects
that a char data type is always extended to an int. Using

        unsigned char count = joy_count ();

is no problem when joy_count() does not set the X register, but

        unsigned count = joy_count ();

is, because the compiler doesn't do the conversion from char to int, so the
high byte is wrong.

Regarding the code in where.s: It is wrong. In this case however, it is almost
never a problem, since the respective goto... functions will ignore the high
byte of the passed coordinates, so things like

        gotox (wherex () + 1);

or

        unsigned X = wherex ();
        unsigned Y = wherey ();
        ...
        gotoxy (X++, Y - 5);

will always work. There are constructs that will not work, but they are not
very common.

If you are archiving your mail, you may want to have a look at our private
mail exchange starting "Sat, 25 Mar 2000 11:56:16 +0100", where I explained
exactly the same thing to you:-)

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de 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 : 2003-01-01 22:17:33 CET