Jump to content
Jagware
Sign in to follow this  
Starcat

Getting started using C on the Jaguar

Recommended Posts

Starcat    0

Hello everybody!

 

I finally want to get around to using C on the Jaguar.

I already downloaded the remover's lib and the compiler that is linked to on the remover's homepage.

However I still do not quite get the environment to work.

 

How exactly is this done? And maybe just as important, is there any license or limitation connected to using the remover's lib with C on the Jag?

 

Also can somebody tell me how C and asm code can pass parameters to each other in case I want to put parts of my own asm code in a c program?

 

Any help is highly appreciated, thanks.

 

Regards, Lars.

Share this post


Link to post
Share on other sites
Zerosquare    10
And maybe just as important, is there any license or limitation connected to using the remover's lib with C on the Jag?
AFAIK the only thing you have to do is to say you used the library in the credits, even if your game is commercial.

 

Also can somebody tell me how C and asm code can pass parameters to each other in case I want to put parts of my own asm code in a c program?
Here's what SebRmv told me (actually I asked him about using C functions in ASM, but it must be the same) :

 

- in an ASM source file, functions must be declared that way : .globl _myfunc if the C function name is myfunc

- d0, d1, a0 and a1 can be modified ; other registers must be preserved

- the return value is written into d0

- all arguments must be longwords

- arguments are pushed on the stack, starting with the rightmost one ; the call is made using jsr ; the caller must adjust the stack pointer after the call

 

For example :

 

C :

myfunc(a, 5);

 

ASM :

move.l #5, -(sp)

move.l a, -(sp)

jsr _myfunc

addq.w #8, sp

Share this post


Link to post
Share on other sites
SebRmv    2

Hi,

 

I have released these libraries under the LGPL license.

I hope this license will not bother you. Otherwise tell me and we'll find a deal.

 

Regarding the interaction between C & ASM, I think Zerosquare has basically said everything.

To see on a real example, you may wish to inspect the example4 available on my website.

I have added a small example in assembly that call the sound driver to replay a sample.

 

For the installation issues, what is your setting? Windows? Linux?

In any case, do not hesitate to ask precise questions, I will be pleased to help you.

 

Best,

 

Seb

Share this post


Link to post
Share on other sites
Starcat    0

Thank you very much Seb. :)

I would really like to get started using C on the Jag and the removers lib seems to be the best for that, if one doesn't want to develop his own c lib from scratch. What I would really like is a stable library I can use to develop my ideas in a fast and clean fashion.

 

I'm using Windows XP and I'm not sure how to set up the right environment to compile the examples.

I downloaded the C lib and removers lib from your site. I also downloaded the Cross GCC mc68k.

How do I continue from there?

 

Regards, Lars.

 

Share this post


Link to post
Share on other sites
SebRmv    2

Argh, you have chosen the hard way: using Windows :P

 

Maybe you could first check on belboz website... I believe he has compiled a working dev environment that includes my library.

(http://www.hillsoftware.com/atari/index.html)

 

Otherwise, we'll try to do it (and document the process) together.

 

 

Share this post


Link to post
Share on other sites
Starcat    0

He does have a dev environment, but from his own statements, he said it doesn't work with your lib as it is yet.

So I guess we have to try to together ;)

I think it would be great to have a real tutorial that covers it all, so it's easier for people to get started.

Share this post


Link to post
Share on other sites
ggn    0

Hello,

 

I had a quick look at it. Seems that in order to use it, you need a few components:

 

a ) A unixoid enviroment (since you're using Window$ and all)

b ) Madmac assembler

c ) Cross-68k-gcc

 

For ( a ) I'd go with cygwin (http://cygwin.org/), because of ( c ) :).

For ( b ) I'd suggest going with smac, as the only way Reboot has managed to make mac work on new OSes is via DOSbox, which would increase complexity in your build scripts (again, maybe not so much). Beware though, there are still bugs creeping in smac.

For ( c ) the sane choice is Vincent Riviere's gcc port for Cygwin (http://vincent.riviere.free.fr/soft/m68k-atari-mint/).

 

I'd give it a go myself, but I have a MinGW installation, and it's not so straightforward getting gcc up'n'running in that. (actually I have a 2nd machine running Win7 and cygwin -not mine!- so if you get really stuck I might set it up there)

 

After you set everything up, it should be a simple matter of editing the Makefile and Makefile.conf, bringing up a console, CDing to the relevant directory and typing 'make' ;). Hmm, yeah, another point worth mentioning is to use a text editor that can edit unix source files (iirc they're CR while DOS is CR/LF). Notepad++, Notepad2 or gvim are all up to the task.

 

Good luck, and please share your experiences!

Share this post


Link to post
Share on other sites
Starcat    0

I installed the cygwin environment and also installed the Cross-68k-gcc following the "quickstart guide" on the website you mentioned.

I also used madmac and smac from a dos command window before.

 

I'm not really sure how to continue from here though, as I didn't really use cygwin before and I also don't know how I would have to modify the makefile of the removers examples to make them work.

 

 

Share this post


Link to post
Share on other sites
ggn    0

Hello,

 

Let's see now...

 

- Did you check that the cross-68k tools work from the cygwin console?

- Can you also run mac/smac from the console? It must be present in cygwin's PATH, which generally isn't the same as the system's. You might have to copy the executables to a directory that is on cygwin's path (typing "set|grep PATH" on console will help)

- If both of the above work, then locate cygwin's home directory (can't remember by heart, it should be something like <path-to-cygwin>/home/administrator) and extract the remover's lib on a folder there (typically if you've copied the lib archive on the root, "tar -zxvf jlibc-0.5.6.tar.gz" will do the trick.

 

Now, for editing the Makefile (sorry if you made all of the above, I just wasn't certain): Seems to me that you don't need to edit Makefile, but instead you need to edit Makefile.config. It seems to me that Seb has installed the whole Atari Jagdev kit to $HOME/Jaguar. If you don't need all this, you can just remove JAGPATH and edit the MADMAC entry to point to mac or smac. After that, edit CROSSPATH to the path where the cross-68k tools reside. If you don't know the path, I think something like "which m68k-atari-mint-gcc" or similar will help (I can't remember exactly how the cross-gcc filename is, Vincent should state that on his website).

 

After all this is done, type "make" on the lib directory and it should compile. Of course, the most likely thing is that it won't, but if you get to that, you can give more info :)

 

 

 

Share this post


Link to post
Share on other sites
belboz    0

Using Seb's library with VBCC proved to be problematic. It is fixable, but I never spent the time to mess with it.

 

One thing you could use Starcat if you want to play with the removers library is my bootable Linux GUI CD on my website.

 

You burn it to a CD and boot it with your PC. It loads up a fully working Linux based dev environment. It has working versions of mac,aln,rdbjag,wdb, smac,sln, vbcc, and gcc. The removers library is already installed and setup correctly. Also skunk tools too. It gives you a lot of options since you can use gcc, vbcc, mac/aln or smac/sln. I also include a GUI code editor which can call your makefiles and reset a skunkboard.

 

Boots fully from CD and doesn't modify your HD. Although you can access you HD with it if you wish to build projects stored on your Windows partition.

 

Here is a video of it in action.

 

http://vimeo.com/7270758

 

The CD is on my site.

 

http://www.hillsoftware.com

 

He does have a dev environment, but from his own statements, he said it doesn't work with your lib as it is yet.

So I guess we have to try to together ;)

I think it would be great to have a real tutorial that covers it all, so it's easier for people to get started.

 

Share this post


Link to post
Share on other sites
Starcat    0

Hello ggn!

 

Let's see now...

 

- Did you check that the cross-68k tools work from the cygwin console?

 

How can I test it?

 

- Can you also run mac/smac from the console? It must be present in cygwin's PATH, which generally isn't the same as the system's. You might have to copy the executables to a directory that is on cygwin's path (typing "set|grep PATH" on console will help)

 

Yes, it works.

 

- If both of the above work, then locate cygwin's home directory (can't remember by heart, it should be something like <path-to-cygwin>/home/administrator) and extract the remover's lib on a folder there (typically if you've copied the lib archive on the root, "tar -zxvf jlibc-0.5.6.tar.gz" will do the trick.

 

Now, for editing the Makefile (sorry if you made all of the above, I just wasn't certain): Seems to me that you don't need to edit Makefile, but instead you need to edit Makefile.config. It seems to me that Seb has installed the whole Atari Jagdev kit to $HOME/Jaguar. If you don't need all this, you can just remove JAGPATH and edit the MADMAC entry to point to mac or smac. After that, edit CROSSPATH to the path where the cross-68k tools reside. If you don't know the path, I think something like "which m68k-atari-mint-gcc" or similar will help (I can't remember exactly how the cross-gcc filename is, Vincent should state that on his website).

 

After all this is done, type "make" on the lib directory and it should compile. Of course, the most likely thing is that it won't, but if you get to that, you can give more info :)

 

Hmm, I put the Jaguar folder into my home directory and also placed the example1 of the removers lib into the home directory.

Installed the same Gcc as mentioned on the removers lib, just to be sure, as well.

 

However when I type make in the example1 folder, I get error messages as if the jag c lib wasn't found.

Now where exactly in the makefile does it say where the remover / jag c lib has to be located?

I think if I get that right, things might work already.

 

 

 

 

Share this post


Link to post
Share on other sites
ggn    0

Hiya Lars,

 

How can I test it?

 

Easy - j ust open a Cygwin console and type "m68k-atari-mint-gcc --version". That should run the cross-gcc and print some generic infor about it.

 

Hmm, I put the Jaguar folder into my home directory and also placed the example1 of the removers lib into the home directory.

Installed the same Gcc as mentioned on the removers lib, just to be sure, as well.

 

However when I type make in the example1 folder, I get error messages as if the jag c lib wasn't found.

Now where exactly in the makefile does it say where the remover / jag c lib has to be located?

I think if I get that right, things might work already.

 

Umm, the way I understand it, Seb is offering the lib in source format. So you will have to compile that first before anything you write using it works. Get the archive, unpack it, edit the makefile(s) to point to your tools, and type make. If no errors occur, type 'make install' and the library should be installed in your cygwin system. Then, the example program should compile (perhaps with more makefile tinkering).

 

I think we're making good progress though :)

Share this post


Link to post
Share on other sites
Starcat    0

Okay, it seems like the mint-gcc isn't setup correctly. The path is not found when I type what you suggested.

 

When I try to compile the c lib I get a bunch of error messages, of included files not being found.

 

Starcat@samsung ~/jlibc-0.5.6

$ make

make -C string

make[1]: Entering directory `/home/Starcat/jlibc-0.5.6/string'

/usr/local/m68k-aout/m68k-aout/bin/gcc -MM strchr.c strrchr.c memchr.c memcmp.c

strlen.c strcpy.c strncpy.c strcmp.c strncmp.c strcoll.c strcat.c strncat.c str

xfrm.c > .depend

make[1]: Leaving directory `/home/Starcat/jlibc-0.5.6/string'

make[1]: Entering directory `/home/Starcat/jlibc-0.5.6/string'

/usr/local/m68k-aout/m68k-aout/bin/gcc -mc68000 -Wall -fomit-frame-pointer -O2 -

msoft-float -c strchr.c

strchr.c:19:20: string.h: No such file or directory

strchr.c: In function `strchr':

strchr.c:28: error: `NULL' undeclared (first use in this function)

strchr.c:28: error: (Each undeclared identifier is reported only once

strchr.c:28: error: for each function it appears in.)

make[1]: *** [strchr.o] Error 1

make[1]: Leaving directory `/home/Starcat/jlibc-0.5.6/string'

make: *** [string] Error 2

Starcat@samsung ~/jlibc-0.5.6

$

 

Any ideas how I can fix it?

 

Share this post


Link to post
Share on other sites
ggn    0

Well, string.h is stdlib stuff, and I've seen that Seb offers a stdlib for the Jag. So I'd say go compile and 'make install' it.

Share this post


Link to post
Share on other sites
SebRmv    2

Hi,

 

sorry, I did not get time to answer before.

 

The best advice I could give is

 

if you are running on windows, please take the binary distribution of jlibc and rmvlib !

 

(I think rebuilding them on windows is a nightmare in the current state)

 

Second, take the cross gcc on my website.

It should run on a standalone Windows (ie without cygwin) as long as you copy the included DLL files (that comes from cygwin) in the right directory (probably something resembling to C:\System)

Try to run gcc -v in a command shell for instance.

 

You also have to copy the header files of my lib (ie the *.h) at a place where the cross gcc will find them.

 

The difficult part is to get madmac and aln running on Windows.

If you plan to develop only in C, then you just need aln.

Otherwise madmac is also needed (obviously).

 

The idea is to use the cross gcc to produce object files.

Then, thanks to aln, you link them against my libs and it produces magically a Jaguar executable :)

 

Maybe you can use sln and smac, but I never tested this setting myself.

Otherwise, I believe that madmac and aln work under dosbox.

 

So if you open a dosbox console, and assuming you have the right path

 

gcc -v foo.c -> produces foo.o (for the options passed to gcc, you may have a look at the Makefile I give with the examples)

...

 

and then

aln rmvlib.a foo.o ... (once again, have a look at one of the Makefile furnished with the examples to get the right command line)

 

You may also have a look at this webpage (sadly in french)

http://removers.free.fr/spip/?92-je-veux-d...opper-sur-atari

It contains probably some useful hints.

 

Hope this helps.

 

--

 

One thing that is missing on windows is the GNU Make tool and the bash shell.

(that's why it is probably a nightmare to rebuild my libs from the sources on Windows)

 

Regarding make, I will try to investigate a bit in the direction of CMake, which seems

to be a good candidate to replace make (and which is portable).

Share this post


Link to post
Share on other sites
Starcat    0

Hi ggn!

 

When I enter "make install" in the jlibc directory I get the following error message...

 

mkdir -p "/home/Starcat/tmp/jlibc/include"; \

mkdir -p "/home/Starcat/tmp/jlibc/lib"; \

for file in jagtypes.h jagdefs.h; do \

install -m "u+rw,go+r" "$file" "/home/Starcat/tmp/jlibc/include"; \

done; \

for dir in string stdlib stdio doc ctype; do \

for file in `make -s install-h -C $dir`; do \

install -m "u+rw,go+r" "$dir/$file" "/home/Starcat/tmp/jlibc/include

"; \

done; \

done; \

for file in crt0.o jlibc.a; do \

install -m "u+rw,go+r" "$file" "/home/Starcat/tmp/jlibc/lib"; \

done; \

for dir in string stdlib stdio doc ctype; do \

for file in `make -s install-lib -C $dir`; do \

install -m "u+rw,go+r" "$dir/$file" "/home/Starcat/tmp/jlibc/lib"; \

 

done; \

done

install: cannot stat `crt0.o': No such file or directory

install: cannot stat `jlibc.a': No such file or directory

 

Any ideas?

Thanks, I really appreciate your input. :)

Share this post


Link to post
Share on other sites
Starcat    0
Hi,

 

sorry, I did not get time to answer before.

 

The best advice I could give is

 

if you are running on windows, please take the binary distribution of jlibc and rmvlib !

 

(I think rebuilding them on windows is a nightmare in the current state)

 

Okay, in that case I should probably just use the binaries for now.

 

Second, take the cross gcc on my website.

It should run on a standalone Windows (ie without cygwin) as long as you copy the included DLL files (that comes from cygwin) in the right directory (probably something resembling to C:\System)

Try to run gcc -v in a command shell for instance.

 

You also have to copy the header files of my lib (ie the *.h) at a place where the cross gcc will find them.

 

The difficult part is to get madmac and aln running on Windows.

If you plan to develop only in C, then you just need aln.

Otherwise madmac is also needed (obviously).

 

The idea is to use the cross gcc to produce object files.

Then, thanks to aln, you link them against my libs and it produces magically a Jaguar executable :)

 

Maybe you can use sln and smac, but I never tested this setting myself.

Otherwise, I believe that madmac and aln work under dosbox.

 

So if you open a dosbox console, and assuming you have the right path

 

gcc -v foo.c -> produces foo.o (for the options passed to gcc, you may have a look at the Makefile I give with the examples)

...

 

and then

aln rmvlib.a foo.o ... (once again, have a look at one of the Makefile furnished with the examples to get the right command line)

 

You may also have a look at this webpage (sadly in french)

http://removers.free.fr/spip/?92-je-veux-d...opper-sur-atari

It contains probably some useful hints.

 

Hope this helps.

 

--

 

One thing that is missing on windows is the GNU Make tool and the bash shell.

(that's why it is probably a nightmare to rebuild my libs from the sources on Windows)

 

Regarding make, I will try to investigate a bit in the direction of CMake, which seems

to be a good candidate to replace make (and which is portable).

 

Thanks. :) I'll try it and see how far I get.

 

Share this post


Link to post
Share on other sites
Starcat    0

The problem really seems to be setting the right paths so the lib is found. But I just can't get it to work, neither using cygwin nor windows xp command window, so far. :(

 

Next thing I'll try is belboz boot cd, however I'd really prefer being able to use the lib in windows xp.

Share this post


Link to post
Share on other sites
SebRmv    2

Ok, I will have a look at it after my musical session :)

I will test on Windows 7 - 64 bits ;)

 

Share this post


Link to post
Share on other sites
ggn    0
Hi ggn!

 

When I enter "make install" in the jlibc directory I get the following error message...

 

[snippety snip]

 

install: cannot stat `crt0.o': No such file or directory

install: cannot stat `jlibc.a': No such file or directory[/b]

 

Any ideas?

Thanks, I really appreciate your input. :)

 

Dunno if you're going to use cygwin at all but for what it's worth: if 'make install' can't find the files, it means they weren't compiled. Did you do a 'make' before 'make install'? Did it exit without errors? Also, did you modify Makefile.config?

Share this post


Link to post
Share on other sites
SebRmv    2

Ok, here is the first step of the recipe (tried on Windows 7 - 64 bits: note that cygwin is not installed on my windows)

 

This one deals with Cross GCC installation.

 

Install Cross GCC compiler
==========================

1-Get xgcc-3.3.6-m68k.tar.bz2 from The Removers web site.

2-Decompress the archive to the wanted directory.

3-Open a command console
[Windows]+[R] cmd

4-Go to the directory where you uncompressed the archive.

cd path\to\uncompressed\archive

In the following, I assume that gcc has been uncompressed in F:\gcc-68k

So, I did 

f:
cd f:\gcc-68k

5-Go into cygwin subdirectory (windows binary is in it)

cd cygwin

6-Copy Cygwin DLLs to C:\Windows (you may need administrator rights)

cp dll\cygiconv-2.dll C:\Windows
cp dll\cygintl-3.dll C:\Windows
cp dll\cygwin1.dll C:\Windows

7-Try gcc

usr\local\m68k-aout\m68k-aout\bin\gcc.exe -v

Expected output is:

Using built-in specs.
Configured with: ../gcc-3.3.6/configure --prefix=/usr/local/m68k-aout --enable-languages=c --target=m68k-aout
Thread model: single
gcc version 3.3.6

Share this post


Link to post
Share on other sites
SebRmv    2

Ok part 2

 

Install Removers libraries
==========================

1-Get latest binary build of jlibc and rmvlib.

2-Uncompress the two archives.

In the sequel, I assume that you have uncompressed these archives as follows:
- jlibc is in f:\gcc-68k\jlibc
- rmvlib is in f:\gcc-68k\jlibc

 

Share this post


Link to post
Share on other sites
SebRmv    2

Part 3

 

Test compilation with GCC
=========================

1-Get an example from the Removers website

In the following, I assume that you have chosen example4.tar.gz

2-Uncompress the archive.

I assume you uncompressed the archive in f:\gcc-68k\example4

(shame on me, the archive does not create a directory example4)

3-Set your environment PATH variable so that gcc find its binaries.

set PATH=%PATH%;F:\gcc-68k\cygwin\usr\local\m68k-aout\m68k-aout\bin
set PATH=%PATH%;F:\gcc-68k\cygwin\usr\local\m68k-aout\lib\gcc-lib\m68k-aout\3.3.6

4-Compile example4.c

F:\gcc-68k\example4>gcc -c -I f:\gcc-68k\jlibc\include  -I f:\gcc-68k\rmvlib\include -I f:\gcc-68k\cygwin\usr\local\m68k-aout\lib\gcc-lib\m68k-aout\3.3.6\include example4.c

This should produce example4.o!

Share this post


Link to post
Share on other sites
SebRmv    2

Ok, I stop here for today. Please keep me informed if this works on your setup.

 

The difficult part will be to invoke aln ;)

 

Note: the gcc -c command in the previous message is not exactly what should be typed (some compiler flags should be put) but this permits to test if this works.

 

The good command is:

 

gcc -mc68000 -Wall -fomit-frame-pointer -O2 -msoft-float -funroll-loops -c -I f:\gcc-68k\jlibc\include  -I f:\gcc-68k\rmvlib\include -I f:\gcc-68k\cygwin\usr\local\m68k-aout\lib\gcc-lib\m68k-aout\3.3.6\include example4.c

 

Don't be afraid if you get some warnings...

Share this post


Link to post
Share on other sites
Starcat    0

Thank you Seb!

 

I got as far as your tutorial goes. I'm ready for the rest :)

Share this post


Link to post
Share on other sites
Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×