Starting with C on the QL

Anything QL Software or Programming Related.
Derek_Stewart
Font of All Knowledge
Posts: 3958
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Starting with C on the QL

Post 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.


Regards,

Derek
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: Starting with C on the QL

Post 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 World!
hello.png (1.63 KiB) Viewed 3703 times
Tom


User avatar
XorA
Site Admin
Posts: 1365
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Starting with C on the QL

Post 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


stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: Starting with C on the QL

Post 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.


swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: Starting with C on the QL

Post 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


stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: Starting with C on the QL

Post 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.


User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: Starting with C on the QL

Post 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.


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
XorA
Site Admin
Posts: 1365
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Starting with C on the QL

Post by XorA »

Lattice-C
Fondly remembered from the Amiga, it was a great compiler!


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Starting with C on the QL

Post 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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Post Reply