Mariano DM Posted January 3, 2023 Share Posted January 3, 2023 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 ? Quote Link to comment Share on other sites More sharing options...
damosan Posted January 3, 2023 Share Posted January 3, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
dmsc Posted January 3, 2023 Share Posted January 3, 2023 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! 1 Quote Link to comment Share on other sites More sharing options...
Mariano DM Posted January 3, 2023 Author Share Posted January 3, 2023 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 Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted January 3, 2023 Share Posted January 3, 2023 (edited) 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. (https://www.explainxkcd.com/wiki/index.php/1691:_Optimization) Edited January 3, 2023 by Irgendwer 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.