vbcc C compiler notes and status

All aspects of programming on the Commander X16.
Post Reply
Xiphod
Posts: 568
Joined: Thu Apr 15, 2021 8:05 am

vbcc C compiler notes and status

Post by Xiphod »

So today I wanted to give vbcc C compiler a try on the X16, because it say it supports the C99 standard that lets you do declarations and code at the same time. Old-school C (and cc65) requires all the declarations to be at the top of a function. I'm ok with that on new code, but trying to fire up some old code bases, the C99 updates would be nice.

So first step is "where to get vbcc" - and the place I went to was here:
http://www.compilers.de/vbcc.html

This seems to be last updated April 2022. It does have an X16 target (confusing since it also has a C16 target). And looks like there is a "reduced" or "tiny" X16R target as well.

Ok, so I gave it a try with a simple main - and it actually did produce a PRG that the r43 emulator would load. A few simple things worked (like a for-loop and printf on an integer). But fairly quickly, weird stuff started to happen in the produced PRG - like sprintf to do int to string conversion, and I'd end up with random garbage printed on the screen. I thought maybe the internal library was just converting to wrong display codes or something, but it was a different kind of random each time I ran it (so implies some kind of corrupted memory).

So, is this the "newest" vbcc distro to get? Does it work, but just avoid the standard library for now? I haven't yet seen examples for the inline assembly (and the .a's in the targets, I'm not seeing source for -- which is often good examples of how to do inline assembly, that's how I poked around in cc65).


For reference, here is how I'm doing the 6502 X16 build: (add the vbcc bin to path)

Code: Select all

set VBCC=f:\x16\vbcc_win_x64\vbcc
vc +x16 main.c -o test.prg -If:\x16\vbcc_win_x64\vbcc\targets\6502-x16
(or can use +x16r for that "reduced" or "tiny" stuff, I think)
The -I gets you much of the C standard library (no conio.h like cc65 has, but remember conio isn't really part of the C-standard library, iirc it was something Borland started providing with their compilers in the mid 1980s

Tracing "vc" a bit with this target, it seems to run vbcc6502.exe and then vasm6502_oldstyle.exe for you.


Anyone else further along with vbcc? Is this a good distro to be using? Again, it did make a valid formed PRG and did load, but it's a bit hit or miss on which parts of the standard library stuff works (not sure if r43 issues, or maybe still config issues on my part)

For now, going to stick with recommending cc65 for C and X16 r43.
Xiphod
Posts: 568
Joined: Thu Apr 15, 2021 8:05 am

Re: vbcc C compiler notes and status

Post by Xiphod »

printf in vbcc seems to be working ok. My issue was the sprintf was failing and not putting the null terminator in the string, so then printing a "rando-string" the X16 interprets some of the non-printable characters in special ways. So sprintf needs some work, but for basic output of variables, printf seemed to be working.

Still don't have examples yet of inline assembly in vbcc. You can of course still do these macros:

#define POKE(addr,val) (*(unsigned char*) (addr) = (val))
#define POKEW(addr,val) (*(unsigned*) (addr) = (val))
#define PEEK(addr) (*(unsigned char*) (addr))
#define PEEKW(addr) (*(unsigned*) (addr))
Post Reply