6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Jun 05, 2024 8:31 pm

All times are UTC




Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: WDC02CC Compiler
PostPosted: Tue Apr 20, 2021 10:05 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8198
Location: Midwestern USA
Druzyek wrote:
vbc wrote:
tokafondo wrote:
What would be a fair set of tests that could be created to make a comparison between 65xx C compilers?

Well, that is a non-trivial area of science, basically. And it is made harder by the fact that the existing 6502 compilers do vary quite a lot regarding their goals/capabilities, and quite a lot of existing C code does not work on 6502. So, clearly not an easy task, but IMHO at least you should either use code that has not been written/pre-selected with any specific compiler in mind, or it should be adapted/optimized equally for all compilers.
Another way to go about it is to write the type of code you are actually going to be using the compilers for. You may not actually care if a particular compiler is better at doing something you don't need it to do.

And for the truly insane, one could disassemble and examine the code emitted by the compiler and see just how sloppy it might be. :D

The WDC C compiler (at least the 65C816 version) that I played with some years ago seemed to generate reasonably succinct code, although nowhere near what a good assembly language programmer could produce. Of course, compiling C for the 65C816 is "easier" than for the 65C02, since the former has more addressing modes, including stack-relative, as well as the very useful ability to relocate direct (zero) page. such as to the stack.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Tue Apr 20, 2021 10:43 pm 
Offline

Joined: Sat Apr 11, 2020 7:28 pm
Posts: 341
I though that there was a set of standard functions like Mandelbrot calculations, or sorting algorythms, or things like that, that could be programmed in a standard C code, not specific to an architecture or compiler. And then fed to the compilers to see what code they do spit out.

I mean...

Code:
10 PRINT "HELLO, WORLD!"
20 GOTO 10


Is almost universally understood by every BASIC out there, but when compiled to machine code, there are differences between not only architectures but also compilers, aren't them?


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Wed Apr 21, 2021 4:59 am 
Offline
User avatar

Joined: Tue Jul 17, 2018 9:58 am
Posts: 104
Location: Long Island, NY
Well, I did spend my evening implementing Tetris for my system in C. I didn't consciously do anything to tailor it to the WDC compiler so it might be a good candidate to see how easily I can build the same code with cc65 or vbcc.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Wed Apr 21, 2021 6:07 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 693
Location: North Tejas
tokafondo wrote:
I though that there was a set of standard functions like Mandelbrot calculations, or sorting algorythms, or things like that, that could be programmed in a standard C code, not specific to an architecture or compiler. And then fed to the compilers to see what code they do spit out.

Mandelbrot was discussed here: viewtopic.php?f=1&t=6323

The result is tied too much to output speed.

There was fib and tarai, thought not everyone wants or needs recursion: viewtopic.php?p=78840#p78840

tokafondo wrote:
I mean...

Code:
10 PRINT "HELLO, WORLD!"
20 GOTO 10


Is almost universally understood by every BASIC out there, but when compiled to machine code, there are differences between not only architectures but also compilers, aren't them?

My BASIC compiler generates this:
Code:
                          00277          ifdef  __INIT
                          00278          jsr    InitRTL   ; Initialize run-time environment
                          00279          endif
                          00280
 0B06 20 0224         [6] 00281          jsr    NewLine
                          00282
                          00283 ; 10 PRINT "HELLO, WORLD!"
 0B09                     00284 L00010:
                          00285          ifdef  __TRACE
                          00286          ldx    #<10
                          00287          lda    #>10
                          00288          jsr    Trace
                          00289          endif
                          00290
 0B09 A2 A3           [2] 00291          ldx    #<S00000
 0B0B A9 0B           [2] 00292          lda    #>S00000
 0B0D 20 0B6E         [6] 00293          jsr    PStr
                          00294
 0B10 20 0224         [6] 00295          jsr    NewLine
                          00296
                          00297 ; 20 GOTO 10
 0B13                     00298 L00020:
                          00299          ifdef  __TRACE
                          00300          ldx    #<20
                          00301          lda    #>20
                          00302          jsr    Trace
                          00303          endif
                          00304
 0B13 4C 0B09         [3] 00305          jmp    L00010
                          00306
 0B16                     00307 End_

The total binary file size is under 200 bytes.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Wed Apr 21, 2021 11:06 am 
Offline

Joined: Thu Apr 23, 2020 5:04 pm
Posts: 45
tokafondo wrote:
I though that there was a set of standard functions like Mandelbrot calculations, or sorting algorythms, or things like that, that could be programmed in a standard C code, not specific to an architecture or compiler. And then fed to the compilers to see what code they do spit out.

Yes, I have seen 6502 C benchmarks using mandelbrot, md5, or dhrystones. However, those are very small and the results are often dominated by the implmentation of a single feature or optimization. E.g. a mandelbrot calculation on the 6502 will mainly test the math libraries used. The dhrystone benchmark was intended to test a mixture of features considered typical use at that time. However, with modern compilers, it emphasizes a few specific optimizations that have far less impact in practice. So you may get hugely varying results using only one or two small tests.

So, if a comprehensive test suite is required, you probably want more and bigger tests. Those, however, are more likely to not work out of the box with all 6502 compilers due to different limitations of either the 6502 or the compilers. So you may have to pick and adapt, i.e. some work.

As another poster mentioned, if you are just choosing a compiler for your project, the best option probably is to test some of that code.

Quote:
Code:
10 PRINT "HELLO, WORLD!"
20 GOTO 10


Is almost universally understood by every BASIC out there, but when compiled to machine code, there are differences between not only architectures but also compilers, aren't them?

Yes, but that test will probably not be a good indication of how the compilers will translate e.g. a mandelbrot calculation.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Wed Apr 21, 2021 5:37 pm 
Offline

Joined: Sat Apr 11, 2020 7:28 pm
Posts: 341
This
tokafondo wrote:
Code:
10 PRINT "HELLO, WORLD!"
20 GOTO 10

was used to make a point, not to be taken as a real compiler test. :) :) :)

I'm reading comments about how to write code tailored for this or that compiler, and what I'm talking about is to create code that would stick to standard C (hence the BASIC example), and then leave up to the compilers how to make assembler from it.

That's why I talked about standard operations like the Mandelbrot stuff, or sorting stuff, or working with arrays... you name it! Those operations would be written in the most standard C (instead of tailored for cc65, vbc, WDC, or what ever) and fed to the compilers.

Then, things like code size and time of the operations the code is written to do would help to know which compiler is best in overall or in certain areas.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Wed Apr 21, 2021 5:47 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10822
Location: England
Compiler tests which spring to mind, all of which seem to have the property of creating an executable with some kind of function:
- compile a Basic or Logo interpreter
- compile a screen editor
- compile a program like Xmodem
- compile a FAT filesystem
- compile a TCP/IP stack
- compile a compiler

But of course, just blinking an LED or reading a temperature sensor are also in there. Something you might want to do with your '02 system.

All of these things have in common a need to perform I/O, which is going to be somewhat platform-specific.

Edit: I seem to be answering the question "Is this compiler useful" rather than "Which compiler is best" and I think I'm happy with that.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Thu Apr 22, 2021 1:10 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 693
Location: North Tejas
Here is someone who is comparing compilers...

https://bestofcpp.com/repo/sgadrat-6502-compilers-bench


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Thu Apr 22, 2021 1:12 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 693
Location: North Tejas
BigDumbDinosaur wrote:
And for the truly insane, one could disassemble and examine the code emitted by the compiler and see just how sloppy it might be. :D


Guilty as charged...

viewtopic.php?p=79347#p79347


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Thu Apr 22, 2021 3:43 pm 
Offline
User avatar

Joined: Sat Sep 29, 2012 10:15 pm
Posts: 899
BigDumbDinosaur wrote:
..And for the truly insane, one could disassemble and examine the code emitted by the compiler and see just how sloppy it might be. :D


Uh-oh. It is true, then...

_________________
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Thu Apr 22, 2021 11:47 pm 
Offline
User avatar

Joined: Tue Jul 17, 2018 9:58 am
Posts: 104
Location: Long Island, NY
Has anybody else had the WDC compiler just crash when there's an error of any kind in your C code? Mine prints out the offending line but then segfaults leaving the reason as an exercise for the reader.


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Thu Apr 29, 2021 3:54 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 693
Location: North Tejas
Andrew had been working on this compiler with WDC before his passing.

Does anybody know what he had accomplished and whether his changes are in the latest official version?


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Mon May 03, 2021 1:47 am 
Offline

Joined: Mon May 03, 2021 12:07 am
Posts: 21
Location: Brisbane Australia
Hi

I have just started my journey down the 6502 road, or perhaps continuing where I left off back in the 80's.
I started with an "Aloha 66" clone of an Apple 2. Unfortunately I no longer have any of the gear that I collected back in the day.

I am currently looking at the WDC compiler.
I am a (Electronics Engineer) embedded C programmer and not really that keen to go back to assembler if I can help it. (though I think assembler it may be)

Tide is a waste of time. I thought it would be something like AVR studio....IDE as in "Integrated Development Environment"....as in editor.
It can call an external editor...that's about it.
If I try to change anything in options I get an Error message "Failed to set data for 'Version'" ...don't know what this means.
Though, when I finally exit options and come back in the changes are there. I had other problems too.
I would not bother with Tide, seems buggy.
(If I supplied software like this to a customer I would be out of business)

After finding the startup.asm files in your posts, (Thanks)
I have managed to compile a simple program for example,

unsigned char x, y;
void main(void)
{
y = 100;
for(x=0;x<10;x++)
{
y++;
}
while(1);
}

Error reporting is rudimentary. For example drop the semi-colon at Y=100 above and you get

WDC 65C02 C Version 3.49.1 Feb 6 2006 16:25:18
Copyright 1992-2006 by The Western Design Center, Inc.
for(x=0;x<10;x++)

So the problem is possibly on or above this line....but we can't tell you any more.

I then add these lines and re-compile

#include "stdio.h"
char WrkSpc[20];
sprintf(WrkSpc,"HELLO WORLD");

WDC 65C816 Linker Version 3.49.1 Apr 24 2006 15:40:38
Copyright (C) 1992-2006 The Western Design Center, Inc.
Undefined symbol: _unlink
Undefined symbol: _close
Undefined symbol: _isatty
Undefined symbol: _write
Undefined symbol: _lseek

Now, the documentation (https://www.wdc65xx.com/wdc/documentati ... Linker.pdf) mentions in CHAPTER 7 WDCLN (LINKER)
that
Note: There are calls to user defined functions that are system dependent.
Example: _unlink, _ _close, _ _isatty,_ _write, _ _lseek, _ _fseek.
_ _read, _ _open, _ _creat, _ _ access (see WDC_SDS/INCLUDE/FCNTL.H

So I guess I need to write some code to perform these functions or maybe do nothing.
I don't see how sprintf uses them because the result from sprintf goes back to memory.
Actually, after this compile and link there is a HEX file. Not sure if the code will run or not.

As was pointed out, without the ability to recompile the libraries (with modified zpage and cfg files) you are stuck with the standard zpage layout.
This to me is a major problem for what I had in mind.

It would be nice to get this compiler working and to see some (even if limited) support from WDC. It could only benefit them in the long run.

(Off topic)
I receive a first (prototype) 6502 PCB in a few days. Was to lazy to breadboard or use vero board. Some people have too much time.
Was hoping to have the compiler ready to test. The board is pretty much just CPU + memory + 2 expansion slots. I did breadboard a potential video card based loosely on Ben Eater's videos. Bread boarding it is painfully slow and fixing errors means hours of rework. I bought an Altera CPLD programmer and dev board instead. Much easier to change logic on the fly.

Please keep this post alive with new information on the compiler, bug reports/fixes, etc. anything you think will help others.

I will try to use the compiler and see how far I get.

Thanks
Andre


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Mon May 03, 2021 7:24 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10822
Location: England
(Welcome!)


Top
 Profile  
Reply with quote  
 Post subject: Re: WDC02CC Compiler
PostPosted: Mon May 03, 2021 12:33 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
Hi Andre, welcome and thanks for helping try to get the compiler working. I was able to get some simple test code working but I get the same errors as you when I try to use sprintf. I also get the annoying non-sensical error messages. I think if I were ever to use this compiler, I would find some pre-existing tool that checks C code for errors and let that run first.

If you just need a C compiler, have you tried CC65? The output is not especially well optimized (hence our interest in WDC) but it's very reliable and doesn't force you to recompile libraries when you change zp usage or anything stupid like that.

EDIT: and you may want to avoid sprintf and printf anyway since they can take up a huge amount of ROM even when you're only using a small percentage of their functionality. I just handle strings myself since something like puts is basically a 1 line function. You can devise sprintf/printf functionality with very, very little code if you know exactly what you want. I've done something like this in C with CC65: PrintInt("Three is % and five is %", 3, 5); You can give a dummy argument for the second int if you only need to print the first one in the string.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: