Re: [cc65] Strange cc65 generation?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-10-15 22:33:52
On Thu, Oct 15, 2009 at 10:16:39PM +0200, Carlos wrote:
> This second function seems to work fine, so i conclude there are something
> wrong in the first case. Any idea? What's exactly means the jsr boolult
> sentence?

No, there is nothing wrong in the first case. boolugt converts cpu flags into
a boolean value and sets the Z flag accordingly. It is not as optimal as it
could be, but the code itself is correct.

You didn't specify which compiler you're using. I assume it's an older
version, since 2.13 generates almost perfect code (without a call to boolugt):

------------------------------------------------------------------------------
;
; if ((VIC.ctrl1 & 0x80) == 0x0) {
;
        lda     $D011
        and     #$80
        bne     L0009
;
; while (VIC.rasterline < 0xfb);
;
L000F:  lda     $D012
        cmp     #$FB
        bcc     L000F
;
; }
;
L0009:  rts
------------------------------------------------------------------------------

Hint: If you want to check bit 7 (the sign bit) of $D011, you can do that by
saying so:

------------------------------------------------------------------------------
static void waitraster (void)
{
    if ((signed char)VIC.ctrl1 >= 0)
        while (VIC.rasterline < 0xfb);
    }
}
------------------------------------------------------------------------------

Now, the generated code looks like hand written assembly:

------------------------------------------------------------------------------
;
; if ((signed char)VIC.ctrl1 >= 0) {
;
        ldx     $D011
        bmi     L0008
;
; while (VIC.rasterline < 0xfb);
;
L000E:  lda     $D012
        cmp     #$FB
        bcc     L000E
;
; }
;
L0008:  rts
------------------------------------------------------------------------------

Please note that using "__fastcall__" in a function with no parameters has no
effect.

The VIC is also able to generate an interrupt if it reaches a programmable
scan line. Using this feature may be better suited to your needs.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Oct 15 22:36:45 2009

This archive was generated by hypermail 2.1.8 : 2009-10-15 22:36:47 CEST