Jump to content
IGNORED

cc65 arguments to assembler .. confused


Recommended Posts

Hello.

 

I'm trying to debug my routine called from c to assembler

 

AFAIK, last argument is always in accumulator, like this :

 

; void __fastcall__ _setcolor     (unsigned char color_reg, unsigned char hue, unsigned char luminace);

.proc   __setcolor
        sta     lum             ; remember luminance
        jsr     popa            ; get hue
        asl     a


and then popa, gets the arguments right to left.

however, I see some calls that get the rightmost element manually, and define the external and internal function

 

gotoxy:
        jsr     popa            ; Get Y

_gotoxy:                        ; Set the cursor position
        sta     ROWCRS          ; Set Y
        jsr     popa            ; Get X
        sta     COLCRS          ; Set X


I tried both, bit is seems there is no difference, and what is the calling convention ?
 

Link to comment
Share on other sites

The better way is to use page zero (or some other unused memory area) to set parameters.  In the assembly file you'll define equates pointing to that memory area.  This will result in smaller/faster code -- CC65 is great but passing parameters the conventional way will generate slower code.

 

For setting Atari specific registers check out atari.h.  You can set ROWCRS / COLCRS directly from C vs. calling a routine to do so.

  • Like 1
Link to comment
Share on other sites

Hi!

1 hour ago, Mariano DM said:

Hello.

 

I'm trying to debug my routine called from c to assembler

 

AFAIK, last argument is always in accumulator, like this :
 

; void __fastcall__ _setcolor     (unsigned char color_reg, unsigned char hue, unsigned char luminace);

.proc   __setcolor
        sta     lum             ; remember luminance
        jsr     popa            ; get hue
        asl     a


and then popa, gets the arguments right to left.

This is for "fastcall" functions, you can also define "cdecl" functions that pass all arguments via the stack. It is important that you declare the function in C with the correct keyword, as the default can change - if a function is not properly declared it won't work correctly.

 

1 hour ago, Mariano DM said:

however, I see some calls that get the rightmost element manually, and define the external and internal function

gotoxy:
        jsr     popa            ; Get Y

_gotoxy:                        ; Set the cursor position
        sta     ROWCRS          ; Set Y
        jsr     popa            ; Get X
        sta     COLCRS          ; Set X

 

Here, `_gotoxy` is the function called from C (the compiler adds an underscore at the start of all C symbols), so it works just like above. The `gooxy` without underscore is called from other functions, not from C code.

 

1 hour ago, Mariano DM said:

I tried both, bit is seems there is no difference, and what is the calling convention ?

Here is the documentation: https://cc65.github.io/doc/cc65-intern.html#toc1.1

 

Note that the *rightmost* parameter is passed in A/X/sreg, this is the last parameter in the C argument list.

 

Have Fun!

  • Like 1
Link to comment
Share on other sites

yay ! working now.

ended up making a routine to print the argument in screen. arguments were passed as expected I guess I need to figure out how to work this in atari800 monitor

 

; print a single byte in screen+y_register, restores x and accumulator
__debug:
       sta tval
       txa 
       pha ; save x
       lda tval
       adc #16  ;use icode for numbers 0-9
       clc
       sta (SAVMSC),y
       pla 
       tax ; restore x
       lda tval
       rts

 

Link to comment
Share on other sites

16 hours ago, damosan said:

The better way is to use page zero (or some other unused memory area) to set parameters.  In the assembly file you'll define equates pointing to that memory area.  This will result in smaller/faster code -- CC65 is great but passing parameters the conventional way will generate slower code.

 

optimization.png

(https://www.explainxkcd.com/wiki/index.php/1691:_Optimization)

Edited by Irgendwer
  • Haha 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...