Welcome, Guest. Please login or register.

Author Topic: Basic Amiga-API coding  (Read 11915 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Basic Amiga-API coding
« on: July 31, 2006, 03:56:49 PM »
From time to time there pops up a thread where people complain that learning the Amiga-API would be so hard and that no good resources would be available.

Now, there is the the Amiga-C-Manual, but thats quite outdated, and there is the Yahoo-maillist amiga_bcg but here you will find all sorts of skill-levels and question mixed up.

And then you have the occasional tutorial in print-magazines, but I allways found they were trying to do to much at a time overwhelming the reader, and making it hard to figure out where the tutorial ends, and where the pseudo-functionallity starts.

I therefore decided *fanzy fanfare* to do my own !!

It's very basic
It's targeted a users with basic C-skills
It's examples won't try to be usefull in any kind
It's a one proble at a time approach
It expects the reader to look up further options and arguments himself

Preparing yourself for the ride:

http://home.arcor.de/dietmar_eilert/site/cubic/download.htm

Download atleast the Demo-versoin (should suffice), buying the full package is offcourse an even better idea (and no I'm not getting paid for writing this  :pissed: ), you may also wish to download the C/C++ Add-On Package, unless you know how to setup and use a bare compiler&documentation.

After installing, set Compiler to gcc (press blue box in toolbar), and target to amigaos3 (gcc 2.95.3). Useing other compilers and targets should be possible, but for the moment we should keep the possible problems to a minimum.
Now create a new project (the tilted white paper)and make it an Amiga project. After doing that open the created file main.c and paste the tutorial-source into it (yes, I'm sure there are more elegant ways of doing it, but for the moment this will do).

You should now be able to call "make all" (the 4 connected blue boxes) and "run" (white on green arrow).

O.k. here are the 1st chapters:

Intuition1
Intuition2

Once you got them working you should right-click some of the coloured keyword, selcect "look up word" (or something similar) to see other related functions, structures and tags.
I will not explain all of them, only those that aren't self-explaining and/or important.

As noted above these were written for OS3.x, no change is needed to adapt them for MorphOS-native (and same should go for AROS), adapting them to OS4-native would either need a pre-processor statement switching of the use of interfaces, or actully adding the code for interfaces. As none of this changes the way the API and it's functions work, this isn't neccasary until you have grown out of tutorials.
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show only replies by Heinz
    • http://amidevcpp.amiga-world.de
Re: Basic Amiga-API coding
« Reply #1 on: July 31, 2006, 04:28:06 PM »
The examples both compiles for Aros without any problems (using AmiDevCpp).

Am I allowed to upload them as example projects to the AmiDevCpp Homepage ?

http://amidevcpp.amiga-world.de/exampleupload.php
 

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Basic Amiga-API coding
« Reply #2 on: July 31, 2006, 04:29:56 PM »
Sure, consider them freeware in the most orginal meaning of the word.
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Hans_

Re: Basic Amiga-API coding
« Reply #3 on: July 31, 2006, 04:52:20 PM »
I haven't had a chance to look at them yet, but this is a good idea. I'm sure someone can give you a small #ifdef, that will allow your code to compile in OS4 without requiring modifications.

EDIT: Make that a few #ifdefs, because of OS4's library Interface system

Hans
Join the Kea Campus - upgrade your skills; support my work; enjoy the Amiga corner.
https://keasigmadelta.com/ - see more of my work
 

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Basic Amiga-API coding
« Reply #4 on: July 31, 2006, 04:59:30 PM »
@Hans
AFAIK there is a way to switch back to the normal way to access the API, which would require only 1 #ifdef at the start.

Everything else would make things much to complicted for something that is intended to be simple.
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline Slash

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 112
  • Country: gb
  • Gender: Male
    • Show only replies by Slash
    • http://www.the-snakepit.co.uk
Re: Basic Amiga-API coding
« Reply #5 on: July 31, 2006, 05:05:46 PM »
Just a couple of suggestions, and me being pedantic, but:

1) The 'int main()' line should probably be written as 'int main(int argc, char** argv)'

2) Probably a personal preference, but I'd make sure my window pointer was NULL when it is declared; i.e. 'struct Window *win = NULL'

3) Not as important in this instance, but after the window was closed, I'd reset the win variable to NULL after the window has been closed; i.e. 'win = NULL;'

4) Truth statements should be encapsulated within another set of parenthesis; i.e. 'if(win = OpenWindowTags(NULL,TAG_DONE))' would become if((win = OpenWindowTags(NULL, TAG_DONE))!=NULL) { ... } or if((win = OpenWindowTags(NULL, TAG_DONE))) { ... }.

Always compile with the GCC option -Wall and you'll catch these warnings.

Good idea though. :-)
 

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Basic Amiga-API coding
« Reply #6 on: July 31, 2006, 05:27:19 PM »
@slash

1) I know that, but the point is keep it as simple as possible, not to teach finer details of C.

2) Since the 1st use of a that variable is assigning it a value there is no point in presetting it to one. It also makes it harder to keep track of those that need to be presetted, and doing it to every pointer would also bloat of both source and code.

3) pretty much the same as 2)

4) never heard of that one (and have no idea what it should be good for)
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline _yak_

  • Full Member
  • ***
  • Join Date: Mar 2006
  • Posts: 227
    • Show only replies by _yak_
Re: Basic Amiga-API coding
« Reply #7 on: July 31, 2006, 05:48:51 PM »
@ Kronos

4) Possible scenario:

You write your code and accidently put assignment operator (=) instead of comparision (==) in some 'if' or loop. If you have -Wall switch enabled, GCC will generate a warning telling you that this may be possibly an error. You go there and if you see that this indeed should be an assignment and not a comparision, you put the parenthesis around it to tell GCC that it's ok this way. If GCC was right, you fix the bug.

Btw, good idea with the tutorial.
 

Offline redrumloa

  • Original Omega User
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 10126
    • Show only replies by redrumloa
Re: Basic Amiga-API coding
« Reply #8 on: July 31, 2006, 05:49:42 PM »
@Kronos

Great initiative! :-D
Someone has to state the obvious and that someone is me!
 

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Basic Amiga-API coding
« Reply #9 on: July 31, 2006, 05:54:28 PM »
@_yak_

Maybe I should at some point in time really start reading the compiler-docs further than what I need at that moment  :rtfm:
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Re: Basic Amiga-API coding
« Reply #10 on: July 31, 2006, 06:36:27 PM »
Many warnings activated by -Wall option in GCC are just little pedantic. Maybe not important to beginners even.
My Amigas: A500, Mac Mini and PowerBook
 

Offline KronosTopic starter

  • Resident blue troll
  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 4017
    • Show only replies by Kronos
    • http://www.SteamDraw.de
Re: Basic Amiga-API coding
« Reply #11 on: July 31, 2006, 07:19:38 PM »
Added 3rd chapter (yes I'm THAT bored)

Basic reacting on user-input, menus are next and watching more than 1 window will be chapter 5.

intuition3

After that I will move to the topic of graphics, simple drawing, blitting, chunky-images and window-refresh.

Would like to see some comments wether I'm  moving to fast or too slow.
1. Make an announcment.
2. Wait a while.
3. Check if it can actually be done.
4. Wait for someone else to do it.
5. Start working on it while giving out hillarious progress-reports.
6. Deny that you have ever announced it
7. Blame someone else
 

Offline nyteschayde

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Basic Amiga-API coding
« Reply #12 on: July 31, 2006, 09:15:47 PM »
Can you do a demo on how to create a button that, say... closed the window. I'd like to see a simple example on how to use widgets and events.

It's interesting to know we don't have to open/close the various libBases.

Gabriel
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Basic Amiga-API coding
« Reply #13 on: July 31, 2006, 10:09:29 PM »
I hope that request doesn't turn into a Reaction v MUI v Gadtools v GTK wrapper thingy type flamefest :lol:
int p; // A
 

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show only replies by Heinz
    • http://amidevcpp.amiga-world.de
Re: Basic Amiga-API coding
« Reply #14 on: July 31, 2006, 10:21:24 PM »
Quote

Karlos wrote:
I hope that request doesn't turn into a Reaction v MUI v Gadtools v GTK wrapper thingy type flamefest :lol:


Why bother when there is ZUNE :lol: