Re: [cc65] Own parameter call stack?

From: Karri Kaksonen <karri1sipo.fi>
Date: 2009-09-03 12:12:29
Ullrich von Bassewitz wrote:
> On Thu, Sep 03, 2009 at 08:10:35AM +0200, Oliver Schmidt wrote:
>   
>>> Whow, that's really respectable.
>>>       
>> Maybe a case for the cc65 web site 'Links' section?
>>     
>
> Yes, good idea! Karri, do you have a project page or something? I would like
> to add a link from the cc65 pages.
>
> Regards
>
>
>         Uz
>
>
>   

Well... Not really. I only have my home computer that has a public 
address sipo.fi
But it is only accessible now and then.

Perhaps AtariAge could add it somewhere. Or perhaps I could add it to 
the contrib section at cc65.org?

Another thing is that the new compiler messes with the code and 
introduced bugs in gameplay. The piles don't scroll as they should 
anymore :(

It appears that this routine (very bad code by me - just a last minute 
hack) produces a zero always. Before it returned many values.

int getOffY(Pile *pile, int card_in_pile, unsigned char start, unsigned 
char end, int ds)
{
    int count;

    count = Pile_cardsLeft(pile);
    if (count > start) {
        while (count - card_in_pile > end) {
            --count;
        }
        return -ds * (count - start);
    }
    return 0;
}

The good old compiler produced code like this:
; ---------------------------------------------------------------
; int __near__ getOffY (__near__ struct $anon-struct-0008*, int, 
unsigned char, unsigned char, int)
; ---------------------------------------------------------------

.segment    "CARDS_CODE"

.proc    _getOffY: near

.segment    "CARDS_BSS"

L0074:
    .res    2,$00

.segment    "CARDS_CODE"

;
; count = Pile_cardsLeft(pile);
;
    ldy     #$09
    jsr     pushwysp
    jsr     _Pile_cardsLeft
    sta     L0074
    stx     L0074+1
;
; if (count > start) {
;
    jsr     pushax
    ldy     #$05
    ldx     #$00
    lda     (sp),y
    jsr     tosicmp
    bcc     L0078
    beq     L0078
;
; while (count - card_in_pile > end) {
;
L007A:    lda     L0074
    ldx     L0074+1
    jsr     pushax
    ldy     #$07
    jsr     ldaxysp
    jsr     tossubax
    jsr     pushax
    ldy     #$04
    ldx     #$00
    lda     (sp),y
    jsr     tosicmp
    bcc     L007B
    beq     L007B
;
; --count;
;
    sec
    lda     L0074
    sbc     #$01
    sta     L0074
    bcs     L007A
    dec     L0074+1
;
; }
;
    bra     L007A
;
; return -ds * (count - start);
;
L007B:    jsr     ldax0sp
    jsr     negax
    jsr     pushax
    lda     L0074
    ldx     L0074+1
    jsr     pushax
    ldy     #$07
    lda     (sp),y
    jsr     tossuba0
    jsr     tosumulax
    jmp     incsp8
;
; return 0;
;
L0078:    ldx     #$00
    txa
;
; }
;
    jmp     incsp8

.endproc

The current buggy compiler produces code like this:
; ---------------------------------------------------------------
; int __near__ getOffY (__near__ struct $anon-struct-0008*, int, 
unsigned char, unsigned char, int)
; ---------------------------------------------------------------

.segment    "CARDS_CODE"

.proc    _getOffY: near

.segment    "CARDS_BSS"

L0074:
    .res    2,$00

.segment    "CARDS_CODE"

;
; count = Pile_cardsLeft(pile);
;
    ldy     #$09
    jsr     pushwysp
    jsr     _Pile_cardsLeft
    sta     L0074
    stx     L0074+1
;
; if (count > start) {
;
    ldy     #$03
    cmp     (sp),y
    txa
    sbc     #$00
    bcc     L0078
    beq     L0078
;
; while (count - card_in_pile > end) {
;
L007A:    lda     L0074
    sec
    ldy     #$04
    sbc     (sp),y
    pha
    lda     L0074+1
    iny
    sbc     (sp),y
    tax
    pla
    ldy     #$02
    cmp     (sp),y
    txa
    sbc     #$00
    bcc     L007B
    beq     L007B
;
; --count;
;
    lda     L0074
    sec
    sbc     #$01
    sta     L0074
    bcs     L007A
    dec     L0074+1
;
; }
;
    bra     L007A
;
; return -ds * (count - start);
;
L007B:    jsr     ldax0sp
    jsr     negax
    jsr     pushax
    lda     L0074
    sec
    ldy     #$05
    sbc     (sp),y
    pha
    lda     L0074+1
    sbc     #$00
    tax
    pla
    jsr     tosumulax
    jmp     incsp8
;
; return 0;
;
L0078:    ldx     #$00
    txa
;
; }
;
    jmp     incsp8

.endproc

--
Karri

----------------------------------------------------------------------
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 Sep 3 12:12:41 2009

This archive was generated by hypermail 2.1.8 : 2009-09-03 12:12:44 CEST