Starting with C on Atari
Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team
Starting with C on Atari
I have coded a lot in C on PC and would like to do some on the Atari as well. Are there any good compilers that let you set up projects similar to Visual Studio on PC and how fast is the compiled result compared to something coded in assembler. Ok I understand that it's not so easy to say since it all depends on the application and how good you code it, but let's say something like game logic or similar stuff that is not tight graphic loops.
It had been good if it's possible with inline assembly so it's possible to make critical stuff in assembler.
It had been good if it's possible with inline assembly so it's possible to make critical stuff in assembler.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
- tenox
- Captain Atari
- Posts: 382
- Joined: Thu Apr 05, 2012 11:52 pm
- Location: Sunnyvale, California
- Contact:
Re: Starting with C on Atari
There are a few, but most popular are, Pure C which is a Borland Turbo C clone and Lattice C. Check here:
https://sites.google.com/site/stessential/development
Pure C seems to be simpler but in the past I had much more luck with Lattice C.
Also see this:
http://info-coach.fr/atari/software/languages.php
https://sites.google.com/site/stessential/development
Pure C seems to be simpler but in the past I had much more luck with Lattice C.
Also see this:
http://info-coach.fr/atari/software/languages.php
Re: Starting with C on Atari
There is also AHCC and VBCC. AHCC is pure C compatible, comes with an IDE and should be easy to set up.
http://members.chello.nl/h.robbers/
VBCC can be used for cross compiling as well as natively though I am not quite sure on the memory requirements.
http://sun.hasenbraten.de/vbcc/
I also found this site that has more detailed information so you can figure out what is best for you. I haven't done any C coding so I can't say much..
http://koti.mbnet.fi/tammat/hatari/devel.shtml
http://members.chello.nl/h.robbers/
VBCC can be used for cross compiling as well as natively though I am not quite sure on the memory requirements.
http://sun.hasenbraten.de/vbcc/
I also found this site that has more detailed information so you can figure out what is best for you. I haven't done any C coding so I can't say much..
http://koti.mbnet.fi/tammat/hatari/devel.shtml
Re: Starting with C on Atari
I guess GCC and VBCC generates fairly efficient code. AHCC doesn't generate equally fast code afaik, but on the other hand it works really really well when developing natively since compile times are much shorter.Zamuel_a wrote:I have coded a lot in C on PC and would like to do some on the Atari as well. Are there any good compilers that let you set up projects similar to Visual Studio on PC and how fast is the compiled result compared to something coded in assembler. Ok I understand that it's not so easy to say since it all depends on the application and how good you code it, but let's say something like game logic or similar stuff that is not tight graphic loops.
It had been good if it's possible with inline assembly so it's possible to make critical stuff in assembler.
Ain't no space like PeP-space.
Re: Starting with C on Atari
What are you going to make?Zamuel_a wrote:I have coded a lot in C on PC and would like to do some on the Atari as well.
I've used Lattice C, PureC and gcc quite a lot the last 20 years, and have now landed on AHCC.Zamuel_a wrote: Are there any good compilers that let you set up projects similar to Visual Studio on PC...
gcc produce efficient code but is very slow and eats huge amounts of memory. You would need atleast a TT with lots of memory, and either make or a GEM-based IDE like AGNUS to actually build something. You can use inline assembly in gcc. gcc is the only c++ compiler for TOS/MiNT.
PureC has a good, fast and efficient editor/IDE with a decent debugger (in TOS only). Produce less optimized code than gcc, but still quite good. Widely used, much commercial software was developed with PureC. No inline assembly, you must put assembler functions in separate files. *Very* fast compilation, PureC and AHCC are IMO the only realistic options if you're developing on a stock Atari.
Lattice C is comprehensible, and was widely used in the 90's. Still favoured by some, but I never really liked it. Compared to PureC it was slow and sluggish IMO. But it came with excellent documentation. I don't know anything about the quality of the produced binaries, sorry.
AHCC is actively developed. Quirky editor/IDE, but I'm beginning to like it. Loosely based on Sozobon X, binary compatible with PureC objects and linker, quite fast and fully open source. Solid and stable, but some bugs in the libraries. Good support from the author. Does not optimize code much, but OTOH it can produce binaries that works on both 020-060 and ColdFire. Inline assembly is supported, and you can access variables/structures declared in C directly from assembler.
VBCC is the new kid on the block. I'm not familiar with it. It comes from the Amiga world, Atari/TOS-support is relatively new. Actively developed.
gcc, AHCC and vbcc can produce native Coldfire binaries. AHCC can even produce binaries that runs on both 020-060 and Coldfire.
Forget about Sozobon C, Lazer C, Mark Williams C and a few other implementations from the stone age. They are not worth spending time on
There's more detailed information and some download links on Eero Tamminen's web site.
I guess that depends on the person that writes the assembler codeZamuel_a wrote:...and how fast is the compiled result compared to something coded in assembler.

If you're developing on an Atari, and you're developing games, I'd say PureC and AHCC both are good choices. PureC for it's very quick IDE and compiler, excellent help-system and good debugger. AHCC for almost equally quick IDE/compiler, better support for inline assembler and partial C99. Forget about gcc on real hardware, unless it's a CT60 or Firebee.Zamuel_a wrote:Ok I understand that it's not so easy to say since it all depends on the application and how good you code it, but let's say something like game logic or similar stuff that is not tight graphic loops.
It had been good if it's possible with inline assembly so it's possible to make critical stuff in assembler.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
Re: Starting with C on Atari
And AHCC also has an IDE. Not exactly Eclipse, but very functional. The GUI is quirky, but very efficient when you're getting used to it. Very PureC-like in some aspects. E.g. the code you're working on is calling a function "foo(bar)", but you can't remember where that function is implemented. Just position the cursor somewhere on the function name and press Help, and you jump to the function implementation. Press Undo and you jump back to were you were working. Simple and brilliantly efficient.shoggoth wrote:I guess GCC and VBCC generates fairly efficient code. AHCC doesn't generate equally fast code afaik, but on the other hand it works really really well when developing natively since compile times are much shorter.
It can also display a function call three, as well as a dependencies three. Very useful, especially when working with other people's code.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
Re: Starting with C on Atari
AHCC has indeed some really nice features which makes life easier, but for some reason it doesn't have syntax highlighting, and I haven't found a way to switch to a more programmer friendly font. Maybe I've missed something.joska wrote:And AHCC also has an IDE. Not exactly Eclipse, but very functional. The GUI is quirky, but very efficient when you're getting used to it. Very PureC-like in some aspects. E.g. the code you're working on is calling a function "foo(bar)", but you can't remember where that function is implemented. Just position the cursor somewhere on the function name and press Help, and you jump to the function implementation. Press Undo and you jump back to were you were working. Simple and brilliantly efficient.
It can also display a function call three, as well as a dependencies three. Very useful, especially when working with other people's code.
Ain't no space like PeP-space.
Re: Starting with C on Atari
You can't select fonts, but it does have limited syntax highlighting. I'm not a big fan of syntax highlighting myself but I see the value in it.
One thing I'm missing is the ability to fold code. Many editors can fold code between brackets and/or indendation levels, which I find very useful. Once you've got a working function, just fold it and the implementation is hidden from view.
But the nice thing about AHCC is that it's fully open source, so if I really miss these things I can do something about it myself.
One thing I'm missing is the ability to fold code. Many editors can fold code between brackets and/or indendation levels, which I find very useful. Once you've got a working function, just fold it and the implementation is hidden from view.
But the nice thing about AHCC is that it's fully open source, so if I really miss these things I can do something about it myself.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
-
- Moderator
- Posts: 5309
- Joined: Wed Oct 23, 2002 4:36 pm
- Location: Friedrichshafen, Germany
- Contact:
Re: Starting with C on Atari
AHCC's shell has one big drawback, it does not allow to launch the compiled executable. For users of MiNT this may be acceptable but for TOS users it is a pain the a**. You have to ompile, leave the shell, run the (probably crashing) exectuable and load the shell again.
I personally use the command line TTP version and edit my sources on the PC, the rest is done by Hatari.
I personally use the command line TTP version and edit my sources on the PC, the rest is done by Hatari.
Simon Sunnyboy/Paradize - http://paradize.atari.org/
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Re: Starting with C on Atari
Thanks for the information
I have tried Pure C alittle in the past so maybe I should check it out again. I saw that you have to define a project file with all the sources you need to include. How do I add assembler sources? I guess just adding a .S file won't help. It need an external assembler I guess?

ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Re: Starting with C on Atari
Just add the *.s files. PureC has it's own assembler. AHCC is the same. In fact, AHCC project files are identical to PureC project files.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
Re: Starting with C on Atari
Henk has built AHCC for his own needs/ideas, and I respect that. It's a kick-ass project - but still, I'd like to have syntax hl and font selection, it really improves readability for me. It's what I'm used to.joska wrote:You can't select fonts, but it does have limited syntax highlighting. I'm not a big fan of syntax highlighting myself but I see the value in it.
One thing I'm missing is the ability to fold code. Many editors can fold code between brackets and/or indendation levels, which I find very useful. Once you've got a working function, just fold it and the implementation is hidden from view.
Well, true, but I don't want to rewrite the GUI of GiMP just to be able to draw pictures, if you catch my drift. In this case it means => Qed.But the nice thing about AHCC is that it's fully open source, so if I really miss these things I can do something about it myself.
Ain't no space like PeP-space.
Re: Starting with C on Atari
how do I call the assembler routines from within my C file? I would have to set the registers and all that stuff.Just add the *.s files. PureC has it's own assembler.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Re: Starting with C on Atari
Take a look in the "demo_ass" folder in the PureC distribution. There's an example of how this works. This example shows parameter passing in registers. Which registers to use is explained in the PureC help-file.Zamuel_a wrote:how do I call the assembler routines from within my C file? I would have to set the registers and all that stuff.
You can also pass parameters on the stack if you define the function as "cdecl".
I use very little assembler, but I think AHCC is more clever than PureC in this area. First of all, in AHCC you can use inline assembly. Secondly, in AHCC you can access structs declared in C directly from assembler.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
Re: Starting with C on Atari
The versions of Pure C I found didn't include any demo sources of any kind. I guess it was removed to reduce the size of the package. Is there anythere I can get the full version?
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
-
- Moderator
- Posts: 5309
- Joined: Wed Oct 23, 2002 4:36 pm
- Location: Friedrichshafen, Germany
- Contact:
Re: Starting with C on Atari
I can't help you with a complete Pure C install but I have some examples for AHCC and assembly source integration ready at the Paradize website, check the AHCC section.
Simon Sunnyboy/Paradize - http://paradize.atari.org/
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Re: Starting with C on Atari
I think this is the complete one: http://dhs.nu/files.php?t=single&ID=10Zamuel_a wrote:The versions of Pure C I found didn't include any demo sources of any kind. I guess it was removed to reduce the size of the package. Is there anythere I can get the full version?
Re: Starting with C on Atari
Pure C uses the Atari standard for passing parameters:Zamuel_a wrote:how do I call the assembler routines from within my C file? I would have to set the registers and all that stuff.
first two pointers in A0 and A1
first three integers in D0, D1, D2
The rest of the parameters on the stack.
The result is returned in D0 (integer) or A0 (pointer)
Example (for mixed use with PureC and gcc, offsets in comments are for PureC):
Code: Select all
EXPORT make_hufftable
include "command.mac"
; The following exports should be after "include command.mac"
if GNUC
EXPORT _make_hufftable
endif
EVEN
TEXT
;void make_hufftable(uint8* len, A0 O: lengths of the Huffman codes */
; uint16* table, A1 O: Huffman codes */
; uint16* freq, 4(SP) I: occurrence frequencies */
; uint16 totalfreq, D0 I: sum of all occurrence frequencies */
; int nchar, D1 I: number of characters in <freq> */
; int max_hufflen D2 I: maximum hufflength code
; packstruct *com 8(sp)I: command)
;
; Note that if this source is assembled for use with GCC, this
; function should be called from assembly with the parameters on
; the stack.
X_CHARS equ 42 ; aantal hulp characters
NC equ 512 ; max aantal characters
if GNUC
freq_offset equ 56
max_hufflen_offset equ 70
com_offset equ 72
else
freq_offset equ 48
max_hufflen_offset equ 2
com_offset equ 52
endif
;d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4,a5,a6,a7,sp, .s,rts
;*******************************************************************************
if GNUC
_make_hufftable:
make_hufftable:
movem.l d2-d7/a2-a6,-(sp) ; Save registers
move.l 48(sp),a0 ; *len
move.l 52(sp),a1 ; *table
move.l 60(sp),d0 ; totalfreq
move.l 64(sp),d1 ; nchar
else
make_hufftable:
movem.l d2-d7/a2-a6,-(sp) ; Save registers
endif
move.w d1,d2 ; nchar
lea 0(a0,d2.w),a2 ; wis adres
moveq #0,d3 ; clear D2 om len te wissen
move.l com_offset(sp),a6 ; command
move.l fast_log(a6),com_offset(sp) ; com_offset(sp)=command.fast_log
lsr.w #1,d2 ; nchar/2
bcc.s .cnchar_even0
move.b d3,-(a2)
.cnchar_even0:
....
Re: Starting with C on Atari
No that's the version I got. It has no example files included.I think this is the complete one: http://dhs.nu/files.php?t=single&ID=10
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
-
- Moderator
- Posts: 5309
- Joined: Wed Oct 23, 2002 4:36 pm
- Location: Friedrichshafen, Germany
- Contact:
Re: Starting with C on Atari
Nyh wrote:Pure C uses the Atari standard for passing parameters:Zamuel_a wrote:how do I call the assembler routines from within my C file? I would have to set the registers and all that stuff.
first two pointers in A0 and A1
first three integers in D0, D1, D2
The rest of the parameters on the stack.
The result is returned in D0 (integer) or A0 (pointer)
Example (for mixed use with PureC and gcc, offsets in comments are for PureC):Code: Select all
EXPORT make_hufftable include "command.mac" ; The following exports should be after "include command.mac" if GNUC EXPORT _make_hufftable endif EVEN TEXT ;void make_hufftable(uint8* len, A0 O: lengths of the Huffman codes */ ; uint16* table, A1 O: Huffman codes */ ; uint16* freq, 4(SP) I: occurrence frequencies */ ; uint16 totalfreq, D0 I: sum of all occurrence frequencies */ ; int nchar, D1 I: number of characters in <freq> */ ; int max_hufflen D2 I: maximum hufflength code ; packstruct *com 8(sp)I: command) ; ; Note that if this source is assembled for use with GCC, this ; function should be called from assembly with the parameters on ; the stack. X_CHARS equ 42 ; aantal hulp characters NC equ 512 ; max aantal characters if GNUC freq_offset equ 56 max_hufflen_offset equ 70 com_offset equ 72 else freq_offset equ 48 max_hufflen_offset equ 2 com_offset equ 52 endif ;d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4,a5,a6,a7,sp, .s,rts ;******************************************************************************* if GNUC _make_hufftable: make_hufftable: movem.l d2-d7/a2-a6,-(sp) ; Save registers move.l 48(sp),a0 ; *len move.l 52(sp),a1 ; *table move.l 60(sp),d0 ; totalfreq move.l 64(sp),d1 ; nchar else make_hufftable: movem.l d2-d7/a2-a6,-(sp) ; Save registers endif move.w d1,d2 ; nchar lea 0(a0,d2.w),a2 ; wis adres moveq #0,d3 ; clear D2 om len te wissen move.l com_offset(sp),a6 ; command move.l fast_log(a6),com_offset(sp) ; com_offset(sp)=command.fast_log lsr.w #1,d2 ; nchar/2 bcc.s .cnchar_even0 move.b d3,-(a2) .cnchar_even0: ....
This is very interesting. Do you think you could write a more standalone post on this, for creating assembly sources both compatible with PureC,AHCC and gcc?
It might be very helpful, and I think this little example without more indepth explanation will get lost inside this thread.
Simon Sunnyboy/Paradize - http://paradize.atari.org/
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Stay cool, stay Atari!
1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Re: Starting with C on Atari
Here's the assembler-demo from PureC 1.0.Zamuel_a wrote:No that's the version I got. It has no example files included.
You do not have the required permissions to view the files attached to this post.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
-
- AHCC Developer
- Posts: 39
- Joined: Mon Nov 14, 2011 2:37 pm
Re: Starting with C on Atari
AHCC does not "inline" assembly the way GCC does.
In stead you can write assembler functions as part of a C file and its infrastructure.
#include "whatever.h"
int save_i;
void __asm__ asm_func(int i)
{
move d0, save_i
; do your asm things using names from whatever.h
rts
}
void C_function(void)
{
....
int some_i;
asm_func(some_i);
...
}
But really, you can read more about it in the hypertext documentation. AHCC.HYP
AHCSTART.C is a nice example of what is possible.
This writing only presents a raw impression.
GCC is smarter. however, while GCC generates assembly code, it seems not to be aware
of the needs of assembly instructions when confronted with some.
In stead you can write assembler functions as part of a C file and its infrastructure.
#include "whatever.h"
int save_i;
void __asm__ asm_func(int i)
{
move d0, save_i
; do your asm things using names from whatever.h
rts
}
void C_function(void)
{
....
int some_i;
asm_func(some_i);
...
}
But really, you can read more about it in the hypertext documentation. AHCC.HYP
AHCSTART.C is a nice example of what is possible.
This writing only presents a raw impression.
GCC is smarter. however, while GCC generates assembly code, it seems not to be aware
of the needs of assembly instructions when confronted with some.

- JustinPayne
- Atari User
- Posts: 31
- Joined: Tue Nov 26, 2013 2:20 am
- Contact:
Re: Starting with C on Atari
gcc produce efficient code but is very slow and eats huge amounts of memory. You would need atleast a TT with lots of memory, and either make or a GEM-based IDE like AGNUS to actually build something. You can use inline assembly in gcc. gcc is the only c++ compiler for TOS/MiNT.
PureC has a good, fast and efficient editor/IDE with a decent debugger (in TOS only). Produce less optimized code than gcc, but still quite good.
So, can you explain what you mean by, "gcc produce efficient code but is very slow and eats huge amounts of memory."? It seems that if it's efficient then it should run pretty fast on the ST, compared to less efficient code. Are you saying that the code is efficient but doesn't take into account the limited ram the ol' STs had?
Re: Starting with C on Atari
By that I mean that gcc produce good code but use a lot of time and RAM while doing it.
Jo Even
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64