Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C compiler? #7

Open
tywkeene opened this issue Oct 8, 2019 · 16 comments

Comments

@tywkeene
Copy link

@tywkeene tywkeene commented Oct 8, 2019

I realize, in the scheme of things, getting a C compiler running is a serious undertaking, but do you have any plans for it?

I don't have any experience with z80 assembly (Something I feel I could work on given some time, and this project to work on), but do know C.

If there were to be a C compiler, I'd love to help port over some userspace applications in the future.

Anyways, this is a really neat project, really caught my attention.

@theWebalyst

This comment has been minimized.

Copy link

@theWebalyst theWebalyst commented Oct 8, 2019

Back in the 80's my office mate (who went on to head Netflix cloud services!) had a side project to get 'Small C' running on his kit computer (not Z80 but that doesn't matter). The point is he was hand coding it to the point where it would compile itself. So that would be a suitable route to getting C and many other tools on this platform - and there are likely people who have already written the code which is needed. I just did a quick search for Z80 C compiler and turned up this handy list of Z80 tools:

http://www.z80.info/z80sdt.htm

I am committed on other projects but will keep an eye over here in case I can offer any help.

@hsoft

This comment has been minimized.

Copy link
Owner

@hsoft hsoft commented Oct 9, 2019

FUZIX has a SmallC implementation which would be a good start, but the problem is that C doesn't translate very well to z80. It is hard for a compiler to properly optimize register usage, so you end up with either inefficient binary or complicated C compiler. Either way, RAM usage gets big.

It would be nice to have, but not very high in my priorities.

@agsb

This comment has been minimized.

Copy link

@agsb agsb commented Oct 9, 2019

Always have the original system6 of old Unix as reference

@NoahGWood

This comment has been minimized.

Copy link

@NoahGWood NoahGWood commented Oct 9, 2019

I imagine implementing BASIC would be much easier than C for an 8 bit processor

@hsoft

This comment has been minimized.

Copy link
Owner

@hsoft hsoft commented Oct 9, 2019

@NoahGWood Yes, there are many many BASIC interpreters written in z80 asm. Eventually, one of them (that isn't copyright-ladden) could be integrated in Collapse OS.

@Midnoclose

This comment has been minimized.

Copy link

@Midnoclose Midnoclose commented Oct 10, 2019

@hsoft perhaps something similar to this could be made: https://github.com/nanochess/bootBASIC

@aaretali

This comment has been minimized.

Copy link

@aaretali aaretali commented Oct 10, 2019

One BASIC interpreter that could be somewhat useful was published in Soviet magazine 'Radio" in early 1980-s, under 8KB in size. It was for i8080, but Z80 can execute all i8080 instructions. The only requirement from hardware was to have a specific ROM-BIOS, but that ROM was 2K with only few input/output subroutines. Both were published as hex dump and since they were in a magazine they can be freely shared.

@aaretali

This comment has been minimized.

Copy link

@aaretali aaretali commented Oct 10, 2019

There is CWDL CC386 C compiler, http://ladsoft.tripod.com/cc386_compiler.html. I used much earlier version of it and reworked code generator to produce Z80 assembly. The compiler was running as a cross-compiler on MS-DOS host, but it was supporting fairly good amount of C so it could be self-hosting (never tried this though). I chose it over Small-C and Micro-C for various reasons. If this sounds interesting enough, I could dig it out of my backups.

@keithstellyes

This comment has been minimized.

Copy link
Contributor

@keithstellyes keithstellyes commented Oct 11, 2019

Surprised nobody mentioned sdcc, it's regularly updated and frequently mentioned when Z80 and C comes up

http://sdcc.sourceforge.net/

But, I assume we would want it actually running on the Z80 :)

@aaretali

This comment has been minimized.

Copy link

@aaretali aaretali commented Oct 14, 2019

You're right, it needs to run in 64KB address space on a Z80.

SDCC is just too fat for fitting into 64K of RAM. 4 largest source files in SDCC are between 100KB and 288KB. The entire generic source tree is over 1.5MB, Z80 code generator is another 650KB, one file of the code generator is 400KB alone.

This is why Small-C and others are much more viable. Desmet C http://desmet-c.com/ and BDS C https://www.bdsoft.com/resources/bdsc.html from CP/M world were open-sourced recently.

@hsoft

This comment has been minimized.

Copy link
Owner

@hsoft hsoft commented Oct 16, 2019

I had a look at BDS C at the beginning of this year and it looked promising. Well written. A lot of fitting work will be necessary, however, to have this run on Collapse OS.

@nelsonrpn

This comment has been minimized.

Copy link

@nelsonrpn nelsonrpn commented Oct 16, 2019

If more people come with me, im up to design and write a new language and compiler that fit in the whole idea, i think we have time to do this before the collapse

@Midnoclose

This comment has been minimized.

Copy link

@Midnoclose Midnoclose commented Oct 17, 2019

What about a simple lisp interpreter? https://github.com/kanaka/mal

@f4grx

This comment has been minimized.

Copy link

@f4grx f4grx commented Oct 17, 2019

This is not a compiler that generates native code.

@Midnoclose

This comment has been minimized.

Copy link

@Midnoclose Midnoclose commented Oct 17, 2019

@f4grx perhaps something like https://github.com/dubek/malc without llvm, written in z80 assembly

@Allisontheolder

This comment has been minimized.

Copy link

@Allisontheolder Allisontheolder commented Nov 12, 2019

SmallC is existent and developed on a CPM z80 system. its output is assembler
and you assemble and link modules. It was self compiling on a minimum of 48K
and preferable 56K system.

There were two other smaller Cs all ran in less than 48K, self compiling was not
known as source was unavailable.

I used BDS-C as it was fast, small and it was also direct to assembled code system
that could handle code broken into modules. BDS C relies on many of the CP/M
BDOS APIs (borrow a PC term) to operate quite a few so you would need a
source to build your own and knowledge of the CP/M APIs to work out what the
required functions do. Doable but maybe writing a C compiler from SmallC is easier.

NOTE that is the TPA Transisent Program Area and it extends from the 0100h to the bottom
of BIOS in high memory. A full boat system without bank switching can be as large as 61K
but typical is more like 60K.

The compiler (SMALLC) also writes out to disk/mass storage so you need space there as well.

SDCC was never a resident on z80 systems, it was for PCs for cross platform work.

I havent got ther eyet but is there a uniform interface for applications programmer to use for file and character IO? does it provide functions similar to string input with editing, or print a string?
What is the calling protocol, address of routine or function number though a common address?

Allison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.