VBCC Optimizing C-compiler now supports NES

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Mon Jul 27, 2020 1:30 am

rox_midge wrote:
Sat Jul 25, 2020 11:00 am
vbc, the more I play with this, the more I love it. Thanks to the advanced nature of the optimizations present here, I've been able to convert almost all of my project over to pure C, with only some parts left in assembly.
Nice to hear, thank you.
Would it be possible to get two small "creature comfort" options added in somehow? Neither of these are dealbreakers for me, but they'd make things a bit more comfortable to use:
  1. When using the -k option to keep the intermediate files, I'd like to specify a directory where those intermediate files should be written. Right now, the intermediate files (.asm, .o, etc.) get put into the same directory as the corresponding source file. I'd like to be able to have them written to an entirely different directory instead, so that I can examine them without having them clutter up my source directory.
  2. When generating assembly, I'd like some / all integer constants to be rendered in hexadecimal instead of decimal. This would be super helpful when reviewing the output, because although I know that, say, $8000 means the MMC3 bank select register, my eyes glaze over when I see "sta 40960".
Having the original C source included in the assembly would possibly address the second issue, but I couldn't find a way to do that either.
I will check if any of your suggestions can be implemented without much effort.

User avatar
Banshaku
Posts: 2377
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: VBCC Optimizing C-compiler now supports NES

Post by Banshaku » Mon Jul 27, 2020 1:56 am

@vbc,

regarding the old/standard style, understood. I guess it comes from my lack of experience with older style but these days I looked at some older code and I saw exactly that pattern, labels without columns on line 1 and everything else on other columns.
vbc wrote:
Mon Jul 27, 2020 1:18 am
You can define and access a structure for example like this:

Code: Select all

        struct point
x:      dw 1
y:      db 2
        endstruct

s1:     point
s2 = $8000

        lda     s1+point.x
        lda     s2+point.y
I see. That's quite similar then. I guess I misunderstood the doc. The example seemed to define a struct but with default value in them but after that reserved it and used the field on that variable so I thought you couldn't use it that way (i.e. as offset for another memory region). I will try it tonight and see how it goes. Soon I need to convert a lot of code that require struct so without understanding them that would have been an issue.

Regarding the other message from @rox_midge, inlined C code as comments (guess hard to make with current flow) and hex value (this one should be easier) would be quite useful.

Thanks again!

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Mon Jul 27, 2020 2:00 am

rox_midge wrote:
Sat Jul 25, 2020 7:47 pm
Although I can do the same thing, running the underlying `vbcc6502` and `vasm6502_oldstyle` commands in my makefile manually, but it appears that when `vc` is run with '-O3', it generates an opaque command script that it passes to `vbcc6502` using the '-cmd' option. I can't make `vc` show me what's in that script. But like I said, it's not a dealbreaker.
When using the -v option, you see the filename. With the -k option, the file will not be removed and can be inspected. The cmd file will contain all the source file names. When using -O3, vc passes all source files to vbcc at once. Some hosts have limited length for command lines, therefore vc will create this cmd file to avoid problems on such hosts.
I already had my own linker file, and wound up having to create my own config file, because something was causing the %%VBCC%% environment variable to not be available when running `make`. Although I could run `vc` from the command line just fine, when `make` ran `vc` for me, it wasn't properly expanding the %%VBCC%% variable, so I had to hard-code it. Not my favorite thing, but it's better than a sharp stick in the eye.
It should work with a suitable version of make. But finding a good port of make for Windows always seems to be a bit of a problem.

User avatar
Banshaku
Posts: 2377
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: VBCC Optimizing C-compiler now supports NES

Post by Banshaku » Tue Jul 28, 2020 1:27 am

@vbc,

I don't know how hard it would be to add but if zpage could work like global and allow a list on one line that would be great. It's quite tedious to have to write every variables one by one. To allow to group them like global makes the list smaller (adding the . notation would be great too but we already talked about that).

edit:

It seems that the concept of enum didn't exist in older syntax asm? I cannot find anything in the vasm doc on the subject. I will use symbols for now in that case.

yaros
Posts: 3
Joined: Mon Jul 27, 2020 1:14 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by yaros » Wed Jul 29, 2020 7:40 am

vbc wrote:
Mon Jul 27, 2020 1:18 am
You can define and access a structure for example like this:

Code: Select all

        struct point
x:      dw 1
y:      db 2
        endstruct

s1:     point
s2 = $8000

        lda     s1+point.x
        lda     s2+point.y
If we already defined that s1 is of type point is it possible to simplify

Code: Select all

lda s1+point.x
to

Code: Select all

lda s1.x
?

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Wed Jul 29, 2020 8:05 am

Banshaku wrote:
Tue Jul 28, 2020 1:27 am
I don't know how hard it would be to add but if zpage could work like global and allow a list on one line that would be great. It's quite tedious to have to write every variables one by one. To allow to group them like global makes the list smaller
Agreed. Will be added.
It seems that the concept of enum didn't exist in older syntax asm? I cannot find anything in the vasm doc on the subject. I will use symbols for now in that case.
I do not think I have ever seen enums in assembly code. It is not a feature in vasm. Using symbols should be ok.

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Wed Jul 29, 2020 8:10 am

yaros wrote:
Wed Jul 29, 2020 7:40 am
If we already defined that s1 is of type point is it possible to simplify

Code: Select all

lda s1+point.x
to

Code: Select all

lda s1.x
?
Unfortunately not. To vasm it is just a symbol. vasm does not keep track of something like type information. That's what vbcc is for. :-)

User avatar
Banshaku
Posts: 2377
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: VBCC Optimizing C-compiler now supports NES

Post by Banshaku » Wed Jul 29, 2020 8:52 am

Regarding zpage, great, that will be useful ;)
vbc wrote:
Wed Jul 29, 2020 8:05 am
I do not think I have ever seen enums in assembly code. It is not a feature in vasm. Using symbols should be ok.
There is some "kind" of enum in ca65 but when you look at it, it's just a list of constant. In other assembler, they uses the term for mapping memory (which I think is quite unusual) so the one used in ca65 is the closest to C but with some kind of scope.

It allow to do something like this:

Code: Select all

	.enum myEnum
		val1 = 2	; start at 2
		val2		; contains 3
		val3          ; contains 4 etc
	.endenum
	
	; later you can use it that way
	lda myEnum::val2
but when you think about it, you can just use a symbol called myEnum_val2 and it exactly the same, albeit the fact that you have to assign all values manually. So I guess is something very specific to ca65 and I never liked their :: notation but got used with time.

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Wed Jul 29, 2020 5:09 pm

I have uploaded a new version to: http://www.compilers.de/vbcc.html

Major changes since Alpha 2:

- first version of an Atari 8bit target (Atari)
- configuration for running banked code with REU (C64)
- configuration for TxROM mapper (NES)
- some speed and size optimizations of the C library (thanks to Frank Wille) => up to 234 dhrystones/s on C64
- chars are unsigned by default for slightly better code
- return values of banked function calls work now
- setjmp/longjmp added
- new option -depobj to fix problems with -deps
- zpage now supports multiple arguments (vasm)
- some support for mixing source and assembly with -g
- a few bug fixes
- updated/improved documentation

User avatar
Banshaku
Posts: 2377
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: VBCC Optimizing C-compiler now supports NES

Post by Banshaku » Wed Jul 29, 2020 7:56 pm

vbc wrote:
Wed Jul 29, 2020 5:09 pm
- chars are unsigned by default for slightly better code
- new option -depobj to fix problems with -deps
- zpage now supports multiple arguments (vasm)
- some support for mixing source and assembly with -g
char is a good thing for 8 bit platform. For deps, I guess it's related to my bug so I will check it. zpage, I will test it right away. -g, will check that too.

I don't see any mention of the vlink update for ORIGIN/LENGTH, does this mean this part is not included yet?

edit:

The vlink docs now contain more information on how to use and both are included so I will tests them soon.

As for depobj, it works properly. The file is still created in the same folder but my makefile takes care of it. the dep file still contains "//" for the path separator before the name of the file so I guess this bug is still there.

-g, not sure yet how it works after reading the doc, seems that you need to add the code yourself if I understood what it meant.

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Thu Jul 30, 2020 1:28 am

Banshaku wrote:
Wed Jul 29, 2020 7:56 pm
-g, not sure yet how it works after reading the doc, seems that you need to add the code yourself if I understood what it meant.
Yes, you should be able to use some kind of script to create a mixed C/assembly files. Not sure how good the results will be, though.

timschuerewegen
Posts: 29
Joined: Wed Dec 04, 2019 10:42 am

Re: VBCC Optimizing C-compiler now supports NES

Post by timschuerewegen » Thu Jul 30, 2020 3:35 am

I think I found a bug. See attached project. It should display "0808" when you press up but it displays "1808" instead.
menu.zip
(5.35 KiB) Downloaded 10 times

vbc
Posts: 40
Joined: Sun Jun 21, 2020 5:03 pm

Re: VBCC Optimizing C-compiler now supports NES

Post by vbc » Thu Jul 30, 2020 6:51 am

timschuerewegen wrote:
Thu Jul 30, 2020 3:35 am
I think I found a bug. See attached project. It should display "0808" when you press up but it displays "1808" instead.

menu.zip
Indeed. There was a code path that was missing a clc before an adc. I have updated the files on my page.

Thanks for the report.

timschuerewegen
Posts: 29
Joined: Wed Dec 04, 2019 10:42 am

Re: VBCC Optimizing C-compiler now supports NES

Post by timschuerewegen » Thu Jul 30, 2020 3:22 pm

vbc wrote:
Thu Jul 30, 2020 6:51 am
Indeed. There was a code path that was missing a clc before an adc. I have updated the files on my page.

Thanks for the report.
Thanks.

I think I found another bug :)

Code: Select all

#define IO8(addr) (*(volatile ubyte *)(addr))

void test()
{
	ubyte val;
	IO8(0x4147) = IO8(0x4147) & 0xBF;
	val = IO8(0x4147) & 0xDF;
	IO8(0x4147) = val;
	IO8(0x4147) = val | 0x20;
}
results in the following reads/writes

Code: Select all

R 4147 41
W 4147 01 01 21
but it should be

Code: Select all

R 4147 41
W 4147 01
R 4147 41
W 4147 41 61
Adding "volatile" to "val" seems to fix it but that should not be necessary.

User avatar
Banshaku
Posts: 2377
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: VBCC Optimizing C-compiler now supports NES

Post by Banshaku » Thu Jul 30, 2020 5:50 pm

vbc wrote:
Thu Jul 30, 2020 1:28 am
Yes, you should be able to use some kind of script to create a mixed C/assembly files. Not sure how good the results will be, though.
Ok then. For now this is not a high priority so I will check about that later.

edit:

I removed the test of the message since I think I found the source of the error and it's just a mistake inside the makefile for C files. I will figure it out now.
Last edited by Banshaku on Fri Jul 31, 2020 2:46 am, edited 2 times in total.

Post Reply