6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 6:34 am

All times are UTC




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Feb 21, 2024 5:04 pm 
Offline

Joined: Tue Jan 09, 2024 6:48 am
Posts: 3
Have built a WDC65c816SXB-inspired SBC with a 65c816 CPU with an 6551 ACIA for console input/output. Have an assembler startup file that does the basic initing of CPU and ACIA after power-up and then transfers to control to the main() function in a .c file. At the moment, the main() function calls two functions I wrote myself called getchar() and putchar(). These are used to show a welcome message on the console and to read keystrokes from the keyboard. Both functions directly access the 4 ACIA registers, memory-mapped at RAM addresses 0x7F80...0x7F83. Nothing too hard or shocking. The ANSI-compliant C compiler from WDC (WDC816CC) includes the standard libraries that also have putchar() and getchar() functions. They typically read from stdin and write to stdout.

How do I configure the compiler's putchar() and getchar() to use those RAM addresses so they can replace my versions? This way I can also use other "stdio.h" functions such as printf() and scanf()?


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 21, 2024 6:23 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 745
Location: Germany
personally i wouldn't be using WDC's tools, they definitely show their age... but if you get them to work and they work fine for your needs then go ahead.
but i would recommend something like Calypsi C, it's C99 instead of C89, has pretty good documentation, and is actively being maintained.
i also remember vbc (a forum member) talking about working on a VBCC port for the 65816, but that was a really long time ago and i wonder what happend to that project since (from my experience) making a crappy but functional backend shouldn't take that long, right?

anyways back to the WDC tools, i don't know how exactly they handle their standard libraries (but from the documentation i can see that they include them), but i'd assume that similar to newlib, the included libraries would only contain the hardware independent components which would make calls to system specific functions (open, close, read, write, sbrk, etc.)
to see if that's the case you could just try it out. make a simple hello world program with printf, include the given library while linking and then see which function the compiler will complain about being missing.

or if they include the source code for the used libraries (which they should) try to see if you can find any function stubs for read, write, etc. or grep (findstr on windows) through them to find any mentions of functions like that, which would also tell you what arguments they need.

then you just write them (either in assembly or C) assemble/compile them to object files and throw them into a library to link along side your program.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 3:46 pm 
Offline

Joined: Wed Jan 03, 2007 3:53 pm
Posts: 50
Location: Sunny So Cal
My main objections to Calypsi C are closed source, x86 only and restrictive license terms. But I suppose it's good it's out there.

_________________
Machine room: http://www.floodgap.com/etc/machines.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 4:29 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 745
Location: Germany
the same is true for the WDC tools though, unless they just released the source code or made an ARM (or native 65816) version that i don't know of...

i'm still hoping for that VBCC port so we have a fully open source compiler that could in theory compile itself to allow for native C programming on a 65816. ah, the dream!


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 4:44 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 660
Location: Potsdam, DE
There's still SDCC (I still need to try out the latest version; the last had some issues. The most recent is still missing 6502 and 65c02 specific documentation).

I seem to remember that with SDCC it is necessary only to define putc() and getc() to make the stdio work.

Neil

edit: putchar() and getchar() - see here: viewtopic.php?f=2&t=7049#p98263


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 6:10 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 745
Location: Germany
wait since when does SDCC have a 65816 target? i can't find anything to that online...


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 8:12 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 660
Location: Potsdam, DE
Oh I'm sorry; for some reason I thought we were looking for 65(c)02.

Mea culpa!

Neil


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 8:39 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
Proxy wrote:
i'm still hoping for that VBCC port so we have a fully open source compiler that could in theory compile itself to allow for native C programming on a 65816. ah, the dream!

Dr Volker had briefly mentioned a 65C816 VBCC port in work about a year ago.  However, nothing seems to be forthcoming.  I suspect such a port is not a trivial project and also suspect it will remain vaporware for the foreseeable future due to the complexity involved, as well as the limited demand for such a thing.

Every so often, I get a small burr under my saddle to look at porting the ehBASIC interpreter to the 816 running in native mode and making full use of 16-bit registers, enhanced stack capabilities, etc.  I then come to my senses as I contemplate the amount of work involved and the fact that relative to the typical lifespan of most men, I am a short-timer.  :D  I don’t even have a working kernel written for my POC unit, so finding time to rework a major piece of software such as ehBASIC seems ludicrous to me—I’m literally unlikely to see results in my lifetime.  :(

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 9:19 pm 
Offline

Joined: Mon Feb 15, 2021 2:11 am
Posts: 98
Alan Cox has a C compiler under development that includes 6502 and 65816 support as part of his FUZIX Compiler Kit project. I don't think it is production ready yet, and I believe it has some limitations due to its intended use as part of the FUZIX project. No idea how good it is. Source is at https://github.com/EtchedPixels/Fuzix-Compiler-Kit.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 9:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
I don't like to see the term "vaporware" applied to personal projects. It reads to me as perjorative. If a project seems to be making slow progress, there will be reasons. No-one has a right to demand that someone else's project should make progress.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 10:04 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
Proxy wrote:
personally i wouldn't be using WDC's tools, they definitely show their age...

Some years ago, I mucked around with the WDC tools, but ended up setting them aside.  C compilation for the 65C816 seemed reasonably competent, but the resulting linked binaries tended to be bulky and slow-executing.

One of my tests was to implement my version of mkfs (filesystem builder) in C, which uses a lot of integer math and BIOS I/O calls.  During testing, the C version of mkfs ran at about one-fourth the speed of the assembly language version.  Additionally, the binary produced by the WDC linker was nearly twice the size of that produced by assembly language.  Although I didn’t dig into the binary to see where the bottlenecks were, I suspect the compiler’s handling of the API interface was inefficient.

Based on that testing, as well as on some other tests I ran, I decided that while C in itself on the 816 would be acceptable for applications, and possibly an operating system kernel¹, using the WDC compiler to compile the source would not produce satisfactory results.

Quote:
i also remember vbc (a forum member) talking about working on a VBCC port for the 65816, but that was a really long time ago and i wonder what happend to that project since (from my experience) making a crappy but functional backend shouldn't take that long, right?

I suspect an 816 back end that knows how to effectively use the different possible memory models (similar to what C compilers of the 8086-80286 era had to do) would be a non-trivial exercise.  For example, in my assembly language programs, I use macros for library function calls that know the difference between “near” and “far” pointers,² each of which requires a different approach to constructing the stack frame that passes parameters into the function.  The macros were definitely not trivial to write, so I imagine code for a C compiler that would be able to implement equivalent 816 memory models would also not be trivial to develop.

A complication with C on the 816 is how to define the heap and how to give a running program more RAM when requested, i.e., how to model the equivalent of sbrk and malloc.  While the 816’s address space can be treated as flat for data purposes, in some cases, treating it as segmented may result in a faster-executing program, mainly due to the aforementioned use of 16-bit pointers, vs. 24-bit.³  That being a consideration, sbrk has to know which addressing model to use—a one-size-fits-all approach is not going to work.

—————————————————————————
  1. The time-critical parts, mainly interrupt handlers and device drivers, would likely have to be written in assembly language.

  2. In this context, “near” and “far” refer to objects that are in the execution bank or are elsewhere in memory, respectively.  “Near” addressing can use a 16-bit pointer, which can be dereferenced more quickly than the “far” equivalent.

  3. 24-bit pointers on the 816 are computationally inefficient—I use 32-bit pointers for “far” accesses.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 10:22 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
BigEd wrote:
I don't like to see the term "vaporware" applied to personal projects.  It reads to me as perjorative.

Vaporware, as defined in Wikipedia:

Quote:
In the computer industry, vaporware (or vapourware) is a product, typically computer hardware or software, that is announced to the general public but is late, never actually manufactured, or officially cancelled.

I’m not using “vaporware” in a pejorative sense.  The term’s definition is sufficiently generalized to be understood as “the product is not forthcoming.”  I’m merely highlighting the fact that significant time has elapsed between the present and when the 65C816 vbcc port was mentioned.

Quote:
No-one has a right to demand that someone else's project should make progress.

No one has made any such demand.  You are manufacturing controversy out of thin air, Mr. Ed.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 11:02 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 745
Location: Germany
BigDumbDinosaur wrote:
I suspect an 816 back end that knows how to effectively use the different possible memory models (similar to what C compilers of the 8086-80286 era had to do) would be a non-trivial exercise.  For example, in my assembly language programs, I use macros for library function calls that know the difference between “near” and “far” pointers,² each of which requires a different approach to constructing the stack frame that passes parameters into the function.  The macros were definitely not trivial to write, so I imagine code for a C compiler that would be able to implement equivalent 816 memory models would also not be trivial to develop.

that's why i specifically said crappy backend. getting a backend into a "functional" state doesn't nearly take as long as making it generate good assembly.

my own SW32VM backend for VBCC took me a few months to get (mostly) working, 32-bit ints are broken for some reason, and VBCC doesn't include any kind of test suite, so knowing what features are still missing is difficult. but for having never worked with VBCC before i think i did pretty good so far. (i'll post an update on the SW32VM thread when i get time to just sit down and write it and push all updates to the github as well)

anyways this is why i would think that someone (or a team of people) much more knowledgeable than me likely already have a mostly functional backend and now just focus on bug fixing, optimizing the code generation, and adding customization options (like default pointer sizes).


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 22, 2024 11:03 pm 
Offline

Joined: Thu Apr 23, 2020 5:04 pm
Posts: 45
Proxy wrote:
i also remember vbc (a forum member) talking about working on a VBCC port for the 65816, but that was a really long time ago and i wonder what happend to that project since (from my experience) making a crappy but functional backend shouldn't take that long, right?

Unfortunately some issues have prevented me from working on it as I had originally planned. It has not been canceled and the backend is mostly complete, but I still need to finish the C library, run my test suite, and do some optimizations.

And I am not aiming for "crappy but functional". :-)


Top
 Profile  
Reply with quote  
PostPosted: Fri Feb 23, 2024 1:10 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
vbc wrote:
And I am not aiming for "crappy but functional". :-)

That’s reassuring!  “Crappy but functional” would be too much like Microsoft Windows.  :D

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


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

All times are UTC


Who is online

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