6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun May 12, 2024 10:04 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Using WDCTools
PostPosted: Tue Sep 05, 2023 7:59 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Hi guys,

I finally got around to making a very minimalistic homebrew computer using a W65C02 and am beyond happy with the progress so far!

I am presently trying to get my head around how to compile a simple C program with WDCTools, but am running in to issues.

The code I am attempting to compile is as simple as it gets.

Code:
int main()
{
   return 0;
}


I can compile it happily by running wdc02cc test.c which generates an object file of test.obj.

Quote:
G:\wdc\Tools\bin>wdc02cc test.c
WDC 65C02 C Version 3.49.1 Feb 6 2006 16:25:18
Copyright 1992-2006 by The Western Design Center, Inc.


But if I try to link it by doing wdcln -C8000 -D200, test.obj I get an error.

Quote:
G:\wdc\Tools\bin>wdcln -C8000 -D200, test.obj
WDC 65C816 Linker Version 3.49.1 Apr 24 2006 15:40:38
Copyright (C) 1992-2006 The Western Design Center, Inc.
Undefined symbol: ~csav


I have had a brief read through the manual (https://www.westerndesigncenter.com/wdc ... mpiler.pdf) but am at a loss as to what I am doing wrong.

Any advice would be greatly appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 8:12 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Ah! It looks like I needed to add an additional parameter (-LC)

Although I'm not quite sure if the output is what I'm expecting to see, as it starts with a PHA ($5A) then a BRK ($00) etc... Which seems unusual to me.

Code:
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000  5A 00 80 00 0C 00 00 20 0C 80 00 00 00 00 86 58  Z.€.... .€....†X
00000010  86 59 60 0C 80 00 EB 00 00 AA 68 85 38 68 85 39  †Y`.€.ë..ªh…8h…9
00000020  18 68 69 01 85 30 68 69 00 85 31 A0 01 B1 38 C9  .hi.…0hi.…1 .±8É
00000030  FF D0 01 8A 85 3E 38 A5 32 85 48 E5 3E 85 3C A5  ÿÐ.Š…>8¥2…Hå>…<¥
00000040  33 85 49 E9 00 85 3D 38 A5 3C E9 09 85 40 A5 3D  3…Ié.…=8¥<é.…@¥=
00000050  E9 00 85 41 C8 B1 38 85 3F 38 A5 40 E5 3F 85 44  é.…Aȱ8…?8¥@å?…D
00000060  A5 41 E9 00 85 45 08 78 C8 18 A5 44 71 38 85 32  ¥Aé.…E.xÈ.¥Dq8…2
00000070  C8 A5 45 71 38 85 33 28 A5 3E AA F0 09 A0 00 68  È¥Eq8…3(¥>ªð. .h
00000080  91 3C C8 CA D0 F9 A0 07 B9 30 00 91 40 88 10 F8  ‘<ÈÊÐù .¹0.‘@ˆ.ø
00000090  A5 48 A0 02 91 40 C8 A5 49 91 40 A5 40 85 34 A5  ¥H .‘@È¥I‘@¥@…4¥
000000A0  41 85 35 A5 44 85 36 A5 45 3A 85 37 A5 3F A0 08  A…5¥D…6¥E:…7¥? .
000000B0  91 34 A8 F0 09 88 B9 20 00 91 44 88 10 F8 18 A5  ‘4¨ð.ˆ¹ .‘Dˆ.ø.¥
000000C0  38 69 05 85 38 90 02 E6 39 A9 80 48 A9 C9 48 A9  8i.…8..æ9©€H©ÉH©
000000D0  00 AA A0 01 6C 38 00 E6 37 A0 08 B1 34 A8 F0 09  .ª .l8.æ7 .±4¨ð.
000000E0  88 B1 36 99 20 00 88 10 F8 A5 34 85 3C A5 35 85  ˆ±6™ .ˆ.ø¥4…<¥5…
000000F0  3D A0 07 08 78 B1 3C 99 30 00 88 10 F8 28 A0 01  = ..x±<™0.ˆ.ø( .
00000100  8A 6C 30 00 00 00 00 00 00 00                    Šl0.......


Hopefully someone with a bit more experience might be able to shine some light on this?


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 9:15 am 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
Honestly I wouldn't recommend the WDC Tools considering all the community made tools available that are usually less buggy, more modern, and intuitive.
I did get the compiler working years ago, If you actually want to stick with the tools then after work I can see if I still have that mostly functional setup on my PC and post it.

But for tool alternatives I would recommend cc65, an open source and active compiler/assembler/linker utility.
It's also usable for the 65816 but not the compiler, it's only for the 8-bit 65xx CPUs.
There is also [url]Calypsi C[/url] which gives you a C compiler/assembler/linker for the 65C02 and 65816.
There are probably a lot more tools online as well.


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 9:24 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Thanks for that, Proxy.

Funnily enough I started off this endeavor with CC65 today. Testing on the C64, but it turns out there is a confirmed bug in the latest version which leaves me dead in the water on that front too (https://www.lemon64.com/forum/viewtopic ... 76#p998776).

I guess I'll look in to Calypsi C as a third option now.

Not having a good run. :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 9:37 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 298
It looks like it's giving you 'WDC Binary' format even though you're not asking for it. Page 37 of the linker documentation https://www.westerndesigncenter.com/wdc/documentation/Assembler_Linker.pdf describes it:
Code:
Initial byte 'Z' as signature.
Then for each block:
    3 byte address
    3 byte length
    length bytes of data
The final block has an address and length of 0.

So you have a block at 008000 of size 00000c, starting 20 0c 80 00 00 00 00 86 58 ... (JSR $800c, ..., STX $58, STX $59, RTS).
Then a block at 00800c of size 0000eb, starting aa 68 85 38 68 ... (TAX, PLA, STA $38, PLA, ...)
I'm guessing the code at $800c is adjusting the return address to skip over the 00 bytes at $8003.


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 12:15 pm 
Offline

Joined: Mon Sep 17, 2018 2:39 am
Posts: 133
Hi!

J64C wrote:
Thanks for that, Proxy.

Funnily enough I started off this endeavor with CC65 today. Testing on the C64, but it turns out there is a confirmed bug in the latest version which leaves me dead in the water on that front too (https://www.lemon64.com/forum/viewtopic ... 76#p998776).

You just hit a bad commit that broke the C64 link script....

Until the fixed version is out, It is very easy to fix locally, just edit the "c64.cfg" file and in the line for the segment "INIT" change the type from "bss" to "rw".

The fixed line should look like this:
Code:
INIT: load = MAIN, type = rw, optional = yes;

Have Fun!


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 10:17 pm 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
Excellent! That did the job. :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Tue Sep 05, 2023 10:44 pm 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
So with CC65, how would you go about setting up a 'vanilla' config file that assumes nothing about the system.

With the C64 config file, when executing your prg on a C64, my empty program (return 0) drops the system in to lowercase text mode, meaning there is a bit more going on than just a simple return 0. Which means the compilation process is assuming a bit more than just what's in the cfg file. That, and it's adding the BASIC header for the SYS call.

Edit - Reading through https://cc65.github.io/doc/customizing.html right now to see if I can make sense of it all.


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Wed Sep 06, 2023 7:10 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
This is how I use cc65 for a simple project that assumes nothing about the system:
viewtopic.php?p=57876#p57876


Top
 Profile  
Reply with quote  
 Post subject: Re: Using WDCTools
PostPosted: Wed Sep 06, 2023 7:52 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 137
BigEd wrote:
This is how I use cc65 for a simple project that assumes nothing about the system:
viewtopic.php?p=57876#p57876


Very nice! Thanks for the heads up!


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

All times are UTC


Who is online

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