Page 3 of 3
Re: Starting with C on the QL
Posted: Sat Sep 06, 2014 3:30 pm
by Derek_Stewart
Hi Tom,
I think recompiling on a modern version is a really good idea.
I will see if I can do this on my 64Bit Ubuntu 14.04 laptop.
Re: Starting with C on the QL
Posted: Sat Sep 06, 2014 6:53 pm
by tcat
Derek,
I tested qdos-gcc on hello world prog
Code: Select all
#include <stdio.h>
main (int argc, char *argv[])
{
printf ("%s\n\n", "hello world!");
}
on my Linux box I compile as follows
Code: Select all
$ qdos-gcc hello.c -o hello
hello: dataspace 882 (372)
It reports the stack dataspace value, plus another value in parenthesis, that I do not know what means exactly
It produces a binary hello without an executable header, when transferred to the QL, and after creating the header.
It can execute in STD I/O window as follows

- Hello World!
- hello.png (1.63 KiB) Viewed 4595 times
Tom
Re: Starting with C on the QL
Posted: Sun Feb 19, 2017 11:09 pm
by XorA
It reports the stack dataspace value, plus another value in parenthesis, that I do not know what means exactly
its the same value in hex
Re: Starting with C on the QL
Posted: Mon Feb 20, 2017 12:22 am
by stevepoole
Hi,
First try learning C and C++ , then try transcoding very short and simple superbasic programs directly into C.
When you understand the initial C notions, it will be easier to understand what is required by C68.
You are advised to write superbasic in a way that C can be easily adapted to.
Transcoding long superbasic code is easier if that code can be turbo-compiled.
Turbo-code can be more easily CPorted, Cfixed and then becomes executable C68-code.
To get C68 code to run natively on a PC, you have to rewrite all the SB_keyword calls into C-code.
Because C68 is not C, just an adaptation of C for the QL.....
Native PC C code runs hundreds of times faster than superbasic, but the latter is oh so much easier to write and debug...
I have spent more than a year doing such things with two other QL programmers. There were scores of pages of tight superbasic code.
It was a very big undertaking, but eventually suceeded, after grappling with hardware, emulator and front-end software incompatibilities.
QL software can be ported to native PCs, but demands a lot of software modifications at every step.
A short account will appear in the next issue of the Quanta magazine.
Steve Poole.
Re: Starting with C on the QL
Posted: Mon Feb 20, 2017 12:50 am
by swensont
"To get C68 code to run natively on a PC, you have to rewrite all the SB_keyword calls into C-code.
Because C68 is not C, just an adaptation of C for the QL....."
C68 really is C and the most complete C compiler on the QL. It can do both K&R C and ANSI C. If your C / C68 code makes use of a lot of QDOS library calls, then that is not very portable code and will not compile on another platform (unless someone writes a library that converts QDOS calls to something similar in that OS). Writing portable C code is a long subject and it addresses compiler differences, version differences and OS differences. A C program written for DOS may not work on Linux. I've been writing some C programs for C68 knowing that they will be ported to Linux, so I've written them to be as simple as possible and they have compiled fine on Linux with a few minor changes.
Tim Swenson
Re: Starting with C on the QL
Posted: Mon Feb 20, 2017 7:28 am
by stevepoole
Hi Tim,
Yes, our team wrote the C and C++ extensions, to transcode alll the standard SB_procs_&_fns (from Cported QDOS Library calls).
So our extensions mean that superbasic can be transcoded into C68, and becomes usable on native PCs.
The process is almost automatic, but requires several intermediate platforms and interfaces, but is easier than writing the C code by hand...
But your SuperBasic must be adapted to conform to the intermediate configurations, so some rewriting of the superbasic source is necessary.
A fully automatic transcoding QL software system would require much work being done on all the other more recent extensions.
CPort is a very old piece of software now, but it works remarkably well on standard superbasic keywords in the beginner's guide...
C you later!
Steve.
Re: Starting with C on the QL
Posted: Tue Feb 21, 2017 2:18 am
by ql_freak
Slightly OFFTOPIC:
C68 ist GREAT - but it is IMHO not capable of producing reentrant code (programs which you can HOT_CHP without the I option). But there is one C compiler available for the QL which can do it. Unfortunately it was never officially released:
EJC (Erling Jacobsen's C). It uses the commercial Lattice-C Compiler (published by Metacomco), which always was capable of producing reentrant code (also there were no libs and startup files, so that you could use it). Erling has corrected that.
So if you have the chance to get this excellent compiler (it is a full K&R-compiler, in opposite to e.g. Digital Precision C or GST C), then get, buy or steel it! It's superb for QDOS.
Re: Starting with C on the QL
Posted: Tue Feb 21, 2017 8:52 am
by XorA
Lattice-C
Fondly remembered from the Amiga, it was a great compiler!
Re: Starting with C on the QL
Posted: Tue Feb 21, 2017 9:19 am
by tofro
ql_freak wrote:Slightly OFFTOPIC:
C68 ist GREAT - but it is IMHO not capable of producing reentrant code (programs which you can HOT_CHP without the I option).
C68 actually has some options to produce position-independent code:
Code: Select all
datamodel = small
codemodel = small
regdata = a5
regframe = a6
Should produce a position-independent program according to the documentation (provided you have libraries compiled in such a way). Unfortunately, though, this combination of options tends to trigger an internal compiler error in my installation. Apparently, support for PIC has not been fully completed.
Tobias