6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 8:15 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Apr 12, 2020 8:46 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Back in January when CaptainCulry start a post about creating an SL appliance (http://forum.6502.org/viewtopic.php?f=12&t=5898) I tried porting the sl utility using the WDC 6502 C compiler and found that it mysteriously crashed mid-module so I gave up and ported part of it manually to assembler.

I found some time today to try and figure out why the compiler is crashing. I added comment blocks to the code until the (nearly) empty files where compilable (but did nothing) then removed the comments one at a time until the compiler crashed and examined the last section to see what might have triggered it.

It turns out the tenary (or conditional) operator (e.g. (a == 9) ? x : y) is the source of the bug. When I replaced these with equivalent code using if/then/else and added some support code for UNIX functions not in the WDC library, I managed to get it all compiled and linked.

At the moment its over 32K linked with over 16K of data. I may have to take one of the trains out to make it run in less memory. There are too many strings.
Code:
        wdcln -G -HZ -G -T -C0300 -Osl.bin  sl.obj curses.obj unix.obj -Lc
WDC 65C816 Linker Version 3.49.1 Apr 24 2006 15:40:38
   Copyright (C) 1992-2006 The Western Design Center, Inc.

Section: ORG:    ROM ORG:  SIZE:
PAGE0    000020  ------       4EH (    78)
CODE     000300  000300     2B42H ( 11074)
DATA     002E42  002E42     41DEH ( 16862)
UDATA    007020  ------     1F4AH (  8010)
Total

The SL application uses the UNIX ncurses library and I have started coding a simple implementation. I will keep working at it so it can serve as a demonstration of the WDC 6502 C compiler.

I'll try to get a video of it running on one of my three chip boards at a measley ~1MHz when its complete.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 18, 2020 7:46 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
After a lot of head scratching I managed to get the WDC 65C02 C Compiler to build a simple working application.

I'm going to get something a bit more substantial working and then upload it all to github with some documentation.

It turns out:

1. You have to avoid conditional expressions (as in stated in the last post)
2. Edit the wdc02cc.cfg file in the wdc/tools/bin file to match the C runtime memory usage or it defaults to the 65C134 model.
3. Write your own startup module to initialise the return stack, function frame stack, initialised data (if in ROM) and clear the uninitialised RAM to zero -- boiler plate but not provided by WDC with the free edition of the tools.
4. Provide dummy implementations of some standard I/O functions and write code to map others to your hardware or BIOS functions.

I get the impression that WDC's compiler is a more complete version of C that CC65 but I don't think its as efficient at function calls.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2020 6:06 pm 
Offline

Joined: Sun Oct 07, 2018 6:04 pm
Posts: 30
Do you have this project on Github? I am a bit interested in playing with a real 6502 C project.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 11:56 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
If you can please wait until I've finished working on the compiler and library.

Using the current released version is very hard as its crashes very easily. My fixed version is a lot more stable and I'm using it to write code for the W65C165MMC.

When I've finished updating the library it should be possible to get WDC to do a release.

I'm doing this in my limited spare time so it will take a while longer.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 4:46 pm 
Offline

Joined: Sun Oct 07, 2018 6:04 pm
Posts: 30
There is no big hurry on my side, take your time.

The reason why I ask is that I have a 6502 C compiler in the works and it would be interesting to try a real project out. I just want to compile, study output and perhaps compare to WDC C to get an idea of where I am.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 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: