English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 13 August 2015, 11:32   #1
nobody
Registered User

nobody's Avatar
 
Join Date: Dec 2013
Location: GR
Age: 41
Posts: 1,203
Learning C

After some time of thinking what language to learn I decided to go with C. I installed SAS-C 5.10 from eab server. I got some (expensive) books for amateurs and started reading. I am learning fast, its not so hard for the moment. I compiled and executed some programs with printf, scanf, if-else, getchar(), variables etc in the sasc compiler-linker ("build") which was amazing.

What I want to ask is how hard is to control graphics on the Amiga with C and if some decent games with scrolling could be done with it. The target is A500 with 1 mb ram and I want better performance than backbone and at least equal to Amos.

Last edited by nobody; 13 August 2015 at 13:29.
nobody is offline  
Old 13 August 2015, 13:16   #2
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,493
It's possible for sure, and the Amiga API is more or less designed for use with C, so double buffering graphics to a screen or window isn't a big deal. I would familiarise yourself with pointers and structs before you think about getting deeply into the OS calls though, some of them can be a little bit involved.

That's going the "OS friendly" way about things. If you're looking to access the custom chips directly (and I assume you are given the target spec) the code will look very different. It's not something I've done in C. You should easily be able to beat the performance of both Backbone and AMOS, though it will be a lot more work.

There's a lot of excellent reference material here:

http://amigadev.elowar.com/

It includes all the OS calls (includes and autodocs) as well as the Hardware Reference Manual, which contains all the details for accessing the chipset and hardware directly. Unfortunately it doesn't contain that many examples, but if you're up to speed enough on generic C, you should be able to give it a bash anyway.
Daedalus is offline  
Old 13 August 2015, 13:48   #3
nobody
Registered User

nobody's Avatar
 
Join Date: Dec 2013
Location: GR
Age: 41
Posts: 1,203
Thanks for the advice and the link. That's what I was thinking too, learn the language well first and then jump to Amiga specifics.
nobody is offline  
Old 13 August 2015, 15:45   #4
zardoz
Zone Friend
zardoz's Avatar
 
Join Date: Oct 2004
Location: Wales
Age: 47
Posts: 138
I was wondering this just last night. I found some chap's tutorial project

http://monkeyfighter.com/tetris.html

which looks like its got some examples of how to call into amiga hardware.

BTW I am a C/C++ dev., you need to be able to interface with the system is one way or another (to get input or send output) otherwise your program's not going to be doing very much. Think of a nice simple project and ask for help when you get stuck?
zardoz is offline  
Old 13 August 2015, 15:58   #5
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 654
@nobody
If you want, I can put to the Zone, very simple project in c. I use cross compiler vbcc under Windows with visual studio 2008 c++ express edition. This simple example just disable OS, open screen, write 16 pixels on top screen (for test) and wait for left mouse button.
Interested ?
Asman is offline  
Old 13 August 2015, 17:24   #6
ReadOnlyCat
Code Kitten

 
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 47
Posts: 1,090
You can control the entire Amiga hardware with C without problems.
Hardware addressing wise, both C and assembly language will give you access to the whole creature.

Also, if you want more comfort when coding and have a Windows machine you should definitely install Hannibal's toolchain: http://www.pouet.net/prod.php?which=65625.
(Corresponding EAB threads: http://eab.abime.net/showthread.php?t=78242 and http://eab.abime.net/showthread.php?t=62945.)

It comes with WinUAE and WinFellow(s?) pre-included, Amiga headers and documentation as well as pre-configured Visual Studio setup to build and run straight from the IDE. It builds and links the executable using a vbcc-based cross compiling toolchain and bootstraps the program directly into a WinUAE instance.

This is a really neat setup which I highly recommend.
A shame it does not exist for OS X.
ReadOnlyCat is offline  
Old 13 August 2015, 17:46   #7
nobody
Registered User

nobody's Avatar
 
Join Date: Dec 2013
Location: GR
Age: 41
Posts: 1,203
Thanks for the links and Info's.
@zardoz will do when I make some project.
@asman why not?
@readonlycat I am using notepad++ to write, save as something.c to "starter" folder of sasc then simply start "build" on winuae setup (a500 ks3.1 wb3.1 on HD) and compile. I have an executable linked to something.o. I have cygnus-ed too.
For the moment it works smooth and I read that sasc uses less memory and program has less size as it was targeted for small amigas.

PS. All ".c" files that are inside starter folder of sasc are auto compiled and linked if you start build. If having errors it tells you what line it is and the kind of error. For now it serves well.

Last edited by nobody; 13 August 2015 at 18:15.
nobody is offline  
Old 13 August 2015, 20:31   #8
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 654
@nobody.
In the zone. File name: TmpNonOs.zip. Enjoy. If you have any question then just ask.

Regards
Asman is offline  
Old 13 August 2015, 21:22   #9
nobody
Registered User

nobody's Avatar
 
Join Date: Dec 2013
Location: GR
Age: 41
Posts: 1,203
Thanks for the upload.
nobody is offline  
Old 13 August 2015, 22:46   #10
nogginthenog
Amigan

 
Join Date: Feb 2012
Location: London
Posts: 678
Quote:
Originally Posted by ReadOnlyCat View Post
You can control the entire Amiga hardware with C without problems.
Hardware addressing wise, both C and assembly language will give you access to the whole creature.
This can be a bit tricky from C. Some hardware registers are read only or write only.
The compiler does not know this.
nogginthenog is offline  
Old 13 August 2015, 23:13   #11
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,157
Neither does an Assembler. Making sure to use the hardware registers correctly is the job of the coder, not the compiler.
StingRay is offline  
Old 14 August 2015, 06:56   #12
ReadOnlyCat
Code Kitten

 
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 47
Posts: 1,090
Quote:
Originally Posted by StingRay View Post
Neither does an Assembler. Making sure to use the hardware registers correctly is the job of the coder, not the compiler.
Yup.
You will want to use dedicated functions/macros to guarantee that read only and write only registers are correctly accessed.
Of course, the C version of these might end up being much slower than the assembly one but in the beginning this matters less than actually having the hardware do what you want.

When nobody reaches the stage where he needs to worry about the access speed to the custom chips registers he will be able to switch to dedicated asm code with ease.

This said, it is always good to be curious about the underlying assembly code especially given how readable and powerful the 68k's is.

Added:
Quote:
Originally Posted by nobody View Post
@readonlycat I am using notepad++ to write, save as something.c to "starter" folder of sasc then simply start "build" on winuae setup (a500 ks3.1 wb3.1 on HD) and compile. I have an executable linked to something.o. I have cygnus-ed too.
For the moment it works smooth and I read that sasc uses less memory and program has less size as it was targeted for small amigas.

PS. All ".c" files that are inside starter folder of sasc are auto compiled and linked if you start build. If having errors it tells you what line it is and the kind of error. For now it serves well.
If you feel that your workflow is efficient and has no friction points then that is all that matters.
I have to admit that I am spoiled by Visual Studio and C# development at work so I appreciate to be able to edit a source file then press a single key and have the resulting program run under WinUAE almost instantly.

Not having that on my home Mac at the moment has demotivated me so much when working on my Amiga project in the past months that I am currently working on setting up a similar system on OS X before I restart.

Last edited by ReadOnlyCat; 14 August 2015 at 07:06.
ReadOnlyCat is offline  
Old 14 August 2015, 18:53   #13
kamelito
Zone Friend
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 930
@ReadOnlyCat
Or you can use vamos. (http://lallafa.de/blog/category/amiga/vamos/
Kamelito
kamelito is offline  
Old 15 August 2015, 13:17   #14
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,196
I posted links to the final version of SAS/C a while ago. I don't know if the compiler is much better, but the archives contain full user manuals in .txt format that could be useful:
http://eab.abime.net/showthread.php?t=79344

BTW, the "starter" folder is the template used when creating new projects using "scsetup", so you may want to keep it in its original state.
Leffmann is offline  
Old 04 September 2015, 05:50   #15
desiv
Registered User
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,393
OK, color me bemused, but...

I DL'd the toolchain so I could compile C on my Linux box and test it in FS-UAE.
Did a little helloworld.c thing (of course).

Compiled it in linux, compiles, runs, displays hello world. Yay.
Compiled it in linux for Amiga, compiles. Transfer it to my basic WB floppy image and run it and it kind of works.

I mean, the compile obviously works, but I get:
System Request
Need version 37 of dos.library

Really? Just to display text, the Amiga includes require a specific version?

Does that mean I'm going to need 2 build environments, one for WB1.3 and one for WB3.x?

I knew there would be issues for newer/changed features, but just displaying text?

Oh well..
At least it worked...

desiv
desiv is offline  
Old 04 September 2015, 07:13   #16
ReadOnlyCat
Code Kitten

 
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 47
Posts: 1,090
Quote:
Originally Posted by desiv View Post
I mean, the compile obviously works, but I get:
System Request
Need version 37 of dos.library

Really? Just to display text, the Amiga includes require a specific version?
Dos.library is not actually required for displaying text but for sending the string back to the standard output. The shell is the one which is actually doing the drawing of the text.
Technically, when calling printf() your program actually sends the "Hello world" string to "stdout" and is then received by the Shell it has been launched from. printf() is completely incapable of displaying the actual pixels of the text. The reason dos.library is needed is that it is the one responsible for handling stdout on the Amiga.

If you had typed "myprog.exe > file.txt" instead, then there would be no text display but a "file.txt" file would have been created by the shell containing "hello world".

Quote:
Originally Posted by desiv View Post
Does that mean I'm going to need 2 build environments, one for WB1.3 and one for WB3.x?
Before even main() is executed, your program is actually running a piece of code called the startup which is provided by the toolchain at link time and it looks like this startup code requires dos.library v37.

SAS C provided different types of startup code precisely so one could tailor the requirements of their final executable according to their needs and it might be possible to select which startup code to link against also with your toolchain.

Try looking for "startup" or "runtime" in the documentation. There is probably an option which tells the linker to target a particular kickstart.

Hope this helps!

Last edited by ReadOnlyCat; 04 September 2015 at 07:23. Reason: My explanation was incorrect and confusing. Clarified.
ReadOnlyCat is offline  
Old 04 September 2015, 12:44   #17
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,196
Quote:
Originally Posted by desiv View Post
Does that mean I'm going to need 2 build environments, one for WB1.3 and one for WB3.x?
I'm guessing you're running VBCC? Open up the config directory and duplicate the default configuration as "ks13" or something, edit it and change "startup.o" into "startup13.o", and if there's a flag "-Rshort" anywhere, remove it.

Now you can just specify "+ks13" as the first argument to vc. Also, if you're linking with "-lmieee" to use the Workbench math libraries, then you need to change it to "-lm13".
Leffmann is offline  
Old 04 September 2015, 18:29   #18
desiv
Registered User
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,393
Thanx for the heads up/info!!
Its been QUITE a while since I did any C, much less on/for an Amiga.
Quote:
Originally Posted by Leffmann View Post
I'm guessing you're running VBCC?
Yep, VBCC (Had to check, I got it from: http://fengestad.no/m68k-amigaos-toolchain/ )

Not planning on anything fancy at this stage (not a professional developer!!!), just looking to poke around...

Awhile ago, I found the code (printed out unfortunately, but still) for an old solitaire game I had written for someone and thought it might be fun to try to re-compile it..

It wasn't great, but I remember being impressed with myself at the time...
It wasn't ever really finished (when you selected cards, you clicked and it outlined them, which was fast, but I always planned an option to actually PICK them up (and they follow your pointer till you put them down)) and I might want to do that...
And it still had some bugs..
The one I remember was that I had full intuition menus for settings, and I did that totally wrong. It worked, until my brother (my tester at the time) decided to select multiple items at the same time.... I didn't know the OS supported that (probably really should have read something about it) so it would put checks next to everything you selected, but only activate the LAST one you selected.. :-(

Ooops.. ;-)

But for some "life at the time" reason, that's apparently when I stopped.

(That and someone released Klondike about then which was MUCH MUCH MUCH nicer than mine.. ;-)

I also remember I used an iff.library for some things.. Hopefully I picked a standard one I can still find . (is there only really 1?)
I was using DICE, which I remember liking. But since i already have a Linux box setup, thought this might work..

Thanx again!

desiv
p.s. Funny side point.. I didn't even actually know how to play Solitaire at the time I started. ;-) Yes, the person I wrote it for was female, which was partly why I thought it would be a good idea. ;-)
(She actually enjoyed the game and played it much longer than I did (or said so). Never ended up meeting her.)

Last edited by desiv; 04 September 2015 at 18:38.
desiv is offline  
Old 05 September 2015, 01:13   #19
desiv
Registered User
 
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,393
No luck so far...
To be pretty sure I was making the changes (and because I wasn't totally sure where to put the ks13 on command line), I went to editing the /opt/m68k-amigaos/etc/vc.config file to say:

-cc=vbccm68k -quiet %s -o= %s %s -O=%ld -I/opt/m68k-amigaos/vbcc-include -I/opt/m68k-amigaos/os-include
-ccv=vbccm68k %s -o= %s %s -O=%ld -I/opt/m68k-amigaos/vbcc-include -I/opt/m68k-amigaos/os-include
-as=vasmm68k_mot -quiet -Fhunk -phxass %s -o %s -I/opt/m68k-amigaos/os-include
-asv=vasmm68k_mot -Fhunk -phxass %s -o %s -I/opt/m68k-amigaos/os-include
-rm=rm %s
-rmv=rm -v %s
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib /opt/m68k-amigaos/vbcc-lib/startup13.o %s %s -L/opt/m68k-amigaos/vbcc-lib -L/opt/m68k-amigaos/vbcc-include -lvc -lamiga -o %s
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L/opt/m68k-amigaos/vbcc-lib -L/opt/m68k-amigaos/vbcc-include -o %s
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib /opt/m68k-amigaos/vbcc-lib/startup13.o %s %s -L/opt/m68k-amigaos/vbcc-lib -L/opt/m68k-amigaos/vbcc-include -lvc -lamiga -o %s
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L/opt/m68k-amigaos/vbcc-lib -L/opt/m68k-amigaos/vbcc-include -o %s
-ldnodb=-s
-ul=-l%s
-cf=-F%s
-ml=500
------------------------

So it has the startup13.o where it had the startup.o and I removed the Rshort.
But when I invoke:
m68k-amigaos-gcc helloworld.c -noixemul -o helloworld

The compile works, but it's the exact same executable. So it's ignoring something..

I'll keep poking this weekend..

desiv
desiv is offline  
Old 05 September 2015, 08:53   #20
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,196
Ok I see you're actually calling GCC. From the download page you linked to it almost looks like VBCC is some utility library, but it's actually a complete compiler. Since you've edited the default config, assuming everything else is correctly installed, you can just run "vc -o helloworld helloworld.c" and get a KS 1.3 compatible executable.
Leffmann is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
A new Learning Demo for Amiga OCS and beyond. Toni Galvez Amiga scene 46 01 March 2015 16:20
Help with learning more about my A2000 and bring it up to speed? kurtis New to Emulation or Amiga scene 3 04 December 2014 19:35
I need help with my intro... I´m learning... Skillion76 Coders. General 10 27 September 2014 18:36
Suggestions for learning pmc Coders. Tutorials 248 20 October 2010 22:42
Learning assembler bLAZER Coders. General 1 12 May 2007 06:00

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.09077 seconds with 13 queries