vbcc optimizing C compiler for 6502 now supports bbc

handy tools that can assist in the development of new software
nicolagiacobbe
Posts: 215
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by nicolagiacobbe »

Thanks for the effort vbc. I am eager to test your latest improvements.
Fabrizio
Posts: 30
Joined: Fri Apr 27, 2018 5:33 pm
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Fabrizio »

Hi everyone,


I am trying to use vbcc to display some redefined character on some screen mode but I am not able to set the screen to any graphics mode.
If I do set it in BASIC before starting the vbcc binary, I do sort of get the result but it looks like to binary is loaded in screen memory (I see gibberish on the screen and on top of it I see the redefined character).

In order to do this things I am using the ROM routines by just "printing" control sequences on screen as described in the code below.

What am I doing wrong?

Fabrizio

Code: Select all

#include <stdint.h>
#include <stdio.h>

static uint8_t stripes[] = {255,0,255,0,255,0,255,0};

void redefine(uint8_t ch, uint8_t *data)
{
    uint8_t i;
    
    putchar(23);
    putchar(ch);
    for(i=0;i<8;++i)
    {
        putchar(data[i]);
    }
    putchar('\n');
}


void _XL_INIT_GRAPHICS(void)
{

    // Set mode 3
    putchar(22);
    putchar(3);
    
    // Delete graphics screen data
    putchar(16);
    
    // Redefine character 240
    redefine(240,stripes);
    
    // Redefine character 241
    redefine(241,stripes);
    
    // Display some text
    putchar('O');
    putchar('K');
    
    printf("hello world\n");
    
    // Display character 240
    putchar(240);
    
    // Display character 241
    putchar(241);
    
    // Display "hello world"
    printf("\nhello world\n");
    
    while(1){};
}
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Ragster »

I'm possibly being a bit dense, but I'm struggling to get it to work.
Windows install, I've edited the path and set the VBCC path, and I've trued various combinations of command line options, and editing the vc.cfg file.
The closest I've got to success is with a heavy edit of the vc.cfg where I fully expand all the paths. That gets me through the compile of a single source file, and a temporary object file created. But it fails at the link stage, with unresolved externals, and I can't get it to accept libraries into the link.

I'm fully prepared to accept that I've possibly made a mistake somewhere in the setup that has broken something, but I'm struggling to see what.

Trying to compile the simplest possible file:

Code: Select all

int main(void) {
return 0;
}
I get:

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>vc nothing.c -o test
startup.o: In "l3":
Error 21: startup.o (text+0x2b): Reference to undefined symbol ___main.
vlink -m -b bbc -Cvbcc -TD:\Downloads\vbcc6502_r3p3\vbcc6502\vbcc6502_win\vbcc/targets/6502-bbc/vlink.cmd -LD:/Downloads/vbcc6502_r3p3/vbcc6502/vbcc6502_win/vbcc/targets/6502-bbc/lib D:/Downloads/vbcc6502_r3p3/vbcc6502/vbcc6502_win/vbcc/targets/6502-bbc/lib/startup.o "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.o"   -o test  failed
Reference to undefined symbol __main ... in startup.o

Anyone know the obvious cause - or any suggestions as what daft mistake I've made?

Thanks
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by B3_B3_B3 »

Fabrizio wrote: Thu Jun 16, 2022 10:10 pm Hi everyone,


I am trying to use vbcc to display some redefined character on some screen mode but I am not able to set the screen to any graphics mode.
If I do set it in BASIC before starting the vbcc binary, I do sort of get the result but it looks like to binary is loaded in screen memory (I see gibberish on the screen and on top of it I see the redefined character).

In order to do this things I am using the ROM routines by just "printing" control sequences on screen as described in the code below.

What am I doing wrong?

Fabrizio

Code: Select all

#include <stdint.h>
#include <stdio.h>

static uint8_t stripes[] = {255,0,255,0,255,0,255,0};

void redefine(uint8_t ch, uint8_t *data)
{
    uint8_t i;
    
    putchar(23);
    putchar(ch);
    for(i=0;i<8;++i)
    {
        putchar(data[i]);
    }
    putchar('\n');
}


void _XL_INIT_GRAPHICS(void)
{

    // Set mode 3
    putchar(22);
    putchar(3);
    
    // Delete graphics screen data
    putchar(16);
    
    // Redefine character 240
    redefine(240,stripes);
    
    // Redefine character 241
    redefine(241,stripes);
    
    // Display some text
    putchar('O');
    putchar('K');
    
    printf("hello world\n");
    
    // Display character 240
    putchar(240);
    
    // Display character 241
    putchar(241);
    
    // Display "hello world"
    printf("\nhello world\n");
    
    while(1){};
}
It is more portable for those actual character variables/parameters/pointers(rather than raw bytes) to be declared as a (plain) char, as their signedness is compiler dependant and they are characters rather than general integer byte variables otherwise a compiler with signed chars won't /shouldn't compile the above with its uint8_t characters.

I wonder if C11+n should create an actual plain_char_t type for characters and deprecate usage of the char keyword for them?
vbc
Posts: 24
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Ragster wrote: Sat May 27, 2023 11:45 pm I'm fully prepared to accept that I've possibly made a mistake somewhere in the setup that has broken something, but I'm struggling to see what.
I'd suggest to start with the default installation. After setting the VBCC environment variable and PATH, please post the output of the following commands (assuming your nothing.c example is in the current directory):

Code: Select all

echo %VBCC%
vc +bbc -v nothing.c
Trying to compile the simplest possible file:

Code: Select all

int main(void) {
return 0;
}
I get:

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>vc nothing.c -o test
startup.o: In "l3":
Error 21: startup.o (text+0x2b): Reference to undefined symbol ___main.
vlink -m -b bbc -Cvbcc -TD:\Downloads\vbcc6502_r3p3\vbcc6502\vbcc6502_win\vbcc/targets/6502-bbc/vlink.cmd -LD:/Downloads/vbcc6502_r3p3/vbcc6502/vbcc6502_win/vbcc/targets/6502-bbc/lib D:/Downloads/vbcc6502_r3p3/vbcc6502/vbcc6502_win/vbcc/targets/6502-bbc/lib/startup.o "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.o"   -o test  failed
Reference to undefined symbol __main ... in startup.o
Seems like the linker command in your config file is missing -lvc to link with the standard library.
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Ragster »

vbc wrote: Mon May 29, 2023 6:48 pm Seems like the linker command in your config file is missing -lvc to link with the standard library.
It is indeed. If I add that, nothing.c compiles and links.

vbc wrote: Mon May 29, 2023 6:48 pm I'd suggest to start with the default installation. After setting the VBCC environment variable and PATH, please post the output of the following commands (assuming your nothing.c example is in the current directory):

Code: Select all

echo %VBCC%
vc +bbc -v nothing.c
I started with the default, and gradually worked away from it, getting steps to work bit by bit. But I ground to a halt with the linker error.

Here is what I get from the echo and vc with verbose on:

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>vc +bbc -v nothing.c
vc frontend for vbcc (c) in 1995-2020 by Volker Barthelmann
vbcc6502 -I"%VBCC%"/targets/6502-bbc/include -quiet "nothing.c" -o= "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.asm" -unsigned-char -mainargs -mask-opt  -O=1
vbcc V0.9i pre (c) in 1995-2022 by Volker Barthelmann
vbcc 6502 code-generator V0.5 (c) in 2022 by Volker Barthelmann
error 6: No input file
aborting...
1 error found!
vbcc6502 -I"%VBCC%"/targets/6502-bbc/include -quiet "nothing.c" -o= "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.asm" -unsigned-char -mainargs -mask-opt  -O=1 failed

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>
Having had that fixed, I will see if I can compile something marginally more involved, and see if I can run that in BeebEm.

Thank you very much!


ETA:
And once I managed to get the inf file association sorted, the programs load and run, including using the floating point libraries and printf. So, It seems to be working nicely.
And now to work!
(Well, actually, to bed, since it's late.... but, soon, to work!)
vbc
Posts: 24
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Ragster wrote: Mon May 29, 2023 10:45 pm It is indeed. If I add that, nothing.c compiles and links.
It is good to hear that at least you found a workaround to get it working for now.
Here is what I get from the echo and vc with verbose on:

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>vc +bbc -v nothing.c
vc frontend for vbcc (c) in 1995-2020 by Volker Barthelmann
vbcc6502 -I"%VBCC%"/targets/6502-bbc/include -quiet "nothing.c" -o= "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.asm" -unsigned-char -mainargs -mask-opt  -O=1
vbcc V0.9i pre (c) in 1995-2022 by Volker Barthelmann
vbcc 6502 code-generator V0.5 (c) in 2022 by Volker Barthelmann
error 6: No input file
aborting...
1 error found!
vbcc6502 -I"%VBCC%"/targets/6502-bbc/include -quiet "nothing.c" -o= "C:\Users\rgodi\AppData\Local\Temp\vbcc068c.asm" -unsigned-char -mainargs -mask-opt  -O=1 failed

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>
The output from echo %VBCC% was missing. Could you add that?

The command lines look ok to me. If you copy (or type by hand) the vbcc6502-command above and execute it directly, do you get the same error?

Are you using a normal Windows with a standard command window or are you using a special shell or something like that?
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Ragster »

vbc wrote: Tue May 30, 2023 10:08 pm The output from echo %VBCC% was missing. Could you add that?
the echo %VBCC% gives me this:

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>echo %VBCC%
D:\Downloads\vbcc6502_r3p3\vbcc6502\vbcc6502_win\vbcc\
vbc wrote: Tue May 30, 2023 10:08 pm The command lines look ok to me. If you copy (or type by hand) the vbcc6502-command above and execute it directly, do you get the same error?

Are you using a normal Windows with a standard command window or are you using a special shell or something like that?
Standard Windows command line - no special shell, tools, or anything wrapping it.

If I run the command line as given, I get the same error - error 6: No input file

If I use my config file with the full paths it works. If I try to use the platform specific config files, it fails to find the files. It just doesn't seem to be expanding the variables the one one might expect.

I would be nice to get it working as intended - I dislike having to rely on hacks and hard coded exceptions.
(And that may be easier than figuring out how to make make system calls to talk to econet and then draw graphics....!)
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Ragster »

This may be a daft question... (long time since I wrote any code for what's a kind of essentially embedded system) - but vbcc doesn't seem to allow setting of pointers to absolute values, only to null.
So... how do I address specific memory locations? Say, for memory mapped I/O, or screen memory?

Sorry if these are basic questions or if I'm missing something obvious.
vbc
Posts: 24
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Ragster wrote: Tue May 30, 2023 11:53 pm

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>echo %VBCC%
D:\Downloads\vbcc6502_r3p3\vbcc6502\vbcc6502_win\vbcc\
Could you try removing the trailing backslash from the VBCC environment variable? I think it interferes with the quotes in the generated command line. I probably should add some code to check for that.
vbc
Posts: 24
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Ragster wrote: Fri Jun 02, 2023 11:09 pm This may be a daft question... (long time since I wrote any code for what's a kind of essentially embedded system) - but vbcc doesn't seem to allow setting of pointers to absolute values, only to null.
So... how do I address specific memory locations? Say, for memory mapped I/O, or screen memory?
Just cast the value to the pointer type, e.g.:

Code: Select all

int *p=(int *)0x1234;
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Ragster »

vbc wrote: Sat Jun 03, 2023 3:35 pm
Ragster wrote: Tue May 30, 2023 11:53 pm

Code: Select all

D:\Downloads\vbcc6502_r3p3\vbcc6502\samples>echo %VBCC%
D:\Downloads\vbcc6502_r3p3\vbcc6502\vbcc6502_win\vbcc\
Could you try removing the trailing backslash from the VBCC environment variable? I think it interferes with the quotes in the generated command line. I probably should add some code to check for that.
With the backslash removed, it seems as though it works as intended - using a specified config (e.g. +bbcr) it finds the input files and compiles.
Thanks - mystery solved.

And the casting for the pointer set seems to work too - at least it compiles... Now to see if I can make it do what I want, and start building the libraries I need...
Cheers!
Post Reply

Return to “development tools”