Fusion-C and SDCC 4.2.0

Страница 1/2
| 2

By Paulo Garcia

Rookie (18)

Аватар пользователя Paulo Garcia

10-03-2022, 21:30

Hi,

I've been toying with fusion C and because I am using a Mac with M1 chip, I wasn't able to run the sdcc 3.6.0 bundled in the fusion-c 1.2 tool chain. For other reasons, I wasn't able to compile it from source either, so I decided to try my luck using fusion-c with sdcc 4.2.0.

I managed to compile without errors both the test.c and some graphic example (circle_msx1) but when I run hex2bin and put it in the dsk image, the program doesn't run properly. For example, test.c prints out "ILECOUNT".

I am new to sdcc (as msx) in general so I wonder if someone can either tell me 4.2.0 should work, or I would need to stick to 3.6.0. Or even if there is anything I can look at in the temporary files generated by the compiler.

Thanks

Paulo

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By megatron-uk

Resident (51)

Аватар пользователя megatron-uk

10-03-2022, 23:29

From what I gather, much of the assembly routines in Fusion-C 1.2 are written in z80 assembly using the calling conventions of SDCC 3.x, there was a thread on here talking about the change in assembly calls when going to the latest 4.2 version of SDCC.

Long story short, I'd expect much of the assembly in the fusion C lib not to run properly.

I need to look at this myself, as I quite like the features included in z88dk (out of the box support for banked functions without the need to write any assembly), but the vdp assembly functions in fusion C won't be a straight port over from what I gather.

By megatron-uk

Resident (51)

Аватар пользователя megatron-uk

10-03-2022, 23:31

https://www.msx.org/forum/msx-talk/development/sdcc-4112-a-g...

Some discussion about the compatibility of SDCC 4.1.x+ and previous assembly written for the older targets.

By ARTRAG

Enlighted (6976)

Аватар пользователя ARTRAG

11-03-2022, 00:21

Eric Boez is updating the Fusion library to the new calling convention
In the meantime you can set as default the old convention also in sdcc4.2 using the appropriate parameter in the command line
The new convention can be activated function by function using a qualifier in the definition

By aoineko

Paragon (1133)

Аватар пользователя aoineko

11-03-2022, 00:28

There are two different things:
- Even with recent versions of SDCC, it is possible to force the use of the old function calling convention by default (either globally via a parameter in the command line, or per file via a pragma, or per function via a directive).
- On the other hand, only the versions of SDCC before 4.1.12 are shipped with a Z80 library compiled with the old calling convention (this library is essential for a lot of basic C operations; like modulo for example).

So if you want to compile Fusion-C 1.2 with SDCC 4.2.0 you have to activate the parameters to force the use of the old calling convention and use the Z80 libraries of SDCC 4.1.11.
Otherwise, you can try to recompile the Z80 libraries of SDCC 4.2.0 to generate versions with the old calling convention, but I don't know how complicated it is.

By Paulo Garcia

Rookie (18)

Аватар пользователя Paulo Garcia

11-03-2022, 06:17

First of all, thanks for all answers and thorough explanations.

I managed to compile the two mentioned programs, plus a few others only adding the --sdcccall 0 to the CCFLAGS variable. I haven't done anything related to the z80 libraries though, so I am not sure if some more complex programs will still work.

Meanwhile I will also try to get one of the 3.x.x versions running on the M1.

At least, for now I can start doing something!

Thanks again!

Paulo

By Paulo Garcia

Rookie (18)

Аватар пользователя Paulo Garcia

12-03-2022, 05:05

Quick update. As soon I tried to compile more complex examples, I started getting errors from functions in the z80 library, like @aoineko predicted.

I was able to compile the 3.6.0 in another Intel Mac and move the binaries over my M1, and everything works fine now regarding fusion-c. I will keep my eyes on for updates, but for now I am good Smile

Cheers

By geijoenr

Champion (391)

Аватар пользователя geijoenr

12-03-2022, 06:33

Based on my experience there seem to be issues with sdcc 4.2.0 beyond the changes related to new calling convention. I couldn't get some perfectly valid older code to actually compile.

I would wait a bit until those issues are ironed out before switching.

By aoineko

Paragon (1133)

Аватар пользователя aoineko

12-03-2022, 10:40

@Paulo Garcia For my first test with new calling convention I used the z80 lib provided with SDCC 4.1.11 (the last one generated with old calling convention). I guess the content of this lib should not change much with time so it seems pretty safe to use the SDCC 4.1.11 lib with the toolchain of a recent version of SDCC (like 4.2.0).
However, as you probably know, if you use the global compiler parameter --sdcccall 0, you will not get any benefit from the new function calling system (all function parameters will be passed through the stack).

To convert Fusion-C for use with the new calling convention, the first thing I'll do is put __sdcccall(0) on all functions in the library that access input parameters through inline assembler. Then you can compile the library with --sdcccall 1 to benefit from the new convention on all other functions. This is how I converted MSXgl. The last step is to convert the functions that access parameters in assembler (to read from the registers instead of the stack) and to remove the __sdcccall(0) once it is done.

@geijoenr The creators of SDCC are very careful when releasing stable versions like 4.2.0 (this is less the case for snapshots). It seems very unlikely to me that your problem is a bug in the library. On the other hand, depending on the version you were using before, you may have to adjust your code accordingly (the changes that require modifications are listed in the first part of the SDCC doc).

In fact, I didn't have any problem to switch my MSXgl library from version 4.1.12 to version 4.2.0. All the sample programs work without any problem.

By geijoenr

Champion (391)

Аватар пользователя geijoenr

12-03-2022, 19:34

Quote:

@geijoenr The creators of SDCC are very careful when releasing stable versions like 4.2.0 (this is less the case for snapshots). It seems very unlikely to me that your problem is a bug in the library. On the other hand, depending on the version you were using before, you may have to adjust your code accordingly (the changes that require modifications are listed in the first part of the SDCC doc).

Yeah, I am sure they are very careful, I am just sharing my experience with 4.2.0.

By aoineko

Paragon (1133)

Аватар пользователя aoineko

12-03-2022, 21:53

What is the latest version of SDCC that your program was running on?

Страница 1/2
| 2