Questions to CC65 users

Questions, bug reports, features requests, ... about the Oric Software Development Kit. Please indicate clearly in the title the related element (OSDK for generic questions, PictConv, FilePack, XA, Euphoric, etc...) to make it easy to locate messages.

Post Reply
User avatar
NekoNoNiaow
Flight Lieutenant
Posts: 272
Joined: Sun Jan 15, 2006 10:08 pm
Location: Montreal, Canadia

Questions to CC65 users

Post by NekoNoNiaow » Tue Jan 15, 2019 2:33 am

Reading the posts around there it seems there are a few people who do actually use CC65 for the Oric on a regular basis.
Since I am dissatisfied with the output of the compiler currently used by the OSDK I am considering switching to CC65 but before I start experimenting with it I figured it would be simpler to ask you guys about it.

- From what I can read, it seems that CC65 is not fully capable of handling 8-bit only variables and will by default use 16 bits ints (it calls that the AX pair if I recall correctly what I read in the docs). Can you guys confirm? Is it possible to have "char" variables which are manipulated using a single register
- Have you had a chance to use CC65 with the library of the OSDK? If so, which adaptations were required?
- Are there ways to put variables in the zero page? The OSDK compiler apparently is aware of the zero page but it does not seem to offer any way to share it or control it explicitly.

Aside from these questions, if you guys were also willing to share your experience of CC65 in terms of ease-of-setup and ease-of-integration with the OSDK that would also be very welcome.

Thanks!
(leaching from the experience of better people ^^)

User avatar
Dbug
Site Admin
Posts: 2986
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Questions to CC65 users

Post by Dbug » Tue Jan 15, 2019 9:18 am

NekoNoNiaow wrote:
Tue Jan 15, 2019 2:33 am
- Are there ways to put variables in the zero page? The OSDK compiler apparently is aware of the zero page but it does not seem to offer any way to share it or control it explicitly.
That's why I declare these variables in assembler modules, using .zero section marker, and in the C file I just use "extern" to access them.

User avatar
iss
Squad Leader
Posts: 890
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Questions to CC65 users

Post by iss » Tue Jan 15, 2019 11:37 am

Here are kind of answers from me :) :
First thing first - what are the sizes of the base types in CC65 and OSDK:

Code: Select all

  printf("char   : %d\n", sizeof(char  ));
  printf("short  : %d\n", sizeof(short ));
  printf("int    : %d\n", sizeof(int   ));
  printf("long   : %d\n", sizeof(long  ));
  printf("float  : %d\n", sizeof(float ));
  printf("double : %d\n", sizeof(double));
result:
sizes.jpg
Keep in mind in CC65 'float' and 'double' are valid type but there is NO support of float point math!
it seems that CC65 is not fully capable of handling 8-bit only variables and will by default use 16 bits ints...
...Is it possible to have "char" variables which are manipulated using a single register
This is easy to check:

Code: Select all

static char i,x,y;
void main(void)
{
  x = 1;
  y = 2;
  i = x + y;
}
It's assembled with CC65 as:

Code: Select all

;
; x = 1;
;
	.dbg	line, "test.c", 36
	lda     #$01
	sta     _x
;
; y = 2;
;
	.dbg	line, "test.c", 37
	lda     #$02
	sta     _y
;
; i = x + y;
;
	.dbg	line, "test.c", 38
	lda     _x
	clc
	adc     _y
	sta     _i
And for the 3rd question DBug already answered - for CC65 works the same - use assembler module to define variable in ZP.

User avatar
iss
Squad Leader
Posts: 890
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Questions to CC65 users

Post by iss » Tue Jan 15, 2019 11:56 am

And for this one:
- Have you had a chance to use CC65 with the library of the OSDK? If so, which adaptations were required?
Yes, but only 'void func(void)' works as is :). There are differences in:
- how the result is returned: OSDK uses A(msb):X(lsb), CC65 uses X(msb):A(lsb). And because I'm always forgetting which one is the correct for the particular compiler, I use a macro at end of assembler function which returns 'int': :)

Code: Select all

#ifdef __OSDK__
#define return(x) .byt $a2, <x, $a9, >x, $60
#else
#define return(x) .byt $a9, <x, $a2, >x, $60
#endif
- how the parameters are passed to functions: in OSDK they are always 16-bit, in CC65 ... hmmm, it depends ... the best is to read CC65 docs. In short, my approach is to avoid functions with parameters - I'm using simply global variables :).

User avatar
Dbug
Site Admin
Posts: 2986
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Questions to CC65 users

Post by Dbug » Tue Jan 15, 2019 2:06 pm

iss wrote:
Tue Jan 15, 2019 11:56 am
In short, my approach is to avoid functions with parameters - I'm using simply global variables :).
That's also the approach I'm using.

Even when the best and tightest tweaks of the universes, the C compiler will always generate shitty code compared to the assembler. It's not a problem of smart engineering, it's a problem of data model not matching the CPU 6502 strengths and weaknesses.

It's definitely possible to improve the parameter passing, better tailor the size of variables, etc... but ultimately there are not enough registers, not enough zero page, not enough stack space, so the only sane solution Fabrice found was to use this crazy second stack that allows us to run almost standard C programs that do recursion and all kind of other crazy things without too much struggle.

It's really the usual balance between performance and features, which is why I recommend CC65 for people who want all the comfort of a toolchain that is designed to be generic portable and using the usual linking system, while the OSDK is for people who want to hack around like there was no tomorrow, look at the generated assemble code, etc...

I would be ok in using CC65 instead of LCC, but I refuse to use the linker and assembler that comes with it, saying that I don't like the syntax is like saying that Linus Torvalds has strong opinion against certain things ;)

User avatar
Chema
Game master
Posts: 2482
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Questions to CC65 users

Post by Chema » Tue Jan 15, 2019 2:32 pm

Dbug wrote:
Tue Jan 15, 2019 2:06 pm
...
+1


Using C is great for prototyping, creating the main structure of your code, small utilities, but far from the needs of serious programming that pushes the limits of the machine. For that, you need asm. Plain and simple.

Mixing C and asm with the current OSDK toolchain is very simple. When Fabrice and I developed Pinforic (not using OSDK, it did not exist yet, but using LCC and frasm) I started with pure C code. I ran out of space, so I went for the global-variables-instead-of-parameters thing and I could put everything into the Oric's RAM leaving 2K (IIRC) for pages of game data read from disk. It was sloooooow, so Fabrice came into rescue and started rewriting functions in asm. Man that was incredible! He rewrote most of the interpreter and now it is smal and fast!

The only better way to go is forgetting about C and use only asm. XA is excellent for that purpose.

User avatar
polluks
Pilot Officer
Posts: 65
Joined: Tue Jun 05, 2012 10:09 pm
Location: Germany
Contact:

Re: Questions to CC65 users

Post by polluks » Mon Jan 21, 2019 12:11 am

NekoNoNiaow wrote:
Tue Jan 15, 2019 2:33 am
- Are there ways to put variables in the zero page? The OSDK compiler apparently is aware of the zero page but it does not seem to offer any way to share it or control it explicitly.
cc65 uses

Code: Select all

#pragma zpsym (<name>)
cc65 development
Oric Atmos + Cumulus
Acorn Electron

User avatar
NekoNoNiaow
Flight Lieutenant
Posts: 272
Joined: Sun Jan 15, 2006 10:08 pm
Location: Montreal, Canadia

Re: Questions to CC65 users

Post by NekoNoNiaow » Tue Feb 05, 2019 1:20 am

polluks wrote:
Mon Jan 21, 2019 12:11 am
cc65 uses

Code: Select all

#pragma zpsym (<name>)
Thanks!

Post Reply