SDCC crt0.s for floppy bload

Page 3/3
1 | 2 |

By aoineko

Hero (518)

aoineko's picture

06-02-2021, 21:44

ocitygate wrote:

Important that --code-loc 0xC020 is exactly 0x20 higher that the first address.

I feel like there's something weird with your memory address values. It seems to me that if your header is placed in A000h, it means that you are aiming at an MSX with at least 24K of memory. In this case, your code should be just after (around A020h). If you aim at an MSX with 32K, these values should be 8000h and 8020h. And for 16K, C000h and C020h.

By aoineko

Hero (518)

aoineko's picture

07-02-2021, 00:39

By the way, if you don't like to waste a few bytes like me, you can place your code segment at _HEADER + 7 (the header is 7 bytes long).
To do that, just put the _CODE segment just before the init: label in your crt0, then use --code-loc 0xA007 in your SDCC command line (if your program starts at 0xA000).
That's it! Not only have you saved a few bytes on your binary file size, but above all, you no longer have the risk of overlap between the code in your crt0 and the one in your C file(s).
You can check the crt0 I use in my game library for Basic binary program: https://github.com/aoineko-fr/CMSX/blob/master/cmsx/src/crt0...

By DamnedAngel

Master (248)

DamnedAngel's picture

07-02-2021, 02:25

ocitygate wrote:

I want to code C for my first generation MSX (Toshiba HX-10), but since I do not have any disk controllers and therefore no MSX DOS, I need to load my programs through the cassette interface with the BLOAD command in MSX BASIC.

Hi ocitygate,

You might want to take a look at my SDCC templates for MSX. The config files and build scripts get your addresses just right and, on top of that, they offer a lot of common services, including references for integration with MSX-BASIC for BIN programs and symbol exporting to be used along OpenMSX Debugger.

In case you are under Windows and have a taste for MS Visual Studio, the templates integrate nicely with the IDE. But if you aren't, then you can use whatever IDE pleases you most and call the build script manually.

You can find the templates at https://github.com/DamnedAngel/MSX-Templates-for-VisualStudio.

cheers,

By ocitygate

Expert (72)

ocitygate's picture

13-02-2021, 19:23

Thanks Angelo, I am taking a look.
I am on Windows and use Visual Studio (C++ and C#) but I use it just for Windows programming.
For MSX I'm using SDCC compiler. I tried MSX-C but I prefer keeping my development environment on Windows.
What I like the most about SDCC is that you can embed Z80 assembly in your code.
For emulation I'm using blueMSX on Windows and fMSX on my Android phone.
Tried OpenMSX but did not like Catapult. Too much configuration which I do not need.
Thanks for replying to my post.

By snake

Resident (61)

snake's picture

15-08-2022, 16:57

Thank you for sharing or linking crt code Smile

Is there any guide about Sdcc crt files? I ask because i have to solve a weird issue with executable files larger than 16384 bytes that start @32768 (8000h). They freeze at the beginning without even executing the early instructions. None of posted code works (but they work when size is less than 16384). Or maybe is it a limit of BLOAD command?

By aoineko

Hero (518)

aoineko's picture

15-08-2022, 17:30

I am not familiar with the binary programs executed in the BASIC environment, but I don't think your problem is related to SDCC crt0. On the crt0 side, you just have to make sure that the header is well defined (0xFE, start/end address of the binary, execution address).
If your program is larger than 16 KB, it will enter the last page visible to the Z80 (page 3), but this is not supposed to be a problem because your program (on page 2) is on the same RAM slot as page 3.
I think I managed to run under BASIC sample programs from my MSXgl library which was around 24 KB.

By aoineko

Hero (518)

aoineko's picture

15-08-2022, 17:37

Oh! I just thought of something related to SDCC. For BASIC programs (and MSX-DOS one), you should set --data-loc to 0 when linking your program.
If you set a hardcoded value like 0xC000, you may overwrite the space allocated for your variables with the content of your program.
If you set the address to 0, SDCC will put your variables, right after your program.

Page 3/3
1 | 2 |